Reference 〉 Hook


This model runs once per period, at the end, after all agents have been stepped and data collected.

Required Parameters

  • model Helipad

    The model object.

Notes and Examples

  1. charwick

    Mar 22, 2020 at 20:24

    modelPostStep is a good place to consolidate data for reporting that needs more processing than agentReporter() can handle. This example calculates some per-capita rates for each agent breed at the end of each period and puts it in a dict in the model object, to be subsequently gathered by modelReporter(). (Note however that because this hook fires after data collection, the rates will be reported with a one-period delay, which is ok given the heavy smoothing in this example)

    def modelPostStep(model):
    	for breed in model.primitives['agent']['breeds']:
    		pop = len(model.agent(breed))
    		if pop > 0:
    			#Store each breed's move and birth rates in a dict in the model object.
    			#During the model we incremented model.movers and model.births each time one of these occurred.
    			setattr(model,'moverate'+breed, model.movers[breed]/pop)
    			setattr(model,'birthrate'+breed, model.births[breed]/pop)
    			#Reset the counters for the next period
    			model.movers[breed] = 0
    			model.births[breed] = 0
    for breed in heli.primitives['agent']['breeds']:'moveRate','moverate'+breed), smooth=0.98)'birthrate','birthrate'+breed), smooth=0.98)
  2. charwick

    Mar 22, 2020 at 20:15

    This example hooks modelPostStep to pause the model if all agents are dead.

    def modelPostStep(model):
    	if len(model.agents['agent']) == 0:
  3. Contribute a Note

    Your email address will not be published. Required fields are marked *

    You may use limited HTML for formatting. Please embed blocks of code in <pre><code> </code></pre> tags.