SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MSRightOfWayJunction.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // junction.
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #include "MSRightOfWayJunction.h"
35 #include "MSLane.h"
36 #include "MSEdge.h"
37 #include "MSJunctionLogic.h"
38 #include "MSGlobals.h"
39 #include <algorithm>
40 #include <cassert>
41 #include <cmath>
43 
44 #ifdef CHECK_MEMORY_LEAKS
45 #include <foreign/nvwa/debug_new.h>
46 #endif // CHECK_MEMORY_LEAKS
47 
48 
49 // ===========================================================================
50 // method definitions
51 // ===========================================================================
53  SumoXMLNodeType type,
54  const Position& position,
55  const PositionVector& shape,
56  std::vector<MSLane*> incoming,
58  std::vector<MSLane*> internal,
59 #endif
60  MSJunctionLogic* logic)
61  : MSLogicJunction(id, type, position, shape, incoming
63  , internal),
64 #else
65  ),
66 #endif
67  myLogic(logic) {}
68 
69 
71  delete myLogic;
72 }
73 
74 
75 void
77  // inform links where they have to report approaching vehicles to
78  int requestPos = 0;
79  std::vector<MSLane*>::iterator i;
80  // going through the incoming lanes...
81  int maxNo = 0;
82  std::vector<std::pair<MSLane*, MSLink*> > sortedLinks;
83  for (i = myIncomingLanes.begin(); i != myIncomingLanes.end(); ++i) {
84  const MSLinkCont& links = (*i)->getLinkCont();
85  // ... set information for every link
86  for (MSLinkCont::const_iterator j = links.begin(); j != links.end(); j++) {
87  if ((*j)->getLane()->getEdge().isWalkingArea() ||
88  ((*i)->getEdge().isWalkingArea() && !(*j)->getLane()->getEdge().isCrossing())) {
89  continue;
90  }
91  sortedLinks.push_back(std::make_pair(*i, *j));
92  ++maxNo;
93  }
94  }
95 
96  const bool hasFoes = myLogic->hasFoes();
97  for (i = myIncomingLanes.begin(); i != myIncomingLanes.end(); ++i) {
98  const MSLinkCont& links = (*i)->getLinkCont();
99  // ... set information for every link
100  for (MSLinkCont::const_iterator j = links.begin(); j != links.end(); j++) {
101  if ((*j)->getLane()->getEdge().isWalkingArea() ||
102  ((*i)->getEdge().isWalkingArea() && !(*j)->getLane()->getEdge().isCrossing())) {
103  continue;
104  }
105  if (myLogic->getLogicSize() <= requestPos) {
106  throw ProcessError("Found invalid logic position of a link for junction '" + getID() + "' (" + toString(requestPos) + ", max " + toString(myLogic->getLogicSize()) + ") -> (network error)");
107  }
108  const MSLogicJunction::LinkBits& linkResponse = myLogic->getResponseFor(requestPos); // SUMO_ATTR_RESPONSE
109  const MSLogicJunction::LinkBits& linkFoes = myLogic->getFoesFor(requestPos); // SUMO_ATTR_FOES
110  bool cont = myLogic->getIsCont(requestPos);
111  myLinkFoeLinks[*j] = std::vector<MSLink*>();
112  for (int c = 0; c < maxNo; ++c) {
113  if (linkResponse.test(c)) {
114  MSLink* foe = sortedLinks[c].second;
115  myLinkFoeLinks[*j].push_back(foe);
116 #ifdef HAVE_INTERNAL_LANES
117  if (MSGlobals::gUsingInternalLanes && foe->getViaLane() != 0) {
118  assert(foe->getViaLane()->getLinkCont().size() == 1);
119  MSLink* foeExitLink = foe->getViaLane()->getLinkCont()[0];
120  // add foe links after an internal junction
121  if (foeExitLink->getViaLane() != 0) {
122  myLinkFoeLinks[*j].push_back(foeExitLink);
123  }
124  }
125 #endif
126  }
127  }
128  std::vector<MSLink*> foes;
129  for (int c = 0; c < maxNo; ++c) {
130  if (linkFoes.test(c)) {
131  MSLink* foe = sortedLinks[c].second;
132  foes.push_back(foe);
133 #ifdef HAVE_INTERNAL_LANES
134  MSLane* l = foe->getViaLane();
135  if (l == 0) {
136  continue;
137  }
138  // add foe links after an internal junction
139  const MSLinkCont& lc = l->getLinkCont();
140  for (MSLinkCont::const_iterator q = lc.begin(); q != lc.end(); ++q) {
141  if ((*q)->getViaLane() != 0) {
142  foes.push_back(*q);
143  }
144  }
145 #endif
146  }
147  }
148 
149  myLinkFoeInternalLanes[*j] = std::vector<MSLane*>();
150 #ifdef HAVE_INTERNAL_LANES
151  if (MSGlobals::gUsingInternalLanes && myInternalLanes.size() > 0) {
152  int li = 0;
153  for (int c = 0; c < (int)sortedLinks.size(); ++c) {
154  if (sortedLinks[c].second->getLane() == 0) { // dead end
155  continue;
156  }
157  if (linkFoes.test(c)) {
158  myLinkFoeInternalLanes[*j].push_back(myInternalLanes[li]);
159  if (linkResponse.test(c)) {
160  const std::vector<MSLane::IncomingLaneInfo>& l = myInternalLanes[li]->getIncomingLanes();
161  if (l.size() == 1 && l[0].lane->getEdge().getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL) {
162  myLinkFoeInternalLanes[*j].push_back(l[0].lane);
163  }
164  }
165  }
166  ++li;
167  }
168  }
169 #endif
170  (*j)->setRequestInformation((int)requestPos, hasFoes, cont, myLinkFoeLinks[*j], myLinkFoeInternalLanes[*j]);
171 #ifdef HAVE_INTERNAL_LANES
172  // the exit link for a link before an internal junction is handled in MSInternalJunction
173  // so we need to skip if cont=true
174  if (MSGlobals::gUsingInternalLanes && (*j)->getViaLane() != 0 && !cont) {
175  assert((*j)->getViaLane()->getLinkCont().size() == 1);
176  MSLink* exitLink = (*j)->getViaLane()->getLinkCont()[0];
177  exitLink->setRequestInformation((int)requestPos, false, false, std::vector<MSLink*>(),
178  myLinkFoeInternalLanes[*j], (*j)->getViaLane());
179  }
180 #endif
181  for (std::vector<MSLink*>::const_iterator k = foes.begin(); k != foes.end(); ++k) {
182  (*j)->addBlockedLink(*k);
183  (*k)->addBlockedLink(*j);
184  }
185  requestPos++;
186  }
187  }
188 }
189 
190 
191 /****************************************************************************/
192 
MSRightOfWayJunction(const std::string &id, SumoXMLNodeType type, const Position &position, const PositionVector &shape, std::vector< MSLane * > incoming, MSJunctionLogic *logic)
Constructor.
MSJunctionLogic * myLogic
virtual bool getIsCont(int linkIndex) const
void postloadInit()
initialises the junction after the whole net has been loaded
std::vector< MSLane * > myIncomingLanes
list of incoming lanes
virtual ~MSRightOfWayJunction()
Destructor.
const std::string & getID() const
Returns the id.
Definition: Named.h:66
std::map< const MSLink *, std::vector< MSLink * > > myLinkFoeLinks
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
virtual bool hasFoes() const
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:73
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:55
std::map< const MSLink *, std::vector< MSLane * > > myLinkFoeInternalLanes
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
#define HAVE_INTERNAL_LANES
Definition: config.h:56
virtual const MSLogicJunction::LinkBits & getFoesFor(int linkIndex) const
Returns the foes for the given link.
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:1512
virtual const MSLogicJunction::LinkBits & getResponseFor(int linkIndex) const
Returns the response for the given link.
int getLogicSize() const
The edge is an internal edge.
Definition: MSEdge.h:97
std::bitset< SUMO_MAX_CONNECTIONS > LinkBits
Container for link response and foes.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79