mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
introduce Location obj
This commit is contained in:
parent
4881c50096
commit
e33590b380
10 changed files with 489 additions and 135 deletions
93
jsprit-core/src/main/java/jsprit/core/problem/Location.java
Normal file
93
jsprit-core/src/main/java/jsprit/core/problem/Location.java
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package jsprit.core.problem;
|
||||||
|
|
||||||
|
import jsprit.core.util.Coordinate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by schroeder on 16.12.14.
|
||||||
|
*/
|
||||||
|
public final class Location implements HasIndex, HasId{
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
private int index = -1;
|
||||||
|
|
||||||
|
private Coordinate coordinate;
|
||||||
|
|
||||||
|
public static Builder newInstance(){ return new Builder(); }
|
||||||
|
|
||||||
|
public Builder setIndex(int index){
|
||||||
|
if(index < 0) throw new IllegalArgumentException("index must be >= 0");
|
||||||
|
this.index = index;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setCoordinate(Coordinate coordinate){
|
||||||
|
this.coordinate = coordinate;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder setId(String id){
|
||||||
|
this.id = id;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location build(){
|
||||||
|
if(id == null && coordinate == null){
|
||||||
|
if(index == -1) throw new IllegalStateException("either id or coordinate or index must be set");
|
||||||
|
}
|
||||||
|
if(coordinate != null && id == null){
|
||||||
|
this.id = coordinate.toString();
|
||||||
|
}
|
||||||
|
if(index != -1 && id == null){
|
||||||
|
this.id = Integer.toString(index);
|
||||||
|
}
|
||||||
|
return new Location(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private final int index;
|
||||||
|
|
||||||
|
private final Coordinate coordinate;
|
||||||
|
|
||||||
|
private final String id;
|
||||||
|
|
||||||
|
private Location(Builder builder) {
|
||||||
|
this.index = builder.index;
|
||||||
|
this.coordinate = builder.coordinate;
|
||||||
|
this.id = builder.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getIndex() {
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Coordinate getCoordinate(){
|
||||||
|
return coordinate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,22 +1,24 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (C) 2013 Stefan Schroeder
|
* Copyright (C) 2014 Stefan Schroeder
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* 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.
|
* 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,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* 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/>.
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package jsprit.core.problem.job;
|
package jsprit.core.problem.job;
|
||||||
|
|
||||||
|
|
||||||
|
import jsprit.core.problem.Location;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delivery extends Service and is intended to model a Service where smth is UNLOADED (i.e. delivered) from a transport unit.
|
* Delivery extends Service and is intended to model a Service where smth is UNLOADED (i.e. delivered) from a transport unit.
|
||||||
*
|
*
|
||||||
|
|
@ -48,9 +50,10 @@ public class Delivery extends Service{
|
||||||
* @throws IllegalStateException if neither locationId nor coord is set
|
* @throws IllegalStateException if neither locationId nor coord is set
|
||||||
*/
|
*/
|
||||||
public Delivery build(){
|
public Delivery build(){
|
||||||
if(locationId == null) {
|
if(location == null) {
|
||||||
if(coord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not.");
|
location = Location.Builder.newInstance().setCoordinate(coord).setId(locationId).build();
|
||||||
locationId = coord.toString();
|
// if(coord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not.");
|
||||||
|
// locationId = coord.toString();
|
||||||
}
|
}
|
||||||
this.setType("delivery");
|
this.setType("delivery");
|
||||||
super.capacity = super.capacityBuilder.build();
|
super.capacity = super.capacityBuilder.build();
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,24 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (C) 2013 Stefan Schroeder
|
* Copyright (C) 2014 Stefan Schroeder
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* 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.
|
* 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,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* 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/>.
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package jsprit.core.problem.job;
|
package jsprit.core.problem.job;
|
||||||
|
|
||||||
|
|
||||||
|
import jsprit.core.problem.Location;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pickup extends Service and is intended to model a Service where smth is LOADED (i.e. picked up) to a transport unit.
|
* Pickup extends Service and is intended to model a Service where smth is LOADED (i.e. picked up) to a transport unit.
|
||||||
*
|
*
|
||||||
|
|
@ -50,9 +52,10 @@ public class Pickup extends Service {
|
||||||
* @throws IllegalStateException if neither locationId nor coordinate has been set
|
* @throws IllegalStateException if neither locationId nor coordinate has been set
|
||||||
*/
|
*/
|
||||||
public Pickup build(){
|
public Pickup build(){
|
||||||
if(locationId == null) {
|
if(location == null) {
|
||||||
if(coord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not.");
|
location = Location.Builder.newInstance().setCoordinate(coord).setId(locationId).build();
|
||||||
locationId = coord.toString();
|
// if(coord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not.");
|
||||||
|
// locationId = coord.toString();
|
||||||
}
|
}
|
||||||
this.setType("pickup");
|
this.setType("pickup");
|
||||||
super.capacity = super.capacityBuilder.build();
|
super.capacity = super.capacityBuilder.build();
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package jsprit.core.problem.job;
|
||||||
|
|
||||||
import jsprit.core.problem.AbstractJob;
|
import jsprit.core.problem.AbstractJob;
|
||||||
import jsprit.core.problem.Capacity;
|
import jsprit.core.problem.Capacity;
|
||||||
|
import jsprit.core.problem.Location;
|
||||||
import jsprit.core.problem.Skills;
|
import jsprit.core.problem.Skills;
|
||||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||||
import jsprit.core.util.Coordinate;
|
import jsprit.core.util.Coordinate;
|
||||||
|
|
@ -37,6 +38,7 @@ public class Service extends AbstractJob {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder that builds a service.
|
* Builder that builds a service.
|
||||||
*
|
*
|
||||||
|
|
@ -79,6 +81,8 @@ public class Service extends AbstractJob {
|
||||||
|
|
||||||
private String name = "no-name";
|
private String name = "no-name";
|
||||||
|
|
||||||
|
protected Location location;
|
||||||
|
|
||||||
Builder(String id){
|
Builder(String id){
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
@ -101,18 +105,33 @@ public class Service extends AbstractJob {
|
||||||
*
|
*
|
||||||
* @param locationId the location id of the service
|
* @param locationId the location id of the service
|
||||||
* @return builder
|
* @return builder
|
||||||
|
* @deprecated use .setLocation(..) instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Builder setLocationId(String locationId){
|
public Builder setLocationId(String locationId){
|
||||||
this.locationId = locationId;
|
this.locationId = locationId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets location
|
||||||
|
*
|
||||||
|
* @param location location
|
||||||
|
* @return builder
|
||||||
|
*/
|
||||||
|
public Builder setLocation(Location location){
|
||||||
|
this.location = location;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the coordinate of this service.
|
* Sets the coordinate of this service.
|
||||||
*
|
*
|
||||||
* @param coord the coordinate of service
|
* @param coord the coordinate of service
|
||||||
* @return builder
|
* @return builder
|
||||||
|
* @deprecated use .setLocation(..) instead and add coordinate ot Location obj
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Builder setCoord(Coordinate coord){
|
public Builder setCoord(Coordinate coord){
|
||||||
this.coord = coord;
|
this.coord = coord;
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -170,10 +189,14 @@ public class Service extends AbstractJob {
|
||||||
* @throws IllegalStateException if neither locationId nor coordinate is set.
|
* @throws IllegalStateException if neither locationId nor coordinate is set.
|
||||||
*/
|
*/
|
||||||
public Service build(){
|
public Service build(){
|
||||||
if(locationId == null) {
|
if(location == null) {
|
||||||
if(coord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not.");
|
location = Location.Builder.newInstance().setCoordinate(coord).setId(locationId).build();
|
||||||
locationId = coord.toString();
|
// 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");
|
this.setType("service");
|
||||||
capacity = capacityBuilder.build();
|
capacity = capacityBuilder.build();
|
||||||
skills = skillBuilder.build();
|
skills = skillBuilder.build();
|
||||||
|
|
@ -193,13 +216,9 @@ public class Service extends AbstractJob {
|
||||||
|
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
private final String locationId;
|
|
||||||
|
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
private final Coordinate coord;
|
|
||||||
|
|
||||||
private final double serviceTime;
|
private final double serviceTime;
|
||||||
|
|
||||||
private final TimeWindow timeWindow;
|
private final TimeWindow timeWindow;
|
||||||
|
|
@ -210,16 +229,17 @@ public class Service extends AbstractJob {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
private final Location location;
|
||||||
|
|
||||||
Service(Builder builder){
|
Service(Builder builder){
|
||||||
id = builder.id;
|
id = builder.id;
|
||||||
locationId = builder.locationId;
|
serviceTime = builder.serviceTime;
|
||||||
coord = builder.coord;
|
|
||||||
serviceTime = builder.serviceTime;
|
|
||||||
timeWindow = builder.timeWindow;
|
timeWindow = builder.timeWindow;
|
||||||
type = builder.type;
|
type = builder.type;
|
||||||
size = builder.capacity;
|
size = builder.capacity;
|
||||||
skills = builder.skills;
|
skills = builder.skills;
|
||||||
name = builder.name;
|
name = builder.name;
|
||||||
|
location = builder.location;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -231,19 +251,33 @@ public class Service extends AbstractJob {
|
||||||
* Returns the location-id of this service.
|
* Returns the location-id of this service.
|
||||||
*
|
*
|
||||||
* @return String that indicates the location
|
* @return String that indicates the location
|
||||||
|
* @deprecated use .getLocation().getId() instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public String getLocationId() {
|
public String getLocationId() {
|
||||||
return locationId;
|
return location.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public AbstractLocation getLocation()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the coordinate of this service.
|
* Returns the coordinate of this service.
|
||||||
*
|
*
|
||||||
* @return {@link Coordinate}
|
* @return {@link Coordinate}
|
||||||
|
* @deprecated use .getLocation().getCoordinate() instead
|
||||||
*/
|
*/
|
||||||
public Coordinate getCoord(){
|
@Deprecated
|
||||||
return coord;
|
public Coordinate getCoord(){ return location.getCoordinate(); }
|
||||||
}
|
|
||||||
|
/**
|
||||||
|
* Returns location.
|
||||||
|
*
|
||||||
|
* @return location
|
||||||
|
*/
|
||||||
|
public Location getLocation(){
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the service-time/duration a service takes at service-location.
|
* Returns the service-time/duration a service takes at service-location.
|
||||||
|
|
@ -277,7 +311,7 @@ public class Service extends AbstractJob {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[id=" + id + "][name="+name+"][type="+type+"][locationId=" + locationId + "][coord="+coord+"][capacity=" + size + "][serviceTime=" + serviceTime + "][timeWindow=" + timeWindow + "]";
|
return "[id=" + id + "][name="+name+"][type="+type+"][location=" + location + "][capacity=" + size + "][serviceTime=" + serviceTime + "][timeWindow=" + timeWindow + "]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package jsprit.core.problem.job;
|
||||||
|
|
||||||
import jsprit.core.problem.AbstractJob;
|
import jsprit.core.problem.AbstractJob;
|
||||||
import jsprit.core.problem.Capacity;
|
import jsprit.core.problem.Capacity;
|
||||||
|
import jsprit.core.problem.Location;
|
||||||
import jsprit.core.problem.Skills;
|
import jsprit.core.problem.Skills;
|
||||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||||
import jsprit.core.util.Coordinate;
|
import jsprit.core.util.Coordinate;
|
||||||
|
|
@ -79,6 +80,10 @@ public class Shipment extends AbstractJob{
|
||||||
|
|
||||||
private String name = "no-name";
|
private String name = "no-name";
|
||||||
|
|
||||||
|
private Location pickupLocation_;
|
||||||
|
|
||||||
|
private Location deliveryLocation_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns new instance of this builder.
|
* Returns new instance of this builder.
|
||||||
*
|
*
|
||||||
|
|
@ -100,13 +105,26 @@ public class Shipment extends AbstractJob{
|
||||||
* @param pickupLocationId the location id of shipment's pickup
|
* @param pickupLocationId the location id of shipment's pickup
|
||||||
* @return builder
|
* @return builder
|
||||||
* @throws IllegalArgumentException if location is null
|
* @throws IllegalArgumentException if location is null
|
||||||
|
* @deprecated use .setLocation(..) instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Builder setPickupLocationId(String pickupLocationId){
|
public Builder setPickupLocationId(String pickupLocationId){
|
||||||
if(pickupLocationId == null) throw new IllegalArgumentException("location must not be null");
|
if(pickupLocationId == null) throw new IllegalArgumentException("location must not be null");
|
||||||
this.pickupLocation = pickupLocationId;
|
this.pickupLocation = pickupLocationId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets pickup location.
|
||||||
|
*
|
||||||
|
* @param pickupLocation pickup location
|
||||||
|
* @return builder
|
||||||
|
*/
|
||||||
|
public Builder setPickupLocation(Location pickupLocation){
|
||||||
|
this.pickupLocation_ = pickupLocation;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets pickup-location id.
|
* Sets pickup-location id.
|
||||||
*
|
*
|
||||||
|
|
@ -128,7 +146,9 @@ public class Shipment extends AbstractJob{
|
||||||
* @param pickupCoord the coordinate of shipment's pickup location
|
* @param pickupCoord the coordinate of shipment's pickup location
|
||||||
* @return builder
|
* @return builder
|
||||||
* @throws IllegalArgumentException if pickupCoord is null
|
* @throws IllegalArgumentException if pickupCoord is null
|
||||||
|
* @deprecated use .setLocation(..) instead and add coordinate to location obj.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Builder setPickupCoord(Coordinate pickupCoord){
|
public Builder setPickupCoord(Coordinate pickupCoord){
|
||||||
if(pickupCoord == null) throw new IllegalArgumentException("coord must not be null");
|
if(pickupCoord == null) throw new IllegalArgumentException("coord must not be null");
|
||||||
this.pickupCoord = pickupCoord;
|
this.pickupCoord = pickupCoord;
|
||||||
|
|
@ -172,13 +192,26 @@ public class Shipment extends AbstractJob{
|
||||||
* @param deliveryLocationId the delivery location id
|
* @param deliveryLocationId the delivery location id
|
||||||
* @return builder
|
* @return builder
|
||||||
* @throws IllegalArgumentException if location is null
|
* @throws IllegalArgumentException if location is null
|
||||||
|
* @deprecated use .setDeliveryLocation instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Builder setDeliveryLocationId(String deliveryLocationId){
|
public Builder setDeliveryLocationId(String deliveryLocationId){
|
||||||
if(deliveryLocationId == null) throw new IllegalArgumentException("delivery location must not be null");
|
if(deliveryLocationId == null) throw new IllegalArgumentException("delivery location must not be null");
|
||||||
this.deliveryLocation = deliveryLocationId;
|
this.deliveryLocation = deliveryLocationId;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets delivery location.
|
||||||
|
*
|
||||||
|
* @param deliveryLocation delivery location
|
||||||
|
* @return builder
|
||||||
|
*/
|
||||||
|
public Builder setDeliveryLocation(Location deliveryLocation){
|
||||||
|
this.deliveryLocation_ = deliveryLocation;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the delivery-location.
|
* Sets the delivery-location.
|
||||||
*
|
*
|
||||||
|
|
@ -186,6 +219,7 @@ public class Shipment extends AbstractJob{
|
||||||
* @return builder
|
* @return builder
|
||||||
* @throws IllegalArgumentException if location is null
|
* @throws IllegalArgumentException if location is null
|
||||||
* @deprecated use .setDeliveryLocationId(deliveryLocationId)
|
* @deprecated use .setDeliveryLocationId(deliveryLocationId)
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Builder setDeliveryLocation(String deliveryLocation){
|
public Builder setDeliveryLocation(String deliveryLocation){
|
||||||
|
|
@ -200,7 +234,9 @@ public class Shipment extends AbstractJob{
|
||||||
* @param deliveryCoord the coordinate of shipment's delivery location
|
* @param deliveryCoord the coordinate of shipment's delivery location
|
||||||
* @return builder
|
* @return builder
|
||||||
* @throws IllegalArgumentException if coord is null;
|
* @throws IllegalArgumentException if coord is null;
|
||||||
|
* @deprecated use .setDeliveryLocation(..) instead and add coordinate to location obj
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Builder setDeliveryCoord(Coordinate deliveryCoord){
|
public Builder setDeliveryCoord(Coordinate deliveryCoord){
|
||||||
if(deliveryCoord == null) throw new IllegalArgumentException("coord must not be null");
|
if(deliveryCoord == null) throw new IllegalArgumentException("coord must not be null");
|
||||||
this.deliveryCoord = deliveryCoord;
|
this.deliveryCoord = deliveryCoord;
|
||||||
|
|
@ -261,13 +297,15 @@ public class Shipment extends AbstractJob{
|
||||||
* is set
|
* is set
|
||||||
*/
|
*/
|
||||||
public Shipment build(){
|
public Shipment build(){
|
||||||
if(pickupLocation == null) {
|
if(pickupLocation_ == null) {
|
||||||
if(pickupCoord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not.");
|
this.pickupLocation_ = Location.Builder.newInstance().setCoordinate(pickupCoord).setId(pickupLocation).build();
|
||||||
pickupLocation = pickupCoord.toString();
|
// if(pickupCoord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not.");
|
||||||
}
|
// pickupLocation = pickupCoord.toString();
|
||||||
if(deliveryLocation == null) {
|
}
|
||||||
if(deliveryCoord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not.");
|
if(deliveryLocation_ == null) {
|
||||||
deliveryLocation = deliveryCoord.toString();
|
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();
|
capacity = capacityBuilder.build();
|
||||||
skills = skillBuilder.build();
|
skills = skillBuilder.build();
|
||||||
|
|
@ -287,16 +325,8 @@ public class Shipment extends AbstractJob{
|
||||||
}
|
}
|
||||||
|
|
||||||
private final String id;
|
private final String id;
|
||||||
|
|
||||||
private final String pickupLocation;
|
|
||||||
|
|
||||||
private final Coordinate pickupCoord;
|
|
||||||
|
|
||||||
private final double pickupServiceTime;
|
private final double pickupServiceTime;
|
||||||
|
|
||||||
private final String deliveryLocation;
|
|
||||||
|
|
||||||
private final Coordinate deliveryCoord;
|
|
||||||
|
|
||||||
private final double deliveryServiceTime;
|
private final double deliveryServiceTime;
|
||||||
|
|
||||||
|
|
@ -308,21 +338,23 @@ public class Shipment extends AbstractJob{
|
||||||
|
|
||||||
private final Skills skills;
|
private final Skills skills;
|
||||||
|
|
||||||
private String name;
|
private final String name;
|
||||||
|
|
||||||
|
private final Location pickupLocation_;
|
||||||
|
|
||||||
|
private final Location deliveryLocation_;
|
||||||
|
|
||||||
Shipment(Builder builder){
|
Shipment(Builder builder){
|
||||||
this.id = builder.id;
|
this.id = builder.id;
|
||||||
this.pickupLocation = builder.pickupLocation;
|
|
||||||
this.pickupCoord = builder.pickupCoord;
|
|
||||||
this.pickupServiceTime = builder.pickupServiceTime;
|
this.pickupServiceTime = builder.pickupServiceTime;
|
||||||
this.pickupTimeWindow = builder.pickupTimeWindow;
|
this.pickupTimeWindow = builder.pickupTimeWindow;
|
||||||
this.deliveryLocation = builder.deliveryLocation;
|
|
||||||
this.deliveryCoord = builder.deliveryCoord;
|
|
||||||
this.deliveryServiceTime = builder.deliveryServiceTime;
|
this.deliveryServiceTime = builder.deliveryServiceTime;
|
||||||
this.deliveryTimeWindow = builder.deliveryTimeWindow;
|
this.deliveryTimeWindow = builder.deliveryTimeWindow;
|
||||||
this.capacity = builder.capacity;
|
this.capacity = builder.capacity;
|
||||||
this.skills = builder.skills;
|
this.skills = builder.skills;
|
||||||
this.name = builder.name;
|
this.name = builder.name;
|
||||||
|
this.pickupLocation_ = builder.pickupLocation_;
|
||||||
|
this.deliveryLocation_ = builder.deliveryLocation_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -330,35 +362,30 @@ public class Shipment extends AbstractJob{
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the pickup-location.
|
|
||||||
*
|
|
||||||
* @return pickup-location
|
|
||||||
* @deprecated use .getPickupLocationId() instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public String getPickupLocation() {
|
|
||||||
return pickupLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the pickup-location.
|
* Returns the pickup-location.
|
||||||
*
|
*
|
||||||
* @return pickup-location
|
* @return pickup-location
|
||||||
|
* @deprecated use .getLocation().getId() instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public String getPickupLocationId() {
|
public String getPickupLocationId() {
|
||||||
return pickupLocation;
|
return pickupLocation_.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the pickup-coordinate.
|
* Returns the pickup-coordinate.
|
||||||
*
|
*
|
||||||
* @return coordinate of the pickup
|
* @return coordinate of the pickup
|
||||||
|
* @deprecated use .getLocation(..).getCoordinate() instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Coordinate getPickupCoord() {
|
public Coordinate getPickupCoord() {
|
||||||
return pickupCoord;
|
return pickupLocation_.getCoordinate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Location getPickupLocation(){ return pickupLocation_; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the pickup service-time.
|
* Returns the pickup service-time.
|
||||||
*
|
*
|
||||||
|
|
@ -370,35 +397,30 @@ public class Shipment extends AbstractJob{
|
||||||
return pickupServiceTime;
|
return pickupServiceTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns delivery-location.
|
|
||||||
*
|
|
||||||
* @return delivery-location
|
|
||||||
* @deprecated use .getDeliveryLocationId() instead
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public String getDeliveryLocation() {
|
|
||||||
return deliveryLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns delivery-location.
|
* Returns delivery-location.
|
||||||
*
|
*
|
||||||
* @return delivery-location
|
* @return delivery-location
|
||||||
|
* @deprecated use .getLocation().getId() instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public String getDeliveryLocationId() {
|
public String getDeliveryLocationId() {
|
||||||
return deliveryLocation;
|
return deliveryLocation_.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns coordinate of the delivery.
|
* Returns coordinate of the delivery.
|
||||||
*
|
*
|
||||||
* @return coordinate of delivery
|
* @return coordinate of delivery
|
||||||
|
* @deprecated use .getLocation().getCoordinate() instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Coordinate getDeliveryCoord() {
|
public Coordinate getDeliveryCoord() {
|
||||||
return deliveryCoord;
|
return deliveryLocation_.getCoordinate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Location getDeliveryLocation() { return deliveryLocation_; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns service-time of delivery.
|
* Returns service-time of delivery.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -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
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Lesser General Public
|
* 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.
|
* 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,
|
* This library is distributed in the hope that it will be useful,
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* Lesser General Public License for more details.
|
* Lesser General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU Lesser General Public
|
* 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/>.
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
@ -18,6 +18,7 @@ package jsprit.core.problem.vehicle;
|
||||||
|
|
||||||
import jsprit.core.problem.HasId;
|
import jsprit.core.problem.HasId;
|
||||||
import jsprit.core.problem.HasIndex;
|
import jsprit.core.problem.HasIndex;
|
||||||
|
import jsprit.core.problem.Location;
|
||||||
import jsprit.core.problem.Skills;
|
import jsprit.core.problem.Skills;
|
||||||
import jsprit.core.util.Coordinate;
|
import jsprit.core.util.Coordinate;
|
||||||
|
|
||||||
|
|
@ -68,22 +69,30 @@ public interface Vehicle extends HasId, HasIndex {
|
||||||
/**
|
/**
|
||||||
* Returns the start-locationId of this vehicle.
|
* Returns the start-locationId of this vehicle.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public abstract String getStartLocationId();
|
public abstract String getStartLocationId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the start-locationCoord of this vehicle.
|
* Returns the start-locationCoord of this vehicle.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public abstract Coordinate getStartLocationCoordinate();
|
public abstract Coordinate getStartLocationCoordinate();
|
||||||
|
|
||||||
|
public abstract Location getStartLocation();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the end-locationId of this vehicle.
|
* Returns the end-locationId of this vehicle.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public abstract String getEndLocationId();
|
public abstract String getEndLocationId();
|
||||||
|
|
||||||
|
public abstract Location getEndLocation();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the end-locationCoord of this vehicle.
|
* Returns the end-locationCoord of this vehicle.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public abstract Coordinate getEndLocationCoordinate();
|
public abstract Coordinate getEndLocationCoordinate();
|
||||||
|
|
||||||
public abstract VehicleTypeKey getVehicleTypeIdentifier();
|
public abstract VehicleTypeKey getVehicleTypeIdentifier();
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
package jsprit.core.problem.vehicle;
|
package jsprit.core.problem.vehicle;
|
||||||
|
|
||||||
import jsprit.core.problem.AbstractVehicle;
|
import jsprit.core.problem.AbstractVehicle;
|
||||||
|
import jsprit.core.problem.Location;
|
||||||
import jsprit.core.problem.Skills;
|
import jsprit.core.problem.Skills;
|
||||||
import jsprit.core.util.Coordinate;
|
import jsprit.core.util.Coordinate;
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
@ -35,6 +36,7 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extension of {@link VehicleImpl} representing an unspecified vehicle with the id 'noVehicle'
|
* Extension of {@link VehicleImpl} representing an unspecified vehicle with the id 'noVehicle'
|
||||||
* (to avoid null).
|
* (to avoid null).
|
||||||
|
|
@ -42,13 +44,75 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
* @author schroeder
|
* @author schroeder
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static class NoVehicle extends VehicleImpl {
|
public static class NoVehicle extends AbstractVehicle {
|
||||||
|
|
||||||
|
private String id = "noVehicle";
|
||||||
|
|
||||||
|
private VehicleType type = VehicleTypeImpl.Builder.newInstance("noType").build();
|
||||||
|
|
||||||
public NoVehicle() {
|
public NoVehicle() {
|
||||||
super(Builder.newInstance("noVehicle").setType(VehicleTypeImpl.Builder.newInstance("noType").build()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
@Override
|
||||||
|
public double getEarliestDeparture() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getLatestArrival() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VehicleType getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isReturnToDepot() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getStartLocationId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Coordinate getStartLocationCoordinate() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getStartLocation() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getEndLocationId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Location getEndLocation() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Coordinate getEndLocationCoordinate() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Skills getSkills() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder that builds the vehicle.
|
* Builder that builds the vehicle.
|
||||||
|
|
@ -90,6 +154,10 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
|
|
||||||
private Skills skills;
|
private Skills skills;
|
||||||
|
|
||||||
|
private Location startLocation;
|
||||||
|
|
||||||
|
private Location endLocation;
|
||||||
|
|
||||||
private Builder(String id) {
|
private Builder(String id) {
|
||||||
super();
|
super();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
@ -131,7 +199,9 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
* @param startLocationId the location id of vehicle's start
|
* @param startLocationId the location id of vehicle's start
|
||||||
* @return this builder
|
* @return this builder
|
||||||
* @throws IllegalArgumentException if startLocationId is null
|
* @throws IllegalArgumentException if startLocationId is null
|
||||||
|
* @deprecated use .setStartLocation(..) instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Builder setStartLocationId(String startLocationId){
|
public Builder setStartLocationId(String startLocationId){
|
||||||
if(startLocationId == null) throw new IllegalArgumentException("startLocationId cannot be null");
|
if(startLocationId == null) throw new IllegalArgumentException("startLocationId cannot be null");
|
||||||
this.startLocationId = startLocationId;
|
this.startLocationId = startLocationId;
|
||||||
|
|
@ -144,19 +214,33 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
*
|
*
|
||||||
* @param coord the coordinate of vehicle's start location
|
* @param coord the coordinate of vehicle's start location
|
||||||
* @return this builder
|
* @return this builder
|
||||||
|
* @deprecated use .setStartLocation(..) instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Builder setStartLocationCoordinate(Coordinate coord){
|
public Builder setStartLocationCoordinate(Coordinate coord){
|
||||||
this.startLocationCoord = coord;
|
this.startLocationCoord = coord;
|
||||||
this.locationCoord = coord;
|
this.locationCoord = coord;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets start location.
|
||||||
|
* @param startLocation start location
|
||||||
|
* @return start location
|
||||||
|
*/
|
||||||
|
public Builder setStartLocation(Location startLocation){
|
||||||
|
this.startLocation = startLocation;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the end-locationId of this vehicle.
|
* Sets the end-locationId of this vehicle.
|
||||||
*
|
*
|
||||||
* @param endLocationId the location id of vehicle's end
|
* @param endLocationId the location id of vehicle's end
|
||||||
* @return this builder
|
* @return this builder
|
||||||
|
* @deprecated use .setEndLocation(..) instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Builder setEndLocationId(String endLocationId){
|
public Builder setEndLocationId(String endLocationId){
|
||||||
this.endLocationId = endLocationId;
|
this.endLocationId = endLocationId;
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -167,11 +251,18 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
*
|
*
|
||||||
* @param coord the coordinate of vehicle's end location
|
* @param coord the coordinate of vehicle's end location
|
||||||
* @return this builder
|
* @return this builder
|
||||||
|
* @deprecated use .setEndLocation(..) instead
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public Builder setEndLocationCoordinate(Coordinate coord){
|
public Builder setEndLocationCoordinate(Coordinate coord){
|
||||||
this.endLocationCoord = coord;
|
this.endLocationCoord = coord;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder setEndLocation(Location endLocation){
|
||||||
|
this.endLocation = endLocation;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets earliest-start of vehicle which should be the lower bound of the vehicle's departure times.
|
* Sets earliest-start of vehicle which should be the lower bound of the vehicle's departure times.
|
||||||
|
|
@ -217,23 +308,35 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
* or (endLocationId!=null AND returnToDepot=false)
|
* or (endLocationId!=null AND returnToDepot=false)
|
||||||
*/
|
*/
|
||||||
public VehicleImpl build(){
|
public VehicleImpl build(){
|
||||||
if((locationId == null && locationCoord == null) && (startLocationId == null && startLocationCoord == null)){
|
if(startLocation != null && endLocation != null){
|
||||||
throw new IllegalStateException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set");
|
if( !startLocation.getId().equals(endLocation.getId()) && !returnToDepot) throw new IllegalStateException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" +
|
||||||
}
|
"if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified.");
|
||||||
if(locationId == null && locationCoord != null) {
|
}
|
||||||
locationId = locationCoord.toString();
|
if (startLocation != null && endLocation == null && endLocationId == null && endLocationCoord == null) {
|
||||||
startLocationId = locationCoord.toString();
|
endLocation = startLocation;
|
||||||
}
|
}
|
||||||
if(locationId == null && locationCoord == null) throw new IllegalStateException("locationId and locationCoord is missing.");
|
if(startLocation == null && endLocation == null) {
|
||||||
if(locationCoord == null) log.warn("locationCoord for vehicle " + id + " is missing.");
|
if ((locationId == null && locationCoord == null) && (startLocationId == null && startLocationCoord == null)) {
|
||||||
if(endLocationId == null && endLocationCoord != null) endLocationId = endLocationCoord.toString();
|
throw new IllegalStateException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set");
|
||||||
if(endLocationId == null && endLocationCoord == null) {
|
}
|
||||||
endLocationId = startLocationId;
|
if(locationId == null && locationCoord == null) throw new IllegalStateException("locationId and locationCoord is missing.");
|
||||||
endLocationCoord = startLocationCoord;
|
if(locationCoord == null) log.warn("locationCoord for vehicle " + id + " is missing.");
|
||||||
}
|
if (locationId == null && locationCoord != null) {
|
||||||
if( !startLocationId.equals(endLocationId) && !returnToDepot) throw new IllegalStateException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" +
|
locationId = locationCoord.toString();
|
||||||
"if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified.");
|
startLocationId = locationCoord.toString();
|
||||||
skills = skillBuilder.build();
|
}
|
||||||
|
startLocation = Location.Builder.newInstance().setCoordinate(locationCoord).setId(locationId).build();
|
||||||
|
|
||||||
|
if (endLocationId == null && endLocationCoord != null) endLocationId = endLocationCoord.toString();
|
||||||
|
if (endLocationId == null && endLocationCoord == null) {
|
||||||
|
endLocationId = startLocationId;
|
||||||
|
endLocationCoord = startLocationCoord;
|
||||||
|
}
|
||||||
|
endLocation = Location.Builder.newInstance().setCoordinate(endLocationCoord).setId(endLocationId).build();
|
||||||
|
if( !startLocationId.equals(endLocationId) && !returnToDepot) throw new IllegalStateException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" +
|
||||||
|
"if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified.");
|
||||||
|
}
|
||||||
|
skills = skillBuilder.build();
|
||||||
return new VehicleImpl(this);
|
return new VehicleImpl(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -266,40 +369,28 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
|
|
||||||
private final VehicleType type;
|
private final VehicleType type;
|
||||||
|
|
||||||
private final String locationId;
|
|
||||||
|
|
||||||
private final Coordinate coord;
|
|
||||||
|
|
||||||
private final double earliestDeparture;
|
private final double earliestDeparture;
|
||||||
|
|
||||||
private final double latestArrival;
|
private final double latestArrival;
|
||||||
|
|
||||||
private final boolean returnToDepot;
|
private final boolean returnToDepot;
|
||||||
|
|
||||||
private final Coordinate endLocationCoord;
|
private final Skills skills;
|
||||||
|
|
||||||
private final String endLocationId;
|
private final Location endLocation;
|
||||||
|
|
||||||
private final Coordinate startLocationCoord;
|
private final Location startLocation;
|
||||||
|
|
||||||
private final String startLocationId;
|
|
||||||
|
|
||||||
private Skills skills;
|
|
||||||
|
|
||||||
private VehicleImpl(Builder builder){
|
private VehicleImpl(Builder builder){
|
||||||
id = builder.id;
|
id = builder.id;
|
||||||
type = builder.type;
|
type = builder.type;
|
||||||
coord = builder.locationCoord;
|
|
||||||
locationId = builder.locationId;
|
|
||||||
earliestDeparture = builder.earliestStart;
|
earliestDeparture = builder.earliestStart;
|
||||||
latestArrival = builder.latestArrival;
|
latestArrival = builder.latestArrival;
|
||||||
returnToDepot = builder.returnToDepot;
|
returnToDepot = builder.returnToDepot;
|
||||||
startLocationId = builder.startLocationId;
|
skills = builder.skills;
|
||||||
startLocationCoord = builder.startLocationCoord;
|
endLocation = builder.endLocation;
|
||||||
endLocationId = builder.endLocationId;
|
startLocation = builder.startLocation;
|
||||||
endLocationCoord = builder.endLocationCoord;
|
setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(),startLocation.getId(),endLocation.getId(),earliestDeparture,latestArrival,skills));
|
||||||
skills = builder.skills;
|
|
||||||
setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(),startLocationId,endLocationId,earliestDeparture,latestArrival,skills));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -311,10 +402,8 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[id="+id+"]" +
|
return "[id="+id+"]" +
|
||||||
"[type="+type+"]" +
|
"[type="+type+"]" +
|
||||||
"[startLocationId="+startLocationId+"]" +
|
"[startLocation="+startLocation+"]" +
|
||||||
"[startLocationCoordinate=" + startLocationCoord + "]" +
|
"[endLocation=" + endLocation+"]" +
|
||||||
"[endLocationId=" + endLocationId+"]" +
|
|
||||||
"[endLocationCoordinate=" + endLocationCoord + "]" +
|
|
||||||
"[isReturnToDepot=" + isReturnToDepot() + "]" +
|
"[isReturnToDepot=" + isReturnToDepot() + "]" +
|
||||||
"[skills="+ skills + "]";
|
"[skills="+ skills + "]";
|
||||||
|
|
||||||
|
|
@ -346,22 +435,32 @@ public class VehicleImpl extends AbstractVehicle{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getStartLocationId() {
|
public String getStartLocationId() {
|
||||||
return this.startLocationId;
|
return this.startLocation.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Coordinate getStartLocationCoordinate() {
|
public Coordinate getStartLocationCoordinate() {
|
||||||
return this.startLocationCoord;
|
return this.startLocation.getCoordinate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public Location getStartLocation() {
|
||||||
|
return startLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public String getEndLocationId() {
|
public String getEndLocationId() {
|
||||||
return this.endLocationId;
|
return this.endLocation.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
public Location getEndLocation() {
|
||||||
|
return endLocation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Coordinate getEndLocationCoordinate() {
|
public Coordinate getEndLocationCoordinate() {
|
||||||
return this.endLocationCoord;
|
return this.endLocation.getCoordinate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,62 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package jsprit.core.problem;
|
||||||
|
|
||||||
|
import jsprit.core.util.Coordinate;
|
||||||
|
import junit.framework.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by schroeder on 16.12.14.
|
||||||
|
*/
|
||||||
|
public class LocationTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenIndexSet_buildLocation(){
|
||||||
|
Location l = Location.Builder.newInstance().setIndex(1).build();
|
||||||
|
Assert.assertEquals(1,l.getIndex());
|
||||||
|
Assert.assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void whenIndexSmallerZero_throwException(){
|
||||||
|
Location l = Location.Builder.newInstance().setIndex(-1).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalStateException.class)
|
||||||
|
public void whenCoordinateAndIdAndIndexNotSet_throwException(){
|
||||||
|
Location l = Location.Builder.newInstance().build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenIdSet_build(){
|
||||||
|
Location l = Location.Builder.newInstance().setId("id").build();
|
||||||
|
Assert.assertEquals("id",l.getId());
|
||||||
|
Assert.assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenCoordinateSet_build(){
|
||||||
|
Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10,20)).build();
|
||||||
|
Assert.assertEquals(10.,l.getCoordinate().getX());
|
||||||
|
Assert.assertEquals(20.,l.getCoordinate().getY());
|
||||||
|
Assert.assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package jsprit.core.problem.job;
|
package jsprit.core.problem.job;
|
||||||
|
|
||||||
|
import jsprit.core.problem.Location;
|
||||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||||
import jsprit.core.util.Coordinate;
|
import jsprit.core.util.Coordinate;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
@ -102,13 +103,24 @@ public class ServiceTest {
|
||||||
public void whenSettingLocation_itShouldBeSetCorrectly(){
|
public void whenSettingLocation_itShouldBeSetCorrectly(){
|
||||||
Service s = Service.Builder.newInstance("s").setLocationId("loc").build();
|
Service s = Service.Builder.newInstance("s").setLocationId("loc").build();
|
||||||
assertEquals("loc",s.getLocationId());
|
assertEquals("loc",s.getLocationId());
|
||||||
|
assertEquals("loc",s.getLocation().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSettingLocation_itShouldWork(){
|
||||||
|
Service s = Service.Builder.newInstance("s").setLocation(Location.Builder.newInstance().setId("loc").build()).build();
|
||||||
|
assertEquals("loc",s.getLocationId());
|
||||||
|
assertEquals("loc",s.getLocation().getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenSettingLocationCoord_itShouldBeSetCorrectly(){
|
public void whenSettingLocationCoord_itShouldBeSetCorrectly(){
|
||||||
Service s = Service.Builder.newInstance("s").setCoord(Coordinate.newInstance(1, 2)).build();
|
Service s = Service.Builder.newInstance("s").setCoord(Coordinate.newInstance(1, 2)).build();
|
||||||
assertEquals(1.0,s.getCoord().getX(),0.01);
|
assertEquals(1.0,s.getCoord().getX(),0.01);
|
||||||
assertEquals(2.0,s.getCoord().getY(),0.01);
|
assertEquals(2.0,s.getCoord().getY(),0.01);
|
||||||
|
assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01);
|
||||||
|
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalStateException.class)
|
@Test(expected=IllegalStateException.class)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package jsprit.core.problem.job;
|
package jsprit.core.problem.job;
|
||||||
|
|
||||||
|
import jsprit.core.problem.Location;
|
||||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||||
import jsprit.core.util.Coordinate;
|
import jsprit.core.util.Coordinate;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
@ -91,6 +92,7 @@ public class ShipmentTest {
|
||||||
public void whenPickupLocationIdIsSet_itShouldBeDoneCorrectly(){
|
public void whenPickupLocationIdIsSet_itShouldBeDoneCorrectly(){
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocationId("delLoc").setPickupLocationId("pickLoc").build();
|
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocationId("delLoc").setPickupLocationId("pickLoc").build();
|
||||||
assertEquals("pickLoc",s.getPickupLocationId());
|
assertEquals("pickLoc",s.getPickupLocationId());
|
||||||
|
assertEquals("pickLoc",s.getPickupLocation().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
|
|
@ -104,6 +106,8 @@ public class ShipmentTest {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocationId("delLoc").setPickupLocationId("pickLoc").setPickupCoord(Coordinate.newInstance(1, 2)).build();
|
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocationId("delLoc").setPickupLocationId("pickLoc").setPickupCoord(Coordinate.newInstance(1, 2)).build();
|
||||||
assertEquals(1.0,s.getPickupCoord().getX(),0.01);
|
assertEquals(1.0,s.getPickupCoord().getX(),0.01);
|
||||||
assertEquals(2.0,s.getPickupCoord().getY(),0.01);
|
assertEquals(2.0,s.getPickupCoord().getY(),0.01);
|
||||||
|
assertEquals(1.0,s.getPickupLocation().getCoordinate().getX(),0.01);
|
||||||
|
assertEquals(2.0,s.getPickupLocation().getCoordinate().getY(),0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
|
|
@ -116,6 +120,7 @@ public class ShipmentTest {
|
||||||
public void whenDeliveryLocationIdIsSet_itShouldBeDoneCorrectly(){
|
public void whenDeliveryLocationIdIsSet_itShouldBeDoneCorrectly(){
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocationId("delLoc").setPickupLocationId("pickLoc").build();
|
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocationId("delLoc").setPickupLocationId("pickLoc").build();
|
||||||
assertEquals("delLoc",s.getDeliveryLocationId());
|
assertEquals("delLoc",s.getDeliveryLocationId());
|
||||||
|
assertEquals("delLoc",s.getDeliveryLocation().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
|
|
@ -129,6 +134,8 @@ public class ShipmentTest {
|
||||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocationId("delLoc").setPickupLocationId("pickLoc").setDeliveryCoord(Coordinate.newInstance(1, 2)).build();
|
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocationId("delLoc").setPickupLocationId("pickLoc").setDeliveryCoord(Coordinate.newInstance(1, 2)).build();
|
||||||
assertEquals(1.0,s.getDeliveryCoord().getX(),0.01);
|
assertEquals(1.0,s.getDeliveryCoord().getX(),0.01);
|
||||||
assertEquals(2.0,s.getDeliveryCoord().getY(),0.01);
|
assertEquals(2.0,s.getDeliveryCoord().getY(),0.01);
|
||||||
|
assertEquals(1.0,s.getDeliveryLocation().getCoordinate().getX(),0.01);
|
||||||
|
assertEquals(2.0,s.getDeliveryLocation().getCoordinate().getY(),0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=IllegalArgumentException.class)
|
@Test(expected=IllegalArgumentException.class)
|
||||||
|
|
@ -277,4 +284,14 @@ public class ShipmentTest {
|
||||||
.setName("name").build();
|
.setName("name").build();
|
||||||
assertEquals("name",s.getName());
|
assertEquals("name",s.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenSettingLocation_itShouldWork(){
|
||||||
|
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||||
|
.setDeliveryLocation(Location.Builder.newInstance().setId("del").build()).build();
|
||||||
|
assertEquals("loc", s.getPickupLocationId());
|
||||||
|
assertEquals("loc", s.getPickupLocation().getId());
|
||||||
|
assertEquals("del",s.getDeliveryLocation().getId());
|
||||||
|
assertEquals("del",s.getDeliveryLocationId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue