0% found this document useful (0 votes)
32 views68 pages

Topic 2 Structures and Strategies For

This document discusses state space search approaches for solving problems symbolically in artificial intelligence. It defines key terms like problem states, operators, and state space. State space search represents problems as graphs with nodes as states and arcs as state transitions. It provides examples like the 8-puzzle and car diagnosis problems. Different graph search strategies are discussed, including breadth-first, depth-first, and iterative deepening searches. Knowledge representation using predicate calculus and graphs is also covered.

Uploaded by

Renhe SONG
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)
32 views68 pages

Topic 2 Structures and Strategies For

This document discusses state space search approaches for solving problems symbolically in artificial intelligence. It defines key terms like problem states, operators, and state space. State space search represents problems as graphs with nodes as states and arcs as state transitions. It provides examples like the 8-puzzle and car diagnosis problems. Different graph search strategies are discussed, including breadth-first, depth-first, and iterative deepening searches. Knowledge representation using predicate calculus and graphs is also covered.

Uploaded by

Renhe SONG
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/ 68

EE4483/IM4483

Part I: Topic 2
Structures and Strategies for
State Space Search

1
Part I: Topic 2 Structures and Strategies for State Space Search
Key Terms
Symbolic Artificial Intelligence
Outline Problem States
• What is Symbolic AI Operators/Inference Rules
State Space
• State SpaceApproaches Knowledge Representations:
Graph Representation o Predicate Calculus /Neural Network
o Graph/Tree
Search Strategies Konigsberg Problem & Euler Conclusion
Why State Space Graph
Graph Terminologies
o Node/Arch/Path/Tree
o Directed/Rooted Graphs
o Parent, Siblings/Ancestor/Descendant
State Space Approach Examples
o Tic-Tac-Toe/8-puzzle/TSP
Search Strategies
o Data-driven vs Goal-driven
Graph Search
o Backtracking
o Breadth-first
o Depth-first
2
o Depth-First with Iterative Deepening
Introduction: AI & Search
• Two most fundamental concerns ofAIresearchers

– Knowledge Representation (capture K in a language)


• capturing knowledge in a way suitable forcomputer manipulation

– Search (problem-solving techniques)


• systematically explores a space of problem states

Luger, G.F. Artificial Intelligence: Structures and Strategies for Complex Problem Solving

3
Symbolic AI : 8-puzzle Problem
States in Problem-solving Process 1 2 3

State: board configuration of ‘move’ 4 5 6

Start State 7 8
Goal State

Fig 3.8 State space of the 8-puzzle generated by “move blank” operations
4
Symbolic AI : Car Diagnosis Problem
States in Problem-solving Process
State: a state of partial knowledge =>symptom
Arc = diagnostic check
The process: exam symptoms

Fig II.7 State space description of the automotive diagnosis problem. 5


Symbolic AI
• Problem states: initial knowledge and its
inferences, e.g.,
– intermediate steps in reasoning
– different board configurations in a board game, suchas
chess and go

• State space: the collection ofproblem states

• Inference rules: inferring new knowledge from


initial knowledge

6
Solving Problems with
Search Algorithms
Input: a problem P

Preprocessing:
Define states and a state space
Define Operators
Define a start state and goal set of states.

Processing:
Activate a Search algorithm to find a path from start
to one of the goal states.

7
Courtesy of Prof. Sarit Kraus at Bar-Ilan University
Knowledge Representation
formal semantics and sound & complete inference rules.
• Predicate calculus: Represent & Reason
– a formal (computerѪfriendly) language for AI
– fordescribing the properties of and relationships
among objects (problem states and inference rules)

• Graphs
• ANN – network +weights

Predicate Calculus :

1. All cats have tails. 3. Tomhas a tail.


2. Tomis acat.

8
8-puzzle : Symbolic AI vs sub-Symbolic AI

State space of the 8-puzzle

9
Search Strategy !!!

• Successive and alternative stages in a problem-


solving process.
• The degree of success in designing and
implementing search algorithms depends on the
programmer's ability to analyse the problem
No universally superior search algorithms for all problems, also known
as the “No-Free-Lunch-Theorem”

10
What is a Graph?
Agraph consists of a set of nodes and a set of arcs
– Aset of nodes N1, N2, N3, ..., Nn...,
– Aset of arcs that connect pairs of nodes

Courtesy of https://ohmygodd.com/social-networking-tips 11
Twitter social network, curtesy of http://www.necsi.edu/guide/concepts/network.html 20
Undirected/Directed graph
A directed graph has an indicated
• In an undirected graph, all arcs
direction for traversing each arc.
are bi‐directional, or equivalently,
without any directions – For example, a directed graph
might have (Na,Nb) as an arc, but not
• Two states in a graph are said to (Nb,Na)
be connected if a path exists that
includes them both

13
Parent, Siblings

• If a directed arc connects Nj to Nk, then Nj is


called the parent of Nk and Nk the child (or
successor) of Nj.
• If the graph also contains an arc (Nj , Ni), then Nk
and Ni are called siblings

14
RootedG, Leaf, Path, Ancestor/Descendant, Loop

• A rooted graph has a unique node NS from which all paths


originate
• A tip or leaf node is a node that has no children
• An ordered sequence of nodes [N1, N2, N3, ..., Nn], where each
(Ni, Ni+1) in the sequence represents an arc, is called a path of
length n-1 in the graph
• On a path in a rooted graph, a state is said to be an ancestor of
all states positioned after it (to its right) and a descendant of all
states before it (to its left)
• A path that contains any state more than once is said to contain a
cycle or loop

15
More Graph Terminologies
• End nodes of an arc:
U, and V are the end nodes of the arc a
• Arc incident on a node
a, d, b are incident on V
• Adjacent nodes
U and V are adjacent node
• Degree of a node
X has degree 5
• Neighborhood of a node
N(V) is the set of nodes adjacent to V
N(V)={U, W, X}
• Parallel arc
h and i are parallel arcs
• Self-loop
j is a self-loop

16
Path, Simple Path
• Path
Sequence of alternating nodes and arcs
Begins with a node, ends with a node
Each arc is preceded and followed by its end nodes

• Simple path
Path with no repeated nodes

• Examples
P1= (V, b, X, h, Z) is a simple path
P2= (U,c, W, e, X, g, Y, f, W, d, V) is a path that is not simple

17
Tree
• A tree is a graph in which there
is a unique path between every
pair of nodes
– Each node in a rooted tree has a
unique parent
– There are no loops or cycles in a
tree

Relationship between nodes:


Parent/child/sibling – like a familial fashion
Parent preceding its child along a directed arc Figure 3.4: A Rooted tree,
The Children of a node are called sibling exemplifying family relationships

18
State Space Approach to Problem Solving

• Nodes of a graph correspond to partial problem solution states


• Arcs correspond to steps in problem solvingprocess
• The graph also defines a goal condition, which is the solution to a
problem instance
• State space search characterizes problem solving as the process of
finding a solution path from start state to a goal

19
Example: the tic-tac-toe Game

• Goal: to have 3 circles


or crosses in a line

• 9 possible 1st moves; 8


possible 2nd moves…;
Total 9! =362,880
possible moves

Fig 4.1: Portion of the state space for tic-tac-toe 20


State Space Search
A state space is represented by a fourѪtuple [N, A, S, GD],
where:
– N is the set of nodes or states of the graph. Thesecorrespond
to the states in a problemѪsolvingprocess
– A is the set of arcs (or links) between nodes. These correspond
to the steps in a problemѪsolvingprocess
– S, a nonempty subset of N, contains the start state(s) of the
problem
– GD a nonempty subset of N, contains the goal state(s) or
the problem.

21
State space Search

Asolution path is
a path through this
graph from a node
in S to a node in
GD

22
Another example:
the 15Ѫpuzzle and the 8Ѫpuzzle
• Goal: achieve the goal configuration (sequential
numbering) by moving tiles in and out of the blank
space

23
Example: the 15Ѫpuzzle and the 8Ѫpuzzle
• The 15Ѫpuzzle’s state space islarger than that
of ticѪtacѪtoe
– The state space is large enough to be interesting,
but is not complete intractable
• Cycles are possible, unliketicѪtacѪtoe Graph vs Tree

24
State space of the 8Ѫpuzzle

Fig 3.8 State space of the 8-puzzle generated by “move blank” operations
25
Exercise 1: Two Jugs problem

You are given an empty 4-litre jug (J4), an empty 3-litre jug (J3) and a
water tap supplying unlimited amount of water. A drain is available. The
aim is to get exactly 2-litres of water in J4.

Suppose the state representation of the problem is (x,y) where x and y denote,
respectively, the contents of J4 and J3: (J4, J3)

i) Write down the initial state and the goal state.


ii) Give a complete list of the required operators. Two such operators are:
1. Fill J4 from tap
2. Empty J4 into drain
iii) Draw the search graph/tree for any one solution.

26
Exercise1_Discussions
i) Initial and goal state: (J4,J3):
initial(s): (0,0) or (i,j), where 0 <i<=4; 0<j<=3
Goal(s): (2,0) or (2, k), where k=0,1,2,3

ii) Operations:
1. Fill J4 from tap
2. Empty J4 into drain
3. Fill J3 from tap
4. Empty J3 into drain
5. Transfer J3’s contents into J4
6. Transfer J4’s contents into J3

27
(J4, J3) Exercise1_discussions

36
Another Example:
Travelling Salesman Problem (TSP)
• Asalesman needs to find the shortest path to visit N cities,
each city only once, and return to the originating city

• The number of possible ways


to visit N cities, (N-1)!,
becomes very large for large N

Fig 3.9 An instance of the travelling salesperson problem


29
Search of the Traveling SalespersonProblem
Planning
Optimization N=5 ;
Total (5-1) ! =24 paths

Fig 3.10 Search for the travelling salesperson problem. Each arc is marked with
the total weight of all paths from the start node (A) to its endpoint.
30
Strategies for State Space Search
• DataѪdriven search : Facts&Rules=>newFacts =>… =>Goal
– Begins with the given facts of the problem and a set of legal
moves or rules for changing state
– Apply rules to facts to produce new facts, which are in turn
used by the rules to generate more new facts
– Continues until (we hope!) it generates a path to a goal
– This approach is sometimes called forward chaining

31
Strategies for State Space Search
• GoalѪdriven search : Goal=>subGoals =>… =>Facts
– Start from the goal
– See what facts can lead to this goal
– These facts become the new goals, or subѪgoals,
for the search
– Search continues, working backward through
successive subѪgoals until (we hope!) it works back
to the facts of the problem
– This finds the chain of moves or rules leading from
data to a goal, although it does so inreverse order
– This approach is also called backward chaining

32
Strategies: Data-driven vs. Goal-driven

• Similarity and differences between dataѪdriven and


goalѪdriven searches
– Both search the same state space
– However, the order and actual number of states
searched can differ
– The preferred strategy is determined bythe
properties of the problem itself

• Hybrid of dataѪdriven and goalѪdriven searches

33
34
Exercise: would you use data-driven or goal-driven search for
each of the following problems? Briefly justify your answer.
i) A GO playing program.
ii) A medical diagnostic program.

Exercise_Discussions
i) Go playing : likely it is data-driven as many initial data are
available. But it is not clear what the goal is or have huge number
of possible goals.

ii) Medical – Likely it is goal-driven as goal=condition to be


diagnosed is known ; but the rest of data (causes of the condition)
need to be found.

35
Implementation of Graph Search
• Why Search a Graph?
– Graph search is used to explore the state space for
searching a certain node (goal)
– It can also be used to search for a path between
two nodes, check if the graph contains loops or is
connected, etc.

• Backtracking Search ?

36
Notations of Backtracking
• CS= Current State (the state currently under consideration)

• SL= State List (the list of states in the current path being pursued. If a
goal is found, SL contains the ordered list of states on the solution path)

• NSL =New State List (the list of new states contains nodes awaiting
evaluation, i.e., nodes whose descendants have not yet been generated
and searched)

• DE = Dead Ends (the list of states whose descendants have failed to


contain a goal node. If these states are encountered again, they will be
deleted as elements of DEand eliminated)

• CS (Current State) is always equal to the state most recently added to SL


and represents the "frontier" of the solution path currently beingexplored

37
Procedure of Backtracking

• Begins at the start state


• Pursues a path until it reaches eithera
goal or a"dead end"
• If it finds a goal, it quits and returns
the solution path
• If it reaches a dead end, it "backtracks" to
the most recent node on the path having
unexamined siblings and continuesdown
one of these branches

38
Recursive at Each Node
• If the present state S does not meet the
requirements of the goal description, then
generate its first descendant Schild‐l and apply the
backtrack procedure recursively to this node
• If backtrack does not find a goal node in the
sub‐graph rooted at Schild‐1, repeat the procedure
forits sibling Schild‐2
• This continues until either some descendant of a
child is a goal node or all of the children have
been searched.

39
In the Backtracking
• Inference rules, moves in the game, or appropriate problem
solving operators are applied to CS. The result is a set of
children of CS
• One of these children is made the new current state and the
rest are placed in the left (front) of NSL for future
examination
• The new current state is added to SL and the search
continues
• If CS has no unexamined children, it is removed from SL (this
is where the algorithm backtracks) and any remaining children
from its predecessor (siblings) on SL are examined

40
Main ideas used in Backtracking
1. The use of a list of unprocessed states (NSL)to allow the
algorithm to return (backtrack) to any of these states
2. A list of "bad" states DE to prevent the algorithm
from retrying useless states
3. Alist of nodes (SL) on the current solution path that is
returned if a goal is found
4. Explicit checks for memberships of new states in
these lists to prevent looping

41
The backtrackingalgorithm

% un-checked state

42
ExampleonBacktracking
• Systematically trying all paths through a state space
• An exhaustive search: not always affordable Suppose G is the Goal State

A trace of backtrack on the graph of Figure 3.12

Fig 3.12 Backtracking Search

43
Exercise 3 : Backtracking on Graph

Assume: there is no goal state in the search space.


Initialize: SL=[A];NSL=[A]; DE=[ ]; CS=A;
44
Exercise 3 _ Discussions : BackTracking

“Hand run” the backtracking algorithm on the right graph


Keep track of the successive values of NSL, SL, CS, DE.
We assume there is no goal state in the search space.
Initialize: SL=[A];NSL=[A]; DE=[]; CS=A;

45
Breadth-First Search
• A search space is explored in a levelѪbyѪlevel fashion
– Only when there are no more states to be
explored at a given level does the algorithm
move on to the next level

A breadth‐first search of
the graph of Figure 3.13
considers the states in the
order:
A, B, C, D, E, F,G, H, I, J,
K,L,M, N, O, P, Q, R, S, T,U

Fig 3.13 Graph for breadth - and depth - first search examples.
46
Implementation of BreadthѪfirst Search

• Two lists:
– open Ѫstates that have been generated but whose
children have not been examined
– closed Ѫstates that have already been examined

• The ancestor states are removed from the left


(beginning) of open and descendant states are added
from the right (ending) of open.
open is maintained as a queue, or firstѪinѪfirstѪout
(FIFO) structure

47
Algorithm of Breadth-First Search

48
Example: Breadth-First Search
Trace of Breadth-First Search on the Fig 3.13 The Graph.
graph of Fig.3.13 (U is desired goal state)

OPEN: FIFO ; descendant add from right


Closed: add from the left

49
Breadth-First Search: open and closed

50
Limitations on Breadth-First Search
• If the branching factor,B
(average number of children), is
large, the combinatorics may
prevent the algorithm from
finding a solution using the
available space

• The space utilization of breadth‐first


search, measured in terms of the
number of states on open, is an
exponential function of the length
of the path at any time or Bn states
on level n

51
Depth-First Search
• When a state is examined, all of its children and their
descendants are examined before any of its siblings
– Only when no further descendants of a state can be found are
its siblings considered

Depth‐first search examines


the states in the graph of
Figure3.13 in the order:
A, B, E, K, S, L, T,F,M,C,
G, N, H, O, P,U, D, I, Q,J,
R

The backtrack algorithm


Fig 3.13 The Graph. previously discussed
implements depth‐first search
52
An alternative implementation of
depthѪfirst search
• The descendant states are both added and removed
from the left (beginning) of open Ѫopen is
maintained as a stack, or lastѪinѪfirstѪout (LIFO)
structure:
• The organization of open in the above manner
biases search toward the mostrecently
generated states, giving search adepthѪfirst
order

53
Implementation of DepthѪfirst search
• Two lists:
– open ‐ states that have been generated but
whose children have not been examined
• similar to NSL in backtrack
– closed ‐ states that have already been examined
• an union of DEand SLin backtrack

54
Algorithm of Depth-First Search

55
Example :Depth-First Search Open: stack

Fig 3.13 The Graph.

An alternative implementation of depthѪfirst search 56


Alternative implementation of depth‐first search

Fig 3.16 Graph of Fig 3.13 at iteration 6 of depth-first search.


States on open and closed are highlighted.
57
Exercise 4 : Perform both the breadth-first and depth-first search in the graph
Fig.Ex4, starting from node A. The nodes are visited in alphabetical order, for
example, B is ahead of C. Explain which search will examine a smaller number
of nodes to find the goal node G.

Fig. Ex4

58
Exercise 4_Discussions

Depth-First Breadth-First

Open Closed Open Closed


A [] A []
BC A BC A
DFHC B CDFH B
FHC D DFHEI C
HC F FHEI D
KLC H HEI F
LC K EIKL H
GIC L IKL E
G KLG I
LG K
G L
G

59
Example : Breadth-First vs Depth-First Search

breadthѪfirst depthѪfirst

60
Advantages : Breadth-First & Depth-First

• Advantages of breadthѪfirst
search:
– Finds the shortest path from the
start state to the goal
– Never gets trapped exploring a blind
alley

• Advantage of depthѪfirst search


– DepthѪfirst search requires less
memory since only the nodes on
the current path are stored B*n. This
contrasts with breadthѪfirst search
where all of the tree that has so far
n
been generated B
61
Discussions on Breadth-First Search

• If the branching factor, B (average number of children),


is large, the combinatorics may prevent the algorithm
from finding a solution using the availablespace

• The space utilization of breadthѪfirst search, measured


in terms of the number of states on open, is an
exponential function of the length of the path at any
time or Bn states on level n

62
Discussions on Depth-First Search
• DepthѪfirst search gets quickly into a deep searchspace.
• DepthѪfirst search can get "lost" deep in a graph, missing
shorter paths to a goal or even becoming stuck in an
infinitely long path.
• The space usage of depthѪfirst search is a linear function
of the length of the path. At each level, open retains only
the children of a single state or B times n states to go n
levels deep into the space

63
Depth‐First search with
Iterative Deepening

DepthѪFirst search with Iterative Deepening :


— First performs a depth‐first search of the space witha
depth bound of one
– If it fails to find a goal, it performs another depthѪfirst
search with a depth bound of two. We increase the
depth bound by one eachtime.
– At each iteration, the algorithm performs a complete
depthѪfirst search to the current depth bound. No
information about the state spaceis retained between
iterations

64
Depth‐First Search with Iterative Deepening
Depth bound from 1, and increase by one each time.

65
Discussions on Depth‐first search with
Iterative Deepening

• Since the algorithm searches the space in a


levelѪbyѪlevel fashion, it is guaranteed to find a
shortest path to a goal
• Since it does only depthѪfirst search at each
iteration, the space usage at any level n is B
times n, where B is the average number of
children of a node

66
Typical Questions forSearch

• Is the search guaranteed to find asolution?


• When a solution is found, is it guaranteed to be
optimal?
• Will the search always terminate, or can it become
caught in an infinite loop?
• What is the complexity of the search process in terms
of time usage? Space (computer memory)usage?

67
Summary on Topic 2
- Knowledge Representation
- Symbols, logic, rules
- Can be processed: structures and computer languages
- Symbolic AI: Predicate Calculus ; state space Graph

- Search Strategies
- Data-driven vs Goal-driven
- Graph: Back-tracking
n
- Breadth-First : FIFO queue; shortest path; B
- Depth-First: FILO stack; dead-end; B*n
- Depth-Iterative: Depth-bound

68

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy