Class: Gecode::SetEnum::SetEnumConstraintReceiver
- Inherits:
-
ConstraintReceiver
- Object
- ConstraintReceiver
- Gecode::SetEnum::SetEnumConstraintReceiver
- Defined in:
- lib/gecoder/interface/constraints/set_enum_constraints.rb,
lib/gecoder/interface/constraints/set_enum/channel.rb,
lib/gecoder/interface/constraints/set_enum/distinct.rb
Overview
SetEnumConstraintReceiver contains all constraints that can be placed on a SetEnumOperand.
Constraints are placed by calling SetEnumOperand#must (or any other of the variations defined in Operand), which produces a SetEnumConstraintReceiver from which the desired constraint can be used.
Examples
Constrains set_enum
to channel int_enum
by using SetEnumConstraintReceiver#channel:
set_enum.must.channel set_enum
Constrains each pair of set operands in set_enum
to at most share one element. Also constrains each set to have size 17. Uses SetEnumConstraintReceiver#at_most_share_one_element.
set_enum.must.at_most_share_one_element(:size => 17)
Instance Method Summary collapse
-
#at_most_share_one_element(options = {}) ⇒ Object
Constrains all pairs of set operands in the enumeration to at most have one element in common and be of a specified size.
-
#channel(enum, options = {}) ⇒ Object
Constrains this set enum to channel
int_enum_operand
. -
#initialize(model, params) ⇒ SetEnumConstraintReceiver
constructor
Raises TypeError unless the left hand side is a set enum operand.
Constructor Details
#initialize(model, params) ⇒ SetEnumConstraintReceiver
Raises TypeError unless the left hand side is a set enum operand.
71 72 73 74 75 76 77 |
# File 'lib/gecoder/interface/constraints/set_enum_constraints.rb', line 71 def initialize(model, params) #:nodoc: super unless params[:lhs].respond_to? :to_set_enum raise TypeError, 'Must have set enum operand as left hand side.' end end |
Instance Method Details
#at_most_share_one_element(options = {}) ⇒ Object
Constrains all pairs of set operands in the enumeration to at most have one element in common and be of a specified size. Providing a size is not optional.
Neither negation nor reification is supported.
Examples
# All set operands in +sets+ must have cardinality 17 and no pair may
# have more than one element in common.
sets.must.at_most_share_one_element(:size => 17)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/gecoder/interface/constraints/set_enum/distinct.rb', line 14 def at_most_share_one_element( = {}) unless .has_key? :size raise ArgumentError, 'Option :size has to be specified.' end # TODO can we use Set::Util::decode_options here instead? unless .size == 1 raise ArgumentError, 'Only the option :size is accepted, got ' + "#{.keys.join(', ')}." end if @params[:negate] raise Gecode::MissingConstraintError, 'A negated atmost one ' + 'constrain is not implemented.' end @model.add_constraint Distinct::AtMostOneConstraint.new( @model, @params.update()) end |
#channel(enum, options = {}) ⇒ Object
Constrains this set enum to channel int_enum_operand
. The i:th set in the enumeration of set operands is constrained to includes the value of the j:th integer operand.
Neither reification nor negation is supported.
Examples
# +set_enum+ is constrained to channel +int_enum+.
int_enum.must.channel set_enum
# This is another way of writing the above.
set_enum.must.channel int_enum
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/gecoder/interface/constraints/set_enum/channel.rb', line 16 def channel(enum, = {}) unless enum.respond_to? :to_int_enum raise TypeError, "Expected integer enum, for #{enum.class}." end if @params[:negate] raise Gecode::MissingConstraintError, 'A negated channel constraint ' + 'is not implemented.' end if .has_key? :reify raise ArgumentError, 'The channel constraints does not support the ' + 'reification option.' end @params.update(Gecode::Set::Util.()) @params.update(:rhs => enum) @model.add_constraint Channel::IntEnumChannelConstraint.new(@model, @params) end |