To initialise agents within PLZ areas SesamGIM conducts the following steps as default:
A small guide on how to build an area shapefile from Market Cell Shapefile in Quantum GIS:
First, read section Parameter Settings in the main part of this manual. Then, consider and check all parameters in GPlzPa. The following parameters in other param classes are mandatory:
PmParameterManager.setParameter(GInitialisersPa.INITIALISER_AGENTS, GPlzAreaAgentInitialiser.class); PmParameterManager.setParameter(GInitialisersPa.INITIALISER_GROUP, null);
Furthermore, the following parameters need some consideration:
PmParameterManager.setParameter(GBasicPa.ADD_MC_TO_AREA, false); PmParameterManager.setParameter(GBasicPa.AREAS_SHAPEFILE, "./config/shapes/areas/areas.shp"); PmParameterManager.setParameter(GBasicPa.MC_SHAPEFILE, "./config/shapes/mc/mc.shp"); PmParameterManager.setParameter(GMilieuPa.DISTRIBUTE_AGENTS_UNIFORMLY_IN_MC, true);
GInitialisersPa.IS_PLZ only needs to be adapted in case a custom PLZ-area class shall be used.
GimModelInitialiser<AgentType> gimInitialiser; gimInitialiser = new GPlzModelInitialiser<Household<?>>(); gimInitialiser.initAll();
See section "Parameter definitions" for required parameter definitions.
NOTE: In case you do not use gimInitialiser.initAll() you need to set the following parameter:
PmParameterManager.setParameter(GBasicPa.ADD_MC_TO_AREA, Boolean.FALSE);
Usually when Microm (R) data is applied, agent numbers are determined on the market cell level using GimMarketCellContexts. However, sometimes it is required for large model regions to increase the area for which agent numbers are determined at once in order to prevent ugly rounding effects. NOTE: The application of larger areas for the determination of agent numbers reduces accuracy of geographical agent localisation which is especially relevant for spatial social networks. Therefore, it is recommended to check your model's sensitivity towards the size of areas.
In order to apply PLZ areas as the level of agent number determination one basically has to use a special GimAgentInitialiser, namely GPlzWiseAreaAgentInitialiser:
PmParameterManager.setParameter(GInitialisersPa.INITIALISER_AGENTS, GPlzWiseAreaAgentInitialiser.class);
Usually, in this case it is not necessary or desired to initialise market cell contexts. Therefore, for initialisation the following code is sufficient:
GimModelInitialiser<AgentType> gimInitialiser; gimInitialiser = new GPlzModelInitialiser<Household<?>>(); gimInitialiser.initAreas(); gimInitialiser.initPlzContexts(); gimInitialiser.initAgents();
The procedure reads PLZ-based Microm (R) data from the database (de.cesr.sesamgim.init.plz.GPlzInitialiser). Therefore, the table name needs to be specified:
PmParameterManager.setParameter(GSqlPa.TBLNAME_HHSTRUCT_PLZ, "sesamgim_test_plzwise");
NOTE: In case you apply a custom implementation of GPlzContext make sure that it extends GUpdatablePlzContext or implements GimUpdatableContext
NOTE: In order to speed up the process of fetching data from DB the strategy described in section Custom SQL statements for GimMarketCellInitialiser can be applied here as well. The relevant method to override is GPlzInitialiser#buildSqlQuery().
There is a test for PLZ level agent number determination: de.cesr.sesamgim.testing.init.agent.GPlzWiseAreaAgentInitialiserTest. The SQL code that is required to create dependent tables is also helpful for creating the required model tables. It is found in ./config/test/sql/TestMySQL.sql.
Repast Simphony usually returns objects of the context that is queried and all its sub-context (see also Tipps and Tricks). For PLZ areas this is troublesome since a market cell can belong to more than one PLZ area, and thus its members may occur in the listing of more than one PLZ area. As a work-around, use the following method:
this.getDirectObjects(Agent.class);
See Checks for tools to test. You may have a look in de.cesr.sesamgim.testing.init.plz.GPlzInitialiserTest to see things working.