Class: Gecode::Constraints::Int::Linear::LinearConstraint
- Inherits:
-
ReifiableConstraint
- Object
- Constraint
- ReifiableConstraint
- Gecode::Constraints::Int::Linear::LinearConstraint
- Defined in:
- lib/gecoder/interface/constraints/int/linear.rb
Overview
Linear constraints specify that an integer variable must have a linear equation containing variables must hold. The same relations and options used in SimpleRelationConstraint
can also be used for linear constraints.
Boolean variables can also be used instead of integer variables. In that case a boolean variable assigned true is equal to 1 and a boolean variable assigned false is equal to 0. There is one exception: boolean variables can not be used alone as left hand side.
Do not mix boolean and integer variables. Even if possible it’s not supported, and might be removed in the future.
Examples
# The sum of the int variables +x+ and +y+ must equal +z+ + 3.
(x + y).must == z + 3
# Another way of writing the above.
z.must == x + y - 3
# The inequality 10(x + y) > 3x must not hold.
(x + y)*10.must_not > x*3
# Specifies the above, but reifies the constraint with the boolean
# variable +bool+ and gives it propagation strength +domain+.
(x + y)*10.must_not_be.greater_than(x*3, :reify => bool, :strength => :domain)
Instance Method Summary collapse
Methods inherited from ReifiableConstraint
#&, #reification_var, #reification_var=, #|
Methods inherited from Constraint
Constructor Details
This class inherits a constructor from Gecode::Constraints::Constraint
Instance Method Details
#post ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/gecoder/interface/constraints/int/linear.rb', line 143 def post lhs, rhs, relation_type, reif_var = @params.values_at(:lhs, :rhs, :relation_type, :reif) reif_var = reif_var.bind if reif_var.respond_to? :bind if rhs.respond_to? :to_minimodel_lin_exp rhs = rhs.to_minimodel_lin_exp elsif rhs.respond_to? :bind rhs = rhs.bind * 1 end final_exp = (lhs.to_minimodel_lin_exp - rhs) if reif_var.nil? final_exp.post(@model.active_space, relation_type, *) else final_exp.post(@model.active_space, relation_type, reif_var, *) end end |