M = Graph({1:{2:' 8 ',3:' 4 ',4:'2 '}, 2:{3:' 3 ',4:'2',5:' 2 '}, 4:{5:' 7 ',3:'1'},3:{5:'5'}})
M.plot(edge_labels=True).show()
weight = lambda  e: 1/( (e[0]+1)*(e[1]+1) )
lst=M.min_spanning_tree(algorithm='Kruskal',weight_function=weight)
l=range(1,6)
def adj(x):
    l1={}
    for i in lst:
        if i[0]==x:
           l1[i[1]]=i[2]
        elif i[1]==x:
            l1[i[0]]=i[2]
    return l1
grp={}
for i in l:
    grp[i]=adj(i)
T=Graph(grp)
T.plot(edge_labels=True)

Kreyszig-21.4 - 3-U (last edited 2010-12-18 05:52:47 by 10)