public void visit(TourActivity activity) {
   for (Vehicle vehicle : vehicles) {
     double latestArrTimeAtPrevAct =
         latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()];
     Location prevLocation = location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()];
     double potentialLatestArrivalTimeAtCurrAct =
         latestArrTimeAtPrevAct
             - transportCosts.getBackwardTransportTime(
                 activity.getLocation(),
                 prevLocation,
                 latestArrTimeAtPrevAct,
                 route.getDriver(),
                 vehicle)
             - activity.getOperationTime();
     double latestArrivalTime =
         Math.min(
             activity.getTheoreticalLatestOperationStartTime(),
             potentialLatestArrivalTimeAtCurrAct);
     if (latestArrivalTime < activity.getTheoreticalEarliestOperationStartTime()) {
       stateManager.putTypedInternalRouteState(
           route, vehicle, InternalStates.SWITCH_NOT_FEASIBLE, true);
     }
     stateManager.putInternalTypedActivityState(
         activity, vehicle, InternalStates.LATEST_OPERATION_START_TIME, latestArrivalTime);
     latest_arrTimes_at_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = latestArrivalTime;
     location_of_prevAct[vehicle.getVehicleTypeIdentifier().getIndex()] = activity.getLocation();
   }
 }
Пример #2
0
 private static void printVerbose(
     PrintWriter out, VehicleRoutingProblem problem, VehicleRoutingProblemSolution solution) {
   String leftAlgin = "| %-7s | %-20s | %-21s | %-15s | %-15s | %-15s | %-15s |%n";
   out.format(
       "+--------------------------------------------------------------------------------------------------------------------------------+%n");
   out.printf(
       "| detailed solution                                                                                                              |%n");
   out.format(
       "+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n");
   out.printf(
       "| route   | vehicle              | activity              | job             | arrTime         | endTime         | costs           |%n");
   int routeNu = 1;
   for (VehicleRoute route : solution.getRoutes()) {
     out.format(
         "+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n");
     double costs = 0;
     out.format(
         leftAlgin,
         routeNu,
         getVehicleString(route),
         route.getStart().getName(),
         "-",
         "undef",
         Math.round(route.getStart().getEndTime()),
         Math.round(costs));
     TourActivity prevAct = route.getStart();
     for (TourActivity act : route.getActivities()) {
       String jobId;
       if (act instanceof JobActivity) {
         jobId = ((JobActivity) act).getJob().getId();
       } else {
         jobId = "-";
       }
       double c =
           problem
               .getTransportCosts()
               .getTransportCost(
                   prevAct.getLocation(),
                   act.getLocation(),
                   prevAct.getEndTime(),
                   route.getDriver(),
                   route.getVehicle());
       c +=
           problem
               .getActivityCosts()
               .getActivityCost(act, act.getArrTime(), route.getDriver(), route.getVehicle());
       costs += c;
       out.format(
           leftAlgin,
           routeNu,
           getVehicleString(route),
           act.getName(),
           jobId,
           Math.round(act.getArrTime()),
           Math.round(act.getEndTime()),
           Math.round(costs));
       prevAct = act;
     }
     double c =
         problem
             .getTransportCosts()
             .getTransportCost(
                 prevAct.getLocation(),
                 route.getEnd().getLocation(),
                 prevAct.getEndTime(),
                 route.getDriver(),
                 route.getVehicle());
     c +=
         problem
             .getActivityCosts()
             .getActivityCost(
                 route.getEnd(),
                 route.getEnd().getArrTime(),
                 route.getDriver(),
                 route.getVehicle());
     costs += c;
     out.format(
         leftAlgin,
         routeNu,
         getVehicleString(route),
         route.getEnd().getName(),
         "-",
         Math.round(route.getEnd().getArrTime()),
         "undef",
         Math.round(costs));
     routeNu++;
   }
   out.format(
       "+--------------------------------------------------------------------------------------------------------------------------------+%n");
   if (!solution.getUnassignedJobs().isEmpty()) {
     out.format("+----------------+%n");
     out.format("| unassignedJobs |%n");
     out.format("+----------------+%n");
     String unassignedJobAlgin = "| %-14s |%n";
     for (Job j : solution.getUnassignedJobs()) {
       out.format(unassignedJobAlgin, j.getId());
     }
     out.format("+----------------+%n");
   }
 }