-
Notifications
You must be signed in to change notification settings - Fork 453
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TODO: the linear stop duration is not in the latest master branch?
- Loading branch information
1 parent
037a2a5
commit 67c1316
Showing
3 changed files
with
134 additions
and
9 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
.../java/org/matsim/contrib/drt/extension/preplanned/optimizer/LinearStopDurationModule.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,39 @@ | ||
/* | ||
package org.matsim.contrib.drt.extension.preplanned.optimizer; | ||
import org.matsim.contrib.drt.passenger.DrtRequest; | ||
import org.matsim.contrib.drt.run.DrtConfigGroup; | ||
import org.matsim.contrib.drt.schedule.DrtStopTask; | ||
import org.matsim.contrib.dvrp.fleet.DvrpVehicle; | ||
import org.matsim.contrib.dvrp.run.AbstractDvrpModeModule; | ||
import org.matsim.contrib.drt.optimizer.insertion.IncrementalStopDurationEstimator; | ||
import org.matsim.contrib.drt.schedule.StopDurationEstimator; | ||
public class LinearStopDurationModule extends AbstractDvrpModeModule { | ||
private final DrtConfigGroup drtConfigGroup; | ||
public LinearStopDurationModule(DrtConfigGroup drtConfigGroup) { | ||
super(drtConfigGroup.getMode()); | ||
this.drtConfigGroup = drtConfigGroup; | ||
} | ||
@Override | ||
public void install() { | ||
bindModal(StopDurationEstimator.class).toInstance((vehicle, dropoffRequests, pickupRequests) -> drtConfigGroup.stopDuration * (dropoffRequests.size() + pickupRequests.size())); | ||
bindModal(IncrementalStopDurationEstimator.class).toInstance(new LinearDrtStopDurationEstimator(drtConfigGroup.stopDuration)); | ||
} | ||
public static record LinearDrtStopDurationEstimator( | ||
double fixedStopDuration) implements IncrementalStopDurationEstimator { | ||
@Override | ||
public double calcForPickup(DvrpVehicle vehicle, DrtStopTask stopTask, DrtRequest pickupRequest) { | ||
return fixedStopDuration; | ||
} | ||
@Override | ||
public double calcForDropoff(DvrpVehicle vehicle, DrtStopTask stopTask, DrtRequest dropoffRequest) { | ||
return fixedStopDuration; | ||
} | ||
} | ||
} | ||
*/ |
86 changes: 86 additions & 0 deletions
86
.../extension/preplanned/optimizer/offlineOptimization/RollingHorizonDrtOperationModule.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,86 @@ | ||
package org.matsim.contrib.drt.extension.preplanned.optimizer.offlineOptimization; | ||
|
||
import org.matsim.api.core.v01.network.Network; | ||
import org.matsim.api.core.v01.population.Population; | ||
import org.matsim.contrib.drt.extension.preplanned.optimizer.offlineOptimization.vrpSolver.VrpSolver; | ||
import org.matsim.contrib.drt.extension.preplanned.optimizer.offlineOptimization.vrpSolver.VrpSolverJsprit; | ||
import org.matsim.contrib.drt.extension.preplanned.optimizer.offlineOptimization.vrpSolver.VrpSolverRegretHeuristic; | ||
import org.matsim.contrib.drt.extension.preplanned.optimizer.offlineOptimization.vrpSolver.VrpSolverSeqInsertion; | ||
import org.matsim.contrib.drt.extension.preplanned.optimizer.offlineOptimization.vrpSolver.ruinAndRecreate.VrpSolverRuinAndRecreate; | ||
import org.matsim.contrib.drt.optimizer.DrtOptimizer; | ||
import org.matsim.contrib.drt.optimizer.QSimScopeForkJoinPoolHolder; | ||
import org.matsim.contrib.drt.optimizer.VehicleDataEntryFactoryImpl; | ||
import org.matsim.contrib.drt.optimizer.VehicleEntry; | ||
import org.matsim.contrib.drt.run.DrtConfigGroup; | ||
import org.matsim.contrib.drt.schedule.DrtTaskFactory; | ||
import org.matsim.contrib.dvrp.fleet.Fleet; | ||
import org.matsim.contrib.dvrp.run.AbstractDvrpModeQSimModule; | ||
import org.matsim.contrib.dvrp.schedule.ScheduleTimingUpdater; | ||
import org.matsim.core.api.experimental.events.EventsManager; | ||
import org.matsim.core.mobsim.framework.MobsimTimer; | ||
import org.matsim.core.router.costcalculators.TravelDisutilityFactory; | ||
import org.matsim.core.router.util.TravelTime; | ||
|
||
import java.util.Random; | ||
|
||
public class RollingHorizonDrtOperationModule extends AbstractDvrpModeQSimModule { | ||
private final Population prebookedPlans; | ||
private final DrtConfigGroup drtConfigGroup; | ||
private final double horizon; | ||
private final double interval; | ||
private final int maxIteration; | ||
private final boolean multiThread; | ||
private final long seed; | ||
private final OfflineSolverType offlineSolverType; | ||
|
||
public RollingHorizonDrtOperationModule(Population prebookedPlans, DrtConfigGroup drtConfigGroup, double horizon, | ||
double interval, int maxIterations, boolean multiThread, long seed, OfflineSolverType type) { | ||
super(drtConfigGroup.getMode()); | ||
this.prebookedPlans = prebookedPlans; | ||
this.drtConfigGroup = drtConfigGroup; | ||
this.horizon = horizon; | ||
this.interval = interval; | ||
this.maxIteration = maxIterations; | ||
this.multiThread = multiThread; | ||
this.seed = seed; | ||
this.offlineSolverType = type; | ||
} | ||
|
||
public enum OfflineSolverType {JSPRIT, SEQ_INSERTION, REGRET_INSERTION, RUIN_AND_RECREATE} | ||
|
||
@Override | ||
protected void configureQSim() { | ||
addModalComponent(DrtOptimizer.class, this.modalProvider((getter) -> new RollingHorizonOfflineDrtOptimizer(getter.getModal(Network.class), getter.getModal(TravelTime.class), | ||
getter.get(MobsimTimer.class), getter.getModal(DrtTaskFactory.class), | ||
getter.get(EventsManager.class), getter.getModal(ScheduleTimingUpdater.class), | ||
getter.getModal(TravelDisutilityFactory.class).createTravelDisutility(getter.getModal(TravelTime.class)), | ||
drtConfigGroup, getter.getModal(Fleet.class), | ||
getter.getModal(QSimScopeForkJoinPoolHolder.class).getPool(), | ||
getter.getModal(VehicleEntry.EntryFactory.class), | ||
getter.getModal(VrpSolver.class), | ||
getter.get(Population.class), horizon, interval, prebookedPlans))); | ||
|
||
switch (offlineSolverType) { | ||
case JSPRIT -> bindModal(VrpSolver.class).toProvider(modalProvider( | ||
getter -> new VrpSolverJsprit( | ||
new VrpSolverJsprit.Options(maxIteration, multiThread, new Random(seed)), | ||
drtConfigGroup, getter.getModal(Network.class), getter.getModal(TravelTime.class)))); | ||
case SEQ_INSERTION -> bindModal(VrpSolver.class).toProvider(modalProvider( | ||
getter -> new VrpSolverSeqInsertion( | ||
getter.getModal(Network.class), getter.getModal(TravelTime.class), drtConfigGroup))); | ||
case REGRET_INSERTION -> bindModal(VrpSolver.class).toProvider(modalProvider( | ||
getter -> new VrpSolverRegretHeuristic( | ||
getter.getModal(Network.class), getter.getModal(TravelTime.class), drtConfigGroup))); | ||
case RUIN_AND_RECREATE -> bindModal(VrpSolver.class).toProvider(modalProvider( | ||
getter -> new VrpSolverRuinAndRecreate(maxIteration, | ||
getter.getModal(Network.class), getter.getModal(TravelTime.class), drtConfigGroup, | ||
new Random(seed)))); | ||
default -> throw new RuntimeException("The solver is not implemented!"); | ||
} | ||
|
||
addModalComponent(QSimScopeForkJoinPoolHolder.class, | ||
() -> new QSimScopeForkJoinPoolHolder(drtConfigGroup.numberOfThreads)); | ||
bindModal(VehicleEntry.EntryFactory.class).toInstance(new VehicleDataEntryFactoryImpl(drtConfigGroup)); | ||
|
||
} | ||
} |
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