diff --git a/examples/boid_flockers/boid_flockers/model.py b/examples/boid_flockers/boid_flockers/model.py index 6ebbf8aa..8ddfc11a 100644 --- a/examples/boid_flockers/boid_flockers/model.py +++ b/examples/boid_flockers/boid_flockers/model.py @@ -28,7 +28,6 @@ def __init__( self, unique_id, model, - pos, speed, direction, vision, @@ -42,7 +41,6 @@ def __init__( Args: unique_id: Unique agent identifier. - pos: Starting position speed: Distance to move per step. direction: numpy vector for the Boid's direction of movement. vision: Radius to look around for nearby Boids. @@ -52,7 +50,6 @@ def __init__( match: the relative importance of matching neighbors' headings """ super().__init__(unique_id, model) - self.pos = np.array(pos) self.speed = speed self.direction = direction self.vision = vision @@ -140,7 +137,6 @@ def make_agents(self): boid = Boid( unique_id=i, model=self, - pos=pos, speed=self.speed, direction=direction, vision=self.vision, diff --git a/examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/server.py b/examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/server.py index fce6b4cd..50a019ce 100644 --- a/examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/server.py +++ b/examples/boltzmann_wealth_model_network/boltzmann_wealth_model_network/server.py @@ -12,9 +12,11 @@ def network_portrayal(G): "id": node_id, "size": 3 if agents else 1, "color": "#CC0000" if not agents or agents[0].wealth == 0 else "#007959", - "label": None - if not agents - else f"Agent:{agents[0].unique_id} Wealth:{agents[0].wealth}", + "label": ( + None + if not agents + else f"Agent:{agents[0].unique_id} Wealth:{agents[0].wealth}" + ), } for (node_id, agents) in G.nodes.data("agent") ] diff --git a/examples/color_patches/color_patches/server.py b/examples/color_patches/color_patches/server.py index aa52332e..34d0d744 100644 --- a/examples/color_patches/color_patches/server.py +++ b/examples/color_patches/color_patches/server.py @@ -2,6 +2,7 @@ handles the definition of the canvas parameters and the drawing of the model representation on the canvas """ + # import webbrowser import mesa diff --git a/examples/forest_fire/forest_fire/agent.py b/examples/forest_fire/forest_fire/agent.py index 34ff2aa2..4837119c 100644 --- a/examples/forest_fire/forest_fire/agent.py +++ b/examples/forest_fire/forest_fire/agent.py @@ -14,15 +14,14 @@ class TreeCell(mesa.Agent): practice to give one to each agent anyway. """ - def __init__(self, pos, model): + def __init__(self, unique_id, model): """ Create a new tree. Args: - pos: The tree's coordinates on the grid. + unique_id: Unique identifier for the agent. model: standard model reference for agent. """ - super().__init__(pos, model) - self.pos = pos + super().__init__(unique_id, model) self.condition = "Fine" def step(self): diff --git a/examples/forest_fire/forest_fire/model.py b/examples/forest_fire/forest_fire/model.py index 843176b7..4b2d5b41 100644 --- a/examples/forest_fire/forest_fire/model.py +++ b/examples/forest_fire/forest_fire/model.py @@ -33,7 +33,7 @@ def __init__(self, width=100, height=100, density=0.65): for contents, (x, y) in self.grid.coord_iter(): if self.random.random() < density: # Create a tree - new_tree = TreeCell((x, y), self) + new_tree = TreeCell(self.next_id(), self) # Set all trees in the first column on fire. if x == 0: new_tree.condition = "On Fire" diff --git a/examples/pd_grid/pd_grid/agent.py b/examples/pd_grid/pd_grid/agent.py index e289169f..d658ddc8 100644 --- a/examples/pd_grid/pd_grid/agent.py +++ b/examples/pd_grid/pd_grid/agent.py @@ -4,18 +4,17 @@ class PDAgent(mesa.Agent): """Agent member of the iterated, spatial prisoner's dilemma model.""" - def __init__(self, pos, model, starting_move=None): + def __init__(self, unique_id, model, starting_move=None): """ Create a new Prisoner's Dilemma agent. Args: - pos: (x, y) tuple of the agent's position. + unique_id: Unique identifier for the agent. model: model instance starting_move: If provided, determines the agent's initial state: C(ooperating) or D(efecting). Otherwise, random. """ - super().__init__(pos, model) - self.pos = pos + super().__init__(unique_id, model) self.score = 0 if starting_move: self.move = starting_move diff --git a/examples/pd_grid/pd_grid/model.py b/examples/pd_grid/pd_grid/model.py index b970c0f4..448e4745 100644 --- a/examples/pd_grid/pd_grid/model.py +++ b/examples/pd_grid/pd_grid/model.py @@ -37,7 +37,7 @@ def __init__( # Create agents for x in range(width): for y in range(height): - agent = PDAgent((x, y), self) + agent = PDAgent(self.next_id(), self) self.grid.place_agent(agent, (x, y)) self.schedule.add(agent) diff --git a/examples/schelling_experimental/model.py b/examples/schelling_experimental/model.py index c91b034a..a5e05de5 100644 --- a/examples/schelling_experimental/model.py +++ b/examples/schelling_experimental/model.py @@ -6,17 +6,15 @@ class SchellingAgent(mesa.Agent): Schelling segregation agent """ - def __init__(self, pos, model, agent_type): + def __init__(self, unique_id, model, agent_type): """ Create a new Schelling agent. Args: unique_id: Unique identifier for the agent. - pos: Agent initial location. agent_type: Indicator for the agent's type (minority=1, majority=0) """ - super().__init__(pos, model) - self.pos = pos + super().__init__(unique_id, model) self.type = agent_type def step(self): @@ -57,7 +55,7 @@ def __init__(self, width=20, height=20, density=0.8, minority_pc=0.2, homophily= for _, pos in self.grid.coord_iter(): if self.random.random() < density: agent_type = 1 if self.random.random() < minority_pc else 0 - agent = SchellingAgent(pos, self, agent_type) + agent = SchellingAgent(self.next_id(), self, agent_type) self.grid.place_agent(agent, pos) self.datacollector.collect(self) diff --git a/examples/sugarscape_cg/sugarscape_cg/agents.py b/examples/sugarscape_cg/sugarscape_cg/agents.py index 6e245eaa..de5f65c7 100644 --- a/examples/sugarscape_cg/sugarscape_cg/agents.py +++ b/examples/sugarscape_cg/sugarscape_cg/agents.py @@ -17,11 +17,8 @@ def get_distance(pos_1, pos_2): class SsAgent(mesa.Agent): - def __init__( - self, unique_id, pos, model, moore=False, sugar=0, metabolism=0, vision=0 - ): + def __init__(self, unique_id, model, moore=False, sugar=0, metabolism=0, vision=0): super().__init__(unique_id, model) - self.pos = pos self.moore = moore self.sugar = sugar self.metabolism = metabolism @@ -74,7 +71,7 @@ def step(self): class Sugar(mesa.Agent): - def __init__(self, unique_id, pos, model, max_sugar): + def __init__(self, unique_id, model, max_sugar): super().__init__(unique_id, model) self.amount = max_sugar self.max_sugar = max_sugar diff --git a/examples/sugarscape_cg/sugarscape_cg/model.py b/examples/sugarscape_cg/sugarscape_cg/model.py index e1857cb0..3aaa250d 100644 --- a/examples/sugarscape_cg/sugarscape_cg/model.py +++ b/examples/sugarscape_cg/sugarscape_cg/model.py @@ -50,7 +50,7 @@ def __init__(self, width=50, height=50, initial_population=100): agent_id = 0 for _, (x, y) in self.grid.coord_iter(): max_sugar = sugar_distribution[x, y] - sugar = Sugar(agent_id, (x, y), self, max_sugar) + sugar = Sugar(agent_id, self, max_sugar) agent_id += 1 self.grid.place_agent(sugar, (x, y)) self.schedule.add(sugar) @@ -62,7 +62,7 @@ def __init__(self, width=50, height=50, initial_population=100): sugar = self.random.randrange(6, 25) metabolism = self.random.randrange(2, 4) vision = self.random.randrange(1, 6) - ssa = SsAgent(agent_id, (x, y), self, False, sugar, metabolism, vision) + ssa = SsAgent(agent_id, self, False, sugar, metabolism, vision) agent_id += 1 self.grid.place_agent(ssa, (x, y)) self.schedule.add(ssa) diff --git a/examples/sugarscape_g1mt/sugarscape_g1mt/model.py b/examples/sugarscape_g1mt/sugarscape_g1mt/model.py index f88f1c2c..3500b0c2 100644 --- a/examples/sugarscape_g1mt/sugarscape_g1mt/model.py +++ b/examples/sugarscape_g1mt/sugarscape_g1mt/model.py @@ -97,7 +97,7 @@ def __init__( for _, (x, y) in self.grid.coord_iter(): max_sugar = sugar_distribution[x, y] max_spice = spice_distribution[x, y] - resource = Resource(agent_id, self, (x, y), max_sugar, max_spice) + resource = Resource(agent_id, self, max_sugar, max_spice) self.schedule.add(resource) self.grid.place_agent(resource, (x, y)) agent_id += 1 @@ -123,7 +123,6 @@ def __init__( trader = Trader( agent_id, self, - (x, y), moore=False, sugar=sugar, spice=spice, diff --git a/examples/sugarscape_g1mt/sugarscape_g1mt/resource_agents.py b/examples/sugarscape_g1mt/sugarscape_g1mt/resource_agents.py index 18d11cd6..2be75de7 100644 --- a/examples/sugarscape_g1mt/sugarscape_g1mt/resource_agents.py +++ b/examples/sugarscape_g1mt/sugarscape_g1mt/resource_agents.py @@ -9,9 +9,8 @@ class Resource(mesa.Agent): - grows 1 amount of spice at each turn """ - def __init__(self, unique_id, model, pos, max_sugar, max_spice): + def __init__(self, unique_id, model, max_sugar, max_spice): super().__init__(unique_id, model) - self.pos = pos self.sugar_amount = max_sugar self.max_sugar = max_sugar self.spice_amount = max_spice diff --git a/examples/sugarscape_g1mt/sugarscape_g1mt/trader_agents.py b/examples/sugarscape_g1mt/sugarscape_g1mt/trader_agents.py index 96bc8c5b..4ddb4d38 100644 --- a/examples/sugarscape_g1mt/sugarscape_g1mt/trader_agents.py +++ b/examples/sugarscape_g1mt/sugarscape_g1mt/trader_agents.py @@ -31,7 +31,6 @@ def __init__( self, unique_id, model, - pos, moore=False, sugar=0, spice=0, @@ -40,7 +39,6 @@ def __init__( vision=0, ): super().__init__(unique_id, model) - self.pos = pos self.moore = moore self.sugar = sugar self.spice = spice diff --git a/examples/wolf_sheep/wolf_sheep/agents.py b/examples/wolf_sheep/wolf_sheep/agents.py index 460c4abb..6d73e113 100644 --- a/examples/wolf_sheep/wolf_sheep/agents.py +++ b/examples/wolf_sheep/wolf_sheep/agents.py @@ -12,8 +12,8 @@ class Sheep(RandomWalker): energy = None - def __init__(self, unique_id, pos, model, moore, energy=None): - super().__init__(unique_id, pos, model, moore=moore) + def __init__(self, unique_id, model, moore, energy=None): + super().__init__(unique_id, model, moore=moore) self.energy = energy def step(self): @@ -44,9 +44,7 @@ def step(self): # Create a new sheep: if self.model.grass: self.energy /= 2 - lamb = Sheep( - self.model.next_id(), self.pos, self.model, self.moore, self.energy - ) + lamb = Sheep(self.model.next_id(), self.model, self.moore, self.energy) self.model.grid.place_agent(lamb, self.pos) self.model.schedule.add(lamb) @@ -58,8 +56,8 @@ class Wolf(RandomWalker): energy = None - def __init__(self, unique_id, pos, model, moore, energy=None): - super().__init__(unique_id, pos, model, moore=moore) + def __init__(self, unique_id, model, moore, energy=None): + super().__init__(unique_id, model, moore=moore) self.energy = energy def step(self): @@ -86,10 +84,8 @@ def step(self): if self.random.random() < self.model.wolf_reproduce: # Create a new wolf cub self.energy /= 2 - cub = Wolf( - self.model.next_id(), self.pos, self.model, self.moore, self.energy - ) - self.model.grid.place_agent(cub, cub.pos) + cub = Wolf(self.model.next_id(), self.model, self.moore, self.energy) + self.model.grid.place_agent(cub, self.pos) self.model.schedule.add(cub) @@ -98,7 +94,7 @@ class GrassPatch(mesa.Agent): A patch of grass that grows at a fixed rate and it is eaten by sheep """ - def __init__(self, unique_id, pos, model, fully_grown, countdown): + def __init__(self, unique_id, model, fully_grown, countdown): """ Creates a new patch of grass @@ -109,7 +105,6 @@ def __init__(self, unique_id, pos, model, fully_grown, countdown): super().__init__(unique_id, model) self.fully_grown = fully_grown self.countdown = countdown - self.pos = pos def step(self): if not self.fully_grown: diff --git a/examples/wolf_sheep/wolf_sheep/model.py b/examples/wolf_sheep/wolf_sheep/model.py index 2626f958..48128d00 100644 --- a/examples/wolf_sheep/wolf_sheep/model.py +++ b/examples/wolf_sheep/wolf_sheep/model.py @@ -98,7 +98,7 @@ def __init__( x = self.random.randrange(self.width) y = self.random.randrange(self.height) energy = self.random.randrange(2 * self.sheep_gain_from_food) - sheep = Sheep(self.next_id(), (x, y), self, True, energy) + sheep = Sheep(self.next_id(), self, True, energy) self.grid.place_agent(sheep, (x, y)) self.schedule.add(sheep) @@ -107,7 +107,7 @@ def __init__( x = self.random.randrange(self.width) y = self.random.randrange(self.height) energy = self.random.randrange(2 * self.wolf_gain_from_food) - wolf = Wolf(self.next_id(), (x, y), self, True, energy) + wolf = Wolf(self.next_id(), self, True, energy) self.grid.place_agent(wolf, (x, y)) self.schedule.add(wolf) @@ -121,7 +121,7 @@ def __init__( else: countdown = self.random.randrange(self.grass_regrowth_time) - patch = GrassPatch(self.next_id(), (x, y), self, fully_grown, countdown) + patch = GrassPatch(self.next_id(), self, fully_grown, countdown) self.grid.place_agent(patch, (x, y)) self.schedule.add(patch) diff --git a/examples/wolf_sheep/wolf_sheep/random_walk.py b/examples/wolf_sheep/wolf_sheep/random_walk.py index 49219fa7..920ae08c 100644 --- a/examples/wolf_sheep/wolf_sheep/random_walk.py +++ b/examples/wolf_sheep/wolf_sheep/random_walk.py @@ -18,7 +18,7 @@ class RandomWalker(mesa.Agent): y = None moore = True - def __init__(self, unique_id, pos, model, moore=True): + def __init__(self, unique_id, model, moore=True): """ grid: The MultiGrid object in which the agent lives. x: The agent's current x coordinate @@ -27,7 +27,6 @@ def __init__(self, unique_id, pos, model, moore=True): Otherwise, only up, down, left, right. """ super().__init__(unique_id, model) - self.pos = pos self.moore = moore def random_move(self):