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

remove deprecated methods dealing with old location concept

This commit is contained in:
oblonski 2015-04-22 00:43:53 +02:00
parent 917d5d3d2c
commit b3af33ccf9
22 changed files with 201 additions and 551 deletions

View file

@ -17,8 +17,6 @@
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.
*
@ -50,9 +48,7 @@ public class Delivery extends Service{
* @throws IllegalStateException if neither locationId nor coord is set
*/
public Delivery build(){
if(location == null) {
location = Location.Builder.newInstance().setCoordinate(coord).setId(locationId).build();
}
if(location == null) throw new IllegalStateException("location is missing");
this.setType("delivery");
super.capacity = super.capacityBuilder.build();
super.skills = super.skillBuilder.build();

View file

@ -17,8 +17,6 @@
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.
*
@ -52,9 +50,7 @@ public class Pickup extends Service {
* @throws IllegalStateException if neither locationId nor coordinate has been set
*/
public Pickup build(){
if(location == null) {
location = Location.Builder.newInstance().setCoordinate(coord).setId(locationId).build();
}
if(location == null) throw new IllegalStateException("location is missing");
this.setType("pickup");
super.capacity = super.capacityBuilder.build();
super.skills = super.skillBuilder.build();

View file

@ -99,19 +99,6 @@ public class Service extends AbstractJob {
this.type = name;
return this;
}
/**
* Sets the location-id of this service.
*
* @param locationId the location id of the service
* @return builder
* @deprecated use .setLocation(..) instead
*/
@Deprecated
public Builder setLocationId(String locationId){
this.locationId = locationId;
return this;
}
/**
* Sets location
@ -123,20 +110,7 @@ public class Service extends AbstractJob {
this.location = location;
return this;
}
/**
* Sets the coordinate of this service.
*
* @param coord the coordinate of service
* @return builder
* @deprecated use .setLocation(..) instead and add coordinate ot Location obj
*/
@Deprecated
public Builder setCoord(Coordinate coord){
this.coord = coord;
return this;
}
/**
* Sets the serviceTime of this service.
*
@ -189,9 +163,7 @@ public class Service extends AbstractJob {
* @throws IllegalStateException if neither locationId nor coordinate is set.
*/
public Service build(){
if(location == null) {
location = Location.Builder.newInstance().setCoordinate(coord).setId(locationId).build();
}
if(location == null) throw new IllegalStateException("location is missing");
this.setType("service");
capacity = capacityBuilder.build();
skills = skillBuilder.build();
@ -243,28 +215,6 @@ public class Service extends AbstractJob {
}
/**
* Returns the location-id of this service.
*
* @return String that indicates the location
* @deprecated use .getLocation().getId() instead
*/
@Deprecated
public String getLocationId() {
return location.getId();
}
// public AbstractLocation getLocation()
/**
* Returns the coordinate of this service.
*
* @return {@link Coordinate}
* @deprecated use .getLocation().getCoordinate() instead
*/
@Deprecated
public Coordinate getCoord(){ return location.getCoordinate(); }
/**
* Returns location.
*
* @return location

View file

@ -21,7 +21,7 @@ import jsprit.core.problem.Capacity;
import jsprit.core.problem.Location;
import jsprit.core.problem.Skills;
import jsprit.core.problem.solution.route.activity.TimeWindow;
import jsprit.core.util.Coordinate;
/**
* Shipment is an implementation of Job and consists of a pickup and a delivery of something.
@ -53,16 +53,8 @@ public class Shipment extends AbstractJob{
public static class Builder {
private String id;
private String pickupLocation;
private Coordinate pickupCoord;
private double pickupServiceTime = 0.0;
private String deliveryLocation;
private Coordinate deliveryCoord;
private double deliveryServiceTime = 0.0;
@ -99,22 +91,7 @@ public class Shipment extends AbstractJob{
this.id = id;
}
/**
* Sets pickup-location id.
*
* @param pickupLocationId the location id of shipment's pickup
* @return builder
* @throws IllegalArgumentException if location is null
* @deprecated use .setLocation(..) instead
*/
@Deprecated
public Builder setPickupLocationId(String pickupLocationId){
if(pickupLocationId == null) throw new IllegalArgumentException("location must not be null");
this.pickupLocation = pickupLocationId;
return this;
}
/**
/**
* Sets pickup location.
*
* @param pickupLocation pickup location
@ -125,36 +102,6 @@ public class Shipment extends AbstractJob{
return this;
}
/**
* Sets pickup-location id.
*
* @param pickupLocationId the location id of shipment's pickup
* @return builder
* @throws IllegalArgumentException if location is null
* @deprecated use .setPickupLocationId(locationId) instead
*/
@Deprecated
public Builder setPickupLocation(String pickupLocationId){
if(pickupLocationId == null) throw new IllegalArgumentException("location must not be null");
this.pickupLocation = pickupLocationId;
return this;
}
/**
* Sets pickup-coordinate.
*
* @param pickupCoord the coordinate of shipment's pickup location
* @return builder
* @throws IllegalArgumentException if pickupCoord is null
* @deprecated use .setLocation(..) instead and add coordinate to location obj.
*/
@Deprecated
public Builder setPickupCoord(Coordinate pickupCoord){
if(pickupCoord == null) throw new IllegalArgumentException("coord must not be null");
this.pickupCoord = pickupCoord;
return this;
}
/**
* Sets pickupServiceTime.
*
@ -186,21 +133,6 @@ public class Shipment extends AbstractJob{
return this;
}
/**
* Sets the delivery-location.
*
* @param deliveryLocationId the delivery location id
* @return builder
* @throws IllegalArgumentException if location is null
* @deprecated use .setDeliveryLocation instead
*/
@Deprecated
public Builder setDeliveryLocationId(String deliveryLocationId){
if(deliveryLocationId == null) throw new IllegalArgumentException("delivery location must not be null");
this.deliveryLocation = deliveryLocationId;
return this;
}
/**
* Sets delivery location.
*
@ -212,37 +144,6 @@ public class Shipment extends AbstractJob{
return this;
}
/**
* Sets the delivery-location.
*
* @param deliveryLocation the delivery location id
* @return builder
* @throws IllegalArgumentException if location is null
* @deprecated use .setDeliveryLocationId(deliveryLocationId)
*
*/
@Deprecated
public Builder setDeliveryLocation(String deliveryLocation){
if(deliveryLocation == null) throw new IllegalArgumentException("delivery location must not be null");
this.deliveryLocation = deliveryLocation;
return this;
}
/**
* Sets delivery-coord.
*
* @param deliveryCoord the coordinate of shipment's delivery location
* @return builder
* @throws IllegalArgumentException if coord is null;
* @deprecated use .setDeliveryLocation(..) instead and add coordinate to location obj
*/
@Deprecated
public Builder setDeliveryCoord(Coordinate deliveryCoord){
if(deliveryCoord == null) throw new IllegalArgumentException("coord must not be null");
this.deliveryCoord = deliveryCoord;
return this;
}
/**
* Sets the delivery service-time.
*
@ -297,12 +198,8 @@ public class Shipment extends AbstractJob{
* is set
*/
public Shipment build(){
if(pickupLocation_ == null) {
this.pickupLocation_ = Location.Builder.newInstance().setCoordinate(pickupCoord).setId(pickupLocation).build();
}
if(deliveryLocation_ == null) {
this.deliveryLocation_ = Location.Builder.newInstance().setCoordinate(deliveryCoord).setId(deliveryLocation).build();
}
if(pickupLocation_ == null) throw new IllegalStateException("pickup location is missing");
if(deliveryLocation_ == null) throw new IllegalStateException("delivery location is missing");
capacity = capacityBuilder.build();
skills = skillBuilder.build();
return new Shipment(this);
@ -358,28 +255,6 @@ public class Shipment extends AbstractJob{
return id;
}
/**
* Returns the pickup-location.
*
* @return pickup-location
* @deprecated use .getLocation().getId() instead
*/
@Deprecated
public String getPickupLocationId() {
return pickupLocation_.getId();
}
/**
* Returns the pickup-coordinate.
*
* @return coordinate of the pickup
* @deprecated use .getLocation(..).getCoordinate() instead
*/
@Deprecated
public Coordinate getPickupCoord() {
return pickupLocation_.getCoordinate();
}
public Location getPickupLocation(){ return pickupLocation_; }
/**
@ -393,28 +268,6 @@ public class Shipment extends AbstractJob{
return pickupServiceTime;
}
/**
* Returns delivery-location.
*
* @return delivery-location
* @deprecated use .getLocation().getId() instead
*/
@Deprecated
public String getDeliveryLocationId() {
return deliveryLocation_.getId();
}
/**
* Returns coordinate of the delivery.
*
* @return coordinate of delivery
* @deprecated use .getLocation().getCoordinate() instead
*/
@Deprecated
public Coordinate getDeliveryCoord() {
return deliveryLocation_.getCoordinate();
}
public Location getDeliveryLocation() { return deliveryLocation_; }
/**

View file

@ -20,7 +20,6 @@ import jsprit.core.problem.HasId;
import jsprit.core.problem.HasIndex;
import jsprit.core.problem.Location;
import jsprit.core.problem.Skills;
import jsprit.core.util.Coordinate;
/**
* Basic interface for vehicle-data.
@ -65,37 +64,12 @@ public interface Vehicle extends HasId, HasIndex {
* @return true if isReturnToDepot
*/
public abstract boolean isReturnToDepot();
/**
* Returns the start-locationId of this vehicle.
*/
@Deprecated
public abstract String getStartLocationId();
/**
* Returns the start-locationCoord of this vehicle.
*/
@Deprecated
public abstract Coordinate getStartLocationCoordinate();
public abstract Location getStartLocation();
/**
* Returns the end-locationId of this vehicle.
*
*/
@Deprecated
public abstract String getEndLocationId();
public abstract Location getEndLocation();
public abstract Location getEndLocation();
/**
* Returns the end-locationCoord of this vehicle.
*/
@Deprecated
public abstract Coordinate getEndLocationCoordinate();
public abstract VehicleTypeKey getVehicleTypeIdentifier();
public abstract VehicleTypeKey getVehicleTypeIdentifier();
public abstract Skills getSkills();
}

View file

@ -19,7 +19,6 @@ package jsprit.core.problem.vehicle;
import jsprit.core.problem.AbstractVehicle;
import jsprit.core.problem.Location;
import jsprit.core.problem.Skills;
import jsprit.core.util.Coordinate;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
@ -78,36 +77,16 @@ public class VehicleImpl extends AbstractVehicle{
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;
@ -129,23 +108,11 @@ public class VehicleImpl extends AbstractVehicle{
static final Logger log = LogManager.getLogger(Builder.class.getName());
private String id;
private String locationId;
private Coordinate locationCoord;
private double earliestStart = 0.0;
private double latestArrival = Double.MAX_VALUE;
private String startLocationId;
private Coordinate startLocationCoord;
private String endLocationId;
private Coordinate endLocationCoord;
private boolean returnToDepot = true;
private VehicleType type = VehicleTypeImpl.Builder.newInstance("default").build();
@ -192,36 +159,6 @@ public class VehicleImpl extends AbstractVehicle{
this.returnToDepot = returnToDepot;
return this;
}
/**
* Sets the start-location of this vehicle.
*
* @param startLocationId the location id of vehicle's start
* @return this builder
* @throws IllegalArgumentException if startLocationId is null
* @deprecated use .setStartLocation(..) instead
*/
@Deprecated
public Builder setStartLocationId(String startLocationId){
if(startLocationId == null) throw new IllegalArgumentException("startLocationId cannot be null");
this.startLocationId = startLocationId;
this.locationId = startLocationId;
return this;
}
/**
* Sets the start-coordinate of this vehicle.
*
* @param coord the coordinate of vehicle's start location
* @return this builder
* @deprecated use .setStartLocation(..) instead
*/
@Deprecated
public Builder setStartLocationCoordinate(Coordinate coord){
this.startLocationCoord = coord;
this.locationCoord = coord;
return this;
}
/**
* Sets start location.
@ -232,32 +169,6 @@ public class VehicleImpl extends AbstractVehicle{
this.startLocation = startLocation;
return this;
}
/**
* Sets the end-locationId of this vehicle.
*
* @param endLocationId the location id of vehicle's end
* @return this builder
* @deprecated use .setEndLocation(..) instead
*/
@Deprecated
public Builder setEndLocationId(String endLocationId){
this.endLocationId = endLocationId;
return this;
}
/**
* Sets the end-coordinate of this vehicle.
*
* @param coord the coordinate of vehicle's end location
* @return this builder
* @deprecated use .setEndLocation(..) instead
*/
@Deprecated
public Builder setEndLocationCoordinate(Coordinate coord){
this.endLocationCoord = coord;
return this;
}
public Builder setEndLocation(Location endLocation){
this.endLocation = endLocation;
@ -312,30 +223,12 @@ public class VehicleImpl extends AbstractVehicle{
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 (startLocation != null && endLocation == null && endLocationId == null && endLocationCoord == null) {
if (startLocation != null && endLocation == null) {
endLocation = startLocation;
}
if(startLocation == null && endLocation == null) {
if ((locationId == null && locationCoord == null) && (startLocationId == null && startLocationCoord == null)) {
throw new IllegalStateException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set");
}
if(locationId == null && locationCoord == null) throw new IllegalStateException("locationId and locationCoord is missing.");
if(locationCoord == null) log.warn("locationCoord for vehicle " + id + " is missing.");
if (locationId == null && locationCoord != null) {
locationId = locationCoord.toString();
startLocationId = locationCoord.toString();
}
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.");
}
throw new IllegalStateException("vehicle requires startLocation. but neither locationId nor locationCoord nor startLocationId nor startLocationCoord has been set");
}
skills = skillBuilder.build();
return new VehicleImpl(this);
}
@ -433,36 +326,16 @@ public class VehicleImpl extends AbstractVehicle{
return returnToDepot;
}
@Override
public String getStartLocationId() {
return this.startLocation.getId();
}
@Override
public Coordinate getStartLocationCoordinate() {
return this.startLocation.getCoordinate();
}
@Override
public Location getStartLocation() {
return startLocation;
}
@Override
public String getEndLocationId() {
return this.endLocation.getId();
}
@Override
public Location getEndLocation() {
return endLocation;
}
@Override
public Coordinate getEndLocationCoordinate() {
return this.endLocation.getCoordinate();
}
@Override
public Skills getSkills() {
return skills;

View file

@ -1,24 +0,0 @@
/*******************************************************************************
* Copyright (C) 2013 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.util;
@Deprecated
public interface Neighborhood {
public boolean areNeighbors(String location1, String location2);
}

View file

@ -1,107 +0,0 @@
/*******************************************************************************
* 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.util;
import jsprit.core.problem.job.Service;
import jsprit.core.problem.vehicle.Vehicle;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.*;
@Deprecated
public class NeighborhoodImpl implements Neighborhood{
private static Logger log = LogManager.getLogger(NeighborhoodImpl.class);
private Set<String> neighborsToAll;
private double threshold = Double.MAX_VALUE;
private boolean initialised = false;
public void setThreshold(double threshold) {
this.threshold = threshold;
log.info("set threshold to " + threshold);
}
private Map<String,Set<String>> neighbors;
private Collection<Vehicle> vehicles;
private Collection<Service> services;
public NeighborhoodImpl(Collection<Vehicle> vehicles, Collection<Service> services) {
neighborsToAll = new HashSet<String>();
this.vehicles = vehicles;
this.services = services;
neighbors = new HashMap<String, Set<String>>();
}
private void makeNeighbors() {
for(Service i : services){
Set<String> neigh = new HashSet<String>();
for(Vehicle v : vehicles){
double dist2depot = EuclideanDistanceCalculator.calculateDistance(v.getStartLocationCoordinate(), i.getLocation().getCoordinate());
if(dist2depot <= threshold){
neighborsToAll.add(((Service)i).getLocation().getId());
}
}
for(Service j : services){
double crowFlyDistance = EuclideanDistanceCalculator.calculateDistance(i.getLocation().getCoordinate(), j.getLocation().getCoordinate());
if(crowFlyDistance <= threshold) {
neigh.add(((Service)j).getLocation().getId());
}
}
neighbors.put(((Service)i).getLocation().getId(), neigh);
}
}
private void makeNeighborsToAll(Collection<Vehicle> vehicles) {
for(Vehicle v : vehicles){
neighborsToAll.add(v.getStartLocationId());
}
}
public void initialise(){
log.info("initialise neighboorhood [threshold="+ this.threshold + "]");
makeNeighborsToAll(vehicles);
makeNeighbors();
initialised = true;
}
public boolean areNeighbors(String location1, String location2){
if(!initialised) {
// initialise();
return true;
}
if(neighborsToAll.contains(location1) || neighborsToAll.contains(location2)){
return true;
}
if(neighbors.get(location1).contains(location2)){
return true;
}
return false;
}
@Override
public String toString() {
return "[name=euclideanNeighborhood][threshold="+threshold+"]";
}
}