Sha256: fb379cc936cb9fe6ad78d3ade5cbef1cbc6d784ed0ee3f91fc8b8f9c979e8618

Contents?: true

Size: 1.61 KB

Versions: 2

Compression:

Stored size: 1.61 KB

Contents

module Gecode::IntEnumMethods
  # Starts an arithmetic max constraint. This overrides the normal enum max, but
  # that's not a problem since variables are not implemented to be comparable.
  def max
    return Gecode::Constraints::IntEnum::Arithmetic::MaxExpressionStub.new(
      @model, :lhs => self)
  end
  
  # Starts an arithmetic min constraint. This overrides the normal enum min, but
  # that's not a problem since variables are not implemented to be comparable.
  def min
    return Gecode::Constraints::IntEnum::Arithmetic::MinExpressionStub.new(
      @model, :lhs => self)
  end
end

# A module that gathers the classes and modules used by arithmetic constraints.
module Gecode::Constraints::IntEnum::Arithmetic 
  # Describes an expression stub started with an int var enum following by #max.
  class MaxExpressionStub < Gecode::Constraints::Int::CompositeStub
    def constrain_equal(variable, params, constrain)
      enum, strength = @params.values_at(:lhs, :strength)
      if constrain
        variable.must_be.in enum.domain_range
      end
      
      Gecode::Raw::max(@model.active_space, enum.to_int_var_array, 
        variable.bind, strength)
    end
  end
  
  # Describes an expression stub started with an int var enum following by #min.
  class MinExpressionStub < Gecode::Constraints::Int::CompositeStub
    def constrain_equal(variable, params, constrain)
      enum, strength = @params.values_at(:lhs, :strength)
      if constrain
        variable.must_be.in enum.domain_range
      end
      
      Gecode::Raw::min(@model.active_space, enum.to_int_var_array, 
        variable.bind, strength)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gecoder-0.7.0 lib/gecoder/interface/constraints/int_enum/arithmetic.rb
gecoder-0.6.1 lib/gecoder/interface/constraints/int_enum/arithmetic.rb