-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
MSLink.cpp
2084 lines (1949 loc) · 99.7 KB
/
MSLink.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************/
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
// Copyright (C) 2001-2023 German Aerospace Center (DLR) and others.
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0/
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License 2.0 are satisfied: GNU General Public License, version 2
// or later which is available at
// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
/****************************************************************************/
/// @file MSLink.cpp
/// @author Daniel Krajzewicz
/// @author Jakob Erdmann
/// @author Michael Behrisch
/// @author Laura Bieker
/// @date Sept 2002
///
// A connection between lanes
/****************************************************************************/
#include <config.h>
#include <iostream>
#include <algorithm>
#include <limits>
#include <utils/iodevices/OutputDevice.h>
#include <utils/common/RandHelper.h>
#include <utils/common/StringTokenizer.h>
#include "MSNet.h"
#include "MSJunction.h"
#include "MSJunctionLogic.h"
#include "MSLink.h"
#include "MSLane.h"
#include <microsim/transportables/MSPerson.h>
#include <microsim/transportables/MSTransportableControl.h>
#include "MSEdge.h"
#include "MSGlobals.h"
#include "MSVehicle.h"
#include <microsim/lcmodels/MSAbstractLaneChangeModel.h>
#include <microsim/transportables/MSPModel.h>
//#define MSLink_DEBUG_CROSSING_POINTS
//#define MSLink_DEBUG_CROSSING_POINTS_DETAILS
//#define MSLink_DEBUG_OPENED
//#define DEBUG_APPROACHING
//#define DEBUG_ZIPPER
//#define DEBUG_WALKINGAREA
//#define DEBUG_COND (myLane->getID()=="43[0]_0" && myLaneBefore->getID()==":33_0_0")
//#define DEBUG_COND (myLane->getID()=="end_0")
//#define DEBUG_COND (true)
#define DEBUG_COND2(obj) (obj->isSelected())
//#define DEBUG_COND2(obj) (obj->getID() == "train2")
//#define DEBUG_COND_ZIPPER (gDebugFlag1)
//#define DEBUG_COND_ZIPPER (true)
#define DEBUG_COND_ZIPPER (ego->isSelected())
// ===========================================================================
// static member variables
// ===========================================================================
#define INVALID_TIME -1000
// the default safety gap when passing before oncoming pedestrians
#define JM_CROSSING_GAP_DEFAULT 10
// minimim width between sibling lanes to qualify as non-overlapping
#define DIVERGENCE_MIN_WIDTH 2.5
const SUMOTime MSLink::myLookaheadTime = TIME2STEPS(1);
// additional caution is needed when approaching a zipper link
const SUMOTime MSLink::myLookaheadTimeZipper = TIME2STEPS(4);
std::set<std::pair<MSLink*, MSLink*> > MSLink::myRecheck;
const double MSLink::NO_INTERSECTION(10000);
// ===========================================================================
// ConflictInfo member method definitions
// ===========================================================================
double
MSLink::ConflictInfo::getFoeLengthBehindCrossing(const MSLink* foeExitLink) const {
if (flag == CONFLICT_DUMMY_MERGE) {
return 0;
} else if (foeConflictIndex >= 0) {
return foeExitLink->myConflicts[foeConflictIndex].lengthBehindCrossing;
} else {
return -NO_INTERSECTION;
}
}
double
MSLink::ConflictInfo::getFoeConflictSize(const MSLink* foeExitLink) const {
if (foeConflictIndex >= 0) {
return foeExitLink->myConflicts[foeConflictIndex].conflictSize;
} else {
return 0;
}
}
double
MSLink::ConflictInfo::getLengthBehindCrossing(const MSLink* exitLink) const {
if (flag == CONFLICT_STOP_AT_INTERNAL_JUNCTION) {
return exitLink->getInternalLaneBefore()->getLength();
} else {
return lengthBehindCrossing;
}
}
// ===========================================================================
// member method definitions
// ===========================================================================
MSLink::MSLink(MSLane* predLane, MSLane* succLane, MSLane* via, LinkDirection dir, LinkState state,
double length, double foeVisibilityDistance, bool keepClear,
MSTrafficLightLogic* logic, int tlIndex,
bool indirect) :
myLane(succLane),
myLaneBefore(predLane),
myIndex(-1),
myTLIndex(tlIndex),
myLogic(logic),
myState(state),
myLastGreenState(LINKSTATE_TL_GREEN_MINOR),
myOffState(state),
myLastStateChange(SUMOTime_MIN / 2), // a large negative value, but avoid overflows when subtracting
myDirection(dir),
myLength(length),
myFoeVisibilityDistance(foeVisibilityDistance),
myHasFoes(false),
myAmCont(false),
myAmContOff(false),
myKeepClear(keepClear),
myInternalLane(via),
myInternalLaneBefore(nullptr),
myMesoTLSPenalty(0),
myGreenFraction(1),
myLateralShift(0),
myOffFoeLinks(nullptr),
myWalkingAreaFoe(nullptr),
myWalkingAreaFoeExit(nullptr),
myHavePedestrianCrossingFoe(false),
myParallelRight(nullptr),
myParallelLeft(nullptr),
myAmIndirect(indirect),
myRadius(std::numeric_limits<double>::max()),
myJunction(nullptr) {
if (MSGlobals::gLateralResolution > 0) {
// detect lateral shift from lane geometries
//std::cout << "DEBUG link=" << myLaneBefore->getID() << "->" << getViaLaneOrLane()->getID() << " hasInternal=" << MSNet::getInstance()->hasInternalLinks() << " shapeBefore=" << myLaneBefore->getShape().back() << " shapeFront=" << getViaLaneOrLane()->getShape().front() << "\n";
if ((myInternalLane != nullptr || predLane->isInternal())
&& myLaneBefore->getShape().back() != getViaLaneOrLane()->getShape().front()) {
PositionVector from = myLaneBefore->getShape();
const PositionVector& to = getViaLaneOrLane()->getShape();
const double dist = from.back().distanceTo2D(to.front());
// figure out direction of shift
try {
from.move2side(dist);
} catch (InvalidArgument&) {
}
myLateralShift = (from.back().distanceTo2D(to.front()) < dist) ? dist : -dist;
if (MSGlobals::gLefthand) {
myLateralShift *= -1;
}
//std::cout << " lateral shift link=" << myLaneBefore->getID() << "->" << getViaLaneOrLane()->getID() << " dist=" << dist << " shift=" << myLateralShift << "\n";
}
}
}
MSLink::~MSLink() {
delete myOffFoeLinks;
}
void
MSLink::addCustomConflict(const MSLane* from, const MSLane* to, double startPos, double endPos) {
myCustomConflicts.push_back(CustomConflict(from, to, startPos, endPos));
}
const MSLink::CustomConflict*
MSLink::getCustomConflict(const MSLane* foeLane) const {
if (myCustomConflicts.size() > 0) {
const MSLane* foeFrom = foeLane->getNormalPredecessorLane();
const MSLane* foeTo = foeLane->getNormalSuccessorLane();
for (const CustomConflict& cc : myCustomConflicts) {
if (cc.from == foeFrom && cc.to == foeTo) {
return &cc;
}
}
}
return nullptr;
}
void
MSLink::setRequestInformation(int index, bool hasFoes, bool isCont,
const std::vector<MSLink*>& foeLinks,
const std::vector<MSLane*>& foeLanes,
MSLane* internalLaneBefore) {
//#ifdef MSLink_DEBUG_CROSSING_POINTS
// std::cout << " setRequestInformation() for junction " << getViaLaneOrLane()->getEdge().getFromJunction()->getID()
// << "\nInternalLanes = " << toString(getViaLaneOrLane()->getEdge().getFromJunction()->getInternalLanes())
// << std::endl;
//#endif
myIndex = index;
myHasFoes = hasFoes;
myAmCont = isCont;
myFoeLinks = foeLinks;
for (MSLane* foeLane : foeLanes) {
// cannot assign vector due to const-ness
myFoeLanes.push_back(foeLane);
}
myJunction = const_cast<MSJunction*>(myLane->getEdge().getFromJunction()); // junctionGraph is initialized after the whole network is loaded
myAmContOff = isCont && myLogic != nullptr && internalLaneBefore == nullptr && checkContOff();
myInternalLaneBefore = internalLaneBefore;
MSLane* lane = nullptr;
if (internalLaneBefore != nullptr) {
// this is an exit link. compute crossing points with all foeLanes
lane = internalLaneBefore;
//} else if (myLane->getEdge().isCrossing()) {
// // this is the link to a pedestrian crossing. compute crossing points with all foeLanes
// // @note not currently used by pedestrians
// lane = myLane;
}
const MSLink* entryLink = getCorrespondingEntryLink();
if (entryLink->getOffState() == LinkState::LINKSTATE_ALLWAY_STOP && entryLink->getTLLogic() != nullptr) {
// TLS has "normal" right of way rules but all conflicting links are foes when switching TLS off
// (unless it's an internal junction link which should ignore all foes and should be ignored by all foes
myOffFoeLinks = new std::vector<MSLink*>();
if (isEntryLink()) {
for (MSLane* foeLane : foeLanes) {
assert(foeLane->isInternal());
MSLink* viaLink = foeLane->getIncomingLanes().front().viaLink;
if (viaLink->getLaneBefore()->isNormal()) {
myOffFoeLinks->push_back(viaLink);
}
}
}
}
#ifdef MSLink_DEBUG_CROSSING_POINTS
std::cout << "link " << myIndex << " to " << getViaLaneOrLane()->getID() << " internalLaneBefore=" << (lane == 0 ? "NULL" : lane->getID()) << " has foes: " << toString(foeLanes) << "\n";
#endif
if (lane != nullptr) {
const bool beforeInternalJunction = lane->getLinkCont()[0]->getViaLaneOrLane()->getEdge().isInternal();
if (lane->getIncomingLanes().size() != 1) {
throw ProcessError("Internal lane '" + lane->getID() + "' has " + toString(lane->getIncomingLanes().size()) + " predecessors");
}
const MSLink* junctionEntryLink = lane->getEntryLink();
const bool isSecondPart = isExitLinkAfterInternalJunction();
// compute crossing points
for (const MSLane* foeLane : myFoeLanes) {
const CustomConflict* cc = junctionEntryLink != nullptr ? junctionEntryLink->getCustomConflict(foeLane) : nullptr;
if (cc != nullptr) {
// handle custom conflict definition
double startPos = cc->startPos;
const double conflictSize = cc->endPos - cc->startPos;
if (isSecondPart) {
startPos -= junctionEntryLink->getViaLane()->getLength();
}
// the foe connection may be split at an internal
// junction, we need to figure out whether the current
// foeLane is the intended target for the custom conflict
// There are two possibilities:
// a) We have no custom conflict for the reverse pair of connections
// -> just check whether lane and foeLane intersect
// b) We have a "reverse" custom conflict
// -> check whether it covers the foeLane
const CustomConflict* rcc = foeLane->getEntryLink()->getCustomConflict(lane);
bool haveIntersection = false;
if (rcc == nullptr) {
// a)
haveIntersection = lane->getShape().intersectsAtLengths2D(foeLane->getShape()).size() > 0;
} else {
// b)
const bool foeIsSecondPart = foeLane->getLogicalPredecessorLane()->isInternal();
double foeStartPos = rcc->startPos;
const double foeConflictSize = rcc->endPos - rcc->startPos;
if (foeIsSecondPart) {
foeStartPos -= foeLane->getLogicalPredecessorLane()->getLength();
}
const double foeEndPos = foeStartPos + foeConflictSize;
haveIntersection = ((foeStartPos > 0 && foeStartPos < foeLane->getLength())
|| (foeEndPos > 0 && foeEndPos < foeLane->getLength()));
}
if (haveIntersection) {
myConflicts.push_back(ConflictInfo(lane->getLength() - startPos, conflictSize));
} else {
myConflicts.push_back(ConflictInfo(-NO_INTERSECTION, 0));
}
#ifdef MSLink_DEBUG_CROSSING_POINTS
std::cout << " " << lane->getID() << " custom conflict with " << foeLane->getID() << " customReverse=" << (rcc != nullptr)
<< " haveIntersection=" << haveIntersection
<< " startPos=" << startPos << " conflictSize=" << conflictSize
<< " lbc=" << myConflicts.back().lengthBehindCrossing
<< "\n";
#endif
continue;
}
myHavePedestrianCrossingFoe = myHavePedestrianCrossingFoe || foeLane->getEdge().isCrossing();
const bool sameTarget = myLane == foeLane->getLinkCont()[0]->getLane();
if (sameTarget && !beforeInternalJunction && !contIntersect(lane, foeLane)) {
//if (myLane == foeLane->getLinkCont()[0]->getLane()) {
// this foeLane has the same target and merges at the end (lane exits the junction)
const double minDist = MIN2(DIVERGENCE_MIN_WIDTH, 0.5 * (lane->getWidth() + foeLane->getWidth()));
if (lane->getShape().back().distanceTo2D(foeLane->getShape().back()) >= minDist) {
// account for lateral shift by the entry links
if (foeLane->getEntryLink()->isIndirect()) {
myConflicts.push_back(ConflictInfo(-NO_INTERSECTION, 0)); // dummy value, never used
#ifdef MSLink_DEBUG_CROSSING_POINTS
std::cout << " " << lane->getID() << " dummy merge with indirect" << foeLane->getID() << "\n";
#endif
} else {
myConflicts.push_back(ConflictInfo(0, foeLane->getWidth(), CONFLICT_DUMMY_MERGE)); // dummy value, never used
#ifdef MSLink_DEBUG_CROSSING_POINTS
std::cout << " " << lane->getID() << " dummy merge with " << foeLane->getID() << "\n";
#endif
}
} else {
const double distAfterDivergence = computeDistToDivergence(lane, foeLane, minDist, false);
const double lbcLane = lane->interpolateGeometryPosToLanePos(distAfterDivergence);
myConflicts.push_back(ConflictInfo(lbcLane, foeLane->getWidth()));
#ifdef MSLink_DEBUG_CROSSING_POINTS
std::cout
<< " " << lane->getID()
<< " merges with " << foeLane->getID()
<< " nextLane " << lane->getLinkCont()[0]->getViaLaneOrLane()->getID()
<< " dist1=" << myConflicts.back().lengthBehindCrossing
<< "\n";
#endif
}
} else {
std::vector<double> intersections1 = lane->getShape().intersectsAtLengths2D(foeLane->getShape());
#ifdef MSLink_DEBUG_CROSSING_POINTS_DETAILS
std::cout << " intersections1=" << toString(intersections1) << "\n";
#endif
bool haveIntersection = true;
if (intersections1.size() == 0) {
intersections1.push_back(-NO_INTERSECTION); // disregard this foe (using maxdouble leads to nasty problems down the line)
haveIntersection = false;
} else if (intersections1.size() > 1) {
std::sort(intersections1.begin(), intersections1.end());
}
std::vector<double> intersections2 = foeLane->getShape().intersectsAtLengths2D(lane->getShape());
#ifdef MSLink_DEBUG_CROSSING_POINTS_DETAILS
std::cout << " intersections2=" << toString(intersections2) << "\n";
#endif
if (intersections2.size() == 0) {
intersections2.push_back(0);
} else if (intersections2.size() > 1) {
std::sort(intersections2.begin(), intersections2.end());
}
double conflictSize = foeLane->getWidth();
ConflictFlag flag = CONFLICT_NO_INTERSECTION;
if (haveIntersection) {
flag = CONFLICT_DEFAULT;
const double angle1 = GeomHelper::naviDegree(lane->getShape().rotationAtOffset(intersections1.back()));
const double angle2 = GeomHelper::naviDegree(foeLane->getShape().rotationAtOffset(intersections2.back()));
const double angleDiff = GeomHelper::getMinAngleDiff(angle1, angle2);
//const double angleDiff = MIN2(GeomHelper::getMinAngleDiff(angle1, angle2),
// GeomHelper::getMinAngleDiff(angle1, angle2 + 180));
const double widthFactor = 1 / MAX2(sin(DEG2RAD(angleDiff)), 0.2) * 2 - 1;
//std::cout << " intersection of " << lane->getID() << " with " << foeLane->getID() << " angle1=" << angle1 << " angle2=" << angle2 << " angleDiff=" << angleDiff << " widthFactor=" << widthFactor << "\n";
conflictSize *= widthFactor;
conflictSize = MIN2(conflictSize, lane->getLength());
// lane width affects the crossing point
intersections1.back() -= conflictSize / 2;
// ensure non-negative offset for weird geometries
intersections1.back() = MAX2(0.0, intersections1.back());
// also length/geometry factor. (XXX: Why subtract width/2 *before* converting geometric position to lane pos? refs #3031)
intersections1.back() = lane->interpolateGeometryPosToLanePos(intersections1.back());
if (internalLaneBefore->getLogicalPredecessorLane()->getEdge().isInternal() && !foeLane->getEdge().isCrossing()) {
flag = CONFLICT_STOP_AT_INTERNAL_JUNCTION;
}
}
myConflicts.push_back(ConflictInfo(
lane->getLength() - intersections1.back(),
conflictSize, flag));
#ifdef MSLink_DEBUG_CROSSING_POINTS
std::cout
<< " intersection of " << lane->getID()
<< " totalLength=" << lane->getLength()
<< " with " << foeLane->getID()
<< " totalLength=" << foeLane->getLength()
<< " dist1=" << myConflicts.back().lengthBehindCrossing
<< " widthFactor=" << myConflicts.back().conflictSize / foeLane->getWidth()
<< "\n";
#endif
}
}
// check for overlap with internal lanes from the same source lane
const MSLane* pred = lane->getLogicalPredecessorLane();
// to avoid overlap with vehicles that came from pred (especially when pred has endOffset > 0)
// we add all other internal lanes from pred as foeLanes
for (const MSLink* const link : pred->getLinkCont()) {
const MSLane* const sibling = link->getViaLane();
if (sibling != lane && sibling != nullptr) {
const double minDist = MIN2(DIVERGENCE_MIN_WIDTH, 0.5 * (lane->getWidth() + sibling->getWidth()));
if (lane->getShape().front().distanceTo2D(sibling->getShape().front()) >= minDist) {
// account for lateral shift by the entry links
continue;
}
const double distToDivergence = computeDistToDivergence(lane, sibling, minDist, true);
double lbcLane;
if (lane->getLength() == sibling->getLength() && &lane->getEdge() == &sibling->getEdge()) {
// for parallel lanes, avoid inconsistency in distance estimation (#10988)
// between forward distance (getLeaderInfo)
// and backward distance used in lane-changing (getFollowersOnConsecutive)
lbcLane = lane->getLength() - distToDivergence;
} else {
lbcLane = MAX2(0.0, lane->getLength() - lane->interpolateGeometryPosToLanePos(distToDivergence));
}
ConflictInfo ci = ConflictInfo(lbcLane, sibling->getWidth());
auto it = std::find(myFoeLanes.begin(), myFoeLanes.end(), sibling);
if (it != myFoeLanes.end()) {
// avoid duplicate foeLane
const int replacedIndex = (int)(it - myFoeLanes.begin());
myConflicts[replacedIndex] = ci;
} else {
myConflicts.push_back(ci);
myFoeLanes.push_back(sibling);
}
#ifdef MSLink_DEBUG_CROSSING_POINTS
std::cout << " adding same-origin foe" << sibling->getID()
<< " dist1=" << myConflicts.back().lengthBehindCrossing
<< "\n";
#endif
}
}
// init points for the symmetrical conflict
// for each pair of conflicting lanes, the link that gets second, sets the pointers
for (int i = 0; i < (int)myFoeLanes.size(); i++) {
const MSLane* foeLane = myFoeLanes[i];
MSLink* foeExitLink = foeLane->getLinkCont()[0];
int foundIndex = -1;
for (int i2 = 0; i2 < (int)foeExitLink->myFoeLanes.size(); i2++) {
if (foeExitLink->myFoeLanes[i2] == lane) {
myConflicts[i].foeConflictIndex = i2;
foeExitLink->myConflicts[i2].foeConflictIndex = i;
myRecheck.erase({foeExitLink, this});
foundIndex = i2;
break;
}
}
#ifdef MSLink_DEBUG_CROSSING_POINTS
std::cout << lane->getID() << " foeLane=" << foeLane->getID() << " index=" << i << " foundIndex=" << foundIndex << "\n";
#endif
if (foundIndex < 0) {
if (myConflicts[i].flag != CONFLICT_NO_INTERSECTION) {
myRecheck.insert({this, foeExitLink});
}
}
}
}
if (MSGlobals::gLateralResolution > 0) {
// check for links with the same origin lane and the same destination edge
const MSEdge* myTarget = &myLane->getEdge();
// save foes for entry links
for (MSLink* const it : myLaneBefore->getLinkCont()) {
const MSEdge* target = &(it->getLane()->getEdge());
if (it == this) {
continue;
}
if (target == myTarget) {
mySublaneFoeLinks.push_back(it);
#ifdef MSLink_DEBUG_CROSSING_POINTS
std::cout << " sublaneFoeLink (same target): " << it->getViaLaneOrLane()->getID() << "\n";
#endif
} else if (myDirection != LinkDirection::STRAIGHT && it->getDirection() == LinkDirection::STRAIGHT) {
// potential turn conflict
mySublaneFoeLinks2.push_back(it);
#ifdef MSLink_DEBUG_CROSSING_POINTS
std::cout << " sublaneFoeLink2 (other target: " << it->getViaLaneOrLane()->getID() << "\n";
#endif
}
}
// save foes for exit links
if (fromInternalLane()) {
//std::cout << " setRequestInformation link=" << getViaLaneOrLane()->getID() << " before=" << myLaneBefore->getID() << " before2=" << myLaneBefore->getIncomingLanes().front().lane->getID() << "\n";
for (const MSLink* const link : myLaneBefore->getIncomingLanes().front().lane->getLinkCont()) {
if (link->getViaLane() != myInternalLaneBefore && &link->getLane()->getEdge() == myTarget) {
//std::cout << " add sublaneFoe=" << (*it)->getViaLane()->getID() << "\n";
mySublaneFoeLanes.push_back(link->getViaLane());
}
}
}
}
if (myInternalLaneBefore != nullptr
&& myDirection != LinkDirection::STRAIGHT
// for right turns, the curvature helps rather than restricts the linkLeader check
&& (
(!MSGlobals::gLefthand && myDirection != LinkDirection::RIGHT)
|| (MSGlobals::gLefthand && myDirection != LinkDirection::LEFT))) {
const double angle = fabs(GeomHelper::angleDiff(
myLaneBefore->getNormalPredecessorLane()->getShape().angleAt2D(-2),
myLane->getShape().angleAt2D(0)));
if (angle > 0) {
double length = myInternalLaneBefore->getShape().length2D();
if (myInternalLaneBefore->getIncomingLanes().size() == 1 &&
myInternalLaneBefore->getIncomingLanes()[0].lane->isInternal()) {
length += myInternalLaneBefore->getIncomingLanes()[0].lane->getShape().length2D();
} else if (myInternalLane != nullptr) {
length += myInternalLane->getShape().length2D();
}
myRadius = length / angle;
//std::cout << getDescription() << " a=" << RAD2DEG(angle) << " l=" << length << " r=" << myRadius << "\n";
}
}
}
void
MSLink::recheckSetRequestInformation() {
for (auto item : myRecheck) {
#ifdef MSLink_DEBUG_CROSSING_POINTS
std::cout << " recheck l1=" << item.first->getDescription() << " l2=" << item.second->getDescription() << "\n";
#endif
MSLink* link = item.first;
MSLink* foeExitLink = item.second;
const MSLane* lane = link->getInternalLaneBefore();
const MSLane* foeLane = foeExitLink->getInternalLaneBefore();
int conflictIndex = -1;
for (int i = 0; i < (int)link->myFoeLanes.size(); i++) {
if (link->myFoeLanes[i] == foeLane) {
conflictIndex = i;
break;
}
}
if (conflictIndex == -1) {
WRITE_WARNING("Could not recheck ConflictInfo for " + link->getDescription() + " and " + foeExitLink->getDescription() + "\n");
continue;
}
ConflictInfo& ci = link->myConflicts[conflictIndex];
std::vector<double> intersections1 = foeLane->getShape().intersectsAtLengths2D(lane->getShape());
if (intersections1.size() == 0) {
#ifdef MSLink_DEBUG_CROSSING_POINTS
std::cout << " no intersection\n";
#endif
continue;
}
const double widthFactor = ci.conflictSize / foeLane->getWidth();
const double conflictSize2 = lane->getWidth() * widthFactor;
std::sort(intersections1.begin(), intersections1.end());
intersections1.back() -= conflictSize2 / 2;
intersections1.back() = MAX2(0.0, intersections1.back());
ci.foeConflictIndex = (int)foeExitLink->myConflicts.size();
foeExitLink->myConflicts.push_back(ConflictInfo(foeLane->getLength() - intersections1.back(), conflictSize2));
#ifdef MSLink_DEBUG_CROSSING_POINTS
std::cout << " ci=" << conflictIndex << " wf=" << widthFactor << " flag=" << ci.flag << " flbc=" << foeExitLink->myConflicts.back().lengthBehindCrossing << "\n";
#endif
}
myRecheck.clear();
}
double
MSLink::computeDistToDivergence(const MSLane* lane, const MSLane* sibling, double minDist, bool sameSource) const {
double lbcSibling = 0;
double lbcLane = 0;
PositionVector l = lane->getShape();
PositionVector s = sibling->getShape();
double length = l.length2D();
double sibLength = s.length2D();
if (!sameSource) {
l = l.reverse();
s = s.reverse();
} else if (sibling->getEntryLink()->myAmIndirect) {
// ignore final waiting position since it may be quite close to the lane
// shape but the waiting position is perpendicular (so the minDist
// requirement is not necessary
lbcSibling += s[-1].distanceTo2D(s[-2]);
s.pop_back();
} else if (lane->getEntryLink()->myAmIndirect) {
// ignore final waiting position since it may be quite close to the lane
// shape but the waiting position is perpendicular (so the minDist
// requirement is not necessary
lbcLane += l[-1].distanceTo2D(l[-2]);
l.pop_back();
}
#ifdef MSLink_DEBUG_CROSSING_POINTS_DETAILS
std::cout << " sameSource=" << sameSource << " minDist=" << minDist << " backDist=" << l.back().distanceTo2D(s.back()) << "\n";
#endif
if (l.back().distanceTo2D(s.back()) > minDist) {
// compute the final divergence point
// this position serves two purposes:
// 1) once the foe vehicle back (on sibling) has passed this point, we can safely ignore it
// 2) both vehicles are put into a cf-relationship while before the point.
// Since the actual crossing point is at the start of the junction,
// we want to make sure that both vehicles have the same distance to the crossing point and thus follow each other naturally
std::vector<double> distances = l.distances(s);
#ifdef MSLink_DEBUG_CROSSING_POINTS
std::cout << " distances=" << toString(distances) << "\n";
#endif
assert(distances.size() == l.size() + s.size());
if (distances.back() > minDist && distances[l.size() - 1] > minDist) {
// do a pairwise check between lane and sibling to make because we do not know which of them bends more
for (int j = (int)s.size() - 2; j >= 0; j--) {
const int i = j + (int)l.size();
const double segLength = s[j].distanceTo2D(s[j + 1]);
if (distances[i] > minDist) {
lbcSibling += segLength;
} else {
// assume no sharp bends and just interpolate the last segment
lbcSibling += segLength - (minDist - distances[i]) * segLength / (distances[i + 1] - distances[i]);
break;
}
}
for (int i = (int)l.size() - 2; i >= 0; i--) {
const double segLength = l[i].distanceTo2D(l[i + 1]);
if (distances[i] > minDist) {
lbcLane += segLength;
} else {
// assume no sharp bends and just interpolate the last segment
lbcLane += segLength - (minDist - distances[i]) * segLength / (distances[i + 1] - distances[i]);
break;
}
}
}
assert(lbcSibling >= -NUMERICAL_EPS);
assert(lbcLane >= -NUMERICAL_EPS);
}
const double distToDivergence1 = sibling->getLength() - lbcSibling;
const double distToDivergence2 = lane->getLength() - lbcLane;
const double distToDivergence = MIN3(
MAX2(distToDivergence1, distToDivergence2),
sibLength, length);
#ifdef MSLink_DEBUG_CROSSING_POINTS
std::cout << " distToDivergence=" << distToDivergence
<< " distTD1=" << distToDivergence1
<< " distTD2=" << distToDivergence2
<< " length=" << length
<< " sibLength=" << sibLength
<< "\n";
#endif
return distToDivergence;
}
bool
MSLink::contIntersect(const MSLane* lane, const MSLane* foe) {
if (foe->getLinkCont()[0]->getViaLane() != nullptr) {
std::vector<double> intersections = lane->getShape().intersectsAtLengths2D(foe->getShape());
return intersections.size() > 0;
}
return false;
}
void
MSLink::setApproaching(const SUMOVehicle* approaching, const SUMOTime arrivalTime, const double arrivalSpeed, const double leaveSpeed,
const bool setRequest, const double arrivalSpeedBraking, const SUMOTime waitingTime, double dist, double latOffset) {
const SUMOTime leaveTime = getLeaveTime(arrivalTime, arrivalSpeed, leaveSpeed, approaching->getVehicleType().getLength());
#ifdef DEBUG_APPROACHING
if (DEBUG_COND2(approaching)) {
std::cout << SIMTIME << " Link '" << (myLaneBefore == 0 ? "NULL" : myLaneBefore->getID()) << "'->'" << (myLane == 0 ? "NULL" : myLane->getID()) << "' Adding approaching vehicle '" << approaching->getID() << "'\nCurrently registered vehicles:" << std::endl;
for (auto i = myApproachingVehicles.begin(); i != myApproachingVehicles.end(); ++i) {
std::cout << "'" << i->first->getID() << "'" << std::endl;
}
}
#endif
myApproachingVehicles.emplace(approaching,
ApproachingVehicleInformation(arrivalTime, leaveTime, arrivalSpeed, leaveSpeed, setRequest,
arrivalSpeedBraking, waitingTime, dist, approaching->getSpeed(), latOffset));
}
void
MSLink::setApproaching(const SUMOVehicle* approaching, ApproachingVehicleInformation ai) {
#ifdef DEBUG_APPROACHING
if (DEBUG_COND2(approaching)) {
std::cout << SIMTIME << " Link '" << (myLaneBefore == 0 ? "NULL" : myLaneBefore->getID()) << "'->'" << (myLane == 0 ? "NULL" : myLane->getID()) << "' Adding approaching vehicle '" << approaching->getID() << "'\nCurrently registered vehicles:" << std::endl;
for (auto i = myApproachingVehicles.begin(); i != myApproachingVehicles.end(); ++i) {
std::cout << "'" << i->first->getID() << "'" << std::endl;
}
}
#endif
myApproachingVehicles.emplace(approaching, ai);
}
void
MSLink::addBlockedLink(MSLink* link) {
myBlockedFoeLinks.insert(link);
}
bool
MSLink::willHaveBlockedFoe() const {
for (std::set<MSLink*>::const_iterator i = myBlockedFoeLinks.begin(); i != myBlockedFoeLinks.end(); ++i) {
if ((*i)->isBlockingAnyone()) {
return true;
}
}
return false;
}
void
MSLink::removeApproaching(const SUMOVehicle* veh) {
#ifdef DEBUG_APPROACHING
if (DEBUG_COND2(veh)) {
std::cout << SIMTIME << " Link '" << (myLaneBefore == 0 ? "NULL" : myLaneBefore->getID()) << "'->'" << (myLane == 0 ? "NULL" : myLane->getID()) << std::endl;
std::cout << "' Removing approaching vehicle '" << veh->getID() << "'\nCurrently registered vehicles:" << std::endl;
for (auto i = myApproachingVehicles.begin(); i != myApproachingVehicles.end(); ++i) {
std::cout << "'" << i->first->getID() << "'" << std::endl;
}
}
#endif
myApproachingVehicles.erase(veh);
}
MSLink::ApproachingVehicleInformation
MSLink::getApproaching(const SUMOVehicle* veh) const {
auto i = myApproachingVehicles.find(veh);
if (i != myApproachingVehicles.end()) {
return i->second;
} else {
return ApproachingVehicleInformation(INVALID_TIME, INVALID_TIME, 0, 0, false, 0, 0, 0, 0, 0);
}
}
void
MSLink::clearState() {
myApproachingVehicles.clear();
}
SUMOTime
MSLink::getLeaveTime(const SUMOTime arrivalTime, const double arrivalSpeed,
const double leaveSpeed, const double vehicleLength) const {
return arrivalTime == SUMOTime_MAX ? SUMOTime_MAX : arrivalTime + TIME2STEPS((getLength() + vehicleLength) / MAX2(0.5 * (arrivalSpeed + leaveSpeed), NUMERICAL_EPS));
}
bool
MSLink::opened(SUMOTime arrivalTime, double arrivalSpeed, double leaveSpeed, double vehicleLength,
double impatience, double decel, SUMOTime waitingTime, double posLat,
BlockingFoes* collectFoes, bool ignoreRed, const SUMOTrafficObject* ego) const {
#ifdef MSLink_DEBUG_OPENED
if (gDebugFlag1) {
std::cout << SIMTIME << " opened? link=" << getDescription() << " red=" << haveRed() << " cont=" << isCont() << " numFoeLinks=" << myFoeLinks.size() << " havePrio=" << havePriority() << " lastWasContMajorGreen=" << lastWasContState(LINKSTATE_TL_GREEN_MAJOR) << "\n";
}
#endif
if (haveRed() && !ignoreRed) {
return false;
}
if (isCont() && MSGlobals::gUsingInternalLanes) {
return true;
}
const SUMOTime leaveTime = getLeaveTime(arrivalTime, arrivalSpeed, leaveSpeed, vehicleLength);
if (MSGlobals::gLateralResolution > 0) {
// check for foes on the same lane with the same target edge
for (const MSLink* foeLink : mySublaneFoeLinks) {
assert(myLane != foeLink->getLane());
for (const auto& it : foeLink->myApproachingVehicles) {
const SUMOVehicle* foe = it.first;
if (
// there only is a conflict if the paths cross
((posLat < foe->getLateralPositionOnLane() + it.second.latOffset && myLane->getIndex() > foeLink->myLane->getIndex())
|| (posLat > foe->getLateralPositionOnLane() + it.second.latOffset && myLane->getIndex() < foeLink->myLane->getIndex()))
// the vehicle that arrives later must yield
&& (arrivalTime > it.second.arrivalTime
// if both vehicles arrive at the same time, the one
// to the left must yield
|| (arrivalTime == it.second.arrivalTime && posLat > foe->getLateralPositionOnLane()))) {
if (blockedByFoe(foe, it.second, arrivalTime, leaveTime, arrivalSpeed, leaveSpeed, false,
impatience, decel, waitingTime, ego)) {
#ifdef MSLink_DEBUG_OPENED
if (gDebugFlag1) {
std::cout << SIMTIME << " blocked by " << foe->getID() << " arrival=" << arrivalTime << " foeArrival=" << it.second.arrivalTime << "\n";
}
#endif
if (collectFoes == nullptr) {
#ifdef MSLink_DEBUG_OPENED
if (gDebugFlag1) {
std::cout << " link=" << getViaLaneOrLane()->getID() << " blocked by sublaneFoe=" << foe->getID() << " foeLink=" << foeLink->getViaLaneOrLane()->getID() << " posLat=" << posLat << "\n";
}
#endif
return false;
} else {
collectFoes->push_back(it.first);
}
}
}
}
}
// check for foes on the same lane with a different target edge
// (straight movers take precedence if the paths cross)
const int lhSign = MSGlobals::gLefthand ? -1 : 1;
for (const MSLink* foeLink : mySublaneFoeLinks2) {
assert(myDirection != LinkDirection::STRAIGHT);
for (const auto& it : foeLink->myApproachingVehicles) {
const SUMOVehicle* foe = it.first;
// there only is a conflict if the paths cross
// and if the vehicles are not currently in a car-following relationship
const double egoWidth = ego == nullptr ? 1.8 : ego->getVehicleType().getWidth();
if (!lateralOverlap(posLat, egoWidth, foe->getLateralPositionOnLane() + it.second.latOffset, foe->getVehicleType().getWidth())
&& (((myDirection == LinkDirection::RIGHT || myDirection == LinkDirection::PARTRIGHT)
&& (posLat * lhSign > (foe->getLateralPositionOnLane() + it.second.latOffset) * lhSign))
|| ((myDirection == LinkDirection::LEFT || myDirection == LinkDirection::PARTLEFT)
&& (posLat * lhSign < (foe->getLateralPositionOnLane() + it.second.latOffset) * lhSign)))) {
if (blockedByFoe(foe, it.second, arrivalTime, leaveTime, arrivalSpeed, leaveSpeed, false,
impatience, decel, waitingTime, ego)) {
#ifdef MSLink_DEBUG_OPENED
if (gDebugFlag1) {
std::cout << SIMTIME << " blocked by sublane foe " << foe->getID() << " arrival=" << arrivalTime << " foeArrival=" << it.second.arrivalTime << "\n";
}
#endif
if (collectFoes == nullptr) {
#ifdef MSLink_DEBUG_OPENED
if (gDebugFlag1) {
std::cout << " link=" << getViaLaneOrLane()->getID() << " blocked by sublaneFoe2=" << foe->getID() << " foeLink=" << foeLink->getViaLaneOrLane()->getID() << " posLat=" << posLat << "\n";
}
#endif
return false;
} else {
collectFoes->push_back(it.first);
}
}
}
}
}
}
if ((havePriority() || lastWasContState(LINKSTATE_TL_GREEN_MAJOR)) && myState != LINKSTATE_ZIPPER) {
// priority usually means the link is open but there are exceptions:
// zipper still needs to collect foes
// sublane model could have detected a conflict
return collectFoes == nullptr || collectFoes->size() == 0;
}
if ((myState == LINKSTATE_STOP || myState == LINKSTATE_ALLWAY_STOP) && waitingTime == 0) {
return false;
}
const std::vector<MSLink*>& foeLinks = (myOffFoeLinks == nullptr || getCorrespondingEntryLink()->getState() != LINKSTATE_ALLWAY_STOP) ? myFoeLinks : *myOffFoeLinks;
#ifdef MSLink_DEBUG_OPENED
if (gDebugFlag1) {
std::cout << SIMTIME << " opened link=" << getViaLaneOrLane()->getID() << " foeLinks=" << foeLinks.size() << "\n";
}
#endif
if (MSGlobals::gUseMesoSim && impatience == 1) {
return true;
}
const bool lastWasContRed = lastWasContState(LINKSTATE_TL_RED);
for (const MSLink* const link : foeLinks) {
if (MSGlobals::gUseMesoSim) {
if (link->haveRed()) {
continue;
}
}
#ifdef MSLink_DEBUG_OPENED
if (gDebugFlag1) {
std::cout << " foeLink=" << link->getViaLaneOrLane()->getID() << " numApproaching=" << link->getApproaching().size() << "\n";
}
#endif
if (link->blockedAtTime(arrivalTime, leaveTime, arrivalSpeed, leaveSpeed, myLane == link->getLane(),
impatience, decel, waitingTime, collectFoes, ego, lastWasContRed)) {
return false;
}
}
if (collectFoes != nullptr && collectFoes->size() > 0) {
return false;
}
return true;
}
bool
MSLink::blockedAtTime(SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
BlockingFoes* collectFoes, const SUMOTrafficObject* ego, bool lastWasContRed) const {
for (const auto& it : myApproachingVehicles) {
#ifdef MSLink_DEBUG_OPENED
if (gDebugFlag1) {
if (ego != nullptr
&& ego->getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_IGNORE_FOE_SPEED, 0) >= it.second.speed
&& ego->getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_IGNORE_FOE_PROB, 0) > 0) {
std::stringstream stream; // to reduce output interleaving from different threads
stream << SIMTIME << " " << myApproachingVehicles.size() << " foe link=" << getViaLaneOrLane()->getID()
<< " foeVeh=" << it.first->getID() << " (below ignore speed)"
<< " ignoreFoeProb=" << ego->getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_IGNORE_FOE_PROB, 0)
<< "\n";
std::cout << stream.str();
}
}
#endif
if (it.first != ego
&& (ego == nullptr
|| ego->getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_IGNORE_FOE_PROB, 0) == 0
|| ego->getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_IGNORE_FOE_SPEED, 0) < it.second.speed
|| ego->getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_IGNORE_FOE_PROB, 0) < RandHelper::rand(ego->getRNG()))
&& !ignoreFoe(ego, it.first)
&& (!lastWasContRed || it.first->getSpeed() > SUMO_const_haltingSpeed)
&& blockedByFoe(it.first, it.second, arrivalTime, leaveTime, arrivalSpeed, leaveSpeed, sameTargetLane,
impatience, decel, waitingTime, ego)) {
if (collectFoes == nullptr) {
return true;
} else {
collectFoes->push_back(it.first);
}
}
}
return false;
}
bool
MSLink::blockedByFoe(const SUMOVehicle* veh, const ApproachingVehicleInformation& avi,
SUMOTime arrivalTime, SUMOTime leaveTime, double arrivalSpeed, double leaveSpeed,
bool sameTargetLane, double impatience, double decel, SUMOTime waitingTime,
const SUMOTrafficObject* ego) const {
#ifdef MSLink_DEBUG_OPENED
if (gDebugFlag1) {
std::stringstream stream; // to reduce output interleaving from different threads
stream << " link=" << getDescription()
<< " foeVeh=" << veh->getID()
<< " req=" << avi.willPass
<< " aT=" << avi.arrivalTime
<< " lT=" << avi.leavingTime
<< "\n";
std::cout << stream.str();
}
#endif
if (!avi.willPass) {
return false;
}
if (myState == LINKSTATE_ALLWAY_STOP) {
assert(waitingTime > 0);
if (waitingTime > avi.waitingTime) {
return false;
}
if (waitingTime == avi.waitingTime && arrivalTime < avi.arrivalTime) {
return false;
}
}
SUMOTime foeArrivalTime = avi.arrivalTime;
double foeArrivalSpeedBraking = avi.arrivalSpeedBraking;
if (impatience > 0 && arrivalTime < avi.arrivalTime) {
#ifdef MSLink_DEBUG_OPENED
gDebugFlag6 = ((ego == nullptr || ego->isSelected()) && (veh == nullptr || veh->isSelected()));
#endif
const SUMOTime fatb = computeFoeArrivalTimeBraking(arrivalTime, veh, avi.arrivalTime, impatience, avi.dist, foeArrivalSpeedBraking);
foeArrivalTime = (SUMOTime)((1. - impatience) * (double)avi.arrivalTime + impatience * (double)fatb);
#ifdef MSLink_DEBUG_OPENED
if (gDebugFlag6) {
std::cout << SIMTIME << " link=" << getDescription() << " ego=" << ego->getID() << " foe=" << veh->getID()
<< " at=" << STEPS2TIME(arrivalTime)
<< " fat=" << STEPS2TIME(avi.arrivalTime)
<< " fatb=" << STEPS2TIME(fatb)
<< " fat2=" << STEPS2TIME(foeArrivalTime)
<< "\n";
}
#endif
}
const SUMOTime lookAhead = (myState == LINKSTATE_ZIPPER
? myLookaheadTimeZipper
: (ego == nullptr
? myLookaheadTime
: TIME2STEPS(ego->getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_TIMEGAP_MINOR, STEPS2TIME(myLookaheadTime)))));
//if (ego != 0) std::cout << SIMTIME << " ego=" << ego->getID() << " jmTimegapMinor=" << ego->getVehicleType().getParameter().getJMParam(SUMO_ATTR_JM_TIMEGAP_MINOR, -1) << " lookAhead=" << lookAhead << "\n";
#ifdef MSLink_DEBUG_OPENED
if (gDebugFlag1 || gDebugFlag6) {
std::stringstream stream; // to reduce output interleaving from different threads
stream << " imp=" << impatience << " fAT2=" << foeArrivalTime << " fASb=" << foeArrivalSpeedBraking << " lA=" << lookAhead << " egoAT=" << arrivalTime << " egoLT=" << leaveTime << " egoLS=" << leaveSpeed << "\n";
std::cout << stream.str();
}
#endif
if (avi.leavingTime < arrivalTime) {
// ego wants to be follower
if (sameTargetLane && (arrivalTime - avi.leavingTime < lookAhead
|| unsafeMergeSpeeds(avi.leaveSpeed, arrivalSpeed,
veh->getVehicleType().getCarFollowModel().getMaxDecel(), decel))) {
#ifdef MSLink_DEBUG_OPENED
if (gDebugFlag1 || gDebugFlag6) {
std::cout << " blocked (cannot follow)\n";
}
#endif
return true;
}
} else if (foeArrivalTime > leaveTime + lookAhead) {
// ego wants to be leader.
if (sameTargetLane && unsafeMergeSpeeds(leaveSpeed, foeArrivalSpeedBraking,
decel, veh->getVehicleType().getCarFollowModel().getMaxDecel())) {
#ifdef MSLink_DEBUG_OPENED
if (gDebugFlag1 || gDebugFlag6) {
std::cout << " blocked (cannot lead)\n";
}
#endif