1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
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
|
/* This file is part of the KDE project
Copyright (C) 2001 Thomas Zander zander@kde.org
Copyright (C) 2004 Dag Andersen <danders@get2net.dk>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef KPTTASK_H
#define KPTTASK_H
#include "kptnode.h"
#include "kptduration.h"
#include "kptresource.h"
#include <qptrlist.h>
namespace KPlato
{
class DateTime;
/**
* A task in the scheduling software is represented by this class. A task
* can be anything from 'build house' to 'drill hole' It will always mean
* an activity.
*/
class Task : public Node {
public:
Task(Node *parent = 0);
Task(Task &task, Node *parent = 0);
~Task();
/// Return task type. Can be Type_Task, Type_Summarytask ot Type_Milestone.
virtual int type() const;
/**
* Returns the (previously) calculated duration.
* The caller must delete returned object.
*/
Duration *getExpectedDuration();
/**
* Instead of using the expected duration, generate a random value using
* the Distribution of each Task. This can be used for Monte-Carlo
* estimation of Project duration.
*/
Duration *getRandomDuration();
/**
* Return the resource request made to group
* (There should be only one)
*/
ResourceGroupRequest *resourceGroupRequest(ResourceGroup *group) const;
void clearResourceRequests();
void addRequest(ResourceGroup *group, int numResources);
void addRequest(ResourceGroupRequest *request);
void takeRequest(ResourceGroupRequest *request);
int units() const;
int workUnits() const;
void makeAppointments();
/**
* Calculates if the assigned resource is overbooked
* within the duration of this task
*/
void calcResourceOverbooked();
void setConstraint(Node::ConstraintType type);
/// Load from document
virtual bool load(QDomElement &element, Project &project);
/// Save to document
virtual void save(QDomElement &element) const;
/// Save appointments for schedule with id
virtual void saveAppointments(QDomElement &element, long id) const;
/**
* Returns a list of planned effort and cost for this task
* for the interval start, end inclusive
*/
virtual EffortCostMap plannedEffortCostPrDay(const QDate &start, const QDate &end) const;
/// Returns the total planned effort for this task (or subtasks)
virtual Duration plannedEffort();
/// Returns the total planned effort for this task (or subtasks) on date
virtual Duration plannedEffort(const QDate &date);
/// Returns the planned effort up to and including date
virtual Duration plannedEffortTo(const QDate &date);
/// Returns the total actual effort for this task (or subtasks)
virtual Duration actualEffort();
/// Returns the total actual effort for this task (or subtasks) on date
virtual Duration actualEffort(const QDate &date);
/// Returns the actual effort up to and including date
virtual Duration actualEffortTo(const QDate &date);
/**
* Returns the total planned cost for this task (or subtasks)
*/
virtual double plannedCost();
/// Planned cost on date
virtual double plannedCost(const QDate &/*date*/);
/// Planned cost up to and including date
virtual double plannedCostTo(const QDate &/*date*/);
/**
* Returns the actaually reported cost for this task (or subtasks)
*/
virtual double actualCost();
/// Actual cost on date
virtual double actualCost(const QDate &/*date*/);
/// Actual cost up to and including date
virtual double actualCostTo(const QDate &/*date*/);
/// Effort based performance index
double effortPerformanceIndex(const QDate &date, bool *error=0);
/// Cost performance index
double costPerformanceIndex(const QDate &date, bool *error=0);
void initiateCalculation(Schedule &sch);
/**
* Sets up the lists used for calculation.
* This includes adding summarytasks relations to subtasks
* and lists for start- and endnodes.
*/
void initiateCalculationLists(QPtrList<Node> &startnodes, QPtrList<Node> &endnodes, QPtrList<Node> &summarytasks);
/**
* Calculates ref m_durationForward from ref earliestStart and
* returns the resulting end time,
* which will be used as the succesors ref earliestStart.
*
* @param use Calculate using expected-, optimistic- or pessimistic estimate.
*/
DateTime calculateForward(int use);
/**
* Calculates ref m_durationBackward from ref latestFinish and
* returns the resulting start time,
* which will be used as the predecessors ref latestFinish.
*
* @param use Calculate using expected-, optimistic- or pessimistic estimate.
*/
DateTime calculateBackward(int use);
/**
* Schedules the task within the limits of earliestStart and latestFinish.
* Calculates ref m_startTime, ref m_endTime and ref m_duration,
* Assumes ref calculateForward() and ref calculateBackward() has been run.
*
* @param earliest The task is not scheduled to start earlier than this
* @param use Calculate using expected-, optimistic- or pessimistic estimate.
* @return The tasks endtime which can be used for scheduling the successor.
*/
DateTime scheduleForward(const DateTime &earliest, int use);
/**
* Schedules the task within the limits of earliestStart and latestFinish.
* Calculates ref m_startTime, ref m_endTime and ref m_duration,
* Assumes ref calculateForward() and ref calculateBackward() has been run.
*
* @param latest The task is not scheduled to end later than this
* @param use Calculate using expected-, optimistic- or pessimistic estimate.
* @return The tasks starttime which can be used for scheduling the predeccessor.
*/
DateTime scheduleBackward(const DateTime &latest, int use);
/**
* Summarytasks (with milestones) need special treatment because
* milestones are always 'glued' to their predecessors.
*/
void adjustSummarytask();
/**
* Return the duration calculated on bases of the requested resources
*/
Duration calcDuration(const DateTime &time, const Duration &effort, bool backward);
// Proxy relations are relations to/from summarytasks.
// These relations are distrubuted to the relevant tasks before calculation.
void clearProxyRelations();
void addParentProxyRelations(QPtrList<Relation> &list);
void addChildProxyRelations(QPtrList<Relation> &list);
void addParentProxyRelation(Node *node, const Relation *rel);
void addChildProxyRelation(Node *node, const Relation *rel);
/// Check if this node has any dependent child nodes.
bool isEndNode() const;
/// Check if this node has any dependent parent nodes
bool isStartNode() const;
/**
* Return the time when work can actually start on this task.
* This will be the time assigned resources can start work in accordance
* with their calendar, or if no resources have been assigned,
* the scheduled starttime is used.
*/
virtual DateTime workStartTime() const;
/**
* Return the time when work can actually finish on this task.
* This will be the time assigned resources can end work in accordance
* with their calendar, or if no resources have been assigned,
* the scheduled endtime is used.
*/
virtual DateTime workEndTime() const;
/**
* Return the duration that an activity's start can be delayed
* without affecting the project completion date.
* An activity with positive float is not on the critical path.
*/
Duration positiveFloat();
/**
* Return the duration by which the duration of an activity or path
* has to be reduced in order to fullfill a timing constraint.
*/
Duration negativeFloat() { return Duration(); }
/**
* Return the duration by which an activity can be delayed or extended
* without affecting the start of any succeeding activity.
*/
Duration freeFloat() { return Duration(); }
/**
* Return the duration from Early Start to Late Start.
*/
Duration startFloat() { return Duration(); }
/**
* Return the duration the task has at its finish before a successor task starts.
* This is the difference between the start time of the successor and
* the finish time of this task.
*/
Duration finishFloat() { return Duration(); }
/// A task is critical if there is no positive float
virtual bool isCritical();
/// Calculate critical path
virtual bool calcCriticalPath(bool fromEnd);
/// Set current schedule to schedule with identity id, for me nd my children
virtual void setCurrentSchedule(long id);
virtual bool effortMetError() const;
struct Progress {
Progress() { started = finished = false; percentFinished = 0; }
bool operator==(struct Progress &p) {
return started == p.started && finished == p.finished &&
startTime == p.startTime && finishTime == p.finishTime &&
percentFinished == p.percentFinished &&
remainingEffort == p.remainingEffort &&
totalPerformed == p.totalPerformed;
}
bool operator!=(struct Progress &p) { return !(*this == p); }
struct Progress &operator=(struct Progress &p) {
started = p.started; finished = p.finished;
startTime = p.startTime; finishTime = p.finishTime;
percentFinished = p.percentFinished;
remainingEffort = p.remainingEffort;
totalPerformed = p.totalPerformed;
return *this;
}
bool started, finished;
DateTime startTime, finishTime;
int percentFinished;
Duration remainingEffort;
Duration totalPerformed;
};
struct Progress &progress() { return m_progress; }
private:
DateTime calculateSuccessors(const QPtrList<Relation> &list, int use);
DateTime calculatePredeccessors(const QPtrList<Relation> &list, int use);
DateTime scheduleSuccessors(const QPtrList<Relation> &list, int use);
DateTime schedulePredeccessors(const QPtrList<Relation> &list, int use);
DateTime workStartAfter(const DateTime &dt);
DateTime workFinishBefore(const DateTime &dt);
private:
QPtrList<ResourceGroup> m_resource;
ResourceRequestCollection *m_requests;
QPtrList<Relation> m_parentProxyRelations;
QPtrList<Relation> m_childProxyRelations;
struct Progress m_progress;
#ifndef NDEBUG
public:
void printDebug(bool children, QCString indent);
#endif
};
} //KPlato namespace
#endif
|