Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
42 lines (30 sloc) 1.07 KB
# -*- coding: utf-8 -*-
import sys
import json
import networkx as nx
G = sys.argv[1]
g = nx.read_gpickle(G)
# Finding cliques is a hard problem, so this could
# take a while for large graphs.
# See and
cliques = [c for c in nx.find_cliques(g)]
num_cliques = len(cliques)
clique_sizes = [len(c) for c in cliques]
max_clique_size = max(clique_sizes)
avg_clique_size = sum(clique_sizes) / num_cliques
max_cliques = [c for c in cliques if len(c) == max_clique_size]
num_max_cliques = len(max_cliques)
max_clique_sets = [set(c) for c in max_cliques]
people_in_every_max_clique = list(reduce(lambda x, y: x.intersection(y),
print 'Num cliques:', num_cliques
print 'Avg clique size:', avg_clique_size
print 'Max clique size:', max_clique_size
print 'Num max cliques:', num_max_cliques
print 'People in all max cliques:'
print json.dumps(people_in_every_max_clique, indent=4)
print 'Max cliques:'
print json.dumps(max_cliques, indent=4)