Class: Gecode::Constraints::BoolEnum::Extensional::TupleConstraint

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

Overview

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

Example

# Constrains the three boolean variables in +bools+ to either
# be true, false, true, or false, false, true.
bools.must_be.in [[true, false, true], [false, false, true]]

# The same as above, but preferring speed over low memory usage.
bools.must_be.in([[true, false, true], [false, false, true]], 
  :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/bool_enum/extensional.rb', line 68

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

  # Create the tuple set.
  tuple_set = Gecode::Raw::TupleSet.new
  @params[:tuples].each do |tuple|
    tuple_set.add tuple.map{ |b| b ? 1 : 0 }
  end
  tuple_set.finalize

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