Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ If the vehicle leaves the detector because it arrived, changed lanes or
teleported a leave event without occupancy is generated.

!!! note
The timing values are of sub-step resolution, computed by interpolating from the last two simulation steps. This interpolation takes into account **--step-method**.
For longitudinal movement, the detector interpolates entry and exit times within the simulation step using **--step-method**. A `stay` timestamp marks the end of the movement step.

## Visualization

Expand Down
34 changes: 20 additions & 14 deletions src/microsim/output/MSInstantInductLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,14 @@ MSInstantInductLoop::notifyEnter(SUMOTrafficObject& veh, Notification reason, co
return false;
}
if (veh.getPositionOnLane() >= myPosition) {
double entryTime = SIMTIME;
// Lane changes occur after the longitudinal movement of the step.
const double entryTime = reason == NOTIFICATION_LANE_CHANGE ? STEPS2TIME(SIMSTEP + DELTA_T) : SIMTIME;
if (myLastExitTime >= 0) {
write("enter", entryTime, veh, veh.getSpeed(), "gap", entryTime - myLastExitTime);
} else {
write("enter", entryTime, veh, veh.getSpeed());
}
myEntryTimes[&veh] = entryTime;
myDetections[&veh] = {entryTime, entryTime};
}
}
return true;
Expand All @@ -108,31 +109,35 @@ MSInstantInductLoop::notifyMove(SUMOTrafficObject& veh, double oldPos,

if (newPos >= myPosition && oldPos < myPosition/* && static_cast<MSVehicle&>(veh).getLane() == myLane*/) {
const double timeBeforeEnter = MSCFModel::passingTime(oldPos, myPosition, newPos, oldSpeed, newSpeed);
const double entryTime = SIMTIME - TS + timeBeforeEnter;
const double entryTime = SIMTIME + timeBeforeEnter;
enterSpeed = MSCFModel::speedAfterTime(timeBeforeEnter, oldSpeed, newPos - oldPos);
if (myLastExitTime >= 0) {
write("enter", entryTime, veh, enterSpeed, "gap", entryTime - myLastExitTime);
} else {
write("enter", entryTime, veh, enterSpeed);
}
myEntryTimes[&veh] = entryTime;
myDetections[&veh] = {entryTime, entryTime};
}
const double newBackPos = newPos - veh.getVehicleType().getLength();
const double oldBackPos = oldPos - veh.getVehicleType().getLength();
const auto detection = myDetections.find(&veh);
if (newBackPos > myPosition) {
std::map<SUMOTrafficObject*, double>::iterator i = myEntryTimes.find(&veh);
if (i != myEntryTimes.end()) {
if (detection != myDetections.end()) {
// vehicle passed the detector
const double timeBeforeLeave = MSCFModel::passingTime(oldBackPos, myPosition, newBackPos, oldSpeed, newSpeed);
const double leaveTime = SIMTIME - TS + timeBeforeLeave;
write("leave", leaveTime, veh, newSpeed, "occupancy", leaveTime - (*i).second);
myEntryTimes.erase(i);
const double leaveTime = SIMTIME + timeBeforeLeave;
write("leave", leaveTime, veh, newSpeed, "occupancy", leaveTime - detection->second.entryTime);
myDetections.erase(detection);
myLastExitTime = leaveTime;
}
return false;
}
// vehicle stays on the detector
write("stay", SIMTIME, veh, newSpeed);
const double stepEnd = STEPS2TIME(SIMSTEP + DELTA_T);
write("stay", stepEnd, veh, newSpeed);
if (detection != myDetections.end()) {
detection->second.lastTime = stepEnd;
}
return true;
}

Expand Down Expand Up @@ -177,10 +182,11 @@ MSInstantInductLoop::notifyLeave(SUMOTrafficObject& veh, double /* lastPos */, M
#ifdef HAVE_FOX
ScopedLocker<> lock(myNotificationMutex, MSGlobals::gNumSimThreads > 1);
#endif
std::map<SUMOTrafficObject*, double>::iterator i = myEntryTimes.find(&veh);
if (i != myEntryTimes.end()) {
write("leave", SIMTIME, veh, veh.getSpeed());
myEntryTimes.erase(i);
const auto detection = myDetections.find(&veh);
if (detection != myDetections.end()) {
// Removal may follow the movement of this step, for example during a lane change.
write("leave", MAX2(SIMTIME, detection->second.lastTime), veh, veh.getSpeed());
myDetections.erase(detection);
}
return false;
}
Expand Down
9 changes: 7 additions & 2 deletions src/microsim/output/MSInstantInductLoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,13 @@ class MSInstantInductLoop
/// @brief The last exit time
double myLastExitTime;

/// @brief The last exit time
std::map<SUMOTrafficObject*, double> myEntryTimes;
struct Detection {
double entryTime;
double lastTime;
};

/// @brief Entry and latest observation time for vehicles still on the detector.
std::map<SUMOTrafficObject*, Detection> myDetections;

/// @brief an event of this step, written in detectorUpdate
struct Event {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ SPDX-License-Identifier: EPL-2.0
-->

<instantE1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/instant_e1_file.xsd">
<instantOut id="end3" time="4.86" state="enter" vehID="leader" speed="36.00" length="5.00" type="leader"/>
<instantOut id="end3" time="4.90" state="stay" vehID="leader" speed="36.00" length="5.00" type="leader"/>
<instantOut id="end3" time="5.00" state="leave" vehID="leader" speed="36.00" length="5.00" type="leader" occupancy="0.14"/>
<instantOut id="end3" time="6.44" state="enter" vehID="follower" speed="34.04" length="5.00" type="follower" gap="1.44"/>
<instantOut id="end3" time="6.50" state="stay" vehID="follower" speed="34.20" length="5.00" type="follower"/>
<instantOut id="end3" time="6.58" state="leave" vehID="follower" speed="34.46" length="5.00" type="follower" occupancy="0.15"/>
<instantOut id="end3" time="4.96" state="enter" vehID="leader" speed="36.00" length="5.00" type="leader"/>
<instantOut id="end3" time="5.00" state="stay" vehID="leader" speed="36.00" length="5.00" type="leader"/>
<instantOut id="end3" time="5.10" state="leave" vehID="leader" speed="36.00" length="5.00" type="leader" occupancy="0.14"/>
<instantOut id="end3" time="6.54" state="enter" vehID="follower" speed="34.04" length="5.00" type="follower" gap="1.44"/>
<instantOut id="end3" time="6.60" state="stay" vehID="follower" speed="34.20" length="5.00" type="follower"/>
<instantOut id="end3" time="6.68" state="leave" vehID="follower" speed="34.46" length="5.00" type="follower" occupancy="0.15"/>
</instantE1>
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ SPDX-License-Identifier: EPL-2.0
-->

<instantE1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/instant_e1_file.xsd">
<instantOut id="end3" time="4.86" state="enter" vehID="leader" speed="36.00" length="5.00" type="leader"/>
<instantOut id="end3" time="4.90" state="stay" vehID="leader" speed="36.00" length="5.00" type="leader"/>
<instantOut id="end3" time="5.00" state="leave" vehID="leader" speed="36.00" length="5.00" type="leader" occupancy="0.14"/>
<instantOut id="end3" time="6.55" state="enter" vehID="follower" speed="38.45" length="5.00" type="follower" gap="1.56"/>
<instantOut id="end3" time="6.60" state="stay" vehID="follower" speed="38.57" length="5.00" type="follower"/>
<instantOut id="end3" time="6.68" state="leave" vehID="follower" speed="38.83" length="5.00" type="follower" occupancy="0.13"/>
<instantOut id="end3" time="4.96" state="enter" vehID="leader" speed="36.00" length="5.00" type="leader"/>
<instantOut id="end3" time="5.00" state="stay" vehID="leader" speed="36.00" length="5.00" type="leader"/>
<instantOut id="end3" time="5.10" state="leave" vehID="leader" speed="36.00" length="5.00" type="leader" occupancy="0.14"/>
<instantOut id="end3" time="6.65" state="enter" vehID="follower" speed="38.45" length="5.00" type="follower" gap="1.56"/>
<instantOut id="end3" time="6.70" state="stay" vehID="follower" speed="38.57" length="5.00" type="follower"/>
<instantOut id="end3" time="6.78" state="leave" vehID="follower" speed="38.83" length="5.00" type="follower" occupancy="0.13"/>
</instantE1>
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ SPDX-License-Identifier: EPL-2.0
-->

<instantE1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/instant_e1_file.xsd">
<instantOut id="beg_end" time="23.60" state="enter" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.60" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.70" state="enter" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.70" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.80" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.84" state="leave" vehID="leader" speed="20.00" length="5.00" type="leader" occupancy="0.25"/>
<instantOut id="beg_end" time="24.88" state="enter" vehID="follower" speed="20.14" length="5.00" type="follower" gap="1.03"/>
<instantOut id="beg_end" time="24.90" state="stay" vehID="follower" speed="20.14" length="5.00" type="follower"/>
<instantOut id="beg_end" time="23.90" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.95" state="leave" vehID="leader" speed="20.00" length="5.00" type="leader" occupancy="0.25"/>
<instantOut id="beg_end" time="24.98" state="enter" vehID="follower" speed="20.14" length="5.00" type="follower" gap="1.03"/>
<instantOut id="beg_end" time="25.00" state="stay" vehID="follower" speed="20.14" length="5.00" type="follower"/>
<instantOut id="beg_end" time="25.10" state="stay" vehID="follower" speed="20.14" length="5.00" type="follower"/>
<instantOut id="beg_end" time="25.12" state="leave" vehID="follower" speed="20.13" length="5.00" type="follower" occupancy="0.25"/>
<instantOut id="beg_end" time="25.20" state="stay" vehID="follower" speed="20.14" length="5.00" type="follower"/>
<instantOut id="beg_end" time="25.22" state="leave" vehID="follower" speed="20.13" length="5.00" type="follower" occupancy="0.25"/>
</instantE1>
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ SPDX-License-Identifier: EPL-2.0
-->

<instantE1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/instant_e1_file.xsd">
<instantOut id="beg_end" time="23.61" state="enter" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.70" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.71" state="enter" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.80" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.86" state="leave" vehID="leader" speed="20.00" length="5.00" type="leader" occupancy="0.25"/>
<instantOut id="beg_end" time="24.42" state="enter" vehID="follower" speed="20.48" length="5.00" type="follower" gap="0.57"/>
<instantOut id="beg_end" time="24.50" state="stay" vehID="follower" speed="20.30" length="5.00" type="follower"/>
<instantOut id="beg_end" time="24.60" state="stay" vehID="follower" speed="20.07" length="5.00" type="follower"/>
<instantOut id="beg_end" time="24.67" state="leave" vehID="follower" speed="19.83" length="5.00" type="follower" occupancy="0.25"/>
<instantOut id="beg_end" time="23.90" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.96" state="leave" vehID="leader" speed="20.00" length="5.00" type="leader" occupancy="0.25"/>
<instantOut id="beg_end" time="24.52" state="enter" vehID="follower" speed="20.48" length="5.00" type="follower" gap="0.57"/>
<instantOut id="beg_end" time="24.60" state="stay" vehID="follower" speed="20.30" length="5.00" type="follower"/>
<instantOut id="beg_end" time="24.70" state="stay" vehID="follower" speed="20.07" length="5.00" type="follower"/>
<instantOut id="beg_end" time="24.77" state="leave" vehID="follower" speed="19.83" length="5.00" type="follower" occupancy="0.25"/>
</instantE1>
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ SPDX-License-Identifier: EPL-2.0
-->

<instantE1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/instant_e1_file.xsd">
<instantOut id="beg_end" time="23.61" state="enter" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.70" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.71" state="enter" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.80" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.86" state="leave" vehID="leader" speed="20.00" length="5.00" type="leader" occupancy="0.25"/>
<instantOut id="beg_end" time="24.42" state="enter" vehID="follower" speed="20.48" length="5.00" type="follower" gap="0.57"/>
<instantOut id="beg_end" time="24.50" state="stay" vehID="follower" speed="20.30" length="5.00" type="follower"/>
<instantOut id="beg_end" time="24.60" state="stay" vehID="follower" speed="20.07" length="5.00" type="follower"/>
<instantOut id="beg_end" time="24.67" state="leave" vehID="follower" speed="19.83" length="5.00" type="follower" occupancy="0.25"/>
<instantOut id="beg_end" time="23.90" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.96" state="leave" vehID="leader" speed="20.00" length="5.00" type="leader" occupancy="0.25"/>
<instantOut id="beg_end" time="24.52" state="enter" vehID="follower" speed="20.48" length="5.00" type="follower" gap="0.57"/>
<instantOut id="beg_end" time="24.60" state="stay" vehID="follower" speed="20.30" length="5.00" type="follower"/>
<instantOut id="beg_end" time="24.70" state="stay" vehID="follower" speed="20.07" length="5.00" type="follower"/>
<instantOut id="beg_end" time="24.77" state="leave" vehID="follower" speed="19.83" length="5.00" type="follower" occupancy="0.25"/>
</instantE1>
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ SPDX-License-Identifier: EPL-2.0
-->

<instantE1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/instant_e1_file.xsd">
<instantOut id="beg_end" time="23.60" state="enter" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.60" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.70" state="enter" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.70" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.80" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.84" state="leave" vehID="leader" speed="20.00" length="5.00" type="leader" occupancy="0.25"/>
<instantOut id="beg_end" time="24.88" state="enter" vehID="follower" speed="20.14" length="5.00" type="follower" gap="1.03"/>
<instantOut id="beg_end" time="24.90" state="stay" vehID="follower" speed="20.14" length="5.00" type="follower"/>
<instantOut id="beg_end" time="23.90" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.95" state="leave" vehID="leader" speed="20.00" length="5.00" type="leader" occupancy="0.25"/>
<instantOut id="beg_end" time="24.98" state="enter" vehID="follower" speed="20.14" length="5.00" type="follower" gap="1.03"/>
<instantOut id="beg_end" time="25.00" state="stay" vehID="follower" speed="20.14" length="5.00" type="follower"/>
<instantOut id="beg_end" time="25.10" state="stay" vehID="follower" speed="20.14" length="5.00" type="follower"/>
<instantOut id="beg_end" time="25.12" state="leave" vehID="follower" speed="20.13" length="5.00" type="follower" occupancy="0.25"/>
<instantOut id="beg_end" time="25.20" state="stay" vehID="follower" speed="20.14" length="5.00" type="follower"/>
<instantOut id="beg_end" time="25.22" state="leave" vehID="follower" speed="20.13" length="5.00" type="follower" occupancy="0.25"/>
</instantE1>
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ SPDX-License-Identifier: EPL-2.0
-->

<instantE1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/instant_e1_file.xsd">
<instantOut id="beg_end" time="23.61" state="enter" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.70" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.71" state="enter" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.80" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.86" state="leave" vehID="leader" speed="20.00" length="5.00" type="leader" occupancy="0.25"/>
<instantOut id="beg_end" time="24.88" state="enter" vehID="follower" speed="20.13" length="5.00" type="follower" gap="1.03"/>
<instantOut id="beg_end" time="24.90" state="stay" vehID="follower" speed="20.13" length="5.00" type="follower"/>
<instantOut id="beg_end" time="23.90" state="stay" vehID="leader" speed="20.00" length="5.00" type="leader"/>
<instantOut id="beg_end" time="23.96" state="leave" vehID="leader" speed="20.00" length="5.00" type="leader" occupancy="0.25"/>
<instantOut id="beg_end" time="24.98" state="enter" vehID="follower" speed="20.13" length="5.00" type="follower" gap="1.03"/>
<instantOut id="beg_end" time="25.00" state="stay" vehID="follower" speed="20.13" length="5.00" type="follower"/>
<instantOut id="beg_end" time="25.10" state="stay" vehID="follower" speed="20.13" length="5.00" type="follower"/>
<instantOut id="beg_end" time="25.13" state="leave" vehID="follower" speed="20.13" length="5.00" type="follower" occupancy="0.25"/>
<instantOut id="beg_end" time="25.20" state="stay" vehID="follower" speed="20.13" length="5.00" type="follower"/>
<instantOut id="beg_end" time="25.23" state="leave" vehID="follower" speed="20.13" length="5.00" type="follower" occupancy="0.25"/>
</instantE1>
6 changes: 3 additions & 3 deletions tests/sumo/bugs/0xxx/ticket881c/detector.sumo
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ SPDX-License-Identifier: EPL-2.0
-->

<instantE1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/instant_e1_file.xsd">
<instantOut id="test" time="23.62" state="enter" vehID="veh0" speed="11.11" length="5.00" type="DEFAULT_VEHTYPE"/>
<instantOut id="test" time="24.00" state="stay" vehID="veh0" speed="11.11" length="5.00" type="DEFAULT_VEHTYPE"/>
<instantOut id="test" time="24.06" state="leave" vehID="veh0" speed="13.71" length="5.00" type="DEFAULT_VEHTYPE" occupancy="0.44"/>
<instantOut id="test" time="24.62" state="enter" vehID="veh0" speed="11.11" length="5.00" type="DEFAULT_VEHTYPE"/>
<instantOut id="test" time="25.00" state="stay" vehID="veh0" speed="11.11" length="5.00" type="DEFAULT_VEHTYPE"/>
<instantOut id="test" time="25.06" state="leave" vehID="veh0" speed="13.71" length="5.00" type="DEFAULT_VEHTYPE" occupancy="0.44"/>
</instantE1>
Loading
Loading