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 final double result;
public final double time;
public final int nuOfVehicles;
public final BenchmarkInstance instance;
public Double delta = null;
public BenchmarkResult(BenchmarkInstance p, double result, double time) {
public BenchmarkResult(BenchmarkInstance p, double result, double time, int nuOfVehicles) {
super();
this.result = result;
this.time = time;
this.instance = p;
this.nuOfVehicles = nuOfVehicles;
}
void setBestKnownDelta(double delta){
this.delta = delta;
@ -148,7 +150,7 @@ public class ConcurrentBenchmarker {
vra.getAlgorithmListeners().addListener(stopwatch,Priority.HIGH);
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
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));
return result;
}
@ -168,13 +170,13 @@ public class ConcurrentBenchmarker {
}
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)+"]");
// for(BenchmarkWriter writer : writers){
// writer.write(r);
// }
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)+"][nuOfVehicles="+r.nuOfVehicles+"]");
}
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));
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);
// for(VehicleRoute route : routes){
// 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

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