SUMO - Simulation of Urban MObility
MSInternalJunction.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
20 // junction.
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 "MSInternalJunction.h"
34 #include "MSRightOfWayJunction.h"
35 #include "MSLane.h"
36 #include "MSEdge.h"
37 #include "MSJunctionLogic.h"
38 #include <algorithm>
39 #include <cassert>
40 #include <cmath>
41 
42 
43 // ===========================================================================
44 // method definitions
45 // ===========================================================================
47  SumoXMLNodeType type,
48  const Position& position,
49  const PositionVector& shape,
50  std::vector<MSLane*> incoming,
51  std::vector<MSLane*> internal)
52  : MSLogicJunction(id, type, position, shape, incoming, internal) {}
53 
54 
55 
57 
58 
59 void
61  if (myIncomingLanes.size() == 0) {
62  throw ProcessError("Internal junction " + getID() + " has no incoming lanes");
63  }
64  // the first lane in the list of incoming lanes is special. It defines the
65  // link that needs to do all the checking for this internal junction
66  const MSLane* specialLane = myIncomingLanes[0];
67  assert(specialLane->getLinkCont().size() == 1);
68  MSLink* thisLink = specialLane->getLinkCont()[0];
69  const MSRightOfWayJunction* parent = dynamic_cast<const MSRightOfWayJunction*>(specialLane->getEdge().getToJunction());
70  if (parent == 0) {
71  // parent has type traffic_light_unregulated
72  return;
73  }
74  const int ownLinkIndex = specialLane->getIncomingLanes()[0].viaLink->getIndex();
75  const MSLogicJunction::LinkBits& response = parent->getLogic()->getResponseFor(ownLinkIndex);
76  // inform links where they have to report approaching vehicles to
77  int requestPos = 0;
78  for (std::vector<MSLane*>::iterator i = myInternalLanes.begin(); i != myInternalLanes.end(); ++i) {
79  const MSLinkCont& lc = (*i)->getLinkCont();
80  for (MSLinkCont::const_iterator q = lc.begin(); q != lc.end(); ++q) {
81  if ((*q)->getViaLane() != 0) {
82  const int foeIndex = (*i)->getIncomingLanes()[0].viaLink->getIndex();
83  if (response.test(foeIndex)) {
84  // only respect vehicles before internal junctions if they
85  // have priority (see the analogous foeLinks.test() when
86  // initializing myLinkFoeInternalLanes in MSRightOfWayJunction
87  myInternalLaneFoes.push_back(*i);
88  }
89  myInternalLaneFoes.push_back((*q)->getViaLane());
90  } else {
91  myInternalLaneFoes.push_back(*i);
92  }
93  }
94 
95  }
96  for (std::vector<MSLane*>::const_iterator i = myIncomingLanes.begin() + 1; i != myIncomingLanes.end(); ++i) {
97  MSLane* l = *i;
98  const MSLinkCont& lc = l->getLinkCont();
99  for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
100  MSLane* via = (*j)->getViaLane();
101  if (std::find(myInternalLanes.begin(), myInternalLanes.end(), via) == myInternalLanes.end()) {
102  continue;
103  }
104  myInternalLinkFoes.push_back(*j);
105  }
106  }
107  // thisLinks is itself an exitLink of the preceding internal lane
108  thisLink->setRequestInformation((int)requestPos, true, false, myInternalLinkFoes, myInternalLaneFoes, thisLink->getViaLane()->getLogicalPredecessorLane());
109  assert(thisLink->getViaLane()->getLinkCont().size() == 1);
110  MSLink* exitLink = thisLink->getViaLane()->getLinkCont()[0];
111  exitLink->setRequestInformation((int)requestPos, false, false, std::vector<MSLink*>(),
112  myInternalLaneFoes, thisLink->getViaLane());
113  for (std::vector<MSLink*>::const_iterator k = myInternalLinkFoes.begin(); k != myInternalLinkFoes.end(); ++k) {
114  thisLink->addBlockedLink(*k);
115  (*k)->addBlockedLink(thisLink);
116  }
117 }
118 
119 
120 /****************************************************************************/
121 
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
Definition: MSLane.h:752
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:607
MSInternalJunction(const std::string &id, SumoXMLNodeType type, const Position &position, const PositionVector &shape, std::vector< MSLane *> incoming, std::vector< MSLane *> internal)
Constructor.
const MSJunctionLogic * getLogic() const
const std::string & getID() const
Returns the id.
Definition: Named.h:74
const MSJunction * getToJunction() const
Definition: MSEdge.h:352
std::vector< MSLane * > myIncomingLanes
list of incoming lanes
virtual ~MSInternalJunction()
Destructor.
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
A list of positions.
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.
A junction with right-of-way - rules.
std::vector< MSLane * > myInternalLaneFoes
std::vector< MSLink * > myInternalLinkFoes
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:1874
std::bitset< SUMO_MAX_CONNECTIONS > LinkBits
Container for link response and foes.
void postloadInit()
initialises the junction after the whole net has been loaded
Representation of a lane in the micro simulation.
Definition: MSLane.h:77