Skip to content

faq 280756225

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

Read population directly from Postgresql database?

by Davi Bicudo on 2018-05-22 08:33:06


We have our population in a Postgresql database, containing everything the basic population needs in one table. Currently we're using a converter that reads this database and writes the xml file which will then be used for the simulation.

This converter is creating a Population object, so it would be time-saving if, instead of writing to xml and parsing again later, we could pass this object directly to the Scenario. It's not clear how to do that though.

Is there currently any implementation that does something like this? Would a custom module need to be installed and if yes, how would this override the current ScenarioLoader?

Thanks!


Comments: 2


Re: Read population directly from Postgresql database?

by Sebastian Hörl on 2018-05-22 08:36:38

Hi Davi,

I guess https://jdbc.postgresql.org/ should help. The way to do it would probably be to write a new "PopulationReader" implementation around that and to construct the population from the database. As discussed at STRC, this would be quite useful to have.

Best,
Sebastian


Re: Read population directly from Postgresql database?

by Kai Nagel on 2018-05-22 11:26:14

Controler takes Scenario as input. That is, you can write

Config config = ConfigUtils.createConfig() ;
// or ConfigUtils.loadConfig(...)

Scenario scenario = ScenarioUtils.createScenario( config ) ;
// (so far this is just an empty scenario)

new MyPopulationReader(scenario.getPopulation()).read(filename) ;

Controler controler = new Controler( scenario ) ;

If some of your material still comes from xml files, you could also do

Config config = ConfigUtils.createConfig() ;
// or ConfigUtils.loadConfig(...)

Scenario scenario = ScenarioUtils.loadScenario( config ) ;
// (this now loads all files defined in config)

new MyPopulationReader(scenario.getPopulation()).read(filename) ;

Controler controler = new Controler( scenario ) ;

Clone this wiki locally