diff --git a/benchmarks/Flocking/flocking.py b/benchmarks/Flocking/flocking.py index 352cacb84f4..025bd71cd5f 100644 --- a/benchmarks/Flocking/flocking.py +++ b/benchmarks/Flocking/flocking.py @@ -29,7 +29,6 @@ def __init__( self, unique_id, model, - pos, speed, direction, vision, @@ -43,7 +42,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. @@ -54,7 +52,6 @@ def __init__( """ super().__init__(unique_id, model) - self.pos = np.array(pos) self.speed = speed self.direction = direction self.vision = vision @@ -141,7 +138,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/tests/test_grid.py b/tests/test_grid.py index 686d8e78b59..b2500bbccb8 100644 --- a/tests/test_grid.py +++ b/tests/test_grid.py @@ -24,10 +24,10 @@ class MockAgent: Minimalistic agent for testing purposes. """ - def __init__(self, unique_id, pos): + def __init__(self, unique_id): self.random = random.Random(0) self.unique_id = unique_id - self.pos = pos + self.pos = None class TestSingleGrid(unittest.TestCase): @@ -53,7 +53,7 @@ def setUp(self): continue counter += 1 # Create and place the mock agent - a = MockAgent(counter, None) + a = MockAgent(counter) self.agents.append(a) self.grid.place_agent(a, (x, y)) @@ -258,7 +258,7 @@ def setUp(self): continue counter += 1 # Create and place the mock agent - a = MockAgent(counter, None) + a = MockAgent(counter) self.agents.append(a) self.grid.place_agent(a, (x, y)) self.num_agents = len(self.agents) @@ -270,7 +270,7 @@ def test_enforcement(self, mock_model): """ assert len(self.grid.empties) == 9 - a = MockAgent(100, None) + a = MockAgent(100) with self.assertRaises(Exception): self.grid.place_agent(a, (0, 1)) @@ -288,12 +288,12 @@ def test_enforcement(self, mock_model): # Place agents until the grid is full empty_cells = len(self.grid.empties) for i in range(empty_cells): - a = MockAgent(101 + i, None) + a = MockAgent(101 + i) self.grid.move_to_empty(a) self.num_agents += 1 assert len(self.grid.empties) == 0 - a = MockAgent(110, None) + a = MockAgent(110) with self.assertRaises(Exception): self.grid.move_to_empty(a) with self.assertRaises(Exception): @@ -334,7 +334,7 @@ def setUp(self): for _i in range(TEST_MULTIGRID[x][y]): counter += 1 # Create and place the mock agent - a = MockAgent(counter, None) + a = MockAgent(counter) self.agents.append(a) self.grid.place_agent(a, (x, y)) @@ -393,7 +393,7 @@ def setUp(self): continue counter += 1 # Create and place the mock agent - a = MockAgent(counter, None) + a = MockAgent(counter) self.agents.append(a) self.grid.place_agent(a, (x, y)) @@ -447,7 +447,7 @@ def setUp(self): continue counter += 1 # Create and place the mock agent - a = MockAgent(counter, None) + a = MockAgent(counter) self.agents.append(a) self.grid.place_agent(a, (x, y)) diff --git a/tests/test_space.py b/tests/test_space.py index aabdf98ba8d..23cf8c95450 100644 --- a/tests/test_space.py +++ b/tests/test_space.py @@ -42,7 +42,7 @@ def test_agents_add_many(self): """ positions = np.random.rand(TEST_AGENTS_PERF, 2) for i in range(TEST_AGENTS_PERF): - a = MockAgent(i, None) + a = MockAgent(i) pos = [positions[i, 0], positions[i, 1]] self.space.place_agent(a, pos) @@ -59,7 +59,7 @@ def setUp(self): self.space = ContinuousSpace(70, 20, True, -30, -30) self.agents = [] for i, pos in enumerate(TEST_AGENTS): - a = MockAgent(i, None) + a = MockAgent(i) self.agents.append(a) self.space.place_agent(a, pos) @@ -126,7 +126,7 @@ def test_bounds(self): """ boundary_agents = [] for i, pos in enumerate(OUTSIDE_POSITIONS): - a = MockAgent(len(self.agents) + i, None) + a = MockAgent(len(self.agents) + i) boundary_agents.append(a) self.space.place_agent(a, pos) @@ -152,7 +152,7 @@ def setUp(self): self.space = ContinuousSpace(70, 20, False, -30, -30) self.agents = [] for i, pos in enumerate(TEST_AGENTS): - a = MockAgent(i, None) + a = MockAgent(i) self.agents.append(a) self.space.place_agent(a, pos) @@ -208,7 +208,7 @@ def test_bounds(self): Test positions outside of boundary """ for i, pos in enumerate(OUTSIDE_POSITIONS): - a = MockAgent(len(self.agents) + i, None) + a = MockAgent(len(self.agents) + i) with self.assertRaises(Exception): self.space.place_agent(a, pos) @@ -231,7 +231,7 @@ def setUp(self): self.space = ContinuousSpace(70, 50, False, -30, -30) self.agents = [] for i, pos in enumerate(REMOVAL_TEST_AGENTS): - a = MockAgent(i, None) + a = MockAgent(i) self.agents.append(a) self.space.place_agent(a, pos) @@ -442,7 +442,7 @@ def setUp(self): self.space = SingleGrid(50, 50, False) self.agents = [] for i, pos in enumerate(TEST_AGENTS_GRID): - a = MockAgent(i, None) + a = MockAgent(i) self.agents.append(a) self.space.place_agent(a, pos) @@ -466,7 +466,7 @@ def test_remove_agent(self): def test_empty_cells(self): if self.space.exists_empty_cells(): for i, pos in enumerate(list(self.space.empties)): - a = MockAgent(-i, pos) + a = MockAgent(-i) self.space.place_agent(a, pos) with self.assertRaises(Exception): self.space.move_to_empty(a) @@ -551,7 +551,7 @@ def setUp(self): self.space = SingleGrid(50, 50, True) # Torus is True here self.agents = [] for i, pos in enumerate(TEST_AGENTS_GRID): - a = MockAgent(i, None) + a = MockAgent(i) self.agents.append(a) self.space.place_agent(a, pos) @@ -643,7 +643,7 @@ def test_get_empty_mask(self): self.assertTrue(np.all(empty_mask == np.ones((10, 10), dtype=bool))) def test_get_empty_mask_with_agent(self): - agent = MockAgent(0, self.grid) + agent = MockAgent(0) self.grid.place_agent(agent, (4, 6)) empty_mask = self.grid.empty_mask @@ -653,8 +653,8 @@ def test_get_empty_mask_with_agent(self): self.assertTrue(np.all(empty_mask == expected_mask)) def test_get_neighborhood_mask(self): - agent = MockAgent(0, self.grid) - agent2 = MockAgent(1, self.grid) + agent = MockAgent(0) + agent2 = MockAgent(1) self.grid.place_agent(agent, (5, 5)) self.grid.place_agent(agent2, (5, 6)) neighborhood_mask = self.grid.get_neighborhood_mask((5, 5), True, False, 1) @@ -680,7 +680,7 @@ def condition(x): self.assertTrue(selected_mask.all()) def test_move_agent_to_cell_by_properties(self): - agent = MockAgent(1, self.grid) + agent = MockAgent(1) self.grid.place_agent(agent, (5, 5)) conditions = {"layer1": lambda x: x == 0} target_cells = self.grid.select_cells(conditions) @@ -689,7 +689,7 @@ def test_move_agent_to_cell_by_properties(self): self.assertNotEqual(agent.pos, (5, 5)) def test_move_agent_no_eligible_cells(self): - agent = MockAgent(3, self.grid) + agent = MockAgent(3) self.grid.place_agent(agent, (5, 5)) conditions = {"layer1": lambda x: x != 0} target_cells = self.grid.select_cells(conditions) @@ -711,7 +711,7 @@ def test_select_extreme_value_cells_return_mask(self): self.assertTrue(target_mask[3, 1]) def test_move_agent_to_extreme_value_cell(self): - agent = MockAgent(2, self.grid) + agent = MockAgent(2) self.grid.place_agent(agent, (5, 5)) self.grid.properties["layer2"].set_cell((3, 1), 1.1) target_cells = self.grid.select_cells(extreme_values={"layer2": "highest"}) @@ -721,7 +721,7 @@ def test_move_agent_to_extreme_value_cell(self): # Test using masks def test_select_cells_by_properties_with_empty_mask(self): self.grid.place_agent( - MockAgent(0, self.grid), (5, 5) + MockAgent(0), (5, 5) ) # Placing an agent to ensure some cells are not empty empty_mask = self.grid.empty_mask @@ -755,10 +755,10 @@ def condition(x): self.assertCountEqual(selected_cells, expected_selection) def test_move_agent_to_cell_by_properties_with_empty_mask(self): - agent = MockAgent(1, self.grid) + agent = MockAgent(1) self.grid.place_agent(agent, (5, 5)) self.grid.place_agent( - MockAgent(2, self.grid), (4, 5) + MockAgent(2), (4, 5) ) # Placing another agent to create a non-empty cell empty_mask = self.grid.empty_mask conditions = {"layer1": lambda x: x == 0} @@ -769,7 +769,7 @@ def test_move_agent_to_cell_by_properties_with_empty_mask(self): ) # Agent should not move to (4, 5) as it's not empty def test_move_agent_to_cell_by_properties_with_neighborhood_mask(self): - agent = MockAgent(1, self.grid) + agent = MockAgent(1) self.grid.place_agent(agent, (5, 5)) neighborhood_mask = self.grid.get_neighborhood_mask((5, 5), True, False, 1) conditions = {"layer1": lambda x: x == 0} @@ -789,7 +789,7 @@ def condition(x): # Test if coordinates means the same between the grid and the property layer def test_property_layer_coordinates(self): - agent = MockAgent(0, self.grid) + agent = MockAgent(0) correct_pos = (1, 8) incorrect_pos = (8, 1) self.grid.place_agent(agent, correct_pos) @@ -811,14 +811,14 @@ def test_property_layer_coordinates(self): # Test selecting cells with only_empty parameter def test_select_cells_only_empty(self): - self.grid.place_agent(MockAgent(0, self.grid), (5, 5)) # Occupying a cell + self.grid.place_agent(MockAgent(0), (5, 5)) # Occupying a cell selected_cells = self.grid.select_cells(only_empty=True) self.assertNotIn( (5, 5), selected_cells ) # The occupied cell should not be selected def test_select_cells_only_empty_with_conditions(self): - self.grid.place_agent(MockAgent(1, self.grid), (5, 5)) + self.grid.place_agent(MockAgent(1), (5, 5)) self.grid.properties["layer1"].set_cell((5, 5), 2) self.grid.properties["layer1"].set_cell((6, 6), 2) @@ -855,7 +855,7 @@ def setUp(self): self.space = NetworkGrid(G) self.agents = [] for i, pos in enumerate(TEST_AGENTS_NETWORK_SINGLE): - a = MockAgent(i, None) + a = MockAgent(i) self.agents.append(a) self.space.place_agent(a, pos) @@ -968,7 +968,7 @@ def setUp(self): self.space = NetworkGrid(G) self.agents = [] for i, pos in enumerate(TEST_AGENTS_NETWORK_MULTIPLE): - a = MockAgent(i, None) + a = MockAgent(i) self.agents.append(a) self.space.place_agent(a, pos)