Module: Gecode::SetEnum::SetEnumOperand
- Includes:
- Operand
- Included in:
- Dummy, Gecode::SetEnumMethods
- Defined in:
- lib/gecoder/interface/constraints/set_enum_constraints.rb,
lib/gecoder/interface/constraints/set_enum/element.rb,
lib/gecoder/interface/constraints/set_enum/operation.rb
Overview
A SetEnumOperand is a enumeration of SetOperand on which the constraints defined in SetEnumConstraintReceiver can be placed.
Enumerations of set operands can be created either by using Gecode::Mixin#set_var_array and Gecode::Mixin#set_var_matrix, or by wrapping an existing enumeration containing SetOperand using Gecode::Mixin#wrap_enum. The enumerations, no matter how they were created, all respond to the properties defined by SetEnumOperand.
Examples
Produces an array of five set operands, with greatest lower bound 0 and least upper bound 1, 2, inside a problem formulation using Gecode::Mixin#set_var_array:
set_enum = set_var_array(5, 0, 1..2)
Uses Gecode::Mixin#wrap_enum inside a problem formulation to create a SetEnumOperand from an existing enumeration containing the set operands set_operand1
and set_operand2
:
set_enum = wrap_enum([set_operand1, set_operand2])
– Classes that mix in SetEnumOperand must define #model and #to_set_enum .
Class Method Summary collapse
-
.included(mod) ⇒ Object
This adds the adder for the methods in the modules including it.
Instance Method Summary collapse
-
#disjoint_union ⇒ Object
Produces a SetOperand representing the disjoint union of all sets in this enumeration.
-
#intersection ⇒ Object
Produces a SetOperand representing the intersection of all sets in this enumeration.
-
#method_missing(method, *args) ⇒ Object
:nodoc:.
-
#union ⇒ Object
Produces a SetOperand representing the union of all sets in this enumeration.
Methods included from Operand
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
:nodoc:
33 34 35 36 37 38 39 40 |
# File 'lib/gecoder/interface/constraints/set_enum_constraints.rb', line 33 def method_missing(method, *args) #:nodoc: if Gecode::SetEnum::Dummy.instance_methods.include? method.to_s # Delegate to the set enum. to_set_enum.method(method).call(*args) else super end end |
Class Method Details
.included(mod) ⇒ Object
This adds the adder for the methods in the modules including it. The reason for doing it so indirect is that the first #[] won’t be defined before the module that this is mixed into is mixed into an enum.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/gecoder/interface/constraints/set_enum/element.rb', line 6 def self.included(mod) #:nodoc: mod.module_eval do # Now we enter the module SetEnumOperands is mixed into. class << self alias_method :pre_set_element_included, :included def included(mod) #:nodoc: mod.module_eval do # Now we enter the module that the module possibly defining #[] # is mixed into. if instance_methods.include?('[]') and not instance_methods.include?('pre_set_element_access') alias_method :pre_set_element_access, :[] end # Produces a SetOperand representing the i:th set # operand in the enumeration, where i is the value of the # int operand used as index. # # A set can also be used as index, in which case a # SelectedSetOperand is produced. # # ==== Examples # # # The set operand at the +x+:th position in +set_enum+, # # where +x+ is a int operand. # set_enum[x] # # # The SelectedSetOperand representing sets at positions # # included in the value of +set+ in +set_enum+, # set_enum[set] # def [](*vars) # Hook in an element constraint if a operand is used for array # access. if vars.first.respond_to? :to_int_var Element::ElementSetOperand.new( model, self, vars.first) elsif vars.first.respond_to? :to_set_var Gecode::SelectedSet::SelectedSetOperand.new( self, vars.first) else if respond_to? :pre_set_element_access pre_set_element_access(*vars) end end end end pre_set_element_included(mod) end end end end |
Instance Method Details
#disjoint_union ⇒ Object
Produces a SetOperand representing the disjoint union of all sets in this enumeration.
Examples
# The disjoint union of all sets in +set_enum+.
set_enum.disjoint_union
32 33 34 |
# File 'lib/gecoder/interface/constraints/set_enum/operation.rb', line 32 def disjoint_union set_operation(:disjoint_union) end |
#intersection ⇒ Object
Produces a SetOperand representing the intersection of all sets in this enumeration.
Examples
# The intersection of all sets in +set_enum+.
set_enum.intersection
21 22 23 |
# File 'lib/gecoder/interface/constraints/set_enum/operation.rb', line 21 def intersection set_operation(:intersection) end |
#union ⇒ Object
Produces a SetOperand representing the union of all sets in this enumeration.
Examples
# The union of all sets in +set_enum+.
set_enum.union
10 11 12 |
# File 'lib/gecoder/interface/constraints/set_enum/operation.rb', line 10 def union set_operation(:union) end |