Decision Trees State-Space Graphs • There are various methods for searching state spaces. • One possibility is breadth-first search: – Mark the start node with a 0. – Mark all adjacent nodes with 1. – Mark all unmarked nodes adjacent to nodes with a 1 with the number 2, and so on, until you arrive at a goal node. – Finally, trace a path back from the goal to the start along a sequence of decreasing numbers. February 11, 2016 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II 1 A decision tree is a special case of a state-space graph. It is a rooted tree in which each internal node corresponds to a decision, with a subtree at these nodes for each possible outcome of the decision. Decision trees can be used to model problems in which a series of decisions leads to a solution. The possible solutions of the problem correspond to the paths from the root to the leaves of the decision tree. February 11, 2016 Let us consider the 4-queens problem. Example: The n-queens problem How can we place n queens on an n×n chessboard so that no two queens can capture each other? Here, the possible target squares of the queen Q are marked with an x. February 11, 2016 x x x x x x x x x x x x x x No, it is generally useful to think about a search problem more carefully and discover constraints on the problem’s solutions. x Such constraints can dramatically reduce the size of the relevant state space. x x Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II 3 Decision Trees Otherwise, the two queens in the same column could capture each other. Therefore, we can describe the solution of this problem as a sequence of n decisions: Decision 1: Place a queen in the first column. Decision 2: Place a queen in the second column. … Decision n: Place a queen in the n-th column. This way, “only” 256 configurations need to be tested. Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II Answer: There are 16!/(12!⋅4!) = (13⋅14⋅15⋅16)/(2⋅3⋅4) = 13⋅7⋅5⋅4 = 1820 possible configurations. x x x Question: How many possible configurations of 4×4 chessboards containing 4 queens are there? Shall we simply try them out one by one until we encounter a solution? x x Q x x x x x Obviously, in any solution of the n-queens problem, there must be exactly one queen in each column of the board. February 11, 2016 2 Decision Trees Decision Trees A queen can move any number of squares horizontally, vertically, and diagonally. Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II 5 February 11, 2016 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II 4 Backtracking in Decision Trees • There are problems that require us to perform an exhaustive search of all possible sequences of decisions in order to find the solution. • We can solve such problems by constructing the complete decision tree and then find a path from its root to a leave that corresponds to a solution of the problem (breadth-first search often requires the construction of an almost complete decision tree). • In many cases, the efficiency of this procedure can be dramatically increased by a technique called backtracking (depth-first search with “sanity checks”). February 11, 2016 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II 6 1 Backtracking in Decision Trees Backtracking in Decision Trees Idea: Start at the root of the decision tree and move downwards, that is, make a sequence of decisions, until you either reach a solution or you enter a situation from where no solution can be reached by any further sequence of decisions. In the latter case, backtrack to the parent of the current node and take a different path downwards from there. If all paths from this node have already been explored, backtrack to its parent. empty board Q place 1st queen Q Q Q place 2nd queen Q Q Q Q Q Q place 3rd queen Q Q Q Continue this procedure until you find a solution or establish that no solution exists (there are no more paths to try out). February 11, 2016 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II 7 Q Q place 4th queen Q Q Q February 11, 2016 Introduction to Artificial Intelligence Lecture 6: Search in State Spaces II 8 2
© Copyright 2026 Paperzz