Exemple #1
0
 def __init__(self, max_depth=infinity):
     '''
     Constructs the graph search with the queue being a LIFO queue.
     This causes the order in which we traverse newly discovered nodes to be in
     a depth first manner.
     Optionally, a maximum depth may be provided at which to stop looking for
     the goal state.
     '''
     GraphSearch.__init__(self, LIFOQueue, max_depth)
Exemple #2
0
 def __init__(self, max_depth=infinity):
     '''
     Constructs the graph search with the queue being a LIFO queue.
     This causes the order in which we traverse newly discovered nodes to be in
     a depth first manner.
     Optionally, a maximum depth may be provided at which to stop looking for
     the goal state.
     '''
     GraphSearch.__init__(self, LIFOQueue, max_depth)
Exemple #3
0
    def find(self, problem_state, heuristic=None):
        '''
        @param problem_state: The initial state to start the search from.
        @param heuristic: Ignored.
        '''
        # This is the node evaluation function for the given heuristic.
        def evaluator(node):
            return node.path_cost
    
        # This is a generator for the PriorityQueue we need.
        def queue_generator():
            return PriorityQueue(evaluator)

        # Use a graph search with a minimum priority queue to conduct the search.
        search = GraphSearch(queue_generator, self.max_depth)
        return search.find(problem_state)
Exemple #4
0
    def find(self, problem_state, heuristic=None):
        '''
        @param problem_state: The initial state to start the search from.
        @param heuristic: Ignored.
        '''

        # This is the node evaluation function for the given heuristic.
        def evaluator(node):
            return node.path_cost

        # This is a generator for the PriorityQueue we need.
        def queue_generator():
            return PriorityQueue(evaluator)

        # Use a graph search with a minimum priority queue to conduct the search.
        search = GraphSearch(queue_generator, self.max_depth)
        return search.find(problem_state)
Exemple #5
0
    def find(self, problem_state, heuristic):
        '''
        A* search is best-first graph search with f(n) = g(n)+h(n).
        You need to specify the h function when you call astar_search.
        Uses the pathmax trick: f(n) = max(f(n), g(n)+h(n)).

        @param problem_state: The initial state to start the search from.
        @param heuristic: A heuristic function that scores the Problem states.
        '''
        # This is the node evaluation function for the given heuristic.
        def evaluator(node):
            return 0.1*node.path_cost +(1-0.1)* heuristic.evaluate(node.state)
    
        # This is a generator for the PriorityQueue we need.
        def queue_generator():
            return PriorityQueue(evaluator)

        # Use a graph search with a minimum priority queue to conduct the search.
        search = GraphSearch(queue_generator, self.max_depth)
        return search.find(problem_state)
Exemple #6
0
    def find(self, problem_state, heuristic):
        '''
        Beam search is best-first graph search with a beam width that determines
        how many states are in the open states. This conserves memory and
        focuses the search path on the short-term most likely candidates.

        @param problem_state: The initial state to start the search from.
        @param heuristic: A heuristic function that scores the Problem states.
        '''
        # This is the node evaluation function for the given heuristic.
        def evaluator(node):
            return heuristic.evaluate(node.state)
    
        # This is a generator for the LimitedPriorityQueue we need.
        def queue_generator():
            return LimitedPriorityQueue(evaluator, self.beam_width)

        # Use a graph search with a minimum priority queue to conduct the search.
        search = GraphSearch(queue_generator, self.max_depth)
        return search.find(problem_state)
Exemple #7
0
    def find(self, problem_state, heuristic):
        '''
        A* search is best-first graph search with f(n) = g(n)+h(n).
        You need to specify the h function when you call astar_search.
        Uses the pathmax trick: f(n) = max(f(n), g(n)+h(n)).

        @param problem_state: The initial state to start the search from.
        @param heuristic: A heuristic function that scores the Problem states.
        '''

        # This is the node evaluation function for the given heuristic.
        def evaluator(node):
            return node.path_cost + heuristic.evaluate(node.state)

        # This is a generator for the PriorityQueue we need.
        def queue_generator():
            return PriorityQueue(evaluator)

        # Use a graph search with a minimum priority queue to conduct the search.
        search = GraphSearch(queue_generator, self.max_depth)
        return search.find(problem_state)
Exemple #8
0
    def find(self, problem_state, heuristic):
        """
        Search the nodes with the lowest heuristic evaluated scores first.
        You specify the heuristic that you want to minimize.
        For example, if the heuristic is an estimate to the goal, then we have
        greedy best first search.
        If the heuristic is the depth of the node, then we have DFS.
        Optionally a limit may be supplied to limit the depth of the seach.

        @param problem_state: The initial state to start the search from.
        @param heuristic: A heuristic function that scores the Problem states.
        """
        # This is the node evaluation function for the given heuristic.
        def evaluator(node):
            return heuristic.evaluate(node.state)

        # This is a generator for the PriorityQueue we need.
        def queue_generator():
            return PriorityQueue(evaluator)

        # Use a graph search with a minimum priority queue to conduct the search.
        search = GraphSearch(queue_generator, self.max_depth)
        return search.find(problem_state)
Exemple #9
0
    def find(self, problem_state, heuristic):
        '''
        Search the nodes with the lowest heuristic evaluated scores first.
        You specify the heuristic that you want to minimize.
        For example, if the heuristic is an estimate to the goal, then we have
        greedy best first search.
        If the heuristic is the depth of the node, then we have DFS.
        Optionally a limit may be supplied to limit the depth of the seach.

        @param problem_state: The initial state to start the search from.
        @param heuristic: A heuristic function that scores the Problem states.
        '''

        # This is the node evaluation function for the given heuristic.
        def evaluator(node):
            return heuristic.evaluate(node.state)

        # This is a generator for the PriorityQueue we need.
        def queue_generator():
            return PriorityQueue(evaluator)

        # Use a graph search with a minimum priority queue to conduct the search.
        search = GraphSearch(queue_generator, self.max_depth)
        return search.find(problem_state)