module Gecode::FixnumEnum::FixnumEnumOperand
A FixnumEnumOperand is a enumeration of Fixnum on which the constraints defined in FixnumEnumConstraintReceiver can be placed. They typically service as constant arrays or constant sets.
The fixnum enumeration operands are created by wrapping an enumeration of fixnum Gecode::Mixin#wrap_enum. The enumerations created that way all respond to the properties defined by FixnumEnumOperand.
Examples ¶ ↑
Uses Gecode::Mixin#wrap_enum inside a problem formulation to create a FixnumEnumOperand from an existing enumeration of Fixnum:
fixnum_enum = wrap_enum([3, 5, 7])
Public Instance Methods
Produces a new SetOperand representing the disjoint union between this
operand, interpreted as a constant set, and set_operand
. The
disjoint union is the union of the disjoint parts of the sets.
Examples ¶ ↑
# The disjoint union between +fixnum_enum+ and +set+. fixnum_enum.disjoint_union set
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/fixnum_enum/operation.rb, line 23 def disjoint_union(set_operand) set_operation(:disjoint_union, set_operand) end
Produces a new SetOperand representing the intersection between this
operand, interpreted as a constant set, and set_operand
.
Examples ¶ ↑
# The intersection between +fixnum_enum+ and +set+. fixnum_enum.intersection set
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/fixnum_enum/operation.rb, line 35 def intersection(set_operand) set_operation(:intersection, set_operand) end
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/fixnum_enum_constraints.rb, line 24 def method_missing(method, *args) if Gecode::FixnumEnum::Dummy.instance_methods.include? method.to_s # Delegate to the fixnum enum. to_fixnum_enum.method(method).call(*args) else super end end
Produces a new SetOperand representing this operand, interpreted as a
constant set, minus set_operand
.
Examples ¶ ↑
# +fixnum_enum+ minus +set+. fixnum_enum.minus set
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/fixnum_enum/operation.rb, line 46 def minus(set_operand) set_operation(:minus, set_operand) end
Produces a new SetOperand representing the union between this operand,
interpreted as a constant set, and set_operand
.
Examples ¶ ↑
# The union between +fixnum_enum+ and +set+. fixnum_enum.union set
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/fixnum_enum/operation.rb, line 10 def union(set_operand) set_operation(:union, set_operand) end
Public Class Methods
Produces an IntOperand representing the i:th constant integer in the enumeration, where i is the value of the integer operand used as index. Think of it as array access in the world of constraint programming.
Examples ¶ ↑
# The price of +selected_item+ as described by +prices+ . prices = wrap_enum([500, 24, 4711, 412, 24]) prices[selected_item]
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/fixnum_enum/element.rb, line 28 def [](*vars) if vars.first.respond_to? :to_int_var return Element::ElementIntOperand.new( self, vars.first, model) else pre_element_access(*vars) if respond_to? :pre_element_access end end
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/fixnum_enum/element.rb, line 6 def self.included(enum_mod) enum_mod.module_eval do # Now we enter the module FixnumEnumOperands is mixed into. class << self alias_method :pre_element_included, :included def included(mod) mod.module_eval do if instance_methods.include? '[]' alias_method :pre_element_access, :[] end # Produces an IntOperand representing the # i:th constant integer in the enumeration, where i is the # value of the integer operand used as index. Think of it # as array access in the world of constraint programming. # # ==== Examples # # # The price of +selected_item+ as described by +prices+ . # prices = wrap_enum([500, 24, 4711, 412, 24]) # prices[selected_item] # def [](*vars) if vars.first.respond_to? :to_int_var return Element::ElementIntOperand.new( self, vars.first, model) else pre_element_access(*vars) if respond_to? :pre_element_access end end end pre_element_included(mod) end end end end