Module: Gecode::Operand
- Included in:
- Bool::BoolOperand, BoolEnum::BoolEnumOperand, FixnumEnum::FixnumEnumOperand, Int::IntOperand, IntEnum::IntEnumOperand, SelectedSet::SelectedSetOperand, Set::SetOperand, SetElements::SetElementsOperand, SetEnum::SetEnumOperand
- Defined in:
- lib/gecoder/interface/constraints.rb
Overview
Describes an operand, something that a constraint can be placed on. Constraints are placed by calling #must or #must_not (the latter negates the constraint). This produces a ConstraintReceiver, which defines methods that places constraints on the operand.
In general this produces something like the following.
operand.must.constraint_method(params)
See e.g. Gecode::Int::IntOperand for concrete examples.
Classes that mix in Operand must define the methods #model and #construct_receiver. They should also define a method that converts the operand into a variable of the operand’s type (e.g. int var operands should define a method #to_int_var that returns an instance of Gecode::IntVar that represents the operand). The latter method should be used by constraints to fetch variables needed when posting constraints. The presence of the method should also be used for type checking (rather than e.g. checking whether a parameter is of type IntOperand).
Instance Method Summary collapse
-
#model ⇒ Object
Fetches the model that the operand belongs to.
-
#must ⇒ Object
(also: #must_be)
Specifies that a constraint must hold for the left hand side.
-
#must_not ⇒ Object
(also: #must_not_be)
Specifies that the negation of a constraint must hold for the left hand side.
Instance Method Details
#model ⇒ Object
Fetches the model that the operand belongs to.
43 44 45 |
# File 'lib/gecoder/interface/constraints.rb', line 43 def model raise NotImplementedError, 'Abstract method has not been implemented.' end |
#must ⇒ Object Also known as: must_be
Specifies that a constraint must hold for the left hand side.
30 31 32 |
# File 'lib/gecoder/interface/constraints.rb', line 30 def must construct_receiver :lhs => self, :negate => false end |
#must_not ⇒ Object Also known as: must_not_be
Specifies that the negation of a constraint must hold for the left hand side.
37 38 39 |
# File 'lib/gecoder/interface/constraints.rb', line 37 def must_not construct_receiver :lhs => self, :negate => true end |