Class: Gecode::Constraints::Set::Operation::OperationConstraint

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

Overview

Describes an operation constraint, which constrains the result of an operation with two sets as operands. Either constant sets or set variables may be used for the result and operands, with the exception of that all three may not be constant sets.

The typical form is

set_operand_1.<operation>(set_operand_2).must.<relation>(result_set)

The following operations are supported:

  • union

  • disjoint_union

  • intersection

  • minus

The allowed relations are the same as for Set::Relation::RelationConstraint.

Neither reification nor negation is supported.

Examples

# +set_1+ union +set_2+ must equal +set_3+.
set_1.union(set_2).must == set_3

# +set_1+ intersection [3,5,6] must equal +set_3+.
set_1.intersection([3,5,6]).must == set_3

# [0,1,2] minus +set_2+ must be superset of +set_3+.
wrap_enum([0,1,2]).minus(set_2).must_be.superset_of(set_3)

# +set_1+ disjoint union with [0] must be subset of 0..17.
set_1.disjoint_union(0).must_be.subset_of 0..17

Instance Method Summary collapse

Methods inherited from Constraint

#initialize

Constructor Details

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

Instance Method Details

#postObject



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/gecoder/interface/constraints/set/operation.rb', line 113

def post
  op1, op2, operation, relation, rhs, negate = @params.values_at(:lhs, 
    :op2, :operation, :relation, :rhs, :negate)

  op1, op2, rhs = [op1, op2, rhs].map do |expression|
    # The expressions can either be set variables or constant sets, 
    # convert them appropriately.
    if expression.respond_to? :bind
      expression.bind
    else
      Gecode::Constraints::Util::constant_set_to_int_set(expression)
    end
  end

  Gecode::Raw::rel(@model.active_space, op1, operation, op2, relation, 
    rhs)
end