def main(p_choices, s_choices): problems = [PROBLEMS[i-1] for i in map(int, p_choices)] searches = [SEARCHES[i-1] for i in map(int, s_choices)] for pname, problem_fn in problems: for sname, search_fn, heuristic in searches: hstring = heuristic if not heuristic else " with {}".format(heuristic) print("\nSolving {} using {}{}...".format(pname, sname, hstring)) problem_instance = problem_fn() heuristic_fn = None if not heuristic else getattr(problem_instance, heuristic) run_search(problem_instance, search_fn, heuristic_fn)
def main(p_choices, s_choices): problems = [PROBLEMS[i - 1] for i in map(int, p_choices)] searches = [SEARCHES[i - 1] for i in map(int, s_choices)] #columns=['Problem', 'Number', 'Search Method', 'Heuristic', \ # 'Actions', 'Expansions', 'Goal Tests', 'New Nodes' \ # 'Plan length', 'Time'] #results = pd.DataFrame(columns=columns) results = [] for pname, problem_fn in problems: for sname, search_fn, heuristic in searches: hstring = heuristic if not heuristic else " with {}".format( heuristic) print("\nSolving {} using {}{}...".format(pname, sname, hstring)) problem_instance = problem_fn() heuristic_fn = None if not heuristic else getattr( problem_instance, heuristic) ip, plan_length, time = run_search(problem_instance, search_fn, heuristic_fn) results.append([pname, sname, hstring, ip, plan_length, time]) with open("results.txt", "w") as f: for s in results: f.write(str(s) + "\n")
def main(p_choices, s_choices): problems = [PROBLEMS[i - 1] for i in map(int, p_choices)] searches = [SEARCHES[i - 1] for i in map(int, s_choices)] out_list = [] for pname, problem_fn in problems: for sname, search_fn, heuristic in searches: hstring = heuristic if not heuristic else " with {}".format( heuristic) print("\nSolving {} using {}{}...".format(pname, sname, hstring)) problem_instance = problem_fn() heuristic_fn = None if not heuristic else getattr( problem_instance, heuristic) out = "{},{}{},{}".format( pname, sname, hstring, run_search(problem_instance, search_fn, heuristic_fn)) out_list.append(out) import datetime curr_time = datetime.datetime.now().strftime("%H%M%S") with open("output_{}.csv".format(curr_time), "w") as f: f.write( "Problem,SearchAlgo,Actions,Expansions,Goal_Tests,New_Nodes,Plan_Length,Time\n" ) for l in out_list: f.write("{}\n".format(l)) print("print output to output_{}.csv".format(curr_time))
def main(p_choices, s_choices): problems = [PROBLEMS[i - 1] for i in map(int, p_choices)] searches = [SEARCHES[i - 1] for i in map(int, s_choices)] print( "Problem,Search,Actions,Expansions,Goal_Tests,New_Nodes,Plan_Length,Time" ) for pname, problem_fn in problems: for sname, search_fn, heuristic in searches: hstring = heuristic if not heuristic else " with {}".format( heuristic) #print("\nSolving {} using {}{}...".format(pname, sname, hstring)) problem_instance = problem_fn() heuristic_fn = None if not heuristic else getattr( problem_instance, heuristic) run_search(problem_instance, search_fn, heuristic_fn, pname, sname, hstring)
return have_relations + eaten_relations return HaveCakeProblem(get_init(), get_goal()) if __name__ == '__main__': p = have_cake() print("**** Have Cake example problem setup ****") print("Fluents in this problem are:") for f in p.state_map: print(' {}'.format(f)) print("Initial state for this problem is {}".format(p.initial)) print("Actions for this domain are:") for a in p.actions_list: print(' {}{}'.format(a.name, a.args)) print("Goal requirement for this problem are:") for g in p.goal: print(' {}'.format(g)) print() print("*** Breadth First Search") run_search(p, breadth_first_search) print("*** Depth First Search") run_search(p, depth_first_graph_search) print("*** Uniform Cost Search") run_search(p, uniform_cost_search) print("*** Greedy Best First Graph Search - null heuristic") run_search(p, greedy_best_first_graph_search, parameter=lambda x: 0) print("*** A-star null heuristic") run_search(p, astar_search, lambda x: 0)