def solve(G): """ Args: G: networkx.Graph Returns: T: networkx.Graph """ g = GraphSolver(G) start = g.find_leaf_path() T = g.dijkstra_solve_graph(start, calculate_heuristic, first_heuristic) optimize_sorted(g, T) rebuilder = Rebuilder(g) min_T = T.copy() min_cost = average_pairwise_distance(T) # print('*', min_cost) for _ in range(50): if rebuilder.rebuild(): g = GraphSolver(G) for v in min_T.nodes: g.visit(v) for e in min_T.edges: g.add_edge(e) # print('reset') g.dijkstra_solve_graph(start, calculate_heuristic, first_heuristic) optimize_sorted(g, g.T) cost = average_pairwise_distance(g.T) # print(cost) if cost < min_cost: min_cost = cost min_T = g.T.copy() return min_T
def solve(G): """ Args: G: networkx.Graph Returns: T: networkx.Graph """ # TODO: your code here! g = GraphSolver(G) T = g.dijkstra_solve_graph() return T
def solve(G): """ Args: G: networkx.Graph Returns: T: networkx.Graph """ g = GraphSolver(G) start = g.find_leaf_path() T = g.dijkstra_solve_graph(start, calculate_heuristic, first_heuristic) return T
def solve(G): """ Args: G: networkx.Graph Returns: T: networkx.Graph """ g = GraphSolver(G) start = g.find_leaf_path() T = g.dijkstra_solve_graph(start, calculate_heuristic, first_heuristic) optimize_sorted(g, T, kill_cycle_all_paths) return T
def solve(G): """ Args: G: networkx.Graph Returns: T: networkx.Graph """ g = GraphSolver(G) T = g.dijkstra_solve_graph(None, calculate_heuristic, first_heuristic) if average_pairwise_distance(T) == 0: return T optimize_sorted(g, T, cycle_killer_fn=kill_cycle) return T
def solve(G): """ Args: G: networkx.Graph Returns: T: networkx.Graph """ g = GraphSolver(G) start = g.find_leaf_path() T = g.dijkstra_solve_graph(start, calculate_heuristic, first_heuristic) if average_pairwise_distance(T) == 0: return T optimize(g, T) return T