def run_dfs(map_path): g = graph_search.GridMap(map_path) res = graph_search.dfs(g.init_pos, g.transition, g.is_goal, graph_search._ACTIONS) print("Path: " + str(res[0])) print("Visited: " + str(res[1])) g.display_map(res[0], res[1])
def run_bfs(map_path): g = graph_search.GridMap(map_path) res = graph_search.bfs(g.init_pos, g.transition, g.is_goal, graph_search._ACTIONS) #res = graph_search.bfs(g.init_pos, g.transition, g.is_goal, graph_search._ACTIONS_2) #actionset = res[0]; print("Plan: " + str(res[0])) print("Visited: " + str(res[1])) #print res; #g.display_map(res[0],res[1]) y = len(res[0]) res1 = g.init_pos list = [] for x in range(0, y): i = 0 actionset = res[0][i] i = +1 res1 = g.bfs_simulator(res1, res[0][x], graph_search._ACTIONS, action_probability=0.8, neighbour_probability=0.1, ortho_probability=0, simulate=False) #res1 = g.bfs_simulator(res1, res[0][x], graph_search._ACTIONS_2, action_probability=0.8, neighbour_probability=0.1, ortho_probability=0.05, simulate=False) #res1= graph_search.GridMap.bfs_simulator() list.append(res1) #print res1; print(list) g.display_map(list, res[1])
def run_astar(map_path): g = graph_search.GridMap(map_path) #res = graph_search.a_star_search(g.init_pos, g.transition, g.is_goal, graph_search._ACTIONS_2, g.uninformed_heuristic_euclidean) res = graph_search.a_star_search(g.init_pos, g.transition, g.is_goal, graph_search._ACTIONS_2, g.uninformed_heuristic_manhattan) print("Path: " + str(res[0])) print("Visited: " + str(res[1])) g.display_map(res[0], res[1])
def run_value_iteration(map_path): start = time.time() g = graph_search.GridMap(map_path) actions_list = graph_search._ACTIONS #actions_list1 = graph_search._ACTIONS_2 values = g.findValues(10, -1) result = g.value_iteration(0.8, values, actions_list, 0.8, 0.1, 0) #result = g.value_iteration(0.8, values, actions_list1, 0.8, 0.1, 0.0) print("run time: " + str(time.time() - start)) print(result[0]) print(result[1]) g.display_values(result[0]) g.display_policy(result[0], result[1])
def run_PI(map_path): start = time.time() g = graph_search.GridMap(map_path) actions_list = graph_search._ACTIONS #actions_list1 = graph_search._ACTIONS_2 values = g.findValues(10, 0) policy = g.find_policy(actionset=actions_list, randomize=True) #policy = g.find_policy(actionset= actions_list1, randomize= True) result = g.PI(0.8, values, actions_list, 0.8, 0.1, 0.0, policy) #result = g.PI(0.8,values,actions_list1,0.8,0.1,0,policy) print("run time: " + str(time.time() - start)) print(result[0]) print(result[1]) g.display_values(result[0]) g.display_policy(result[0], result[1])
import graph_search g = graph_search.GridMap('./map0.txt') file = open('output0.txt', 'a') [[path, action_path],visited]=graph_search.dfs(g.init_pos , g.transition , g.is_goal, graph_search._ACTIONS) file.write("BFS on map0: path = "+str(path) + "\n") file.write("BFS on map0: action_path = "+str(action_path) + "\n") file.write("BFS on map0: visited = "+str(visited) + "\n") g.display_map(path,visited) file.close() import graph_search g = graph_search.GridMap('./map1.txt') file = open('output1.txt', 'a') [[path, action_path],visited]=graph_search.dfs(g.init_pos , g.transition , g.is_goal, graph_search._ACTIONS) file.write("BFS on map1: path = "+str(path) + "\n") file.write("BFS on map1: action_path = "+str(action_path) + "\n") file.write("BFS on map2: visited = "+str(visited) + "\n") g.display_map(path,visited) file.close() import graph_search g = graph_search.GridMap('./map2.txt') file = open('output2.txt', 'a') [[path, action_path],visited]=graph_search.dfs(g.init_pos , g.transition , g.is_goal, graph_search._ACTIONS) file.write("BFS on map2: path = "+str(path) + "\n") file.write("BFS on map2: action_path = "+str(action_path) + "\n") file.write("BFS on map2: visited = "+str(visited) + "\n") g.display_map(path,visited) file.close()
s = sim.Sim() s.sim_connect() s.sim_start() s.sim_get_handles() #If using V_REP, start second thread for rover control if not _SANS_V_REP: #Start the interface thread to send frame instructions try: thread.start_new_thread( s.sim_drive_rover, ()) except: print "Error: unable to start thread" #Load terrain image file and compute slope map print "Loading", cmn._map_file g = graph_search.GridMap(s, cmn._map_file) g.calcRatesOfChange(n=3, ret=False,dbg=False) #Create plotes for each action direction and save to disk cmap = cm.Spectral; cmap.set_bad(color='k') cmn.createArrImg(g.height_map, cmap=cmap, plotTitle='Height Map', fn=os.path.join(cmn._IMG_FLDR, 'heightmap.svg'), show=False) for a in cmn._actions: cmn.createArrImg(g.rates[0][a], cmap=cmap, plotTitle='Rate Map: {}'.format(a), fn=os.path.join(cmn._IMG_FLDR, 'ratemap_{}.svg'.format(a)), show=False) cmn.overlayArrImgs(arr1=g.height_map, arr2=g.rates[0][a], plotTitle='Overlayed Rate Map: {}'.format(a), fn=os.path.join(cmn._IMG_FLDR, 'ratemap_ovr_{}.svg'.format(a)), show=False) rover_pos = s.sim_get_xy(s.rover_handle) changed_rover_pos = cmn.convert_VREPXY(rover_pos)
def run_dfs(map_path): g = graph_search.GridMap(map_path) res = graph_search.dfs(g.init_pos, g.transition, g.is_goal, graph_search._ACTIONS) g.display_map(res[0][0], res[1])