Skip to content

Commit

Permalink
remove WaitForStop task
Browse files Browse the repository at this point in the history
  • Loading branch information
sebhoerl committed Jan 4, 2024
1 parent 48f584e commit 6caa4d2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public class DefaultAlonsoMoraScheduler implements AlonsoMoraScheduler {

private final StayTaskEndTimeCalculator endTimeCalculator;

public DefaultAlonsoMoraScheduler(DrtTaskFactory taskFactory, PassengerStopDurationProvider stopDurationProvider, double vehicleStopDuration,
boolean checkDeterminsticTravelTimes, boolean reroutingDuringScheduling, TravelTime travelTime,
Network network, StayTaskEndTimeCalculator endTimeCalculator, LeastCostPathCalculator router,
OperationalVoter operationalVoter) {
public DefaultAlonsoMoraScheduler(DrtTaskFactory taskFactory, PassengerStopDurationProvider stopDurationProvider,
double vehicleStopDuration, boolean checkDeterminsticTravelTimes, boolean reroutingDuringScheduling,
TravelTime travelTime, Network network, StayTaskEndTimeCalculator endTimeCalculator,
LeastCostPathCalculator router, OperationalVoter operationalVoter) {
this.taskFactory = taskFactory;
this.vehicleStopDuration = vehicleStopDuration;
this.checkDeterminsticTravelTimes = checkDeterminsticTravelTimes;
Expand Down Expand Up @@ -171,10 +171,9 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) {
boolean isStayTask = task instanceof DrtStayTask;
boolean isStopTask = task instanceof DrtStopTask;
boolean isDriveTask = task instanceof DrtDriveTask;
boolean isWaitForStopTask = task instanceof WaitForStopTask;
boolean isOperationalTask = operationalVoter.isOperationalTask(task);

Verify.verify(isStayTask || isStopTask || isDriveTask || isWaitForStopTask || isOperationalTask,
Verify.verify(isStayTask || isStopTask || isDriveTask || isOperationalTask,
"Don't know what to do with this task");
}

Expand Down Expand Up @@ -203,7 +202,7 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) {
} else if (currentTask instanceof StayTask) {
currentLink = ((StayTask) currentTask).getLink();

if (currentTask instanceof DrtStayTask || currentTask instanceof WaitForStopTask) {
if (currentTask instanceof DrtStayTask) {
// If we are currently staying somewhere, end the stay task now
currentTask.setEndTime(now);
}
Expand Down Expand Up @@ -265,18 +264,25 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) {
double earliestStartTime = stop.getRequest().getEarliestPickupTime();

if (earliestStartTime > currentTask.getEndTime()) {
currentTask = new WaitForStopTask(currentTask.getEndTime(), earliestStartTime, currentLink);
schedule.addTask(currentTask);
if (currentTask instanceof DrtStayTask) {
currentTask.setEndTime(earliestStartTime);
} else {
currentTask = taskFactory.createStayTask(dvrpVehicle, currentTask.getEndTime(),
earliestStartTime, currentLink);
schedule.addTask(currentTask);
}
}
}

// Obtain the stop duration
final double passengerStopDuration;

if (stop.getType().equals(StopType.Pickup)) {
passengerStopDuration = stopDurationProvider.calcPickupDuration(dvrpVehicle, stop.getRequest().getDrtRequest());
passengerStopDuration = stopDurationProvider.calcPickupDuration(dvrpVehicle,
stop.getRequest().getDrtRequest());
} else if (stop.getType().equals(StopType.Dropoff)) {
passengerStopDuration = stopDurationProvider.calcDropoffDuration(dvrpVehicle, stop.getRequest().getDrtRequest());
passengerStopDuration = stopDurationProvider.calcDropoffDuration(dvrpVehicle,
stop.getRequest().getDrtRequest());
} else {
throw new IllegalStateException();
}
Expand All @@ -293,7 +299,7 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) {
} else {
// Create a new stop task as we are not at a previously created stop
double stopDuration = Math.max(vehicleStopDuration, passengerStopDuration);

stopTask = taskFactory.createStopTask(dvrpVehicle, currentTask.getEndTime(),
currentTask.getEndTime() + stopDuration, stop.getLink());

Expand All @@ -306,8 +312,9 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) {
if (stop.getType().equals(StopType.Pickup)) {
stopTask.addPickupRequest(stop.getRequest().getAcceptedDrtRequest());
stop.getRequest().setPickupTask(vehicle, stopTask);

double passengerDepartureTime = Math.max(stopTask.getBeginTime(), stop.getRequest().getEarliestPickupTime());

double passengerDepartureTime = Math.max(stopTask.getBeginTime(),
stop.getRequest().getEarliestPickupTime());
double passengerPickupTime = passengerDepartureTime + passengerStopDuration;
stopTask.setEndTime(Math.max(stopTask.getEndTime(), passengerPickupTime));

Expand All @@ -320,7 +327,8 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) {
} else if (stop.getType().equals(StopType.Dropoff)) {
stopTask.addDropoffRequest(stop.getRequest().getAcceptedDrtRequest());
stop.getRequest().setDropoffTask(vehicle, stopTask);
stopTask.setEndTime(Math.max(stopTask.getEndTime(), stopTask.getBeginTime() + passengerStopDuration));
stopTask.setEndTime(
Math.max(stopTask.getEndTime(), stopTask.getBeginTime() + passengerStopDuration));

if (checkDeterminsticTravelTimes) {
Verify.verify(stop.getTime() == stopTask.getBeginTime(),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
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.WaitForStopTask;
import org.matsim.api.core.v01.network.Link;
import org.matsim.api.core.v01.network.Network;
import org.matsim.contrib.drt.extension.operations.shifts.schedule.ShiftBreakTask;
Expand Down Expand Up @@ -66,9 +65,10 @@ public class ShiftAlonsoMoraScheduler implements AlonsoMoraScheduler {

private final StayTaskEndTimeCalculator endTimeCalculator;

public ShiftAlonsoMoraScheduler(DrtTaskFactory taskFactory, PassengerStopDurationProvider stopDurationProvider, double vehicleStopDuration,
boolean checkDeterminsticTravelTimes, boolean reroutingDuringScheduling, TravelTime travelTime,
Network network, StayTaskEndTimeCalculator endTimeCalculator, LeastCostPathCalculator router,
public ShiftAlonsoMoraScheduler(DrtTaskFactory taskFactory, PassengerStopDurationProvider stopDurationProvider,
double vehicleStopDuration, boolean checkDeterminsticTravelTimes, boolean reroutingDuringScheduling,
TravelTime travelTime, Network network, StayTaskEndTimeCalculator endTimeCalculator,
LeastCostPathCalculator router,
org.matsim.alonso_mora.scheduling.DefaultAlonsoMoraScheduler.OperationalVoter operationalVoter) {
this.taskFactory = taskFactory;
this.vehicleStopDuration = vehicleStopDuration;
Expand Down Expand Up @@ -175,10 +175,9 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) {
boolean isStayTask = task instanceof DrtStayTask;
boolean isStopTask = task instanceof DrtStopTask;
boolean isDriveTask = task instanceof DrtDriveTask;
boolean isWaitForStopTask = task instanceof WaitForStopTask;
boolean isOperationalTask = operationalVoter.isOperationalTask(task);

Verify.verify(isStayTask || isStopTask || isDriveTask || isWaitForStopTask || isOperationalTask,
Verify.verify(isStayTask || isStopTask || isDriveTask || isOperationalTask,
"Don't know what to do with this task");
}

Expand Down Expand Up @@ -207,7 +206,7 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) {
} else if (currentTask instanceof StayTask) {
currentLink = ((StayTask) currentTask).getLink();

if (currentTask instanceof DrtStayTask || currentTask instanceof WaitForStopTask) {
if (currentTask instanceof DrtStayTask) {
// If we are currently staying somewhere, end the stay task now
currentTask.setEndTime(now);
}
Expand Down Expand Up @@ -269,18 +268,25 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) {
double earliestStartTime = stop.getRequest().getEarliestPickupTime();

if (earliestStartTime > currentTask.getEndTime()) {
currentTask = new WaitForStopTask(currentTask.getEndTime(), earliestStartTime, currentLink);
schedule.addTask(currentTask);
if (currentTask instanceof DrtStayTask) {
currentTask.setEndTime(earliestStartTime);
} else {
currentTask = taskFactory.createStayTask(dvrpVehicle, currentTask.getEndTime(),
earliestStartTime, currentLink);
schedule.addTask(currentTask);
}
}
}

// Obtain the stop duration
final double passengerStopDuration;

if (stop.getType().equals(StopType.Pickup)) {
passengerStopDuration = stopDurationProvider.calcPickupDuration(dvrpVehicle, stop.getRequest().getDrtRequest());
passengerStopDuration = stopDurationProvider.calcPickupDuration(dvrpVehicle,
stop.getRequest().getDrtRequest());
} else if (stop.getType().equals(StopType.Dropoff)) {
passengerStopDuration = stopDurationProvider.calcDropoffDuration(dvrpVehicle, stop.getRequest().getDrtRequest());
passengerStopDuration = stopDurationProvider.calcDropoffDuration(dvrpVehicle,
stop.getRequest().getDrtRequest());
} else {
throw new IllegalStateException();
}
Expand All @@ -297,7 +303,7 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) {
} else {
// Create a new stop task as we are not at a previously created stop
double stopDuration = Math.max(vehicleStopDuration, passengerStopDuration);

stopTask = taskFactory.createStopTask(dvrpVehicle, currentTask.getEndTime(),
currentTask.getEndTime() + stopDuration, stop.getLink());

Expand All @@ -311,10 +317,11 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) {
stopTask.addPickupRequest(stop.getRequest().getAcceptedDrtRequest());
stop.getRequest().setPickupTask(vehicle, stopTask);

double passengerDepartureTime = Math.max(stopTask.getBeginTime(), stop.getRequest().getEarliestPickupTime());
double passengerDepartureTime = Math.max(stopTask.getBeginTime(),
stop.getRequest().getEarliestPickupTime());
double passengerPickupTime = passengerDepartureTime + passengerStopDuration;
stopTask.setEndTime(Math.max(stopTask.getEndTime(), passengerPickupTime));

if (checkDeterminsticTravelTimes) {
Verify.verify(stop.getTime() == stopTask.getEndTime(),
"Checking for determinstic travel times and found mismatch between expected stop time and scheduled stop time.");
Expand All @@ -324,7 +331,8 @@ public void schedule(AlonsoMoraVehicle vehicle, double now) {
} else if (stop.getType().equals(StopType.Dropoff)) {
stopTask.addDropoffRequest(stop.getRequest().getAcceptedDrtRequest());
stop.getRequest().setDropoffTask(vehicle, stopTask);
stopTask.setEndTime(Math.max(stopTask.getEndTime(), stopTask.getBeginTime() + passengerStopDuration));
stopTask.setEndTime(
Math.max(stopTask.getEndTime(), stopTask.getBeginTime() + passengerStopDuration));

if (checkDeterminsticTravelTimes) {
Verify.verify(stop.getTime() == stopTask.getBeginTime(),
Expand Down

0 comments on commit 6caa4d2

Please sign in to comment.