extened Makefile, added ./tools/removeiso.py, added option --graphviz, readme Makefile

This commit is contained in:
Ämin on ThinkPad
2023-09-07 10:03:10 +02:00
parent 6939bd5fa9
commit ab5a90dc38
6 changed files with 139 additions and 18 deletions

77
tools/removeiso.py Executable file
View File

@@ -0,0 +1,77 @@
#!/usr/bin/python3
"""
SPDX-FileCopyrightText: 2023 Ämin Baumeler <amin@indyfac.ch> and Eleftherios-Ermis Tselentis <eleftheriosermis.tselentis@oeaw.ac.at>
SPDX-License-Identifier: GPL-3.0-or-later
"""
import sys
import getopt
import numpy as np
import networkx as nx
"""Parse command line arguments first."""
helpstr = """Usage: """+sys.argv[0]+""" -f <filename>
Filters out the isomorphic graphs in `filename'."""
FILENAME = False
try:
opts, args = getopt.getopt(sys.argv[1:], "hf:")
except getopt.GetoptError:
print(helpstr, file=sys.stderr)
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print(helpstr)
sys.exit()
elif opt == '-f':
FILENAME = arg
if not FILENAME:
print(helpstr, file=sys.stderr)
sys.exit(2)
with open(FILENAME, 'rb') as f:
num_lines = sum(1 for _ in f)
print(f"Total number of digraphs is {num_lines}", file=sys.stderr)
nonisodigraphs = set()
cnt = 0
fnd = 0
with open(FILENAME, 'r') as f:
while 1:
cnt = cnt + 1
print("\r{:.2f}%".format(100*cnt/num_lines), end='', file=sys.stderr)
line = f.readline().strip('{}\n')
if not line:
break
G = nx.from_numpy_matrix(np.vectorize(int)(np.matrix([x.split(',') for x in line.split('},{')])), create_using=nx.DiGraph)
couldbeold = False
for H in nonisodigraphs:
# Returns False if graphs are definitely not isomorphic.
# True does NOT guarantee isomorphism.
if nx.faster_could_be_isomorphic(G, H):
couldbeold = True
break
if not couldbeold:
nonisodigraphs.add(G)
fnd = fnd + 1
print(f"{{{{{line}}}}}")
continue
new = True
for H in nonisodigraphs:
if nx.is_isomorphic(G, H):
new = False
break
if new:
nonisodigraphs.add(G)
fnd = fnd + 1
print(f"{{{{{line}}}}}")
print(f"\r100% Found {fnd} non-isomoric graphs", file=sys.stderr)