print("there are",msearcher.frontier.count(msearcher.solution.cost), "elements remaining on the queue with f-value=",msearcher.solution.cost) bound = asearcher.solution.cost+0.01 print("\nBranch and bound (with too-good initial bound of", bound,")") tbb = DF_branch_and_bound(problem,bound) # cheating!!!! print("Path found:",tbb.search()," cost=",tbb.solution.cost) print("Rerunning B&B") print("Path found:",tbb.search()) bbound = asearcher.solution.cost*2+10 print("\nBranch and bound (with not-very-good initial bound of", bbound, ")") tbb2 = DF_branch_and_bound(problem,bbound) # cheating!!!! print("Path found:",tbb2.search()," cost=",tbb2.solution.cost) print("Rerunning B&B") print("Path found:",tbb2.search()) print("\nDepth-first search: (Use ^C if it goes on forever)") tsearcher = Searcher(problem) print("Path found:",tsearcher.search()," cost=",tsearcher.solution.cost) import searchProblem from searchTest import run if __name__ == "__main__": run(searchProblem.problem1,"Problem 1") # run(searchProblem.acyclic_delivery_problem,"Acyclic Delivery") # run(searchProblem.cyclic_delivery_problem,"Cyclic Delivery") # also test some graphs with cycles, and some with multiple least-cost paths
print("Rerunning B&B") print("Path found:", tbb.search()) bbound = asearcher.solution.cost * 2 + 10 print("\nBranch and bound (with not-very-good initial bound of", bbound, ")") tbb2 = DF_branch_and_bound(problem, bbound) # cheating!!!! print("Path found:", tbb2.search(), " cost=", tbb2.solution.cost) print("Rerunning B&B") print("Path found:", tbb2.search()) print("\nBFS: (Use ^C if it goes on forever)") bfs = BFS(problem) print("Path found:", bfs.search(), " cost=", bfs.solution.cost) print("\nDepth-first search: (Use ^C if it goes on forever)") #tsearcher = Searcher(problem) print("Path found:", tsearcher.search(), " cost=", tsearcher.solution.cost) import searchProblem from searchTest import run if __name__ == "__main__": #run(searchProblem.problem2,"problem2") run(searchProblem.Romania_map, "Romania_map") # run(searchProblem.acyclic_delivery_problem,"Acyclic Delivery") # run(searchProblem.cyclic_delivery_problem,"Cyclic Delivery") # also test some graphs with cycles, and some with multiple least-cost paths
# bound = asearcher.solution.cost + 0.01 # print("\nBranch and bound (with too-good initial bound of", bound, ")") # tbb = DF_branch_and_bound(problem, bound) # cheating!!!! # print("Path found:", tbb.search(), " cost=", tbb.solution.cost) # print("Rerunning B&B") # print("Path found:", tbb.search()) # # bbound = asearcher.solution.cost * 2 + 10 # print("\nBranch and bound (with not-very-good initial bound of", bbound, ")") # tbb2 = DF_branch_and_bound(problem, bbound) # cheating!!!! # print("Path found:", tbb2.search(), " cost=", tbb2.solution.cost) # print("Rerunning B&B") # print("Path found:", tbb2.search()) print("\nDepth-first search: (Use ^C if it goes on forever)") tsearcher = Searcher(problem) print("Path found:", tsearcher.search(), " cost=", tsearcher.solution.cost) # print("\nBreadth-first search: ") # tsearcher = BFSearcher(problem) # print("Path found:", tsearcher.search(), # " cost=", tsearcher.solution.cost) if __name__ == "__main__": run(searchProblem.romania_map, "romania_map") # run(searchProblem.acyclic_delivery_problem,"Acyclic Delivery") # run(searchProblem.cyclic_delivery_problem,"Cyclic Delivery") # also test some graphs with cycles, and some with multiple least-cost paths
def run(problem, name): print("\n\n*******", name) print("\nA*:") tsearcher = Searcher(problem) print("Path found:", tsearcher.search(), " cost=", tsearcher.solution.cost) print("there are", tsearcher.frontier.count(tsearcher.solution.cost), "elements remaining on the queue with f-value=", tsearcher.solution.cost) print("\nA* with MPP:"), msearcher = SearcherMPP(problem) print("Path found:", msearcher.search(), " cost=", msearcher.solution.cost) print("there are", msearcher.frontier.count(msearcher.solution.cost), "elements remaining on the queue with f-value=", msearcher.solution.cost) print("\nBranch and bound (with too-good initial bound):") tbb = DF_branch_and_bound(problem, tsearcher.solution.cost + 0.1) # cheating!!!! print("Path found:", tbb.search(), " cost=", tbb.solution.cost) if __name__ == "__main__": run(searchProblem.search_simple1, "Problem 1") # run(searchProblem.search_acyclic_delivery,"Acyclic Delivery") # run(searchProblem.search_cyclic_delivery,"Cyclic Delivery") # also test some graphs with cycles, and some with multiple least-cost paths