Class: Gecode::Constraints::Int::Arithmetic::SquaredExpressionStub
- Inherits:
-
CompositeStub
- Object
- ExpressionStub
- CompositeStub
- CompositeStub
- Gecode::Constraints::Int::Arithmetic::SquaredExpressionStub
- Defined in:
- lib/gecoder/interface/constraints/int/arithmetic.rb
Overview
Describes a CompositeStub for the squared constraint, which constrain the squared value of the variable.
Examples
# The value of +x*x+ must be equal to y.
x.squared.must == y
# The value of +x*x+ must be less than or equal to 16, with +bool+ as
# reification variable and +domain+ as strength.
x.squared.must_be.less_or_equal(16, :reify => bool, :strength => :domain)
Instance Method Summary collapse
Methods inherited from 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
99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/gecoder/interface/constraints/int/arithmetic.rb', line 99 def constrain_equal(variable, params, constrain) lhs = @params[:lhs] if constrain min = lhs.min; max = lhs.max products = [min*max, min*min, max*max] variable.must_be.in products.min..products.max end Gecode::Raw::sqr(@model.active_space, lhs.bind, variable.bind, *) end |