SUMO - Simulation of Urban MObility
MSInternalJunction.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 "MSInternalJunction.h"
35 #include "MSRightOfWayJunction.h"
36 #include "MSLane.h"
37 #include "MSEdge.h"
38 #include "MSJunctionLogic.h"
39 #include <algorithm>
40 #include <cassert>
41 #include <cmath>
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
48  SumoXMLNodeType type,
49  const Position& position,
50  const PositionVector& shape,
51  std::vector<MSLane*> incoming,
52  std::vector<MSLane*> internal)
53  : MSLogicJunction(id, type, position, shape, incoming, internal) {}
54 
55 
56 
58 
59 
60 void
62  if (myIncomingLanes.size() == 0) {
63  throw ProcessError("Internal junction " + getID() + " has no incoming lanes");
64  }
65  // the first lane in the list of incoming lanes is special. It defines the
66  // link that needs to do all the checking for this internal junction
67  const MSLane* specialLane = myIncomingLanes[0];
68  assert(specialLane->getLinkCont().size() == 1);
69  MSLink* thisLink = specialLane->getLinkCont()[0];
70  const MSRightOfWayJunction* parent = dynamic_cast<const MSRightOfWayJunction*>(specialLane->getEdge().getToJunction());
71  if (parent == 0) {
72  // parent has type traffic_light_unregulated
73  return;
74  }
75  const int ownLinkIndex = specialLane->getIncomingLanes()[0].viaLink->getIndex();
76  const MSLogicJunction::LinkBits& response = parent->getLogic()->getResponseFor(ownLinkIndex);
77  // inform links where they have to report approaching vehicles to
78  int requestPos = 0;
79  for (std::vector<MSLane*>::iterator i = myInternalLanes.begin(); i != myInternalLanes.end(); ++i) {
80  const MSLinkCont& lc = (*i)->getLinkCont();
81  for (MSLinkCont::const_iterator q = lc.begin(); q != lc.end(); ++q) {
82  if ((*q)->getViaLane() != 0) {
83  const int foeIndex = (*i)->getIncomingLanes()[0].viaLink->getIndex();
84  if (response.test(foeIndex)) {
85  // only respect vehicles before internal junctions if they
86  // have priority (see the analogous foeLinks.test() when
87  // initializing myLinkFoeInternalLanes in MSRightOfWayJunction
88  myInternalLaneFoes.push_back(*i);
89  }
90  myInternalLaneFoes.push_back((*q)->getViaLane());
91  } else {
92  myInternalLaneFoes.push_back(*i);
93  }
94  }
95 
96  }
97  for (std::vector<MSLane*>::const_iterator i = myIncomingLanes.begin() + 1; i != myIncomingLanes.end(); ++i) {
98  MSLane* l = *i;
99  const MSLinkCont& lc = l->getLinkCont();
100  for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
101  MSLane* via = (*j)->getViaLane();
102  if (std::find(myInternalLanes.begin(), myInternalLanes.end(), via) == myInternalLanes.end()) {
103  continue;
104  }
105  myInternalLinkFoes.push_back(*j);
106  }
107  }
108  // thisLinks is itself an exitLink of the preceding internal lane
109  thisLink->setRequestInformation((int)requestPos, true, false, myInternalLinkFoes, myInternalLaneFoes, thisLink->getViaLane()->getLogicalPredecessorLane());
110  assert(thisLink->getViaLane()->getLinkCont().size() == 1);
111  MSLink* exitLink = thisLink->getViaLane()->getLinkCont()[0];
112  exitLink->setRequestInformation((int)requestPos, false, false, std::vector<MSLink*>(),
113  myInternalLaneFoes, thisLink->getViaLane());
114  for (std::vector<MSLink*>::const_iterator k = myInternalLinkFoes.begin(); k != myInternalLinkFoes.end(); ++k) {
115  thisLink->addBlockedLink(*k);
116  (*k)->addBlockedLink(thisLink);
117  }
118 }
119 
120 
121 /****************************************************************************/
122 
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
Definition: MSLane.h:719
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:582
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:66
const MSJunction * getToJunction() const
Definition: MSEdge.h:372
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:46
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:1597
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:79