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

generate better gadget decompositions

parent 5473738a
No related branches found
No related tags found
No related merge requests found
......@@ -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"]
......
......@@ -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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment