Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 55

1 Search

 The need for search


 Uninformed search
 Informed search
 Games and adversarial search
2 Search

The need for search:


 Clear differentiation between the AI search and the classical
search you perform over the internet using a search engine
Search examples:
 I lost my car keys (problem), I tried to find them (solution) by
searching the last visited places
 I planned a trip to Leeds (problem), it requires to search the map
for a suitable route and schedule an itinerary for when I got
there (solution)
 Finding the best sequence of tasks and the days and times of my
upcoming week (problem), I search through a whole set of
possible schemes by trial and error until I arrive at the one that
seems best (solution)
3 Search

We want:
 To automatically solve a problem

We need:
 A representation of the problem
 Algorithms that use some strategy to solve the problem defined in
that representation
4 Search

Common characteristics of search activities:


 Goals

 Point at which they start

 Many possible paths to follow

 Other influencing factors


5 Search

We can characterize the kind of search that takes place in


Symbolic AI as follows:

 State space: a problem is divided into a set of resolution


steps from the initial state to the goal state
 Searching in symbolic AI is a process of attempting to find a
goal state from the initial state
 It needs to go through a large number of intermediate states
before it reaches the goal state (for large problems)
 The set of all possible states form the state space, also called
search space or problem space.
 Operators are required to progress form one state to
another state. It is a transformation function on a state
representation, which convert it into another state.
6 Search

A state is a representation of those elements in a given moment.


Two special states are defined:

– Initial state (starting point)


– Final state (goal state)
7 Search

 The state space is the set of all states reachable from


the initial state.
 It forms a graph (or map) in which the nodes are states
and the arcs between nodes are actions.
 A path in the state space is a sequence of states
connected by a sequence of actions.
 The solution of the problem is part of the map formed
by the state space.
8 Search

 A solution in the state space is a path from the initial


state to a goal state or, sometimes, just a goal state.
 Path/solution cost: function that assigns a numeric
cost to each path, the cost of applying the operators to
the states
 Solution quality is measured by the path cost
function, and an optimal solution has the lowest path
cost among all solutions.
 Solutions: any, an optimal one, all. Cost is important
depending on the problem and the type of solution
sought.
9 Search

The main components of the search space problem:


initial state, goal state, space state and operator
 Usually, there are a number of possible operators

that can be applied to any state.


 The goal state might not be reachable because of

the requirements (time, effort are too great)


 The goal state might not be reachable at all.

 The task might not be just to search a solution, but

to find the best solution among several


possibilities
10 Search
Example: Missionaries and cannibals
There are 3 missionaries, 3 cannibals, and 1 boat that can carry up
to two people on one side of a river.

 We need a purely symbolic representation of all the relevant facts


needed for a solution
 We can do this by denoting:
 By A and B the opposite banks of the river
 By m a missionary and by c a cannibal, and the boat by b
 The state of the picture can be denoted as follows:
 bankA(mmm,ccc,b)
 bankB()
11 Search

Goal: Move all the missionaries and cannibals across the


river.
Constraint: Missionaries can never be outnumbered by
cannibals on either side of river, or else the
missionaries are killed.
State: configuration of missionaries and cannibals and
boat on each side of river.
Operators: Move boat containing some set of occupants
across the river (in either direction) to the other side.
12 Search
Near side Far side
0 Initial setup: MMMCCC B -
1 Two cannibals cross over: MMMC B CC
2 One comes back: MMMCC B C
3 Two cannibals go over again: MMM B CCC
4 One comes back: MMMC B CC
5 Two missionaries cross: MC B MMCC
6 A missionary & cannibal return: MMCC B MC
7 Two missionaries cross again: CC B MMMC
8 A cannibal returns: CCC B MMM
9 Two cannibals cross: C B MMMCC
10 One returns: CC B MMMC
11 And brings over the third: - B MMMCCC
13 Search
The route planning: observations
14 Search

The route planning: observations


 There may be no direct path

 Looking for a better sequence of cities ?

 What do we mean by better ?

 Fitness: how good the solution is

 The solution with highest fitness will be the best

 It is not a problem of finding a route, but to find


the solution with maximum fitness (optimization)
 What about the cost ?

 Goal: minimize the cost and maximize the fitness.


15 Search

The missionaries and cannibals problem


presents different complications:
 Some states are not reachable from others:
 bankA(m,c,b)
 bankB(mm,cc,-)

And
 bankA(mm,cc,b)
 bankB(m,c,-)
16 Search

The state space:


 The state space of a particular problem includes the start
state, the goal state and all the possible intermediate

 State space for route planning


 Cyclic graph
17 Search

The state space: a part of it for the missionaries and


cannibals problem
18 Search

The state space: a part of it for the missionaries and


cannibals problem
19
Search and solution
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.
20
Solution via search example
21
Measuring search performance

Completeness: Is the algorithm guaranteed to


find a solution when there is one?
Optimality: Does the strategy find the optimal
solution?
Time complexity: How long does it take to find
a solution?
Space complexity: How much memory is
needed to perform the search?
22
Search

Basic idea:
Exploration of state space by generating successors of already-
explored states
(a.k.a.~expanding states).
Every states is evaluated: is it a goal state?
23 Example: how to go from Arad to
Bucharest?
24 Example: how to go from Arad to
Bucharest?
25 Example: how to go from Arad to
Bucharest?
26
Search broad categories
• Uninformed search (Blind search):
 The term means that the strategies have no additional information
about states beyond that provided in the problem definition.
 All they can do is generate successors and distinguish a goal state
from a non-goal state.

• Informed search:
 Strategies that know whether one non-goal state is “more promising”
than another are called informed search or heuristic
HEURISTIC SEARCH.
27 Search

Components of the Uninformed search:


 Agenda a data structure that holds all the states that we

want to explore
 Expanding the state is the process of applying operators on

this state to generate new states


 The agenda will contain paths from the start state to the

current state.
 All search strategies are distinguished by the order in which

nodes are expanded.


28
Uninformed search strategies
Uninformed strategies use only the
information available in the problem
definition.
♦ Breadth-first search
♦ Uniform-cost search
♦ Depth-first search
♦ Depth-limited search
♦ Iterative deepening search
29 Uninformed search
 Breadth-first search

is a FIFO queue, i.e., new successors go


at end
Expand shallowest unexpanded node
30
Breadth-first search
A
B,C
C,D,E
D,E,F,G,

Snapshot of the states in the
agenda across time

 Newly generated states are placed at the end


of the queue
31 Uniformed search
 Depth-first

 Expand the deepest unexpanded node


 Is implemented as LIFO queue
 put successors at front
32 Search complexity

Observations:
 Breadth-first has the advantage that it will always find the

route (if one exists) with the least number of intermediate


states, but at the expense of having to keep on the agenda
every path with this number of steps.
 if b is the branching factor and m is the number of links in the

path, the agenda needs to store bm paths, which is quite large.


(space complexity is exponential)
 Depth-first can be used to reduce the memory requirements

of search. (space complexity is linear)


 It explores one path at a time.
33 Uninformed Search

Techniques for taming uninformed search:


 Depth-limited search

 Iterative deepening (depth limited search with a small depth


limit, if no solution is found, we increase the depth limit)
34
Uninformed search
 Iterative deepening
35
Uninformed search
 Iterative deepening
36
Uninformed search
 Iterative deepening
37 Enhancing uniformed search

Techniques for taming uninformed search:


 Depth-limited search

 Iterative deepening (depth limited search with a small


depth limit, if no solution is found, we increase the depth
limit)
 Beam search is limiting the size of the agenda (keep only
the most promising candidates).
 Uniform-cost search: examine the shortest partial route
first, this means, keep the cost of all the paths on the
agenda as uniform as possible to prevent the search from
drawn into a long route while there are shorter routes to
be explored.
 Exercise 2.5 page 82.

 Computer exercise 2.5, 2.6 and 2.7


38 Uninformed search

 Uniform cost search

• Expand the cheapest unexpanded node


• priority queue ordered by path cost g(n)
• Equivalent to breadth-first search, if all step costs
are equal
39 Informed search

 one that uses problem-specific knowledge beyond the


definition of the problem itself -heuristic.
 can find solutions more efficiently than can
an uninformed strategy.
 Heuristic means a way to embed the knowledge we have in
our problem-solving system
 Extra information that allows us to complete a task
 This information is generally but not always true: “elephants
are bigger that people” !!
40 Informed search
 Best search first
 A node is selected for expansion based on an evaluation
function, f(n).
 The evaluation function is construed as a cost estimate, so
the node with the lowest evaluation is expanded first.
 The
implementation of best-first graph search is identical to that
for uniform-cost search except for the use of f instead of g to
order the priority queue.
 Given a heuristic function, we can use it to select the most
promising partials routes to the goal.
 Most best-first algorithms include as a component of f a
heuristic function, denoted h(n)
41
Best-first search

Idea: use an evaluation function f(n) for each node


f(n) provides an estimate for the total cost.
Expand the node n with smallest f(n).

Implementation
Order the nodes in increasing order of cost.
42
Best-first search

Cost can be represented as:


Straight line distance to destination
43
Informed search
 Best search first

Heuristic function:
h(n) = estimated cost of the cheapest path from the
state at node n to a goal state.
(Notice that h(n) takes a node as input, but, unlike
g(n), it depends only on the state at that node)
For example, in Romania, one might estimate the
cost of the cheapest path from Arad to Bucharest
via the straight-line distance from Arad to
Bucharest.
44 Best-first search example –with
constrains
Having the following grid and the depicted agent at location (x=6, y=1) and a target
object located at (x=1,y=4). Assume that the agent can just go forward, backward,
upward, downward, using best first search write the content of the search agenda at
each time step until reaching the target showing the selected directions on the grid.
Assume Euclidian distance from the current location to the target location as the
heuristic value.     
45
Best-first search example
46
Best-first search example
47
Informed search –A*
• Idea: avoid expanding paths that are already
expensive
• Evaluation function f(n) = g(n) + h(n)
• g(n) = cost so far to reach n
• h(n) = estimated cost from n to goal
• f(n) = estimated total cost of path through n to
goal
• Best First search has f(n)=h(n)
• Uniform Cost search has f(n)=g(n)
48 How to go from Arad to Bucharest
using A* algorithm?
 Assume heuristic is the air distance,
specified: Town  Air Dist.
 Arad  366
 Bucharest  0
 Craiova  160
 Dobreta  242
 Eforie  161
 Fagaras  176
 Giurgiu  77
 Hirsova  151
 Iasi  226
 Lugoj  244
 Mehadia  241
 Neamt  234
 Oradea  380
 Pitesti  100
 Rimnicu Vilcea  193
 Sibiu  253
 Timisoara  329
 Urziceni  80
 Vaslui  199
 Zerind  374
49 How to go from Arad to Bucharest
using A* algorithm?

 Possibilities from Arad: Go to Zerind, Timisoara, or Sibiu?


 Take as heuristic the air distance plus cost to town:
 Zerind (374+75=449),
 Timisoara (329+118=447),
 or Sibiu (253+140=393)
 Most promising Sibiu, hence explore going to Sibiu.
50 How to go from Arad to Bucharest
using A* algorithm?

 Possibilities from Sibiu: Arad, Fagaras, Oradea, or


Rimnicu Vilcea?
 Take as heuristic the air distance plus cost to town:
 Arad (140+140+366=646),
 Fagaras (140+99+176=415),
 Oradea (140+151+380=671),
 or Rimnicu Vilcea (140+80+193=413)
 Overall most promising not expanded Rimnicu Vilcea,
hence explore going to Rimnicu Vilcea
51 How to go from Arad to Bucharest
using A* algorithm?
 Possibilities from Rimnicu Vilcea: Sibiu, Pitesti, or
Craiova?
 Take as heuristic the air distance plus cost to town:
 Sibiu (140+80+80+253=553),
 Pitesti (140+80+97+100=417),
 or Craiova (140+80+146+160=526)
 Overall most promising not expanded Fagaras,
 hence explore going to Fagaras (from Sibiu)
52 How to go from Arad to Bucharest
using A* algorithm?
 Possibilities from Fagaras: Sibiu, or Bucharest?
 Take as heuristic the air distance plus cost to town:
 Sibiu (140+99+99+253=591),
 or Bucharest (140+99+211+0=450)
 Overall most promising not expanded Pitesti,
 hence explore going to Pitesti (from Rimnicu Vilcea)
53 How to go from Arad to Bucharest
using A* algorithm?
 Possibilities from Pitesti: Rimnicu Vilcea, Craiova, or
Bucharest?
 Take as heuristic the air distance plus cost to town:
 Rimnicu Vilcea (140+80+97+97+193=607),
 Craiova (140+80+97+138+160=615) or
 Bucharest (140+80+97+101+0=418)
 Overall most promising go to Bucharest from Pitesti.
 Since there is no way to get on a shorter route to
Bucharest the last one is taken.
54
Given the following search graph, write the sequence of node numbers in the search agenda across the search life-time
and using A* search.

Node
Node Heuristic value
ID
1 446
2 364
3 408
4 264
5 0
6 271
7 402
8 255

Assume the following heuristic value per


node:
Assume distance between cities are as
mentioned on the links
Apply A* algorithm showing intermediate
values for the Agenda, g(n), h(n)
Source city is :C6
Destination city:C5
55

You might also like