Skip to content

Commit 6ba22dc

Browse files
derkweijersjackiekazil
authored andcommitted
fix: make the tsp_graph argument non-required
1 parent 3fb4812 commit 6ba22dc

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

examples/aco_tsp/aco_tsp/model.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ def step(self):
151151
self._traveled_distance = 0
152152

153153

154+
# Don't create the TSPGraph.from_random as argument default: https://docs.astral.sh/ruff/rules/function-call-in-default-argument/
155+
TSP_GRAPH = TSPGraph.from_random(20)
156+
157+
154158
class AcoTspModel(mesa.Model):
155159
"""The model class holds the model-level attributes, manages the agents, and generally handles
156160
the global level of our model.
@@ -161,16 +165,12 @@ class AcoTspModel(mesa.Model):
161165

162166
def __init__(
163167
self,
164-
tsp_graph: TSPGraph | None,
165168
num_agents: int = 20,
166169
max_steps: int = int(1e6),
167170
ant_alpha: float = 1.0,
168171
ant_beta: float = 5.0,
172+
tsp_graph: TSPGraph = TSP_GRAPH,
169173
):
170-
# Don't create the TSPGraph.from_random as argument default: https://docs.astral.sh/ruff/rules/function-call-in-default-argument/
171-
if tsp_graph is None:
172-
tsp_graph = TSPGraph.from_random(20)
173-
174174
super().__init__()
175175
self.num_agents = num_agents
176176
self.tsp_graph = tsp_graph

0 commit comments

Comments
 (0)