Class: Gecode::FreeSetVar
- Inherits:
-
Object
- Object
- Gecode::FreeSetVar
- 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
-
#cardinality ⇒ Object
Returns a range containing the allowed values for the set’s cardinality.
-
#elements ⇒ Object
Starts a constraint on all the elements of the set.
-
#lower_bound ⇒ Object
Gets all the elements located in the greatest lower bound of the set (an Enumerable).
-
#size ⇒ Object
Starts a constraint on the size of the set.
-
#upper_bound ⇒ Object
Gets all the elements located in the least upper bound of the set (an Enumerable).
-
#value ⇒ Object
Gets the values in the assigned set variable (an enumerable).
Methods included from Constraints::LeftHandSideMethods
Instance Method Details
#cardinality ⇒ Object
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 |
#elements ⇒ Object
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_bound ⇒ Object
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 |
#size ⇒ Object
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_bound ⇒ Object
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 |
#value ⇒ Object
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 |