matsim-org / matsim-code-examples

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

QSim - Mobsim error triggering simulation shutdown #316

Closed alex-andrey closed 4 years ago

alex-andrey commented 4 years ago

Hello,

My colleagues & I have been attempting to run MATSim simulations with a multimodal network and are consistently encountering the same error. We initially thought the error was network-related but we ran into it again when running simulations for a different geography.

Please find below:

Thanks in advance for your help

Logs

INFO QSimProvider:129 Added AgentSource class ch.sbb.matsim.mobsim.qsim.pt.SBBTransitQSimEngine
ERROR QSim:313 got exception while cleaning up
java.lang.NullPointerException
at org.matsim.core.mobsim.qsim.qnetsimengine.QNetsimEngine.afterSim(QNetsimEngine.java:239)
at org.matsim.core.mobsim.qsim.QSim.cleanupSim(QSim.java:310)
at org.matsim.core.mobsim.qsim.QSim.run(QSim.java:244)
at org.matsim.core.controler.NewControler.runMobSim(NewControler.java:126)
at org.matsim.core.controler.AbstractController$8.run(AbstractController.java:197)
at org.matsim.core.controler.AbstractController.iterationStep(AbstractController.java:229)
at org.matsim.core.controler.AbstractController.mobsim(AbstractController.java:193)
at org.matsim.core.controler.AbstractController.iteration(AbstractController.java:144)
at org.matsim.core.controler.AbstractController.doIterations(AbstractController.java:112)
at org.matsim.core.controler.AbstractController.access$100(AbstractController.java:28)
at org.matsim.core.controler.AbstractController$1.run(AbstractController.java:80)
at org.matsim.core.controler.MatsimRuntimeModifications.run(MatsimRuntimeModifications.java:48)
at org.matsim.core.controler.MatsimRuntimeModifications.run(MatsimRuntimeModifications.java:31)
at org.matsim.core.controler.AbstractController.run(AbstractController.java:88)
at org.matsim.core.controler.NewControler.run(NewControler.java:84)
at org.matsim.core.controler.Controler.run(Controler.java:240)
at com.arup.cm.RunMatsim.main(RunMatsim.java:18)
ERROR AbstractController:208 Mobsim did not complete normally! afterMobsimListeners will be called anyway.
java.lang.ClassCastException: org.matsim.pt.routes.ExperimentalTransitRoute cannot be cast to org.matsim.core.population.routes.NetworkRoute
at org.matsim.core.mobsim.qsim.agents.PopulationAgentSource.insertVehicles(PopulationAgentSource.java:85)

shortly after, a SHUTDOWN is initiated

MATSim Specs

MATSim version 11.0 Dependencies org.matsim.contrib : roadpricing 11.0, multimodal 11.0 junit 4.12 test-jar 11.0 Dependency com.github.SchweizerischeBundesbahnen : matsim-sbb-extensions 11.0

Build plugins: maven-compiler-plugin 2.3.2 maven-eclipse-plugin maven-assembly-plugin

Our custom MATSim Controler

Please note that in this controller we knowingly don't include multimodal or roadpricing, but the jar files associated with those are present when running (we use a jar in the class path which has them inside).

package com.arup.cm;

import org.matsim.core.config.Config;
import org.matsim.core.config.ConfigUtils;
import org.matsim.core.controler.Controler;

import ch.sbb.matsim.mobsim.qsim.SBBTransitModule;
import ch.sbb.matsim.mobsim.qsim.pt.SBBTransitEngineQSimModule;
import ch.sbb.matsim.routing.pt.raptor.SwissRailRaptorModule;

public class RunMatsim {
    public static void main(String[] args) {
        Config config = ConfigUtils.loadConfig(args[0]);
        Controler controler = new Controler(config);
        controler.addOverridingModule(new SBBTransitModule());
        controler.addOverridingModule(new SwissRailRaptorModule());
        controler.configureQSimComponents(components -> {SBBTransitEngineQSimModule.configure(components);});
        controler.run();
    }
}
mrieser commented 4 years ago

In the config, you specify car,bus,rail,tram,ferry,pt as mainMode for the qsim. This likely is wrong, because by default at least pt is the mode used by public transport passengers (and is also specified as such in the config in transit.transitModes. There should not be any intersection between qsim.mainMode and transit.transitModes.

The list in mainMode is actually the list of modes that should run on the road network. pt (for the passengers) are not directly on the road network, they get transported by PT vehicles. Those vehicles could, but don't have to, run on the network.

alex-andrey commented 4 years ago

just tested it and it worked ! Amazing, thank you very much.