Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored function AdaptToJunctionLeader #11583

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 45 additions & 19 deletions src/microsim/MSVehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2982,28 +2982,12 @@ MSVehicle::adaptToJunctionLeader(const std::pair<const MSVehicle*, double> leade
if (!MSGlobals::gSemiImplicitEulerUpdate) {
vsafeLeader = -std::numeric_limits<double>::max();
}
if (leaderInfo.second >= 0) {
vsafeLeader = cfModel.followSpeed(this, getSpeed(), leaderInfo.second, leaderInfo.first->getSpeed(), leaderInfo.first->getCurrentApparentDecel(), leaderInfo.first);
} else {
// the leading, in-lapping vehicle is occupying the complete next lane
// stop before entering this lane
vsafeLeader = cfModel.stopSpeed(this, getSpeed(), seen - lane->getLength() - POSITION_EPS);
#ifdef DEBUG_PLAN_MOVE_LEADERINFO
if (DEBUG_COND) {
std::cout << SIMTIME << " veh=" << getID() << " stopping before junction: lane=" << lane->getID() << " seen=" << seen
<< " laneLength=" << lane->getLength()
<< " stopDist=" << seen - lane->getLength() - POSITION_EPS
<< " vsafeLeader=" << vsafeLeader
<< " distToCrossing=" << distToCrossing
<< "\n";
}
#endif
}
if (distToCrossing >= 0) {
// can the leader still stop in the way?
const double vStop = cfModel.stopSpeed(this, getSpeed(), distToCrossing - getVehicleType().getMinGap());
double vStop = 0;
if (leaderInfo.first == this) {
// braking for pedestrian
vStop = cfModel.stopSpeed(this, getSpeed(), distToCrossing - getVehicleType().getMinGap());
vsafeLeader = vStop;
#ifdef DEBUG_PLAN_MOVE_LEADERINFO
if (DEBUG_COND) {
Expand All @@ -3017,7 +3001,12 @@ MSVehicle::adaptToJunctionLeader(const std::pair<const MSVehicle*, double> leade
std::cout << " stop at crossing point for critical leader\n";
};
#endif
vsafeLeader = MAX2(vsafeLeader, vStop);
// The if-else-clause should be the same as "vsafeLeader = MAX2(vsafeLeader, vStop);"
if (seen - lane->getLength() - POSITION_EPS >= distToCrossing - getVehicleType().getMinGap()) {
vsafeLeader = cfModel.stopSpeed(this, getSpeed(), seen - lane->getLength() - POSITION_EPS);
} else {
vsafeLeader = cfModel.stopSpeed(this, getSpeed(), distToCrossing - getVehicleType().getMinGap());
}
} else {
const double leaderDistToCrossing = distToCrossing - leaderInfo.second;
// estimate the time at which the leader has gone past the crossing point
Expand All @@ -3027,6 +3016,24 @@ MSVehicle::adaptToJunctionLeader(const std::pair<const MSVehicle*, double> leade
// ballistic: avgSpeed = (getSpeed + vFinal) / 2
const double vFinal = MAX2(getSpeed(), 2 * (distToCrossing - getVehicleType().getMinGap()) / leaderPastCPTime - getSpeed());
const double v2 = getSpeed() + ACCEL2SPEED((vFinal - getSpeed()) / leaderPastCPTime);
if (leaderInfo.second >= 0) {
vsafeLeader = cfModel.followSpeed(this, getSpeed(), leaderInfo.second, leaderInfo.first->getSpeed(), leaderInfo.first->getCurrentApparentDecel(), leaderInfo.first);
} else {
// the leading, in-lapping vehicle is occupying the complete next lane
// stop before entering this lane
vsafeLeader = cfModel.stopSpeed(this, getSpeed(), seen - lane->getLength() - POSITION_EPS, MSCFModel::CalcReason::CURRENT_WAIT);
#ifdef DEBUG_PLAN_MOVE_LEADERINFO
if (DEBUG_COND) {
std::cout << SIMTIME << " veh=" << getID() << " stopping before junction: lane=" << lane->getID() << " seen=" << seen
<< " laneLength=" << lane->getLength()
<< " stopDist=" << seen - lane->getLength() - POSITION_EPS
<< " vsafeLeader=" << vsafeLeader
<< " distToCrossing=" << distToCrossing
<< "\n";
}
#endif
}
vStop = cfModel.stopSpeed(this, getSpeed(), distToCrossing - getVehicleType().getMinGap(), MSCFModel::CalcReason::CURRENT_WAIT);
vsafeLeader = MAX2(vsafeLeader, MIN2(v2, vStop));
#ifdef DEBUG_PLAN_MOVE_LEADERINFO
if (DEBUG_COND) {
Expand All @@ -3037,6 +3044,25 @@ MSVehicle::adaptToJunctionLeader(const std::pair<const MSVehicle*, double> leade
<< " vStop=" << vStop
<< " vsafeLeader=" << vsafeLeader << "\n";
}
#endif
}
} else {
if (leaderInfo.second >= 0) {
// if "leaderInfo.first == this" is true, "leaderInfo.second < 0" is also true
vsafeLeader = cfModel.followSpeed(this, getSpeed(), leaderInfo.second, leaderInfo.first->getSpeed(), leaderInfo.first->getCurrentApparentDecel(), leaderInfo.first);
} else {
// the leading, in-lapping vehicle is occupying the complete next lane
// stop before entering this lane
vsafeLeader = cfModel.stopSpeed(this, getSpeed(), seen - lane->getLength() - POSITION_EPS);
#ifdef DEBUG_PLAN_MOVE_LEADERINFO
if (DEBUG_COND) {
std::cout << SIMTIME << " veh=" << getID() << " stopping before junction: lane=" << lane->getID() << " seen=" << seen
<< " laneLength=" << lane->getLength()
<< " stopDist=" << seen - lane->getLength() - POSITION_EPS
<< " vsafeLeader=" << vsafeLeader
<< " distToCrossing=" << distToCrossing
<< "\n";
}
#endif
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/sumo/cf_model/EIDM/ticket11165/tripinfos.sumo
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 2022-09-09 15:04:18 by Eclipse SUMO sumo Version v1_14_1+0800-6c6ff67716b
<!-- generated on 2022-09-13 08:39:48 by Eclipse SUMO sumo Version v1_14_1+0979-0e6273e9f71
This data file and the accompanying materials
are made available under the terms of the Eclipse Public License v2.0
which accompanies this distribution, and is available at
Expand Down Expand Up @@ -44,5 +44,5 @@ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
-->

<tripinfos xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/tripinfo_file.xsd">
<tripinfo id="0" depart="0.00" departLane="SC_0" departPos="5.10" departSpeed="13.89" departDelay="0.00" arrival="1352.50" arrivalLane="CS_0" arrivalPos="89.60" arrivalSpeed="7.26" duration="1352.50" routeLength="4347.55" waitingTime="443.10" waitingCount="15" stopTime="0.00" timeLoss="1039.46" rerouteNo="0" devices="tripinfo_0" vType="default" speedFactor="1.00" vaporized=""/>
<tripinfo id="0" depart="0.00" departLane="SC_0" departPos="5.10" departSpeed="13.89" departDelay="0.00" arrival="1352.30" arrivalLane="CS_0" arrivalPos="89.60" arrivalSpeed="7.07" duration="1352.30" routeLength="4347.55" waitingTime="444.40" waitingCount="12" stopTime="0.00" timeLoss="1039.28" rerouteNo="0" devices="tripinfo_0" vType="default" speedFactor="1.00" vaporized=""/>
</tripinfos>