Skip to content

Commit 0c9a6c6

Browse files
authored
fix: attributes in legs rather than in interaction activities (#245)
1 parent 3a8b9e7 commit 0c9a6c6

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

core/src/main/java/org/eqasim/core/simulation/modes/feeder_drt/mode_choice/utilities/estimator/DefaultFeederDrtUtilityEstimator.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ public double estimateUtility(Person person, DiscreteModeChoiceTrip trip, List<?
3333
UtilityEstimator ptEstimator = null;
3434
UtilityEstimator drtEstimator = null;
3535

36-
FeederDrtRoutingModule.FeederDrtTripSegmentType nextSegmentType = FeederDrtRoutingModule.FeederDrtTripSegmentType.MAIN;
36+
FeederDrtRoutingModule.FeederDrtTripSegmentType previousSegmentType = null;
3737

3838
for (PlanElement element : elements) {
3939
if (element instanceof Activity stageActivity && stageActivity.getType().equals(stageActivityType)) {
40-
FeederDrtRoutingModule.FeederDrtTripSegmentType previousSegmentType = (FeederDrtRoutingModule.FeederDrtTripSegmentType) stageActivity.getAttributes().getAttribute(FeederDrtRoutingModule.STAGE_ACTIVITY_PREVIOUS_SEGMENT_TYPE_ATTR);
40+
if(previousSegmentType == null) {
41+
throw new IllegalStateException("Encountered Feeder interaction activity before any leg");
42+
}
4143
if(previousSegmentType.equals(FeederDrtRoutingModule.FeederDrtTripSegmentType.MAIN)) {
4244
totalUtility += ptEstimator.estimateUtility(person, trip, currentTrip);
43-
nextSegmentType = FeederDrtRoutingModule.FeederDrtTripSegmentType.DRT;
4445
} else if (previousSegmentType.equals(FeederDrtRoutingModule.FeederDrtTripSegmentType.DRT)) {
4546
totalUtility += drtEstimator.estimateUtility(person, trip, currentTrip);
46-
nextSegmentType = FeederDrtRoutingModule.FeederDrtTripSegmentType.MAIN;
4747
} else {
4848
throw new IllegalStateException(String.format("Unhandled previous segment type %s in trip of person %s", previousSegmentType, person.getId().toString()));
4949
}
@@ -57,14 +57,15 @@ public double estimateUtility(Person person, DiscreteModeChoiceTrip trip, List<?
5757
drtEstimator = this.drtEstimators.get(routingMode);
5858
stageActivityType = routingMode + " interaction";
5959
}
60+
previousSegmentType = (FeederDrtRoutingModule.FeederDrtTripSegmentType) leg.getAttributes().getAttribute(FeederDrtRoutingModule.CURRENT_SEGMENT_TYPE_ATTR);
6061
}
6162
}
6263
}
6364
if(currentTrip.size() > 0) {
6465
if(ptEstimator == null) {
6566
throw new IllegalStateException(String.format("Plan of person %s has no legs", person.getId().toString()));
6667
}
67-
if (nextSegmentType.equals(FeederDrtRoutingModule.FeederDrtTripSegmentType.MAIN)) {
68+
if (previousSegmentType.equals(FeederDrtRoutingModule.FeederDrtTripSegmentType.MAIN)) {
6869
totalUtility += ptEstimator.estimateUtility(person, trip, currentTrip);
6970
} else {
7071
totalUtility += drtEstimator.estimateUtility(person, trip, currentTrip);

core/src/main/java/org/eqasim/core/simulation/modes/feeder_drt/router/FeederDrtRoutingModule.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212

1313
public class FeederDrtRoutingModule implements RoutingModule {
1414

15-
public enum FeederDrtTripSegmentType {MAIN, DRT};
15+
public enum FeederDrtTripSegmentType {MAIN, DRT}
1616

17-
public static final String STAGE_ACTIVITY_PREVIOUS_SEGMENT_TYPE_ATTR = "previousSegmentType";
17+
public static final String CURRENT_SEGMENT_TYPE_ATTR = "currentSegmentType";
1818

1919
private final RoutingModule drtRoutingModule;
2020
private final RoutingModule transitRoutingModule;
@@ -63,11 +63,11 @@ public List<? extends PlanElement> calcRoute(RoutingRequest routingRequest) {
6363
if (element instanceof Leg leg) {
6464
accessTime = Math.max(accessTime, leg.getDepartureTime().seconds());
6565
accessTime += leg.getTravelTime().seconds();
66+
leg.getAttributes().putAttribute(CURRENT_SEGMENT_TYPE_ATTR, FeederDrtTripSegmentType.DRT);
6667
}
6768
}
6869
Activity accessInteractionActivity = populationFactory.createActivityFromLinkId(this.mode + " interaction", accessFacility.getLinkId());
6970
accessInteractionActivity.setMaximumDuration(0);
70-
accessInteractionActivity.getAttributes().putAttribute(STAGE_ACTIVITY_PREVIOUS_SEGMENT_TYPE_ATTR, FeederDrtTripSegmentType.DRT);
7171
intermodalRoute.add(accessInteractionActivity);
7272
}
7373

@@ -79,6 +79,7 @@ public List<? extends PlanElement> calcRoute(RoutingRequest routingRequest) {
7979
if (element instanceof Leg leg) {
8080
egressTime = Math.max(egressTime, leg.getDepartureTime().seconds());
8181
egressTime += leg.getTravelTime().seconds();
82+
leg.getAttributes().putAttribute(CURRENT_SEGMENT_TYPE_ATTR, FeederDrtTripSegmentType.MAIN);
8283
}
8384
}
8485

@@ -90,13 +91,15 @@ public List<? extends PlanElement> calcRoute(RoutingRequest routingRequest) {
9091

9192
// If no valid DRT route is found, we recompute a PT route from the access facility to the trip destination
9293
if (drtRoute == null) {
93-
intermodalRoute.addAll(transitRoutingModule.calcRoute(DefaultRoutingRequest.withoutAttributes(accessFacility, toFacility, accessTime, person)));
94+
ptRoute = new LinkedList<>(transitRoutingModule.calcRoute(DefaultRoutingRequest.withoutAttributes(accessFacility, toFacility, accessTime, person)));
95+
ptRoute.stream().filter(planElement -> planElement instanceof Leg).map(planElement -> (Leg) planElement).forEach(leg -> leg.getAttributes().putAttribute(CURRENT_SEGMENT_TYPE_ATTR, FeederDrtTripSegmentType.MAIN));
96+
intermodalRoute.addAll(ptRoute);
9497
} else {
9598
// Otherwise we add it as an egress to the whole route
9699
intermodalRoute.addAll(ptRoute);
97100
Activity egressInteractionActivity = populationFactory.createActivityFromLinkId(this.mode + " interaction", egressFacility.getLinkId());
98101
egressInteractionActivity.setMaximumDuration(0);
99-
egressInteractionActivity.getAttributes().putAttribute(STAGE_ACTIVITY_PREVIOUS_SEGMENT_TYPE_ATTR, FeederDrtTripSegmentType.MAIN);
102+
drtRoute.stream().filter(planElement -> planElement instanceof Leg).map(planElement -> (Leg) planElement).forEach(leg -> leg.getAttributes().putAttribute(CURRENT_SEGMENT_TYPE_ATTR, FeederDrtTripSegmentType.DRT));
100103
intermodalRoute.add(egressInteractionActivity);
101104
intermodalRoute.addAll(drtRoute);
102105
}

0 commit comments

Comments
 (0)