mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
fix bug #131
This commit is contained in:
parent
800e03d48c
commit
f961fa8971
7 changed files with 142 additions and 51 deletions
|
|
@ -1,20 +1,18 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Stefan Schroeder.
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
* 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/>.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package jsprit.core.algorithm;
|
||||
|
||||
|
|
@ -22,9 +20,7 @@ import jsprit.core.algorithm.io.AlgorithmConfig;
|
|||
import jsprit.core.algorithm.io.AlgorithmConfigXmlReader;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.algorithm.state.UpdateActivityTimes;
|
||||
import jsprit.core.algorithm.state.UpdateEndLocationIfRouteIsOpen;
|
||||
import jsprit.core.algorithm.state.UpdateVariableCosts;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.solution.SolutionCostCalculator;
|
||||
|
|
@ -162,8 +158,7 @@ public class VehicleRoutingAlgorithmBuilder {
|
|||
//add core updater
|
||||
stateManager.addStateUpdater(new UpdateEndLocationIfRouteIsOpen());
|
||||
// stateManager.addStateUpdater(new OpenRouteStateVerifier());
|
||||
stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts()));
|
||||
stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager));
|
||||
|
||||
if(addCoreConstraints){
|
||||
constraintManager.addLoadConstraint();
|
||||
constraintManager.addTimeWindowConstraint();
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ import jsprit.core.problem.vehicle.FiniteFleetManagerFactory;
|
|||
import jsprit.core.problem.vehicle.InfiniteFleetManagerFactory;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
import jsprit.core.util.ActivityTimeTracker;
|
||||
import org.apache.commons.configuration.HierarchicalConfiguration;
|
||||
import org.apache.commons.configuration.XMLConfiguration;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
|
@ -546,6 +547,7 @@ public class VehicleRoutingAlgorithms {
|
|||
switchAllowed = Boolean.parseBoolean(switchString);
|
||||
}
|
||||
else switchAllowed = true;
|
||||
ActivityTimeTracker.ActivityPolicy activityPolicy;
|
||||
if(stateManager.timeWindowUpdateIsActivated()){
|
||||
UpdateVehicleDependentPracticalTimeWindows timeWindowUpdater = new UpdateVehicleDependentPracticalTimeWindows(stateManager,vrp.getTransportCosts());
|
||||
timeWindowUpdater.setVehiclesToUpdate(new UpdateVehicleDependentPracticalTimeWindows.VehiclesToUpdate() {
|
||||
|
|
@ -562,7 +564,13 @@ public class VehicleRoutingAlgorithms {
|
|||
|
||||
});
|
||||
stateManager.addStateUpdater(timeWindowUpdater);
|
||||
activityPolicy = ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS;
|
||||
}
|
||||
else{
|
||||
activityPolicy = ActivityTimeTracker.ActivityPolicy.AS_SOON_AS_ARRIVED;
|
||||
}
|
||||
stateManager.addStateUpdater(new UpdateActivityTimes(vrp.getTransportCosts(),activityPolicy));
|
||||
stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager, activityPolicy));
|
||||
|
||||
SolutionCostCalculator costCalculator;
|
||||
if(solutionCostCalculator==null) costCalculator = getDefaultCostCalculator(stateManager);
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Stefan Schroeder.
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
* 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/>.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package jsprit.core.algorithm.state;
|
||||
|
||||
|
|
@ -35,10 +33,12 @@ import jsprit.core.util.ActivityTimeTracker;
|
|||
*/
|
||||
public class UpdateActivityTimes implements ActivityVisitor, StateUpdater{
|
||||
|
||||
private ActivityTimeTracker timeTracker;
|
||||
|
||||
|
||||
private ActivityTimeTracker timeTracker;
|
||||
|
||||
private VehicleRoute route;
|
||||
|
||||
|
||||
/**
|
||||
* Updates arrival and end times of activities.
|
||||
*
|
||||
|
|
@ -48,7 +48,7 @@ public class UpdateActivityTimes implements ActivityVisitor, StateUpdater{
|
|||
* <code>activity.getArrTime()</code> and
|
||||
* <code>activity.getEndTime()</code>
|
||||
*
|
||||
* @author stefan
|
||||
*
|
||||
*
|
||||
*/
|
||||
public UpdateActivityTimes(ForwardTransportTime transportTime) {
|
||||
|
|
@ -56,6 +56,10 @@ public class UpdateActivityTimes implements ActivityVisitor, StateUpdater{
|
|||
timeTracker = new ActivityTimeTracker(transportTime);
|
||||
}
|
||||
|
||||
public UpdateActivityTimes(ForwardTransportTime transportTime, ActivityTimeTracker.ActivityPolicy activityPolicy){
|
||||
timeTracker = new ActivityTimeTracker(transportTime,activityPolicy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
timeTracker.begin(route);
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Stefan Schroeder.
|
||||
*
|
||||
* 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
|
||||
* 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
|
||||
* 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/>.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package jsprit.core.algorithm.state;
|
||||
|
||||
|
|
@ -71,7 +69,14 @@ public class UpdateVariableCosts implements ActivityVisitor,StateUpdater{
|
|||
timeTracker = new ActivityTimeTracker(transportCost);
|
||||
}
|
||||
|
||||
@Override
|
||||
public UpdateVariableCosts(VehicleRoutingActivityCosts activityCosts, VehicleRoutingTransportCosts transportCosts, StateManager stateManager, ActivityTimeTracker.ActivityPolicy activityPolicy) {
|
||||
this.activityCost = activityCosts;
|
||||
this.transportCost = transportCosts;
|
||||
this.states = stateManager;
|
||||
timeTracker = new ActivityTimeTracker(transportCosts, activityPolicy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void begin(VehicleRoute route) {
|
||||
vehicleRoute = route;
|
||||
timeTracker.begin(route);
|
||||
|
|
|
|||
|
|
@ -167,5 +167,6 @@ public class ConstraintManager implements HardActivityConstraint, HardRouteConst
|
|||
public double getCosts(JobInsertionContext iFacts, TourActivity prevAct,TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
|
||||
return softActivityConstraintManager.getCosts(iFacts, prevAct, newAct, nextAct, prevActDepTime);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
* 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.
|
||||
*
|
||||
*
|
||||
* 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/>.
|
||||
******************************************************************************/
|
||||
|
|
@ -23,6 +23,12 @@ import jsprit.core.problem.solution.route.activity.TourActivity;
|
|||
|
||||
public class ActivityTimeTracker implements ActivityVisitor{
|
||||
|
||||
public static enum ActivityPolicy {
|
||||
|
||||
AS_SOON_AS_TIME_WINDOW_OPENS, AS_SOON_AS_ARRIVED
|
||||
|
||||
}
|
||||
|
||||
private ForwardTransportTime transportTime;
|
||||
|
||||
private TourActivity prevAct = null;
|
||||
|
|
@ -36,12 +42,20 @@ public class ActivityTimeTracker implements ActivityVisitor{
|
|||
private double actArrTime;
|
||||
|
||||
private double actEndTime;
|
||||
|
||||
private ActivityPolicy activityPolicy = ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS;
|
||||
|
||||
public ActivityTimeTracker(ForwardTransportTime transportTime) {
|
||||
super();
|
||||
this.transportTime = transportTime;
|
||||
}
|
||||
|
||||
public ActivityTimeTracker(ForwardTransportTime transportTime, ActivityPolicy activityPolicy) {
|
||||
super();
|
||||
this.transportTime = transportTime;
|
||||
this.activityPolicy = activityPolicy;
|
||||
}
|
||||
|
||||
public double getActArrTime(){
|
||||
return actArrTime;
|
||||
}
|
||||
|
|
@ -54,12 +68,9 @@ public class ActivityTimeTracker implements ActivityVisitor{
|
|||
public void begin(VehicleRoute route) {
|
||||
prevAct = route.getStart();
|
||||
startAtPrevAct = prevAct.getEndTime();
|
||||
|
||||
actEndTime = startAtPrevAct;
|
||||
|
||||
this.route = route;
|
||||
|
||||
beginFirst = true;
|
||||
actEndTime = startAtPrevAct;
|
||||
this.route = route;
|
||||
beginFirst = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -69,8 +80,16 @@ public class ActivityTimeTracker implements ActivityVisitor{
|
|||
double arrivalTimeAtCurrAct = startAtPrevAct + transportTime;
|
||||
|
||||
actArrTime = arrivalTimeAtCurrAct;
|
||||
|
||||
double operationStartTime = Math.max(activity.getTheoreticalEarliestOperationStartTime(), arrivalTimeAtCurrAct);
|
||||
double operationStartTime;
|
||||
|
||||
if(activityPolicy.equals(ActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS)){
|
||||
operationStartTime = Math.max(activity.getTheoreticalEarliestOperationStartTime(), arrivalTimeAtCurrAct);
|
||||
}
|
||||
else if(activityPolicy.equals(ActivityPolicy.AS_SOON_AS_ARRIVED)){
|
||||
operationStartTime = actArrTime;
|
||||
}
|
||||
else operationStartTime = actArrTime;
|
||||
|
||||
double operationEndTime = operationStartTime + activity.getOperationTime();
|
||||
|
||||
actEndTime = operationEndTime;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue