| 1 |
/* |
| 2 |
* Allocation.cpp - TaskJuggler |
| 3 |
* |
| 4 |
* SPDX-FileCopyrightText: 2001, 2002, 2003, 2004 Chris Schlaeger <[email protected]> |
| 5 |
* SPDX-FileCopyrightText: 2011 Dag Andersen <[email protected]> |
| 6 |
* |
| 7 |
* This program is free software; you can redistribute it and/or modify |
| 8 |
* it under the terms of version 2 of the GNU General Public License as |
| 9 |
* published by the Free Software Foundation. |
| 10 |
* |
| 11 |
* $Id$ |
| 12 |
*/ |
| 13 |
|
| 14 |
// clazy:excludeall=qstring-arg |
| 15 |
#include "Allocation.h" |
| 16 |
|
| 17 |
#include "tjlib-internal.h" |
| 18 |
#include "Resource.h" |
| 19 |
#include "ResourceTreeIterator.h" |
| 20 |
// #include "ReportXML.h" |
| 21 |
#include "UsageLimits.h" |
| 22 |
|
| 23 |
/* -- DTD -- |
| 24 |
<!ELEMENT Allocation (Load, Persistent)> |
| 25 |
<!ELEMENT Load (#PCDATA)> |
| 26 |
<!ELEMENT Persistent (#PCDATA)> |
| 27 |
<!ATTLIST Allocation ResourceID CDATA #REQUIRED> |
| 28 |
/-- DTD --/ |
| 29 |
*/ |
| 30 |
|
| 31 |
namespace TJ |
| 32 |
{ |
| 33 |
|
| 34 |
Allocation::Allocation() : |
| 35 |
limits(nullptr), |
| 36 |
shifts(), |
| 37 |
persistent(false), |
| 38 |
mandatory(false), |
| 39 |
lockedResource(nullptr), |
| 40 |
conflictStart(0), |
| 41 |
candidates(), |
| 42 |
selectionMode(minAllocationProbability) |
| 43 |
{ |
| 44 |
// shifts.setAutoDelete(true); |
| 45 |
} |
| 46 |
|
| 47 |
Allocation::~Allocation() |
| 48 |
{ |
| 49 |
while(!shifts.isEmpty()) delete shifts.takeFirst(); |
| 50 |
delete limits; |
| 51 |
} |
| 52 |
|
| 53 |
Allocation::Allocation(const Allocation& a) : |
| 54 |
limits(a.limits ? new UsageLimits(*a.limits) : nullptr), |
| 55 |
shifts(), |
| 56 |
persistent(a.persistent), |
| 57 |
mandatory(a.mandatory), |
| 58 |
lockedResource(a.lockedResource), |
| 59 |
conflictStart(0), |
| 60 |
candidates(a.candidates), |
| 61 |
selectionMode(a.selectionMode) |
| 62 |
{ |
| 63 |
// shifts.setAutoDelete(true); |
| 64 |
|
| 65 |
for (QListIterator<ShiftSelection*> sli(a.shifts); sli.hasNext();) |
| 66 |
shifts.append(new ShiftSelection(*(sli.next()))); |
| 67 |
} |
| 68 |
|
| 69 |
void |
| 70 |
Allocation::setLimits(UsageLimits* l) |
| 71 |
{ |
| 72 |
delete limits; |
| 73 |
limits = l; |
| 74 |
} |
| 75 |
|
| 76 |
bool |
| 77 |
Allocation::isWorker() const |
| 78 |
{ |
| 79 |
/* For an allocation to be a worker, all allocated resources must have an |
| 80 |
* non zero efficiency. */ |
| 81 |
for (QListIterator<Resource*> cli(candidates); cli.hasNext();) |
| 82 |
if (!cli.next()->isWorker()) |
| 83 |
return false; |
| 84 |
|
| 85 |
return true; |
| 86 |
} |
| 87 |
|
| 88 |
/* Creation of the XML Representation of the Allocation */ |
| 89 |
QDomElement Allocation::xmlElement(QDomDocument& doc) |
| 90 |
{ |
| 91 |
Q_UNUSED(doc); |
| 92 |
QDomElement elem;/* = doc.createElement("Allocation"); |
| 93 |
elem.appendChild(ReportXML::createXMLElem(doc, "Persistent", isPersistent() ? "Yes":"No")); |
| 94 |
elem.setAttribute("ResourceID", candidates.first()->getId());*/ |
| 95 |
|
| 96 |
/* candidates are missing TODO */ |
| 97 |
return elem; |
| 98 |
|
| 99 |
} |
| 100 |
|
| 101 |
bool |
| 102 |
Allocation::setSelectionMode(const QString& smt) |
| 103 |
{ |
| 104 |
if (smt == KW("order")) |
| 105 |
selectionMode = order; |
| 106 |
else if (smt == KW("minallocated")) |
| 107 |
selectionMode = minAllocationProbability; |
| 108 |
else if (smt == KW("minloaded")) |
| 109 |
selectionMode = minLoaded; |
| 110 |
else if (smt == KW("maxloaded")) |
| 111 |
selectionMode = maxLoaded; |
| 112 |
else if (smt == KW("random")) |
| 113 |
selectionMode = random; |
| 114 |
else |
| 115 |
return false; |
| 116 |
return true; |
| 117 |
} |
| 118 |
|
| 119 |
} // namespace TJ |
| 120 |
|
| 121 |
|