21 package org.matsim.core.network.algorithms;
23 import com.google.common.base.Verify;
24 import org.apache.logging.log4j.LogManager;
25 import org.apache.logging.log4j.Logger;
85 switch (this.mergetype) {
88 log.info(
" Link id=" + link2.
getId() +
" removed because of Link id=" + link1.
getId());
96 log.info(
" Link id=" + link2.
getId() +
" merged (additive) into Link id=" + link1.
getId());
113 log.info(
" Link id=" + link2.
getId() +
" merged (maximum) into Link id=" + link1.
getId());
130 throw new IllegalArgumentException(
"'mergetype' not known!");
141 Map<Id<Link>,
Replacement> replacedLinks =
new HashMap<>();
143 Iterator<? extends Link> l1_it = n.getOutLinks().values().iterator();
144 while (l1_it.hasNext()) {
145 Link l1 = l1_it.next();
146 Iterator<? extends Link> l2_it = n.getOutLinks().values().iterator();
147 while (l2_it.hasNext()) {
148 Link l2 = l2_it.next();
149 if (!l2.equals(l1)) {
152 log.info(
" Node id=" + n.getId());
158 l1_it = n.getOutLinks().values().iterator();
159 l2_it = n.getOutLinks().values().iterator();
171 for (
Replacement mergedLinks : replacedLinks.values()) {
178 if(disallowedNextLinks != null) {
180 Map<String, List<List<Id<Link>>>> restrictionsPerMode = disallowedNextLinks.
getAsMap();
181 Map<String, List<List<Id<Link>>>> restrictionsPerModeCopy =
new HashMap<>();
183 for (Map.Entry<String, List<List<
Id<Link>>>> restrictions : restrictionsPerMode.entrySet()) {
184 List<List<Id<Link>>> restrictionsCopy =
new ArrayList<>();
185 for (List<
Id<Link>> restriction : restrictions.getValue()) {
186 List<Id<Link>> restrictionCopy =
new ArrayList<>();
187 for (
Id<Link> linkId : restriction) {
188 if(replacedLinks.containsKey(linkId)) {
189 restrictionCopy.add(replacedLinks.get(linkId).substitute.getId());
191 restrictionCopy.add(linkId);
194 restrictionsCopy.add(restrictionCopy);
196 restrictionsPerModeCopy.put(restrictions.getKey(), restrictionsCopy);
199 disallowedNextLinks.
clear();
200 restrictionsPerModeCopy.forEach((mode, sequences) ->
201 sequences.forEach(sequence ->
214 if (disallowedNextLinks1 != null) {
215 if (disallowedNextLinks2 != null) {
217 Map<String, List<List<Id<Link>>>> perMode1 = disallowedNextLinks1.
getAsMap();
218 Map<String, List<List<Id<Link>>>> perMode2 = disallowedNextLinks2.
getAsMap();
219 Map<String, List<List<Id<Link>>>> merged =
new HashMap<>();
221 for (Map.Entry<String, List<List<
Id<Link>>>> restrictionsPerMode : perMode1.entrySet()) {
222 if (perMode2.containsKey(restrictionsPerMode.getKey())) {
223 for (List<
Id<Link>> forbiddenSequence : restrictionsPerMode.getValue()) {
224 Id<Link> target = forbiddenSequence.getLast();
225 if(replacedLinks.containsKey(target)) {
226 target = replacedLinks.
get(target).substitute.getId();
229 for (List<
Id<Link>> forbiddenSequence2 : perMode2.
get(restrictionsPerMode.getKey())) {
230 Id<Link> target2 = forbiddenSequence2.getLast();
231 if(replacedLinks.containsKey(target2)) {
232 target2 = replacedLinks.
get(target2).substitute.getId();
234 if(target.
equals(target2)) {
235 merged.computeIfAbsent(restrictionsPerMode.getKey(), k ->
new ArrayList<>()).add(forbiddenSequence);
241 disallowedNextLinks1.
clear();
242 merged.forEach((mode, sequences) -> sequences.forEach(sequence -> disallowedNextLinks1.
addDisallowedLinkSequence(mode, sequence)));
static boolean isValid(Network network)
static int getNumberOfLanesAsInt(final double time, final Link link)
void setNumberOfLanes(double lanes)
static< T > Id< T > get(int index, final Class< T > type)
Map< Id< Node >, ? extends Node > getNodes()
void setFreespeed(double freespeed)
Link removeLink(final Id< Link > linkId)
void run(Network network)
final MergeType mergetype
static void removeDisallowedNextLinks(Link link)
boolean addDisallowedLinkSequence(String mode, List< Id< Link >> linkSequence)
void handleTurnRestrictions(Network network, Map< Id< Link >, Replacement > replacedLinks)
NetworkMergeDoubleLinks(final MergeType mergetype)
static DisallowedNextLinks getDisallowedNextLinks(Link link)
static void mergeTurnRestrictions(Link link1, Link link2, Map< Id< Link >, Replacement > replacedLinks)
void setLength(double length)
NetworkMergeDoubleLinks()
NetworkMergeDoubleLinks(final MergeType mergetype, final LogInfoLevel logInfoLevel)
Map< Id< Link >, ? extends Link > getLinks()
final LogInfoLevel logInfoLevel
Map< String, List< List< Id< Link > > > > getAsMap()
boolean equals(Object obj)
void mergeLink2IntoLink1(Link link1, Link link2, Network network)
void setCapacity(double capacity)
record Replacement(Link orginal, Link substitute)