Class: Gecode::Constraints::Int::Arithmetic::SquareRootExpressionStub
- Inherits:
-
CompositeStub
- Object
- ExpressionStub
- CompositeStub
- CompositeStub
- Gecode::Constraints::Int::Arithmetic::SquareRootExpressionStub
- Defined in:
- lib/gecoder/interface/constraints/int/arithmetic.rb
Overview
Describes a CompositeStub for the square root constraint, which constrain the rounded down square root of the variable.
Examples
# The square root of +x+, rounded down, must equal y.
x.square_root.must == y
# The square root of +x+, rounded down, must be larger than 17, with
# +bool+ as reification variable and +domain+ as strength.
x.square_root.must_be.larger_than(17, :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
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/gecoder/interface/constraints/int/arithmetic.rb', line 124 def constrain_equal(variable, params, constrain) lhs = @params[:lhs] if constrain max = lhs.max if max < 0 # The left hand side does not have a real valued square root. upper_bound = 0 else upper_bound = Math.sqrt(max).floor; end min = lhs.min if min < 0 lower_bound = 0 else lower_bound = Math.sqrt(min).floor; end variable.must_be.in lower_bound..upper_bound end Gecode::Raw::sqrt(@model.active_space, lhs.bind, variable.bind, *) end |