Class: Gecode::FreeSetVar

Inherits:
Object
  • Object
show all
Includes:
Constraints::LeftHandSideMethods
Defined in:
lib/gecoder/interface/variables.rb,
lib/gecoder/interface/constraints/set/relation.rb,
lib/gecoder/interface/constraints/set/operation.rb,
lib/gecoder/interface/constraints/set/cardinality.rb,
lib/gecoder/interface/constraints/set_var_constraints.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.

Instance Method Summary collapse

Methods included from Constraints::LeftHandSideMethods

#must, #must_not

Instance Method Details

#cardinalityObject

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



184
185
186
# File 'lib/gecoder/interface/variables.rb', line 184

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

#elementsObject

Starts a constraint on all the elements of the set.



4
5
6
7
8
9
# File 'lib/gecoder/interface/constraints/set/relation.rb', line 4

def elements
  params = {:lhs => self}
  Gecode::Constraints::SimpleExpressionStub.new(@model, params) do |m, ps|
    Gecode::Constraints::Set::Relation::ElementExpression.new(m, ps)
  end
end

#lower_boundObject

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



159
160
161
162
163
164
165
# File 'lib/gecoder/interface/variables.rb', line 159

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

#sizeObject

Starts a constraint on the size of the set.



4
5
6
7
8
# File 'lib/gecoder/interface/constraints/set/cardinality.rb', line 4

def size
  params = {:lhs => self}
  Gecode::Constraints::Set::Cardinality::SizeExpressionStub.new(
    @model, params)
end

#upper_boundObject

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



169
170
171
172
173
174
175
# File 'lib/gecoder/interface/variables.rb', line 169

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).



178
179
180
181
# File 'lib/gecoder/interface/variables.rb', line 178

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