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

added skills

This commit is contained in:
oblonski 2014-07-29 14:02:14 +02:00
parent ea7407d936
commit f56d735b83
2 changed files with 66 additions and 29 deletions

View file

@ -24,6 +24,7 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity;
import jsprit.core.problem.vehicle.PenaltyVehicleType;
/**
* Printer to print the details of a vehicle-routing-problem solution.
@ -49,7 +50,7 @@ public class SolutionPrinter {
/**
* Prints costs and #vehicles to stdout (System.out.println).
*
* @param solution
* @param solution the solution to be printed
*/
public static void print(VehicleRoutingProblemSolution solution){
System.out.println("[costs="+solution.getCost() + "]");
@ -100,36 +101,44 @@ public class SolutionPrinter {
}
private static void printVerbose(VehicleRoutingProblem problem, VehicleRoutingProblemSolution solution) {
String leftAlgin = "| %-7s | %-20s | %-21s | %-15s | %-15s | %-15s | %-15s |%n";
System.out.format("+--------------------------------------------------------------------------------------------------------------------------------+%n");
System.out.printf("| detailed solution |%n");
System.out.format("+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n");
System.out.printf("| route | vehicle | activity | job | arrTime | endTime | costs |%n");
int routeNu = 1;
for(VehicleRoute route : solution.getRoutes()){
System.out.format("+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n");
double costs = 0;
System.out.format(leftAlgin, routeNu, route.getVehicle().getId(), 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.getLocationId(), act.getLocationId(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
c+= problem.getActivityCosts().getActivityCost(act, act.getArrTime(), route.getDriver(), route.getVehicle());
costs+=c;
System.out.format(leftAlgin, routeNu, route.getVehicle().getId(), act.getName(), jobId, Math.round(act.getArrTime()), Math.round(act.getEndTime()),Math.round(costs));
prevAct=act;
}
double c = problem.getTransportCosts().getTransportCost(prevAct.getLocationId(), route.getEnd().getLocationId(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
c+= problem.getActivityCosts().getActivityCost(route.getEnd(), route.getEnd().getArrTime(), route.getDriver(), route.getVehicle());
costs+=c;
System.out.format(leftAlgin, routeNu, route.getVehicle().getId(), route.getEnd().getName(), "-", Math.round(route.getEnd().getArrTime()), "undef", Math.round(costs));
routeNu++;
}
System.out.format("+--------------------------------------------------------------------------------------------------------------------------------+%n");
String leftAlgin = "| %-7s | %-20s | %-21s | %-15s | %-15s | %-15s | %-15s |%n";
System.out.format("+--------------------------------------------------------------------------------------------------------------------------------+%n");
System.out.printf("| detailed solution |%n");
System.out.format("+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n");
System.out.printf("| route | vehicle | activity | job | arrTime | endTime | costs |%n");
int routeNu = 1;
for(VehicleRoute route : solution.getRoutes()){
System.out.format("+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n");
double costs = 0;
System.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.getLocationId(), act.getLocationId(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
c+= problem.getActivityCosts().getActivityCost(act, act.getArrTime(), route.getDriver(), route.getVehicle());
costs+=c;
System.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.getLocationId(), route.getEnd().getLocationId(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
c+= problem.getActivityCosts().getActivityCost(route.getEnd(), route.getEnd().getArrTime(), route.getDriver(), route.getVehicle());
costs+=c;
System.out.format(leftAlgin, routeNu, getVehicleString(route), route.getEnd().getName(), "-", Math.round(route.getEnd().getArrTime()), "undef", Math.round(costs));
routeNu++;
}
System.out.format("+*:=PenaltyVehicle+%n");
System.out.format("+--------------------------------------------------------------------------------------------------------------------------------+%n");
}
private static String getVehicleString(VehicleRoute route) {
if(route.getVehicle().getType() instanceof PenaltyVehicleType){
return route.getVehicle().getId()+"*";
}
return route.getVehicle().getId();
}
private static Jobs getNuOfJobs(VehicleRoutingProblem problem) {
int nShipments = 0;
int nServices = 0;