Sha256: 3a9cc0b70de06515ba45283abcb8e925970eee1b6cce8a085081d3281efe9015

Contents?: true

Size: 1.75 KB

Versions: 14

Compression:

Stored size: 1.75 KB

Contents

module Gecode::IntEnum
  module IntEnumOperand
    # Produces an IntOperand representing the maximum value of the 
    # integer operands in this enumeration.
    #
    # ==== Examples 
    #
    #   # The maximum of +int_enum+.
    #   int_enum.max
    def max
      Arithmetic::IntEnumMaxOperand.new(@model, self)
    end
    
    # Produces an IntOperand representing the minimum value of the 
    # integer operands in this enumeration.
    #
    # ==== Examples 
    #
    #   # The minimum of +int_enum+.
    #   int_enum.min
    def min
      Arithmetic::IntEnumMinOperand.new(@model, self)
    end
  end

  # A module that gathers the classes and modules used by arithmetic 
  # constraints.
  module Arithmetic #:nodoc:
    class IntEnumMaxOperand < Gecode::Int::ShortCircuitEqualityOperand #:nodoc:
      def initialize(model, int_enum)
        super model
        @int_enum = int_enum
      end

      def constrain_equal(int_operand, constrain, propagation_options)
        enum = @int_enum.to_int_enum
        if constrain
          int_operand.must_be.in enum.domain_range
        end
        
        Gecode::Raw::max(@model.active_space, enum.bind_array, 
          int_operand.to_int_var.bind, *propagation_options)
      end
    end
    
    class IntEnumMinOperand < Gecode::Int::ShortCircuitEqualityOperand #:nodoc:
      def initialize(model, int_enum)
        super model
        @int_enum = int_enum
      end

      def constrain_equal(int_operand, constrain, propagation_options)
        enum = @int_enum.to_int_enum
        if constrain
          int_operand.must_be.in enum.domain_range
        end
        
        Gecode::Raw::min(@model.active_space, enum.bind_array, 
          int_operand.to_int_var.bind, *propagation_options)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
gecoder-with-gecode-1.1.1.1 lib/gecoder/interface/constraints/int_enum/arithmetic.rb
gecoder-with-gecode-1.1.1 lib/gecoder/interface/constraints/int_enum/arithmetic.rb
gecoder-1.1.1 lib/gecoder/interface/constraints/int_enum/arithmetic.rb
gecoder-with-gecode-1.1.0 lib/gecoder/interface/constraints/int_enum/arithmetic.rb
gecoder-1.1.0 lib/gecoder/interface/constraints/int_enum/arithmetic.rb
gecoder-1.0.0 lib/gecoder/interface/constraints/int_enum/arithmetic.rb
gecoder-0.9.0 lib/gecoder/interface/constraints/int_enum/arithmetic.rb
gecoder-0.9.1 lib/gecoder/interface/constraints/int_enum/arithmetic.rb
gecoder-with-gecode-0.9.0-x86-mswin32-60 lib/gecoder/interface/constraints/int_enum/arithmetic.rb
gecoder-with-gecode-0.9.1-x86-mswin32-60 lib/gecoder/interface/constraints/int_enum/arithmetic.rb
gecoder-with-gecode-0.9.0 lib/gecoder/interface/constraints/int_enum/arithmetic.rb
gecoder-with-gecode-0.9.1 lib/gecoder/interface/constraints/int_enum/arithmetic.rb
gecoder-with-gecode-1.0.0-x86-mswin32-60 lib/gecoder/interface/constraints/int_enum/arithmetic.rb
gecoder-with-gecode-1.0.0 lib/gecoder/interface/constraints/int_enum/arithmetic.rb