In addition to the critical path calculation, another requirement of the neighborhood implemented in this example is to be able to access both the next and previous resource constraints for each resource constraint in a solution. The next resource constraints are directly stored in an IloSchedulerSolution
. There is, however, no direct representation of the previous resource constraints. Therefore, we need a function that, given a solution, calculates the previous resource constraints. Since we have the next resource constraints in the solution, this is easy to do.
void CalculatePrevs(IloSchedulerSolution soln) {
// reset prev pointers
for(IloSchedulerSolution::ResourceIterator resIter(soln);
resIter.ok(); ++resIter) {
assert(soln.hasSetupRC(*resIter));
IloResourceConstraint rc = soln.getSetupRC(*resIter);
// setup has no prev
rc.setObject(0);
while(soln.hasNextRC(rc)) {
IloResourceConstraint next = soln.getNextRC(rc);
next.setObject(rc.getImpl());
rc = next;
}
}
}
|