private double getDeltaAbsoluteFixCost(VehicleRoute route, Vehicle newVehicle, Job job) {
   Capacity load = Capacity.addup(getCurrentMaxLoadInRoute(route), job.getSize());
   //		double load = getCurrentMaxLoadInRoute(route) + job.getCapacityDemand();
   double currentFix = 0.0;
   if (route.getVehicle() != null) {
     if (!(route.getVehicle() instanceof NoVehicle)) {
       currentFix += route.getVehicle().getType().getVehicleCostParams().fix;
     }
   }
   if (!newVehicle.getType().getCapacityDimensions().isGreaterOrEqual(load)) {
     return Double.MAX_VALUE;
   }
   return newVehicle.getType().getVehicleCostParams().fix - currentFix;
 }
Exemplo n.º 2
0
 private void writeInitialRoutes(XMLConf xmlConfig) {
   if (vrp.getInitialVehicleRoutes().isEmpty()) return;
   String path = "initialRoutes.route";
   int routeCounter = 0;
   for (VehicleRoute route : vrp.getInitialVehicleRoutes()) {
     xmlConfig.setProperty(path + "(" + routeCounter + ").driverId", route.getDriver().getId());
     xmlConfig.setProperty(path + "(" + routeCounter + ").vehicleId", route.getVehicle().getId());
     xmlConfig.setProperty(path + "(" + routeCounter + ").start", route.getStart().getEndTime());
     int actCounter = 0;
     for (TourActivity act : route.getTourActivities().getActivities()) {
       xmlConfig.setProperty(
           path + "(" + routeCounter + ").act(" + actCounter + ")[@type]", act.getName());
       if (act instanceof JobActivity) {
         Job job = ((JobActivity) act).getJob();
         if (job instanceof Service) {
           xmlConfig.setProperty(
               path + "(" + routeCounter + ").act(" + actCounter + ").serviceId", job.getId());
         } else if (job instanceof Shipment) {
           xmlConfig.setProperty(
               path + "(" + routeCounter + ").act(" + actCounter + ").shipmentId", job.getId());
         } else {
           throw new IllegalStateException(
               "cannot write solution correctly since job-type is not know. make sure you use either service or shipment, or another writer");
         }
       }
       xmlConfig.setProperty(
           path + "(" + routeCounter + ").act(" + actCounter + ").arrTime", act.getArrTime());
       xmlConfig.setProperty(
           path + "(" + routeCounter + ").act(" + actCounter + ").endTime", act.getEndTime());
       actCounter++;
     }
     xmlConfig.setProperty(path + "(" + routeCounter + ").end", route.getEnd().getArrTime());
     routeCounter++;
   }
 }
Exemplo n.º 3
0
  public void insertJob(Job job, InsertionData insertionData, VehicleRoute vehicleRoute) {
    insertionListeners.informBeforeJobInsertion(job, insertionData, vehicleRoute);

    if (insertionData == null || (insertionData instanceof NoInsertionFound))
      throw new IllegalStateException("insertionData null. cannot insert job.");
    if (job == null) throw new IllegalStateException("cannot insert null-job");
    if (!(vehicleRoute.getVehicle().getId().equals(insertionData.getSelectedVehicle().getId()))) {
      insertionListeners.informVehicleSwitched(
          vehicleRoute, vehicleRoute.getVehicle(), insertionData.getSelectedVehicle());
      vehicleRoute.setVehicleAndDepartureTime(
          insertionData.getSelectedVehicle(), insertionData.getVehicleDepartureTime());
    }
    jobInsertionHandler.handleJobInsertion(job, insertionData, vehicleRoute);

    insertionListeners.informJobInserted(
        job, vehicleRoute, insertionData.getInsertionCost(), insertionData.getAdditionalTime());
  }
 @Override
 public void informInsertionEnds(Collection<VehicleRoute> vehicleRoutes) {
   List<VehicleRoute> routes = new ArrayList<VehicleRoute>(vehicleRoutes);
   for (VehicleRoute route : routes) {
     if (route.isEmpty()) {
       fleetManager.unlock(route.getVehicle());
       vehicleRoutes.remove(route);
     }
   }
 }
 private double getDeltaRelativeFixCost(VehicleRoute route, Vehicle newVehicle, Job job) {
   Capacity currentLoad = getCurrentMaxLoadInRoute(route);
   //		int currentLoad = getCurrentMaxLoadInRoute(route);
   Capacity load = Capacity.addup(currentLoad, job.getSize());
   //		double load = currentLoad + job.getCapacityDemand();
   double currentRelFix = 0.0;
   if (route.getVehicle() != null) {
     if (!(route.getVehicle() instanceof NoVehicle)) {
       currentRelFix +=
           route.getVehicle().getType().getVehicleCostParams().fix
               * Capacity.divide(
                   currentLoad, route.getVehicle().getType().getCapacityDimensions());
     }
   }
   if (!newVehicle.getType().getCapacityDimensions().isGreaterOrEqual(load)) {
     return Double.MAX_VALUE;
   }
   double relativeFixCost =
       newVehicle.getType().getVehicleCostParams().fix
               * (Capacity.divide(load, newVehicle.getType().getCapacityDimensions()))
           - currentRelFix;
   return relativeFixCost;
 }
Exemplo n.º 6
0
 private void writeSolutions(XMLConf xmlConfig) {
   if (solutions == null) return;
   String solutionPath = "solutions.solution";
   int counter = 0;
   for (VehicleRoutingProblemSolution solution : solutions) {
     xmlConfig.setProperty(solutionPath + "(" + counter + ").cost", solution.getCost());
     int routeCounter = 0;
     for (VehicleRoute route : solution.getRoutes()) {
       //				xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter
       // + ").cost", route.getCost());
       xmlConfig.setProperty(
           solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").driverId",
           route.getDriver().getId());
       xmlConfig.setProperty(
           solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").vehicleId",
           route.getVehicle().getId());
       xmlConfig.setProperty(
           solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").start",
           route.getStart().getEndTime());
       int actCounter = 0;
       for (TourActivity act : route.getTourActivities().getActivities()) {
         xmlConfig.setProperty(
             solutionPath
                 + "("
                 + counter
                 + ").routes.route("
                 + routeCounter
                 + ").act("
                 + actCounter
                 + ")[@type]",
             act.getName());
         if (act instanceof JobActivity) {
           Job job = ((JobActivity) act).getJob();
           if (job instanceof Service) {
             xmlConfig.setProperty(
                 solutionPath
                     + "("
                     + counter
                     + ").routes.route("
                     + routeCounter
                     + ").act("
                     + actCounter
                     + ").serviceId",
                 job.getId());
           } else if (job instanceof Shipment) {
             xmlConfig.setProperty(
                 solutionPath
                     + "("
                     + counter
                     + ").routes.route("
                     + routeCounter
                     + ").act("
                     + actCounter
                     + ").shipmentId",
                 job.getId());
           } else {
             throw new IllegalStateException(
                 "cannot write solution correctly since job-type is not know. make sure you use either service or shipment, or another writer");
           }
         }
         xmlConfig.setProperty(
             solutionPath
                 + "("
                 + counter
                 + ").routes.route("
                 + routeCounter
                 + ").act("
                 + actCounter
                 + ").arrTime",
             act.getArrTime());
         xmlConfig.setProperty(
             solutionPath
                 + "("
                 + counter
                 + ").routes.route("
                 + routeCounter
                 + ").act("
                 + actCounter
                 + ").endTime",
             act.getEndTime());
         actCounter++;
       }
       xmlConfig.setProperty(
           solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").end",
           route.getEnd().getArrTime());
       routeCounter++;
     }
     int unassignedJobCounter = 0;
     for (Job unassignedJob : solution.getUnassignedJobs()) {
       xmlConfig.setProperty(
           solutionPath
               + "("
               + counter
               + ").unassignedJobs.job("
               + unassignedJobCounter
               + ")[@id]",
           unassignedJob.getId());
       unassignedJobCounter++;
     }
     counter++;
   }
 }
 @Override
 public Collection<Vehicle> get(VehicleRoute route) {
   return Arrays.asList(route.getVehicle());
 }
Exemplo n.º 8
0
 private static String getVehicleString(VehicleRoute route) {
   return route.getVehicle().getId();
 }
Exemplo n.º 9
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");
   }
 }