1
0
mirror of https://github.com/kalmarek/SmallHyperbolic synced 2024-12-25 02:15:29 +01:00

add python script to generate morphisms json

This commit is contained in:
Marek Kaluba 2022-02-22 14:21:01 +01:00
parent ea4c16c715
commit bc6792e9c2
No known key found for this signature in database
GPG Key ID: 8BF1A3855328FC15
2 changed files with 43 additions and 0 deletions

View File

@ -1,3 +1,4 @@
digraph {
"G^{14,14,48}_{0}" -> "G^{14,14,24}_{1}"
"G^{14,14,48}_{0}" -> "G^{14,14,16}_{1}"
"G^{14,14,48}_{1}" -> "G^{14,14,24}_{0}"
@ -302,3 +303,4 @@
"G^{54,54,54}_{2}" -> "G^{18,54,54}_{0}"
"G^{54,54,54}_{2}" -> "G^{18,54,54}_{8}"
"G^{54,54,54}_{2}" -> "G^{18,54,54}_{2}"
}

View File

@ -0,0 +1,41 @@
import networkx
import json
import os
DATA_DIR = os.path.join("..", "..", "data")
MORPHISMS_FILE = os.path.join(DATA_DIR, "morphisms.dot")
MORPHISMS_JSON = os.path.join(DATA_DIR, "triangle_groups_morphisms.json")
def level(G, node):
parents = list(G.predecessors(node))
if len(parents) == 0:
return 0
else:
return 1 + max([level(G, n) for n in parents])
def nodes_from_component(G, cc, graph_json):
subG = networkx.induced_subgraph(G, cc)
assert networkx.is_weakly_connected(subG)
root = [n for n,d in subG.in_degree() if d==0][0]
for node in graph_json["nodes"]:
if node["id"] in subG:
print(node)
n = node["id"]
node["level"] = level(G, n)
node["component_id"] = root
return graph_json
G = networkx.nx_pydot.read_dot(MORPHISMS_FILE)
G_json = networkx.node_link_data(G)
G_components = networkx.weakly_connected_components(G)
for cc in G_components:
nodes_from_component(G, cc, G_json)
with open(MORPHISMS_JSON, "w") as file:
print("writing to ", MORPHISMS_JSON, "\n")
json.dump(G_json, file, indent=4)