Inherited Classes
Mesa Base Model Class
Base class for models in the Mesa ABM library.
This class serves as a foundational structure for creating agent-based models. It includes the basic attributes and methods necessary for initializing and running a simulation model.
Attributes:
Name | Type | Description |
---|---|---|
running |
A boolean indicating if the model should continue running. |
|
schedule |
An object to manage the order and execution of agent steps. |
|
current_id |
A counter for assigning unique IDs to agents. |
|
agents_ |
defaultdict[type, dict]
|
A defaultdict mapping each agent type to a dict of its instances. This private attribute is used internally to manage agents. |
Properties
agents: An AgentSet containing all agents in the model, generated from the _agents attribute. agent_types: A list of different agent types present in the model.
Methods:
Name | Description |
---|---|
get_agents_of_type |
Returns an AgentSet of agents of the specified type. |
run_model |
Runs the model's simulation until a defined end condition is reached. |
step |
Executes a single step of the model's simulation process. |
next_id |
Generates and returns the next unique identifier for an agent. |
reset_randomizer |
Resets the model's random number generator with a new or existing seed. |
initialize_data_collector |
Sets up the data collector for the model, requiring an initialized scheduler and agents. |
Source code in mesa/model.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
|
agent_types
property
Return a list of different agent types.
agents
property
writable
Provides an AgentSet of all agents in the model, combining agents from all types.
__init__(*args, **kwargs)
Create a new model. Overload this method with the actual code to start the model. Always start with super().init() to initialize the model object properly.
Source code in mesa/model.py
66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
__new__(*args, **kwargs)
Create a new model object and instantiate its RNG automatically.
Source code in mesa/model.py
52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
get_agents_of_type(agenttype)
Retrieves an AgentSet containing all agents of the specified type.
Source code in mesa/model.py
107 108 109 |
|
next_id()
Return the next unique ID for agents, increment current_id
Source code in mesa/model.py
126 127 128 129 |
|
reset_randomizer(seed=None)
Reset the model random number generator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seed
|
int | None
|
A new seed for the RNG; if None, reset using the current seed |
None
|
Source code in mesa/model.py
131 132 133 134 135 136 137 138 139 140 141 |
|
run_model()
Run the model until the end condition is reached. Overload as needed.
Source code in mesa/model.py
111 112 113 114 115 116 |
|
step()
A single step. Fill in here.
Source code in mesa/model.py
118 119 |
|
---
Mesa Base Agent Class
Base class for a model agent in Mesa.
Attributes:
Name | Type | Description |
---|---|---|
unique_id |
int
|
A unique identifier for this agent. |
model |
Model
|
A reference to the model instance. |
self.pos |
Model
|
Position | None = None |
Source code in mesa/agent.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
|
__init__(unique_id, model)
Create a new agent.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
unique_id
|
int
|
A unique identifier for this agent. |
required |
model
|
Model
|
The model instance in which the agent exists. |
required |
Source code in mesa/agent.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
remove()
Remove and delete the agent from the model.
Source code in mesa/agent.py
67 68 69 70 |
|
step()
A single step of the agent.
Source code in mesa/agent.py
72 73 |
|