Base Classes#
- class Agent(unique_id: int, model: Model)[source]#
Base class for a model agent in Mesa.
- Attributes:
unique_id (int): A unique identifier for this agent. model (Model): A reference to the model instance. self.pos: Position | None = None
Create a new agent.
- Args:
unique_id (int): A unique identifier for this agent. model (Model): The model instance in which the agent exists.
- class Model(*args: Any, **kwargs: Any)[source]#
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:
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_: 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:
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.
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.
- property agents: AgentSet#
Provides an AgentSet of all agents in the model, combining agents from all types.