Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: canceling prebooked drt requests #2930

Merged
merged 13 commits into from
Nov 21, 2023
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