Class: Gecode::Constraints::IntEnum::Extensional::TupleConstraint

Inherits:
Constraint
  • Object
show all
Defined in:
lib/gecoder/interface/constraints/int_enum/extensional.rb

Overview

Describes a tuple constraint, which constrains all the variables in an enumeration of integer variables to be equal to one of the specified tuples. Neither negation nor reification is supported.

Example

# Constrains the two integer variables in +numbers+ to either have 
# values 1 and 7, or values 47 and 11.
numbers.must_be.in [[1,7], [47,11]]

# The same as above, but preferring speed over low memory usage.
numbers.must_be.in([[1,7], [47,11]], :kind => :speed)

Instance Method Summary collapse

Methods inherited from Constraint

#initialize

Constructor Details

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

Instance Method Details

#postObject



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gecoder/interface/constraints/int_enum/extensional.rb', line 68

def post
  # Bind lhs.
  lhs = @params[:lhs].to_int_var_array

  # Create the tuple set.
  tuple_set = Gecode::Raw::TupleSet.new
  @params[:tuples].each do |tuple|
    tuple_set.add tuple
  end
  tuple_set.finalize

  # Post the constraint.
  Gecode::Raw::extensional(@model.active_space, lhs, tuple_set, 
    *propagation_options)
end