mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
added skills
This commit is contained in:
parent
ea7407d936
commit
f56d735b83
2 changed files with 66 additions and 29 deletions
|
|
@ -24,6 +24,7 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||||
import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity;
|
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.
|
* 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).
|
* Prints costs and #vehicles to stdout (System.out.println).
|
||||||
*
|
*
|
||||||
* @param solution
|
* @param solution the solution to be printed
|
||||||
*/
|
*/
|
||||||
public static void print(VehicleRoutingProblemSolution solution){
|
public static void print(VehicleRoutingProblemSolution solution){
|
||||||
System.out.println("[costs="+solution.getCost() + "]");
|
System.out.println("[costs="+solution.getCost() + "]");
|
||||||
|
|
@ -109,7 +110,7 @@ public class SolutionPrinter {
|
||||||
for(VehicleRoute route : solution.getRoutes()){
|
for(VehicleRoute route : solution.getRoutes()){
|
||||||
System.out.format("+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n");
|
System.out.format("+---------+----------------------+-----------------------+-----------------+-----------------+-----------------+-----------------+%n");
|
||||||
double costs = 0;
|
double costs = 0;
|
||||||
System.out.format(leftAlgin, routeNu, route.getVehicle().getId(), route.getStart().getName(), "-", "undef", Math.round(route.getStart().getEndTime()),Math.round(costs));
|
System.out.format(leftAlgin, routeNu, getVehicleString(route), route.getStart().getName(), "-", "undef", Math.round(route.getStart().getEndTime()),Math.round(costs));
|
||||||
TourActivity prevAct = route.getStart();
|
TourActivity prevAct = route.getStart();
|
||||||
for(TourActivity act : route.getActivities()){
|
for(TourActivity act : route.getActivities()){
|
||||||
String jobId;
|
String jobId;
|
||||||
|
|
@ -118,18 +119,26 @@ public class SolutionPrinter {
|
||||||
double c = problem.getTransportCosts().getTransportCost(prevAct.getLocationId(), act.getLocationId(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
|
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());
|
c+= problem.getActivityCosts().getActivityCost(act, act.getArrTime(), route.getDriver(), route.getVehicle());
|
||||||
costs+=c;
|
costs+=c;
|
||||||
System.out.format(leftAlgin, routeNu, route.getVehicle().getId(), act.getName(), jobId, Math.round(act.getArrTime()), Math.round(act.getEndTime()),Math.round(costs));
|
System.out.format(leftAlgin, routeNu, getVehicleString(route), act.getName(), jobId, Math.round(act.getArrTime()), Math.round(act.getEndTime()),Math.round(costs));
|
||||||
prevAct=act;
|
prevAct=act;
|
||||||
}
|
}
|
||||||
double c = problem.getTransportCosts().getTransportCost(prevAct.getLocationId(), route.getEnd().getLocationId(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
|
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());
|
c+= problem.getActivityCosts().getActivityCost(route.getEnd(), route.getEnd().getArrTime(), route.getDriver(), route.getVehicle());
|
||||||
costs+=c;
|
costs+=c;
|
||||||
System.out.format(leftAlgin, routeNu, route.getVehicle().getId(), route.getEnd().getName(), "-", Math.round(route.getEnd().getArrTime()), "undef", Math.round(costs));
|
System.out.format(leftAlgin, routeNu, getVehicleString(route), route.getEnd().getName(), "-", Math.round(route.getEnd().getArrTime()), "undef", Math.round(costs));
|
||||||
routeNu++;
|
routeNu++;
|
||||||
}
|
}
|
||||||
|
System.out.format("+*:=PenaltyVehicle+%n");
|
||||||
System.out.format("+--------------------------------------------------------------------------------------------------------------------------------+%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) {
|
private static Jobs getNuOfJobs(VehicleRoutingProblem problem) {
|
||||||
int nShipments = 0;
|
int nShipments = 0;
|
||||||
int nServices = 0;
|
int nServices = 0;
|
||||||
|
|
|
||||||
|
|
@ -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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue