matsim-org / matsim-code-examples

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

Unexpected Agent Behavior in MATSim Simulation Across Iterations #1103

Open mina11so opened 6 months ago

mina11so commented 6 months ago

Hi, I am a beginner who has just started using MATSim. While conducting a simple verification, I encountered unexpected agent behavior during the simulation. I set up a simple network with three train stations and conducted simulations with trains that stop at different stations. I ran a total of 200 iterations, but while reviewing the intermediate file from the 50th iteration, I noticed that a specific agent (id=2) is departing at a time that does not match any scheduled train departures.

Here are the details:

Could this phenomenon be due to the optimization being at an intermediate stage? Could the small number of agents be influencing this, or is there a mistake in the input? I am curious why a plan that shows the agent boarding the train after the departure time is still being selected.

I have attached the relevant sections of my config.xml, network.xml, transitschedule.xml, plans.xml, and 50.plans.xml files. Could someone help identify any input errors or suggest what might be causing this discrepancy? config.xml.zip network.xml.zip transitschedule.xml.zip plans.xml.zip 50.plans.xml.gz

Thank you in advance.

cnabu commented 6 months ago

Hi, I'm beginner to MATSim as well. I try and run your scenario it says you're missing transitVehicles.xml. Just off the top of my head, by looking at your config.xml file I can see that 10% of your agents are allowed to change their departure time, perhaps that's the reason.

Janekdererste commented 6 months ago

@cnabu is correct. Your config references a transitVehicles file on L114

<param name="vehiclesFile" value="transitVehicles.xml" />

At least for the files you have provided here, it is missing. I would recommend the user guide section 12.

mina11so commented 6 months ago

Thank you both for your responses. I will share the transitVehicles.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<vehicleDefinitions xmlns="http://www.matsim.org/files/dtd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.matsim.org/files/dtd http://www.matsim.org/files/dtd/vehicleDefinitions_v1.0.xsd">
<vehicleType id="1">
   <description>pt</description>
   <capacity>
      <seats persons="50"/>
      <standingRoom persons="100"/>
   </capacity>
   <length meter="12"/>
</vehicleType>
<vehicle id="1000" type="1"/>
<vehicle id="2000" type="1"/>
<vehicle id="6000" type="1"/>
<vehicle id="7000" type="1"/>
</vehicleDefinitions>

I'm particularly concerned about why a plan that does not align with the set train schedules is being selected in the output file. For example, in the 50.plans.xml, an agent is shown to board a train at 09:09:10 under trnsitRouteId 'local', even though the 'local' train is supposed to depart at 09:00:00. This timing does not match any train schedules.

Additionally, there seems to be a discrepancy between the output_plans.xml file and the output_events.xml file from the same iteration, where the travel and departure times differ. Is it normal for the output plans.xml file to differ from the simulation results in the events.xml file? Would increasing the number of iterations help the output plans.xml and events.xml files to converge on similar timings?

JWJoubert commented 6 months ago

@mina11so, remember that the plans.xml file is exactly that: what the agent plans to do (his/her intention). The agent then tries to execute that plan, and the actual events are what is reported in the events.xml file.

That might explain why your agent presents with an unreasonable plan: planning to take a train that already left might result in being stuck at the station.

There is an option in the Config, if I recall correctly (maybe it is activated by default, but I doubt it) that you can set to also write the experienced plans. To my knowledge, this then reverse engineers the events.xml file into a format that reports the actual experienced sequence of events, for each agent, in a format that is readable to you and me: a plans.xml file format.

But, to emphasise, there is a difference (that is the value of MATSim, in my view) between what agents plan to do and how those plans turn out in practice (the mobility simulation).

I hope that helps somewhat.