52 Object::createString<OperationFixedTime>,
true);
63 Object::createString<OperationTimePer>);
74 Object::createString<OperationAlternate>);
86 Object::createString<OperationRouting>);
121 if (k->getOperation() ==
this) k->setOperation(NULL);
125 if (l->getOperation() ==
this) l->setOperation(NULL);
129 if (m->getProducingOperation() ==
this) m->setProducingOperation(NULL);
162 bool makeflowsloads)
const
176 vector<Calendar::EventIterator*> cals(10);
179 if (actualduration) *actualduration = duration;
185 if (loc && loc->getAvailable())
211 DateRange(thedate-duration, thedate);
216 Date curdate = thedate;
222 bool available =
true;
223 for (
int c = 0; c < calcount && available; c++)
229 available = cals[c]->getCalendar()->getBool();
231 curdate = cals[0]->getDate();
233 if (available && !status)
238 if (forward && result.
getStart() == Date::infinitePast)
241 else if (!forward && result.
getEnd() == Date::infiniteFuture)
245 else if (!available && status)
253 if (delta >= curduration)
255 result.
setEnd(thedate + curduration);
259 curduration -= delta;
265 if (delta >= curduration)
267 result.
setStart(thedate - curduration);
271 curduration -= delta;
274 else if (forward && curdate == Date::infiniteFuture)
280 if (delta >= curduration)
281 result.
setEnd(thedate + curduration);
282 else if (actualduration)
283 *actualduration = duration - curduration;
285 else if (actualduration)
286 *actualduration = duration - curduration;
289 else if (!forward && curdate == Date::infinitePast)
295 if (delta >= curduration)
296 result.
setStart(thedate - curduration);
297 else if (actualduration)
298 *actualduration = duration - curduration;
300 else if (actualduration)
301 *actualduration = duration - curduration;
306 if (forward) ++(*cals[0]);
311 while (calcount)
delete cals[--calcount];
317 while (calcount)
delete cals[calcount--];
337 vector<Calendar::EventIterator*> cals(10);
340 if (actualduration) *actualduration = 0L;
346 if (loc && loc->getAvailable())
371 if (actualduration) *actualduration = end - start;
378 Date curdate = start;
383 bool available =
true;
384 for (
int c = 0; c < calcount && available; c++)
386 if (cals[c]->getBucket())
387 available = cals[c]->getBucket()->getBool();
389 available = cals[c]->getCalendar()->getBool();
391 curdate = cals[0]->getDate();
393 if (available && !status)
404 if (result.
getStart() == Date::infinitePast)
408 else if (!available && status)
414 if (actualduration) *actualduration += end - start;
419 if (actualduration) *actualduration += curdate - start;
422 else if (curdate >= end)
427 if (actualduration) *actualduration += end - start;
441 while (calcount)
delete cals[--calcount];
447 while (calcount)
delete cals[calcount--];
456 unsigned long i,
bool makeflowsloads)
const
458 opplan->oper =
const_cast<Operation*
>(
this);
500 if (size_minimum != 1.0)
502 if (size_multiple > 0.0)
504 if (size_maximum < DBL_MAX)
565 else throw LogicException(
"Incorrect object type during read operation");
581 throw LogicException(
"Incorrect parameters for fixedtime operationplan");
587 if (q > 0 && q < getSizeMinimum()) q = getSizeMinimum();
588 if (q > getSizeMaximum()) q = getSizeMaximum();
597 if (preferEnd) x = calculateOperationTime(e, duration,
false, &actualduration);
598 else x = calculateOperationTime(s, duration,
true, &actualduration);
600 else if (s) x = calculateOperationTime(s, duration,
true, &actualduration);
601 else x = calculateOperationTime(e, duration,
false, &actualduration);
605 else if (actualduration == duration)
645 while (fp1 != o->endFlowPlans())
664 while (fp1 != o->endFlowPlans())
718 throw LogicException(
"Incorrect parameters for timeper operationplan");
723 if (q > 0 && q < getSizeMinimum()) q = getSizeMinimum();
724 if (q > getSizeMaximum()) q = getSizeMaximum();
733 x = calculateOperationTime(s,e,&actual);
734 if (actual < duration)
747 if (q * duration_per < static_cast<double>(actual - duration) + 1)
754 static_cast<double>(actual - duration) / duration_per,
755 true,
false, execute);
763 duration + static_cast<long>(duration_per * q)
765 if (preferEnd) x = calculateOperationTime(e, wanted,
false, &actual);
766 else x = calculateOperationTime(s, wanted,
true, &actual);
778 TimePeriod wanted(duration + static_cast<long>(duration_per * q));
779 x = calculateOperationTime(e, wanted,
false, &actual);
780 if (actual == wanted)
786 else if (actual < duration)
796 double max_q = duration_per ?
797 static_cast<double>(actual-duration) / duration_per :
799 q = opplan->
setQuantity(q < max_q ? q : max_q,
true,
false, execute);
800 wanted = duration +
static_cast<long>(duration_per * q);
801 x = calculateOperationTime(e, wanted,
false, &actual);
812 duration + static_cast<long>(duration_per * q)
815 x = calculateOperationTime(s, wanted,
true, &actual);
816 if (actual == wanted)
822 else if (actual < duration)
832 double max_q = duration_per ?
833 static_cast<double>(actual-duration) / duration_per :
835 q = opplan->
setQuantity(q < max_q ? q : max_q,
true,
false, execute);
836 wanted = duration +
static_cast<long>(duration_per * q);
837 x = calculateOperationTime(e, wanted,
false, &actual);
902 for (Operationlist::const_iterator i = steps.begin(); i!=steps.end(); ++i)
926 else throw LogicException(
"Incorrect object type during read operation");
937 throw LogicException(
"Incorrect parameters for routing operationplan");
958 bool realfirst =
true;
962 for (
OperationPlan* i = opplan->lastsubopplan; i; i = i->prevsubopplan)
965 x = i->getOperation()->setOperationPlanParameters(i,q,Date::infinitePast,e,preferEnd,execute);
978 for (
OperationPlan *i = opplan->firstsubopplan; i; i = i->nextsubopplan)
981 x = i->getOperation()->setOperationPlanParameters(i,q,s,Date::infinitePast,preferEnd,execute);
993 "Updating a routing operationplan without start or end date argument"
1006 if (d != Date::infiniteFuture)
1009 for (Operation::Operationlist::const_reverse_iterator e =
1013 d, NULL, o, 0,
true);
1023 for (Operation::Operationlist::const_iterator e =
1027 Date::infinitePast, NULL, o, 0,
true);
1038 if (c ==
"PRIORITY")
return PRIORITY;
1039 if (c ==
"MINCOST")
return MINCOST;
1050 Operationlist::iterator altIter = alternates.begin();
1051 alternatePropertyList::iterator propIter = alternateProperties.begin();
1052 while (altIter!=alternates.end() && prio >= propIter->first)
1058 alternates.insert(altIter,o);
1068 suboperation of alternate operation '" +
getName() +
"'");
1069 Operationlist::const_iterator altIter = alternates.begin();
1070 alternatePropertyList::const_iterator propIter = alternateProperties.begin();
1071 while (altIter!=alternates.end() && *altIter != o)
1076 if (*altIter == o)
return *propIter;
1078 "' isn't a suboperation of alternate operation '" +
getName() +
"'");
1085 Operationlist::const_iterator altIter = alternates.begin();
1086 alternatePropertyList::iterator propIter = alternateProperties.begin();
1087 while (altIter!=alternates.end() && *altIter != o)
1093 propIter->first = f;
1096 "' isn't a suboperation of alternate operation '" +
getName() +
"'");
1103 Operationlist::const_iterator altIter = alternates.begin();
1104 alternatePropertyList::iterator propIter = alternateProperties.begin();
1105 while (altIter!=alternates.end() && *altIter != o)
1111 propIter->second = dr;
1114 "' isn't a suboperation of alternate operation '" +
getName() +
"'");
1140 alternatePropertyList::const_iterator propIter = alternateProperties.begin();
1141 for (Operationlist::const_iterator i = alternates.begin();
1142 i != alternates.end(); ++i)
1147 if (propIter->second.getStart() != Date::infinitePast)
1149 if (propIter->second.getEnd() != Date::infiniteFuture)
1173 typedef pair<Operation*,alternateProperty> tempData;
1178 tempData* tmp =
static_cast<tempData*
>(pIn.
getUserArea());
1182 addAlternate(tmp->first, tmp->second.first, tmp->second.second);
1185 tmp->second.first = 1;
1189 tmp->second.first = pElement.
getInt();
1193 tmp->second.second.setStart(pElement.
getDate());
1195 tmp->second.second.setEnd(pElement.
getDate());
1200 if (b) tmp->first = b;
1201 else throw LogicException(
"Incorrect object type during read operation");
1217 throw LogicException(
"Incorrect parameters for alternate operationplan");
1223 x = x->prevsubopplan;
1255 if (props.first != 0.0 && props.second.within(o->
getDates().
getEnd()))
1260 (*altIter)->createOperationPlan(
1270 Operationlist::iterator altIter = alternates.begin();
1271 alternatePropertyList::iterator propIter = alternateProperties.begin();
1272 while (altIter!=alternates.end() && *altIter != o)
1279 alternates.erase(altIter);
1280 alternateProperties.erase(propIter);
1281 o->superoplist.remove(
this);
1285 logger <<
"Warning: operation '" << *o
1286 <<
"' isn't a suboperation of alternate operation '" << *
this
1304 throw LogicException(
"Setup operationplan always must have an owner");
1307 if (g->getResource()->getSetupMatrix() && !g->getSetup().empty())
1309 ldplan =
new LoadPlan(opplan, &*g);
1318 const Load* lastld = NULL;
1319 Date boundary = s ? s : e;
1320 if (ldplan->
getDate() < boundary)
1366 if (preferEnd) x = calculateOperationTime(e, duration,
false, &actualduration);
1367 else x = calculateOperationTime(s, duration,
true, &actualduration);
1369 else if (s) x = calculateOperationTime(s, duration,
true, &actualduration);
1370 else x = calculateOperationTime(e, duration,
false, &actualduration);
1374 else if (actualduration == duration)
1549 if (!altoper)
throw LogicException(
"Can't add alternates to NULL alternate");
1552 PyObject *oper = NULL;
1554 PyObject *eff_start = NULL;
1555 PyObject *eff_end = NULL;
1556 static const char *kwlist[] = {
"operation",
"priority",
"effective_start",
"effective_end", NULL};
1557 if (!PyArg_ParseTupleAndKeywords(args, kwdict,
1558 "O|iOO:addAlternate",
1559 const_cast<char**>(kwlist), &oper, &prio, &eff_start, &eff_end))
1562 throw DataException(
"alternate operation must be of type operation");
1576 altoper->
addAlternate(static_cast<Operation*>(oper), prio, eff);
1580 PythonType::evalException();
1583 return Py_BuildValue(
"");
1607 if (!oper)
throw LogicException(
"Can't add steps to NULL routing");
1611 for (
unsigned int i=0; i<4; ++i) steps[i] = NULL;
1612 if (PyArg_UnpackTuple(args,
"addStep", 1, 4, &steps[0], &steps[1], &steps[2], &steps[3]))
1613 for (
unsigned int i=0; i<4 && steps[i]; ++i)
1616 throw DataException(
"routing steps must be of type operation");
1617 oper->
addStepBack(static_cast<Operation*>(steps[i]));
1622 PythonType::evalException();
1625 return Py_BuildValue(
"");