matsim-org / matsim-code-examples

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

ERROR: "Routing mode not set for leg" in Public Transport simulation #439

Open ciolo opened 3 years ago

ciolo commented 3 years ago

Hi everyone, I'm trying to simulate a pt scenario with MatSim jar (v12). I generated population file based on my own data (see esample on attachment)

Screenshot 2020-10-02 at 15 54 25

I generated with pt2matsim library transitSchedule, transitVehicles and the network files ased on the GTFS and OSM data of my area of interest. When I run the simulation it raised an exception: Screenshot 2020-10-02 at 16 05 03 What am I doing wrong? Do I have to set a "particular" attribute in config file?

Thank u all.

vsp-gleich commented 3 years ago

Hi,

what version of matsim are you using?

I tried to reproduce your error with the current matsim 13 snapshot and the example agent at the bottom, but it passed the code where your error occurred and errored only later due to another issue with your plans file: In matsim plans always consist of a sequence of activity-leg-activity-leg-activity, i.e. they always start and end with an activity. In your case you have to simply repeat the home activity at the end of each plan (without end time). It is not necessary to insert empty routes <route/> but they apparently do not cause problems.

All legs should have an attribute routing mode which your legs do not have. That is what the error message is about. However, for backward compatibility the code tries to find the routing mode based on the leg mode while reading in outdated plan files, but that restricts to trips with only one leg (like your plans) if not configured otherwise. I cannot tell you why this failed for you (and not for me), but plans without an activity at their end are definitely faulty, so maybe fixing that will also fix your initial problem shown in the error message. By the way, you can set the routing mode using TripStructureUtils.setRoutingMode(leg, routingMode);

`

12062410 car

`

ciolo commented 3 years ago

Hi, Thanks for the quick response. Yes, I noticed the latest activity was missing as soon as I posted the issue. After addressing this problem, the simulation ran successfully without the routingMode attribute. I take this moment to ask you, what does routingMode represent in leg? Anyway, I'm using v12 of MatSim.

vsp-gleich commented 3 years ago

We introduced routing mode last year. It solves situations where e.g. the agent intended to take pt but no service was available. E.g. the closest bus stop to the origin is the same as the closest bus stop to the destination, so the agent walks without taking any bus (leg mode walk, routing mode pt). Or the last bus has already departed. Routing mode also helps with intermodal routing, because all legs of the trip can have the routing mode to show which router should be used for re-routing, but the legs itself can have different modes (e.g. walk-pt-bike). So technically it is the mode whose router shall be called to route the trip (not only the leg). You could interpret it as the intended mode of the trip. It makes life simpler in comparison to the old approach using a main mode identifier which takes all leg modes used on a trip and tries to guess which router might be responsible for that trip.

ClarissaLiv commented 3 years ago

Has anybody used the "setRoutingMode" method inside a new class that has the logic to identify the "routing mode" of old plans that lack the "routing mode attribute" and then insert the "routing mode attribute" into the older plans? Essentially a plan converter?

I just don't want to reinvent this if somebody has already done it, but my searching hasn't turned up anything. Thanks!

As for why I want to do this: I've got a large collection of scenarios that were created with MATSim 11. I do not want to have to run all of them again in order to use their output as a starting point for new runs. That would take weeks (!) of runtime.

kainagel commented 3 years ago

I am pretty sure that there is some infrastructure for that. @vsp-gleich should know about it.

vsp-gleich commented 3 years ago

Has anybody used the "setRoutingMode" method inside a new class that has the logic to identify the "routing mode" of old plans that lack the "routing mode attribute" and then insert the "routing mode attribute" into the older plans? Essentially a plan converter?

This should happen automatically after reading the plans from file in PrepareForSimImpl in adaptOutdatedPlansForRoutingMode() during simulation startup if you set plansConfigGroup.getHandlingOfPlansWithoutRoutingMode().equals(HandlingOfPlansWithoutRoutingMode.useMainModeIdentifier). This needs the now outdated MainModeIdentifier to be bound to an implementation which identifies the routing mode (for most simple cases the default MainModeIdentifierImpl should be sufficient). MainModeIdentifier is not used for any other purpose any more to avoid mixing it up with other purposes.