diff --git a/jsprit-core/src/main/java/jsprit/core/reporting/SolutionPrinter.java b/jsprit-core/src/main/java/jsprit/core/reporting/SolutionPrinter.java index d0e1dd45..22abcc1b 100644 --- a/jsprit-core/src/main/java/jsprit/core/reporting/SolutionPrinter.java +++ b/jsprit-core/src/main/java/jsprit/core/reporting/SolutionPrinter.java @@ -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; diff --git a/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleTypeKeyTest.java b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleTypeKeyTest.java new file mode 100644 index 00000000..5dea8ca3 --- /dev/null +++ b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleTypeKeyTest.java @@ -0,0 +1,28 @@ +package jsprit.core.problem.vehicle; + + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class VehicleTypeKeyTest { + + @Test + public void typeIdentifierShouldBeEqual(){ + Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("start").addSkill("skill1").addSkill("skill2") + .addSkill("skill3").build(); + Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("start").addSkill("skill2").addSkill("skill1") + .addSkill("skill3").build(); + assertTrue(v1.getVehicleTypeIdentifier().equals(v2.getVehicleTypeIdentifier())); + } + + @Test + public void typeIdentifierShouldNotBeEqual(){ + Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("start").addSkill("skill1").addSkill("skill2") + .build(); + Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("start").addSkill("skill2").addSkill("skill1") + .addSkill("skill3").build(); + assertFalse(v1.getVehicleTypeIdentifier().equals(v2.getVehicleTypeIdentifier())); + } +}