Skip to content

Commit

Permalink
feat: canceling prebooked drt requests (#2930)
Browse files Browse the repository at this point in the history
* drt cancel functionality

* rename StuckPrebookingTest

* rename StuckPrebookingTest

* remove unnecessary condition

* extend testing on complex unscheduler

* transform if to switch

* make thread safe

* restructuring: process booking events directly, rejection separately

* move rejection events to next time step
  • Loading branch information
sebhoerl authored Nov 21, 2023
1 parent 18d5a95 commit 6988e84
Show file tree
Hide file tree
Showing 25 changed files with 2,085 additions and 76 deletions.
5 changes: 5 additions & 0 deletions contribs/drt-extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@
<version>16.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>

</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,14 @@ public void addDropoffRequest(AcceptedDrtRequest request) {
public void addPickupRequest(AcceptedDrtRequest request) {
delegate.addPickupRequest(request);
}

@Override
public void removePickupRequest(Id<Request> requestId) {
delegate.removePickupRequest(requestId);
}

@Override
public void removeDropoffRequest(Id<Request> requestId) {
delegate.removeDropoffRequest(requestId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,14 @@ public void addDropoffRequest(AcceptedDrtRequest request) {
public void addPickupRequest(AcceptedDrtRequest request) {
delegate.addPickupRequest(request);
}

@Override
public void removePickupRequest(Id<Request> requestId) {
delegate.removePickupRequest(requestId);
}

@Override
public void removeDropoffRequest(Id<Request> requestId) {
delegate.removeDropoffRequest(requestId);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package org.matsim.contrib.drt.extension.operations.shifts.schedule;

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

import java.util.Map;

import org.matsim.api.core.v01.Id;
import org.matsim.api.core.v01.network.Link;
import org.matsim.contrib.drt.extension.operations.operationFacilities.OperationFacility;
Expand All @@ -11,10 +15,6 @@
import org.matsim.contrib.dvrp.optimizer.Request;
import org.matsim.contrib.dvrp.schedule.DefaultStayTask;

import java.util.Map;

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

/**
* A task representing stopping and waiting for a new shift.
* @author nkuehnel / MOIA
Expand Down Expand Up @@ -64,5 +64,15 @@ public void addDropoffRequest(AcceptedDrtRequest request) {
public void addPickupRequest(AcceptedDrtRequest request) {
delegate.addPickupRequest(request);
}

@Override
public void removePickupRequest(Id<Request> requestId) {
delegate.removePickupRequest(requestId);
}

@Override
public void removeDropoffRequest(Id<Request> requestId) {
delegate.removeDropoffRequest(requestId);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,11 @@ public void notifyIterationEnds(IterationEndsEvent event) {
.collect(toList());

collection2Text(drtEventSequenceCollector.getRejectedRequestSequences().values(), filename(event, "drt_rejections", ".csv"),
String.join(delimiter, "time", "personId", "requestId", "fromLinkId", "toLinkId", "fromX", "fromY", "toX", "toY"), seq -> {
String.join(delimiter, "time", "personId", "requestId", "fromLinkId", "toLinkId", "fromX", "fromY", "toX", "toY", "cause"), seq -> {
DrtRequestSubmittedEvent submission = seq.getSubmitted();
Coord fromCoord = network.getLinks().get(submission.getFromLinkId()).getToNode().getCoord();
Coord toCoord = network.getLinks().get(submission.getToLinkId()).getToNode().getCoord();
PassengerRequestRejectedEvent rejection = seq.getRejected().get();
return String.join(delimiter, submission.getTime() + "",//
submission.getPersonId() + "",//
submission.getRequestId() + "",//
Expand All @@ -188,7 +189,8 @@ public void notifyIterationEnds(IterationEndsEvent event) {
fromCoord.getX() + "",//
fromCoord.getY() + "",//
toCoord.getX() + "",//
toCoord.getY() + "");
toCoord.getY() + "",//
rejection.getCause());
});

double rejectionRate = (double)drtEventSequenceCollector.getRejectedRequestSequences().size()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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

import org.matsim.contrib.drt.prebooking.abandon.AbandonVoter;
import org.matsim.contrib.drt.schedule.DrtStopTask;
import org.matsim.contrib.drt.schedule.DrtTaskBaseType;
import org.matsim.contrib.drt.stops.PassengerStopDurationProvider;
Expand All @@ -27,12 +28,17 @@ public class PrebookingActionCreator implements VrpAgentLogic.DynActionCreator {
private final VrpAgentLogic.DynActionCreator delegate;
private final PassengerHandler passengerHandler;
private final PassengerStopDurationProvider stopDurationProvider;
private final PrebookingManager prebookingManager;
private final AbandonVoter abandonVoter;

public PrebookingActionCreator(PassengerHandler passengerHandler, VrpAgentLogic.DynActionCreator delegate,
PassengerStopDurationProvider stopDurationProvider) {
PassengerStopDurationProvider stopDurationProvider, PrebookingManager prebookingManager,
AbandonVoter abandonVoter) {
this.delegate = delegate;
this.passengerHandler = passengerHandler;
this.stopDurationProvider = stopDurationProvider;
this.prebookingManager = prebookingManager;
this.abandonVoter = abandonVoter;
}

@Override
Expand All @@ -42,7 +48,8 @@ public DynAction createAction(DynAgent dynAgent, DvrpVehicle vehicle, double now
if (getBaseTypeOrElseThrow(task).equals(DrtTaskBaseType.STOP)) {
DrtStopTask stopTask = (DrtStopTask) task;
return new PrebookingStopActivity(passengerHandler, dynAgent, stopTask, stopTask.getDropoffRequests(),
stopTask.getPickupRequests(), DrtActionCreator.DRT_STOP_NAME, () -> stopTask.getEndTime(), stopDurationProvider, vehicle);
stopTask.getPickupRequests(), DrtActionCreator.DRT_STOP_NAME, () -> stopTask.getEndTime(),
stopDurationProvider, vehicle, prebookingManager, abandonVoter);
}

return delegate.createAction(dynAgent, vehicle, now);
Expand Down
Loading

0 comments on commit 6988e84

Please sign in to comment.