def run(G: Graph) -> Result: memory: int = 0 k: int = 0 W: float = 0.0 path: List[Edge] = [] vertices: List[int] = G.vertices() memory += sizeof(vertices) i: int = randrange(len(vertices)) start: int = vertices[i] del vertices[i] u: int = start while len(vertices) > 0: i = randrange(len(vertices)) v: int = vertices[i] del vertices[i] e = G.get_edge(u, v) path.append(e) W += e.w k += 1 u = v e = G.get_edge(u, start) path.append(e) W += e.w k += 1 return Result(k, W, memory, path=path)
def run(G: Graph) -> Result: memory: int = 0 k: int = 0 W: float = 0.0 path: List[Edge] = [] vertices: List[int] = G.vertices() memory += sizeof(vertices) i: int = randrange(len(vertices)) start: int = vertices[i] del vertices[i] G.order_edges() u: int = start while len(vertices) > 0: next_e: Optional[Edge] = next( (e for e in G.get_incident_edges(u) if e.snd in vertices), None) if next_e is None: raise Exception('None') v: int = next_e.snd vertices.remove(v) e = G.get_edge(u, v) path.append(e) W += e.w k += 1 u = v e = G.get_edge(u, start) path.append(e) W += e.w k += 1 return Result(k, W, memory, path=path)