mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
pdp
This commit is contained in:
parent
dfe25738bf
commit
e912979bbb
25 changed files with 30297 additions and 1169 deletions
|
|
@ -34,7 +34,7 @@ import basics.costs.VehicleRoutingTransportCosts;
|
|||
* @author stefan schroeder
|
||||
*
|
||||
*/
|
||||
class AvgJobDistance implements JobDistance {
|
||||
public class AvgJobDistance implements JobDistance {
|
||||
|
||||
private static Logger log = Logger.getLogger(AvgJobDistance.class);
|
||||
|
||||
|
|
|
|||
|
|
@ -137,9 +137,8 @@ final class BestInsertion implements InsertionStrategy{
|
|||
vehicleRoutes.add(newRoute);
|
||||
}
|
||||
}
|
||||
|
||||
// logger.info("insert " + unassignedJob + " pickup@" + bestInsertion.getInsertionData().getPickupInsertionIndex() + " delivery@" + bestInsertion.getInsertionData().getDeliveryInsertionIndex());
|
||||
inserter.insertJob(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
|
||||
|
||||
}
|
||||
insertionsListeners.informInsertionEndsListeners(vehicleRoutes);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,9 +53,11 @@ public class BestInsertionBuilder implements InsertionStrategyBuilder{
|
|||
constraintManager.addConstraint(new HardPickupAndDeliveryLoadRouteLevelConstraint(stateManager));
|
||||
if(vrp.getProblemConstraints().contains(Constraint.DELIVERIES_FIRST)){
|
||||
constraintManager.addConstraint(new HardPickupAndDeliveryBackhaulActivityLevelConstraint(stateManager));
|
||||
constraintManager.addConstraint(new HardPickupAndDeliveryShipmentActivityLevelConstraint(stateManager,true));
|
||||
}
|
||||
else{
|
||||
constraintManager.addConstraint(new HardPickupAndDeliveryActivityLevelConstraint(stateManager));
|
||||
constraintManager.addConstraint(new HardPickupAndDeliveryShipmentActivityLevelConstraint(stateManager,true));
|
||||
}
|
||||
stateManager.addActivityVisitor(new UpdateOccuredDeliveriesAtActivityLevel(stateManager));
|
||||
stateManager.addActivityVisitor(new UpdateFuturePickupsAtActivityLevel(stateManager));
|
||||
|
|
|
|||
263
jsprit-core/src/main/java/algorithms/BestInsertionConc.java
Normal file
263
jsprit-core/src/main/java/algorithms/BestInsertionConc.java
Normal file
|
|
@ -0,0 +1,263 @@
|
|||
/*******************************************************************************
|
||||
* 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 algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorCompletionService;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import util.RandomNumberGeneration;
|
||||
import algorithms.InsertionData.NoInsertionFound;
|
||||
import basics.Job;
|
||||
import basics.algo.InsertionListener;
|
||||
import basics.route.Driver;
|
||||
import basics.route.Vehicle;
|
||||
import basics.route.VehicleRoute;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author stefan schroeder
|
||||
*
|
||||
*/
|
||||
|
||||
final class BestInsertionConc implements InsertionStrategy{
|
||||
|
||||
static class Batch {
|
||||
List<VehicleRoute> routes = new ArrayList<VehicleRoute>();
|
||||
|
||||
}
|
||||
|
||||
class Insertion {
|
||||
|
||||
private final VehicleRoute route;
|
||||
|
||||
private final InsertionData insertionData;
|
||||
|
||||
public Insertion(VehicleRoute vehicleRoute, InsertionData insertionData) {
|
||||
super();
|
||||
this.route = vehicleRoute;
|
||||
this.insertionData = insertionData;
|
||||
}
|
||||
|
||||
public VehicleRoute getRoute() {
|
||||
return route;
|
||||
}
|
||||
|
||||
public InsertionData getInsertionData() {
|
||||
return insertionData;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static Logger logger = Logger.getLogger(BestInsertionConc.class);
|
||||
|
||||
private Random random = RandomNumberGeneration.getRandom();
|
||||
|
||||
private final static double NO_NEW_DEPARTURE_TIME_YET = -12345.12345;
|
||||
|
||||
private final static Vehicle NO_NEW_VEHICLE_YET = null;
|
||||
|
||||
private final static Driver NO_NEW_DRIVER_YET = null;
|
||||
|
||||
private InsertionListeners insertionsListeners;
|
||||
|
||||
private Inserter inserter;
|
||||
|
||||
private JobInsertionCostsCalculator bestInsertionCostCalculator;
|
||||
|
||||
private boolean minVehiclesFirst = false;
|
||||
|
||||
private int nuOfBatches;
|
||||
|
||||
private ExecutorService executor;
|
||||
|
||||
private ExecutorCompletionService<Insertion> completionService;
|
||||
|
||||
public void setRandom(Random random) {
|
||||
this.random = random;
|
||||
}
|
||||
|
||||
public BestInsertionConc(JobInsertionCostsCalculator jobInsertionCalculator, ExecutorService executorService, int nuOfBatches) {
|
||||
super();
|
||||
this.insertionsListeners = new InsertionListeners();
|
||||
this.executor = executorService;
|
||||
this.nuOfBatches = nuOfBatches;
|
||||
inserter = new Inserter(insertionsListeners);
|
||||
bestInsertionCostCalculator = jobInsertionCalculator;
|
||||
completionService = new ExecutorCompletionService<Insertion>(executor);
|
||||
logger.info("initialise " + this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[name=bestInsertion]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insertJobs(Collection<VehicleRoute> vehicleRoutes, Collection<Job> unassignedJobs) {
|
||||
insertionsListeners.informInsertionStarts(vehicleRoutes,unassignedJobs);
|
||||
List<Job> unassignedJobList = new ArrayList<Job>(unassignedJobs);
|
||||
Collections.shuffle(unassignedJobList, random);
|
||||
for(final Job unassignedJob : unassignedJobList){
|
||||
|
||||
|
||||
Insertion bestInsertion = null;
|
||||
double bestInsertionCost = Double.MAX_VALUE;
|
||||
|
||||
List<Batch> batches = distributeRoutes(vehicleRoutes,nuOfBatches);
|
||||
|
||||
for(final Batch batch : batches){
|
||||
completionService.submit(new Callable<Insertion>() {
|
||||
|
||||
@Override
|
||||
public Insertion call() throws Exception {
|
||||
return getBestInsertion(batch,unassignedJob);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
try{
|
||||
for(int i=0;i<batches.size();i++){
|
||||
Future<Insertion> futureIData = completionService.take();
|
||||
Insertion insertion = futureIData.get();
|
||||
if(insertion == null) continue;
|
||||
if(insertion.getInsertionData().getInsertionCost() < bestInsertionCost){
|
||||
bestInsertion = insertion;
|
||||
bestInsertionCost = insertion.getInsertionData().getInsertionCost();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(InterruptedException e){
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
logger.error(e.getCause().toString());
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
|
||||
if(!minVehiclesFirst){
|
||||
VehicleRoute newRoute = VehicleRoute.emptyRoute();
|
||||
InsertionData newIData = bestInsertionCostCalculator.getInsertionData(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost);
|
||||
if(newIData.getInsertionCost() < bestInsertionCost){
|
||||
bestInsertion = new Insertion(newRoute,newIData);
|
||||
bestInsertionCost = newIData.getInsertionCost();
|
||||
vehicleRoutes.add(newRoute);
|
||||
}
|
||||
}
|
||||
if(bestInsertion == null){
|
||||
VehicleRoute newRoute = VehicleRoute.emptyRoute();
|
||||
InsertionData bestI = bestInsertionCostCalculator.getInsertionData(newRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, Double.MAX_VALUE);
|
||||
if(bestI instanceof InsertionData.NoInsertionFound){
|
||||
throw new IllegalStateException(getErrorMsg(unassignedJob));
|
||||
}
|
||||
else{
|
||||
bestInsertion = new Insertion(newRoute,bestI);
|
||||
vehicleRoutes.add(newRoute);
|
||||
}
|
||||
}
|
||||
// logger.info("insert " + unassignedJob + " pickup@" + bestInsertion.getInsertionData().getPickupInsertionIndex() + " delivery@" + bestInsertion.getInsertionData().getDeliveryInsertionIndex());
|
||||
inserter.insertJob(unassignedJob, bestInsertion.getInsertionData(), bestInsertion.getRoute());
|
||||
}
|
||||
insertionsListeners.informInsertionEndsListeners(vehicleRoutes);
|
||||
}
|
||||
|
||||
private String getErrorMsg(Job unassignedJob) {
|
||||
return "given the vehicles, could not insert job\n" +
|
||||
"\t" + unassignedJob +
|
||||
"\n\tthis might have the following reasons:\n" +
|
||||
"\t- no vehicle has the capacity to transport the job [check whether there is at least one vehicle that is capable to transport the job]\n" +
|
||||
"\t- the time-window cannot be met, even in a commuter tour the time-window is missed [check whether it is possible to reach the time-window on the shortest path or make hard time-windows soft]\n" +
|
||||
"\t- if you deal with finite vehicles, and the available vehicles are already fully employed, no vehicle can be found anymore to transport the job [add penalty-vehicles]";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(InsertionListener insertionListener) {
|
||||
insertionsListeners.removeListener(insertionListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<InsertionListener> getListeners() {
|
||||
return Collections.unmodifiableCollection(insertionsListeners.getListeners());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(InsertionListener insertionListener) {
|
||||
insertionsListeners.addListener(insertionListener);
|
||||
|
||||
}
|
||||
|
||||
private Insertion getBestInsertion(Batch batch, Job unassignedJob) {
|
||||
Insertion bestInsertion = null;
|
||||
double bestInsertionCost = Double.MAX_VALUE;
|
||||
for(VehicleRoute vehicleRoute : batch.routes){
|
||||
InsertionData iData = bestInsertionCostCalculator.getInsertionData(vehicleRoute, unassignedJob, NO_NEW_VEHICLE_YET, NO_NEW_DEPARTURE_TIME_YET, NO_NEW_DRIVER_YET, bestInsertionCost);
|
||||
if(iData instanceof NoInsertionFound) {
|
||||
continue;
|
||||
}
|
||||
if(iData.getInsertionCost() < bestInsertionCost){
|
||||
bestInsertion = new Insertion(vehicleRoute,iData);
|
||||
bestInsertionCost = iData.getInsertionCost();
|
||||
}
|
||||
}
|
||||
return bestInsertion;
|
||||
}
|
||||
|
||||
private List<Batch> distributeRoutes(Collection<VehicleRoute> vehicleRoutes, int nuOfBatches) {
|
||||
List<Batch> batches = new ArrayList<Batch>();
|
||||
for(int i=0;i<nuOfBatches;i++) batches.add(new Batch());
|
||||
/*
|
||||
* if route.size < nuOfBatches add as much routes as empty batches are available
|
||||
* else add one empty route anyway
|
||||
*/
|
||||
if(vehicleRoutes.size()<nuOfBatches){
|
||||
int nOfNewRoutes = nuOfBatches-vehicleRoutes.size();
|
||||
for(int i=0;i<nOfNewRoutes;i++){
|
||||
vehicleRoutes.add(VehicleRoute.emptyRoute());
|
||||
}
|
||||
}
|
||||
else{
|
||||
vehicleRoutes.add(VehicleRoute.emptyRoute());
|
||||
}
|
||||
/*
|
||||
* distribute routes to batches equally
|
||||
*/
|
||||
int count = 0;
|
||||
for(VehicleRoute route : vehicleRoutes){
|
||||
if(count == nuOfBatches) count=0;
|
||||
batches.get(count).routes.add(route);
|
||||
count++;
|
||||
}
|
||||
return batches;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -19,6 +19,8 @@ package algorithms;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import basics.Service;
|
||||
import basics.Shipment;
|
||||
import basics.VehicleRoutingProblem;
|
||||
import basics.algo.InsertionListener;
|
||||
import basics.algo.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener;
|
||||
|
|
@ -221,11 +223,7 @@ class CalculatorBuilder {
|
|||
private CalculatorPlusListeners createStandardLocal(VehicleRoutingProblem vrp, StateGetter statesManager){
|
||||
if(constraintManager == null) throw new IllegalStateException("constraint-manager is null");
|
||||
|
||||
//<<<<<<< HEAD
|
||||
// ActivityInsertionCostsCalculator defaultCalc = new LocalActivityInsertionCostsCalculator(vrp.getTransportCosts(), vrp.getActivityCosts(), constraintManager);
|
||||
// JobInsertionCalculator standardServiceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), defaultCalc, constraintManager);
|
||||
//
|
||||
//=======
|
||||
|
||||
ActivityInsertionCostsCalculator actInsertionCalc;
|
||||
if(activityInsertionCostCalculator == null){
|
||||
actInsertionCalc = new LocalActivityInsertionCostsCalculator(vrp.getTransportCosts(), vrp.getActivityCosts());
|
||||
|
|
@ -234,10 +232,16 @@ class CalculatorBuilder {
|
|||
actInsertionCalc = activityInsertionCostCalculator;
|
||||
}
|
||||
|
||||
JobInsertionCostsCalculator standardServiceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager, constraintManager);
|
||||
//>>>>>>> refs/remotes/choose_remote_name/relaxAPI
|
||||
((ServiceInsertionCalculator) standardServiceInsertion).setNeighborhood(vrp.getNeighborhood());
|
||||
CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(standardServiceInsertion);
|
||||
ShipmentInsertionCalculator shipmentInsertion = new ShipmentInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager, constraintManager);
|
||||
ServiceInsertionCalculator serviceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager, constraintManager);
|
||||
|
||||
JobCalculatorSwitcher switcher = new JobCalculatorSwitcher();
|
||||
switcher.put(Shipment.class, shipmentInsertion);
|
||||
switcher.put(Service.class, serviceInsertion);
|
||||
|
||||
// JobInsertionCostsCalculator standardServiceInsertion = new ServiceInsertionCalculator(vrp.getTransportCosts(), actInsertionCalc, constraintManager, constraintManager);
|
||||
// ((ServiceInsertionCalculator) standardServiceInsertion).setNeighborhood(vrp.getNeighborhood());
|
||||
CalculatorPlusListeners calcPlusListeners = new CalculatorPlusListeners(switcher);
|
||||
|
||||
return calcPlusListeners;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package algorithms;
|
||||
|
||||
public class ConcurrentVehicleRoutingAlgorithmWrapper {
|
||||
|
||||
|
||||
private int nuOfThreads;
|
||||
|
||||
public ConcurrentVehicleRoutingAlgorithmWrapper(int nuOfThreads) {
|
||||
super();
|
||||
this.nuOfThreads = nuOfThreads;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
package algorithms;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import basics.route.DeliverShipment;
|
||||
import basics.route.PickupShipment;
|
||||
import basics.route.Start;
|
||||
|
|
@ -7,6 +9,8 @@ import basics.route.TourActivity;
|
|||
|
||||
class HardPickupAndDeliveryShipmentActivityLevelConstraint implements HardActivityLevelConstraint {
|
||||
|
||||
private static Logger logger = Logger.getLogger(HardPickupAndDeliveryShipmentActivityLevelConstraint.class);
|
||||
|
||||
private StateManager stateManager;
|
||||
|
||||
private boolean backhaul = false;
|
||||
|
|
@ -24,16 +28,22 @@ class HardPickupAndDeliveryShipmentActivityLevelConstraint implements HardActivi
|
|||
|
||||
@Override
|
||||
public ConstraintsStatus fulfilled(InsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||
// logger.info(prevAct + " - " + newAct + " - " + nextAct);
|
||||
if(!(newAct instanceof PickupShipment) && !(newAct instanceof DeliverShipment)){
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
if(backhaul){
|
||||
// if(newAct instanceof PickupShipment && nextAct instanceof DeliverShipment){ return false; }
|
||||
if(newAct instanceof DeliverShipment && prevAct instanceof PickupShipment){ return ConstraintsStatus.NOT_FULFILLED; }
|
||||
if(newAct instanceof PickupShipment && prevAct instanceof DeliverShipment){
|
||||
// logger.info("NOT_FULFILLED_BREAK");
|
||||
return ConstraintsStatus.NOT_FULFILLED_BREAK; }
|
||||
if(newAct instanceof DeliverShipment && nextAct instanceof PickupShipment){
|
||||
// logger.info("NOT_FULFILLED");
|
||||
return ConstraintsStatus.NOT_FULFILLED; }
|
||||
}
|
||||
int loadAtPrevAct;
|
||||
// int futurePicks;
|
||||
// int pastDeliveries;
|
||||
|
||||
if(prevAct instanceof Start){
|
||||
loadAtPrevAct = (int)stateManager.getRouteState(iFacts.getRoute(), StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
// futurePicks = (int)stateManager.getRouteState(iFacts.getRoute(), StateTypes.LOAD).toDouble();
|
||||
|
|
@ -46,15 +56,18 @@ class HardPickupAndDeliveryShipmentActivityLevelConstraint implements HardActivi
|
|||
}
|
||||
if(newAct instanceof PickupShipment){
|
||||
if(loadAtPrevAct + newAct.getCapacityDemand() > iFacts.getNewVehicle().getCapacity()){
|
||||
// logger.info("NOT_FULFILLED");
|
||||
return ConstraintsStatus.NOT_FULFILLED;
|
||||
}
|
||||
}
|
||||
if(newAct instanceof DeliverShipment){
|
||||
if(loadAtPrevAct + Math.abs(newAct.getCapacityDemand()) > iFacts.getNewVehicle().getCapacity()){
|
||||
// logger.info("NOT_FULFILLED_BREAK");
|
||||
return ConstraintsStatus.NOT_FULFILLED_BREAK;
|
||||
}
|
||||
|
||||
}
|
||||
// logger.info("FULFILLED");
|
||||
return ConstraintsStatus.FULFILLED;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
******************************************************************************/
|
||||
package algorithms;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import algorithms.InsertionData.NoInsertionFound;
|
||||
import basics.Job;
|
||||
import basics.Service;
|
||||
|
|
@ -72,7 +74,7 @@ class Inserter {
|
|||
}
|
||||
|
||||
class ShipmentInsertionHandler implements JobInsertionHandler {
|
||||
|
||||
|
||||
private TourShipmentActivityFactory activityFactory = new DefaultShipmentActivityFactory();
|
||||
|
||||
private JobInsertionHandler delegator = new JobExceptionHandler();
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ import basics.route.TourActivity;
|
|||
* @author stefan
|
||||
*
|
||||
*/
|
||||
class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCalculator{
|
||||
public class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCalculator{
|
||||
|
||||
private VehicleRoutingTransportCosts routingCosts;
|
||||
|
||||
|
|
|
|||
|
|
@ -154,8 +154,9 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
|||
prevAct_deliveryLoop = activities.get(j);
|
||||
}
|
||||
if(!deliverShipmentLoopBroken){ //check insertion between lastAct and endOfTour
|
||||
ActivityInsertionCosts deliveryAIC = calculate(insertionContext,prevAct_deliveryLoop,deliverShipment,end,prevActEndTime_deliveryLoop);
|
||||
if(deliveryAIC != null){
|
||||
ConstraintsStatus deliverShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct_deliveryLoop, deliverShipment, end, prevActEndTime_deliveryLoop);
|
||||
if(deliverShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)){
|
||||
ActivityInsertionCosts deliveryAIC = calculate(insertionContext,prevAct_deliveryLoop,deliverShipment,end,prevActEndTime_deliveryLoop);
|
||||
double totalActivityInsertionCosts = pickupAIC.getAdditionalCosts() + deliveryAIC.getAdditionalCosts();
|
||||
if(totalActivityInsertionCosts < bestCost){
|
||||
bestCost = totalActivityInsertionCosts;
|
||||
|
|
@ -170,19 +171,24 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
|||
prevAct = activities.get(i);
|
||||
}
|
||||
if(!pickupShipmentLoopBroken){ //check insertion of pickupShipment and deliverShipment at just before tour ended
|
||||
ActivityInsertionCosts pickupAIC = calculate(insertionContext,prevAct,pickupShipment,end,prevActEndTime);
|
||||
if(pickupAIC != null){ //evaluate delivery
|
||||
ConstraintsStatus pickupShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct, pickupShipment, end, prevActEndTime);
|
||||
if(pickupShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)){
|
||||
ActivityInsertionCosts pickupAIC = calculate(insertionContext,prevAct,pickupShipment,end,prevActEndTime);
|
||||
|
||||
TourActivity prevAct_deliveryLoop = pickupShipment;
|
||||
double shipmentPickupArrTime = prevActEndTime + transportCosts.getTransportTime(prevAct.getLocationId(), pickupShipment.getLocationId(), prevActEndTime, newDriver, newVehicle);
|
||||
double shipmentPickupEndTime = CalculationUtils.getActivityEndTime(shipmentPickupArrTime, pickupShipment);
|
||||
double prevActEndTime_deliveryLoop = shipmentPickupEndTime;
|
||||
|
||||
ActivityInsertionCosts deliveryAIC = calculate(insertionContext,prevAct_deliveryLoop,deliverShipment,end,prevActEndTime_deliveryLoop);
|
||||
double totalActivityInsertionCosts = pickupAIC.getAdditionalCosts() + deliveryAIC.getAdditionalCosts();
|
||||
if(totalActivityInsertionCosts < bestCost){
|
||||
bestCost = totalActivityInsertionCosts;
|
||||
pickupInsertionIndex = activities.size();
|
||||
deliveryInsertionIndex = activities.size();
|
||||
|
||||
ConstraintsStatus deliverShipmentConstraintStatus = hardActivityLevelConstraint.fulfilled(insertionContext, prevAct_deliveryLoop, deliverShipment, end, prevActEndTime_deliveryLoop);
|
||||
if(deliverShipmentConstraintStatus.equals(ConstraintsStatus.FULFILLED)){
|
||||
ActivityInsertionCosts deliveryAIC = calculate(insertionContext,prevAct_deliveryLoop,deliverShipment,end,prevActEndTime_deliveryLoop);
|
||||
double totalActivityInsertionCosts = pickupAIC.getAdditionalCosts() + deliveryAIC.getAdditionalCosts();
|
||||
if(totalActivityInsertionCosts < bestCost){
|
||||
bestCost = totalActivityInsertionCosts;
|
||||
pickupInsertionIndex = activities.size();
|
||||
deliveryInsertionIndex = activities.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -190,6 +196,7 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
|||
return InsertionData.createEmptyInsertionData();
|
||||
}
|
||||
InsertionData insertionData = new InsertionData(bestCost, pickupInsertionIndex, deliveryInsertionIndex, newVehicle, newDriver);
|
||||
// logger.info("pickupIndex="+pickupInsertionIndex + ";deliveryIndex=" + deliveryInsertionIndex);
|
||||
insertionData.setVehicleDepartureTime(newVehicleDepartureTime);
|
||||
return insertionData;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package algorithms;
|
||||
|
||||
import algorithms.StateManager.StateImpl;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import basics.route.ActivityVisitor;
|
||||
import basics.route.TourActivity;
|
||||
import basics.route.VehicleRoute;
|
||||
|
|
@ -17,6 +18,9 @@ import basics.route.VehicleRoute;
|
|||
*
|
||||
*/
|
||||
class UpdateLoadAtActivityLevel implements ActivityVisitor, StateUpdater {
|
||||
|
||||
private static Logger logger = Logger.getLogger(UpdateLoadAtActivityLevel.class);
|
||||
|
||||
private StateManager stateManager;
|
||||
private int currentLoad = 0;
|
||||
private VehicleRoute route;
|
||||
|
|
@ -48,6 +52,7 @@ class UpdateLoadAtActivityLevel implements ActivityVisitor, StateUpdater {
|
|||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
currentLoad = (int) stateManager.getRouteState(route, StateFactory.LOAD_AT_BEGINNING).toDouble();
|
||||
// logger.info(route + " load@beginning=" + currentLoad);
|
||||
this.route = route;
|
||||
}
|
||||
|
||||
|
|
@ -55,12 +60,14 @@ class UpdateLoadAtActivityLevel implements ActivityVisitor, StateUpdater {
|
|||
public void visit(TourActivity act) {
|
||||
currentLoad += act.getCapacityDemand();
|
||||
stateManager.putActivityState(act, StateFactory.LOAD, StateFactory.createState(currentLoad));
|
||||
// logger.info(act + " load@act=" + currentLoad + " vehcap=" + route.getVehicle().getCapacity());
|
||||
assert currentLoad <= route.getVehicle().getCapacity() : "currentLoad at activity must not be > vehicleCapacity";
|
||||
assert currentLoad >= 0 : "currentLoad at act must not be < 0";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
// logger.info("end of " + route);
|
||||
// stateManager.putRouteState(route, StateFactory., state)
|
||||
currentLoad = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
package algorithms;
|
||||
|
||||
import algorithms.StateManager.StateImpl;
|
||||
import basics.Delivery;
|
||||
import basics.Job;
|
||||
import basics.Pickup;
|
||||
|
|
|
|||
|
|
@ -133,10 +133,6 @@ public class Shipment implements Job{
|
|||
return demand;
|
||||
}
|
||||
|
||||
public int getSize() {
|
||||
return demand;
|
||||
}
|
||||
|
||||
public String getPickupLocation() {
|
||||
return pickupLocation;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -326,6 +326,11 @@ public class VrpXMLReader{
|
|||
}
|
||||
}
|
||||
|
||||
// String pickupTWStart = shipmentConfig.getString("pickup.timeWindows.timeWindow(0).start");
|
||||
// String pickupTWEnd = shipmentConfig.getString("pickup.timeWindows.timeWindow(0).end");
|
||||
// TimeWindow pickupTW = TimeWindow.newInstance(Double.parseDouble(pickupTWStart), Double.parseDouble(pickupTWEnd));
|
||||
// builder.setPickupTimeWindow(pickupTW);
|
||||
|
||||
String deliveryLocationId = shipmentConfig.getString("delivery.locationId");
|
||||
builder.setDeliveryLocation(deliveryLocationId);
|
||||
|
||||
|
|
@ -341,6 +346,12 @@ public class VrpXMLReader{
|
|||
builder.setPickupLocation(deliveryCoord.toString());
|
||||
}
|
||||
}
|
||||
|
||||
String delTWStart = shipmentConfig.getString("delivery.timeWindows.timeWindow(0).start");
|
||||
String delTWEnd = shipmentConfig.getString("delivery.timeWindows.timeWindow(0).end");
|
||||
TimeWindow delTW = TimeWindow.newInstance(Double.parseDouble(delTWStart), Double.parseDouble(delTWEnd));
|
||||
builder.setDeliveryTimeWindow(delTW);
|
||||
|
||||
Shipment shipment = builder.build();
|
||||
vrpBuilder.addJob(shipment);
|
||||
shipmentMap .put(shipment.getId(),shipment);
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public final class DeliverShipment implements DeliveryActivity{
|
|||
|
||||
@Override
|
||||
public int getCapacityDemand() {
|
||||
return shipment.getSize()*-1;
|
||||
return shipment.getCapacityDemand()*-1;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public final class PickupShipment implements PickupActivity{
|
|||
|
||||
@Override
|
||||
public int getCapacityDemand() {
|
||||
return shipment.getSize();
|
||||
return shipment.getCapacityDemand();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -113,6 +113,10 @@ public class VehicleTypeImpl implements VehicleType {
|
|||
|
||||
private double maxVelocity;
|
||||
|
||||
/**
|
||||
* @deprecated use builder instead
|
||||
*/
|
||||
@Deprecated
|
||||
public static VehicleTypeImpl newInstance(String typeId, int capacity, VehicleTypeImpl.VehicleCostParams para){
|
||||
return new VehicleTypeImpl(typeId, capacity, para);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue