diff --git a/graph/combine.py b/graph/combine.py index 25bf7ae..014bf8a 100755 --- a/graph/combine.py +++ b/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): index_map[(layer_index, union_index)] = g_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 for layer_index in range(len(split_data)-1): @@ -172,5 +172,5 @@ if __name__ == '__main__': # print(gg) # 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') diff --git a/graph/cut.py b/graph/cut.py new file mode 100755 index 0000000..a607e05 --- /dev/null +++ b/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)