class Gecode::SetVar

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.

Attributes

model[R]

Public Instance Methods

cardinality() click to toggle source

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

# File doc/tmp/rdoc_dev/gecoder/interface/variables.rb, line 241
def cardinality
  send_bound(:cardMin)..send_bound(:cardMax)
end
lower_bound() click to toggle source

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

# File doc/tmp/rdoc_dev/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_var() click to toggle source

Returns the receiver.

# File doc/tmp/rdoc_dev/gecoder/interface/variables.rb, line 246
def to_set_var
  self
end
upper_bound() click to toggle source

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

# File doc/tmp/rdoc_dev/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
value() click to toggle source

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

# File doc/tmp/rdoc_dev/gecoder/interface/variables.rb, line 235
def value
  raise 'No value is assigned.' unless assigned?
  lower_bound
end