def main(): # initialize the problems problem_1 = Problem1('L1.txt') problem_2 = Problem1('L2.txt') problem_3 = Problem1('L3.txt') # create the graphs based on the text file problem_1.create_graph() problem_2.create_graph() problem_3.create_graph() # create the actual problem to search problem_1 = InstrumentedProblem( GraphProblem(problem_1.start_coordinates, problem_1.end_coordinates, problem_1.graph)) problem_2 = InstrumentedProblem( GraphProblem(problem_2.start_coordinates, problem_2.end_coordinates, problem_2.graph)) problem_3 = InstrumentedProblem( GraphProblem(problem_3.start_coordinates, problem_3.end_coordinates, problem_3.graph)) #compare the search algorithms on all problems compare_searchers(problems=[problem_1, problem_2, problem_3], header=[ 'Algorithm', 'L1 ((1,1), (14,19))', 'L2 ((1,1), (12,11))', 'L3 ((1,1), (13,4))' ], searchers=[ uniform_cost_search, greedy_best_first_graph_search, astar_search ])
def main(): L1 = graphHelper() L2 = graphHelper() L3 = graphHelper() print("Manhattan") compare_searchers(problems=[ InstrumentedProblem(ManhattanProblem(L1[0], L1[1], L1[2])), InstrumentedProblem(ManhattanProblem(L2[0], L2[1], L2[2])), InstrumentedProblem(ManhattanProblem(L3[0], L3[1], L3[2])) ], header=['Algorithm', "L1", "L2", "L3"], searchers=[ uniform_cost_search, greedy_best_first_graph_search, astar_search ]) print("Euclidean") compare_searchers(problems=[ InstrumentedProblem(GraphProblem(L1[0], L1[1], L1[2])), InstrumentedProblem(GraphProblem(L2[0], L2[1], L2[2])), InstrumentedProblem(GraphProblem(L3[0], L3[1], L3[2])) ], header=['Algorithm', "L1", "L2", "L3"], searchers=[ uniform_cost_search, greedy_best_first_graph_search, astar_search ])
def main(): ''' #Explicitly create an instrumented problem ab = InstrumentedProblem(GraphProblem('A','B',romania)) goal = uniform_cost_search(ab) print("Path = ",goal.path()) print("Cost = ",goal.path_cost) print("Expanded/Goal Tests/Generated/Cost/Goal Found") ab.final_cost = goal.path_cost print(ab) ''' #To change h dynamically, provide a selection parameter in the constructor of your #derived class, then use that parameter to choose the version of h in your #overriden version of h in the derived class #You might need to create multiple versions of the problem, one for each value of the parameter simpleGraphCreation() compare_searchers(problems=[ GraphProblem('A', 'B', romania), GraphProblem('A', 'N', romania) ], header=['Algorithm', 'Romania(A, B)', 'Romania(A, N)'], searchers=[ uniform_cost_search, greedy_best_first_graph_search, astar_search ]) print()
def visualize_callback(Visualize): if Visualize is True: button.value = False problem = GraphProblem(start_dropdown.value, end_dropdown.value, romania_map) global all_node_colors user_algorithm = algorithm[algo_dropdown.value] iterations, all_node_colors, node = user_algorithm(problem) solution = node.solution() all_node_colors.append(final_path_colors(all_node_colors[0], problem, solution)) slider.max = len(all_node_colors) - 1 for i in range(slider.max + 1): slider.value = i
def __init__(self, env): """ Constructor to initialise the environment for the simple agent """ # Use the parser to get the location in state space, # the set of actions in each state, the initial starting # state and the terminal (goal) state w_1, x_1, y_1, z_1 = env2statespace(env) self.state_space_locations = w_1 self.state_space_actions = x_1 self.state_initial_id = y_1 self.state_goal_id = z_1 self.map = UndirectedGraph(self.state_space_actions) # Create a new GraphProblem instance to specify the problem in a format # in which it can be sovled self.problem = GraphProblem('{0}'.format(self.state_initial_id), '{0}'.format(self.state_goal_id), self.map)
''' Created on Oct 2, 2016 @author: farida ''' from search import romania_map, GraphProblem, breadth_first_tree_search,\ depth_first_graph_search, iterative_deepening_search,\ recursive_best_first_search, breadth_first_search, uniform_cost_search,\ depth_limited_search print("Romania Locations:") print("==================") print(romania_map.locations) print("Romania Map:") print("=============") print(romania_map.dict) romania_problem = GraphProblem('Arad', 'Bucharest', romania_map) print("Search Algorithms Results:") print("==========================") print(breadth_first_search(romania_problem).solution()) #print(breadth_first_search(romania_problem).path_cost) print(uniform_cost_search(romania_problem).solution()) #print(uniform_cost_search(romania_problem).path_cost) print(depth_first_graph_search(romania_problem).solution()) print(depth_first_graph_search(romania_problem).path_cost)
def main(): node = astar_search(GraphProblem('Lugoj', 'Bucharest', romania_map)) print(node.path())
def test_oradea_oradea(): res = bidirectional_breadth_first_search( GraphProblem("Oradea", "Oradea", romania_map), GraphProblem("Oradea", "Oradea", romania_map)) assert res.state == "Oradea"
def test_arad_bucharest(): res = bidirectional_breadth_first_search( GraphProblem("Arad", "Bucharest", romania_map), GraphProblem("Bucharest", "Arad", romania_map)) assert res.state == "Bucharest"
def romania_problem_test(): problem = GraphProblem('Arad', 'Bucharest', romania_map) s = breadth_first_tree_search(problem) assert s.state == "Bucharest"
def test_depth_first_tree_search_without_cycle_detection(): res = depth_first_tree_search( GraphProblem("Arad", "Bucharest", romania_map)) assert res.state == "Bucharest"