diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/companions/DrtCompanionRideGenerator.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/companions/DrtCompanionRideGenerator.java index 8f1839b67d6..d6019872aa3 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/companions/DrtCompanionRideGenerator.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/companions/DrtCompanionRideGenerator.java @@ -57,8 +57,8 @@ final class DrtCompanionRideGenerator implements BeforeMobsimListener, AfterMobs private final Scenario scenario; private final String drtMode; private final int maxCapacity; - private final Set> companionAgentIds = new HashSet<>(); + private final Set drtLegs = new HashSet<>(); private WeightedRandomSelection sampler; private final Map, List> passengerGroups = new HashMap<>(); @@ -113,6 +113,7 @@ private void addCompanionAgents() { for (Leg leg : trip.getLegsOnly()) { if (leg.getMode().equals(this.drtMode)) { + this.drtLegs.add(leg); // Initial person travels now in a group Id currentGroupIdentifier = getGroupIdentifier(); DrtCompanionUtils.setPassengerGroupIdentifier(leg, currentGroupIdentifier); @@ -221,6 +222,10 @@ private void removeCompanionAgents() { passengerGroups.clear(); personIdentifierSuffix.set(0); LOG.info("Removed # {} drt companion agents", counter); + + // Remove attribute from legs of initial drt riders + this.drtLegs.stream().forEach(DrtCompanionUtils::removePassengerGroupIdentifier); + this.drtLegs.clear(); } @Override diff --git a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/companions/DrtCompanionUtils.java b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/companions/DrtCompanionUtils.java index cc2f7caed31..8646f201d3a 100644 --- a/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/companions/DrtCompanionUtils.java +++ b/contribs/drt-extensions/src/main/java/org/matsim/contrib/drt/extension/companions/DrtCompanionUtils.java @@ -109,4 +109,9 @@ public static void setPassengerGroupIdentifier(Leg leg, Id