You are on page 1of 32

TAI2151 – ARTIFICIAL INTELLIGENCE

FUNDAMENTALS

LECTURE 5 – SOLVING PROBLEMS


BY SEARCHING
(INFORMED SEARCHES)
PART 1

Solving Problems By Searching – Informed Searches


LECTURE OUTLINE

• Part 1: Best First Search


• Greedy search
• A* search
• Part 2: Heuristic functions

Solving Problems By Searching – Informed Searches


INFORMED SEARCH
• Ideally, we want AI to know the knowledge and draw conclusion
• Assume that you want to travel from MMU Melaka to MMU Cyberjaya

Problem appear, how to solve it?


• You do not know the exact route
• In the reality,
• you can use non highway road to get to the destination
• You can choose Putrajaya/Cyberjaya exit
• human
• For You canbeing,
choose
theKajang exit be:
best could
•• You
No can choose(minimum
toll please USJ exit cost)
• But• which is the
Shortest bestplease
path route?(minimum distant)
• Uninformed search, will not tell you all this, the main goal in
uninformed search algorithm is to find the path between the
departure location and the arrival location.

Solving Problems By Searching – Informed Searches


INFORMED SEARCH
• Search strategy that uses problem
specific knowledge beyond the
definition of the problem itself
• To fine a goal with less search
space (that is informed)
For e.g.:
• Problem: We want to find the path from MMU Melaka to MMU
Cyberjaya
• Can
• We find solutions
inform Google map that: I want more efficiently
the shortest path
• It just search the shortest and return the result and need not to
search all the available path between MMU Melaka and MMU
Cyberjaya

Solving Problems By Searching – Informed Searches


INFORMED VS UNINFORMED SEARCH

• Uninformed search:
• Use only available information in the problem
• For e.g.:
• From City A to D: look only the available path from A to D

• Informed search:
• Use knowledge specific to a particular problem
• Interpret the problem and available information
• Involve reasoning
• For e.g.:
• From City A to D: getting the shortest path from A to D, is better than the longest path from A to
D; or find the path with least traffic jam

Solving Problems By Searching – Informed Searches


UNINFORMED SEARCH
Depth First Search (Uninformed Serach)
Start Goal

Solving Problems By Searching – Informed Searches


PROBLEM: FINDING A MINIMUM COST
PATH
• Previously we wanted an arbitrary path to a goal.
• Now, we want the minimum cost path to a goal G
• Cost of a path = sum of individual transitions along path
• Examples of path-cost:
• Navigation
• path-cost g(n) = distance to node (n) from start node in
miles
• minimum => minimum time, least fuel, least distance

• 8-Puzzle
• path-cost = number of pieces moved
• minimum => least time to solve the puzzle
Solving Problems By Searching – Informed Searches
PATH COST
Start Goal
16 15 14 13 12 11 10 9 6 5 4 3 2 1
12 1
13 11 2
19 18 17 16 15 14 13 12 3
13 4
17 16 15 14 13 12 11 10 9 8 7 6 5
18 16
19 17
20 18
21 19

Solving Problems By Searching – Informed Searches


TERMINOLOGY
AI in Google Map

• Agent: AI or someone whoWhat tryis the initial


tostates
and goal solve in a the
problem map?

• States: configuration of the agent in its


environment.
Initial state: all How about if we have a Tic Tac
empty Toe now? What is the agent?
• Initial state: initial startingWhatstate
is the initial state and
Few goalgoal state?
state: either A win,
• Goal state: solutionorstate
B win or fair for both

Solving Problems By Searching – Informed Searches


TERMINOLOGY Current state: MMU Melaka, so must
take action to move
State 1: car park in MMU Melaka
• Operators/Actions:State
a kind
2: the Tof (movement)
junction of the car parkthat
make within a stateand
(choices
so on that can be made
Action (State 1): move from car park
within a state) and reach State 2

• Goal test: way to determine whether a given state


Goal test will test whether state 2 is
is a goal state the destination. If it is not, then
continue.
• A machine needs some way to encode whether a
state happens toPath
becost in athe
in is mapgoal
will letstate
you know
the distant from a state to a state.
• Path Cost: numerical
How cost associated
about Tic Tac Toe? with a given
How about the path cost? Number of
path steps to win the game

Solving Problems By Searching – Informed Searches


TERMINOLOGY
• Transition Model: returns the state resulting from
performing action a in state s
• State space: the set of all states reachable from the
initial state by any sequence of actions
I have reached the T
junction (current state). If I The state space in a map,
turn left (action), it will give can be presented by using a
me a state (correct, so directed graph with node
continue). If I turn right, it and edges
will give me a state too
(wrong, make a U turn).

Solving Problems By Searching – Informed Searches


INFORMED SEARCHES

 Approach: Best-First Search


* Greedy Search
* A* Search

 Heuristic Functions
* Designing a Heuristic Function

Solving Problems By Searching – Informed Searches


BEST FIRST SEARCH

• A search algorithm that expands the node (from one state


to another state) that is closest to the goal
• If we do not know which is the closest to the goal, then we
use a heuristic function to make estimation (we guess, but
guess with mathematics, i.e. probability and statistics logic
rules & facts)

Solving Problems By Searching – Informed Searches


Informed search strategy uses problem-specific knowledge

Solving Problems By Searching – Informed Searches


GREEDY SEARCHES

 Search algorithm: expands node that is closest


to the goal

 Estimate through heuristic function (a function


that calculates an approximate cost (ranks
alternatives) in search algorithm at each
branching step based on available information
to decide which branch to follow)

 Since it is approximate, so not necessary it will


be the best solution (most optimize)

Solving Problems By Searching – Informed Searches


Heuristic function: straight line
distance from goal
GREEDY SEARCH: THE CONCEPT
10 or 12?
Start Goal
16 15 14 13 12 11 10 9 6 5 4 3 2 1
12 1
13 11 1113 or
or 15?
13?
15?
2
13
19 18 17 16 15 14 13 12 3
13 4
17 16 15 14 13 12 11 10 9 8 7 6 5
18 16
19 17
20 18
21 19

Solving Problems By Searching – Informed Searches


Minimize estimated cost to reach a goal: Greedy search

Solving Problems By Searching – Informed Searches


Map of Romania with road distances in km, and straight-line distances to Bucharest.

Minimize estimated cost to reach a goal: Greedy Search

Solving Problems By Searching – Informed Searches


GREEDY SEARCH - EXAMPLE

Which city has the


most minimum cost
to Bucharest?

Solving Problems By Searching – Informed Searches


GREEDY SEARCH – EXAMPLE (CONT.)

Solving Problems By Searching – Informed Searches


GREEDY SEARCH – EXAMPLE (CONT.)

Arad  Sibiu  Fagaras  Bucharest : not optimal (140 + 99 +211 = 450)


( 32 kilometer longer than Arad  Sibiu  Rimnicu  Pitesti  Bucharest): Optimal
(140 + 80 + 97 + 101 = 418)

Solving Problems By Searching – Informed Searches


NOT OPTIMAL

Stuck in loop: NOT COMPLETE

Solving Problems By Searching – Informed Searches


PROPERTIES OF GREEDY SEARCH
• Complete: No:
• Fails in infinite-depth spaces -- example
• Spaces with loops (e.g. going from Lasi to Oradea)
 Complete in finite spaces with repeated state
checking
No - optimal path goes through Pitesti.
• Optimal: O(bm): like depth first, but a good heuristic
• Time: function gives dramatic improvement on
average

• Space: O(bm): Potentially keeps all nodes in memory


Let b: Branching factor
m: Maximum Depth

Solving Problems By Searching – Informed Searches


GREEDY SEARCH

• Some problems are unsolved


• Underestimate the true cost (the cost
in reality)

Solving Problems By Searching – Informed Searches


A*- a special Best-first search
Improved the heuristic function
by adding in another function

• Goal: find a minimum total cost path


• Notation:
– g(n) = cost of current path from start to node n in the search tree.
– h(n) = estimate of the cheapest cost of a path from n to a goal.
– evaluation function: f = g + h

Solving Problems By Searching – Informed Searches


MINIMIZING THE TOTAL PATH COST: A*
IDEA

Solving Problems By Searching – Informed Searches


Admissible Heuristics
• A* search uses an admissible (never over estimate, get us the
optimal solution) heuristic in which
h(n)  h*(n)
where h*(n) is the TRUE cost from n.

• h(n) is a consistent underestimate of the true cost

• For example, hSLD(n) never overestimates the actual road


distance.
Remember triangle inequality:
two sides of a triangle cannot add up to less than the third side.

Solving Problems By Searching – Informed Searches


A* Search

Straight-line distance is admissible because the shortest


path between any two points is a straight line.

Solving Problems By Searching – Informed Searches


EXAMPLE – CONT.

Solving Problems By Searching – Informed Searches


EXAMPLE – CONT.

Solving Problems By Searching – Informed Searches


EXAMPLE – FINALLY…

Solving Problems By Searching – Informed Searches


PROPERTIES OF A*

• Complete: Yes, unless there are infinitely many


nodes with f  f(G)
• Optimal: Yes
• Time: Exponential with path length
• Space: Potentially keeps all nodes in memory (runs
out of space before it runs out of time)
Note, A* is also optimally efficient for
a given heuristic: That is, no other
optimal search algorithm is guaranteed
to open fewer nodes. Let b: Branching factor
m: Maximum Depth
Solving Problems By Searching – Informed Searches

You might also like