1 package org.matsim.core.network.turnRestrictions;
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Collections;
6 import java.util.HashMap;
7 import java.util.HashSet;
8 import java.util.LinkedHashSet;
11 import java.util.Map.Entry;
13 import java.util.stream.Collectors;
15 import javax.annotation.Nullable;
17 import org.apache.logging.log4j.LogManager;
18 import org.apache.logging.log4j.Logger;
22 import com.google.common.collect.ImmutableList;
65 if (!warnedAboutNotConsideredInRouting) {
66 warnedAboutNotConsideredInRouting =
true;
67 LOG.warn(
"Considering DisallowedNextLinks in routing is only implemented by SpeedyDijkstra and SpeedyALT!");
80 List<List<Id<Link>>> linkSequences = this.linkIdSequencesMap.computeIfAbsent(mode, m ->
new ArrayList<>());
83 if (linkSequence.isEmpty() ||
new HashSet<>(linkSequence).size() != linkSequence.size()
84 || linkSequences.contains(linkSequence)) {
88 if (!linkSequences.add(ImmutableList.copyOf(linkSequence))) {
96 Collections.sort(linkSequences, (l, r) -> l.toString().compareTo(r.toString()));
101 List<List<Id<Link>>> sequences = this.linkIdSequencesMap.get(mode);
102 return sequences != null ? Collections.unmodifiableList(sequences) : Collections.emptyList();
115 final Set<List<Id<Link>>> sequences =
new LinkedHashSet<>();
117 for (List<List<
Id<Link>>> sequencesForMode : linkIdSequencesMap.values()) {
118 sequences.addAll(sequencesForMode);
121 return Collections.unmodifiableSet(sequences);
126 return this.linkIdSequencesMap.remove(mode);
129 public Map<String, List<List<Id<Link>>>>
getAsMap() {
130 return this.linkIdSequencesMap.entrySet().stream()
131 .collect(Collectors.toMap(Entry::getKey, e -> Collections.unmodifiableList(e.getValue())));
137 for (String mode : modes) {
147 this.linkIdSequencesMap.clear();
151 return this.linkIdSequencesMap.isEmpty();
158 && this.linkIdSequencesMap.keySet().
equals(dnl.linkIdSequencesMap.keySet())) {
159 for (Entry<String, List<List<
Id<Link>>>> entry : this.linkIdSequencesMap.entrySet()) {
160 String mode = entry.getKey();
161 List<List<Id<Link>>> linkSequences = entry.getValue();
162 List<List<Id<Link>>> otherLinkSequences = dnl.linkIdSequencesMap.get(mode);
165 if (linkSequences.size() != otherLinkSequences.size()
166 || !linkSequences.containsAll(otherLinkSequences)
167 || !otherLinkSequences.containsAll(linkSequences)) {
178 return this.linkIdSequencesMap.hashCode();
183 return "DisallowedNextLinks [linkIdSequencesMap=" + linkIdSequencesMap +
"]";
List< List< Id< Link > > > getDisallowedLinkSequences(String mode)
List< List< Id< Link > > > removeDisallowedLinkSequences(String mode)
boolean equals(Object obj)
boolean addDisallowedLinkSequence(String mode, List< Id< Link >> linkSequence)
final DisallowedNextLinks instance
final Map< String, List< List< Id< Link > > > > linkIdSequencesMap
Builder withDisallowedLinkSequence(String mode, List< Id< Link >> linkSequence)
DisallowedNextLinks build()
static boolean warnedAboutNotConsideredInRouting
DisallowedNextLinks copyOnlyModes(final Collection< String > modes)
Map< String, List< List< Id< Link > > > > getAsMap()
Collection< List< Id< Link > > > getMergedDisallowedLinkSequences()