Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSLink.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2002-2023 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/****************************************************************************/
20// A connection between lanes
21/****************************************************************************/
22#pragma once
23#include <config.h>
24
25#include <vector>
26#include <set>
31
32
33// ===========================================================================
34// class declarations
35// ===========================================================================
36class MSLane;
37class MSJunction;
38class MSVehicle;
39class MSPerson;
40class OutputDevice;
42
43
44// ===========================================================================
45// class definitions
46// ===========================================================================
67class MSLink {
68public:
69
75 LL_IN_THE_WAY = 1 << 0,
77 LL_FROM_LEFT = 1 << 1,
81 LL_SAME_TARGET = 1 << 3
82 };
83
84 struct LinkLeader {
85 LinkLeader(MSVehicle* _veh, double _gap, double _distToCrossing, int _llFlags = LL_FROM_LEFT, double _latOffst = 0) :
86 vehAndGap(std::make_pair(_veh, _gap)),
87 distToCrossing(_distToCrossing),
88 llFlags(_llFlags),
89 latOffset(_latOffst)
90 { }
91
92 inline bool fromLeft() const {
93 return (llFlags & LL_FROM_LEFT) != 0;
94 }
95 inline bool inTheWay() const {
96 return (llFlags & LL_IN_THE_WAY) != 0;
97 }
98 inline bool sameTarget() const {
99 return (llFlags & LL_SAME_TARGET) != 0;
100 }
101 inline bool sameSource() const {
102 return (llFlags & LL_SAME_SOURCE) != 0;
103 }
104
105 std::pair<MSVehicle*, double> vehAndGap;
108 double latOffset;
109
110 };
111
112 typedef std::vector<LinkLeader> LinkLeaders;
113
123 ApproachingVehicleInformation(const SUMOTime _arrivalTime, const SUMOTime _leavingTime,
124 const double _arrivalSpeed, const double _leaveSpeed,
125 const bool _willPass,
126 const double _arrivalSpeedBraking,
127 const SUMOTime _waitingTime,
128 const double _dist,
129 const double _speed,
130 const double _latOffset
131 ) :
132 arrivalTime(_arrivalTime), leavingTime(_leavingTime),
133 arrivalSpeed(_arrivalSpeed), leaveSpeed(_leaveSpeed),
134 willPass(_willPass),
135 arrivalSpeedBraking(_arrivalSpeedBraking),
136 waitingTime(_waitingTime),
137 dist(_dist),
138 speed(_speed),
139 latOffset(_latOffset) {
140 }
141
147 const double arrivalSpeed;
149 const double leaveSpeed;
151 const bool willPass;
157 const double dist;
159 const double speed;
161 const double latOffset;
162
163 };
164
165 typedef std::map<const SUMOVehicle*, const ApproachingVehicleInformation, ComparatorNumericalIdLess> ApproachInfos;
166 typedef std::vector<const SUMOVehicle*> BlockingFoes;
167
174
177
178 ConflictInfo(double lbc, double cs, ConflictFlag fl = CONFLICT_DEFAULT) :
181 conflictSize(cs),
182 flag(fl)
183 {}
190
192
193 double getFoeLengthBehindCrossing(const MSLink* foeExitLink) const;
194 double getFoeConflictSize(const MSLink* foeExitLink) const;
195 double getLengthBehindCrossing(const MSLink* exitLink) const;
196 };
197
200 CustomConflict(const MSLane* f, const MSLane* t, double s, double e) :
201 from(f), to(t), startPos(s), endPos(e) {}
202 const MSLane* from;
203 const MSLane* to;
204 double startPos;
205 double endPos;
206 };
207
216 MSLink(MSLane* predLane,
217 MSLane* succLane,
218 MSLane* via,
219 LinkDirection dir,
220 LinkState state,
221 double length,
222 double foeVisibilityDistance,
223 bool keepClear,
224 MSTrafficLightLogic* logic,
225 int tlLinkIdx,
226 bool indirect);
227
228
230 ~MSLink();
231
232 void addCustomConflict(const MSLane* from, const MSLane* to, double startPos, double endPos);
233
241 void setRequestInformation(int index, bool hasFoes, bool isCont,
242 const std::vector<MSLink*>& foeLinks, const std::vector<MSLane*>& foeLanes,
243 MSLane* internalLaneBefore = 0);
244
246 void addWalkingAreaFoe(const MSLane* lane) {
247 myWalkingAreaFoe = lane;
248 }
249
251 void addWalkingAreaFoeExit(const MSLane* lane) {
253 }
254
257 return myWalkingAreaFoe;
258 }
262
267 void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
268 const double arrivalSpeed, const double leaveSpeed, const bool setRequest,
269 const double arrivalSpeedBraking,
270 const SUMOTime waitingTime, double dist, double latOffset);
271
273 void setApproaching(const SUMOVehicle* approaching, ApproachingVehicleInformation ai);
274
276 void removeApproaching(const SUMOVehicle* veh);
277
278 void addBlockedLink(MSLink* link);
279
280 /* @brief return information about this vehicle if it is registered as
281 * approaching (dummy values otherwise)
282 * @note used for visualisation of link items */
283 ApproachingVehicleInformation getApproaching(const SUMOVehicle* veh) const;
284
288 }
289
291 void clearState();
292
300 bool opened(SUMOTime arrivalTime, double arrivalSpeed, double leaveSpeed, double vehicleLength,
301 double impatience, double decel, SUMOTime waitingTime,
302 double posLat = 0,
303 BlockingFoes* collectFoes = nullptr,
304 bool ignoreRed = false,
305 const SUMOTrafficObject* ego = nullptr) const;
306
322 bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
323 bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
324 BlockingFoes* collectFoes = nullptr, const SUMOTrafficObject* ego = nullptr, bool lastWasContRed = false) const;
325
326
327 bool isBlockingAnyone() const {
328 return myApproachingVehicles.size() != 0;
329 }
330
331 bool willHaveBlockedFoe() const;
332
333
334
344 bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, double speed, double decel) const;
345
350 std::pair<const SUMOVehicle*, const MSLink*> getFirstApproachingFoe(const MSLink* wrapAround) const;
351
353 return myJunction;
354 }
355
356
362 return myState;
363 }
364
365
371 return myOffState;
372 }
373
379 return myLastGreenState;
380 }
381
382
383 //@brief Returns the time of the last state change
385 return myLastStateChange;
386 }
387
388
394 return myDirection;
395 }
396
397
398
404 void setTLState(LinkState state, SUMOTime t);
405
406
411 inline MSLane* getLane() const {
412 return myLane;
413 }
414
415
420 inline int getIndex() const {
421 return myIndex;
422 }
423
425 inline int getTLIndex() const {
426 return myTLIndex;
427 }
428
430 inline const MSTrafficLightLogic* getTLLogic() const {
431 return myLogic;
432 }
433
437 inline bool havePriority() const {
438 return myState >= 'A' && myState <= 'Z';
439 }
440
444 inline bool haveRed() const {
446 }
447
448 inline bool haveYellow() const {
450 }
451
452 inline bool haveGreen() const {
454 }
455
456 inline bool isTLSControlled() const {
457 return myLogic != 0;
458 }
459
463
468 double getLength() const {
469 return myLength;
470 }
471
472
481 }
482
483
488 bool hasFoes() const {
489 return myHasFoes;
490 }
491
492 // @brief return whether the vehicle may continute past this link to wait within the intersection
493 bool isCont() const;
494
495
497 bool keepClear() const {
498 return myKeepClear;
499 }
500
502 bool isIndirect() const {
503 return myAmIndirect;
504 }
505
507 bool lastWasContMajor() const;
508
510 bool lastWasContState(LinkState linkState) const;
511
515 double getInternalLengthsAfter() const;
516
520 double getInternalLengthsBefore() const;
521
527 double getLengthsBeforeCrossing(const MSLane* foeLane) const;
528
529
535 double getLengthBeforeCrossing(const MSLane* foeLane) const;
536
537
542 inline MSLane* getViaLane() const {
543 return myInternalLane;
544 }
545
554 const LinkLeaders getLeaderInfo(const MSVehicle* ego, double dist, std::vector<const MSPerson*>* collectBlockers = 0, bool isShadowLink = false) const;
555
557 double getZipperSpeed(const MSVehicle* ego, const double dist, double vSafe,
558 SUMOTime arrivalTime,
559 const BlockingFoes* foes) const;
560
562 inline MSLane* getViaLaneOrLane() const {
563 return myInternalLane != nullptr ? myInternalLane : myLane;
564 }
565
566
568 inline const MSLane* getLaneBefore() const {
569 assert(myInternalLaneBefore == nullptr || myLaneBefore == myInternalLaneBefore); // lane before mismatch!
570 return myLaneBefore;
571 }
572
574 inline const MSLane* getInternalLaneBefore() const {
576 }
577
579 SUMOTime getLeaveTime(const SUMOTime arrivalTime, const double arrivalSpeed, const double leaveSpeed, const double vehicleLength) const;
580
582 void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
583
585 MSLink* getParallelLink(int direction) const;
586
589
591 inline bool fromInternalLane() const {
592 return myInternalLaneBefore != nullptr;
593 }
594
596 bool isEntryLink() const;
597
599 bool isConflictEntryLink() const;
600
602 bool isExitLink() const;
603
606
608 const MSLink* getCorrespondingExitLink() const;
609
611 const MSLink* getCorrespondingEntryLink() const;
612
614 bool isInternalJunctionLink() const;
615
618 return myMesoTLSPenalty;
619 }
620
622 double getGreenFraction() const {
623 return myGreenFraction;
624 }
625
627 void setMesoTLSPenalty(const SUMOTime penalty) {
628 myMesoTLSPenalty = penalty;
629 }
630
632 void setGreenFraction(const double fraction) {
633 myGreenFraction = fraction;
634 }
635
636 const std::vector<const MSLane*>& getFoeLanes() const {
637 return myFoeLanes;
638 }
639
640 const std::vector<ConflictInfo>& getConflicts() const {
641 return myConflicts;
642 }
643
644 const std::vector<MSLink*>& getFoeLinks() const {
645 return myFoeLinks;
646 }
647
649 void initParallelLinks();
650
652 inline double getLateralShift() const {
653 return myLateralShift;
654 }
655
657 std::string getDescription() const;
658
660 static void recheckSetRequestInformation();
661
662 static bool ignoreFoe(const SUMOTrafficObject* ego, const SUMOTrafficObject* foe);
663
664 static const double NO_INTERSECTION;
665
666private:
668 static inline bool unsafeMergeSpeeds(double leaderSpeed, double followerSpeed, double leaderDecel, double followerDecel) {
669 // XXX mismatch between continuous an discrete deceleration
670 return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
671 }
672
674 static bool couldBrakeForLeader(double followDist, double leaderDist, const MSVehicle* follow, const MSVehicle* leader);
675
676 MSLink* computeParallelLink(int direction);
677
679 void checkWalkingAreaFoe(const MSVehicle* ego, const MSLane* foeLane, std::vector<const MSPerson*>* collectBlockers, LinkLeaders& result) const;
680
682 bool isInFront(const MSVehicle* ego, const PositionVector& egoPath, const Position& pPos) const;
683
685 double isOnComingPed(const MSVehicle* ego, const MSPerson* p) const;
686
688 Position getFuturePosition(const MSPerson* p, double timeHorizon = 1) const;
689
690 bool blockedByFoe(const SUMOVehicle* veh, const ApproachingVehicleInformation& avi,
691 SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
692 bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
693 const SUMOTrafficObject* ego) const;
694
696 bool checkContOff() const;
697
699 bool contIntersect(const MSLane* lane, const MSLane* foe);
700
702 double computeDistToDivergence(const MSLane* lane, const MSLane* sibling, double minDist, bool sameSource) const;
703
705 static SUMOTime computeFoeArrivalTimeBraking(SUMOTime arrivalTime, const SUMOVehicle* foe, SUMOTime foeArrivalTime, double impatience, double dist, double& fasb);
706
708 static bool lateralOverlap(double posLat, double width, double posLat2, double width2);
709
711 const CustomConflict* getCustomConflict(const MSLane* foeLane) const;
712
713private:
716
719
721 std::set<MSLink*> myBlockedFoeLinks;
722
725
727 const int myTLIndex;
728
731
738
741
744
747 double myLength;
748
754
757
758 // @brief whether vehicles may continue past this link to wait within the intersection
760 // @brief whether vehicles may continue past this link to wait within the intersection after switching of the traffic light at this intersection
762
763 // @brief whether vehicles must keep the intersection clear if there is a downstream jam
765
768
769 /* @brief The preceding junction-internal lane, only used at
770 * - exit links (from internal lane to normal lane)
771 * - internal junction links (from internal lane to internal lane)
772 */
774
779
782
783 /* @brief lengths after the crossing point with foeLane
784 * (index corresponds to myFoeLanes)
785 * empty vector for entry links
786 * */
787 std::vector<ConflictInfo> myConflicts;
788
789 std::vector<CustomConflict> myCustomConflicts;
790
791 // TODO: documentation
792 std::vector<MSLink*> myFoeLinks;
793 std::vector<const MSLane*> myFoeLanes;
794
795 /* prioritized links when the traffic light is switched off (only needed for RightOfWay::ALLWAYSTOP)
796 * @note stored as a pointer to save space since it won't be used in most cases
797 */
798 std::vector<MSLink*>* myOffFoeLinks;
799
804
807
808 /* @brief Links with the same origin lane and the same destination edge that may
809 be in conflict for sublane simulation */
810 std::vector<MSLink*> mySublaneFoeLinks;
811 /* @brief Links with the same origin lane and different destination edge that may
812 be in conflict for sublane simulation */
813 std::vector<MSLink*> mySublaneFoeLinks2;
814
815 /* @brief Internal Lanes with the same origin lane and the same destination edge that may
816 be in conflict for sublane simulation */
817 std::vector<MSLane*> mySublaneFoeLanes;
818
821
823 static std::set<std::pair<MSLink*, MSLink*> > myRecheck;
824
827
829 const bool myAmIndirect;
830
832 double myRadius;
833
836
838 MSLink(const MSLink& s);
839
842
843};
long long int SUMOTime
Definition GUI.h:36
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
@ TURN
The link is a 180 degree turn.
@ TURN_LEFTHAND
The link is a 180 degree turn (left-hand network)
LinkState
The right-of-way state of a link between two lanes used when constructing a NBTrafficLightLogic,...
@ LINKSTATE_TL_REDYELLOW
The link has red light (must brake) but indicates upcoming green.
@ LINKSTATE_TL_YELLOW_MAJOR
The link has yellow light, may pass.
@ LINKSTATE_TL_GREEN_MAJOR
The link has green light, may pass.
@ LINKSTATE_TL_YELLOW_MINOR
The link has yellow light, has to brake anyway.
@ LINKSTATE_TL_RED
The link has red light (must brake)
@ LINKSTATE_TL_GREEN_MINOR
The link has green light, has to brake.
The base class for an intersection.
Definition MSJunction.h:58
Representation of a lane in the micro simulation.
Definition MSLane.h:84
The parent class for traffic light logics.
Representation of a vehicle in the micro simulation.
Definition MSVehicle.h:77
Static storage of an output device and its base (abstract) implementation.
A point in 2D or 3D with translation and scaling methods.
Definition Position.h:37
A list of positions.
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition SUMOVehicle.h:62
Definition json.hpp:4471