From e982252fc727ae0a6f2762e3b77c42eec695428d Mon Sep 17 00:00:00 2001 From: oblonski <4sschroeder@gmail.com> Date: Tue, 2 Jul 2013 06:18:29 +0200 Subject: [PATCH] fix bug in ChristophidesReader --- .../java/analysis/ConcurrentBenchmarker.java | 16 +++++++++------- .../java/algorithms/RemoveEmptyVehicles.java | 7 +++++++ .../main/java/readers/ChristophidesReader.java | 14 +++++--------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/jsprit-analysis/src/main/java/analysis/ConcurrentBenchmarker.java b/jsprit-analysis/src/main/java/analysis/ConcurrentBenchmarker.java index 6d3a9817..bcddcd34 100644 --- a/jsprit-analysis/src/main/java/analysis/ConcurrentBenchmarker.java +++ b/jsprit-analysis/src/main/java/analysis/ConcurrentBenchmarker.java @@ -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 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)); } diff --git a/jsprit-core/src/main/java/algorithms/RemoveEmptyVehicles.java b/jsprit-core/src/main/java/algorithms/RemoveEmptyVehicles.java index 906f01fd..49d12618 100644 --- a/jsprit-core/src/main/java/algorithms/RemoveEmptyVehicles.java +++ b/jsprit-core/src/main/java/algorithms/RemoveEmptyVehicles.java @@ -46,6 +46,13 @@ class RemoveEmptyVehicles implements InsertionStartsListener, InsertionEndsListe // List routes = new ArrayList(vehicleRoutes); // for(VehicleRoute route : routes){ // if(route.isEmpty()) { vehicleRoutes.remove(route); } +// } +// List routes = new ArrayList(vehicleRoutes); +// for(VehicleRoute route : routes){ +// if(route.isEmpty()) { +// fleetManager.unlock(route.getVehicle()); +// vehicleRoutes.remove(route); +// } // } } diff --git a/jsprit-instances/src/main/java/readers/ChristophidesReader.java b/jsprit-instances/src/main/java/readers/ChristophidesReader.java index 15aa5325..735dcd43 100644 --- a/jsprit-instances/src/main/java/readers/ChristophidesReader.java +++ b/jsprit-instances/src/main/java/readers/ChristophidesReader.java @@ -54,8 +54,6 @@ public class ChristophidesReader { private final VehicleRoutingProblem.Builder vrpBuilder; 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(); - vrpBuilder.addService(service); - customerCounter++; + String customer = Integer.valueOf(counter-1).toString(); + Service service = Service.Builder.newInstance(customer, demand).setServiceTime(serviceTime).setCoord(customerCoord).build(); + vrpBuilder.addService(service); } counter++; }