def plan_diff(self, lambda_1, lambda_2, length): start_node = ox.get_nearest_node(self.unproj, self.env.origin) self.planner = randomplanner.planner(self.kalman.env) self.planner.set_config(3, lambda_1, lambda_2) self.planner.update_edge_weight() path = self.planner.difference_pathing(start_node, length) self.plot_graph_route_over_cost(path)
def plan_random(self, branch_per_expans, lambda_1, lambda_2, length): start_node = ox.get_nearest_node(self.unproj, self.env.origin) self.planner = randomplanner.planner(self.kalman.env) self.planner.update_edge_weight() end, graph, dict = self.planner.random_paths_unique_random_queue(start_node, length, 300) path_converted = self.planner.path_converter(dict, graph, 0, end) self.plot_graph_route_over_cost(path_converted)
def plan_dijkstras_obj_sum_test(self, branch_per_expans, lambda_1, lambda_2, length, paths_to_consider): start_node = ox.get_nearest_node(self.unproj, self.env.origin) self.planner = randomplanner.planner(self.kalman.env) self.planner.set_config(branch_per_expans, lambda_1, lambda_2) self.planner.update_edge_weight() sorted_end_list, graph, dict = self.planner.dijkstras_obj_sum_test(start_node, length, paths_to_consider) path_converted = self.planner.path_converter(dict, graph, 0, sorted_end_list[0]) self.plot_graph_route_over_cost(path_converted)
def plan_brute_force(self, lambda_1, lambda_2, length): start_node = ox.get_nearest_node(self.unproj, self.env.origin) self.planner = randomplanner.planner(self.kalman.env) self.planner.set_config(4, lambda_1, lambda_2) self.planner.update_edge_weight() sorted_end_list, graph, dict = self.planner.path_brute_force(start_node, length) path_converted = self.planner.path_converter(dict, graph, 0, sorted_end_list) self.plot_graph_route_over_cost(path_converted)
def grid_weighting_nodes(self, meters, n): self.planner = randomplanner.planner(self.kalman.env) coords = self.env.grid_weight_nodes(self.north, self.south, self.east, self.west, meters, n) nc = ox.get_node_colors_by_attr(self.env.graph, 'grid_weight', cmap='plasma', num_bins=20) fig, ax = ox.plot_graph(self.env.G, fig_height=6, node_color=nc, node_zorder=2, edge_color='#dddddd', use_geom=True, show=False, close=False) for lat, long in coords: print("(" + str(lat) + ", " + str(long) +")") ax.scatter(long, lat, c='red', alpha=0.2, s=2) ax.set_title("Weighted nodes from Grid") plt.show()
def plan_difference(self, branch_per_expans, lambda_1, lambda_2, length, paths_to_consider, from_data=False): if from_data: start_node = ox.get_nearest_node(self.graph, self.kalman.last_loc) else: print(self.env.origin) start_node = ox.get_nearest_node(self.unproj, self.env.origin) self.planner = randomplanner.planner(self.kalman.env) self.planner.set_config(branch_per_expans, lambda_1, lambda_2) self.planner.update_edge_weight() path = self.planner.difference_pathing(start_node, length) self.plot_graph_route_over_cost(path)
def plan_random_cost_per_node(self, branch_per_expans, lambda_1, lambda_2, length, paths_to_consider, from_data=False): if from_data: start_node = ox.get_nearest_node(self.unproj, self.kalman.last_loc) else: print(self.env.origin) start_node = ox.get_nearest_node(self.unproj, self.env.origin) self.planner = randomplanner.planner(self.kalman.env) self.planner.set_config(branch_per_expans, lambda_1, lambda_2) self.planner.update_edge_weight() sorted_end_list, graph, dict = self.planner.random_paths_random_queue(start_node, length, paths_to_consider) path_converted = self.planner.path_converter(dict, graph, 0, sorted_end_list) self.plot_graph_route_over_cost(path_converted)
def timer_test2(self): times = [] start_node = ox.get_nearest_node(self.unproj, self.env.origin) print("running") for x in range(200): self.kalman.wipe_initilize() self.random_kalman(200, 20000, 50000) self.planner = randomplanner.planner(self.kalman.env) self.planner.set_config(2, 0.1, 0.4) self.planner.update_edge_weight() start = time.time() sorted_end_list, graph, dict, z = self.planner.dij_timer(start_node, 21000, 200, 0.5) path_converted = self.planner.path_converter(dict, graph, 0, sorted_end_list[0]) times.append(time.time() - start)
def plan_dijkstras_edge_length(self, branch_per_expans, lambda_1, lambda_2, length, paths_to_consider, from_data=False, filename=None): if from_data: start_node = ox.get_nearest_node(self.unproj, self.kalman.last_loc) else: print(self.env.origin) start_node = ox.get_nearest_node(self.unproj, self.env.origin) self.planner = randomplanner.planner(self.kalman.env) self.planner.set_config(branch_per_expans, lambda_1, lambda_2) self.planner.update_edge_weight() start = time.time() sorted_end_list, graph, dict = self.planner.dijkstras_edge_lengths(start_node, length, paths_to_consider) print(time.time() - start) path_converted = self.planner.path_converter(dict, graph, 0, sorted_end_list[0]) self.plot_graph_route_over_cost(path_converted, filename=filename)
def plan_dijkstras1(self, branch_per_expans, lambda_1, lambda_2, length, paths_to_consider, from_data=False, filename=None): if from_data: start_node = ox.get_nearest_node(self.unproj, self.kalman.last_loc) else: print(self.env.origin) start_node = ox.get_nearest_node(self.unproj, self.env.origin) self.planner = randomplanner.planner(self.kalman.env) self.planner.set_config(branch_per_expans, lambda_1, lambda_2) self.planner.update_edge_weight() start = time.time() route = self.planner.dijkstras1(start_node, length, paths_to_consider) print("time was " + str(time.time() - start)) # nc = ox.get_node_colors_by_attr(self.kalman.env.graph, 'pol', cmap='plasma', num_bins=20) # ns = [50 if node in self.updated_nodes else 8 for node in self.kalman.env.graph.nodes()] # fig, ax = ox.plot_graph(self.kalman.env.graph, fig_height=6, node_color=nc, node_size=ns, node_zorder=2, edge_color='#dddddd', use_geom=True) self.plot_graph_route_over_cost(route, filename=filename)
def grid_weighting_nodes_dist(self, meters, n, dist): self.planner = randomplanner.planner(self.kalman.env) coords = self.planner.grid_weight_nodes_max_dist(self.north, self.south, self.east, self.west, meters, n, dist) nc = ox.get_node_colors_by_attr(self.planner.graph, 'grid_weight', cmap='plasma', num_bins=20) fig, ax = ox.plot_graph(self.planner.env.G, fig_height=6, node_color=nc, node_zorder=2, edge_color='#dddddd', use_geom=True, show=False, close=False) for lat, long in coords: print("(" + str(lat) + ", " + str(long) +")") ax.scatter(long, lat, c='red', alpha=0.3, s=3) ax.set_title("Weighted nodes from Grid") for node in self.planner.graph.nodes(): lat = self.planner.env.G.node[node]['lat'] long = self.planner.env.G.node[node]['long'] data = self.planner.graph.node[node]['grid_weight'] print(str(long) + ", " + str(lat) + ", " + str(data)) ax.annotate(long, lat, str(data)) plt.show()
def timer_test(self): times = [] #start_node = ox.get_nearest_node(self.unproj, self.env.origin) start_node = self.randomStartNode() self.kalman.wipe_initilize() self.random_kalman(200, 20000, 50000) self.planner = randomplanner.planner(self.kalman.env) self.planner.set_config(2, 0.1, 0.4) self.planner.update_edge_weight() print("running") with open('testingdeleteme.csv', 'w', newline='') as csvfile: spamwriter = csv.writer(csvfile, dialect='excel') spamwriter.writerow(['time 2 expanc', '2 expanc objective', '2 count', 'time 3 expanc', '3 expanc objective', '3 count', 'time 4 expanc', '4 expanc objective', '4 count', 'time 2 expanc dij', '2 expanc objective', '2 dij count', 'time 3 expanc dij', '3 expanc objective', '3 dij count', 'time 4 expanc dij', '4 expanc objective', '4 dij count']) distanceForRoute = 21000 for x in range(5): start_node = self.randomStartNode() self.kalman.wipe_initilize() self.random_kalman(200, 20000, 50000) # self.planner.set_config(2, 0.1, 0.4) # start2 = time.time() # y, objective2, count2 = self.planner.random_paths_unique_random_queue(start_node, distanceForRoute, 200, loopcounting=True) # end2 = time.time() # self.planner.set_config(3, 0.1, 0.4) # start3 = time.time() # # y, objective3, count3 = self.planner.random_paths_unique_random_queue(start_node, distanceForRoute, 200, loopcounting=True) # end3 = time.time() # self.planner.set_config(4, 0.1, 0.4) # start4 = time.time() # y, objective4, count4 = self.planner.random_paths_unique_random_queue(start_node, distanceForRoute, 200, loopcounting=True) # end4 = time.time() start2= "" start3="" start4="" end2="" end3="" end4="" objective2="" objective3="" objective4="" count2="" count3="" count4="" #self.kalman.set_random_loc() self.planner.set_config(2, 0.1, 0.4) start5 = time.time() y, objective5, count5 = self.planner.dijkstras1(start_node, distanceForRoute, 200, loopcounting=True) end5 = time.time() self.planner.set_config(3, 0.1, 0.4) start6 = time.time() y, objective6, count6 = self.planner.dijkstras1(start_node, distanceForRoute, 200, loopcounting=True) end6 = time.time() self.planner.set_config(4, 0.1, 0.4) start7 = time.time() y, objective7, count7 = self.planner.dijkstras1(start_node, distanceForRoute, 200, loopcounting=True) end7 = time.time() #spamwriter.writerow([end2-start2, objective2, count2, end3-start3, objective3, count3, end4-start4, objective4, count4, end5-start5, objective5, count5, end6-start6, objective6, count6, end7-start7, objective7, count7]) spamwriter.writerow([end2, objective2, count2, end3, objective3, count3, end4, objective4, count4, end5-start5, objective5, count5, end6-start6, objective6, count6, end7-start7, objective7, count7]) print(x) print(x) print(x) print(times)