Reference 〉 Hook

decideBreed(idint, breedslist[str], modelHelipad)

By default, Helipad creates agents with equiproportional breeds, cycling through the list of registered breeds as it creates agents of a specific primitive. decideBreed allows the user to specify a function to determine which breed agents should be assigned when initialized. The hook runs only during the creation of parentless agents, i.e. when agents are initialized at the beginning of the model and when agents are created via the population control panel slider. It does not run when agents reproduce, as the breed is inherited from the primary parent by default.

The decideBreed hook will run every time a parentless agent of any primitive is created. There are corresponding primitive-specific hooks [primitive]DecideBreed for a more narrow focus, e.g. bankDecideBreed will only run for a bank primitive. See Agents.addPrimitive().

Required Parameters

  • id int

    The globally unique ID assigned to the agent. See Agent().__init__().

  • breeds list[str]

    A list of breed names corresponding to the primitive of the agent being initialized. See model.addBreed().

  • model Helipad

    The model object.

Expected Return Value str

The breed to assign to the agent in question. Return value must be the name of a previously registered breed, or the function will raise a ValueError. The function can return None in which case Helipad will assign a breed using the default alternating logic.

Notes and Examples

  1. charwick

    Mar 22, 2020 at 21:29

    In this model there are two breeds, 'urban' and 'rural', but we want the model to begin with all rural agents.

    heli.agents.addBreed('urban', 'CC0000')
    heli.agents.addBreed('rural', '00CC00')
    
    @heli.hook
    def decideBreed(id, breeds, model):
    	return 'rural';

    Or if we wanted to randomize breed assignment without worrying about strict equiproportionality,

    from random import choice
    
    @heli.hook
    def decideBreed(id, breeds, model):
    	return choice(breeds);
  2. 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.