Class: Gecode::Constraints::Int::Arithmetic::MultExpressionStub

Inherits:
CompositeStub show all
Defined in:
lib/gecoder/interface/constraints/int/arithmetic.rb

Overview

Describes a CompositeStub for multiplication constraint, which constrain the value of the multiplication of two variables.

Examples

# The value of +x*y+ must be equal to their sum.
(x*y).must == x + y

# The valye of +x*y+ must be less than 17, with +bool+ as reification 
# variable and +domain+ as strength.
(x*y).must_be.less_than(17, :reify => bool, :strength => :domain)

Instance Method Summary collapse

Methods inherited from CompositeStub

#initialize

Methods inherited from CompositeStub

#initialize

Methods included from LeftHandSideMethods

#must, #must_not

Methods inherited from ExpressionStub

#initialize

Constructor Details

This class inherits a constructor from Gecode::Constraints::Int::CompositeStub

Instance Method Details

#constrain_equal(variable, params, constrain) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/gecoder/interface/constraints/int/arithmetic.rb', line 59

def constrain_equal(variable, params, constrain)
  lhs, lhs2 = @params.values_at(:lhs, :var)
  if constrain
    a_min = lhs.min; a_max = lhs.max
    b_min = lhs2.min; b_max = lhs2.max
    products = [a_min*b_min, a_min*b_max, a_max*b_min, a_max*b_max]
    variable.must_be.in products.min..products.max
  end

  Gecode::Raw::mult(@model.active_space, lhs.bind, lhs2.bind, 
    variable.bind, *propagation_options)
end