Skip to content

Commit

Permalink
Merge pull request #3732 from matsim-org/checkRouteAndModeInNetworkCl…
Browse files Browse the repository at this point in the history
…eaner

add check for mode and route consistency to check wether the network …
  • Loading branch information
jfbischoff authored Feb 18, 2025
2 parents a1b8188 + 36b0158 commit 93b15e4
Showing 1 changed file with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -621,16 +621,30 @@ public void run(Person person) {
}
}

// Remove routes that contain now non-existing links
Set<Id<Link>> linkIds = TripStructureUtils.getLegs(plan).stream()
.map(Leg::getRoute)
.filter(r -> r instanceof NetworkRoute)
.map(r -> (NetworkRoute) r)
.flatMap(r -> Stream.concat(Stream.of(r.getStartLinkId(), r.getEndLinkId()), r.getLinkIds().stream()))
.collect(Collectors.toSet());

if (!linkIds.stream().allMatch(l -> network.getLinks().containsKey(l)))
PopulationUtils.resetRoutes(person.getSelectedPlan());
for (Leg leg : TripStructureUtils.getLegs(plan)) {

if (!(leg.getRoute() instanceof NetworkRoute r))
continue;

Stream<Id<Link>> stream = Stream.concat(Stream.of(r.getStartLinkId(), r.getEndLinkId()), r.getLinkIds().stream());

boolean valid = stream.allMatch(l -> {

Link link = network.getLinks().get(l);

// Check if link is present in the network
if (link == null)
return false;

// Check if the link has the needed mode
return link.getAllowedModes().contains(leg.getMode());
});

if (!valid) {
PopulationUtils.resetRoutes(plan);
break;
}
}
}
}

Expand Down

0 comments on commit 93b15e4

Please sign in to comment.