class Gecode::Set::SetConstraintReceiver
SetConstraintReceiver contains all constraints that can be placed on a SetOperand.
Constraints are placed by calling Gecode::Operand#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 {0, 1, 2} using an
alias of #subset:
set_operand.must_be.subset_of 0..2
Constrains the union of set_operand1
and
set_operand2
to a subset of {0, 1, 2} using the Gecode::Set::SetOperand#union
property and #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 {0, 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)
Public Instance Methods
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)
# File lib/gecoder/interface/constraints/set/domain.rb, line 16 def ==(constant_set, options = {}) add_domain_constraint(:==, constant_set, options) end
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
# 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
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)
# File lib/gecoder/interface/constraints/set/domain.rb, line 96 def complement(constant_set, options = {}) add_domain_constraint(:complement, constant_set, options) end
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)
# File lib/gecoder/interface/constraints/set/domain.rb, line 76 def disjoint(constant_set, options = {}) add_domain_constraint(:disjoint, constant_set, options) end
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
# 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
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)
# File lib/gecoder/interface/constraints/set/domain.rb, line 56 def subset(constant_set, options = {}) add_domain_constraint(:subset, constant_set, options) end
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)
# File lib/gecoder/interface/constraints/set/domain.rb, line 36 def superset(constant_set, options = {}) add_domain_constraint(:superset, constant_set, options) end