Skip to content

Commit

Permalink
Add super().__init__() in model.__init__()
Browse files Browse the repository at this point in the history
  • Loading branch information
rht committed Jan 11, 2024
1 parent b0ac96c commit 5156977
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/bank_reserves/bank_reserves/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def __init__(
rich_threshold=10,
reserve_percent=50,
):
super().__init__()
self.height = height
self.width = width
self.init_people = init_people
Expand Down
1 change: 1 addition & 0 deletions examples/boid_flockers/boid_flockers/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(
keep from any other
cohere, separate, match: factors for the relative importance of
the three drives."""
super().__init__()
self.population = population
self.vision = vision
self.speed = speed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class BoltzmannWealthModel(mesa.Model):
"""

def __init__(self, N=100, width=10, height=10):
super().__init__()
self.num_agents = N
self.grid = mesa.space.MultiGrid(width, height, True)
self.schedule = mesa.time.RandomActivation(self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class BoltzmannWealthModelNetwork(mesa.Model):
"""A model with some number of agents."""

def __init__(self, num_agents=7, num_nodes=10):
super().__init__()
self.num_agents = num_agents
self.num_nodes = num_nodes if num_nodes >= self.num_agents else self.num_agents
self.G = nx.erdos_renyi_graph(n=self.num_nodes, p=0.5)
Expand Down
1 change: 1 addition & 0 deletions examples/charts/charts/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def __init__(
rich_threshold=10,
reserve_percent=50,
):
super().__init__()
self.height = height
self.width = width
self.init_people = init_people
Expand Down
2 changes: 1 addition & 1 deletion examples/color_patches/color_patches/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def __init__(self, width=20, height=20):
Create a 2D lattice with strict borders where agents live
The agents next state is first determined before updating the grid
"""

super().__init__()
self._grid = mesa.space.SingleGrid(width, height, torus=False)
self._schedule = mesa.time.SimultaneousActivation(self)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self, width=50, height=50):
"""
Create a new playing area of (width, height) cells.
"""
super().__init__()

# Set up the grid and schedule.

Expand Down
1 change: 1 addition & 0 deletions examples/el_farol/el_farol/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def __init__(
height=100,
N=100,
):
super().__init__()
self.running = True
self.num_agents = N
self.schedule = mesa.time.RandomActivation(self)
Expand Down
1 change: 1 addition & 0 deletions examples/forest_fire/forest_fire/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def __init__(self, width=100, height=100, density=0.65):
width, height: The size of the grid to model
density: What fraction of grid cells have a tree in them.
"""
super().__init__()
# Set up model objects
self.schedule = mesa.time.RandomActivation(self)
self.grid = mesa.space.SingleGrid(width, height, torus=False)
Expand Down
2 changes: 1 addition & 1 deletion examples/hex_snowflake/hex_snowflake/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def __init__(self, width=50, height=50):
"""
Create a new playing area of (width, height) cells.
"""

super().__init__()
# Set up the grid and schedule.

# Use SimultaneousActivation which simulates all the cells
Expand Down
1 change: 1 addition & 0 deletions examples/pd_grid/pd_grid/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(
Determines the agent activation regime.
payoffs: (optional) Dictionary of (move, neighbor_move) payoffs.
"""
super().__init__()
self.grid = mesa.space.SingleGrid(width, height, torus=True)
self.schedule_type = schedule_type
self.schedule = self.schedule_types[self.schedule_type](self)
Expand Down
3 changes: 1 addition & 2 deletions examples/schelling/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class Schelling(mesa.Model):
"""

def __init__(self, width=20, height=20, density=0.8, minority_pc=0.2, homophily=3):
""" """

super().__init__()
self.width = width
self.height = height
self.density = density
Expand Down
1 change: 1 addition & 0 deletions examples/shape_example/shape_example/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def __init__(self, unique_id, model, pos, heading=(1, 0)):

class ShapeExample(mesa.Model):
def __init__(self, N=2, width=20, height=10):
super().__init__()
self.N = N # num of agents
self.headings = ((1, 0), (0, 1), (-1, 0), (0, -1)) # tuples are fast
self.grid = mesa.space.SingleGrid(width, height, torus=False)
Expand Down
1 change: 1 addition & 0 deletions examples/sugarscape_cg/sugarscape_cg/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def __init__(self, width=50, height=50, initial_population=100):
Args:
initial_population: Number of population to start with
"""
super().__init__()

# Set parameters
self.width = width
Expand Down
1 change: 1 addition & 0 deletions examples/sugarscape_g1mt/sugarscape_g1mt/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def __init__(
vision_max=5,
enable_trade=True,
):
super().__init__()
# Initiate width and heigh of sugarscape
self.width = width
self.height = height
Expand Down
1 change: 1 addition & 0 deletions examples/virus_on_network/virus_on_network/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def __init__(
recovery_chance=0.3,
gain_resistance_chance=0.5,
):
super().__init__()
self.num_nodes = num_nodes
prob = avg_node_degree / self.num_nodes
self.G = nx.erdos_renyi_graph(n=self.num_nodes, p=prob)
Expand Down

0 comments on commit 5156977

Please sign in to comment.