Sha256: f58b8b7099b15a07b8deb46f9e88809f45d6a49c573465752e04b4539673843b

Contents?: true

Size: 1.74 KB

Versions: 1

Compression:

Stored size: 1.74 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)
      enum, strength = @params.values_at(:lhs, :strength)
      if variable.nil?
        variable = @model.int_var(enum.domain_range)
      end
      
      @model.add_interaction do
        Gecode::Raw::max(@model.active_space, enum.to_int_var_array, 
          variable.bind, strength)
      end
      return variable
    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)
      enum, strength = @params.values_at(:lhs, :strength)
      if variable.nil?
        variable = @model.int_var(enum.domain_range)
      end
      
      @model.add_interaction do
        Gecode::Raw::min(@model.active_space, enum.to_int_var_array, 
          variable.bind, strength)
      end
      return variable
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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