Class: Quicopt::Partition
- Inherits:
-
Object
- Object
- Quicopt::Partition
- Defined in:
- lib/quicopt/structured.rb
Overview
A partition declared by Model#partition: n_items items in n_parts
parts, both numbered from 0. Read it with part_of and size_of.
teams = m.partition("teams", 6, 2)
teams.part_of(4) # the team person 4 joins
teams.size_of(0) # how many people team 0 has
Instance Attribute Summary collapse
-
#model ⇒ Model
readonly
The model that declared this partition.
-
#n_items ⇒ Integer
readonly
The number of items.
-
#n_parts ⇒ Integer
readonly
The number of parts.
-
#name ⇒ String
readonly
The partition's name; its assignment comes back keyed by it.
-
#start ⇒ Array<Integer>?
readonly
The part each item starts in, or
nilfor the default (itemiin parti % n_parts).
Instance Method Summary collapse
-
#initialize(model, name, n_items, n_parts, start) ⇒ Partition
constructor
private
Declared with
Model#partition, not built directly. -
#inspect ⇒ String
Name, number of items and number of parts.
-
#part_of(item) ⇒ Expression
The part item
itemis in, an expression whose value the service chooses. -
#size_of(part) ⇒ Expression
The number of items in part
part, an expression whose value the service chooses: a count from 0 ton_items.
Constructor Details
#initialize(model, name, n_items, n_parts, start) ⇒ Partition
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Declared with Model#partition, not built directly.
194 195 196 197 198 199 200 201 |
# File 'lib/quicopt/structured.rb', line 194 def initialize(model, name, n_items, n_parts, start) @model = model @name = name @n_items = n_items @n_parts = n_parts @start = start&.freeze @reads = {} end |
Instance Attribute Details
#model ⇒ Model (readonly)
Returns the model that declared this partition.
180 181 182 |
# File 'lib/quicopt/structured.rb', line 180 def model @model end |
#n_items ⇒ Integer (readonly)
Returns the number of items.
184 185 186 |
# File 'lib/quicopt/structured.rb', line 184 def n_items @n_items end |
#n_parts ⇒ Integer (readonly)
Returns the number of parts.
186 187 188 |
# File 'lib/quicopt/structured.rb', line 186 def n_parts @n_parts end |
#name ⇒ String (readonly)
Returns the partition's name; its assignment comes back keyed by it.
182 183 184 |
# File 'lib/quicopt/structured.rb', line 182 def name @name end |
#start ⇒ Array<Integer>? (readonly)
Returns the part each item starts in, or nil for the
default (item i in part i % n_parts).
189 190 191 |
# File 'lib/quicopt/structured.rb', line 189 def start @start end |
Instance Method Details
#inspect ⇒ String
Returns name, number of items and number of parts.
224 225 226 |
# File 'lib/quicopt/structured.rb', line 224 def inspect "#<Quicopt::Partition #{@name} (#{@n_items} items in #{@n_parts} parts)>" end |
#part_of(item) ⇒ Expression
The part item item is in, an expression whose value the service
chooses. Index a LookupTable with it to read data about that part.
209 210 211 |
# File 'lib/quicopt/structured.rb', line 209 def part_of(item) read(:part_of, Positions.check(item, @n_items, "item", owner)) end |
#size_of(part) ⇒ Expression
The number of items in part part, an expression whose value the service
chooses: a count from 0 to n_items.
219 220 221 |
# File 'lib/quicopt/structured.rb', line 219 def size_of(part) read(:size_of, Positions.check(part, @n_parts, "part", owner)) end |