schelling2.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:cess 作者: frnsys 项目源码 文件源码
def __init__(self, agents, width, height):
        super().__init__(agents)

        if len(agents) > width * height:
            raise Exception('there must be enough space for all agents')

        # seutp grid
        self.space = nx.grid_2d_graph(width, height)
        self.width = width
        self.height = height

        # place agents
        positions = self.space.nodes()
        random.shuffle(positions)
        for agent in self.agents:
            pos = positions.pop()
            self.sync(self.place(agent, pos))

        # setup vacant positions
        for pos in positions:
            self.space.node[pos] = {'agent': None}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号