Class: Gecode::SelectedSet::SelectedSetOperand
- Inherits:
-
Object
- Object
- Gecode::SelectedSet::SelectedSetOperand
- Includes:
- Operand
- Defined in:
- lib/gecoder/interface/constraints/selected_set_constraints.rb,
lib/gecoder/interface/constraints/selected_set/select.rb
Overview
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]
Instance Method Summary collapse
-
#initialize(set_enum, set) ⇒ SelectedSetOperand
constructor
Constructs a new selected set operand from
set_enum
andset
. -
#intersection(options = {}) ⇒ Object
Produces a SetOperand representing the selected sets’ intersection.
-
#model ⇒ Object
:nodoc:.
-
#to_selected_set ⇒ Object
Returns the set enum and set that make up the selected set operand.
-
#union ⇒ Object
Produces a SetOperand representing the selected sets’ union.
Methods included from Operand
Constructor Details
#initialize(set_enum, set) ⇒ SelectedSetOperand
Constructs a new selected set operand from set_enum
and set
.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gecoder/interface/constraints/selected_set_constraints.rb', line 18 def initialize(set_enum, set) #:nodoc: 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 |
Instance Method Details
#intersection(options = {}) ⇒ Object
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])
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gecoder/interface/constraints/selected_set/select.rb', line 24 def intersection( = {}) universe = nil unless .empty? unless .size == 1 and .has_key?(:with) raise ArgumentError, "Expected option key :with, got #{.keys}." else universe = [: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 ⇒ Object
:nodoc:
36 37 38 |
# File 'lib/gecoder/interface/constraints/selected_set_constraints.rb', line 36 def model #:nodoc: @set_enum.model end |
#to_selected_set ⇒ Object
Returns the set enum and set that make up the selected set operand.
32 33 34 |
# File 'lib/gecoder/interface/constraints/selected_set_constraints.rb', line 32 def to_selected_set #:nodoc: return @set_enum, @set end |
#union ⇒ Object
Produces a SetOperand representing the selected sets’ union.
Examples
# The union of all sets selected by +set_enum[set]+.
set_enum[set].union
9 10 11 |
# File 'lib/gecoder/interface/constraints/selected_set/select.rb', line 9 def union Element::SelectedSetUnionOperand.new(model, self) end |