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-2024 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"
35
36
37// ===========================================================================
38// method definitions
39// ===========================================================================
41 SumoXMLNodeType type,
42 const Position& position,
43 const PositionVector& shape,
44 const std::string& name,
45 std::vector<MSLane*> incoming,
46 std::vector<MSLane*> internal,
47 MSJunctionLogic* logic) : MSLogicJunction(id, type, position, shape, name, incoming, internal),
48 myLogic(logic) {}
49
50
54
55
56void
58 // inform links where they have to report approaching vehicles to
59 int requestPos = 0;
60 // going through the incoming lanes...
61 int maxNo = 0;
62 std::vector<std::pair<const MSLane*, MSLink*> > sortedLinks;
63 for (MSLane* const lane : myIncomingLanes) {
64 // ... set information for every link
65 for (MSLink* const link : lane->getLinkCont()) {
66 if (link->getLane()->getEdge().isWalkingArea() ||
67 (lane->getEdge().isWalkingArea() && !link->getLane()->getEdge().isCrossing())) {
68 continue;
69 }
70 sortedLinks.emplace_back(lane, link);
71 ++maxNo;
72 }
73 }
74
75 const bool hasFoes = myLogic->hasFoes();
76 for (const MSLane* const lane : myIncomingLanes) {
77 // ... set information for every link
78 const MSLane* walkingAreaFoe = nullptr;
79 for (MSLink* const link : lane->getLinkCont()) {
80 if (link->getLane()->getEdge().isWalkingArea()) {
81 if (lane->getPermissions() != SVC_PEDESTRIAN) {
82 // vehicular lane connects to a walkingarea
83 walkingAreaFoe = link->getLane();
84 }
85 continue;
86 } else if ((lane->getEdge().isWalkingArea() && !link->getLane()->getEdge().isCrossing())) {
87 continue;
88 }
89 if (myLogic->getLogicSize() <= requestPos) {
90 throw ProcessError("Found invalid logic position of a link for junction '" + getID() + "' (" + toString(requestPos) + ", max " + toString(myLogic->getLogicSize()) + ") -> (network error)");
91 }
92 const MSLogicJunction::LinkBits& linkResponse = myLogic->getResponseFor(requestPos); // SUMO_ATTR_RESPONSE
93 const MSLogicJunction::LinkBits& linkFoes = myLogic->getFoesFor(requestPos); // SUMO_ATTR_FOES
94 bool cont = myLogic->getIsCont(requestPos);
95 for (int c = 0; c < maxNo; ++c) {
96 if (linkResponse.test(c)) {
97 MSLink* foe = sortedLinks[c].second;
98 myLinkFoeLinks[link].push_back(foe);
99 if (MSGlobals::gUsingInternalLanes && foe->getViaLane() != nullptr) {
100 assert(foe->getViaLane()->getLinkCont().size() == 1);
101 MSLink* foeExitLink = foe->getViaLane()->getLinkCont()[0];
102 // add foe links after an internal junction
103 if (foeExitLink->getViaLane() != nullptr) {
104 myLinkFoeLinks[link].push_back(foeExitLink);
105 }
106 }
107 }
108 }
109 std::vector<MSLink*> foes;
110 for (int c = 0; c < maxNo; ++c) {
111 if (linkFoes.test(c)) {
112 MSLink* foe = sortedLinks[c].second;
113 foes.push_back(foe);
114 MSLane* l = foe->getViaLane();
115 if (l == nullptr) {
116 continue;
117 }
118 // add foe links after an internal junction
119 for (MSLink* const vLink : l->getLinkCont()) {
120 if (vLink->getViaLane() != nullptr) {
121 foes.push_back(vLink);
122 }
123 }
124 }
125 }
126
128 int li = 0;
129 for (int c = 0; c < (int)sortedLinks.size(); ++c) {
130 if (sortedLinks[c].second->getLane() == nullptr) { // dead end
131 continue;
132 }
133 if (linkFoes.test(c)) {
134 myLinkFoeInternalLanes[link].push_back(myInternalLanes[li]);
135 if (linkResponse.test(c) || sortedLinks[c].second->isIndirect() ||
136 link->getLane()->getBidiLane() == sortedLinks[c].second->getLaneBefore()) {
137 const std::vector<MSLane::IncomingLaneInfo>& l = myInternalLanes[li]->getIncomingLanes();
138 if (l.size() == 1 && l[0].lane->getEdge().isInternal()) {
139 myLinkFoeInternalLanes[link].push_back(l[0].lane);
140 }
141 }
142 }
143 ++li;
144 }
145 }
146 link->setRequestInformation((int)requestPos, hasFoes, cont, myLinkFoeLinks[link], myLinkFoeInternalLanes[link]);
147 // the exit link for a link before an internal junction is handled in MSInternalJunction
148 // so we need to skip if cont=true
149 if (MSGlobals::gUsingInternalLanes && link->getViaLane() != nullptr && !cont) {
150 assert(link->getViaLane()->getLinkCont().size() == 1);
151 MSLink* exitLink = link->getViaLane()->getLinkCont()[0];
152 exitLink->setRequestInformation((int)requestPos, false, false, std::vector<MSLink*>(),
153 myLinkFoeInternalLanes[link], link->getViaLane());
154 for (const auto& ili : exitLink->getLane()->getIncomingLanes()) {
155 if (ili.lane->getEdge().isWalkingArea()) {
156 exitLink->addWalkingAreaFoeExit(ili.lane);
157 break;
158 }
159 }
160 }
161 // the exit link for a crossing is needed for the pedestrian model
162 if (MSGlobals::gUsingInternalLanes && link->getLane()->getEdge().isCrossing()) {
163 MSLink* exitLink = link->getLane()->getLinkCont()[0];
164 exitLink->setRequestInformation((int)requestPos, false, false, std::vector<MSLink*>(),
165 myLinkFoeInternalLanes[link], link->getLane());
166 }
167 requestPos++;
168 }
169 if (walkingAreaFoe != nullptr && lane->getLinkCont().size() > 1) {
170 for (const MSLink* const link : lane->getLinkCont()) {
171 if (!link->getLane()->getEdge().isWalkingArea()) {
172 MSLink* exitLink = link->getViaLane()->getLinkCont()[0];
173 exitLink->addWalkingAreaFoe(walkingAreaFoe);
174 }
175 }
176 }
177 }
178}
179
180
181/****************************************************************************/
@ 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:950
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
Definition MSLane.h:724
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.