Lecture2 Uninformedsearch
Lecture2 Uninformedsearch
International University
School of Computer Science and Engineering
NP-Complete
States:
location of each tile and the blank
Initial state: any
Actions:
blank moves Left, Right, Up or Down
Transition model:
Given a state and action, returns the resulting state
Goal test: Goal configuration
Path cost: Each step costs 1
Example: Robotic Assembly
States
real-valued coordinates of robot joint angles; parts of the
object to be assembled
Actions
continuous motions of robot joints
Transition model
States of robot joints after each action
Goal test
complete assembly
Path cost: time to execute
Missionaries & Cannibals
Both missionaries and cannibals must cross the river safely.
Boats can ride up to three people.
If the number of cannibals is more than the number of
missionaries anywhere, missionaries will be eaten.
Check on this link:
https://javalab.org/en/boat_puzzle_en/
Problem Formulation
States:
<m, c, b> representing the # of missionaries and the # of
cannibals, and the position of the boat
Initial state:
<3, 3, 1>
Actions:
take 1 missionary, 1 cannibal, 2 missionaries, 2 cannibals,
or 1 missionary and 1 cannibal across the river
Transition model:
state after an action
Goal test:
<0, 0, 0>
Path cost:
number of crossing
Real-World Problems
Touring problem: visit every city at least
once, starting in Arad and ending in
Bucharest
Traveling sales problem: exactly once
Robot navigation
Internet searching: software robots
Searching for Solutions
? ?
? ?
? ?
Searching for Solutions
Search tree: generated by initial state and
possible actions
Basic idea:
offline, simulated exploration of state space by
generating successors of already-explored states
(expanding states)
the choice of which state to expand is determined
by search strategy
Tree Search Example
20
Tree Search Example
Tree Search Example
Terminologies
Frontier: set of all leaf nodes available for
expansion at any given point
Repeated state
Loopy path: Arad to Sibiu to Arad
Redundant path: more than one way to get from
one state to another
30
Search Strategies
A search strategy is defined by picking the order of node
expansion
40
Uniform-Cost Search
Analysis
Complete?
Yes, if step cost ≥ ε
Time?
O (b ceiling(C*/ ε)) where C * is the cost of the optimal solution
# of nodes with g ≤ cost of optimal solution
Space?
O (b ceiling(C*/ ε))
# of nodes with g ≤ cost of optimal solution
Optimal?
Yes – nodes expanded in increasing order of g(n)
Uniform-Cost Search is Optimal
Uniform-cost search expands nodes in order
of their optimal path cost
Hence, the first goal node selected for
expansion must be the optimal solution
Depth-First Search
Expand deepest unexpanded node
Implementation:
frontier = LIFO queue, i.e., put successors at front
Or a recursive function
Depth-First Search
Expand deepest unexpanded node
Implementation:
frontier = LIFO queue, i.e., put successors at front
Or a recursive function
Depth-First Search
Expand deepest unexpanded node
Implementation:
frontier = LIFO queue, i.e., put successors at front
Or a recursive function
Depth-First Search
Expand deepest unexpanded node
Implementation:
frontier = LIFO queue, i.e., put successors at front
Or a recursive function
Depth-First Search
Expand deepest unexpanded node
Implementation:
frontier = LIFO queue, i.e., put successors at front
Or a recursive function
Depth-First Search
Expand deepest unexpanded node
Implementation:
frontier = LIFO queue, i.e., put successors at front
Or a recursive function
Depth-First Search
Expand deepest unexpanded node
Implementation:
frontier = LIFO queue, i.e., put successors at front
Or a recursive function
50
Depth-First Search
Expand deepest unexpanded node
Implementation:
frontier = LIFO queue, i.e., put successors at front
Or a recursive function
Depth-First Search
Expand deepest unexpanded node
Implementation:
frontier = LIFO queue, i.e., put successors at front
Or a recursive function
Properties of DFS
Properties of DFS depend strongly on
whether the graph-search or tree-search
version is used
Analysis of DFS + Tree Search
Complete?
No: fails in infinite-depth spaces, or spaces with loops
Modify to avoid repeated states along path
=> complete in finite spaces
Time?
O (bm): terrible if m is much larger than d
but if solutions are dense, may be much faster than
breadth-first
Space?
O (bm), i.e., linear space!
Optimal?
No
Analysis of DFS + Graph Search
Complete?
No: also fails in infinite-depth spaces
Yes: for finite state spaces
Time?
O (bm): terrible if m is much larger than d
but if solutions are dense, may be much faster than
breadth-first
Space?
Not linear any more, because of explored set
Optimal?
No
Backtracking Search
Backtracking search is a variant of DFS
Only one successor is generated at a time rather
than all successors
Each partially expanded node remembers which
successor to generate next
60
Depth Limit = 2
Depth Limit = 3
Analysis of Iterative Deepening Search
Number of nodes generated in a depth-limited search to depth
d with branching factor b:
NDLS = b0 + b1 + b2 + … + b d-2 + b d-1 + b d
For b = 10, d = 5,
NDLS = 1 + 10 + 100 + 1,000 + 10,000 + 100,000 = 111,111
NIDS = 6 + 50 + 400 + 3,000 + 20,000 + 100,000 = 123,456
Optimality:
uniform-cost search or breadth-first search with identical
step costs are still optimal even if it returns the first path
found
iterative-deepening, identical step cost or non-decreasing
function of depth of a node