de.cesr.sesamgim.init.agent
Class GAreaAgentInitialiser<AgentType extends GimMilieuAgent<AgentType>>

java.lang.Object
  extended by de.cesr.sesamgim.init.agent.GAreaAgentInitialiser<AgentType>
All Implemented Interfaces:
GimAgentInitialiser<AgentType>, GimAgentPlacingInitialiser<AgentType>
Direct Known Subclasses:
GGroupAreaAgentInitialiser, GPlzAreaAgentInitialiser

public class GAreaAgentInitialiser<AgentType extends GimMilieuAgent<AgentType>>
extends Object
implements GimAgentPlacingInitialiser<AgentType>

Initializes the agents of an entire area at once. - Queries all market cells as sub-contexts of the given area context - For each market cell: - Fetches data about agents in the market cell - Calculates the number of required group contexts - Initialises agents and assign them to group contexts.

Date:
19.07.2010

Field Summary
protected  NumberFormat format
           
protected  GimMilieuKeyMap milieuMap
           
protected  de.cesr.uranus.core.UranusRandomService randomService
           
 
Constructor Summary
GAreaAgentInitialiser()
          Assigns the main context.
 
Method Summary
protected  void adaptMilieuSums()
          Adapt numbers in milieuSums in a way that, each value divided by GBasicPa.NUM_HH_PER_AGENT), the sum is a multiplicative of GMilieuPa.GROUP_SIZE
protected  void calculateAgentSums(GimMarketCellContext<AgentType> mc)
           
protected  com.vividsolutions.jts.geom.Point findPlaceExtending(GimAreaContext<? super AgentType> area, repast.simphony.space.gis.Geography<Object> areas, GimUpdatableContext<AgentType> uc, com.vividsolutions.jts.geom.Coordinate centerCoords, com.vividsolutions.jts.geom.Envelope env, double initStdDev, String generator)
          Searches for a point (mostly for the location of group context) within the given area near the given MC coordinates.
 GimGroupInitialiseService<AgentType> getGroupIS()
           
 Collection<AgentType> initAgents(GimModelInitialiser<AgentType> gimInitialiser)
           
protected  boolean initAgentsPerUpdatableContext(Collection<AgentType> agents, GimAreaContext<AgentType> area, GimUpdatableContext<AgentType> uc)
           
protected  GimGroupInitialiser<AgentType> initialiseGroups(GimAreaContext<AgentType> area, GimMarketCellContext<AgentType> mc, GimGroupInitialiser<AgentType> gi)
           
protected  void logGroupContexts(GimUpdatableContext<AgentType> uc)
           
protected  void logGroupContextsAsTotal(GimAreaContext<AgentType> area, int numAgents)
           
 void placeAgent(GimAreaContext<AgentType> area, GimUpdatableContext<AgentType> uc, AgentType agent)
           
 void placeAgentNearMarketCell(AgentType agent, GimAreaContext<? super AgentType> area, GimMarketCellContext<AgentType> mc)
           
 void placeGroupContext(GimGroupContext<AgentType> gc, GimAreaContext<? super AgentType> area, GimMarketCellContext<AgentType> mc)
          Determines a geographical centre for the given NeighbourhoodContext near the given MarketCellContext using GAreaAgentInitialiser#STD_DEV_PLACE_NEIGHBOURHOODS.
 void placeGroupContextOnRadius(Collection<GimGroupContext<AgentType>> gcCol, GimAreaContext<? super AgentType> area, GimMarketCellContext<AgentType> mc)
          Determines a geographical center for the given GGroupContext on a radius around the given MarketCellContext using GBasicPa.PLACE_GROUP_ON_RADIUS.
protected  void processAgentNumberUnits(Collection<AgentType> agents, GimAreaContext<AgentType> area)
           
 void setGroupIS(GimGroupInitialiseService<AgentType> groupIS)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

randomService

protected final de.cesr.uranus.core.UranusRandomService randomService

format

protected final NumberFormat format

milieuMap

protected GimMilieuKeyMap milieuMap
Constructor Detail

GAreaAgentInitialiser

public GAreaAgentInitialiser()
Assigns the main context.

Parameters:
mainContext - the root context
Method Detail

initAgents

public Collection<AgentType> initAgents(GimModelInitialiser<AgentType> gimInitialiser)
Specified by:
initAgents in interface GimAgentInitialiser<AgentType extends GimMilieuAgent<AgentType>>
Returns:
See Also:
init.AgentInitializer#initAgents(contexts.AreaContext)

processAgentNumberUnits

protected void processAgentNumberUnits(Collection<AgentType> agents,
                                       GimAreaContext<AgentType> area)
Parameters:
agents -
area -

initAgentsPerUpdatableContext

protected boolean initAgentsPerUpdatableContext(Collection<AgentType> agents,
                                                GimAreaContext<AgentType> area,
                                                GimUpdatableContext<AgentType> uc)
Parameters:
agents -
area -
uc -
Returns:

logGroupContextsAsTotal

protected void logGroupContextsAsTotal(GimAreaContext<AgentType> area,
                                       int numAgents)
Parameters:
area -
numAgents -

logGroupContexts

protected void logGroupContexts(GimUpdatableContext<AgentType> uc)
Parameters:
uc -

initialiseGroups

protected GimGroupInitialiser<AgentType> initialiseGroups(GimAreaContext<AgentType> area,
                                                          GimMarketCellContext<AgentType> mc,
                                                          GimGroupInitialiser<AgentType> gi)
Parameters:
area -
mc -
gi -
Returns:

calculateAgentSums

protected void calculateAgentSums(GimMarketCellContext<AgentType> mc)
Parameters:
mc -

adaptMilieuSums

protected void adaptMilieuSums()
Adapt numbers in milieuSums in a way that, each value divided by GBasicPa.NUM_HH_PER_AGENT), the sum is a multiplicative of GMilieuPa.GROUP_SIZE


placeAgent

public void placeAgent(GimAreaContext<AgentType> area,
                       GimUpdatableContext<AgentType> uc,
                       AgentType agent)
Specified by:
placeAgent in interface GimAgentPlacingInitialiser<AgentType extends GimMilieuAgent<AgentType>>
Parameters:
area -
mc -
agent -

placeAgentNearMarketCell

public void placeAgentNearMarketCell(AgentType agent,
                                     GimAreaContext<? super AgentType> area,
                                     GimMarketCellContext<AgentType> mc)
Parameters:
agent -
area -
mc -

placeGroupContext

public void placeGroupContext(GimGroupContext<AgentType> gc,
                              GimAreaContext<? super AgentType> area,
                              GimMarketCellContext<AgentType> mc)
Determines a geographical centre for the given NeighbourhoodContext near the given MarketCellContext using GAreaAgentInitialiser#STD_DEV_PLACE_NEIGHBOURHOODS. Ensures that the neighourhood's centre is located within the area. Furthermore, it checks for containment in inhabited area, if BasicPa#ALLOW_AGENTS_TO_LEAVE_INHABITED_AREAS is not true.

Parameters:
gc - the neighbourhood context to place
area - the area the NC shall be placed within.
mc - the market cell this NC belongs to

findPlaceExtending

protected com.vividsolutions.jts.geom.Point findPlaceExtending(GimAreaContext<? super AgentType> area,
                                                               repast.simphony.space.gis.Geography<Object> areas,
                                                               GimUpdatableContext<AgentType> uc,
                                                               com.vividsolutions.jts.geom.Coordinate centerCoords,
                                                               com.vividsolutions.jts.geom.Envelope env,
                                                               double initStdDev,
                                                               String generator)
Searches for a point (mostly for the location of group context) within the given area near the given MC coordinates. Checks GMilieuPa.ALLOW_AGENTS_TO_LEAVE_AREA_BOUNDARIES and GMilieuPa.ALLOW_AGENTS_TO_LEAVE_INHABITED_AREAS and searches again with increased standard deviation after STD_DEV_EXTENSION_COUNTER_TRESHOLD unsuccessful searches.

Parameters:
area -
areas -
centerCoords -
env -
stdDev -
Returns:

placeGroupContextOnRadius

public void placeGroupContextOnRadius(Collection<GimGroupContext<AgentType>> gcCol,
                                      GimAreaContext<? super AgentType> area,
                                      GimMarketCellContext<AgentType> mc)
Determines a geographical center for the given GGroupContext on a radius around the given MarketCellContext using GBasicPa.PLACE_GROUP_ON_RADIUS. Ensures that the neighourhood's center is located within the area.

Parameters:
gcCol - the collection of group contexts to place
area - the area the GC shall be placed within.
mc - the market cell this GC belongs to

getGroupIS

public GimGroupInitialiseService<AgentType> getGroupIS()
Returns:
the groupInitialiser

setGroupIS

public void setGroupIS(GimGroupInitialiseService<AgentType> groupIS)
Parameters:
groupInitialiser - the groupInitialiser to set