SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MSRightOfWayJunction.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // junction.
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
13 // Copyright (C) 2001-2014 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  const Position& position,
54  const PositionVector& shape,
55  std::vector<MSLane*> incoming,
57  std::vector<MSLane*> internal,
58 #endif
59  MSJunctionLogic* logic)
60  : MSLogicJunction(id, position, shape, incoming
62  , internal),
63 #else
64  ),
65 #endif
66  myLogic(logic) {}
67 
68 
70  delete myLogic;
71 }
72 
73 
74 void
76  // inform links where they have to report approaching vehicles to
77  unsigned int requestPos = 0;
78  std::vector<MSLane*>::iterator i;
79  // going through the incoming lanes...
80  unsigned int maxNo = 0;
81  std::vector<std::pair<MSLane*, MSLink*> > sortedLinks;
82  for (i = myIncomingLanes.begin(); i != myIncomingLanes.end(); ++i) {
83  const MSLinkCont& links = (*i)->getLinkCont();
84  // ... set information for every link
85  for (MSLinkCont::const_iterator j = links.begin(); j != links.end(); j++) {
86  if ((*j)->getLane()->getEdge().isWalkingArea() ||
87  ((*i)->getEdge().isWalkingArea() && !(*j)->getLane()->getEdge().isCrossing())) {
88  continue;
89  }
90  sortedLinks.push_back(std::make_pair(*i, *j));
91  ++maxNo;
92  }
93  }
94 
95  const bool hasFoes = myLogic->hasFoes();
96  for (i = myIncomingLanes.begin(); i != myIncomingLanes.end(); ++i) {
97  const MSLinkCont& links = (*i)->getLinkCont();
98  // ... set information for every link
99  for (MSLinkCont::const_iterator j = links.begin(); j != links.end(); j++) {
100  if ((*j)->getLane()->getEdge().isWalkingArea() ||
101  ((*i)->getEdge().isWalkingArea() && !(*j)->getLane()->getEdge().isCrossing())) {
102  continue;
103  }
104  if (myLogic->getLogicSize() <= requestPos) {
105  throw ProcessError("Found invalid logic position of a link for junction '" + getID() + "' (" + toString(requestPos) + ", max " + toString(myLogic->getLogicSize()) + ") -> (network error)");
106  }
107  const MSLogicJunction::LinkFoes& foeLinks = myLogic->getFoesFor(requestPos); // SUMO_ATTR_RESPONSE
108  const std::bitset<64>& internalFoes = myLogic->getInternalFoesFor(requestPos); // SUMO_ATTR_FOES
109  bool cont = myLogic->getIsCont(requestPos);
110  myLinkFoeLinks[*j] = std::vector<MSLink*>();
111  for (unsigned int c = 0; c < maxNo; ++c) {
112  if (foeLinks.test(c)) {
113  MSLink* foe = sortedLinks[c].second;
114  myLinkFoeLinks[*j].push_back(foe);
115 #ifdef HAVE_INTERNAL_LANES
116  if (MSGlobals::gUsingInternalLanes && foe->getViaLane() != 0) {
117  assert(foe->getViaLane()->getLinkCont().size() == 1);
118  MSLink* foeExitLink = foe->getViaLane()->getLinkCont()[0];
119  // add foe links after an internal junction
120  if (foeExitLink->getViaLane() != 0) {
121  myLinkFoeLinks[*j].push_back(foeExitLink);
122  }
123  }
124 #endif
125  }
126  }
127  std::vector<MSLink*> foes;
128  for (unsigned int c = 0; c < maxNo; ++c) {
129  if (internalFoes.test(c)) {
130  MSLink* foe = sortedLinks[c].second;
131  foes.push_back(foe);
132 #ifdef HAVE_INTERNAL_LANES
133  MSLane* l = foe->getViaLane();
134  if (l == 0) {
135  continue;
136  }
137  // add foe links after an internal junction
138  const MSLinkCont& lc = l->getLinkCont();
139  for (MSLinkCont::const_iterator q = lc.begin(); q != lc.end(); ++q) {
140  if ((*q)->getViaLane() != 0) {
141  foes.push_back(*q);
142  }
143  }
144 #endif
145  }
146  }
147 
148  myLinkFoeInternalLanes[*j] = std::vector<MSLane*>();
149 #ifdef HAVE_INTERNAL_LANES
150  if (MSGlobals::gUsingInternalLanes && myInternalLanes.size() > 0) {
151  int li = 0;
152  for (unsigned int c = 0; c < sortedLinks.size(); ++c) {
153  if (sortedLinks[c].second->getLane() == 0) { // dead end
154  continue;
155  }
156  if (internalFoes.test(c)) {
157  myLinkFoeInternalLanes[*j].push_back(myInternalLanes[li]);
158  if (foeLinks.test(c)) {
159  const std::vector<MSLane::IncomingLaneInfo>& l = myInternalLanes[li]->getIncomingLanes();
160  if (l.size() == 1 && l[0].lane->getEdge().getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL) {
161  myLinkFoeInternalLanes[*j].push_back(l[0].lane);
162  }
163  }
164  }
165  ++li;
166  }
167  }
168 #endif
169  (*j)->setRequestInformation((int)requestPos, hasFoes, cont, myLinkFoeLinks[*j], myLinkFoeInternalLanes[*j]);
170 #ifdef HAVE_INTERNAL_LANES
171  // the exit link for a link before an internal junction is handled in MSInternalJunction
172  // so we need to skip if cont=true
173  if (MSGlobals::gUsingInternalLanes && (*j)->getViaLane() != 0 && !cont) {
174  assert((*j)->getViaLane()->getLinkCont().size() == 1);
175  MSLink* exitLink = (*j)->getViaLane()->getLinkCont()[0];
176  exitLink->setRequestInformation((int)requestPos, false, false, std::vector<MSLink*>(),
177  myLinkFoeInternalLanes[*j], (*j)->getViaLane());
178  }
179 #endif
180  for (std::vector<MSLink*>::const_iterator k = foes.begin(); k != foes.end(); ++k) {
181  (*j)->addBlockedLink(*k);
182  (*k)->addBlockedLink(*j);
183  }
184  requestPos++;
185  }
186  }
187 }
188 
189 
190 /****************************************************************************/
191 
virtual bool getIsCont(unsigned int linkIndex) const
unsigned int getLogicSize() const
MSJunctionLogic * myLogic
MSRightOfWayJunction(const std::string &id, const Position &position, const PositionVector &shape, std::vector< MSLane * > incoming, MSJunctionLogic *logic)
Constructor.
virtual const std::bitset< 64 > & getInternalFoesFor(unsigned 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:60
virtual const MSLogicJunction::LinkFoes & getFoesFor(unsigned int linkIndex) const
Returns the foes of the given link.
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:71
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
Definition: ToString.h:53
std::map< const MSLink *, std::vector< MSLane * > > myLinkFoeInternalLanes
std::bitset< 64 > LinkFoes
Container for link foes.
#define HAVE_INTERNAL_LANES
Definition: config.h:47
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:997
The edge is an internal edge.
Definition: MSEdge.h:91
Representation of a lane in the micro simulation.
Definition: MSLane.h:77