def is_graph_weakly_connected(G):
    return snap.IsWeaklyConn(G)
Beispiel #2
0
import snap

# create a random directed graph
G = snap.GenRndGnm(snap.PNGraph, 10000, 5000)

# test if the graph is connected or weakly connected
print("IsConnected(G) =", snap.IsConnected(G))
print("IsWeaklyConnected(G) =", snap.IsWeaklyConn(G))

# get the weakly connected component counts
WccSzCnt = snap.TIntPr64V()
snap.GetWccSzCnt(G, WccSzCnt)
#print (WccSzCnt[0],WccSzCnt[0].Val1,WccSzCnt[0].Val2)
for i in range(0, WccSzCnt.Len()):
    print("WccSzCnt[%d] = (%d, %d)" %
          (i, WccSzCnt[i].Val1.Val, WccSzCnt[i].Val2.Val))

# return nodes in the same weakly connected component as node 1
CnCom = snap.TInt64V()
snap.GetNodeWcc(G, 1, CnCom)
print("CnCom.Len() = %d" % (CnCom.Len()))

# get nodes in weakly connected components
WCnComV = snap.TCnComV()
snap.GetWccs(G, WCnComV)
for i in range(0, WCnComV.Len()):
    print("WCnComV[%d].Len() = %d" % (i, WCnComV[i].Len()))
    for j in range(0, WCnComV[i].Len()):
        print("WCnComV[%d][%d] = %d" % (i, j, WCnComV[i][j]))

# get the size of the maximum weakly connected component
Beispiel #3
0
 def isWeaklyConnected(self):
     return snap.IsWeaklyConn(self.rawGraph)