matsim-org / matsim-code-examples

A repository containing code examples around MATSim
GNU General Public License v3.0
81 stars 178 forks source link

Get the total travel time for each link in the network #1162

Open xuhan-incore opened 2 weeks ago

xuhan-incore commented 2 weeks ago

Hello,

Could anybody tell me after running the MATSIM, how to get the total travel time on each link in the network? Thank you.

xuhan-incore commented 1 week ago

Hello,

Can anyone answer my questions? Is there a way to modify the config file so that the total travel time for each link can be shown in output files? Thank you.

Yours sincerely, Xu Han

tschlenther commented 1 week ago

Hi,

have a look into your iteration output directories for the ..linkstats.txt.gz. It contains travel time statistics for every hour (but not the sum of all travel times neither the volume, I think). Writing this output file can be configured via the LinkStatsConfigGroup, e.g. like that:

<module name="linkStats" >
        <!-- Specifies over how many iterations the link volumes should be averaged that are used for the link statistics. Use 1 or 0 to only use the link volumes of a single iteration. This values cannot be larger than the value specified for writeLinkStatsInterval -->
        <param name="averageLinkStatsOverIterations" value="5" />
        <!-- Specifies how often the link stats should be calculated and written. Use 0 to disable the generation of link stats. -->
        <param name="writeLinkStatsInterval" value="50" />
    </module>

The easiest way to what you want might be running LinkStats class in matsim-libs as a postprocess. In case you have a scenario which is setup in the MATSim Application style (like matsim-berlin e.g.), you can also do that by starting your main run class but call link-stats instead of run on the command line.

Alternatively, you can program that yourself via an own implementation of LinkEnterEventHandler and LinkLeaveEventHandler. See the corresponding code-examples package, especially MyEventHandler1 for a kick-start.

Another way would be to load output events and network into Via and then make it compute average volumes and speeds (click on the network properties -> Link Attributes -> Add...) and then potentially export the network, if needed.

If you are rather interested in avrage speeds and volumes, you can also add the SimwrapperConfigGroup to your config and/or run script, and then enjoy interactive SimWrapper visualisations (especially the Overview and the Travel time dashboards).

xuhan-incore commented 1 week ago

Hi tschlenther,

Thank you for your detailed response. I tried using the first approach (adding linkStats module in the config file). I was able to get the link statistics in the ITERS file. However, the results I obtained were a little bit weired. The hourly travel time (I think it is under the labels such as "TRAVELTIME0-1avg") seems to be constant, as follows image I know this isn't correct. As there are no cars passing in many time periods (such as 12am-8am), as can be seen from the data on hourly car volumes. image I cannot figure out why this happened. Could you help me figure it out? Thank you.

Xu Han

xuhan-incore commented 4 days ago

Hello,

I can the columns like TRAVELTIME2-3avg indicates that the time for one vehicle to pass a link. So perhaps TRAVELTIME2-3avg times HRS2-3avg is the total time that all vehicles spent on each link during hours 2-3. However, it seems that the results for different iterations are different. I don't know the event output file is related to which iteration. Can anyone tell me? In addition, how to use LinkStats class in matsim-libs to do the postprocessing?