Eclipse SUMO - Simulation of Urban MObility
MSLink.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3// Copyright (C) 2002-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/****************************************************************************/
20// A connnection 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
70 struct LinkLeader {
71 LinkLeader(MSVehicle* _veh, double _gap, double _distToCrossing, bool _fromLeft = true, bool _inTheWay = false) :
72 vehAndGap(std::make_pair(_veh, _gap)),
73 distToCrossing(_distToCrossing),
74 fromLeft(_fromLeft),
75 inTheWay(_inTheWay) {
76 }
77
78 std::pair<MSVehicle*, double> vehAndGap;
82 };
83
84 typedef std::vector<LinkLeader> LinkLeaders;
85
95 ApproachingVehicleInformation(const SUMOTime _arrivalTime, const SUMOTime _leavingTime,
96 const double _arrivalSpeed, const double _leaveSpeed,
97 const bool _willPass,
98 const double _arrivalSpeedBraking,
99 const SUMOTime _waitingTime,
100 const double _dist,
101 const double _speed,
102 const double _latOffset
103 ) :
104 arrivalTime(_arrivalTime), leavingTime(_leavingTime),
105 arrivalSpeed(_arrivalSpeed), leaveSpeed(_leaveSpeed),
106 willPass(_willPass),
107 arrivalSpeedBraking(_arrivalSpeedBraking),
108 waitingTime(_waitingTime),
109 dist(_dist),
110 speed(_speed),
111 latOffset(_latOffset) {
112 }
113
119 const double arrivalSpeed;
121 const double leaveSpeed;
123 const bool willPass;
129 const double dist;
131 const double speed;
133 const double latOffset;
134
135 };
136
137 typedef std::map<const SUMOVehicle*, const ApproachingVehicleInformation, ComparatorNumericalIdLess> ApproachInfos;
138 typedef std::vector<const SUMOVehicle*> BlockingFoes;
139
148 MSLink(MSLane* predLane,
149 MSLane* succLane,
150 MSLane* via,
151 LinkDirection dir,
152 LinkState state,
153 double length,
154 double foeVisibilityDistance,
155 bool keepClear,
156 MSTrafficLightLogic* logic,
157 int tlLinkIdx,
158 bool indirect);
159
160
162 ~MSLink();
163
164
172 void setRequestInformation(int index, bool hasFoes, bool isCont,
173 const std::vector<MSLink*>& foeLinks, const std::vector<MSLane*>& foeLanes,
174 MSLane* internalLaneBefore = 0);
175
177 void addWalkingAreaFoe(const MSLane* lane) {
178 myWalkingAreaFoe = lane;
179 }
180
182 void addWalkingAreaFoeExit(const MSLane* lane) {
184 }
185
188 return myWalkingAreaFoe;
189 }
192 }
193
198 void setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime,
199 const double arrivalSpeed, const double leaveSpeed, const bool setRequest,
200 const double arrivalSpeedBraking,
201 const SUMOTime waitingTime, double dist, double latOffset);
202
204 void setApproaching(const SUMOVehicle* approaching, ApproachingVehicleInformation ai);
205
207 void removeApproaching(const SUMOVehicle* veh);
208
209 void addBlockedLink(MSLink* link);
210
211 /* @brief return information about this vehicle if it is registered as
212 * approaching (dummy values otherwise)
213 * @note used for visualisation of link items */
214 ApproachingVehicleInformation getApproaching(const SUMOVehicle* veh) const;
215
219 }
220
222 void clearState();
223
231 bool opened(SUMOTime arrivalTime, double arrivalSpeed, double leaveSpeed, double vehicleLength,
232 double impatience, double decel, SUMOTime waitingTime,
233 double posLat = 0,
234 BlockingFoes* collectFoes = nullptr,
235 bool ignoreRed = false,
236 const SUMOTrafficObject* ego = nullptr) const;
237
253 bool blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
254 bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
255 BlockingFoes* collectFoes = nullptr, const SUMOTrafficObject* ego = nullptr, bool lastWasContRed = false) const;
256
257
258 bool isBlockingAnyone() const {
259 return myApproachingVehicles.size() != 0;
260 }
261
262 bool willHaveBlockedFoe() const;
263
264
265
275 bool hasApproachingFoe(SUMOTime arrivalTime, SUMOTime leaveTime, double speed, double decel) const;
276
281 std::pair<const SUMOVehicle*, const MSLink*> getFirstApproachingFoe(const MSLink* wrapAround) const;
282
284 return myJunction;
285 }
286
287
293 return myState;
294 }
295
296
302 return myOffState;
303 }
304
310 return myLastGreenState;
311 }
312
313
314 //@brief Returns the time of the last state change
316 return myLastStateChange;
317 }
318
319
325 return myDirection;
326 }
327
328
329
335 void setTLState(LinkState state, SUMOTime t);
336
337
342 inline MSLane* getLane() const {
343 return myLane;
344 }
345
346
351 inline int getIndex() const {
352 return myIndex;
353 }
354
356 inline int getTLIndex() const {
357 return myTLIndex;
358 }
359
361 inline const MSTrafficLightLogic* getTLLogic() const {
362 return myLogic;
363 }
364
368 inline bool havePriority() const {
369 return myState >= 'A' && myState <= 'Z';
370 }
371
375 inline bool haveRed() const {
377 }
378
379 inline bool haveYellow() const {
381 }
382
383 inline bool haveGreen() const {
385 }
386
387 inline bool isTLSControlled() const {
388 return myLogic != 0;
389 }
390
391 inline bool isTurnaround() const {
393 }
394
399 double getLength() const {
400 return myLength;
401 }
402
403
412 }
413
414
419 bool hasFoes() const {
420 return myHasFoes;
421 }
422
423 // @brief return whether the vehicle may continute past this link to wait within the intersection
424 bool isCont() const;
425
426
428 bool keepClear() const {
429 return myKeepClear;
430 }
431
433 bool isIndirect() const {
434 return myAmIndirect;
435 }
436
438 bool lastWasContMajor() const;
439
441 bool lastWasContState(LinkState linkState) const;
442
446 double getInternalLengthsAfter() const;
447
451 double getInternalLengthsBefore() const;
452
458 double getLengthsBeforeCrossing(const MSLane* foeLane) const;
459
460
466 double getLengthBeforeCrossing(const MSLane* foeLane) const;
467
468
473 inline MSLane* getViaLane() const {
474 return myInternalLane;
475 }
476
485 const LinkLeaders getLeaderInfo(const MSVehicle* ego, double dist, std::vector<const MSPerson*>* collectBlockers = 0, bool isShadowLink = false) const;
486
488 double getZipperSpeed(const MSVehicle* ego, const double dist, double vSafe,
489 SUMOTime arrivalTime,
490 BlockingFoes* collectFoes) const;
491
493 inline MSLane* getViaLaneOrLane() const {
494 return myInternalLane != nullptr ? myInternalLane : myLane;
495 }
496
497
499 inline const MSLane* getLaneBefore() const {
500 assert(myInternalLaneBefore == nullptr || myLaneBefore == myInternalLaneBefore); // lane before mismatch!
501 return myLaneBefore;
502 }
503
505 inline const MSLane* getInternalLaneBefore() const {
507 }
508
510 SUMOTime getLeaveTime(const SUMOTime arrivalTime, const double arrivalSpeed, const double leaveSpeed, const double vehicleLength) const;
511
513 void writeApproaching(OutputDevice& od, const std::string fromLaneID) const;
514
516 MSLink* getParallelLink(int direction) const;
517
520
522 inline bool fromInternalLane() const {
523 return myInternalLaneBefore != nullptr;
524 }
525
527 bool isEntryLink() const;
528
530 bool isConflictEntryLink() const;
531
533 bool isExitLink() const;
534
537
539 const MSLink* getCorrespondingExitLink() const;
540
542 const MSLink* getCorrespondingEntryLink() const;
543
545 bool isInternalJunctionLink() const;
546
549 return myMesoTLSPenalty;
550 }
551
553 double getGreenFraction() const {
554 return myGreenFraction;
555 }
556
558 void setMesoTLSPenalty(const SUMOTime penalty) {
559 myMesoTLSPenalty = penalty;
560 }
561
563 void setGreenFraction(const double fraction) {
564 myGreenFraction = fraction;
565 }
566
567 const std::vector<const MSLane*>& getFoeLanes() const {
568 return myFoeLanes;
569 }
570
571 const std::vector<std::pair<double, double> >& getLengthsBehindCrossing() const {
573 }
574
575 const std::vector<MSLink*>& getFoeLinks() const {
576 return myFoeLinks;
577 }
578
580 void initParallelLinks();
581
583 inline double getLateralShift() const {
584 return myLateralShift;
585 }
586
588 std::string getDescription() const;
589
590private:
592 static inline bool unsafeMergeSpeeds(double leaderSpeed, double followerSpeed, double leaderDecel, double followerDecel) {
593 // XXX mismatch between continuous an discrete deceleration
594 return (leaderSpeed * leaderSpeed / leaderDecel) <= (followerSpeed * followerSpeed / followerDecel);
595 }
596
598 static bool couldBrakeForLeader(double followDist, double leaderDist, const MSVehicle* follow, const MSVehicle* leader);
599
600 MSLink* computeParallelLink(int direction);
601
603 void checkWalkingAreaFoe(const MSVehicle* ego, const MSLane* foeLane, std::vector<const MSPerson*>* collectBlockers, LinkLeaders& result) const;
604
606 bool isInFront(const MSVehicle* ego, const PositionVector& egoPath, const MSPerson* p) const;
607
608 bool blockedByFoe(const SUMOVehicle* veh, const ApproachingVehicleInformation& avi,
609 SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
610 bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
611 const SUMOTrafficObject* ego) const;
612
614 bool checkContOff() const;
615
617 bool contIntersect(const MSLane* lane, const MSLane* foe);
618
620 double computeDistToDivergence(const MSLane* lane, const MSLane* sibling, double minDist, bool sameSource) const;
621
623 static SUMOTime computeFoeArrivalTimeBraking(SUMOTime arrivalTime, const SUMOVehicle* foe, SUMOTime foeArrivalTime, double impatience, double dist, double& fasb);
624
626 static bool lateralOverlap(double posLat, double width, double posLat2, double width2);
627
628 static bool ignoreFoe(const SUMOTrafficObject* ego, const SUMOVehicle* foe);
629
630private:
633
636
638 std::set<MSLink*> myBlockedFoeLinks;
639
642
644 const int myTLIndex;
645
648
655
658
661
664 double myLength;
665
671
674
675 // @brief whether vehicles may continue past this link to wait within the intersection
677 // @brief whether vehicles may continue past this link to wait within the intersection after switching of the traffic light at this intersection
679
680 // @brief whether vehicles must keep the intersection clear if there is a downstream jam
682
685
686 /* @brief The preceding junction-internal lane, only used at
687 * - exit links (from internal lane to normal lane)
688 * - internal junction links (from internal lane to internal lane)
689 */
691
696
699
700 /* @brief lengths after the crossing point with foeLane
701 * (lengthOnThis, lengthOnFoe)
702 * (index corresponds to myFoeLanes)
703 * empty vector for entry links
704 * */
705 std::vector<std::pair<double, double> > myLengthsBehindCrossing;
706
707 // TODO: documentation
708 std::vector<MSLink*> myFoeLinks;
709 std::vector<const MSLane*> myFoeLanes;
710
715
718
719 /* @brief Links with the same origin lane and the same destination edge that may
720 be in conflict for sublane simulation */
721 std::vector<MSLink*> mySublaneFoeLinks;
722 /* @brief Links with the same origin lane and different destination edge that may
723 be in conflict for sublane simulation */
724 std::vector<MSLink*> mySublaneFoeLinks2;
725
726 /* @brief Internal Lanes with the same origin lane and the same destination edge that may
727 be in conflict for sublane simulation */
728 std::vector<MSLane*> mySublaneFoeLanes;
729
732
735
737 const bool myAmIndirect;
738
740 double myRadius;
741
744
746 MSLink(const MSLink& s);
747
750
751};
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.
Definition: OutputDevice.h:61
A list of positions.
Representation of a vehicle, person, or container.
Representation of a vehicle.
Definition: SUMOVehicle.h:60
Definition: json.hpp:4471