Download presentation
Presentation is loading. Please wait.
Published byJustin Mathews Modified over 9 years ago
1
CS 415 – A.I. Slide Set 5
2
Chapter 3 Structures and Strategies for State Space Search – Predicate Calculus: provides a means of describing objects and relations in a problem domain – Inference Rules: allow us to infer new knowledge from these descriptions – Inferences and Base Rules define a space that is searched to find a problem solution
3
Key Questions Is the problem solver guaranteed to find a solution? Will the problem solver always terminate, or can it become caught in an infinite loop? When a solution is found, is it guaranteed optimal? What is the complexity of the search algorithm? How can the interpreter most effectively reduce complexity? How can an interpreter be designed to most effectively use a representation language?
4
Theory of State-Space Search Primary tool for answering these questions – Represent the problems as a state-space graph – Use graph theory to analyze the structure and complexity Graph = (V,E) – Vs are the particular states in a problem solving process – Es are the transitions between states Logical inferances or legal moves of a game
5
Euler Invents Graph Theory Bridges of Konigsberg Is there any simple path so that all 7 bridges are crossed once and then one returns to the starting point?
6
A new formalization What might a predicate calculus representation of this look like? A “Eulerian Path” exists iff there are no nodes with odd degree or exactly two nodes with odd degree
7
Graph Theory Graph = (V,E) Labeled Graph: has labels attached to nodes to distinguish them – Arcs (edges) are indicated by combining the labels of the nodes on each end of the arc – Arcs may also be otherwise labeled Indicates a named relation Directed graphs vs. non-directed Path: connects successive nodes through a series of edges
8
A Directed Graph
9
Rooted Graphs and Trees Rooted Graphs – a node with a “root” – Root: a node such that there is a path from the node to all other nodes in the graph Tree – A graph in which two nodes have at most one path between them – Eliminates loops (cycles) in the graph – Most often trees are “rooted” – Parent, Child, and Sibling – Ancestor and Descendent
10
Example
11
Formal Definitions
12
Finite State Machine Might be familiar to you – All modern computers and programs can be represented as FSMs Finite State Machine (FSM) – a finite, directed, connected graph, having a set of states, a set of input values, and a state transition function that describes the effect that the elements of the input stream have on the state of the graph – Often used as a tool for compilers/interpreters
13
Fig 3.5(a) The finite state graph for a flip flop and (b) its transition matrix.
14
Fig 3.6(a) The finite state graph and (b) the transition matrix for string recognition example
15
The State Space Representation of Problems Nodes – correspond to partial problem solutions – Much like the Moore Machine FSM had nodes that represented states of partial solutions Also allow the graph to define an initial condition and a goal condition – Again, much like the Moore machine
16
Formal Definition
17
Example: The Traveling Salesperson N – all the cities A – interconnecting S – intermediate list of cities reached and total cost GD – State where all cities have been reached and we have returned home WITH the minimum possible cost of all such paths Must be able to compare to all possible costs
18
State Space? Note: the notion of “dead end” states
19
Dealing with Huge State Spaces The only way to be guaranteed to find the answer is to find all the possibilities In some cases, we have provable algorithms that solve the problem without doing so Any ideas for “general rules”?
20
Nearest Neighbor
21
Strategies for State Space Search Data-driven and Goal-driven Search Data-driven (forward chaining) Begin with given facts and set of legal moves Continually apply rules to facts to create new facts Goal-driven (backward chaining) Begin with the goal Work backwards based on applying rules in reverse Work back to the start state
22
When Goal-Driven Search? 1. A goal is given or can easily by formulated 2. A large number of rules that match the facts of the problem, and thus create an increasing number of goals Early selection of a goal eliminates most of the branches 3. Problem data are not given Goal-driven search can direct problem data acquisition (i.e. – medical examiner)
23
When Data-Driven Search? All (or most) of the data in initial problem statement Interpretation problems, etc. There are a large number of potential goals, but only a few ways to use the facts and given information of a problem instance It is difficult to form a goal or hypothesis
24
Implementing Graph Search Backtracking Begin at a start state and pursue path until dead- end or goal If dead-end backtrack to most recent node in path with unexamined siblings depth-first search Going to be implemented recursively
25
Function Backtrack Algorithm Notation SL – state list, lists the states in the current path, if goal is found, SL lists solution NSL – new state list, contains nodes whose descendants have not been generated/searched DE – dead end, lists states whose descendents have failed to contain goal CS – current state
26
For graphs (not just trees) need to prevent loops Test each new node to see if it is in any set If so, ignore it Why is it ok to ignore a state once visited? Function continues until goal or exhausts state-space
27
Function backtrack algorithm Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 16
28
Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 Fig 3.14Backtracking search of a hypothetical state space space. 18
29
A trace of backtrack on the graph of figure 3.14 Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 17
30
Data or Goal-Driven? Currently, this is a data-driven search Takes the root as a start state and evaluates its children Could be implemented as goal-driven Let the goal be the root, evaluate descendants backward until a start-state is found
31
DFS and BFS 2 Design Considerations Data-driven or goal-driven Depth-first or breadth-first Going to give general DFS and BFS algorithms that don’t store paths Each can be augmented easily to do so Look at Figure 3.15 -on next slide
32
Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 Fig 3.15Graph for breadth - and depth - first search examples. 19 DFS – A,B,E,K,S,L,T,F,M,C,G,N,H,O,P,U,D,I,Q,J,R BFS – A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U
33
Implementing BFS Use lists closed – keeps track of states that are already examined The union of dead end (DE) and state list (SL) open – keeps track of nodes that have children that have not been visited Note: the order in which nodes are removed from open determines the order of the search Algorithm on next slide
34
Function breadth_first search algorithm Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 20
35
A trace of breadth_first_search on the graph of Figure 3.15 Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 21 Also, look at Fig. 3.17 to see the BFS search solution to an instance of the 8-puzzle (next slide)
36
Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 Fig 3.17Breadth-first search of the 8-puzzle, showing order in which states were removed from open. 5
37
DFS Algorithm Simplification of the backtrack algorithm No ancestor information is stored Use open and closed lists as before open list must be implemented as a stack rather than a queue as in the case of BFS Remember, the order in which items are removed from open determines the structure of the search
38
Function depth_first_search algorithm Luger: Artificial Intelligence, 5th edition. © Pearson Education Limited, 2005 3
39
Fig 3.19Depth-first search of the 8-puzzle with a depth bound of 5. 7 How far down do we go? How many states were we required to visit? What about with BFS?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.