@@ -1121,7 +1121,7 @@ def get_crowfly_air_pollutants(origin, destination):
1121
1121
1122
1122
def aggregate_journeys (journeys ):
1123
1123
"""
1124
- when building candidates_pool, we should take into count the similarity of journeys, which means, we add a journey
1124
+ when building candidates_pool, we should take into account the similarity of journeys, which means, we add a journey
1125
1125
into the pool only when there are no other "similar" journey already existing in the pool.
1126
1126
1127
1127
the similarity is defined by a tuple of journeys sections.
@@ -1130,20 +1130,29 @@ def aggregate_journeys(journeys):
1130
1130
aggregated_journeys = list ()
1131
1131
remaining_journeys = list ()
1132
1132
1133
+ def to_retain (j ):
1134
+ return j .type in JOURNEY_TYPES_TO_RETAIN or set (j .tags ) & set (JOURNEY_TAGS_TO_RETAIN )
1135
+
1136
+ journeys_to_retain = (j for j in journeys if to_retain (j ))
1137
+ journeys_not_to_retain = (j for j in journeys if not to_retain (j ))
1138
+
1133
1139
# we pick out all journeys that must be kept:
1134
- for j in ( j for j in journeys if j . type in JOURNEY_TYPES_TO_RETAIN ) :
1140
+ for j in journeys_to_retain :
1135
1141
section_id = tuple (_get_section_id (s ) for s in j .sections if s .type in SECTION_TYPES_TO_RETAIN )
1136
1142
aggregated_journeys .append (j )
1137
1143
added_sections_ids .add (section_id )
1138
1144
1139
- for j in ( j for j in journeys if j . type not in JOURNEY_TYPES_TO_RETAIN ) :
1145
+ for j in journeys_not_to_retain :
1140
1146
section_id = tuple (_get_section_id (s ) for s in j .sections if s .type in SECTION_TYPES_TO_RETAIN )
1141
1147
1142
1148
if section_id in added_sections_ids :
1143
1149
remaining_journeys .append (j )
1144
1150
else :
1145
1151
aggregated_journeys .append (j )
1146
1152
added_sections_ids .add (section_id )
1153
+
1154
+ # aggregated_journeys will be passed to culling algorithm,
1155
+ # remaining_journeys are the redundant ones to be removed
1147
1156
return aggregated_journeys , remaining_journeys
1148
1157
1149
1158
0 commit comments