Skip to content

Commit

Permalink
Merge branch 'master' into fix_prebooking_abandonment
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuehnel authored Jul 23, 2024
2 parents f55bf93 + 9e934d4 commit aea22bd
Show file tree
Hide file tree
Showing 35 changed files with 789 additions and 227 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@
public class EDrtControlerCreator {

public static Controler createControler(Config config, boolean otfvis) {
MultiModeDrtConfigGroup multiModeDrtConfig = MultiModeDrtConfigGroup.get(config);
DrtConfigs.adjustMultiModeDrtConfig(multiModeDrtConfig, config.scoring(), config.routing());

Scenario scenario = DrtControlerCreator.createScenarioWithDrtRouteFactory(config);
ScenarioUtils.loadScenario(scenario);
return createControler(config, scenario, otfvis);
}
public static Controler createControler(Config config, Scenario scenario, boolean otfvis) {
MultiModeDrtConfigGroup multiModeDrtConfig = MultiModeDrtConfigGroup.get(config);
DrtConfigs.adjustMultiModeDrtConfig(multiModeDrtConfig, config.scoring(), config.routing());

Controler controler = new Controler(scenario);
controler.addOverridingModule(new MultiModeEDrtModule());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.matsim.contrib.drt.extension.operations;

import org.matsim.api.core.v01.Scenario;
import org.matsim.contrib.drt.extension.DrtWithExtensionsConfigGroup;
import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesModeModule;
import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilitiesQSimModule;
Expand Down Expand Up @@ -27,10 +28,25 @@ public class DrtOperationsControlerCreator {
* @return
*/
public static Controler createControler(Config config, boolean otfvis) {
MultiModeDrtConfigGroup multiModeDrtConfig = MultiModeDrtConfigGroup.get(config);

Controler controler = DrtControlerCreator.createControler(config, otfvis);
return prepareController(config, controler);
}

/**
* Creates a controller in one step.
*
* @param config
* @param scenario
* @param otfvis
* @return
*/
public static Controler createControler(Config config, Scenario scenario, boolean otfvis) {
Controler controler = DrtControlerCreator.createControler(config, scenario, otfvis);
return prepareController(config, controler);
}

private static Controler prepareController(Config config, Controler controler) {
MultiModeDrtConfigGroup multiModeDrtConfig = MultiModeDrtConfigGroup.get(config);
for (DrtConfigGroup drtCfg : multiModeDrtConfig.getModalElements()) {
controler.addOverridingModule(new ShiftDrtModeModule(drtCfg));
controler.addOverridingQSimModule(new DrtModeQSimModule(drtCfg, new ShiftDrtModeOptimizerQSimModule(drtCfg)));
Expand All @@ -40,7 +56,6 @@ public static Controler createControler(Config config, boolean otfvis) {
}

controler.configureQSimComponents(DvrpQSimComponents.activateAllModes(multiModeDrtConfig));

return controler;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.matsim.contrib.drt.extension.operations;

import org.matsim.api.core.v01.Scenario;
import org.matsim.contrib.drt.extension.DrtWithExtensionsConfigGroup;
import org.matsim.contrib.drt.extension.edrt.run.EDrtControlerCreator;
import org.matsim.contrib.drt.extension.operations.eshifts.charging.ShiftOperatingVehicleProvider;
Expand All @@ -24,11 +25,19 @@
public class EDrtOperationsControlerCreator {

public static Controler createControler(Config config, boolean otfvis) {

MultiModeDrtConfigGroup multiModeDrtConfig = MultiModeDrtConfigGroup.get(config);

Controler controler = EDrtControlerCreator.createControler(config, otfvis);
prepareController(config, controler);
return controler;
}

public static Controler createControler(Config config, Scenario scenario, boolean otfvis) {
Controler controler = EDrtControlerCreator.createControler(config, scenario, otfvis);
prepareController(config, controler);
return controler;
}

private static void prepareController(Config config, Controler controler) {
MultiModeDrtConfigGroup multiModeDrtConfig = MultiModeDrtConfigGroup.get(config);
for (DrtConfigGroup drtCfg : multiModeDrtConfig.getModalElements()) {
controler.addOverridingModule(new ShiftDrtModeModule(drtCfg));
controler.addOverridingQSimModule(new DrtModeQSimModule(drtCfg, new ShiftDrtModeOptimizerQSimModule(drtCfg)));
Expand All @@ -39,14 +48,11 @@ public static Controler createControler(Config config, boolean otfvis) {
controler.addOverridingModule(new DrtShiftEfficiencyModeModule(drtCfg));
}


controler.addOverridingQSimModule(new AbstractQSimModule() {
@Override
protected void configureQSim() {
this.bind(IdleDischargingHandler.VehicleProvider.class).to(ShiftOperatingVehicleProvider.class);
}
});

return controler;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# DRT Operations

Provides functionality to realistically simulate operational aspects,
designed for, bot not limited to, non-autonomous services.

Initially developed for MOIA GmbH

If used, please cite:

Felix Zwick, Nico Kuehnel, Sebastian Hörl.
Shifts in perspective: Operational aspects in (non-)autonomous
ride-pooling simulations.
Transportation Research Part A: Policy and Practice,
Volume 165, 2022, Pages 300-320.
https://doi.org/10.1016/j.tra.2022.09.001.


## Core features:

- Operation facilities
- (Driver) shifts


The entry point for setting up a simulation are the specific control(l)er creators:
- DrtOperationsControlerCreator
- or
- EDrtOperationsControlerCreator
- in the electric vehicles case

## Operation Facilities
Operation facilities are meant to represent hubs and in-field break locations.
The facilities have a capacity that cannot be exceeded and may be linked to
existing chargers via the id.

(Driver) shifts may only start or end at operation facilities in the default setup.
Vehicles will route to operation facilities to end a shift or for scheduling a break.

Operational facilities may be described with an xml file like this:
```
<facilities>
<facility id="1" linkId="274110" x="4478595" y="5304631" chargerId="1" capacity="20" type="hub">
<chargers>
<charger id="1"/>
<charger id="2"/>
</chargers>
</facility>
</facilities>
```

## Shifts
Shifts define periods in which vehicles may be active serving passengers.
Shifts are dynamically assigned to vehicles.

In autonomous settings, shifts may be used to model up- and down-time and/or cleaning
cycles.

Shifts have a start and end time and can optionally have a break which is defined
by earliest start and latest end as well as a duration. Optionally, as operation
facility id may be defined to control the location of the start/end of the shift.

Shifts may be described in an xml file likes this:
```
<shifts>
<shift id="0" start="14400" end="45000" operationFacilityId="1">
<break earliestStart="28800.0" latestEnd="32400.0" duration="1800.0"/>
</shift>
<shift id="1" start="14400" end="45000" operationFacilityId="1">
<break earliestStart="28800.0" latestEnd="32400.0" duration="1800.0"/>
</shift>
</shifts>
```

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
package org.matsim.contrib.drt.extension.operations.eshifts.dispatcher;

import org.matsim.contrib.drt.extension.operations.eshifts.fleet.EvShiftDvrpVehicle;
import org.matsim.contrib.drt.extension.operations.eshifts.schedule.EDrtWaitForShiftStayTask;
import org.matsim.contrib.drt.extension.operations.eshifts.schedule.EDrtWaitForShiftTask;
import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams;
import org.matsim.contrib.drt.extension.operations.shifts.dispatcher.AssignShiftToVehicleLogic;
import org.matsim.contrib.drt.extension.operations.shifts.fleet.ShiftDvrpVehicle;
Expand Down Expand Up @@ -37,8 +37,8 @@ public boolean canAssignVehicleToShift(ShiftDvrpVehicle vehicle, DrtShift shift)
// no, if charging
if(vehicle.getSchedule().getStatus() == Schedule.ScheduleStatus.STARTED) {
final Task currentTask = vehicle.getSchedule().getCurrentTask();
if (currentTask instanceof EDrtWaitForShiftStayTask) {
if (((EDrtWaitForShiftStayTask) currentTask).getChargingTask() != null) {
if (currentTask instanceof EDrtWaitForShiftTask) {
if (((EDrtWaitForShiftTask) currentTask).getChargingTask() != null) {
if (currentTask.getEndTime() > shift.getStartTime()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.contrib.drt.extension.operations.eshifts.fleet.EvShiftDvrpVehicle;
import org.matsim.contrib.drt.extension.operations.eshifts.schedule.EDrtWaitForShiftStayTask;
import org.matsim.contrib.drt.extension.operations.eshifts.schedule.EDrtWaitForShiftTask;
import org.matsim.contrib.drt.extension.operations.eshifts.scheduler.EShiftTaskScheduler;
import org.matsim.contrib.drt.extension.operations.shifts.config.ShiftsParams;
import org.matsim.contrib.drt.extension.operations.shifts.dispatcher.DrtShiftDispatcher;
import org.matsim.contrib.drt.extension.operations.shifts.fleet.ShiftDvrpVehicle;
import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacilities;
import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacility;
import org.matsim.contrib.drt.extension.operations.shifts.schedule.ShiftBreakTask;
import org.matsim.contrib.drt.extension.operations.shifts.schedule.WaitForShiftStayTask;
import org.matsim.contrib.drt.extension.operations.shifts.schedule.WaitForShiftTask;
import org.matsim.contrib.dvrp.fleet.DvrpVehicle;
import org.matsim.contrib.dvrp.fleet.Fleet;
import org.matsim.contrib.dvrp.schedule.Schedule;
Expand Down Expand Up @@ -96,8 +96,8 @@ private void checkChargingAtHub(double timeStep) {
final ElectricVehicle electricVehicle = eShiftVehicle.getElectricVehicle();
if (electricVehicle.getBattery().getCharge() / electricVehicle.getBattery().getCapacity() < drtShiftParams.chargeAtHubThreshold) {
final Task currentTask = eShiftVehicle.getSchedule().getCurrentTask();
if (currentTask instanceof EDrtWaitForShiftStayTask
&& ((EDrtWaitForShiftStayTask) currentTask).getChargingTask() == null) {
if (currentTask instanceof EDrtWaitForShiftTask
&& ((EDrtWaitForShiftTask) currentTask).getChargingTask() == null) {
Optional<Charger> selectedCharger = chargerIds
.stream()
.map(id -> chargingInfrastructure.getChargers().get(id))
Expand All @@ -122,7 +122,7 @@ private void checkChargingAtHub(double timeStep) {
.calcRemainingEnergyToCharge(electricVehicle);
final double endTime = timeStep + waitTime + chargingTime;
if (endTime < currentTask.getEndTime()) {
shiftTaskScheduler.chargeAtHub((WaitForShiftStayTask) currentTask, eShiftVehicle,
shiftTaskScheduler.chargeAtHub((WaitForShiftTask) currentTask, eShiftVehicle,
electricVehicle, selectedChargerImpl, timeStep, endTime, energy);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
package org.matsim.contrib.drt.extension.operations.eshifts.dispatcher;

import org.matsim.contrib.drt.extension.operations.eshifts.schedule.EDrtWaitForShiftStayTask;
import org.matsim.contrib.drt.extension.operations.eshifts.schedule.EDrtWaitForShiftTask;
import org.matsim.contrib.drt.extension.operations.shifts.dispatcher.DrtShiftDispatcher;
import org.matsim.contrib.drt.extension.operations.shifts.dispatcher.ShiftStartLogic;
import org.matsim.contrib.dvrp.schedule.Schedule;
Expand All @@ -29,9 +29,9 @@ public EDrtShiftStartLogic(ShiftStartLogic delegate) {
public boolean shiftStarts(DrtShiftDispatcher.ShiftEntry shiftEntry) {
Schedule schedule = shiftEntry.vehicle().getSchedule();
Task currentTask = schedule.getCurrentTask();
if (currentTask instanceof EDrtWaitForShiftStayTask) {
if (currentTask instanceof EDrtWaitForShiftTask) {
//check whether vehicle still needs to complete charging task
if(((EDrtWaitForShiftStayTask) currentTask).getChargingTask() == null) {
if(((EDrtWaitForShiftTask) currentTask).getChargingTask() == null) {
return delegate.shiftStarts(shiftEntry);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ drtShiftParams, new EDrtShiftStartLogic(new DefaultShiftStartLogic()),
new EDrtAssignShiftToVehicleLogic(new DefaultAssignShiftToVehicleLogic(drtShiftParams), drtShiftParams)),
getter.getModal(Fleet.class)))).asEagerSingleton();

bindModal(VehicleEntry.EntryFactory.class).toProvider(modalProvider(getter -> new ShiftVehicleDataEntryFactory(new EDrtVehicleDataEntryFactory(0)))).asEagerSingleton();
bindModal(VehicleEntry.EntryFactory.class).toProvider(modalProvider(getter ->
new ShiftVehicleDataEntryFactory(new EDrtVehicleDataEntryFactory(0),
drtShiftParams.considerUpcomingShiftsForInsertion))).asEagerSingleton();

bindModal(DrtTaskFactory.class).toProvider(modalProvider(getter -> new ShiftEDrtTaskFactoryImpl(new EDrtTaskFactoryImpl(), getter.getModal(OperationFacilities.class)))).in(Singleton.class);
bindModal(ShiftDrtTaskFactory.class).toProvider(modalProvider(getter -> ((ShiftDrtTaskFactory) getter.getModal(DrtTaskFactory.class))));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
package org.matsim.contrib.drt.extension.operations.eshifts.schedule;

import org.matsim.api.core.v01.network.Link;
import org.matsim.contrib.drt.extension.operations.shifts.schedule.WaitForShiftTask;
import org.matsim.contrib.evrp.ChargingTask;
import org.matsim.contrib.evrp.ETask;
import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacility;
import org.matsim.contrib.drt.extension.operations.shifts.schedule.WaitForShiftStayTask;

/**
* @author nkuehnel / MOIA
*/
public class EDrtWaitForShiftStayTask extends WaitForShiftStayTask implements ETask {
public class EDrtWaitForShiftTask extends WaitForShiftTask implements ETask {

private final double consumedEnergy;

private final ChargingTask chargingTask;

public EDrtWaitForShiftStayTask(double beginTime, double endTime, Link link,
double consumedEnergy, OperationFacility facility,
ChargingTask chargingTask) {
public EDrtWaitForShiftTask(double beginTime, double endTime, Link link,
double consumedEnergy, OperationFacility facility,
ChargingTask chargingTask) {
super(beginTime, endTime, link, facility);
this.consumedEnergy = consumedEnergy;
this.chargingTask = chargingTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public DynAction createAction(DynAgent dynAgent, DvrpVehicle vehicle, double now
task.initTaskTracker(new OfflineETaskTracker((EvDvrpVehicle) vehicle, timer));
DrtStopTask t = (DrtStopTask) task;
return new ChargingChangeoverActivity(((EDrtShiftChangeoverTaskImpl) task).getChargingTask(), passengerHandler, dynAgent, t, t.getDropoffRequests(), t.getPickupRequests());
} else if (task instanceof EDrtWaitForShiftStayTask && ((EDrtWaitForShiftStayTask) task).getChargingTask() != null) {
} else if (task instanceof EDrtWaitForShiftTask && ((EDrtWaitForShiftTask) task).getChargingTask() != null) {
task.initTaskTracker(new OfflineETaskTracker((EvDvrpVehicle) vehicle, timer));
return new ChargingWaitForShiftActivity(((EDrtWaitForShiftStayTask) task).getChargingTask());
return new ChargingWaitForShiftActivity(((EDrtWaitForShiftTask) task).getChargingTask());
}

DynAction dynAction = delegate.createAction(dynAgent, vehicle, now);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import org.matsim.contrib.drt.extension.operations.shifts.schedule.ShiftBreakTask;
import org.matsim.contrib.drt.extension.operations.shifts.schedule.ShiftChangeOverTask;
import org.matsim.contrib.drt.extension.operations.shifts.schedule.ShiftDrtTaskFactory;
import org.matsim.contrib.drt.extension.operations.shifts.schedule.WaitForShiftStayTask;
import org.matsim.contrib.drt.extension.operations.shifts.schedule.WaitForShiftTask;
import org.matsim.contrib.drt.extension.operations.shifts.shift.DrtShift;
import org.matsim.contrib.drt.extension.operations.shifts.shift.DrtShiftBreak;
import org.matsim.contrib.drt.schedule.DrtDriveTask;
Expand Down Expand Up @@ -69,14 +69,14 @@ public DefaultStayTask createInitialTask(DvrpVehicle vehicle, double beginTime,
} catch (Throwable e) {
throw new RuntimeException(e);
}
WaitForShiftStayTask waitForShiftStayTask = createWaitForShiftStayTask(vehicle, vehicle.getServiceBeginTime(), vehicle.getServiceEndTime(),
WaitForShiftTask waitForShiftTask = createWaitForShiftStayTask(vehicle, vehicle.getServiceBeginTime(), vehicle.getServiceEndTime(),
vehicle.getStartLink(), operationFacility);
boolean success = operationFacility.register(vehicle.getId());
if (!success) {
throw new RuntimeException(String.format("Cannot register vehicle %s at facility %s at start-up. Please check" +
"facility capacity and initial fleet distribution.", vehicle.getId().toString(), operationFacility.getId().toString()));
}
return waitForShiftStayTask;
return waitForShiftTask;
}

@Override
Expand All @@ -92,16 +92,16 @@ public ShiftChangeOverTask createShiftChangeoverTask(DvrpVehicle vehicle, double
}

@Override
public WaitForShiftStayTask createWaitForShiftStayTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link,
OperationFacility facility) {
return new EDrtWaitForShiftStayTask(beginTime, endTime, link, 0, facility, null);
public WaitForShiftTask createWaitForShiftStayTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link,
OperationFacility facility) {
return new EDrtWaitForShiftTask(beginTime, endTime, link, 0, facility, null);
}

public WaitForShiftStayTask createChargingWaitForShiftStayTask(DvrpVehicle vehicle, double beginTime,
double endTime, Link link, OperationFacility facility,
double totalEnergy, Charger charger) {
public WaitForShiftTask createChargingWaitForShiftStayTask(DvrpVehicle vehicle, double beginTime,
double endTime, Link link, OperationFacility facility,
double totalEnergy, Charger charger) {
ChargingTask chargingTask = new ChargingTaskImpl(EDrtChargingTask.TYPE, beginTime, endTime, charger, ((EvDvrpVehicle)vehicle).getElectricVehicle(), totalEnergy);
return new EDrtWaitForShiftStayTask(beginTime, endTime, link, totalEnergy, facility, chargingTask);
return new EDrtWaitForShiftTask(beginTime, endTime, link, totalEnergy, facility, chargingTask);
}

public EDrtShiftBreakTaskImpl createChargingShiftBreakTask(DvrpVehicle vehicle, double beginTime, double endTime, Link link,
Expand Down
Loading

0 comments on commit aea22bd

Please sign in to comment.