class Gecode::SetEnum::SetEnumConstraintReceiver

SetEnumConstraintReceiver contains all constraints that can be placed on a SetEnumOperand.

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


Constrains set_enum to channel int_enum by using #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 #at_most_share_one_element.

set_enum.must.at_most_share_one_element(:size => 17)

Public Instance Methods

at_most_share_one_element(options = {}) click to toggle source

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.


# 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)
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/set_enum/distinct.rb, line 14
def at_most_share_one_element(options = {})
  unless options.has_key? :size
    raise ArgumentError, 'Option :size has to be specified.'
  # TODO can we use Set::Util::decode_options here instead?
  unless options.size == 1
    raise ArgumentError, 'Only the option :size is accepted, got ' + 
      "#{options.keys.join(', ')}."
  if @params[:negate]
    raise Gecode::MissingConstraintError, 'A negated atmost one ' + 
      'constrain is not implemented.'
    @model, @params.update(options))
channel(enum, options = {}) click to toggle source

Constrains this set enum to channel int_enum_operand. The i:th set in the enumeration of set operands is constrained to include the value of the j:th integer operand.

Neither reification nor negation is supported.


# +set_enum+ is constrained to channel +int_enum+. set_enum

# This is another way of writing the above. int_enum
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/set_enum/channel.rb, line 16
def channel(enum, options = {})
  unless enum.respond_to? :to_int_enum
    raise TypeError, "Expected integer enum, for #{enum.class}."
  if @params[:negate]
    raise Gecode::MissingConstraintError, 'A negated channel constraint ' + 
      'is not implemented.'
  if options.has_key? :reify
    raise ArgumentError, 'The channel constraints does not support the ' +
      'reification option.'
  @params.update(:rhs => enum)
  @model.add_constraint, @params)

Public Class Methods

new(model, params) click to toggle source

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

Calls superclass method
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/set_enum_constraints.rb, line 71
def initialize(model, params) 
  unless params[:lhs].respond_to? :to_set_enum
    raise TypeError, 'Must have set enum operand as left hand side.'