41#define LOOK_FORWARD 10.
45#define LCA_RIGHT_IMPATIENCE -1.
46#define CUT_IN_LEFT_SPEED_THRESHOLD 27.
47#define MAX_ONRAMP_LENGTH 200.
49#define LOOK_AHEAD_MIN_SPEED 0.0
50#define LOOK_AHEAD_SPEED_MEMORY 0.9
52#define HELP_DECEL_FACTOR 1.0
54#define HELP_OVERTAKE (10.0 / 3.6)
55#define MIN_FALLBEHIND (7.0 / 3.6)
59#define KEEP_RIGHT_TIME 5.0
61#define RELGAIN_NORMALIZATION_MIN_SPEED 10.0
63#define TURN_LANE_DIST 200.0
64#define GAIN_PERCEPTION_THRESHOLD 0.05
66#define ARRIVALPOS_LAT_THRESHOLD 100.0
69#define LATGAP_SPEED_THRESHOLD (50 / 3.6)
72#define LATGAP_SPEED_THRESHOLD2 (50 / 3.6)
75#define SPEEDGAIN_DECAY_FACTOR 0.5
77#define SPEEDGAIN_MEMORY_FACTOR 0.5
79#define REACT_TO_STOPPED_DISTANCE 100
105#define DEBUG_COND (myVehicle.isSelected())
117 mySpeedGainProbabilityRight(0),
118 mySpeedGainProbabilityLeft(0),
119 myKeepRightProbability(0),
120 myLeadingBlockerLength(0),
124 myCanChangeFully(true),
125 mySafeLatDistRight(0),
126 mySafeLatDistLeft(0),
134 myMinGapLat(v.getVehicleType().getMinGapLat()),
137 MAX2(NUMERICAL_EPS, myMinGapLat)) /
138 MAX2(NUMERICAL_EPS, myMinGapLat)))),
140 myMinImpatience(myImpatience),
192 const std::vector<MSVehicle::LaneQ>& preb,
195 double& latDist,
double& maneuverDist,
int& blocked) {
198 const std::string changeType = laneOffset == -1 ?
"right" : (laneOffset == 1 ?
"left" :
"current");
206 <<
" neigh=" << neighLane.
getID()
211 <<
" considerChangeTo=" << changeType
218 leaders, followers, blockers,
219 neighLeaders, neighFollowers, neighBlockers,
221 lastBlocked, firstBlocked, latDist, maneuverDist, blocked);
223 result =
keepLatGap(result, leaders, followers, blockers,
224 neighLeaders, neighFollowers, neighBlockers,
225 neighLane, laneOffset, latDist, maneuverDist, blocked);
227 result |=
getLCA(result, latDist);
229#if defined(DEBUG_MANEUVER) || defined(DEBUG_STATE)
230 double latDistTmp = latDist;
233#if defined(DEBUG_MANEUVER) || defined(DEBUG_STATE)
235 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" maneuverDist=" << maneuverDist <<
" latDist=" << latDistTmp <<
" mySpeedPrev=" <<
mySpeedLat <<
" speedLat=" <<
DIST2SPEED(latDist) <<
" latDist2=" << latDist <<
"\n";
242 <<
" wantsChangeTo=" << changeType
243 <<
" latDist=" << latDist
244 <<
" maneuverDist=" << maneuverDist
252 <<
" wantsNoChangeTo=" << changeType
309 const double newSpeed =
_patchSpeed(
MAX2(min, 0.0), wanted, max, cfModel);
310#ifdef DEBUG_PATCHSPEED
312 const std::string patched = (wanted != newSpeed ?
" patched=" +
toString(newSpeed) :
"");
319 <<
" wanted=" << wanted
338 double nVSafe = wanted;
344#ifdef DEBUG_PATCHSPEED
352 max =
MIN2(max, safe);
357 if (safe >= vMinEmergency) {
359 min =
MAX2(vMinEmergency, safe);
362#ifdef DEBUG_PATCHSPEED
364 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" slowing down for leading blocker, safe=" << safe << (safe + NUMERICAL_EPS < min ?
" (not enough)" :
"") <<
"\n";
367 nVSafe =
MAX2(min, safe);
374 double accel = i.first;
376 if (v >= min && v <= max) {
378 nVSafe =
MIN2(v * coopWeight + (1 - coopWeight) * wanted, nVSafe);
381 nVSafe =
MIN2(v, nVSafe);
384#ifdef DEBUG_PATCHSPEED
386 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" got accel=" << accel <<
" nVSafe=" << nVSafe <<
"\n";
390#ifdef DEBUG_PATCHSPEED
393 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" ignoring low nVSafe=" << v <<
" (accel=" << accel <<
") min=" << min <<
"\n";
397 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" ignoring high nVSafe=" << v <<
" (accel=" << accel <<
") max=" << max <<
"\n";
405#ifdef DEBUG_PATCHSPEED
418#if defined(DEBUG_PATCHSPEED) || defined(DEBUG_STATE)
423 return (max + wanted) / 2.0;
427#if defined(DEBUG_PATCHSPEED) || defined(DEBUG_STATE)
432 return (min + wanted) / 2.0;
435#if defined(DEBUG_PATCHSPEED) || defined(DEBUG_STATE)
440 return (max + wanted) / 2.0;
481#if defined(DEBUG_PATCHSPEED) || defined(DEBUG_STATE)
486 return (max + wanted) / 2.0;
490#if defined(DEBUG_PATCHSPEED) || defined(DEBUG_STATE)
510 if (pinfo->first >= 0) {
519 <<
" informedBy=" << sender->
getID()
520 <<
" info=" << pinfo->second
521 <<
" vSafe=" << pinfo->first
534 assert(cld.first != 0);
543 double remainingSeconds) {
549 plannedSpeed =
MIN2(plannedSpeed, v);
554 std::cout <<
" informLeader speed=" <<
myVehicle.
getSpeed() <<
" planned=" << plannedSpeed <<
"\n";
565 if (
gDebugFlag2) std::cout <<
" blocked by leader nv=" << nv->
getID() <<
" nvSpeed=" << nv->
getSpeed() <<
" needGap="
569 const double dv = plannedSpeed - nv->
getSpeed();
570 const double overtakeDist = (neighLead.second
582 || dv * remainingSeconds < overtakeDist)
583 && (!neighLead.first->isStopped() || (
isOpposite() && neighLead.second >= 0))) {
598 <<
" cannot overtake leader nv=" << nv->
getID()
600 <<
" remainingSeconds=" << remainingSeconds
601 <<
" targetSpeed=" << targetSpeed
602 <<
" nextSpeed=" << nextSpeed
613 <<
" cannot overtake fast leader nv=" << nv->
getID()
615 <<
" remainingSeconds=" << remainingSeconds
616 <<
" targetSpeed=" << targetSpeed
627 <<
" wants to overtake leader nv=" << nv->
getID()
629 <<
" remainingSeconds=" << remainingSeconds
630 <<
" currentGap=" << neighLead.second
632 <<
" overtakeDist=" << overtakeDist
642 }
else if (neighLead.first != 0) {
645 double dv, nextNVSpeed;
665 std::cout <<
" not blocked by leader nv=" << nv->
getID()
667 <<
" gap=" << neighLead.second
668 <<
" nextGap=" << neighLead.second - dv
670 <<
" targetSpeed=" << targetSpeed
674 return MIN2(targetSpeed, plannedSpeed);
686 double remainingSeconds,
687 double plannedSpeed) {
695 std::cout <<
"\n nv=" << nv->
getID() <<
" not willing to help\n";
707 if (
gDebugFlag2) std::cout <<
" blocked by follower nv=" << nv->
getID() <<
" nvSpeed=" << nv->
getSpeed() <<
" needGap="
714 if ((neededGap - neighFollow.second) / remainingSeconds < (plannedSpeed - nv->
getSpeed())) {
717 std::cout <<
" wants to cut in before nv=" << nv->
getID() <<
" without any help neededGap=" << neededGap <<
"\n";
735 const double neighNewSpeed1s =
MAX2(0., nv->
getSpeed() - helpDecel);
736 const double dv = plannedSpeed - neighNewSpeed1s;
738 const double decelGap = neighFollow.second + dv;
744 <<
" egoNV=" << plannedSpeed
745 <<
" nvNewSpeed=" << neighNewSpeed
746 <<
" nvNewSpeed1s=" << neighNewSpeed1s
747 <<
" deltaGap=" << dv
748 <<
" decelGap=" << decelGap
749 <<
" secGap=" << secureGap
753 if (decelGap > 0 && decelGap >= secureGap) {
768 std::cout <<
" wants to cut in before nv=" << nv->
getID()
769 <<
" vsafe1=" << vsafe1
770 <<
" vsafe=" << vsafe
775 }
else if (dv > 0 && dv * remainingSeconds > (secureGap - decelGap + POSITION_EPS)) {
780 std::cout <<
" wants to cut in before nv=" << nv->
getID() <<
" (eventually)\n";
788 std::cout <<
" wants to cut in before nv=" << nv->
getID() <<
" (nv cannot overtake right)\n";
804 std::cout <<
" wants right follower to slow down a bit\n";
810 std::cout <<
" wants to cut in before right follower nv=" << nv->
getID() <<
" (eventually)\n";
819 const double overtakeDist = (neighFollow.second
825 const double needDV = overtakeDist / remainingSeconds;
833 <<
" wants to be overtaken by=" << nv->
getID()
834 <<
" overtakeDist=" << overtakeDist
836 <<
" vhelp=" << vhelp
837 <<
" needDV=" << needDV
843 }
else if (neighFollow.first != 0) {
848 std::cout <<
" wants to cut in before non-blocking follower nv=" << neighFollow.first->getID() <<
"\n";
856 const std::vector<CLeaderDist>& blockers,
857 double remainingSeconds) {
869 plannedSpeed =
MIN2(plannedSpeed, safe);
871 for (std::vector<CLeaderDist>::const_iterator it = blockers.begin(); it != blockers.end(); ++it) {
872 plannedSpeed =
MIN2(plannedSpeed,
informLeader(blocked, dir, *it, remainingSeconds));
880 const std::vector<CLeaderDist>& blockers,
881 double remainingSeconds,
882 double plannedSpeed) {
884 for (std::vector<CLeaderDist>::const_iterator it = blockers.begin(); it != blockers.end(); ++it) {
885 informFollower(blocked, dir, *it, remainingSeconds, plannedSpeed);
910 const double halfWidth =
getWidth() * 0.5;
923 std::vector<double> newExpectedSpeeds;
932 const std::vector<MSLane*>& lanes = currEdge->
getLanes();
933 for (std::vector<MSLane*>::const_iterator it_lane = lanes.begin(); it_lane != lanes.end(); ++it_lane) {
935 for (
int i = 0; i < subLanes; ++i) {
936 newExpectedSpeeds.push_back((*it_lane)->getVehicleMaxSpeed(&
myVehicle));
942 for (
int i = 0; i < subLanes; ++i) {
943 newExpectedSpeeds.push_back(lanes.back()->getVehicleMaxSpeed(&
myVehicle));
951 if (subLaneShift < std::numeric_limits<int>::max()) {
953 const int newI = i + subLaneShift;
954 if (newI > 0 && newI < (
int)newExpectedSpeeds.size()) {
990 for (
const MSLink*
const link : lane->getLinkCont()) {
991 if (&link->getLane()->getEdge() == curEdge) {
993 const MSLane* target = link->getLane();
994 const std::vector<MSLane*>& lanes2 = curEdge->
getLanes();
995 for (std::vector<MSLane*>::const_iterator it_lane2 = lanes2.begin(); it_lane2 != lanes2.end(); ++it_lane2) {
996 const MSLane* lane2 = *it_lane2;
997 if (lane2 == target) {
998 return prevShift + curShift;
1009 return std::numeric_limits<int>::max();
1044#if defined(DEBUG_MANEUVER) || defined(DEBUG_STATE)
1077 const std::vector<MSVehicle::LaneQ>& preb,
1080 double& latDist,
double& maneuverDist,
int& blocked) {
1082 if (laneOffset != 0) {
1084 const double halfWidth =
getWidth() * 0.5;
1086 if (laneOffset < 0) {
1096 int bestLaneOffset = 0;
1097 double currentDist = 0;
1098 double neighDist = 0;
1110 const int prebOffset = (checkOpposite ? 0 : laneOffset);
1111 for (
int p = 0; p < (int) preb.size(); ++p) {
1112 if (preb[p].lane == prebLane && p + laneOffset >= 0) {
1113 assert(p + prebOffset < (
int)preb.size());
1115 neigh = preb[p + prebOffset];
1116 currentDist = curr.
length;
1117 neighDist = neigh.
length;
1120 if (bestLaneOffset == 0 && preb[p + prebOffset].bestLaneOffset == 0 && !checkOpposite) {
1121#ifdef DEBUG_WANTSCHANGE
1125 <<
" bestLaneOffsetOld=" << bestLaneOffset
1126 <<
" bestLaneOffsetNew=" << laneOffset
1130 bestLaneOffset = prebOffset;
1132 best = preb[p + bestLaneOffset];
1136 assert(curr.
lane !=
nullptr);
1137 assert(neigh.
lane !=
nullptr);
1138 assert(best.
lane !=
nullptr);
1139 double driveToNextStop = -std::numeric_limits<double>::max();
1148#ifdef DEBUG_WANTS_CHANGE
1153 <<
" stopPos=" << stopPos
1154 <<
" currentDist=" << currentDist
1155 <<
" neighDist=" << neighDist
1159 currentDist =
MAX2(currentDist, stopPos);
1160 neighDist =
MAX2(neighDist, stopPos);
1163 const bool right = (laneOffset == -1);
1164 const bool left = (laneOffset == 1);
1167 const bool changeToBest = (right && bestLaneOffset < 0) || (left && bestLaneOffset > 0) || (laneOffset == 0 && bestLaneOffset == 0);
1193#ifdef DEBUG_WANTSCHANGE
1200 <<
"\n leaders=" << leaders.
toString()
1201 <<
"\n followers=" << followers.
toString()
1202 <<
"\n blockers=" << blockers.
toString()
1203 <<
"\n neighLeaders=" << neighLeaders.
toString()
1204 <<
"\n neighFollowers=" << neighFollowers.
toString()
1205 <<
"\n neighBlockers=" << neighBlockers.
toString()
1206 <<
"\n changeToBest=" << changeToBest
1207 <<
" latLaneDist=" << latLaneDist
1216 if (lastBlocked != firstBlocked) {
1267 for (
int i = 0; i < neighLeaders.
numSublanes(); ++i) {
1269 if (vehDist.first !=
nullptr && vehDist.first->isStopped()) {
1287 currentDist += roundaboutBonus;
1288 neighDist += roundaboutBonus;
1307 if ((ret &
LCA_STAY) != 0 && latDist == 0) {
1320 if (changeToBest && abs(bestLaneOffset) > 1
1326#ifdef DEBUG_WANTSCHANGE
1328 std::cout <<
" reserving space for unseen blockers myLeadingBlockerLength=" <<
myLeadingBlockerLength <<
"\n";
1337#ifdef DEBUG_WANTSCHANGE
1343 if (*firstBlocked != neighLeadLongest &&
tieBrakeLeader(*firstBlocked)) {
1352 std::vector<CLeaderDist> collectLeadBlockers;
1353 std::vector<CLeaderDist> collectFollowBlockers;
1354 int blockedFully = 0;
1355 maneuverDist = latDist;
1357 blocked =
checkBlocking(neighLane, latDist, maneuverDist, laneOffset,
1358 leaders, followers, blockers,
1359 neighLeaders, neighFollowers, neighBlockers, &collectLeadBlockers, &collectFollowBlockers,
1360 false, gapFactor, &blockedFully);
1362 const double absLaneOffset = fabs(bestLaneOffset != 0 ? bestLaneOffset : latDist /
SUMO_const_laneWidth);
1363 const double remainingSeconds = ((ret &
LCA_TRACI) == 0 ?
1366 const double plannedSpeed =
informLeaders(blocked, myLca, collectLeadBlockers, remainingSeconds);
1368 if (plannedSpeed >= 0) {
1370 informFollowers(blocked, myLca, collectFollowBlockers, remainingSeconds, plannedSpeed);
1372 if (plannedSpeed > 0) {
1373 commitManoeuvre(blocked, blockedFully, leaders, neighLeaders, neighLane, maneuverDist);
1375#if defined(DEBUG_WANTSCHANGE) || defined(DEBUG_STATE)
1382 <<
" remainingSeconds=" << remainingSeconds
1383 <<
" plannedSpeed=" << plannedSpeed
1394 if (roundaboutBonus > 0) {
1396#ifdef DEBUG_WANTS_CHANGE
1400 <<
" roundaboutBonus=" << roundaboutBonus
1411 latDist = latLaneDist;
1412 maneuverDist = latLaneDist;
1413 blocked =
checkBlocking(neighLane, latDist, maneuverDist, laneOffset,
1414 leaders, followers, blockers,
1415 neighLeaders, neighFollowers, neighBlockers);
1419 ret &= ~LCA_COOPERATIVE;
1435 const double inconvenience = (latLaneDist < 0
1438#ifdef DEBUG_COOPERATE
1446 <<
" inconvenience=" << inconvenience
1448 <<
" wantsChangeToHelp=" << (right ?
"right" :
"left")
1465 && (changeToBest ||
currentDistAllows(neighDist, abs(bestLaneOffset) + 1, laDist))) {
1468#ifdef DEBUG_COOPERATE
1470 std::cout <<
" wants cooperative change\n";
1477 maneuverDist = latDist;
1478 blocked =
checkBlocking(neighLane, latDist, maneuverDist, laneOffset,
1479 leaders, followers, blockers,
1480 neighLeaders, neighFollowers, neighBlockers);
1506 const double vehWidth =
getWidth();
1508 const double leftVehSide = rightVehSide + vehWidth;
1510 double defaultNextSpeed = std::numeric_limits<double>::max();
1512 int leftmostOnEdge = (int)sublaneSides.size() - 1;
1513 while (leftmostOnEdge > 0 && sublaneSides[leftmostOnEdge] > leftVehSide) {
1516 int rightmostOnEdge = leftmostOnEdge;
1517 while (rightmostOnEdge > 0 && sublaneSides[rightmostOnEdge] > rightVehSide + NUMERICAL_EPS) {
1519#ifdef DEBUG_WANTSCHANGE
1521 std::cout <<
" adapted to current sublane=" << rightmostOnEdge <<
" defaultNextSpeed=" << defaultNextSpeed <<
"\n";
1522 std::cout <<
" sublaneSides[rightmostOnEdge]=" << sublaneSides[rightmostOnEdge] <<
" rightVehSide=" << rightVehSide <<
"\n";
1528#ifdef DEBUG_WANTSCHANGE
1530 std::cout <<
" adapted to current sublane=" << rightmostOnEdge <<
" defaultNextSpeed=" << defaultNextSpeed <<
"\n";
1531 std::cout <<
" sublaneSides[rightmostOnEdge]=" << sublaneSides[rightmostOnEdge] <<
" rightVehSide=" << rightVehSide <<
"\n";
1534 double maxGain = -std::numeric_limits<double>::max();
1535 double maxGainRight = -std::numeric_limits<double>::max();
1536 double maxGainLeft = -std::numeric_limits<double>::max();
1537 double latDistNice = std::numeric_limits<double>::max();
1540 double leftMax =
MAX2(
1547 assert(leftMax <= edge.
getWidth());
1549 int sublaneCompact =
MAX2(iMin, rightmostOnEdge - 1);
1555 const double maxLatDist = leftMax - leftVehSide;
1556 const double minLatDist = rightMin - rightVehSide;
1557 const int iStart = laneOffset == 0 ? iMin : 0;
1558 const double rightEnd = laneOffset == 0 ? leftMax : (checkOpposite ?
getLeftBorder() : edge.
getWidth());
1559#ifdef DEBUG_WANTSCHANGE
1561 <<
" checking sublanes rightmostOnEdge=" << rightmostOnEdge
1562 <<
" rightEnd=" << rightEnd
1563 <<
" leftmostOnEdge=" << leftmostOnEdge
1564 <<
" iStart=" << iStart
1566 <<
" sublaneSides=" << sublaneSides.size()
1567 <<
" leftMax=" << leftMax
1568 <<
" minLatDist=" << minLatDist
1569 <<
" maxLatDist=" << maxLatDist
1570 <<
" sublaneCompact=" << sublaneCompact
1573 for (
int i = iStart; i < (int)sublaneSides.size(); ++i) {
1574 if (sublaneSides[i] + vehWidth < rightEnd) {
1580 while (vMin > 0 && j < (
int)sublaneSides.size() && sublaneSides[j] < sublaneSides[i] + vehWidth) {
1582#ifdef DEBUG_WANTSCHANGE
1590 if (laneOffset != 0 &&
overlap(sublaneSides[i], sublaneSides[i] + vehWidth, laneBoundary, laneBoundary)) {
1594 double currentLatDist = sublaneSides[i] - rightVehSide;
1595 if ((laneOffset == 0 && (currentLatDist > maxLatDist || currentLatDist < minLatDist))
1596 || (laneOffset < 0 && currentLatDist > maxLatDist)
1597 || (laneOffset > 0 && currentLatDist < minLatDist)) {
1598#ifdef DEBUG_WANTSCHANGE
1600 std::cout <<
" i=" << i <<
" currentLatDist=" << currentLatDist <<
" outOfBounds\n";
1605 currentLatDist =
MIN2(
MAX2(currentLatDist, minLatDist), maxLatDist);
1609 relativeGain *= 0.5;
1612 if (relativeGain > maxGain && currentLatDist * laneOffset >= 0) {
1613 maxGain = relativeGain;
1616 latDist = currentLatDist;
1617#ifdef DEBUG_WANTSCHANGE
1619 std::cout <<
" i=" << i <<
" vMin=" << vMin <<
" newLatDist=" << latDist <<
" relGain=" << relativeGain <<
"\n";
1625 if (currentLatDist > 0
1629 && maxGain - relativeGain < NUMERICAL_EPS) {
1630 latDist = currentLatDist;
1633#ifdef DEBUG_WANTSCHANGE
1635 std::cout <<
" i=" << i <<
" rightmostOnEdge=" << rightmostOnEdge <<
" vMin=" << vMin <<
" relGain=" << relativeGain <<
" sublaneCompact=" << sublaneCompact <<
" curLatDist=" << currentLatDist <<
"\n";
1639 maxGainRight =
MAX2(maxGainRight, relativeGain);
1641 maxGainLeft =
MAX2(maxGainLeft, relativeGain);
1643 const double subAlignDist = sublaneSides[i] - rightVehSide;
1644 if (fabs(subAlignDist) < fabs(latDistNice)) {
1645 latDistNice = subAlignDist;
1646#ifdef DEBUG_WANTSCHANGE
1648 <<
" nicest sublane=" << i
1649 <<
" side=" << sublaneSides[i]
1650 <<
" rightSide=" << rightVehSide
1651 <<
" latDistNice=" << latDistNice
1652 <<
" maxGainR=" << (maxGainRight == -std::numeric_limits<double>::max() ?
"n/a" :
toString(maxGainRight))
1653 <<
" maxGainL=" << (maxGainLeft == -std::numeric_limits<double>::max() ?
"n/a" :
toString(maxGainLeft))
1660 if (maxGainRight != -std::numeric_limits<double>::max()) {
1661#ifdef DEBUG_WANTSCHANGE
1667#ifdef DEBUG_WANTSCHANGE
1673 if (maxGainLeft != -std::numeric_limits<double>::max()) {
1674#ifdef DEBUG_WANTSCHANGE
1680#ifdef DEBUG_WANTSCHANGE
1687 if ((fabs(maxGainRight) < NUMERICAL_EPS || maxGainRight == -std::numeric_limits<double>::max())
1688 && (right || (alternatives &
LCA_RIGHT) == 0)) {
1691 if ((fabs(maxGainLeft) < NUMERICAL_EPS || maxGainLeft == -std::numeric_limits<double>::max())
1692 && (left || (alternatives &
LCA_LEFT) == 0)) {
1697#ifdef DEBUG_WANTSCHANGE
1700 <<
" defaultNextSpeed=" << defaultNextSpeed
1701 <<
" maxGain=" << maxGain
1702 <<
" maxGainRight=" << maxGainRight
1703 <<
" maxGainLeft=" << maxGainLeft
1706 <<
" latDist=" << latDist
1707 <<
" latDistNice=" << latDistNice
1708 <<
" sublaneCompact=" << sublaneCompact
1721 double acceptanceTime;
1730 double minFactor = 1.0;
1731 for (
int i = 0; i < followers.
numSublanes(); ++i) {
1733 if (follower.first !=
nullptr && follower.second < 2 * follower.first->getCarFollowModel().brakeGap(follower.first->getSpeed())) {
1736 const double fRSF = follower.first->getLane()->getVehicleMaxSpeed(follower.first) / follower.first->getLane()->getSpeedLimit();
1737 if (fRSF > roadSpeedFactor) {
1740 if (factor < minFactor) {
1746 acceptanceTime *= minFactor;
1750 double fullSpeedDrivingSeconds =
MIN2(acceptanceTime, fullSpeedGap / vMax);
1752 if (neighLead.first != 0 && neighLead.first->getSpeed() < vMax) {
1753 fullSpeedGap =
MAX2(0.,
MIN2(fullSpeedGap,
1755 vMax, neighLead.first->
getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel())));
1756 fullSpeedDrivingSeconds =
MIN2(fullSpeedDrivingSeconds, fullSpeedGap / (vMax - neighLead.first->getSpeed()));
1765#ifdef DEBUG_WANTSCHANGE
1768 <<
" considering keepRight:"
1770 <<
" neighDist=" << neighDist
1772 <<
" leaderSpeed=" << (neighLead.first == 0 ? -1 : neighLead.first->getSpeed())
1774 myVehicle.
getSpeed(), neighLead.first->getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel()))
1775 <<
" acceptanceTime=" << acceptanceTime
1776 <<
" fullSpeedGap=" << fullSpeedGap
1777 <<
" fullSpeedDrivingSeconds=" << fullSpeedDrivingSeconds
1778 <<
" dProb=" << deltaProb
1779 <<
" isSlide=" << isSlide
1790 latDist = latLaneDist;
1791 maneuverDist = latLaneDist;
1792 blocked =
checkBlocking(neighLane, latDist, maneuverDist, laneOffset,
1793 leaders, followers, blockers,
1794 neighLeaders, neighFollowers, neighBlockers);
1797 ret &= ~LCA_KEEPRIGHT;
1803#ifdef DEBUG_WANTSCHANGE
1808 <<
" neighDist=" << neighDist
1812 <<
" latDist=" << latDist
1822 int blockedFully = 0;
1823 maneuverDist = latDist;
1824 blocked =
checkBlocking(neighLane, latDist, maneuverDist, laneOffset,
1825 leaders, followers, blockers,
1826 neighLeaders, neighFollowers, neighBlockers,
1827 nullptr,
nullptr,
false, 0, &blockedFully);
1833 ret &= ~LCA_SPEEDGAIN;
1840#ifdef DEBUG_WANTSCHANGE
1845 <<
" latDist=" << latDist
1846 <<
" neighDist=" << neighDist
1849 <<
" stayInLane=" << stayInLane
1860 int blockedFully = 0;
1861 maneuverDist = latDist;
1862 blocked =
checkBlocking(neighLane, latDist, maneuverDist, laneOffset,
1863 leaders, followers, blockers,
1864 neighLeaders, neighFollowers, neighBlockers,
1865 nullptr,
nullptr,
false, 0, &blockedFully);
1870 ret &= ~LCA_SPEEDGAIN;
1875 double latDistSublane = 0.;
1877 const double halfVehWidth =
getWidth() * 0.5;
1880 && bestLaneOffset == 0
1900#ifdef DEBUG_WANTSCHANGE
1911 latDistSublane = -halfLaneWidth + halfVehWidth -
getPosLat();
1914 latDistSublane = halfLaneWidth - halfVehWidth -
getPosLat();
1921 latDistSublane = latDistNice;
1924 latDistSublane = sublaneSides[sublaneCompact] - rightVehSide;
1930 if (fabs(posLat) > hLW) {
1933 latDistSublane -= (posLat - hLW);
1935 latDistSublane += (-posLat - hLW);
1940 if (rightVehSide < 0) {
1941 latDistSublane -= rightVehSide;
1942 }
else if (leftVehSide > edgeWidth) {
1943 latDistSublane -= leftVehSide - edgeWidth;
1962 latDistSublane * latDist > 0) {
1964#if defined(DEBUG_WANTSCHANGE) || defined(DEBUG_STATE) || defined(DEBUG_MANEUVER)
1969 <<
" latDist=" << latDist
1970 <<
" latDistSublane=" << latDistSublane
1971 <<
" relGainSublane=" <<
computeSpeedGain(latDistSublane, defaultNextSpeed)
1972 <<
" maneuverDist=" << maneuverDist
1984#if defined(DEBUG_WANTSCHANGE)
1986 <<
" speedGain=" <<
computeSpeedGain(latDistSublane, defaultNextSpeed) <<
")\n";
1994#if defined(DEBUG_WANTSCHANGE)
1996 std::cout <<
" aborting sublane change due to prior maneuver\n";
2001 latDist = latDistSublane * (
isOpposite() ? -1 : 1);
2006#ifdef DEBUG_WANTSCHANGE
2009 <<
" latDist=" << latDist
2017#ifdef DEBUG_WANTSCHANGE
2023 maneuverDist = latDist;
2024 blocked =
checkBlocking(neighLane, latDist, maneuverDist, laneOffset,
2025 leaders, followers, blockers,
2026 neighLeaders, neighFollowers, neighBlockers);
2029 ret &= ~LCA_SUBLANE;
2055#ifdef DEBUG_WANTSCHANGE
2072 if ((*blocked) !=
nullptr) {
2074#ifdef DEBUG_SLOWDOWN
2083 if (gap > POSITION_EPS) {
2097 (*blocked)->getSpeed(), (*blocked)->getCarFollowModel().getMaxDecel());
2100 std::cout <<
" slowing down for blocked " <<
Named::getIDSecure(*blocked) <<
" targetSpeed=" << targetSpeed <<
"\n";
2121 if (cand !=
nullptr && cand->getBidiLane() == lane) {
2134 const MSLink* link = next !=
nullptr ? lane->
getLinkTo(next) :
nullptr;
2138 assert(preb.size() == lanes.size() ||
isOpposite());
2139#ifdef DEBUG_EXPECTED_SLSPEED
2142 <<
" sublaneOffset=" << sublaneOffset <<
" laneIndex=" << laneIndex <<
" lane=" << lane->
getID() <<
" ahead=" << ahead.
toString() <<
"\n";
2146 for (
int sublane = 0; sublane < (int)ahead.
numSublanes(); ++sublane) {
2147 const int edgeSublane = sublane + sublaneOffset;
2155#ifdef DEBUG_EXPECTED_SLSPEED
2157 std::cout <<
" updateExpectedSublaneSpeeds sublane=" << sublane <<
" doesNotContinue\n";
2164 const MSVehicle* leader = ahead[sublane].first;
2165 const double gap = ahead[sublane].second;
2167 if (leader ==
nullptr) {
2172 const int prebIndex =
isOpposite() ? (int)preb.size() - 1 : laneIndex;
2183#ifdef DEBUG_EXPECTED_SLSPEED
2185 std::cout <<
SIMTIME <<
" updateExpectedSublaneSpeeds sublane=" << sublane <<
" leader=" << leader->
getID() <<
" bidi=" << bidi->
getID() <<
" gap=" << gap <<
" vSafe=" << vSafe <<
"\n";
2195#ifdef DEBUG_EXPECTED_SLSPEED
2197 std::cout <<
" updateExpectedSublaneSpeeds edgeSublane=" << edgeSublane <<
" leader=" << leader->
getID() <<
" gap=" << gap <<
" vSafe=" << vSafe <<
"\n";
2206 double foeRight, foeLeft;
2210 if (pedLeader.first != 0) {
2215#ifdef DEBUG_EXPECTED_SLSPEED
2217 std::cout <<
" updateExpectedSublaneSpeeds edgeSublane=" << edgeSublane <<
" pedLeader=" << pedLeader.first->getID() <<
" gap=" << pedGap <<
" vSafe=" << vSafe <<
"\n";
2225 double foeRight, foeLeft;
2227 const double foeRightBidi = bidi->
getWidth() - foeLeft;
2228 const double foeLeftBidi = bidi->
getWidth() - foeRight;
2233 if (pedLeader.first != 0) {
2238#ifdef DEBUG_EXPECTED_SLSPEED
2240 std::cout <<
" updateExpectedSublaneSpeeds edgeSublane=" << edgeSublane <<
" pedLeader=" << pedLeader.first->getID() <<
" (bidi) gap=" << pedGap <<
" vSafe=" << vSafe <<
"\n";
2245 vSafe =
MIN2(vMax, vSafe);
2252#ifdef DEBUG_EXPECTED_SLSPEED
2254 std::cout <<
" updateExpectedSublaneSpeeds edgeSublane=" << edgeSublane <<
" lane " << lane->
getID() <<
" forbidden\n";
2266 return ((side < -NUMERICAL_EPS
2275 const double deltaV = vMax - vLeader;
2276 if (deltaV > 0 && gap / deltaV < mySpeedGainLookahead && mySpeedGainLookahead > 0) {
2280 const double gapClosingTime =
MAX2(0.0, gap / deltaV);
2281 const double vSafe2 = (gapClosingTime * vSafe + (foreCastTime - gapClosingTime) * vLeader) / foreCastTime;
2282#ifdef DEBUG_EXPECTED_SLSPEED
2284 std::cout <<
" foreCastTime=" << foreCastTime <<
" gapClosingTime=" << gapClosingTime <<
" extrapolated vSafe=" << vSafe2 <<
"\n";
2295 double result = std::numeric_limits<double>::max();
2297 const double vehWidth =
getWidth();
2299 const double leftVehSide = rightVehSide + vehWidth;
2300 for (
int i = 0; i < (int)sublaneSides.size(); ++i) {
2302 if (
overlap(rightVehSide, leftVehSide, sublaneSides[i], leftSide)) {
2307 return result - defaultNextSpeed;
2314 double maxLength = -1;
2325 return iMax >= 0 ? ldi[iMax] : std::make_pair(
nullptr, -1);
2342 double minSpeed = std::numeric_limits<double>::max();
2344 if (ldi[i].first != 0) {
2345 const double speed = ldi[i].first->getSpeed();
2346 if (speed < minSpeed) {
2360 if (v !=
nullptr && v->isStopped()) {
2390 std::vector<CLeaderDist>* collectLeadBlockers,
2391 std::vector<CLeaderDist>* collectFollowBlockers,
2392 bool keepLatGapManeuver,
2394 int* retBlockedFully) {
2397 latDist =
MAX2(
MIN2(latDist, maxDist), -maxDist);
2406 if (laneOffset != 0) {
2417 if (laneOffset != 0) {
2421#ifdef DEBUG_BLOCKING
2433 }
else if (!forcedTraCIChange) {
2439 }
else if (!forcedTraCIChange) {
2445#ifdef DEBUG_BLOCKING
2447 std::cout <<
" checkBlocking latDist=" << latDist <<
" maneuverDist=" << maneuverDist <<
"\n";
2461 if (laneOffset != 0) {
2468 int blockedFully = 0;
2473 if (laneOffset != 0) {
2479 if (retBlockedFully !=
nullptr) {
2480 *retBlockedFully = blockedFully;
2482#ifdef DEBUG_BLOCKING
2485 <<
" canChangeFully=" <<
myCanChangeFully <<
" keepLatGapManeuver=" << keepLatGapManeuver <<
"\n";
2493 blocked |= blockedFully;
2498#ifdef DEBUG_BLOCKING
2503 if (collectFollowBlockers !=
nullptr && collectLeadBlockers !=
nullptr) {
2505 for (std::vector<CLeaderDist>::const_iterator it2 = collectLeadBlockers->begin(); it2 != collectLeadBlockers->end(); ++it2) {
2506 for (std::vector<CLeaderDist>::iterator it = collectFollowBlockers->begin(); it != collectFollowBlockers->end();) {
2507 if ((*it2).first == (*it).first) {
2508#ifdef DEBUG_BLOCKING
2510 std::cout <<
" removed follower " << (*it).first->getID() <<
" because it is already a leader\n";
2513 it = collectFollowBlockers->erase(it);
2527 int laneOffset,
double latDist,
double foeOffset,
bool leaders,
2528 double& safeLatGapRight,
double& safeLatGapLeft,
2529 std::vector<CLeaderDist>* collectBlockers)
const {
2536 const double vehWidth =
getWidth();
2538 const double leftVehSide = rightVehSide + vehWidth;
2539 const double rightVehSideDest = rightVehSide + latDist;
2540 const double leftVehSideDest = leftVehSide + latDist;
2541 const double rightNoOverlap =
MIN2(rightVehSideDest, rightVehSide);
2542 const double leftNoOverlap =
MAX2(leftVehSideDest, leftVehSide);
2543#ifdef DEBUG_BLOCKING
2545 std::cout <<
" checkBlockingVehicles"
2546 <<
" laneOffset=" << laneOffset
2547 <<
" latDist=" << latDist
2548 <<
" foeOffset=" << foeOffset
2549 <<
" vehRight=" << rightVehSide
2550 <<
" vehLeft=" << leftVehSide
2551 <<
" rightNoOverlap=" << rightNoOverlap
2552 <<
" leftNoOverlap=" << leftNoOverlap
2553 <<
" destRight=" << rightVehSideDest
2554 <<
" destLeft=" << leftVehSideDest
2555 <<
" leaders=" << leaders
2561 for (
int i = 0; i < vehicles.
numSublanes(); ++i) {
2563 if (vehDist.first != 0 &&
myCFRelated.count(vehDist.first) == 0) {
2564 const MSVehicle* leader = vehDist.first;
2570 double foeRight, foeLeft;
2572 const bool overlapBefore =
overlap(rightVehSide, leftVehSide, foeRight, foeLeft);
2573 const bool overlapDest =
overlap(rightVehSideDest, leftVehSideDest, foeRight, foeLeft);
2574 const bool overlapAny =
overlap(rightNoOverlap, leftNoOverlap, foeRight, foeLeft);
2575#ifdef DEBUG_BLOCKING
2577 std::cout <<
" foe=" << vehDist.first->getID()
2578 <<
" gap=" << vehDist.second
2580 <<
" foeRight=" << foeRight
2581 <<
" foeLeft=" << foeLeft
2582 <<
" overlapBefore=" << overlapBefore
2583 <<
" overlap=" << overlapAny
2584 <<
" overlapDest=" << overlapDest
2589 if (vehDist.second < 0) {
2590 if (overlapBefore && !overlapDest && !
outsideEdge()) {
2591#ifdef DEBUG_BLOCKING
2593 std::cout <<
" ignoring current overlap to come clear\n";
2597#ifdef DEBUG_BLOCKING
2603 if (collectBlockers ==
nullptr) {
2606 collectBlockers->push_back(vehDist);
2622 const double expectedGap =
MSCFModel::gapExtrapolation(timeTillAction, vehDist.second, leader->
getSpeed(), follower->
getSpeed(), leaderAccel, followerAccel, std::numeric_limits<double>::max(), std::numeric_limits<double>::max());
2625 const double followerExpectedSpeed = follower->
getSpeed() + timeTillAction * followerAccel;
2626 const double leaderExpectedSpeed =
MAX2(0., leader->
getSpeed() + timeTillAction * leaderAccel);
2629#if defined(DEBUG_ACTIONSTEPS) && defined(DEBUG_BLOCKING)
2631 std::cout <<
" timeTillAction=" << timeTillAction
2632 <<
" followerAccel=" << followerAccel
2633 <<
" followerExpectedSpeed=" << followerExpectedSpeed
2634 <<
" leaderAccel=" << leaderAccel
2635 <<
" leaderExpectedSpeed=" << leaderExpectedSpeed
2636 <<
"\n gap=" << vehDist.second
2637 <<
" gapChange=" << (expectedGap - vehDist.second)
2638 <<
" expectedGap=" << expectedGap
2639 <<
" expectedSecureGap=" << expectedSecureGap
2640 <<
" safeLatGapLeft=" << safeLatGapLeft
2641 <<
" safeLatGapRight=" << safeLatGapRight
2648 if (expectedGap < secureGap2) {
2650 if (foeRight > leftVehSide) {
2651 safeLatGapLeft =
MIN2(safeLatGapLeft, foeRight - leftVehSide);
2652 }
else if (foeLeft < rightVehSide) {
2653 safeLatGapRight =
MIN2(safeLatGapRight, rightVehSide - foeLeft);
2656#ifdef DEBUG_BLOCKING
2658 std::cout <<
" blocked by " << vehDist.first->getID() <<
" gap=" << vehDist.second <<
" expectedGap=" << expectedGap
2659 <<
" expectedSecureGap=" << expectedSecureGap <<
" secGap2=" << secureGap2 <<
" safetyFactor=" <<
getSafetyFactor()
2660 <<
" safeLatGapLeft=" << safeLatGapLeft <<
" safeLatGapRight=" << safeLatGapRight
2664 result |= blockType;
2665 if (collectBlockers ==
nullptr) {
2668#ifdef DEBUG_BLOCKING
2669 }
else if (
gDebugFlag2 && expectedGap < expectedSecureGap) {
2670 std::cout <<
" ignore blocker " << vehDist.first->getID() <<
" gap=" << vehDist.second <<
" expectedGap=" << expectedGap
2671 <<
" expectedSecureGap=" << expectedSecureGap <<
" secGap2=" << secureGap2 <<
" safetyFactor=" <<
getSafetyFactor() <<
"\n";
2674 if (collectBlockers !=
nullptr) {
2677 collectBlockers->push_back(vehDist);
2694 const double leftVehSide = rightVehSide + vehWidth;
2695#ifdef DEBUG_BLOCKING
2697 std::cout <<
" updateCFRelated foeOffset=" << foeOffset <<
" vehicles=" << vehicles.
toString() <<
"\n";
2700 for (
int i = 0; i < vehicles.
numSublanes(); ++i) {
2702 if (vehDist.first != 0 && (
myCFRelated.count(vehDist.first) == 0 || vehDist.second < 0)) {
2703 double foeRight, foeLeft;
2705#ifdef DEBUG_BLOCKING
2707 std::cout <<
" foe=" << vehDist.first->getID() <<
" gap=" << vehDist.second
2709 <<
" foeOffset=" << foeOffset
2710 <<
" egoR=" << rightVehSide <<
" egoL=" << leftVehSide
2711 <<
" iR=" << foeRight <<
" iL=" << foeLeft
2719 && (vehDist.second >= vehDist.first->getVehicleType().getMinGap() * (1 - vehDist.first->getCarFollowModel().getCollisionMinGapFactor())
2725 && -vehDist.second < vehDist.first->getVehicleType().getMinGap()
2728#ifdef DEBUG_BLOCKING
2730 std::cout <<
" ignoring cfrelated foe=" << vehDist.first->getID() <<
"\n";
2735 const int erased = (int)
myCFRelated.erase(vehDist.first);
2736#ifdef DEBUG_BLOCKING
2738 std::cout <<
" restoring cfrelated foe=" << vehDist.first->getID() <<
"\n";
2751 assert(right <= left);
2752 assert(right2 <= left2);
2753 return left2 >= right + NUMERICAL_EPS && left >= right2 + NUMERICAL_EPS;
2774 return changeReason;
2781 if (sd1.
state == 0) {
2783 }
else if (sd2.
state == 0) {
2793#ifdef DEBUG_DECISION
2799 <<
" dir1=" << sd1.
dir
2803 <<
" dir2=" << sd2.
dir
2819 if (reason1 < reason2) {
2821 return (!can1 && can2 && sd1.
sameDirection(sd2)) ? sd2 : sd1;
2823 }
else if (reason1 > reason2) {
2825 return (!can2 && can1 && sd1.
sameDirection(sd2)) ? sd1 : sd2;
2833 }
else if (sd2.
dir == 0) {
2838 assert(sd1.
dir == -1);
2839 assert(sd2.
dir == 1);
2842 }
else if (sd2.
latDist >= 0) {
2898 double& currentDist,
2901 double roundaboutBonus,
2906 const bool right = (laneOffset == -1);
2907 const bool left = (laneOffset == 1);
2910 if (laneOffset != 0) {
2916 const double neighLeftPlace =
MAX2(0., neighDist - forwardPos - maxJam);
2920#ifdef DEBUG_STRATEGIC_CHANGE
2924 <<
" forwardPos=" << forwardPos
2926 <<
" laDist=" << laDist
2927 <<
" currentDist=" << currentDist
2928 <<
" usableDist=" << usableDist
2929 <<
" bestLaneOffset=" << bestLaneOffset
2930 <<
" best.length=" << best.
length
2931 <<
" maxJam=" << maxJam
2932 <<
" neighLeftPlace=" << neighLeftPlace
2939 if (laneOffset == 0) {
2946#ifdef DEBUG_STRATEGIC_CHANGE
2948 std::cout <<
SIMTIME <<
" returnToLaneBounds\n";
2957 if (link !=
nullptr &&
getWidth() < next->
getWidth() && distOnLane < 100) {
2963 latDist = -rightVehSide;
2966#ifdef DEBUG_STRATEGIC_CHANGE
2973 latDist = -(leftVehSide - next->
getWidth());
2976#ifdef DEBUG_STRATEGIC_CHANGE
2985 }
else if (laneOffset != 0 && changeToBest && bestLaneOffset == curr.
bestLaneOffset
2988 if (!
mustOvertakeStopped(
false, neighLane, neighLeaders, leaders, forwardPos, neighDist, right, latLaneDist, neigh.
bestContinuations, currentDist, latDist)) {
2989 latDist = latLaneDist;
2991#ifdef DEBUG_STRATEGIC_CHANGE
2993 std::cout <<
SIMTIME <<
" mustChangeToBest\n";
2997#ifdef DEBUG_STRATEGIC_CHANGE
2999 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" avoidStoppedNeigh\n";
3019#ifdef DEBUG_STRATEGIC_CHANGE
3022 <<
" avoid overtaking on the right nv=" << nv->
getID()
3034 if (laneOffset != 0 &&
myStrategicParam >= 0 && noOpposites &&
mustOvertakeStopped(
true, neighLane, leaders, neighLeaders, forwardPos, neighDist, right, latLaneDist, curr.
bestContinuations, currentDist, latDist)) {
3035#ifdef DEBUG_STRATEGIC_CHANGE
3037 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" mustOvertakeStopped\n";
3046 }
else if (!changeToBest && (
currentDistDisallows(neighLeftPlace, abs(bestLaneOffset) + 2, laDist))) {
3053#ifdef DEBUG_STRATEGIC_CHANGE
3055 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" could not change back and forth in time (1) neighLeftPlace=" << neighLeftPlace <<
"\n";
3061 && bestLaneOffset == 0
3064 && roundaboutBonus == 0
3071#ifdef DEBUG_STRATEGIC_CHANGE
3073 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" does not want to leave the bestLane (neighDist=" << neighDist <<
")\n";
3078 && bestLaneOffset == 0
3084#ifdef DEBUG_STRATEGIC_CHANGE
3086 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" does not want to get stranded on the on-ramp of a highway\n";
3100 MSLane* shadowPrev =
nullptr;
3102 if (*it ==
nullptr) {
3106 if (shadow ==
nullptr || currentShadowDist >= requiredDist) {
3109 if (shadowPrev !=
nullptr) {
3112 currentShadowDist += shadow->
getLength();
3113 shadowPrev = shadow;
3114#ifdef DEBUG_STRATEGIC_CHANGE
3116 std::cout <<
" shadow=" << shadow->
getID() <<
" currentShadowDist=" << currentShadowDist <<
"\n";
3120#ifdef DEBUG_STRATEGIC_CHANGE
3122 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" currentShadowDist=" << currentShadowDist <<
" requiredDist=" << requiredDist <<
" overlap=" <<
overlap <<
"\n";
3125 if (currentShadowDist < requiredDist && currentShadowDist < usableDist) {
3128#ifdef DEBUG_STRATEGIC_CHANGE
3130 std::cout <<
" must change for shadowLane end latDist=" << latDist <<
" myLeftSpace=" <<
myLeftSpace <<
"\n";
3138#if defined(DEBUG_STRATEGIC_CHANGE) || defined(DEBUG_TRACI)
3150 }
else if (((retTraCI &
LCA_RIGHT) != 0 && laneOffset < 0)
3151 || ((retTraCI &
LCA_LEFT) != 0 && laneOffset > 0)) {
3153 latDist = latLaneDist;
3156#if defined(DEBUG_STRATEGIC_CHANGE) || defined(DEBUG_TRACI)
3167 double posOnLane,
double neighDist,
bool right,
double latLaneDist,
const std::vector<MSLane*>& conts,
double& currentDist,
double& latDist) {
3168 bool mustOvertake =
false;
3173 const bool curHasStopped = stoppedLeader !=
nullptr;
3174 const int dir = latLaneDist < 0 ? -1 : 1;
3180 for (
int i = rightmost; i <= leftmost; i++) {
3184 const double remaining =
MIN2(neighDist, currentDist) - posOnLane;
3185#ifdef DEBUG_STRATEGIC_CHANGE
3187 std::cout <<
" overtakeDist=" << overtakeDist <<
" remaining=" << remaining
3189 <<
" hasLaneBeyond=" << hasLaneBeyond
3194 remaining > overtakeDist
3196 && (!checkCurrent || !checkOverTakeRight || !right)
3205 latDist = latLaneDist;
3206 mustOvertake =
true;
3207#ifdef DEBUG_STRATEGIC_CHANGE
3210 <<
" overtake " << (leader.first->isStopped() ?
"stopped" :
"bidi") <<
" leader=" << leader.first->getID()
3211 <<
" newCurrentDist=" << currentDist
3212 <<
" overtakeDist=" << overtakeDist
3213 <<
" remaining=" << remaining
3229 mustOvertake =
true;
3230 if (i >= rightmost && i <= leftmost) {
3237 return mustOvertake;
3258 double& maneuverDist,
3294 const double oldLatDist = latDist;
3295 const double oldManeuverDist = maneuverDist;
3300 const double halfWidth =
getWidth() * 0.5;
3306 double surplusGapRight = oldCenter - halfWidth;
3307 double surplusGapLeft =
getLeftBorder(laneOffset != 0) - oldCenter - halfWidth;
3308 const bool stayInLane = (laneOffset == 0
3312 && (surplusGapLeft >= 0 && surplusGapRight >= 0)));
3315 std::swap(surplusGapLeft, surplusGapRight);
3317#ifdef DEBUG_KEEP_LATGAP
3319 std::cout <<
"\n " <<
SIMTIME <<
" keepLatGap() laneOffset=" << laneOffset
3320 <<
" latDist=" << latDist
3321 <<
" maneuverDist=" << maneuverDist
3325 <<
" gapFactor=" << gapFactor
3326 <<
" stayInLane=" << stayInLane <<
"\n"
3327 <<
" stayInEdge: surplusGapRight=" << surplusGapRight <<
" surplusGapLeft=" << surplusGapLeft <<
"\n";
3331 if (surplusGapLeft < 0 || surplusGapRight < 0) {
3341 if (laneOffset != 0) {
3344 updateGaps(neighLeaders, neighRight, oldCenter, gapFactor, surplusGapRight, surplusGapLeft,
true);
3345 updateGaps(neighFollowers, neighRight, oldCenter, gapFactor, surplusGapRight, surplusGapLeft,
true, netOverlap);
3347#ifdef DEBUG_KEEP_LATGAP
3349 std::cout <<
" minGapLat: surplusGapRight=" << surplusGapRight <<
" surplusGapLeft=" << surplusGapLeft <<
"\n"
3359 if (stayInLane || laneOffset == 1) {
3362 surplusGapRight =
MIN2(surplusGapRight,
MAX2(0.0, halfLaneWidth + posLat - halfWidth));
3363 physicalGapRight =
MIN2(physicalGapRight,
MAX2(0.0, halfLaneWidth + posLat - halfWidth));
3365 if (stayInLane || laneOffset == -1) {
3368 surplusGapLeft =
MIN2(surplusGapLeft,
MAX2(0.0, halfLaneWidth - posLat - halfWidth));
3369 physicalGapLeft =
MIN2(physicalGapLeft,
MAX2(0.0, halfLaneWidth - posLat - halfWidth));
3371#ifdef DEBUG_KEEP_LATGAP
3373 std::cout <<
" stayInLane: surplusGapRight=" << surplusGapRight <<
" surplusGapLeft=" << surplusGapLeft <<
"\n";
3377 if (surplusGapRight + surplusGapLeft < 0) {
3382 const double equalDeficit = 0.5 * (surplusGapLeft + surplusGapRight);
3383 if (surplusGapRight < surplusGapLeft) {
3385 const double delta =
MIN2(equalDeficit - surplusGapRight, physicalGapLeft);
3387 maneuverDist = delta;
3388#ifdef DEBUG_KEEP_LATGAP
3390 std::cout <<
" insufficient latSpace, move left: delta=" << delta <<
"\n";
3395 const double delta =
MIN2(equalDeficit - surplusGapLeft, physicalGapRight);
3397 maneuverDist = -delta;
3398#ifdef DEBUG_KEEP_LATGAP
3400 std::cout <<
" insufficient latSpace, move right: delta=" << delta <<
"\n";
3406 latDist =
MAX2(
MIN2(latDist, surplusGapLeft), -surplusGapRight);
3407 maneuverDist =
MAX2(
MIN2(maneuverDist, surplusGapLeft), -surplusGapRight);
3408 if ((state &
LCA_KEEPRIGHT) != 0 && maneuverDist != oldManeuverDist) {
3410 latDist = oldLatDist;
3411 maneuverDist = oldManeuverDist;
3413#ifdef DEBUG_KEEP_LATGAP
3415 std::cout <<
" adapted latDist=" << latDist <<
" maneuverDist=" << maneuverDist <<
" (old=" << oldLatDist <<
")\n";
3430#ifdef DEBUG_KEEP_LATGAP
3432 std::cout <<
" traci influenced latDist=" << latDist <<
"\n";
3438 const bool traciChange = ((state | traciState) &
LCA_TRACI) != 0;
3439 if (nonSublaneChange && !traciChange) {
3441#ifdef DEBUG_KEEP_LATGAP
3443 std::cout <<
" wanted changeToLeft oldLatDist=" << oldLatDist <<
", blocked latGap changeToRight\n";
3446 latDist = oldLatDist;
3449#ifdef DEBUG_KEEP_LATGAP
3451 std::cout <<
" wanted changeToRight oldLatDist=" << oldLatDist <<
", blocked latGap changeToLeft\n";
3454 latDist = oldLatDist;
3464#ifdef DEBUG_KEEP_LATGAP
3466 std::cout <<
" latDistUpdated=" << latDist <<
" oldLatDist=" << oldLatDist <<
"\n";
3469 blocked =
checkBlocking(neighLane, latDist, maneuverDist, laneOffset, leaders, followers, blockers, neighLeaders, neighFollowers, neighBlockers,
nullptr,
nullptr, nonSublaneChange);
3472 state = (state & ~LCA_STAY);
3483#if defined(DEBUG_KEEP_LATGAP) || defined(DEBUG_STATE)
3485 std::cout <<
" latDist2=" << latDist
3499 double& surplusGapRight,
double& surplusGapLeft,
3500 bool saveMinGap,
double netOverlap,
3502 std::vector<CLeaderDist>* collectBlockers) {
3504 const double halfWidth =
getWidth() * 0.5 + NUMERICAL_EPS;
3507 if (others[i].first != 0 && others[i].second <= 0
3509 && (netOverlap == 0 || others[i].second + others[i].first->getVehicleType().getMinGap() < netOverlap)) {
3513 double foeRight, foeLeft;
3515 const double foeCenter = foeRight + 0.5 * res;
3516 const double gap =
MIN2(fabs(foeRight - oldCenter), fabs(foeLeft - oldCenter)) - halfWidth;
3519 const double currentMinGap = desiredMinGap * gapFactor;
3530#if defined(DEBUG_BLOCKING) || defined(DEBUG_KEEP_LATGAP)
3532 std::cout <<
" updateGaps"
3534 <<
" foe=" << foe->
getID()
3535 <<
" foeRight=" << foeRight
3536 <<
" foeLeft=" << foeLeft
3537 <<
" oldCenter=" << oldCenter
3538 <<
" gap=" << others[i].second
3539 <<
" latgap=" << gap
3540 <<
" currentMinGap=" << currentMinGap
3541 <<
" surplusGapRight=" << surplusGapRight
3542 <<
" surplusGapLeft=" << surplusGapLeft
3550 if (foeCenter < oldCenter) {
3552 surplusGapRight =
MIN3(surplusGapRight, gap - currentMinGap,
MAX2(currentMinGap, gap - foeManeuverDist));
3555 surplusGapLeft =
MIN3(surplusGapLeft, gap - currentMinGap,
MAX2(currentMinGap, gap - foeManeuverDist));
3558 if (foeCenter < oldCenter) {
3559#if defined(DEBUG_BLOCKING) || defined(DEBUG_KEEP_LATGAP)
3561 std::cout <<
" new minimum rightGap=" << gap <<
"\n";
3566#if defined(DEBUG_BLOCKING) || defined(DEBUG_KEEP_LATGAP)
3568 std::cout <<
" new minimum leftGap=" << gap <<
"\n";
3574 if (collectBlockers !=
nullptr) {
3576 if ((foeCenter < oldCenter && latDist < 0 && gap < (desiredMinGap - latDist))
3577 || (foeCenter > oldCenter && latDist > 0 && gap < (desiredMinGap + latDist))) {
3578 collectBlockers->push_back(others[i]);
3595 int currentDirection =
mySpeedLat >= 0 ? 1 : -1;
3596 int directionWish = latDist >= 0 ? 1 : -1;
3603 maxSpeedLat =
MIN2(maxSpeedLat, speedBound);
3607 maxSpeedLat =
MAX2(maxSpeedLat, speedBound);
3616 accelLat =
MAX2(accelLat, 2 * edgeOverlap);
3617 maxSpeedLat =
MAX2(maxSpeedLat, edgeOverlap);
3620#ifdef DEBUG_MANEUVER
3624 <<
" computeSpeedLat()"
3625 <<
" latDist=" << latDist
3626 <<
" maneuverDist=" << maneuverDist
3627 <<
" urgent=" << urgent
3629 <<
" currentDirection=" << currentDirection
3630 <<
" directionWish=" << directionWish
3632 <<
" maxSpeedLat=" << maxSpeedLat
3638 if (directionWish == 1) {
3652 if (maneuverDist * latDist > 0) {
3653 maneuverDist = fullLatDist;
3656#ifdef DEBUG_MANEUVER
3660 <<
" fullLatDist=" << fullLatDist
3661 <<
" speedAccel=" << speedAccel
3662 <<
" speedDecel=" << speedDecel
3663 <<
" speedBound=" << speedBound
3667 if (speedDecel * speedAccel <= 0 && (
3669 (latDist >= 0 && speedAccel >= speedBound && speedBound >= speedDecel)
3670 || (latDist <= 0 && speedAccel <= speedBound && speedBound <= speedDecel))) {
3672#ifdef DEBUG_MANEUVER
3674 std::cout <<
" computeSpeedLat a)\n";
3681#ifdef DEBUG_MANEUVER
3683 std::cout <<
" computeSpeedLat b)\n";
3690 if ((fabs(minDistAccel) < fabs(fullLatDist)) || (fabs(minDistAccel - fullLatDist) < NUMERICAL_EPS)) {
3691#ifdef DEBUG_MANEUVER
3693 std::cout <<
" computeSpeedLat c)\n";
3698#ifdef DEBUG_MANEUVER
3700 std::cout <<
" minDistAccel=" << minDistAccel <<
"\n";
3705 if ((fabs(minDistCurrent) < fabs(fullLatDist)) || (fabs(minDistCurrent - fullLatDist) < NUMERICAL_EPS)) {
3706#ifdef DEBUG_MANEUVER
3708 std::cout <<
" computeSpeedLat d)\n";
3715#ifdef DEBUG_MANEUVER
3717 std::cout <<
" computeSpeedLat e)\n";
3729#ifdef DEBUG_MANEUVER
3731 std::cout <<
" rightDanger speedLat=" << speedLat <<
"\n";
3736#ifdef DEBUG_MANEUVER
3738 std::cout <<
" leftDanger speedLat=" << speedLat <<
"\n";
3753 const bool indirect = turnInfo.second ==
nullptr ? false : turnInfo.second->isIndirect();
3786 double maneuverDist) {
3789 double secondsToLeaveLane;
3799#if defined(DEBUG_MANEUVER) || defined(DEBUG_COMMITTED_SPEED)
3815 double nextLeftSpace;
3816 if (nextActionStepSpeed > 0.) {
3831#if defined(DEBUG_MANEUVER) || defined(DEBUG_COMMITTED_SPEED)
3835 <<
" avoidArrivalSpeed=" << avoidArrivalSpeed
3838 <<
"\n nextLeftSpace=" << nextLeftSpace
3839 <<
" nextActionStepSpeed=" << nextActionStepSpeed
3840 <<
" nextActionStepRemainingSeconds=" << secondsToLeaveLane - timeTillActionStep
3850#if defined(DEBUG_MANEUVER) || defined(DEBUG_COMMITTED_SPEED)
3854 <<
" secondsToLeave=" << secondsToLeaveLane
3876 const double vehWidth =
getWidth();
3878 const double leftVehSide = rightVehSide + vehWidth;
3879 const double rightVehSideDest = rightVehSide + latDist;
3880 const double leftVehSideDest = leftVehSide + latDist;
3881#if defined(DEBUG_MANEUVER) || defined(DEBUG_COMMITTED_SPEED)
3883 std::cout <<
" commitFollowSpeed"
3884 <<
" latDist=" << latDist
3885 <<
" foeOffset=" << foeOffset
3886 <<
" vehRight=" << rightVehSide
3887 <<
" vehLeft=" << leftVehSide
3888 <<
" destRight=" << rightVehSideDest
3889 <<
" destLeft=" << leftVehSideDest
3895 if (vehDist.first != 0) {
3896 const MSVehicle* leader = vehDist.first;
3898 double foeRight, foeLeft;
3900#if defined(DEBUG_MANEUVER) || defined(DEBUG_COMMITTED_SPEED)
3902 std::cout <<
" foe=" << vehDist.first->getID()
3903 <<
" gap=" << vehDist.second
3905 <<
" foeRight=" << foeRight
3906 <<
" foeLeft=" << foeLeft
3907 <<
" overlapBefore=" <<
overlap(rightVehSide, leftVehSide, foeRight, foeLeft)
3908 <<
" overlapDest=" <<
overlap(rightVehSideDest, leftVehSideDest, foeRight, foeLeft)
3912 if (
overlap(rightVehSideDest, leftVehSideDest, foeRight, foeLeft)) {
3916 speed =
MIN2(speed, vSafe);
3917#if defined(DEBUG_MANEUVER) || defined(DEBUG_COMMITTED_SPEED)
3919 std::cout <<
" case1 vsafe=" << vSafe <<
" speed=" << speed <<
"\n";
3922 }
else if (
overlap(rightVehSide, leftVehSide, foeRight, foeLeft)) {
3927 speed =
MIN2(speed, vSafe);
3928#if defined(DEBUG_MANEUVER) || defined(DEBUG_COMMITTED_SPEED)
3930 std::cout <<
" case2 vsafe=" << vSafe <<
" speed=" << speed <<
"\n";
3950 return myOppositeParam <= 0 ? std::numeric_limits<double>::max() : 1 /
myOppositeParam;
4009 }
else if (key ==
"speedGainProbabilityRight") {
4011 }
else if (key ==
"speedGainProbabilityLeft") {
4013 }
else if (key ==
"keepRightProbability") {
4015 }
else if (key ==
"lookAheadSpeed") {
4017 }
else if (key ==
"sigmaState") {
4020 }
else if (key ==
"speedGainRP") {
4022 }
else if (key ==
"speedGainLP") {
4024 }
else if (key ==
"keepRightP") {
4094 }
else if (key ==
"speedGainProbabilityRight") {
4096 }
else if (key ==
"speedGainProbabilityLeft") {
4098 }
else if (key ==
"keepRightProbability") {
4100 }
else if (key ==
"lookAheadSpeed") {
4102 }
else if (key ==
"sigmaState") {
4116 const std::pair<MSVehicle*, double>& leader,
4117 const std::pair<MSVehicle*, double>& follower,
4118 const std::pair<MSVehicle*, double>& neighLead,
4119 const std::pair<MSVehicle*, double>& neighFollow,
4121 const std::vector<MSVehicle::LaneQ>& preb,
4127#ifdef DEBUG_WANTSCHANGE
4129 std::cout <<
"\nWANTS_CHANGE\n" <<
SIMTIME
4133 <<
" neigh=" << neighLane.
getID()
4137 <<
" considerChangeTo=" << (laneOffset == -1 ?
"right" :
"left")
4151 double maneuverDist;
4154 leaders, followers, blockers,
4155 neighLeaders, neighFollowers, neighBlockers,
4157 lastBlocked, firstBlocked, latDist, maneuverDist, blocked);
4161 result &= ~LCA_SUBLANE;
4162 result |=
getLCA(result, latDist);
4164#if defined(DEBUG_WANTSCHANGE) || defined(DEBUG_STATE)
4169 <<
" wantsChangeTo=" << (laneOffset == -1 ?
"right" :
"left")
4170 << ((result &
LCA_URGENT) ?
" (urgent)" :
"")
4176 << ((result &
LCA_TRACI) ?
" (traci)" :
"")
4228 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" bgap=" << brakeGap <<
" maneuverDist=" << maneuverDist
#define HELP_DECEL_FACTOR
#define LOOK_AHEAD_MIN_SPEED
#define LCA_RIGHT_IMPATIENCE
#define REACT_TO_STOPPED_DISTANCE
#define RELGAIN_NORMALIZATION_MIN_SPEED
#define CUT_IN_LEFT_SPEED_THRESHOLD
#define MAX_ONRAMP_LENGTH
#define LOOK_AHEAD_SPEED_MEMORY
#define ARRIVALPOS_LAT_THRESHOLD
#define SPEEDGAIN_MEMORY_FACTOR
#define LOOK_AHEAD_MIN_SPEED
#define SPEEDGAIN_DECAY_FACTOR
#define LATGAP_SPEED_THRESHOLD
#define GAIN_PERCEPTION_THRESHOLD
#define LATGAP_SPEED_THRESHOLD2
std::pair< const MSVehicle *, double > CLeaderDist
std::pair< const MSPerson *, double > PersonDist
LatAlignmentDefinition
Possible ways to choose the lateral alignment, i.e., how vehicles align themselves within their lane.
@ RIGHT
drive on the right side
@ GIVEN
The alignment as offset is given.
@ DEFAULT
No information given; use default.
@ LEFT
drive on the left side
@ ARBITRARY
maintain the current alignment
@ NICE
align with the closest sublane border
@ COMPACT
align with the rightmost sublane that allows keeping the current speed
@ CENTER
drive in the middle
@ SVC_EMERGENCY
public emergency vehicles
@ RIGHT
At the rightmost side of the lane.
@ GIVEN
The position is given.
@ DEFAULT
No information given; use default.
@ LEFT
At the leftmost side of the lane.
@ CENTER
At the center of the lane.
LinkDirection
The different directions a link between two lanes may take (or a stream between two edges)....
@ PARTLEFT
The link is a partial left direction.
@ RIGHT
The link is a (hard) right direction.
@ TURN
The link is a 180 degree turn.
@ LEFT
The link is a (hard) left direction.
@ STRAIGHT
The link is a straight direction.
@ TURN_LEFTHAND
The link is a 180 degree turn (left-hand network)
@ PARTRIGHT
The link is a partial right direction.
@ NODIR
The link has no direction (is a dead end link)
LaneChangeAction
The state of a vehicle's lane-change behavior.
@ LCA_BLOCKED_LEFT
blocked left
@ LCA_KEEPRIGHT
The action is due to the default of keeping right "Rechtsfahrgebot".
@ LCA_BLOCKED
blocked in all directions
@ LCA_URGENT
The action is urgent (to be defined by lc-model)
@ LCA_BLOCKED_BY_RIGHT_LEADER
The vehicle is blocked by right leader.
@ LCA_STAY
Needs to stay on the current lane.
@ LCA_SUBLANE
used by the sublane model
@ LCA_BLOCKED_BY_LEADER
blocked by leader
@ LCA_BLOCKED_BY_LEFT_FOLLOWER
The vehicle is blocked by left follower.
@ LCA_AMBLOCKINGFOLLOWER_DONTBRAKE
@ LCA_COOPERATIVE
The action is done to help someone else.
@ LCA_OVERLAPPING
The vehicle is blocked being overlapping.
@ LCA_LEFT
Wants go to the left.
@ LCA_BLOCKED_RIGHT
blocked right
@ LCA_BLOCKED_BY_RIGHT_FOLLOWER
The vehicle is blocked by right follower.
@ LCA_STRATEGIC
The action is needed to follow the route (navigational lc)
@ LCA_AMBACKBLOCKER_STANDING
@ LCA_CHANGE_REASONS
reasons of lane change
@ LCA_TRACI
The action is due to a TraCI request.
@ LCA_SPEEDGAIN
The action is due to the wish to be faster (tactical lc)
@ LCA_WANTS_LANECHANGE
lane can change
@ LCA_RIGHT
Wants go to the right.
@ LCA_BLOCKED_BY_FOLLOWER
blocker by follower
@ LCA_BLOCKED_BY_LEFT_LEADER
@ SUMO_ATTR_LCA_COOPERATIVE_SPEED
@ SUMO_ATTR_LCA_ASSERTIVE
@ SUMO_ATTR_LCA_LANE_DISCIPLINE
@ SUMO_ATTR_LCA_TURN_ALIGNMENT_DISTANCE
@ SUMO_ATTR_LCA_LOOKAHEADLEFT
@ SUMO_ATTR_LCA_SPEEDGAIN_PARAM
@ SUMO_ATTR_LCA_MAXDISTLATSTANDING
@ SUMO_ATTR_LCA_IMPATIENCE
@ SUMO_ATTR_LCA_COOPERATIVE_ROUNDABOUT
@ SUMO_ATTR_LCA_SPEEDGAIN_LOOKAHEAD
@ SUMO_ATTR_LCA_MAXSPEEDLATFACTOR
@ SUMO_ATTR_LCA_MAXSPEEDLATSTANDING
@ SUMO_ATTR_LCA_KEEPRIGHT_PARAM
@ SUMO_ATTR_LCA_COOPERATIVE_PARAM
@ SUMO_ATTR_LCA_OPPOSITE_PARAM
@ SUMO_ATTR_LCA_SPEEDGAIN_REMAIN_TIME
@ SUMO_ATTR_LCA_OVERTAKE_DELTASPEED_FACTOR
@ SUMO_ATTR_LCA_SUBLANE_PARAM
@ SUMO_ATTR_LCA_ACCEL_LAT
@ SUMO_ATTR_LCA_STRATEGIC_PARAM
@ SUMO_ATTR_LCA_KEEPRIGHT_ACCEPTANCE_TIME
@ SUMO_ATTR_LCA_TIME_TO_IMPATIENCE
@ SUMO_ATTR_LCA_SPEEDGAINRIGHT
int gPrecision
the precision for floating point outputs
const double SUMO_const_laneWidth
const double SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
A class responsible for exchanging messages between cars involved in lane-change interaction.
Interface for lane-change models.
double getForwardPos() const
get vehicle position relative to the forward direction lane
virtual double getExtraReservation(int bestLaneOffset, double neighExtraDist=0) const
bool hasBlueLight() const
void addLCSpeedAdvice(const double vSafe, int flag)
Takes a vSafe (speed advice for speed in the next simulation step), converts it into an acceleration ...
double getPreviousManeuverDist() const
std::vector< std::pair< double, int > > myLCAccelerationAdvices
virtual void setOwnState(const int state)
int myPreviousState
lane changing state from the previous simulation step
double getManeuverDist() const
Returns the remaining unblocked distance for the current maneuver. (only used by sublane model)
int myOwnState
The current state of the vehicle.
virtual void prepareStep()
MSLane * getShadowLane() const
Returns the lane the vehicle's shadow is on during continuous/sublane lane change.
double myLastLateralGapRight
double myCommittedSpeed
the speed when committing to a change maneuver
virtual LatAlignmentDefinition getDesiredAlignment() const
static const double NO_NEIGHBOR
double myMaxDistLatStanding
static bool myAllowOvertakingRight
whether overtaking on the right is permitted
bool canOvertakeRight(const MSVehicle *const nv, const double dist, const double maxSpeedDiff, const double helpOvertakeSpeed, double &vSafe, double &deltaV) const
int & getCanceledState(const int dir)
double myMaxSpeedLatFactor
const LaneChangeModel myModel
the type of this model
bool cancelRequest(int state, int laneOffset)
whether the influencer cancels the given request
virtual bool avoidOvertakeRight(const MSVehicle *const neighLeader, const bool allowProb=false) const
double getMaxSpeedLat2() const
return the max of maxSpeedLat and lcMaxSpeedLatStanding
const MSCFModel & getCarFollowModel() const
The vehicle's car following model.
double mySpeedLat
the current lateral speed
double myMaxSpeedLatStanding
MSVehicle & myVehicle
The vehicle this lane-changer belongs to.
double myLastLateralGapLeft
the minimum lateral gaps to other vehicles that were found when last changing to the left and right
virtual bool debugVehicle() const
whether the current vehicles shall be debugged
virtual double getArrivalPos() const
Returns this vehicle's desired arrivalPos for its current route (may change on reroute)
const SUMOVehicleParameter & getParameter() const
Returns the vehicle's parameter (including departure definition)
double getLength() const
Returns the vehicle's length.
const MSEdge * getEdge() const
Returns the edge the vehicle is currently at.
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
const MSStop & getNextStop() const
SUMOVehicleClass getVClass() const
Returns the vehicle's access class.
const MSRoute & getRoute() const
Returns the current route.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
The car-following model abstraction.
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
static double gapExtrapolation(const double duration, const double currentGap, double v1, double v2, double a1=0, double a2=0, const double maxV1=std::numeric_limits< double >::max(), const double maxV2=std::numeric_limits< double >::max())
return the resulting gap if, starting with gap currentGap, two vehicles continue with constant accele...
virtual double minNextSpeedEmergency(double speed, const MSVehicle *const veh=0) const
Returns the minimum speed after emergency braking, given the current speed (depends on the numerical ...
virtual double followSpeedTransient(double duration, const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel) const
Computes the vehicle's follow speed that avoids a collision for the given amount of time.
double getEmergencyDecel() const
Get the vehicle type's maximal physically possible deceleration [m/s^2].
static double brakeGapEuler(const double speed, const double decel, const double headwayTime)
static double avoidArrivalAccel(double dist, double time, double speed, double maxDecel)
Computes the acceleration needed to arrive not before the given time.
virtual double minNextSpeed(double speed, const MSVehicle *const veh=0) const
Returns the minimum speed given the current speed (depends on the numerical update scheme and its ste...
virtual void setMaxDecel(double decel)
Sets a new value for maximal comfortable deceleration [m/s^2].
@ LANE_CHANGE
the return value is used for lane change calculations
virtual double getSecureGap(const MSVehicle *const veh, const MSVehicle *const, const double speed, const double leaderSpeed, const double leaderMaxDecel) const
Returns the minimum gap to reserve if the leader is braking at maximum (>=0)
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
static double estimateArrivalTime(double dist, double speed, double maxSpeed, double accel)
Computes the time needed to travel a distance dist given an initial speed and constant acceleration....
virtual double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0, const CalcReason usage=CalcReason::CURRENT) const =0
Computes the vehicle's follow speed (no dawdling)
double stopSpeed(const MSVehicle *const veh, const double speed, double gap, const CalcReason usage=CalcReason::CURRENT) const
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
A road/street connecting two junctions.
const std::set< MSTransportable *, ComparatorNumericalIdLess > & getPersons() const
Returns this edge's persons set.
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
double getInternalFollowingLengthTo(const MSEdge *followerAfterInternal, SUMOVehicleClass vClass) const
returns the length of all internal edges on the junction until reaching the non-internal edge followe...
bool canChangeToOpposite() const
whether this edge allows changing to the opposite direction edge
bool isInternal() const
return whether this edge is an internal edge
double getWidth() const
Returns the edges's width (sum over all lanes)
const std::vector< double > getSubLaneSides() const
Returns the right side offsets of this edge's sublanes.
static double gLateralResolution
static bool gSemiImplicitEulerUpdate
static bool gLefthand
Whether lefthand-drive is being simulated.
static bool canSaveBlockerLength(const MSVehicle &veh, double requested, double leftSpace)
static double getSpeedPreservingSecureGap(const MSVehicle &leader, const MSVehicle &follower, double currentGap, double leaderPlannedSpeed)
static double getRoundaboutDistBonus(const MSVehicle &veh, double bonusParam, const MSVehicle::LaneQ &curr, const MSVehicle::LaneQ &neigh, const MSVehicle::LaneQ &best)
static bool isBidiLeader(const MSVehicle *leader, const std::vector< MSLane * > &cont)
static bool updateBlockerLength(const MSVehicle &veh, MSVehicle *blocker, int lcaCounter, double leftSpace, bool reliefConnection, double &leadingBlockerLength)
static bool unwillingToHelp(const MSVehicle &ego, double plannedSpeed, const MSVehicle &nv)
whether the neighboring vehicle nv is unwilling to yield to help ego merge
static bool divergentRoute(const MSVehicle &v1, const MSVehicle &v2)
return whether the vehicles are on the same junction but on divergent paths
double mySafeLatDistRight
the lateral distance the vehicle can safely move in the currently considered direction
static bool overlap(double right, double left, double right2, double left2)
return whether the given intervals overlap
double _patchSpeed(double min, const double wanted, double max, const MSCFModel &cfModel)
double informLeaders(int blocked, int dir, const std::vector< CLeaderDist > &blockers, double remainingSeconds)
void commitManoeuvre(int blocked, int blockedFully, const MSLeaderDistanceInfo &leaders, const MSLeaderDistanceInfo &neighLeaders, const MSLane &neighLane, double maneuverDist)
commit to lane change maneuver potentially overriding safe speed
std::set< const MSVehicle * > myCFRelated
set of vehicles that are in a car-following relationship with ego (leader of followers)
void prepareStep() override
double myKeepRightProbability
double commitFollowSpeed(double speed, double latDist, double secondsToLeaveLane, const MSLeaderDistanceInfo &leaders, double foeOffset) const
compute speed when committing to an urgent change that is safe in regard to leading vehicles
double getLeftBorder(bool checkOpposite=true) const
return current edge width optionally extended by opposite direction lane width
double myChangeProbThresholdRight
double informLeader(int blocked, int dir, const CLeaderDist &neighLead, double remainingSeconds)
MSLCM_SL2015(MSVehicle &v)
int computeSublaneShift(const MSEdge *prevEdge, const MSEdge *curEdge)
compute shift so that prevSublane + shift = newSublane
double patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel) override
Called to adapt the speed in order to allow a lane change. It uses information on LC-related desired ...
double getSafetyFactor() const override
return factor for modifying the safety constraints of the car-following model
double myCooperativeSpeed
double computeSpeedLat(double latDist, double &maneuverDist, bool urgent) const override
decides the next lateral speed depending on the remaining lane change distance to be covered and upda...
std::vector< double > myExpectedSublaneSpeeds
expected travel speeds on all sublanes on the current edge(!)
double getWidth() const
return the width of this vehicle (padded for numerical stability)
bool myCanChangeFully
whether the current lane changing maneuver can be finished in a single step
int wantsChange(int laneOffset, MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, const std::pair< MSVehicle *, double > &leader, const std::pair< MSVehicle *, double > &follower, const std::pair< MSVehicle *, double > &neighLead, const std::pair< MSVehicle *, double > &neighFollow, const MSLane &neighLane, const std::vector< MSVehicle::LaneQ > &preb, MSVehicle **lastBlocked, MSVehicle **firstBlocked) override
Called to examine whether the vehicle wants to change using the given laneOffset (this is a wrapper a...
bool outsideEdge() const
whether the ego vehicle is driving outside edgebounds
bool myDontBrake
flag to prevent speed adaptation by slowing down
std::string getParameter(const std::string &key) const override
try to retrieve the given parameter from this device. Throw exception for unsupported key
bool wantsKeepRight(double keepRightProb) const
check against thresholds
double forecastAverageSpeed(double vSafe, double vMax, double gap, double vLeader) const
estimate average speed over mySpeedGainLookahead time
int checkStrategicChange(int ret, const MSLane &neighLane, int laneOffset, const MSLeaderDistanceInfo &leaders, const MSLeaderDistanceInfo &neighLeaders, const MSVehicle::LaneQ &curr, const MSVehicle::LaneQ &neigh, const MSVehicle::LaneQ &best, int bestLaneOffset, bool changeToBest, double ¤tDist, double neighDist, double laDist, double roundaboutBonus, double latLaneDist, bool checkOpposite, double &latDist)
compute strategic lane change actions TODO: Better documentation, refs #2
void updateCFRelated(const MSLeaderDistanceInfo &vehicles, double foeOffset, bool leaders)
find leaders/followers that are already in a car-following relationship with ego
bool debugVehicle() const override
whether the current vehicles shall be debugged
int wantsChangeSublane(int laneOffset, LaneChangeAction alternatives, const MSLeaderDistanceInfo &leaders, const MSLeaderDistanceInfo &followers, const MSLeaderDistanceInfo &blockers, const MSLeaderDistanceInfo &neighLeaders, const MSLeaderDistanceInfo &neighFollowers, const MSLeaderDistanceInfo &neighBlockers, const MSLane &neighLane, const std::vector< MSVehicle::LaneQ > &preb, MSVehicle **lastBlocked, MSVehicle **firstBlocked, double &latDist, double &maneuverDist, int &blocked) override
Called to examine whether the vehicle wants to change with the given laneOffset (using the sublane mo...
LatAlignmentDefinition getDesiredAlignment() const override
double mySpeedGainProbabilityRight
a value for tracking the probability that a change to the right is beneficial
int slowDownForBlocked(MSVehicle **blocked, int state)
compute useful slowdowns for blocked vehicles
void initDerivedParameters()
init cached parameters derived directly from model parameters
int keepLatGap(int state, const MSLeaderDistanceInfo &leaders, const MSLeaderDistanceInfo &followers, const MSLeaderDistanceInfo &blockers, const MSLeaderDistanceInfo &neighLeaders, const MSLeaderDistanceInfo &neighFollowers, const MSLeaderDistanceInfo &neighBlockers, const MSLane &neighLane, int laneOffset, double &latDist, double &maneuverDist, int &blocked)
check whether lateral gap requirements are met override the current maneuver if necessary
bool tieBrakeLeader(const MSVehicle *veh) const
bool currentDistAllows(double dist, int laneOffset, double lookForwardDist)
CLeaderDist getLongest(const MSLeaderDistanceInfo &ldi) const
get the longest vehicle in the given info
double myCooperativeParam
double getNeighRight(const MSLane &neighLane) const
return the right offset of the neighboring lane relative to the current edge
double computeSpeedGain(double latDistSublane, double defaultNextSpeed) const
compute speedGain when moving by the given amount
double emergencySpeedLat(double speedLat) const
avoid unsafe lateral speed (overruling lcAccelLat)
double myKeepRightAcceptanceTime
void updateGaps(const MSLeaderDistanceInfo &others, double foeOffset, double oldCenter, double gapFactor, double &surplusGapRight, double &surplusGapLeft, bool saveMinGap=false, double netOverlap=0, double latDist=0, std::vector< CLeaderDist > *collectBlockers=0)
check remaining lateral gaps for the given foe vehicles and optionally update minimum lateral gaps
virtual void updateSafeLatDist(const double travelledLatDist) override
Updates the value of safe lateral distances (mySafeLatDistLeft and mySafeLatDistRight) during maneuve...
const MSEdge * myLastEdge
expected travel speeds on all sublanes on the current edge(!)
double getOppositeSafetyFactor() const override
return factor for modifying the safety constraints for opposite-diretction overtaking of the car-foll...
StateAndDist decideDirection(StateAndDist sd1, StateAndDist sd2) const override
decide in which direction to move in case both directions are desirable
std::pair< double, int > Info
information regarding save velocity (unused) and state flags of the ego vehicle
void msg(const CLeaderDist &cld, double speed, int state)
send a speed recommendation to the given vehicle
double mySpeedGainRemainTime
int checkBlocking(const MSLane &neighLane, double &latDist, double maneuverDist, int laneOffset, const MSLeaderDistanceInfo &leaders, const MSLeaderDistanceInfo &followers, const MSLeaderDistanceInfo &blockers, const MSLeaderDistanceInfo &neighLeaders, const MSLeaderDistanceInfo &neighFollowers, const MSLeaderDistanceInfo &neighBlockers, std::vector< CLeaderDist > *collectLeadBlockers=0, std::vector< CLeaderDist > *collectFollowBlockers=0, bool keepLatGapManeuver=false, double gapFactor=0, int *retBlockedFully=0)
restrict latDist to permissible speed and determine blocking state depending on that distance
double getVehicleCenter() const
return vehicle position relative to the current edge (extend by another virtual lane for opposite-dir...
int _wantsChangeSublane(int laneOffset, LaneChangeAction alternatives, const MSLeaderDistanceInfo &leaders, const MSLeaderDistanceInfo &followers, const MSLeaderDistanceInfo &blockers, const MSLeaderDistanceInfo &neighLeaders, const MSLeaderDistanceInfo &neighFollowers, const MSLeaderDistanceInfo &neighBlockers, const MSLane &neighLane, const std::vector< MSVehicle::LaneQ > &preb, MSVehicle **lastBlocked, MSVehicle **firstBlocked, double &latDist, double &maneuverDist, int &blocked)
helper function for doing the actual work
double getLateralDrift()
get lateral drift for the current step
double computeGapFactor(int state) const
compute the gap factor for the given state
bool hasBidiLeader(const MSLeaderDistanceInfo &ldi, const std::vector< MSLane * > &conts)
return true if any leader on the upcoming lanes is driving in the opposite direction
bool mustOvertakeStopped(bool checkCurrent, const MSLane &neighLane, const MSLeaderDistanceInfo &leaders, const MSLeaderDistanceInfo &neighLead, double posOnLane, double neighDist, bool right, double latLaneDist, const std::vector< MSLane * > &conts, double ¤tDist, double &latDist)
double getPosLat()
get lateral position of this vehicle
bool preventSliding(double maneuverDist) const
bool isBidi(const MSLane *lane) const
check whether lane is an upcoming bidi lane
void * inform(void *info, MSVehicle *sender) override
void informFollower(int blocked, int dir, const CLeaderDist &neighFollow, double remainingSeconds, double plannedSpeed)
decide whether we will try cut in before the follower or allow to be overtaken
void setParameter(const std::string &key, const std::string &value) override
try to set the given parameter for this laneChangeModel. Throw exception for unsupported key
bool saveBlockerLength(double length, double foeLeftSpace) override
reserve space at the end of the lane to avoid dead locks
double myOvertakeDeltaSpeedFactor
double myTurnAlignmentDist
double myLeadingBlockerLength
void setOwnState(const int state) override
int checkBlockingVehicles(const MSVehicle *ego, const MSLeaderDistanceInfo &vehicles, int laneOffset, double latDist, double foeOffset, bool leaders, double &safeLatGapRight, double &safeLatGapLeft, std::vector< CLeaderDist > *collectBlockers=0) const
check whether any of the vehicles overlaps with ego
void informFollowers(int blocked, int dir, const std::vector< CLeaderDist > &blockers, double remainingSeconds, double plannedSpeed)
call informFollower for multiple followers
static const MSVehicle * getStopped(const MSLeaderDistanceInfo &ldi)
get a stopped vehicle in the given info
double mySpeedGainLookahead
double mySpeedLossProbThreshold
void resetState() override
double mySpeedGainProbabilityLeft
a value for tracking the probability that a change to the left is beneficial
static LaneChangeAction getLCA(int state, double latDist)
compute lane change action from desired lateral distance
double myChangeProbThresholdLeft
void updateExpectedSublaneSpeeds(const MSLeaderDistanceInfo &ahead, int sublaneOffset, int laneIndex) override
update expected speeds for each sublane of the current edge
bool sublaneEnds(int i, const MSLane *next, double shift)
check whether the sublane continues on the next lane
bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist)
double myTimeToImpatience
static int lowest_bit(int changeReason)
return the most important change reason
static CLeaderDist getSlowest(const MSLeaderDistanceInfo &ldi)
get the slowest vehicle in the given info
bool amBlockingFollowerPlusNB()
Representation of a lane in the micro simulation.
std::pair< const MSPerson *, double > nextBlocking(double minPos, double minRight, double maxLeft, double stopTime=0, bool bidi=false) const
This is just a wrapper around MSPModel::nextBlocking. You should always check using hasPedestrians be...
MSLane * getParallelLane(int offset, bool includeOpposite=true) const
Returns the lane with the given offset parallel to this one or 0 if it does not exist.
const MSLink * getLinkTo(const MSLane *const) const
returns the link to the given lane or nullptr, if it is not connected
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
double getLength() const
Returns the lane's length.
bool allowsVehicleClass(SUMOVehicleClass vclass) const
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
double getRightSideOnEdge() const
bool hasPedestrians() const
whether the lane has pedestrians on it
int getIndex() const
Returns the lane's index.
MSLane * getOpposite() const
return the neighboring opposite direction lane for lane changing or nullptr
MSLane * getBidiLane() const
retrieve bidirectional lane or nullptr
MSLane * getParallelOpposite() const
return the opposite direction lane of this lanes edge or nullptr
MSEdge & getEdge() const
Returns the lane's edge.
const MSLane * getNormalPredecessorLane() const
get normal lane leading to this internal lane, for normal lanes, the lane itself is returned
double getWidth() const
Returns the lane's width.
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
int getRightmostSublane() const
saves leader/follower vehicles and their distances relative to an ego vehicle
virtual std::string toString() const
print a debugging representation
double getMinDistToStopped() const
return minimum distance to a stopped vehicle or max double
bool hasStoppedVehicle() const
whether a stopped vehicle is leader
void getSublaneBorders(int sublane, double latOffset, double &rightSide, double &leftSide) const
void getSubLanes(const MSVehicle *veh, double latOffset, int &rightmost, int &leftmost) const
const std::vector< const MSVehicle * > & getVehicles() const
double getLateralShift() const
return lateral shift that must be applied when passing this link
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
const MSEdge * getLastEdge() const
returns the destination edge
const MSLane * lane
The lane to stop at (microsim only)
double getLatDist() const
double changeRequestRemainingSeconds(const SUMOTime currentTime) const
Return the remaining number of seconds of the current laneTimeLine assuming one exists.
bool ignoreOverlap() const
Representation of a vehicle in the micro simulation.
double getRightSideOnEdge(const MSLane *lane=0) const
Get the vehicle's lateral position on the edge of the given lane (or its current edge if lane == 0)
double getLeftSideOnEdge(const MSLane *lane=0) const
Get the vehicle's lateral position on the edge of the given lane (or its current edge if lane == 0)
bool isActive() const
Returns whether the current simulation step is an action point for the vehicle.
const std::pair< double, const MSLink * > & getNextTurn()
Get the distance and direction of the next upcoming turn for the vehicle (within its look-ahead range...
MSAbstractLaneChangeModel & getLaneChangeModel()
double getLeftSideOnLane() const
Get the lateral position of the vehicles left side on the lane:
double getActionStepLengthSecs() const
Returns the vehicle's action step length in secs, i.e. the interval between two action points.
int influenceChangeDecision(int state)
allow TraCI to influence a lane change decision
double nextStopDist() const
return the distance to the next stop or doubleMax if there is none.
double getAcceleration() const
Returns the vehicle's acceleration in m/s (this is computed as the last step's mean acceleration in c...
const std::vector< MSLane * > & getBestLanesContinuation() const
Returns the best sequence of lanes to continue the route starting at myLane.
int getBestLaneOffset() const
double lateralDistanceToLane(const int offset) const
Get the minimal lateral distance required to move fully onto the lane at given offset.
const MSEdge * getCurrentEdge() const
Returns the edge the vehicle is currently at (possibly an internal edge or nullptr)
const MSLane * getLane() const
Returns the lane the vehicle is on.
double getLastStepDist() const
Get the distance the vehicle covered in the previous timestep.
Influencer & getInfluencer()
double getRightSideOnLane() const
Get the lateral position of the vehicles right side on the lane:
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
double getSpeed() const
Returns the vehicle's current speed.
const std::vector< LaneQ > & getBestLanes() const
Returns the description of best lanes to use in order to continue the route.
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
double getPositionOnLane() const
Get the vehicle's position along the lane.
double getLateralOverlap() const
return the amount by which the vehicle extends laterally outside it's primary lane
bool hasInfluencer() const
whether the vehicle is individually influenced (via TraCI or special parameters)
double getCenterOnEdge(const MSLane *lane=0) const
Get the vehicle's lateral position on the edge of the given lane (or its current edge if lane == 0)
double getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
const LatAlignmentDefinition & getPreferredLateralAlignment() const
Get vehicle's preferred lateral alignment procedure.
double getMinGap() const
Get the free space in front of vehicles of this class.
double getMaxSpeedLat() const
Get vehicle's maximum lateral speed [m/s].
double getLength() const
Get vehicle's length [m].
double getPreferredLateralAlignmentOffset() const
Get vehicle's preferred lateral alignment offset (in m from center line)
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
const std::string & getID() const
Returns the id.
void step(double dt)
evolve for a time step of length dt.
double arrivalPosLat
(optional) The lateral position the vehicle shall arrive on
ArrivalPosLatDefinition arrivalPosLatProcedure
Information how the vehicle shall choose the lateral arrival position.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
#define UNUSED_PARAMETER(x)
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
bool sameDirection(const StateAndDist &other) const
A structure representing the best lanes for continuing the current route starting at 'lane'.
double length
The overall length which may be driven when using this lane without a lane change.
std::vector< MSLane * > bestContinuations
MSLane * lane
The described lane.
int bestLaneOffset
The (signed) number of lanes to be crossed to get to the lane which allows to continue the drive.
double occupation
The overall vehicle sum on consecutive lanes which can be passed without a lane change.