12
12
13
13
public class FeederDrtRoutingModule implements RoutingModule {
14
14
15
- public enum FeederDrtTripSegmentType {MAIN , DRT };
15
+ public enum FeederDrtTripSegmentType {MAIN , DRT }
16
16
17
- public static final String STAGE_ACTIVITY_PREVIOUS_SEGMENT_TYPE_ATTR = "previousSegmentType " ;
17
+ public static final String CURRENT_SEGMENT_TYPE_ATTR = "currentSegmentType " ;
18
18
19
19
private final RoutingModule drtRoutingModule ;
20
20
private final RoutingModule transitRoutingModule ;
@@ -63,11 +63,11 @@ public List<? extends PlanElement> calcRoute(RoutingRequest routingRequest) {
63
63
if (element instanceof Leg leg ) {
64
64
accessTime = Math .max (accessTime , leg .getDepartureTime ().seconds ());
65
65
accessTime += leg .getTravelTime ().seconds ();
66
+ leg .getAttributes ().putAttribute (CURRENT_SEGMENT_TYPE_ATTR , FeederDrtTripSegmentType .DRT );
66
67
}
67
68
}
68
69
Activity accessInteractionActivity = populationFactory .createActivityFromLinkId (this .mode + " interaction" , accessFacility .getLinkId ());
69
70
accessInteractionActivity .setMaximumDuration (0 );
70
- accessInteractionActivity .getAttributes ().putAttribute (STAGE_ACTIVITY_PREVIOUS_SEGMENT_TYPE_ATTR , FeederDrtTripSegmentType .DRT );
71
71
intermodalRoute .add (accessInteractionActivity );
72
72
}
73
73
@@ -79,6 +79,7 @@ public List<? extends PlanElement> calcRoute(RoutingRequest routingRequest) {
79
79
if (element instanceof Leg leg ) {
80
80
egressTime = Math .max (egressTime , leg .getDepartureTime ().seconds ());
81
81
egressTime += leg .getTravelTime ().seconds ();
82
+ leg .getAttributes ().putAttribute (CURRENT_SEGMENT_TYPE_ATTR , FeederDrtTripSegmentType .MAIN );
82
83
}
83
84
}
84
85
@@ -90,13 +91,15 @@ public List<? extends PlanElement> calcRoute(RoutingRequest routingRequest) {
90
91
91
92
// If no valid DRT route is found, we recompute a PT route from the access facility to the trip destination
92
93
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 );
94
97
} else {
95
98
// Otherwise we add it as an egress to the whole route
96
99
intermodalRoute .addAll (ptRoute );
97
100
Activity egressInteractionActivity = populationFactory .createActivityFromLinkId (this .mode + " interaction" , egressFacility .getLinkId ());
98
101
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 ) );
100
103
intermodalRoute .add (egressInteractionActivity );
101
104
intermodalRoute .addAll (drtRoute );
102
105
}
0 commit comments