本文整理汇总了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