190 likes | 440 Views
3.0 State Space Representation of Problems. 3.1 Graphs 3.2 Formulating Search Problems 3.3 The 8-Puzzle as an example 3.4 State Space Representation using graphs 3.5 Performing a State Space Search 3.6 Basic Depth First Search (DFS) 3.7 Basic Breadth First Search (DFS)
E N D
3.0 State Space Representation of Problems 3.1 Graphs 3.2 Formulating Search Problems 3.3 The 8-Puzzleas an example 3.4 State Space Representation using graphs 3.5 Performing a State Space Search 3.6 Basic Depth First Search (DFS) 3.7 Basic Breadth First Search (DFS) 3.8 Best First Search (DFS)
3.1 Graphs 1 2 3 4 • Definitions: • a graph consists of: • A set of nodes N1, N2, N3,…Nn. • A set of arcs that connect pairs of nodes. • A directed graph has an indicated direction for traversing each arc. • A labeled graph has its nodes labeled. • A labeled directed graph is shown in figure 4.2 5 Figure 4.1:5 nodes, and 6 arcs graph. a b c d e Figure 4.2: Labeled directed graph Nodes {a,b,c,d,e} Arcs:{(a,b),(b,e),(c,a),(c,b), (d,c),(e,d)}
a b c • A path through a graph connects a sequence of nodes through successive arcs. It is represented by an ordered list of the nodes representing the path. • For example in figure 4.3, [a, b, e, d] is a path through nodes a ,b ,e , d. • A rooted graph has a unique node (called the root ) such that there is a path from the root to all nodes within the graph.i.e. all paths originate from the root ( figure 4.4). d e Figure 4.3: dotted curve indicates the path [a,b,e,d] a The root b d c Figure 4.4: a rooted graph
a The root • A tree is a graph in which each two nodes have at most one path between them. • Figure 4.5 is an example of a rooted tree. • If a directed arc connects Ni to Nk then • Ni is the parent of Nk and • Nk is the child of Ni.. • In figure 4.5: d is the parent of e and f. • e and f are called siblings. d c b e f g j h i Figure 4.5: a rooted tree
In a graph: • An ordered sequence of nodes [ N1, N2, N3 .., Nn], where each Ni, Ni+1 in the sequence represent an arc (Ni,Ni+1), is called a path of length n-1. • If a path contains any node more than once it said to contain a cycle or loop. • Two nodes in a graph are said to be connected if there is a path that includes them both. • On a path on a rooted graph, a node is said to be the ancestor of all nodes positioned after it ( to its right) as well as descendent of all nodes before it ( to its left) -For example, in figure 4.5, d is the ancestor of e, while it is the descendent of a in the path [a, d, e].
3.2 Formulating Search Problems • All search problems can be cast into the following general form: • Starting StateE.g. • starting city for a route • Goal State (or a test for goal state)E.g. • destination city • The permissible operatorsE.g. • go to city X • A state is a data structure which captures all relevant information about the problem.E.g. • a node on a partial path
3.3 The 8-Puzzleas an example • The eight puzzle consists of a 3 x 3 grid with 8 consecutively numbered tiles arranged on it. Any tile adjacent to the space can be moved on it. A number of different goal states are used. A state for this problem needs to keep track of the position of all tiles on the game board, with 0 representing the blank position (space) on the board The initial state could be represented as: ( (5,4,0), (6,1,8), (7,3,2) ) The final state could be represented as: ( (1,2,3) (8,0,4), (7,6,5) ) The operators can be thought of in terms of the direction that the blank space effectively moves. i.e.. up, down, left, right.
3.4 State Space Representation Using Graphs • In the state space representation of a problem: • nodes of a graph correspond to partial problem solution states. • arcs correspond to steps (application of operators) in a problem solving process. • The root of the graph corresponds to the initial state of the problem. • The goal node which may not exist, is a leaf node which corresponds to a goal state. • State Space Search is the process of finding a solution path from the start state to a goal state.
The task of a search algorithm is to find a solution path through such a problem space. • The generation of new states ( expansion of nodes) along the path is done by applying the operators (such as legal moves in a game). • A goal may describe • a statea winning board in a simple game. • or some property of the solution path itself (length of the path) shortest path for example.
Consider the following segment of a search for a solution to the 8-Puzzle problem • The initial state • b. After expanding that state
c. After expanding "last" successor generated In depth first search, the "last" successor generated will be expanded next.
Example: road map • Consider the following road map A 5 B 3 G Applying the DFS 1-Open=[S], closed=[] 2-Open=[AC], closed=[S] 3-Open=[BC], closed=[AS] 4-Open=[DC], closed=[BAS] 5-Open=[GC], closed=[DBAS] 6-Open=[C], closed=[GDBAS] Report success Path is SABDG 3 2 4 S 3 4 D 4 S C A C B C D A B D D G D G G G
Example: road map • Consider the following road map A 5 B 3 G Applying the BRFS 1-Open=[S], closed=[] 2-Open=[AC], closed=[S] 3-Open=[CB], closed=[AS] 4-Open=[BD], closed=[CAS] 5-Open=[D], closed=[CAS] 6-Open=[G], closed=[DCAS] 7-Open=[], closed=[GDCAS] Report success Path is SCDG 3 2 4 S 3 4 D 4 S C C A C C D A B D G D G G G
3.8 Best First Search (BFS) /* OPEN and CLOSED are lists */ OPEN = Start node, CLOSED = empty While OPEN is not empty do Remove leftmost state from OPEN, call it X If X is a goal return success Put X on CLOSED Generate all successors of X Eliminate any successors that are already on OPEN or CLOSED put remaining successorson OPEN sorted according to their heuristic distance to the goal ( ascending from left to right) End while
Example: road map • Consider the following road map A 5 B 3 G Applying the BFS 1-Open=[S], closed=[] 2-Open=[C7A8], closed=[S] 3-Open=[D3A8], closed=[CS] 4-Open=[G0B3A8], closed=[DCS] 5-Open=[B3A8], closed=[GDCS] Report success Path is SCDG 3 2 4 3 S 4 D 4 S C C A C C D A B D G D G G G