Ai CH - 1
Ai CH - 1
Ai CH - 1
Basics of search
1
Problem Solving Agents
• This chapter describes one kind of goal-
based agent called a problem-solving
agent.
• Goal formulation: -
• We will consider a goal to be a set of
world states—exactly those states in which
the goal is satisfied. The agent’s task is to
find out how to act, now and in the future,
so that it reaches a goal state.
2
• Problem formulation: - is the process of deciding
what actions and states to consider, given a goal.
– Here we may have unknown environment so our agent
has no choice but to try one of the actions at random.
• The process of looking for a sequence of actions
that reaches the goal is called search.
• A search algorithm takes a problem as input and
returns a solution in the form of an action
sequence. Once a solution is found, the actions it
recommends can be carried out. This is called the
execution phase.
• Thus, we have a simple:
formulate search execute 3
Well-defined problems and solutions
Example:-
4
Count…
• A problem can be defined formally by five
components:
– Initial State: - The initial state that the agent starts
in. For example, the initial state for the above
figures can be described as A. In(A)
– Actions: - Description of possible actions
available to the agent. Given a particular state s,
ACTIONS(s) returns the set of actions that can
be executed in s. We say that each of these actions
is applicable in s.
• Example: - In (A), the applicable actions are {Go (C),
Go (D), Go E)}.
5
Count…
– Transition Model: - A description of what
each action does. Specified by a function
RESULT(s,a) that returns the state that
results from doing action a in state s. We
also use the term successor to refer to any
state reachable from a given state by a
single action.
• Example: - RESULT (In (A), Go (E)) = In (E)
6
Count…
– Goal state: - Determines whether a given state is a
goal state or not.
– Path cost: -Is a function that assigns a numeric cost
to each path. It reflects agent’s performance
measure.
• The preceding elements define a problem and can be
gathered into a single data structure that is given as
input to a problem-solving algorithm.
• A solution to a problem is an action sequence that leads
from the initial state to a goal state. Solution quality is
measured by the path cost function, and an optimal
solution has the lowest path cost among all solutions.
7
Count…
• Together, the initial state, actions, and
transition model implicitly define the state
space of the problem—the set of all states
reachable from the initial state by any
sequence of actions.
• The state space forms a directed network or
graph in which the nodes are states and the
links between nodes are actions.
• A path in the state space is a sequence of
states connected by a sequence of actions.
8
Searching for solutions
• A solution is an action sequence, so search
algorithms work by considering various possible
action sequences.
– The possible action sequences starting at the initial
state form a search tree with the initial state at the
root; the branches are actions and the nodes
correspond to states in the state space of the problem.
• A leaf node is a node with no children in the
tree. The set of all leaf nodes available for
expansion at any given point is called the
frontier.
9
Measuring problem-solving performance
• We can evaluate an algorithm’s performance in
four ways:
– COMPLETENESS: - Is the algorithm guaranteed
to find a solution when there is one?
– OPTIMALITY: - Does the strategy find the
optimal solution?
– TIMECOMPLEXITY: - How long does it take to
find a solution?
– SPACECOMPLEXITY: -How much memory is
needed to perform the search?
10
Count…
• Time and space complexity is expressed in
terms of three quantities:
– b: maximum number of successors of any
node (OR maximum branching factor of the
search tree)
– d: the depth of the shallowest goal need (OR
depth of the least cost solution )
– m: the maximum length of any path in the
state space (OR maximum depth of the sate
space )
11
Uninformed (Blind) Search
13
Count…
• Breadth-first search is an instance of the
general graph-search algorithm in which the
shallowest unexpanded node is chosen for
expansion.
• This is achieved very simply by using a FIFO
queue for the frontier.
• Goal test is done when a node is generated
rather than when it is selected for expansion.
14
15
Performance of breadth- first search
• Completeness: - yes it is complete if we have a
finite branching factor. i.e. if we have some finite
branching factor then we have finite depth.
• Optimality: -Breadth-first search is optimal if
the path cost is a non decreasing function of the
depth of the node.
• Time complexity: - if every state has b
successors and the solution is at depth d.
– The total number of node generated is: -
b+b2+b3+…+bd=O(bd)
16
Count…
• Space complexity: - for breadth- first search
every node generated remains in memory.
– There will be O(bd-1)) nodes in the explored set and
O(bd) nodes in the frontier.
– So the space complexity is O(bd) i.e. it is dominant
by the size of the frontier.
17
Uniform-cost search
• Example: -
19
Count…
• From the above figure the successor of A are C
and B, with cost 80 and 99 respectively.
• The least cost node is C so we expand it next we
will find D with cost 97 so we add the two
80+97=177.
• Then we compare it with B, B=99<177 therefore
we expand B and get E with cost 99+211=310.
• At this point we compare 310 and 177 so we will
expand D and get 80+97+101=278.
• The algorithm chooses 278 because it is the least.
20
Performance of uniform- cost search
• Completeness:- Uniform-cost search does not
care about the number of steps a path has, but
only about their total cost.
• Therefore, it will get stuck in an infinite loop if
there is a path with an infinite sequence of
zero-cost actions.
• Completeness is guaranteed, if provided with
the cost of every step exceeds some small
positive constant
21
Count…
• Optimality: - it is optimal in general because of
two reasons:
– When a node n is selected for expansion the
optimality path to that node has been found.
– Step costs are non- negative paths never getting
shorter as nodes are added.
• By these two reasons we can imply that
uniform- cost search expands nodes in order of
their optimal path cost.
• Hence, the first node selected for expansion
must be the optimal solution.
22
Count…
• Time and space complexity: - the algorithms
worst case time and space complexity will be
• O (b1+[C*/ ]) where,
– - is the cost of every action
– C*- the cost of the optimal solution
23
Depth-first search
24
Count…
• Depth-first search uses a LIFO queue. A LIFO
stack means that the most recently generated
node is chosen for expansion.
• This must be the deepest unexpanded node
because it is one deeper than its parent—
which, in turn, was the deepest unexpanded
node when it was selected.
25
26
27
Performance of Depth- first search
• Completeness:- The graph-search version,
which avoids repeated states and redundant
paths, is complete in finite state spaces
because it will eventually expand every node.
• The tree-search version, on the other hand, is
not complete.
• If we have infinite state space the both the tree
and graph search version are not complete.
28
Count…
• Optimality: - Whether we are using graph or
tree search version to apply to depth first
search it is not optimal consider the following
figure:
29
Count…
• If node C is a goal state the depth first search
will explore the entire left sub tree even if
node C is a goal node.
• If G were also a goal node state the depth first
search would return it as a solution instead of
C which would be a better solution; hence,
depth-first search is not optimal.
30
Count…
• Time Complexity: - it may generate all the nodes
in the search tree. It is O(bm) , b is branching factor
and m is the maximum depth of any node.
• Space complexity: - its tree search version has
advantage over breadth first search in its space
complexity.
• Depth first search removes a node form memory
once all its descendents have been expanded.
• Therefore, its space complexity will be O (bm).
31
Depth limited Search
• Depth first search suffers from non termination
when the length of a path in the search tree is
infinite, so we perform depth first search to a
limited depth which is called Depth limited
search.
• This search precedes the search by declaring
nodes at depth l are treated as if they have no
successors.
• This helps to solve the infinite path problem.
32
Performance of Depth- limited search
• Unfortunately, it also introduces an additional
source of incompleteness if we choose l<d,
that is, the shallowest goal is beyond the depth
limit. (This is likely when d is unknown.)
• Depth-limited search will also be non optimal
if we choose l >d.
• Its time complexity is O(b l) and its space
complexity isO(b l).
• Depth-first search can be viewed as a special
case of depth-limited search with l =∞.
33
Iterative deepening depth-first search (IDS)
34
35
Performance of iterative deepening depth first search
38
Count…
• Heuristic functions are the most common form in
which additional knowledge of the problem is
imparted to the search algorithm.
• For now, we consider them to be arbitrary,
nonnegative, problem-specific functions, with one
constraint: if n is a goal node, then h(n )=0.
39
Greedy best-first search
45
Count…
• Time and space complexity:
– The worst-case time and space complexity for the
tree version is O(bm),where m is the maximum
depth of the search space.
• With a good heuristic function, however, the
complexity can be reduced substantially.
• The amount of the reduction depends on the
particular problem and on the quality of the
heuristic.
46
A* search: Minimizing the total
estimated solution cost
• 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)
• Since 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 n to the goal,
– we have f (n )= estimated cost of the cheapest solution
through n.
• The algorithm is identical to uniform cost- search
except that A* uses g + h instead of g.
47
Example
48
49
50
51
Performance of A*
• A* is optimal and complete.
• Conditions for optimality
– Admissibility (if we apply A* using THREE-
SEARCH strategy)
• The first condition we require for optimality is that h(n)
be an admissible heuristic.
• 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. 52
Count…
– Consistency (if we apply A* using GRAPH-
SEARCH strategy )
• 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’:
h(n)≤c(n,a,n’)+h(n’)
53
Memory bounded heuristic Search
54
55
56
Performance of Recursive best-first search (RBFS)
I
THANK YOU!!!
58