diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/GraphStreamViewer.java b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/GraphStreamViewer.java index 16928de8..898213ab 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/GraphStreamViewer.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/GraphStreamViewer.java @@ -385,17 +385,27 @@ public class GraphStreamViewer { } private void renderVehicle(Graph g, Vehicle vehicle, Label label) { - Node n = g.addNode(makeId(vehicle.getId(),vehicle.getLocationId())); - if(label.equals(Label.ID)) n.addAttribute("ui.label", "depot"); + Node vehicleStart = g.addNode(makeId(vehicle.getId(),vehicle.getStartLocationId())); + if(label.equals(Label.ID)) vehicleStart.addAttribute("ui.label", "depot"); // if(label.equals(Label.ACTIVITY)) n.addAttribute("ui.label", "start"); - n.addAttribute("x", vehicle.getCoord().getX()); - n.addAttribute("y", vehicle.getCoord().getY()); - n.setAttribute("ui.class", "depot"); + vehicleStart.addAttribute("x", vehicle.getStartLocationCoordinate().getX()); + vehicleStart.addAttribute("y", vehicle.getStartLocationCoordinate().getY()); + vehicleStart.setAttribute("ui.class", "depot"); + + if(!vehicle.getStartLocationId().equals(vehicle.getEndLocationId())){ + Node vehicleEnd = g.addNode(makeId(vehicle.getId(),vehicle.getEndLocationId())); + if(label.equals(Label.ID)) vehicleEnd.addAttribute("ui.label", "depot"); +// if(label.equals(Label.ACTIVITY)) n.addAttribute("ui.label", "start"); + vehicleEnd.addAttribute("x", vehicle.getEndLocationCoordinate().getX()); + vehicleEnd.addAttribute("y", vehicle.getEndLocationCoordinate().getY()); + vehicleEnd.setAttribute("ui.class", "depot"); + + } } private void renderRoute(Graph g, VehicleRoute route, int routeId, long renderDelay_in_ms, Label label) { int vehicle_edgeId = 1; - String prevIdentifier = makeId(route.getVehicle().getId(),route.getVehicle().getLocationId()); + String prevIdentifier = makeId(route.getVehicle().getId(),route.getVehicle().getStartLocationId()); if(label.equals(Label.ACTIVITY)){ Node n = g.getNode(prevIdentifier); n.addAttribute("ui.label", "start"); @@ -414,7 +424,7 @@ public class GraphStreamViewer { sleep(renderDelay_in_ms); } if(route.getVehicle().isReturnToDepot()){ - String lastIdentifier = makeId(route.getVehicle().getId(),route.getVehicle().getLocationId()); + String lastIdentifier = makeId(route.getVehicle().getId(),route.getVehicle().getEndLocationId()); g.addEdge(makeEdgeId(routeId,vehicle_edgeId), prevIdentifier, lastIdentifier, true); } } diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/Plotter.java b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/Plotter.java index 38e8fbcf..44535d05 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/Plotter.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/Plotter.java @@ -404,9 +404,15 @@ public class Plotter { XYSeriesCollection coll = new XYSeriesCollection(); XYSeries vehicleSeries = new XYSeries("depot", false, true); for(Vehicle v : vehicles){ - Coordinate coord = v.getCoord(); - if(coord == null) throw new NoLocationFoundException(); - vehicleSeries.add(coord.getX(),coord.getY()); + Coordinate startCoord = v.getStartLocationCoordinate(); + if(startCoord == null) throw new NoLocationFoundException(); + vehicleSeries.add(startCoord.getX(),startCoord.getY()); + + if(!v.getStartLocationId().equals(v.getEndLocationId())){ + Coordinate endCoord = v.getEndLocationCoordinate(); + if(endCoord == null) throw new NoLocationFoundException(); + vehicleSeries.add(endCoord.getX(),endCoord.getY()); + } } coll.addSeries(vehicleSeries); @@ -473,11 +479,18 @@ public class Plotter { private Locations retrieveLocations(VehicleRoutingProblem vrp) throws NoLocationFoundException { final Map locs = new HashMap(); for(Vehicle v : vrp.getVehicles()){ - String locationId = v.getLocationId(); - if(locationId == null) throw new NoLocationFoundException(); - Coordinate coord = v.getCoord(); - if(coord == null) throw new NoLocationFoundException(); - locs.put(locationId, coord); + String startLocationId = v.getStartLocationId(); + if(startLocationId == null) throw new NoLocationFoundException(); + Coordinate startCoord = v.getStartLocationCoordinate(); + if(startCoord == null) throw new NoLocationFoundException(); + locs.put(startLocationId, startCoord); + + String endLocationId = v.getEndLocationId(); + if(!startLocationId.equals(endLocationId)){ + Coordinate endCoord = v.getEndLocationCoordinate(); + if(endCoord == null) throw new NoLocationFoundException(); + locs.put(endLocationId, endCoord); + } } for(Job j : vrp.getJobs().values()){ if(j instanceof Service){ diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/SolutionPlotter.java b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/SolutionPlotter.java index 141c8c22..c86a6266 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/SolutionPlotter.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/SolutionPlotter.java @@ -75,8 +75,10 @@ public class SolutionPlotter { * @param vrp * @param pngFile target path with filename. - * @see VehicleRoutingProblem, VehicleRoutingProblemSolution + * @see VehicleRoutingProblem, VehicleRoutingProblemSolution + * @deprecated use Plotter.java instead (this plotter is not maintained anymore and might plot incorrectly) */ + @Deprecated public static void plotVrpAsPNG(VehicleRoutingProblem vrp, String pngFile, String title){ String filename = pngFile; if(!pngFile.endsWith(".png")) filename += ".png"; @@ -102,7 +104,9 @@ public class SolutionPlotter { * @param pngFile target path with filename. * @param plotTitle * @see VehicleRoute + * @deprecated use Plotter.java instead (this plotter is not maintained anymore and might plot incorrectly) */ + @Deprecated public static void plotRoutesAsPNG(Collection routes, Locations locations, String pngFile, String title) { String filename = pngFile; if(!pngFile.endsWith(".png")) filename += ".png"; @@ -130,8 +134,10 @@ public class SolutionPlotter { * @param vrp * @param solution * @param pngFile target path with filename. - * @see VehicleRoutingProblem, VehicleRoutingProblemSolution + * @see VehicleRoutingProblem, VehicleRoutingProblemSolution + * @deprecated use Plotter.java instead (this plotter is not maintained anymore and might plot incorrectly) */ + @Deprecated public static void plotSolutionAsPNG(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution, String pngFile, String title){ String filename = pngFile; if(!pngFile.endsWith(".png")) filename += ".png"; @@ -294,7 +300,7 @@ public class SolutionPlotter { XYSeriesCollection coll = new XYSeriesCollection(); XYSeries vehicleSeries = new XYSeries("depot", false, true); for(Vehicle v : vehicles){ - Coordinate coord = v.getCoord(); + Coordinate coord = v.getStartLocationCoordinate(); if(coord == null) throw new NoLocationFoundException(); vehicleSeries.add(coord.getX(),coord.getY()); } @@ -353,11 +359,11 @@ public class SolutionPlotter { private static Locations retrieveLocations(VehicleRoutingProblem vrp) throws NoLocationFoundException { final Map locs = new HashMap(); for(Vehicle v : vrp.getVehicles()){ - String locationId = v.getLocationId(); - if(locationId == null) throw new NoLocationFoundException(); - Coordinate coord = v.getCoord(); + String startLocationId = v.getStartLocationId(); + if(startLocationId == null) throw new NoLocationFoundException(); + Coordinate coord = v.getStartLocationCoordinate(); if(coord == null) throw new NoLocationFoundException(); - locs.put(locationId, coord); + locs.put(startLocationId, coord); } for(Job j : vrp.getJobs().values()){ if(j instanceof Service){ diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/io/InsertionFactory.java b/jsprit-core/src/main/java/jsprit/core/algorithm/io/InsertionFactory.java index 00a18fe3..9a4f49a5 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/io/InsertionFactory.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/io/InsertionFactory.java @@ -86,9 +86,15 @@ class InsertionFactory { String weight = config.getString("considerFixedCosts[@weight]"); if(weight == null) weight = config.getString("considerFixedCost[@weight]"); if(weight != null) fixedCostWeight = Double.parseDouble(weight); - else log.warn("parameter considerFixedCosts[@weight] is missing. by default, it is 0.5."); + else throw new IllegalStateException("fixedCostsParameter 'weight' must be set, e.g. true.\n" + + "this has to be changed in algorithm-config-xml-file."); iBuilder.considerFixedCosts(fixedCostWeight); } + else if(val.equals("false")){ + + } + else throw new IllegalStateException("considerFixedCosts must either be true or false, i.e. true or \nfalse. " + + "if latter, you can also omit the tag. this has to be changed in algorithm-config-xml-file"); } String timeSliceString = config.getString("experimental[@timeSlice]"); String neighbors = config.getString("experimental[@neighboringSlices]"); diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/io/VehicleRoutingAlgorithms.java b/jsprit-core/src/main/java/jsprit/core/algorithm/io/VehicleRoutingAlgorithms.java index 0a636235..428f0276 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/io/VehicleRoutingAlgorithms.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/io/VehicleRoutingAlgorithms.java @@ -481,9 +481,6 @@ public class VehicleRoutingAlgorithms { @Override public void finish() { - if(firstAct){ - assert vehicle.getLocationId() == end.getLocationId() : "route end and last activity are not equal even route is open. this should not be."; - } firstAct = true; } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionCalculator.java index 1a1ead9c..c07b6e44 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionCalculator.java @@ -106,9 +106,9 @@ final class ServiceInsertionCalculator implements JobInsertionCostsCalculator{ TourActivity deliveryAct2Insert = activityFactory.createActivity(service); - Start start = Start.newInstance(newVehicle.getLocationId(), newVehicle.getEarliestDeparture(), newVehicle.getLatestArrival()); + Start start = Start.newInstance(newVehicle.getStartLocationId(), newVehicle.getEarliestDeparture(), Double.MAX_VALUE); start.setEndTime(newVehicleDepartureTime); - End end = End.newInstance(newVehicle.getLocationId(), 0.0, newVehicle.getLatestArrival()); + End end = End.newInstance(newVehicle.getEndLocationId(), 0.0, newVehicle.getLatestArrival()); TourActivity prevAct = start; double prevActStartTime = newVehicleDepartureTime; diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionOnRouteLevelCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionOnRouteLevelCalculator.java index f5dc6b79..272400cb 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionOnRouteLevelCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionOnRouteLevelCalculator.java @@ -314,22 +314,22 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC */ private void initialiseStartAndEnd(final Vehicle newVehicle, double newVehicleDepartureTime) { if(start == null){ - start = Start.newInstance(newVehicle.getLocationId(), newVehicle.getEarliestDeparture(), newVehicle.getLatestArrival()); + start = Start.newInstance(newVehicle.getStartLocationId(), newVehicle.getEarliestDeparture(), Double.MAX_VALUE); start.setEndTime(newVehicleDepartureTime); } else{ - start.setLocationId(newVehicle.getLocationId()); + start.setLocationId(newVehicle.getStartLocationId()); start.setTheoreticalEarliestOperationStartTime(newVehicle.getEarliestDeparture()); - start.setTheoreticalLatestOperationStartTime(newVehicle.getLatestArrival()); + start.setTheoreticalLatestOperationStartTime(Double.MAX_VALUE); start.setEndTime(newVehicleDepartureTime); } if(end == null){ - end = End.newInstance(newVehicle.getLocationId(), 0.0, newVehicle.getLatestArrival()); + end = End.newInstance(newVehicle.getEndLocationId(), 0.0, newVehicle.getLatestArrival()); } else{ - end.setLocationId(newVehicle.getLocationId()); - end.setTheoreticalEarliestOperationStartTime(newVehicleDepartureTime); + end.setLocationId(newVehicle.getEndLocationId()); + end.setTheoreticalEarliestOperationStartTime(0.0); end.setTheoreticalLatestOperationStartTime(newVehicle.getLatestArrival()); } } diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java index 8a98d517..87377a8f 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java @@ -100,10 +100,10 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{ int pickupInsertionIndex = InsertionData.NO_INDEX; int deliveryInsertionIndex = InsertionData.NO_INDEX; - Start start = Start.newInstance(newVehicle.getLocationId(), newVehicle.getEarliestDeparture(), newVehicle.getLatestArrival()); + Start start = Start.newInstance(newVehicle.getStartLocationId(), newVehicle.getEarliestDeparture(), newVehicle.getLatestArrival()); start.setEndTime(newVehicleDepartureTime); - End end = End.newInstance(newVehicle.getLocationId(), 0.0, newVehicle.getLatestArrival()); + End end = End.newInstance(newVehicle.getEndLocationId(), 0.0, newVehicle.getLatestArrival()); TourActivity prevAct = start; double prevActEndTime = newVehicleDepartureTime; diff --git a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java index eb263d6f..86768bfe 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java @@ -327,7 +327,11 @@ public class VehicleRoutingProblem { if(!vehicleTypes.contains(vehicle.getType())){ vehicleTypes.add(vehicle.getType()); } - coordinates.put(vehicle.getLocationId(), vehicle.getCoord()); + String startLocationId = vehicle.getStartLocationId(); + coordinates.put(startLocationId, vehicle.getStartLocationCoordinate()); + if(!vehicle.getEndLocationId().equals(startLocationId)){ + coordinates.put(vehicle.getEndLocationId(), vehicle.getEndLocationCoordinate()); + } return this; } @@ -373,7 +377,7 @@ public class VehicleRoutingProblem { Set locTypeKeys = new HashSet(); List uniqueVehicles = new ArrayList(); for(Vehicle v : vehicles){ - LocTypeKey key = new LocTypeKey(v.getLocationId(),v.getType().getTypeId()); + LocTypeKey key = new LocTypeKey(v.getStartLocationId(),v.getType().getTypeId()); if(!locTypeKeys.contains(key)){ uniqueVehicles.add(v); locTypeKeys.add(key); @@ -390,9 +394,10 @@ public class VehicleRoutingProblem { .setFixedCost(fixed) .build(); PenaltyVehicleType penType = new PenaltyVehicleType(t,penaltyFactor); - String vehicleId = "penaltyVehicle_" + v.getLocationId() + "_" + t.getTypeId(); + String vehicleId = "penaltyVehicle_" + v.getStartLocationId() + "_" + t.getTypeId(); Vehicle penVehicle = VehicleImpl.Builder.newInstance(vehicleId).setEarliestStart(v.getEarliestDeparture()) - .setLatestArrival(v.getLatestArrival()).setLocationCoord(v.getCoord()).setLocationId(v.getLocationId()) + .setLatestArrival(v.getLatestArrival()).setStartLocationCoordinate(v.getStartLocationCoordinate()).setLocationId(v.getStartLocationId()) + .setEndLocationId(v.getEndLocationId()).setEndLocationCoordinate(v.getEndLocationCoordinate()) .setReturnToDepot(v.isReturnToDepot()).setType(penType).build(); addVehicle(penVehicle); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/VehicleRoute.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/VehicleRoute.java index 86e66106..2a099724 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/VehicleRoute.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/VehicleRoute.java @@ -165,7 +165,7 @@ public class VehicleRoute { this.driver = driver; start = Start.newInstance(vehicle.getStartLocationId(), vehicle.getEarliestDeparture(), Double.MAX_VALUE); start.setEndTime(vehicle.getEarliestDeparture()); - end = End.newInstance(vehicle.getLocationId(), 0.0, vehicle.getLatestArrival()); + end = End.newInstance(vehicle.getEndLocationId(), 0.0, vehicle.getLatestArrival()); } /** diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/Vehicle.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/Vehicle.java index 6176910c..c73cfb24 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/Vehicle.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/Vehicle.java @@ -47,7 +47,9 @@ public interface Vehicle { *

Consequently, it should be the end-location of this vehicle, if returnToDepot is true. * * @return location-id of this vehicle + * @deprecated use getStartLocationId() instead */ + @Deprecated public abstract String getLocationId(); /** @@ -56,7 +58,9 @@ public interface Vehicle { *

Consequently, it should be the coordinate of the end-location, if returnToDepot is true. * * @return coordinate of this vehicle + * @deprecated use getStartLocationCoordinate() instead */ + @Deprecated public abstract Coordinate getCoord(); /** diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleImpl.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleImpl.java index 6a534e7e..5a50813f 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleImpl.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleImpl.java @@ -176,10 +176,8 @@ public class VehicleImpl implements Vehicle { * * @param coord * @return this builder - * @throws IllegalArgumentException if start-coordinate is null */ public Builder setStartLocationCoordinate(Coordinate coord){ - if(coord == null) throw new IllegalArgumentException("start-coordinate must not be null"); this.startLocationCoord = coord; this.locationCoord = coord; return this; @@ -190,10 +188,8 @@ public class VehicleImpl implements Vehicle { * * @param endLocationId * @return this builder - * @throws IllegalArgumentException if endLocation is null */ public Builder setEndLocationId(String endLocationId){ - if(endLocationId == null) throw new IllegalArgumentException("end-locationId must not be null"); this.endLocationId = endLocationId; return this; } @@ -203,10 +199,8 @@ public class VehicleImpl implements Vehicle { * * @param coord * @return this builder - * @throws IllegalArgumentException if coord is null */ public Builder setEndLocationCoordinate(Coordinate coord){ - if(coord == null) throw new IllegalArgumentException("end-coordinate must not be null"); this.endLocationCoord = coord; return this; } @@ -336,6 +330,10 @@ public class VehicleImpl implements Vehicle { return "[id="+id+"][type="+type+"][locationId="+locationId+"][coord=" + coord + "][isReturnToDepot=" + isReturnToDepot() + "]"; } + /** + * @deprecated use getStartLocationCoordinate() instead + */ + @Deprecated public Coordinate getCoord() { return coord; } @@ -350,6 +348,10 @@ public class VehicleImpl implements Vehicle { return latestArrival; } + /** + * @deprecated use getStartLocationId() instead + */ + @Deprecated @Override public String getLocationId() { return locationId; diff --git a/jsprit-core/src/main/resources/algorithm_schema.xsd b/jsprit-core/src/main/resources/algorithm_schema.xsd index 6ea5d966..b2a80039 100644 --- a/jsprit-core/src/main/resources/algorithm_schema.xsd +++ b/jsprit-core/src/main/resources/algorithm_schema.xsd @@ -226,7 +226,8 @@ - + + diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/CalcVehicleTypeDependentServiceInsertionTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/CalcVehicleTypeDependentServiceInsertionTest.java index b7d775ab..a1495182 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/CalcVehicleTypeDependentServiceInsertionTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/CalcVehicleTypeDependentServiceInsertionTest.java @@ -53,8 +53,8 @@ public class CalcVehicleTypeDependentServiceInsertionTest { veh2 = mock(Vehicle.class); when(veh1.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type1", 0).build()); when(veh2.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type2", 0).build()); - when(veh1.getLocationId()).thenReturn("loc1"); - when(veh2.getLocationId()).thenReturn("loc2"); + when(veh1.getStartLocationId()).thenReturn("loc1"); + when(veh2.getStartLocationId()).thenReturn("loc2"); fleetManager = mock(VehicleFleetManager.class); service = mock(Service.class); vehicleRoute = mock(VehicleRoute.class); diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertion.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertion.java index 9e820e3f..ae238881 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertion.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertion.java @@ -75,14 +75,16 @@ public class TestCalculatesServiceInsertion { costs = mock(VehicleRoutingTransportCosts.class); vehicle = mock(Vehicle.class); when(vehicle.getCapacity()).thenReturn(1000); - when(vehicle.getLocationId()).thenReturn("depot"); + when(vehicle.getStartLocationId()).thenReturn("depot"); + when(vehicle.getEndLocationId()).thenReturn("depot"); when(vehicle.getEarliestDeparture()).thenReturn(0.0); when(vehicle.getLatestArrival()).thenReturn(100.0); when(vehicle.isReturnToDepot()).thenReturn(true); newVehicle = mock(Vehicle.class); when(newVehicle.getCapacity()).thenReturn(1000); - when(newVehicle.getLocationId()).thenReturn("depot"); + when(newVehicle.getStartLocationId()).thenReturn("depot"); + when(newVehicle.getEndLocationId()).thenReturn("depot"); when(newVehicle.getEarliestDeparture()).thenReturn(0.0); when(newVehicle.getLatestArrival()).thenReturn(100.0); when(newVehicle.isReturnToDepot()).thenReturn(true); diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertionOnRouteLevel.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertionOnRouteLevel.java index 98f82120..02d2119a 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertionOnRouteLevel.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestCalculatesServiceInsertionOnRouteLevel.java @@ -79,7 +79,6 @@ public class TestCalculatesServiceInsertionOnRouteLevel { costs = mock(VehicleRoutingTransportCosts.class); vehicle = mock(Vehicle.class); when(vehicle.getCapacity()).thenReturn(1000); - when(vehicle.getLocationId()).thenReturn("0,0"); when(vehicle.getStartLocationId()).thenReturn("0,0"); when(vehicle.getEndLocationId()).thenReturn("0,0"); when(vehicle.getEarliestDeparture()).thenReturn(0.0); @@ -88,7 +87,6 @@ public class TestCalculatesServiceInsertionOnRouteLevel { newVehicle = mock(Vehicle.class); when(newVehicle.getCapacity()).thenReturn(1000); - when(newVehicle.getLocationId()).thenReturn("0,0"); when(newVehicle.getStartLocationId()).thenReturn("0,0"); when(newVehicle.getEndLocationId()).thenReturn("0,0"); when(newVehicle.getEarliestDeparture()).thenReturn(0.0); diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestInserter.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestInserter.java index 672d3236..4a1d3228 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestInserter.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestInserter.java @@ -22,7 +22,6 @@ public class TestInserter { public void whenInsertingServiceAndRouteIsClosed_itInsertsCorrectly(){ Service service = mock(Service.class); Vehicle vehicle = mock(Vehicle.class); - when(vehicle.getLocationId()).thenReturn("vehLoc"); when(vehicle.getStartLocationId()).thenReturn("vehLoc"); when(vehicle.getEndLocationId()).thenReturn("vehLoc"); when(vehicle.isReturnToDepot()).thenReturn(true); @@ -42,14 +41,13 @@ public class TestInserter { assertEquals(2,route.getTourActivities().getActivities().size()); assertEquals(route.getTourActivities().getActivities().get(1).getLocationId(),serviceToInsert.getLocationId()); - assertEquals(route.getEnd().getLocationId(),vehicle.getLocationId()); + assertEquals(route.getEnd().getLocationId(),vehicle.getEndLocationId()); } @Test public void whenInsertingServiceAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation(){ Service service = mock(Service.class); Vehicle vehicle = mock(Vehicle.class); - when(vehicle.getLocationId()).thenReturn("vehLoc"); when(vehicle.getStartLocationId()).thenReturn("vehLoc"); when(vehicle.getEndLocationId()).thenReturn("vehLoc"); when(vehicle.isReturnToDepot()).thenReturn(false); @@ -76,7 +74,6 @@ public class TestInserter { public void whenInsertingShipmentAndRouteIsClosed_itInsertsCorrectly(){ Shipment shipment = mock(Shipment.class); Vehicle vehicle = mock(Vehicle.class); - when(vehicle.getLocationId()).thenReturn("vehLoc"); when(vehicle.getStartLocationId()).thenReturn("vehLoc"); when(vehicle.getEndLocationId()).thenReturn("vehLoc"); when(vehicle.isReturnToDepot()).thenReturn(true); @@ -98,14 +95,13 @@ public class TestInserter { assertEquals(4,route.getTourActivities().getActivities().size()); assertEquals(route.getTourActivities().getActivities().get(2).getLocationId(),shipmentToInsert.getPickupLocation()); assertEquals(route.getTourActivities().getActivities().get(3).getLocationId(),shipmentToInsert.getDeliveryLocation()); - assertEquals(route.getEnd().getLocationId(),vehicle.getLocationId()); + assertEquals(route.getEnd().getLocationId(),vehicle.getEndLocationId()); } @Test public void whenInsertingShipmentAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation(){ Shipment shipment = mock(Shipment.class); Vehicle vehicle = mock(Vehicle.class); - when(vehicle.getLocationId()).thenReturn("vehLoc"); when(vehicle.isReturnToDepot()).thenReturn(false); when(vehicle.getId()).thenReturn("vehId"); @@ -148,7 +144,7 @@ public class TestInserter { Inserter inserter = new Inserter(mock(InsertionListeners.class)); inserter.insertJob(shipmentToInsert, iData, route); - assertEquals(newVehicle.getLocationId(),route.getEnd().getLocationId()); + assertEquals(route.getEnd().getLocationId(),newVehicle.getEndLocationId()); } @Test diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/state/TestTourStateUpdaterWithService.java b/jsprit-core/src/test/java/jsprit/core/algorithm/state/TestTourStateUpdaterWithService.java index f659b405..3498829a 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/state/TestTourStateUpdaterWithService.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/state/TestTourStateUpdaterWithService.java @@ -138,7 +138,7 @@ public class TestTourStateUpdaterWithService { public void testStatesOfAct0(){ states.informInsertionStarts(Arrays.asList(vehicleRoute), null); assertEquals(0.0, vehicleRoute.getStart().getEndTime(),0.05); - assertEquals(vehicleRoute.getVehicle().getLocationId(), vehicleRoute.getStart().getLocationId()); + assertEquals(vehicleRoute.getVehicle().getStartLocationId(), vehicleRoute.getStart().getLocationId()); assertEquals(vehicleRoute.getVehicle().getEarliestDeparture(), vehicleRoute.getStart().getTheoreticalEarliestOperationStartTime(),0.05); assertEquals(Double.MAX_VALUE, vehicleRoute.getStart().getTheoreticalLatestOperationStartTime(),0.05); diff --git a/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java b/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java index fb2ce5b2..62728eb7 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/VehicleRoutingProblemTest.java @@ -66,10 +66,10 @@ public class VehicleRoutingProblemTest { public void whenBuildingWithFourVehicles_vrpShouldContainTheCorrectNuOfVehicles(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - Vehicle v1 = mock(VehicleImpl.class); - Vehicle v2 = mock(VehicleImpl.class); - Vehicle v3 = mock(VehicleImpl.class); - Vehicle v4 = mock(VehicleImpl.class); + Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("start").build(); + Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("start").build(); + Vehicle v3 = VehicleImpl.Builder.newInstance("v3").setStartLocationId("start").build(); + Vehicle v4 = VehicleImpl.Builder.newInstance("v4").setStartLocationId("start").build(); builder.addVehicle(v1).addVehicle(v2).addVehicle(v3).addVehicle(v4); @@ -82,10 +82,10 @@ public class VehicleRoutingProblemTest { public void whenAddingFourVehiclesAllAtOnce_vrpShouldContainTheCorrectNuOfVehicles(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - Vehicle v1 = mock(VehicleImpl.class); - Vehicle v2 = mock(VehicleImpl.class); - Vehicle v3 = mock(VehicleImpl.class); - Vehicle v4 = mock(VehicleImpl.class); + Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("start").build(); + Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("start").build(); + Vehicle v3 = VehicleImpl.Builder.newInstance("v3").setStartLocationId("start").build(); + Vehicle v4 = VehicleImpl.Builder.newInstance("v4").setStartLocationId("start").build(); builder.addAllVehicles(Arrays.asList(v1,v2,v3,v4)); @@ -471,4 +471,22 @@ public class VehicleRoutingProblemTest { assertTrue(anotherPenVehInCollection); } + + @Test + public void whenAddingVehicleWithDiffStartAndEnd_startLocationMustBeRegisteredInLocationMap(){ + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("end").build(); + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addVehicle(vehicle); + assertTrue(vrpBuilder.getLocationMap().containsKey("start")); + } + + @Test + public void whenAddingVehicleWithDiffStartAndEnd_endLocationMustBeRegisteredInLocationMap(){ + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("end").build(); + + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + vrpBuilder.addVehicle(vehicle); + assertTrue(vrpBuilder.getLocationMap().containsKey("end")); + } } diff --git a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpReaderV2Test.java b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpReaderV2Test.java index aec2da95..19f29541 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpReaderV2Test.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpReaderV2Test.java @@ -70,9 +70,9 @@ public class VrpReaderV2Test { VehicleRoutingProblem vrp = builder.build(); Vehicle v1 = getVehicle("v1",vrp.getVehicles()); assertEquals(20,v1.getCapacity()); - assertEquals(100.0,v1.getCoord().getX(),0.01); + assertEquals(100.0,v1.getStartLocationCoordinate().getX(),0.01); assertEquals(0.0,v1.getEarliestDeparture(),0.01); - assertEquals("depotLoc2",v1.getLocationId()); + assertEquals("depotLoc2",v1.getStartLocationId()); assertNotNull(v1.getType()); assertEquals("vehType", v1.getType().getTypeId()); assertEquals(1000.0,v1.getLatestArrival(),0.01); @@ -229,8 +229,8 @@ public class VrpReaderV2Test { new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Vehicle v3 = getVehicle("v3",vrp.getVehicles()); - assertEquals(10.0,v3.getCoord().getX(),0.01); - assertEquals(100.0,v3.getCoord().getY(),0.01); + assertEquals(10.0,v3.getStartLocationCoordinate().getX(),0.01); + assertEquals(100.0,v3.getStartLocationCoordinate().getY(),0.01); } @Test @@ -239,7 +239,7 @@ public class VrpReaderV2Test { new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Vehicle v3 = getVehicle("v3",vrp.getVehicles()); - assertEquals("startLoc",v3.getLocationId()); + assertEquals("startLoc",v3.getStartLocationId()); } @Test @@ -286,8 +286,8 @@ public class VrpReaderV2Test { new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Vehicle v = getVehicle("v4",vrp.getVehicles()); - assertEquals(10.0,v.getCoord().getX(),0.01); - assertEquals(100.0,v.getCoord().getY(),0.01); + assertEquals(10.0,v.getStartLocationCoordinate().getX(),0.01); + assertEquals(100.0,v.getStartLocationCoordinate().getY(),0.01); } @Test diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/TestVehicleRoute.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/TestVehicleRoute.java index 6c78d14a..15047e17 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/TestVehicleRoute.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/TestVehicleRoute.java @@ -164,42 +164,49 @@ public class TestVehicleRoute { } } + @Test public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectStartLocation(){ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("end").build(); VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); assertTrue(vRoute.getStart().getLocationId().equals("start")); } + @Test public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectEndLocation(){ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("end").build(); VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); assertTrue(vRoute.getEnd().getLocationId().equals("end")); } + @Test public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectStartLocation(){ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("start").build(); VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); assertTrue(vRoute.getStart().getLocationId().equals("start")); } + @Test public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectEndLocation(){ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("start").build(); VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); assertTrue(vRoute.getEnd().getLocationId().equals("start")); } + @Test public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectStartLocationV2(){ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("start").setEndLocationId("start").build(); VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); assertTrue(vRoute.getStart().getLocationId().equals("start")); } + @Test public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectEndLocationV2(){ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("start").setEndLocationId("start").build(); VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); assertTrue(vRoute.getEnd().getLocationId().equals("start")); } + @Test public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectDepartureTime(){ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setStartLocationId("start").setEndLocationId("end").build(); VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); @@ -207,13 +214,14 @@ public class TestVehicleRoute { assertEquals(vRoute.getStart().getEndTime(),100.0,0.01); } + @Test public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectEndTime(){ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build(); VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); - assertEquals(vRoute.getEnd().getArrTime(),100.0,0.01); - assertEquals(vRoute.getEnd().getTheoreticalLatestOperationStartTime(),100.0,0.01); + assertEquals(200.0,vRoute.getEnd().getTheoreticalLatestOperationStartTime(),0.01); } + @Test public void whenSettingDepartureTimeInBetweenEarliestStartAndLatestArr_routeMustHaveCorrectDepartureTime(){ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build(); VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); @@ -222,6 +230,7 @@ public class TestVehicleRoute { assertEquals(vRoute.getDepartureTime(),150.0,0.01); } + @Test public void whenSettingDepartureEarlierThanEarliestStart_routeMustHaveEarliestDepTimeAsDepTime(){ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build(); VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); @@ -230,6 +239,7 @@ public class TestVehicleRoute { assertEquals(vRoute.getDepartureTime(),100.0,0.01); } + @Test public void whenSettingDepartureTimeLaterThanLatestArrival_routeMustHaveThisDepTime(){ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build(); VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); @@ -238,12 +248,14 @@ public class TestVehicleRoute { assertEquals(vRoute.getDepartureTime(),100.0,0.01); } + @Test public void whenCreatingEmptyRoute_itMustReturnEmptyRoute(){ @SuppressWarnings("unused") VehicleRoute route = VehicleRoute.emptyRoute(); assertTrue(true); } + @Test public void whenIniRouteWithNewVehicle_startLocationMustBeCorrect(){ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build(); Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocationId("new_start").setEndLocationId("new_end").build(); @@ -252,14 +264,16 @@ public class TestVehicleRoute { assertEquals("new_start",vRoute.getStart().getLocationId()); } + @Test public void whenIniRouteWithNewVehicle_endLocationMustBeCorrect(){ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build(); Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocationId("new_start").setEndLocationId("new_end").build(); VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build(); vRoute.setVehicleAndDepartureTime(new_vehicle, 50.0); - assertEquals("new_end",vRoute.getStart().getLocationId()); + assertEquals("new_end",vRoute.getEnd().getLocationId()); } + @Test public void whenIniRouteWithNewVehicle_depTimeMustBeEarliestDepTimeOfNewVehicle(){ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build(); Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocationId("new_start").setEndLocationId("new_end").build(); @@ -268,6 +282,7 @@ public class TestVehicleRoute { assertEquals(1000.0,vRoute.getDepartureTime(),0.01); } + @Test public void whenIniRouteWithNewVehicle_depTimeMustBeSetDepTime(){ Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build(); Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocationId("new_start").setEndLocationId("new_end").build(); diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java index 900c5ec9..389527a7 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java @@ -65,14 +65,15 @@ public class VehicleRouteBuilderTest { Shipment s2 = mock(Shipment.class); Vehicle vehicle = mock(Vehicle.class); when(vehicle.isReturnToDepot()).thenReturn(true); - when(vehicle.getLocationId()).thenReturn("vehLoc"); + when(vehicle.getStartLocationId()).thenReturn("vehLoc"); + when(vehicle.getEndLocationId()).thenReturn("vehLoc"); VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)); builder.addPickup(s); builder.addPickup(s2); builder.addDelivery(s); builder.addDelivery(s2); VehicleRoute route = builder.build(); - assertEquals(route.getEnd().getLocationId(), vehicle.getLocationId()); + assertEquals("vehLoc",route.getEnd().getLocationId()); } @Test @@ -82,7 +83,7 @@ public class VehicleRouteBuilderTest { when(s2.getDeliveryLocation()).thenReturn("delLoc"); Vehicle vehicle = mock(Vehicle.class); when(vehicle.isReturnToDepot()).thenReturn(false); - when(vehicle.getLocationId()).thenReturn("vehLoc"); + when(vehicle.getStartLocationId()).thenReturn("vehLoc"); VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)); builder.addPickup(s); builder.addPickup(s2); @@ -99,7 +100,7 @@ public class VehicleRouteBuilderTest { when(s2.getDeliveryLocation()).thenReturn("delLoc"); Vehicle vehicle = mock(Vehicle.class); when(vehicle.isReturnToDepot()).thenReturn(false); - when(vehicle.getLocationId()).thenReturn("vehLoc"); + when(vehicle.getStartLocationId()).thenReturn("vehLoc"); VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)); builder.addPickup(s); builder.addPickup(s2); @@ -119,7 +120,7 @@ public class VehicleRouteBuilderTest { when(s2.getDeliveryLocation()).thenReturn("delLoc"); Vehicle vehicle = mock(Vehicle.class); when(vehicle.isReturnToDepot()).thenReturn(false); - when(vehicle.getLocationId()).thenReturn("vehLoc"); + when(vehicle.getStartLocationId()).thenReturn("vehLoc"); when(vehicle.getLatestArrival()).thenReturn(200.0); VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)); builder.addPickup(s); diff --git a/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleImplTest.java b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleImplTest.java index 6578892a..adb5344a 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleImplTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/vehicle/VehicleImplTest.java @@ -121,12 +121,6 @@ public class VehicleImplTest { assertEquals(2.0, v.getCoord().getY(),0.01); } - @Test(expected=IllegalArgumentException.class) - public void whenStartLocationCoordIsNull_itThrowsException(){ - @SuppressWarnings("unused") - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(null).build(); - } - @Test public void whenEndLocationIsSet_itIsDoneCorrectly(){ Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").setEndLocationId("endLoc").build(); @@ -134,12 +128,6 @@ public class VehicleImplTest { assertEquals("endLoc", v.getEndLocationId()); } - @Test(expected=IllegalArgumentException.class) - public void whenEndLocationIsNull_itThrowsException(){ - @SuppressWarnings("unused") - Vehicle v = VehicleImpl.Builder.newInstance("v").setEndLocationId(null).build(); - } - @Test public void whenEndLocationCoordIsSet_itIsDoneCorrectly(){ Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").setEndLocationCoordinate(Coordinate.newInstance(1, 2)).build(); @@ -147,12 +135,7 @@ public class VehicleImplTest { assertEquals(2.0, v.getEndLocationCoordinate().getY(),0.01); } - @Test(expected=IllegalArgumentException.class) - public void whenEndLocationCoordIsNull_itThrowsException(){ - @SuppressWarnings("unused") - Vehicle v = VehicleImpl.Builder.newInstance("v").setEndLocationCoordinate(null).build(); - } - + @Test public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationIdMustBeEqualToStartLocationId(){ Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").build(); diff --git a/jsprit-examples/input/algorithmConfig_fix.xml b/jsprit-examples/input/algorithmConfig_fix.xml index b7ffdd9c..7d01a4f3 100755 --- a/jsprit-examples/input/algorithmConfig_fix.xml +++ b/jsprit-examples/input/algorithmConfig_fix.xml @@ -7,7 +7,7 @@ - 1.0 + true diff --git a/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java b/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java index 14b67a24..e3a13739 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java +++ b/jsprit-examples/src/main/java/jsprit/examples/BicycleMessenger.java @@ -318,7 +318,7 @@ public class BicycleMessenger { static double getTimeOfDirectRoute(Job job, Vehicle v, VehicleRoutingTransportCosts routingCosts) { Shipment envelope = (Shipment) job; - double direct = routingCosts.getTransportTime(v.getLocationId(), envelope.getPickupLocation(), 0.0, DriverImpl.noDriver(), v) + + double direct = routingCosts.getTransportTime(v.getStartLocationId(), envelope.getPickupLocation(), 0.0, DriverImpl.noDriver(), v) + routingCosts.getTransportTime(envelope.getPickupLocation(), envelope.getDeliveryLocation(), 0.0, DriverImpl.noDriver(), v); return direct; } diff --git a/jsprit-examples/src/main/java/jsprit/examples/ConfigureAlgorithmInCodeInsteadOfPerXml.java b/jsprit-examples/src/main/java/jsprit/examples/ConfigureAlgorithmInCodeInsteadOfPerXml.java index 339e1ecb..c81a58a7 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/ConfigureAlgorithmInCodeInsteadOfPerXml.java +++ b/jsprit-examples/src/main/java/jsprit/examples/ConfigureAlgorithmInCodeInsteadOfPerXml.java @@ -19,7 +19,7 @@ package jsprit.examples; import java.io.File; import java.util.Collection; -import jsprit.analysis.toolbox.SolutionPlotter; +import jsprit.analysis.toolbox.Plotter; import jsprit.analysis.toolbox.SolutionPrinter; import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.io.AlgorithmConfig; @@ -106,7 +106,7 @@ public class ConfigureAlgorithmInCodeInsteadOfPerXml { /* * plot */ - SolutionPlotter.plotSolutionAsPNG(problem, bestSolution, "output/solution.png", "solution"); + new Plotter(problem,bestSolution).plot("output/solution.png", "solution"); } private static AlgorithmConfig getAlgorithmConfig() { diff --git a/jsprit-examples/src/main/java/jsprit/examples/CostMatrixExample.java b/jsprit-examples/src/main/java/jsprit/examples/CostMatrixExample.java index 0357b9ef..e03bb64a 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/CostMatrixExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/CostMatrixExample.java @@ -19,7 +19,7 @@ package jsprit.examples; import java.io.File; import java.util.Collection; -import jsprit.analysis.toolbox.SolutionPlotter; +import jsprit.analysis.toolbox.Plotter; import jsprit.analysis.toolbox.SolutionPrinter; import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; @@ -110,9 +110,9 @@ public class CostMatrixExample { Collection solutions = vra.searchSolutions(); SolutionPrinter.print(Solutions.bestOf(solutions)); - - SolutionPlotter.plotSolutionAsPNG(vrp, Solutions.bestOf(solutions), "output/yo.png", "po"); - + + new Plotter(vrp, Solutions.bestOf(solutions)).plot("output/yo.png", "po"); + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExample.java b/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExample.java index 14071e2b..c26c8027 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExample.java @@ -22,7 +22,7 @@ import java.util.Collection; import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; import jsprit.analysis.toolbox.GraphStreamViewer; -import jsprit.analysis.toolbox.SolutionPlotter; +import jsprit.analysis.toolbox.Plotter; import jsprit.analysis.toolbox.SolutionPrinter; import jsprit.analysis.toolbox.StopWatch; import jsprit.core.algorithm.VehicleRoutingAlgorithm; @@ -112,8 +112,9 @@ public class MultipleDepotExample { Collection solutions = vra.searchSolutions(); SolutionPrinter.print(Solutions.bestOf(solutions)); - SolutionPlotter.plotSolutionAsPNG(vrp, Solutions.bestOf(solutions), "output/p01_solution.png", "p01"); - + + new Plotter(vrp, Solutions.bestOf(solutions)).plot("output/p01_solution.png", "p01"); + new GraphStreamViewer(vrp, Solutions.bestOf(solutions)).setRenderDelay(100).display(); } diff --git a/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExampleWithPenaltyVehicles.java b/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExampleWithPenaltyVehicles.java index 0224cb4d..9881ba15 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExampleWithPenaltyVehicles.java +++ b/jsprit-examples/src/main/java/jsprit/examples/MultipleDepotExampleWithPenaltyVehicles.java @@ -22,10 +22,10 @@ import java.util.Collection; import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; import jsprit.analysis.toolbox.GraphStreamViewer; -import jsprit.analysis.toolbox.SolutionPlotter; +import jsprit.analysis.toolbox.Plotter; import jsprit.analysis.toolbox.SolutionPrinter; -import jsprit.analysis.toolbox.StopWatch; import jsprit.analysis.toolbox.SolutionPrinter.Print; +import jsprit.analysis.toolbox.StopWatch; import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.Priority; @@ -140,8 +140,9 @@ public class MultipleDepotExampleWithPenaltyVehicles { Collection solutions = vra.searchSolutions(); SolutionPrinter.print(vrp,Solutions.bestOf(solutions),Print.VERBOSE); - SolutionPlotter.plotSolutionAsPNG(vrp, Solutions.bestOf(solutions), "output/p08_solution.png", "p08"); + new Plotter(vrp, Solutions.bestOf(solutions)).plot("output/p08_solution.png", "p08"); + new GraphStreamViewer(vrp,Solutions.bestOf(solutions)).setRenderDelay(50).display(); } diff --git a/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample.java b/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample.java index 04aafdaa..69097990 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample.java @@ -22,7 +22,6 @@ import java.util.Collection; import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; import jsprit.analysis.toolbox.Plotter; import jsprit.analysis.toolbox.Plotter.Label; -import jsprit.analysis.toolbox.SolutionPlotter; import jsprit.analysis.toolbox.SolutionPrinter; import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; @@ -65,7 +64,8 @@ public class PickupAndDeliveryExample { VehicleRoutingProblem vrp = vrpBuilder.build(); - SolutionPlotter.plotVrpAsPNG(vrp, "output/pd_solomon_r101.png", "pd_r101"); + new Plotter(vrp).plot("output/pd_solomon_r101.png", "pd_r101"); + /* * Define the required vehicle-routing algorithms to solve the above problem. diff --git a/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample2.java b/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample2.java index c235a8ae..cef1fe44 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample2.java +++ b/jsprit-examples/src/main/java/jsprit/examples/PickupAndDeliveryExample2.java @@ -23,7 +23,6 @@ import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; import jsprit.analysis.toolbox.GraphStreamViewer; import jsprit.analysis.toolbox.Plotter; import jsprit.analysis.toolbox.Plotter.Label; -import jsprit.analysis.toolbox.SolutionPlotter; import jsprit.analysis.toolbox.SolutionPrinter; import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; @@ -71,7 +70,8 @@ public class PickupAndDeliveryExample2 { VehicleRoutingProblem vrp = vrpBuilder.build(); - SolutionPlotter.plotVrpAsPNG(vrp, "output/pd_christophides_vrpnc1.png", "pd_vrpnc1"); + new Plotter(vrp).plot("output/pd_christophides_vrpnc1.png", "pd_vrpnc1"); + /* * Define the required vehicle-routing algorithms to solve the above problem. diff --git a/jsprit-examples/src/main/java/jsprit/examples/SimpleExampleOpenRoutes.java b/jsprit-examples/src/main/java/jsprit/examples/SimpleExampleOpenRoutes.java index d7b8ba24..97c34da2 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SimpleExampleOpenRoutes.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SimpleExampleOpenRoutes.java @@ -19,7 +19,7 @@ package jsprit.examples; import java.io.File; import java.util.Collection; -import jsprit.analysis.toolbox.SolutionPlotter; +import jsprit.analysis.toolbox.Plotter; import jsprit.analysis.toolbox.SolutionPrinter; import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; @@ -105,7 +105,9 @@ public class SimpleExampleOpenRoutes { /* * plot */ - SolutionPlotter.plotSolutionAsPNG(problem, bestSolution, "output/solution.png", "solution"); + + new Plotter(problem, bestSolution).plot("output/solution.png", "solution"); + } } diff --git a/jsprit-examples/src/main/java/jsprit/examples/SolomonExample.java b/jsprit-examples/src/main/java/jsprit/examples/SolomonExample.java index 25c2cacd..34cee239 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SolomonExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SolomonExample.java @@ -20,10 +20,9 @@ import java.io.File; import java.util.Collection; import jsprit.analysis.toolbox.GraphStreamViewer; -import jsprit.analysis.toolbox.Plotter; -import jsprit.analysis.toolbox.SolutionPlotter; -import jsprit.analysis.toolbox.SolutionPrinter; import jsprit.analysis.toolbox.GraphStreamViewer.Label; +import jsprit.analysis.toolbox.Plotter; +import jsprit.analysis.toolbox.SolutionPrinter; import jsprit.analysis.toolbox.SolutionPrinter.Print; import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; @@ -64,7 +63,7 @@ public class SolomonExample { */ VehicleRoutingProblem vrp = vrpBuilder.build(); - SolutionPlotter.plotVrpAsPNG(vrp, "output/solomon_C101.png", "C101"); + new Plotter(vrp).plot("output/solomon_C101.png", "C101"); /* * Define the required vehicle-routing algorithms to solve the above problem. diff --git a/jsprit-examples/src/main/java/jsprit/examples/SolomonOpenExample.java b/jsprit-examples/src/main/java/jsprit/examples/SolomonOpenExample.java index 8f35317c..1604e74b 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SolomonOpenExample.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SolomonOpenExample.java @@ -20,9 +20,9 @@ import java.io.File; import java.util.Collection; import jsprit.analysis.toolbox.GraphStreamViewer; -import jsprit.analysis.toolbox.SolutionPlotter; -import jsprit.analysis.toolbox.SolutionPrinter; import jsprit.analysis.toolbox.GraphStreamViewer.Label; +import jsprit.analysis.toolbox.Plotter; +import jsprit.analysis.toolbox.SolutionPrinter; import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import jsprit.core.algorithm.selector.SelectBest; @@ -62,7 +62,7 @@ public class SolomonOpenExample { */ VehicleRoutingProblem vrp = vrpBuilder.build(); - SolutionPlotter.plotVrpAsPNG(vrp, "output/solomon_C101_open.png", "C101"); + new Plotter(vrp).plot("output/solomon_C101_open.png", "C101"); /* * Define the required vehicle-routing algorithms to solve the above problem. diff --git a/jsprit-examples/src/main/java/jsprit/examples/SolomonR101Example.java b/jsprit-examples/src/main/java/jsprit/examples/SolomonR101Example.java index f89d2171..f1251299 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/SolomonR101Example.java +++ b/jsprit-examples/src/main/java/jsprit/examples/SolomonR101Example.java @@ -19,7 +19,7 @@ package jsprit.examples; import java.io.File; import java.util.Collection; -import jsprit.analysis.toolbox.SolutionPlotter; +import jsprit.analysis.toolbox.Plotter; import jsprit.analysis.toolbox.SolutionPrinter; import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; @@ -60,7 +60,7 @@ public class SolomonR101Example { */ VehicleRoutingProblem vrp = vrpBuilder.build(); - SolutionPlotter.plotVrpAsPNG(vrp, "output/solomon_R101.png", "R101"); + new Plotter(vrp).plot("output/solomon_R101.png", "R101"); /* * Define the required vehicle-routing algorithms to solve the above problem. @@ -91,9 +91,7 @@ public class SolomonR101Example { /* * Plot solution. */ - SolutionPlotter.plotSolutionAsPNG(vrp, solution, "output/solomon_R101_solution.png","R101"); - - + new Plotter(vrp,solution).plot( "output/solomon_R101_solution.png","R101"); } diff --git a/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample2.java b/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample2.java index 7deb9c71..b2b8bdb3 100644 --- a/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample2.java +++ b/jsprit-examples/src/main/java/jsprit/examples/VRPWithBackhaulsExample2.java @@ -21,7 +21,6 @@ import java.util.Collection; import jsprit.analysis.toolbox.Plotter; import jsprit.analysis.toolbox.Plotter.Label; -import jsprit.analysis.toolbox.SolutionPlotter; import jsprit.analysis.toolbox.SolutionPrinter; import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; @@ -69,7 +68,8 @@ public class VRPWithBackhaulsExample2 { */ VehicleRoutingProblem vrp = vrpBuilder.build(); - SolutionPlotter.plotVrpAsPNG(vrp, "output/vrpwbh_christophides_vrpnc1.png", "pd_vrpnc1"); + new Plotter(vrp).plot("output/vrpwbh_christophides_vrpnc1.png", "pd_vrpnc1"); + /* * Define the required vehicle-routing algorithms to solve the above problem.