39 #ifdef CHECK_MEMORY_LEAKS
41 #endif // CHECK_MEMORY_LEAKS
44 #ifdef DEBUG_VEHICLE_GUI_SELECTION
56 #define LOOK_FORWARD_SPEED_DIVIDER (SUMOReal)14.
62 #define LOOK_FORWARD_RIGHT (SUMOReal)10.
63 #define LOOK_FORWARD_LEFT (SUMOReal)20.
65 #define JAM_FACTOR (SUMOReal)1.
68 #define LCA_RIGHT_IMPATIENCE (SUMOReal)-1.
69 #define CUT_IN_LEFT_SPEED_THRESHOLD (SUMOReal)27.
71 #define LOOK_AHEAD_MIN_SPEED (SUMOReal)0.0
72 #define LOOK_AHEAD_SPEED_MEMORY (SUMOReal)0.9
73 #define LOOK_AHEAD_SPEED_DECREMENT 6.
75 #define HELP_DECEL_FACTOR (SUMOReal)1.0
77 #define HELP_OVERTAKE (SUMOReal)(10.0 / 3.6)
78 #define MIN_FALLBEHIND (SUMOReal)(14.0 / 3.6)
80 #define KEEP_RIGHT_HEADWAY (SUMOReal)2.0
82 #define URGENCY (SUMOReal)2.0
84 #define ROUNDABOUT_DIST_BONUS (SUMOReal)100.0
86 #define CHANGE_PROB_THRESHOLD_RIGHT (SUMOReal)2.0
87 #define CHANGE_PROB_THRESHOLD_LEFT (SUMOReal)0.2
88 #define KEEP_RIGHT_TIME (SUMOReal)5.0 // the number of seconds after which a vehicle should move to the right lane
89 #define KEEP_RIGHT_ACCEPTANCE (SUMOReal)2.0 // calibration factor for determining the desire to keep right
91 #define OVERTAKE_RIGHT_FORBIDDEN true // This holds true for german traffic but should be made configurable to model american traffic
97 #define DEBUG_COND false
102 return v == 0 ?
"NULL" : v->
getID();
111 mySpeedGainProbability(0),
112 myKeepRightProbability(0),
113 myLeadingBlockerLength(0),
128 const std::pair<MSVehicle*, SUMOReal>& leader,
129 const std::pair<MSVehicle*, SUMOReal>& neighLead,
130 const std::pair<MSVehicle*, SUMOReal>& neighFollow,
132 const std::vector<MSVehicle::LaneQ>& preb,
143 <<
" considerChangeTo=" << (laneOffset == -1 ?
"right" :
"left")
147 const int result =
_wantsChange(laneOffset, msgPass, blocked, leader, neighLead, neighFollow, neighLane, preb, lastBlocked, firstBlocked);
152 <<
" wantsChangeTo=" << (laneOffset == -1 ?
"right" :
"left")
159 << ((result &
LCA_TRACI) ?
" (traci)" :
"")
176 const std::string patched = (wanted != newSpeed ?
" patched=" +
toString(newSpeed) :
"");
182 <<
" wanted=" << wanted
213 std::cout << time <<
" veh=" <<
myVehicle.
getID() <<
" slowing down for leading blocker" << (safe +
NUMERICAL_EPS < min ?
" (not enough)" :
"") <<
"\n";
215 return MAX2(min, safe);
222 for (std::vector<SUMOReal>::const_iterator i =
myVSafes.begin(); i !=
myVSafes.end(); ++i) {
224 if (v >= min && v <= max) {
225 nVSafe =
MIN2(v, nVSafe);
228 std::cout << time <<
" veh=" <<
myVehicle.
getID() <<
" got nVSafe=" << nVSafe <<
"\n";
233 std::cout << time <<
" veh=" <<
myVehicle.
getID() <<
" ignoring low nVSafe=" << v <<
" min=" << min <<
"\n";
237 std::cout << time <<
" veh=" <<
myVehicle.
getID() <<
" ignoring high nVSafe=" << v <<
" max=" << max <<
"\n";
245 std::cout << time <<
" veh=" <<
myVehicle.
getID() <<
" got vSafe\n";
256 std::cout << time <<
" veh=" <<
myVehicle.
getID() <<
" LCA_WANTS_LANECHANGE (strat, no vSafe)\n";
258 return (max + wanted) / (
SUMOReal) 2.0;
263 std::cout << time <<
" veh=" <<
myVehicle.
getID() <<
" LCA_BLOCKED_BY_LEADER (coop)\n";
265 return (min + wanted) / (
SUMOReal) 2.0;
269 std::cout << time <<
" veh=" <<
myVehicle.
getID() <<
" LCA_BLOCKED_BY_FOLLOWER (coop)\n";
271 return (max + wanted) / (
SUMOReal) 2.0;
313 std::cout << time <<
" veh=" <<
myVehicle.
getID() <<
" LCA_AMBLOCKINGLEADER\n";
315 return (max + wanted) / (
SUMOReal) 2.0;
320 std::cout << time <<
" veh=" <<
myVehicle.
getID() <<
" LCA_AMBLOCKINGFOLLOWER_DONTBRAKE\n";
341 if (pinfo->first >= 0) {
349 <<
" informedBy=" << sender->
getID()
350 <<
" info=" << pinfo->second
351 <<
" vSafe=" << pinfo->first
363 const std::pair<MSVehicle*, SUMOReal>& neighLead,
367 for (std::vector<SUMOReal>::const_iterator i =
myVSafes.begin(); i !=
myVSafes.end(); ++i) {
370 plannedSpeed =
MIN2(plannedSpeed, v);
374 std::cout <<
" informLeader speed=" <<
myVehicle.
getSpeed() <<
" planned=" << plannedSpeed <<
"\n";
378 assert(neighLead.first != 0);
380 if (
gDebugFlag2) std::cout <<
" blocked by leader nv=" << nv->
getID() <<
" nvSpeed=" << nv->
getSpeed() <<
" needGap="
384 const SUMOReal overtakeDist = (neighLead.second
396 || dv * remainingSeconds < overtakeDist) {
409 <<
" cannot overtake leader nv=" << nv->
getID()
411 <<
" remainingSeconds=" << remainingSeconds
412 <<
" targetSpeed=" << targetSpeed
413 <<
" nextSpeed=" << nextSpeed
422 <<
" cannot overtake fast leader nv=" << nv->
getID()
424 <<
" remainingSeconds=" << remainingSeconds
425 <<
" targetSpeed=" << targetSpeed
434 <<
" wants to overtake leader nv=" << nv->
getID()
436 <<
" remainingSeconds=" << remainingSeconds
437 <<
" currentGap=" << neighLead.second
445 }
else if (neighLead.first != 0) {
454 std::cout <<
" not blocked by leader nv=" << nv->
getID()
456 <<
" gap=" << neighLead.second
457 <<
" nextGap=" << neighLead.second - dv
459 <<
" targetSpeed=" << targetSpeed
462 return MIN2(targetSpeed, plannedSpeed);
474 const std::pair<MSVehicle*, SUMOReal>& neighFollow,
478 assert(neighFollow.first != 0);
480 if (
gDebugFlag2) std::cout <<
" blocked by follower nv=" << nv->
getID() <<
" nvSpeed=" << nv->
getSpeed() <<
" needGap="
486 if ((neededGap - neighFollow.second) / remainingSeconds < (plannedSpeed - nv->
getSpeed())) {
488 std::cout <<
" wants to cut in before nv=" << nv->
getID() <<
" without any help neededGap=" << neededGap <<
"\n";
507 const SUMOReal dv = plannedSpeed - neighNewSpeed1s;
509 const SUMOReal decelGap = neighFollow.second + dv;
514 <<
" egoNV=" << plannedSpeed
515 <<
" nvNewSpeed=" << neighNewSpeed
516 <<
" nvNewSpeed1s=" << neighNewSpeed1s
517 <<
" deltaGap=" << dv
518 <<
" decelGap=" << decelGap
519 <<
" secGap=" << secureGap
522 if (decelGap > 0 && decelGap >= secureGap) {
529 std::cout <<
" wants to cut in before nv=" << nv->
getID() <<
"\n";
531 }
else if (dv > 0 && dv * remainingSeconds > (secureGap - decelGap +
POSITION_EPS)) {
535 std::cout <<
" wants to cut in before nv=" << nv->
getID() <<
" (eventually)\n";
547 std::cout <<
" wants right follower to slow down a bit\n";
551 std::cout <<
" wants to cut in before right follower nv=" << nv->
getID() <<
" (eventually)\n";
559 const SUMOReal overtakeDist = (neighFollow.second
565 const SUMOReal needDV = overtakeDist / remainingSeconds;
572 <<
" wants to be overtaken by=" << nv->
getID()
573 <<
" overtakeDist=" << overtakeDist
575 <<
" vhelp=" << vhelp
576 <<
" needDV=" << needDV
621 const std::pair<MSVehicle*, SUMOReal>& leader,
622 const std::pair<MSVehicle*, SUMOReal>& neighLead,
623 const std::pair<MSVehicle*, SUMOReal>& neighFollow,
625 const std::vector<MSVehicle::LaneQ>& preb,
628 assert(laneOffset == 1 || laneOffset == -1);
632 int bestLaneOffset = 0;
641 for (
int p = 0; p < (
int) preb.size(); ++p) {
642 if (preb[p].lane == prebLane && p + laneOffset >= 0) {
643 assert(p + laneOffset < (
int)preb.size());
645 neigh = preb[p + laneOffset];
646 currentDist = curr.
length;
648 bestLaneOffset = curr.bestLaneOffset;
650 if (bestLaneOffset == 0 && preb[p + laneOffset].bestLaneOffset == 0) {
654 <<
" bestLaneOffsetOld=" << bestLaneOffset
655 <<
" bestLaneOffsetNew=" << laneOffset
658 bestLaneOffset = laneOffset;
660 best = preb[p + bestLaneOffset];
666 const bool right = (laneOffset == -1);
671 const bool changeToBest = (right && bestLaneOffset < 0) || (!right && bestLaneOffset > 0);
694 <<
" firstBlocked=" <<
tryID(*firstBlocked)
695 <<
" lastBlocked=" <<
tryID(*lastBlocked)
696 <<
" neighLead=" <<
tryID(neighLead.first)
697 <<
" neighLeadGap=" << neighLead.second
698 <<
" neighFollow=" <<
tryID(neighFollow.first)
699 <<
" neighFollowGap=" << neighFollow.second
705 if (lastBlocked != firstBlocked) {
744 int roundaboutEdgesAhead = 0;
746 if ((*it) != 0 && (*it)->getEdge().isRoundabout()) {
747 roundaboutEdgesAhead += 1;
748 }
else if (roundaboutEdgesAhead > 0) {
753 int roundaboutEdgesAheadNeigh = 0;
755 if ((*it) != 0 && (*it)->getEdge().isRoundabout()) {
756 roundaboutEdgesAheadNeigh += 1;
757 }
else if (roundaboutEdgesAheadNeigh > 0) {
762 if (roundaboutEdgesAhead > 1) {
766 if (roundaboutEdgesAhead > 0) {
768 std::cout <<
" roundaboutEdgesAhead=" << roundaboutEdgesAhead <<
" roundaboutEdgesAheadNeigh=" << roundaboutEdgesAheadNeigh <<
"\n";
774 const SUMOReal maxJam =
MAX2(preb[currIdx + laneOffset].occupation, preb[currIdx].occupation);
781 <<
" laDist=" << laDist
782 <<
" currentDist=" << currentDist
783 <<
" usableDist=" << usableDist
784 <<
" bestLaneOffset=" << bestLaneOffset
785 <<
" best.length=" << best.
length
786 <<
" maxJam=" << maxJam
787 <<
" neighLeftPlace=" << neighLeftPlace
809 <<
" avoid overtaking on the right nv=" << nv->
getID()
812 <<
" plannedSpeed=" <<
myVSafes.back()
826 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" could not change back and forth in time (1) neighLeftPlace=" << neighLeftPlace <<
"\n";
829 }
else if (bestLaneOffset == 0 && (neighLeftPlace * 2. < laDist)) {
835 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" could not change back and forth in time (2) neighLeftPlace=" << neighLeftPlace <<
"\n";
838 }
else if (bestLaneOffset == 0
839 && (leader.first == 0 || !leader.first->isStopped())
841 && roundaboutEdgesAhead == 0) {
847 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" does not want to leave the bestLane\n";
857 if ((ret & lcaCounter) != 0) {
862 std::cout <<
" retAfterInfluence=" << ret <<
"\n";
872 if (changeToBest &&
abs(bestLaneOffset) > 1) {
875 std::cout <<
" reserving space for unseen blockers\n";
883 if (*firstBlocked != neighLead.first) {
890 const SUMOReal plannedSpeed =
informLeader(msgPass, blocked, myLca, neighLead, remainingSeconds);
891 if (plannedSpeed >= 0) {
893 informFollower(msgPass, blocked, myLca, neighFollow, remainingSeconds, plannedSpeed);
900 <<
" remainingSeconds=" << remainingSeconds
901 <<
" plannedSpeed=" << plannedSpeed
908 if (roundaboutEdgesAhead > 1) {
923 std::cout <<
" veh=" <<
myVehicle.
getID() <<
" does not want to get stranded on the on-ramp of a highway\n";
945 <<
" wantsChangeToHelp=" << (right ?
"right" :
"left")
947 << (((
myOwnState & myLcaCounter) != 0) ?
" (counter)" :
"")
969 if (neighLead.first == 0) {
974 &
myVehicle,
myVehicle.
getSpeed(), neighLead.second, neighLead.first->getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel()));
976 if (leader.first == 0) {
986 const SUMOReal relativeGain = (neighLaneVSafe - thisLaneVSafe) / neighLaneVSafe;
989 if (thisLaneVSafe - 5 / 3.6 > neighLaneVSafe) {
1004 SUMOReal fullSpeedDrivingSeconds =
MIN2(acceptanceTime, fullSpeedGap / vMax);
1005 if (neighLead.first != 0 && neighLead.first->getSpeed() < vMax) {
1008 vMax, neighLead.first->getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel())));
1009 fullSpeedDrivingSeconds =
MIN2(fullSpeedDrivingSeconds, fullSpeedGap / (vMax - neighLead.first->getSpeed()));
1020 <<
" neighDist=" << neighDist
1022 <<
" leaderSpeed=" << (neighLead.first == 0 ? -1 : neighLead.first->getSpeed())
1024 myVehicle.
getSpeed(), neighLead.first->getSpeed(), neighLead.first->getCarFollowModel().getMaxDecel()))
1025 <<
" acceptanceTime=" << acceptanceTime
1026 <<
" fullSpeedGap=" << fullSpeedGap
1027 <<
" fullSpeedDrivingSeconds=" << fullSpeedDrivingSeconds
1028 <<
" dProb=" << deltaProb
1041 <<
" thisLaneVSafe=" << thisLaneVSafe
1042 <<
" neighLaneVSafe=" << neighLaneVSafe
1043 <<
" relativeGain=" << relativeGain
1044 <<
" blocked=" << blocked
1054 if (thisLaneVSafe > neighLaneVSafe) {
1078 && (right ? mySpeedGainProbability < 0 : mySpeedGainProbability > 0)) {
1087 <<
" thisLaneVSafe=" << thisLaneVSafe
1088 <<
" neighLaneVSafe=" << neighLaneVSafe
1098 if ((*blocked) != 0) {
1103 <<
" blocked=" <<
tryID(*blocked)
1122 (*blocked)->getCarFollowModel().getMaxDecel()));
1143 <<
" blocker=" <<
tryID(blocker)
1153 <<
" blocker=" <<
tryID(blocker)
void * inform(void *info, MSVehicle *sender)
#define LOOK_AHEAD_MIN_SPEED
bool gDebugFlag1
global utility flags for debugging
int _wantsChange(int laneOffset, MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, const std::pair< MSVehicle *, SUMOReal > &leader, const std::pair< MSVehicle *, SUMOReal > &neighLead, const std::pair< MSVehicle *, SUMOReal > &neighFollow, const MSLane &neighLane, const std::vector< MSVehicle::LaneQ > &preb, MSVehicle **lastBlocked, MSVehicle **firstBlocked)
helper function for doing the actual work
MSEdge & getEdge() const
Returns the lane's edge.
#define CHANGE_PROB_THRESHOLD_LEFT
Representation of a vehicle in the micro simulation.
SUMOReal getMaxSpeed() const
Get vehicle's maximum speed [m/s].
int slowDownForBlocked(MSVehicle **blocked, int state)
compute useful slowdowns for blocked vehicles
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
bool currentDistAllows(SUMOReal dist, int laneOffset, SUMOReal lookForwardDist)
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
The action is done to help someone else.
SUMOReal getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
int bestLaneOffset
The (signed) number of lanes to be crossed to get to the lane which allows to continue the drive...
virtual SUMOReal followSpeed(const MSVehicle *const veh, SUMOReal speed, SUMOReal gap2pred, SUMOReal predSpeed, SUMOReal predMaxDecel) const =0
Computes the vehicle's safe speed (no dawdling)
SUMOReal myLeadingBlockerLength
The car-following model abstraction.
void * informNeighFollower(void *info, MSVehicle *sender)
Informs the follower on the desired lane.
SUMOReal getLength() const
Get vehicle's length [m].
int wantsChange(int laneOffset, MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, const std::pair< MSVehicle *, SUMOReal > &leader, const std::pair< MSVehicle *, SUMOReal > &neighLead, const std::pair< MSVehicle *, SUMOReal > &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...
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
MSLCM_JE2013(MSVehicle &v)
std::vector< SUMOReal > myVSafes
SUMOReal getSecureGap(const SUMOReal speed, const SUMOReal leaderSpeed, const SUMOReal leaderMaxDecel) const
Returns the minimum gap to reserve if the leader is braking at maximum.
SUMOReal getPositionOnLane() const
Get the vehicle's position along the lane.
The action is due to a TraCI request.
SUMOTime getCurrentTimeStep() const
Returns the current simulation step.
SUMOReal length
The overall length which may be driven when using this lane without a lane change.
The action is urgent (to be defined by lc-model)
MSAbstractLaneChangeModel & getLaneChangeModel()
void informFollower(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, SUMOReal > &neighFollow, SUMOReal remainingSeconds, SUMOReal plannedSpeed)
decide whether we will try cut in before the follower or allow to be overtaken
#define LCA_RIGHT_IMPATIENCE
std::pair< SUMOReal, int > Info
information regarding save velocity (unused) and state flags of the ego vehicle
A class responsible for exchanging messages between cars involved in lane-change interaction.
const std::string & getID() const
Returns the id.
SUMOReal brakeGap(const SUMOReal speed) const
Returns the distance the vehicle needs to halt including driver's reaction time.
#define CUT_IN_LEFT_SPEED_THRESHOLD
SUMOReal mySpeedGainProbability
a value for tracking the probability that a change to the offset with the same sign is beneficial ...
SUMOReal getMinGap() const
Get the free space in front of vehicles of this class.
#define LOOK_FORWARD_RIGHT
bool amBlockingFollowerPlusNB()
SUMOReal informLeader(MSAbstractLaneChangeModel::MSLCMessager &msgPass, int blocked, int dir, const std::pair< MSVehicle *, SUMOReal > &neighLead, SUMOReal remainingSeconds)
SUMOReal _patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max, const MSCFModel &cfModel)
void saveBlockerLength(MSVehicle *blocker, int lcaCounter)
save space for vehicles which need to counter-lane-change
virtual SUMOReal stopSpeed(const MSVehicle *const veh, const SUMOReal speed, SUMOReal gap2pred) const =0
Computes the vehicle's safe speed for approaching a non-moving obstacle (no dawdling) ...
SUMOReal getSpeedLimit() const
Returns the lane's maximum allowed speed.
std::string tryID(const MSVehicle *v)
A structure representing the best lanes for continuing the route.
SUMOReal getMaxDecel() const
Get the vehicle type's maximum deceleration [m/s^2].
SUMOReal changeRequestRemainingSeconds(const SUMOTime currentTime) const
Return the remaining number of seconds of the current laneTimeLine assuming one exists.
int myOwnState
The current state of the vehicle.
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
virtual void saveBlockerLength(SUMOReal length)
reserve space at the end of the lane to avoid dead locks
#define HELP_DECEL_FACTOR
MSVehicle & myVehicle
The vehicle this lane-changer belongs to.
void * informNeighLeader(void *info, MSVehicle *sender)
Informs the leader on the desired lane.
The action is needed to follow the route (navigational lc)
EdgeBasicFunction getPurpose() const
Returns the edge type (EdgeBasicFunction)
Influencer & getInfluencer()
Returns the velocity/lane influencer.
SUMOReal myKeepRightProbability
#define LOOK_AHEAD_SPEED_MEMORY
SUMOTime myLastLaneChangeOffset
information how long ago the vehicle has performed a lane-change
#define ROUNDABOUT_DIST_BONUS
SUMOReal occupation
The overall vehicle sum on consecutive lanes which can be passed without a lane change.
#define CHANGE_PROB_THRESHOLD_RIGHT
std::vector< MSLane * > bestContinuations
Consecutive lane that can be followed without a lane change (contribute to length and occupation) ...
SUMOReal myLookAheadSpeed
The action is due to the default of keeping right "Rechtsfahrgebot".
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
const SUMOReal SUMO_const_haltingSpeed
the speed threshold at which vehicles are considered as halting
Needs to stay on the current lane.
SUMOReal getSpeed() const
Returns the vehicle's current speed.
SUMOReal getWaitingSeconds() const
Returns the number of seconds waited (speed was lesser than 0.1m/s)
#define KEEP_RIGHT_ACCEPTANCE
#define OVERTAKE_RIGHT_FORBIDDEN
#define LOOK_FORWARD_LEFT
const MSLinkCont & getLinkCont() const
returns the container with all links !!!
SUMOReal getVehicleMaxSpeed(const SUMOVehicle *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
MSLane * getLane() const
Returns the lane the vehicle is on.
int influenceChangeDecision(int state)
allow TraCI to influence a lane change decision
The edge is an internal edge.
Representation of a lane in the micro simulation.
const MSCFModel & myCarFollowModel
The vehicle's car following model.
bool currentDistDisallows(SUMOReal dist, int laneOffset, SUMOReal lookForwardDist)
Interface for lane-change models.
int getBestLaneOffset() const
returns the current offset from the best lane
SUMOReal patchSpeed(const SUMOReal min, const SUMOReal wanted, const SUMOReal max, const MSCFModel &cfModel)
Called to adapt the speed in order to allow a lane change.
const std::string & getID() const
Returns the name of the vehicle.
The action is due to the wish to be faster (tactical lc)