Reference 〉 Hook

modelPostStep(modelHelipad)

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)

    @heli.hook
    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']:
    	heli.data.addReporter(breed+'moveRate', heli.data.modelReporter('moverate'+breed), smooth=0.98)
    	heli.data.addReporter(breed+'birthrate', heli.data.modelReporter('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.

    @heli.hook
    def modelPostStep(model):
    	if len(model.agents['agent']) == 0:
    		model.stop()
  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.