Class: Gecode::Constraints::SetEnum::Operation::ExpressionStub

Inherits:
Gecode::Constraints::Set::CompositeStub show all
Defined in:
lib/gecoder/interface/constraints/set_enum/operation.rb

Overview

Describes a CompositeStub for the enumeration operation constraint, which constrains the result of applying an operation between all set variables in a set enumeration.

The supported operations are:

  • union

  • disjoint_union

  • intersection

  • minus

Example

# The union of all set variables in +sets+ must be subset of 1..17.
sets.union.must_be.subset_of 1..17

# The intersection of all set variables must equal [1,3,5].
sets.intersection.must == [1,3,5]

# The union of all set variable must be a subset of the set variable
# +universe+.
sets.union.must_be.subset_of universe

# The same as above, but reified with the boolean variable 
# +is_within_universe+. 
sets.union.must_be.subset_of(universe, :reify => is_within_universe)

Instance Method Summary collapse

Methods inherited from Gecode::Constraints::Set::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::Set::CompositeStub

Instance Method Details

#constrain_equal(variable, params, constrain) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/gecoder/interface/constraints/set_enum/operation.rb', line 44

def constrain_equal(variable, params, constrain)
  enum, operation = @params.values_at(:lhs, :operation)

  if constrain
    if operation == Gecode::Raw::SOT_INTER or 
        operation == Gecode::Raw::SOT_MINUS
      variable.must_be.subset_of enum.first.upper_bound
    else
      variable.must_be.subset_of enum.upper_bound_range
    end
  end
  
  Gecode::Raw::rel(@model.active_space, operation, enum.to_set_var_array,
    variable.bind)
end