diff --git a/graph_tools/parameters.py b/graph_tools/parameters.py index 5c781d6803f34fe8a154decdfbe996c133aa7256..c1843f27291784307428d27090c549fcb1a51096 100644 --- a/graph_tools/parameters.py +++ b/graph_tools/parameters.py @@ -109,6 +109,10 @@ def _init_(): BV((0, 0, 0), Graph([[0], []], multiedges=True, loops=True, immutable=True)) ] + FREE_EDGE = [ + BV((0, 0), Graph([[0], []], multiedges=True, loops=True, immutable=True)) + ] + def join_boundaries(self, x, _): offsets = [0] for b in x: @@ -137,17 +141,25 @@ def _init_(): def merge_values(self, a, b): assert False def finalize(self, b): + from sage.all import Graph assert len(b) == 1 assert b[0].boundary == tuple() - return b[0].value + G = Graph(b[0].value, immutable=False) + + for v in G.vertices(): + if G.degree(v) != 2: continue + u, w = G.neighbors(v) + G.add_edge(u, w) + G.delete_vertex(v) + + return Graph(G, immutable=True) @Singleton class VertexCount(GraphParameterBase): """Count vertices of gadget. - Same as `gadget.eval(UnderlyingGraph).num_verts()` but - also works for gadgets containing FREE_EDGE. + Same as `gadget.eval(UnderlyingGraph).num_verts()`. """ CUBIC_VERTEX = [ BV(None, 1) ] FREE_EDGE = [ BV(None, 0) ]