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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
18 // junction.
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include "MSInternalJunction.h"
28 #include "MSRightOfWayJunction.h"
29 #include "MSLane.h"
30 #include "MSEdge.h"
31 #include "MSJunctionLogic.h"
32 #include <algorithm>
33 #include <cassert>
34 #include <cmath>
35 
36 
37 // ===========================================================================
38 // method definitions
39 // ===========================================================================
41  SumoXMLNodeType type,
42  const Position& position,
43  const PositionVector& shape,
44  std::vector<MSLane*> incoming,
45  std::vector<MSLane*> internal)
46  : MSLogicJunction(id, type, position, shape, incoming, internal) {}
47 
48 
49 
51 
52 
53 void
55  if (myIncomingLanes.size() == 0) {
56  throw ProcessError("Internal junction " + getID() + " has no incoming lanes");
57  }
58  // the first lane in the list of incoming lanes is special. It defines the
59  // link that needs to do all the checking for this internal junction
60  const MSLane* specialLane = myIncomingLanes[0];
61  assert(specialLane->getLinkCont().size() == 1);
62  MSLink* thisLink = specialLane->getLinkCont()[0];
63  const MSRightOfWayJunction* parent = dynamic_cast<const MSRightOfWayJunction*>(specialLane->getEdge().getToJunction());
64  if (parent == nullptr) {
65  // parent has type traffic_light_unregulated
66  return;
67  }
68  const int ownLinkIndex = specialLane->getIncomingLanes()[0].viaLink->getIndex();
69  const MSLogicJunction::LinkBits& response = parent->getLogic()->getResponseFor(ownLinkIndex);
70  // inform links where they have to report approaching vehicles to
71  //std::cout << " special=" << specialLane->getID() << " incoming=" << toString(myIncomingLanes) << " internal=" << toString(myInternalLanes) << "\n";
72  for (std::vector<MSLane*>::iterator i = myInternalLanes.begin(); i != myInternalLanes.end(); ++i) {
73  const MSLinkCont& lc = (*i)->getLinkCont();
74  for (MSLinkCont::const_iterator q = lc.begin(); q != lc.end(); ++q) {
75  if ((*q)->getViaLane() != nullptr) {
76  const int foeIndex = (*i)->getIncomingLanes()[0].viaLink->getIndex();
77  //std::cout << " response=" << response << " index=" << ownLinkIndex << " foeIndex=" << foeIndex << " ibct=" << indirectBicycleTurn(specialLane, thisLink, *i, *q) << "\n";
78  if (response.test(foeIndex) || indirectBicycleTurn(specialLane, thisLink, *i, *q)) {
79  // only respect vehicles before internal junctions if they
80  // have priority (see the analogous foeLinks.test() when
81  // initializing myLinkFoeInternalLanes in MSRightOfWayJunction
82  // Indirect left turns for bicycles are a special case
83  // because they both intersect on their second part with the first part of the other one
84  // and only one of the has priority
85  myInternalLaneFoes.push_back(*i);
86  }
87  myInternalLaneFoes.push_back((*q)->getViaLane());
88  } else {
89  myInternalLaneFoes.push_back(*i);
90  }
91  //std::cout << " i=" << (*i)->getID() << " qLane=" << (*q)->getLane()->getID() << " qVia=" << Named::getIDSecure((*q)->getViaLane()) << " foes=" << toString(myInternalLaneFoes) << "\n";
92  }
93 
94  }
95  for (std::vector<MSLane*>::const_iterator i = myIncomingLanes.begin() + 1; i != myIncomingLanes.end(); ++i) {
96  MSLane* l = *i;
97  const MSLinkCont& lc = l->getLinkCont();
98  for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
99  MSLane* via = (*j)->getViaLane();
100  if (std::find(myInternalLanes.begin(), myInternalLanes.end(), via) == myInternalLanes.end()) {
101  continue;
102  }
103  myInternalLinkFoes.push_back(*j);
104  }
105  }
106  // thisLinks is itself an exitLink of the preceding internal lane
107  thisLink->setRequestInformation(ownLinkIndex, true, false, myInternalLinkFoes, myInternalLaneFoes, thisLink->getViaLane()->getLogicalPredecessorLane());
108  assert(thisLink->getViaLane()->getLinkCont().size() == 1);
109  MSLink* exitLink = thisLink->getViaLane()->getLinkCont()[0];
110  exitLink->setRequestInformation(ownLinkIndex, false, false, std::vector<MSLink*>(),
111  myInternalLaneFoes, thisLink->getViaLane());
112  for (std::vector<MSLink*>::const_iterator k = myInternalLinkFoes.begin(); k != myInternalLinkFoes.end(); ++k) {
113  thisLink->addBlockedLink(*k);
114  (*k)->addBlockedLink(thisLink);
115  }
116 }
117 
118 
119 bool
120 MSInternalJunction::indirectBicycleTurn(const MSLane* specialLane, const MSLink* thisLink, const MSLane* foeFirstPart, const MSLink* foeLink) const {
121  if (specialLane->getPermissions() == SVC_BICYCLE && foeFirstPart->getPermissions() == SVC_BICYCLE
122  && thisLink->getDirection() == LINKDIR_LEFT && foeLink->getDirection() == LINKDIR_LEFT
123  && thisLink->getViaLane() != nullptr
124  && thisLink->getViaLane()->getShape().intersects(foeFirstPart->getShape())) {
125  return true;
126  } else {
127  return false;
128  }
129 }
130 
131 /****************************************************************************/
132 
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
Definition: MSLane.h:785
MSEdge & getEdge() const
Returns the lane&#39;s edge.
Definition: MSLane.h:640
MSInternalJunction(const std::string &id, SumoXMLNodeType type, const Position &position, const PositionVector &shape, std::vector< MSLane *> incoming, std::vector< MSLane *> internal)
Constructor.
vehicle is a bicycle
const MSJunctionLogic * getLogic() const
const PositionVector & getShape() const
Returns this lane&#39;s shape.
Definition: MSLane.h:456
const std::string & getID() const
Returns the id.
Definition: Named.h:78
const MSJunction * getToJunction() const
Definition: MSEdge.h:347
The link is a (hard) left direction.
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:39
A list of positions.
bool indirectBicycleTurn(const MSLane *specialLane, const MSLink *thisLink, const MSLane *foeFirstPart, const MSLink *foeLink) const
SVCPermissions getPermissions() const
Returns the vehicle class permissions for this lane.
Definition: MSLane.h:522
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:1975
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:78
bool intersects(const Position &p1, const Position &p2) const
Returns the information whether this list of points interesects the given line.