-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert_dimacs.py
34 lines (25 loc) · 1.19 KB
/
convert_dimacs.py
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
30
31
32
33
34
import networkx as nx
import os
for filename in os.listdir('.'):
print(filename)
if not (filename.endswith(".adj") or filename.endswith(".csv") or filename.endswith(".txt") or filename.endswith(".txtw") or filename.endswith(".tsv")):
continue
print(filename, sum(1 for line in open(filename)))
aaname = "%s.aa"% os.path.splitext(filename)[0]
if filename.endswith(".adj"):
G = nx.read_adjlist(filename)
if filename.endswith(".csv"):
G = nx.read_edgelist(filename, delimiter=',', data=(('weight1', int),('weight2',float)))
if filename.endswith(".txt"):
G = nx.read_edgelist(filename)
if filename.endswith(".txtw"):
G = nx.read_edgelist(filename, data=(('weight1', long),))
if filename.endswith(".tsv"):
G = nx.read_edgelist(filename, delimiter='\t', data=(('weight1', float),))
print("letto", G.number_of_nodes(), G.number_of_edges())
G.remove_edges_from(G.selfloop_edges())
print("scrivo", G.number_of_nodes(), G.number_of_edges())
nx.write_edgelist(G,aaname,data=False)
G = nx.read_edgelist(aaname)
K = list(nx.find_cliques(G))
print("grafo %s, cricche: %d, cricca max: %d" % (aaname,len(K),max(len(k) for k in K)))