Beispiel #1
0
def LoadState():
    fname = sw.GetStateName()
    if not os.path.exists(fname):
        return None

    FIn = Snap.TFIn(Snap.TStr(fname))
    AdjLists = Snap.TIntIntVH(FIn)
    return AdjLists
Beispiel #2
0
def GetEdges(sw, Edges):

    sw.log.debug("edges: %d" % Edges.Len())

    AdjLists = Snap.TIntIntVH()
    Snap.GetAdjLists(Edges, AdjLists)

    return AdjLists
Beispiel #3
0
def GetEdges(Edges):

    #print edges
    sw.flog.write("edges " + str(Edges.Len()) + "\n")
    sw.flog.flush()

    AdjLists = Snap.TIntIntVH()
    Snap.GetAdjLists(Edges, AdjLists)

    return AdjLists
    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.TIntH()
print "type", type(Edges), type(Hash)
snap.Edge2Hash(Edges, Hash)

for i in range(0, valrange):
    Vec2 = Hash.GetDat(i)
    print i, Vec2.Val

AdjLists = snap.TIntIntVH()
print "type", type(Edges), type(AdjLists)
snap.GetAdjLists(Edges, AdjLists)

size = 0
for i in range(0, valrange):
    Vec2 = AdjLists.GetDat(i)
    size += Vec2.Len()

    for j in range(0, Vec2.Len()):
        print i, Vec2.GetVal(j).Val

print "done", Edges.Len(), AdjLists.Len(), size, len(d)

sys.exit(0)
Beispiel #5
0
import snap as Snap

h = Snap.TIntIntVH()
print(h.Len())

for i in range(0, 10):
    k = h.AddKey(Snap.TInt(i))
    v = h.GetDat(Snap.TInt(i))

    for j in range(0, i + 3):
        v.Add(j)

    print(i, k)

print(h.Len())

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

for i in range(0, 10):
    j = h.GetKeyId(Snap.TInt(i))
    print(j)

    v = h.GetDat(Snap.TInt(i))
    #print(type(j), type(v))
    print(v.Len())
    print()
Beispiel #6
0
Key = Iter.GetKey().Val
Value = Iter.GetDat().Val
print("iter", Key, Value)

print("Iter < Hash.EndI", Iter < Hash.EndI())
#while Iter < Hash.EndI():
while not Iter.IsEnd():
    Key = Iter.GetKey().Val
    Value = Iter.GetDat().Val
    print(Key, Value)

    Iter.Next()

sys.exit(0)

AdjLists = Snap.TIntIntVH()
print("type", type(Edges), type(AdjLists))
Snap.GetAdjLists(Edges, AdjLists)

size = 0
for i in range(0,valrange):
    Vec2 = AdjLists.GetDat(i)
    size += Vec2.Len()

    for j in range(0,Vec2.Len()):
        print(i, Vec2.GetVal(j).Val)

print("done", Edges.Len(), AdjLists.Len(), size, len(d))

sys.exit(0)
Beispiel #7
0
import snap

h = snap.TIntIntVH()
print h.Len()

for i in range(0, 10):
    k = h.AddKey(snap.TInt(i))
    v = h.GetDat(snap.TInt(i))

    for j in range(0, i + 3):
        v.Add(j)

    print i, k

print h.Len()

print "-----------"

for i in range(0, 10):
    j = h.GetKeyId(snap.TInt(i))
    print j

    v = h.GetDat(snap.TInt(i))
    #print type(j), type(v)
    print v.Len()
    print
    def getNodeInducedSubgraphs(self):


        info = ""

        print "Size of the overlap %d" % (self.overlap_size)

        nodeIdV,nodeDegH=self.getNodeDegVector()


        # nodeDegH_walker = nodeDegH.BegI()
        # while not nodeDegH_walker.IsEnd():
        #     overlap_info += "%d,%d\n" % (nodeDegH_walker.GetKey(),nodeDegH_walker.GetDat())
        #     #print "Node Id: %d, degree: %d" % (nodeDegH_walker.GetKey(), nodeDegH_walker.GetDat())
        #     nodeDegH_walker.Next()

        #info+="# overlap_size:%d\n" % (self.overlap_size)


        # Random choice for overlap, better to replace with heuristic
        #randNodeIdV=np.random.choice(nodeIdV, overlap_size, replace=False)
        randNodeIdV=self.getOverlapSet(nodeDegH)

        overlapNodeIdV=snap.TIntV();
        subgraph1NodeIdV = snap.TIntV();
        subgraph2NodeIdV = snap.TIntV();

        #info+="# Node Id,Degree\n"
        for randNodeId in randNodeIdV:
            overlapNodeIdV.Add(randNodeId)
            #print randNodeId, nodeDegH[randNodeId]
            info += "%d,%d\n" % (randNodeId,nodeDegH[randNodeId])
            nodeIdV.DelIfIn(randNodeId)

        #overlapG = snap.TUNGraph.New()
        overlapG = snap.GetSubGraph(self.G, overlapNodeIdV)
        #print "Overlap: ", overlapG.GetNodes()
        #print self.targetDir + "/" + self.graphName+ "-overlap-edges.txt"


        self.writeFile(info,self.targetDir+"/"+self.graphName+"-overlap.txt")

        self.saveGraph(overlapG,self.targetDir + "/" + self.graphName+ "-overlap-edges.txt")
        #self.saveLblGraph(overlapG, self.targetDir + "/" + self.graphName + "-overlap-edges-Lbl.txt")

        non_overlap_size=self.graph_size-self.overlap_size
        subgraph_size=int(non_overlap_size/2)

        randNodeIdV = np.random.choice(nodeIdV, non_overlap_size, replace=False)

        node_count=0
        for randNodeId in randNodeIdV:
            node_count+=1
            if(node_count<=subgraph_size):
                subgraph1NodeIdV.Add(randNodeId)
            else:
                subgraph2NodeIdV.Add(randNodeId)

        subgraph1NodeIdV.AddV(overlapNodeIdV)
        subgraph2NodeIdV.AddV(overlapNodeIdV)

        subgraphNodeIdHV=snap.TIntIntVH(2)
        subgraphNodeIdHV[1]=subgraph1NodeIdV
        subgraphNodeIdHV[2]=subgraph2NodeIdV

        # save unlabeled graph
        #snap.SaveEdgeList(self.G, self.targetDir + "/" + self.graphName + ".txt")
        return self.getSubgraph(subgraphNodeIdHV)