Topic 2 Structures and Strategies For
Topic 2 Structures and Strategies For
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
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
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
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 :
8
8-puzzle : Symbolic AI vs sub-Symbolic AI
9
Search Strategy !!!
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
14
RootedG, Leaf, Path, Ancestor/Descendant, 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
18
State Space Approach to Problem Solving
19
Example: the tic-tac-toe Game
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)
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
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
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.
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)
37
Procedure of Backtracking
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
43
Exercise 3 : Backtracking on Graph
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
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)
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
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
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. Ex4
58
Exercise 4_Discussions
Depth-First Breadth-First
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
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
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
66
Typical Questions forSearch
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