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

fix bug in ChristophidesReader

This commit is contained in:
oblonski 2013-07-02 06:18:29 +02:00
parent 45b0c35a95
commit e982252fc7
3 changed files with 21 additions and 16 deletions

View file

@ -58,13 +58,15 @@ public class ConcurrentBenchmarker {
public static class BenchmarkResult { public static class BenchmarkResult {
public final double result; public final double result;
public final double time; public final double time;
public final int nuOfVehicles;
public final BenchmarkInstance instance; public final BenchmarkInstance instance;
public Double delta = null; public Double delta = null;
public BenchmarkResult(BenchmarkInstance p, double result, double time) { public BenchmarkResult(BenchmarkInstance p, double result, double time, int nuOfVehicles) {
super(); super();
this.result = result; this.result = result;
this.time = time; this.time = time;
this.instance = p; this.instance = p;
this.nuOfVehicles = nuOfVehicles;
} }
void setBestKnownDelta(double delta){ void setBestKnownDelta(double delta){
this.delta = delta; this.delta = delta;
@ -148,7 +150,7 @@ public class ConcurrentBenchmarker {
vra.getAlgorithmListeners().addListener(stopwatch,Priority.HIGH); vra.getAlgorithmListeners().addListener(stopwatch,Priority.HIGH);
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
VehicleRoutingProblemSolution best = Solutions.getBest(solutions); VehicleRoutingProblemSolution best = Solutions.getBest(solutions);
BenchmarkResult result = new BenchmarkResult(p,best.getCost(),stopwatch.getCompTimeInSeconds()); BenchmarkResult result = new BenchmarkResult(p,best.getCost(),stopwatch.getCompTimeInSeconds(), best.getRoutes().size());
if(p.bestKnown != null) result.setBestKnownDelta((best.getCost()/p.bestKnown-1)); if(p.bestKnown != null) result.setBestKnownDelta((best.getCost()/p.bestKnown-1));
return result; return result;
} }
@ -168,13 +170,13 @@ public class ConcurrentBenchmarker {
} }
private void print(BenchmarkResult r, int count) { private void print(BenchmarkResult r, int count) {
System.out.println("("+count+"/"+problems.size() +")"+ "\t[instance="+r.instance.name+"][time="+round(r.time,2)+"][result="+round(r.result,2)+"][delta="+round(r.delta,3)+"]"); System.out.println("("+count+"/"+problems.size() +")"+ "\t[instance="+r.instance.name+"][time="+round(r.time,2)+"][result="+round(r.result,2)+
// for(BenchmarkWriter writer : writers){ "][delta="+round(r.delta,3)+"][nuOfVehicles="+r.nuOfVehicles+"]");
// writer.write(r);
// }
} }
private double round(Double value, int i) { private Double round(Double value, int i) {
if(value==null) return null;
long roundedVal = Math.round(value*Math.pow(10, i)); long roundedVal = Math.round(value*Math.pow(10, i));
return (double)roundedVal/(double)(Math.pow(10, i)); return (double)roundedVal/(double)(Math.pow(10, i));
} }

View file

@ -46,6 +46,13 @@ class RemoveEmptyVehicles implements InsertionStartsListener, InsertionEndsListe
// List<VehicleRoute> routes = new ArrayList<VehicleRoute>(vehicleRoutes); // List<VehicleRoute> routes = new ArrayList<VehicleRoute>(vehicleRoutes);
// for(VehicleRoute route : routes){ // for(VehicleRoute route : routes){
// if(route.isEmpty()) { vehicleRoutes.remove(route); } // if(route.isEmpty()) { vehicleRoutes.remove(route); }
// }
// List<VehicleRoute> routes = new ArrayList<VehicleRoute>(vehicleRoutes);
// for(VehicleRoute route : routes){
// if(route.isEmpty()) {
// fleetManager.unlock(route.getVehicle());
// vehicleRoutes.remove(route);
// }
// } // }
} }

View file

@ -54,8 +54,6 @@ public class ChristophidesReader {
private final VehicleRoutingProblem.Builder vrpBuilder; private final VehicleRoutingProblem.Builder vrpBuilder;
private double coordProjectionFactor = 1; private double coordProjectionFactor = 1;
private int customerCounter = 1;
/** /**
* Constructs the reader. * Constructs the reader.
@ -91,21 +89,19 @@ public class ChristophidesReader {
serviceTime = Double.parseDouble(tokens[3].trim()); serviceTime = Double.parseDouble(tokens[3].trim());
} }
else if(counter == 1){ else if(counter == 1){
String id = Integer.valueOf(counter).toString();
Coordinate depotCoord = makeCoord(tokens[0].trim(),tokens[1].trim()); Coordinate depotCoord = makeCoord(tokens[0].trim(),tokens[1].trim());
VehicleTypeImpl vehicleType = VehicleTypeImpl.Builder.newInstance("christophidesType", vehicleCapacity). VehicleTypeImpl vehicleType = VehicleTypeImpl.Builder.newInstance("christophidesType", vehicleCapacity).
setCostPerDistance(1.0).setFixedCost(100).build(); setCostPerDistance(1.0).build();
Vehicle vehicle = VehicleImpl.Builder.newInstance("christophidesVehicle").setLatestArrival(endTime).setLocationId(id).setLocationCoord(depotCoord). Vehicle vehicle = VehicleImpl.Builder.newInstance("christophidesVehicle").setLatestArrival(endTime).setLocationCoord(depotCoord).
setType(vehicleType).build(); setType(vehicleType).build();
vrpBuilder.addVehicle(vehicle); vrpBuilder.addVehicle(vehicle);
} }
else{ else{
Coordinate customerCoord = makeCoord(tokens[0].trim(),tokens[1].trim()); Coordinate customerCoord = makeCoord(tokens[0].trim(),tokens[1].trim());
int demand = Integer.parseInt(tokens[2].trim()); int demand = Integer.parseInt(tokens[2].trim());
String customer = Integer.valueOf(customerCounter).toString(); String customer = Integer.valueOf(counter-1).toString();
Service service = Service.Builder.newInstance(customer, demand).setServiceTime(serviceTime).setLocationId(customer).setCoord(customerCoord).build(); Service service = Service.Builder.newInstance(customer, demand).setServiceTime(serviceTime).setCoord(customerCoord).build();
vrpBuilder.addService(service); vrpBuilder.addService(service);
customerCounter++;
} }
counter++; counter++;
} }