| Class | TaskJuggler::Allocation |
| In: |
lib/taskjuggler/Allocation.rb
|
| Parent: | Object |
The Allocation is key object in TaskJuggler. It contains a description how Resources are assigned to a Task. Each allocation holds a non-empty list of candidate resources. For each time slot one candidate will be assigned if any are available. A selectionMode controls the order in which the resources are checked for availability. The first available one is selected.
| lockedResource | [RW] | |
| mandatory | [RW] | |
| persistent | [RW] | |
| selectionMode | [R] | |
| shifts | [RW] |
Create an Allocation object. The candidates list must at least contain one Resource reference.
# File lib/taskjuggler/Allocation.rb, line 31 def initialize(candidates, selectionMode = 1, persistent = false, mandatory = false) @candidates = candidates # The selection mode determines how the candidate is selected from the # list of candidates. # 0 : 'order' : select by order of list # 1 : 'minallocated' : select candidate with lowest allocation # probability # 2 : 'minloaded' : select candidate with lowest allocated overall # load # 3 : 'maxloaded' : select candidate with highest allocated overall # load # 4 : 'random' : select a random candidate @selectionMode = selectionMode @persistent = persistent @mandatory = mandatory @shifts = nil end
Append another candidate to the candidates list.
# File lib/taskjuggler/Allocation.rb, line 59 def addCandidate(candidate) @candidates << candidate end
Return the candidate list sorted according to the selectionMode.
# File lib/taskjuggler/Allocation.rb, line 72 def candidates(scenarioIdx = nil) if scenarioIdx.nil? || @selectionMode == 0 # declaration order return @candidates end if @selectionMode == 4 # random # For a random sorting we put the candidates in a hash with a random # number as key. Then we sort the hash according to the random keys an # use the resuling sequence of the values. hash = {} @candidates.each { |c| hash[rand] = c } twinList = hash.sort { |x, y| x[0] <=> y[0] } list = [] twinList.each { |k, v| list << v } return list end list = @candidates.sort do |x, y| case @selectionMode when 1 # lowest alloc probability x['criticalness', scenarioIdx] <=> y['criticalness', scenarioIdx] when 2 # lowest allocated load x['effort', scenarioIdx] <=> y['effort', scenarioIdx] when 3 # hightes allocated load y['effort', scenarioIdx] <=> x['effort', scenarioIdx] else raise "Unknown selection mode #{@selectionMode}" end end list end
Returns true if we either have no shifts defined or the defined shifts are active at date specified by global scoreboard index sbIdx.
# File lib/taskjuggler/Allocation.rb, line 65 def onShift?(sbIdx) return @shifts.onShift?(sbIdx) if @shifts true end
Set the selection mode identified by name specified in str. For efficiency reasons, we turn the name into a Fixnum value.
# File lib/taskjuggler/Allocation.rb, line 52 def setSelectionMode(str) modes = %w( order minallocated minloaded maxloaded random ) @selectionMode = modes.index(str) raise "Unknown selection mode #{str}" if @selectionMode.nil? end