def eliminate(g, eqs, eq): rowp = [eq] remaining_eqs = sorted(n for n in g if n in eqs and n != eq) heap = PriorityQueue() heap.populate((r, len(g[r])) for r in remaining_eqs) elimination_step(g, heap, eq) while heap: eq, nzeros = heap.peekitem() if nzeros > 1: break heap.popitem() rowp.append(eq) elimination_step(g, heap, eq) return rowp, heap
def eliminate(g, remaining_eqs, eq): rowp = [ eq ] remaining_eqs.remove(eq) heap = PriorityQueue() heap.populate((r, len(g[r])) for r in sorted(remaining_eqs)) elimination_step(g, heap, eq) while heap: eq, nzeros = heap.peekitem() if nzeros > 1: break remaining_eqs.remove(eq) heap.popitem() rowp.append(eq) elimination_step(g, heap, eq) return rowp, heap
def initial_solution(g_orig, eqs): # Duplication of heap_md.min_degree with none forbidden g = fast_copy(g_orig) eq_nzeros = PriorityQueue() eq_nzeros.populate((eq, len(g[eq])) for eq in sorted(eqs)) rowp, n_tears = [ ], len(g) - len(eqs) while eq_nzeros: nzeros, eq = eq_nzeros.popitem() if nzeros: n_tears -= 1 rowp.append(eq) vrs = sorted(g[eq]) eqs_update = set(chain.from_iterable(g[v] for v in vrs)) eqs_update.discard(eq) g.remove_node(eq) g.remove_nodes_from(vrs) for e in sorted(eqs_update): eq_nzeros[e] = len(g[e]) assert len(rowp) == len(eqs) return n_tears, rowp