Module: Gecode::SetEnumMethods

Includes:
Gecode::SetEnum::SetEnumOperand, VariableEnumMethods
Defined in:
lib/gecoder/interface/enum_wrapper.rb

Overview

A module containing the methods needed by enumerations containing set operands. Requires that it’s included in an enumerable.

Instance Attribute Summary

Attributes included from EnumMethods

#model

Instance Method Summary collapse

Methods included from VariableEnumMethods

#values

Methods included from EnumMethods

#active_space

Methods included from Gecode::SetEnum::SetEnumOperand

#disjoint_union, included, #intersection, #method_missing, #union

Methods included from Operand

#model, #must, #must_not

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Gecode::SetEnum::SetEnumOperand

Instance Method Details

#bind_arrayObject

Returns a set variable array with all the bound variables.



145
146
147
148
149
150
151
152
153
154
# File 'lib/gecoder/interface/enum_wrapper.rb', line 145

def bind_array
  space = @model.active_space
  unless @bound_space == space
    elements = to_a
    @bound_arr = Gecode::Raw::SetVarArray.new(active_space, elements.size)
    elements.each_with_index{ |var, index| @bound_arr[index] = var.bind }
    @bound_space = space
  end
  return @bound_arr
end

#to_set_enumObject

Returns the receiver.



157
158
159
# File 'lib/gecoder/interface/enum_wrapper.rb', line 157

def to_set_enum
  self
end

#upper_bound_rangeObject

Returns the range of the union of the contained sets’ upper bounds.



162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/gecoder/interface/enum_wrapper.rb', line 162

def upper_bound_range
  inject(nil) do |range, var|
    upper_bound = var.upper_bound
    min = upper_bound.min
    max = upper_bound.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