From 05f3f1e3e9186d94904106b6f91b9684db9d2980 Mon Sep 17 00:00:00 2001 From: Michal Maciejewski Date: Thu, 26 Oct 2017 20:13:37 +0200 Subject: [PATCH 1/5] unused timeWindow variables removed from Service and Shipment --- .../graphhopper/jsprit/core/problem/job/Service.java | 5 +---- .../graphhopper/jsprit/core/problem/job/Shipment.java | 10 ++-------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Service.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Service.java index 09167dc6..af4e6b85 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Service.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Service.java @@ -72,8 +72,6 @@ public class Service extends AbstractJob { protected double serviceTime; - protected TimeWindow timeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE); - protected Capacity.Builder capacityBuilder = Capacity.Builder.newInstance(); protected Capacity capacity; @@ -98,7 +96,7 @@ public class Service extends AbstractJob { Builder(String id){ this.id = id; timeWindows = new TimeWindowsImpl(); - timeWindows.add(timeWindow); + timeWindows.add(TimeWindow.newInstance(0.0, Double.MAX_VALUE)); } /** @@ -176,7 +174,6 @@ public class Service extends AbstractJob { public Builder setTimeWindow(TimeWindow tw){ if(tw == null) throw new IllegalArgumentException("time-window arg must not be null"); - this.timeWindow = tw; this.timeWindows = new TimeWindowsImpl(); timeWindows.add(tw); return this; diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java index 91a8b628..a3eeaaf6 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/job/Shipment.java @@ -61,10 +61,6 @@ public class Shipment extends AbstractJob { private double deliveryServiceTime = 0.0; - private TimeWindow deliveryTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE); - - private TimeWindow pickupTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE); - private Capacity.Builder capacityBuilder = Capacity.Builder.newInstance(); private Capacity capacity; @@ -107,9 +103,9 @@ public class Shipment extends AbstractJob { if (id == null) throw new IllegalArgumentException("id must not be null"); this.id = id; pickupTimeWindows = new TimeWindowsImpl(); - pickupTimeWindows.add(pickupTimeWindow); + pickupTimeWindows.add(TimeWindow.newInstance(0.0, Double.MAX_VALUE)); deliveryTimeWindows = new TimeWindowsImpl(); - deliveryTimeWindows.add(deliveryTimeWindow); + deliveryTimeWindows.add(TimeWindow.newInstance(0.0, Double.MAX_VALUE)); } /** @@ -169,7 +165,6 @@ public class Shipment extends AbstractJob { */ public Builder setPickupTimeWindow(TimeWindow timeWindow) { if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null"); - this.pickupTimeWindow = timeWindow; this.pickupTimeWindows = new TimeWindowsImpl(); this.pickupTimeWindows.add(timeWindow); return this; @@ -215,7 +210,6 @@ public class Shipment extends AbstractJob { */ public Builder setDeliveryTimeWindow(TimeWindow timeWindow) { if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null"); - this.deliveryTimeWindow = timeWindow; this.deliveryTimeWindows = new TimeWindowsImpl(); this.deliveryTimeWindows.add(timeWindow); return this; From e3acb05b0afb2917a8abbfbbd7589fb5a26e4735 Mon Sep 17 00:00:00 2001 From: Michal Maciejewski Date: Mon, 6 Nov 2017 00:02:02 +0100 Subject: [PATCH 2/5] unnecessary @SuppressWarnings removed --- .../graphhopper/jsprit/core/problem/VehicleRoutingProblem.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblem.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblem.java index 4e88701e..99a1788e 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblem.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/VehicleRoutingProblem.java @@ -447,7 +447,6 @@ public class VehicleRoutingProblem { return new VehicleRoutingProblem(this); } - @SuppressWarnings("UnusedDeclaration") public Builder addLocation(String locationId, Coordinate coordinate) { tentative_coordinates.put(locationId, coordinate); return this; @@ -473,7 +472,6 @@ public class VehicleRoutingProblem { * @param vehicles vehicles to be added * @return this builder */ - @SuppressWarnings("deprecation") public Builder addAllVehicles(Collection vehicles) { for (Vehicle v : vehicles) { addVehicle(v); From b3b154cdd64fcd4bda87ac423225baa4d7d344bf Mon Sep 17 00:00:00 2001 From: Michal Maciejewski Date: Mon, 6 Nov 2017 00:03:16 +0100 Subject: [PATCH 3/5] count LiuShen services from 1, instead of 11 --- .../com/graphhopper/jsprit/instance/reader/LuiShenReader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jsprit-instances/src/main/java/com/graphhopper/jsprit/instance/reader/LuiShenReader.java b/jsprit-instances/src/main/java/com/graphhopper/jsprit/instance/reader/LuiShenReader.java index 9215b5e2..b6ec812b 100644 --- a/jsprit-instances/src/main/java/com/graphhopper/jsprit/instance/reader/LuiShenReader.java +++ b/jsprit-instances/src/main/java/com/graphhopper/jsprit/instance/reader/LuiShenReader.java @@ -86,7 +86,7 @@ public class LuiShenReader { if (counter == 10) { createVehicles(vehicleFile, costScenario, customerId, coord, start, end); } else { - Service service = Service.Builder.newInstance("" + counter).addSizeDimension(0, demand) + Service service = Service.Builder.newInstance("" + (counter - 10)).addSizeDimension(0, demand) .setLocation(Location.Builder.newInstance().setCoordinate(coord).setId(customerId).build()).setServiceTime(serviceTime) .setTimeWindow(TimeWindow.newInstance(start, end)).build(); vrpBuilder.addJob(service); From 0946dc239ef9c8388f086444f32c469f6ec24738 Mon Sep 17 00:00:00 2001 From: Michal Maciejewski Date: Mon, 6 Nov 2017 00:05:27 +0100 Subject: [PATCH 4/5] Belhaiza is INFINITE -> create only 1 vehicle --- .../jsprit/instance/reader/BelhaizaReader.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/jsprit-instances/src/main/java/com/graphhopper/jsprit/instance/reader/BelhaizaReader.java b/jsprit-instances/src/main/java/com/graphhopper/jsprit/instance/reader/BelhaizaReader.java index f17218dc..401f70fe 100644 --- a/jsprit-instances/src/main/java/com/graphhopper/jsprit/instance/reader/BelhaizaReader.java +++ b/jsprit-instances/src/main/java/com/graphhopper/jsprit/instance/reader/BelhaizaReader.java @@ -103,13 +103,10 @@ public class BelhaizaReader { System.out.println("fix: " + fixedCostPerVehicle + "; perDistance: 1.0; perWaitingTime: 0.8"); VehicleTypeImpl vehicleType = typeBuilder.build(); double end = Double.parseDouble(tokens[8])*timeProjectionFactor; - for(int i=0;i<10;i++) { - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("solomonVehicle"+(i+1)).setEarliestStart(0.).setLatestArrival(end) - .setStartLocation(Location.Builder.newInstance().setId(customerId) + VehicleImpl vehicle = VehicleImpl.Builder.newInstance("solomonVehicle").setEarliestStart(0.).setLatestArrival(end) + .setStartLocation(Location.Builder.newInstance().setId(customerId) .setCoordinate(coord).build()).setType(vehicleType).build(); - vrpBuilder.addVehicle(vehicle); - } - + vrpBuilder.addVehicle(vehicle); } else{ Service.Builder serviceBuilder = Service.Builder.newInstance(customerId); From 0a5c3e01c0ea5b251cc5c192e2b9395b7ca0e3c7 Mon Sep 17 00:00:00 2001 From: Michal Maciejewski Date: Mon, 6 Nov 2017 11:18:26 +0100 Subject: [PATCH 5/5] CrowFlyCosts inherits from EuclideanCosts to remove duplicated code --- .../jsprit/core/util/CrowFlyCosts.java | 57 +------------------ .../jsprit/core/util/EuclideanCosts.java | 36 +++++------- 2 files changed, 16 insertions(+), 77 deletions(-) diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/CrowFlyCosts.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/CrowFlyCosts.java index 5ed4b217..709f1f4c 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/CrowFlyCosts.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/CrowFlyCosts.java @@ -21,80 +21,29 @@ package com.graphhopper.jsprit.core.util; import com.graphhopper.jsprit.core.problem.Location; -import com.graphhopper.jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts; -import com.graphhopper.jsprit.core.problem.driver.Driver; -import com.graphhopper.jsprit.core.problem.vehicle.Vehicle; /** * @author stefan schroeder */ -public class CrowFlyCosts extends AbstractForwardVehicleRoutingTransportCosts { - - public int speed = 1; - - public double detourFactor = 1.0; +public class CrowFlyCosts extends EuclideanCosts { private Locations locations; public CrowFlyCosts(Locations locations) { - super(); this.locations = locations; } - @Override - public String toString() { - return "[name=crowFlyCosts]"; - } - - @Override - public double getTransportCost(Location from, Location to, double time, Driver driver, Vehicle vehicle) { - double distance; - try { - distance = calculateDistance(from, to); - } catch (NullPointerException e) { - throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator."); - } - double costs = distance; - if (vehicle != null) { - if (vehicle.getType() != null) { - costs = distance * vehicle.getType().getVehicleCostParams().perDistanceUnit; - } - } - return costs; - } - - private double calculateDistance(Location fromLocation, Location toLocation) { + double calculateDistance(Location fromLocation, Location toLocation) { Coordinate from = null; Coordinate to = null; - if (fromLocation.getCoordinate() != null & toLocation.getCoordinate() != null) { + if (fromLocation.getCoordinate() != null && toLocation.getCoordinate() != null) { from = fromLocation.getCoordinate(); to = toLocation.getCoordinate(); } else if (locations != null) { from = locations.getCoord(fromLocation.getId()); to = locations.getCoord(toLocation.getId()); } - if (from == null || to == null) throw new NullPointerException(); - return calculateDistance(from, to); - } - - private double calculateDistance(Coordinate from, Coordinate to) { - return EuclideanDistanceCalculator.calculateDistance(from, to) * detourFactor; - } - - @Override - public double getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) { - double distance; - try { - distance = calculateDistance(from, to); - } catch (NullPointerException e) { - throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator."); - } - return distance / speed; - } - - @Override - public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) { return calculateDistance(from, to); } } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/EuclideanCosts.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/EuclideanCosts.java index 265ac70e..c17e6357 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/EuclideanCosts.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/EuclideanCosts.java @@ -42,42 +42,32 @@ public class EuclideanCosts extends AbstractForwardVehicleRoutingTransportCosts @Override public double getTransportCost(Location from, Location to, double time, Driver driver, Vehicle vehicle) { - double distance; - try { - distance = calculateDistance(from, to); - } catch (NullPointerException e) { - throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator."); + double distance = calculateDistance(from, to); + if (vehicle != null && vehicle.getType() != null) { + return distance * vehicle.getType().getVehicleCostParams().perDistanceUnit; } - double costs = distance; - if (vehicle != null) { - if (vehicle.getType() != null) { - costs = distance * vehicle.getType().getVehicleCostParams().perDistanceUnit; - } - } - return costs; + return distance; } - private double calculateDistance(Location fromLocation, Location toLocation) { + double calculateDistance(Location fromLocation, Location toLocation) { return calculateDistance(fromLocation.getCoordinate(), toLocation.getCoordinate()); } - private double calculateDistance(Coordinate from, Coordinate to) { - return EuclideanDistanceCalculator.calculateDistance(from, to) * detourFactor; + double calculateDistance(Coordinate from, Coordinate to) { + try { + return EuclideanDistanceCalculator.calculateDistance(from, to) * detourFactor; + } catch (NullPointerException e) { + throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator."); + } } @Override public double getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) { - double distance; - try { - distance = calculateDistance(from, to); - } catch (NullPointerException e) { - throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator."); - } - return distance / speed; + return calculateDistance(from, to) / speed; } @Override public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) { - return calculateDistance(from, to); + return calculateDistance(from, to); } }