Esempio 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)
Esempio 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)
Esempio n. 3
0
                    todo.append((x,x1))
        return newconst

    def possible(self,pair,constraint):
        (x,y) = pair
        return (y,x) not in constraint

from searchBranchAndBound import DF_branch_and_bound
from searchGeneric import AStarSearcher
from searchMPP import SearcherMPP 
from stripsProblem import problem0, problem1, problem2 

rplanning0 = POP_search_from_STRIPS(problem0)
rplanning1 = POP_search_from_STRIPS(problem1)
rplanning2 = POP_search_from_STRIPS(problem2)
searcher0 = DF_branch_and_bound(rplanning0,5)
searcher0a = AStarSearcher(rplanning0)
searcher1 = DF_branch_and_bound(rplanning1,10)
searcher1a = AStarSearcher(rplanning1)
searcher2 = DF_branch_and_bound(rplanning2,10)
searcher2a = AStarSearcher(rplanning2)
# Try one of the following searchers
# a = searcher0.search()
# a = searcher0a.search()
# a.end().extract_plan()  # print a plan found
# a.end().constraints     # print the constraints
# AStarSearcher.max_display_level = 0  # less detailed display
# DF_branch_and_bound.max_display_level = 0  # less detailed display
# a = searcher1.search()
# a = searcher1a.search()
# a = searcher2.search()
Esempio n. 4
0
            for x, y in newconst:
                if x == x1 and (x0, y) not in newconst:
                    todo.append((x0, y))
                if y == x0 and (x, x1) not in newconst:
                    todo.append((x, x1))
        return newconst

    def possible(self, pair, constraint):
        (x, y) = pair
        return (y, x) not in constraint


rplanning1 = POP_search_from_STRIPS(strips_delivery1)
rplanning2 = POP_search_from_STRIPS(strips_delivery2)
rplanning3 = POP_search_from_STRIPS(strips_delivery3)
searcher1 = DF_branch_and_bound(rplanning1, 5)
searcher1a = AStarSearcher(rplanning1)
searcher2 = DF_branch_and_bound(rplanning2, 10)
searcher2a = AStarSearcher(rplanning2)
searcher3 = DF_branch_and_bound(rplanning3, 10)
searcher3a = AStarSearcher(rplanning4)
# Try one of the following searchers
# a = searcher1.search()
# a = searcher1a.search()
# a.end().extract_plan()  # print a plan found
# a.end().constraints     # print the constraints
# AStarSearcher.max_display_level = 0  # less detailed display
# DF_branch_and_bound.max_display_level = 0  # less detailed display
# a = searcher2.search()
# a = searcher2a.search()
# a = searcher3.search()