mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
refine insertion calc
This commit is contained in:
parent
adeceb2640
commit
9717926b8e
5 changed files with 375 additions and 42 deletions
|
|
@ -95,6 +95,7 @@ class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCal
|
|||
double tp_costs_newAct_nextAct = routingCosts.getTransportCost(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double tp_time_newAct_nextAct = routingCosts.getTransportTime(newAct.getLocation(), nextAct.getLocation(), newAct_endTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
double nextAct_arrTime = newAct_endTime + tp_time_newAct_nextAct;
|
||||
double endTime_nextAct_new = CalculationUtils.getActivityEndTime(nextAct_arrTime, nextAct);
|
||||
double act_costs_nextAct = activityCosts.getActivityCost(nextAct, nextAct_arrTime, iFacts.getNewDriver(), iFacts.getNewVehicle());
|
||||
|
||||
if(hasVariableDeparture(iFacts.getNewVehicle())){
|
||||
|
|
@ -110,7 +111,8 @@ class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCal
|
|||
}
|
||||
else{
|
||||
double tp_costs_prevAct_nextAct = routingCosts.getTransportCost(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
double arrTime_nextAct = prevAct.getEndTime() + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
double arrTime_nextAct = depTimeAtPrevAct + routingCosts.getTransportTime(prevAct.getLocation(), nextAct.getLocation(), prevAct.getEndTime(), iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
double endTime_nextAct_old = CalculationUtils.getActivityEndTime(arrTime_nextAct,nextAct);
|
||||
double actCost_nextAct = activityCosts.getActivityCost(nextAct, arrTime_nextAct, iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
if(isStart(prevAct) && hasVariableDeparture(iFacts.getRoute().getVehicle())) {
|
||||
actCost_nextAct = 0;
|
||||
|
|
@ -118,7 +120,12 @@ class LocalActivityInsertionCostsCalculator implements ActivityInsertionCostsCal
|
|||
else if(hasVariableDeparture(iFacts.getRoute().getVehicle())){
|
||||
actCost_nextAct = activityCosts.getActivityCost(nextAct, arrTime_nextAct + slack_time_prev, iFacts.getRoute().getDriver(), iFacts.getRoute().getVehicle());
|
||||
}
|
||||
oldCosts = tp_costs_prevAct_nextAct + solutionCompletenessRatio * activityCostsWeight * actCost_nextAct;
|
||||
double endTimeDelay_nextAct = Math.max(0,endTime_nextAct_new - endTime_nextAct_old);
|
||||
Double futureWaiting = stateManager.getActivityState(nextAct,iFacts.getRoute().getVehicle(),InternalStates.FUTURE_WAITING,Double.class);
|
||||
if(futureWaiting == null) futureWaiting = 0.;
|
||||
double waitingTime_savings_timeUnit = Math.min(futureWaiting,endTimeDelay_nextAct);
|
||||
double waitingTime_savings = waitingTime_savings_timeUnit * iFacts.getRoute().getVehicle().getType().getVehicleCostParams().perWaitingTimeUnit;
|
||||
oldCosts = tp_costs_prevAct_nextAct + solutionCompletenessRatio * activityCostsWeight * ( actCost_nextAct + waitingTime_savings);
|
||||
}
|
||||
return totalCosts - oldCosts;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,4 +46,6 @@ public class InternalStates {
|
|||
public static final StateId WAITING = new StateFactory.StateIdImpl("waiting",11);
|
||||
|
||||
public static final StateId TIME_SLACK = new StateFactory.StateIdImpl("time_slack",12);
|
||||
|
||||
public static final StateId FUTURE_WAITING = new StateFactory.StateIdImpl("future_waiting",13);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,60 @@
|
|||
/*******************************************************************************
|
||||
* 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.algorithm.state;
|
||||
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ReverseActivityVisitor;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
|
||||
/**
|
||||
* Updates and memorizes latest operation start times at activities.
|
||||
*
|
||||
* @author schroeder
|
||||
*
|
||||
*/
|
||||
public class UpdateFutureWaitingTimes implements ReverseActivityVisitor, StateUpdater{
|
||||
|
||||
private StateManager states;
|
||||
|
||||
private VehicleRoute route;
|
||||
|
||||
private VehicleRoutingTransportCosts transportCosts;
|
||||
|
||||
private double futureWaiting;
|
||||
|
||||
public UpdateFutureWaitingTimes(StateManager states, VehicleRoutingTransportCosts tpCosts) {
|
||||
super();
|
||||
this.states = states;
|
||||
this.transportCosts = tpCosts;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
this.route = route;
|
||||
this.futureWaiting = 0.;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(TourActivity activity) {
|
||||
states.putInternalTypedActivityState(activity,route.getVehicle(),InternalStates.FUTURE_WAITING,futureWaiting);
|
||||
futureWaiting += Math.max(activity.getTheoreticalEarliestOperationStartTime() - activity.getArrTime(),0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue