35#define DEBUG_COND (veh.isSelected())
53#ifdef DEBUG_WANTS_CHANGE
56 std::cout <<
SIMTIME <<
" veh=" << veh.
getID() <<
" getRoundaboutDistBonus bonusParam=" << bonusParam
71 int roundaboutJunctionsAhead = 0;
72 bool enteredRoundabout =
false;
78 if (lane ==
nullptr) {
83#ifdef DEBUG_WANTS_CHANGE
85 std::cout <<
" noBonus: inner does not continue (lane=" << lane->
getID() <<
")\n";
92#ifdef DEBUG_WANTS_CHANGE
94 std::cout <<
" noBonus: seen=" << seen <<
" (lane=" << lane->
getID() <<
")\n";
101 enteredRoundabout =
true;
103 roundaboutJunctionsAhead++;
105 }
else if (enteredRoundabout) {
112 if (roundaboutJunctionsAhead < 2) {
113#ifdef DEBUG_WANTS_CHANGE
115 std::cout <<
" noBonus: roundaboutJunctionsAhead=" << roundaboutJunctionsAhead <<
"\n";
122 double occupancyOuter = 0;
123 double occupancyInner = 0;
124 double distanceInRoundabout = 0;
125 MSLane* prevNormal =
nullptr;
126 MSLane* prevInner =
nullptr;
127 enteredRoundabout =
false;
130 if (lane ==
nullptr) {
134 enteredRoundabout =
true;
135 }
else if (enteredRoundabout) {
140 if (prevNormal !=
nullptr) {
142 if (link->getLane() == lane) {
143 via = link->getViaLane();
147 if (enteredRoundabout) {
148 distanceInRoundabout += lane->
getLength();
149 if (via !=
nullptr) {
150 distanceInRoundabout += via->
getLength();
158#ifdef DEBUG_WANTS_CHANGE
160 std::cout <<
" lane=" << lane->
getID() <<
" occ=" << lane->
getBruttoVehLenSum() <<
" discount=" << upstreamDiscount <<
" outer=" << occupancyOuter <<
"\n";
163 if (via !=
nullptr) {
165#ifdef DEBUG_WANTS_CHANGE
167 std::cout <<
" via=" << via->
getID() <<
" occ=" << via->
getBruttoVehLenSum() <<
" outer=" << occupancyOuter <<
"\n";
174#ifdef DEBUG_WANTS_CHANGE
176 std::cout <<
" inner=" << innerLane->
getID() <<
" occ=" << innerLane->
getBruttoVehLenSum() <<
" discount=" << upstreamDiscount <<
" inner=" << occupancyInner <<
"\n";
179 if (prevInner !=
nullptr) {
181 if (link->getLane() == innerLane && link->getViaLane() !=
nullptr) {
182 occupancyInner += link->getViaLane()->getBruttoVehLenSum();
183#ifdef DEBUG_WANTS_CHANGE
185 std::cout <<
" innerVia=" << link->getViaLane()->getID() <<
" occ=" << link->getViaLane()->getBruttoVehLenSum() <<
" inner=" << occupancyInner <<
"\n";
191 prevInner = innerLane;
195#ifdef DEBUG_WANTS_CHANGE
197 std::cout <<
" distanceInRoundabout=" << distanceInRoundabout
198 <<
" roundaboutJunctionsAhead=" << roundaboutJunctionsAhead
199 <<
" occupancyInner=" << occupancyInner
200 <<
" occupancyOuter=" << occupancyOuter
207 const double leftSpace = distanceInRoundabout - reservation - veh.
getPositionOnLane();
208#ifdef DEBUG_WANTS_CHANGE
210 std::cout <<
" bGap=" << bGap <<
" reserving=" << reservation <<
" leftover=" << (leftSpace - bGap) <<
"\n";
213 if (bGap > leftSpace) {
218 const double maxOccupancy =
MAX2(occupancyInner, occupancyOuter);
220 const double bonus = roundaboutJunctionsAhead * 7.5;
221 const double relativeJam = (occupancyOuter - occupancyInner + bonus) / (maxOccupancy + bonus);
223 double jamFactor =
MAX2(0.0, relativeJam);
229 const double result = distanceInRoundabout * jamFactor * bonusParam * 9;
230#ifdef DEBUG_WANTS_CHANGE
232 std::cout <<
" relativeJam=" << relativeJam
233 <<
" jamFactor=" << jamFactor
234 <<
" distanceBonus=" << result
244#ifdef DEBUG_SAVE_BLOCKER_LENGTH
247 <<
" veh=" << veh.
getID()
258 if (required <= potential) {
260 leadingBlockerLength =
MAX2(required, leadingBlockerLength);
261#ifdef DEBUG_SAVE_BLOCKER_LENGTH
264 <<
" veh=" << veh.
getID()
265 <<
" required=" << required
266 <<
" potential=" << potential
268 <<
" saving myLeadingBlockerLength=" << leadingBlockerLength
279#ifdef DEBUG_SAVE_BLOCKER_LENGTH
282 <<
" veh=" << veh.
getID()
283 <<
" required=" << required
284 <<
" potential=" << potential
286 <<
" required2=" << required2
287 <<
" foeCanReserve=" << canReserve
288 <<
" myReserved=" << leadingBlockerLength
289 <<
" reliefConnection=" << reliefConnection
293 if (!canReserve && !reliefConnection) {
298 leadingBlockerLength =
MAX2(required, leadingBlockerLength);
299#ifdef DEBUG_SAVE_BLOCKER_LENGTH
301 std::cout <<
" reserving anyway to avoid deadlock (will cause emergency braking)\n";
316#ifdef DEBUG_SAVE_BLOCKER_LENGTH
318 std::cout <<
SIMTIME <<
" canSaveBlockerLength veh=" << veh.
getID() <<
" requested=" << requested <<
" leftSpace=" << leftSpace <<
" potential=" << potential <<
"\n";
321 return potential >= requested;
339 const double nextGap = currentGap +
SPEED2DIST(leaderPlannedSpeed - follower.
getSpeed());
341 if (nextGap >= sGap) {
359 if (leader ==
nullptr) {
364 if (lane1 ==
nullptr && lane2 ==
nullptr) {
367 bool result = std::find(cont.begin(), cont.end(), lane1) != cont.end();
368 if (!result && lane1 != lane2 && lane2 !=
nullptr) {
369 result = std::find(cont.begin(), cont.end(), lane2) != cont.end();
377 if (follower ==
nullptr) {
384 if (lane1 !=
nullptr) {
385 result = std::find(route.begin(), route.end(), &lane1->
getEdge()) != route.end();
387 if (!result && lane1 != lane2 && lane2 !=
nullptr) {
388 result = std::find(route.begin(), route.end(), &lane2->
getEdge()) != route.end();
400#ifdef DEBUG_UNWILLING_TO_HELP
402 std::cout <<
"\n nv=" << nv.
getID() <<
" not willing to help because ego is much slower\n";
410#ifdef DEBUG_UNWILLING_TO_HELP
412 std::cout <<
"\n nv=" << nv.
getID() <<
" not willing to help because it is already too slow\n";
std::vector< const MSEdge * > ConstMSEdgeVector
LaneChangeAction
The state of a vehicle's lane-change behavior.
@ LCA_URGENT
The action is urgent (to be defined by lc-model)
@ LCA_STRATEGIC
The action is needed to follow the route (navigational lc)
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
virtual double getExtraReservation(int bestLaneOffset, double neighExtraDist=0) const
double getCooperativeHelpThreshold() const
double getCooperativeMinSpeed() const
SUMOTime getCooperativeHelpTime() const
virtual bool saveBlockerLength(double, double)
reserve space at the end of the lane to avoid dead locks
virtual bool debugVehicle() const
whether the current vehicles shall be debugged
const MSRoute & getRoute() const
Returns the current route.
const MSVehicleType & getVehicleType() const
Returns the vehicle's type definition.
virtual double maxNextSpeed(double speed, const MSVehicle *const veh) const
Returns the maximum speed given the current speed.
virtual double minNextSpeed(double speed, const MSVehicle *const veh=0) const
Returns the minimum speed given the current speed (depends on the numerical update scheme and its ste...
virtual double getSecureGap(const MSVehicle *const veh, const MSVehicle *const, const double speed, const double leaderSpeed, const double leaderMaxDecel) const
Returns the minimum gap to reserve if the leader is braking at maximum (>=0)
double getMaxAccel() const
Get the vehicle type's maximum acceleration [m/s^2].
double brakeGap(const double speed) const
Returns the distance the vehicle needs to halt including driver's reaction time tau (i....
double getMaxDecel() const
Get the vehicle type's maximal comfortable deceleration [m/s^2].
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)
const MSJunction * getToJunction() const
const MSJunction * getFromJunction() const
bool isRoundabout() const
The base class for an intersection.
const ConstMSEdgeVector & getOutgoing() const
const ConstMSEdgeVector & getIncoming() const
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
Representation of a lane in the micro simulation.
const MSLane * getNormalSuccessorLane() const
get normal lane following this internal lane, for normal lanes, the lane itself is returned
double getBruttoVehLenSum() const
Returns the sum of lengths of vehicles, including their minGaps, which were on the lane during the la...
double getLength() const
Returns the lane's length.
double getVehicleMaxSpeed(const SUMOTrafficObject *const veh) const
Returns the lane's maximum speed, given a vehicle's speed limit adaptation.
int getIndex() const
Returns the lane's index.
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 !!!
const ConstMSEdgeVector & getEdges() const
Representation of a vehicle in the micro simulation.
SUMOTime getWaitingTime(const bool accumulated=false) const
Returns the SUMOTime waited (speed was lesser than 0.1m/s)
MSAbstractLaneChangeModel & getLaneChangeModel()
double getActionStepLengthSecs() const
Returns the vehicle's action step length in secs, i.e. the interval between two action points.
const MSLane * getLane() const
Returns the lane the vehicle is on.
double getSpeed() const
Returns the vehicle's current speed.
const MSCFModel & getCarFollowModel() const
Returns the vehicle's car following model definition.
double getPositionOnLane() const
Get the vehicle's position along the lane.
double getLengthWithGap() const
Get vehicle's length including the minimum gap [m].
double getMinGap() const
Get the free space in front of vehicles of this class.
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.
A structure representing the best lanes for continuing the current route starting at 'lane'.
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.