Class: Gecode::Set::SetConstraintReceiver

Inherits:
ConstraintReceiver show all
Defined in:
lib/gecoder/interface/constraints/set_var_constraints.rb,
lib/gecoder/interface/constraints/set/domain.rb,
lib/gecoder/interface/constraints/set/channel.rb,
lib/gecoder/interface/constraints/set/include.rb,
lib/gecoder/interface/constraints/set/relation.rb

Overview

SetConstraintReceiver contains all constraints that can be placed on a SetOperand.

Constraints are placed by calling SetOperand#must (or any other of the variations defined in Operand), which produces a SetConstraintReceiver from which the desired constraint can be used.

Most constraint accept :reify option. See ConstraintReceiver for more information.

Examples

Constrains set_operand to be a subset of 1, 2 using an alias of SetConstraintReceiver#subset:

set_operand.must_be.subset_of 0..2

Constrains the union of set_operand1 and set_operand2 to a subset of 1, 2 using the SetOperand#union property and SetConstraintReceiver#subset:

set_operand1.union(set_operand2).must_be.subset_of 0..2

Constrains the union of the set operands in set_enum to not equal 1, 2 by using the SetEnumOperand#union property and an alias of SetConstraintReceiver#==:

set_enum.union.must_not == 0..2

The same as above, but alsa specifying that the constraint should be reified with bool_operand:

set_enum.union.must_not.equal(0..2, :reify => bool_operand)

Instance Method Summary collapse

Constructor Details

#initialize(model, params) ⇒ SetConstraintReceiver

Raises TypeError unless the left hand side is a set operand.



210
211
212
213
214
215
216
# File 'lib/gecoder/interface/constraints/set_var_constraints.rb', line 210

def initialize(model, params) #:nodoc:
  super

  unless params[:lhs].respond_to? :to_set_var
    raise TypeError, 'Must have set operand as left hand side.'
  end
end

Instance Method Details

#==(set_operand, options = {}) ⇒ Object

Constrains the set operand to equal set_operand.

Examples

set1 must equal set2

set1.must == set2

set1 must equal set2. Reify the constraint with the

boolean operand bool.

set1.must.equal(set2, :reify => bool)



16
17
18
# File 'lib/gecoder/interface/constraints/set/domain.rb', line 16

def ==(constant_set, options = {})
  add_domain_constraint(:==, constant_set, options)
end

#channel(bool_enum, options = {}) ⇒ Object

Constrains this set to channel bool_enum. The set is constrained to include value i exactly when the operand at index i in the boolean enumeration is true.

Neither reification nor negation is supported. The boolean enum and set can be interchanged.

Examples

Constrains the enumeration of boolean operands called bools to at

least have the first and third operands set to true

set.must_be.superset_of [0, 2] set.must.channel bools

An alternative way of writing the above.

set.must_be.superset_of [0, 2] bools.must.channel set



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gecoder/interface/constraints/set/channel.rb', line 20

def channel(bool_enum, options = {})
  if @params[:negate]
    raise Gecode::MissingConstraintError, 'A negated channel constraint ' + 
      'is not implemented.'
  end
  if options.has_key? :reify
    raise ArgumentError, 'The channel constraint does not support the ' + 
      'reification option.'
  end
  unless bool_enum.respond_to? :to_bool_enum
    raise TypeError, 'Expected an enum of bool operands, ' + 
      "got #{bool_enum.class}."
  end
  
  @params.update(:rhs => bool_enum)
  @params.update Gecode::Set::Util.decode_options(options)
  @model.add_constraint Channel::ChannelConstraint.new(@model, @params)
end

#complement(set_operand, options = {}) ⇒ Object

Constrains the set operand to be the complement of set_operand.

Examples

set1 must be the complement of set2

set1.must_be.complement_of set2

set1 must be the complement of set2. Reify the constraint

with the boolean operand bool.

set1.must_be.complement(set2, :reify => bool)



96
97
98
# File 'lib/gecoder/interface/constraints/set/domain.rb', line 96

def complement(constant_set, options = {})
  add_domain_constraint(:complement, constant_set, options)
end

#disjoint(set_operand, options = {}) ⇒ Object

Constrains the set operand to be disjoint with set_operand.

Examples

set1 must be disjoint with set2

set1.must_be.disjoint_with set2

set1 must be disjoint with set2. Reify the constraint

with the boolean operand bool.

set1.must_be.disjoint(set2, :reify => bool)



76
77
78
# File 'lib/gecoder/interface/constraints/set/domain.rb', line 76

def disjoint(constant_set, options = {})
  add_domain_constraint(:disjoint, constant_set, options)
end

#include(int_enum) ⇒ Object

Constrains this set to include the values of int_enum.

The constraint has the side effect of sorting the integer operands in a non-descending order. It does not support reification nor negation.

Examples

Constrain set to include the values of all operands in

int_enum.

set.must.include int_enum



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gecoder/interface/constraints/set/include.rb', line 13

def include(int_enum)
  unless int_enum.respond_to? :to_int_enum
    raise TypeError, "Expected int var enum, got #{int_enum.class}."
  end
  if @params[:negate]
    raise Gecode::MissingConstraintError, 'A negated include is not ' + 
      'implemented.'
  end
  
  @params.update(:variables => int_enum)
  @model.add_constraint Connection::IncludeConstraint.new(@model, @params)
end

#pre_relation_complementObject

Constrains the set operand to be the complement of constant_set.

Examples

set must be the complement of [1,2,5]

set.must_be.complement_of [1,2,5]

set must be the complement of 1..67

set.must_be.complement_of 1..67

set must not be the complement of [0].

set.must_not_be.complement_of 0

set must be the complement of [1,3,5,7]. The constraint is

reified with the boolean operand bool.

set.must_be.complement_of([1.3.5.7], :reify => bool)



79
80
81
# File 'lib/gecoder/interface/constraints/set/relation.rb', line 79

def complement(constant_set, options = {})
  add_domain_constraint(:complement, constant_set, options)
end

#pre_relation_disjointObject

Constrains the set operand to be disjoint with constant_set.

Examples

set must be disjoint with [1,2,5]

set.must_be.disjoint_with [1,2,5]

set must be disjoint with 1..67

set.must_be.disjoint_with 1..67

set must not be disjoint with [0].

set.must_not_be.disjoint_with 0

set must be disjoint with [1,3,5,7]. The constraint is reified with

the boolean operand bool.

set.must_be.disjoint_with([1.3.5.7], :reify => bool)



60
61
62
# File 'lib/gecoder/interface/constraints/set/relation.rb', line 60

def disjoint(constant_set, options = {})
  add_domain_constraint(:disjoint, constant_set, options)
end

#pre_relation_equalityObject

Constrains the set operand to have a domain equal to constant_set.

Examples

set must equal [1,2,5]

set.must == [1,2,5]

set must not equal 1..67

set.must_not == 1..67

set must equal the singleton set 0. The constraint is reified with

the boolean operand is_singleton_zero.

set.must.equal(0, :reify => is_singleton_zero)



3
4
5
# File 'lib/gecoder/interface/constraints/set/relation.rb', line 3

def ==(constant_set, options = {})
  add_domain_constraint(:==, constant_set, options)
end

#pre_relation_subsetObject

Constrains the set operand to be a subset of constant_set.

Examples

set must be a subset of [1,2,5]

set.must_be.subset_of [1,2,5]

set must be a subset of 1..67

set.must_be.subset_of 1..67

set must not be a subset of [0].

set.must_not_be.subset_of 0

set must be a subset of [1,3,5,7]. The constraint is reified with

the boolean operand bool.

set.must_be.subset_of([1.3.5.7], :reify => bool)



41
42
43
# File 'lib/gecoder/interface/constraints/set/relation.rb', line 41

def subset(constant_set, options = {})
  add_domain_constraint(:subset, constant_set, options)
end

#pre_relation_supersetObject

Constrains the set operand to be a superset of constant_set.

Examples

set must be a superset of [1,2,5]

set.must_be.superset_of [1,2,5]

set must be a superset of 1..67

set.must_be.superset_of 1..67

set must not be a superset of [0].

set.must_not_be.superset_of 0

set must be a superset of [1,3,5,7]. The constraint is reified with

the boolean operand bool.

set.must_be.superset_of([1.3.5.7], :reify => bool)



22
23
24
# File 'lib/gecoder/interface/constraints/set/relation.rb', line 22

def superset(constant_set, options = {})
  add_domain_constraint(:superset, constant_set, options)
end

#subset(set_operand, options = {}) ⇒ Object

Constrains the set operand to be a subeset of set_operand.

Examples

set1 must be a subset of set2

set1.must_be.subset_of == set2

set1 must be a subset of set2. Reify the constraint

with the boolean operand bool.

set1.must_be.subset(set2, :reify => bool)



56
57
58
# File 'lib/gecoder/interface/constraints/set/domain.rb', line 56

def subset(constant_set, options = {})
  add_domain_constraint(:subset, constant_set, options)
end

#superset(set_operand, options = {}) ⇒ Object

Constrains the set operand to be a superset of set_operand.

Examples

set1 must be a superset of set2

set1.must_be.superset_of set2

set1 must be a superset of set2. Reify the constraint

with the boolean operand bool.

set1.must_be.superset(set2, :reify => bool)



36
37
38
# File 'lib/gecoder/interface/constraints/set/domain.rb', line 36

def superset(constant_set, options = {})
  add_domain_constraint(:superset, constant_set, options)
end