0% found this document useful (0 votes)
11 views

State Space

The document discusses state space search, focusing on graph theory and its application in problem-solving. It covers various search strategies, including data-driven and goal-driven approaches, as well as specific algorithms like depth-first and breadth-first search. Additionally, it provides examples such as the 8-puzzle and the traveling salesperson problem to illustrate state space representation and search techniques.

Uploaded by

11mosta22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

State Space

The document discusses state space search, focusing on graph theory and its application in problem-solving. It covers various search strategies, including data-driven and goal-driven approaches, as well as specific algorithms like depth-first and breadth-first search. Additionally, it provides examples such as the 8-puzzle and the traveling salesperson problem to illustrate state space representation and search techniques.

Uploaded by

11mosta22
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

02/07/1441

State Space Search

Prepared By:
Dr. Muhanad Tahrir Younis

Structures and Strategies for


State Space Search
• Introduction
• Graph Theory
– Structures for state space search
– state space representation of problems
• Strategies for state space search
– Data-Driven and Goal-Driven Search
– Implementing Graph Search
– Depth-First and Breadth-First Search
– Depth-limited Search
– Depth-First Search with Iterative Deepening

1
02/07/1441

Introduction
• A graph consists of nodes and a set of arcs or links
connecting pairs of nodes.
• Nodes are used to represent discrete states.
– A configuration of a game board. (tic-tac-toe)
• Arcs are used to represent transitions between
states.
– Legal moves of a game
• Leonhard Euler invented graph theory to solve the
“bridge of Königsberg problem”
– Is there a walk around the city that crosses each bridge
exactly once.
3

Königsberg Bridge System (1)

2
02/07/1441

Königsberg Bridge System (2)


• Euler focused on the degree of the nodes of the
graph
– Even degree node has an even number of arcs joining it
to neighboring nodes.
– Odd degree node has an odd number of arcs.
• Unless a graph contained either exactly zero or
two nodes of odd degree, the walk was impossible.
– No odd dgree node: the walk start at the first and end at
the same node
– Two odd degree nodes: the walk could start at the first
and end at the second
5

Definition of Graph(1)
A graph consists of nodes and arcs
– A set of nodes N1, N2, …, Nn … need not be finite.
– A set of arcs connects pairs of nodes.
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 6

3
02/07/1441

Definition of Graph (2)


• 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. 7

State Space Representation of


Problems(1)
• In the state space representation of a
problem, the nodes of a graph corresponds
to partial problem solution states, the arcs
corresponds to steps in a problem-solving
process.
• State space search characterize problem
solving as the process of finding a solution
path from the start state to a goal.

4
02/07/1441

State Space Representation of


Problems(2)
• Definition : STATE SPACE SEARCH
A state space is represented by a four tuple [N, A, S, GD]
where
– N is the set of states.
– A is the set of steps between states
– S is the start state(S) of the problem.
– GD is the goal state(S) of the problem. The
states in GD are described:
1.A measurable property of the states. (winning board in tic-tac-
toe)
2.A property of the path.(shortest path in traveling sales man
problem)
A solution path is a path through this graph from S to GD.

The 8-puzzle (1)


The set of states are all different configurations of
9 tiles (9!).
The legal moves are : move the blank tile up(),
right(), down(), and the left().
– make sure that it does not move the blank off the board.
– All four moves are not applicable at all times.
The start state
The goal stateunlike tic-tac-toe, cycles are possible
in the 8-puzzle.
Applicable heuristics
10

5
02/07/1441

The 8 puzzle (2)

11

The Traveling Salesperson(1)


• The goal of the problem is to find the shortest path
for the salesperson to travel, visiting each city, and
then returning to the starting city.
• The goal description requires a complete circuit
with minimum cost.
• The complexity of exhaustive search is (N-1)!,
where N is the number of cities

12

6
02/07/1441

The Traveling Salesperson(2)

13

The Traveling Salesperson(4)

14

7
02/07/1441

Data-Driven and Goal-Driven


Search (1)
Data-driven search(forward chaining) takes the
facts of the problem and applies the rules and legal
moves to produce new facts that lead to a goal.
Goal-driven search (backward chaining) focused
on the goal, finds the rules that could produce the
goal, and chains backward through successive
rules and subgoals to the given facts of the
problem.
Both problem solvers search the same state space
graph. The search order and the actual number of
states searched can differ.
15

Data-Driven and Goal-Driven


Search (2)
• The preferred strategy is determined by the
properties of the problem: complexity of the rules,
“shape” of the state space, the nature and
availability of the problem data.
• Confirming or denying the statement
“I am a descendant of Thomas Jefferson.”
– Assume that Thomas Jefferson was born about 250
years ago and that 25 years per generation and that 3
children per family
– I -> Jefferson (backward) 210 ancestors
– Jefferson -> I (forward) 310 nodes of family
16

8
02/07/1441

Goal-Driven Search is
Suggested(1)
• A goal or hypothesis is given in the problem
statement or can easily be formulated.
– Mathematics theorem prover, diagnostic systems
• Early selection of a goal can eliminate most
branches, making goal-driven search more
effective in pruning the space.
• Mathematics theorem prover.
• Problem data are not given but must be acquired.
– A medical diagnosis program.

17

Goal-Driven Search is
Suggested(2)

18

9
02/07/1441

Data-driven Search is
Appropriate
 All or most of the data are given in the initial problem
statement.
– PROSPECTOR interpreting geological data.
 There are only a few ways to use the facts and given
information.
– DENDRAL finding the molecular structure of organic compounds.
For any organic compound, enormous number of possible
structures. The mass spectrographic data on a compound allow
DENDRAL to eliminate most of possible structures.
 Branching factor, availability of data, and ease of
determining potential goals are carefully analyzed to
determine the direction of search.

19

Depth-First and Breadth-First


Search
• A search algorithm must determine the
order in which states are examined.
• Breadth-first search explores the space
– A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q,
R, S, T, U
• Depth-first search goes deeper into the
search space whenever this is possible.
– A, B, E, K, S, L, T, F, M, C, G, N, H, O, P, U,
D, I, Q, J, R

20

10
02/07/1441

Search Example

21

Breadth-First Search (1)


Procedure breadth_first_search;
begin
open := [Start];
closed := [];
while open  [] do
begin
remove leftmost state from open, call it X;
if X is a goal then return(success)
else begin
generate children of X;
put X on closed;
eliminate children of X on open or closed;
put remaining children on right end of open
end
end
return(failure)
end.
22

11
02/07/1441

Breadth-First Search(2)
1. open=[A]; closed=[]
2. open=[B,C,D]; closed=[A]
3. open=[C,D,E,F]; closed=[B,A]
4. open=[D,E,F,G,H]; closed=[C,B,A]
5. open=[E,F,G,H,I,J]; closed=[D,C,B,A]
6. open=[F,G,H,I,J,K,L]; closed=[E,D,C,B,A]
7. open=[G,H,I,J,K,L,M](as L is already on open);
closed=[F,E,D,C,B,A]
8. open=[H,I,J,K,L,M,N]; closed=[G,F,E,D,C,B,A]
9. And so on until either U is found or open=[]

23

Breadth first search (3)

24

12
02/07/1441

Breadth-First Search (4)


• OPEN lists states that have been generated but whose
children have not been examined.
• CLOSED records states that have already been
examined.
• OPEN is maintained as a queue, FIFO data structure.
– States are added to the right of the list and removed from
the left
• Breadth-first search is guaranteed to find the shortest
path from the start state to the goal.
• If the path is required for a solution, we can store
ancestor information along with each state.
– open = [(D,A), (E,B), (F,B), (G,C), (H,C)]
– closed = [(C,A), (B,A), (A,nil)]
25

Depth-First Search (1)


Procedure depth_first_search;
begin
open := [Start];
closed := [];
while open  [] do
begin
remove leftmost state from open, call it X;
if X is a goal then return(success)
else begin
generate children of X;
put X on closed;
eliminate children of X on open or closed;
put remaining children on left end of open
end
end
return(failure)
end.
26

13
02/07/1441

Depth-First Search (2)


1. open=[A]; closed=[]
2. open=[B,C,D]; closed=[A]
3. open=[E,F,C,D]; closed=[B,A]
4. open=[K,L,F,C,D]; closed=[E,B,A]
5. open=[S,L,F,C,D]; closed=[K,E,B,A]
6. open=[L,F,C,D]; closed=[S,K,E,B,A]
7. open=[T,F,C,D]; closed=[L,S,K,E,B,A]
8. open=[F,C,D]; closed=[T,L,S,K,E,B,A]
9. open=[M,C,D], as L is already on closed;
closed=[F,T,L,S,K,E,B,A]
10. open=[C,D]; closed=[M,F,T,L,S,K,E,B,A]
11. open=[G,H,D]; closed=[C,M,F,T,L,S,K,E,B,A]
27

Depth-First Search (3)


• OPEN is maintained as a stack, or LIFO
data structure.
– The state are both added and removed from the
left end of OPEN.
– Figure 3.16 (p.104)
• is not guaranteed to find the shortest path.

28

14
02/07/1441

Depth first search (4)

29

Depth-First vs. Breadth-First


 The choice depends on the specific problem being solved.
 Significant features include the importance of finding the
shortest path, the branching of the state space, the available
time and space resources, the average length of paths to a
goal node, and whether we want all solutions or only the
first solution.
 Breadth-First
– always finds the shortest path to a goal node.
– If there is a bad branching factor, the combinatorial explosion
may prevent the algorithm from finding a solution.
 Depth-First
– may not waste time searching a large number of shallow state
in the graph.
– can get lost deep in a graph missing shorter paths to goal.

30

15
02/07/1441

Depth-First Search with Iterative


Deepening
• Depth-limited search (DLS)
The unbounded tree problem appeared in DFS can be fixed
by imposing a limit on the depth that DFS can reach,
this limit we will call depth limit (D) ,this solves the
infinite path problem
• Depth-First Search with Iterative Deepening
performs a depth-first search of the space with a depth
bound of 1. If it fails to find a goal, it performs another
depth-first search with a depth bound of 2. This continues,
increasing the depth bound by one at each iteration.

31

16

You might also like