2 * Allocation.cpp - TaskJuggler
4 * Copyright (c) 2001, 2002, 2003, 2004 by Chris Schlaeger <cs@kde.org>
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.
13 #include "Allocation.h"
15 #include "tjlib-internal.h"
17 #include "ResourceTreeIterator.h"
18 #include "ReportXML.h"
19 #include "UsageLimits.h"
22 <!ELEMENT Allocation (Load, Persistent)>
23 <!ELEMENT Load (#PCDATA)>
24 <!ELEMENT Persistent (#PCDATA)>
25 <!ATTLIST Allocation ResourceID CDATA #REQUIRED>
29 Allocation::Allocation() :
37 selectionMode(minAllocationProbability)
39 shifts.setAutoDelete(true);
42 Allocation::~Allocation()
47 Allocation::Allocation(const Allocation& a) :
48 limits(a.limits ? new UsageLimits(*a.limits) : 0),
50 persistent(a.persistent),
51 mandatory(a.mandatory),
52 lockedResource(a.lockedResource),
54 candidates(a.candidates),
55 selectionMode(a.selectionMode)
57 shifts.setAutoDelete(true);
59 for (Q3PtrListIterator<ShiftSelection> sli(a.shifts); *sli; ++sli)
60 shifts.append(new ShiftSelection(**sli));
64 Allocation::setLimits(UsageLimits* l)
71 Allocation::isWorker() const
73 /* For an allocation to be a worker, all allocated resources must have an
74 * non zero efficiency. */
75 for (Q3PtrListIterator<Resource> cli(candidates); *cli; ++cli)
76 if (!(*cli)->isWorker())
82 /* Creation of the XML Reprsentation of the Allocation */
83 QDomElement Allocation::xmlElement( QDomDocument& doc )
85 QDomElement elem = doc.createElement( "Allocation" );
86 elem.appendChild(ReportXML::createXMLElem( doc, "Persistent", isPersistent() ? "Yes":"No" ));
87 elem.setAttribute( "ResourceID", candidates.getFirst()->getId());
89 /* candidates are missing TODO */
95 Allocation::setSelectionMode(const QString& smt)
97 if (smt == KW("order"))
98 selectionMode = order;
99 else if (smt == KW("minallocated"))
100 selectionMode = minAllocationProbability;
101 else if (smt == KW("minloaded"))
102 selectionMode = minLoaded;
103 else if (smt == KW("maxloaded"))
104 selectionMode = maxLoaded;
105 else if (smt == KW("random"))
106 selectionMode = random;