1 package org.matsim.core.network.algorithms;
3 import org.apache.logging.log4j.LogManager;
4 import org.apache.logging.log4j.Logger;
14 import java.util.function.Function;
15 import java.util.stream.Collectors;
32 this.modesToRemoveByLinkId = l -> modesToRemoveByLinkId.getOrDefault(l, Set.of());
37 Map<String, Long> modeCountBefore =
countModes(network);
44 Map<String, Long> modeCountAfter =
countModes(network);
55 Set<String> modes = network.
getLinks().values().stream().flatMap(l -> l.getAllowedModes().stream()).collect(Collectors.toSet());
56 for (String mode : modes) {
58 multimodalNetworkCleaner.
run(Set.of(mode));
64 .filter(l -> l.getAllowedModes().isEmpty())
66 .forEach(network::removeLink);
71 .filter(n -> n.getInLinks().isEmpty() && n.getOutLinks().isEmpty())
73 .forEach(network::removeNode);
77 modeCountBefore.forEach((mode, countBefore) -> {
78 long countAfter = modeCountAfter.getOrDefault(mode, 0L);
79 log.info(
"Removed mode {} from {} links.", mode, countBefore - countAfter);
84 return network.
getLinks().values().stream()
85 .flatMap(l -> l.getAllowedModes().stream())
86 .collect(Collectors.groupingBy(m -> m, Collectors.counting()));
void removeLinksWithNoModes(Network network)
Map< Id< Node >, ? extends Node > getNodes()
void run(final Set< String > modes)
void removeNodesWithNoLinks(Network network)
void run(Network network)
NetworkModeRestriction(Map< Id< Link >, Set< String >> modesToRemoveByLinkId)
static void removeAllowedMode(Link link, String mode)
Map< Id< Link >, ? extends Link > getLinks()
void applyModeChanges(Network network)
NetworkModeRestriction(Function< Id< Link >, Set< String >> modesToRemoveByLinkId)
final Function< Id< Link >, Set< String > > modesToRemoveByLinkId
void logModeCountDifference(Map< String, Long > modeCountBefore, Map< String, Long > modeCountAfter)
static Map< String, Long > countModes(Network network)
void cleanNetworkPerMode(Network network)