Skip to content

Commit

Permalink
Merge pull request #6 from moia-oss/master
Browse files Browse the repository at this point in the history
shifts, drt operations and WaitForStopTask
  • Loading branch information
nkuehnel authored Nov 24, 2022
2 parents e154d6c + b9830b5 commit 3b61b3c
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@
import org.matsim.alonso_mora.algorithm.relocation.CbcMpsRelocationSolver;
import org.matsim.alonso_mora.algorithm.relocation.GlpkMpsRelocationSolver;
import org.matsim.alonso_mora.algorithm.relocation.RelocationSolver;
import org.matsim.alonso_mora.scheduling.AlonsoMoraScheduler;
import org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler;
import org.matsim.alonso_mora.scheduling.*;
import org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler.NoopOperationalVoter;
import org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler.OperationalVoter;
import org.matsim.alonso_mora.scheduling.ParallelLeastCostPathCalculator;
import org.matsim.alonso_mora.scheduling.StandardRebalancer;
import org.matsim.alonso_mora.travel_time.*;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.drt.optimizer.DrtOptimizer;
Expand Down Expand Up @@ -308,6 +305,8 @@ protected void configureQSim() {
return new DrtStayTaskEndTimeCalculator((dvrpVehicle, dropOffRequests, pickupRequests) -> drtConfig.stopDuration);
}));

bindModal(AlonsoMoraTaskFactory.class).toInstance(new DefaultAlonsoMoraTaskFactory());

bindModal(AlonsoMoraScheduler.class).toProvider(modalProvider(getter -> {
StayTaskEndTimeCalculator endTimeCalculator = getter.getModal(StayTaskEndTimeCalculator.class);
DrtTaskFactory taskFactory = getter.getModal(DrtTaskFactory.class);
Expand All @@ -320,7 +319,7 @@ protected void configureQSim() {

return new DefaultAlonsoMoraScheduler(taskFactory, drtConfig.stopDuration,
amConfig.getCheckDeterminsticTravelTimes(), amConfig.getRerouteDuringScheduling(), travelTime,
network, endTimeCalculator, router, operationalVoter);
network, endTimeCalculator, router, operationalVoter, getter.getModal(AlonsoMoraTaskFactory.class));
}));

bindModal(OperationalVoter.class).toInstance(new NoopOperationalVoter());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.matsim.alonso_mora.scheduling;

import org.matsim.api.core.v01.network.Link;

/**
* @author mga, nkuehnel / MOIA
*/
public interface AlonsoMoraTaskFactory {


WaitForStopTask createWaitForStopTask(double beginTime, double endTime, Link link);

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ public class DefaultAlonsoMoraScheduler implements AlonsoMoraScheduler {

private final StayTaskEndTimeCalculator endTimeCalculator;

private final AlonsoMoraTaskFactory alonsoMoraTaskFactory;

public DefaultAlonsoMoraScheduler(DrtTaskFactory taskFactory, double stopDuration,
boolean checkDeterminsticTravelTimes, boolean reroutingDuringScheduling, TravelTime travelTime,
Network network, StayTaskEndTimeCalculator endTimeCalculator, LeastCostPathCalculator router,
OperationalVoter operationalVoter) {
boolean checkDeterminsticTravelTimes, boolean reroutingDuringScheduling, TravelTime travelTime,
Network network, StayTaskEndTimeCalculator endTimeCalculator, LeastCostPathCalculator router,
OperationalVoter operationalVoter, AlonsoMoraTaskFactory alonsoMoraTaskFactory) {
this.taskFactory = taskFactory;
this.stopDuration = stopDuration;
this.checkDeterminsticTravelTimes = checkDeterminsticTravelTimes;
Expand All @@ -68,6 +70,7 @@ public DefaultAlonsoMoraScheduler(DrtTaskFactory taskFactory, double stopDuratio
this.travelTime = travelTime;
this.router = router;
this.operationalVoter = operationalVoter;
this.alonsoMoraTaskFactory = alonsoMoraTaskFactory;
}

/**
Expand Down Expand Up @@ -258,7 +261,7 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) {
double expectedStartTime = stop.getRequest().getEarliestPickupTime() - stopDuration;

if (expectedStartTime > currentTask.getEndTime()) {
currentTask = new WaitForStopTask(currentTask.getEndTime(), expectedStartTime, currentLink);
currentTask = alonsoMoraTaskFactory.createWaitForStopTask(currentTask.getEndTime(), expectedStartTime, currentLink);
schedule.addTask(currentTask);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.matsim.alonso_mora.scheduling;

import org.matsim.api.core.v01.network.Link;

/**
* @author mga, nkuehnel / MOIA
*/
public class DefaultAlonsoMoraTaskFactory implements AlonsoMoraTaskFactory {

@Override
public WaitForStopTask createWaitForStopTask(double beginTime, double endTime, Link link) {
return new WaitForStopTask(beginTime, endTime, link);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicleFactory;
import org.matsim.alonso_mora.algorithm.function.DefaultAlonsoMoraFunction.Constraint;
import org.matsim.alonso_mora.scheduling.AlonsoMoraScheduler;
import org.matsim.alonso_mora.scheduling.AlonsoMoraTaskFactory;
import org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler.OperationalVoter;
import org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraTaskFactory;
import org.matsim.alonso_mora.travel_time.TravelTimeEstimator;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.drt.extension.operations.DrtWithOperationsConfigGroup;
Expand Down Expand Up @@ -58,6 +60,8 @@ protected void configureQSim() {
modalProvider((getter) -> new ShiftDrtOptimizer(getter.getModal(AlonsoMoraOptimizer.class),
getter.getModal(DrtShiftDispatcher.class), getter.getModal(ScheduleTimingUpdater.class))));

bindModal(AlonsoMoraTaskFactory.class).toInstance(new DefaultAlonsoMoraTaskFactory());

bindModal(AlonsoMoraScheduler.class).toProvider(modalProvider(getter -> {
StayTaskEndTimeCalculator endTimeCalculator = getter.getModal(StayTaskEndTimeCalculator.class);
DrtTaskFactory taskFactory = getter.getModal(DrtTaskFactory.class);
Expand All @@ -70,7 +74,7 @@ protected void configureQSim() {

return new ShiftAlonsoMoraScheduler(taskFactory, drtConfig.stopDuration,
amConfig.getCheckDeterminsticTravelTimes(), amConfig.getRerouteDuringScheduling(), travelTime,
network, endTimeCalculator, router, operationalVoter);
network, endTimeCalculator, router, operationalVoter, getter.getModal(AlonsoMoraTaskFactory.class));
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.matsim.alonso_mora.algorithm.AlonsoMoraStop.StopType;
import org.matsim.alonso_mora.algorithm.AlonsoMoraVehicle;
import org.matsim.alonso_mora.scheduling.AlonsoMoraScheduler;
import org.matsim.alonso_mora.scheduling.AlonsoMoraTaskFactory;
import org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler;
import org.matsim.alonso_mora.scheduling.WaitForStopTask;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
Expand Down Expand Up @@ -60,10 +62,12 @@ public class ShiftAlonsoMoraScheduler implements AlonsoMoraScheduler {

private final StayTaskEndTimeCalculator endTimeCalculator;

private final AlonsoMoraTaskFactory alonsoMoraTaskFactory;

public ShiftAlonsoMoraScheduler(DrtTaskFactory taskFactory, double stopDuration,
boolean checkDeterminsticTravelTimes, boolean reroutingDuringScheduling, TravelTime travelTime,
Network network, StayTaskEndTimeCalculator endTimeCalculator, LeastCostPathCalculator router,
org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler.OperationalVoter operationalVoter) {
DefaultAlonsoMoraScheduler.OperationalVoter operationalVoter, AlonsoMoraTaskFactory alonsoMoraTaskFactory) {
this.taskFactory = taskFactory;
this.stopDuration = stopDuration;
this.checkDeterminsticTravelTimes = checkDeterminsticTravelTimes;
Expand All @@ -72,6 +76,7 @@ public ShiftAlonsoMoraScheduler(DrtTaskFactory taskFactory, double stopDuration,
this.travelTime = travelTime;
this.router = router;
this.operationalVoter = operationalVoter;
this.alonsoMoraTaskFactory = alonsoMoraTaskFactory;
}

/**
Expand Down Expand Up @@ -262,7 +267,7 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) {
double expectedStartTime = stop.getRequest().getEarliestPickupTime() - stopDuration;

if (expectedStartTime > currentTask.getEndTime()) {
currentTask = new WaitForStopTask(currentTask.getEndTime(), expectedStartTime, currentLink);
currentTask = alonsoMoraTaskFactory.createWaitForStopTask(currentTask.getEndTime(), expectedStartTime, currentLink);
schedule.addTask(currentTask);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.matsim.contrib.drt.extension.operations.DrtOperationsParams;
import org.matsim.contrib.drt.extension.operations.DrtWithOperationsConfigGroup;
import org.matsim.contrib.drt.extension.operations.operationFacilities.*;
import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams;
import org.matsim.contrib.drt.extension.operations.shifts.run.ShiftDrtModeModule;
import org.matsim.contrib.drt.extension.operations.shifts.run.ShiftDrtModeOptimizerQSimModule;
import org.matsim.contrib.drt.extension.operations.shifts.run.ShiftDvrpFleetQsimModule;
Expand Down Expand Up @@ -138,6 +139,12 @@ public void testRunAlonsoMoraWithShifts() {
DrtOperationsParams operationsParams = (DrtOperationsParams) drtConfig.createParameterSet(DrtOperationsParams.SET_NAME);
drtConfig.addParameterSet(operationsParams);

ShiftsParams shiftParams = new ShiftsParams();
OperationFacilitiesParams operationFacilitiesParams = new OperationFacilitiesParams();

operationsParams.addParameterSet(shiftParams);
operationsParams.addParameterSet(operationFacilitiesParams);

// Load scenario
Scenario scenario = ScenarioUtils.createScenario(config);
scenario.getPopulation().getFactory().getRouteFactories().setRouteFactory(DrtRoute.class,
Expand Down Expand Up @@ -213,6 +220,7 @@ public void testRunAlonsoMoraWithShifts() {

for (DrtConfigGroup drtCfg : MultiModeDrtConfigGroup.get(config).getModalElements()) {
controller.addOverridingModule(new ShiftDrtModeModule(drtCfg));
controller.addOverridingQSimModule(new OperationFacilitiesQSimModule(drtCfg));
controller.addOverridingQSimModule(new DrtModeQSimModule(drtCfg, new ShiftDrtModeOptimizerQSimModule(drtCfg)));
controller.addOverridingQSimModule(new ShiftDvrpFleetQsimModule(drtCfg.getMode()));
}
Expand Down

0 comments on commit 3b61b3c

Please sign in to comment.