1818from mesa .agent import Agent , AgentSet
1919from mesa .datacollection import DataCollector
2020
21- TimeT = float | int
22-
2321
2422class Model :
2523 """Base class for models in the Mesa ABM library.
@@ -38,6 +36,8 @@ class Model:
3836 Properties:
3937 agents: An AgentSet containing all agents in the model, generated from the _agents attribute.
4038 agent_types: A list of different agent types present in the model.
39+ steps: An integer representing the number of steps the model has taken.
40+ It increases automatically at the start of each step() call.
4141
4242 Methods:
4343 get_agents_of_type: Returns an AgentSet of agents of the specified type.
@@ -57,9 +57,6 @@ def __new__(cls, *args: Any, **kwargs: Any) -> Any:
5757 # advance.
5858 obj ._seed = random .random ()
5959 obj .random = random .Random (obj ._seed )
60- # TODO: Remove these 2 lines just before Mesa 3.0
61- obj ._steps = 0
62- obj ._time = 0
6360 return obj
6461
6562 def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
@@ -72,23 +69,18 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
7269 self .schedule = None
7370 self .current_id = 0
7471 self .agents_ : defaultdict [type , dict ] = defaultdict (dict )
75-
76- self ._steps : int = 0
77- self ._time : TimeT = 0 # the model's clock
72+ self .steps : int = 0
7873
7974 # Wrap the user-defined step method
80- if hasattr (self , "step" ):
81- self ._user_step = self .step
82- self .step = self ._wrapped_step
75+ self ._user_step = self .step
76+ self .step = self ._wrapped_step
8377
8478 def _wrapped_step (self , * args : Any , ** kwargs : Any ) -> None :
8579 """Automatically increments time and steps after calling the user's step method."""
8680 # Automatically increment time and step counters
87- self ._time += kwargs .get ("time" , 1 )
88- self ._steps += kwargs .get ("step" , 1 )
81+ self .steps += 1
8982 # Call the original user-defined step method
90- if self ._user_step :
91- self ._user_step (* args , ** kwargs )
83+ self ._user_step (* args , ** kwargs )
9284
9385 @property
9486 def agents (self ) -> AgentSet :
0 commit comments