matsim-org / matsim-code-examples

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

#PT simulation only walk mode is captured on the pkm_modestats #695

Closed Owen295 closed 2 years ago

Owen295 commented 2 years ago

I am executing a simulation for Nairobi but the simulation stats don't make sense as it is multimodal simulation but pkm_modestats is only walk.

The issue is I don’t get to see the PT mode on the pkm_modestats.png output.

I am not sure what I am missing in my config file, but my mode change is ( pt, walk). Here is a config file.

I have also attached the output .png for pkm_modestats. Does anyone know what could be the issue?

pkm_modestats

Config.txt

Janekdererste commented 2 years ago

Could you please provide a log file? Maybe, we can see something in there.

Owen295 commented 2 years ago

Hello @Janekdererste

Here is the log file logfile.log .

Janekdererste commented 2 years ago
2022-02-16T11:30:34,611  INFO ModeStatsControlerListener:144 Mode shares over all 50356.0 trips found. MainModeIdentifier: class org.matsim.core.router.RoutingModeMainModeIdentifier
2022-02-16T11:30:34,611  INFO ModeStatsControlerListener:151 -- mode share of mode pt = 0.619389943601557
2022-02-16T11:30:34,611  INFO ModeStatsControlerListener:151 -- mode share of mode walk = 0.3806100563984431
2022-02-16T11:30:34,754  INFO ControlerListenerManagerImpl:167 calling notifyIterationEnds on org.matsim.analysis.ScoreStatsControlerListener
2022-02-16T11:30:34,761  INFO ScoreStatsControlerListener:181 -- avg. score of the executed plan of each agent: -79.290025217584
2022-02-16T11:30:34,761  INFO ScoreStatsControlerListener:182 -- avg. score of the worst plan of each agent: -81.43362066175598
2022-02-16T11:30:34,761  INFO ScoreStatsControlerListener:183 -- avg. of the avg. plan score per agent: -80.16422337825338
2022-02-16T11:30:34,761  INFO ScoreStatsControlerListener:184 -- avg. score of the best plan of each agent: -78.93661592682164
2022-02-16T11:30:34,813  INFO ControlerListenerManagerImpl:167 calling notifyIterationEnds on org.matsim.analysis.IterationTravelStatsControlerListener
2022-02-16T11:30:34,828  INFO TravelDistanceStats:143 -- average leg distance per plan (executed plans only): 8849.42978661336 meters
2022-02-16T11:30:34,828  INFO TravelDistanceStats:144 average leg distance per Person (executed plans only): 12845.946464438748 meters (statistic on all 42660 legs which have a finite distance)
2022-02-16T11:30:34,828  INFO TravelDistanceStats:145 -- average trip distance per plan (executed plans only): 8849.42978661336 meters
2022-02-16T11:30:34,828  INFO TravelDistanceStats:146 average trip distance per Person (executed plans only): 12845.946464438748 meters (statistic on all 42660 trips which have a finite distance)
2022-02-16T11:30:34,829  INFO TravelDistanceStats:147 (TravelDistanceStats takes an average over all legs where the simulation reports travelled (network) distances
2022-02-16T11:30:34,829  INFO TravelDistanceStats:148 (and teleported legs whose route contains a distance.)
2022-02-16T11:30:36,602  INFO ControlerListenerManagerImpl:167 calling notifyIterationEnds on org.matsim.analysis.LegHistogramListener
2022-02-16T11:30:36,605  INFO LegHistogramListener:72 number of legs:   48245   100%
2022-02-16T11:30:36,605  INFO LegHistogramListener:79 number of walk legs:  48245   100.0%
2022-02-16T11:30:36,864  INFO ControlerListenerManagerImpl:167 calling notifyIterationEnds on org.matsim.analysis.LinkStatsControlerListener
2022-02-16T11:30:36,864  INFO ControlerListenerManagerImpl:171 [it.10] all ControlerIterationEndsListeners called.
2022-02-16T11:30:36,951  INFO AbstractController:181 ### ITERATION 10 ENDS
2022-02-16T11:30:36,951  INFO AbstractController:182 ###################################################

2022-02-16T11:30:34,611 INFO ModeStatsControlerListener:151 -- mode share of mode pt = 0.619389943601557

So, looking at the log file the mode share of pt is at around 61%. This means 61% of your agents try to do a pt trip.

2022-02-16T11:30:36,605 INFO LegHistogramListener:72 number of legs: 48245 100%

However, in the end all your trips are executed as walk legs. This indicates that agents didn't find a suitable pt connection.

2022-02-16T11:26:28,763  INFO SwissRailRaptorData:211 SwissRailRaptor data preparation done. Took 0 seconds.
2022-02-16T11:26:28,763  INFO SwissRailRaptorData:212 SwissRailRaptor statistics:  #routes = 1054
2022-02-16T11:26:28,763  INFO SwissRailRaptorData:213 SwissRailRaptor statistics:  #departures = 61013
2022-02-16T11:26:28,763  INFO SwissRailRaptorData:214 SwissRailRaptor statistics:  #routeStops = 11188
2022-02-16T11:26:28,764  INFO SwissRailRaptorData:215 SwissRailRaptor statistics:  #stopFacilities = 4659
2022-02-16T11:26:28,764  INFO SwissRailRaptorData:216 SwissRailRaptor statistics:  #transfers (between routeStops) = 84955
2022-02-16T11:26:28,771  INFO NetworkImpl:163  node # 1
2022-02-16T11:26:28,771  INFO NetworkImpl:163  node # 4
2022-02-16T11:26:28,772  INFO NetworkImpl:163  node # 16
2022-02-16T11:26:28,772  INFO NetworkImpl:163  node # 64
2022-02-16T11:26:28,772  INFO NetworkImpl:163  node # 256
2022-02-16T11:26:28,806  INFO NetworkImpl:163  node # 1024
2022-02-16T11:26:28,818  WARN RandomizingTimeDistanceTravelDisutilityFactory:112 There will be no routing randomness. The randomization of the travel disutility requires the monetary distance rate to be different than zero. Continuing anyway.

This part of your log file might indicate that your pt network is missing links in between stops. You could check, whether your pt network contains those links and that they are connected to the transit nodes.

Owen295 commented 2 years ago

Hello,

@Janekdererste

I am comparing the simulation log files with one from Capetown which works perfectly. They have the same warning message but the simulation shows the pt walk split as in the .png below. I am not sure if the issue could be the demand files since those are the only different I see as shown below. I have attached an example of the output and the log file from the capetown simulation.

Capetown :

<person id="1">
    <plan selected="yes">
        <act type="Home" x="-48518.7748449864" y="-3710221.39107603" end_time="06:01:00.000"/>
        <leg mode="pt"/>
        <act type="Bus_Stop" x="-46634.0641183322" y="-3714016.64141122" start_time="06:28:00.000" end_time="06:28:00.000"/>
        <leg mode="pt"/>
        <act type="Work" x="-47058.3186274383" y="-3750816.18996136" start_time="07:12:00.000" end_time="14:44:00.000"/>
        <leg mode="pt"/>
        <act type="Bus_Stop" x="-46634.0641183322" y="-3714016.64141122" start_time="16:04:00.000" end_time="16:05:00.000"/>
        <leg mode="pt"/>
        <act type="Home" x="-48518.7748449864" y="-3710221.39107603" start_time="16:22:00.000"/>
    </plan>
</person>

Nairobi :

<person employed="yes" id="2">
    <plan>
        <act end_time="06:40:00" type="h" x="36.869452000000003" y="-1.261518002000000"/>
        <leg mode="pt"/>
        <act end_time="16:10:00" start_time="07:10:00" type="w" x="36.828907729999997" y="-1.287224293000000"/>
        <leg mode="pt"/>
        <act start_time="16:40:00" type="h" x="36.869452000000003" y="-1.261518002000000"/>
    </plan>
</person>

logfile.log pkm_modestats

Janekdererste commented 2 years ago

The Nairobi Plans file should be fine. You should check your transit-Schedule as well as your Network.

If you can give me:

I can have a look at your scenario

Owen295 commented 2 years ago

Hello, I have attached them here.

output_network.xml.gz output_plans.xml.gz

The output_events.xml.gz file is too large but have copied some sections

<event time="16436.0" type="actend" person="191" link="Nai_1119" x="36.89554989" y="-1.316594481" actType="h"  />
<event time="16436.0" type="departure" person="191" link="Nai_1119" legMode="walk" computationalRoutingMode="pt"  />
<event time="16436.0" type="travelled" person="191" distance="0.0993666935640792" mode="walk"  />

<event time="21600.0" type="TransitDriverStarts" driverId="pt_tr_800_defaultTransitVehicleType" vehicleId="tr_800" transitLineId="100A---20100100A11" transitRouteId="100A---20100100A11_0" departureId="2100A110.21600"  />
<event time="21600.0" type="departure" person="pt_tr_800_defaultTransitVehicleType" link="Nai_341" legMode="car"  />
<event time="21600.0" type="PersonEntersVehicle" person="pt_tr_800_defaultTransitVehicleType" vehicle="tr_800"  />

<event time="47908.0" type="left link" link="Nai_4506" vehicle="tr_24437"  />
<event time="47908.0" type="entered link" link="Nai_4507" vehicle="tr_24437"  />
<event time="47908.0" type="left link" link="Nai_2012" vehicle="tr_7282"  />
<event time="47908.0" type="entered link" link="Nai_2013" vehicle="tr_7282"  />
<event time="47908.0" type="left link" link="Nai_4774" vehicle="tr_26683"  />
<event time="47908.0" type="entered link" link="Nai_4775" vehicle="tr_26683"  />
Owen295 commented 2 years ago

Hello @Janekdererste

Here is the link for the events file:

https://www.dropbox.com/s/tidqd9lrhpt0794/output_events.xml.gz?dl=0

I did not think of this initially.

Janekdererste commented 2 years ago

I have had a look at your data. Your plans.xml as well as your network.xml have EPSG:4326 as coordinate reference system. This is a spheric coordinate system. Matsim requires an eucledian coordinate reference system. To have things work out, you have to transform your coordinates into such a crs. For Nairobi, this could be UTM-37s (EPSG:32737).

Matsim will transform your input for you automatically, as long as you have the coordinateReferenceSystem attribute set in your input files. To make sure your simulation is set up with an eucledian crs, you could set the global.coordinateSystem value of your config to EPSG:32737 and Matsim will take care of the transformation. It is important to note though, that the output files will then be in UTM-37s coordinates.

The question why nobody is using the pt is related to the coordinates you are using. Your network has coordinates somewhere around x="939081.0921210845" y="9844759.531660017". Your agents have coordinates x="36.869452" y="-1.261518002". This means your agents live several thousand kilometers away from your transport network. In the image below, the red dot are all your agents, the small black dot is your entire network. My guess would be, that this is also related to coordinate transformations. I would advice to have everything in the same crs. This makes life usually a lot easier.

transport issue

Owen295 commented 2 years ago

Hello Janek,

I made correction on the coordinate reference system. Now my Network and Plans are in the same reference system. Thank you so much for pointing that out.

Fortunately the simulation runs but I still end up with the same results where the walking mode is the only captured mode. I am not sure if my config file may have a misrepresentation. Does having a penalty for walking help resolving this kind of output? Or does now the schedule affect this simulation since we have resolved errors in the network and the plans file?

I will attach the files for you to see what is happening. I will also have the output files in the drop box link below.

config file: Config.txt

Log File: logfile.log

Output Files: https://www.dropbox.com/scl/fo/t50jmezgkl6ra361vcf3i/h?dl=0&rlkey=rt0ap7fp9ohbagsftimzuywxo

I use pt2matsim in generating the schedule, network and vehicle input files. Do I need to check this? Could this be the issue?

Janekdererste commented 2 years ago

transprt-issue-2

It looks like you still have an issue with your transformations. Your people now live several thousand kilometers to the east of your network. Same Problem, just another direction I guess 😉)

Owen295 commented 2 years ago

Hello Janek,

Thank you so much for your time on this.

Indeed, the issue was with transformation. The simulation runs and the stats are now representative of all the modes. I had to work out the transformation out of MATSim. I attempted to define the transformation as per the instruction on the user guide which failed.

I bet the syntax may be the issue. Thank you once again.