diff --git a/experiments/test_exp_cdc.sh b/experiments/test_exp_cdc.sh index d9200463695e71f215316e20a871cb2799be1f56..76c8af6d08b42cd0948c5d331eb400baaa622f18 100755 --- a/experiments/test_exp_cdc.sh +++ b/experiments/test_exp_cdc.sh @@ -40,19 +40,22 @@ if True: sys.path.append(sys.argv[1] + "/..") import json - from graph_tools.misc import count_cdc_naive + from graph_tools.misc import graph_to_gadget + from graph_tools.parameters import CircuitDoubleCover from sage.all import Graph from parmap import parmap def process(l): G = Graph(l) - ret = count_cdc_naive(G) + gadget = graph_to_gadget(G) + real = gadget.eval(CircuitDoubleCover) + exp = 2**(G.num_verts() // 2) // 2 j = { - "cdc_count": ret[0], + "cdc_count": real, "n": G.num_verts(), - "expected_cdc_lowerbound": ret[1], - "is_ok": (ret[0] >= ret[1]) + "expected_cdc_lowerbound": exp, + "is_ok": (real >= exp) } return json.dumps(j), j["is_ok"] diff --git a/graph_tools/misc.py b/graph_tools/misc.py index c4539e763ba2dbfc2cc83e6bd092267850a1a712..44c7daa8e238b07e0a97133149483f0300bd253b 100644 --- a/graph_tools/misc.py +++ b/graph_tools/misc.py @@ -16,15 +16,22 @@ def _init_(): ) - def count_cdc_naive(G): - """Count circuit double covers of G. + def graph_to_gadget_naive(G): + """Transform graph into a Gadget. - Requires G to be cubic. + Very naive (and hence obviously correct) implementation. - EXAMPLE: + EXAMPLES: >>> from sage.all import * - >>> count_cdc_naive(graphs.PetersenGraph()) - (52, 16) + >>> from .parameters import CircuitDoubleCover, UnderlayingGraph + >>> P = graphs.PetersenGraph() + >>> graph_to_gadget_naive(P).eval(CircuitDoubleCover) + 52 + >>> d = [ list(range(5)), list(range(5, 10)) ] + >>> P.is_isomorphic(graph_to_gadget_naive(P, d).eval(UnderlayingGraph)) + True + >>> graph_to_gadget_naive(P, d).eval(CircuitDoubleCover) + 52 """ assert(G.degree() == [3]*G.num_verts()) @@ -42,7 +49,7 @@ def _init_(): b = Gadget.join([ CUBIC_VERTEX ] * G.num_verts(), joins, []) assert b.is_graph() - return (b.eval(CircuitDoubleCover), 2**(G.num_verts() // 2) // 2) + return b def graph_to_gadget(G, decomposition = None, allow_non_graph = False): @@ -69,7 +76,9 @@ def _init_(): edges = [ (verts[u], verts[v]) for u, v, _ in G.edges() ] if decomposition is None: - decomposition = G.vertices() + decomposition = G.vertices()[0] + for v in G.vertices()[1:]: + decomposition = [ v, decomposition ] vert_map = { v: [0, 1, 2] for v in range(len(verts)) } @@ -109,7 +118,8 @@ def _init_(): for i in old: outs.append((vert_to_gadget[v]+1, i+1)) - return (Gadget.join([ g for g, _ in gadgets ], joins, outs), gadget_verts) + ret = Gadget.join([ g for g, _ in gadgets ], joins, outs) + return (ret, gadget_verts) b, _ = process(decomposition) assert allow_non_graph or b.is_graph()