SUMO - Simulation of Urban MObility
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-2017 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 
45 // ===========================================================================
46 // method definitions
47 // ===========================================================================
49  SumoXMLNodeType type,
50  const Position& position,
51  const PositionVector& shape,
52  std::vector<MSLane*> incoming,
53  std::vector<MSLane*> internal,
54  MSJunctionLogic* logic) : MSLogicJunction(id, type, position, shape, incoming, internal),
55  myLogic(logic) {}
56 
57 
59  delete myLogic;
60 }
61 
62 
63 void
65  // inform links where they have to report approaching vehicles to
66  int requestPos = 0;
67  std::vector<MSLane*>::iterator i;
68  // going through the incoming lanes...
69  int maxNo = 0;
70  std::vector<std::pair<MSLane*, MSLink*> > sortedLinks;
71  for (i = myIncomingLanes.begin(); i != myIncomingLanes.end(); ++i) {
72  const MSLinkCont& links = (*i)->getLinkCont();
73  // ... set information for every link
74  for (MSLinkCont::const_iterator j = links.begin(); j != links.end(); j++) {
75  if ((*j)->getLane()->getEdge().isWalkingArea() ||
76  ((*i)->getEdge().isWalkingArea() && !(*j)->getLane()->getEdge().isCrossing())) {
77  continue;
78  }
79  sortedLinks.push_back(std::make_pair(*i, *j));
80  ++maxNo;
81  }
82  }
83 
84  const bool hasFoes = myLogic->hasFoes();
85  for (i = myIncomingLanes.begin(); i != myIncomingLanes.end(); ++i) {
86  const MSLinkCont& links = (*i)->getLinkCont();
87  // ... set information for every link
88  for (MSLinkCont::const_iterator j = links.begin(); j != links.end(); j++) {
89  if ((*j)->getLane()->getEdge().isWalkingArea() ||
90  ((*i)->getEdge().isWalkingArea() && !(*j)->getLane()->getEdge().isCrossing())) {
91  continue;
92  }
93  if (myLogic->getLogicSize() <= requestPos) {
94  throw ProcessError("Found invalid logic position of a link for junction '" + getID() + "' (" + toString(requestPos) + ", max " + toString(myLogic->getLogicSize()) + ") -> (network error)");
95  }
96  const MSLogicJunction::LinkBits& linkResponse = myLogic->getResponseFor(requestPos); // SUMO_ATTR_RESPONSE
97  const MSLogicJunction::LinkBits& linkFoes = myLogic->getFoesFor(requestPos); // SUMO_ATTR_FOES
98  bool cont = myLogic->getIsCont(requestPos);
99  myLinkFoeLinks[*j] = std::vector<MSLink*>();
100  for (int c = 0; c < maxNo; ++c) {
101  if (linkResponse.test(c)) {
102  MSLink* foe = sortedLinks[c].second;
103  myLinkFoeLinks[*j].push_back(foe);
104  if (MSGlobals::gUsingInternalLanes && foe->getViaLane() != 0) {
105  assert(foe->getViaLane()->getLinkCont().size() == 1);
106  MSLink* foeExitLink = foe->getViaLane()->getLinkCont()[0];
107  // add foe links after an internal junction
108  if (foeExitLink->getViaLane() != 0) {
109  myLinkFoeLinks[*j].push_back(foeExitLink);
110  }
111  }
112  }
113  }
114  std::vector<MSLink*> foes;
115  for (int c = 0; c < maxNo; ++c) {
116  if (linkFoes.test(c)) {
117  MSLink* foe = sortedLinks[c].second;
118  foes.push_back(foe);
119  MSLane* l = foe->getViaLane();
120  if (l == 0) {
121  continue;
122  }
123  // add foe links after an internal junction
124  const MSLinkCont& lc = l->getLinkCont();
125  for (MSLinkCont::const_iterator q = lc.begin(); q != lc.end(); ++q) {
126  if ((*q)->getViaLane() != 0) {
127  foes.push_back(*q);
128  }
129  }
130  }
131  }
132 
133  myLinkFoeInternalLanes[*j] = std::vector<MSLane*>();
135  int li = 0;
136  for (int c = 0; c < (int)sortedLinks.size(); ++c) {
137  if (sortedLinks[c].second->getLane() == 0) { // dead end
138  continue;
139  }
140  if (linkFoes.test(c)) {
141  myLinkFoeInternalLanes[*j].push_back(myInternalLanes[li]);
142  if (linkResponse.test(c)) {
143  const std::vector<MSLane::IncomingLaneInfo>& l = myInternalLanes[li]->getIncomingLanes();
144  if (l.size() == 1 && l[0].lane->getEdge().getPurpose() == MSEdge::EDGEFUNCTION_INTERNAL) {
145  myLinkFoeInternalLanes[*j].push_back(l[0].lane);
146  }
147  }
148  }
149  ++li;
150  }
151  }
152  (*j)->setRequestInformation((int)requestPos, hasFoes, cont, myLinkFoeLinks[*j], myLinkFoeInternalLanes[*j]);
153  // the exit link for a link before an internal junction is handled in MSInternalJunction
154  // so we need to skip if cont=true
155  if (MSGlobals::gUsingInternalLanes && (*j)->getViaLane() != 0 && !cont) {
156  assert((*j)->getViaLane()->getLinkCont().size() == 1);
157  MSLink* exitLink = (*j)->getViaLane()->getLinkCont()[0];
158  exitLink->setRequestInformation((int)requestPos, false, false, std::vector<MSLink*>(),
159  myLinkFoeInternalLanes[*j], (*j)->getViaLane());
160  }
161  for (std::vector<MSLink*>::const_iterator k = foes.begin(); k != foes.end(); ++k) {
162  (*j)->addBlockedLink(*k);
163  (*k)->addBlockedLink(*j);
164  }
165  requestPos++;
166  }
167  }
168 }
169 
170 
171 /****************************************************************************/
172 
MSJunctionLogic * myLogic
int getLogicSize() const
const std::string & getID() const
Returns the id.
Definition: Named.h:66
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:56
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 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:76
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:1597
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