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 test_forward_heuristic(thisproblem=problem1):
    print("\n***** FORWARD NO HEURISTIC")
    print(SearcherMPP(Forward_STRIPS(thisproblem)).search())

    print("\n***** FORWARD WITH HEURISTIC h1")
    print(SearcherMPP(Forward_STRIPS(thisproblem, h1)).search())

    print("\n***** FORWARD WITH HEURISTICs h1 and h2")
    print(SearcherMPP(Forward_STRIPS(thisproblem, maxh(h1, h2))).search())
Esempio n. 3
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. 4
0
def test_regression_heuristic(thisproblem=problem1):
    print("\n***** REGRESSION NO HEURISTIC")
    print(SearcherMPP(Regression_STRIPS(thisproblem)).search())

    print("\n***** REGRESSION WITH HEURISTICs h1 and h2")
    print(SearcherMPP(Regression_STRIPS(thisproblem, maxh(h1, h2))).search())
Esempio n. 5
0
        return newconst

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


from searchBranchAndBound import DF_branch_and_bound
from searchMPP import SearcherMPP
from stripsProblem import problem0, problem1, problem2, blocks1, blocks2, blocks3

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 = SearcherMPP(rplanning0)
searcher1 = DF_branch_and_bound(rplanning1, 10)
searcher1a = SearcherMPP(rplanning1)
searcher2 = DF_branch_and_bound(rplanning2, 10)
searcher2a = SearcherMPP(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
# SearcherMPP.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()
# a = searcher2a.search()
        'cash_pop_out_from_T3':
        Strips({'REQUEST_SENT_FROM_T3': True}, {'RESPONSE_SENT_TO_T3': True}),
        'close_T3_connection':
        Strips({'RESPONSE_SENT_TO_T3': True}, {
            'T3_CONNECTTED': False,
            'SERVER_LISTENING': False,
            'FREE_SOCKET_T3': False
        }),
    })

case1 = Planning_problem(domain, {'T_IDLE': 'T1'}, {
    'RESPONSE_SENT_TO_T1': True,
    'T1_CONNECTTED': False
})

case1_solution1 = SearcherMPP(Forward_STRIPS(case1)).search()
case1_solution2 = SearcherMPP(Regression_STRIPS(case1)).search()

print('---------')
print('case1 forward planner solution:')
print(case1_solution1)
print('---------')
print('case1 regression planner solution:')
print(case1_solution2)
print('---------')

case2 = Planning_problem(domain, {'T_IDLE': 'T2_T3'}, {
    'RESPONSE_SENT_TO_T3': True,
    'RESPONSE_SENT_TO_T2': True,
    'T3_CONNECTTED': False,
    'T2_CONNECTTED': False