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 /****************************************************************************/
10 /// @file MSInternalJunction.cpp
11 /// @author Christian Roessel
12 /// @author Daniel Krajzewicz
13 /// @author Michael Behrisch
14 /// @author Jakob Erdmann
15 /// @date Wed, 12 Dez 2001
16 /// @version $Id$
17 ///
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 // ===========================================================================
MSInternalJunction(const std::string & id,SumoXMLNodeType type,const Position & position,const PositionVector & shape,std::vector<MSLane * > incoming,std::vector<MSLane * > internal)40 MSInternalJunction::MSInternalJunction(const std::string& id,
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
~MSInternalJunction()50 MSInternalJunction::~MSInternalJunction() {}
51
52
53 void
postloadInit()54 MSInternalJunction::postloadInit() {
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
indirectBicycleTurn(const MSLane * specialLane,const MSLink * thisLink,const MSLane * foeFirstPart,const MSLink * foeLink) const126 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
139