Overview
Agent Interactions
Interactions from params.classes.bond_types.acts_allowed
are implemented in standalone files that implement the interface from interactions.BaseInteraction
. This allows for the logic related to an interaction type to be consolidated into one place and make incorporating a new interaction type as simple as possible.
To add a new interaction:
- Add the param to
param.classes.bond_types.acts_allowed
- Add a file to
interactions/
which creates a class that is a sub-class ofBaseInteraction
- Implement the methods of
BaseInteraction
which are needed for this interaction - Not all methods are needed for all interactions (see below for details on the methods)
- Implement the methods of
- Re-export the feature from
interactions/__init__.py
- Add tests in
tests/interactions/
- Add it to the docs in
docs/api/interactions/
and to the nav inmkdocs.yml
The TITAN
class uses sub-classes of BaseInteraction
to initialize the object/call methods as appropriate.
BaseInteraction
name: str
Name of interaction in the params file.
interact(model, rel)
classmethod
Given a model and a relation, have the agents in the relationship interact for a time step.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
model.TITAN |
The running model |
required |
rel |
agent.Relationship |
The relationship where interaction is happening |
required |
Source code in titan/interactions/base_interaction.py
@classmethod
def interact(cls, model: "model.TITAN", rel: "agent.Relationship"):
"""
Given a model and a relation, have the agents in the relationship interact for a time step.
args:
model: The running model
rel: The relationship where interaction is happening
"""
num_acts = cls.get_num_acts(model, rel)
if num_acts < 1:
return
for exposure in model.exposures:
if model.time >= model.params[exposure.name].start_time:
exposure.expose(model, cls.name, rel, num_acts)