1717from mesa .agent import Agent , AgentSet
1818from mesa .datacollection import DataCollector
1919
20- TimeT = float | int
21-
2220
2321class Model :
2422 """Base class for models in the Mesa ABM library.
@@ -35,6 +33,8 @@ class Model:
3533 Properties:
3634 agents: An AgentSet containing all agents in the model
3735 agent_types: A list of different agent types present in the model.
36+ steps: An integer representing the number of steps the model has taken.
37+ It increases automatically at the start of each step() call.
3838
3939 Methods:
4040 get_agents_of_type: Returns an AgentSet of agents of the specified type.
@@ -62,10 +62,6 @@ def __new__(cls, *args: Any, **kwargs: Any) -> Any:
6262 # advance.
6363 obj ._seed = random .random ()
6464 obj .random = random .Random (obj ._seed )
65-
66- # TODO: Remove these 2 lines just before Mesa 3.0
67- obj ._steps = 0
68- obj ._time = 0
6965 return obj
7066
7167 def __init__ (self , * args : Any , ** kwargs : Any ) -> None :
@@ -77,25 +73,20 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
7773 self .running = True
7874 self .schedule = None
7975 self .current_id = 0
76+ self .steps : int = 0
8077
8178 self ._setup_agent_registration ()
8279
83- self ._steps : int = 0
84- self ._time : TimeT = 0 # the model's clock
85-
8680 # Wrap the user-defined step method
87- if hasattr (self , "step" ):
88- self ._user_step = self .step
89- self .step = self ._wrapped_step
81+ self ._user_step = self .step
82+ self .step = self ._wrapped_step
9083
9184 def _wrapped_step (self , * args : Any , ** kwargs : Any ) -> None :
9285 """Automatically increments time and steps after calling the user's step method."""
9386 # Automatically increment time and step counters
94- self ._time += kwargs .get ("time" , 1 )
95- self ._steps += kwargs .get ("step" , 1 )
87+ self .steps += 1
9688 # Call the original user-defined step method
97- if self ._user_step :
98- self ._user_step (* args , ** kwargs )
89+ self ._user_step (* args , ** kwargs )
9990
10091 @property
10192 def agents (self ) -> AgentSet :
0 commit comments