Skip to content

faq 247922732

Billy Charlton edited this page Sep 5, 2018 · 2 revisions

Post-processing in MATSim: Compute the total Vehicle Kilometer of Travel (VKT)

by Alain Tcheukam on 2018-03-26 13:09:36


How to compute the total vehicle Kilometer of Travel after a simulation in Matsim?

I need to:

  1. Compute for each agent: the total length (km) of the Origin-Destination route really taken by the agent/persond ID after the simulation.

  2. Sum up the travelled distance for all agents/person ID.

Do I need to use the “.experienced_plans.xml” file produced at the end of the simulation in the MATSim output file?


Comments: 3


Re: Post-processing in MATSim: Compute the total Vehicle Kilometer of Travel (VKT)

by Marcel Rieser on 2018-03-26 21:24:36

You could use either the experienced_plans.xml or the output_events.xml. I personally would go with the output_events.xml and write an events-handler. Basically, for each LinkEnterEvent, you could look up the length of the link in the network, and collect it for each (driving) agent. Something like the following (didn't try it out, wrote it how I remember the API):

Map<Id<Vehicle>, Double> vkt = new HashMap<>();

 public void handleEvent(LinkEnterEvent event) {
   double length = this.network.getLinks().get(event.getLinkId()).getLength();
   Double value = this.vkt.get(event.getVehicleId());
   if (value == null) {
     value = 0.0;
   }
   this.vkt.put(event.getVehicleId(), value + length);
 }

Re: Post-processing in MATSim: Compute the total Vehicle Kilometer of Travel (VKT)

by Johan W. Joubert on 2018-03-27 18:56:25

I like Marcel's answer. I followed the other approach - using the plans - a few years ago, and the code is still available here (for the time being) in the southAfrica playground, but we're cleaning it out bit by bit. Maybe you can look at it as an example... I don't vouch for my code efficiency ;-)


Re: Post-processing in MATSim: Compute the total Vehicle Kilometer of Travel (VKT)

by Alain Tcheukam on 2018-03-27 19:36:33

Dear Marcel,
Dear Johan,

thank you very much for your reply and help.

Alain

Clone this wiki locally