python类grid_2d_graph()的实例源码

schelling2.py 文件源码 项目:cess 作者: frnsys 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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}
schelling.py 文件源码 项目:cess 作者: frnsys 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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)

        # 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}
synctools_v0.py 文件源码 项目:delayCoupledDPLLnet 作者: cuichi23 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def get_couling_derivate_matrix(self, h, twist_number, s):
        if type(twist_number) == InPhase or type(twist_number) == Twist2D:
            if type(twist_number) == InPhase:
                mx = 0
                my = 0
            else:
                mx = twist_number.get_mx()
                my = twist_number.get_my()
            dhdx = h.get_derivative()
            dphi_x = (2 * np.pi * mx) / self.nx
            dphi_y = (2 * np.pi * my) / self.nx

            g = networkx.grid_2d_graph(self.ny, self.nx, periodic=True)
            g = networkx.convert_node_labels_to_integers(g, ordering='sorted')
            c = _networkx2mat(g, self.n)
            a = _build_2d_dhdx_matrix(dhdx, self.nx, self.ny, self.n, dphi_x, dphi_y, s)
            d = c * a
            return d
        else:
            raise Exception('Topology not compatible with state')
hcNetworks.py 文件源码 项目:synchrony 作者: cknd 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def grid_fourNN(M,N,strength=1.0):
    """
    return an MxN grid graph with 4-nearest-neighbour connectivity

    Args:
        M,N: desired grid dimensions
        strength: desired edge strength
    """
    graph = nx.grid_2d_graph(M, N)
    graph.graph["grid_dimensions"] = (M,N)
    for e in graph.edges_iter():
        graph.edge[e[0]][e[1]] = {"strength":strength}
        graph.edge[e[1]][e[0]] = {"strength":strength}
    return graph
synctools_v0.py 文件源码 项目:delayCoupledDPLLnet 作者: cuichi23 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def get_couling_derivate_matrix(self, h, twist_number, s):
        if type(twist_number) == InPhase:
            dhdx = h.get_derivative()
            dphi_x = 0.0
            dphi_y = 0.0

            g = networkx.grid_2d_graph(self.ny, self.nx, periodic=False)
            g = networkx.convert_node_labels_to_integers(g, ordering='sorted')
            c = _networkx2mat(g, self.n)
            a = _build_2d_dhdx_matrix(dhdx, self.nx, self.ny, self.n, dphi_x, dphi_y, s)
            d = c * a
            return d
        else:
            raise Exception('Topology not compatible with state')


问题


面经


文章

微信
公众号

扫码关注公众号