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 /****************************************************************************/
9 // junction.
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo-sim.org/
12 // Copyright (C) 2001-2013 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
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 "MSBitSetLogic.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 (myLogic->getLogicSize() <= requestPos) {
87  throw ProcessError("Found invalid logic position of a link (network error)");
88  }
89  sortedLinks.push_back(std::make_pair(*i, *j));
90  ++maxNo;
91  }
92  }
93 
94  bool isCrossing = myLogic->isCrossing();
95  for (i = myIncomingLanes.begin(); i != myIncomingLanes.end(); ++i) {
96  const MSLinkCont& links = (*i)->getLinkCont();
97  // ... set information for every link
98  for (MSLinkCont::const_iterator j = links.begin(); j != links.end(); j++) {
99  if (myLogic->getLogicSize() <= requestPos) {
100  throw ProcessError("Found invalid logic position of a link (network error)");
101  }
102  const MSLogicJunction::LinkFoes& foeLinks = myLogic->getFoesFor(requestPos); // SUMO_ATTR_RESPONSE
103  const std::bitset<64>& internalFoes = myLogic->getInternalFoesFor(requestPos); // SUMO_ATTR_FOES
104  bool cont = myLogic->getIsCont(requestPos);
105  myLinkFoeLinks[*j] = std::vector<MSLink*>();
106  for (unsigned int c = 0; c < maxNo; ++c) {
107  if (foeLinks.test(c)) {
108  MSLink* foe = sortedLinks[c].second;
109  myLinkFoeLinks[*j].push_back(foe);
110 #ifdef HAVE_INTERNAL_LANES
111  if (MSGlobals::gUsingInternalLanes && foe->getViaLane() != 0) {
112  assert(foe->getViaLane()->getLinkCont().size() == 1);
113  MSLink* foeExitLink = foe->getViaLane()->getLinkCont()[0];
114  // add foe links after an internal junction
115  if (foeExitLink->getViaLane() != 0) {
116  myLinkFoeLinks[*j].push_back(foeExitLink);
117  }
118  }
119 #endif
120  }
121  }
122  std::vector<MSLink*> foes;
123  for (unsigned int c = 0; c < maxNo; ++c) {
124  if (internalFoes.test(c)) {
125  MSLink* foe = sortedLinks[c].second;
126  foes.push_back(foe);
127 #ifdef HAVE_INTERNAL_LANES
128  MSLane* l = foe->getViaLane();
129  if (l == 0) {
130  continue;
131  }
132  // add foe links after an internal junction
133  const MSLinkCont& lc = l->getLinkCont();
134  for (MSLinkCont::const_iterator q = lc.begin(); q != lc.end(); ++q) {
135  if ((*q)->getViaLane() != 0) {
136  foes.push_back(*q);
137  }
138  }
139 #endif
140  }
141  }
142 
143  myLinkFoeInternalLanes[*j] = std::vector<MSLane*>();
144 #ifdef HAVE_INTERNAL_LANES
145  if (MSGlobals::gUsingInternalLanes && myInternalLanes.size() > 0) {
146  int li = 0;
147  for (unsigned int c = 0; c < sortedLinks.size(); ++c) {
148  if (sortedLinks[c].second->getLane() == 0) { // dead end
149  continue;
150  }
151  if (internalFoes.test(c)) {
152  myLinkFoeInternalLanes[*j].push_back(myInternalLanes[li]);
153  if (foeLinks.test(c)) {
154  const std::vector<MSLane::IncomingLaneInfo>& l = myInternalLanes[li]->getIncomingLanes();
155  if (l.size() == 1 && l[0].lane->getEdge().getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL) {
156  myLinkFoeInternalLanes[*j].push_back(l[0].lane);
157  }
158  }
159  }
160  ++li;
161  }
162  }
163 #endif
164  (*j)->setRequestInformation(requestPos, requestPos, isCrossing, cont, myLinkFoeLinks[*j], myLinkFoeInternalLanes[*j]);
165 #ifdef HAVE_INTERNAL_LANES
166  // the exit link for a link before an internal junction is handled in MSInternalJunction
167  // so we need to skip if cont=true
168  if (MSGlobals::gUsingInternalLanes && (*j)->getViaLane() != 0 && !cont) {
169  assert((*j)->getViaLane()->getLinkCont().size() == 1);
170  MSLink* exitLink = (*j)->getViaLane()->getLinkCont()[0];
171  exitLink->setRequestInformation(requestPos, requestPos, false, false, std::vector<MSLink*>(),
172  myLinkFoeInternalLanes[*j], (*j)->getViaLane());
173  }
174 #endif
175  for (std::vector<MSLink*>::const_iterator k = foes.begin(); k != foes.end(); ++k) {
176  (*j)->addBlockedLink(*k);
177  (*k)->addBlockedLink(*j);
178  }
179  requestPos++;
180  }
181  }
182 }
183 
184 
185 /****************************************************************************/
186 
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.
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.
static bool gUsingInternalLanes
Information whether the simulation regards internal lanes.
Definition: MSGlobals.h:70
std::map< const MSLink *, std::vector< MSLane * > > myLinkFoeInternalLanes
virtual bool isCrossing() const
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:981
The edge is an internal edge.
Definition: MSEdge.h:90
Representation of a lane in the micro simulation.
Definition: MSLane.h:77