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