From 5beba525795ccc2609348d5ef7c9d124af5135f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20Hu=C5=A1ek?= <PitelVonSacek@gmail.com> Date: Thu, 10 Dec 2015 19:44:16 +0100 Subject: [PATCH] Add optimization based on matching subgraphs If group has size 4 and graph contains one of following subgraphs, it cannot be group-connected: - vertex with all neighbours of degree 2 - vertex such that 2 of 3 his neighbours has degree 2 and so do their neighbours - edge such that all 4 of her neighbours have degree 2 --- groupConnectivity.pyx | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/groupConnectivity.pyx b/groupConnectivity.pyx index f405d70..28c4cc8 100644 --- a/groupConnectivity.pyx +++ b/groupConnectivity.pyx @@ -38,9 +38,21 @@ def pathToEdges(G, path): return ret +def theOtherNeighbour(G, v, w): + """ + Given vertex v of degree 2 returns neighbour + of v not equal to w. + """ + N = G.neighbors(v) + if N[0] == w: + return N[1] + else: + return N[0] + + def testGroupConnectivity(G, group = "Z4", getClasses = False, useTwoCuts = True, useDoubleSubdivisions = True, - debug = False): + useSubgraphs = True, debug = False): cdef AbstractTester* tester = NULL if group == "Z4": tester = new Tester[Z4[int]]() @@ -51,6 +63,20 @@ def testGroupConnectivity(G, group = "Z4", getClasses = False, assert(tester != NULL) + if useSubgraphs and group in ["Z4", "Z2_2"] and not getClasses: + for v in G.vertex_iterator(): + degs = sorted(G.degree(G.neighbors(v))) + if degs[-1] <= 2: + return False + if len(degs) == 3 and degs[0] <= 2 and degs[1] <= 2: + N = [ theOtherNeighbour(G, w, v) for w in G.neighbors(v) if G.degree(w) <= 2 ] + if G.degree(N) == [ 2, 2 ]: + return False + for (u, v, _) in G.edge_iterator(): + if sorted(G.degree(G.neighbors(u))) == [ 2, 2, 3 ] and \ + sorted(G.degree(G.neighbors(v))) == [ 2, 2, 3 ]: + return False + if useTwoCuts: G.relabel() -- GitLab