module Gecode::IntEnum::IntEnumOperand
A IntEnumOperand is a enumeration of IntOperand on which the constraints defined in IntEnumConstraintReceiver can be placed.
Enumerations of integer operands can be created either by using Gecode::Mixin#int_var_array and Gecode::Mixin#int_var_matrix, or by wrapping an existing enumeration containing IntOperand using Gecode::Mixin#wrap_enum. The enumerations, no matter how they were created, all respond to the properties defined by IntEnumOperand.
Examples ¶ ↑
Produces an array of five int operands with domain 0..9 inside a problem formulation using Gecode::Mixin#int_var_array:
int_enum = int_var_array(5, 0..9)
Uses Gecode::Mixin#wrap_enum
inside a problem formulation to create a IntEnumOperand from an existing enumeration
containing the integer operands int_operand1
and
int_operand2
:
int_enum = wrap_enum([int_operand1, int_operand2])
Public Instance Methods
Produces a new IntOperand representing the number of times
int_operand_or_fixnum
is present in this enumeration.
Examples ¶ ↑
# The number of times 17 occurs in +int_enum+. int_enum.count(17) # The number of times +int_operand+ occurs in +int_enum+. int_enum.count(int_operand)
# File lib/gecoder/interface/constraints/int_enum/count.rb, line 13 def count(int_operand_or_fixnum) unless int_operand_or_fixnum.respond_to? :to_int_var or int_operand_or_fixnum.kind_of?(Fixnum) raise TypeError, 'Expected integer operand of fixnum, got ' + "#{int_operand_or_fixnum.class}." end Count::IntEnumCountOperand.new(@model, self, int_operand_or_fixnum) end
Public Class Methods
Produces an IntOperand representing the i:th integer operand 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 operand at the +x+:th position in +int_enum+, # where +x+ is an integer operand. int_enum[x]
# File lib/gecoder/interface/constraints/int_enum/element.rb, line 28 def [](*vars) if vars.first.respond_to? :to_int_var return Element::ElementIntOperand.new( model, self, vars.first) else pre_element_access(*vars) if respond_to? :pre_element_access end end