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

bump

parent e0f86229
Branches
No related tags found
No related merge requests found
......@@ -155,6 +155,19 @@ class UnderlayingGraph(GraphParameterBase):
return b[0].value
@Singleton
class VertexCount(GraphParameterBase):
CUBIC_VERTEX = [ Boundary(None, 1) ]
FREE_EDGE = [ Boundary(None, 0) ]
def join_boundaries(self, x, _):
yield Boundary(None, sum( b.value for b in x ))
def join_edges(self, b, _, __): yield b
def project_and_canonize(self, _, b): return b
def finalize(self, b): return b[0].value
@Singleton
class HamiltonianCycle(GraphParameterBase):
FREE_EDGE = [ Boundary((1, 1), 1), Boundary((None, None), 1) ]
......
from flower_snarks import *
from sage.all import *
from itertools import permutations
def solve_gadget(g, alt_gadgets):
N = g.size()
......@@ -17,25 +18,44 @@ def solve_gadget(g, alt_gadgets):
def gadget_to_poly(gadget):
return sum(
V[b] * join(fake_gadget(b), gadget).eval(CircuitDoubleCover)
V[b] * float(join(fake_gadget(b), gadget).eval(CircuitDoubleCover))
for b in BOUNDARIES
)
def gadget_to_constraint(gadget):
poly = gadget_to_poly(gadget)
n = gadget.eval(UnderlayingGraph)[0].value.num_verts()
n = VertexCount.finalize(gadget.eval(VertexCount))
P.add_constraint(poly >= 2**(n // 2))
for ag in alt_gadgets: gadget_to_constraint(ag)
P.set_objective(gadget_to_poly(g))
P.show()
print (floor(P.solve()), 2**(g.eval(UnderlayingGraph)[0].value.num_verts()//2))
if False:
P.show()
for i, v in sorted(P.get_values(V).items()):
print('w_%s = %s' % (i, v))
return (floor(P.solve()), 2**(g.eval(UnderlayingGraph)[0].value.num_verts()//2))
def friend_boundary(g):
N = g.size();
BOUNDARIES = list(CircuitDoubleCover.enumerate_boundaries(N))
def test_boundary(b):
fg = FakeGadget(N, [ Boundary(b, 1) ])
joins = [ ((1, i), (2, i)) for i in range(1,N+1) ]
return (b, Gadget.join([ fg, g ], joins, []).eval(CircuitDoubleCover))
return [ test_boundary(b) for b in BOUNDARIES ]
def rot(l, x):
return l[x:] + l[:x]
G4 = [
Gadget.join([CUBIC_VERTEX] * 2, [((1,1), (2,1))], [ (1,2), (1,3), (2,2), (2,3) ]),
Gadget.join([CUBIC_VERTEX] * 2, [((1,1), (2,1))], [ (1,2), (2,2), (1,3), (2,3) ]),
......@@ -49,8 +69,29 @@ G4f = [
]
G5 = [
Gadget.join([CUBIC_VERTEX] * 3, [((1,1), (2,1)), ((2,2), (3,2))], [ (1,2), (1,3), (2,3), (3,1), (3,3) ]),
Gadget.join([CUBIC_VERTEX] * 3, [((1,1), (2,1)), ((2,2), (3,2))], out)
for out in permutations([ (1,2), (1,3), (2,3), (3,1), (3,3) ])
] + [
Gadget.join([ CUBIC_VERTEX, FREE_EDGE ], [], out)
for out in permutations([ (1,1), (1,2), (1,3), (2,1), (2,2) ])
]
G5s = [
Gadget.join([CUBIC_VERTEX] * 3, [((1,1), (2,1)), ((2,2), (3,2))], rot([ (1,2), (1,3), (2,3), (3,1), (3,3) ], i))
for i in range(5)
] + [
Gadget.join([ CUBIC_VERTEX, FREE_EDGE ], [], rot([ (1,1), (1,2), (1,3), (2,1), (2,2) ], i))
for i in range(5)
]
G6 = [
Gadget.join([CUBIC_VERTEX]*4, [((1,1), (2,1)), ((1,2), (3,1)), ((1,3), (4,1))], out)
for out in [[ (2,2), (2,3), (3,2), (3,3), (4,2), (4,3) ]]
]
print(solve_gadget(sun(4), G4))
# print(solve_gadget(G4[0], G4f))
l = sorted(friend_boundary(G4[0]), key=lambda x: x[1])
print(len(l))
for x in l: print(x)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment