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