Skip to content

Commit

Permalink
Minor updates
Browse files Browse the repository at this point in the history
TODO: the linear stop duration is not in the latest master branch?
  • Loading branch information
luchengqi7 committed Oct 19, 2023
1 parent 037a2a5 commit 67c1316
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 9 deletions.
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;
}
}
}
*/
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));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@

import static org.matsim.contrib.drt.schedule.DrtTaskBaseType.STAY;

public class OnlineAndOfflineDrtOptimizer implements DrtOptimizer {
private final Logger log = LogManager.getLogger(OnlineAndOfflineDrtOptimizer.class);
public class RollingHorizonOfflineDrtOptimizer implements DrtOptimizer {
private final Logger log = LogManager.getLogger(RollingHorizonOfflineDrtOptimizer.class);
private final Network network;
private final TravelTime travelTime;
private final MobsimTimer timer;
Expand Down Expand Up @@ -86,12 +86,12 @@ public class OnlineAndOfflineDrtOptimizer implements DrtOptimizer {
* work with other VRP solver). The spontaneous requests will be inserted to the timetable
* via a simple insertion heuristic* *
*/
public OnlineAndOfflineDrtOptimizer(Network network, TravelTime travelTime, MobsimTimer timer, DrtTaskFactory taskFactory,
EventsManager eventsManager, ScheduleTimingUpdater scheduleTimingUpdater,
TravelDisutility travelDisutility, DrtConfigGroup drtCfg,
Fleet fleet, ForkJoinPool forkJoinPool, VehicleEntry.EntryFactory vehicleEntryFactory,
VrpSolver solver, Population plans,
double horizon, double interval, Population prebookedTrips) {
public RollingHorizonOfflineDrtOptimizer(Network network, TravelTime travelTime, MobsimTimer timer, DrtTaskFactory taskFactory,
EventsManager eventsManager, ScheduleTimingUpdater scheduleTimingUpdater,
TravelDisutility travelDisutility, DrtConfigGroup drtCfg,
Fleet fleet, ForkJoinPool forkJoinPool, VehicleEntry.EntryFactory vehicleEntryFactory,
VrpSolver solver, Population plans,
double horizon, double interval, Population prebookedTrips) {
this.network = network;
this.travelTime = travelTime;
this.timer = timer;
Expand Down Expand Up @@ -300,7 +300,7 @@ private List<GeneralRequest> readRequestsFromTimeBin(double now) {
}
}
prebookedRequests.removeAll(newRequests);
return newRequests.stream().map(OnlineAndOfflineDrtOptimizer::createFromDrtRequest).collect(Collectors.toList());
return newRequests.stream().map(RollingHorizonOfflineDrtOptimizer::createFromDrtRequest).collect(Collectors.toList());
}

private void updateFleetStatus(double now) {
Expand Down

0 comments on commit 67c1316

Please sign in to comment.