module Gecode::SetEnum::SetEnumOperand

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 {0, 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])

Public Instance Methods

disjoint_union() click to toggle source

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
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/set_enum/operation.rb, line 32
def disjoint_union
  set_operation(:disjoint_union)
end
intersection() click to toggle source

Produces a SetOperand representing the intersection of all sets in this enumeration.

Examples

# The intersection of all sets in +set_enum+.
set_enum.intersection
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/set_enum/operation.rb, line 21
def intersection
  set_operation(:intersection)
end
method_missing(method, *args) click to toggle source
Calls superclass method
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/set_enum_constraints.rb, line 33
def method_missing(method, *args) 
  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
union() click to toggle source

Produces a SetOperand representing the union of all sets in this enumeration.

Examples

# The union of all sets in +set_enum+.
set_enum.union
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/set_enum/operation.rb, line 10
def union
  set_operation(:union)
end

Public Class Methods

[](*vars) click to toggle source

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]
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/set_enum/element.rb, line 37
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
included(mod) click to toggle source

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.

# File doc/tmp/rdoc_dev/gecoder/interface/constraints/set_enum/element.rb, line 6
def self.included(mod) 
  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) 
        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
Also aliased as: pre_set_element_included
pre_set_element_included(mod)
Alias for: included