Ejemplo n.º 1
0
def run(problem,name):
    print("\n\n*******",name)

    print("\nA*:")
    asearcher = AStarSearcher(problem)
    print("Path found:",asearcher.search(),"  cost=",asearcher.solution.cost)
    print("there are",asearcher.frontier.count(asearcher.solution.cost),
          "elements remaining on the queue with f-value=",asearcher.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)

    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)
Ejemplo n.º 2
0
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)