Example #1
0
def find_shortest(start, end, rooms, corridors):
    try:
        _graph = graph.Graph(rooms, corridors)
        solution = solver.solve(_graph, start, end)
    except Exception as error:
        solution = repr(error)
    return create_response(solution)
    st = time.time()

    # dummy map (for testing)
    obstacle_map = TestMap()

    # get a random start and goal
    start_node = get_random_node(obstacle_map)
    goal_node = get_random_node(obstacle_map)

    print("Start node: {}".format(start_node))
    print("Goal  node: {}".format(goal_node))

    # generate graph
    print("Building search graph...")
    st_graph = time.time()
    graph = graph.Graph(obstacle_map, start_node)
    print("Took {:.3f}s to build search graph.".format(time.time() - st_graph))

    # perform search (via Dijkstra's Algorithm)
    print("Solving for optimal path...")
    st_solve = time.time()
    d = dijkstra.Dijkstra(graph, start_node)
    d.solve()
    print("Took {:.3f}s to solve for optimal path.".format(time.time() -
                                                           st_solve))

    # get path to goal node
    optimal_path, _ = d.get_path(goal_node)
    print("Took {:.3f} for all operations.".format(time.time() - st))

    # visualize optimal path (and make video of exploration)
    # Timing metadata
    st = time.time()

    # dummy map (for testing)
    obstacle_map = FinalMap()

    # start and goal nodes
    start_node = node.Node(np.array([5, 5]))
    goal_node = node.Node(np.array([295, 195]))
    print("Start node: {}".format(start_node))
    print("Goal  node: {}".format(goal_node))

    # generate graph
    print("Building search graph...")
    st_graph = time.time()
    graph = graph.Graph(obstacle_map, start_node, buffer_=5)
    print("Took {:.3f}s to build search graph.".format(time.time() - st_graph))

    # perform search (via Dijkstra's Algorithm)
    print("Solving for optimal path...")
    st_solve = time.time()
    d = dijkstra.Dijkstra(graph, start_node)
    d.solve()
    print("Took {:.3f}s to solve for optimal path.".format(time.time() -
                                                           st_solve))

    # get path to goal node
    optimal_path, _ = d.get_path(goal_node)
    print("Took {:.3f} for all operations.".format(time.time() - st))

    # visualize optimal path (and make video of exploration)
Example #4
0
 def test_init(self):
     g_raph = graph.Graph()
     n_ode = graph.Node()