Ch3 SolvingProblemsBySearching
Ch3 SolvingProblemsBySearching
Solving Problems by
Searching
❖ Problem-Solving Agents
❖ Example Problems
❖ Searching for Solutions
❖ Uninformed Search Strategies
❖ Informed Search Strategies
❖ Together, the initial state, actions, and transition model define the
state space of the problem – the set of all states reachable from the
initial state by any sequence of actions. ( or – a graph in which the nodes are
states and the arcs between nodes are actions)
Ch3: Solving Problems by Searching 11
3.1.1 well defined problems and solutions
(Cont’d)
4. goal test : which determine whether a given state is a goal state, and can
be :
explicit, e.g., {In(Bucharest)}
implicit, e.g., “checkmate” state in chess
5. path cost function
e.g., sum of distances, number of actions executed, etc.
c(s; a; s’) is the step cost of taking action a in state s to reach state s’ assumed
to be nonnegative
❖States :
The state is
determined by
both the agent
location and the
dirt location
Initial state??:
actions??:
transition model??:
goal test??:
path cost??:
❖States :
The state is
determined by
both the agent
location and the
dirt location
❖States :
any arrangement of 0 to
8 queens on the board is
a state.
Not a solution
❖ Robot navigation
❖ Internet searching
Each of these six nodes is a leaf node ( a node with no children in the tree)
Ch3: Solving Problems by Searching 21
General tree search
Return
❖ Optimality:
Does it always find the least-cost solution?
In general YES
▪ Unless actions have different cost.
❖ Time complexity:
Assume a state space where every state has b successors.
▪ Root has b successors, each node at the next level has again b successors (total b2), …
▪ Assume solution is at depth d
▪ Worst case; expand all but the last node at depth d
▪ Total numb. of nodes generated:
▪ 1 + b + b2 + …+ bd + b(bd-1) = O(bd+1)
❖S.PATH-COST=0
❖Priority Queue=[(s)0]
Ch3: Solving Problems by Searching 35
3.4.2 Uniform-cost search (UCS) (Cont’d)
❖Expanding S
❖AS.PATH-COST=1, BS.PATH-COST=5,
CS.PATH-COST=15
❖Priority Queue=[(AS)1,(BS)5,(CS)15]
Ch3: Solving Problems by Searching 36
3.4.2 Uniform-cost search (UCS) (Cont’d)
❖Expanding AS
❖GAS.PATH-COST=11, BS.PATH-
COST=5, CS.PATH-COST=15
❖Priority Queue=[(BS)5,(GAS)11 ,(CS)15]
Ch3: Solving Problems by Searching 37
3.4.2 Uniform-cost search (UCS) (Cont’d)
❖Expanding BS
❖GAS.PATH-COST=11, GBS.PATH-
COST=10, CS.PATH-COST=15
❖Priority Queue=[(GBS)10, (GAS)11,(CS)15]
Ch3: Solving Problems by Searching 38
3.4.2 Uniform-cost search (UCS) :
Evaluation
❖ Completeness:
Does it always find a solution if one exists?
YES
▪ If step cost ≥ ε (some small positive integer)
▪ Uniform-cost search will get stuck in an infinite loop if there is a path with an infinite sequence of zero-
cost actions (for example : a sequence of NoOp actions))
❖ Optimality:
Does it always find the least-cost solution?
In general YES
❖ Time and space complexity:
Uniform-cost search is guided by the path costs rather than depths, so its complexity is not
characterized in terms of b and d.
Instead, let C* be the cost of the optimal solution and assume that every action costs at
least ε,
The algorithm’s worst-case time and space complexity is O(b 1+[C*/ ε] )
▪ When all step costs are equal , b 1+[C*/ ε] is just bd+1
❖Expand A
❖LIFO=[(BA),(CA)]
❖Expand BA
❖LIFO=[(DBA),(EBA),(CA)]
❖LIFO=[(FCA),(GCA)]
❖LIFO=[(MFCA)
,(GCA)]
❖LIFO=[(LFCA)
,(MFCA),(GCA)]
❖Remove MFCA
❖It is the goal state
❖Return solution
❖ Optimality:
Does it always find the least-cost solution?
No
▪ (Might never find any solutions)
❖ Time complexity:
O(bm), m is the maximum depth of any node.
m can be much larger than d (the depth of the shallowest solution)
m =∞ if the tree is unbounded
❖ Space complexity : O(bm)
Must store all nodes on current path
Must store all unexplored sibling nodes on each hit
At depth m, required to store b*m nodes
Much better than O(bm)
Ch3: Solving Problems by Searching 47
3.4.4 Depth-limited search (DLS)
❖ = depth-first search with depth limit l,
i.e., nodes at depth l have no successors.
Choosing an appropriate l may not be easy and could result in
incompleteness (WHY?)
Iteration 1
❖ Optimality:
Does it always find the least-cost solution?
YES
▪ If step costs are all identical
❖ Time complexity:
O(bd), d (the depth of the shallowest solution)
Total numb. of nodes generated:
▪ (d+1)1 + db + (d-1)b2 + …+ (1)bd = O(bd)
❖ Space complexity :
O(bd)
❖ Implementation
The structure to store the open nodes is a priority queue ordered by
evaluation function, lowest first.
❖ Special cases:
uniform-cost search: f(n) = g(n), the cost of node n from the initial node.
greedy search: f(n) = h(n), the estimated cost of node n reaching the
goal.
A* search: f(n) = g(n) + h(n).
❖ Optimality:
Does it always find the least-cost solution?
No
▪ the path Arad-Sibiu-Fagaras-Bucharest is sub-optimal (Total path cost = 140 + 99 + 211 = 440 km)
▪ Arad→Sibiu→Rimnicu Virea→Pitesti→Bucharest is shorter!
– Path cost = 140 + 80 + 97 + 101 = 418 km
▪ Best-first search can be improved by taking the actual cost to a state n into account
– The new search strategy is called A*
❖ Time complexity:
O(bm), m is the maximum depth of any node.
but a good heuristic can give dramatic improvement
❖ Space complexity : O(bm)
Ch3: Solving Problems by Searching 64
3.5.2 A* search
❖ Idea: avoid expanding paths that are already expensive
❖ Optimality:
Does it always find the least-cost solution?
YES
▪ if h(n) satisfies certain conditions ( admissibility and consistency)
❖ Time complexity:
▪ Depends on h, can be exponential
❖ Space complexity :
▪ O(bm)
▪ stores all nodes