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-2024 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
174 ApproachingPersonInformation(const SUMOTime _arrivalTime, const SUMOTime _leavingTime) :
175 arrivalTime(_arrivalTime), leavingTime(_leavingTime) {}
180 };
181
182 typedef std::map<const SUMOVehicle*, const ApproachingVehicleInformation, ComparatorNumericalIdLess> ApproachInfos;
183 typedef std::vector<const SUMOTrafficObject*> BlockingFoes;
184 typedef std::map<const MSPerson*, ApproachingPersonInformation> PersonApproachInfos;
185
192
195
196 ConflictInfo(double lbc, double cs, ConflictFlag fl = CONFLICT_DEFAULT) :
199 conflictSize(cs),
200 flag(fl)
201 {}
208
210
211 double getFoeLengthBehindCrossing(const MSLink* foeExitLink) const;
212 double getFoeConflictSize(const MSLink* foeExitLink) const;
213 double getLengthBehindCrossing(const MSLink* exitLink) const;
214 };
215
218 CustomConflict(const MSLane* f, const MSLane* t, double s, double e) :
219 from(f), to(t), startPos(s), endPos(e) {}
220 const MSLane* from;
221 const MSLane* to;
222 double startPos;
223 double endPos;
224 };
225
234 MSLink(MSLane* predLane,
235 MSLane* succLane,
236 MSLane* via,
237 LinkDirection dir,
238 LinkState state,
239 double length,
240 double foeVisibilityDistance,
241 bool keepClear,
242 MSTrafficLightLogic* logic,
243 int tlLinkIdx,
244 bool indirect);
245
246
248 ~MSLink();
249
250 void addCustomConflict(const MSLane* from, const MSLane* to, double startPos, double endPos);
251
259 void setRequestInformation(int index, bool hasFoes, bool isCont,
260 const std::vector<MSLink*>& foeLinks, const std::vector<MSLane*>& foeLanes,
261 MSLane* internalLaneBefore = 0);
262
264 void addWalkingAreaFoe(const MSLane* lane) {
265 myWalkingAreaFoe = lane;
266 }
267
269 void addWalkingAreaFoeExit(const MSLane* lane) {
271 }
272
275 return myWalkingAreaFoe;
276 }
280
285 void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
286 const double arrivalSpeed, const double leaveSpeed, const bool setRequest,
287 const double arrivalSpeedBraking,
288 const SUMOTime waitingTime, double dist, double latOffset);
289
291 void setApproaching(const SUMOVehicle* approaching, ApproachingVehicleInformation ai);
292
294 void setApproachingPerson(const MSPerson* approaching, const SUMOTime arrivalTime, const SUMOTime leaveTime);
295
297 void removeApproaching(const SUMOVehicle* veh);
298
300 void removeApproachingPerson(const MSPerson* person);
301
302 /* @brief return information about this vehicle if it is registered as
303 * approaching (dummy values otherwise)
304 * @note used for visualisation of link items */
305 ApproachingVehicleInformation getApproaching(const SUMOVehicle* veh) const;
306
310 }
311
316
318 void clearState();
319
327 bool opened(SUMOTime arrivalTime, double arrivalSpeed, double leaveSpeed, double vehicleLength,
328 double impatience, double decel, SUMOTime waitingTime,
329 double posLat = 0,
330 BlockingFoes* collectFoes = nullptr,
331 bool ignoreRed = false,
332 const SUMOTrafficObject* ego = nullptr,
333 double dist = -1) const;
334
350 bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
351 bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
352 BlockingFoes* collectFoes = nullptr, const SUMOTrafficObject* ego = nullptr, bool lastWasContRed = false, double dist = -1) const;
353
354
364 bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, double speed, double decel) const;
365
370 std::pair<const SUMOVehicle*, const MSLink*> getFirstApproachingFoe(const MSLink* wrapAround) const;
371
373 return myJunction;
374 }
375
376
382 return myState;
383 }
384
385
391 return myOffState;
392 }
393
399 return myLastGreenState;
400 }
401
402
403 //@brief Returns the time of the last state change
405 return myLastStateChange;
406 }
407
408
414 return myDirection;
415 }
416
417
418
424 void setTLState(LinkState state, SUMOTime t);
425
429 void setTLLogic(const MSTrafficLightLogic* logic);
430
435 inline MSLane* getLane() const {
436 return myLane;
437 }
438
439
444 inline int getIndex() const {
445 return myIndex;
446 }
447
449 inline int getTLIndex() const {
450 return myTLIndex;
451 }
452
454 inline const MSTrafficLightLogic* getTLLogic() const {
455 return myLogic;
456 }
457
461 inline bool havePriority() const {
462 return myState >= 'A' && myState <= 'Z';
463 }
464
465 inline bool haveOffPriority() const {
466 return myOffState >= 'A' && myOffState <= 'Z';
467 }
468
472 inline bool haveRed() const {
474 }
475
476 inline bool haveYellow() const {
478 }
479
480 inline bool haveGreen() const {
482 }
483
484 inline bool mustStop() const {
486 }
487
488 inline bool isTLSControlled() const {
489 return myLogic != 0;
490 }
491
495
500 double getLength() const {
501 return myLength;
502 }
503
504
513 }
514
515 double getDistToFoePedCrossing() const {
517 }
518
523 bool hasFoes() const {
524 return myHasFoes;
525 }
526
527 // @brief return whether the vehicle may continute past this link to wait within the intersection
528 bool isCont() const;
529
530
532 bool keepClear() const {
533 return myKeepClear;
534 }
535
537 bool isIndirect() const {
538 return myAmIndirect;
539 }
540
542 bool lastWasContMajor() const;
543
545 bool lastWasContState(LinkState linkState) const;
546
550 double getInternalLengthsAfter() const;
551
555 double getInternalLengthsBefore() const;
556
562 double getLengthsBeforeCrossing(const MSLane* foeLane) const;
563
564
570 double getLengthBeforeCrossing(const MSLane* foeLane) const;
571
572
577 inline MSLane* getViaLane() const {
578 return myInternalLane;
579 }
580
589 const LinkLeaders getLeaderInfo(const MSVehicle* ego, double dist, std::vector<const MSPerson*>* collectBlockers = 0, bool isShadowLink = false) const;
590
592 double getZipperSpeed(const MSVehicle* ego, const double dist, double vSafe,
593 SUMOTime arrivalTime,
594 const BlockingFoes* foes) const;
595
597 inline MSLane* getViaLaneOrLane() const {
598 return myInternalLane != nullptr ? myInternalLane : myLane;
599 }
600
601
603 inline const MSLane* getLaneBefore() const {
604 assert(myInternalLaneBefore == nullptr || myLaneBefore == myInternalLaneBefore); // lane before mismatch!
605 return myLaneBefore;
606 }
607
609 inline const MSLane* getInternalLaneBefore() const {
611 }
612
614 SUMOTime getLeaveTime(const SUMOTime arrivalTime, const double arrivalSpeed, const double leaveSpeed, const double vehicleLength) const;
615
617 void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
618
620 MSLink* getParallelLink(int direction) const;
621
624
626 inline bool fromInternalLane() const {
627 return myInternalLaneBefore != nullptr;
628 }
629
631 bool isEntryLink() const;
632
634 bool isConflictEntryLink() const;
635
637 bool isExitLink() const;
638
641
643 const MSLink* getCorrespondingExitLink() const;
644
646 const MSLink* getCorrespondingEntryLink() const;
647
649 bool isInternalJunctionLink() const;
650
653 return myMesoTLSPenalty;
654 }
655
657 double getGreenFraction() const {
658 return myGreenFraction;
659 }
660
662 void setMesoTLSPenalty(const SUMOTime penalty) {
663 myMesoTLSPenalty = penalty;
664 }
665
667 void setGreenFraction(const double fraction) {
668 myGreenFraction = fraction;
669 }
670
671 const std::vector<const MSLane*>& getFoeLanes() const {
672 return myFoeLanes;
673 }
674
675 const std::vector<ConflictInfo>& getConflicts() const {
676 return myConflicts;
677 }
678
679 const std::vector<MSLink*>& getFoeLinks() const {
680 return myFoeLinks;
681 }
682
685 return myPermissions;
686 }
687
689 void initParallelLinks();
690
692 inline double getLateralShift() const {
693 return myLateralShift;
694 }
695
697 std::string getDescription() const;
698
700 std::pair<const SUMOVehicle* const, const ApproachingVehicleInformation> getClosest() const;
701
702
704 static void recheckSetRequestInformation();
705
706 static bool ignoreFoe(const SUMOTrafficObject* ego, const SUMOTrafficObject* foe);
707
708 static const double NO_INTERSECTION;
709
710private:
712 static inline bool unsafeMergeSpeeds(double leaderSpeed, double followerSpeed, double leaderDecel, double followerDecel) {
713 // XXX mismatch between continuous an discrete deceleration
714 return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
715 }
716
718 static bool couldBrakeForLeader(double followDist, double leaderDist, const MSVehicle* follow, const MSVehicle* leader);
719
720 MSLink* computeParallelLink(int direction);
721
723 void checkWalkingAreaFoe(const MSVehicle* ego, const MSLane* foeLane, std::vector<const MSPerson*>* collectBlockers, LinkLeaders& result) const;
724
726 bool isInFront(const MSVehicle* ego, const PositionVector& egoPath, const Position& pPos) const;
727
729 double isOnComingPed(const MSVehicle* ego, const MSPerson* p) const;
730
732 Position getFuturePosition(const MSPerson* p, double timeHorizon = 1) const;
733
734 bool blockedByFoe(const SUMOVehicle* veh, const ApproachingVehicleInformation& avi,
735 SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
736 bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
737 const SUMOTrafficObject* ego) const;
738
740 bool checkContOff() const;
741
743 bool contIntersect(const MSLane* lane, const MSLane* foe);
744
746 double computeDistToDivergence(const MSLane* lane, const MSLane* sibling, double minDist, bool sameSource) const;
747
749 static SUMOTime computeFoeArrivalTimeBraking(SUMOTime arrivalTime, const SUMOVehicle* foe, SUMOTime foeArrivalTime, double impatience, double dist, double& fasb);
750
752 static bool lateralOverlap(double posLat, double width, double posLat2, double width2);
753
755 const CustomConflict* getCustomConflict(const MSLane* foeLane) const;
756
758 void updateDistToFoePedCrossing(double dist);
759
760private:
763
766
769
772
774 const int myTLIndex;
775
778
785
788
791
794 double myLength;
795
801
804
807
808 // @brief whether vehicles may continue past this link to wait within the intersection
810 // @brief whether vehicles may continue past this link to wait within the intersection after switching of the traffic light at this intersection
812
813 // @brief whether vehicles must keep the intersection clear if there is a downstream jam
815
818
819 /* @brief The preceding junction-internal lane, only used at
820 * - exit links (from internal lane to normal lane)
821 * - internal junction links (from internal lane to internal lane)
822 */
824
829
832
833 /* @brief lengths after the crossing point with foeLane
834 * (index corresponds to myFoeLanes)
835 * empty vector for entry links
836 * */
837 std::vector<ConflictInfo> myConflicts;
838
839 std::vector<CustomConflict> myCustomConflicts;
840
841 // TODO: documentation
842 std::vector<MSLink*> myFoeLinks;
843 std::vector<const MSLane*> myFoeLanes;
844
845 /* prioritized links when the traffic light is switched off (only needed for RightOfWay::ALLWAYSTOP)
846 * @note stored as a pointer to save space since it won't be used in most cases
847 */
848 std::vector<MSLink*>* myOffFoeLinks;
849
854
857
858 /* @brief Links with the same origin lane and the same destination edge that may
859 be in conflict for sublane simulation */
860 std::vector<MSLink*> mySublaneFoeLinks;
861 /* @brief Links with the same origin lane and different destination edge that may
862 be in conflict for sublane simulation */
863 std::vector<MSLink*> mySublaneFoeLinks2;
864
865 /* @brief Internal Lanes with the same origin lane and the same destination edge that may
866 be in conflict for sublane simulation */
867 std::vector<MSLane*> mySublaneFoeLanes;
868
871
873 static std::set<std::pair<MSLink*, MSLink*> > myRecheck;
874
877
879 const bool myAmIndirect;
880
882 double myRadius;
883
886
889
891 MSLink(const MSLink& s);
892
895
896};
long long int SUMOTime
Definition GUI.h:36
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
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_ALLWAY_STOP
This is an uncontrolled, all-way stop link.
@ LINKSTATE_STOP
This is an uncontrolled, minor link, has to stop.
@ 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