Beispiel #1
0
def compare_searchers(problems):

    searchers=[search.depth_first_tree_search,
               search.depth_limited_search,
               search.depth_first_graph_search,
               search.breadth_first_tree_search,
               search.recursive_best_first_search]


    print("----- Start comparison")
    print("a = total nr. of successful actions")
    print("ua =          of unsuccessful actions (when action() returns [])")
    print("g =           of goal tests")
    print("hmin:hmax = nr. good states vs. bad states ")
    print("s = solution")
    print("t = solving time \n\n")

    def do(searcher, problem):
        p = InstrumentedProblem(problem)
        argspec = inspect.getargspec(searcher)
        if len(argspec.args) == 1:
            searcher(p)
        else:
            searcher(p, p.h)

        p.set_end_time(time.time())
        return p

    table = [[search.name(s)] + [do(s, problems[0])] for s in searchers]
    search.print_table(table, ["Searcher", "Result"])
    print("")
    table = [[search.name(s)] + [do(s, problems[1])] for s in searchers]
    search.print_table(table, ["Searcher", "Result with reverse number selection list"])
Beispiel #2
0
def compare_searchers(problems, header, searchers=[]):
    def do(searcher, problem):
        p = search.InstrumentedProblem(problem)
        goalNode = searcher(p)
        return p, goalNode.path_cost
    table = [[search.name(s)] + [do(s, p) for p in problems] for s in searchers]
    search.print_table(table, header)
def compare_searchers(problems, header, searchers=[]):
    def do(searcher, problem):
        p = search.InstrumentedProblem(problem)
        goalNode = searcher(p)
        return p, goalNode.path_cost
    table = [[search.name(s)] + [do(s, p) for p in problems] for s in searchers]
    search.print_table(table, header)

    class GapSwitch(search.Problem):

        #A 4x4 grid, each square unmarked at the start.
        grid = (['U', 'U', 'U', 'U'],
                ['U', 'U', 'U', 'U'],
                ['U', 'U', 'U', 'U'],
                ['U', 'U', 'U', 'U'])

        #defines the state using row number first, then the spaces between marked squares required in that row,
        #  column number, and the spaces between marked squares required in that column
        state = ((2,2),(4,1))

        def actions(self, state):
            return ['M', 'U']

        def result(self, state, action):
            if action == 'up':
                return 'on'
            else:
                return 'off'

        def start(self, state, grid):
            if

        def goal_test(self, state):
            return state == 'on'

        def h(self, node):
            state = node.state
            if self.goal_test(state):
                return 0
            else:
                return 1

    switch_puzzle = LightSwitch('off')
    switch_puzzle.label = 'Light Switch'