Ejemplo n.º 1
0
def test_bfs():
    # First create and initialize the environment
    env = GridEnvironment(10, 10)
    env.initialize()

    # Get the start and goal
    start = GridState(0, 0)
    goal = GridState(5, 5)

    # Solve the problem
    path = BFS.solve(env, start, goal)

    if path[0] is None:
        raise AssertionError(
            "BFS could not find feasible path in solvable environment")
Ejemplo n.º 2
0
def test_depth_limited_dfs(depth):

    # First create and initialize the environment
    env = GridEnvironment(10, 10)
    env.initialize()

    # Get the start and goal
    start = GridState(0, 0)
    goal = GridState(5, 5)

    # Solve the problem
    path = DepthLimitedDFS.solve(env, start, goal, depth_limit=depth)
    if depth < 11 and path[0] is not None:
        raise AssertionError(
            f"Depth-Limited DFS went too deep: Depth {depth}!")
    elif depth >= 11 and path[0] is None:
        raise AssertionError(
            f"DFS could not find feasible path in solvable environment. Depth {depth}"
        )
Ejemplo n.º 3
0
def test_idastar_heuristic():
    # First create and initialize the environment
    env = GridEnvironment(10, 10)
    env.initialize()

    # Get the start and goal
    start = GridState(0, 0)
    goal = GridState(5, 5)

    def h_fn(x: GridState, y: GridState):
        return 1000 * math.sqrt((x.location[0] - y.location[0])**2 +
                                (x.location[1] - y.location[1])**2)

    # Solve the problem
    path = IDAStar.solve(env, start, goal, heuristic=h_fn)

    if path[0] is None:
        raise AssertionError(
            "BFS could not find feasible path in solvable environment")