Class: Gecode::SelectedSet::SelectedSetConstraintReceiver

Inherits:
ConstraintReceiver show all
Defined in:
lib/gecoder/interface/constraints/selected_set_constraints.rb,
lib/gecoder/interface/constraints/selected_set/select.rb

Overview

SelectedSetConstraintReceiver contains all constraints that can be placed on a SelectedSetOperand.

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

Examples

Constrains the sets in set_enum that are selected by set_operand to be disjoint. This uses SetEnumOperand#[] and SelectedSetConstraintReceiver#disjoint.

set_enum[set_operand].must_be.disjoint

Instance Method Summary collapse

Constructor Details

#initialize(model, params) ⇒ SelectedSetConstraintReceiver

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



65
66
67
68
69
70
71
# File 'lib/gecoder/interface/constraints/selected_set_constraints.rb', line 65

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

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

Instance Method Details

#disjoint(options = {}) ⇒ Object

Constrains the selected sets to be pairwise disjoint.

Examples

# Constrains all sets selected by +set_enum[set]+ to be pairwise
# disjoint.
set_enum[set].must_be.disjoint


51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/gecoder/interface/constraints/selected_set/select.rb', line 51

def disjoint(options = {})
  if @params[:negate]
    raise Gecode::MissingConstraintError, 'A negated disjoint constraint ' + 
      'is not implemented.'
  end
  if options.has_key? :reify
    raise ArgumentError, 'The disjoint constraint does not support the ' + 
      'reification option.'
  end

  @params.update Gecode::Set::Util.decode_options(options)
  @model.add_constraint Element::DisjointConstraint.new(@model, @params)
end