Class: Gecode::Constraints::Int::Arithmetic::AbsExpressionStub

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

Overview

Describes a CompositeStub for absolute value constraints, which constrain the absolute value of an integer variable.

Examples

# The absolute value of +x+ must be less than 2.
x.abs.must < 2

# The absolute value of +x+ must be in the range 5..7, with +bool+ as 
# reification variable and +value+ as strength.
x.abs.must_be.in(5..7, :reify => bool, :strength => :value)

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



49
50
51
52
53
54
55
56
57
58
# File 'lib/gecoder/interface/constraints/int/arithmetic.rb', line 49

def constrain_equal(variable, params, constrain)
  lhs = @params[:lhs]
  if constrain
    bounds = [lhs.min.abs, lhs.max.abs]
    variable.must_be.in bounds.min..bounds.max
  end
  
  Gecode::Raw::abs(@model.active_space, lhs.bind, variable.bind, 
    *propagation_options)
end