A dict
-like container class for storing, retrieving, and manipulating agents. Agents can be accessed by primitive using the dict
index, i.e. model.agents['store']
will return a list of 'store'
-primitive agents. Individual agents can also be retrieved by ID by passing an int
to the dict
index, i.e. model.agents[12]
will return agent ID=12.
Each dict
key is a Primitive
object, which stores data on different types of agents, as well as the agents themselves. Primitives are ordered in the order set by the priority
argument of Agents.addPrimitive()
.
The Agents
object is stored in model.agents
, but should not be instantiated by user code.
Initialization Parameters
model — Helipad, required
The model object.
Methods
Click a method name for more detailed documentation.
addBreed( name, color, prim )
Registers an agent breed, useful for heterogeneity within agent primitives.
This function aliases
Breeds.add()
, but becauseBreeds
is instantiated inPrimitive.breeds
, this function can be used for convenience without specifying a primitive if the model only has one primitive, as in the default setup.addPrimitive( name, class, plural, … )
Registers an agent primitive. A primitive, like a breed, is a way of introducing heterogeneity into a model, but there are several differences.
- Breeds do not affect the order of stepping. All agents of a primitive are stepped before any agents of another (this order can be changed with the
priority
argument). - Breed is set as a property of the agent, which can be used with conditional logic in agent hooks. Building a primitive requires building a new agent class, which allows cleaner separation of logic where different types of agents behave in completely different ways.
- A use case of breeds would be different types of consumers. A use case of primitives would be consumers versus stores.
- Breeds do not affect the order of stepping. All agents of a primitive are stepped before any agents of another (this order can be changed with the
createNetwork( density, kind, prim )
Creates a random undirected and unweighted network of a certain density among agents.
This function can only be called once agents are created, so it will generally be called in the
modelPostSetup
hook.network( kind, prim )
Exports the model's graph structure to a NetworkX object; useful for further network analysis. Agent breed, primitive, and (if a spatial model) position are also stored as metadata.
removePrimitive( name )
Removes a previously added primitive. See also
Agents.addPrimitive()
.summary( var, prim, breed )
A function, generally used in the debug console, that prints summary statistics (length, mean, standard deviation, variance, maximum, minimum, and sum) for an agent property.
initialize( val, prim, model, … )
Creates and/or destroys agents to get a population number. This function is used as a setter function for agent population parameters, and also at the beginning of a model to create the initial agent set.
Object Properties
all — list[Object]
A flat list of all elements (
Agent
orEdge
) within theMultiDict
.Initial value: []
order — str|list[str]
Determines the order in which agents activate. Possible values are:
'random'
, which shuffles the list of agents before each stage'linear'
, which preserves the order of activation between periods.'match-n'
, which steps agents in groups ofn
and passes them to thematch
hook. Iforder=='match'
(without the-n
), agents will pair off at random (i.e.n==2
).
order
can also be set to a list of these values whose length corresponds to the number of stages, in order to use a different ordering in different stages of the model. Use theorder
hook for more complex ordering. Can be overridden on a per-primitive basis; see Agents.addPrimitive().Initial value: 'linear'
edges — dict{str: list[Edge]}
A collection of all active connections in the model, sorted by edge kind. Used to generate
Agents.network()
. A list of all edges of all types can be retrieved withAgents.edges.all
.Initial value: {}
charwick
Mar 24, 2020 at 3:24A few examples of retrieving agents:
charwick
Mar 28, 2020 at 1:52Agents.order=='random'
will shuffle agents at the beginning of every stage, not just the beginning of each period. To shuffle agents only at the beginning of each period and maintain step order within periods, only set the first stage to'random'
.