Class: Gecode::Constraints::IntEnum::Element::ExpressionStub
- Inherits:
-
Gecode::Constraints::Int::CompositeStub
- Object
- ExpressionStub
- CompositeStub
- Gecode::Constraints::Int::CompositeStub
- Gecode::Constraints::IntEnum::Element::ExpressionStub
- Defined in:
- lib/gecoder/interface/constraints/int_enum/element.rb
Overview
Describes a CompositeStub for the element constraint, which places a constraint on a variable at the specified position in an enumeration of integer variables. It’s basically the array access of constraint programming.
Example
# The variable at the +x+:th position in +int_enum+ must be larger than
# +y+.
int_enum[x].must > y
# The price of +selected_item+ as described by +prices+ must not be
# larger than 100.
prices = wrap_enum([500, 24, 4711, 412, 24])
prices[selected_item].must_not > 100
# Reify the constraint that the +x+:th variable in +int_enum+ must be in
# range 7..17 with the boolean variable +bool+ and select strength
# +domain+.
int_enum[x].must_be.in(7..17, :reify => bool, :strength => :domain)
Instance Method Summary collapse
Methods inherited from Gecode::Constraints::Int::CompositeStub
Methods inherited from CompositeStub
Methods included from LeftHandSideMethods
Methods inherited from ExpressionStub
Constructor Details
This class inherits a constructor from Gecode::Constraints::Int::CompositeStub
Instance Method Details
#constrain_equal(variable, params, constrain) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gecoder/interface/constraints/int_enum/element.rb', line 25 def constrain_equal(variable, params, constrain) enum, position = @params.values_at(:lhs, :position) if constrain variable.must_be.in enum.domain_range end # The enum can be a constant array. enum = enum.to_int_var_array if enum.respond_to? :to_int_var_array Gecode::Raw::element(@model.active_space, enum, position.bind, variable.bind, *) end |