48 bool originalPlanningMode = data->constrainedPlanning;
49 data->constrainedPlanning =
true;
52 bool originalLogConstraints = data->logConstraints;
53 data->logConstraints =
false;
56 Date min_next_date(Date::infiniteFuture);
58 Resource *bestAlternateSelection = NULL;
59 double bestCost = DBL_MAX;
60 bool qualified_resource_exists =
false;
61 double bestAlternateValue = DBL_MAX;
62 double bestAlternateQuantity = DBL_MIN;
66 double originalLoadplanQuantity = lplan->
getQuantity();
70 stack<Resource*> res_stack;
72 while (!res_stack.empty())
89 bool isqualified =
false;
90 for (Resource::skilllist::const_iterator i = res->
getSkills().begin();
91 i != res->
getSkills().end() && !isqualified; ++i)
94 && originalOpplan.start >= i->getEffective().getStart()
95 && originalOpplan.
end <= i->getEffective().getEnd())
99 if (!isqualified)
continue;
101 qualified_resource_exists =
true;
112 try { res->
solve(*
this,data); }
116 data->constrainedPlanning = originalPlanningMode;
117 data->logConstraints = originalLogConstraints;
127 double deltaCost = data->
state->
a_cost - beforeCost;
133 << res <<
"': cost " << deltaCost
134 <<
", penalty " << deltaPenalty << endl;
160 bestAlternateValue = val;
161 bestAlternateSelection = res;
168 << lplan->
getResource() <<
"': not available before "
178 if (!qualified_resource_exists)
179 throw DataException(
"No qualified resource exists for load");
182 if (bestAlternateSelection)
188 << bestAlternateSelection <<
"' " << l->
getSearch() << endl;
194 if (lplan->
getResource() != bestAlternateSelection)
199 bestAlternateSelection->
solve(*
this,data);
202 data->constrainedPlanning = originalPlanningMode;
203 data->logConstraints = originalLogConstraints;
212 data->constrainedPlanning = originalPlanningMode;
215 if (originalLogConstraints)
220 -originalLoadplanQuantity);
222 data->logConstraints = originalLogConstraints;
226 " Alternate load doesn't find supply on any alternate : "
260 list<const Load*> thealternates;
265 if ((i->getAlternate() == x || &*i == x)
267 thealternates.push_back(&*i);
273 bool originalPlanningMode = data->constrainedPlanning;
274 data->constrainedPlanning =
true;
277 bool originalLogConstraints = data->logConstraints;
278 data->logConstraints =
false;
282 Date min_next_date(Date::infiniteFuture);
284 double bestAlternateValue = DBL_MAX;
285 double bestAlternateQuantity = DBL_MIN;
286 const Load* bestAlternateSelection = NULL;
291 for (list<const Load*>::const_iterator i = thealternates.begin();
292 i != thealternates.end();)
294 const Load *curload = *i;
318 data->constrainedPlanning = originalPlanningMode;
319 data->logConstraints = originalLogConstraints;
333 data->constrainedPlanning = originalPlanningMode;
334 data->logConstraints = originalLogConstraints;
340 double deltaCost = data->
state->
a_cost - beforeCost;
343 if (loglevel>1 && search !=
PRIORITY)
346 << curload->
getResource() <<
"': cost " << deltaCost
347 <<
", penalty " << deltaPenalty << endl;
355 << curload->
getResource() <<
"' " << search << endl;
357 data->constrainedPlanning = originalPlanningMode;
358 data->logConstraints = originalLogConstraints;
383 bestAlternateValue = val;
384 bestAlternateSelection = curload;
389 else if (loglevel>1 && search !=
PRIORITY)
392 << curload->
getResource() <<
"': not available before "
401 if (++i != thealternates.end() && loglevel>1 && search ==
PRIORITY)
404 << (*i)->getResource()->getName() <<
"'" << endl;
408 if (!originalPlanningMode && !(search !=
PRIORITY && bestAlternateSelection))
411 data->constrainedPlanning =
false;
412 bestAlternateSelection = *(thealternates.begin());
416 if (!originalPlanningMode || (search !=
PRIORITY && bestAlternateSelection))
422 << bestAlternateSelection->
getResource() <<
"' " << search << endl;
428 if (lplan->
getLoad() != bestAlternateSelection)
429 lplan->
setLoad(bestAlternateSelection);
437 data->constrainedPlanning = originalPlanningMode;
438 data->logConstraints = originalLogConstraints;
447 data->constrainedPlanning = originalPlanningMode;
450 if (originalLogConstraints)
452 const Load *primary = *(thealternates.begin());
456 -originalLoadplanQuantity);
458 data->logConstraints = originalLogConstraints;
462 " Alternate load doesn't find supply on any alternate : "