-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCRE.py
More file actions
29 lines (26 loc) · 941 Bytes
/
CRE.py
File metadata and controls
29 lines (26 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
'''
CRE.py
Implements the Contraction of a Random Edge (CRE) graph reduction method
author: Erik Rye
date: 13 June 15
'''
import contraction as ct
import networkx as nx
import os
def CRE(graph, reduction_list, num_trials, verbose):
if not os.path.exists('CRE/'):
os.mkdir('CRE/')
for trial in range(num_trials):
if verbose:
print "Starting reduction w/seed " + str(trial) + "..."
reduced_graph = graph.copy()
for node_num in reduction_list:
if verbose:
print "Reducing to graph of order " + str(node_num) + "..."
c = ct.Contraction(reduced_graph,trial)
reduced_graph = c.CRE(node_num)
nx.write_gexf(reduced_graph, 'CRE/' + str(node_num) + '-CRE-' +
str(trial) + '.gexf')
if verbose:
print "Graph of order " + str(node_num) + " written."
del c