Debian Codegraph @

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

raw
1 /*
2 * Allocation.h - TaskJuggler
3 *
4 * SPDX-FileCopyrightText: 2001, 2002, 2003, 2004, 2005 Chris Schlaeger <[email protected]>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
9 *
10 * $Id$
11 */
12 #ifndef _Allocation_h_
13 #define _Allocation_h_
14
15 #include "plantj_export.h"
16
17 #include <QDomDocument>
18
19 #include "ShiftSelectionList.h"
20
21 namespace TJ
22 {
23
24 class Resource;
25 class UsageLimits;
26
27 class PLANTJ_EXPORT Allocation
28 {
29 public:
30 Allocation();
31 Allocation(const Allocation& a);
32
33 ~Allocation();
34
35 void setLimits(UsageLimits* l);
36 const UsageLimits* getLimits() const { return limits; }
37
38 void setPersistent(bool p) { persistent = p; }
39 bool isPersistent() const { return persistent; }
40
41 void setMandatory(bool m) { mandatory = m; }
42 bool isMandatory() const { return mandatory; }
43
44 void setLockedResource(Resource* r) { lockedResource = r; }
45 Resource* getLockedResource() const { return lockedResource; }
46
47 void addCandidate(Resource* r) { candidates.append(r); }
48 QListIterator<Resource*> getCandidatesIterator() const
49 {
50 return QListIterator<Resource*> (candidates);
51 }
52 QList<Resource*> getCandidates() const { return candidates; }
53
54 /// Return the list of required resources for @p resource
55 QList<Resource*> getRequiredResources(Resource *r) const { return requiredResources.value(r); }
56 /// Add the @p required resource for @p resource
57 void addRequiredResource(Resource *resource, Resource *required)
58 {
59 requiredResources[resource].append(required);
60 }
61 bool hasRequiredResources(Resource *resource) const { return requiredResources.contains(resource); }
62
63 bool addShift(const Interval& i, Shift* s)
64 {
65 return shifts.insert(new ShiftSelection(i, s));
66 }
67
68 bool isOnShift(const Interval& i)
69 {
70 return shifts.isOnShift(i);
71 }
72
73 bool isWorker() const;
74
75 enum SelectionModeType
76 {
77 order, minAllocationProbability, minLoaded, maxLoaded, random
78 };
79 void setSelectionMode(SelectionModeType smt) { selectionMode = smt; }
80 bool setSelectionMode(const QString& smt);
81 SelectionModeType getSelectionMode() const { return selectionMode; }
82
83 QDomElement xmlElement(QDomDocument& doc);
84
85 void setConflictStart(time_t cs) { conflictStart = cs; }
86 time_t getConflictStart() const { return conflictStart; }
87
88 void init()
89 {
90 lockedResource = nullptr;
91 conflictStart = 0;
92 }
93
94 private:
95 /**
96 * Limit values that regulate how many allocations can be made per
97 * day/week/month.
98 */
99 UsageLimits* limits;
100
101 /// The shifts that can limit the allocation to certain intervals.
102 ShiftSelectionList shifts;
103
104 /**
105 * True if the allocation should be persistent over the whole task.
106 * If set the first selection will not be changed even if there is an
107 * available alternative. */
108 bool persistent;
109
110 /**
111 * True if the resource is mandatory. This means, that only if this
112 * allocation can be made, all other allocations will be made. If this
113 * allocation cannot be made for a time slot, no other allocations will be
114 * made for the task.
115 */
116 bool mandatory;
117
118 /// The persistent resource picked by the scheduler.
119 Resource* lockedResource;
120
121 /// Start of a resource conflict. Used during scheduling only.
122 time_t conflictStart;
123
124 /// List of potential resources.
125 QList<Resource*> candidates;
126 /// Map of required resources
127 QMap<Resource*, QList<Resource*> > requiredResources;
128
129 /* The selection mode determines how the resource is selected from
130 * the candidate list. */
131 SelectionModeType selectionMode;
132 } ;
133
134 } // namespace TJ
135
136 #endif