48#define LOOK_FORWARD 10.
52#define LCA_RIGHT_IMPATIENCE -1.
53#define CUT_IN_LEFT_SPEED_THRESHOLD 27.
55#define LOOK_AHEAD_MIN_SPEED 0.0
56#define LOOK_AHEAD_SPEED_MEMORY 0.9
58#define HELP_DECEL_FACTOR 1.0
60#define HELP_OVERTAKE (10.0 / 3.6)
61#define MIN_FALLBEHIND (7.0 / 3.6)
63#define RELGAIN_NORMALIZATION_MIN_SPEED 10.0
65#define OPPOSITE_URGENCY 5.0
67#define KEEP_RIGHT_TIME 5.0
69#define KEEP_RIGHT_HEADWAY 2.0
70#define MAX_ONRAMP_LENGTH 200.
71#define TURN_LANE_DIST 200.0
73#define LC_RESOLUTION_SPEED_LAT 0.5
75#define REACT_TO_STOPPED_DISTANCE 100
76#define BLOCKER_IS_BLOCKED_TIME_THRESHOLD 5
78#define HYST_PRECISION 10000000
93#define DEBUG_COND (myVehicle.isSelected())
101 mySpeedGainProbabilityLeft(0),
102 mySpeedGainProbabilityRight(0),
103 myKeepRightProbability(0),
104 myLeadingBlockerLength(0),
124#ifdef DEBUG_CONSTRUCTOR
168 const std::pair<MSVehicle*, double>& leader,
169 const std::pair<MSVehicle*, double>& follower,
170 const std::pair<MSVehicle*, double>& neighLead,
171 const std::pair<MSVehicle*, double>& neighFollow,
173 const std::vector<MSVehicle::LaneQ>& preb,
177#ifdef DEBUG_WANTS_CHANGE
179 std::cout <<
"\nWANTS_CHANGE\n" <<
SIMTIME
186 <<
" considerChangeTo=" << (laneOffset == -1 ?
"right" :
"left")
191 const int result =
_wantsChange(laneOffset, msgPass, blocked, leader, follower, neighLead, neighFollow, neighLane, preb, *lastBlocked, *firstBlocked);
193#ifdef DEBUG_WANTS_CHANGE
206#ifdef DEBUG_PATCH_SPEED
208 std::cout <<
"\nPATCH_SPEED\n"
215 <<
" wanted=" << wanted
222 const double newSpeed =
_patchSpeed(
MAX2(min, 0.0), wanted, max, cfModel);
224#ifdef DEBUG_PATCH_SPEED
226 const std::string patched = (wanted != newSpeed ?
" patched=" +
toString(newSpeed) :
"");
239#ifdef DEBUG_PATCH_SPEED
251 double nVSafe = wanted;
256#ifdef DEBUG_PATCH_SPEED
265 max =
MIN2(max,
MAX2(safe, vMinEmergency));
270 if (safe >= vMinEmergency) {
272 min =
MAX2(vMinEmergency, safe);
275#ifdef DEBUG_PATCH_SPEED
277 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" slowing down for leading blocker, safe=" << safe << (safe + NUMERICAL_EPS < min ?
" (not enough)" :
"") <<
"\n";
280 nVSafe =
MAX2(min, safe);
302 nVSafe =
MIN2(v * coopWeight + (1 - coopWeight) * wanted, nVSafe);
303 }
else if ((i.second & filter) != filter) {
304#ifdef DEBUG_PATCH_SPEED
314 nVSafe =
MIN2(v, nVSafe);
317#ifdef DEBUG_PATCH_SPEED
324#ifdef DEBUG_PATCH_SPEED
326 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" ignoring low nVSafe=" << v <<
" min=" << min <<
"\n";
330#ifdef DEBUG_PATCH_SPEED
332 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" ignoring high nVSafe=" << v <<
" max=" << max <<
"\n";
340#ifdef DEBUG_PATCH_SPEED
353#ifdef DEBUG_PATCH_SPEED
358 return (max + wanted) / 2.0;
362#ifdef DEBUG_PATCH_SPEED
368 return (
MAX2(0., min) + wanted) / 2.0;
374#ifdef DEBUG_PATCH_SPEED
379 return (max + wanted) / 2.0;
420#ifdef DEBUG_PATCH_SPEED
425 return (max + wanted) / 2.0;
429#ifdef DEBUG_PATCH_SPEED
461 <<
" informedBy=" << sender->
getID()
462 <<
" info=" << pinfo->second
463 <<
" vSafe=" << pinfo->first
475 double overtakeDist = (gap
480 return MAX2(overtakeDist, 0.);
488 const std::pair<MSVehicle*, double>& neighLead,
489 double remainingSeconds) {
492 plannedSpeed =
MIN2(plannedSpeed,
496 const double a = i.first;
503 std::cout <<
"\nINFORM_LEADER"
508 const MSVehicle*
const nv = neighLead.first;
518 neighNextGap = neighLead.second +
SPEED2DIST(neighNextSpeed - plannedSpeed);
529 std::cout <<
" blocked by leader nv=" << nv->
getID() <<
" nvSpeed=" << nv->
getSpeed() <<
" needGap="
536 const double dv = plannedSpeed - nv->
getSpeed();
539 overtakeTime = overtakeDist / dv;
544 overtakeTime = remainingSeconds - 1;
547 overtakeTime = remainingSeconds + 1;
553 <<
"\nnv = " << nv->
getID()
554 <<
"\nplannedSpeed = " << plannedSpeed
555 <<
"\nleaderSpeed = " << nv->
getSpeed()
557 <<
"\nremainingSeconds = " << remainingSeconds
558 <<
"\novertakeDist = " << overtakeDist
559 <<
"\novertakeTime = " << overtakeTime
574 && (!neighLead.first->isStopped() || (
isOpposite() && neighLead.second >= 0))) {
592 <<
" cannot overtake leader nv=" << nv->
getID()
596 <<
" overtakeDist=" << overtakeDist
597 <<
" overtakeTime=" << overtakeTime
598 <<
" remainingSeconds=" << remainingSeconds
599 <<
" currentGap=" << neighLead.second
601 <<
" neighNextSpeed=" << neighNextSpeed
602 <<
" neighNextGap=" << neighNextGap
603 <<
" targetSpeed=" << targetSpeed
604 <<
" nextSpeed=" << nextSpeed
615 <<
" cannot overtake fast leader nv=" << nv->
getID()
619 <<
" overtakeDist=" << overtakeDist
621 <<
" overtakeTime=" << overtakeTime
622 <<
" remainingSeconds=" << remainingSeconds
623 <<
" currentGap=" << neighLead.second
624 <<
" neighNextSpeed=" << neighNextSpeed
625 <<
" neighNextGap=" << neighNextGap
626 <<
" targetSpeed=" << targetSpeed
638 <<
" wants to overtake leader nv=" << nv->
getID()
640 <<
" overtakeDist=" << overtakeDist
641 <<
" remainingSeconds=" << remainingSeconds
642 <<
" overtakeTime=" << overtakeTime
643 <<
" currentGap=" << neighLead.second
656 const double targetSpeed =
MAX2(
662 std::cout <<
" not blocked by leader nv=" << nv->
getID()
664 <<
" gap=" << neighLead.second
665 <<
" neighNextSpeed=" << neighNextSpeed
666 <<
" neighNextGap=" << neighNextGap
668 <<
" targetSpeed=" << targetSpeed
672 return MIN2(targetSpeed, plannedSpeed);
680 const std::pair<MSVehicle*, double>& neighFollow,
681 double remainingSeconds,
682 double plannedSpeed) {
689 std::cout <<
"\nINFORM_FOLLOWER"
699 std::cout <<
"\n nv=" << nv->
getID() <<
" not willing to help\n";
712 std::cout <<
" blocked by follower nv=" << nv->
getID() <<
" nvSpeed=" << nv->
getSpeed() <<
" needGap="
719 if ((neededGap - neighFollow.second) / remainingSeconds < (
MAX2(plannedSpeed, 0.) - nv->
getSpeed())) {
722 std::cout <<
" wants to cut in before nv=" << nv->
getID() <<
" without any help." <<
"\nneededGap = " << neededGap <<
"\n";
740 double neighNewSpeed;
742 double neighNewSpeed1s;
752 dv = plannedSpeed - neighNewSpeed1s;
759 decelGap = neighFollow.second + dv;
766 neighNewSpeed1s = nv->
getSpeed() - helpDecel;
782 <<
" plannedSpeed=" << plannedSpeed
783 <<
" threshold=" << onRampThreshold
784 <<
" neighNewSpeed=" << neighNewSpeed
785 <<
" neighNewSpeed1s=" << neighNewSpeed1s
787 <<
" gap=" << neighFollow.second
788 <<
" decelGap=" << decelGap
789 <<
" secureGap=" << secureGap
796 && neighNewSpeed1s < onRampThreshold) {
800 if (decelGap > 0 && decelGap >= secureGap) {
808 double vsafe, vsafe1;
830 std::cout <<
"nextGap=" << nextGap <<
" (without help decel) \n";
838 MAX2(0., plannedSpeed),
846 nv->
getSpeed(), plannedAccel, -decel2,
856 MAX2(0., plannedSpeed),
859 assert(vsafe >= vsafe1 - NUMERICAL_EPS);
863 std::cout <<
"nextGap=" << nextGap
864 <<
" (with vsafe1 and help decel) \nvsafe1=" << vsafe1
865 <<
" vsafe=" << vsafe
874 if (nextGap < nextSecureGap) {
876 vsafe = neighNewSpeed;
881 std::cout <<
"nextGap=" << nextGap
882 <<
" minNextSecureGap=" << nextSecureGap
883 <<
" vsafe=" << vsafe <<
"\n";
893 std::cout <<
" wants to cut in before nv=" << nv->
getID()
894 <<
" vsafe1=" << vsafe1 <<
" vsafe=" << vsafe
922 std::cout <<
" wants to cut in before nv=" << nv->
getID() <<
" (eventually)\n";
931 std::cout <<
" wants to cut in before nv=" << nv->
getID() <<
" (nv cannot overtake right)\n";
954 std::cout <<
" wants right follower to slow down a bit\n";
964 std::cout <<
" wants to cut in before right follower nv=" << nv->
getID() <<
" (eventually)\n";
986 if (gapAfterRemainingSecs >= secureGapAfterRemainingSecs) {
989 std::cout <<
" wants to cut in before follower nv=" << nv->
getID() <<
" (eventually)\n";
1002#ifdef DEBUG_INFORMER
1006 <<
" informs follower " << nv->
getID()
1007 <<
" vhelp=" << vhelp
1016 const double needDV = overtakeDist / remainingSeconds;
1020#ifdef DEBUG_INFORMER
1024 <<
" wants to be overtaken by=" << nv->
getID()
1025 <<
" overtakeDist=" << overtakeDist
1027 <<
" vhelp=" << vhelp
1028 <<
" needDV=" << needDV
1039#ifdef DEBUG_INFORMER
1041 std::cout <<
" wants to cut in before non-blocking follower nv=" << nv->
getID() <<
"\n";
1068 scaledDelta =
MIN2(overlap, maxDist);
1077 deltaPosLat =
MAX2(
MIN2(deltaPosLat, maxDist), -maxDist);
1126 const std::pair<MSVehicle*, double>& leader,
1127 const std::pair<MSVehicle*, double>& follower,
1128 const std::pair<MSVehicle*, double>& neighLead,
1129 const std::pair<MSVehicle*, double>& neighFollow,
1131 const std::vector<MSVehicle::LaneQ>& preb,
1134 assert(laneOffset == 1 || laneOffset == -1);
1140 int bestLaneOffset = 0;
1145 double currentDist = 0;
1146 double neighDist = 0;
1159 const int prebOffset = laneOffset;
1160 for (
int p = 0; p < (int) preb.size(); ++p) {
1164 if (preb[p].lane == prebLane && p + laneOffset >= 0) {
1165 assert(p + prebOffset < (
int)preb.size());
1167 neigh = &preb[p + prebOffset];
1168 currentDist = curr->
length;
1169 neighDist = neigh->
length;
1171 if (bestLaneOffset == 0 && preb[p + prebOffset].bestLaneOffset == 0 && !checkOpposite) {
1172#ifdef DEBUG_WANTS_CHANGE
1176 <<
" bestLaneOffsetOld=" << bestLaneOffset
1177 <<
" bestLaneOffsetNew=" << laneOffset
1181 bestLaneOffset = prebOffset;
1183 best = &preb[p + bestLaneOffset];
1188 assert(curr->
lane !=
nullptr);
1189 assert(neigh->
lane !=
nullptr);
1190 assert(best->
lane !=
nullptr);
1192 const bool right = (laneOffset == -1);
1194 double driveToNextStop = -std::numeric_limits<double>::max();
1202#ifdef DEBUG_WANTS_CHANGE
1207 <<
" stopPos=" << stopPos
1208 <<
" currentDist=" << currentDist
1209 <<
" neighDist=" << neighDist
1213 currentDist =
MAX2(currentDist, stopPos);
1214 neighDist =
MAX2(neighDist, stopPos);
1219 bool changeToBest = (right && bestLaneOffset < 0) || (!right && bestLaneOffset > 0);
1225 if (lastBlocked != firstBlocked) {
1229#ifdef DEBUG_WANTS_CHANGE
1238 <<
" leaderGap=" << leader.second
1240 <<
" followerGap=" << follower.second
1242 <<
" neighLeadGap=" << neighLead.second
1244 <<
" neighFollowGap=" << neighFollow.second
1267 assert(memoryFactor > 0.);
1273 const bool hasStoppedLeader = leader.first != 0 && leader.first->isStopped() && leader.second < (currentDist - posOnLane);
1276 const bool hasJunctionLeader = leader.first !=
nullptr && leader.first == neighLead.first;
1278 if (bestLaneOffset == 0 && hasBidiLeader) {
1281 }
else if (bestLaneOffset == 0 && hasStoppedLeader) {
1286 + leader.first->getVehicleType().getLengthWithGap()
1288 }
else if (bestLaneOffset == laneOffset && neighLead.first != 0 && (neighLead.first->isStopped() || hasBidiNeighLeader) && neighLead.second < (currentDist - posOnLane)) {
1293 + neighLead.first->getVehicleType().getLengthWithGap()
1294 + neighLead.second);
1295 }
else if (!hasStoppedLeader &&
1297 || hasBidiNeighLeader)) {
1300 changeToBest =
false;
1319 currentDist += roundaboutBonus;
1320 neighDist += roundaboutBonus;
1324 const double maxJam =
MAX2(preb[currIdx + prebOffset].occupation, preb[currIdx].occupation);
1328 double thisLaneVSafe = vMax;
1331 double neighLeftPlace =
MAX2(0.0, neighDist - posOnLane - maxJam);
1332 if (neighLead.first != 0 && neighLead.first->isStopped()) {
1333 neighLeftPlace =
MIN2(neighLeftPlace, neighLead.second);
1336#ifdef DEBUG_WANTS_CHANGE
1341 <<
" laDist=" << laDist
1342 <<
" currentDist=" << currentDist
1343 <<
" usableDist=" << usableDist
1344 <<
" bestLaneOffset=" << bestLaneOffset
1346 <<
" best.length=" << best->
length
1347 <<
"\n roundaboutBonus=" << roundaboutBonus
1348 <<
" maxJam=" << maxJam
1349 <<
" neighDist=" << neighDist
1350 <<
" neighLeftPlace=" << neighLeftPlace
1351 << (hasBidiLeader ?
" bidiLeader" :
"")
1352 << (hasBidiNeighLeader ?
" bidiNeighLeader" :
"")
1357 bool changeLeftToAvoidOvertakeRight =
false;
1364 if (neighLead.first != 0 && checkOverTakeRight && !right) {
1374 thisLaneVSafe =
MIN2(thisLaneVSafe, vSafe);
1377 const double deltaGapFuture = deltaV * 8;
1380 if (vSafeFuture < vSafe) {
1381 const double relativeGain = deltaV /
MAX2(vMax,
1384 changeLeftToAvoidOvertakeRight =
true;
1386#ifdef DEBUG_WANTS_CHANGE
1389 <<
" avoid overtaking on the right nv=" << nv->
getID()
1390 <<
" deltaV=" << deltaV
1400 const bool currFreeUntilNeighEnd = leader.first ==
nullptr || neighDist - posOnLane <= leader.second;
1401 const double overtakeDist = (leader.first == 0 || hasBidiLeader ? -1 :
1403 const double overtakeDist2 = (neighLead.first == 0 || !neighLead.first->isStopped() ? -1 :
1407 &&
MIN2(neighDist, currentDist) - posOnLane > overtakeDist
1409 && (!checkOverTakeRight || !right)
1411 && (neighLead.first == 0 || !neighLead.first->isStopped()
1413 || neighLead.second > overtakeDist
1415 || (overtakeDist2 > leader.second &&
hasFreeLane(laneOffset, neighLead)))) {
1418#ifdef DEBUG_WANTS_CHANGE
1421 <<
" overtake " << (hasBidiLeader ?
"bidi" :
"stopped") <<
" leader=" << leader.first->getID()
1422 <<
" overtakeDist=" << overtakeDist
1423 <<
" overtakeDist2=" << overtakeDist
1424 <<
" hasFreeLane=" <<
hasFreeLane(laneOffset, neighLead)
1425 <<
" remaining=" <<
MIN2(neighDist, currentDist) - posOnLane
1430 }
else if (!changeToBest &&
currentDistDisallows(neighLeftPlace, abs(bestLaneOffset) + 2, laDist) && !hasBidiLeader) {
1437#ifdef DEBUG_WANTS_CHANGE
1439 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" could not change back and forth in time (1) neighLeftPlace=" << neighLeftPlace <<
"\n";
1443 }
else if (bestLaneOffset == 0 && (neighLeftPlace * 2. < laDist)) {
1448#ifdef DEBUG_WANTS_CHANGE
1450 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" could not change back and forth in time (2) neighLeftPlace=" << neighLeftPlace <<
"\n";
1454 }
else if (bestLaneOffset == 0
1455 && (leader.first == 0 || !leader.first->isStopped())
1458 && roundaboutBonus == 0
1467#ifdef DEBUG_WANTS_CHANGE
1469 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" does not want to leave the bestLane (neighDist=" << neighDist <<
")\n";
1476#ifdef DEBUG_WANTS_CHANGE
1484 if ((ret & lcaCounter) != 0) {
1488#ifdef DEBUG_WANTS_CHANGE
1506#ifdef DEBUG_SAVE_BLOCKER_LENGTH
1508 std::cout <<
" reserving space for unseen blockers myLeadingBlockerLength=" <<
myLeadingBlockerLength <<
"\n";
1517 if (firstBlocked != neighLead.first) {
1520#ifdef DEBUG_SAVE_BLOCKER_LENGTH
1522 std::cout <<
SIMTIME <<
" canReserve=" << canReserve <<
" canContinue=" << canContinue <<
"\n";
1531 const int remainingLanes =
MAX2(1, abs(bestLaneOffset));
1533 const double remainingSeconds = ((ret &
LCA_TRACI) == 0 ?
1537 if (!hasBidiNeighLeader && !hasJunctionLeader) {
1538 const double plannedSpeed =
informLeader(msgPass, blocked, myLca, neighLead, remainingSeconds);
1544 if (!hasBidiNeighFollower) {
1545 informFollower(msgPass, blocked, myLca, neighFollow, remainingSeconds, plannedSpeed);
1548#ifdef DEBUG_WANTS_CHANGE
1553 <<
" remainingSeconds=" << remainingSeconds
1554 <<
" plannedSpeed=" << plannedSpeed
1559#ifdef DEBUG_WANTS_CHANGE
1564 <<
" remainingSeconds=" << remainingSeconds
1565 <<
" hasBidiNeighLeader=" << hasBidiNeighLeader
1566 <<
" hasJunctionLeader=" << hasJunctionLeader <<
"\n";
1579 const bool acceleratingLeader = (neighLead.first != 0 && neighLead.first->getAcceleration() > 0)
1580 || (leader.first != 0 && leader.first->getAcceleration() > 0);
1591 double inconvenience = laneOffset < 0
1595 const double relSpeedDiff = thisLaneVSafe == 0 ? 0 : (thisLaneVSafe - neighLaneVSafe) /
MAX2(thisLaneVSafe, neighLaneVSafe);
1596 inconvenience =
MAX2(relSpeedDiff, inconvenience);
1597 inconvenience =
MIN2(1.0, inconvenience);
1601#ifdef DEBUG_WANTS_CHANGE
1607 <<
" neighSpeedFactor=" << (thisLaneVSafe / neighLaneVSafe - 1)
1608 <<
" inconvenience=" << inconvenience
1609 <<
" speedInconv=" << speedGainInconvenient
1610 <<
" occInconv=" << neighOccupancyInconvenient
1616 if (roundaboutBonus > 0) {
1618#ifdef DEBUG_WANTS_CHANGE
1622 <<
" roundaboutBonus=" << roundaboutBonus
1652#ifdef DEBUG_WANTS_CHANGE
1654 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" does not want to get stranded on the on-ramp of a highway\n";
1674 && (!speedGainInconvenient)
1676 && (changeToBest ||
currentDistAllows(neighDist, abs(bestLaneOffset) + 1, laDist))) {
1679#ifdef DEBUG_COOPERATE
1683 <<
" wantsChangeToHelp=" << (right ?
"right" :
"left")
1685 << (((
myOwnState & myLca) == 0) ?
" (counter)" :
"")
1724 const double relativeGain = (neighLaneVSafe - thisLaneVSafe) /
MAX2(neighLaneVSafe,
1727#ifdef DEBUG_WANTS_CHANGE
1731 <<
" currentDist=" << currentDist
1732 <<
" neighDist=" << neighDist
1733 <<
" thisVSafe=" << thisLaneVSafe
1734 <<
" neighVSafe=" << neighLaneVSafe
1735 <<
" relGain=" <<
toString(relativeGain, 8)
1742 if (thisLaneVSafe - 5 / 3.6 > neighLaneVSafe) {
1752 double acceptanceTime;
1759 if (follower.first !=
nullptr && follower.second < 2 * follower.first->getCarFollowModel().brakeGap(follower.first->getSpeed())) {
1763 const double fRSF = follower.first->getLane()->getVehicleMaxSpeed(follower.first) / follower.first->getLane()->getSpeedLimit();
1764 if (fRSF > roadSpeedFactor) {
1765 acceptanceTime /= fRSF;
1771 double fullSpeedDrivingSeconds =
MIN2(acceptanceTime, fullSpeedGap / vMax);
1772 if (neighLead.first != 0 && neighLead.first->getSpeed() < vMax) {
1773 fullSpeedGap =
MAX2(0.,
MIN2(fullSpeedGap,
1775 vMax, neighLead.first->
getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel())));
1776 fullSpeedDrivingSeconds =
MIN2(fullSpeedDrivingSeconds, fullSpeedGap / (vMax - neighLead.first->getSpeed()));
1779 if (checkOverTakeRight && leader.first != 0
1780 && leader.first->getLane()->getVehicleMaxSpeed(leader.first) < vMax) {
1781 fullSpeedGap =
MIN2(fullSpeedGap, leader.second);
1782 fullSpeedDrivingSeconds =
MIN2(fullSpeedDrivingSeconds, fullSpeedGap / (vMax - leader.first->getSpeed()));
1796#ifdef DEBUG_WANTS_CHANGE
1801 <<
" neighDist=" << neighDist
1803 <<
" leaderSpeed=" << (neighLead.first == 0 ? -1 : neighLead.first->getSpeed())
1805 myVehicle.
getSpeed(), neighLead.first->getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel()))
1806 <<
" acceptanceTime=" << acceptanceTime
1807 <<
" fullSpeedGap=" << fullSpeedGap
1808 <<
" fullSpeedDrivingSeconds=" << fullSpeedDrivingSeconds
1822#ifdef DEBUG_WANTS_CHANGE
1829 <<
" thisLaneVSafe=" << thisLaneVSafe
1830 <<
" neighLaneVSafe=" << neighLaneVSafe
1831 <<
" relativeGain=" << relativeGain
1832 <<
" blocked=" << blocked
1849 if (thisLaneVSafe > neighLaneVSafe) {
1852 }
else if (thisLaneVSafe == neighLaneVSafe) {
1867#ifdef DEBUG_WANTS_CHANGE
1874 <<
" thisLaneVSafe=" << thisLaneVSafe
1875 <<
" neighLaneVSafe=" << neighLaneVSafe
1876 <<
" relativeGain=" << relativeGain
1877 <<
" blocked=" << blocked
1883 && (relativeGain > NUMERICAL_EPS || changeLeftToAvoidOvertakeRight)
1905 && relativeGain >= 0
1913#ifdef DEBUG_WANTS_CHANGE
1920 <<
" thisLaneVSafe=" << thisLaneVSafe
1921 <<
" neighLaneVSafe=" << neighLaneVSafe
1932 const MSVehicle* leader = leaderDist.first;
1933 const double gap = leaderDist.second;
1935 if (acceleratingLeader) {
1939 if (leader ==
nullptr) {
1951 if (leader ==
nullptr) {
1962 futureSpeed =
MIN2(vMax, futureSpeed);
1965 const double deltaV = vMax - futureLeaderSpeed;
1966 if (deltaV > 0 && gap > 0) {
1968 const double fullSpeedGap = gap - secGap;
1972 const double gapClosingTime =
MAX2(0.0, fullSpeedGap / deltaV);
1975 futureSpeed =
MIN2(futureSpeed, (gapClosingTime * futureSpeed + (foreCastTime - gapClosingTime) * futureLeaderSpeed) / foreCastTime);
1987 if (blocked !=
nullptr) {
1989#ifdef DEBUG_SLOW_DOWN
1998 if (gap > POSITION_EPS) {
2012 gap - POSITION_EPS, blocked->
getSpeed(),
2016#ifdef DEBUG_SLOW_DOWN
2020 <<
" slowing down for"
2044#ifdef DEBUG_WANTS_CHANGE
2046 std::cout <<
SIMTIME <<
" adapt to pedestrians on lane=" << lane->
getID() <<
"\n";
2052 if (leader.first != 0) {
2054 v =
MIN2(v, stopSpeed);
2055#ifdef DEBUG_WANTS_CHANGE
2057 std::cout <<
SIMTIME <<
" pedLeader=" << leader.first->getID() <<
" dist=" << leader.second <<
" v=" << v <<
"\n";
2068#ifdef DEBUG_WANTS_CHANGE
2070 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" myLeftSpace=" <<
myLeftSpace <<
" latDist=" << latDist <<
" maneuverDist=" << maneuverDist <<
" result=" << result <<
"\n";
2078 result =
MAX2(-speedBound,
MIN2(speedBound, result));
2091 return myOppositeParam <= 0 ? std::numeric_limits<double>::max() : 1 /
myOppositeParam;
2099#ifdef DEBUG_SAVE_BLOCKER_LENGTH
2101 std::cout <<
SIMTIME <<
" saveBlockerLength veh=" <<
myVehicle.
getID() <<
" canReserve=" << canReserve <<
" myLeftSpace=" <<
myLeftSpace <<
" foeLeftSpace=" << foeLeftSpace <<
"\n";
2117 if (neighLeadStopped.first ==
nullptr) {
2120 int dir = (laneOffset > 0 ? 1 : -1);
2127 int nextOffset = laneOffset + dir;
2132 const double overtakeDist = neighLeadStopped.second + neighLeadStopped.first->getVehicleType().getLengthWithGap() +
myVehicle.
getLength() + POSITION_EPS;
2134 return nextLead.first ==
nullptr || nextLead.second >= overtakeDist ||
hasFreeLane(nextOffset, nextLead);
2181 }
else if (key ==
"speedGainProbabilityRight") {
2183 }
else if (key ==
"speedGainProbabilityLeft") {
2185 }
else if (key ==
"keepRightProbability") {
2187 }
else if (key ==
"lookAheadSpeed") {
2190 }
else if (key ==
"speedGainRP") {
2192 }
else if (key ==
"speedGainLP") {
2194 }
else if (key ==
"keepRightP") {
2250 }
else if (key ==
"speedGainProbabilityRight") {
2252 }
else if (key ==
"speedGainProbabilityLeft") {
2254 }
else if (key ==
"keepRightProbability") {
2256 }
else if (key ==
"lookAheadSpeed") {
2268 std::vector<long long int> lcState;
#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 BLOCKER_IS_BLOCKED_TIME_THRESHOLD
#define LC_RESOLUTION_SPEED_LAT
std::pair< const MSPerson *, double > PersonDist
LaneChangeAction
The state of a vehicle's lane-change behavior.
@ 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_STAY
Needs to stay on the current lane.
@ 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_LEFT
Wants go to the left.
@ LCA_STRATEGIC
The action is needed to follow the route (navigational lc)
@ LCA_AMBACKBLOCKER_STANDING
@ 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
@ SUMO_ATTR_LCA_COOPERATIVE_SPEED
@ SUMO_ATTR_LCA_ASSERTIVE
@ SUMO_ATTR_LCA_LOOKAHEADLEFT
@ SUMO_ATTR_LCA_SPEEDGAIN_PARAM
@ SUMO_ATTR_LCA_MAXDISTLATSTANDING
@ 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_STRATEGIC_LOOKAHEAD
@ 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_OVERTAKE_RIGHT
@ SUMO_ATTR_LCA_STRATEGIC_PARAM
@ SUMO_ATTR_LCA_KEEPRIGHT_ACCEPTANCE_TIME
@ SUMO_ATTR_LCA_EXPERIMENTAL1
@ SUMO_ATTR_LCA_SPEEDGAIN_URGENCY
@ SUMO_ATTR_LCA_SPEEDGAINRIGHT
int gPrecision
the precision for floating point outputs
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.
void * informNeighFollower(void *info, MSVehicle *sender)
Informs the follower on the desired lane.
void * informNeighLeader(void *info, MSVehicle *sender)
Informs the leader on the desired lane.
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 ...
std::vector< std::pair< double, int > > myLCAccelerationAdvices
virtual double computeSpeedLat(double latDist, double &maneuverDist, bool urgent) const
decides the next lateral speed depending on the remaining lane change distance to be covered and upda...
virtual void resetSpeedLat()
int myOwnState
The current state of the vehicle.
virtual void saveState(OutputDevice &out) const
Save the state of the laneChangeModel.
double myMaxDistLatStanding
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
void setSpeedLat(double speedLat)
set the lateral speed and update lateral acceleraton
double myOvertakeRightParam
const MSCFModel & getCarFollowModel() const
The vehicle's car following model.
double myMaxSpeedLatStanding
double myStrategicLookahead
virtual void loadState(const SUMOSAXAttributes &attrs)
Loads the state of the laneChangeModel from the given attributes.
MSVehicle & myVehicle
The vehicle this lane-changer belongs to.
virtual void prepareStep(SumoRNG *rng)
rng belongs to the lane that moves the vehicle (not the lane it just entered)
bool isChangingLanes() const
return true if the vehicle currently performs a lane change maneuver
double getImpatience() const
Returns this vehicles impatience.
int getNumRemainingEdges() const
return the number of edges remaining in the route (include the current)
double getLength() const
Returns the vehicle's length.
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 MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
bool isStopped() const
Returns whether the vehicle is at a stop.
The car-following model abstraction.
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 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...
double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion=false) const
Returns the maximum safe velocity for following the given leader.
@ 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 maximumSafeStopSpeed(double gap, double decel, double currentSpeed, bool onInsertion=false, double headway=-1, bool relaxEmergency=true) const
Returns the maximum next velocity for stopping within gap.
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
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)
const std::set< MSTransportable *, ComparatorNumericalIdLess > & getPersons() const
Returns this edge's persons set.
bool hasLaneChanger() const
bool isRoundabout() const
bool isInternal() const
return whether this edge is an internal edge
static bool gSemiImplicitEulerUpdate
static bool isBidiFollower(const MSVehicle *ego, const MSVehicle *follower)
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
bool currentDistAllows(double dist, int laneOffset, double lookForwardDist)
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 method gets th...
void informFollower(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, double > &neighFollow, double remainingSeconds, double plannedSpeed)
decide whether we will try cut in before the follower or allow to be overtaken
long long int myKeepRightProbability
double computeSpeedLat(double latDist, double &maneuverDist, bool urgent) const override
decides the next lateral speed (for continuous lane changing)
double myOvertakeDeltaSpeedFactor
bool debugVehicle() const override
whether the current vehicles shall be debugged
long long int mySpeedGainProbabilityRight
double mySpeedGainLookahead
const double myExperimentalParam1
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 ...
void initDerivedParameters()
init cached parameters derived directly from model parameters
double myCooperativeParam
MSLCM_LC2013(MSVehicle &v)
double anticipateFollowSpeed(const std::pair< MSVehicle *, double > &leaderDist, double dist, double vMax, bool acceleratingLeader)
anticipate future follow speed for the given leader
std::string getParameter(const std::string &key) const override
try to retrieve the given parameter from this device. Throw exception for unsupported key
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 hasFreeLane(int laneOffset, const std::pair< MSVehicle *, double > &neighLeadStopped) const
whether there is a lane beyond laneOffset that can be used to overtake the stopped leader on the neig...
double myCooperativeSpeed
long long int myKeepRightProbThreshold
double informLeader(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, double > &neighLead, double remainingSeconds)
double _patchSpeed(double min, const double wanted, double max, const MSCFModel &cfModel)
double myLeadingBlockerLength
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)
helper function for doing the actual work
std::pair< double, int > Info
information regarding save velocity (unused) and state flags of the ego vehicle
double getSafetyFactor() const override
return factor for modifying the safety constraints of the car-following model
bool amBlockingFollowerPlusNB()
bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist)
void adaptSpeedToPedestrians(const MSLane *lane, double &v)
react to pedestrians on the given lane
virtual void saveState(OutputDevice &out) const override
Save the state of the laneChangeModel.
long long int myChangeProbThresholdRight
double getOppositeSafetyFactor() const override
return factor for modifying the safety constraints for opposite-diretction overtaking of the car-foll...
long long int mySpeedGainProbabilityLeft
a value for tracking the probability that a change to that side is beneficial
void resetState() override
double myKeepRightAcceptanceTime
double mySpeedGainUrgency
int slowDownForBlocked(MSVehicle *blocked, int state)
compute useful slowdowns for blocked vehicles
bool saveBlockerLength(double length, double foeLeftSpace) override
reserve space at the end of the lane to avoid dead locks
double mySpeedGainRemainTime
void * inform(void *info, MSVehicle *sender) override
long long int myChangeProbThresholdLeft
virtual void loadState(const SUMOSAXAttributes &attrs) override
Loads the state of the laneChangeModel from the given attributes.
void prepareStep(SumoRNG *rng) override
rng belongs to the lane that moves the vehicle (not the lane it just entered)
static double overtakeDistance(const MSVehicle *follower, const MSVehicle *leader, const double gap, double followerSpeed=INVALID_SPEED, double leaderSpeed=INVALID_SPEED)
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.
bool isAccelLane() const
return whether this lane is an acceleration lane
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
double getLength() const
Returns the lane's length.
bool allowsChangingLeft(SUMOVehicleClass vclass) const
Returns whether the given vehicle class may change left from this lane.
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.
bool hasPedestrians() const
whether the lane has pedestrians on it
int getIndex() const
Returns the lane's index.
double getBruttoOccupancy() const
Returns the brutto (including minGaps) occupancy of this lane during the last step.
std::pair< MSVehicle *const, double > getLeader(const MSVehicle *veh, const double vehPos, const std::vector< MSLane * > &bestLaneConts, double dist=-1, bool checkTmpVehicles=false) const
Returns the immediate leader of veh and the distance to veh starting on this lane.
MSLane * getBidiLane() const
retrieve bidirectional lane 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
const std::vector< MSLink * > & getLinkCont() const
returns the container with all links !!!
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
const MSLane * lane
The lane to stop at (microsim only)
double changeRequestRemainingSeconds(const SUMOTime currentTime) const
Return the remaining number of seconds of the current laneTimeLine assuming one exists.
Representation of a vehicle in the micro simulation.
MSAbstractLaneChangeModel & getLaneChangeModel()
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 getMaxSpeedOnLane() const
Returns the maximal speed for the vehicle on its current lane (including speed factor and deviation,...
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
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
void setLateralPositionOnLane(double posLat)
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.
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].
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, SumoRNG *rng)
evolve for a time step of length dt.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
Encapsulated SAX-Attributes.
virtual std::string getString(int id, bool *isPresent=nullptr) const =0
Returns the string-value of the named (by its enum-value) attribute.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
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)
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.