This problem is solved with IloSetTimesForward
while minimizing makespan
, as for the previous example. The addition of IloSchedulerSolution
to the model makes the solution data available to the program.
/* SET THE MAKESPAN VARIABLE. */
makespan = IloNumVar(env, 0, IloInfinity, ILOINT);
model.add(moving.endsAt(makespan));
/* ... */
IloEnv env;
IloNumVar makespan;
IloDiscreteResource budget;
IloSchedulerSolution solution(env);
IloModel model = DefineModel(env, makespan, budget, solution);
IloSolver solver(model);
IloGoal goal = IloSetTimesForward(env, makespan);
Print the Solution
The function PrintSolution
allows retrieval and printing of the budget resource capacity from solution
, the instance of the class IloSchedulerSolution
.
void PrintSolution(const IloSolver& solver,
const IloSchedulerSolution solution,
const IloNumVar makespan,
const IloDiscreteResource budget)
{
solver.out() << "Solution with makespan "
<< solution.getMin(makespan) << endl << endl;
for (IloSchedulerSolution::ActivityIterator iter(solution);
iter.ok(); ++iter)
{
IloActivity act = *iter;
solver.out() << act.getName();
solver.out() << " [" << solution.getStartMin(act);
if (solution.getStartMin(act) != solution.getStartMax(act))
solver.out() << ".." << solution.getStartMax(act);
solver.out() << " -- "
<< solution.getProcessingTimeMin(act);
solver.out() << " --> " << solution.getEndMin(act);
if (solution.getEndMin(act) != solution.getEndMax(act))
solver.out() << ".." << solution.getEndMax(act);
solver.out() << "]" << endl;
}
solver.out() << endl;
solver.out() << budget << endl;
solver.out() << endl;
for (IloNumToNumStepFunctionCursor iter1(solution.getLevelMin(budget));
iter1.ok(); ++iter1) {
solver.out() << "date "
<< iter1.getSegmentMin()
<< " amount "
<< iter1.getValue() << endl;
}
}