Reference 〉 Hook

order(agentAgent, modelHelipad, stageint)

Helipad allows the order of agent activation to be specified globally as either 'random' or 'linear'. This hook allows more complex ordering to be specified both globally and on a per-primitive basis.

This hook generates a key function for use in list.sort(). The list of agents will be sorted by the value returned from this function, and activated in that order.

The order hook will run once per primitive per stage. Corresponding per-primitive hooks are also available on the pattern [primitive]Order, e.g. bankOrder would apply to the ordering of a 'bank' primitive. See Agents.addPrimitive().

Required Parameters

  • agent Agent

    An Agent object to be sorted.

  • model Helipad

    The model object.

  • stage int

    The current stage of the model.

Expected Return Value num|str

An ordinal value by which the agent in question should be sorted.

Notes and Examples

  1. charwick

    Mar 26, 2020 at 21:44

    This example sorts agents by the amount of status they possess, in reverse so agents with high status go first.

    @heli.hook
    def order(agent, model, stage):
    	return -agent.stocks['status']
  2. charwick

    Mar 26, 2020 at 21:49

    Returning the same value for all agents leaves the list order unchanged. This example sorts 'store'-primitive agents by ID, but only in the second stage.

    @heli.hook
    def storeOrder(agent, model, stage):
    	if stage == 2:
    		return agent.id
    	else: return 1
  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.

History