lib/gecoder/interface/constraints/int_enum/arithmetic.rb in gecoder-0.4.0 vs lib/gecoder/interface/constraints/int_enum/arithmetic.rb in gecoder-0.5.0

- old
+ new

@@ -15,58 +15,32 @@ 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::ExpressionStub - include Gecode::Constraints::LeftHandSideMethods - - private - - # Produces an expression for the lhs module. - def expression(params) - # We extract the integer and continue as if it had been specified as - # left hand side. This might be elegant, but it could get away with - # fewer constraints at times (when only equality is used) and - # propagation strength can't be specified. - # TODO: cut down on the number of constraints when possible. See if - # there's some neat way of getting the above remarks. + 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 - params.update(@params) - lhs = params[:lhs] - proxy = @model.int_var(lhs.domain_range) - lhs = lhs.to_int_var_array - - Gecode::Raw::max(@model.active_space, lhs, proxy.bind, - Gecode::Raw::ICL_DEF) - Gecode::Constraints::Int::Expression.new(@model, - params.update(:lhs => proxy)) + Gecode::Raw::max(@model.active_space, enum.to_int_var_array, + variable.bind, strength) + return variable end end # Describes an expression stub started with an int var enum following by #min. - class MinExpressionStub < Gecode::Constraints::ExpressionStub - include Gecode::Constraints::LeftHandSideMethods - - private - - # Produces an expression for the lhs module. - def expression(params) - # We extract the integer and continue as if it had been specified as - # left hand side. This might be elegant, but it could get away with - # fewer constraints at times (when only equality is used) and - # propagation strength can't be specified. - # TODO: cut down on the number of constraints when possible. See if - # there's some neat way of getting the above remarks. + 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 - params.update(@params) - lhs = params[:lhs] - proxy = @model.int_var(lhs.domain_range) - lhs = lhs.to_int_var_array - - Gecode::Raw::min(@model.active_space, lhs, proxy.bind, - Gecode::Raw::ICL_DEF) - Gecode::Constraints::Int::Expression.new(@model, - params.update(:lhs => proxy)) + Gecode::Raw::min(@model.active_space, enum.to_int_var_array, + variable.bind, strength) + return variable end end end