Module: Gecode::IntEnumMethods
- Includes:
- Constraints::IntEnum::Element::AdditionalEnumMethods, Constraints::LeftHandSideMethods, VariableEnumMethods
- Defined in:
- lib/gecoder/interface/enum_wrapper.rb,
lib/gecoder/interface/constraints/int_enum/count.rb,
lib/gecoder/interface/constraints/int_enum/element.rb,
lib/gecoder/interface/constraints/int_enum/distinct.rb,
lib/gecoder/interface/constraints/int_enum/arithmetic.rb,
lib/gecoder/interface/constraints/int_enum_constraints.rb
Overview
A module containing the methods needed by enumerations containing int variables. Requires that it’s included in an enumerable.
Instance Attribute Summary
Attributes included from EnumMethods
Instance Method Summary collapse
-
#count(element) ⇒ Object
Specifies that a specific element should be counted, starting a count constraint.
-
#domain_range ⇒ Object
Returns the smallest range that contains the domains of all integer variables involved.
-
#max ⇒ Object
Starts an arithmetic max constraint.
-
#min ⇒ Object
Starts an arithmetic min constraint.
-
#to_int_var_array ⇒ Object
(also: #to_var_array)
Returns an int variable array with all the bound variables.
-
#with_offsets(*offsets) ⇒ Object
Specifies offsets to be used with a distinct constraint.
Methods included from Constraints::LeftHandSideMethods
Methods included from Constraints::IntEnum::Element::AdditionalEnumMethods
Methods included from VariableEnumMethods
Methods included from EnumMethods
Instance Method Details
#count(element) ⇒ Object
Specifies that a specific element should be counted, starting a count constraint. The element can be either an int var or a fixnum.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/gecoder/interface/constraints/int_enum/count.rb', line 5 def count(element) unless element.kind_of?(FreeIntVar) or element.kind_of?(Fixnum) raise TypeError, 'Elements used with count can not be of type ' + "#{element.class}." end params = {:lhs => self, :element => element} Gecode::Constraints::SimpleExpressionStub.new(@model, params) do |m, ps| Gecode::Constraints::IntEnum::Count::Expression.new(m, ps) end end |
#domain_range ⇒ Object
Returns the smallest range that contains the domains of all integer variables involved.
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/gecoder/interface/enum_wrapper.rb', line 80 def domain_range inject(nil) do |range, var| min = var.min max = var.max next min..max if range.nil? range = min..range.last if min < range.first range = range.first..max if max > range.last range end end |
#max ⇒ Object
Starts an arithmetic max constraint. This overrides the normal enum max, but that’s not a problem since variables are not implemented to be comparable.
4 5 6 7 |
# File 'lib/gecoder/interface/constraints/int_enum/arithmetic.rb', line 4 def max return Gecode::Constraints::IntEnum::Arithmetic::MaxExpressionStub.new( @model, :lhs => self) end |
#min ⇒ Object
Starts an arithmetic min constraint. This overrides the normal enum min, but that’s not a problem since variables are not implemented to be comparable.
11 12 13 14 |
# File 'lib/gecoder/interface/constraints/int_enum/arithmetic.rb', line 11 def min return Gecode::Constraints::IntEnum::Arithmetic::MinExpressionStub.new( @model, :lhs => self) end |
#to_int_var_array ⇒ Object Also known as: to_var_array
Returns an int variable array with all the bound variables.
66 67 68 69 70 71 72 73 74 75 |
# File 'lib/gecoder/interface/enum_wrapper.rb', line 66 def to_int_var_array space = @model.active_space unless @bound_space == space elements = to_a @bound_arr = Gecode::Raw::IntVarArray.new(active_space, elements.size) elements.each_with_index{ |var, index| @bound_arr[index] = var.bind } @bound_space = space end return @bound_arr end |
#with_offsets(*offsets) ⇒ Object
Specifies offsets to be used with a distinct constraint. The offsets can be specified one by one or as an array of offsets.
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/gecoder/interface/constraints/int_enum/distinct.rb', line 5 def with_offsets(*offsets) if offsets.kind_of? Enumerable offsets = *offsets end params = {:lhs => self, :offsets => offsets} Gecode::Constraints::SimpleExpressionStub.new(@model, params) do |m, ps| Gecode::Constraints::IntEnum::Expression.new(m, ps) end end |