Browse Source

feat: analyze the core graph structure

master
Dnomd343 6 days ago
parent
commit
5ef07d67d6
  1. 4
      graph/combine.py
  2. 43
      graph/cut.py

4
graph/combine.py

@ -132,7 +132,7 @@ def export_new_graph(g: ig.Graph, split_data: list[list[set[ig.Vertex]]]) -> ig.
for union_index, nodes in enumerate(unions): for union_index, nodes in enumerate(unions):
index_map[(layer_index, union_index)] = g_index index_map[(layer_index, union_index)] = g_index
ng.vs[g_index]['step'] = layer_index ng.vs[g_index]['step'] = layer_index
# ng.vs[g_index]['codes'] = [x['code'] for x in nodes] ng.vs[g_index]['codes'] = [x['code'] for x in nodes]
g_index += 1 g_index += 1
for layer_index in range(len(split_data)-1): for layer_index in range(len(split_data)-1):
@ -172,5 +172,5 @@ if __name__ == '__main__':
# print(gg) # print(gg)
# ig.plot(gg, 'demo.png', vertex_size=10) # ig.plot(gg, 'demo.png', vertex_size=10)
# gg.write_pickle('main_combined.pkl') gg.write_pickle('main_combined.pkl')
# gg.write_graphml('main_combined.graphml') # gg.write_graphml('main_combined.graphml')

43
graph/cut.py

@ -0,0 +1,43 @@
#!/usr/bin/env python3
import igraph as ig
def split_max_graph(g: ig.Graph, cut_point: int):
gg = g.copy()
edges = [(cut_point, x.index) for x in gg.vs[cut_point].neighbors()]
gg.delete_edges(edges)
components = sorted(gg.components(), key=lambda x: -len(x))
return g.subgraph(components[0] + [cut_point])
def split_subgraph(g: ig.Graph):
# def demo():
# sizes = set()
# for cut_point in g.articulation_points():
# gg: ig.Graph = g.copy()
# gg.delete_vertices(cut_point)
# subs = gg.decompose()
# sizes.update([x.vcount() for x in subs])
# print(sorted(sizes))
# demo()
for _ in range(1034):
print(g.vcount(), g.ecount())
points = g.articulation_points()
assert len(points) > 0
g = split_max_graph(g, points[0])
# ig.plot(g, 'demo.png', bbox=(2000, 2000))
print(g.vcount(), g.ecount())
# g.write_graphml('main_cir.graphml')
g.write_pickle('main_cir.pkl')
if __name__ == '__main__':
raw = ig.Graph.Read_Pickle('main_combined.pkl')
# print(raw.vcount())
split_subgraph(raw)
Loading…
Cancel
Save