def solveE(G, even_nodes, odd_nodes, h, pe, po): all_nodes = G.get_nodes() amount_nodes = len(all_nodes) if amount_nodes == 0 or pe <= 1 or h < 0: return [] pe = min(amount_nodes, pe) po = min(amount_nodes, po) while True: Nh = [node for node in G.get_nodes() if node.get_priority() == h] ATRE, _ = atr(G, even_nodes, Nh, 0) if contain_all(G, ATRE, h): Nh_2 = [node for node in G.get_nodes() if node.get_priority() == h-2] Nh += Nh_2 ATRE, _ = atr(G, even_nodes, Nh, 0) nodes, edges = G.remove_nodes(ATRE) H = Graph(nodes, edges) WO = solveO(H, even_nodes, odd_nodes, h-1, po//2, pe) ATRO, equal = atr(G, odd_nodes, WO, 1) nodes, edges = G.remove_nodes(ATRO) G = Graph(nodes, edges) if equal: # testing W0 == ATR0 break #Nh = [node for node in G.get_nodes() if node.get_priority() == h] #ATRE, _ = atr(G, even_nodes, Nh, 0) #nodes, edges = G.remove_nodes(ATRE) #H = Graph(nodes, edges) WO = solveO(H, even_nodes, odd_nodes, h-1, po, pe) ATRO, equal = atr(G, odd_nodes, WO, 1) nodes, edges = G.remove_nodes(ATRO) G = Graph(nodes, edges) while not(equal): Nh = [node for node in G.get_nodes() if node.get_priority() == h] ATRE, _ = atr(G, even_nodes, Nh, 0) if contain_all(G, ATRE, h): Nh_2 = [node for node in G.get_nodes() if node.get_priority() == h-2] Nh += Nh_2 ATRE, _ = atr(G, even_nodes, Nh, 0) nodes, edges = G.remove_nodes(ATRE) H = Graph(nodes, edges) WO = solveO(H, even_nodes, odd_nodes, h-1, po//2, pe) ATRO, equal = atr(G, odd_nodes, WO, 1) nodes, edges = G.remove_nodes(ATRO) G = Graph(nodes, edges) WE = G.get_nodes() return WE
def solveO(G, even_nodes, odd_nodes, h, po, pe): all_nodes = G.get_nodes() if len(all_nodes) == 0 or po <= 1 or h < 0: return [] while True: Nh = [node for node in G.get_nodes() if node.get_priority() == h] ATRO, _ = atr(G, odd_nodes, Nh, 1) if contain_all(G, ATRO, h): Nh_2 = [ node for node in G.get_nodes() if node.get_priority() == h - 2 ] Nh += Nh_2 ATRO, _ = atr(G, odd_nodes, Nh, 1) nodes, edges = G.remove_nodes(ATRO) H = Graph(nodes, edges) WE = solveE(H, even_nodes, odd_nodes, h - 1, pe // 2, po) ATRE, equal = atr(G, even_nodes, WE, 0) nodes, edges = G.remove_nodes(ATRE) G = Graph(nodes, edges) if equal: # testing WE == ATRE break Nh = [node for node in G.get_nodes() if node.get_priority() == h] ATRO, _ = atr(G, odd_nodes, Nh, 1) nodes, edges = G.remove_nodes(ATRO) H = Graph(nodes, edges) WE = solveE(H, even_nodes, odd_nodes, h - 1, pe, po) ATRE, equal = atr(G, even_nodes, WE, 0) nodes, edges = G.remove_nodes(ATRE) G = Graph(nodes, edges) while not (equal): Nh = [node for node in G.get_nodes() if node.get_priority() == h] ATRO, _ = atr(G, odd_nodes, Nh, 1) if contain_all(G, ATRO, h): Nh_2 = [ node for node in G.get_nodes() if node.get_priority() == h - 2 ] Nh += Nh_2 ATRO, _ = atr(G, odd_nodes, Nh, 1) nodes, edges = G.remove_nodes(ATRO) H = Graph(nodes, edges) WE = solveE(H, even_nodes, odd_nodes, h - 1, pe // 2, po) ATRE, equal = atr(G, even_nodes, WE, 0) nodes, edges = G.remove_nodes(ATRE) G = Graph(nodes, edges) WO = G.get_nodes() return WO
def solveE(G, even_nodes, odd_nodes, h, pe, po): all_nodes = G.get_nodes() if len(all_nodes) == 0 or pe <= 1 or h < 0: return [] while True: Nh = [node for node in G.get_nodes() if node.get_priority() == h] ATRE = atr(G, even_nodes, Nh, 0) nodes, edges = G.remove_nodes(ATRE) H = Graph(nodes, edges) WO = solveO(H, even_nodes, odd_nodes, h-1, po//2, pe) ATRO = atr(G, odd_nodes, WO, 1) nodes, edges = G.remove_nodes(ATRO) G = Graph(nodes, edges) if len(WO) == 0: # testing W0 emptiness break Nh = [node for node in G.get_nodes() if node.get_priority() == h] ATRE = atr(G, even_nodes, Nh, 0) nodes, edges = G.remove_nodes(ATRE) H = Graph(nodes, edges) WO = solveO(H, even_nodes, odd_nodes, h-1, po, pe) ATRO = atr(G, odd_nodes, WO, 1) nodes, edges = G.remove_nodes(ATRO) G = Graph(nodes, edges) while len(WO) != 0: Nh = [node for node in G.get_nodes() if node.get_priority() == h] ATRE = atr(G, even_nodes, Nh, 0) nodes, edges = G.remove_nodes(ATRE) H = Graph(nodes, edges) WO = solveO(H, even_nodes, odd_nodes, h-1, po//2, pe) ATRO = atr(G, odd_nodes, WO, 1) nodes, edges = G.remove_nodes(ATRO) G = Graph(nodes, edges) WE = G.get_nodes() return WE
def solveE(G, even_nodes, odd_nodes, h, pe, po): all_nodes = G.get_nodes() if len(all_nodes) == 0 or pe <= 1 or h < 0: return [] while True: Nh = [node for node in G.get_nodes() if node.get_priority() == h] ATRE, equal = atr(G, even_nodes, Nh, 0) nodes, edges = G.remove_nodes(ATRE) H = Graph(nodes, edges) WO = solveO(H, even_nodes, odd_nodes, h - 1, po // 2, pe) ATRO, equal = atr(G, odd_nodes, WO, 1) nodes, edges = G.remove_nodes(ATRO) G = Graph(nodes, edges) if equal: # testing W0 == ATR0 break Nh = [node for node in G.get_nodes() if node.get_priority() == h] ATRE, _ = atr(G, even_nodes, Nh, 0) nodes, edges = G.remove_nodes(ATRE) H = Graph(nodes, edges) WO = solveO(H, even_nodes, odd_nodes, h - 1, po, pe) ATRO, equal = atr(G, odd_nodes, WO, 1) nodes, edges = G.remove_nodes(ATRO) G = Graph(nodes, edges) while not (equal): Nh = [node for node in G.get_nodes() if node.get_priority() == h] ATRE, _ = atr(G, even_nodes, Nh, 0) nodes, edges = G.remove_nodes(ATRE) H = Graph(nodes, edges) WO = solveO(H, even_nodes, odd_nodes, h - 1, po // 2, pe) ATRO, equal = atr(G, odd_nodes, WO, 1) nodes, edges = G.remove_nodes(ATRO) G = Graph(nodes, edges) WE = G.get_nodes() return WE