 |
Eclipse SUMO - Simulation of Urban MObility
|
Go to the documentation of this file.
44 #define LOOK_FORWARD (double)10.
46 #define JAM_FACTOR (double)1.
48 #define LCA_RIGHT_IMPATIENCE (double)-1.
49 #define CUT_IN_LEFT_SPEED_THRESHOLD (double)27.
51 #define LOOK_AHEAD_MIN_SPEED 0.0
52 #define LOOK_AHEAD_SPEED_MEMORY 0.9
54 #define HELP_DECEL_FACTOR (double)1.0
56 #define HELP_OVERTAKE (double)(10.0 / 3.6)
57 #define MIN_FALLBEHIND (double)(7.0 / 3.6)
60 #define OVERTAKE_RIGHT_THRESHOLD (double)(5/3.6)
62 #define RELGAIN_NORMALIZATION_MIN_SPEED (double)10.0
63 #define URGENCY (double)2.0
64 #define OPPOSITE_URGENCY (double)5.0
66 #define KEEP_RIGHT_TIME (double)5.0 // the number of seconds after which a vehicle should move to the right lane
67 #define KEEP_RIGHT_ACCEPTANCE (double)7.0 // calibration factor for determining the desire to keep right
69 #define ROUNDABOUT_DIST_FACTOR (double)10.0 // Must be >=1.0, serves an alternative way of decreasing sense lc-urgency by multiplying the distance along the next roundabout
71 #define KEEP_RIGHT_HEADWAY (double)2.0
72 #define MAX_ONRAMP_LENGTH (double)200.
73 #define TURN_LANE_DIST (double)200.0 // the distance at which a lane leading elsewhere is considered to be a turn-lane that must be avoided
75 #define LC_RESOLUTION_SPEED_LAT (double)0.5 // the lateral speed (in m/s) for a standing vehicle which was unable to finish a continuous LC in time (in case mySpeedLatStanding==0), see #3771
76 #define LC_ASSUMED_DECEL (double)1.0 // the minimal constant deceleration assumed to estimate the duration of a continuous lane-change at its initiation.
78 #define REACT_TO_STOPPED_DISTANCE 100
93 #define DEBUG_COND (myVehicle.isSelected())
101 mySpeedGainProbability(0),
102 myKeepRightProbability(0),
103 myLeadingBlockerLength(0),
117 #ifdef DEBUG_CONSTRUCTOR
153 const std::pair<MSVehicle*, double>& leader,
154 const std::pair<MSVehicle*, double>& neighLead,
155 const std::pair<MSVehicle*, double>& neighFollow,
157 const std::vector<MSVehicle::LaneQ>& preb,
161 #ifdef DEBUG_WANTS_CHANGE
163 std::cout <<
"\nWANTS_CHANGE\n" <<
SIMTIME
170 <<
" considerChangeTo=" << (laneOffset == -1 ?
"right" :
"left")
175 const int result =
_wantsChange(laneOffset, msgPass, blocked, leader, neighLead, neighFollow, neighLane, preb, lastBlocked, firstBlocked);
177 #ifdef DEBUG_WANTS_CHANGE
190 #ifdef DEBUG_PATCH_SPEED
192 std::cout <<
"\nPATCH_SPEED\n"
199 <<
" wanted=" << wanted
206 const double newSpeed =
_patchSpeed(
MAX2(min, 0.0), wanted, max, cfModel);
208 #ifdef DEBUG_PATCH_SPEED
210 const std::string patched = (wanted != newSpeed ?
" patched=" +
toString(newSpeed) :
"");
223 #ifdef DEBUG_PATCH_SPEED
230 <<
" wanted=" << wanted << std::endl;
235 double MAGIC_offset = 1.;
239 #ifdef DEBUG_PATCH_SPEED
250 #ifdef DEBUG_PATCH_SPEED
252 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" slowing down for leading blocker, safe=" << safe << (safe +
NUMERICAL_EPS < min ?
" (not enough)" :
"") <<
"\n";
255 return MAX2(min, safe);
260 double nVSafe = wanted;
274 nVSafe =
MIN2(v * coopWeight + (1 - coopWeight) * wanted, nVSafe);
276 #ifdef DEBUG_PATCH_SPEED
283 #ifdef DEBUG_PATCH_SPEED
285 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" ignoring low nVSafe=" << v <<
" min=" << min <<
"\n";
289 #ifdef DEBUG_PATCH_SPEED
291 std::cout <<
SIMTIME <<
" veh=" <<
myVehicle.
getID() <<
" ignoring high nVSafe=" << v <<
" max=" << max <<
"\n";
299 #ifdef DEBUG_PATCH_SPEED
312 #ifdef DEBUG_PATCH_SPEED
317 return (max + wanted) / (double) 2.0;
321 #ifdef DEBUG_PATCH_SPEED
327 return (
MAX2(0., min) + wanted) / (
double) 2.0;
333 #ifdef DEBUG_PATCH_SPEED
338 return (max + wanted) / (double) 2.0;
379 #ifdef DEBUG_PATCH_SPEED
384 return (max + wanted) / (double) 2.0;
388 #ifdef DEBUG_PATCH_SPEED
416 #ifdef DEBUG_INFORMED
420 <<
" informedBy=" << sender->
getID()
421 <<
" info=" << pinfo->second
422 <<
" vSafe=" << pinfo->first
434 double overtakeDist = (gap
439 return MAX2(overtakeDist, 0.);
447 const std::pair<MSVehicle*, double>& neighLead,
448 double remainingSeconds) {
457 #ifdef DEBUG_INFORMER
459 std::cout <<
"\nINFORM_LEADER"
464 const MSVehicle*
const nv = neighLead.first;
472 neighNextGap = neighLead.second +
SPEED2DIST(neighNextSpeed - plannedSpeed);
477 #ifdef DEBUG_INFORMER
479 std::cout <<
" blocked by leader nv=" << nv->
getID() <<
" nvSpeed=" << nv->
getSpeed() <<
" needGap="
486 const double dv = plannedSpeed - nv->
getSpeed();
489 overtakeTime = overtakeDist / dv;
492 overtakeTime = remainingSeconds + 1;
495 #ifdef DEBUG_INFORMER
498 <<
"\nnv = " << nv->
getID()
499 <<
"\nplannedSpeed = " << plannedSpeed
500 <<
"\nleaderSpeed = " << nv->
getSpeed()
502 <<
"\nremainingSeconds = " << remainingSeconds
503 <<
"\novertakeDist = " << overtakeDist
504 <<
"\novertakeTime = " << overtakeTime
519 && !(
isOpposite() && neighLead.second < 0 && neighLead.first->isStopped())) {
524 const double targetSpeed =
MAX2(
533 #ifdef DEBUG_INFORMER
536 <<
" cannot overtake leader nv=" << nv->
getID()
540 <<
" overtakeDist=" << overtakeDist
541 <<
" overtakeTime=" << overtakeTime
542 <<
" remainingSeconds=" << remainingSeconds
543 <<
" currentGap=" << neighLead.second
545 <<
" neighNextSpeed=" << neighNextSpeed
546 <<
" neighNextGap=" << neighNextGap
547 <<
" targetSpeed=" << targetSpeed
548 <<
" nextSpeed=" << nextSpeed
556 #ifdef DEBUG_INFORMER
559 <<
" cannot overtake fast leader nv=" << nv->
getID()
563 <<
" overtakeDist=" << overtakeDist
565 <<
" overtakeTime=" << overtakeTime
566 <<
" remainingSeconds=" << remainingSeconds
567 <<
" currentGap=" << neighLead.second
568 <<
" targetSpeed=" << targetSpeed
577 #ifdef DEBUG_INFORMER
580 <<
" wants to overtake leader nv=" << nv->
getID()
582 <<
" overtakeDist=" << overtakeDist
583 <<
" remainingSeconds=" << remainingSeconds
584 <<
" overtakeTime=" << overtakeTime
585 <<
" currentGap=" << neighLead.second
595 const double targetSpeed =
MAX2(
599 #ifdef DEBUG_INFORMER
601 std::cout <<
" not blocked by leader nv=" << nv->
getID()
603 <<
" gap=" << neighLead.second
604 <<
" neighNextSpeed=" << neighNextSpeed
605 <<
" neighNextGap=" << neighNextGap
607 <<
" targetSpeed=" << targetSpeed
611 return MIN2(targetSpeed, plannedSpeed);
619 const std::pair<MSVehicle*, double>& neighFollow,
620 double remainingSeconds,
621 double plannedSpeed) {
626 #ifdef DEBUG_INFORMER
628 std::cout <<
"\nINFORM_FOLLOWER"
634 #ifdef DEBUG_INFORMER
636 std::cout <<
" blocked by follower nv=" << nv->
getID() <<
" nvSpeed=" << nv->
getSpeed() <<
" needGap="
644 if ((neededGap - neighFollow.second) / remainingSeconds < (
MAX2(plannedSpeed, 0.) - nv->
getSpeed())) {
645 #ifdef DEBUG_INFORMER
647 std::cout <<
" wants to cut in before nv=" << nv->
getID() <<
" without any help." <<
"\nneededGap = " << neededGap <<
"\n";
667 double neighNewSpeed;
669 double neighNewSpeed1s;
679 dv = plannedSpeed - neighNewSpeed1s;
686 decelGap = neighFollow.second + dv;
693 neighNewSpeed1s = nv->
getSpeed() - helpDecel;
705 #ifdef DEBUG_INFORMER
709 <<
" plannedSpeed=" << plannedSpeed
710 <<
" threshold=" << onRampThreshold
711 <<
" neighNewSpeed=" << neighNewSpeed
712 <<
" neighNewSpeed1s=" << neighNewSpeed1s
714 <<
" gap=" << neighFollow.second
715 <<
" decelGap=" << decelGap
716 <<
" secureGap=" << secureGap
723 && neighNewSpeed1s < onRampThreshold) {
727 if (decelGap > 0 && decelGap >= secureGap) {
735 double vsafe, vsafe1;
744 assert(vsafe <= vsafe1);
755 #ifdef DEBUG_INFORMER
757 std::cout <<
"nextGap=" << nextGap <<
" (without help decel) \n";
765 MAX2(0., plannedSpeed),
773 nv->
getSpeed(), plannedAccel, -decel2,
783 MAX2(0., plannedSpeed),
788 #ifdef DEBUG_INFORMER
790 std::cout <<
"nextGap=" << nextGap
791 <<
" (with vsafe1 and help decel) \nvsafe1=" << vsafe1
792 <<
" vsafe=" << vsafe
801 if (nextGap < nextSecureGap) {
803 vsafe = neighNewSpeed;
806 #ifdef DEBUG_INFORMER
808 std::cout <<
"nextGap=" << nextGap
809 <<
" minNextSecureGap=" << nextSecureGap
810 <<
" vsafe=" << vsafe <<
"\n";
818 #ifdef DEBUG_INFORMER
820 std::cout <<
" wants to cut in before nv=" << nv->
getID()
821 <<
" vsafe1=" << vsafe1 <<
" vsafe=" << vsafe
847 #ifdef DEBUG_INFORMER
849 std::cout <<
" wants to cut in before nv=" << nv->
getID() <<
" (eventually)\n";
856 #ifdef DEBUG_INFORMER
858 std::cout <<
" wants to cut in before nv=" << nv->
getID() <<
" (nv cannot overtake right)\n";
877 #ifdef DEBUG_INFORMER
881 std::cout <<
" wants right follower to slow down a bit\n";
888 #ifdef DEBUG_INFORMER
891 std::cout <<
" wants to cut in before right follower nv=" << nv->
getID() <<
" (eventually)\n";
913 if (gapAfterRemainingSecs >= secureGapAfterRemainingSecs) {
914 #ifdef DEBUG_INFORMER
916 std::cout <<
" wants to cut in before follower nv=" << nv->
getID() <<
" (eventually)\n";
929 #ifdef DEBUG_INFORMER
933 <<
" informs follower " << nv->
getID()
934 <<
" vhelp=" << vhelp
943 const double needDV = overtakeDist / remainingSeconds;
947 #ifdef DEBUG_INFORMER
951 <<
" wants to be overtaken by=" << nv->
getID()
952 <<
" overtakeDist=" << overtakeDist
954 <<
" vhelp=" << vhelp
955 <<
" needDV=" << needDV
964 double vsafe, vsafe1;
978 double anticipationTime = 1.;
989 if (anticipatedGap > secureGap) {
996 if (anticipatedGap < secureGap) {
1007 #ifdef DEBUG_INFORMER
1009 std::cout <<
" wants to cut in before non-blocking follower nv=" << nv->
getID() <<
"\n";
1064 const std::pair<MSVehicle*, double>& leader,
1065 const std::pair<MSVehicle*, double>& neighLead,
1066 const std::pair<MSVehicle*, double>& neighFollow,
1068 const std::vector<MSVehicle::LaneQ>& preb,
1071 assert(laneOffset == 1 || laneOffset == -1);
1075 int bestLaneOffset = 0;
1080 double currentDist = 0;
1081 double neighDist = 0;
1090 const int prebOffset = (checkOpposite ? 0 : laneOffset);
1091 for (
int p = 0; p < (int) preb.size(); ++p) {
1092 if (preb[p].lane == prebLane && p + laneOffset >= 0) {
1093 assert(p + prebOffset < (
int)preb.size());
1095 neigh = preb[p + prebOffset];
1096 currentDist = curr.
length;
1097 neighDist = neigh.
length;
1099 if (bestLaneOffset == 0 && preb[p + prebOffset].bestLaneOffset == 0) {
1100 #ifdef DEBUG_WANTS_CHANGE
1104 <<
" bestLaneOffsetOld=" << bestLaneOffset
1105 <<
" bestLaneOffsetNew=" << laneOffset
1109 bestLaneOffset = prebOffset;
1111 best = preb[p + bestLaneOffset];
1117 const bool right = (laneOffset == -1);
1119 neigh = preb[preb.size() - 1];
1122 bestLaneOffset = -1;
1124 neighDist = neigh.
length;
1125 currentDist = curr.
length;
1127 double driveToNextStop = -std::numeric_limits<double>::max();
1135 #ifdef DEBUG_WANTS_CHANGE
1140 <<
" stopPos=" << stopPos
1141 <<
" currentDist=" << currentDist
1142 <<
" neighDist=" << neighDist
1146 currentDist =
MAX2(currentDist, stopPos);
1147 neighDist =
MAX2(neighDist, stopPos);
1153 const bool changeToBest = (right && bestLaneOffset < 0) || (!right && bestLaneOffset > 0);
1159 if (lastBlocked != firstBlocked) {
1163 #ifdef DEBUG_WANTS_CHANGE
1172 <<
" leaderGap=" << leader.second
1174 <<
" neighLeadGap=" << neighLead.second
1176 <<
" neighFollowGap=" << neighFollow.second
1199 assert(memoryFactor > 0.);
1207 if (bestLaneOffset == 0 && leader.first != 0 && leader.first->isStopped() && leader.second < (currentDist - posOnLane)) {
1212 + leader.first->getVehicleType().getLengthWithGap()
1214 }
else if (bestLaneOffset == laneOffset && neighLead.first != 0 && neighLead.first->isStopped() && neighLead.second < (currentDist - posOnLane)) {
1217 + neighLead.first->getVehicleType().getLengthWithGap()
1218 + neighLead.second);
1233 currentDist += roundaboutBonus;
1234 neighDist += roundaboutBonus;
1238 const double maxJam =
MAX2(preb[currIdx + prebOffset].occupation, preb[currIdx].occupation);
1239 const double neighLeftPlace =
MAX2((
double) 0, neighDist - posOnLane - maxJam);
1242 double thisLaneVSafe = vMax;
1248 #ifdef DEBUG_WANTS_CHANGE
1253 <<
" laDist=" << laDist
1254 <<
" currentDist=" << currentDist
1255 <<
" usableDist=" << usableDist
1256 <<
" bestLaneOffset=" << bestLaneOffset
1258 <<
" best.length=" << best.
length
1259 <<
"\n roundaboutBonus=" << roundaboutBonus
1260 <<
" maxJam=" << maxJam
1261 <<
" neighDist=" << neighDist
1262 <<
" neighLeftPlace=" << neighLeftPlace
1267 bool changeLeftToAvoidOvertakeRight =
false;
1274 if (neighLead.first != 0 && checkOverTakeRight && !right) {
1286 if (vSafeFollow >= vMaxDecel) {
1287 vSafe = vSafeFollow;
1289 vSafe =
MAX2(vMaxDecel, vStayBehind);
1294 thisLaneVSafe =
MIN2(thisLaneVSafe, vSafe);
1297 const double deltaGapFuture = deltaV * 8;
1300 if (vSafeFuture < vSafe) {
1301 const double relativeGain = deltaV /
MAX2(vMax,
1304 changeLeftToAvoidOvertakeRight =
true;
1306 #ifdef DEBUG_WANTS_CHANGE
1309 <<
" avoid overtaking on the right nv=" << nv->
getID()
1310 <<
" deltaV=" << deltaV
1319 const double overtakeDist = (leader.first == 0 ? -1 :
1323 &&
MIN2(neighDist, currentDist) - posOnLane > overtakeDist
1325 && (!checkOverTakeRight || !right)
1326 && (neighLead.first == 0 || !neighLead.first->isStopped()
1328 || neighLead.second > overtakeDist)) {
1331 #ifdef DEBUG_WANTS_CHANGE
1333 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" overtake stopped leader=" << leader.first->getID()
1334 <<
" overtakeDist=" << overtakeDist
1335 <<
" remaining=" <<
MIN2(neighDist, currentDist) - posOnLane
1340 }
else if (!changeToBest && (
currentDistDisallows(neighLeftPlace, abs(bestLaneOffset) + 2, laDist))) {
1347 #ifdef DEBUG_WANTS_CHANGE
1349 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" could not change back and forth in time (1) neighLeftPlace=" << neighLeftPlace <<
"\n";
1353 }
else if (bestLaneOffset == 0 && (neighLeftPlace * 2. < laDist)) {
1358 #ifdef DEBUG_WANTS_CHANGE
1360 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" could not change back and forth in time (2) neighLeftPlace=" << neighLeftPlace <<
"\n";
1364 }
else if (bestLaneOffset == 0
1365 && (leader.first == 0 || !leader.first->isStopped())
1367 && roundaboutBonus == 0
1373 #ifdef DEBUG_WANTS_CHANGE
1375 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" does not want to leave the bestLane (neighDist=" << neighDist <<
")\n";
1382 #ifdef DEBUG_WANTS_CHANGE
1390 if ((ret & lcaCounter) != 0) {
1394 #ifdef DEBUG_WANTS_CHANGE
1396 std::cout <<
" retAfterInfluence=" << ret <<
"\n";
1407 if (changeToBest && abs(bestLaneOffset) > 1) {
1410 #ifdef DEBUG_WANTS_CHANGE
1412 std::cout <<
" reserving space for unseen blockers myLeadingBlockerLength=" <<
myLeadingBlockerLength <<
"\n";
1420 if (*firstBlocked != neighLead.first) {
1424 const int remainingLanes =
MAX2(1, abs(bestLaneOffset));
1426 const double remainingSeconds = ((ret &
LCA_TRACI) == 0 ?
1430 const double plannedSpeed =
informLeader(msgPass, blocked, myLca, neighLead, remainingSeconds);
1435 informFollower(msgPass, blocked, myLca, neighFollow, remainingSeconds, plannedSpeed);
1438 #ifdef DEBUG_WANTS_CHANGE
1443 <<
" remainingSeconds=" << remainingSeconds
1444 <<
" plannedSpeed=" << plannedSpeed
1452 const double inconvenience =
MIN2((
double)1.0, (laneOffset < 0
1459 if (roundaboutBonus > 0) {
1461 #ifdef DEBUG_WANTS_CHANGE
1465 <<
" roundaboutBonus=" << roundaboutBonus
1495 #ifdef DEBUG_WANTS_CHANGE
1497 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" does not want to get stranded on the on-ramp of a highway\n";
1517 && (!speedGainInconvenient)
1519 && (changeToBest ||
currentDistAllows(neighDist, abs(bestLaneOffset) + 1, laDist))) {
1522 #ifdef DEBUG_COOPERATE
1526 <<
" wantsChangeToHelp=" << (right ?
"right" :
"left")
1528 << (((
myOwnState & myLca) == 0) ?
" (counter)" :
"")
1557 const bool acceleratingLeader = (neighLead.first != 0 && neighLead.first->getAcceleration() > 0)
1558 || (leader.first != 0 && leader.first->getAcceleration() > 0);
1560 if (acceleratingLeader) {
1567 if (neighLead.first == 0) {
1571 &
myVehicle, correctedSpeed, neighLead.second, neighLead.first->
getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel()));
1573 if (leader.first == 0) {
1577 &
myVehicle, correctedSpeed, leader.second, leader.first->
getSpeed(), leader.first->getCarFollowModel().getMaxDecel()));
1580 if (neighLead.first == 0) {
1584 neighLead.first->getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel(),
true));
1586 if (leader.first == 0) {
1590 leader.first->getSpeed(), leader.first->getCarFollowModel().getMaxDecel(),
true));
1600 const double relativeGain = (neighLaneVSafe - thisLaneVSafe) /
MAX2(neighLaneVSafe,
1603 #ifdef DEBUG_WANTS_CHANGE
1607 <<
" currentDist=" << currentDist
1608 <<
" neighDist=" << neighDist
1609 <<
" thisVSafe=" << thisLaneVSafe
1610 <<
" neighVSafe=" << neighLaneVSafe
1611 <<
" relGain=" <<
toString(relativeGain, 8)
1618 if (thisLaneVSafe - 5 / 3.6 > neighLaneVSafe) {
1635 if (mySpeedGainProbability < 0 || relativeGain > 0) {
1644 double fullSpeedDrivingSeconds =
MIN2(acceptanceTime, fullSpeedGap / vMax);
1645 if (neighLead.first != 0 && neighLead.first->getSpeed() < vMax) {
1646 fullSpeedGap =
MAX2(0.,
MIN2(fullSpeedGap,
1648 vMax, neighLead.first->
getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel())));
1649 fullSpeedDrivingSeconds =
MIN2(fullSpeedDrivingSeconds, fullSpeedGap / (vMax - neighLead.first->getSpeed()));
1652 if (checkOverTakeRight && leader.first != 0
1653 && leader.first->getLane()->getVehicleMaxSpeed(leader.first) < vMax) {
1654 fullSpeedGap =
MIN2(fullSpeedGap, leader.second);
1655 fullSpeedDrivingSeconds =
MIN2(fullSpeedDrivingSeconds, fullSpeedGap / (vMax - leader.first->getSpeed()));
1656 const double relativeGain = (vMax - leader.first->getLane()->getVehicleMaxSpeed(leader.first)) /
MAX2(vMax,
1665 #ifdef DEBUG_WANTS_CHANGE
1670 <<
" neighDist=" << neighDist
1672 <<
" leaderSpeed=" << (neighLead.first == 0 ? -1 : neighLead.first->getSpeed())
1674 myVehicle.
getSpeed(), neighLead.first->getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel()))
1675 <<
" acceptanceTime=" << acceptanceTime
1676 <<
" fullSpeedGap=" << fullSpeedGap
1677 <<
" fullSpeedDrivingSeconds=" << fullSpeedDrivingSeconds
1678 <<
" dProb=" << deltaProb
1691 #ifdef DEBUG_WANTS_CHANGE
1697 <<
" thisLaneVSafe=" << thisLaneVSafe
1698 <<
" neighLaneVSafe=" << neighLaneVSafe
1699 <<
" relativeGain=" << relativeGain
1700 <<
" blocked=" << blocked
1714 if (thisLaneVSafe > neighLaneVSafe) {
1719 }
else if (thisLaneVSafe == neighLaneVSafe) {
1737 #ifdef DEBUG_WANTS_CHANGE
1743 <<
" thisLaneVSafe=" << thisLaneVSafe
1744 <<
" neighLaneVSafe=" << neighLaneVSafe
1745 <<
" relativeGain=" << relativeGain
1746 <<
" blocked=" << blocked
1752 && (relativeGain >
NUMERICAL_EPS || changeLeftToAvoidOvertakeRight)
1762 && relativeGain >= 0
1763 && (right ? mySpeedGainProbability < 0 : mySpeedGainProbability > 0)) {
1770 #ifdef DEBUG_WANTS_CHANGE
1776 <<
" thisLaneVSafe=" << thisLaneVSafe
1777 <<
" neighLaneVSafe=" << neighLaneVSafe
1793 int roundaboutJunctionsAhead = 0;
1794 bool enteredRoundabout =
false;
1800 if (lane ==
nullptr) {
1805 #ifdef DEBUG_WANTS_CHANGE
1807 std::cout <<
" noBonus: inner does not continue (lane=" << lane->
getID() <<
")\n";
1814 #ifdef DEBUG_WANTS_CHANGE
1816 std::cout <<
" noBonus: seen=" << seen <<
" (lane=" << lane->
getID() <<
")\n";
1823 enteredRoundabout =
true;
1825 roundaboutJunctionsAhead++;
1827 }
else if (enteredRoundabout) {
1834 if (roundaboutJunctionsAhead < 2) {
1840 double occupancyOuter = 0;
1841 double occupancyInner = 0;
1842 double distanceInRoundabout = 0;
1843 MSLane* prevNormal =
nullptr;
1844 MSLane* prevInner =
nullptr;
1845 enteredRoundabout =
false;
1848 if (lane ==
nullptr) {
1852 enteredRoundabout =
true;
1853 }
else if (enteredRoundabout) {
1858 if (prevNormal !=
nullptr) {
1860 if (link->getLane() == lane) {
1861 via = link->getViaLane();
1865 if (enteredRoundabout) {
1866 distanceInRoundabout += lane->
getLength();
1867 if (via !=
nullptr) {
1868 distanceInRoundabout += via->
getLength();
1877 std::cout <<
" lane=" << lane->
getID() <<
" occ=" << lane->
getBruttoVehLenSum() <<
" discount=" << upstreamDiscount <<
" outer=" << occupancyOuter <<
"\n";
1879 if (via !=
nullptr) {
1882 std::cout <<
" via=" << via->
getID() <<
" occ=" << via->
getBruttoVehLenSum() <<
" outer=" << occupancyOuter <<
"\n";
1889 std::cout <<
" inner=" << innerLane->
getID() <<
" occ=" << innerLane->
getBruttoVehLenSum() <<
" discount=" << upstreamDiscount <<
" inner=" << occupancyInner <<
"\n";
1891 if (prevInner !=
nullptr) {
1893 if (link->getLane() == innerLane && link->getViaLane() !=
nullptr) {
1894 occupancyInner += link->getViaLane()->getBruttoVehLenSum();
1896 std::cout <<
" innerVia=" << link->getViaLane()->getID() <<
" occ=" << link->getViaLane()->getBruttoVehLenSum() <<
" inner=" << occupancyInner <<
"\n";
1901 prevInner = innerLane;
1905 #ifdef DEBUG_WANTS_CHANGE
1907 std::cout <<
" distanceInRoundabout=" << distanceInRoundabout
1908 <<
" roundaboutJunctionsAhead=" << roundaboutJunctionsAhead
1909 <<
" occupancyInner=" << occupancyInner
1910 <<
" occupancyOuter=" << occupancyOuter
1915 const double maxOccupancy =
MAX2(occupancyInner, occupancyOuter);
1916 if (maxOccupancy == 0) {
1921 const double bonus = roundaboutJunctionsAhead * 7.5;
1922 const double relativeJam = (occupancyOuter - occupancyInner + bonus) / (maxOccupancy + bonus);
1924 const double jamFactor =
MAX2(0.0, relativeJam);
1926 #ifdef DEBUG_WANTS_CHANGE
1928 std::cout <<
" relativeJam=" << relativeJam
1929 <<
" jamFactor=" << jamFactor
1930 <<
" distanceBonus=" << result
1941 if ((*blocked) !=
nullptr) {
1943 #ifdef DEBUG_SLOW_DOWN
1967 (*blocked)->getCarFollowModel().getMaxDecel()));
1970 #ifdef DEBUG_SLOW_DOWN
1974 <<
" slowing down for"
1996 #ifdef DEBUG_SAVE_BLOCKER_LENGTH
2012 #ifdef DEBUG_SAVE_BLOCKER_LENGTH
2024 #ifdef DEBUG_SAVE_BLOCKER_LENGTH
2030 <<
" potential=" << potential
2043 #ifdef DEBUG_WANTS_CHANGE
2045 std::cout <<
SIMTIME <<
" adapt to pedestrians on lane=" << lane->
getID() <<
"\n";
2051 if (leader.first != 0) {
2053 v =
MIN2(v, stopSpeed);
2054 #ifdef DEBUG_WANTS_CHANGE
2056 std::cout <<
SIMTIME <<
" pedLeader=" << leader.first->getID() <<
" dist=" << leader.second <<
" v=" << v <<
"\n";
2077 return MAX2(-speedBound,
MIN2(speedBound,
2093 return myOppositeParam <= 0 ? std::numeric_limits<double>::max() : 1 /
myOppositeParam;
double getOppositeSafetyFactor() const
return factor for modifying the safety constraints for opposite-diretction overtaking of the car-foll...
double getAssumedDecelForLaneChangeDuration() const
Returns a deceleration value which is used for the estimation of the duration of a lane change.
#define UNUSED_PARAMETER(x)
bool isRoundabout() const
@ SUMO_ATTR_LCA_SPEEDGAIN_PARAM
int bestLaneOffset
The (signed) number of lanes to be crossed to get to the lane which allows to continue the drive.
void setLateralPositionOnLane(double posLat)
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
int getBestLaneOffset() const
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
void step(double dt)
evolve for a time step of length dt.
double maximumSafeFollowSpeed(double gap, double egoSpeed, double predSpeed, double predMaxDecel, bool onInsertion=false) const
Returns the maximum safe velocity for following the given leader.
const std::set< MSTransportable * > & getPersons() const
Returns this edge's persons set.
void * informNeighLeader(void *info, MSVehicle *sender)
Informs the leader on the desired lane.
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
@ SVC_EMERGENCY
public emergency vehicles
void addLCSpeedAdvice(const double vSafe)
Takes a vSafe (speed advice for speed in the next simulation step), converts it into an acceleration ...
#define REACT_TO_STOPPED_DISTANCE
std::pair< double, int > Info
information regarding save velocity (unused) and state flags of the ego vehicle
Representation of a lane in the micro simulation.
bool isStopped() const
Returns whether the vehicle is at a stop.
double myKeepRightProbability
@ LCA_LEFT
Wants go to the left.
double getSafetyFactor() const
return factor for modifying the safety constraints of the car-following model
bool cancelRequest(int state, int laneOffset)
whether the influencer cancels the given request
@ SUMO_ATTR_LCA_COOPERATIVE_PARAM
#define ROUNDABOUT_DIST_FACTOR
static bool myAllowOvertakingRight
whether overtaking on the right is permitted
The base class for an intersection.
int influenceChangeDecision(int state)
allow TraCI to influence a lane change decision
A class responsible for exchanging messages between cars involved in lane-change interaction.
static double toDouble(const std::string &sData)
converts a string into the double value described by it by calling the char-type converter
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...
double length
The overall length which may be driven when using this lane without a lane change.
virtual double getSecureGap(const MSVehicle *const, 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)
bool isAccelLane() const
return whether this lane is an acceleration lane
A structure representing the best lanes for continuing the current route starting at 'lane'.
int _wantsChange(int laneOffset, MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, const std::pair< MSVehicle *, double > &leader, 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
double getRoundaboutDistBonus(const MSVehicle::LaneQ &curr, const MSVehicle::LaneQ &neigh, const MSVehicle::LaneQ &best)
Computes the artificial bonus distance for roundabout lanes this additional distance reduces the sens...
double patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel)
Called to adapt the speed in order to allow a lane change. It uses information on LC-related desired ...
@ LCA_SPEEDGAIN
The action is due to the wish to be faster (tactical lc)
@ LCA_URGENT
The action is urgent (to be defined by lc-model)
void saveBlockerLength(MSVehicle *blocker, int lcaCounter)
save space for vehicles which need to counter-lane-change
@ LCA_BLOCKED_BY_LEADER
blocked by leader
double myChangeProbThresholdLeft
bool hasLaneChanger() const
#define RELGAIN_NORMALIZATION_MIN_SPEED
@ SUMO_ATTR_LCA_KEEPRIGHT_PARAM
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
double getBruttoOccupancy() const
Returns the brutto (including minGaps) occupancy of this lane during the last step.
MSAbstractLaneChangeModel & getLaneChangeModel()
bool isChangingLanes() const
return true if the vehicle currently performs a lane change maneuver
@ SUMO_ATTR_LCA_EXPERIMENTAL1
const ConstMSEdgeVector & getIncoming() const
const double SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
Influencer & getInfluencer()
Returns the velocity/lane influencer.
int wantsChange(int laneOffset, MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, const std::pair< MSVehicle *, double > &leader, 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)
Called to examine whether the vehicle wants to change using the given laneOffset. This method gets th...
const ConstMSEdgeVector & getOutgoing() const
double getLateralPositionOnLane() const
Get the vehicle's lateral position on the lane.
bool isInternal() const
return whether this edge is an internal edge
double getBruttoVehLenSum() const
Returns the sum of lengths of vehicles, including their minGaps, which were on the lane during the la...
bool currentDistAllows(double dist, int laneOffset, double lookForwardDist)
bool debugVehicle() const
whether the current vehicles shall be debugged
#define LCA_RIGHT_IMPATIENCE
double computeSpeedLat(double latDist, double &maneuverDist)
decides the next lateral speed (for continuous lane changing)
static double overtakeDistance(const MSVehicle *follower, const MSVehicle *leader, const double gap, double followerSpeed=INVALID_SPEED, double leaderSpeed=INVALID_SPEED)
static double rand(std::mt19937 *rng=0)
Returns a random real number in [0, 1)
std::pair< const MSPerson *, double > PersonDist
@ LCA_STRATEGIC
The action is needed to follow the route (navigational lc)
double getPositionOnLane() const
Get the vehicle's position along the lane.
int & getCanceledState(const int dir)
double mySpeedGainProbability
a value for tracking the probability that a change to the offset with the same sign is beneficial
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
double getImpatience() const
Returns this vehicles impatience.
int slowDownForBlocked(MSVehicle **blocked, int state)
compute useful slowdowns for blocked vehicles
double getActionStepLengthSecs() const
Returns the vehicle's action step length in secs, i.e. the interval between two action points.
LaneChangeAction
The state of a vehicle's lane-change behavior.
double getWidth() const
Get the width which vehicles of this class shall have when being drawn.
#define LOOK_AHEAD_SPEED_MEMORY
@ SUMO_ATTR_LCA_OPPOSITE_PARAM
void initDerivedParameters()
init cached parameters derived directly from model parameters
double myMaxSpeedLatFactor
double getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
bool currentDistDisallows(double dist, int laneOffset, double lookForwardDist)
virtual void prepareStep()
const LaneChangeModel myModel
the type of this model
double _patchSpeed(const double min, const double wanted, const double max, const MSCFModel &cfModel)
double myChangeProbThresholdRight
@ LCA_AMBLOCKINGFOLLOWER_DONTBRAKE
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
double maximumSafeStopSpeed(double gap, double currentSpeed, bool onInsertion=false, double headway=-1) const
Returns the maximum next velocity for stopping within gap.
@ SUMO_ATTR_LCA_SPEEDGAINRIGHT
double getLength() const
Returns the lane's length.
void adaptSpeedToPedestrians(const MSLane *lane, double &v)
react to pedestrians on the given lane
std::vector< double > myLCAccelerationAdvices
vector of LC-related acceleration recommendations Filled in wantsChange() and applied in patchSpeed()
double getOppositePos(double pos) const
return the corresponding position on the opposite lane
@ SUMO_ATTR_LCA_LOOKAHEADLEFT
MSLane * lane
The described lane.
@ SUMO_ATTR_LCA_OVERTAKE_RIGHT
const MSLane * lane
The lane to stop at.
@ SUMO_ATTR_LCA_STRATEGIC_PARAM
double getMinGap() const
Get the free space in front of vehicles of this class.
double occupation
The overall vehicle sum on consecutive lanes which can be passed without a lane change.
void * informNeighFollower(void *info, MSVehicle *sender)
Informs the follower on the desired lane.
const MSJunction * getToJunction() const
double getLastStepDist() const
Get the distance the vehicle covered in the previous timestep.
double myCooperativeParam
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
@ LCA_WANTS_LANECHANGE
lane can change
@ SUMO_ATTR_LCA_ASSERTIVE
const double myExperimentalParam1
virtual PersonDist nextBlocking(const MSLane *lane, double minPos, double minRight, double maxLeft, double stopTime=0)
returns the next pedestrian beyond minPos that is laterally between minRight and maxLeft or 0
MSLane * getLane() const
Returns the lane the vehicle is on.
MSEdge & getEdge() const
Returns the lane's edge.
#define CUT_IN_LEFT_SPEED_THRESHOLD
#define HELP_DECEL_FACTOR
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
double myMaxSpeedLatStanding
@ LCA_RIGHT
Wants go to the right.
std::vector< MSLane * > bestContinuations
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...
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
const MSCFModel & myCarFollowModel
The vehicle's car following model.
@ LCA_STAY
Needs to stay on the current lane.
virtual double getSpeedAfterMaxDecel(double v) const
Returns the velocity after maximum deceleration.
virtual void saveBlockerLength(double length)
reserve space at the end of the lane to avoid dead locks
@ LCA_AMBACKBLOCKER_STANDING
double getLength() const
Get vehicle's length [m].
virtual double stopSpeed(const MSVehicle *const veh, const double speed, double gap) const =0
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling)
int myOwnState
The current state of the vehicle.
double getRightSideOnLane() const
Get the vehicle's lateral position on the lane:
#define LOOK_AHEAD_MIN_SPEED
const std::string & getID() const
Returns the name of the vehicle.
double getAcceleration() const
Returns the vehicle's acceleration in m/s (this is computed as the last step's mean acceleration in c...
static MSPModel * getModel()
The car-following model abstraction.
std::string getParameter(const std::string &key) const
try to retrieve the given parameter from this device. Throw exception for unsupported key
@ LCA_BLOCKED_BY_FOLLOWER
blocker by follower
double myOvertakeRightParam
static std::string getIDSecure(const T *obj, const std::string &fallBack="NULL")
get an identifier for Named-like object which may be Null
Interface for lane-change models.
double getSpeed() const
Returns the vehicle's current speed.
MSVehicle & myVehicle
The vehicle this lane-changer belongs to.
@ LCA_KEEPRIGHT
The action is due to the default of keeping right "Rechtsfahrgebot".
int gPrecision
the precision for floating point outputs
static SUMOTime gLaneChangeDuration
virtual double computeSpeedLat(double latDist, double &maneuverDist)
decides the next lateral speed depending on the remaining lane change distance to be covered and upda...
#define MAX_ONRAMP_LENGTH
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
double changeRequestRemainingSeconds(const SUMOTime currentTime) const
Return the remaining number of seconds of the current laneTimeLine assuming one exists.
double getSpeedLimit() const
Returns the lane's maximum allowed speed.
SUMOVehicleClass getVehicleClass() const
Get this vehicle type's vehicle class.
void * inform(void *info, MSVehicle *sender)
static bool gSemiImplicitEulerUpdate
double nextStopDist() const
return the distance to the next stop or doubleMax if there is none.
const std::string & getID() const
Returns the id.
virtual double followSpeed(const MSVehicle *const veh, double speed, double gap2pred, double predSpeed, double predMaxDecel, const MSVehicle *const pred=0) const =0
Computes the vehicle's follow speed (no dawdling)
@ LCA_COOPERATIVE
The action is done to help someone else.
#define KEEP_RIGHT_ACCEPTANCE
void setParameter(const std::string &key, const std::string &value)
try to set the given parameter for this laneChangeModel. Throw exception for unsupported key
bool amBlockingFollowerPlusNB()
@ LCA_TRACI
The action is due to a TraCI request.
@ LCA_BLOCKED
blocked in all directions
double getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
double informLeader(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, double > &neighLead, double remainingSeconds)
std::mt19937 * getRNG() const
double myLeadingBlockerLength
MSLCM_LC2013(MSVehicle &v)
Representation of a vehicle in the micro simulation.
double getMaxSpeedOnLane() const
Returns the maximal speed for the vehicle on its current lane (including speed factor and deviation,...
#define LC_RESOLUTION_SPEED_LAT