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-2016 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 #ifdef CHECK_MEMORY_LEAKS
44 #include <foreign/nvwa/debug_new.h>
45 #endif // CHECK_MEMORY_LEAKS
46 
47 
48 // ===========================================================================
49 // method definitions
50 // ===========================================================================
51 #ifdef HAVE_INTERNAL_LANES
52 MSInternalJunction::MSInternalJunction(const std::string& id,
53  SumoXMLNodeType type,
54  const Position& position,
55  const PositionVector& shape,
56  std::vector<MSLane*> incoming,
57  std::vector<MSLane*> internal)
58  : MSLogicJunction(id, type, position, shape, incoming, internal) {}
59 
60 
61 
62 MSInternalJunction::~MSInternalJunction() {}
63 
64 
65 void
66 MSInternalJunction::postloadInit() {
67  if (myIncomingLanes.size() == 0) {
68  throw ProcessError("Internal junction " + getID() + " has no incoming lanes");
69  }
70  // the first lane in the list of incoming lanes is special. It defines the
71  // link that needs to do all the checking for this internal junction
72  const MSLane* specialLane = myIncomingLanes[0];
73  assert(specialLane->getLinkCont().size() == 1);
74  MSLink* thisLink = specialLane->getLinkCont()[0];
75  const MSRightOfWayJunction* parent = dynamic_cast<const MSRightOfWayJunction*>(specialLane->getEdge().getToJunction());
76  if (parent == 0) {
77  // parent has type traffic_light_unregulated
78  return;
79  }
80  const int ownLinkIndex = specialLane->getIncomingLanes()[0].viaLink->getIndex();
81  const MSLogicJunction::LinkBits& response = parent->getLogic()->getResponseFor(ownLinkIndex);
82  // inform links where they have to report approaching vehicles to
83  int requestPos = 0;
84  for (std::vector<MSLane*>::iterator i = myInternalLanes.begin(); i != myInternalLanes.end(); ++i) {
85  const MSLinkCont& lc = (*i)->getLinkCont();
86  for (MSLinkCont::const_iterator q = lc.begin(); q != lc.end(); ++q) {
87  if ((*q)->getViaLane() != 0) {
88  const int foeIndex = (*i)->getIncomingLanes()[0].viaLink->getIndex();
89  if (response.test(foeIndex)) {
90  // only respect vehicles before internal junctions if they
91  // have priority (see the analogous foeLinks.test() when
92  // initializing myLinkFoeInternalLanes in MSRightOfWayJunction
93  myInternalLaneFoes.push_back(*i);
94  }
95  myInternalLaneFoes.push_back((*q)->getViaLane());
96  } else {
97  myInternalLaneFoes.push_back(*i);
98  }
99  }
100 
101  }
102  for (std::vector<MSLane*>::const_iterator i = myIncomingLanes.begin() + 1; i != myIncomingLanes.end(); ++i) {
103  MSLane* l = *i;
104  const MSLinkCont& lc = l->getLinkCont();
105  for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
106  MSLane* via = (*j)->getViaLane();
107  if (std::find(myInternalLanes.begin(), myInternalLanes.end(), via) == myInternalLanes.end()) {
108  continue;
109  }
110  myInternalLinkFoes.push_back(*j);
111  }
112  }
113  // thisLinks is itself an exitLink of the preceding internal lane
114  thisLink->setRequestInformation((int)requestPos, true, false, myInternalLinkFoes, myInternalLaneFoes, thisLink->getViaLane()->getLogicalPredecessorLane());
115  assert(thisLink->getViaLane()->getLinkCont().size() == 1);
116  MSLink* exitLink = thisLink->getViaLane()->getLinkCont()[0];
117  exitLink->setRequestInformation((int)requestPos, false, false, std::vector<MSLink*>(),
118  myInternalLaneFoes, thisLink->getViaLane());
119  for (std::vector<MSLink*>::const_iterator k = myInternalLinkFoes.begin(); k != myInternalLinkFoes.end(); ++k) {
120  thisLink->addBlockedLink(*k);
121  (*k)->addBlockedLink(thisLink);
122  }
123 }
124 
125 
126 #endif
127 
128 
129 /****************************************************************************/
130 
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
Definition: MSLane.h:708
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:571
const MSJunctionLogic * getLogic() const
const std::string & getID() const
Returns the id.
Definition: Named.h:66
const MSJunction * getToJunction() const
Definition: MSEdge.h:387
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
A list of positions.
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.
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:1512
std::bitset< SUMO_MAX_CONNECTIONS > LinkBits
Container for link response and foes.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79