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-2022 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
21// junction.
22/****************************************************************************/
23#include <config.h>
24
25#include <algorithm>
26#include <cassert>
27#include <cmath>
29#include "MSLane.h"
30#include "MSLink.h"
31#include "MSEdge.h"
32#include "MSJunctionLogic.h"
33#include "MSInternalJunction.h"
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
52void
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 (MSLane* const lane : myInternalLanes) {
72 for (MSLink* const link : lane->getLinkCont()) {
73 if (link->getViaLane() != nullptr) {
74 const int foeIndex = lane->getIncomingLanes()[0].viaLink->getIndex();
75 //std::cout << " response=" << response << " index=" << ownLinkIndex << " foeIndex=" << foeIndex << " ibct=" << indirectBicycleTurn(specialLane, thisLink, *i, *q) << "\n";
76 if (response.test(foeIndex) || indirectBicycleTurn(specialLane, thisLink, lane, link)) {
77 // only respect vehicles before internal junctions if they
78 // have priority (see the analogous foeLinks.test() when
79 // initializing myLinkFoeInternalLanes in MSRightOfWayJunction
80 // Indirect left turns for bicycles are a special case
81 // because they both intersect on their second part with the first part of the other one
82 // and only one of the has priority
83 myInternalLaneFoes.push_back(lane);
84 }
85 myInternalLaneFoes.push_back(link->getViaLane());
86 } else {
87 myInternalLaneFoes.push_back(lane);
88 }
89 //std::cout << " i=" << (*i)->getID() << " qLane=" << (*q)->getLane()->getID() << " qVia=" << Named::getIDSecure((*q)->getViaLane()) << " foes=" << toString(myInternalLaneFoes) << "\n";
90 }
91
92 }
93 for (std::vector<MSLane*>::const_iterator i = myIncomingLanes.begin() + 1; i != myIncomingLanes.end(); ++i) {
94 for (MSLink* const link : (*i)->getLinkCont()) {
95 MSLane* via = link->getViaLane();
96 if (std::find(myInternalLanes.begin(), myInternalLanes.end(), via) == myInternalLanes.end()) {
97 continue;
98 }
99 myInternalLinkFoes.push_back(link);
100 }
101 }
102 // thisLinks is itself an exitLink of the preceding internal lane
103 thisLink->setRequestInformation(ownLinkIndex, true, false, myInternalLinkFoes, myInternalLaneFoes, thisLink->getViaLane()->getLogicalPredecessorLane());
104 assert(thisLink->getViaLane()->getLinkCont().size() == 1);
105 MSLink* exitLink = thisLink->getViaLane()->getLinkCont()[0];
106 exitLink->setRequestInformation(ownLinkIndex, false, false, std::vector<MSLink*>(),
107 myInternalLaneFoes, thisLink->getViaLane());
108 for (const auto& ili : exitLink->getLane()->getIncomingLanes()) {
109 if (ili.lane->getEdge().isWalkingArea()) {
110 exitLink->addWalkingAreaFoeExit(ili.lane);
111 break;
112 }
113 }
114 for (MSLink* const link : myInternalLinkFoes) {
115 thisLink->addBlockedLink(link);
116 link->addBlockedLink(thisLink);
117 }
118}
119
120
121bool
122MSInternalJunction::indirectBicycleTurn(const MSLane* specialLane, const MSLink* thisLink, const MSLane* foeFirstPart, const MSLink* foeLink) const {
123 if (specialLane->getPermissions() == SVC_BICYCLE && foeFirstPart->getPermissions() == SVC_BICYCLE
124 && thisLink->getDirection() == LinkDirection::LEFT && foeLink->getDirection() == LinkDirection::LEFT
125 && thisLink->getViaLane() != nullptr
126 && thisLink->getViaLane()->getShape().intersects(foeFirstPart->getShape())) {
127 return true;
128 } else {
129 return false;
130 }
131}
132
133
134/****************************************************************************/
@ SVC_BICYCLE
vehicle is a bicycle
@ LEFT
The link is a (hard) left direction.
SumoXMLNodeType
Numbers representing special SUMO-XML-attribute values for representing node- (junction-) types used ...
const MSJunction * getToJunction() const
Definition: MSEdge.h:415
void postloadInit()
initialises the junction after the whole net has been loaded
virtual ~MSInternalJunction()
Destructor.
bool indirectBicycleTurn(const MSLane *specialLane, const MSLink *thisLink, const MSLane *foeFirstPart, const MSLink *foeLink) const
std::vector< MSLane * > myInternalLaneFoes
std::vector< MSLink * > myInternalLinkFoes
MSInternalJunction(const std::string &id, SumoXMLNodeType type, const Position &position, const PositionVector &shape, std::vector< MSLane * > incoming, std::vector< MSLane * > internal)
Constructor.
virtual const MSLogicJunction::LinkBits & getResponseFor(int linkIndex) const
Returns the response for the given link.
Representation of a lane in the micro simulation.
Definition: MSLane.h:84
SVCPermissions getPermissions() const
Returns the vehicle class permissions for this lane.
Definition: MSLane.h:583
const std::vector< IncomingLaneInfo > & getIncomingLanes() const
Definition: MSLane.h:879
const PositionVector & getShape() const
Returns this lane's shape.
Definition: MSLane.h:506
MSLane * getLogicalPredecessorLane() const
get the most likely precedecessor lane (sorted using by_connections_to_sorter). The result is cached ...
Definition: MSLane.cpp:2866
MSEdge & getEdge() const
Returns the lane's edge.
Definition: MSLane.h:713
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
Definition: MSLane.h:675
std::vector< MSLane * > myInternalLanes
list of internal lanes
std::bitset< SUMO_MAX_CONNECTIONS > LinkBits
Container for link response and foes.
std::vector< MSLane * > myIncomingLanes
list of incoming lanes
A junction with right-of-way - rules.
const MSJunctionLogic * getLogic() const
const std::string & getID() const
Returns the id.
Definition: Named.h:74
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:37
A list of positions.
bool intersects(const Position &p1, const Position &p2) const
Returns the information whether this list of points interesects the given line.