def refineColors(self, g1, g2): """ Refines the colors with the graphs :param g1: graph1 :param g2: graph2 :return: Nothing, this function acts on the current object """ if self.refined: print("Warning! Refining a ColorCombination that is already flagged as refined!") self.applyToGraphs(g1, g2) g = disjointUnionMulti([g1, g2], True) p = generatePartitions(g, True) newColoring = dict() for c in range(len(p)): for v in p[c]: newColoring[v] = c # newColoring = refineColorsv2(g, True) newColoringG1 = dict() gV = g.V() g1V = g1.V() for i in range(len(g1V)): newColoringG1[g1V[i]] = newColoring[gV[i]] newColoringG2 = dict() g2V = g2.V() for i in range(len(g2V)): newColoringG2[g2V[i]] = newColoring[gV[i + len(g1V)]] self.generateCoreValues(newColoringG1, newColoringG2, True)
def countTreeAutomorphismsRS(G, visualize=False): p = generatePartitions(G) n = generateNeighbourList(G) degrees = dict() for v in G.V(): degree = len(n[v]) degreeSet = degrees.get(degree, 0) if degreeSet: degreeSet.add(v) else: degrees[degree] = {v} colorOf = dict() for color in p: for v in color: colorOf[v] = color queue = [] done = set() automorphisms = 1 for c in p: if len(c) == 1: queue.append((pickFromSet(c), None)) break if not queue: for c in p: if len(c) == 2: r, l = c if True or l in n[r]: queue.append((r, None)) break while queue: vertex, parent = queue[-1] color = colorOf[vertex] del queue[-1] for v in n[vertex] - done: if v not in done: queue.append((v, vertex)) done |= colorOf[v] if parent: automorphisms *= factorial(len(n[parent] & color))**(len(colorOf[parent])) else: automorphisms *= factorial(len(color)) if visualize: drawProgress(G, vertex, color, done, queue) done |= color if visualize: drawProgress(G, None, set(), done, queue) return automorphisms
def countTreeAutomorphismsLS(G, visualize=False): p = generatePartitions(G) n = generateNeighbourList(G) degrees = dict() for v in G.V(): degree = len(n[v]) degreeSet = degrees.get(degree, 0) if degreeSet: degreeSet.add(v) else: degrees[degree] = {v} colorOf = dict() for color in p: for v in color: colorOf[v] = color queue = [] done = set() for color in p: if len(color) > 1 and color <= degrees[1]: queue.append(color) done = done | color automorphisms = 1 while queue: # is not empty newQueue = [] for color in queue: v = pickFromSet(color) if visualize: drawProgress(G, v, color, done, queue) parent = None for neighbour in n[v]: if len(n[neighbour] & color) > 1 : parent = neighbour break if parent is None: unvisitedNeighbours = n[v] - done if len(unvisitedNeighbours) == 1: parent = unvisitedNeighbours.pop() elif len(unvisitedNeighbours) > 1: newQueue.append(color) continue if parent: if len(colorOf[parent]) > 1 and parent not in done: newQueue.append(colorOf[parent]) automorphisms *= factorial(len(n[parent] & color))**(len(colorOf[parent])) done |= color else: if len(color) == 2 and len(color&n[v]) == 1: automorphisms *= 2 queue = newQueue for c in queue: done |= c if visualize: drawProgress(G, None, set(), done, queue) return automorphisms