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

replace deprecated methods

This commit is contained in:
oblonski 2015-03-09 21:49:30 +01:00
parent db0cdbe310
commit 62e12d5153
23 changed files with 291 additions and 327 deletions

View file

@ -18,6 +18,7 @@ package jsprit.core.algorithm.recreate;
import jsprit.core.algorithm.state.InternalStates;
import jsprit.core.problem.JobActivityFactory;
import jsprit.core.problem.Location;
import jsprit.core.problem.constraint.HardActivityConstraint;
import jsprit.core.problem.constraint.HardActivityConstraint.ConstraintsStatus;
import jsprit.core.problem.constraint.HardRouteConstraint;
@ -38,7 +39,10 @@ import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
@ -127,7 +131,7 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC
/**
* map that memorizes the costs with newVehicle, which is a cost-snapshot at tour-activities.
*/
Map<TourActivity,Double> activity2costWithNewVehicle = new HashMap<TourActivity,Double>();
// Map<TourActivity,Double> activity2costWithNewVehicle = new HashMap<TourActivity,Double>();
/**
* priority queue that stores insertion-data by insertion-costs in ascending order.
@ -197,7 +201,7 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC
* memorize transport and activity costs with new vehicle without inserting k
*/
sumOf_prevCosts_newVehicle += transportCost_prevAct_nextAct_newVehicle + activityCost_nextAct;
activity2costWithNewVehicle.put(nextAct, sumOf_prevCosts_newVehicle);
// activity2costWithNewVehicle.put(nextAct, sumOf_prevCosts_newVehicle);
/**
* departure time at nextAct with new vehicle
@ -284,20 +288,14 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC
insertionData.setVehicleDepartureTime(start.getEndTime());
return insertionData;
}
/**
* initialize start and end of tour.
*
* @param newVehicle
* @param newVehicleDepartureTime
*/
private void initialiseStartAndEnd(final Vehicle newVehicle, double newVehicleDepartureTime) {
if(start == null){
start = new Start(newVehicle.getStartLocation(), newVehicle.getEarliestDeparture(), Double.MAX_VALUE);
start.setEndTime(newVehicleDepartureTime);
}
else{
start.setLocationId(newVehicle.getStartLocationId());
start.setLocation(Location.newInstance(newVehicle.getStartLocation().getId()));
start.setTheoreticalEarliestOperationStartTime(newVehicle.getEarliestDeparture());
start.setTheoreticalLatestOperationStartTime(Double.MAX_VALUE);
start.setEndTime(newVehicleDepartureTime);
@ -307,7 +305,7 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC
end = new End(newVehicle.getEndLocation(), 0.0, newVehicle.getLatestArrival());
}
else{
end.setLocationId(newVehicle.getEndLocationId());
end.setLocation(Location.newInstance(newVehicle.getEndLocation().getId()));
end.setTheoreticalEarliestOperationStartTime(0.0);
end.setTheoreticalLatestOperationStartTime(newVehicle.getLatestArrival());
}
@ -323,10 +321,6 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC
return prevCost;
}
/**
* creates a comparator to sort insertion-data in insertionQueue in ascending order according insertion costs.
* @return
*/
private Comparator<InsertionData> getComparator() {
return new Comparator<InsertionData>() {

View file

@ -365,10 +365,10 @@ public class VehicleRoutingProblem {
if(!vehicleTypes.contains(vehicle.getType())){
vehicleTypes.add(vehicle.getType());
}
String startLocationId = vehicle.getStartLocationId();
tentative_coordinates.put(startLocationId, vehicle.getStartLocationCoordinate());
if(!vehicle.getEndLocationId().equals(startLocationId)){
tentative_coordinates.put(vehicle.getEndLocationId(), vehicle.getEndLocationCoordinate());
String startLocationId = vehicle.getStartLocation().getId();
tentative_coordinates.put(startLocationId, vehicle.getStartLocation().getCoordinate());
if(!vehicle.getEndLocation().getId().equals(startLocationId)){
tentative_coordinates.put(vehicle.getEndLocation().getId(), vehicle.getEndLocation().getCoordinate());
}
return this;
}

View file

@ -52,8 +52,6 @@ public class Delivery extends Service{
public Delivery build(){
if(location == null) {
location = Location.Builder.newInstance().setCoordinate(coord).setId(locationId).build();
// if(coord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not.");
// locationId = coord.toString();
}
this.setType("delivery");
super.capacity = super.capacityBuilder.build();

View file

@ -54,8 +54,6 @@ public class Pickup extends Service {
public Pickup build(){
if(location == null) {
location = Location.Builder.newInstance().setCoordinate(coord).setId(locationId).build();
// if(coord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not.");
// locationId = coord.toString();
}
this.setType("pickup");
super.capacity = super.capacityBuilder.build();

View file

@ -191,11 +191,6 @@ public class Service extends AbstractJob {
public Service build(){
if(location == null) {
location = Location.Builder.newInstance().setCoordinate(coord).setId(locationId).build();
// if (locationId == null) {
// if (coord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not.");
// locationId = coord.toString();
// }
//
}
this.setType("service");
capacity = capacityBuilder.build();

View file

@ -299,13 +299,9 @@ public class Shipment extends AbstractJob{
public Shipment build(){
if(pickupLocation_ == null) {
this.pickupLocation_ = Location.Builder.newInstance().setCoordinate(pickupCoord).setId(pickupLocation).build();
// if(pickupCoord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not.");
// pickupLocation = pickupCoord.toString();
}
if(deliveryLocation_ == null) {
this.deliveryLocation_ = Location.Builder.newInstance().setCoordinate(deliveryCoord).setId(deliveryLocation).build();
// if(deliveryCoord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not.");
// deliveryLocation = deliveryCoord.toString();
}
capacity = capacityBuilder.build();
skills = skillBuilder.build();

View file

@ -19,7 +19,10 @@ package jsprit.core.problem.vehicle;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@ -30,7 +33,7 @@ class InfiniteVehicles implements VehicleFleetManager{
private Map<VehicleTypeKey,Vehicle> types = new HashMap<VehicleTypeKey, Vehicle>();
private List<VehicleTypeKey> sortedTypes = new ArrayList<VehicleTypeKey>();
// private List<VehicleTypeKey> sortedTypes = new ArrayList<VehicleTypeKey>();
public InfiniteVehicles(Collection<Vehicle> vehicles){
extractTypes(vehicles);
@ -44,10 +47,9 @@ class InfiniteVehicles implements VehicleFleetManager{
private void extractTypes(Collection<Vehicle> vehicles) {
for(Vehicle v : vehicles){
VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(),v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills());
VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocation().getId(),v.getEndLocation().getId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills());
types.put(typeKey,v);
sortedTypes.add(typeKey);
// sortedTypes.add(typeKey);
}
}
@ -81,7 +83,7 @@ class InfiniteVehicles implements VehicleFleetManager{
@Override
public Collection<Vehicle> getAvailableVehicles(Vehicle withoutThisType) {
Collection<Vehicle> vehicles = new ArrayList<Vehicle>();
VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocationId(), withoutThisType.getEndLocationId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills());
VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocation().getId(), withoutThisType.getEndLocation().getId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills());
for(VehicleTypeKey key : types.keySet()){
if(!key.equals(thisKey)){
vehicles.add(types.get(key));

View file

@ -28,20 +28,6 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
public VehicleFleetManagerImpl newInstance(Collection<Vehicle> vehicles){
return new VehicleFleetManagerImpl(vehicles);
}
@Deprecated
public static VehicleFleetManager createDefaultFleetManager() {
return new DefaultFleetManager();
}
public static class DefaultFleetManager extends VehicleFleetManagerImpl {
public DefaultFleetManager() {
super(Collections.<Vehicle> emptyList());
}
}
static class TypeContainer {
@ -92,17 +78,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
makeMap();
logger.info("initialise " + this);
}
public VehicleFleetManagerImpl(Collection<Vehicle> vehicles, Collection<Vehicle> lockedVehicles) {
this.vehicles = vehicles;
makeMap();
this.lockedVehicles = new HashSet<Vehicle>();
for(Vehicle v : lockedVehicles){
lock(v);
}
logger.info("initialise " + this);
}
@Override
public String toString() {
return "[name=finiteVehicles]";
@ -120,7 +96,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
if(v.getType() == null){
throw new IllegalStateException("vehicle needs type");
}
VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(), v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills());
VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocation().getId(), v.getEndLocation().getId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills());
if(!typeMapOfAvailableVehicles.containsKey(typeKey)){
typeMapOfAvailableVehicles.put(typeKey, new TypeContainer());
}
@ -129,7 +105,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
}
private void removeVehicle(Vehicle v){
VehicleTypeKey key = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(), v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills());
VehicleTypeKey key = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocation().getId(), v.getEndLocation().getId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills());
if(typeMapOfAvailableVehicles.containsKey(key)){
typeMapOfAvailableVehicles.get(key).remove(v);
}
@ -161,7 +137,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
@Override
public Collection<Vehicle> getAvailableVehicles(Vehicle withoutThisType) {
List<Vehicle> vehicles = new ArrayList<Vehicle>();
VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocationId(), withoutThisType.getEndLocationId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills());
VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocation().getId(), withoutThisType.getEndLocation().getId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills());
for(VehicleTypeKey key : typeMapOfAvailableVehicles.keySet()){
if(key.equals(thisKey)) continue;
if(!typeMapOfAvailableVehicles.get(key).isEmpty()){
@ -225,12 +201,10 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
throw new IllegalStateException("no vehicle must be locked");
}
}
@Deprecated
public int sizeOfLockedVehicles(){
return lockedVehicles.size();
}
}