-
Notifications
You must be signed in to change notification settings - Fork 179
faq 191594515
by Gregory Macfarlane on 2018-02-28 21:30:25
I'm trying to generate dummy plans from a trip matrix obtained from a four-step regional travel demand model. The matrix is stored in an OMX file, and represents decimal flows between points in a region.
I've created a playground workspace on our fork of the playgrounds repo (module tf) with a complete setup. But I can illustrate the problem here:
String dir = "tf/src/main/resources/";
Config config = ConfigUtils.loadConfig(dir + "config.xml");
Scenario scenario = ScenarioUtils.createScenario(config);
//sampling rate
Double samplingRate = 0.1;
//writes population.xml.gz plans file
makeOmxTrips(dir, scenario, samplingRate);
Controler controler = new Controler(config);
controler.run();
Basically, the makeOmxTrips method reads the matrix file and converts the decimal flows into discrete trips that make two "Home" activities, one at the origin point and one at the destination point. The samplingRate parameter determines the rate at which flows are converted into plans, with 0.01 meaning one person-plan for every 100 decimal trips.
But this is all background. In the example above, everything works as expected. But if I change the samplingRate to 1.0, the scenario appears to attempt to load the network file multiple times. This creates an error where IDs are repeated, because of course they are.
2018-02-28 16:02:26,920 INFO PopulationImpl:112 person # 256
2018-02-28 16:02:26,943 INFO ScenarioLoaderImpl:108 loading scenario from base directory: /Users/gregmacfarlane/playgrounds/
2018-02-28 16:02:26,944 INFO ScenarioLoaderImpl:130 loading network from file:/Users/gregmacfarlane/playgrounds/tf/src/main/resources/highway_network.xml.gz
2018-02-28 16:02:26,945 INFO MatsimNetworkReader:95 using network_v2-reader.
2018-02-28 16:02:26,946 INFO MatsimXmlParser:270 Trying to load http://www.matsim.org/files/dtd/network_v2.dtd. In some cases (e.g. network interface up but no connection), this may take a bit.
2018-02-28 16:02:26,944 WARN MatsimXmlParser:155 starting to parse xml from url file:/Users/gregmacfarlane/playgrounds/tf/src/main/resources/highway_network.xml.gz ...
2018-02-28 16:02:27,161 INFO ScenarioLoaderImpl:108 loading scenario from base directory: /Users/gregmacfarlane/playgrounds/
2018-02-28 16:02:27,161 INFO ScenarioLoaderImpl:130 loading network from file:/Users/gregmacfarlane/playgrounds/tf/src/main/resources/highway_network.xml.gz
2018-02-28 16:02:27,162 WARN MatsimXmlParser:155 starting to parse xml from url file:/Users/gregmacfarlane/playgrounds/tf/src/main/resources/highway_network.xml.gz ...
2018-02-28 16:02:27,163 INFO MatsimNetworkReader:95 using network_v2-reader.
2018-02-28 16:02:27,163 INFO MatsimXmlParser:270 Trying to load http://www.matsim.org/files/dtd/network_v2.dtd. In some cases (e.g. network interface up but no connection), this may take a bit.
2018-02-28 16:02:27,368 WARN MatsimXmlParser:155 starting to parse xml from url
...
...
...
2) Error in custom provider, java.lang.IllegalArgumentException: There exists already a node with id = 0.
Existing node: [id=0][coord=[x=299666.0758658158][y=163294.94229271446]] [type=null][nof_inlinks=1][nof_outlinks=1]
Node to be added: [id=0][coord=[x=299666.0758658158][y=163294.94229271446]] [type=null][nof_inlinks=0][nof_outlinks=0].
Node is not added to the network.
at org.matsim.core.scenario.ScenarioByConfigModule.createScenario(ScenarioByConfigModule.java:9) (via modules: com.google.inject.util.Modules$CombinedModule -> com.google.inject.util.Modules$CombinedModule -> org.matsim.core.controler.AbstractModule$4 -> com.google.inject.util.Modules$OverrideModule -> org.matsim.core.scenario.ScenarioByConfigModule)
at org.matsim.core.scenario.ScenarioByConfigModule.createScenario(ScenarioByConfigModule.java:9) (via modules: com.google.inject.util.Modules$CombinedModule -> com.google.inject.util.Modules$CombinedModule -> org.matsim.core.controler.AbstractModule$4 -> com.google.inject.util.Modules$OverrideModule -> org.matsim.core.scenario.ScenarioByConfigModule)
while locating org.matsim.api.core.v01.Scenario
Complete logfile attached.
by Kai Nagel on 2018-02-28 21:39:50
Can't say, not enough information, sorry. What I can say is that the code snippet that you provide seems inconsistent: you are creating a scenario, then using it in makeOmxTrip, and then somehow not using it any further. But maybe that is a typo? In general I would recommend the following sequence:
Config config = ConfigUtils.loadConfig(configFileName);
Scenario scenario = ScenarioUtils.loadScenario( config ) ; // note _load_, not create
// modify scenario, e.g. add trips from omx
Controler controler = new Controler( scenario ) ; // note scenario as argument
PS: In general we would recommend to clone matsim-example-project as a starting point for own programming, and matsim-code-examples for code examples. playgrounds contain lots of code that should not be used any more.
You are viewing an archive of the previous MATSim Q&A site. The real site is now at https://matsim.org/faq