def main(n='20', k='4', p='0.4'):
    n = int(n)
    k = int(k)
    p = float(p)
    g = SmallWorldGraph(n, k)
    g.rewire(p)

    layout = CircleLayout(g)

    # draw the graph
    gw = GraphWorld()
    gw.show_graph(g, layout)
    gw.mainloop()
def main(script, n='10', *args):

    # create n Vertices
    n = int(n)
    labels = string.ascii_lowercase + string.ascii_uppercase
    vs = [Vertex(c) for c in labels[:n]]

    # create a graph and a layout
    g = Graph(vs)
    g.add_all_edges()
    layout = CircleLayout(g)

    # draw the graph
    gw = GraphWorld()
    gw.show_graph(g, layout)
    gw.mainloop()
def main(script, n='52', k='5', p='0.1', *args):
    random.seed(17)
    
    # create n Vertices
    n = int(n)
    k = int(k)
    p = float(p)
    
    names = name_generator()
    vs = [Vertex(names.next()) for c in range(n)]
    
    # create a graph
    g = SmallWorldGraph(vs, k, p)
    
    from time import clock

    print 'number of edges = ', len(g.edges())
    print 'Is connected?', g.is_connected()
    print 'diameter = ', g.diameter()
    
    start = clock()
    print 'char_length = ', g.char_length()
    print clock()-start
    
    start = clock()
    print 'char_length2 = ', g.char_length2()
    print clock()-start
    
    start = clock()
    print 'char_length3 = ', g.char_length3()
    print clock()-start
    
    start = clock()
    print 'char_length4 = ', g.char_length4()
    print clock()-start
    
    print 'cluster_coef = ', g.cluster_coef()
    
    # draw the graph
    draw = True
    if draw:
        layout = CircleLayout(g)
        gw = GraphWorld()
        gw.show_graph(g, layout)
        gw.mainloop()
示例#4
0
def main(script, *args):
    labels = string.ascii_lowercase + string.ascii_uppercase
    vs = [Vertex(c) for c in labels[:10]]

    # create a graph and a layout
    g = Graph(vs)
    g.add_all_edges()
    #    g.remove_edge(Edge(vs[1],vs[2]))
    #    g.add_regular_edges(9)
    layout = CircleLayout(g)

    # draw the graph
    gw = GraphWorld()
    gw.show_graph(g, layout)
    gw.mainloop()
    g.is_connected()
示例#5
0
def main(script, n='10', *args):
    n = int(n)
    labels = string.ascii_lowercase + string.ascii_uppercase
    vs = [Vertex(c) for c in labels[:n]]
    g = Graph(vs)

    if g.add_regular_edges(n-2) == True:
        print (g.edges())
    else:
        print ("I couldn't!")
        for v in g.vertices():
            print (len(g.out_edges(v)))
    # draw the graph
    layout = CircleLayout(g)
    gw = GraphWorld()
    gw.show_graph(g, layout)
    gw.mainloop()
示例#6
0
def main(script, n='52', k='5', p='0.1', *args):
    random.seed(17)

    # create n Vertices
    n = int(n)
    k = int(k)
    p = float(p)

    names = name_generator()
    vs = [Vertex(names.next()) for c in range(n)]

    # create a graph
    g = SmallWorldGraph(vs, k, p)

    from time import clock

    print 'number of edges = ', len(g.edges())
    print 'Is connected?', g.is_connected()
    print 'diameter = ', g.diameter()

    start = clock()
    print 'char_length = ', g.char_length()
    print clock() - start

    start = clock()
    print 'char_length2 = ', g.char_length2()
    print clock() - start

    start = clock()
    print 'char_length3 = ', g.char_length3()
    print clock() - start

    start = clock()
    print 'char_length4 = ', g.char_length4()
    print clock() - start

    print 'cluster_coef = ', g.cluster_coef()

    # draw the graph
    draw = False
    if draw:
        layout = CircleLayout(g)
        gw = GraphWorld()
        gw.show_graph(g, layout)
        gw.mainloop()
        bins = [d+0.5 for d in range(max(degrees))]
        bins.append(max(degrees) + 1.5)
        hist, edges = histogram(degrees, bins)
        return zip(bins, list(hist))
            
if __name__=="__main__":
    if 0: 
        alphabet = 'abcdefghijklmnopqrstuvwxyz'
        vs = []
        for v in range(10):
            vs.append(Vertex(alphabet[v]))   
        g = ScaleFreeGraph(vs)
        g.add_regular_edges(2)
        
        # draw the graph
        gw = GraphWorld()
        layout = CircleLayout(g)
        gw.show_graph(g, layout)
        gw.mainloop()
        
        # grow one round
        g.grow_by_edges(3,500)
        
        # draw the graph
        gw = GraphWorld()
        layout = CircleLayout(g)
        gw.show_graph(g, layout)
        gw.mainloop()
        
        
    if 1: 
示例#8
0
def draw(graph, size=500):
    layout = CircleLayout(graph)
    gw = GraphWorld(width=size, height=size)
    gw.show_graph(graph, layout)
    gw.mainloop()
            #Need a recursive function to check that for unconnected vertices and then add them.
            lengths = [v.dist for v in vs]
            tot_length.append(avg(lengths))

        return avg(tot_length)

def avg(lst):
    return sum(lst)/float(len(lst))

Inf = float('Inf')

if __name__ == '__main__':
    g = SmallWorldGraph([Vertex(str(i)) for i in xrange(10)], 3, 0)
    print g.clust, g.length

    layout = CircleLayout(g)

    # # draw the graph
    gw = GraphWorld()
    gw.show_graph(g, layout)
    gw.mainloop()