34#define DEBUG_COND (veh.isSelected())
52#ifdef DEBUG_WANTS_CHANGE
55 std::cout <<
SIMTIME <<
" veh=" << veh.
getID() <<
" getRoundaboutDistBonus bonusParam=" << bonusParam
70 int roundaboutJunctionsAhead = 0;
71 bool enteredRoundabout =
false;
77 if (lane ==
nullptr) {
82#ifdef DEBUG_WANTS_CHANGE
84 std::cout <<
" noBonus: inner does not continue (lane=" << lane->
getID() <<
")\n";
91#ifdef DEBUG_WANTS_CHANGE
93 std::cout <<
" noBonus: seen=" << seen <<
" (lane=" << lane->
getID() <<
")\n";
100 enteredRoundabout =
true;
102 roundaboutJunctionsAhead++;
104 }
else if (enteredRoundabout) {
111 if (roundaboutJunctionsAhead < 2) {
117 double occupancyOuter = 0;
118 double occupancyInner = 0;
119 double distanceInRoundabout = 0;
120 MSLane* prevNormal =
nullptr;
121 MSLane* prevInner =
nullptr;
122 enteredRoundabout =
false;
125 if (lane ==
nullptr) {
129 enteredRoundabout =
true;
130 }
else if (enteredRoundabout) {
135 if (prevNormal !=
nullptr) {
137 if (link->getLane() == lane) {
138 via = link->getViaLane();
142 if (enteredRoundabout) {
143 distanceInRoundabout += lane->
getLength();
144 if (via !=
nullptr) {
145 distanceInRoundabout += via->
getLength();
153#ifdef DEBUG_WANTS_CHANGE
155 std::cout <<
" lane=" << lane->
getID() <<
" occ=" << lane->
getBruttoVehLenSum() <<
" discount=" << upstreamDiscount <<
" outer=" << occupancyOuter <<
"\n";
158 if (via !=
nullptr) {
160#ifdef DEBUG_WANTS_CHANGE
162 std::cout <<
" via=" << via->
getID() <<
" occ=" << via->
getBruttoVehLenSum() <<
" outer=" << occupancyOuter <<
"\n";
169#ifdef DEBUG_WANTS_CHANGE
171 std::cout <<
" inner=" << innerLane->
getID() <<
" occ=" << innerLane->
getBruttoVehLenSum() <<
" discount=" << upstreamDiscount <<
" inner=" << occupancyInner <<
"\n";
174 if (prevInner !=
nullptr) {
176 if (link->getLane() == innerLane && link->getViaLane() !=
nullptr) {
177 occupancyInner += link->getViaLane()->getBruttoVehLenSum();
178#ifdef DEBUG_WANTS_CHANGE
180 std::cout <<
" innerVia=" << link->getViaLane()->getID() <<
" occ=" << link->getViaLane()->getBruttoVehLenSum() <<
" inner=" << occupancyInner <<
"\n";
186 prevInner = innerLane;
190#ifdef DEBUG_WANTS_CHANGE
192 std::cout <<
" distanceInRoundabout=" << distanceInRoundabout
193 <<
" roundaboutJunctionsAhead=" << roundaboutJunctionsAhead
194 <<
" occupancyInner=" << occupancyInner
195 <<
" occupancyOuter=" << occupancyOuter
200 const double maxOccupancy =
MAX2(occupancyInner, occupancyOuter);
201 if (maxOccupancy == 0) {
206 const double bonus = roundaboutJunctionsAhead * 7.5;
207 const double relativeJam = (occupancyOuter - occupancyInner + bonus) / (maxOccupancy + bonus);
209 double jamFactor =
MAX2(0.0, relativeJam);
215 const double result = distanceInRoundabout * jamFactor * bonusParam * 9;
216#ifdef DEBUG_WANTS_CHANGE
218 std::cout <<
" relativeJam=" << relativeJam
219 <<
" jamFactor=" << jamFactor
220 <<
" distanceBonus=" << result
230#ifdef DEBUG_SAVE_BLOCKER_LENGTH
233 <<
" veh=" << veh.
getID()
246#ifdef DEBUG_SAVE_BLOCKER_LENGTH
249 <<
" veh=" << veh.
getID()
251 <<
" saving myLeadingBlockerLength=" << leadingBlockerLength
260#ifdef DEBUG_SAVE_BLOCKER_LENGTH
263 <<
" veh=" << veh.
getID()
266 <<
" potential=" << potential
267 <<
" myReserved=" << leadingBlockerLength
268 <<
" canReserve=" << canReserve
269 <<
" reliefConnection=" << reliefConnection
273 if (!canReserve && !reliefConnection) {
279#ifdef DEBUG_SAVE_BLOCKER_LENGTH
281 std::cout <<
" reserving anyway to avoid deadlock (will cause emergency braking)\n";
296#ifdef DEBUG_SAVE_BLOCKER_LENGTH
298 std::cout <<
SIMTIME <<
" canSaveBlockerLength veh=" << veh.
getID() <<
" requested=" << requested <<
" leftSpace=" << leftSpace <<
" potential=" << potential <<
"\n";
301 return potential >= requested;
319 const double nextGap = currentGap +
SPEED2DIST(leaderPlannedSpeed - follower.
getSpeed());
321 if (nextGap >= sGap) {
339 if (leader ==
nullptr) {
344 if (lane1 ==
nullptr && lane2 ==
nullptr) {
347 bool result = std::find(cont.begin(), cont.end(), lane1) != cont.end();
348 if (!result && lane1 != lane2 && lane2 !=
nullptr) {
349 result = std::find(cont.begin(), cont.end(), lane2) != cont.end();
357 if (follower ==
nullptr) {
364 if (lane1 !=
nullptr) {
365 result = std::find(route.begin(), route.end(), &lane1->
getEdge()) != route.end();
367 if (!result && lane1 != lane2 && lane2 !=
nullptr) {
368 result = std::find(route.begin(), route.end(), &lane2->
getEdge()) != route.end();
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 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 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 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.
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.
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].
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.