Skip to content

Commit

Permalink
set remaining group sets to lists
Browse files Browse the repository at this point in the history
  • Loading branch information
nkuehnel committed Oct 15, 2023
1 parent a267e3e commit bc35740
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.matsim.contrib.drt.extension.operations.shifts.schedule.ShiftBreakTask;
import org.matsim.core.mobsim.framework.MobsimPassengerAgent;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -67,12 +68,12 @@ public void finalizeAction(double now) {
}

@Override
public void notifyPassengersAreReadyForDeparture(Set<MobsimPassengerAgent> passengers, double now) {
public void notifyPassengersAreReadyForDeparture(List<MobsimPassengerAgent> passengers, double now) {
if (!isLastStep(now)) {
return;// pick up only at the end of stop activity
}

var request = getRequestForPassengers(passengers.stream().map(Identifiable::getId).collect(Collectors.toSet()));
var request = getRequestForPassengers(passengers.stream().map(Identifiable::getId).toList());
if (passengerHandler.tryPickUpPassengers(this, driver, request.getId(), now)) {
passengersPickedUp++;
} else {
Expand All @@ -98,7 +99,7 @@ protected void simStep(double now) {
chargingDelegate.doSimStep(now);
}

private AcceptedDrtRequest getRequestForPassengers(Set<Id<Person>> passengerIds) {
private AcceptedDrtRequest getRequestForPassengers(List<Id<Person>> passengerIds) {
return pickupRequests.values().stream()
.filter(r -> r.getPassengerIds().containsAll(passengerIds))
.findAny()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ protected void simStep(double now) {
}

@Override
public void notifyPassengersAreReadyForDeparture(Set<MobsimPassengerAgent> passengers, double now) {
public void notifyPassengersAreReadyForDeparture(List<MobsimPassengerAgent> passengers, double now) {
if (now < endTime.get()) {
return;// pick up only at the end of stop activity
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.matsim.contrib.dvrp.passenger;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -65,16 +66,16 @@ protected void beforeFirstStep(double now) {
}

@Override
public void notifyPassengersAreReadyForDeparture(Set<MobsimPassengerAgent> passengers, double now) {
PassengerRequest request = getRequestForPassenger(passengers.stream().map(Identifiable::getId).collect(Collectors.toSet()));
public void notifyPassengersAreReadyForDeparture(List<MobsimPassengerAgent> passengers, double now) {
PassengerRequest request = getRequestForPassenger(passengers.stream().map(Identifiable::getId).toList());
if (passengerHandler.tryPickUpPassengers(this, driver, request.getId(), now)) {
requestsPickedUp++;
} else {
throw new IllegalStateException("The passenger is not on the link or not available for departure!");
}
}

private PassengerRequest getRequestForPassenger(Set<Id<Person>> passengerIds) {
private PassengerRequest getRequestForPassenger(List<Id<Person>> passengerIds) {
return requests.values()
.stream()
.filter(r -> r.getPassengerIds().containsAll(passengerIds))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private Link getLink(Id<Link> linkId) {
PassengerRequest prebookedRequest = prebookedRequests.get(0);
PassengerPickupActivity awaitingPickup = awaitingPickups.remove(prebookedRequest.getId());
if (awaitingPickup != null) {
awaitingPickup.notifyPassengersAreReadyForDeparture(Collections.singleton(passenger), now);
awaitingPickup.notifyPassengersAreReadyForDeparture(List.of(passenger), now);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
import org.matsim.contrib.dynagent.DynActivity;
import org.matsim.core.mobsim.framework.MobsimPassengerAgent;

import java.util.List;
import java.util.Set;

public interface PassengerPickupActivity extends DynActivity {
void notifyPassengersAreReadyForDeparture(Set<MobsimPassengerAgent> passengers, double now);
void notifyPassengersAreReadyForDeparture(List<MobsimPassengerAgent> passengers, double now);
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface PassengerRequestCreator {
* Prefer stateless implementation, otherwise provide other ways to achieve thread-safety.
*
* @param id request ID
* @param passengerIds set of unique passenger IDs
* @param passengerIds list of unique passenger IDs
* @param route planned route (the required route type depends on the optimizer)
* @param fromLink start location
* @param toLink end location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.matsim.contrib.dynagent.FirstLastSimStepDynActivity;
import org.matsim.core.mobsim.framework.MobsimPassengerAgent;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -57,8 +58,8 @@ protected void beforeFirstStep(double now) {
}

@Override
public void notifyPassengersAreReadyForDeparture(Set<MobsimPassengerAgent> passengers, double now) {
if (request.getPassengerIds().containsAll(passengers.stream().map(Identifiable::getId).collect(Collectors.toSet()))) {
public void notifyPassengersAreReadyForDeparture(List<MobsimPassengerAgent> passengers, double now) {
if (request.getPassengerIds().containsAll(passengers.stream().map(Identifiable::getId).toList())) {
throw new IllegalArgumentException("I am waiting for a different passenger!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public boolean handleDeparture(double now, MobsimAgent agent, Id<Link> fromLinkI
List.of(passenger.getId()), route, getLink(fromLinkId), getLink(toLinkId), now, now);

if (internalPassengerHandling.validateRequest(request, requestValidator, now)) {
Route teleportedRoute = adaptLegRouteForTeleportation(Collections.singleton(passenger), request, now);
Route teleportedRoute = adaptLegRouteForTeleportation(List.of(passenger), request, now);
eventsManager.processEvent(new PassengerPickedUpEvent(now, mode, request.getId(), passenger.getId(), null));
teleportationEngine.handleDeparture(now, passenger, fromLinkId);
teleportedRequests.add(ImmutablePair.of(now + teleportedRoute.getTravelTime().seconds(), request));
Expand All @@ -160,7 +160,7 @@ public boolean handleDeparture(double now, MobsimAgent agent, Id<Link> fromLinkI
return true;
}

private Route adaptLegRouteForTeleportation(Set<MobsimPassengerAgent> passengers, PassengerRequest request, double now) {
private Route adaptLegRouteForTeleportation(List<MobsimPassengerAgent> passengers, PassengerRequest request, double now) {
Route teleportedRoute = teleportedRouteCalculator.calculateRoute(request);

for (MobsimPassengerAgent passenger : passengers) {
Expand Down

0 comments on commit bc35740

Please sign in to comment.