Model#

class mesa_frames.Model(seed: int | Sequence[int] | None = None)[source]#

Base class for models in the mesa-frames 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.

Methods:

__init__

Create a new model.

get_sets_of_type

Retrieve the AgentSet of a specified type.

reset_randomizer

Reset the model random number generator.

run_model

Run the model until the end condition is reached.

step

Run a single step.

Attributes:

steps

Get the current step count.

sets

Get the AgentSetRegistry object containing all agent sets in the model.

set_types

Get a list of different agent set types present in the model.

space

Get the space object associated with the model.

__init__(seed: int | Sequence[int] | None = None) None[source]#

Create a new model.

Overload this method with the actual code to start the model. Always start with super().__init__(seed) to initialize the model object properly.

Parameters:

seed (int | Sequence[int] | None, optional) – The seed for the model’s generator

get_sets_of_type(agent_type: type) AgentSet[source]#

Retrieve the AgentSet of a specified type.

Parameters:

agent_type (type) – The type of AgentSet to retrieve.

Returns:

The AgentSet of the specified type.

Return type:

AgentSet

reset_randomizer(seed: int | Sequence[int] | None) None[source]#

Reset the model random number generator.

Parameters:

seed (int | Sequence[int] | None) – A new seed for the RNG; if None, reset using the current seed

run_model() None[source]#

Run the model until the end condition is reached.

Overload as needed.

step() None[source]#

Run a single step.

The default method calls the step() method of all agents. Overload as needed.

property steps: int#

Get the current step count.

Returns:

The current step count of the model.

Return type:

int

property sets: AgentSetRegistry#

Get the AgentSetRegistry object containing all agent sets in the model.

Returns:

The AgentSetRegistry object containing all agent sets in the model.

Return type:

AgentSetRegistry

Raises:

ValueError – If the model has not been initialized properly with super().__init__().

property set_types: list[type]#

Get a list of different agent set types present in the model.

Returns:

A list of the different agent set types present in the model.

Return type:

list[type]

property space: Space#

Get the space object associated with the model.

Returns:

The space object associated with the model.

Return type:

Space

Raises:

ValueError – If the space has not been set for the model.