Debian Codegraph @

src/plugins/schedulers/tj/taskjuggler/Resource.h

raw
1 /*
2 * Resource.h - TaskJuggler
3 *
4 * Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006
5 * by Chris Schlaeger <[email protected]>
6 * SPDX-FileCopyrightText: 2011 Dag Andersen <[email protected]>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
11 *
12 * $Id$
13 */
14 #ifndef _Resource_h_
15 #define _Resource_h_
16
17 #include "plantj_export.h"
18
19 #include "ResourceScenario.h"
20
21 class QDomDocument;
22 class QDomElement;
23
24 namespace TJ
25 {
26
27 class Project;
28 class Shift;
29 class Task;
30 class Booking;
31 class SbBooking;
32 class BookingList;
33 class Interval;
34 class UsageLimits;
35
36 /**
37 * @short Stores all information about a resource.
38 * @author Chris Schlaeger <[email protected]>
39 */
40 class PLANTJ_EXPORT Resource : public CoreAttributes
41 {
42 friend int ResourceList::compareItemsLevel(CoreAttributes* c1,
43 CoreAttributes* c2, int level);
44 public:
45 Resource(Project* p, const QString& i, const QString& n, Resource* pr,
46 const QString& df = QString(), uint dl = 0);
47 ~Resource() override;
48
49 static void deleteStaticData();
50
51 CAType getType() const override { return CA_Resource; }
52
53 Resource* getParent() const { return static_cast<Resource*>(parent); }
54
55 ResourceListIterator getSubListIterator() const
56 {
57 return ResourceListIterator(*sub);
58 }
59
60 void inheritValues();
61
62 bool isGroup() const { return !sub->isEmpty(); }
63
64 void setMinEffort(double e) { minEffort = e; }
65 double getMinEffort() const { return minEffort; }
66
67 void setLimits(UsageLimits* l);
68
69 const UsageLimits* getLimits() const { return limits; }
70
71 void setEfficiency(double e) { efficiency = e; }
72 double getEfficiency() const { return efficiency; }
73
74 bool isWorker() const;
75
76 void setRate(double r) { rate = r; }
77 double getRate() const { return rate; }
78
79 void addVacation(Interval* i);
80 QListIterator<Interval*> getVacationListIterator() const
81 {
82 return QListIterator<Interval*>(vacations);
83 }
84
85 bool hasVacationDay(time_t day) const;
86
87 bool isOnShift(const Interval& slot) const;
88
89 void setWorkingHours(int day, const QList<Interval*>& l);
90 const QList<Interval*>* const* getWorkingHours() const
91 {
92 return static_cast<const QList<Interval*>* const*>(workingHours);
93 }
94
95 bool addShift(const Interval& i, Shift* s);
96 bool addShift(ShiftSelection* s);
97
98 const ShiftSelectionList* getShiftList() const
99 {
100 return &shifts;
101 }
102
103 /**
104 * \retval 0 { resource is available }
105 * \retval 1 { resource is unavailable }
106 * \retval 2 { resource is on vacation }
107 * \retval 3 { undefined }
108 * \retval 4 { resource is allocated to a task }
109 */
110 int isAvailable(time_t day);
111
112 bool book(Booking* b);
113
114 bool bookSlot(uint idx, SbBooking* nb);
115
116 bool bookInterval(int scIndex, const Interval &interval, uint reason);
117
118 // bool bookInterval(Booking* b, int sc, int sloppy = 0, int overtime = 0);
119 // bool addBooking(int sc, Booking* b, int sloppy = 0, int overtime = 0);
120 /// Return a list of booked intervals for scenario @p sc and task @p task
121 QVector<Interval> getBookedIntervals(int sc, const Task* task) const;
122
123 double getCurrentLoad(const Interval& i, const Task* task = nullptr) const;
124
125 /// Get the number of work slots for the day @p date. It includes both free and booked.
126 uint getWorkSlots(time_t date) const;
127
128 uint getCurrentDaySlots(time_t date, const Task* t);
129 uint getCurrentWeekSlots(time_t date, const Task* t);
130 uint getCurrentMonthSlots(time_t date, const Task* t);
131
132 /***
133 * Return the load of the resource (and its children) weighted by their
134 * efficiency.
135 */
136 double getEffectiveLoad(int sc, const Interval& i,
137 AccountType acctType = AllAccounts,
138 const Task* task = nullptr) const;
139 double getAllocatedTimeLoad(int sc, const Interval& period,
140 AccountType acctType, const Task* task = nullptr)
141 const;
142 long getAllocatedTime(int sc, const Interval& period, AccountType acctType,
143 const Task* task = nullptr) const;
144
145 /***
146 * Return the unallocated load of the resource and its children weighted
147 * by their efficiency.
148 */
149 double getEffectiveFreeLoad(int sc, const Interval& period);
150 double getAvailableTimeLoad(int sc, const Interval& period);
151 long getAvailableTime(int sc, const Interval& period);
152
153 double getCredits(int sc, const Interval& i, AccountType acctType,
154 const Task* task = nullptr) const;
155
156 QString getProjectIDs(int sc, const Interval& i, const Task* task = nullptr)
157 const;
158
159 bool isAllocated(int sc, const Interval& i,
160 const QString& prjId = QString()) const;
161
162 bool isAllocated(int sc, const Interval& i, const Task* t) const;
163
164 BookingList getJobs(int sc) const;
165
166 time_t getStartOfFirstSlot(int sc, const Task* task);
167 time_t getEndOfLastSlot(int sc, const Task* task);
168
169 QDomElement xmlIDElement(QDomDocument& doc) const;
170
171 void copyBookings(int sc, SbBooking*** srd, SbBooking*** dst);
172 void saveSpecifiedBookings();
173 void prepareScenario(int sc);
174 void finishScenario(int sc);
175
176 bool bookingsOk(int sc);
177
178 void resetAllocationProbability(int sc) { allocationProbability[sc] = 0; }
179 void addAllocationProbability(int sc, double ap)
180 {
181 allocationProbability[sc] += ap;
182 }
183 double getAllocationProbability(int sc) const
184 {
185 return allocationProbability[sc];
186 }
187
188 TaskListIterator getTaskListIterator(int sc) const
189 {
190 return TaskListIterator(scenarios[sc].allocatedTasks);
191 }
192
193 // void addJournalEntry(JournalEntry* entry);
194
195 // bool hasJournal() const { return !journal.isEmpty(); }
196
197 // Journal::Iterator getJournalIterator() const;
198
199 private:
200 void getPIDs(int sc, const Interval& period, const Task* task,
201 QStringList& pids) const;
202
203 void initScoreboard();
204 void initSpecifiedBookings(int scIndex);
205
206 long getCurrentLoadSub(uint startIdx, uint endIdx, const Task* task) const;
207
208 long getAllocatedSlots(int sc, uint startIdx, uint endIdx,
209 AccountType acctType, const Task* task) const;
210
211 long getAvailableSlots(int sc, uint startIdx, uint endIdx);
212
213 bool isAllocatedSub(int sc, uint startIdx, uint endIdx, const QString&
214 prjId) const;
215 bool isAllocatedSub(int sc, uint startIdx, uint endIdx, const Task* task)
216 const;
217 void updateSlotMarks(int sc);
218
219 uint sbIndex(time_t date) const;
220
221 time_t index2start(uint idx) const;
222 time_t index2end(uint idx) const;
223
224 /// The minimum effort (in man days) the resource should be used per day.
225 double minEffort;
226
227 /// List of notes with a date attached.
228 // Journal journal;
229
230 /// Usage limits of the resource.
231 UsageLimits* limits;
232
233 /**
234 * The efficiency of the resource. A team of five should have an
235 * efficiency of 5.0 */
236 double efficiency;
237
238 /// The daily costs of this resource.
239 double rate;
240
241 /// The list of standard working or opening hours for the resource.
242 QList<Interval*>* workingHours[7];
243
244 /**
245 * In addition to the standard working hours a set of shifts can be
246 * defined. This is useful when the working hours change over time.
247 * A shift is only active in a defined interval. If no interval is
248 * defined for a period of time the standard working hours of the
249 * resource are used.
250 */
251 ShiftSelectionList shifts;
252
253 /// List of all intervals the resource is not available.
254 QList<Interval*> vacations;
255
256 /**
257 * For each time slot (of length scheduling granularity) we store:
258 * A pointer to a booking, or
259 * 0 if the resource is available,
260 * 1 if slot is off-hours,
261 * 2 if slot is during a vacation.
262 * 3 if booked by another project
263 */
264 SbBooking** scoreboard;
265 /// The number of time slots in the project.
266 uint sbSize;
267
268 SbBooking*** specifiedBookings;
269 SbBooking*** scoreboards;
270
271 ResourceScenario* scenarios;
272
273 /**
274 * The allocation probability is calculated prior to scheduling a
275 * scenario. It is the expected average effort the resource has to deliver
276 * based on the assignments to tasks, not taking parallel assignments into
277 * account.
278 */
279 double* allocationProbability;
280 } ;
281
282 } // namespace TJ
283
284 #endif