For this second version of the trolley example, we are interested in finding a "good solution" without a lot of computational effort.
This trade off between quality of the solution and computation time is achieved by limiting the number of fails at each step of the optimization process. When the limit is exceeded, the search is stopped and the last found schedule is returned. The maximal number of fails per optimization step is passed to the program as a parameter.
IloInt failLimit = 1000;
if (argc > 1)
failLimit = atol(argv[1]);
/* ... */
IloBool solved = IloFalse;
IloNum minMakespan = 0.;
IloSolver solver(model);
IloGoal unlimitedGoal = IloSetTimesForward(env, makespan);
IloGoal limitedGoal = IloLimitSearch(env, unlimitedGoal,
IloFailLimit(env,failLimit) );
solver.startNewSearch(limitedGoal);
while (solver.next()==IlcTrue) {
solved = IloTrue;
minMakespan = solver.getMin(makespan);
solver.out() << "SOLUTION WITH MAKESPAN "
<< minMakespan << endl;
}
solver.endSearch();
if (solved){
makespan.setBounds(minMakespan,minMakespan);
solver.solve(unlimitedGoal);
PrintSolution(solver,jobs,trolley,machines,makespan);
} else {
solver.out() << "NO SOLUTION FOUND" << endl;
}