IBM ILOG Dispatcher User's Manual > Developing Dispatcher Applications > Developing Your Own First Solution Heuristics > Creating your own first solution heuristic > Building a Complete Solution

The last goal to be written recursively chooses a vehicle and builds its route. It considers the visits which have not yet been assigned to any vehicle by the end of the search and marks those visits as "unperformed." Choosing a vehicle is done by iterating over all vehicles and finding one which has an incomplete route and which has the largest capacity for dimension dim.

IloVehicle ChooseLargestVehicle(IloDispatcher dispatcher, IloDimension1 dim) {
  IloEnv env = dispatcher.getEnv();
  IloVehicle bestVehicle;
  IloNum bestCapacity = - IloInfinity;
  for (IloIterator<IloVehicle> vehIter(env); vehIter.ok(); ++vehIter) {
    IloVehicle vehicle = *vehIter;
    IloNum capa = vehicle.getCapacity(dim);
    if (capa > bestCapacity && !dispatcher.isRouteComplete(vehicle)) {
      bestVehicle = vehicle;
      bestCapacity = capa;
    }
  }
  return bestVehicle;
}

Building a route for the selected vehicle is done using the goals described in the preceding sections. The search ends by making unassigned visits unperformed when all open vehicles have been used.

ILCGOAL0(UnperformVisits) {
  IloSolver solver = getSolver();
  IloDispatcher dispatcher(solver);
  IloEnv env = dispatcher.getEnv();
  for (IloIterator<IloVisit> visIter(env); visIter.ok(); ++visIter) {
    IloVisit visit = *visIter;
    if (!dispatcher.getVehicleVar(visit).isBound())
      solver.add(dispatcher.unperformed(visit));
  }
  return 0;
}

In order to have more propagation from the path constraints during search the filter level is set to IlcBasic.

ILCGOAL1(Ilc_GenerateFirstSolution, IloDimension1, dim) {
  IloSolver solver = getSolver();
  IloDispatcher dispatcher(solver);
  dispatcher.setFilterLevel(IlcBasic);
  IloVehicle vehicle = ChooseLargestVehicle(dispatcher, dim);
  if (vehicle.getImpl() == 0) return UnperformVisits(solver);
  return IlcAnd(Ilc_VehicleGenerateSolution(solver, vehicle), this);
}

To use this goal, a subclass of IlcGoal, in your Concert Technology modeling environment you wrap it using the Solver ILOCPGOALWRAPPER macro.

ILOCPGOALWRAPPER1(GenerateFirstSolution, solver, IloDimension1, dim) {
  return Ilc_GenerateFirstSolution(solver, dim);
}

Note
This approach can be adapted to the user's needs by customizing the functions selecting the vehicles and the visits.