Class: Gecode::Constraints::Int::Linear::SimpleRelationConstraint

Inherits:
ReifiableConstraint show all
Defined in:
lib/gecoder/interface/constraints/int/linear.rb

Overview

Simple relation constraints specify that an integer variable must have a specified relation to a constant integer or another integer variable. The following relations are supported (the aliases of each relation are also listed).

  • <, lesser, lesser_than

  • >, greater, greater_than

  • >=, greater_or_equal, greater_than_or_equal_to

  • <=, less_or_equal, less_than_or_equal_to

  • , equal, equal_to

Each can be negated by using must_not instead of must.

Two options (given as a hash) are available:

strength

Specifies the propagation strength of the constraint. Must be one of value, bounds, domain and default. The strength generally progresses as value -> bounds -> domain (value being the weakest, but usually cheapest, while domain is the strongest but usually costly).

reify

Specifies a boolean variable that should be used for reification (see ReifiableConstraint).

Examples

# Int variable +x+ must not equal 0.
x.must_not.equal(0)

# Another way of writing the above. 
x.must_not == 0

# +x+ must be strictly larger than +y+.
x.must > y

# Specifies the above, but reifies the constraint with the boolean 
# variable +bool+.
x.must_be.greater_than(y, :reify => bool)

Instance Method Summary collapse

Methods inherited from ReifiableConstraint

#&, #reification_var, #reification_var=, #|

Methods inherited from Constraint

#initialize

Constructor Details

This class inherits a constructor from Gecode::Constraints::Constraint

Instance Method Details

#postObject



202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/gecoder/interface/constraints/int/linear.rb', line 202

def post
  # Fetch the parameters to Gecode.
  lhs, relation, rhs, reif_var = 
    @params.values_at(:lhs, :relation_type, :element, :reif)
    
  rhs = rhs.bind if rhs.respond_to? :bind
  if reif_var.nil?
    Gecode::Raw::rel(@model.active_space, lhs.bind, relation, rhs, 
      *propagation_options)
  else
    Gecode::Raw::rel(@model.active_space, lhs.bind, relation, rhs, 
      reif_var.bind, *propagation_options)
  end
end