• Python 图论工具


    networkx:

    一个用Python语言开发的图论与复杂网络建模工具,

    内置了经常使用的图与复杂网络分析算法,

    能够方便的进行复杂网络数据分析、仿真建模等工作。


    依赖工具

    numpy 

    pyparsing 

    datautil 

    matplotlib 

    networkx 


    採用随机图做个实验:

    from random import random, choice
    import networkx as nx
    import matplotlib.pyplot as plt
    
    def dist(a, b):
        (x1, y1) = a
        (x2, y2) = b
        return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
    
    G = nx.Graph()
    
    points = [(random(), random()) for _ in range( 8 )]
    
    for p1, p2 in zip(points[:-1], points[1:]):
        G.add_edge(p1, p2, weight=dist(p1, p2))
    
    
    for _ in range( 8 ):
        p1, p2 = choice(points), choice(points)
        G.add_edge(p1, p2, weight=dist(p1, p2))
        
    nx.draw(G)
    plt.savefig( 'asd.png' )
    plt.show()
    



    全然图做个试验:

    import networkx as nx
    import matplotlib.pyplot as plt
    
    G = nx.complete_graph(6)
    
    nx.draw(G)
    plt.savefig("asd.png")
    plt.show()
    



  • 相关阅读:
    HDU 1421 DP
    HDU1011 树形DP
    CodeForces 219D 树形DP
    HDU2196 树形DP
    HDU5831
    HDU3177 贪心
    数位DP HDU3652
    数位DP bzoj1026
    数位DP HDU3555
    数位DP HDU2089
  • 原文地址:https://www.cnblogs.com/mengfanrong/p/4350017.html
Copyright © 2020-2023  润新知