-
Notifications
You must be signed in to change notification settings - Fork 612
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
braktar
committed
Jul 8, 2016
1 parent
b5d31f8
commit ccbed2a
Showing
4 changed files
with
189 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...src/main/java/com/graphhopper/jsprit/core/algorithm/state/UpdateReverseActivityTimes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/******************************************************************************* | ||
* 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 com.graphhopper.jsprit.core.algorithm.state; | ||
|
||
import com.graphhopper.jsprit.core.problem.cost.TransportTime; | ||
import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts; | ||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute; | ||
import com.graphhopper.jsprit.core.problem.solution.route.activity.ReverseActivityVisitor; | ||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity; | ||
import com.graphhopper.jsprit.core.util.ReverseActivityTimeTracker; | ||
import com.graphhopper.jsprit.core.util.ReverseActivityTimeTracker.ReverseActivityPolicy; | ||
|
||
|
||
/** | ||
* Updates arrival and end times of activities. | ||
* <p> | ||
* <p>Note that this modifies arrTime and endTime of each activity in a route. | ||
* | ||
* @author stefan | ||
*/ | ||
public class UpdateReverseActivityTimes implements ReverseActivityVisitor, StateUpdater { | ||
|
||
private ReverseActivityTimeTracker timeTracker; | ||
|
||
private VehicleRoute route; | ||
|
||
public UpdateReverseActivityTimes(TransportTime transportTime, VehicleRoutingActivityCosts activityCosts) { | ||
super(); | ||
timeTracker = new ReverseActivityTimeTracker(transportTime,activityCosts); | ||
} | ||
|
||
public UpdateReverseActivityTimes(TransportTime transportTime, ReverseActivityPolicy activityPolicy, VehicleRoutingActivityCosts activityCosts) { | ||
timeTracker = new ReverseActivityTimeTracker(transportTime, activityPolicy, activityCosts); | ||
} | ||
|
||
@Override | ||
public void begin(VehicleRoute route) { | ||
timeTracker.begin(route); | ||
this.route = route; | ||
} | ||
|
||
@Override | ||
public void visit(TourActivity activity) { | ||
timeTracker.visit(activity); | ||
} | ||
|
||
@Override | ||
public void finish() { | ||
timeTracker.finish(); | ||
route.getStart().setEndTime(timeTracker.getActEndTime()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/ReverseActivityTimeTracker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/******************************************************************************* | ||
* 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 com.graphhopper.jsprit.core.util; | ||
|
||
import com.graphhopper.jsprit.core.problem.cost.TransportTime; | ||
import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts; | ||
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute; | ||
import com.graphhopper.jsprit.core.problem.solution.route.activity.ReverseActivityVisitor; | ||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity; | ||
|
||
public class ReverseActivityTimeTracker implements ReverseActivityVisitor { | ||
|
||
public static enum ReverseActivityPolicy { | ||
|
||
AS_SOON_AS_TIME_WINDOW_OPENS, AS_SOON_AS_ARRIVED | ||
|
||
} | ||
|
||
private final TransportTime transportTime; | ||
|
||
private final VehicleRoutingActivityCosts activityCosts; | ||
|
||
private TourActivity prevAct = null; | ||
|
||
private double startAtPrevAct; | ||
|
||
private VehicleRoute route; | ||
|
||
private boolean beginFirst = false; | ||
|
||
private double actArrTime; | ||
|
||
private double actEndTime; | ||
|
||
private ReverseActivityPolicy activityPolicy = ReverseActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS; | ||
|
||
public ReverseActivityTimeTracker(TransportTime transportTime, VehicleRoutingActivityCosts activityCosts) { | ||
super(); | ||
this.transportTime = transportTime; | ||
this.activityCosts = activityCosts; | ||
} | ||
|
||
public ReverseActivityTimeTracker(TransportTime transportTime, ReverseActivityPolicy activityPolicy, VehicleRoutingActivityCosts activityCosts) { | ||
super(); | ||
this.transportTime = transportTime; | ||
this.activityPolicy = activityPolicy; | ||
this.activityCosts = activityCosts; | ||
} | ||
|
||
public double getActArrTime() { | ||
return actArrTime; | ||
} | ||
|
||
public double getActEndTime() { | ||
return actEndTime; | ||
} | ||
|
||
@Override | ||
public void begin(VehicleRoute route) { | ||
prevAct = route.getEnd(); | ||
startAtPrevAct = prevAct.getArrTime(); | ||
actArrTime = startAtPrevAct; | ||
this.route = route; | ||
beginFirst = true; | ||
} | ||
|
||
@Override | ||
public void visit(TourActivity activity) { | ||
if (!beginFirst) throw new IllegalStateException("never called begin. this however is essential here"); | ||
double transportTime = this.transportTime.getBackwardTransportTime(prevAct.getLocation(), activity.getLocation(), startAtPrevAct, route.getDriver(), route.getVehicle()); | ||
double arrivalTimeAtCurrAct = startAtPrevAct - transportTime; | ||
|
||
actEndTime = arrivalTimeAtCurrAct; | ||
double operationEndTime = arrivalTimeAtCurrAct; | ||
|
||
double operationStartTime = operationEndTime - activityCosts.getActivityDuration(activity,actEndTime,route.getDriver(),route.getVehicle()); | ||
|
||
if (activityPolicy.equals(ReverseActivityPolicy.AS_SOON_AS_TIME_WINDOW_OPENS)) { | ||
actArrTime = Math.min(activity.getTheoreticalLatestOperationStartTime(), operationStartTime); | ||
} else if (activityPolicy.equals(ReverseActivityPolicy.AS_SOON_AS_ARRIVED)) { | ||
actArrTime = actEndTime; | ||
} else operationEndTime = actEndTime; | ||
|
||
prevAct = activity; | ||
startAtPrevAct = actArrTime; | ||
|
||
} | ||
|
||
@Override | ||
public void finish() { | ||
double transportTime = this.transportTime.getBackwardTransportTime(prevAct.getLocation(), route.getStart().getLocation(), startAtPrevAct, route.getDriver(), route.getVehicle()); | ||
double arrivalTimeAtCurrAct = startAtPrevAct - transportTime; | ||
|
||
actArrTime = arrivalTimeAtCurrAct; | ||
actEndTime = arrivalTimeAtCurrAct; | ||
|
||
beginFirst = false; | ||
} | ||
|
||
|
||
} |