CmSc310 Artificial Intelligence Solving Problems by Searching - Informed Search Search techniques: Uninformed search: Exhaustive search (brute force methods: systematically and exhaustively search all possible paths) Depth-first Breadth-first Informed search: Hill climbing Best-first search Beam search Heuristic search (use rules-of-thumb to guess which paths are likely to lead to a solution) - A* algorithm Informed Search Informed search strategies use problem specific knowledge to evaluate the search: - We can evaluate the cost of search – the cost of the path to find a solution. - We can evaluate how close a given state is to the goal state. - We can evaluate both the cost of the path and the current obtained state. Informed search is used to reduce the search space. Basic idea: explore only promising states and/or paths. We need an evaluation function to estimate each state and/or path. In many problems the length of the path to obtain the solution is not of importance. The solution is the goal state, not known in advance, for example the 8-queens problem. In other problems the goal state is known, the path to obtain the goal state is the solution, for example the 8-puzzle problem. Here we discuss problems where the path is not of importance. 1. Hill Climbing Basic idea: always expand the best successor of the current node. Algorithm: 1. current-state initial-state. 2. Loop do a. neighbor a highest value successor of the current-state. b. if neighbor.score current-state.score return current-state c. current-state neighbor 1 There is no exhaustive search, so no node list is maintained. No problem with loops, as we move always to a better node. Hill climbing terminates when there are no successors of the current state which are better than the current state itself. If a solution is found, it is found for a very short time and with minimum memory requirements. However it is not guaranteed that a solution will be found - the local maxima problem. General hill climbing is only good for a limited class of problems where we have an evaluation function that fairly accurately predicts the actual distance to a solution. Example: The 8-queens problem Initial state: each queen occupies a column, row position is chosen randomly. Operations: move any queen up or down any number of cells within its column 18 14 14 15 Q 17 18 14 12 16 12 14 14 Q 14 14 14 13 18 14 17 16 Q 13 13 15 13 Q 15 18 15 17 13 12 15 13 Q 15 15 12 12 14 12 16 14 Q 14 14 14 12 14 13 16 15 Q 12 14 16 14 16 16 Q 16 18 Q Q Q Q Q Q Q Q Evaluation: each cell has a score representing the score of each possible successor. The score is equal to the number of attacked queens when the queen in the cell column is moved to that cell. The cells with best score are in green. The goal state will have score equal to 0. Right board: a local minimum in the 8-queens state space, the score of this state is 1. 2. Best First Search The evaluation function scores each successor node. The node with the best score is chosen to be expanded. The algorithm works in breadth-first manner, keeps a data structure (called agenda, based on priority queues) of all successors and their scores. The basic algorithm is as follows: 1. Start with agenda = [initial-state]. 2. While agenda is not empty do a. Pick the best node on agenda. 2 b. If it is the goal node then return with success. Otherwise find its successors. c. Assign the successor nodes a score using the evaluation function and add the scored nodes to the agenda If a node that has been chosen does not lead to a solution, the next "best" node is chosen, so eventually the solution is found. The algorithm always finds a solution. Comparison with hill-climbing Similarities: best-first always chooses the best node Difference: best-first search keeps an agenda as in breadth-first search, and in case of a dead end it will backtrack, choosing the next-best node. Note: if the evaluation function is very expensive (i.e., it takes a long time to work out a score) the benefits of cutting down on the amount of search may be outweighed by the costs of assigning a score. 3. Beam Search This is a breadth-first method. It only expands the best few paths at each level. Thus it has the memory advantages of depth-first search. Since it is not exhaustive, it may not find the best solution. It may not find a solution at all. 4. A* Algorithm A* algorithm uses an evaluation function that accounts for the cost from the initial state to the current state, and the cost from the current state to the goal state. f(n) = g(n) + h(n) g(n) - the costs from the initial state to the current node n, the length of the path from the root to n h(n) - future costs, how close node n is to the goal h(n) is an heuristic function, it estimates the cost to get to the goal. For a given problem there may be several heuristic functions. Example: The 8-puzzle problem. 3
© Copyright 2026 Paperzz