Skip to content
Snippets Groups Projects
Commit 5ff3ddca authored by Radek Hušek's avatar Radek Hušek
Browse files

graph_to_gadget: add experimental decomposition

parent b7a69e8e
Branches
No related tags found
No related merge requests found
...@@ -52,6 +52,40 @@ def _init_(): ...@@ -52,6 +52,40 @@ def _init_():
return b return b
def guess_decomposition(G):
from sage.all import flatten
cycles = []
H = G.copy()
while not H.is_forest():
_, c = H.girth(certificate=True)
stack = H.vertex_boundary(c)
H.delete_vertices(c)
while stack:
v = stack.pop()
if v not in H or H.degree(v) > 1: continue
c = [ c, v ]
stack.extend(H.vertex_boundary([ v ]))
H.delete_vertex(v)
cycles.append(c)
score = lambda x: len(G.edge_boundary(flatten([cycles[x[0]], cycles[x[1]]])))
while len(cycles) > 2:
i1, i2 = min([ (i, j) for i in range(len(cycles)) for j in range(i) ], key=score)
c1 = cycles[i1]
c2 = cycles[i2]
del cycles[i1]
del cycles[i2]
cycles.append([ c1, c2 ])
assert(sorted(flatten(cycles)) == sorted(G.vertices()))
return cycles
def graph_to_gadget(G, decomposition = None, allow_non_graph = False): def graph_to_gadget(G, decomposition = None, allow_non_graph = False):
"""Transform graph into a Gadget. """Transform graph into a Gadget.
...@@ -76,9 +110,7 @@ def _init_(): ...@@ -76,9 +110,7 @@ def _init_():
edges = [ (verts[u], verts[v]) for u, v, _ in G.edges() ] edges = [ (verts[u], verts[v]) for u, v, _ in G.edges() ]
if decomposition is None: if decomposition is None:
decomposition = G.vertices()[0] decomposition = guess_decomposition(G)
for v in G.vertices()[1:]:
decomposition = [ v, decomposition ]
vert_map = { v: [0, 1, 2] for v in range(len(verts)) } vert_map = { v: [0, 1, 2] for v in range(len(verts)) }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment