def __init__(self, binary): GraphBuilder.__init__(self, binary) # for func in self.external_functions.values(): # func.visualize_function() self.__label_function_boundaries() self.__create_internal_functions() self.__reduce_functions() for func in self.get_all_functions(): self.__lift_function(func)
def get_local_rrt_search_space(current_position, horizon=300): current_position = tuple((np.array(current_position) - offset[:len(current_position)]).astype(float)) print("Creating local ss", current_position) gb = GraphBuilder(np.array(current_position[:2])-horizon, np.array(current_position[:2])+horizon, polygons, collision_tree=collision_tree) print('Creating RRT graph') graph = gb.create_rrt_graph(current_position, num_vertices=300, dt=5) print('Created RRT graph') #all_nodes = np.array(list(graph.nodes)) #min_values = np.amin(all_nodes, axis=0) #max_values = np.amax(all_nodes, axis=0) search_space = GraphSearchSpace(graph, offset=offset_2D) print('Created search space') return search_space
def __init__(self, binary): """ Lift初始化 :param binary: """ logging.info("链接器初始化") GraphBuilder.__init__(self, binary) # 图构建器 # for func in self.external_functions.values(): # func.visualize_function() self.__label_function_boundaries() self.__create_internal_functions() self.__reduce_functions() for func in self.get_all_functions(): self.__lift_function(func)
def test_graph(self): graphbuilder = GraphBuilder(self.ids, self.edges) subgraphs = graphbuilder.subgraphs #test we get back 2 subgroups self.assertEqual(len(subgraphs), 2) #test the subgroups are the right sizes sortedsubgraphs = sorted(subgraphs, key=lambda x: len(x)) self.assertEqual(len(sortedsubgraphs[1]), 4)
def execute(self, params, content): """ Запустить команду на выполнение. Метод возвращает текст, который будет вставлен на место команды в вики-нотации """ params_dict = self.parseGraphParams(params) graph = GraphBuilder(params_dict, content, self.parser.page).graph render = self._getRender(graph) return render.addGraph(graph)
def create_search_space(search_space_type: SearchSpaceType, search_altitude: float, safety_distance=np.array([5, 5, 0])): """search_altitude: only for 2D search space""" print('Creating search space') # Read in obstacle map data = np.loadtxt('colliders.csv', delimiter=',', dtype='Float64', skiprows=2) # read lat0, lon0 from colliders into floating point values with open('colliders.csv') as f: origin_pos_data = f.readline().split(',') lat0 = float(origin_pos_data[0].strip().split(' ')[1]) lon0 = float(origin_pos_data[1].strip().split(' ')[1]) home = (lon0, lat0, 0) # Define a grid for a particular altitude and safety margin around obstacles polygons, min_bounds = extract_polyheights(data, safety_distance=safety_distance) north_offset, east_offset = min_bounds[:2].astype(int) print("North offset = {0}, east offset = {1}".format(north_offset, east_offset)) offset = np.array([north_offset, east_offset, 0]) offset_2D = offset[:2] # 2D map if search_space_type == SearchSpaceType.SKELETON: grid_builder = GridBuilder(polygons) prune_grid = grid_builder.create_grid_2D(altitude=search_altitude) skel_grid = grid_builder.create_grid_skeleton(altitude=search_altitude) search_space = GridGridSearchSpace(skel_grid, prune_grid, offset=offset_2D) #search_space = GridSearchSpace(grid, offset=offset_2D) elif search_space_type == SearchSpaceType.GRID_25D: grid = GridBuilder(polygons).create_grid_25D() search_space = GridSearchSpace(grid, offset=offset) elif search_space_type == SearchSpaceType.GRID_2D: grid = GridBuilder(polygons).create_grid_2D(altitude=search_altitude) search_space = GridSearchSpace(grid, offset=offset_2D) elif search_space_type == SearchSpaceType.RECEDING_HORIZON_RRT: # Very very naive rough path that just goes in a straight line get_rough_path = lambda s, g: [s, g] collision_tree = CollisionTree(polygons) def get_local_rrt_search_space(current_position, horizon=300): current_position = tuple((np.array(current_position) - offset[:len(current_position)]).astype(float)) print("Creating local ss", current_position) gb = GraphBuilder(np.array(current_position[:2])-horizon, np.array(current_position[:2])+horizon, polygons, collision_tree=collision_tree) print('Creating RRT graph') graph = gb.create_rrt_graph(current_position, num_vertices=300, dt=5) print('Created RRT graph') #all_nodes = np.array(list(graph.nodes)) #min_values = np.amin(all_nodes, axis=0) #max_values = np.amax(all_nodes, axis=0) search_space = GraphSearchSpace(graph, offset=offset_2D) print('Created search space') return search_space search_space = RecedingHorizonSearchSpace(get_local_rrt_search_space, get_rough_path) elif search_space_type == SearchSpaceType.VORONOI: graph_builder = GraphBuilder(np.array([0, 0, 0]), np.array([926, 926, 220]), polygons) graph = graph_builder.create_voronoi_graph(drone_altitude=search_altitude) search_space = GraphSearchSpace(graph, offset=offset_2D) elif search_space_type == SearchSpaceType.VORONOI_WITH_PRUNING: graph_builder = GraphBuilder(np.array([0, 0, 0]), np.array([926, 926, 220]), polygons) graph = graph_builder.create_voronoi_graph(drone_altitude=search_altitude) grid = GridBuilder(polygons).create_grid_25D() search_space = GraphGridSearchSpace(graph, grid, offset=offset) elif search_space_type == SearchSpaceType.RANDOM_SAMPLING_2D: graph_builder = GraphBuilder(np.array([0, 0, 0]), np.array([926, 926, 220]), polygons) graph = graph_builder.create_sample_graph(n_samples=500, n_d=2, k=10) search_space = GraphSearchSpace(graph, offset=offset_2D) elif search_space_type == SearchSpaceType.RANDOM_SAMPLING_3D: graph_builder = GraphBuilder(np.array([0, 0, 0]), np.array([926, 926, 220]), polygons) graph = graph_builder.create_sample_graph(n_samples=1000, n_d=3, k=10) search_space = GraphSearchSpace(graph, offset=offset) else: raise ValueError(f"Unknown search space type {search_space_type}") print('Search space created') return search_space, home