diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionCalculator.java index 6751d370..ca820174 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionCalculator.java @@ -111,9 +111,10 @@ final class ServiceInsertionCalculator implements JobInsertionCostsCalculator{ /* generate new start and end for new vehicle */ - Start start = Start.newInstance(newVehicle.getStartLocationId(), newVehicle.getEarliestDeparture(), Double.MAX_VALUE); +// Start start = Start.newInstance(newVehicle.getStartLocationId(), newVehicle.getEarliestDeparture(), Double.MAX_VALUE); + Start start = new Start(newVehicle.getStartLocation(), newVehicle.getEarliestDeparture(), Double.MAX_VALUE); start.setEndTime(newVehicleDepartureTime); - End end = End.newInstance(newVehicle.getEndLocationId(), 0.0, newVehicle.getLatestArrival()); + End end = new End(newVehicle.getEndLocation(), 0.0, newVehicle.getLatestArrival()); TourActivity prevAct = start; double prevActStartTime = newVehicleDepartureTime; diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionOnRouteLevelCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ServiceInsertionOnRouteLevelCalculator.java index 98f22902..b6943edb 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 @@ -293,7 +293,7 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC */ private void initialiseStartAndEnd(final Vehicle newVehicle, double newVehicleDepartureTime) { if(start == null){ - start = Start.newInstance(newVehicle.getStartLocationId(), newVehicle.getEarliestDeparture(), Double.MAX_VALUE); + start = new Start(newVehicle.getStartLocation(), newVehicle.getEarliestDeparture(), Double.MAX_VALUE); start.setEndTime(newVehicleDepartureTime); } else{ @@ -304,7 +304,7 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC } if(end == null){ - end = End.newInstance(newVehicle.getEndLocationId(), 0.0, newVehicle.getLatestArrival()); + end = new End(newVehicle.getEndLocation(), 0.0, newVehicle.getLatestArrival()); } else{ end.setLocationId(newVehicle.getEndLocationId()); diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java index b97f1cb8..0d8f412a 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/recreate/ShipmentInsertionCalculator.java @@ -111,10 +111,10 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{ int pickupInsertionIndex = InsertionData.NO_INDEX; int deliveryInsertionIndex = InsertionData.NO_INDEX; - Start start = Start.newInstance(newVehicle.getStartLocationId(), newVehicle.getEarliestDeparture(), newVehicle.getLatestArrival()); + Start start = new Start(newVehicle.getStartLocation(), newVehicle.getEarliestDeparture(), newVehicle.getLatestArrival()); start.setEndTime(newVehicleDepartureTime); - End end = End.newInstance(newVehicle.getEndLocationId(), 0.0, newVehicle.getLatestArrival()); + End end = new End(newVehicle.getEndLocation(), 0.0, newVehicle.getLatestArrival()); ActivityContext pickupContext = new ActivityContext(); diff --git a/jsprit-core/src/main/java/jsprit/core/problem/Location.java b/jsprit-core/src/main/java/jsprit/core/problem/Location.java index b6e91b9b..b3f858a0 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/Location.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/Location.java @@ -28,7 +28,7 @@ public final class Location implements HasIndex, HasId{ private String id; - private int index = -1; + private int index = Location.NO_INDEX; private Coordinate coordinate; @@ -65,6 +65,8 @@ public final class Location implements HasIndex, HasId{ } + public final static int NO_INDEX = -1; + private final int index; private final Coordinate coordinate; @@ -90,4 +92,26 @@ public final class Location implements HasIndex, HasId{ public Coordinate getCoordinate(){ return coordinate; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Location)) return false; + + Location location = (Location) o; + + if (index != location.index) return false; + if (coordinate != null ? !coordinate.equals(location.coordinate) : location.coordinate != null) return false; + if (id != null ? !id.equals(location.id) : location.id != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = index; + result = 31 * result + (coordinate != null ? coordinate.hashCode() : 0); + result = 31 * result + (id != null ? id.hashCode() : 0); + return result; + } } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java index 337dc6be..76396e10 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java @@ -16,6 +16,7 @@ ******************************************************************************/ package jsprit.core.problem.io; +import jsprit.core.problem.Location; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem.FleetSize; import jsprit.core.problem.driver.Driver; @@ -366,25 +367,27 @@ public class VrpXMLReader{ String name = shipmentConfig.getString("name"); if(name != null) builder.setName(name); + //pickup location //pickup-locationId + Location.Builder pickupLocationBuilder = Location.Builder.newInstance(); String pickupLocationId = shipmentConfig.getString("pickup.locationId"); - if(pickupLocationId != null){ - builder.setPickupLocationId(pickupLocationId); + if(pickupLocationId == null) pickupLocationId = shipmentConfig.getString("pickup.location.id"); + if(pickupLocationId != null){ + pickupLocationBuilder.setId(pickupLocationId); } //pickup-coord Coordinate pickupCoord = getCoord(shipmentConfig,"pickup."); - if(pickupCoord != null){ - builder.setPickupCoord(pickupCoord); - if(pickupLocationId != null){ -// vrpBuilder.addLocation(pickupLocationId,pickupCoord); - } - else{ -// vrpBuilder.addLocation(pickupCoord.toString(),pickupCoord); - builder.setPickupLocationId(pickupCoord.toString()); - } + if(pickupCoord == null) pickupCoord = getCoord(shipmentConfig,"pickup.location."); + if(pickupCoord != null){ + pickupLocationBuilder.setCoordinate(pickupCoord); } + //pickup.location.index + String pickupLocationIndex = shipmentConfig.getString("pickup.location.index"); + if(pickupLocationIndex != null) pickupLocationBuilder.setIndex(Integer.parseInt(pickupLocationIndex)); + builder.setPickupLocation(pickupLocationBuilder.build()); + //pickup-serviceTime String pickupServiceTime = shipmentConfig.getString("pickup.duration"); if(pickupServiceTime != null) builder.setPickupServiceTime(Double.parseDouble(pickupServiceTime)); @@ -397,25 +400,27 @@ public class VrpXMLReader{ builder.setPickupTimeWindow(pickupTW); } + //delivery location //delivery-locationId + Location.Builder deliveryLocationBuilder = Location.Builder.newInstance(); String deliveryLocationId = shipmentConfig.getString("delivery.locationId"); - if(deliveryLocationId != null){ - builder.setDeliveryLocationId(deliveryLocationId); + if(deliveryLocationId == null) deliveryLocationId = shipmentConfig.getString("delivery.location.id"); + if(deliveryLocationId != null){ + deliveryLocationBuilder.setId(deliveryLocationId); +// builder.setDeliveryLocationId(deliveryLocationId); } //delivery-coord Coordinate deliveryCoord = getCoord(shipmentConfig,"delivery."); - if(deliveryCoord != null){ - builder.setDeliveryCoord(deliveryCoord); - if(deliveryLocationId != null){ -// vrpBuilder.addLocation(deliveryLocationId,deliveryCoord); - } - else{ -// vrpBuilder.addLocation(deliveryCoord.toString(),deliveryCoord); - builder.setDeliveryLocationId(deliveryCoord.toString()); - } + if(deliveryCoord == null) deliveryCoord = getCoord(shipmentConfig,"delivery.location."); + if(deliveryCoord != null){ + deliveryLocationBuilder.setCoordinate(deliveryCoord); } + String deliveryLocationIndex = shipmentConfig.getString("delivery.location.index"); + if(deliveryLocationIndex != null) deliveryLocationBuilder.setIndex(Integer.parseInt(deliveryLocationIndex)); + builder.setDeliveryLocation(deliveryLocationBuilder.build()); + //delivery-serviceTime String deliveryServiceTime = shipmentConfig.getString("delivery.duration"); if(deliveryServiceTime != null) builder.setDeliveryServiceTime(Double.parseDouble(deliveryServiceTime)); @@ -488,19 +493,24 @@ public class VrpXMLReader{ String name = serviceConfig.getString("name"); if(name != null) builder.setName(name); + //location + Location.Builder locationBuilder = Location.Builder.newInstance(); String serviceLocationId = serviceConfig.getString("locationId"); - if(serviceLocationId != null) builder.setLocationId(serviceLocationId); + if(serviceLocationId == null) { + serviceLocationId = serviceConfig.getString("location.id"); + } + if(serviceLocationId != null) locationBuilder.setId(serviceLocationId); + Coordinate serviceCoord = getCoord(serviceConfig,""); - if(serviceCoord != null){ - builder.setCoord(serviceCoord); - if(serviceLocationId != null){ -// vrpBuilder.addLocation(serviceLocationId,serviceCoord); - } - else{ -// vrpBuilder.addLocation(serviceCoord.toString(),serviceCoord); - builder.setLocationId(serviceCoord.toString()); - } + if(serviceCoord == null) serviceCoord = getCoord(serviceConfig,"location."); + if(serviceCoord != null){ + locationBuilder.setCoordinate(serviceCoord); } + + String locationIndex = serviceConfig.getString("location.index"); + if(locationIndex != null) locationBuilder.setIndex(Integer.parseInt(locationIndex)); + builder.setLocation(locationBuilder.build()); + if(serviceConfig.containsKey("duration")){ builder.setServiceTime(serviceConfig.getDouble("duration")); } @@ -602,12 +612,12 @@ public class VrpXMLReader{ builder.setType(type); //read startlocation + Location.Builder startLocationBuilder = Location.Builder.newInstance(); String locationId = vehicleConfig.getString("location.id"); if(locationId == null) { locationId = vehicleConfig.getString("startLocation.id"); } - if(locationId == null) throw new IllegalStateException("location.id is missing."); - builder.setStartLocationId(locationId); + startLocationBuilder.setId(locationId); String coordX = vehicleConfig.getString("location.coord[@x]"); String coordY = vehicleConfig.getString("location.coord[@y]"); if(coordX == null || coordY == null) { @@ -622,13 +632,23 @@ public class VrpXMLReader{ } else{ Coordinate coordinate = Coordinate.newInstance(Double.parseDouble(coordX), Double.parseDouble(coordY)); - builder.setStartLocationCoordinate(coordinate); - - } + startLocationBuilder.setCoordinate(coordinate); + } + String index = vehicleConfig.getString("startLocation.index"); + if(index == null) index = vehicleConfig.getString("location.index"); + if(index != null){ + startLocationBuilder.setIndex(Integer.parseInt(index)); + } + builder.setStartLocation(startLocationBuilder.build()); //read endlocation + Location.Builder endLocationBuilder = Location.Builder.newInstance(); + boolean hasEndLocation = false; String endLocationId = vehicleConfig.getString("endLocation.id"); - if(endLocationId != null) builder.setEndLocationId(endLocationId); + if(endLocationId != null) { + hasEndLocation = true; + endLocationBuilder.setId(endLocationId); + } String endCoordX = vehicleConfig.getString("endLocation.coord[@x]"); String endCoordY = vehicleConfig.getString("endLocation.coord[@y]"); if(endCoordX == null || endCoordY == null) { @@ -639,8 +659,15 @@ public class VrpXMLReader{ } else{ Coordinate coordinate = Coordinate.newInstance(Double.parseDouble(endCoordX), Double.parseDouble(endCoordY)); - builder.setEndLocationCoordinate(coordinate); + hasEndLocation = true; + endLocationBuilder.setCoordinate(coordinate); } + String endLocationIndex = vehicleConfig.getString("endLocation.index"); + if(endLocationIndex != null) { + hasEndLocation = true; + endLocationBuilder.setIndex(Integer.parseInt(endLocationIndex)); + } + if(hasEndLocation) builder.setEndLocation(endLocationBuilder.build()); //read timeSchedule String start = vehicleConfig.getString("timeSchedule.start"); diff --git a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java index a1186366..d9627662 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java @@ -16,6 +16,7 @@ ******************************************************************************/ package jsprit.core.problem.io; +import jsprit.core.problem.Location; import jsprit.core.problem.Skills; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.job.Job; @@ -220,11 +221,14 @@ public class VrpXMLWriter { Service service = (Service) j; xmlConfig.setProperty(shipmentPathString + "("+counter+")[@id]", service.getId()); xmlConfig.setProperty(shipmentPathString + "("+counter+")[@type]", service.getType()); - if(service.getLocationId() != null) xmlConfig.setProperty(shipmentPathString + "("+counter+").locationId", service.getLocationId()); - if(service.getCoord() != null) { - xmlConfig.setProperty(shipmentPathString + "("+counter+").coord[@x]", service.getCoord().getX()); - xmlConfig.setProperty(shipmentPathString + "("+counter+").coord[@y]", service.getCoord().getY()); + if(service.getLocation().getId() != null) xmlConfig.setProperty(shipmentPathString + "("+counter+").location.id", service.getLocation().getId()); + if(service.getLocation().getCoordinate() != null) { + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").location.coord[@x]", service.getLocation().getCoordinate().getX()); + xmlConfig.setProperty(shipmentPathString + "("+counter+").location.coord[@y]", service.getLocation().getCoordinate().getY()); } + if(service.getLocation().getIndex() != Location.NO_INDEX){ + xmlConfig.setProperty(shipmentPathString + "(" + counter + ").location.index", service.getLocation().getIndex()); + } for(int i=0;i. - * - * Contributors: - * Stefan Schroeder - initial API and implementation ******************************************************************************/ package jsprit.core.problem.solution.route.activity; import jsprit.core.problem.AbstractActivity; import jsprit.core.problem.Capacity; +import jsprit.core.problem.Location; import jsprit.core.problem.job.Delivery; public final class DeliverService extends AbstractActivity implements DeliveryActivity{ @@ -56,7 +55,12 @@ public final class DeliverService extends AbstractActivity implements DeliveryAc return delivery.getLocationId(); } - @Override + @Override + public Location getLocation() { + return delivery.getLocation(); + } + + @Override public double getTheoreticalEarliestOperationStartTime() { return delivery.getTimeWindow().getStart(); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverShipment.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverShipment.java index c0f0eefa..9e5079c8 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverShipment.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/DeliverShipment.java @@ -18,6 +18,7 @@ package jsprit.core.problem.solution.route.activity; import jsprit.core.problem.AbstractActivity; import jsprit.core.problem.Capacity; +import jsprit.core.problem.Location; import jsprit.core.problem.job.Job; import jsprit.core.problem.job.Shipment; @@ -61,7 +62,12 @@ public final class DeliverShipment extends AbstractActivity implements DeliveryA return shipment.getDeliveryLocationId(); } - @Override + @Override + public Location getLocation() { + return shipment.getDeliveryLocation(); + } + + @Override public double getTheoreticalEarliestOperationStartTime() { return shipment.getDeliveryTimeWindow().getStart(); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/End.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/End.java index 5c1d97c5..4b5dc022 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/End.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/End.java @@ -1,16 +1,16 @@ /******************************************************************************* - * Copyright (C) 2013 Stefan Schroeder - * + * Copyright (C) 2014 Stefan Schroeder + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ @@ -18,6 +18,7 @@ package jsprit.core.problem.solution.route.activity; import jsprit.core.problem.AbstractActivity; import jsprit.core.problem.Capacity; +import jsprit.core.problem.Location; import jsprit.core.util.Coordinate; public final class End extends AbstractActivity implements TourActivity { @@ -35,15 +36,15 @@ public final class End extends AbstractActivity implements TourActivity { } private final static Capacity capacity = Capacity.Builder.newInstance().build(); - - private String locationId; - + private Coordinate coordinate; - + + @Deprecated Coordinate getCoordinate() { return coordinate; } + @Deprecated void setCoordinate(Coordinate coordinate) { this.coordinate = coordinate; } @@ -57,6 +58,8 @@ public final class End extends AbstractActivity implements TourActivity { private double arrTime; + private Location location; + public void setTheoreticalEarliestOperationStartTime(double theoreticalEarliestOperationStartTime) { theoretical_earliestOperationStartTime = theoreticalEarliestOperationStartTime; } @@ -65,17 +68,27 @@ public final class End extends AbstractActivity implements TourActivity { theoretical_latestOperationStartTime = theoreticalLatestOperationStartTime; } - public End(String locationId, double theoreticalStart, double theoreticalEnd) { + public End(Location location, double theoreticalStart, double theoreticalEnd) { super(); - this.locationId = locationId; + this.location = location; theoretical_earliestOperationStartTime = theoreticalStart; theoretical_latestOperationStartTime = theoreticalEnd; endTime = theoreticalEnd; setIndex(-2); } + public End(String locationId, double theoreticalStart, double theoreticalEnd) { + super(); + if(locationId != null) this.location = Location.Builder.newInstance().setId(locationId).build(); + theoretical_earliestOperationStartTime = theoreticalStart; + theoretical_latestOperationStartTime = theoreticalEnd; + endTime = theoreticalEnd; + setIndex(-2); + } + public End(End end) { - this.locationId = end.getLocationId(); + this.location = end.getLocation(); +// this.locationId = end.getLocationId(); theoretical_earliestOperationStartTime = end.getTheoreticalEarliestOperationStartTime(); theoretical_latestOperationStartTime = end.getTheoreticalLatestOperationStartTime(); arrTime = end.getArrTime(); @@ -99,16 +112,29 @@ public final class End extends AbstractActivity implements TourActivity { this.endTime = endTime; } + @Deprecated public void setLocationId(String locationId) { - this.locationId = locationId; + if(locationId == null) return; + this.location = Location.Builder.newInstance().setId(locationId).build(); } + public void setLocation(Location location){ + this.location = location; + } + + @Deprecated @Override public String getLocationId() { - return locationId; + if(location == null) return null; + return location.getId(); } - @Override + @Override + public Location getLocation() { + return location; + } + + @Override public double getOperationTime() { return 0.0; } @@ -116,7 +142,7 @@ public final class End extends AbstractActivity implements TourActivity { @Override public String toString() { - return "[type="+getName()+"][locationId=" + getLocationId() + return "[type="+getName()+"][location=" + location + "][twStart=" + Activities.round(theoretical_earliestOperationStartTime) + "][twEnd=" + Activities.round(theoretical_latestOperationStartTime) + "]"; } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupService.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupService.java index 880e7818..3bef105c 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupService.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupService.java @@ -1,25 +1,24 @@ /******************************************************************************* - * Copyright (c) 2014 Stefan Schroeder. - * + * Copyright (C) 2014 Stefan Schroeder + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * - * Contributors: - * Stefan Schroeder - initial API and implementation ******************************************************************************/ package jsprit.core.problem.solution.route.activity; import jsprit.core.problem.AbstractActivity; import jsprit.core.problem.Capacity; +import jsprit.core.problem.Location; import jsprit.core.problem.job.Pickup; import jsprit.core.problem.job.Service; @@ -57,7 +56,12 @@ public final class PickupService extends AbstractActivity implements PickupActiv return pickup.getLocationId(); } - @Override + @Override + public Location getLocation() { + return pickup.getLocation(); + } + + @Override public double getTheoreticalEarliestOperationStartTime() { return pickup.getTimeWindow().getStart(); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupShipment.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupShipment.java index e7f33db4..ddf1401b 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupShipment.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/PickupShipment.java @@ -18,6 +18,7 @@ package jsprit.core.problem.solution.route.activity; import jsprit.core.problem.AbstractActivity; import jsprit.core.problem.Capacity; +import jsprit.core.problem.Location; import jsprit.core.problem.job.Job; import jsprit.core.problem.job.Shipment; @@ -57,7 +58,12 @@ public final class PickupShipment extends AbstractActivity implements PickupActi return shipment.getPickupLocationId(); } - @Override + @Override + public Location getLocation() { + return shipment.getPickupLocation(); + } + + @Override public double getTheoreticalEarliestOperationStartTime() { return shipment.getPickupTimeWindow().getStart(); } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ServiceActivity.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ServiceActivity.java index 3d51a638..3a5f5c5a 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ServiceActivity.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/ServiceActivity.java @@ -1,16 +1,16 @@ /******************************************************************************* - * Copyright (C) 2013 Stefan Schroeder - * + * Copyright (C) 2014 Stefan Schroeder + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ @@ -18,6 +18,7 @@ package jsprit.core.problem.solution.route.activity; import jsprit.core.problem.AbstractActivity; import jsprit.core.problem.Capacity; +import jsprit.core.problem.Location; import jsprit.core.problem.job.Service; import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity; @@ -131,8 +132,13 @@ public class ServiceActivity extends AbstractActivity implements JobActivity{ return service.getLocationId(); } - - @Override + @Override + public Location getLocation() { + return service.getLocation(); + } + + + @Override public Service getJob() { return service; } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/Start.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/Start.java index 32a4d569..ef10f2cb 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/Start.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/Start.java @@ -1,16 +1,16 @@ /******************************************************************************* - * Copyright (C) 2013 Stefan Schroeder - * + * Copyright (C) 2014 Stefan Schroeder + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ @@ -18,6 +18,7 @@ package jsprit.core.problem.solution.route.activity; import jsprit.core.problem.AbstractActivity; import jsprit.core.problem.Capacity; +import jsprit.core.problem.Location; public final class Start extends AbstractActivity implements TourActivity { @@ -45,19 +46,31 @@ public final class Start extends AbstractActivity implements TourActivity { private double endTime; - private double arrTime; + private double arrTime; + private Location location; + + @Deprecated public Start(String locationId, double theoreticalStart, double theoreticalEnd) { super(); - this.locationId = locationId; + if(locationId != null) this.location = Location.Builder.newInstance().setId(locationId).build(); this.theoretical_earliestOperationStartTime = theoreticalStart; this.theoretical_latestOperationStartTime = theoreticalEnd; this.endTime = theoreticalStart; setIndex(-1); } + public Start(Location location, double theoreticalStart, double theoreticalEnd) { + super(); + this.location = location; + this.theoretical_earliestOperationStartTime = theoreticalStart; + this.theoretical_latestOperationStartTime = theoreticalEnd; + this.endTime = theoreticalStart; + setIndex(-1); + } + private Start(Start start) { - this.locationId = start.getLocationId(); + this.location = start.getLocation(); theoretical_earliestOperationStartTime = start.getTheoreticalEarliestOperationStartTime(); theoretical_latestOperationStartTime = start.getTheoreticalLatestOperationStartTime(); endTime = start.getEndTime(); @@ -68,10 +81,14 @@ public final class Start extends AbstractActivity implements TourActivity { return theoretical_earliestOperationStartTime; } + @Deprecated public void setLocationId(String locationId) { - this.locationId = locationId; + if(locationId == null) return; + this.location = Location.Builder.newInstance().setId(locationId).build(); } + public void setLocation(Location location) { this.location = location; }; + public double getTheoreticalLatestOperationStartTime() { return theoretical_latestOperationStartTime; } @@ -84,19 +101,26 @@ public final class Start extends AbstractActivity implements TourActivity { this.theoretical_latestOperationStartTime=time; } + @Deprecated @Override public String getLocationId() { - return locationId; + if(location == null) return null; + return location.getId(); } - @Override + @Override + public Location getLocation() { + return location; + } + + @Override public double getOperationTime() { return 0.0; } @Override public String toString() { - return "[type="+getName()+"][locationId=" + getLocationId() + return "[type="+getName()+"][location=" + location + "][twStart=" + Activities.round(theoretical_earliestOperationStartTime) + "][twEnd=" + Activities.round(theoretical_latestOperationStartTime) + "]"; } diff --git a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivity.java b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivity.java index 71621d64..eae62220 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivity.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/solution/route/activity/TourActivity.java @@ -1,16 +1,16 @@ /******************************************************************************* - * Copyright (C) 2013 Stefan Schroeder - * + * Copyright (C) 2014 Stefan Schroeder + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. - * + * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . ******************************************************************************/ @@ -18,6 +18,7 @@ package jsprit.core.problem.solution.route.activity; import jsprit.core.problem.Capacity; import jsprit.core.problem.HasIndex; +import jsprit.core.problem.Location; import jsprit.core.problem.job.Job; /** @@ -60,8 +61,17 @@ public interface TourActivity extends HasIndex { * Returns the activity's locationId. * * @return locationId + * @deprecated use location */ + @Deprecated public abstract String getLocationId(); + + /** + * Returns location. + * + * @return location + */ + public abstract Location getLocation(); /** * Returns the theoretical earliest operation start time, which is the time that is just allowed diff --git a/jsprit-core/src/main/resources/vrp_xml_schema.xsd b/jsprit-core/src/main/resources/vrp_xml_schema.xsd index 85c48eee..c0e878cd 100644 --- a/jsprit-core/src/main/resources/vrp_xml_schema.xsd +++ b/jsprit-core/src/main/resources/vrp_xml_schema.xsd @@ -54,31 +54,9 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + @@ -139,6 +117,7 @@ + @@ -185,6 +164,7 @@ + @@ -201,6 +181,7 @@ + @@ -350,6 +331,14 @@ + + + + + + + + diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestAuxilliaryCostCalculator.java b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestAuxilliaryCostCalculator.java index 1ebd06e2..69104187 100644 --- a/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestAuxilliaryCostCalculator.java +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/recreate/TestAuxilliaryCostCalculator.java @@ -1,38 +1,35 @@ /******************************************************************************* - * Copyright (c) 2014 Stefan Schroeder. - * + * Copyright (C) 2014 Stefan Schroeder + * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either + * License as published by the Free Software Foundation; either * version 3.0 of the License, or (at your option) any later version. - * + * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . - * - * Contributors: - * Stefan Schroeder - initial API and implementation ******************************************************************************/ package jsprit.core.algorithm.recreate; -import static org.junit.Assert.*; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Arrays; - import jsprit.core.problem.cost.VehicleRoutingActivityCosts; import jsprit.core.problem.cost.VehicleRoutingTransportCosts; import jsprit.core.problem.solution.route.activity.End; import jsprit.core.problem.solution.route.activity.TourActivity; import jsprit.core.problem.vehicle.Vehicle; - import org.junit.Before; import org.junit.Test; +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + public class TestAuxilliaryCostCalculator { private VehicleRoutingTransportCosts routingCosts; @@ -76,7 +73,7 @@ public class TestAuxilliaryCostCalculator { public void whenRouteIsClosed_itCalculatesCostUpToEnd_v2(){ TourActivity prevAct = mock(TourActivity.class); when(prevAct.getLocationId()).thenReturn("i"); - End nextAct = End.newInstance("j", 0.0, 0.0); + End nextAct = new End("j", 0.0, 0.0); TourActivity newAct = mock(TourActivity.class); when(newAct.getLocationId()).thenReturn("k"); 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 275cd1c2..8f309677 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 @@ -95,6 +95,8 @@ public class VrpXMLReaderTest { assertEquals("depotLoc2",v1.getStartLocationId()); assertNotNull(v1.getType()); assertEquals("vehType", v1.getType().getTypeId()); + assertNotNull(v1.getStartLocation()); + assertEquals(1,v1.getStartLocation().getIndex()); assertEquals(1000.0,v1.getLatestArrival(),0.01); } @@ -320,6 +322,8 @@ public class VrpXMLReaderTest { VehicleRoutingProblem vrp = builder.build(); Vehicle v3 = getVehicle("v3",vrp.getVehicles()); assertEquals("startLoc",v3.getStartLocationId()); + assertNotNull(v3.getEndLocation()); + assertEquals(4,v3.getEndLocation().getIndex()); } @Test diff --git a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLWriterTest.java b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLWriterTest.java index 40c3bcc0..765407f6 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLWriterTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLWriterTest.java @@ -16,6 +16,7 @@ ******************************************************************************/ package jsprit.core.problem.io; +import jsprit.core.problem.Location; import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem.Builder; import jsprit.core.problem.VehicleRoutingProblem.FleetSize; @@ -138,7 +139,10 @@ public class VrpXMLWriterTest { @Test public void shouldWriteNameOfShipment(){ Builder builder = VehicleRoutingProblem.Builder.newInstance(); - Shipment s1 = Shipment.Builder.newInstance("1").setName("cleaning").setPickupLocationId("pick").setDeliveryLocationId("del").build(); + Location pickLocation = Location.Builder.newInstance().setId("pick").setIndex(1).build(); + Shipment s1 = Shipment.Builder.newInstance("1").setName("cleaning") + .setPickupLocation(pickLocation) + .setDeliveryLocationId("del").build(); VehicleRoutingProblem vrp = builder.addJob(s1).build(); new VrpXMLWriter(vrp, null).write(infileName); diff --git a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java index 31d2db6e..1b0da9b1 100644 --- a/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java +++ b/jsprit-core/src/test/java/jsprit/core/problem/solution/route/VehicleRouteBuilderTest.java @@ -20,6 +20,7 @@ import jsprit.core.problem.Capacity; import jsprit.core.problem.driver.Driver; import jsprit.core.problem.job.Shipment; import jsprit.core.problem.vehicle.Vehicle; +import jsprit.core.problem.vehicle.VehicleImpl; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -93,10 +94,9 @@ public class VehicleRouteBuilderTest { Capacity capacity = Capacity.Builder.newInstance().build(); when(s.getSize()).thenReturn(capacity); when(s2.getSize()).thenReturn(capacity); - Vehicle vehicle = mock(Vehicle.class); - when(vehicle.isReturnToDepot()).thenReturn(true); - when(vehicle.getStartLocationId()).thenReturn("vehLoc"); - when(vehicle.getEndLocationId()).thenReturn("vehLoc"); + Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setEndLocationId("vehLoc") + .build(); + VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class)); builder.addPickup(s); builder.addPickup(s2); diff --git a/jsprit-core/src/test/resources/finiteVrpForReaderTest.xml b/jsprit-core/src/test/resources/finiteVrpForReaderTest.xml index f774287b..eb74e083 100644 --- a/jsprit-core/src/test/resources/finiteVrpForReaderTest.xml +++ b/jsprit-core/src/test/resources/finiteVrpForReaderTest.xml @@ -31,6 +31,7 @@ depotLoc2 + 1 vehType @@ -44,6 +45,7 @@ depotLoc + 2 false vehType2 @@ -57,10 +59,12 @@ startLoc + 3 endLoc + 4 vehType2 diff --git a/jsprit-core/src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml b/jsprit-core/src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml index 63166fc5..5400b9ab 100644 --- a/jsprit-core/src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml +++ b/jsprit-core/src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml @@ -155,8 +155,10 @@ - i(3,9) - + + i(3,9) + + 1 @@ -169,8 +171,10 @@ - j(1,5) - + + j(1,5) + + 1 @@ -186,8 +190,10 @@ - i(3,9) - + + i(3,9) + + 10.0 @@ -197,8 +203,10 @@ - i(9,9) - + + i(9,9) + + 100.0 @@ -213,8 +221,10 @@ - [x=10.0][y=10.0] - + + [x=10.0][y=10.0] + + 0.0 @@ -224,8 +234,10 @@ - [x=10.0][y=0.0] - + + [x=10.0][y=0.0] + + 100.0 diff --git a/jsprit-core/src/test/resources/infiniteWriterV2Test.xml b/jsprit-core/src/test/resources/infiniteWriterV2Test.xml index 01a27b53..f12b9d5a 100644 --- a/jsprit-core/src/test/resources/infiniteWriterV2Test.xml +++ b/jsprit-core/src/test/resources/infiniteWriterV2Test.xml @@ -21,83 +21,37 @@ INFINITE - - - v1 - vehType - - loc - - - loc - - - 0.0 - 1.7976931348623157E308 - - true - - - - - vehType + + + + + pick + 1 + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + + + + del + + 0.0 + + + 0.0 + 1.7976931348623157E308 + + + - 20 + 0 - - 0.0 - 1.0 - - - - - - - loc2 - - 1 - - 4.0 - - - 0.0 - 1.7976931348623157E308 - - - - - loc - - 1 - - 2.0 - - - 0.0 - 1.7976931348623157E308 - - - - - - - 10.0 - - - noDriver - v1 - 0.0 - - 1 - 0.0 - 0.0 - - 0.0 - - - - - - - + cleaning + +