class Gecode::SelectedSet::SelectedSetOperand

A SelectedSetOperand is an uncommon operand that results from calling SetEnumOperand#[] with a SetOperand. It facilitates placing the constraints defined in SelectedSetConstraintReceiver

Examples

Producing a SelectedSetOperand from set_enum and set_operand:

set_enum[set_operand]

Public Instance Methods

intersection(options = {}) click to toggle source

Produces a SetOperand representing the selected sets’ intersection. The option :with can be used to enumerate the elements in the universe.

Examples

# The intersection of all sets selected by +set_enum[set]+.
set_enum[set].intersection

# The same intersection as above, but with [3,5,7] as universe.
set_enum[set].intersection(:with => [3,5,7])
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/selected_set/select.rb, line 24
def intersection(options = {})
  universe = nil
  unless options.empty? 
    unless options.size == 1 and options.has_key?(:with)
      raise ArgumentError, "Expected option key :with, got #{options.keys}."
    else
      universe = options[:with]
      unless universe.kind_of?(Enumerable) and 
          universe.all?{ |element| element.kind_of? Fixnum }
        raise TypeError, "Expected the universe to be specified as " + 
          "an enumeration of fixnum, got #{universe.class}."
      end
    end
  end
  
  Element::SelectedSetIntersectionOperand.new(model, self, universe)
end
model() click to toggle source
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/selected_set_constraints.rb, line 36
def model 
  @set_enum.model
end
to_selected_set() click to toggle source

Returns the set enum and set that make up the selected set operand.

# File doc/tmp/rdoc_dev/gecoder/interface/constraints/selected_set_constraints.rb, line 32
def to_selected_set 
  return @set_enum, @set
end
union() click to toggle source

Produces a SetOperand representing the selected sets’ union.

Examples

# The union of all sets selected by +set_enum[set]+.
set_enum[set].union
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/selected_set/select.rb, line 9
def union
  Element::SelectedSetUnionOperand.new(model, self)
end

Public Class Methods

new(set_enum, set) click to toggle source

Constructs a new selected set operand from set_enum and set.

# File doc/tmp/rdoc_dev/gecoder/interface/constraints/selected_set_constraints.rb, line 18
def initialize(set_enum, set) 
  unless set_enum.respond_to? :to_set_enum
    raise TypeError, "Expected set enum operand, got #{set_enum.class}."
  end
  unless set.respond_to? :to_set_var
    raise TypeError, "Expected set operand, got #{set.class}."
  end

  @set_enum = set_enum
  @set = set
end