IBM ILOG Dispatcher User's Manual > The Basics > Minimizing the Number of Vehicles > Solve > Define the getShortestRoute function

Now you locate the vehicle with the smallest number of visits, since this is vehicle that you will want to empty. An IloIterator is used to search through the vehicles in the problem. The member function IloRoutingSolution::getRouteSize returns the number of visits in the stored route of each vehicle.

Step 10   -  

Find the vehicle with the shortest route

Add the following code after the comment
//Find the vehicle with the shortest route

IloVehicle RoutingSolver::getShortestRoute() {
  IloInt bestSize = 1000000;
  IloVehicle bestVehicle;
  for (IloIterator<IloVehicle> iter(_env); iter.ok(); ++iter) {
    IloVehicle vehicle = *iter;
    IloInt size = _solution.getRouteSize(vehicle);
    if (size < bestSize && size != 0) {
      bestSize = size;
      bestVehicle = vehicle;
    }
  }
  return bestVehicle;
}