Class: Gecode::SetVar

Inherits:
Object
  • Object
show all
Includes:
Gecode::Set::SetOperand
Defined in:
lib/gecoder/interface/variables.rb

Overview

Describes a set variable.

A set variable’s domain, i.e. possible values that it can take, are represented with a greatest lower bound (GLB) and a least upper bound (LUB). The set variable may then take any set value S such that S is a subset of the least upper bound and the greatest lower bound is a subset of S.

If for instance the set has a greatest lower bound 1 and least upper bound 1,3,5 then the assigned set may be any of the following four sets: 1, 1,3, 1,5, 1,3,5.

The domain of a set variable may also specify the cardinality of the set, i.e. the number of elements that the set may contains.

Set variables are set operands and hence respond to everything that Gecode::Set::SetOperand responds to. Any constraint found in Gecode::Set::SetConstraintReceiver can thereby be placed on set variables.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gecode::Set::SetOperand

#disjoint_union, #elements, #intersection, #method_missing, #minus, #size, #union

Methods included from Operand

#must, #must_not

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Gecode::Set::SetOperand

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



205
206
207
# File 'lib/gecoder/interface/variables.rb', line 205

def model
  @model
end

Instance Method Details

#cardinalityObject

Returns a range containing the allowed values for the set’s cardinality.



241
242
243
# File 'lib/gecoder/interface/variables.rb', line 241

def cardinality
  send_bound(:cardMin)..send_bound(:cardMax)
end

#lower_boundObject

Gets all the elements located in the greatest lower bound of the set (an Enumerable).



216
217
218
219
220
221
222
# File 'lib/gecoder/interface/variables.rb', line 216

def lower_bound
  min = send_bound(:glbMin)
  max = send_bound(:glbMax)
  EnumerableView.new(min, max, send_bound(:glbSize)) do
    (min..max).to_a.delete_if{ |e| not send_bound(:contains, e) }
  end
end

#to_set_varObject

Returns the receiver.



246
247
248
# File 'lib/gecoder/interface/variables.rb', line 246

def to_set_var
  self
end

#upper_boundObject

Gets all the elements located in the least upper bound of the set (an Enumerable).



226
227
228
229
230
231
232
# File 'lib/gecoder/interface/variables.rb', line 226

def upper_bound
  min = send_bound(:lubMin)
  max = send_bound(:lubMax)
  EnumerableView.new(min, max, send_bound(:lubSize)) do
    (min..max).to_a.delete_if{ |e| send_bound(:notContains, e) }
  end
end

#valueObject

Gets the values in the assigned set variable (an enumerable).



235
236
237
238
# File 'lib/gecoder/interface/variables.rb', line 235

def value
  raise 'No value is assigned.' unless assigned?
  lower_bound
end