1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

Solution with initial vehicle order

This commit is contained in:
braktar 2016-07-04 10:15:00 +02:00
parent 291764e756
commit 108840c6ab
3 changed files with 25 additions and 2 deletions

View file

@ -30,6 +30,8 @@ import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle; import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
import com.graphhopper.jsprit.core.problem.vehicle.VehicleType; import com.graphhopper.jsprit.core.problem.vehicle.VehicleType;
import com.graphhopper.jsprit.core.util.Solutions; import com.graphhopper.jsprit.core.util.Solutions;
import com.graphhopper.jsprit.core.util.VehicleIndexComparator;
import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.XMLConfiguration; import org.apache.commons.configuration.XMLConfiguration;
import org.apache.xml.serialize.OutputFormat; import org.apache.xml.serialize.OutputFormat;
@ -44,6 +46,7 @@ import java.io.IOException;
import java.io.Writer; import java.io.Writer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
@ -188,7 +191,9 @@ public class VrpXMLWriter {
for (VehicleRoutingProblemSolution solution : solutions) { for (VehicleRoutingProblemSolution solution : solutions) {
xmlConfig.setProperty(solutionPath + "(" + counter + ").cost", solution.getCost()); xmlConfig.setProperty(solutionPath + "(" + counter + ").cost", solution.getCost());
int routeCounter = 0; int routeCounter = 0;
for (VehicleRoute route : solution.getRoutes()) { List<VehicleRoute> list = new ArrayList<VehicleRoute>(solution.getRoutes());
Collections.sort(list , new VehicleIndexComparator());
for (VehicleRoute route : list) {
// xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").cost", route.getCost()); // 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 + ").driverId", route.getDriver().getId());
xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").vehicleId", route.getVehicle().getId()); xmlConfig.setProperty(solutionPath + "(" + counter + ").routes.route(" + routeCounter + ").vehicleId", route.getVehicle().getId());
@ -427,3 +432,4 @@ public class VrpXMLWriter {
} }

View file

@ -26,6 +26,9 @@ import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity; import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/** /**
@ -149,7 +152,10 @@ public class SolutionPrinter {
out.format("+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n"); out.format("+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n");
out.printf("| route | vehicle | activity | job | arrTime | endTime | costs |%n"); out.printf("| route | vehicle | activity | job | arrTime | endTime | costs |%n");
int routeNu = 1; int routeNu = 1;
for (VehicleRoute route : solution.getRoutes()) {
List<VehicleRoute> list = new ArrayList<VehicleRoute>(solution.getRoutes());
Collections.sort(list , new com.graphhopper.jsprit.core.util.VehicleIndexComparator());
for (VehicleRoute route : list) {
out.format("+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n"); out.format("+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n");
double costs = 0; double costs = 0;
out.format(leftAlgin, routeNu, getVehicleString(route), route.getStart().getName(), "-", "undef", Math.round(route.getStart().getEndTime()), out.format(leftAlgin, routeNu, getVehicleString(route), route.getStart().getName(), "-", "undef", Math.round(route.getStart().getEndTime()),

View file

@ -0,0 +1,11 @@
package com.graphhopper.jsprit.core.util;
import java.util.Comparator;
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
public class VehicleIndexComparator implements Comparator<VehicleRoute> {
public int compare(VehicleRoute a, VehicleRoute b) {
return a.getVehicle().getIndex() - b.getVehicle().getIndex();
}
}