本文整理匯總了Python中mesa.space.MultiGrid.get_neighborhood方法的典型用法代碼示例。如果您正苦於以下問題:Python MultiGrid.get_neighborhood方法的具體用法?Python MultiGrid.get_neighborhood怎麽用?Python MultiGrid.get_neighborhood使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mesa.space.MultiGrid
的用法示例。
在下文中一共展示了MultiGrid.get_neighborhood方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestMultiGrid
# 需要導入模塊: from mesa.space import MultiGrid [as 別名]
# 或者: from mesa.space.MultiGrid import get_neighborhood [as 別名]
class TestMultiGrid(unittest.TestCase):
'''
Testing a toroidal MultiGrid
'''
torus = True
def setUp(self):
'''
Create a test non-toroidal grid and populate it with Mock Agents
'''
width = 3
height = 5
self.grid = MultiGrid(width, height, self.torus)
self.agents = []
counter = 0
for x in range(width):
for y in range(height):
for i in range(TEST_MULTIGRID[x][y]):
counter += 1
# Create and place the mock agent
a = MockAgent(counter, None)
self.agents.append(a)
self.grid.place_agent(a, (x, y))
def test_agent_positions(self):
'''
Ensure that the agents are all placed properly on the MultiGrid.
'''
for agent in self.agents:
x, y = agent.pos
assert agent in self.grid[x][y]
def test_neighbors(self):
'''
Test the toroidal MultiGrid neighborhood methods.
'''
neighborhood = self.grid.get_neighborhood((1, 1), moore=True)
assert len(neighborhood) == 8
neighborhood = self.grid.get_neighborhood((1, 4), moore=True)
assert len(neighborhood) == 8
neighborhood = self.grid.get_neighborhood((0, 0), moore=False)
assert len(neighborhood) == 4
neighbors = self.grid.get_neighbors((1, 4), moore=False)
assert len(neighbors) == 0
neighbors = self.grid.get_neighbors((1, 4), moore=True)
assert len(neighbors) == 5
neighbors = self.grid.get_neighbors((1, 1), moore=False,
include_center=True)
assert len(neighbors) == 7
neighbors = self.grid.get_neighbors((1, 3), moore=False, radius=2)
assert len(neighbors) == 11