Professional Documents
Culture Documents
Goals help organize behavior by limiting the objectives that the agent is trying
to achieve and hence the actions it needs to consider.
Problem formulation: deciding what actions and states to consider, given a goal
A search algorithm takes a problem as input and returns a solution in the form
of an action sequence.
2 Prepared by Chala S. (MSc in CSE) 6/19/2022
Problem Space and Search
A problem space is an abstract space.
A problem space encompasses all valid states that can be generated by the application
of any combination of operators/actions on any combination of objects.
The problem space may contain one or more solutions. A solution is a combination of
operations and objects that achieve the goals.
Formulate problem:
states: various cities
actions: drive between cities
Search:
sequence of cities
4 Prepared by Chala S. (MSc in CSE) 6/19/2022
Road map of Romania Touring
Optimal solution: the path that has the lowest path cost among all solutions;
measured by the path cost function.
7 Prepared by Chala S. (MSc in CSE) 6/19/2022
Problem Formulation: Romania Touring
Initial state: In(Arad)
Actions: if current state is In(Arad), actions = {Go{Sibiu), Go(Timisoara), Go(Zerind)}
Transition model:
E.g., Results(In(Arad), Go(Sibiu)) = In(Sibiu)
Goal test determines whether a given state is a goal state
explicit,e.g. In(Bucharest)
implicit, e.g. checkmate: when the opponent’s king is under attack and can’t escape
Real world is complex and has irrelevant details that should be removed from state space and
actions, which is called abstraction.
In(Arad), in actual cross country trip; the traveling companions, the current radio program, the
scenery out of the window, the condition of the road, the weather, and so on are irrelevant real
world descriptions.
the abstraction is useful, if carrying out the actions in the solution is easier than the original problem
Problem Formulation
States: 2 agent location *2 possible dirt locations
*2 different dirt states= 8 states
Initial state: any state
Actions: Left, Right, and Suck
Transition model: complete state space, see next
slide.
Goal test: check if both squares are clean
Path cost: each step costs 1
This family is known to be NP-complete, so one does not expect to find methods
significantly better in the worst case than the search algorithms.
The 15-puzzle (on a 4×4 board) has around 1.3 trillion states, and
States:
Arrangements of n queens, one per column in the leftmost n columns, with no queen
attacking another.
Actions:
Add a queen to any square in the leftmost empty column such that it is not attacked
by any other queen
Problem Formulation
States: list of colors for each cell on each
face
Initial state: one specific cube configuration
Actions: rotate row x or column y on face z
direction
Goal: configuration has only one color on
each face
Path cost: 1 per move
The possible action sequences starting at the initial state form a search tree with:
The initial state at the root;
The branches are actions applied on current state to create a new state and
the nodes correspond to states having no successor.
Search algorithms all share this basic structure; they vary primarily according to
how they choose which state to expand next—the so-called search strategy.
Good choice fewer work faster
18 Prepared by Chala S. (MSc in CSE) 6/19/2022
Terminologies
Frontier/Fringe: set of all leaf nodes available for expansion at any given state.
The appropriate data structure for this is a queue that implemented in FIFO.
Repeated state: in Romanian tour, path from Arad to Sibiu and back to Arad
again. We say that In(Arad) is a repeated state.
Redundant path: more than one way to get from one state to another, Arad–
Sibiu (140 km long) and Arad–Zerind–Oradea–Sibiu (297 km long).
GRAPH-SEARCH
Uses “explored” set to avoid visiting already
explored states.
Uses “frontier” set to store states that remain
to be explored and expanded.
20 Prepared by Chala S. (MSc in CSE) 6/19/2022
Graph-Search
Redundant paths can cause a tractable problem to become intractable.
The way to avoid exploring redundant paths is to remember where one has been.
To do this, we augment the TREE-SEARCH algorithm with a data structure called the
explored set (also known as the closed list), which remembers every expanded node.
Newly generated nodes that match previously generated nodes—ones in the explored set
or the frontier—can be discarded instead of being added to the frontier.
Optimality:
does the strategy find the highest-quality solution when there are several different solutions?
Time complexity:
how long does it take to find a solution?
Space complexity:
how much memory is needed to perform the search?
All search strategies are distinguished by the order in which nodes are expanded.
Uninformed search
no information about the number of steps or the path cost from the current state to the goal.
evaluation function to tell us how far each expanded state is from a goal state,
heuristic function to help us decide which state is likely to be the best one to expand next.
27 Prepared by Chala S. (MSc in CSE) 6/19/2022
Uninformed Search Strategies
Given a state, we only know whether it is a goal state or not
Cannot say one non-goal state looks better than another non-goal state
Traverse state space blindly in hope of somehow hitting a goal state at some point
All the nodes generated by the root node are then expanded
In general, all the nodes are expanded at a given depth in the search tree before
any nodes at the next level are expanded.
A D
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17 G 25
30 Prepared by Chala S. (MSc in CSE) 6/19/2022
BFS on a Graph
Optimal, finds shortest solution if path cost is 1 or non decreasing function of the
depth of the node.
Simple to implement
The disadvantage:
if the branching factor b of a node is large,
for even small instances (e.g., chess)
the space complexity and the time complexity are enormous
32 Prepared by Chala S. (MSc in CSE) 6/19/2022
Analysis(Cont..)
Time complexity? (measured by Number of nodes generated)
b+b2+b3+… +bd = O(bd)
Space?
O (bd) (keeps every node in memory)
Exponential time and space: assuming the branching factor b = 10; 1 million
nodes/sec; 1k bytes/node.
It takes 13 days for the solution to a problem with
search d = 12, nodes =1012 and 350 years at depth 16.
Memory is more of a problem than time
Requires 103GB when d = 8
Exponential-complexity search problems cannot be
solved by uninformed methods but for smallest instances
33 Prepared by Chala S. (MSc in CSE) 6/19/2022
Uniform cost search
Breadth-first finds the shallowest goal state
but not necessarily be the least-cost solution
work only if all step costs are equal
Uniform-cost search is guided by path costs rather than depths, so its complexity
is not easily characterized in terms of b and d.
Implementation:
A D
B D A E
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
19 19 17
40
G 25 Prepared by Chala S. (MSc in CSE) 6/19/2022
DFS Analysis
It overcomes
the time and space complexities
Complete?
The graph-search version, which avoids repeated states and redundant paths, is complete in finite state
spaces.
In Backtracking:
Only one successor is generated at a time rather than all successors
Each partially expanded node remembers which successor to generate next
Memory requirement: only O(m) vs. O(bm)
It solves the infinite-path problem. Unfortunately, it will be incomplete if we choose l < d, that is,
the shallowest goal is beyond the depth limit. (This is likely when d is unknown.)
C E E B B F
11
D F B F C E A C G
14 17 15 15 13
G C G F
44
19 19 17 G 25 Prepared by Chala S. (MSc in CSE) 6/19/2022
Iterative deepening search
No choosing of the best depth limit
Space? O(bd)
Start Goal
For graph searches, the main differences are that DFS is complete for finite state spaces
and that the space and time complexities are bounded by the size of the state space.
Repeated states can be the source of great inefficiency: identical sub trees will be
explored many times.
If the current node matches a node on the closed list, it is discarded instead of
being expanded.
f(n): construed as a cost estimate, so the node with the lowest evaluation is expanded first.
Identical to that for uniform-cost search, except for the use of f instead of g to order the priority
queue.
h(n) = estimated cost of the cheapest path from the state at node n to a goal state.
if n is a goal node, then h(n) = 0.
Thus, it evaluates nodes by using just the heuristic function; that is, f(n) = h(n).
Example: We use the straight line distance heuristic, which we will call hSLD
hSLD(In(Arad))= 366
Let’s examine:
Arad Sibiu Fagaras Bucharest
Optimal? No
Arad Sibiu Fagaras Bucharest
Is 32 km longer than
It evaluates nodes by combining g(n), the cost to reach the node, and h(n), the cost to get from the
node to the goal: f(n) = g(n) + h(n)
g(n) gives the path cost from the start node to node n, and
h(n) is the estimated cost of the cheapest path from node n to the goal node,
Tries the node with the lowest value of f(n)= g(n) + h(n).
Provided that the heuristic function h(n) satisfies certain conditions, A∗ search is both complete
and optimal.
An admissible heuristic is one that never overestimates the cost to reach the goal. Because g(n) is
the actual cost to reach n along the current path, and f(n) = g(n) + h(n), we have as an
immediate consequence that f(n) never overestimates the true cost of a solution along the
current path through n.
A heuristic h(n) is consistent if, for every node n and every successor n of n’ generated by any
action a, the estimated cost of reaching the goal from n is no greater than the step cost of getting
to n ’ plus the estimated cost of reaching the goal from n ’ :
An assignment that does not violate any constraints is called a consistent or legal
assignment.
The task is coloring each region either red, green, or blue in such a way that the neighboring: regions
have no the same color.
The constraints require neighboring regions to have distinct colors; for example,
the allowable combinations for WA and NT are the pairs.
{(red,green),(red,blue),(green,red),(green,blue),(blue,red),(blue,green)}.
Any Question?