Eclipse 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-2019 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 (const auto& ili : exitLink->getLane()->getIncomingLanes()) {
113  if (ili.lane->getEdge().isWalkingArea()) {
114  exitLink->addWalkingAreaFoeExit(ili.lane);
115  break;
116  }
117  }
118  for (std::vector<MSLink*>::const_iterator k = myInternalLinkFoes.begin(); k != myInternalLinkFoes.end(); ++k) {
119  thisLink->addBlockedLink(*k);
120  (*k)->addBlockedLink(thisLink);
121  }
122 }
123 
124 
125 bool
126 MSInternalJunction::indirectBicycleTurn(const MSLane* specialLane, const MSLink* thisLink, const MSLane* foeFirstPart, const MSLink* foeLink) const {
127  if (specialLane->getPermissions() == SVC_BICYCLE && foeFirstPart->getPermissions() == SVC_BICYCLE
128  && thisLink->getDirection() == LINKDIR_LEFT && foeLink->getDirection() == LINKDIR_LEFT
129  && thisLink->getViaLane() != nullptr
130  && thisLink->getViaLane()->getShape().intersects(foeFirstPart->getShape())) {
131  return true;
132  } else {
133  return false;
134  }
135 }
136 
137 /****************************************************************************/
138 
MSInternalJunction::myInternalLinkFoes
std::vector< MSLink * > myInternalLinkFoes
Definition: MSInternalJunction.h:85
MSRightOfWayJunction.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:83
MSInternalJunction::postloadInit
void postloadInit()
initialises the junction after the whole net has been loaded
Definition: MSInternalJunction.cpp:54
MSRightOfWayJunction::getLogic
const MSJunctionLogic * getLogic() const
Definition: MSRightOfWayJunction.h:82
MSJunctionLogic.h
MSLane::getPermissions
SVCPermissions getPermissions() const
Returns the vehicle class permissions for this lane.
Definition: MSLane.h:549
MSLogicJunction::myInternalLanes
std::vector< MSLane * > myInternalLanes
list of internal lanes
Definition: MSLogicJunction.h:90
SVC_BICYCLE
vehicle is a bicycle
Definition: SUMOVehicleClass.h:180
MSInternalJunction::indirectBicycleTurn
bool indirectBicycleTurn(const MSLane *specialLane, const MSLink *thisLink, const MSLane *foeFirstPart, const MSLink *foeLink) const
Definition: MSInternalJunction.cpp:126
MSEdge.h
MSInternalJunction.h
PositionVector
A list of positions.
Definition: PositionVector.h:46
MSLane::getIncomingLanes
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
Definition: MSLane.h:819
PositionVector::intersects
bool intersects(const Position &p1, const Position &p2) const
Returns the information whether this list of points interesects the given line.
Definition: PositionVector.cpp:157
MSLogicJunction::myIncomingLanes
std::vector< MSLane * > myIncomingLanes
list of incoming lanes
Definition: MSLogicJunction.h:87
MSInternalJunction::~MSInternalJunction
virtual ~MSInternalJunction()
Destructor.
Definition: MSInternalJunction.cpp:50
SumoXMLNodeType
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
Definition: SUMOXMLDefinitions.h:1049
MSJunctionLogic::getResponseFor
virtual const MSLogicJunction::LinkBits & getResponseFor(int linkIndex) const
Returns the response for the given link.
Definition: MSJunctionLogic.h:48
ProcessError
Definition: UtilExceptions.h:40
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:39
LINKDIR_LEFT
The link is a (hard) left direction.
Definition: SUMOXMLDefinitions.h:1179
MSEdge::getToJunction
const MSJunction * getToJunction() const
Definition: MSEdge.h:361
MSLane::getLinkCont
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:2099
MSRightOfWayJunction
A junction with right-of-way - rules.
Definition: MSRightOfWayJunction.h:52
MSLane::getEdge
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:670
MSLane::getShape
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:478
MSInternalJunction::MSInternalJunction
MSInternalJunction(const std::string &id, SumoXMLNodeType type, const Position &position, const PositionVector &shape, std::vector< MSLane * > incoming, std::vector< MSLane * > internal)
Constructor.
Definition: MSInternalJunction.cpp:40
MSLogicJunction
Definition: MSLogicJunction.h:51
MSInternalJunction::myInternalLaneFoes
std::vector< MSLane * > myInternalLaneFoes
Definition: MSInternalJunction.h:86
config.h
MSLane.h
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:77
MSLogicJunction::LinkBits
std::bitset< SUMO_MAX_CONNECTIONS > LinkBits
Container for link response and foes.
Definition: MSLogicJunction.h:59