def graph_distance( ci, cj, graph ): p,c = shortpath.astar( graph, ci, cj ) return c
best, phero = ants.search(G, max_it, num_ants, decay, w_heur, w_local_phero, w_history, c_greed, cost_func=ants.graph_distance) LOGN( "\tTransform the resulting nodes permutation into a path on the graph") # by finding the shortest path between two cities. traj = [] for start, end in utils.tour(best["permutation"]): p, c = shortpath.astar(G, start, end) traj += p trajs.append(traj) with open("d%i_tour.points" % depth, "w") as fd: utils.write_points(traj, fd) with open("d%i_pheromones.mat" % depth, "w") as fd: utils.write_matrix(phero, fd) ######################################################################## # TRIANGULATION ######################################################################## triangulated = []
max_it = 2 # num_ants = 10 #* depth num_ants = 2 #* depth decay = 0.1 w_heur = 2.5 w_local_phero = 0.1 c_greed = 0.9 w_history = 1.0 best,phero = ants.search( G, max_it, num_ants, decay, w_heur, w_local_phero, w_history, c_greed, cost_func = ants.graph_distance ) LOGN( "\tTransform the resulting nodes permutation into a path on the graph" ) # by finding the shortest path between two cities. traj = [] for start,end in utils.tour(best["permutation"]): p,c = shortpath.astar( G, start, end ) traj += p trajs.append(traj) with open("d%i_tour.points" % depth, "w") as fd: utils.write_points( traj, fd ) with open("d%i_pheromones.mat" % depth, "w") as fd: utils.write_matrix( phero, fd ) ######################################################################## # TRIANGULATION ######################################################################## triangulated = []