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
5 changes: 2 additions & 3 deletions docs/web/docs/Simulation/Output/StatisticOutput.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ title: Statistic Output

Statistic output is activated by setting the simulation option **--statistic-output** {{DT_FILE}} on the command line or in a *.sumocfg* file.

!!! note
The elements `vehicleTripStatistics`, `pedestrianStatistics`, `rideStatistics` and `transportStatistics` are only generated when either of the options **--duration-log.statistics** or **--tripinfo-output** are set.
Statistic output collects trip statistics for all vehicles and transportables. Tripinfo device assignment options control which individual vehicle records appear in **--tripinfo-output**.

# Generated Output

Expand Down Expand Up @@ -149,7 +148,7 @@ The following output attributes are generated:

## Fair Traveltime comparison between simulations
When comparing simulations with a fixed end-time, those simulations may differ in the number of departed and arrived vehicles. In this case, care must be taken to include the "missing" vehicles in a comparison, since many outputs only include arrived vehicles by default.
To include statistics for these vehicles, the options **--tripinfo-output.write-unfinished --duration-log.statistics** must be set.
Enable **--tripinfo-output.write-unfinished** to include statistics for unfinished trips.
The general idea is to add up the travel time (duration) and the time that was spent waiting for departure (departDelay) for all vehicles that were defined in the input.

To simplify comparison between simulations that have the same number of vehicles, the attributes 'totalTravelTime' and 'totalDepartDelay' are provided.
Expand Down
4 changes: 1 addition & 3 deletions src/microsim/MSNet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,7 @@ MSNet::writeStatistics(const SUMOTime start, const long now) const {
od.writeAttr("abortWait", myPersonControl != nullptr ? myPersonControl->getTeleportsAbortWait() : 0);
od.writeAttr("wrongDest", myPersonControl != nullptr ? myPersonControl->getTeleportsWrongDest() : 0);
od.closeTag();
if (OptionsCont::getOptions().isSet("tripinfo-output") || OptionsCont::getOptions().getBool("duration-log.statistics")) {
MSDevice_Tripinfo::writeStatistics(od);
}
MSDevice_Tripinfo::writeStatistics(od);
}


Expand Down
10 changes: 5 additions & 5 deletions src/microsim/MSVehicleControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,14 @@ MSVehicleControl::removePending() {
myTotalTravelTime += STEPS2TIME(MSNet::getInstance()->getCurrentTimeStep() - veh->getDeparture());
myRunningVehNo--;
MSNet::getInstance()->informVehicleStateListener(veh, MSNet::VehicleState::ARRIVED);
// vehicle is equipped with tripinfo device (not all vehicles are)
const bool hasTripinfo = veh->getDevice(typeid(MSDevice_Tripinfo)) != nullptr;
const auto* tripinfo = static_cast<const MSDevice_Tripinfo*>(veh->getDevice(typeid(MSDevice_Tripinfo)));
OutputDevice* const vehicleTripinfoOut = tripinfo != nullptr && tripinfo->writesTripinfo() ? tripinfoOut : nullptr;
for (MSVehicleDevice* const dev : veh->getDevices()) {
dev->generateOutput(hasTripinfo ? tripinfoOut : nullptr);
dev->generateOutput(vehicleTripinfoOut);
}
if (tripinfoOut != nullptr && hasTripinfo) {
if (vehicleTripinfoOut != nullptr) {
// close tag after tripinfo (possibly including emissions from another device) have been written
tripinfoOut->closeTag();
vehicleTripinfoOut->closeTag();
}
if (myKeepTime == 0) {
deleteVehicle(veh);
Expand Down
17 changes: 10 additions & 7 deletions src/microsim/devices/MSDevice_Tripinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ void
MSDevice_Tripinfo::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevice*>& into) {
OptionsCont& oc = OptionsCont::getOptions();
const bool enableByOutputOption = oc.isSet("tripinfo-output") || oc.getBool("duration-log.statistics");
if (equippedByDefaultAssignmentOptions(oc, "tripinfo", v, enableByOutputOption)) {
MSDevice_Tripinfo* device = new MSDevice_Tripinfo(v, "tripinfo_" + v.getID());
const bool writeTripinfo = equippedByDefaultAssignmentOptions(oc, "tripinfo", v, enableByOutputOption);
if (writeTripinfo || oc.isSet("statistic-output")) {
MSDevice_Tripinfo* device = new MSDevice_Tripinfo(v, "tripinfo_" + v.getID(), writeTripinfo);
into.push_back(device);
myPendingOutput.insert(device);
}
Expand All @@ -104,8 +105,9 @@ MSDevice_Tripinfo::buildVehicleDevices(SUMOVehicle& v, std::vector<MSVehicleDevi
// ---------------------------------------------------------------------------
// MSDevice_Tripinfo-methods
// ---------------------------------------------------------------------------
MSDevice_Tripinfo::MSDevice_Tripinfo(SUMOVehicle& holder, const std::string& id) :
MSDevice_Tripinfo::MSDevice_Tripinfo(SUMOVehicle& holder, const std::string& id, bool writeTripinfo) :
MSVehicleDevice(holder, id),
myWriteTripinfo(writeTripinfo),
myDepartLane(""),
myDepartSpeed(-1),
myDepartPosLat(0),
Expand Down Expand Up @@ -429,16 +431,17 @@ MSDevice_Tripinfo::generateOutputForUnfinished() {
}
if (departed || (writeUndeparted && departDelayed)) {
const_cast<MSDevice_Tripinfo*>(d)->updateParkingStopTime();
d->generateOutput(tripinfoOut);
if (tripinfoOut != nullptr) {
OutputDevice* const vehicleTripinfoOut = d->writesTripinfo() ? tripinfoOut : nullptr;
d->generateOutput(vehicleTripinfoOut);
if (vehicleTripinfoOut != nullptr) {
for (MSVehicleDevice* const dev : d->myHolder.getDevices()) {
if (typeid(*dev) == typeid(MSDevice_Tripinfo) || typeid(*dev) == typeid(MSDevice_Vehroutes)) {
// tripinfo is special and vehroute has its own write-unfinished option
continue;
}
dev->generateOutput(tripinfoOut);
dev->generateOutput(vehicleTripinfoOut);
}
OptionsCont::getDeviceByOption("tripinfo-output").closeTag();
vehicleTripinfoOut->closeTag();
}
} else {
myPendingOutput.erase(d);
Expand Down
9 changes: 8 additions & 1 deletion src/microsim/devices/MSDevice_Tripinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ class MSDevice_Tripinfo : public MSVehicleDevice {
*/
void generateOutput(OutputDevice* tripinfoOut) const;

bool writesTripinfo() const {
return myWriteTripinfo;
}

/** @brief Saves the state of the device
*
* @param[in] out The OutputDevice to write the information into
Expand Down Expand Up @@ -201,8 +205,9 @@ class MSDevice_Tripinfo : public MSVehicleDevice {
*
* @param[in] holder The vehicle that holds this device
* @param[in] id The ID of the device
* @param[in] writeTripinfo Whether to write an individual trip record
*/
MSDevice_Tripinfo(SUMOVehicle& holder, const std::string& id);
MSDevice_Tripinfo(SUMOVehicle& holder, const std::string& id, bool writeTripinfo);


protected:
Expand All @@ -228,6 +233,8 @@ class MSDevice_Tripinfo : public MSVehicleDevice {
static bool lowAcceleration(const SUMOTrafficObject& veh);

private:
const bool myWriteTripinfo;

/// @brief The lane the vehicle departed at
std::string myDepartLane;

Expand Down
2 changes: 1 addition & 1 deletion src/microsim/transportables/MSTransportableControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ MSTransportableControl::erase(MSTransportable* transportable) {
transportable->tripInfoOutput(OptionsCont::getDeviceByOption("personinfo-output"));
} else if (oc.isSet("tripinfo-output")) {
transportable->tripInfoOutput(OptionsCont::getDeviceByOption("tripinfo-output"));
} else if (oc.getBool("duration-log.statistics")) {
} else if (oc.getBool("duration-log.statistics") || oc.isSet("statistic-output")) {
// collecting statistics is a sideffect
OutputDevice_String dev;
transportable->tripInfoOutput(dev);
Expand Down
4 changes: 4 additions & 0 deletions tests/sumo/output/statistic/basic/statistic.sumo
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
<safety collisions="0" emergencyStops="0" emergencyBraking="0"/>
<persons loaded="0" running="0" jammed="0"/>
<personTeleports total="0" abortWait="0" wrongDest="0"/>
<vehicleTripStatistics count="20" routeLength="194.90" speed="11.46" duration="17.00" waitingTime="0.00" timeLoss="2.42" departDelay="2.80" departDelayWaiting="-1.00" totalTravelTime="340.00" totalDepartDelay="56.00"/>
<pedestrianStatistics number="0" routeLength="0.00" duration="0.00" timeLoss="0.00"/>
<rideStatistics number="0"/>
<transportStatistics number="0"/>
</statistics>
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/routes_file.xsd">
<vType id="DEFAULT_VEHTYPE" sigma="0"/>
<route id="SN" edges="SC CN"/>
<route id="WE" edges="WC CE"/>
<vehicle id="selected" depart="0" route="SN"/>
<vehicle id="unselected0" depart="3" route="WE"/>
<vehicle id="unselected1" depart="6" route="SN"/>
</routes>
2 changes: 2 additions & 0 deletions tests/sumo/output/statistic/filtered_tripinfo/options.sumo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--no-step-log --no-duration-log --net-file net2.net.xml --route-files input_routes.rou.xml
--statistic-output statistic.xml --tripinfo-output tripinfos.xml --device.tripinfo.explicit selected
Empty file.
57 changes: 57 additions & 0 deletions tests/sumo/output/statistic/filtered_tripinfo/statistic.sumo
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 2026-12-03T15:36:08.713691+00:00 by Eclipse SUMO sumo v1.28.0
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
http://www.eclipse.org/legal/epl-v20.html
This file may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the Eclipse
Public License 2.0 are satisfied: GNU General Public License, version 2
or later which is available at
https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
<sumoConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/sumoConfiguration.xsd">

<input>
<net-file value="net2.net.xml"/>
<route-files value="input_routes.rou.xml"/>
</input>

<output>
<write-license value="true"/>
<tripinfo-output value="tripinfos.xml"/>
<statistic-output value="statistic.xml"/>
</output>

<processing>
<default.departspeed value="0"/>
<default.departlane value="first"/>
<default.speeddev value="0"/>
</processing>

<report>
<xml-validation value="never"/>
<duration-log.disable value="true"/>
<no-step-log value="true"/>
</report>

<tripinfo_device>
<device.tripinfo.explicit value="selected"/>
</tripinfo_device>

</sumoConfiguration>
-->

<statistics xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/statistic_file.xsd">
<performance clockBegin="670307.20" clockEnd="670307.20" clockDuration="0.00" traciDuration="0.00" realTimeFactor="56000.00" vehicleUpdatesPerSecond="0.00" personUpdatesPerSecond="0.00" begin="0.00" end="56.00" duration="56.00"/>
<vehicles loaded="3" inserted="3" running="0" waiting="0"/>
<teleports total="0" jam="0" yield="0" wrongLane="0"/>
<safety collisions="0" emergencyStops="0" emergencyBraking="0"/>
<persons loaded="0" running="0" jammed="0"/>
<personTeleports total="0" abortWait="0" wrongDest="0"/>
<vehicleTripStatistics count="3" routeLength="194.90" speed="8.89" duration="28.67" waitingTime="10.33" timeLoss="13.80" departDelay="0.00" departDelayWaiting="-1.00" totalTravelTime="86.00" totalDepartDelay="0.00"/>
<pedestrianStatistics number="0" routeLength="0.00" duration="0.00" timeLoss="0.00"/>
<rideStatistics number="0"/>
<transportStatistics number="0"/>
</statistics>
48 changes: 48 additions & 0 deletions tests/sumo/output/statistic/filtered_tripinfo/tripinfos.sumo
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- generated on 2026-12-03T15:36:08.713333+00:00 by Eclipse SUMO sumo v1.28.0
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
http://www.eclipse.org/legal/epl-v20.html
This file may also be made available under the following Secondary
Licenses when the conditions for such availability set forth in the Eclipse
Public License 2.0 are satisfied: GNU General Public License, version 2
or later which is available at
https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
<sumoConfiguration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/sumoConfiguration.xsd">

<input>
<net-file value="net2.net.xml"/>
<route-files value="input_routes.rou.xml"/>
</input>

<output>
<write-license value="true"/>
<tripinfo-output value="tripinfos.xml"/>
<statistic-output value="statistic.xml"/>
</output>

<processing>
<default.departspeed value="0"/>
<default.departlane value="first"/>
<default.speeddev value="0"/>
</processing>

<report>
<xml-validation value="never"/>
<duration-log.disable value="true"/>
<no-step-log value="true"/>
</report>

<tripinfo_device>
<device.tripinfo.explicit value="selected"/>
</tripinfo_device>

</sumoConfiguration>
-->

<tripinfos xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://sumo.dlr.de/xsd/tripinfo_file.xsd">
<tripinfo id="selected" depart="0.00" departLane="SC_0" departPos="5.10" departSpeed="0.00" departDelay="0.00" arrival="17.00" arrivalLane="CN_0" arrivalPos="91.95" arrivalSpeed="13.89" duration="17.00" routeLength="194.90" waitingTime="0.00" waitingCount="0" stopTime="0.00" timeLoss="2.19" rerouteNo="0" devices="tripinfo_selected" vType="DEFAULT_VEHTYPE" speedFactor="1.00" vaporized=""/>
</tripinfos>
1 change: 1 addition & 0 deletions tests/sumo/output/statistic/testsuite.sumo
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
basic
with_tripinfoOutput
filtered_tripinfo
with_unfinished
with_undeparted
with_durationLogStats
Expand Down
Loading