Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSRightOfWayJunction.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
21// junction.
22/****************************************************************************/
23#include <config.h>
24
25#include <algorithm>
26#include <cassert>
27#include <cmath>
29#include "MSEdge.h"
30#include "MSJunctionLogic.h"
31#include "MSGlobals.h"
32#include "MSLane.h"
33#include "MSLink.h"
36
37
38// ===========================================================================
39// method definitions
40// ===========================================================================
42 SumoXMLNodeType type,
43 const Position& position,
44 const PositionVector& shape,
45 const std::string& name,
46 std::vector<MSLane*> incoming,
47 std::vector<MSLane*> internal,
48 MSJunctionLogic* logic) : MSLogicJunction(id, type, position, shape, name, incoming, internal),
49 myLogic(logic) {}
50
51
55
56
57void
59 // inform links where they have to report approaching vehicles to
60 int requestPos = 0;
61 // going through the incoming lanes...
62 int maxNo = 0;
63 std::vector<std::pair<const MSLane*, MSLink*> > sortedLinks;
64 for (MSLane* const lane : myIncomingLanes) {
65 // ... set information for every link
66 for (MSLink* const link : lane->getLinkCont()) {
67 if (link->getLane()->getEdge().isWalkingArea() ||
68 (lane->getEdge().isWalkingArea() && !link->getLane()->getEdge().isCrossing())) {
69 continue;
70 }
71 sortedLinks.emplace_back(lane, link);
72 ++maxNo;
73 }
74 }
75
76 const bool hasFoes = myLogic->hasFoes();
77 for (const MSLane* const lane : myIncomingLanes) {
78 // ... set information for every link
79 const MSLane* walkingAreaFoe = nullptr;
80 for (MSLink* const link : lane->getLinkCont()) {
81 if (link->getLane()->getEdge().isWalkingArea()) {
82 if (lane->getPermissions() != SVC_PEDESTRIAN) {
83 // vehicular lane connects to a walkingarea
84 walkingAreaFoe = link->getLane();
85 }
86 continue;
87 } else if ((lane->getEdge().isWalkingArea() && !link->getLane()->getEdge().isCrossing())) {
88 continue;
89 }
90 if (myLogic->getLogicSize() <= requestPos) {
91 throw ProcessError(TLF("Found invalid logic position of a link for junction '%' (%, max %) -> (network error)", getID(), toString(requestPos), toString(myLogic->getLogicSize())));
92 }
93 const MSLogicJunction::LinkBits& linkResponse = myLogic->getResponseFor(requestPos); // SUMO_ATTR_RESPONSE
94 const MSLogicJunction::LinkBits& linkFoes = myLogic->getFoesFor(requestPos); // SUMO_ATTR_FOES
95 bool cont = myLogic->getIsCont(requestPos);
96 for (int c = 0; c < maxNo; ++c) {
97 if (linkResponse.test(c)) {
98 MSLink* foe = sortedLinks[c].second;
99 myLinkFoeLinks[link].push_back(foe);
100 if (MSGlobals::gUsingInternalLanes && foe->getViaLane() != nullptr) {
101 assert(foe->getViaLane()->getLinkCont().size() == 1);
102 MSLink* foeExitLink = foe->getViaLane()->getLinkCont()[0];
103 // add foe links after an internal junction
104 if (foeExitLink->getViaLane() != nullptr) {
105 myLinkFoeLinks[link].push_back(foeExitLink);
106 }
107 }
108 }
109 }
110 std::vector<MSLink*> foes;
111 for (int c = 0; c < maxNo; ++c) {
112 if (linkFoes.test(c)) {
113 MSLink* foe = sortedLinks[c].second;
114 foes.push_back(foe);
115 MSLane* l = foe->getViaLane();
116 if (l == nullptr) {
117 continue;
118 }
119 // add foe links after an internal junction
120 for (MSLink* const vLink : l->getLinkCont()) {
121 if (vLink->getViaLane() != nullptr) {
122 foes.push_back(vLink);
123 }
124 }
125 }
126 }
127
129 int li = 0;
130 for (int c = 0; c < (int)sortedLinks.size(); ++c) {
131 if (sortedLinks[c].second->getLane() == nullptr) { // dead end
132 continue;
133 }
134 if (linkFoes.test(c)) {
135 myLinkFoeInternalLanes[link].push_back(myInternalLanes[li]);
136 if (linkResponse.test(c) || sortedLinks[c].second->isIndirect() ||
137 link->getLane()->getBidiLane() == sortedLinks[c].second->getLaneBefore()) {
138 const std::vector<MSLane::IncomingLaneInfo>& l = myInternalLanes[li]->getIncomingLanes();
139 if (l.size() == 1 && l[0].lane->getEdge().isInternal()) {
140 myLinkFoeInternalLanes[link].push_back(l[0].lane);
141 }
142 }
143 }
144 ++li;
145 }
146 }
147 link->setRequestInformation((int)requestPos, hasFoes, cont, myLinkFoeLinks[link], myLinkFoeInternalLanes[link]);
148 // the exit link for a link before an internal junction is handled in MSInternalJunction
149 // so we need to skip if cont=true
150 if (MSGlobals::gUsingInternalLanes && link->getViaLane() != nullptr && !cont) {
151 assert(link->getViaLane()->getLinkCont().size() == 1);
152 MSLink* exitLink = link->getViaLane()->getLinkCont()[0];
153 exitLink->setRequestInformation((int)requestPos, false, false, std::vector<MSLink*>(),
154 myLinkFoeInternalLanes[link], link->getViaLane());
155 for (const auto& ili : exitLink->getLane()->getIncomingLanes()) {
156 if (ili.lane->getEdge().isWalkingArea()) {
157 exitLink->addWalkingAreaFoeExit(ili.lane);
158 break;
159 }
160 }
161 }
162 // the exit link for a crossing is needed for the pedestrian model
163 if (MSGlobals::gUsingInternalLanes && link->getLane()->getEdge().isCrossing()) {
164 MSLink* exitLink = link->getLane()->getLinkCont()[0];
165 exitLink->setRequestInformation((int)requestPos, false, false, std::vector<MSLink*>(),
166 myLinkFoeInternalLanes[link], link->getLane());
167 }
168 requestPos++;
169 }
170 if (walkingAreaFoe != nullptr && lane->getLinkCont().size() > 1) {
171 for (const MSLink* const link : lane->getLinkCont()) {
172 if (!link->getLane()->getEdge().isWalkingArea()) {
173 MSLink* exitLink = link->getViaLane()->getLinkCont()[0];
174 exitLink->addWalkingAreaFoe(walkingAreaFoe);
175 }
176 }
177 }
178 }
179}
180
181
182/****************************************************************************/
#define TLF(string,...)
Definition MsgHandler.h:307
@ SVC_PEDESTRIAN
pedestrian
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition ToString.h:46
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition MSGlobals.h:81
virtual bool getIsCont(int linkIndex) const
virtual bool hasFoes() const
virtual const MSLogicJunction::LinkBits & getResponseFor(int linkIndex) const
Returns the response for the given link.
int getLogicSize() const
virtual const MSLogicJunction::LinkBits & getFoesFor(int linkIndex) const
Returns the foes for the given link.
Representation of a lane in the micro simulation.
Definition MSLane.h:84
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
Definition MSLane.h:955
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
Definition MSLane.h:729
std::vector< MSLane * > myInternalLanes
list of internal lanes
std::bitset< SUMO_MAX_CONNECTIONS > LinkBits
Container for link response and foes.
std::vector< MSLane * > myIncomingLanes
list of incoming lanes
MSJunctionLogic * myLogic
std::map< const MSLink *, std::vector< MSLane * > > myLinkFoeInternalLanes
void postloadInit()
initialises the junction after the whole net has been loaded
std::map< const MSLink *, std::vector< MSLink * > > myLinkFoeLinks
virtual ~MSRightOfWayJunction()
Destructor.
MSRightOfWayJunction(const std::string &id, SumoXMLNodeType type, const Position &position, const PositionVector &shape, const std::string &name, std::vector< MSLane * > incoming, std::vector< MSLane * > internal, MSJunctionLogic *logic)
Constructor.
const std::string & getID() const
Returns the id.
Definition Named.h:74
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.