Beispiel #1
0
def count_satisfiable(arg):
    N, i, p_occ = arg

    expanded = 0
    completed = 0
    for _ in range(100):
        count_satisfiable.q.put(i)
        problem = get_random_grid_problem(p_occ, N, N)
        path, num_nodes_expanded, _ = a_star_search(problem)

        expanded += num_nodes_expanded
        if path is not None:
            completed += 1

    return completed, expanded
    Simply fill in the prob. of occupancy values for the 'phase transition' and peak nodes expanded within 0.05. You do
    NOT need to submit your code that determines the values here: that should be computed on your own machine. Simply
    fill in the values!

    :return: tuple containing (transition_start_probability, transition_end_probability, peak_probability)
    """
    ####
    #   REPLACE THESE VALUES
    ####
    transition_start_probability = -1.0
    transition_end_probability = -1.0
    peak_nodes_expanded_probability = -1.0
    return transition_start_probability, transition_end_probability, peak_nodes_expanded_probability


if __name__ == '__main__':
    # Test your code here!
    # Create a random instance of GridSearchProblem
    p_occ = 0.25
    M = 50
    N = 50
    problem = get_random_grid_problem(p_occ, M, N)
    # Solve it
    path, num_nodes_expanded, max_frontier_size = a_star_search(problem)
    # Check the result
    correct = problem.check_solution(path)
    print("Solution is correct: {:}".format(correct))
    # Plot the result
    problem.plot_solution(path)

    # Experiment and compare with BFS
    # problem = get_random_grid_problem(p_occ, M, N)
    # # Solve it
    # path, num_nodes_expanded, max_frontier_size = a_star_search(problem)
    #
    # # Check the result
    # correct = problem.check_solution(path)
    # print("Solution is correct: {:}".format(correct))
    # # Plot the result
    # problem.plot_solution(path)

    # Experiment and compare with BFS
    x = []
    solvability = []
    effort = []
    for i in np.arange(0.1, 0.95, 0.05):
        x.append(i)
        node_count = 0
        solved = 0
        for j in range(100):
            problem = get_random_grid_problem(i, M, N)
            path, num_nodes_expanded, max_frontier_size = a_star_search(problem)
            node_count += num_nodes_expanded
            if path != []:
                solved = solved + 1
        effort.append(node_count / 100)
        solvability.append(solved / 100)

    fig, ax = plt.subplots(2, 1)
    ax[0].plot(x, solvability)
    ax[1].plot(x, effort)
    plt.show()