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 /****************************************************************************/
17 // junction.
18 /****************************************************************************/
19 
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include "MSInternalJunction.h"
27 #include "MSRightOfWayJunction.h"
28 #include "MSLane.h"
29 #include "MSEdge.h"
30 #include "MSJunctionLogic.h"
31 #include <algorithm>
32 #include <cassert>
33 #include <cmath>
34 
35 
36 // ===========================================================================
37 // method definitions
38 // ===========================================================================
40  SumoXMLNodeType type,
41  const Position& position,
42  const PositionVector& shape,
43  std::vector<MSLane*> incoming,
44  std::vector<MSLane*> internal)
45  : MSLogicJunction(id, type, position, shape, incoming, internal) {}
46 
47 
48 
50 
51 
52 void
54  if (myIncomingLanes.size() == 0) {
55  throw ProcessError("Internal junction " + getID() + " has no incoming lanes");
56  }
57  // the first lane in the list of incoming lanes is special. It defines the
58  // link that needs to do all the checking for this internal junction
59  const MSLane* specialLane = myIncomingLanes[0];
60  assert(specialLane->getLinkCont().size() == 1);
61  MSLink* thisLink = specialLane->getLinkCont()[0];
62  const MSRightOfWayJunction* parent = dynamic_cast<const MSRightOfWayJunction*>(specialLane->getEdge().getToJunction());
63  if (parent == nullptr) {
64  // parent has type traffic_light_unregulated
65  return;
66  }
67  const int ownLinkIndex = specialLane->getIncomingLanes()[0].viaLink->getIndex();
68  const MSLogicJunction::LinkBits& response = parent->getLogic()->getResponseFor(ownLinkIndex);
69  // inform links where they have to report approaching vehicles to
70  //std::cout << " special=" << specialLane->getID() << " incoming=" << toString(myIncomingLanes) << " internal=" << toString(myInternalLanes) << "\n";
71  for (std::vector<MSLane*>::iterator i = myInternalLanes.begin(); i != myInternalLanes.end(); ++i) {
72  const MSLinkCont& lc = (*i)->getLinkCont();
73  for (MSLinkCont::const_iterator q = lc.begin(); q != lc.end(); ++q) {
74  if ((*q)->getViaLane() != nullptr) {
75  const int foeIndex = (*i)->getIncomingLanes()[0].viaLink->getIndex();
76  //std::cout << " response=" << response << " index=" << ownLinkIndex << " foeIndex=" << foeIndex << " ibct=" << indirectBicycleTurn(specialLane, thisLink, *i, *q) << "\n";
77  if (response.test(foeIndex) || indirectBicycleTurn(specialLane, thisLink, *i, *q)) {
78  // only respect vehicles before internal junctions if they
79  // have priority (see the analogous foeLinks.test() when
80  // initializing myLinkFoeInternalLanes in MSRightOfWayJunction
81  // Indirect left turns for bicycles are a special case
82  // because they both intersect on their second part with the first part of the other one
83  // and only one of the has priority
84  myInternalLaneFoes.push_back(*i);
85  }
86  myInternalLaneFoes.push_back((*q)->getViaLane());
87  } else {
88  myInternalLaneFoes.push_back(*i);
89  }
90  //std::cout << " i=" << (*i)->getID() << " qLane=" << (*q)->getLane()->getID() << " qVia=" << Named::getIDSecure((*q)->getViaLane()) << " foes=" << toString(myInternalLaneFoes) << "\n";
91  }
92 
93  }
94  for (std::vector<MSLane*>::const_iterator i = myIncomingLanes.begin() + 1; i != myIncomingLanes.end(); ++i) {
95  MSLane* l = *i;
96  const MSLinkCont& lc = l->getLinkCont();
97  for (MSLinkCont::const_iterator j = lc.begin(); j != lc.end(); ++j) {
98  MSLane* via = (*j)->getViaLane();
99  if (std::find(myInternalLanes.begin(), myInternalLanes.end(), via) == myInternalLanes.end()) {
100  continue;
101  }
102  myInternalLinkFoes.push_back(*j);
103  }
104  }
105  // thisLinks is itself an exitLink of the preceding internal lane
106  thisLink->setRequestInformation(ownLinkIndex, true, false, myInternalLinkFoes, myInternalLaneFoes, thisLink->getViaLane()->getLogicalPredecessorLane());
107  assert(thisLink->getViaLane()->getLinkCont().size() == 1);
108  MSLink* exitLink = thisLink->getViaLane()->getLinkCont()[0];
109  exitLink->setRequestInformation(ownLinkIndex, false, false, std::vector<MSLink*>(),
110  myInternalLaneFoes, thisLink->getViaLane());
111  for (const auto& ili : exitLink->getLane()->getIncomingLanes()) {
112  if (ili.lane->getEdge().isWalkingArea()) {
113  exitLink->addWalkingAreaFoeExit(ili.lane);
114  break;
115  }
116  }
117  for (std::vector<MSLink*>::const_iterator k = myInternalLinkFoes.begin(); k != myInternalLinkFoes.end(); ++k) {
118  thisLink->addBlockedLink(*k);
119  (*k)->addBlockedLink(thisLink);
120  }
121 }
122 
123 
124 bool
125 MSInternalJunction::indirectBicycleTurn(const MSLane* specialLane, const MSLink* thisLink, const MSLane* foeFirstPart, const MSLink* foeLink) const {
126  if (specialLane->getPermissions() == SVC_BICYCLE && foeFirstPart->getPermissions() == SVC_BICYCLE
127  && thisLink->getDirection() == LINKDIR_LEFT && foeLink->getDirection() == LINKDIR_LEFT
128  && thisLink->getViaLane() != nullptr
129  && thisLink->getViaLane()->getShape().intersects(foeFirstPart->getShape())) {
130  return true;
131  } else {
132  return false;
133  }
134 }
135 
136 /****************************************************************************/
137 
MSInternalJunction::myInternalLinkFoes
std::vector< MSLink * > myInternalLinkFoes
Definition: MSInternalJunction.h:84
MSRightOfWayJunction.h
MSLane
Representation of a lane in the micro simulation.
Definition: MSLane.h:82
MSInternalJunction::postloadInit
void postloadInit()
initialises the junction after the whole net has been loaded
Definition: MSInternalJunction.cpp:53
MSRightOfWayJunction::getLogic
const MSJunctionLogic * getLogic() const
Definition: MSRightOfWayJunction.h:81
MSJunctionLogic.h
MSLane::getPermissions
SVCPermissions getPermissions() const
Returns the vehicle class permissions for this lane.
Definition: MSLane.h:548
MSLogicJunction::myInternalLanes
std::vector< MSLane * > myInternalLanes
list of internal lanes
Definition: MSLogicJunction.h:89
SVC_BICYCLE
vehicle is a bicycle
Definition: SUMOVehicleClass.h:179
MSInternalJunction::indirectBicycleTurn
bool indirectBicycleTurn(const MSLane *specialLane, const MSLink *thisLink, const MSLane *foeFirstPart, const MSLink *foeLink) const
Definition: MSInternalJunction.cpp:125
MSEdge.h
MSInternalJunction.h
PositionVector
A list of positions.
Definition: PositionVector.h:45
MSLane::getIncomingLanes
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
Definition: MSLane.h:818
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:159
MSLogicJunction::myIncomingLanes
std::vector< MSLane * > myIncomingLanes
list of incoming lanes
Definition: MSLogicJunction.h:86
MSInternalJunction::~MSInternalJunction
virtual ~MSInternalJunction()
Destructor.
Definition: MSInternalJunction.cpp:49
SumoXMLNodeType
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
Definition: SUMOXMLDefinitions.h:1054
MSJunctionLogic::getResponseFor
virtual const MSLogicJunction::LinkBits & getResponseFor(int linkIndex) const
Returns the response for the given link.
Definition: MSJunctionLogic.h:47
ProcessError
Definition: UtilExceptions.h:39
Position
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:38
LINKDIR_LEFT
The link is a (hard) left direction.
Definition: SUMOXMLDefinitions.h:1184
MSEdge::getToJunction
const MSJunction * getToJunction() const
Definition: MSEdge.h:363
MSLane::getLinkCont
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.cpp:2110
MSRightOfWayJunction
A junction with right-of-way - rules.
Definition: MSRightOfWayJunction.h:51
MSLane::getEdge
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:669
MSLane::getShape
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:477
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:39
MSLogicJunction
Definition: MSLogicJunction.h:50
MSInternalJunction::myInternalLaneFoes
std::vector< MSLane * > myInternalLaneFoes
Definition: MSInternalJunction.h:85
config.h
MSLane.h
Named::getID
const std::string & getID() const
Returns the id.
Definition: Named.h:76
MSLogicJunction::LinkBits
std::bitset< SUMO_MAX_CONNECTIONS > LinkBits
Container for link response and foes.
Definition: MSLogicJunction.h:58