def f():
     snap = self.snap
     nodes = self.nodes
     V = snap.TInt64V()
     snap.GetDegSeqV(self.graph, V)
     ret = []
     for i in range(0, V.Len()):
         ret.append((nodes[i], V[i]))
     return ret
Пример #2
0
def build_color_map(hasht, color_name, pct=0.05):
    hasht.SortByDat(False)  #sort descending
    keyV = snap.TInt64V()
    num_to_take = floor(hasht.Len() * pct)
    cmap = snap.TIntStr64H()
    #islice slices a generator like an array
    for key, val in islice(iter_kv_pairs(hasht), num_to_take):
        cmap[key] = color_name
    return cmap
Пример #3
0
import snap
import time

#from utils.network_utils import get_num_elem_per_mode

filename = "Graphs/oldMinerNewSNAP.graph"
FIn = snap.TFIn(filename)
Graph = snap.TMMNet.Load(FIn)

print('Modes: %d' % Graph.GetModeNets())
print('Link types: %d' % Graph.GetCrossNets())

crossnetids = snap.TInt64V()
crossneti = Graph.BegCrossNetI()
while crossneti < Graph.EndCrossNetI():
    crossnetids.Add(crossneti.GetCrossId())
    crossneti.Next()

nodeattrmapping = snap.TIntStrStrTr64V()
edgeattrmapping = snap.TIntStrStrTr64V()
start_time = time.time()
DirectedNetwork = Graph.ToNetwork(crossnetids, nodeattrmapping,
                                  edgeattrmapping)
end_time = time.time()
print("Converting to TNEANet  takes %s seconds" % (end_time - start_time))

snap.PrintInfo(DirectedNetwork, "Python type PNEANet", "output.txt", False)
map(lambda x: x.replace("\n", ""), open("output.txt").readlines())
Пример #4
0
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
MxWccSz = snap.GetMxWccSz(G)
print("MxWccSz = %.5f" % (MxWccSz))
Пример #5
0
import snap

print ("----- vector ----- ")

v = snap.TInt64V()

v.Add(1)
v.Add(2)
v.Add(3)
v.Add(4)
v.Add(5)

print (v.Len())
print (v[2])

v.SetVal(2, 2*v[2])
print (v[2])

for item in v:
    print (item)

for i in range(0, v.Len()):
    print (i, v[i])

print ("----- hash table ----- ")

h = snap.TIntStr64H()

h[5] = "five"
h[3] = "three"
h[9] = "nine"
Пример #6
0
import random
import os
import sys
import time

sys.path.append("../swig")
import snap as Snap

numnodes = 100
valrange = numnodes / 5

Edges = Snap.TInt64V()

for i in range(0, numnodes):
    Edges.Add(int(random.random() * valrange))

d = {}
for i in range(0, numnodes, 2):
    #print "Edges", i/2, Edges.GetVal(i).Val, Edges.GetVal(i+1).Val
    d[(Edges.GetVal(i).Val, Edges.GetVal(i + 1).Val)] = 1

Hash = Snap.TInt64H()
#Snap.Edge2Hash(Edges,Hash)

Hash.AddDat(3, 5)
Hash.AddDat(4, 6)
Hash.AddDat(1, 8)
Hash.AddDat(6, 2)

print "type", type(Edges), type(Hash)
Пример #7
0
import snap

# first vector
a = snap.TInt64V()
a.Add(1)
a.Add(2)
a.Add(3)
a.Add(4)
a.Add(5)
l = [str(elem) for elem in a]
print("a =      ", ", ".join(l))

# second vector
b = snap.TInt64V()
b.Add(3)
b.Add(4)
b.Add(5)
b.Add(6)
b.Add(7)
l = [str(elem) for elem in b]
print("b =      ", ", ".join(l))

# third vector
c = snap.TInt64V()
c.Add(6)
c.Add(7)
c.Add(8)
c.Add(9)
l = [str(elem) for elem in c]
print("c =      ", ", ".join(l))
print()
Пример #8
0
import snap

Graph = snap.GenFull(snap.PNEANet, 10)

NIdV = snap.TInt64V()
Graph.GetNIdV(NIdV)
for i in NIdV:
    print "node", i

EIdV = snap.TInt64V()
Graph.GetEIdV(EIdV)
for i in EIdV:
    print "edge", i

Пример #9
0
import os
import sys
import time

sys.path.append("/home/rok/git/rok/snapworld")
import snap as Snap

if __name__ == '__main__':

    if len(sys.argv) < 2:
        print "Usage: " + sys.argv[0] + " <file>"
        sys.exit(1)

    fname = sys.argv[1]

    FIn = Snap.TFIn(Snap.TStr(fname))
    Vec = Snap.TInt64V(FIn)
    print "len", Vec.Len()

    Vec.Sort()

    for i in range(0,Vec.Len()):
        print "Vec", i, Vec.GetVal(i).Val