1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

switch to Location

This commit is contained in:
oblonski 2014-12-17 16:20:29 +01:00
parent e33590b380
commit 7e39d08e3d
23 changed files with 390 additions and 271 deletions

View file

@ -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;

View file

@ -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());

View file

@ -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();

View file

@ -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;
}
}

View file

@ -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) pickupLocationId = shipmentConfig.getString("pickup.location.id");
if(pickupLocationId != null){
builder.setPickupLocationId(pickupLocationId);
pickupLocationBuilder.setId(pickupLocationId);
}
//pickup-coord
Coordinate pickupCoord = getCoord(shipmentConfig,"pickup.");
if(pickupCoord == null) pickupCoord = getCoord(shipmentConfig,"pickup.location.");
if(pickupCoord != null){
builder.setPickupCoord(pickupCoord);
if(pickupLocationId != null){
// vrpBuilder.addLocation(pickupLocationId,pickupCoord);
}
else{
// vrpBuilder.addLocation(pickupCoord.toString(),pickupCoord);
builder.setPickupLocationId(pickupCoord.toString());
}
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) deliveryLocationId = shipmentConfig.getString("delivery.location.id");
if(deliveryLocationId != null){
builder.setDeliveryLocationId(deliveryLocationId);
deliveryLocationBuilder.setId(deliveryLocationId);
// builder.setDeliveryLocationId(deliveryLocationId);
}
//delivery-coord
Coordinate deliveryCoord = getCoord(shipmentConfig,"delivery.");
if(deliveryCoord == null) deliveryCoord = getCoord(shipmentConfig,"delivery.location.");
if(deliveryCoord != null){
builder.setDeliveryCoord(deliveryCoord);
if(deliveryLocationId != null){
// vrpBuilder.addLocation(deliveryLocationId,deliveryCoord);
}
else{
// vrpBuilder.addLocation(deliveryCoord.toString(),deliveryCoord);
builder.setDeliveryLocationId(deliveryCoord.toString());
}
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) serviceCoord = getCoord(serviceConfig,"location.");
if(serviceCoord != null){
builder.setCoord(serviceCoord);
if(serviceLocationId != null){
// vrpBuilder.addLocation(serviceLocationId,serviceCoord);
}
else{
// vrpBuilder.addLocation(serviceCoord.toString(),serviceCoord);
builder.setLocationId(serviceCoord.toString());
}
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");

View file

@ -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,10 +221,13 @@ 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<service.getSize().getNuOfDimensions();i++){
xmlConfig.setProperty(shipmentPathString + "("+counter+").capacity-dimensions.dimension("+i+")[@index]", i);
@ -255,10 +259,13 @@ public class VrpXMLWriter {
Shipment shipment = (Shipment) j;
xmlConfig.setProperty(shipmentPathString + "("+counter+")[@id]", shipment.getId());
// xmlConfig.setProperty(shipmentPathString + "("+counter+")[@type]", service.getType());
if(shipment.getPickupLocationId() != null) xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.locationId", shipment.getPickupLocationId());
if(shipment.getPickupCoord() != null) {
xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.coord[@x]", shipment.getPickupCoord().getX());
xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.coord[@y]", shipment.getPickupCoord().getY());
if(shipment.getPickupLocation().getId() != null) xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.location.id", shipment.getPickupLocation().getId());
if(shipment.getPickupLocation().getCoordinate() != null) {
xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.location.coord[@x]", shipment.getPickupLocation().getCoordinate().getX());
xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.location.coord[@y]", shipment.getPickupLocation().getCoordinate().getY());
}
if(shipment.getPickupLocation().getIndex() != Location.NO_INDEX){
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").pickup.location.index", shipment.getPickupLocation().getIndex());
}
xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.duration", shipment.getPickupServiceTime());
@ -266,10 +273,13 @@ public class VrpXMLWriter {
xmlConfig.setProperty(shipmentPathString + "("+counter+").pickup.timeWindows.timeWindow(0).end", shipment.getPickupTimeWindow().getEnd());
if(shipment.getDeliveryLocationId() != null) xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.locationId", shipment.getDeliveryLocationId());
if(shipment.getDeliveryCoord() != null) {
xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.coord[@x]", shipment.getDeliveryCoord().getX());
xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.coord[@y]", shipment.getDeliveryCoord().getY());
if(shipment.getDeliveryLocation().getId() != null) xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.location.id", shipment.getDeliveryLocation().getId());
if(shipment.getDeliveryLocation().getCoordinate() != null) {
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.coord[@x]", shipment.getDeliveryLocation().getCoordinate().getX());
xmlConfig.setProperty(shipmentPathString + "(" + counter + ").delivery.location.coord[@y]", shipment.getDeliveryLocation().getCoordinate().getY());
}
if(shipment.getDeliveryLocation().getIndex() != Location.NO_INDEX){
xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.location.index", shipment.getDeliveryLocation().getIndex());
}
xmlConfig.setProperty(shipmentPathString + "("+counter+").delivery.duration", shipment.getDeliveryServiceTime());
@ -310,15 +320,22 @@ public class VrpXMLWriter {
}
xmlConfig.setProperty(vehiclePathString + "("+counter+").id", vehicle.getId());
xmlConfig.setProperty(vehiclePathString + "("+counter+").typeId", vehicle.getType().getTypeId());
xmlConfig.setProperty(vehiclePathString + "("+counter+").startLocation.id", vehicle.getStartLocationId());
if(vehicle.getStartLocationCoordinate() != null){
xmlConfig.setProperty(vehiclePathString + "("+counter+").startLocation.coord[@x]", vehicle.getStartLocationCoordinate().getX());
xmlConfig.setProperty(vehiclePathString + "("+counter+").startLocation.coord[@y]", vehicle.getStartLocationCoordinate().getY());
xmlConfig.setProperty(vehiclePathString + "("+counter+").startLocation.id", vehicle.getStartLocation().getId());
if(vehicle.getStartLocation().getCoordinate() != null){
xmlConfig.setProperty(vehiclePathString + "("+counter+").startLocation.coord[@x]", vehicle.getStartLocation().getCoordinate().getX());
xmlConfig.setProperty(vehiclePathString + "("+counter+").startLocation.coord[@y]", vehicle.getStartLocation().getCoordinate().getY());
}
xmlConfig.setProperty(vehiclePathString + "("+counter+").endLocation.id", vehicle.getEndLocationId());
if(vehicle.getEndLocationCoordinate() != null){
xmlConfig.setProperty(vehiclePathString + "("+counter+").endLocation.coord[@x]", vehicle.getEndLocationCoordinate().getX());
xmlConfig.setProperty(vehiclePathString + "("+counter+").endLocation.coord[@y]", vehicle.getEndLocationCoordinate().getY());
if(vehicle.getStartLocation().getIndex() != Location.NO_INDEX){
xmlConfig.setProperty(vehiclePathString + "("+counter+").startLocation.index", vehicle.getStartLocation().getIndex());
}
xmlConfig.setProperty(vehiclePathString + "("+counter+").endLocation.id", vehicle.getEndLocation().getId());
if(vehicle.getEndLocation().getCoordinate() != null){
xmlConfig.setProperty(vehiclePathString + "("+counter+").endLocation.coord[@x]", vehicle.getEndLocation().getCoordinate().getX());
xmlConfig.setProperty(vehiclePathString + "("+counter+").endLocation.coord[@y]", vehicle.getEndLocation().getCoordinate().getY());
}
if(vehicle.getEndLocation().getIndex() != Location.NO_INDEX){
xmlConfig.setProperty(vehiclePathString + "("+counter+").endLocation.index", vehicle.getEndLocation().getId());
}
xmlConfig.setProperty(vehiclePathString + "("+counter+").timeSchedule.start", vehicle.getEarliestDeparture());
xmlConfig.setProperty(vehiclePathString + "("+counter+").timeSchedule.end", vehicle.getLatestArrival());

View file

@ -175,9 +175,9 @@ public class VehicleRoute {
super();
this.vehicle = vehicle;
this.driver = driver;
start = Start.newInstance(vehicle.getStartLocationId(), vehicle.getEarliestDeparture(), Double.MAX_VALUE);
start = new Start(vehicle.getStartLocation(), vehicle.getEarliestDeparture(), Double.MAX_VALUE);
start.setEndTime(vehicle.getEarliestDeparture());
end = End.newInstance(vehicle.getEndLocationId(), 0.0, vehicle.getLatestArrival());
end = new End(vehicle.getEndLocation(), 0.0, vehicle.getLatestArrival());
}
/**
@ -401,8 +401,8 @@ public class VehicleRoute {
private void setStartAndEnd(Vehicle vehicle, double vehicleDepTime) {
if(!(vehicle instanceof NoVehicle)){
if(start == null && end == null){
start = Start.newInstance(vehicle.getStartLocationId(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival());
end = End.newInstance(vehicle.getEndLocationId(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival());
start = new Start(vehicle.getStartLocation(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival());
end = new End(vehicle.getEndLocation(), vehicle.getEarliestDeparture(), vehicle.getLatestArrival());
}
start.setEndTime(Math.max(vehicleDepTime, vehicle.getEarliestDeparture()));
start.setTheoreticalEarliestOperationStartTime(vehicle.getEarliestDeparture());

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -8,18 +8,17 @@
*
* 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.
* 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 <http://www.gnu.org/licenses/>.
*
* 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,6 +55,11 @@ public final class DeliverService extends AbstractActivity implements DeliveryAc
return delivery.getLocationId();
}
@Override
public Location getLocation() {
return delivery.getLocation();
}
@Override
public double getTheoreticalEarliestOperationStartTime() {
return delivery.getTimeWindow().getStart();

View file

@ -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,6 +62,11 @@ public final class DeliverShipment extends AbstractActivity implements DeliveryA
return shipment.getDeliveryLocationId();
}
@Override
public Location getLocation() {
return shipment.getDeliveryLocation();
}
@Override
public double getTheoreticalEarliestOperationStartTime() {
return shipment.getDeliveryTimeWindow().getStart();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -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 {
@ -36,14 +37,14 @@ 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,9 +68,18 @@ public final class End extends AbstractActivity implements TourActivity {
theoretical_latestOperationStartTime = theoreticalLatestOperationStartTime;
}
public End(Location location, double theoreticalStart, double theoreticalEnd) {
super();
this.location = location;
theoretical_earliestOperationStartTime = theoreticalStart;
theoretical_latestOperationStartTime = theoreticalEnd;
endTime = theoreticalEnd;
setIndex(-2);
}
public End(String locationId, double theoreticalStart, double theoreticalEnd) {
super();
this.locationId = locationId;
if(locationId != null) this.location = Location.Builder.newInstance().setId(locationId).build();
theoretical_earliestOperationStartTime = theoreticalStart;
theoretical_latestOperationStartTime = theoreticalEnd;
endTime = theoreticalEnd;
@ -75,7 +87,8 @@ public final class End extends AbstractActivity implements TourActivity {
}
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,13 +112,26 @@ 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() {
if(location == null) return null;
return location.getId();
}
@Override
public String getLocationId() {
return locationId;
public Location getLocation() {
return location;
}
@Override
@ -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) + "]";
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -8,18 +8,17 @@
*
* 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.
* 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 <http://www.gnu.org/licenses/>.
*
* 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,6 +56,11 @@ public final class PickupService extends AbstractActivity implements PickupActiv
return pickup.getLocationId();
}
@Override
public Location getLocation() {
return pickup.getLocation();
}
@Override
public double getTheoreticalEarliestOperationStartTime() {
return pickup.getTimeWindow().getStart();

View file

@ -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,6 +58,11 @@ public final class PickupShipment extends AbstractActivity implements PickupActi
return shipment.getPickupLocationId();
}
@Override
public Location getLocation() {
return shipment.getPickupLocation();
}
@Override
public double getTheoreticalEarliestOperationStartTime() {
return shipment.getPickupTimeWindow().getStart();

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -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,6 +132,11 @@ public class ServiceActivity extends AbstractActivity implements JobActivity{
return service.getLocationId();
}
@Override
public Location getLocation() {
return service.getLocation();
}
@Override
public Service getJob() {

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -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 {
@ -47,9 +48,21 @@ public final class Start extends AbstractActivity implements TourActivity {
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;
@ -57,7 +70,7 @@ public final class Start extends AbstractActivity implements TourActivity {
}
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,9 +101,16 @@ 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
public Location getLocation() {
return location;
}
@Override
@ -96,7 +120,7 @@ public final class Start 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) + "]";
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -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,9 +61,18 @@ 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
* (not earlier) to start this activity, that is for example <code>service.getTimeWindow().getStart()</code>.

View file

@ -54,31 +54,9 @@
<xs:complexType>
<xs:all>
<xs:element name="id" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="location" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element name="id" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="coord" type="coordType" minOccurs="0" maxOccurs="1"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="startLocation" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element name="id" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="coord" type="coordType" minOccurs="0" maxOccurs="1"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="endLocation" minOccurs="0" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element name="id" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="coord" type="coordType" minOccurs="0" maxOccurs="1"/>
</xs:all>
</xs:complexType>
</xs:element>
<xs:element name="location" type="locationType" minOccurs="0" maxOccurs="1"/>
<xs:element name="startLocation" type="locationType" minOccurs="0" maxOccurs="1"/>
<xs:element name="endLocation" type="locationType" minOccurs="0" maxOccurs="1"/>
<xs:element name="typeId" type="xs:string" minOccurs="1" maxOccurs="1"/>
<xs:element name="timeSchedule" type="timeWindowType"/>
<xs:element name="returnToDepot" type="xs:boolean" minOccurs="0" maxOccurs="1"/>
@ -139,6 +117,7 @@
<xs:element name="service" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:all>
<xs:element name="location" type="locationType" minOccurs="0" maxOccurs="1"/>
<xs:element name="locationId" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="coord" type="coordType" minOccurs="0" maxOccurs="1"/>
<xs:element name="name" type="xs:string" minOccurs="0" maxOccurs="1"/>
@ -185,6 +164,7 @@
<xs:element name="pickup" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element name="location" type="locationType" minOccurs="0" maxOccurs="1"/>
<xs:element name="locationId" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="coord" type="coordType" minOccurs="0" maxOccurs="1"/>
<xs:element name="duration" type="xs:decimal" minOccurs="0" maxOccurs="1" default="0.0"/>
@ -201,6 +181,7 @@
<xs:element name="delivery" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:all>
<xs:element name="location" type="locationType" minOccurs="0" maxOccurs="1"/>
<xs:element name="locationId" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="coord" type="coordType" minOccurs="0" maxOccurs="1"/>
<xs:element name="duration" type="xs:decimal" minOccurs="0" maxOccurs="1" default="0.0"/>
@ -350,6 +331,14 @@
</xs:sequence>
</xs:complexType>
<xs:complexType name="locationType">
<xs:all>
<xs:element name="id" type="xs:string" minOccurs="0" maxOccurs="1"/>
<xs:element name="coord" type="coordType" minOccurs="0" maxOccurs="1"/>
<xs:element name="index" type="xs:int" minOccurs="0" maxOccurs="1"/>
</xs:all>
</xs:complexType>
<xs:complexType name="coordType">
<xs:attribute name="x" type="xs:double" use="required" />
<xs:attribute name="y" type="xs:double" use="required" />

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* 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
@ -8,31 +8,28 @@
*
* 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.
* 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 <http://www.gnu.org/licenses/>.
*
* 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");

View file

@ -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

View file

@ -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);

View file

@ -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);

View file

@ -31,6 +31,7 @@
<location>
<id>depotLoc2</id>
<coord x="100.0" y="100.0"/>
<index>1</index>
</location>
<typeId>vehType</typeId>
<timeSchedule>
@ -44,6 +45,7 @@
<location>
<id>depotLoc</id>
<coord x="10.0" y="100.0"/>
<index>2</index>
</location>
<returnToDepot>false</returnToDepot>
<typeId>vehType2</typeId>
@ -57,10 +59,12 @@
<startLocation>
<id>startLoc</id>
<coord x="10.0" y="100.0"/>
<index>3</index>
</startLocation>
<endLocation>
<id>endLoc</id>
<coord x="1000.0" y="2000.0"/>
<index>4</index>
</endLocation>
<typeId>vehType2</typeId>
<timeSchedule>

View file

@ -155,8 +155,10 @@
</vehicleTypes>
<services>
<service id="2" type="service">
<locationId>i(3,9)</locationId>
<location>
<id>i(3,9)</id>
<coord x="10.0" y="10.0"/>
</location>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
@ -169,8 +171,10 @@
</timeWindows>
</service>
<service id="1" type="service">
<locationId>j(1,5)</locationId>
<location>
<id>j(1,5)</id>
<coord x="10.0" y="10.0"/>
</location>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
@ -186,8 +190,10 @@
<shipments>
<shipment id="3">
<pickup>
<locationId>i(3,9)</locationId>
<location>
<id>i(3,9)</id>
<coord x="10.0" y="10.0"/>
</location>
<duration>10.0</duration>
<timeWindows>
<timeWindow>
@ -197,8 +203,10 @@
</timeWindows>
</pickup>
<delivery>
<locationId>i(9,9)</locationId>
<location>
<id>i(9,9)</id>
<coord x="10.0" y="0.0"/>
</location>
<duration>100.0</duration>
<timeWindows>
<timeWindow>
@ -213,8 +221,10 @@
</shipment>
<shipment id="4">
<pickup>
<locationId>[x=10.0][y=10.0]</locationId>
<location>
<id>[x=10.0][y=10.0]</id>
<coord x="10.0" y="10.0"/>
</location>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
@ -224,8 +234,10 @@
</timeWindows>
</pickup>
<delivery>
<locationId>[x=10.0][y=0.0]</locationId>
<location>
<id>[x=10.0][y=0.0]</id>
<coord x="10.0" y="0.0"/>
</location>
<duration>100.0</duration>
<timeWindows>
<timeWindow>

View file

@ -21,83 +21,37 @@
<problemType>
<fleetSize>INFINITE</fleetSize>
</problemType>
<vehicles>
<vehicle>
<id>v1</id>
<typeId>vehType</typeId>
<startLocation>
<id>loc</id>
</startLocation>
<endLocation>
<id>loc</id>
</endLocation>
<timeSchedule>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeSchedule>
<returnToDepot>true</returnToDepot>
</vehicle>
</vehicles>
<vehicleTypes>
<type>
<id>vehType</id>
<capacity-dimensions>
<dimension index="0">20</dimension>
</capacity-dimensions>
<costs>
<fixed>0.0</fixed>
<distance>1.0</distance>
<time>0.0</time>
</costs>
</type>
</vehicleTypes>
<services>
<service id="2" type="service">
<locationId>loc2</locationId>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
<duration>4.0</duration>
<shipments>
<shipment id="1">
<pickup>
<location>
<id>pick</id>
<index>1</index>
</location>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</service>
<service id="1" type="service">
<locationId>loc</locationId>
<capacity-dimensions>
<dimension index="0">1</dimension>
</capacity-dimensions>
<duration>2.0</duration>
</pickup>
<delivery>
<location>
<id>del</id>
</location>
<duration>0.0</duration>
<timeWindows>
<timeWindow>
<start>0.0</start>
<end>1.7976931348623157E308</end>
</timeWindow>
</timeWindows>
</service>
</services>
<solutions>
<solution>
<cost>10.0</cost>
<routes>
<route>
<driverId>noDriver</driverId>
<vehicleId>v1</vehicleId>
<start>0.0</start>
<act type="service">
<serviceId>1</serviceId>
<arrTime>0.0</arrTime>
<endTime>0.0</endTime>
</act>
<end>0.0</end>
</route>
</routes>
<unassignedJobs>
<job id="2"/>
</unassignedJobs>
</solution>
</solutions>
</delivery>
<capacity-dimensions>
<dimension index="0">0</dimension>
</capacity-dimensions>
<name>cleaning</name>
</shipment>
</shipments>
</problem>