Class: TaskJuggler::TaskScenario
- Inherits:
-
ScenarioData
- Object
- ScenarioData
- TaskJuggler::TaskScenario
- Defined in:
- lib/taskjuggler/TaskScenario.rb
Instance Attribute Summary collapse
-
#hasDurationSpec ⇒ Object
readonly
Returns the value of attribute hasDurationSpec.
-
#isRunAway ⇒ Object
readonly
Returns the value of attribute isRunAway.
Attributes inherited from ScenarioData
Instance Method Summary collapse
- #addBooking(booking) ⇒ Object
-
#assignedResources(interval = nil) ⇒ Object
Gather a list of Resource objects that have been assigned to the task (including sub tasks) for the given Interval interval.
-
#calcCriticalness ⇒ Object
Determine the criticalness of the individual task.
-
#calcPathCriticalness(atEnd = false) ⇒ Object
The path criticalness is a measure for the overall criticalness of the task taking the dependencies into account.
-
#candidates ⇒ Object
This function must be called before prepareScheduling().
-
#canInheritDate?(atEnd) ⇒ Boolean
This function determines if a task can inherit the start or end date from a parent task or the project time frame.
-
#checkForLoops(path, atEnd, fromOutside, forward) ⇒ Object
To ensure that we can properly schedule the project, we need to make sure that it does not contain any circular dependencies.
-
#collectTimeOffIntervals(iv, minDuration) ⇒ Object
Return a list of intervals that lay within iv and are at least minDuration long and contain no working time.
-
#countResourceAllocations ⇒ Object
This function does some prep work for other functions like calcCriticalness.
-
#earliestStart ⇒ Object
Find the earliest possible start date for the task.
-
#finishScheduling ⇒ Object
When the actual scheduling process has been completed, this function must be called to do some more housekeeping.
-
#getAllocatedTime(startIdx, endIdx, resource = nil) ⇒ Object
Compute the total time resource or all resources are allocated during interval specified by startIdx and endIdx.
-
#getEffectiveWork(startIdx, endIdx, resource = nil) ⇒ Object
Compute the effective work a resource or all resources do during the interval specified by startIdx and endIdx.
-
#hasDependency?(depType, target, onEnd) ⇒ Boolean
Return true of this Task has a dependency [ target, onEnd ] in the dependency category depType.
-
#hasResourceAllocated?(interval, resource) ⇒ Boolean
Returns true of the resource is assigned to this task or any of its children.
-
#initialize(task, scenarioIdx, attributes) ⇒ TaskScenario
constructor
Create a new TaskScenario object.
-
#isDependencyOf(task, depth, list = []) ⇒ Object
Check if the Task task depends on this task.
-
#isFeatureOf(task) ⇒ Object
If task or any of its sub-tasks depend on this task or any of its sub-tasks, we call this task a feature of task.
-
#latestEnd ⇒ Object
Find the latest possible end date for the task.
- #markAsScheduled ⇒ Object
-
#postScheduleCheck ⇒ Object
This function is not essential but does perform a large number of consistency checks.
-
#prepareScheduling ⇒ Object
Call this function to reset all scheduling related data prior to scheduling.
-
#preScheduleCheck ⇒ Object
Before the actual scheduling work can be started, we need to do a few consistency checks on the task.
-
#propagateDate(date, atEnd, ignoreEffort = false) ⇒ Object
Set a new start or end date and propagate the value to all other task ends that have a direct dependency to this end of the task.
- #propagateInitialValues ⇒ Object
- #query_activetasks(query) ⇒ Object
- #query_closedtasks(query) ⇒ Object
- #query_competitorcount(query) ⇒ Object
- #query_complete(query) ⇒ Object
-
#query_cost(query) ⇒ Object
Compute the cost generated by this Task for a given Account during a given interval.
-
#query_duration(query) ⇒ Object
The duration of the task.
-
#query_effort(query) ⇒ Object
The effort allocated for the task in the specified interval.
-
#query_effortdone(query) ⇒ Object
The completed (as of ‘now’) effort allocated for the task in the specified interval.
-
#query_effortleft(query) ⇒ Object
The remaining (as of ‘now’) effort allocated for the task in the specified interval.
- #query_followers(query) ⇒ Object
- #query_gauge(query) ⇒ Object
-
#query_headcount(query) ⇒ Object
The number of different resources assigned to the task during the query interval.
- #query_inputs(query) ⇒ Object
- #query_maxend(query) ⇒ Object
- #query_maxstart(query) ⇒ Object
- #query_minend(query) ⇒ Object
- #query_minstart(query) ⇒ Object
- #query_opentasks(query) ⇒ Object
- #query_precursors(query) ⇒ Object
-
#query_resources(query) ⇒ Object
A list of the resources that have been allocated to work on the task in the report time frame.
-
#query_revenue(query) ⇒ Object
Compute the revenue generated by this Task for a given Account during a given interval.
- #query_scheduling(query) ⇒ Object
- #query_status(query) ⇒ Object
- #query_targets(query) ⇒ Object
-
#readyForScheduling? ⇒ Boolean
Check if the task is ready to be scheduled.
- #resetLoopFlags ⇒ Object
-
#schedule ⇒ Object
This function is the entry point for the core scheduling algorithm.
-
#scheduleContainer ⇒ Object
Find the smallest possible interval that encloses all child tasks.
-
#Xref ⇒ Object
The parser only stores the full task IDs for each of the dependencies.
Methods inherited from ScenarioData
#a, #deep_clone, #error, #info, #warning
Constructor Details
#initialize(task, scenarioIdx, attributes) ⇒ TaskScenario
Create a new TaskScenario object.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/taskjuggler/TaskScenario.rb', line 24 def initialize(task, scenarioIdx, attributes) super # Attributed are only really created when they are accessed the first # time. So make sure some needed attributes really exist so we don't # have to check for existance each time we access them. %w( allocate assignedresources booking charge chargeset complete competitors criticalness depends duration effort effortdone effortleft end forward gauge length maxend maxstart minend minstart milestone pathcriticalness precedes priority projectionmode responsible scheduled shifts start status ).each do |attr| @property[attr, @scenarioIdx] end unless @property.parent # The projectionmode attributes is a scenario specific attribute that # can be inherited from the project. The normal inherit-from-project # mechanism does not support scenario specific inheritance. We have to # deal with this separately here. To make it look like a regularly # inherted value, we need to switch the AttributeBase mode and restore # it afterwards. mode = AttributeBase.mode AttributeBase.setMode(1) @property['projectionmode', @scenarioIdx] = @project.scenario(@scenarioIdx).get('projection') AttributeBase.setMode(mode) end # A list of all allocated leaf resources. @candidates = [] @dCache = DataCache.instance end |
Instance Attribute Details
#hasDurationSpec ⇒ Object (readonly)
Returns the value of attribute hasDurationSpec.
21 22 23 |
# File 'lib/taskjuggler/TaskScenario.rb', line 21 def hasDurationSpec @hasDurationSpec end |
#isRunAway ⇒ Object (readonly)
Returns the value of attribute isRunAway.
21 22 23 |
# File 'lib/taskjuggler/TaskScenario.rb', line 21 def isRunAway @isRunAway end |
Instance Method Details
#addBooking(booking) ⇒ Object
1283 1284 1285 1286 1287 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1283 def addBooking(booking) # This append operation will not trigger a copy to sub-scenarios. # Bookings are only valid for the scenario they are defined in. @booking << booking end |
#assignedResources(interval = nil) ⇒ Object
Gather a list of Resource objects that have been assigned to the task (including sub tasks) for the given Interval interval.
1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1729 def assignedResources(interval = nil) interval = Interval.new(a('start'), a('end')) unless interval list = [] if @property.container? @property.kids.each do |task| list += task.assignedResources(@scenarioIdx, interval) end list.uniq! else @assignedresources.each do |resource| if resource.allocated?(@scenarioIdx, interval, @property) list << resource end end end list end |
#calcCriticalness ⇒ Object
Determine the criticalness of the individual task. This is a measure for the likelyhood that this task will get the resources that it needs to complete the effort. Tasks without effort are not cricital. The only exception are milestones which get an arbitrary value between 0 and 2 based on their priority.
824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 |
# File 'lib/taskjuggler/TaskScenario.rb', line 824 def calcCriticalness @criticalness = 0.0 @pathcriticalness = nil # Users feel that milestones are somewhat important. So we use an # arbitrary value larger than 0 for them. We make it priority dependent, # so the user has some control over it. Priority 0 is 0, 500 is 1.0 and # 1000 is 2.0. These values are pretty much randomly picked and probably # require some more tuning based on real projects. if @milestone @criticalness = @priority / 500.0 end # Task without efforts of allocations are not critical. return if @effort <= 0 || @candidates.empty? # Determine the average criticalness of all allocated resources. criticalness = 0.0 @candidates.each do |resource| criticalness += resource['criticalness', @scenarioIdx] end criticalness /= @candidates.length # The task criticalness is the product of effort and average resource # criticalness. @criticalness = @effort * criticalness end |
#calcPathCriticalness(atEnd = false) ⇒ Object
The path criticalness is a measure for the overall criticalness of the task taking the dependencies into account. The fact that a task is part of a chain of effort-based task raises all the task in the chain to a higher criticalness level than the individual tasks. In fact, the path criticalness of this chain is equal to the sum of the individual criticalnesses of the tasks.
858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 |
# File 'lib/taskjuggler/TaskScenario.rb', line 858 def calcPathCriticalness(atEnd = false) # If we have computed this already, just return the value. If we are only # at the end of the task, we do not include the criticalness of this task # as it is not really part of the path. if @pathcriticalness return @pathcriticalness - (atEnd ? 0 : @criticalness) end maxCriticalness = 0.0 if atEnd # At the end, we only care about pathes through the successors of this # task or its parent tasks. if (criticalness = calcPathCriticalnessEndSuccs) > maxCriticalness maxCriticalness = criticalness end else # At the start of the task, we have two options. if @property.container? # For container tasks, we ignore all dependencies and check the pathes # through all the children. @property.children.each do |task| if (criticalness = task.calcPathCriticalness(@scenarioIdx, false)) > maxCriticalness maxCriticalness = criticalness end end else # For leaf tasks, we check all pathes through the start successors and # then the pathes through the end successors of this task and all its # parent tasks. @startsuccs.each do |task, onEnd| if (criticalness = task.calcPathCriticalness(@scenarioIdx, onEnd)) > maxCriticalness maxCriticalness = criticalness end end if (criticalness = calcPathCriticalnessEndSuccs) > maxCriticalness maxCriticalness = criticalness end maxCriticalness += @criticalness end end @pathcriticalness = maxCriticalness end |
#candidates ⇒ Object
This function must be called before prepareScheduling(). It compiles the list of leaf resources that are allocated to this task.
794 795 796 797 798 799 800 801 802 803 804 |
# File 'lib/taskjuggler/TaskScenario.rb', line 794 def candidates @candidates = [] @allocate.each do |allocation| allocation.candidates.each do |candidate| candidate.allLeaves.each do |resource| @candidates << resource unless @candidates.include?(resource) end end end @candidates end |
#canInheritDate?(atEnd) ⇒ Boolean
This function determines if a task can inherit the start or end date from a parent task or the project time frame. atEnd
specifies whether the check should be done for the task end (true) or task start (false).
1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1079 def canInheritDate?(atEnd) # Inheriting a start or end date from the enclosing task or the project # is allowed for the following scenarios: # - --> - inhS*1 - <-- - inhE*1 # - --> | inhS | <-- - inhE # - x-> - inhS - <-x - inhE # - x-> | inhS | <-x - inhE # - x-> -D inhS -D <-x - inhE # - x-> |D inhS |D <-x - inhE # - --> -D inhS -D <-- - inhE # - --> |D inhS |D <-- - inhE # - <-- | inhS | --> - inhE # # *1 when no bookings but allocations are present thisEnd, thatEnd = atEnd ? [ 'end', 'start' ] : [ 'start', 'end' ] # Return false if we already have a date for this end or if we have a # strong dependency for this end. return false if instance_variable_get('@' + thisEnd) || hasStrongDeps?(atEnd) # Containter task can inherit the date if they have no dependencies at # this end. return true if @property.container? hasThatSpec = !instance_variable_get('@' + thatEnd).nil? || hasStrongDeps?(!atEnd) # Check for tasks that have no start and end spec, no duration spec but # allocates. They can inherit the start and end date. return true if hasThatSpec && !@hasDurationSpec && !@allocate.empty? if @forward ^ atEnd # the scheduling direction is pointing away from this end return true if @hasDurationSpec || !@booking.empty? return hasThatSpec else # the scheduling direction is pointing towards this end return !instance_variable_get('@' + thatEnd).nil? && !@hasDurationSpec && @booking.empty? #&& @allocate.empty? end end |
#checkForLoops(path, atEnd, fromOutside, forward) ⇒ Object
To ensure that we can properly schedule the project, we need to make sure that it does not contain any circular dependencies. This method recursively checks for such loops by remembering the path. Each entry is marks the start or end of a task. atEnd specifies whether we are currently at the start or end of the task. fromOutside specifies whether we are coming from a inside or outside that tasks. See specification below. forward specifies whether we are checking the dependencies from start to end or in the opposite direction. If we are moving forward, we only move from start to end of ASAP tasks, not ALAP tasks and vice versa. For milestones, we ignore the scheduling direction.
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 |
# File 'lib/taskjuggler/TaskScenario.rb', line 627 def checkForLoops(path, atEnd, fromOutside, forward) # Check if we have been here before on this path. if path.include?([ @property, atEnd ]) warning('loop_detected', "Dependency loop detected at #{atEnd ? 'end' : 'start'} " + "of task #{@property.fullId}", false) skip = true path.each do |t, e| if t == @property && e == atEnd skip = false next end next if skip info("loop_at_#{e ? 'end' : 'start'}", "Loop ctnd. at #{e ? 'end' : 'start'} of task #{t.fullId}", t.sourceFileInfo) end error('loop_end', "Aborting") end # Used for debugging only if false pathText = '' path.each do |t, e| pathText += "#{t.fullId}(#{e ? 'end' : 'start'}) -> " end pathText += "#{@property.fullId}(#{atEnd ? 'end' : 'start'})" puts pathText end return if @deadEndFlags[(atEnd ? 2 : 0) + (fromOutside ? 1 : 0)] path << [ @property, atEnd ] # To find loops we have to traverse the graph in a certain order. When we # enter a task we can either come from outside or inside. The following # graph explains these definitions: # # | / \ | # outside v / \ v outside # +------------------------------+ # | / Task \ | # -->| o <--- ---> o |<-- # |/ Start End \| # /+------------------------------+\ # / ^ ^ \ # | inside | # # At the top we have the parent task. At the botton the child tasks. # The horizontal arrors are start predecessors or end successors. # As the graph is doubly-linked, we need to becareful to only find real # loops. When coming from outside, we only continue to the inside and vice # versa. Horizontal moves are only made when we are in a leaf task. unless atEnd if fromOutside if @property.container? # # | # v # +-------- # -->| o--+ # +----|--- # | # V # @property.children.each do |child| child.checkForLoops(@scenarioIdx, path, false, true, forward) end else # | # v # +-------- # -->| o----> # +-------- # if (forward && @forward) || @milestone checkForLoops(path, true, false, true) end end else if @startpreds.empty? # # ^ # | # +-|------ # | o <-- # +-------- # ^ # | # if @property.parent @property.parent.checkForLoops(@scenarioIdx, path, false, false, forward) end else # +-------- # <---- o <-- # +-------- # ^ # | # @startpreds.each do |task, targetEnd| task.checkForLoops(@scenarioIdx, path, targetEnd, true, forward) end end end else if fromOutside if @property.container? # # | # v # --------+ # +--o |<-- # ---|----+ # | # v # @property.children.each do |child| child.checkForLoops(@scenarioIdx, path, true, true, forward) end else # | # v # --------+ # <----o |<-- # --------+ # if (!forward && !@forward) || @milestone checkForLoops(path, false, false, false) end end else if @endsuccs.empty? # # ^ # | # ------|-+ # --> o | # --------+ # ^ # | # if @property.parent @property.parent.checkForLoops(@scenarioIdx, path, true, false, forward) end else # --------+ # --> o----> # --------+ # ^ # | # @endsuccs.each do |task, targetEnd| task.checkForLoops(@scenarioIdx, path, targetEnd, true, forward) end end end end path.pop @deadEndFlags[(atEnd ? 2 : 0) + (fromOutside ? 1 : 0)] = true # puts "Finished with #{@property.fullId} #{atEnd ? 'end' : 'start'} " + # "#{fromOutside ? 'outside' : 'inside'}" end |
#collectTimeOffIntervals(iv, minDuration) ⇒ Object
Return a list of intervals that lay within iv and are at least minDuration long and contain no working time.
1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1621 def collectTimeOffIntervals(iv, minDuration) # This function is often called recursively for the same parameters. We # store the results in the cache to avoid repeated computations of the # same results. @dCache.cached(self, :TaskScenarioCollectTimeOffIntervals, iv, minDuration) do il = IntervalList.new il << TimeInterval.new(@project['start'], @project['end']) if @property.leaf? unless (resources = @assignedresources).empty? # The task has assigned resources, so we can use their common time # off intervals. resources.each do |resource| il &= resource.collectTimeOffIntervals(@scenarioIdx, iv, minDuration) end else # The task has no assigned resources. We simply use the global time # off intervals. il &= @project.collectTimeOffIntervals(iv, minDuration) end else @property.kids.each do |task| il &= task.collectTimeOffIntervals(@scenarioIdx, iv, minDuration) end end il end end |
#countResourceAllocations ⇒ Object
This function does some prep work for other functions like calcCriticalness. It compiles a list of all allocated leaf resources and stores it in @candidates. It also adds the allocated effort to the ‘alloctdeffort’ counter of each resource.
810 811 812 813 814 815 816 817 |
# File 'lib/taskjuggler/TaskScenario.rb', line 810 def countResourceAllocations return if @candidates.empty? || @effort <= 0 avgEffort = @effort / @candidates.length @candidates.each do |resource| resource['alloctdeffort', @scenarioIdx] += avgEffort end end |
#earliestStart ⇒ Object
Find the earliest possible start date for the task. This date must be after the end date of all the task that this task depends on. Dependencies may also require a minimum gap between the tasks.
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1172 def earliestStart # This is the date that we will return. startDate = nil @depends.each do |dependency| potentialStartDate = dependency.task[dependency.onEnd ? 'end' : 'start', @scenarioIdx] return nil if potentialStartDate.nil? # Determine the end date of a 'length' gap. dateAfterLengthGap = potentialStartDate gapLength = dependency.gapLength while gapLength > 0 && dateAfterLengthGap < @project['end'] do if @project.isWorkingTime(dateAfterLengthGap) gapLength -= 1 end dateAfterLengthGap += @project['scheduleGranularity'] end # Determine the end date of a 'duration' gap. if dateAfterLengthGap > potentialStartDate + dependency.gapDuration potentialStartDate = dateAfterLengthGap else potentialStartDate += dependency.gapDuration end startDate = potentialStartDate if startDate.nil? || startDate < potentialStartDate end # If any of the parent tasks has an explicit start date, the task must # start at or after this date. task = @property while (task = task.parent) do if task['start', @scenarioIdx] && (startDate.nil? || task['start', @scenarioIdx] > startDate) startDate = task['start', @scenarioIdx] break end end # When the computed start date is after the already determined end date # of the task, the start dependencies were too weak. This happens when # task B depends on A and they are specified this way: # task A: | --> D- # task B: -D <-- | if @end && (startDate.nil? || startDate > @end) error('impossible_start_dep', "Task #{@property.fullId} has start date dependencies " + "that conflict with the end date #{@end}.") end startDate end |
#finishScheduling ⇒ Object
When the actual scheduling process has been completed, this function must be called to do some more housekeeping. It computes some derived data based on the just scheduled values.
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
# File 'lib/taskjuggler/TaskScenario.rb', line 409 def finishScheduling # Recursively descend into all child tasks. @property.children.each do |task| task.finishScheduling(@scenarioIdx) end @property.parents.each do |pTask| # Add the assigned resources to the parent task's list. @assignedresources.each do |resource| unless pTask['assignedresources', @scenarioIdx].include?(resource) pTask['assignedresources', @scenarioIdx] << resource end end end # These lists are no longer needed, so let's save some memory. Set it to # nil so we can detect accidental use. @candidates = nil @mandatories = nil @allLimits = nil end |
#getAllocatedTime(startIdx, endIdx, resource = nil) ⇒ Object
Compute the total time resource or all resources are allocated during interval specified by startIdx and endIdx.
1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1560 def getAllocatedTime(startIdx, endIdx, resource = nil) return 0.0 if @milestone || startIdx >= endIdx || (resource && !@assignedresources.include?(resource)) @dCache.cached(self, :TaskScenarioAllocatedTime, startIdx, endIdx, resource) do allocatedTime = 0.0 if @property.container? @property.kids.each do |task| allocatedTime += task.getAllocatedTime(@scenarioIdx, startIdx, endIdx, resource) end else if resource allocatedTime += resource.getAllocatedTime(@scenarioIdx, startIdx, endIdx, @property) else @assignedresources.each do |r| allocatedTime += r.getAllocatedTime(@scenarioIdx, startIdx, endIdx, @property) end end end allocatedTime end end |
#getEffectiveWork(startIdx, endIdx, resource = nil) ⇒ Object
Compute the effective work a resource or all resources do during the interval specified by startIdx and endIdx. The effective work is the actual work multiplied by the efficiency of the resource.
1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1590 def getEffectiveWork(startIdx, endIdx, resource = nil) # Make sure we have the real Resource and not a proxy. resource = resource.ptn if resource return 0.0 if @milestone || startIdx >= endIdx || (resource && !@assignedresources.include?(resource)) @dCache.cached(self, :TaskScenarioEffectiveWork, startIdx, endIdx, resource) do workLoad = 0.0 if @property.container? @property.kids.each do |task| workLoad += task.getEffectiveWork(@scenarioIdx, startIdx, endIdx, resource) end else if resource workLoad += resource.getEffectiveWork(@scenarioIdx, startIdx, endIdx, @property) else @assignedresources.each do |r| workLoad += r.getEffectiveWork(@scenarioIdx, startIdx, endIdx, @property) end end end workLoad end end |
#hasDependency?(depType, target, onEnd) ⇒ Boolean
Return true of this Task has a dependency [ target, onEnd ] in the dependency category depType.
183 184 185 |
# File 'lib/taskjuggler/TaskScenario.rb', line 183 def hasDependency?(depType, target, onEnd) a(depType).include?([target, onEnd]) end |
#hasResourceAllocated?(interval, resource) ⇒ Boolean
Returns true of the resource is assigned to this task or any of its children.
1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1713 def hasResourceAllocated?(interval, resource) return false unless @assignedresources.include?(resource) if @property.leaf? return resource.allocated?(@scenarioIdx, interval, @property) else @property.kids.each do |t| return true if t.hasResourceAllocated?(@scenarioIdx, interval, resource) end end false end |
#isDependencyOf(task, depth, list = []) ⇒ Object
Check if the Task task depends on this task. depth specifies how many dependent task are traversed at max. A value of 0 means no limit. TODO: Change this to a non-recursive implementation.
1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1655 def isDependencyOf(task, depth, list = []) return true if task == @property # If this task is already in the list of traversed task, we can ignore # it. return false if list.include?(@property) list << @property @startsuccs.each do |t, onEnd| unless onEnd # must be a start->start dependency return true if t.isDependencyOf(@scenarioIdx, task, depth, list) end end # For task to depend on this task, the start of task must be after the # end of this task. if task['start', @scenarioIdx] && @end return false if task['start', @scenarioIdx] < @end end # Check if any of the parent tasks is a dependency of _task_. t = @property.parent while t # If the parent is a dependency, than all childs are as well. return true if t.isDependencyOf(@scenarioIdx, task, depth, list) t = t.parent end return false if depth == 1 @endsuccs.each do |ta, onEnd| unless onEnd # must be an end->start dependency return true if ta.isDependencyOf(@scenarioIdx, task, depth - 1, list) end end false end |
#isFeatureOf(task) ⇒ Object
If task or any of its sub-tasks depend on this task or any of its sub-tasks, we call this task a feature of task.
1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1698 def isFeatureOf(task) sources = @property.all destinations = task.all sources.each do |s| destinations.each do |d| return true if s.isDependencyOf(@scenarioIdx, d, 0) end end false end |
#latestEnd ⇒ Object
Find the latest possible end date for the task. This date must be before the start date of all the task that this task precedes. Dependencies may also require a minimum gap between the tasks.
1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1229 def latestEnd # This is the date that we will return. endDate = nil @precedes.each do |dependency| potentialEndDate = dependency.task[dependency.onEnd ? 'end' : 'start', @scenarioIdx] return nil if potentialEndDate.nil? # Determine the end date of a 'length' gap. dateBeforeLengthGap = potentialEndDate gapLength = dependency.gapLength while gapLength > 0 && dateBeforeLengthGap > @project['start'] do if @project.isWorkingTime(dateBeforeLengthGap - @project['scheduleGranularity']) gapLength -= 1 end dateBeforeLengthGap -= @project['scheduleGranularity'] end # Determine the end date of a 'duration' gap. if dateBeforeLengthGap < potentialEndDate - dependency.gapDuration potentialEndDate = dateBeforeLengthGap else potentialEndDate -= dependency.gapDuration end endDate = potentialEndDate if endDate.nil? || endDate > potentialEndDate end # If any of the parent tasks has an explicit end date, the task must end # at or before this date. task = @property while (task = task.parent) do if task['end', @scenarioIdx] && (endDate.nil? || task['end', @scenarioIdx] < endDate) endDate = task['end', @scenarioIdx] break end end # When the computed end date is before the already determined start date # of the task, the end dependencies were too weak. This happens when # task A precedes B and they are specified this way: # task A: | --> D- # task B: -D <-- | if @start && (endDate.nil? || endDate < @start) error('impossible_end_dep', "Task #{@property.fullId} has end date dependencies " + "that conflict with the start date #{@start}.") end endDate end |
#markAsScheduled ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/taskjuggler/TaskScenario.rb', line 56 def markAsScheduled return if @scheduled @scheduled = true Log.msg do if @milestone typename = 'Milestone' elsif @property.leaf? typename = 'Task' else typename = 'Container' end "#{typename} #{@property.fullId} has been scheduled." end end |
#postScheduleCheck ⇒ Object
This function is not essential but does perform a large number of consistency checks. It should be called after the scheduling run has been finished.
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 |
# File 'lib/taskjuggler/TaskScenario.rb', line 434 def postScheduleCheck @errors = 0 @property.children.each do |task| @errors += 1 unless task.postScheduleCheck(@scenarioIdx) end # There is no point to check the parent if the child(s) have errors. return false if @errors > 0 # Same for runaway tasks. They have already been reported. if @isRunAway error('sched_runaway', "Some tasks did not fit into the project time " + "frame.") end # Make sure the task is marked complete unless @scheduled error('not_scheduled', "Task #{@property.fullId} has not been marked as scheduled.") end # If the task has a follower or predecessor that is a runaway this task # is also incomplete. (@startsuccs + @endsuccs).each do |task, onEnd| return false if task.isRunAway(@scenarioIdx) end (@startpreds + @endpreds).each do |task, onEnd| return false if task.isRunAway(@scenarioIdx) end # Check if the start time is ok if @start.nil? error('task_start_undef', "Task #{@property.fullId} has undefined start time") end if @start < @project['start'] || @start > @project['end'] error('task_start_range', "The start time (#{@start}) of task #{@property.fullId} " + "is outside the project interval (#{@project['start']} - " + "#{@project['end']})") end if !@minstart.nil? && @start < @minstart warning('minstart', "The start time (#{@start}) of task #{@property.fullId} " + "is too early. Must be after #{@minstart}.") end if !@maxstart.nil? && @start > @maxstart warning('maxstart', "The start time (#{@start}) of task #{@property.fullId} " + "is too late. Must be before #{@maxstart}.") end # Check if the end time is ok error('task_end_undef', "Task #{@property.fullId} has undefined end time") if @end.nil? if @end < @project['start'] || @end > @project['end'] error('task_end_range', "The end time (#{@end}) of task #{@property.fullId} " + "is outside the project interval (#{@project['start']} - " + "#{@project['end']})") end if !@minend.nil? && @end < @minend warning('minend', "The end time (#{@end}) of task #{@property.fullId} " + "is too early. Must be after #{@minend}.") end if !@maxend.nil? && @end > @maxend warning('maxend', "The end time (#{@end}) of task #{@property.fullId} " + "is too late. Must be before #{@maxend}.") end # Make sure the start is before the end if @start > @end error('start_after_end', "The start time (#{@start}) of task #{@property.fullId} " + "is after the end time (#{@end}).") end # Check that tasks fits into parent task. unless (parent = @property.parent).nil? || parent['start', @scenarioIdx].nil? || parent['end', @scenarioIdx].nil? if @start < parent['start', @scenarioIdx] error('task_start_in_parent', "The start date (#{@start}) of task #{@property.fullId} " + "is before the start date (#{parent['start', @scenarioIdx]}) " + "of the enclosing task.") end if @end > parent['end', @scenarioIdx] error('task_end_in_parent', "The end date (#{@end}) of task #{@property.fullId} " + "is after the end date (#{parent['end', @scenarioIdx]}) " + "of the enclosing task.") end end # Check that all preceding tasks start/end before this task. @depends.each do |dependency| task = dependency.task limit = task[dependency.onEnd ? 'end' : 'start', @scenarioIdx] next if limit.nil? if @start < limit || (dependency.gapDuration > 0 && limit + dependency.gapDuration > @start) || (dependency.gapLength > 0 && calcLength(limit, @start) < dependency.gapLength) error('task_pred_before', "Task #{@property.fullId} (#{@start}) must start " + (dependency.gapDuration > 0 ? "#{dependency.gapDuration / (60 * 60 * 24)} days " : (dependency.gapLength > 0 ? "#{@project.slotsToDays(dependency.gapLength)} " + "working days " : '')) + "after " + "#{dependency.onEnd ? 'end' : 'start'} (#{limit}) of task " + "#{task.fullId}. This condition could not be met.") end end # Check that all following tasks end before this task @precedes.each do |dependency| task = dependency.task limit = task[dependency.onEnd ? 'end' : 'start', @scenarioIdx] next if limit.nil? if limit < @end || (dependency.gapDuration > 0 && limit - dependency.gapDuration < @end) || (dependency.gapLength > 0 && calcLength(@end, limit) < dependency.gapLength) error('task_succ_after', "Task #{@property.fullId} (#{@end}) must end " + (dependency.gapDuration > 0 ? "#{dependency.gapDuration / (60 * 60 * 24)} days " : (dependency.gapLength > 0 ? "#{@project.slotsToDays(dependency.gapLength)} " + "working days " : '')) + "before " + "#{dependency.onEnd ? 'end' : 'start'} (#{limit}) of task " + "#{task.fullId}. This condition could not be met.") end end if @milestone && @start != @end error('milestone_times_equal', "Milestone #{@property.fullId} must have identical start and " + "end date.") end if @property.leaf? && @effort == 0 && !@milestone && !@allocate.empty? && @assignedresources.empty? # The user used an 'allocate' for the task, but did not specify any # 'effort'. Actual allocations will only happen when resources are # available by chance. If there are no assigned resources, we generate # a warning as this is probably not what the user intended. warning('allocate_no_assigned', "Task #{@property.id} has resource allocation requested, but " + "did not get any resources assigned. Either use 'effort' " + "to ensure allocations or use a higher 'priority'.") end thieves = [] @competitors.each do |t| thieves << t if t['priority', @scenarioIdx] < @priority end unless thieves.empty? warning('priority_inversion', "Due to a mix of ALAP and ASAP scheduled tasks or a " + "dependency on a lower priority tasks the following " + "task#{thieves.length > 1 ? 's' : ''} stole resources from " + "#{@property.fullId} despite having a lower priority:") thieves.each do |t| info('priority_inversion_info', "Task #{t.fullId}", t.sourceFileInfo) end end @errors == 0 end |
#prepareScheduling ⇒ Object
Call this function to reset all scheduling related data prior to scheduling.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/taskjuggler/TaskScenario.rb', line 74 def prepareScheduling @property['startpreds', @scenarioIdx] = [] @property['startsuccs', @scenarioIdx] = [] @property['endpreds', @scenarioIdx] = [] @property['endsuccs', @scenarioIdx] = [] @isRunAway = false # And as global scoreboard index @currentSlotIdx = nil # The 'done' variables count scheduled values in number of time slots. @doneDuration = 0 @doneLength = 0 # Due to the 'efficiency' factor the effort slots must be a float. @doneEffort = 0.0 @nowIdx = @project.dateToIdx(@project['now']) @startIsDetermed = nil @endIsDetermed = nil # To avoid multiple calls to propagateDate() we use these flags to know # when we've done it already. @startPropagated = false @endPropagated = false @durationType = if @effort > 0 @hasDurationSpec = true :effortTask elsif @length > 0 @hasDurationSpec = true :lengthTask elsif @duration > 0 @hasDurationSpec = true :durationTask else # If the task is set as milestone it has a duration spec. @hasDurationSpec = @milestone :startEndTask end markAsMilestone # For start-end-tasks without allocation, we don't have to do # anything but to set the 'scheduled' flag. if @durationType == :startEndTask && @start && @end && @allocate.empty? markAsScheduled end # Collect the limits of this task and all parent tasks into a single # Array. @allLimits = [] task = @property # Reset the counters of all limits of this task. task['limits', @scenarioIdx].reset if task['limits', @scenarioIdx] until task.nil? if task['limits', @scenarioIdx] @allLimits << task['limits', @scenarioIdx] end task = task.parent end @contendedResources = Hash.new { |hash, key| hash[key] = Hash.new(0) } # Collect the mandatory allocations. @mandatories = [] @allocate.each do |allocation| @mandatories << allocation if allocation.mandatory allocation.lockedResource = nil end bookBookings if @durationType == :startEndTask @startIdx = @project.dateToIdx(@start) if @start @endIdx = @project.dateToIdx(@end) if @end end end |
#preScheduleCheck ⇒ Object
Before the actual scheduling work can be started, we need to do a few consistency checks on the task.
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/taskjuggler/TaskScenario.rb', line 209 def preScheduleCheck # Accounts can have sub accounts added after being used in a chargetset. # So we need to re-test here. @chargeset.each do |chargeset| chargeset.each do |account, share| unless account.leaf? error('account_no_leaf', "Chargesets may not include group account #{account.fullId}.") end end end @responsible.map! do |resourceId| # 'resource' is still just an ID and needs to be converted into a # Resource. if (resource = @project.resource(resourceId)).nil? error('resource_id_expected', "#{resourceId} is not a defined " + 'resource.', @sourceFileInfo) end resource end @responsible.uniq! # Leaf tasks can be turned into containers after bookings have been added. # We need to check for this. unless @property.leaf? || @booking.empty? error('container_booking', "Container task #{@property.fullId} may not have bookings.") end # Milestones may not have bookings. if @milestone && !@booking.empty? error('milestone_booking', "Milestone #{@property.fullId} may not have bookings.") end # All 'scheduled' tasks must have a fixed start and end date. if @scheduled && (@start.nil? || @end.nil?) error('not_scheduled', "Task #{@property.fullId} is marked as scheduled but does not " + 'have a fixed start and end date.') end # If an effort has been specified resources must be allocated as well. if @effort > 0 && @allocate.empty? error('effort_no_allocations', "Task #{@property.fullId} has an effort but no resource " + "allocations.") end durationSpecs = 0 durationSpecs += 1 if @effort > 0 durationSpecs += 1 if @length > 0 durationSpecs += 1 if @duration > 0 durationSpecs += 1 if @milestone # The rest of this function performs a number of plausibility tests with # regards to task start and end critiria. To explain the various cases, # the following symbols are used: # # |: fixed start or end date # -: no fixed start or end date # M: Milestone # D: start or end dependency # x->: ASAP task with duration criteria # <-x: ALAP task with duration criteria # -->: ASAP task without duration criteria # <--: ALAP task without duration criteria if @property.container? if durationSpecs > 0 error('container_duration', "Container task #{@property.fullId} may not have a duration " + "or be marked as milestones.") end elsif @milestone if durationSpecs > 1 error('milestone_duration', "Milestone task #{@property.fullId} may not have a duration.") end # Milestones can have the following cases: # # | M - ok |D M - ok - M - err1 -D M - ok # | M | err2 |D M | err2 - M | ok -D M | ok # | M -D ok |D M -D ok - M -D ok -D M -D ok # | M |D err2 |D M |D err2 - M |D ok -D M |D ok # err1: no start and end # already handled by 'start_undetermed' or 'end_undetermed' # err2: differnt start and end dates if @start && @end && @start != @end error('milestone_start_end', "Start (#{@start}) and end (#{@end}) dates of " + "milestone task #{@property.fullId} must be identical.") end else # Error table for non-container, non-milestone tasks: # AMP: Automatic milestone promotion for underspecified tasks when # no bookings or allocations are present. # AMPi: Automatic milestone promotion when no bookings or # allocations are present. When no bookings but allocations are # present the task inherits start and end date. # Ref. implicitXref()| # inhS: Inherit start date from parent task or project # inhE: Inherit end date from parent task or project # # | x-> - ok |D x-> - ok - x-> - inhS -D x-> - ok # | x-> | err1 |D x-> | err1 - x-> | inhS -D x-> | err1 # | x-> -D ok |D x-> -D ok - x-> -D inhS -D x-> -D ok # | x-> |D err1 |D x-> |D err1 - x-> |D inhS -D x-> |D err1 # | --> - AMP |D --> - AMP - --> - AMPi -D --> - AMP # | --> | ok |D --> | ok - --> | inhS -D --> | ok # | --> -D ok |D --> -D ok - --> -D inhS -D --> -D ok # | --> |D ok |D --> |D ok - --> |D inhS -D --> |D ok # | <-x - inhE |D <-x - inhE - <-x - inhE -D <-x - inhE # | <-x | err1 |D <-x | err1 - <-x | ok -D <-x | ok # | <-x -D err1 |D <-x -D err1 - <-x -D ok -D <-x -D ok # | <-x |D err1 |D <-x |D err1 - <-x |D ok -D <-x |D ok # | <-- - inhE |D <-- - inhE - <-- - AMP -D <-- - inhE # | <-- | ok |D <-- | ok - <-- | AMP -D <-- | ok # | <-- -D ok |D <-- -D ok - <-- -D AMP -D <-- -D ok # | <-- |D ok |D <-- |D ok - <-- |D AMP -D <-- |D ok # These cases are normally autopromoted to milestones or inherit their # start or end dates. But this only works for tasks that have no # allocations or bookings. # - --> - # | --> - # |D --> - # -D --> - # - <-- - # - <-- | # - <-- -D # - <-- |D if durationSpecs == 0 && ((@forward && @end.nil? && !hasDependencies(true)) || (!@forward && @start.nil? && !hasDependencies(false))) error('task_underspecified', "Task #{@property.fullId} has too few specifations to be " + "scheduled.") end # err1: Overspecified (12 cases) # | x-> | # | <-x | # | x-> |D # | <-x |D # |D x-> | # |D <-x | # |D <-x |D # |D x-> |D # -D x-> | # -D x-> |D # |D <-x -D # | <-x -D if durationSpecs > 1 error('multiple_durations', "Tasks may only have either a duration, length or effort or " + "be a milestone.") end startSpeced = @property.provided('start', @scenarioIdx) endSpeced = @property.provided('end', @scenarioIdx) if ((startSpeced && endSpeced) || (hasDependencies(false) && @forward && endSpeced) || (hasDependencies(true) && !@forward && startSpeced)) && durationSpecs > 0 && !@property.provided('scheduled', @scenarioIdx) error('task_overspecified', "Task #{@property.fullId} has a start, an end and a " + 'duration specification.') end end if !@booking.empty? && !@forward && !@scheduled error('alap_booking', 'A task scheduled in ALAP mode may only have bookings if it ' + 'has been marked as fully scheduled. Keep in mind that ' + 'certain attributes like \'end\' or \'precedes\' automatically ' + 'switch the task to ALAP mode.') end @startsuccs.each do |task, onEnd| unless task['forward', @scenarioIdx] task.data[@scenarioIdx].error( 'onstart_wrong_direction', 'Tasks with on-start dependencies must be ASAP scheduled') end end @endpreds.each do |task, onEnd| if task['forward', @scenarioIdx] task.data[@scenarioIdx].error( 'onend_wrong_direction', 'Tasks with on-end dependencies must be ALAP scheduled') end end end |
#propagateDate(date, atEnd, ignoreEffort = false) ⇒ Object
Set a new start or end date and propagate the value to all other task ends that have a direct dependency to this end of the task.
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 |
# File 'lib/taskjuggler/TaskScenario.rb', line 979 def propagateDate(date, atEnd, ignoreEffort = false) logTag = "propagateDate_#{@property.id}_#{atEnd ? 'end' : 'start'}" Log.enter(logTag, "Propagating #{atEnd ? 'end' : 'start'} date " + "to task #{@property.id}") thisEnd = atEnd ? 'end' : 'start' otherEnd = atEnd ? 'start' : 'end' #puts "Propagating #{thisEnd} date #{date} to #{@property.fullId} " + # "#{ignoreEffort ? "ignoring effort" : "" }" # These flags are just used to avoid duplicate calls of this function # during propagateInitialValues(). if atEnd @endPropagated = true else @startPropagated = true end # For leaf tasks, propagate start may set the date. Container task dates # are only set in scheduleContainer(). if @property.leaf? # If we already have a date, we will only shrink the task period with # the new date. if (setDate = instance_variable_get('@' + thisEnd)) && atEnd ? date > setDate : date < setDate Log.msg { "Preserving #{thisEnd} date of #{typename} " + "#{@property.fullId}: #{setDate}" } return end instance_variable_set(('@' + thisEnd).intern, date) typename = 'Task' if @durationType == :startEndTask instance_variable_set(('@' + thisEnd + 'Idx').intern, @project.dateToIdx(date)) if @milestone typename = 'Milestone' end end Log.msg { "Update #{typename} #{@property.fullId}: #{period_to_s}" } end if @milestone # Start and end date of a milestone are identical. markAsScheduled if a(otherEnd).nil? propagateDate(a(thisEnd), !atEnd) end elsif !@scheduled && @start && @end && !(@length == 0 && @duration == 0 && @effort == 0 && !@allocate.empty?) markAsScheduled end # Propagate date to all dependent tasks. Don't do this for start # successors or end predecessors if this task is effort based. In this # case, the date might still change to align with the first/last # allocation. In these cases, bookResource() has to propagate the final # date. if atEnd if ignoreEffort || @effort == 0 @endpreds.each do |task, onEnd| propagateDateToDep(task, onEnd) end end @endsuccs.each do |task, onEnd| propagateDateToDep(task, onEnd) end else if ignoreEffort || @effort == 0 @startsuccs.each do |task, onEnd| propagateDateToDep(task, onEnd) end end @startpreds.each do |task, onEnd| propagateDateToDep(task, onEnd) end end # Propagate date to sub tasks which have only an implicit # dependency on the parent task and no other criteria for this end of # the task. @property.children.each do |task| if task.canInheritDate?(@scenarioIdx, atEnd) task.propagateDate(@scenarioIdx, date, atEnd) end end # The date propagation might have completed the date set of the enclosing # containter task. If so, we can schedule it as well. @property.parents.each do |parent| parent.scheduleContainer(@scenarioIdx) end Log.exit(logTag, "Finished propagation of " + "#{atEnd ? 'end' : 'start'} date " + "to task #{@property.id}") end |
#propagateInitialValues ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/taskjuggler/TaskScenario.rb', line 187 def propagateInitialValues unless @startPropagated if @start propagateDate(@start, false, true) elsif @property.parent.nil? && @property.canInheritDate?(@scenarioIdx, false) propagateDate(@project['start'], false, true) end end unless @endPropagated if @end propagateDate(@end, true, true) elsif @property.parent.nil? && @property.canInheritDate?(@scenarioIdx, true) propagateDate(@project['end'], true, true) end end end |
#query_activetasks(query) ⇒ Object
1289 1290 1291 1292 1293 1294 1295 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1289 def query_activetasks(query) count = activeTasks(query) query.sortable = query.numerical = count # For the string output, we only use integer numbers. query.string = "#{count.to_i}" end |
#query_closedtasks(query) ⇒ Object
1297 1298 1299 1300 1301 1302 1303 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1297 def query_closedtasks(query) count = closedTasks(query) query.sortable = query.numerical = count # For the string output, we only use integer numbers. query.string = "#{count.to_i}" end |
#query_competitorcount(query) ⇒ Object
1305 1306 1307 1308 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1305 def query_competitorcount(query) query.sortable = query.numerical = @competitors.length query.string = "#{@competitors.length}" end |
#query_complete(query) ⇒ Object
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1310 def query_complete(query) # If we haven't calculated the value yet, calculate it first. unless @complete calcCompletion end query.sortable = query.numerical = @complete # For the string output, we only use integer numbers. query.string = "#{@complete.to_i}%" end |
#query_cost(query) ⇒ Object
Compute the cost generated by this Task for a given Account during a given interval. If a Resource is provided as scopeProperty only the cost directly generated by the resource is taken into account.
1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1324 def query_cost(query) if query.costAccount query.sortable = query.numerical = cost = turnover(query.startIdx, query.endIdx, query.costAccount, query.scopeProperty) query.string = query.currencyFormat.format(cost) else query.string = 'No \'balance\' defined!' end end |
#query_duration(query) ⇒ Object
The duration of the task. After scheduling, it can be determined for all tasks. Also for those who did not have a ‘duration’ attribute.
1337 1338 1339 1340 1341 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1337 def query_duration(query) query.sortable = query.numerical = duration = (@end - @start) / (60 * 60 * 24) query.string = query.scaleDuration(duration) end |
#query_effort(query) ⇒ Object
The effort allocated for the task in the specified interval. In case a Resource is given as scope property only the effort allocated for this resource is taken into account.
1375 1376 1377 1378 1379 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1375 def query_effort(query) query.sortable = query.numerical = work = getEffectiveWork(query.startIdx, query.endIdx, query.scopeProperty) query.string = query.scaleLoad(work) end |
#query_effortdone(query) ⇒ Object
The completed (as of ‘now’) effort allocated for the task in the specified interval. In case a Resource is given as scope property only the effort allocated for this resource is taken into account.
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1346 def query_effortdone(query) if @effortdone effort = @project.convertToDailyLoad(@effortdone * @project['scheduleGranularity']) else # For this query, we always override the query period. effort = getEffectiveWork(@project.dateToIdx(@project['start'], false), @project.dateToIdx(@project['now']), query.scopeProperty) end query.sortable = query.numerical = effort query.string = query.scaleLoad(effort) end |
#query_effortleft(query) ⇒ Object
The remaining (as of ‘now’) effort allocated for the task in the specified interval. In case a Resource is given as scope property only the effort allocated for this resource is taken into account.
1363 1364 1365 1366 1367 1368 1369 1370 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1363 def query_effortleft(query) # For this query, we always override the query period. query.sortable = query.numerical = effort = getEffectiveWork(@project.dateToIdx(@project['now']), @project.dateToIdx(@project['end'], false), query.scopeProperty) query.string = query.scaleLoad(effort) end |
#query_followers(query) ⇒ Object
1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1381 def query_followers(query) list = [] # First gather the task that depend on the start of this task. @startsuccs.each do |task, onEnd| if onEnd date = task['end', query.scenarioIdx].to_s(query.timeFormat) dep = "[->]" else date = task['start', query.scenarioIdx].to_s(query.timeFormat) dep = "[->[" end list << generateDepencyListItem(query, task, dep, date) end # Than add the tasks that depend on the end of this task. @endsuccs.each do |task, onEnd| if onEnd date = task['end', query.scenarioIdx].to_s(query.timeFormat) dep = "]->]" else date = task['start', query.scenarioIdx].to_s(query.timeFormat) dep = "]->[" end list << generateDepencyListItem(query, task, dep, date) end query.assignList(list) end |
#query_gauge(query) ⇒ Object
1410 1411 1412 1413 1414 1415 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1410 def query_gauge(query) # If we haven't calculated the schedule status yet, calculate it first. calcGauge unless @gauge query.string = @gauge end |
#query_headcount(query) ⇒ Object
The number of different resources assigned to the task during the query interval. Each resource is counted based on their mathematically rounded efficiency.
1420 1421 1422 1423 1424 1425 1426 1427 1428 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1420 def query_headcount(query) headcount = 0 assignedResources(Interval.new(query.start, query.end)).each do |res| headcount += res['efficiency', @scenarioIdx].round end query.sortable = query.numerical = headcount query.string = query.numberFormat.format(headcount) end |
#query_inputs(query) ⇒ Object
1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1430 def query_inputs(query) inputList = PropertyList.new(@project.tasks, false) inputs(inputList, true) inputList.delete(@property) inputList.setSorting([['start', true, @scenarioIdx], ['seqno', true, -1 ]]) inputList.sort! query.assignList(generateTaskList(inputList, query)) end |
#query_maxend(query) ⇒ Object
1441 1442 1443 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1441 def query_maxend(query) queryDateLimit(query, @maxend) end |
#query_maxstart(query) ⇒ Object
1445 1446 1447 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1445 def query_maxstart(query) queryDateLimit(query, @maxstart) end |
#query_minend(query) ⇒ Object
1449 1450 1451 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1449 def query_minend(query) queryDateLimit(query, @minend) end |
#query_minstart(query) ⇒ Object
1453 1454 1455 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1453 def query_minstart(query) queryDateLimit(query, @minstart) end |
#query_opentasks(query) ⇒ Object
1457 1458 1459 1460 1461 1462 1463 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1457 def query_opentasks(query) count = openTasks(query) query.sortable = query.numerical = count # For the string output, we only use integer numbers. query.string = "#{count.to_i}" end |
#query_precursors(query) ⇒ Object
1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1465 def query_precursors(query) list = [] # First gather the task that depend on the start of this task. @startpreds.each do |task, onEnd| if onEnd date = task['end', query.scenarioIdx].to_s(query.timeFormat) dep = "]->[" else date = task['start', query.scenarioIdx].to_s(query.timeFormat) dep = "[->[" end list << generateDepencyListItem(query, task, dep, date) end # Than add the tasks that depend on the end of this task. @endpreds.each do |task, onEnd| if onEnd date = task['end', query.scenarioIdx].to_s(query.timeFormat) dep = "]->]" else date = task['start', query.scenarioIdx].to_s(query.timeFormat) dep = "[->]" end list << generateDepencyListItem(query, task, dep, date) end query.assignList(list) end |
#query_resources(query) ⇒ Object
A list of the resources that have been allocated to work on the task in the report time frame.
1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1496 def query_resources(query) list = [] iv = TimeInterval.new(query.start, query.end) assignedResources(iv).each do |resource| if resource.allocated?(@scenarioIdx, iv, @property) if query.listItem rti = RichText.new(query.listItem, RTFHandlers.create(@project)). generateIntermediateFormat unless rti error('bad_resource_ts_query', "Syntax error in query statement for task attribute " + "'resources'.") end q = query.dup q.property = resource rti.setQuery(q) list << "<nowiki>#{rti.to_s}</nowiki>" else list << "<nowiki>#{resource.name} (#{resource.fullId})</nowiki>" end end end query.assignList(list) end |
#query_revenue(query) ⇒ Object
Compute the revenue generated by this Task for a given Account during a given interval. If a Resource is provided as scopeProperty only the revenue directly generated by the resource is taken into account.
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1524 def query_revenue(query) if query.revenueAccount query.sortable = query.numerical = revenue = turnover(query.startIdx, query.endIdx, query.revenueAccount, query.scopeProperty) query.string = query.currencyFormat.format(revenue) else query.string = 'No \'balance\' defined!' end end |
#query_scheduling(query) ⇒ Object
1535 1536 1537 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1535 def query_scheduling(query) query.string = @forward ? 'ASAP' : 'ASAP' if @property.leaf? end |
#query_status(query) ⇒ Object
1539 1540 1541 1542 1543 1544 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1539 def query_status(query) # If we haven't calculated the completion yet, calculate it first. calcStatus if @status.empty? query.string = @status end |
#query_targets(query) ⇒ Object
1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1546 def query_targets(query) targetList = PropertyList.new(@project.tasks, false) targets(targetList, true) targetList.delete(@property) targetList.setSorting([['start', true, @scenarioIdx], ['seqno', true, -1 ]]) targetList.sort! query.assignList(generateTaskList(targetList, query)) end |
#readyForScheduling? ⇒ Boolean
Check if the task is ready to be scheduled. For this it needs to have at least one specified end date and a duration criteria or the other end date.
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 |
# File 'lib/taskjuggler/TaskScenario.rb', line 910 def readyForScheduling? # If the tasks has already been scheduled, we still call it 'ready' so # it will be removed from the todo list. return true if @scheduled return false if @isRunAway if @forward return true if @start && (@hasDurationSpec || @end) else return true if @end && (@hasDurationSpec || @start) end false end |
#resetLoopFlags ⇒ Object
612 613 614 |
# File 'lib/taskjuggler/TaskScenario.rb', line 612 def resetLoopFlags @deadEndFlags = Array.new(4, false) end |
#schedule ⇒ Object
This function is the entry point for the core scheduling algorithm. It schedules the task to completion. The function returns true if a start or end date has been determined and other tasks may be ready for scheduling now.
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 |
# File 'lib/taskjuggler/TaskScenario.rb', line 930 def schedule # Check if the task has already been scheduled e. g. by propagateDate(). return true if @scheduled logTag = "schedule_#{@property.id}" Log.enter(logTag, "Scheduling task #{@property.id}") # Compute the date of the next slot this task wants to have scheduled. # This must either be the first slot ever or it must be directly # adjecent to the previous slot. If this task has not yet been scheduled # at all, @currentSlotIdx is still nil. Otherwise it contains the index # of the last scheduled slot. if @forward # On first call, the @currentSlotIdx is not set yet. We set it to the # start slot index or the 'now' slot if we are in projection mode and # the tasks has allocations. if @currentSlotIdx.nil? @currentSlotIdx = @project.dateToIdx( @projectionmode && (@project['now'] > @start) && !@allocate.empty? ? @project['now'] : @start) end else # On first call, the @currentSlotIdx is not set yet. We set it to the # slot index of the slot before the end slot. if @currentSlotIdx.nil? @currentSlotIdx = @project.dateToIdx(@end) - 1 end end # Schedule all time slots from slot in the scheduling direction until # the task is completed or a problem has been found. # The task may not excede the project interval. lowerLimit = @project.dateToIdx(@project['start']) upperLimit = @project.dateToIdx(@project['end']) delta = @forward ? 1 : -1 while scheduleSlot @currentSlotIdx += delta if @currentSlotIdx < lowerLimit || upperLimit < @currentSlotIdx markAsRunaway Log.exit(logTag, "Scheduling of task #{@property.id} failed") return false end end Log.exit(logTag, "Scheduling of task #{@property.id} completed") true end |
#scheduleContainer ⇒ Object
Find the smallest possible interval that encloses all child tasks. Abort the operation if any of the child tasks are not yet scheduled.
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 |
# File 'lib/taskjuggler/TaskScenario.rb', line 1125 def scheduleContainer return if @scheduled || !@property.container? nStart = nil nEnd = nil @property.kids.each do |task| # Abort if a child has not yet been scheduled. Since we haven't done # the consistency check yet, we can't rely on start and end being set # if 'scheduled' is set. return if (!task['scheduled', @scenarioIdx] || task['start', @scenarioIdx].nil? || task['end', @scenarioIdx].nil?) if nStart.nil? || task['start', @scenarioIdx] < nStart nStart = task['start', @scenarioIdx] end if nEnd.nil? || task['end', @scenarioIdx] > nEnd nEnd = task['end', @scenarioIdx] end end startSet = endSet = false # Propagate the dates to other dependent tasks. if @start.nil? || @start > nStart @start = nStart startSet = true end if @end.nil? || @end < nEnd @end = nEnd endSet = true end unless @start && @end raise "Start (#{@start}) and end (#{@end}) must be set" end Log.msg { "Container task #{@property.fullId} completed: #{period_to_s}" } markAsScheduled # If we have modified the start or end date, we need to communicate this # new date to surrounding tasks. propagateDate(nStart, false) if startSet propagateDate(nEnd, true) if endSet end |
#Xref ⇒ Object
The parser only stores the full task IDs for each of the dependencies. This function resolves them to task references and checks them. In addition to the ‘depends’ and ‘precedes’ property lists we also keep 4 additional lists. startpreds: All precedessors to the start of this task startsuccs: All successors to the start of this task endpreds: All predecessors to the end of this task endsuccs: All successors to the end of this task Each list element consists of a reference/boolean pair. The reference points to the dependent task and the boolean specifies whether the dependency originates from the end of the task or not.
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/taskjuggler/TaskScenario.rb', line 165 def Xref @depends.each do |dependency| depTask = checkDependency(dependency, 'depends') @startpreds.push([ depTask, dependency.onEnd ]) depTask[dependency.onEnd ? 'endsuccs' : 'startsuccs', @scenarioIdx]. push([ @property, false ]) end @precedes.each do |dependency| predTask = checkDependency(dependency, 'precedes') @endsuccs.push([ predTask, dependency.onEnd ]) predTask[dependency.onEnd ? 'endpreds' : 'startpreds', @scenarioIdx]. push([@property, true ]) end end |