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.sourceforge.net/
12 // Copyright (C) 2001-2012 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 "MSJunctionLogic.h"
36 #include "MSBitSetLogic.h"
37 #include "MSGlobals.h"
38 #include "MSInternalLane.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);
103  const std::bitset<64> &internalFoes = myLogic->getInternalFoesFor(requestPos);
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  myLinkFoeLinks[*j].push_back(sortedLinks[c].second);
109  }
110  }
111  std::vector<MSLink*> foes;
112  for (unsigned int c = 0; c < maxNo; ++c) {
113  if (internalFoes.test(c)) {
114  MSLink* foe = sortedLinks[c].second;
115  foes.push_back(foe);
116 #ifdef HAVE_INTERNAL_LANES
117  MSLane* l = foe->getViaLane();
118  if (l == 0) {
119  continue;
120  }
121  const MSLinkCont& lc = l->getLinkCont();
122  for (MSLinkCont::const_iterator q = lc.begin(); q != lc.end(); ++q) {
123  if ((*q)->getViaLane() != 0) {
124  foes.push_back(*q);
125  }
126  }
127 #endif
128  }
129  }
130 
131  myLinkFoeInternalLanes[*j] = std::vector<MSLane*>();
132 #ifdef HAVE_INTERNAL_LANES
133  if (MSGlobals::gUsingInternalLanes && myInternalLanes.size() > 0) {
134  int li = 0;
135  for (unsigned int c = 0; c < sortedLinks.size(); ++c) {
136  if (sortedLinks[c].second->getLane() == 0) { // dead end
137  continue;
138  }
139  if (internalFoes.test(c)) {
140  myLinkFoeInternalLanes[*j].push_back(myInternalLanes[li]);
141  if(foeLinks.test(c)) {
142  const std::vector<MSLane::IncomingLaneInfo> &l = myInternalLanes[li]->getIncomingLanes();
143  if(l.size()==1&&l[0].lane->getEdge().getPurpose()==MSEdge::EDGEFUNCTION_INTERNAL) {
144  myLinkFoeInternalLanes[*j].push_back(l[0].lane);
145  }
146  }
147  }
148  ++li;
149  }
150  }
151 #endif
152  (*j)->setRequestInformation(requestPos, requestPos, isCrossing, cont, myLinkFoeLinks[*j], myLinkFoeInternalLanes[*j]);
153  for (std::vector<MSLink*>::const_iterator k = foes.begin(); k != foes.end(); ++k) {
154  (*j)->addBlockedLink(*k);
155  (*k)->addBlockedLink(*j);
156  }
157  requestPos++;
158  }
159  }
160 #ifdef HAVE_INTERNAL_LANES
161  // set information for the internal lanes
162  requestPos = 0;
163  for (i = myInternalLanes.begin(); i != myInternalLanes.end(); ++i) {
164  // ... set information about participation
165  static_cast<MSInternalLane*>(*i)->setParentJunctionInformation(&myInnerState, requestPos++);
166  }
167 #endif
168 }
169 
170 
171 /****************************************************************************/
172