M = Graph({1:{2:'16 ',3:'8',4:'4'}, 2:{4:'4',3:'6'}, 3:{4:'2',5:'10'},4:{5:'14'}})
M.plot(edge_labels=True).show()
weight = lambda e: 1/( (e[0]+1)*(e[1]+1) )
lst=M.min_spanning_tree(algorithm='Prim edge',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.5-7-U (last edited 2010-12-18 06:57:38 by K.Swetha)