Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
State Space
A state-space problem consists of a set of states a distinguished set of states called the start states
Graph = (V, E)
Vs are the particular states in a problem solving process Es are the transitions between states
Logical inferences or legal moves of a game
Konigsberg Problem
Euler invented graph theory to solve the "Bridges of Konigsberg problem. The city of Konigsberg occupied two banks and two islands of a river The islands and the riverbanks were connected by seven bridges The bridges of Konigsberg problem asks if there is a walk around the city that crosses each bridge exactly once
Is there any simple path so that all 7 bridges are crossed once and then one returns to the starting point?
The predicate calculus representation is equivalent to the graph representation in that the connectedness is preserved. However, the structure of the problem can be visualized more directly in the graph representation. Euler noted that unless a graph contained either exactly zero or two nodes of odd degree, the walk was impossible. If there were two odd-degree nodes, the walk could start at the first and end at the second; if there were no nodes of odd degree, the walk could begin and end at the same node. The walk is not possible for graphs containing any other number of nodes of odd degree.
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
A Directed 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
Example
Definition of Graph
A graph consists of nodes and arcs
A set of nodes N1, N2, , Nn need not be finite.
A directed graph has an indicated direction for traversing each arc If a directed arc connects Nj and Nk, then Nj is called the parent of Nk and Nk is called the child of Nj.
A rooted graph has a unique node Ns from which all paths in the graph originate
A tip or leaf node is a node without children. An ordered sequence of nodes [N1, N2, N3, Nn] is called a path of length n-1 in the graph
15
Definition of Graph
On a path in a rooted graph, a node is said to be an ancestor of all nodes positioned after it (to its right) as well as a descendant of all nodes before it (to its left). A path that contains any node more than once is said to contain a cycle or loop. A tree is a graph in which there is a unique path between every pair of nodes Two nodes in a graph are said to be connected if a path exists that includes them both.
16
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
Fig 3.5 (a) The finite state graph for a flip flop and (b) its transition matrix.
Fig 3.6 (a) The finite state graph and (b) the transition matrix for string recognition example
Also allow the graph to define an initial condition and a goal condition
Again, much like the Moore machine
Formal Definition
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
State Space?
In some cases, we have provable algorithms that solve the problem without doing so
Nearest Neighbor
Begin with given facts and set of legal moves Continually apply rules to facts to create new facts Begin with the goal Work backwards based on applying rules in reverse Work back to the start state
A goal is given or can easily by formulated 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 Goal-driven search can direct problem data acquisition (i.e. medical examiner)
3.
statement
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
Begin at a start state and pursue path until deadend or goal If dead-end backtrack to most recent node in path with unexamined siblings depth-first search
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
loops
state-space
Data or Goal-Driven?
Currently, this is a data-driven search
Let the goal be the root, evaluate descendants backward until a start-state is found
Fig 3.15 Graph for breadth - and depth - first search examples.
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
Luger: Artificial Intelligence, 5th edition. Pearson Education Limited, 2005
19
Implementing BFS
Use lists
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
Also, look at Fig. 3.17 to see the BFS search solution to an instance of the 8-puzzle (next slide)
Fig 3.17 Breadth-first search of the 8-puzzle, showing order in which states were removed from open.
DFS Algorithm
Simplification of the backtrack algorithm
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
How many states were we required to visit? What about with BFS?