1 package org.matsim.core.network.turnRestrictions;
3 import com.google.common.base.Verify;
14 import java.util.stream.Collectors;
40 if (turnRestrictions.
replacedLinks.containsKey(link.getId())) {
53 if (coloredLink.fromColoredNode != null) {
56 fromNode = network.
getNodes().get(coloredLink.fromNode.getId());
60 if (coloredLink.toColoredNode != null) {
63 toNode = network.
getNodes().get(coloredLink.toNode.getId());
66 Verify.verifyNotNull(fromNode);
67 Verify.verifyNotNull(toNode);
75 coloredLink.link.getLength(),
76 coloredLink.link.getFreespeed(),
77 coloredLink.link.getCapacity(),
78 coloredLink.link.getNumberOfLanes()
91 if (network.
getNodes().containsKey(nodeId) && !network.
getNodes().containsKey(coloredNode.node().getId())) {
95 if (network.
getLinks().containsKey(coloredLink.link.getId())) {
100 if (network.
getLinks().containsKey(coloredLink.link.getId())) {
132 if (network.
getLinks().containsKey(copyId) && !network.
getLinks().containsKey(coloredLink.link.getId())) {
133 Link link = coloredLink.link;
152 Link link = network.
getLinks().get(idColoredLinkEntry.getValue().link.getId());
153 List<Id<Link>> currentPath =
new ArrayList<>();
154 if (idColoredLinkEntry.getValue().toNode != null) {
157 advance(idColoredLinkEntry.getValue(), currentPath, link, network, turnRestrictions);
165 if (!network.
getLinks().containsKey(coloredLink.link.getId())) {
170 if (coloredLink.toColoredNode != null) {
171 Node node = coloredLink.toColoredNode.node();
175 Set<Id<Link>> unrestrictedReachableLinks =
new HashSet<>(node.
getOutLinks().values()
178 .filter(link -> network.
getLinks().containsKey(link))
179 .collect(Collectors.toSet()));
185 unrestrictedReachableLinks.remove(outLink.link.getId());
186 if (outLink.toColoredNode != null) {
187 toAdvance.add(outLink);
193 if (!unrestrictedReachableLinks.isEmpty()) {
195 for (
Id<Link> unrestrictedReachableLink : unrestrictedReachableLinks) {
196 List<Id<Link>> path =
new ArrayList<>(currentPath);
197 path.add(unrestrictedReachableLink);
203 List<Id<Link>> nextPath =
new ArrayList<>(currentPath);
204 nextPath.add(link.link.getId());
205 if (turnRestrictions.
replacedLinks.containsKey(link.link.getId())) {
208 advance(link, nextPath, replacedStartLink, network, turnRestrictions);
214 return Id.
createNodeId(coloredNode.node().getId() +
"_" + coloredNode.index());
218 return Id.
createLinkId(coloredLink.link.getId() +
"_" + coloredLink.index);
void collapseNetwork(Network network, TurnRestrictionsContext turnRestrictions)
Attributes getAttributes()
static DisallowedNextLinks getOrCreateDisallowedNextLinks(Link link)
Map< Id< Node >, ? extends Node > getNodes()
Link removeLink(final Id< Link > linkId)
boolean addOutLink(Link link)
Node removeNode(final Id< Node > nodeId)
static Id< Link > createLinkId(final long key)
void run(final Network network)
static Link createLink(Id< Link > id, Node from, Node to, Network network, double length, double freespeed, double capacity, double lanes)
boolean addDisallowedLinkSequence(String mode, List< Id< Link >> linkSequence)
Id< Link > getColoredLinkId(TurnRestrictionsContext.ColoredLink coloredLink)
static TurnRestrictionsContext build(Network network)
void advance(TurnRestrictionsContext.ColoredLink coloredLink, List< Id< Link >> currentPath, Link replacedStartLink, Network network, TurnRestrictionsContext turnRestrictions)
void checkRealLinkExistence(Network network, TurnRestrictionsContext.ColoredLink coloredLink)
ColoredNode toColoredNode
List< ColoredNode > coloredNodes
record ColoredNode(int index, Node node, List< ColoredLink > outLinks, List< ColoredLink > inLinks)
Map< Id< Link >, List< ColoredLink > > coloredLinksPerLinkMap
double getNumberOfLanes()
boolean addInLink(Link link)
List< ColoredLink > coloredLinks
Object putAttribute(final String attribute, final Object value)
void reapplyRestrictions(Network network, TurnRestrictionsContext turnRestrictions)
Id< Node > getColoredNodeId(TurnRestrictionsContext.ColoredNode coloredNode)
void run(Network network)
Map< Id< Link >, ? extends Link > getLinks()
static void copyAttributesExceptDisallowedNextLinks(Link from, Link to)
Map< Id< Link >, ColoredLink > replacedLinks
Map< Id< Link >, ? extends Link > getOutLinks()
static Node createNode(Id< Node > id)
void colorNetwork(Network network, TurnRestrictionsContext turnRestrictions)
static Id< Node > createNodeId(final long key)