diff --git a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/AlgorithmEventsRecorder.java b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/AlgorithmEventsRecorder.java index 266ce38a..c772ea7e 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/AlgorithmEventsRecorder.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/AlgorithmEventsRecorder.java @@ -65,7 +65,6 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis public static final int CLEAR_SOLUTION = 3; - public static final int RENDER_FINAL_SOLUTION = 4; private Graph graph; @@ -104,6 +103,7 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis initialiseGraph(vrp); } + @Deprecated public AlgorithmEventsRecorder(VehicleRoutingProblem vrp, String dgsFileLocation, boolean renderShipments) { this.renderShipments = renderShipments; new AlgorithmEventsRecorder(vrp, dgsFileLocation); @@ -352,15 +352,15 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis private void addVehicle(Vehicle vehicle) { String startId = makeStartId(vehicle); Node node = graph.addNode(startId); - node.addAttribute("x",vehicle.getStartLocationCoordinate().getX()); - node.addAttribute("y",vehicle.getStartLocationCoordinate().getY()); + node.addAttribute("x",vehicle.getStartLocation().getCoordinate().getX()); + node.addAttribute("y", vehicle.getStartLocation().getCoordinate().getY()); node.addAttribute("ui.class","depot"); String endId = makeEndId(vehicle); if(!startId.equals(endId)){ Node endNode = graph.addNode(endId); - endNode.addAttribute("x",vehicle.getEndLocationCoordinate().getX()); - endNode.addAttribute("y",vehicle.getEndLocationCoordinate().getY()); + endNode.addAttribute("x", vehicle.getEndLocation().getCoordinate().getX()); + endNode.addAttribute("y", vehicle.getEndLocation().getCoordinate().getY()); endNode.addAttribute("ui.class","depot"); } } @@ -370,7 +370,7 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis } private String makeEndId(Vehicle vehicle) { - if(vehicle.getStartLocationId().equals(vehicle.getEndLocationId())) return makeStartId(vehicle); + if(vehicle.getStartLocation().getId().equals(vehicle.getEndLocation().getId())) return makeStartId(vehicle); return vehicle.getId() + "_end"; } @@ -436,15 +436,14 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis String node_i; - if(isFirst(insertionIndex,route)) { + if(isFirst(insertionIndex)) { node_i = makeStartId(data.getSelectedVehicle()); } else { TourActivity.JobActivity jobActivity = (TourActivity.JobActivity) route.getActivities().get(insertionIndex - 1); node_i = getNodeId(jobActivity); } - String node_k = nodeId; - String edgeId_1 = node_i + "_" + node_k; + String edgeId_1 = node_i + "_" + nodeId; String node_j; if(isLast(insertionIndex,route)) { node_j = makeEndId(data.getSelectedVehicle()); @@ -453,12 +452,12 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis TourActivity.JobActivity jobActivity = (TourActivity.JobActivity) route.getActivities().get(insertionIndex); node_j = getNodeId(jobActivity); } - String edgeId_2 = node_k + "_" + node_j; + String edgeId_2 = nodeId + "_" + node_j; - addEdge(edgeId_1, node_i, node_k); + addEdge(edgeId_1, node_i, nodeId); if(!(isLast(insertionIndex,route) && !data.getSelectedVehicle().isReturnToDepot())) { - addEdge(edgeId_2, node_k, node_j); + addEdge(edgeId_2, nodeId, node_j); if (!route.getActivities().isEmpty()) { removeEdge(node_i + "_" + node_j); } @@ -511,7 +510,7 @@ public class AlgorithmEventsRecorder implements RuinListener, IterationStartsLis graph.getEdge(edgeId).addAttribute("ui.class","removed"); } - private boolean isFirst(int index, VehicleRoute route) { + private boolean isFirst(int index) { return index == 0; } 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 513bdb4b..32e7a0cb 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/GraphStreamViewer.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/GraphStreamViewer.java @@ -112,6 +112,8 @@ public class GraphStreamViewer { "}" ; + + @SuppressWarnings("UnusedDeclaration") public static String SIMPLE_WHITE = "node {" + " size: 10px, 10px;" + @@ -287,6 +289,7 @@ public class GraphStreamViewer { return this; } + @Deprecated public GraphStreamViewer setEnableAutoLayout(boolean enableAutoLayout) { return this; } @@ -325,7 +328,7 @@ public class GraphStreamViewer { View view = createEmbeddedView(g,scaling); - JFrame jframe = createJFrame(view,scaling); + createJFrame(view,scaling); render(g, view); } @@ -363,7 +366,7 @@ public class GraphStreamViewer { //conf jframe jframe.setSize((int)(800*scaling),(int)(580*scaling)); jframe.setLocationRelativeTo(null); - jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + jframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); jframe.setVisible(true); jframe.pack(); jframe.setTitle("jsprit - GraphStream"); @@ -548,20 +551,19 @@ public class GraphStreamViewer { } private void renderVehicle(Graph g, Vehicle vehicle, Label label) { - String nodeId = makeId(vehicle.getId(),vehicle.getStartLocationId()); + String nodeId = makeId(vehicle.getId(),vehicle.getStartLocation().getId()); Node vehicleStart = g.addNode(nodeId); if(label.equals(Label.ID)) vehicleStart.addAttribute("ui.label", "depot"); // if(label.equals(Label.ACTIVITY)) n.addAttribute("ui.label", "start"); - vehicleStart.addAttribute("x", vehicle.getStartLocationCoordinate().getX()); - vehicleStart.addAttribute("y", vehicle.getStartLocationCoordinate().getY()); + vehicleStart.addAttribute("x", vehicle.getStartLocation().getCoordinate().getX()); + vehicleStart.addAttribute("y", vehicle.getStartLocation().getCoordinate().getY()); vehicleStart.setAttribute("ui.class", "depot"); - if(!vehicle.getStartLocationId().equals(vehicle.getEndLocationId())){ - Node vehicleEnd = g.addNode(makeId(vehicle.getId(),vehicle.getEndLocationId())); + if(!vehicle.getStartLocation().getId().equals(vehicle.getEndLocation().getId())){ + Node vehicleEnd = g.addNode(makeId(vehicle.getId(),vehicle.getEndLocation().getId())); 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.addAttribute("x", vehicle.getEndLocation().getCoordinate().getX()); + vehicleEnd.addAttribute("y", vehicle.getEndLocation().getCoordinate().getY()); vehicleEnd.setAttribute("ui.class", "depot"); } @@ -569,7 +571,7 @@ public class GraphStreamViewer { 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().getStartLocationId()); + String prevIdentifier = makeId(route.getVehicle().getId(),route.getVehicle().getStartLocation().getId()); if(label.equals(Label.ACTIVITY) || label.equals(Label.JOB_NAME)){ Node n = g.getNode(prevIdentifier); n.addAttribute("ui.label", "start"); @@ -601,7 +603,7 @@ public class GraphStreamViewer { sleep(renderDelay_in_ms); } if(route.getVehicle().isReturnToDepot()){ - String lastIdentifier = makeId(route.getVehicle().getId(),route.getVehicle().getEndLocationId()); + String lastIdentifier = makeId(route.getVehicle().getId(),route.getVehicle().getEndLocation().getId()); 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 4e34bc4e..83598187 100644 --- a/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/Plotter.java +++ b/jsprit-analysis/src/main/java/jsprit/analysis/toolbox/Plotter.java @@ -147,7 +147,7 @@ public class Plotter { * */ public static enum Label { - ID, SIZE, NO_LABEL + ID, SIZE, @SuppressWarnings("UnusedDeclaration")NO_LABEL } private Label label = Label.SIZE; @@ -181,7 +181,7 @@ public class Plotter { /** * Constructs Plotter with problem. Thus only the problem can be rendered. * - * @param vrp + * @param vrp the routing problem */ public Plotter(VehicleRoutingProblem vrp) { super(); @@ -191,8 +191,8 @@ public class Plotter { /** * Constructs Plotter with problem and solution to render them both. * - * @param vrp - * @param solution + * @param vrp the routing problem + * @param solution the solution */ public Plotter(VehicleRoutingProblem vrp, VehicleRoutingProblemSolution solution) { super(); @@ -204,8 +204,8 @@ public class Plotter { /** * Constructs Plotter with problem and routes to render individual routes. * - * @param vrp - * @param routes + * @param vrp the routing problem + * @param routes routes */ public Plotter(VehicleRoutingProblem vrp, Collection routes) { super(); @@ -214,17 +214,7 @@ public class Plotter { plotSolutionAsWell = true; } - /** - * - * @param show - * @return plotter - * @deprecated always true - */ - @Deprecated - public Plotter setShowFirstActivity(boolean show){ - return this; - } - + @SuppressWarnings("UnusedDeclaration") public Plotter setScalingFactor(double scalingFactor){ this.scalingFactor=scalingFactor; return this; @@ -232,8 +222,8 @@ public class Plotter { /** * Sets a label. - * @param label - * @return + * @param label of jobs + * @return plotter */ public Plotter setLabel(Label label){ this.label = label; @@ -243,12 +233,13 @@ public class Plotter { /** * Sets a bounding box to zoom in to certain areas. * - * @param minX - * @param minY - * @param maxX - * @param maxY + * @param minX lower left x + * @param minY lower left y + * @param maxX upper right x + * @param maxY upper right y * @return */ + @SuppressWarnings("UnusedDeclaration") public Plotter setBoundingBox(double minX, double minY, double maxX, double maxY){ boundingBox = new BoundingBox(minX,minY,maxX,maxY); return this; @@ -257,8 +248,8 @@ public class Plotter { /** * Flag that indicates whether shipments should be rendered as well. * - * @param plotShipments - * @return + * @param plotShipments flag to plot shipment + * @return the plotter */ public Plotter plotShipments(boolean plotShipments) { this.plotShipments = plotShipments; @@ -287,7 +278,7 @@ public class Plotter { private void plot(VehicleRoutingProblem vrp, final Collection routes, String pngFile, String title){ log.info("plot to " + pngFile); - XYSeriesCollection problem = null; + XYSeriesCollection problem; XYSeriesCollection solution = null; final XYSeriesCollection shipments; try { @@ -520,13 +511,13 @@ public class Plotter { XYDataItem dataItem = new XYDataItem(s.getPickupLocation().getCoordinate().getX()*scalingFactor, s.getPickupLocation().getCoordinate().getY()*scalingFactor); activities.add(dataItem); addLabel(s, dataItem); - markItem(dataItem,Activity.PICKUP, job); + markItem(dataItem,Activity.PICKUP); containsPickupAct = true; XYDataItem dataItem2 = new XYDataItem(s.getDeliveryLocation().getCoordinate().getX()*scalingFactor, s.getDeliveryLocation().getCoordinate().getY()*scalingFactor); activities.add(dataItem2); addLabel(s, dataItem2); - markItem(dataItem2,Activity.DELIVERY, job); + markItem(dataItem2,Activity.DELIVERY); containsDeliveryAct = true; } else if(job instanceof Pickup){ @@ -535,7 +526,7 @@ public class Plotter { XYDataItem dataItem = new XYDataItem(coord.getX()*scalingFactor, coord.getY()*scalingFactor); activities.add(dataItem); addLabel(service, dataItem); - markItem(dataItem, Activity.PICKUP, job); + markItem(dataItem, Activity.PICKUP); containsPickupAct = true; } else if(job instanceof Delivery){ @@ -544,7 +535,7 @@ public class Plotter { XYDataItem dataItem = new XYDataItem(coord.getX()*scalingFactor, coord.getY()*scalingFactor); activities.add(dataItem); addLabel(service, dataItem); - markItem(dataItem, Activity.DELIVERY, job); + markItem(dataItem, Activity.DELIVERY); containsDeliveryAct = true; } else if(job instanceof Service){ @@ -553,7 +544,7 @@ public class Plotter { XYDataItem dataItem = new XYDataItem(coord.getX()*scalingFactor, coord.getY()*scalingFactor); activities.add(dataItem); addLabel(service, dataItem); - markItem(dataItem, Activity.SERVICE, job); + markItem(dataItem, Activity.SERVICE); containsServiceAct = true; } else{ @@ -591,18 +582,18 @@ public class Plotter { private void retrieveActivities(VehicleRoutingProblem vrp) throws NoLocationFoundException{ activities = new XYSeries("activities", false, true); for(Vehicle v : vrp.getVehicles()){ - Coordinate startCoord = v.getStartLocationCoordinate(); - if(startCoord == null) throw new NoLocationFoundException(); - XYDataItem item = new XYDataItem(startCoord.getX()*scalingFactor, startCoord.getY()*scalingFactor); - markItem(item,Activity.START, null); + Coordinate start_coordinate = v.getStartLocation().getCoordinate(); + if(start_coordinate == null) throw new NoLocationFoundException(); + XYDataItem item = new XYDataItem(start_coordinate.getX()*scalingFactor, start_coordinate.getY()*scalingFactor); + markItem(item,Activity.START); activities.add(item); - if(!v.getStartLocationId().equals(v.getEndLocationId())){ - Coordinate endCoord = v.getEndLocationCoordinate(); - if(endCoord == null) throw new NoLocationFoundException(); - XYDataItem enditem = new XYDataItem(endCoord.getX()*scalingFactor,endCoord.getY()*scalingFactor); - markItem(enditem,Activity.END, null); - activities.add(enditem); + if(!v.getStartLocation().getId().equals(v.getEndLocation().getId())){ + Coordinate end_coordinate = v.getEndLocation().getCoordinate(); + if(end_coordinate == null) throw new NoLocationFoundException(); + XYDataItem end_item = new XYDataItem(end_coordinate.getX()*scalingFactor,end_coordinate.getY()*scalingFactor); + markItem(end_item,Activity.END); + activities.add(end_item); } } for(Job job : vrp.getJobs().values()){ @@ -615,7 +606,7 @@ public class Plotter { } } - private void markItem(XYDataItem item, Activity activity, Job job) { + private void markItem(XYDataItem item, Activity activity) { activitiesByDataItem.put(item,activity); } 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 53229181..13d77870 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 @@ -18,6 +18,7 @@ package jsprit.core.algorithm.recreate; import jsprit.core.algorithm.state.InternalStates; import jsprit.core.problem.JobActivityFactory; +import jsprit.core.problem.Location; import jsprit.core.problem.constraint.HardActivityConstraint; import jsprit.core.problem.constraint.HardActivityConstraint.ConstraintsStatus; import jsprit.core.problem.constraint.HardRouteConstraint; @@ -38,7 +39,10 @@ import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.PriorityQueue; @@ -127,7 +131,7 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC /** * map that memorizes the costs with newVehicle, which is a cost-snapshot at tour-activities. */ - Map activity2costWithNewVehicle = new HashMap(); +// Map activity2costWithNewVehicle = new HashMap(); /** * priority queue that stores insertion-data by insertion-costs in ascending order. @@ -197,7 +201,7 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC * memorize transport and activity costs with new vehicle without inserting k */ sumOf_prevCosts_newVehicle += transportCost_prevAct_nextAct_newVehicle + activityCost_nextAct; - activity2costWithNewVehicle.put(nextAct, sumOf_prevCosts_newVehicle); +// activity2costWithNewVehicle.put(nextAct, sumOf_prevCosts_newVehicle); /** * departure time at nextAct with new vehicle @@ -284,20 +288,14 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC insertionData.setVehicleDepartureTime(start.getEndTime()); return insertionData; } - - /** - * initialize start and end of tour. - * - * @param newVehicle - * @param newVehicleDepartureTime - */ + private void initialiseStartAndEnd(final Vehicle newVehicle, double newVehicleDepartureTime) { if(start == null){ start = new Start(newVehicle.getStartLocation(), newVehicle.getEarliestDeparture(), Double.MAX_VALUE); start.setEndTime(newVehicleDepartureTime); } else{ - start.setLocationId(newVehicle.getStartLocationId()); + start.setLocation(Location.newInstance(newVehicle.getStartLocation().getId())); start.setTheoreticalEarliestOperationStartTime(newVehicle.getEarliestDeparture()); start.setTheoreticalLatestOperationStartTime(Double.MAX_VALUE); start.setEndTime(newVehicleDepartureTime); @@ -307,7 +305,7 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC end = new End(newVehicle.getEndLocation(), 0.0, newVehicle.getLatestArrival()); } else{ - end.setLocationId(newVehicle.getEndLocationId()); + end.setLocation(Location.newInstance(newVehicle.getEndLocation().getId())); end.setTheoreticalEarliestOperationStartTime(0.0); end.setTheoreticalLatestOperationStartTime(newVehicle.getLatestArrival()); } @@ -323,10 +321,6 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC return prevCost; } - /** - * creates a comparator to sort insertion-data in insertionQueue in ascending order according insertion costs. - * @return - */ private Comparator getComparator() { return new Comparator() { 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 818f5c92..16bf271b 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/VehicleRoutingProblem.java @@ -365,10 +365,10 @@ public class VehicleRoutingProblem { if(!vehicleTypes.contains(vehicle.getType())){ vehicleTypes.add(vehicle.getType()); } - String startLocationId = vehicle.getStartLocationId(); - tentative_coordinates.put(startLocationId, vehicle.getStartLocationCoordinate()); - if(!vehicle.getEndLocationId().equals(startLocationId)){ - tentative_coordinates.put(vehicle.getEndLocationId(), vehicle.getEndLocationCoordinate()); + String startLocationId = vehicle.getStartLocation().getId(); + tentative_coordinates.put(startLocationId, vehicle.getStartLocation().getCoordinate()); + if(!vehicle.getEndLocation().getId().equals(startLocationId)){ + tentative_coordinates.put(vehicle.getEndLocation().getId(), vehicle.getEndLocation().getCoordinate()); } return this; } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/job/Delivery.java b/jsprit-core/src/main/java/jsprit/core/problem/job/Delivery.java index 4cd298be..387d7db8 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/job/Delivery.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/job/Delivery.java @@ -52,8 +52,6 @@ public class Delivery extends Service{ public Delivery build(){ if(location == null) { location = Location.Builder.newInstance().setCoordinate(coord).setId(locationId).build(); -// if(coord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not."); -// locationId = coord.toString(); } this.setType("delivery"); super.capacity = super.capacityBuilder.build(); diff --git a/jsprit-core/src/main/java/jsprit/core/problem/job/Pickup.java b/jsprit-core/src/main/java/jsprit/core/problem/job/Pickup.java index 9b191b7b..9860d9ff 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/job/Pickup.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/job/Pickup.java @@ -54,8 +54,6 @@ public class Pickup extends Service { public Pickup build(){ if(location == null) { location = Location.Builder.newInstance().setCoordinate(coord).setId(locationId).build(); -// if(coord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not."); -// locationId = coord.toString(); } this.setType("pickup"); super.capacity = super.capacityBuilder.build(); diff --git a/jsprit-core/src/main/java/jsprit/core/problem/job/Service.java b/jsprit-core/src/main/java/jsprit/core/problem/job/Service.java index b60653fc..e27bfb8f 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/job/Service.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/job/Service.java @@ -191,11 +191,6 @@ public class Service extends AbstractJob { public Service build(){ if(location == null) { location = Location.Builder.newInstance().setCoordinate(coord).setId(locationId).build(); -// if (locationId == null) { -// if (coord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not."); -// locationId = coord.toString(); -// } -// } this.setType("service"); capacity = capacityBuilder.build(); diff --git a/jsprit-core/src/main/java/jsprit/core/problem/job/Shipment.java b/jsprit-core/src/main/java/jsprit/core/problem/job/Shipment.java index a31977e8..e7a4f1d8 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/job/Shipment.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/job/Shipment.java @@ -299,13 +299,9 @@ public class Shipment extends AbstractJob{ public Shipment build(){ if(pickupLocation_ == null) { this.pickupLocation_ = Location.Builder.newInstance().setCoordinate(pickupCoord).setId(pickupLocation).build(); -// if(pickupCoord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not."); -// pickupLocation = pickupCoord.toString(); } if(deliveryLocation_ == null) { this.deliveryLocation_ = Location.Builder.newInstance().setCoordinate(deliveryCoord).setId(deliveryLocation).build(); -// if(deliveryCoord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not."); -// deliveryLocation = deliveryCoord.toString(); } capacity = capacityBuilder.build(); skills = skillBuilder.build(); diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/InfiniteVehicles.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/InfiniteVehicles.java index 71b166f7..77cbea16 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/InfiniteVehicles.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/InfiniteVehicles.java @@ -19,7 +19,10 @@ package jsprit.core.problem.vehicle; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; @@ -30,7 +33,7 @@ class InfiniteVehicles implements VehicleFleetManager{ private Map types = new HashMap(); - private List sortedTypes = new ArrayList(); +// private List sortedTypes = new ArrayList(); public InfiniteVehicles(Collection vehicles){ extractTypes(vehicles); @@ -44,10 +47,9 @@ class InfiniteVehicles implements VehicleFleetManager{ private void extractTypes(Collection vehicles) { for(Vehicle v : vehicles){ - VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(),v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills()); + VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocation().getId(),v.getEndLocation().getId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills()); types.put(typeKey,v); - sortedTypes.add(typeKey); - +// sortedTypes.add(typeKey); } } @@ -81,7 +83,7 @@ class InfiniteVehicles implements VehicleFleetManager{ @Override public Collection getAvailableVehicles(Vehicle withoutThisType) { Collection vehicles = new ArrayList(); - VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocationId(), withoutThisType.getEndLocationId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills()); + VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocation().getId(), withoutThisType.getEndLocation().getId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills()); for(VehicleTypeKey key : types.keySet()){ if(!key.equals(thisKey)){ vehicles.add(types.get(key)); diff --git a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleFleetManagerImpl.java b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleFleetManagerImpl.java index 052075d5..3109d025 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleFleetManagerImpl.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/vehicle/VehicleFleetManagerImpl.java @@ -28,20 +28,6 @@ class VehicleFleetManagerImpl implements VehicleFleetManager { public VehicleFleetManagerImpl newInstance(Collection vehicles){ return new VehicleFleetManagerImpl(vehicles); } - - @Deprecated - public static VehicleFleetManager createDefaultFleetManager() { - return new DefaultFleetManager(); - } - - public static class DefaultFleetManager extends VehicleFleetManagerImpl { - - public DefaultFleetManager() { - super(Collections. emptyList()); - - } - - } static class TypeContainer { @@ -92,17 +78,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager { makeMap(); logger.info("initialise " + this); } - - public VehicleFleetManagerImpl(Collection vehicles, Collection lockedVehicles) { - this.vehicles = vehicles; - makeMap(); - this.lockedVehicles = new HashSet(); - for(Vehicle v : lockedVehicles){ - lock(v); - } - logger.info("initialise " + this); - } - + @Override public String toString() { return "[name=finiteVehicles]"; @@ -120,7 +96,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager { if(v.getType() == null){ throw new IllegalStateException("vehicle needs type"); } - VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(), v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills()); + VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocation().getId(), v.getEndLocation().getId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills()); if(!typeMapOfAvailableVehicles.containsKey(typeKey)){ typeMapOfAvailableVehicles.put(typeKey, new TypeContainer()); } @@ -129,7 +105,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager { } private void removeVehicle(Vehicle v){ - VehicleTypeKey key = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(), v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills()); + VehicleTypeKey key = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocation().getId(), v.getEndLocation().getId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills()); if(typeMapOfAvailableVehicles.containsKey(key)){ typeMapOfAvailableVehicles.get(key).remove(v); } @@ -161,7 +137,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager { @Override public Collection getAvailableVehicles(Vehicle withoutThisType) { List vehicles = new ArrayList(); - VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocationId(), withoutThisType.getEndLocationId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills()); + VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocation().getId(), withoutThisType.getEndLocation().getId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills()); for(VehicleTypeKey key : typeMapOfAvailableVehicles.keySet()){ if(key.equals(thisKey)) continue; if(!typeMapOfAvailableVehicles.get(key).isEmpty()){ @@ -225,12 +201,10 @@ class VehicleFleetManagerImpl implements VehicleFleetManager { throw new IllegalStateException("no vehicle must be locked"); } } - + + @Deprecated public int sizeOfLockedVehicles(){ return lockedVehicles.size(); } - - - } 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 d28721da..73d4b6f3 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 @@ -17,6 +17,7 @@ package jsprit.core.algorithm.recreate; import jsprit.core.problem.Capacity; +import jsprit.core.problem.Location; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.job.Service; import jsprit.core.problem.solution.route.VehicleRoute; @@ -48,8 +49,8 @@ public class CalcVehicleTypeDependentServiceInsertionTest { veh2 = mock(Vehicle.class); when(veh1.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type1").build()); when(veh2.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type2").build()); - when(veh1.getStartLocationId()).thenReturn("loc1"); - when(veh2.getStartLocationId()).thenReturn("loc2"); + when(veh1.getStartLocation()).thenReturn(Location.newInstance("loc1")); + when(veh2.getStartLocation()).thenReturn(Location.newInstance("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/ShipmentInsertionCalculatorTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculatorTest.java index 6f03548a..94dea056 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculatorTest.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculatorTest.java @@ -22,8 +22,11 @@ import jsprit.core.problem.AbstractActivity; import jsprit.core.problem.JobActivityFactory; import jsprit.core.problem.Location; import jsprit.core.problem.VehicleRoutingProblem; -import jsprit.core.problem.constraint.*; +import jsprit.core.problem.constraint.ConstraintManager; import jsprit.core.problem.constraint.ConstraintManager.Priority; +import jsprit.core.problem.constraint.HardRouteConstraint; +import jsprit.core.problem.constraint.PickupAndDeliverShipmentLoadActivityLevelConstraint; +import jsprit.core.problem.constraint.ShipmentPickupsFirstConstraint; import jsprit.core.problem.cost.VehicleRoutingActivityCosts; import jsprit.core.problem.cost.VehicleRoutingTransportCosts; import jsprit.core.problem.driver.Driver; @@ -71,14 +74,6 @@ public class ShipmentInsertionCalculatorTest { }; - HardActivityConstraint hardActivityLevelConstraint = new HardActivityConstraint() { - - @Override - public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct,TourActivity newAct, TourActivity nextAct, double prevActDepTime) { - return ConstraintsStatus.FULFILLED; - } - }; - HardRouteConstraint hardRouteLevelConstraint = new HardRouteConstraint(){ @Override @@ -98,7 +93,7 @@ public class ShipmentInsertionCalculatorTest { public void doBefore(){ routingCosts = CostFactory.createManhattanCosts(); VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 2).setCostPerDistance(1).build(); - vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build(); + vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("0,0")).setType(type).build(); activityInsertionCostsCalculator = new LocalActivityInsertionCostsCalculator(routingCosts, activityCosts); createInsertionCalculator(hardRouteLevelConstraint); vehicleRoutingProblem = mock(VehicleRoutingProblem.class); @@ -112,7 +107,7 @@ public class ShipmentInsertionCalculatorTest { @Test public void whenCalculatingInsertionCostsOfShipment_itShouldReturnCorrectCostValue(){ - Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocationId("10,0").build(); + Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); VehicleRoute route = VehicleRoute.emptyRoute(); JobActivityFactory activityFactory = mock(JobActivityFactory.class); List activities = new ArrayList(); @@ -126,8 +121,8 @@ public class ShipmentInsertionCalculatorTest { @Test public void whenCalculatingInsertionIntoExistingRoute_itShouldReturnCorrectCosts(){ - Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocationId("10,0").build(); - Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocationId("0,0").build(); + Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); + Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); VehicleRoute route = VehicleRoute.emptyRoute(); when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment)); new Inserter(new InsertionListeners(), vehicleRoutingProblem).insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route); @@ -156,8 +151,8 @@ public class ShipmentInsertionCalculatorTest { @Test public void whenInsertingShipmentInRouteWithNotEnoughCapacity_itShouldReturnNoInsertion(){ - Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocationId("10,0").build(); - Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocationId("0,0").build(); + Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); + Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); VehicleRoute route = VehicleRoute.emptyRoute(); when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment)); new Inserter(new InsertionListeners(), vehicleRoutingProblem).insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route); @@ -185,9 +180,9 @@ public class ShipmentInsertionCalculatorTest { @Test public void whenInsertingThirdShipment_itShouldCalcCorrectVal(){ - Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocationId("10,0").build(); - Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocationId("0,0").build(); - Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocationId("9,10").build(); + Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); + Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); + Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("9,10")).build(); VehicleRoute route = VehicleRoute.emptyRoute(); when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment)); @@ -211,9 +206,9 @@ public class ShipmentInsertionCalculatorTest { @Test public void whenInsertingThirdShipment_itShouldCalcCorrectVal2(){ - Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocationId("10,0").build(); - Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocationId("0,0").build(); - Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocationId("9,9").build(); + Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); + Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); + Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("9,9")).build(); when(vehicleRoutingProblem.copyAndGetActivities(shipment)).thenReturn(getTourActivities(shipment)); when(vehicleRoutingProblem.copyAndGetActivities(shipment2)).thenReturn(getTourActivities(shipment2)); VehicleRoute route = VehicleRoute.emptyRoute(); @@ -237,9 +232,9 @@ public class ShipmentInsertionCalculatorTest { @Test public void whenInstertingShipmentWithLoadConstraintWhereCapIsNotSufficient_capConstraintsAreFulfilled(){ - Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocationId("10,0").build(); - Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocationId("0,0").build(); - Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocationId("9,9").build(); + Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("10,0")).build(); + Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); + Shipment shipment3 = Shipment.Builder.newInstance("s3").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,0").build()).setDeliveryLocation(Location.newInstance("9,9")).build(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem vrp = vrpBuilder.addJob(shipment).addJob(shipment2).addJob(shipment3).build(); @@ -270,8 +265,8 @@ public class ShipmentInsertionCalculatorTest { @Test public void whenInsertingServiceWhileNoCapIsAvailable_itMustReturnNoInsertionData(){ - Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocationId("0,0").build(); - Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocationId("0,0").build(); + Shipment shipment = Shipment.Builder.newInstance("s").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("0,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); + Shipment shipment2 = Shipment.Builder.newInstance("s2").addSizeDimension(0, 1).setPickupLocation(Location.Builder.newInstance().setId("10,10").build()).setDeliveryLocation(Location.newInstance("0,0")).build(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem vrp = vrpBuilder.addJob(shipment).addJob(shipment2).build(); 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 4d36bc99..9ad6052c 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 @@ -84,8 +84,8 @@ public class TestInserter { public void whenInsertingServiceAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation(){ Service service = mock(Service.class); Vehicle vehicle = mock(Vehicle.class); - when(vehicle.getStartLocationId()).thenReturn("vehLoc"); - when(vehicle.getEndLocationId()).thenReturn("vehLoc"); + when(vehicle.getStartLocation()).thenReturn(Location.newInstance("vehLoc")); + when(vehicle.getEndLocation()).thenReturn(Location.newInstance("vehLoc")); when(vehicle.isReturnToDepot()).thenReturn(false); when(vehicle.getId()).thenReturn("vehId"); @@ -128,7 +128,7 @@ public class TestInserter { VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); //start - pick(shipment) - del(shipment) - end - Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setDeliveryLocationId("delLoc").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setDeliveryLocation(Location.newInstance("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); InsertionData iData = mock(InsertionData.class); when(iData.getPickupInsertionIndex()).thenReturn(2); @@ -164,7 +164,7 @@ public class TestInserter { VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); //start - pick(shipment) - del(shipment) - end - Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setDeliveryLocationId("delLoc").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); + Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setDeliveryLocation(Location.newInstance("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build(); InsertionData iData = mock(InsertionData.class); when(iData.getPickupInsertionIndex()).thenReturn(2); when(iData.getDeliveryInsertionIndex()).thenReturn(2); @@ -186,12 +186,12 @@ public class TestInserter { Shipment shipment = mock(Shipment.class); Capacity capacity = Capacity.Builder.newInstance().build(); when(shipment.getSize()).thenReturn(capacity); - Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setStartLocationId("vehLoc").setType(mock(VehicleType.class)).build(); - Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setStartLocationId("newVehLoc").setType(mock(VehicleType.class)).build(); + Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setStartLocation(Location.newInstance("vehLoc")).setType(mock(VehicleType.class)).build(); + Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setStartLocation(Location.newInstance("newVehLoc")).setType(mock(VehicleType.class)).build(); VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); //start - pick(shipment) - del(shipment) - end - Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocationId("delLoc").build(); + Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")).build(); InsertionData iData = mock(InsertionData.class); when(iData.getPickupInsertionIndex()).thenReturn(2); @@ -203,7 +203,7 @@ public class TestInserter { Inserter inserter = new Inserter(mock(InsertionListeners.class), vehicleRoutingProblem); inserter.insertJob(shipmentToInsert, iData, route); - assertEquals(route.getEnd().getLocation().getId(),newVehicle.getEndLocationId()); + assertEquals(route.getEnd().getLocation().getId(),newVehicle.getEndLocation().getId()); } @Test @@ -211,12 +211,12 @@ public class TestInserter { Shipment shipment = mock(Shipment.class); Capacity capacity = Capacity.Builder.newInstance().build(); when(shipment.getSize()).thenReturn(capacity); - Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setStartLocationId("vehLoc").setType(mock(VehicleType.class)).build(); - Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setStartLocationId("newVehLoc").setType(mock(VehicleType.class)).build(); + Vehicle vehicle = VehicleImpl.Builder.newInstance("vehId").setReturnToDepot(false).setStartLocation(Location.newInstance("vehLoc")).setType(mock(VehicleType.class)).build(); + Vehicle newVehicle = VehicleImpl.Builder.newInstance("newVehId").setReturnToDepot(false).setStartLocation(Location.newInstance("newVehLoc")).setType(mock(VehicleType.class)).build(); VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); //start - pick(shipment) - del(shipment) - end - Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocationId("delLoc").build(); + Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")).build(); InsertionData iData = mock(InsertionData.class); when(iData.getPickupInsertionIndex()).thenReturn(2); @@ -242,7 +242,7 @@ public class TestInserter { VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)).addPickup(shipment).addDelivery(shipment).build(); //start - pick(shipment) - del(shipment) - end - Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocationId("delLoc").build(); + Shipment shipmentToInsert = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")).build(); InsertionData iData = mock(InsertionData.class); when(iData.getPickupInsertionIndex()).thenReturn(0); diff --git a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLReaderTest.java b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLReaderTest.java index 1e3c0593..f471d0a5 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLReaderTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLReaderTest.java @@ -90,9 +90,9 @@ public class VrpXMLReaderTest { VehicleRoutingProblem vrp = builder.build(); Vehicle v1 = getVehicle("v1",vrp.getVehicles()); assertEquals(20,v1.getType().getCapacityDimensions().get(0)); - assertEquals(100.0,v1.getStartLocationCoordinate().getX(),0.01); + assertEquals(100.0,v1.getStartLocation().getCoordinate().getX(),0.01); assertEquals(0.0,v1.getEarliestDeparture(),0.01); - assertEquals("depotLoc2",v1.getStartLocationId()); + assertEquals("depotLoc2",v1.getStartLocation().getId()); assertNotNull(v1.getType()); assertEquals("vehType", v1.getType().getTypeId()); assertNotNull(v1.getStartLocation()); @@ -321,7 +321,7 @@ public class VrpXMLReaderTest { new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Vehicle v3 = getVehicle("v3",vrp.getVehicles()); - assertEquals("startLoc",v3.getStartLocationId()); + assertEquals("startLoc",v3.getStartLocation().getId()); assertNotNull(v3.getEndLocation()); assertEquals(4,v3.getEndLocation().getIndex()); } @@ -332,7 +332,7 @@ public class VrpXMLReaderTest { new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Vehicle v3 = getVehicle("v3",vrp.getVehicles()); - assertEquals("endLoc",v3.getEndLocationId()); + assertEquals("endLoc",v3.getEndLocation().getId()); } @Test @@ -341,8 +341,8 @@ public class VrpXMLReaderTest { new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Vehicle v3 = getVehicle("v3",vrp.getVehicles()); - assertEquals(1000.0,v3.getEndLocationCoordinate().getX(),0.01); - assertEquals(2000.0,v3.getEndLocationCoordinate().getY(),0.01); + assertEquals(1000.0,v3.getEndLocation().getCoordinate().getX(),0.01); + assertEquals(2000.0,v3.getEndLocation().getCoordinate().getY(),0.01); } @Test @@ -351,8 +351,8 @@ public class VrpXMLReaderTest { new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Vehicle v3 = getVehicle("v3",vrp.getVehicles()); - assertEquals(10.0,v3.getStartLocationCoordinate().getX(),0.01); - assertEquals(100.0,v3.getStartLocationCoordinate().getY(),0.01); + assertEquals(10.0,v3.getStartLocation().getCoordinate().getX(),0.01); + assertEquals(100.0,v3.getStartLocation().getCoordinate().getY(),0.01); } @Test @@ -361,8 +361,8 @@ public class VrpXMLReaderTest { new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Vehicle v3 = getVehicle("v3",vrp.getVehicles()); - assertEquals(10.0,v3.getStartLocationCoordinate().getX(),0.01); - assertEquals(100.0,v3.getStartLocationCoordinate().getY(),0.01); + assertEquals(10.0,v3.getStartLocation().getCoordinate().getX(),0.01); + assertEquals(100.0,v3.getStartLocation().getCoordinate().getY(),0.01); } @Test @@ -371,7 +371,7 @@ public class VrpXMLReaderTest { new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Vehicle v3 = getVehicle("v3",vrp.getVehicles()); - assertEquals("startLoc",v3.getStartLocationId()); + assertEquals("startLoc",v3.getStartLocation().getId()); } @Test @@ -380,7 +380,7 @@ public class VrpXMLReaderTest { new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Vehicle v = getVehicle("v4",vrp.getVehicles()); - assertEquals("startLoc",v.getStartLocationId()); + assertEquals("startLoc",v.getStartLocation().getId()); } @Test @@ -389,7 +389,7 @@ public class VrpXMLReaderTest { new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Vehicle v = getVehicle("v4",vrp.getVehicles()); - assertEquals("endLoc",v.getEndLocationId()); + assertEquals("endLoc",v.getEndLocation().getId()); } @Test @@ -398,8 +398,8 @@ public class VrpXMLReaderTest { new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Vehicle v = getVehicle("v4",vrp.getVehicles()); - assertEquals(1000.0,v.getEndLocationCoordinate().getX(),0.01); - assertEquals(2000.0,v.getEndLocationCoordinate().getY(),0.01); + assertEquals(1000.0,v.getEndLocation().getCoordinate().getX(),0.01); + assertEquals(2000.0,v.getEndLocation().getCoordinate().getY(),0.01); } @Test @@ -408,8 +408,8 @@ public class VrpXMLReaderTest { new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Vehicle v = getVehicle("v4",vrp.getVehicles()); - assertEquals(10.0,v.getStartLocationCoordinate().getX(),0.01); - assertEquals(100.0,v.getStartLocationCoordinate().getY(),0.01); + assertEquals(10.0,v.getStartLocation().getCoordinate().getX(),0.01); + assertEquals(100.0,v.getStartLocation().getCoordinate().getY(),0.01); } @Test @@ -418,8 +418,8 @@ public class VrpXMLReaderTest { new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Vehicle v = getVehicle("v4",vrp.getVehicles()); - assertEquals(10.0,v.getStartLocationCoordinate().getX(),0.01); - assertEquals(100.0,v.getStartLocationCoordinate().getY(),0.01); + assertEquals(10.0,v.getStartLocation().getCoordinate().getX(),0.01); + assertEquals(100.0,v.getStartLocation().getCoordinate().getY(),0.01); } @Test @@ -428,7 +428,7 @@ public class VrpXMLReaderTest { new VrpXMLReader(builder, null).read(inFileName); VehicleRoutingProblem vrp = builder.build(); Vehicle v = getVehicle("v4",vrp.getVehicles()); - assertEquals("startLoc",v.getStartLocationId()); + assertEquals("startLoc",v.getStartLocation().getId()); } @Test diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultShipmentActivityFactoryTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultShipmentActivityFactoryTest.java index 630a370f..7b2232c1 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultShipmentActivityFactoryTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DefaultShipmentActivityFactoryTest.java @@ -29,7 +29,7 @@ public class DefaultShipmentActivityFactoryTest { public void whenCreatingPickupActivityWithShipment_itShouldReturnPickupShipment(){ DefaultShipmentActivityFactory factory = new DefaultShipmentActivityFactory(); Shipment shipment = Shipment.Builder.newInstance("s") - .setPickupLocation(Location.Builder.newInstance().setId("pLoc").build()).setDeliveryLocationId("dLoc").build(); + .setPickupLocation(Location.Builder.newInstance().setId("pLoc").build()).setDeliveryLocation(Location.newInstance("dLoc")).build(); TourActivity act = factory.createPickup(shipment); assertNotNull(act); assertTrue(act instanceof PickupShipment); @@ -39,7 +39,7 @@ public class DefaultShipmentActivityFactoryTest { public void whenCreatingDeliverActivityWithShipment_itShouldReturnDeliverShipment(){ DefaultShipmentActivityFactory factory = new DefaultShipmentActivityFactory(); Shipment shipment = Shipment.Builder.newInstance("s") - .setPickupLocation(Location.Builder.newInstance().setId("pLoc").build()).setDeliveryLocationId("dLoc").build(); + .setPickupLocation(Location.Builder.newInstance().setId("pLoc").build()).setDeliveryLocation(Location.newInstance("dLoc")).build(); TourActivity act = factory.createDelivery(shipment); assertNotNull(act); assertTrue(act instanceof DeliverShipment); diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverShipmentTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverShipmentTest.java index c5ab5d79..d5d39dd3 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverShipmentTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/DeliverShipmentTest.java @@ -26,14 +26,12 @@ import static org.junit.Assert.assertTrue; public class DeliverShipmentTest { - private Shipment shipment; - private DeliverShipment deliver; @Before public void doBefore(){ - shipment = Shipment.Builder.newInstance("shipment").setPickupLocation(Location.Builder.newInstance().setId("pickupLoc").build()) - .setDeliveryLocationId("deliveryLoc") + Shipment shipment = Shipment.Builder.newInstance("shipment").setPickupLocation(Location.Builder.newInstance().setId("pickupLoc").build()) + .setDeliveryLocation(Location.newInstance("deliveryLoc")) .setPickupTimeWindow(TimeWindow.newInstance(1., 2.)) .setDeliveryTimeWindow(TimeWindow.newInstance(3., 4.)) .addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build(); @@ -89,7 +87,7 @@ public class DeliverShipmentTest { @Test public void whenGettingCapacity_itShouldReturnItCorrectly(){ - Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocationId("delLoc") + Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")) .addSizeDimension(0, 10).addSizeDimension(1, 100).build(); PickupShipment pick = new PickupShipment(shipment); assertEquals(10,pick.getSize().get(0)); diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupShipmentTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupShipmentTest.java index 46d12a6e..e1293350 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupShipmentTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/activity/PickupShipmentTest.java @@ -25,15 +25,13 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; public class PickupShipmentTest { - - private Shipment shipment; - + private PickupShipment pickup; @Before public void doBefore(){ - shipment = Shipment.Builder.newInstance("shipment").setPickupLocation(Location.Builder.newInstance().setId("pickupLoc").build()) - .setDeliveryLocationId("deliveryLoc") + Shipment shipment = Shipment.Builder.newInstance("shipment").setPickupLocation(Location.Builder.newInstance().setId("pickupLoc").build()) + .setDeliveryLocation(Location.newInstance("deliveryLoc")) .setPickupTimeWindow(TimeWindow.newInstance(1., 2.)) .setDeliveryTimeWindow(TimeWindow.newInstance(3., 4.)) .addSizeDimension(0, 10).addSizeDimension(1, 100).addSizeDimension(2, 1000).build(); @@ -89,7 +87,7 @@ public class PickupShipmentTest { @Test public void whenGettingCapacity_itShouldReturnItCorrectly(){ - Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocationId("delLoc") + Shipment shipment = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).setDeliveryLocation(Location.newInstance("delLoc")) .addSizeDimension(0, 10).addSizeDimension(1, 100).build(); PickupShipment pick = new PickupShipment(shipment); assertEquals(10,pick.getSize().get(0)); 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 d0d43cf4..20a2c349 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 @@ -19,8 +19,7 @@ package jsprit.core.problem.vehicle; -import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle; -import jsprit.core.util.Coordinate; +import jsprit.core.problem.Location; import org.junit.Test; import static org.junit.Assert.*; @@ -38,159 +37,158 @@ public class VehicleImplTest { @Test public void whenVehicleIsBuiltToReturnToDepot_itShouldReturnToDepot(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setReturnToDepot(true).setStartLocationId("loc").build(); + Vehicle v = VehicleImpl.Builder.newInstance("v").setReturnToDepot(true).setStartLocation(Location.newInstance("loc")).build(); assertTrue(v.isReturnToDepot()); } @Test public void whenVehicleIsBuiltToNotReturnToDepot_itShouldNotReturnToDepot(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setReturnToDepot(false).setStartLocationId("loc").build(); + Vehicle v = VehicleImpl.Builder.newInstance("v").setReturnToDepot(false).setStartLocation(Location.newInstance("loc")).build(); assertFalse(v.isReturnToDepot()); } @Test public void whenVehicleIsBuiltWithLocation_itShouldHvTheCorrectLocation(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").build(); - assertEquals("loc",v.getStartLocationId()); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build(); + assertEquals("loc",v.getStartLocation().getId()); } @Test public void whenVehicleIsBuiltWithCoord_itShouldHvTheCorrectCoord(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1, 2)).build(); - assertEquals(1.0,v.getStartLocationCoordinate().getX(),0.01); - assertEquals(2.0,v.getStartLocationCoordinate().getY(),0.01); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1, 2)).build(); + assertEquals(1.0,v.getStartLocation().getCoordinate().getX(),0.01); + assertEquals(2.0,v.getStartLocation().getCoordinate().getY(),0.01); } @Test public void whenVehicleIsBuiltAndEarliestStartIsNotSet_itShouldSetTheDefaultOfZero(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1, 2)).build(); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1, 2)).build(); assertEquals(0.0,v.getEarliestDeparture(),0.01); } @Test public void whenVehicleIsBuiltAndEarliestStartSet_itShouldBeSetCorrectly(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setEarliestStart(10.0).setStartLocationCoordinate(Coordinate.newInstance(1, 2)).build(); + Vehicle v = VehicleImpl.Builder.newInstance("v").setEarliestStart(10.0).setStartLocation(Location.newInstance(1, 2)).build(); assertEquals(10.0,v.getEarliestDeparture(),0.01); } @Test public void whenVehicleIsBuiltAndLatestArrivalIsNotSet_itShouldSetDefaultOfDoubleMaxValue(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1, 2)).build(); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1, 2)).build(); assertEquals(Double.MAX_VALUE,v.getLatestArrival(),0.01); } @Test public void whenVehicleIsBuiltAndLatestArrivalIsSet_itShouldBeSetCorrectly(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setLatestArrival(30.0).setStartLocationCoordinate(Coordinate.newInstance(1, 2)).build(); + Vehicle v = VehicleImpl.Builder.newInstance("v").setLatestArrival(30.0).setStartLocation(Location.newInstance(1, 2)).build(); assertEquals(30.0,v.getLatestArrival(),0.01); } @Test public void whenNoVehicleIsCreate_itShouldHvTheCorrectId(){ Vehicle v = VehicleImpl.createNoVehicle(); - assertTrue(v instanceof NoVehicle); assertEquals("noVehicle",v.getId()); } @Test public void whenStartLocationIsSet_itIsDoneCorrectly(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").build(); - assertEquals("startLoc", v.getStartLocationId()); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).build(); + assertEquals("startLoc", v.getStartLocation().getId()); } - @Test(expected=IllegalArgumentException.class) + @Test(expected=IllegalStateException.class) public void whenStartLocationIsNull_itThrowsException(){ @SuppressWarnings("unused") - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId(null).build(); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(null)).build(); } @Test public void whenStartLocationCoordIsSet_itIsDoneCorrectly(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1, 2)).build(); - assertEquals(1.0, v.getStartLocationCoordinate().getX(),0.01); - assertEquals(2.0, v.getStartLocationCoordinate().getY(),0.01); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1, 2)).build(); + assertEquals(1.0, v.getStartLocation().getCoordinate().getX(),0.01); + assertEquals(2.0, v.getStartLocation().getCoordinate().getY(),0.01); } @Test public void whenEndLocationIsSet_itIsDoneCorrectly(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").setEndLocationId("endLoc").build(); - assertEquals("startLoc", v.getStartLocationId()); - assertEquals("endLoc", v.getEndLocationId()); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).setEndLocation(Location.newInstance("endLoc")).build(); + assertEquals("startLoc", v.getStartLocation().getId()); + assertEquals("endLoc", v.getEndLocation().getId()); } @Test public void whenEndLocationCoordIsSet_itIsDoneCorrectly(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").setEndLocationCoordinate(Coordinate.newInstance(1, 2)).build(); - assertEquals(1.0, v.getEndLocationCoordinate().getX(),0.01); - assertEquals(2.0, v.getEndLocationCoordinate().getY(),0.01); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).setEndLocation(Location.newInstance(1, 2)).build(); + assertEquals(1.0, v.getEndLocation().getCoordinate().getX(),0.01); + assertEquals(2.0, v.getEndLocation().getCoordinate().getY(),0.01); } @Test public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationIdMustBeEqualToStartLocationId(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").build(); - assertEquals("startLoc", v.getEndLocationId()); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).build(); + assertEquals("startLoc", v.getEndLocation().getId()); } @Test public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationCoordMustBeEqualToStartLocationCoord(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").build(); - assertEquals(v.getEndLocationCoordinate(), v.getStartLocationCoordinate()); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("startLoc")).build(); + assertEquals(v.getEndLocation().getCoordinate(), v.getStartLocation().getCoordinate()); } @Test public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationCoordMustBeEqualToStartLocationCoordV2(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1.0, 2.0)).build(); - assertEquals(v.getEndLocationCoordinate(), v.getStartLocationCoordinate()); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).build(); + assertEquals(v.getEndLocation().getCoordinate(), v.getStartLocation().getCoordinate()); } @Test public void whenEndLocationCoordinateIsSetButNoId_idMustBeCoordToString(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1.0, 2.0)).setEndLocationCoordinate(Coordinate.newInstance(3.0, 4.0)).build(); - assertEquals(v.getEndLocationCoordinate().toString(), v.getEndLocationId()); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance(3.0, 4.0)).build(); + assertEquals(v.getEndLocation().getCoordinate().toString(), v.getEndLocation().getId()); } @Test(expected=IllegalStateException.class) public void whenEndLocationIdIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException(){ @SuppressWarnings("unused") - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1.0, 2.0)).setEndLocationId("endLoc").setReturnToDepot(false).build(); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance("endLoc")).setReturnToDepot(false).build(); } @Test(expected=IllegalStateException.class) public void whenEndLocationCoordIsSpecifiedANDReturnToDepotIsFalse_itShouldThrowException(){ @SuppressWarnings("unused") - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1.0, 2.0)).setEndLocationCoordinate(Coordinate.newInstance(3, 4)).setReturnToDepot(false).build(); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setEndLocation(Location.newInstance(3, 4)).setReturnToDepot(false).build(); } @Test public void whenEndLocationCoordIsNotSpecifiedANDReturnToDepotIsFalse_endLocationCoordMustBeStartLocationCoord(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1.0, 2.0)).setReturnToDepot(false).build(); - assertEquals(v.getStartLocationCoordinate(),v.getEndLocationCoordinate()); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setReturnToDepot(false).build(); + assertEquals(v.getStartLocation().getCoordinate(),v.getEndLocation().getCoordinate()); } @Test public void whenEndLocationIdIsNotSpecifiedANDReturnToDepotIsFalse_endLocationIdMustBeStartLocationId(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(Coordinate.newInstance(1.0, 2.0)).setReturnToDepot(false).build(); - assertEquals(v.getStartLocationCoordinate().toString(),v.getEndLocationId()); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(1.0, 2.0)).setReturnToDepot(false).build(); + assertEquals(v.getStartLocation().getCoordinate().toString(),v.getEndLocation().getId()); } @Test(expected=IllegalStateException.class) public void whenStartAndEndAreUnequalANDReturnToDepotIsFalse_itShouldThrowException(){ @SuppressWarnings("unused") - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("end").setReturnToDepot(false).build(); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("end")).setReturnToDepot(false).build(); } @Test public void whenStartAndEndAreEqualANDReturnToDepotIsFalse_itShouldThrowException(){ @SuppressWarnings("unused") - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("start").setReturnToDepot(false).build(); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("start")).setReturnToDepot(false).build(); assertTrue(true); } @Test public void whenTwoVehiclesHaveTheSameId_theyShouldBeEqual(){ - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("start").setReturnToDepot(false).build(); - Vehicle v2 = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("start").setReturnToDepot(false).build(); + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("start")).setReturnToDepot(false).build(); + Vehicle v2 = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setEndLocation(Location.newInstance("start")).setReturnToDepot(false).build(); assertTrue(v.equals(v2)); } @@ -198,7 +196,7 @@ public class VehicleImplTest { @Test public void whenAddingSkills_theyShouldBeAddedCorrectly(){ VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build(); - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setType(type1).setEndLocationId("start") + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start")) .addSkill("drill").addSkill("screwdriver").build(); assertTrue(v.getSkills().containsSkill("drill")); assertTrue(v.getSkills().containsSkill("drill")); @@ -208,7 +206,7 @@ public class VehicleImplTest { @Test public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){ VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build(); - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setType(type1).setEndLocationId("start") + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start")) .addSkill("drill").addSkill("screwdriver").build(); assertTrue(v.getSkills().containsSkill("drill")); assertTrue(v.getSkills().containsSkill("dRill")); @@ -218,7 +216,7 @@ public class VehicleImplTest { @Test public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly(){ VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build(); - Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setType(type1).setEndLocationId("start") + Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start")) .addSkill("drill").build(); assertFalse(v.getSkills().containsSkill("ScrewDriver")); } diff --git a/jsprit-instances/src/test/java/jsprit/instance/reader/ChristophidesReaderTest.java b/jsprit-instances/src/test/java/jsprit/instance/reader/ChristophidesReaderTest.java index 4cf20d55..c975b7a2 100644 --- a/jsprit-instances/src/test/java/jsprit/instance/reader/ChristophidesReaderTest.java +++ b/jsprit-instances/src/test/java/jsprit/instance/reader/ChristophidesReaderTest.java @@ -16,30 +16,37 @@ ******************************************************************************/ package jsprit.instance.reader; -import static org.junit.Assert.assertEquals; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem.FleetSize; import jsprit.core.problem.job.Service; import jsprit.core.problem.vehicle.Vehicle; -import jsprit.instance.reader.ChristofidesReader; - import org.junit.Test; +import java.net.URL; + +import static org.junit.Assert.assertEquals; + public class ChristophidesReaderTest { @Test public void whenReadingInstance_nuOfCustomersIsCorrect(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new ChristofidesReader(builder).read(this.getClass().getClassLoader().getResource("vrpnc1.txt").getPath()); + new ChristofidesReader(builder).read(getPath("vrpnc1.txt")); VehicleRoutingProblem vrp = builder.build(); assertEquals(50,vrp.getJobs().values().size()); } + + private String getPath(String string) { + URL resource = this.getClass().getClassLoader().getResource(string); + if(resource == null) throw new IllegalStateException("resource " + string + " does not exist"); + return resource.getPath(); + } @Test public void whenReadingInstance_fleetSizeIsInfinite(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new ChristofidesReader(builder).read(this.getClass().getClassLoader().getResource("vrpnc1.txt").getPath()); + new ChristofidesReader(builder).read(getPath("vrpnc1.txt")); VehicleRoutingProblem vrp = builder.build(); assertEquals(FleetSize.INFINITE,vrp.getFleetSize()); } @@ -47,7 +54,7 @@ public class ChristophidesReaderTest { @Test public void whenReadingInstance_vehicleCapacitiesAreCorrect(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new ChristofidesReader(builder).read(this.getClass().getClassLoader().getResource("vrpnc1.txt").getPath()); + new ChristofidesReader(builder).read(getPath("vrpnc1.txt")); VehicleRoutingProblem vrp = builder.build(); for(Vehicle v : vrp.getVehicles()){ assertEquals(160,v.getType().getCapacityDimensions().get(0)); @@ -57,18 +64,18 @@ public class ChristophidesReaderTest { @Test public void whenReadingInstance_vehicleLocationsAreCorrect_and_correspondToDepotLocation(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new ChristofidesReader(builder).read(this.getClass().getClassLoader().getResource("vrpnc1.txt").getPath()); + new ChristofidesReader(builder).read(getPath("vrpnc1.txt")); VehicleRoutingProblem vrp = builder.build(); for(Vehicle v : vrp.getVehicles()){ - assertEquals(30.0,v.getStartLocationCoordinate().getX(),0.01); - assertEquals(40.0,v.getStartLocationCoordinate().getY(),0.01); + assertEquals(30.0,v.getStartLocation().getCoordinate().getX(),0.01); + assertEquals(40.0,v.getStartLocation().getCoordinate().getY(),0.01); } } @Test public void whenReadingInstance_vehicleDurationsAreCorrect(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new ChristofidesReader(builder).read(this.getClass().getClassLoader().getResource("vrpnc13.txt").getPath()); + new ChristofidesReader(builder).read(getPath("vrpnc13.txt")); VehicleRoutingProblem vrp = builder.build(); for(Vehicle v : vrp.getVehicles()){ assertEquals(0.0,v.getEarliestDeparture(),0.01); @@ -79,7 +86,7 @@ public class ChristophidesReaderTest { @Test public void whenReadingInstance_demandOfCustomerOneIsCorrect(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new ChristofidesReader(builder).read(this.getClass().getClassLoader().getResource("vrpnc1.txt").getPath()); + new ChristofidesReader(builder).read(getPath("vrpnc1.txt")); VehicleRoutingProblem vrp = builder.build(); assertEquals(7,vrp.getJobs().get("1").getSize().get(0)); } @@ -87,7 +94,7 @@ public class ChristophidesReaderTest { @Test public void whenReadingInstance_serviceDurationOfCustomerTwoIsCorrect(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new ChristofidesReader(builder).read(this.getClass().getClassLoader().getResource("vrpnc13.txt").getPath()); + new ChristofidesReader(builder).read(getPath("vrpnc13.txt")); VehicleRoutingProblem vrp = builder.build(); assertEquals(50.0,((Service)vrp.getJobs().get("2")).getServiceDuration(),0.1); } diff --git a/jsprit-instances/src/test/java/jsprit/instance/reader/CordeauReaderTest.java b/jsprit-instances/src/test/java/jsprit/instance/reader/CordeauReaderTest.java index 1498554d..7a9f351d 100644 --- a/jsprit-instances/src/test/java/jsprit/instance/reader/CordeauReaderTest.java +++ b/jsprit-instances/src/test/java/jsprit/instance/reader/CordeauReaderTest.java @@ -22,6 +22,8 @@ import jsprit.core.problem.job.Service; import jsprit.core.problem.vehicle.Vehicle; import org.junit.Test; +import java.net.URL; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -31,15 +33,21 @@ public class CordeauReaderTest { @Test public void testCordeauReader(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(this.getClass().getClassLoader().getResource("p01").getPath()); + new CordeauReader(vrpBuilder).read(getPath("p01")); vrpBuilder.build(); } + + private String getPath(String string) { + URL resource = this.getClass().getClassLoader().getResource(string); + if(resource == null) throw new IllegalStateException("resource " + string + " does not exist"); + return resource.getPath(); + } @Test public void whenReadingInstance_fleetSizeIsFinite(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(this.getClass().getClassLoader().getResource("p01").getPath()); + new CordeauReader(vrpBuilder).read(getPath("p01")); VehicleRoutingProblem vrp = vrpBuilder.build(); assertEquals(FleetSize.FINITE, vrp.getFleetSize()); } @@ -47,7 +55,7 @@ public class CordeauReaderTest { @Test public void testNuOfVehicles(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(this.getClass().getClassLoader().getResource("p01").getPath()); + new CordeauReader(vrpBuilder).read(getPath("p01")); VehicleRoutingProblem vrp = vrpBuilder.build(); assertEquals(16,vrp.getVehicles().size()); @@ -56,7 +64,7 @@ public class CordeauReaderTest { @Test public void whenReadingCordeauInstance_vehiclesHaveTheCorrectCapacity(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(this.getClass().getClassLoader().getResource("p01").getPath()); + new CordeauReader(vrpBuilder).read(getPath("p01")); VehicleRoutingProblem vrp = vrpBuilder.build(); for(Vehicle v : vrp.getVehicles()){ assertEquals(80, v.getType().getCapacityDimensions().get(0)); @@ -66,7 +74,7 @@ public class CordeauReaderTest { @Test public void whenReadingCordeauInstance_vehiclesHaveTheCorrectDuration(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(this.getClass().getClassLoader().getResource("p08").getPath()); + new CordeauReader(vrpBuilder).read(getPath("p08")); VehicleRoutingProblem vrp = vrpBuilder.build(); for(Vehicle v : vrp.getVehicles()){ assertEquals(0.0,v.getEarliestDeparture(),0.1); @@ -77,7 +85,7 @@ public class CordeauReaderTest { @Test public void whenReadingCustomersCordeauInstance_customerOneShouldHaveCorrectCoordinates(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(this.getClass().getClassLoader().getResource("p01").getPath()); + new CordeauReader(vrpBuilder).read(getPath("p01")); VehicleRoutingProblem vrp = vrpBuilder.build(); Service service = (Service) vrp.getJobs().get("1"); assertEquals(37.0, service.getLocation().getCoordinate().getX(), 0.1); @@ -87,7 +95,7 @@ public class CordeauReaderTest { @Test public void whenReadingCustomersCordeauInstance_customerTwoShouldHaveCorrectServiceDuration(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(this.getClass().getClassLoader().getResource("p01").getPath()); + new CordeauReader(vrpBuilder).read(getPath("p01")); VehicleRoutingProblem vrp = vrpBuilder.build(); Service service = (Service) vrp.getJobs().get("2"); assertEquals(0.0, service.getServiceDuration(), 0.1); @@ -96,7 +104,7 @@ public class CordeauReaderTest { @Test public void whenReadingCustomersCordeauInstance_customerThreeShouldHaveCorrectDemand(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(this.getClass().getClassLoader().getResource("p01").getPath()); + new CordeauReader(vrpBuilder).read(getPath("p01")); VehicleRoutingProblem vrp = vrpBuilder.build(); Service service = (Service) vrp.getJobs().get("3"); assertEquals(16.0, service.getSize().get(0), 0.1); @@ -105,7 +113,7 @@ public class CordeauReaderTest { @Test public void whenReadingCustomersCordeauInstance_customerFortySevenShouldHaveCorrectDemand(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(this.getClass().getClassLoader().getResource("p01").getPath()); + new CordeauReader(vrpBuilder).read(getPath("p01")); VehicleRoutingProblem vrp = vrpBuilder.build(); Service service = (Service) vrp.getJobs().get("47"); assertEquals(25.0, service.getSize().get(0), 0.1); @@ -114,7 +122,7 @@ public class CordeauReaderTest { @Test public void testLocationsAndCapOfVehicles(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(this.getClass().getClassLoader().getResource("p01").getPath()); + new CordeauReader(vrpBuilder).read(getPath("p01")); VehicleRoutingProblem vrp = vrpBuilder.build(); boolean capacityOk = true; boolean loc1ok = false; @@ -123,10 +131,10 @@ public class CordeauReaderTest { boolean loc4ok = false; for(Vehicle v : vrp.getVehicles()){ if(v.getType().getCapacityDimensions().get(0) != 80) capacityOk = false; - if(v.getStartLocationCoordinate().getX() == 20.0 && v.getStartLocationCoordinate().getY() == 20.0) loc1ok = true; - if(v.getStartLocationCoordinate().getX() == 30.0 && v.getStartLocationCoordinate().getY() == 40.0) loc2ok = true; - if(v.getStartLocationCoordinate().getX() == 50.0 && v.getStartLocationCoordinate().getY() == 30.0) loc3ok = true; - if(v.getStartLocationCoordinate().getX() == 60.0 && v.getStartLocationCoordinate().getY() == 50.0) loc4ok = true; + if(v.getStartLocation().getCoordinate().getX() == 20.0 && v.getStartLocation().getCoordinate().getY() == 20.0) loc1ok = true; + if(v.getStartLocation().getCoordinate().getX() == 30.0 && v.getStartLocation().getCoordinate().getY() == 40.0) loc2ok = true; + if(v.getStartLocation().getCoordinate().getX() == 50.0 && v.getStartLocation().getCoordinate().getY() == 30.0) loc3ok = true; + if(v.getStartLocation().getCoordinate().getX() == 60.0 && v.getStartLocation().getCoordinate().getY() == 50.0) loc4ok = true; } assertTrue(capacityOk); assertTrue(loc1ok); @@ -138,7 +146,7 @@ public class CordeauReaderTest { @Test public void testNuOfCustomers(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - new CordeauReader(vrpBuilder).read(this.getClass().getClassLoader().getResource("p01").getPath()); + new CordeauReader(vrpBuilder).read(getPath("p01")); VehicleRoutingProblem vrp = vrpBuilder.build(); assertEquals(50,vrp.getJobs().values().size()); } diff --git a/jsprit-instances/src/test/java/jsprit/instance/reader/GoldenReaderTest.java b/jsprit-instances/src/test/java/jsprit/instance/reader/GoldenReaderTest.java index 2bfec0f7..0605158a 100644 --- a/jsprit-instances/src/test/java/jsprit/instance/reader/GoldenReaderTest.java +++ b/jsprit-instances/src/test/java/jsprit/instance/reader/GoldenReaderTest.java @@ -25,6 +25,8 @@ import jsprit.core.util.Coordinate; import jsprit.instance.reader.VrphGoldenReader.VrphType; import org.junit.Test; +import java.net.URL; + import static org.junit.Assert.*; public class GoldenReaderTest { @@ -33,21 +35,22 @@ public class GoldenReaderTest { public void whenReadingInstance_itShouldReadCorrectNuOfVehicles(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); - int nuOfVehicles = 0; - for(Vehicle v : vrp.getVehicles()){ - nuOfVehicles++; + assertEquals(17,vrp.getVehicles().size()); + } - } - assertEquals(17,nuOfVehicles); + private String getPath(String string) { + URL resource = this.getClass().getClassLoader().getResource(string); + if(resource == null) throw new IllegalStateException("resource " + string + " does not exist"); + return resource.getPath(); } @Test public void whenReadingInstance_itShouldReadCorrectNuOfType1Vehicles(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); int nuOfType1Vehicles = 0; for(Vehicle v : vrp.getVehicles()){ @@ -62,7 +65,7 @@ public class GoldenReaderTest { public void whenReadingInstance_theSumOfType1VehicleShouldHvTheCorrectCapacity(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); int sumOfType1Cap = 0; for(Vehicle v : vrp.getVehicles()){ @@ -77,7 +80,7 @@ public class GoldenReaderTest { public void whenReadingInstance_itShouldReadCorrectNuOfType2Vehicles(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); int nuOfType1Vehicles = 0; for(Vehicle v : vrp.getVehicles()){ @@ -92,7 +95,7 @@ public class GoldenReaderTest { public void whenReadingInstance_theSumOfType2VehicleShouldHvTheCorrectCapacity(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); int sumOfType1Cap = 0; for(Vehicle v : vrp.getVehicles()){ @@ -107,7 +110,7 @@ public class GoldenReaderTest { public void whenReadingInstance_itShouldReadCorrectNuOfType3Vehicles(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); int nuOfType1Vehicles = 0; for(Vehicle v : vrp.getVehicles()){ @@ -122,7 +125,7 @@ public class GoldenReaderTest { public void whenReadingInstance_theSumOfType3VehicleShouldHvTheCorrectCapacity(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); int sumOfType1Cap = 0; for(Vehicle v : vrp.getVehicles()){ @@ -137,7 +140,7 @@ public class GoldenReaderTest { public void whenReadingInstance_itShouldReadCorrectNuOfType4Vehicles(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); int nuOfType1Vehicles = 0; for(Vehicle v : vrp.getVehicles()){ @@ -152,7 +155,7 @@ public class GoldenReaderTest { public void whenReadingInstance_theSumOfType4VehicleShouldHvTheCorrectCapacity(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); int sumOfType1Cap = 0; for(Vehicle v : vrp.getVehicles()){ @@ -167,7 +170,7 @@ public class GoldenReaderTest { public void whenReadingInstance_itShouldReadCorrectNuOfType5Vehicles(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); int nuOfType1Vehicles = 0; for(Vehicle v : vrp.getVehicles()){ @@ -182,7 +185,7 @@ public class GoldenReaderTest { public void whenReadingInstance_theSumOfType5VehicleShouldHvTheCorrectCapacity(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); int sumOfType1Cap = 0; for(Vehicle v : vrp.getVehicles()){ @@ -197,7 +200,7 @@ public class GoldenReaderTest { public void whenReadingInstance_itShouldReadCorrectNuOfType6Vehicles(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); int nuOfType1Vehicles = 0; for(Vehicle v : vrp.getVehicles()){ @@ -212,7 +215,7 @@ public class GoldenReaderTest { public void whenReadingInstance_theSumOfType6VehicleShouldHvTheCorrectCapacity(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); int sumOfType1Cap = 0; for(Vehicle v : vrp.getVehicles()){ @@ -227,13 +230,13 @@ public class GoldenReaderTest { public void whenReadingInstance_vehicleShouldHvTheCorrectCoord(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); for(Vehicle v : vrp.getVehicles()){ - if(v.getStartLocationCoordinate().getX() != 40.0){ + if(v.getStartLocation().getCoordinate().getX() != 40.0){ assertFalse(true); } - if(v.getStartLocationCoordinate().getY() != 40.0){ + if(v.getStartLocation().getCoordinate().getY() != 40.0){ assertFalse(true); } } @@ -244,7 +247,7 @@ public class GoldenReaderTest { public void whenReadingInstance_service1MustHaveCorrectDemand(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); Job job = getJob("1",vrp); assertEquals(18,job.getSize().get(0)); @@ -254,7 +257,7 @@ public class GoldenReaderTest { public void whenReadingInstance_service1MustHaveCorrectCoordinate(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); Coordinate coord = getCoord("1",vrp); assertEquals(22.0,coord.getX(),0.01); @@ -265,7 +268,7 @@ public class GoldenReaderTest { public void whenReadingInstance_service15MustHaveCorrectCoordinate(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); Coordinate coord = getCoord("15",vrp); assertEquals(62.0,coord.getX(),0.01); @@ -278,7 +281,7 @@ public class GoldenReaderTest { public void whenReadingInstance_service50MustHaveCorrectCoordinate(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); Coordinate coord = getCoord("50",vrp); assertEquals(15.0,coord.getX(),0.01); @@ -294,7 +297,7 @@ public class GoldenReaderTest { public void whenReadingInstance_service4MustHaveCorrectDemand(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); Job job = getJob("4",vrp); assertEquals(30,job.getSize().get(0)); @@ -304,7 +307,7 @@ public class GoldenReaderTest { public void whenReadingInstance_service50MustHaveCorrectDemand(){ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); new VrphGoldenReader(vrpBuilder, VrphType.HVRPD) - .read(this.getClass().getClassLoader().getResource("cn_13mix.txt").getPath()); + .read(getPath("cn_13mix.txt")); VehicleRoutingProblem vrp = vrpBuilder.build(); Job job = getJob("50",vrp); assertEquals(22,job.getSize().get(0)); diff --git a/jsprit-instances/src/test/java/jsprit/instance/reader/SolomonReaderTest.java b/jsprit-instances/src/test/java/jsprit/instance/reader/SolomonReaderTest.java index 44774f7b..7ddbb6b5 100644 --- a/jsprit-instances/src/test/java/jsprit/instance/reader/SolomonReaderTest.java +++ b/jsprit-instances/src/test/java/jsprit/instance/reader/SolomonReaderTest.java @@ -16,30 +16,37 @@ ******************************************************************************/ package jsprit.instance.reader; -import static org.junit.Assert.assertEquals; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem.FleetSize; import jsprit.core.problem.job.Service; import jsprit.core.problem.vehicle.Vehicle; -import jsprit.instance.reader.SolomonReader; - import org.junit.Test; +import java.net.URL; + +import static org.junit.Assert.assertEquals; + public class SolomonReaderTest { @Test public void whenReadingSolomonInstance_nuOfCustomersIsCorrect(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new SolomonReader(builder).read(this.getClass().getClassLoader().getResource("C101_solomon.txt").getPath()); + new SolomonReader(builder).read(getPath()); VehicleRoutingProblem vrp = builder.build(); assertEquals(100,vrp.getJobs().values().size()); } - + + private String getPath() { + URL resource = getClass().getClassLoader().getResource("C101_solomon.txt"); + if(resource == null) throw new IllegalStateException("file C101_solomon.txt does not exist"); + return resource.getPath(); + } + @Test public void whenReadingSolomonInstance_fleetSizeIsInfinite(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new SolomonReader(builder).read(this.getClass().getClassLoader().getResource("C101_solomon.txt").getPath()); + new SolomonReader(builder).read(getPath()); VehicleRoutingProblem vrp = builder.build(); assertEquals(FleetSize.INFINITE,vrp.getFleetSize()); } @@ -47,7 +54,7 @@ public class SolomonReaderTest { @Test public void whenReadingSolomonInstance_vehicleCapacitiesAreCorrect(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new SolomonReader(builder).read(this.getClass().getClassLoader().getResource("C101_solomon.txt").getPath()); + new SolomonReader(builder).read(getPath()); VehicleRoutingProblem vrp = builder.build(); for(Vehicle v : vrp.getVehicles()){ assertEquals(200,v.getType().getCapacityDimensions().get(0)); @@ -57,18 +64,18 @@ public class SolomonReaderTest { @Test public void whenReadingSolomonInstance_vehicleLocationsAreCorrect_and_correspondToDepotLocation(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new SolomonReader(builder).read(this.getClass().getClassLoader().getResource("C101_solomon.txt").getPath()); + new SolomonReader(builder).read(getPath()); VehicleRoutingProblem vrp = builder.build(); for(Vehicle v : vrp.getVehicles()){ - assertEquals(40.0,v.getStartLocationCoordinate().getX(),0.01); - assertEquals(50.0,v.getStartLocationCoordinate().getY(),0.01); + assertEquals(40.0,v.getStartLocation().getCoordinate().getX(),0.01); + assertEquals(50.0,v.getStartLocation().getCoordinate().getY(),0.01); } } @Test public void whenReadingSolomonInstance_demandOfCustomerOneIsCorrect(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new SolomonReader(builder).read(this.getClass().getClassLoader().getResource("C101_solomon.txt").getPath()); + new SolomonReader(builder).read(getPath()); VehicleRoutingProblem vrp = builder.build(); assertEquals(10,vrp.getJobs().get("1").getSize().get(0)); } @@ -76,7 +83,7 @@ public class SolomonReaderTest { @Test public void whenReadingSolomonInstance_serviceDurationOfCustomerTwoIsCorrect(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new SolomonReader(builder).read(this.getClass().getClassLoader().getResource("C101_solomon.txt").getPath()); + new SolomonReader(builder).read(getPath()); VehicleRoutingProblem vrp = builder.build(); assertEquals(90,((Service)vrp.getJobs().get("2")).getServiceDuration(),0.1); } @@ -84,7 +91,7 @@ public class SolomonReaderTest { @Test public void whenReadingSolomonInstance_earliestServiceStartTimeOfCustomerSixtyTwoIsCorrect(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new SolomonReader(builder).read(this.getClass().getClassLoader().getResource("C101_solomon.txt").getPath()); + new SolomonReader(builder).read(getPath()); VehicleRoutingProblem vrp = builder.build(); assertEquals(262.0,((Service)vrp.getJobs().get("62")).getTimeWindow().getStart(),0.1); } @@ -92,7 +99,7 @@ public class SolomonReaderTest { @Test public void whenReadingSolomonInstance_latestServiceStartTimeOfCustomerEightySevenIsCorrect(){ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new SolomonReader(builder).read(this.getClass().getClassLoader().getResource("C101_solomon.txt").getPath()); + new SolomonReader(builder).read(getPath()); VehicleRoutingProblem vrp = builder.build(); assertEquals(144.0,((Service)vrp.getJobs().get("87")).getTimeWindow().getEnd(),0.1); }