40 addPythonRule, METH_VARARGS | METH_KEYWORDS,
"add a new setup rule");
55 x.
setDoc(
"frePPLe setupmatrixrule");
68 "setupmatrix_default",
69 Object::createString<SetupMatrixDefault>,
true);
80 while (firstRule)
delete firstRule;
84 if (m->getSetupMatrix() ==
this) m->setSetupMatrix(NULL);
130 Rule* result = firstRule;
131 while (result && priority > result->priority)
132 result = result->nextRule;
133 if (result && result->priority != priority) result = NULL;
136 switch (MetaClass::decodeAction(atts))
143 o <<
"Rule with priority " << priority
144 <<
" already exists in setup matrix '" <<
getName() <<
"'";
147 result =
new Rule(
this, priority);
154 o <<
"No rule with priority " << priority
155 <<
" exists in setup matrix '" <<
getName() <<
"'";
164 o <<
"No rule with priority " << priority
165 <<
" exists in setup matrix '" <<
getName() <<
"'";
177 result =
new Rule(
this, priority);
218 if (!matrix)
throw LogicException(
"Can't add a rule to a NULL setupmatrix");
222 PyObject *pyfrom = NULL;
223 PyObject *pyto = NULL;
226 static const char *kwlist[] = {
"priority",
"fromsetup",
"tosetup",
"duration",
"cost", NULL};
227 if (!PyArg_ParseTupleAndKeywords(args, kwdict,
229 const_cast<char**>(kwlist), &prio, &pyfrom, &pyto, &duration, &cost))
242 PythonType::evalException();
249 : cost(0), priority(p), matrix(s), nextRule(NULL), prevRule(NULL)
252 if (!matrix)
throw DataException(
"Can't add a rule to NULL setup matrix");
255 Rule *next = matrix->firstRule, *prev = NULL;
256 while (next && p > next->priority)
259 next = next->nextRule;
263 if (next && next->priority == p)
264 throw DataException(
"Multiple rules with identical priority in setup matrix");
269 if (prev) prev->nextRule =
this;
270 else matrix->firstRule =
this;
271 if (next) next->prevRule =
this;
281 if (nextRule) nextRule->prevRule = prevRule;
282 if (prevRule) prevRule->nextRule = nextRule;
283 else matrix->firstRule = nextRule;
302 setPriority(pElement.
getInt());
335 setPriority(field.
getInt());
356 while (prevRule && priority < prevRule->priority)
358 Rule* next = nextRule;
359 Rule* prev = prevRule;
360 if (prev && prev->prevRule) prev->prevRule->nextRule =
this;
361 else matrix->firstRule =
this;
362 if (prev) prev->nextRule = nextRule;
364 prevRule = prev ? prev->prevRule : NULL;
365 if (next && next->nextRule) next->nextRule->prevRule = prev;
366 if (next) next->prevRule = prev;
367 if (prev) prev->prevRule =
this;
371 while (nextRule && priority > nextRule->priority)
373 Rule* next = nextRule;
374 Rule* prev = prevRule;
375 nextRule = next->nextRule;
376 if (next && next->nextRule) next->nextRule->prevRule =
this;
377 if (prev) prev->nextRule = next;
378 if (next) next->nextRule =
this;
379 if (next) next->prevRule = prev;
384 if ((prevRule && prevRule->priority == priority)
385 || (nextRule && nextRule->priority == priority))
388 o <<
"Duplicate priority " << priority <<
" in setup matrix '"
389 << matrix->getName() <<
"'";
399 x.
setName(
"setupmatrixRuleIterator");
400 x.
setDoc(
"frePPLe iterator for setupmatrix rules");
406 PyObject* SetupMatrixRuleIterator::iternext()
408 if (currule == matrix->endRules())
return NULL;
409 PyObject *result = &*(currule++);
416 (
const string oldsetup,
const string newsetup)
const
419 if (oldsetup == newsetup)
return NULL;
422 for (
Rule *curRule = firstRule; curRule; curRule = curRule->nextRule)
425 if (!curRule->getFromSetup().empty()
426 && !
matchWildcard(curRule->getFromSetup().c_str(), oldsetup.c_str()))
429 if (!curRule->getToSetup().empty()
430 && !
matchWildcard(curRule->getToSetup().c_str(), newsetup.c_str()))
437 logger <<
"Warning: Conversion from '" << oldsetup <<
"' to '" << newsetup
438 <<
"' undefined in setup matrix '" <<
getName() << endl;