Ejemplo n.º 1
0
    def setUp(self):
        self.graphname = os.getenv('PYLIBBVG_TESTGRAPH')
        if self.graphname is None:
            self.graphname = '../data/harvard500'
        smatfile = open(self.graphname + '.smat', 'rt')
        header = smatfile.readline().split()
        self.check_nnodes = int(header[0])
        self.check_nedges = int(header[2])
        self.assertEqual(self.check_nnodes,
                         int(header[1]))  # make sure it's square
        self.checkgraph = {}
        for i in xrange(0, self.check_nnodes):
            self.checkgraph[i] = set()
        for line in smatfile:
            parts = line.split()
            src = int(parts[0])
            dst = int(parts[1])
            #if src not in self.checkgraph:
            #    self.checkgraph[src] = set()
            assert (dst not in self.checkgraph[src])  # no duplicateedges
            self.checkgraph[src].add(dst)
        smatfile.close()

        # load with random access, in-memory streaming, and disk-streaming
        self.bvg = bvg.BVGraph(self.graphname, 1)
        self.bvgstream = bvg.BVGraph(self.graphname, 0)
        self.bvgdisk = bvg.BVGraph(self.graphname, -1)
Ejemplo n.º 2
0
def load_twitter_graph():
    print "Loading graph ..."
    start_time = time.time()
    twitter_graph = bvg.BVGraph('../dataset/twitter-2010-symm', 1)
    print "   ... done!   %.1f seconds" % (time.time() - start_time)
    time.sleep(0.75)
    print "\n"
    print "Twitter graph has"
    print "nodes:   %i" % (twitter_graph.nverts)
    print "edges:   %i" % (twitter_graph.nedges)
    time.sleep(0.75)
    print "\nt = 15"
    print "eps = 10^-4\n"
    time.sleep(0.75)
    return twitter_graph
Ejemplo n.º 3
0
#!/usr/bin/env python

import bvg as bvg
import networkx as nx

G = bvg.BVGraph('../data/harvard500', 1)
Gcc = bvg.BVGraph('../data/harvard500-cc', 1)
nx.degree(G, 1)
nx.strongly_connected_components(G)
#g = nx.Graph()

# centrality
nx.degree_centrality(G)
nx.out_degree_centrality(G)
nx.betweenness_centrality(G)
nx.closeness_centrality(G)
nx.eigenvector_centrality(G)

# clique
#list(nx.find_cliques(G))
#list(nx.make_max_clique_graph(G))
#list(nx.make_clique_bipartite(G))
#nx.graph_clique_number(G)
#nx.graph_number_of_cliques(G)

# components
nx.is_strongly_connected(G)
nx.number_strongly_connected_components(G)
scc = nx.strongly_connected_components(G)
nx.strongly_connected_components_recursive(G)
nx.condensation(G, scc)
Ejemplo n.º 4
0
#!/usr/bin/python
import bvg
import sys

data = sys.argv[1]
G = bvg.BVGraph(data, 0)  # load with offset step = 0 (iteration)
print('#nodes = ' + str(G.nverts) + ', #edges = ' + str(G.nedges))
edges_and_degrees = G.edges_and_degrees()
const = 10000000001
count = 0
for (src, dst, degree) in edges_and_degrees:
    count += 1
    if degree == 1 and dst + src != const:
        print('error: reading 64bit bvgraph, src = ' + str(src) + ', dst = ' +
              str(dst))
        break
    elif count == 1000:
        print('Python: testing 64-bit bvgraph sequential read ... passed!')
        break
Ejemplo n.º 5
0
import collections
import time
import random


def compute_psis(N, t):
    psis = {}
    psis[N] = 1.
    for i in xrange(N - 1, 0, -1):
        psis[i] = psis[i + 1] * t / (float(i + 1.)) + 1.
    return psis


start = time.time()
print "Loading graph ..."
G = bvg.BVGraph('twitter-2010-symm', 1)
print "   ... done!   %.1f seconds" % (time.time() - start)
time.sleep(0.75)
print "\n"
print "Twitter graph has"
print "nodes:   %i" % (G.nverts)
print "edges:   %i" % (G.nedges)
time.sleep(0.75)
print "\nt = 15"
print "eps = 10^-4\n"
time.sleep(0.75)

Gvol = G.nedges

## Setup parameters that can be computed automatically
N = 47  # see paper for how to set this automatically
Ejemplo n.º 6
0
#!/usr/bin/python
import bvg
import sys

## new an object without loading graph
#G = bvg.Graph()

## new an object with graph loaded
data = sys.argv[1]
G1 = bvg.BVGraph(data, 0)  # load with offset step = 0 (iteration)
G2 = bvg.BVGraph(data, 1)  # load with offset step = 1 (random access)

node = int(sys.argv[2])  # node is given

## test successors and degree
a = G2.successors(node)
for v in a:
    print v
print 'Degree = ' + str(G2.out_degree(node))

## test direct access to number of nodes and edges
print G1.nverts
print G1.nedges

## test iteration in G
for v in G1:
    print v
#    src = v.curr
#    deg = v.degree
#    print 'src = ' + str(src) + ', degree = ' + str(deg)
#    for neigh in v: