コード例 #1
0
ファイル: searchTest.py プロジェクト: atharvajoshi10/ML
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)
コード例 #2
0
def main():
    prob = Tile_problem(4, [1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0])
    #prob = Tile_problem(3, [1,1,0, 1,0,0, 1,0,1])
    s = AStarSearcher(prob)
    path = s.search()
    if path:
        print(f"Path found (cost = {path.cost})\n{path}")
        return path
コード例 #3
0
def main():
    smoke_test()
    prob = River_problem()
    s = AStarSearcher(prob)
    path = s.search()
    if path:
        print("Path found (cost=%s)\n%s" % (path.cost, path))
        return path

    if __name__ == '__main__':
        main()
コード例 #4
0
ファイル: fuzzyScheduler.py プロジェクト: Zhaokun1997/2020T2
            task = var[0]
            duration = var[1]
            domains[task] = sorted({(i * 10 + j, i * 10 + j + duration) for i in range(1, 6) for j in range(1, 10 - duration)})

    # print("variables = ", variables)
    # print("domains = ", domains)
    # print("constraints", constraints)
    # print("soft_constraints", soft_constraints)
    # print("soft_cost", soft_cost)

    # which adds soft_constraints and soft_cost compared with origin
    my_csp = My_CSP(domains, constraints, soft_constraints, soft_cost)
    my_problem = Search_with_AC_from_Cost_CSP(my_csp)
    my_searcher = AStarSearcher(my_problem)

    my_solution = my_searcher.search()
    # print(my_solution)
    if my_solution is not None:  # there is a solution if finding a path
        final_schedule = my_solution.end()  # find the end node(result) in our solution path
        if final_schedule is not None:
            my_cost = my_problem.heuristic(final_schedule)
            for task in final_schedule:
                start_time = list(final_schedule[task])[0][0]
                day = start_time // 10
                time = start_time % 10
                output_day = ""
                output_time = ""
                for key in day2num:
                    if day2num[key] == day:
                        output_day = key
                for key in time2num: