Artificial Intelligence
Artificial Intelligence
1
Artificial Intelligence
UNIT II
Topics to be State Space Search and
Covered. Heuristic Search
-Research. Techniques:
-state space search. Defining problems as State
-Defineing a Problem of Space search,Production
state space search. systems and characteristics,
-Formalizing Problems as Hill Climberg first and depth
State Space Search. first search, Best first search.
-classification of search
algorithms.
-BFS,DFS Problems & solns
-BFS,DFS comarisions-BFS,DFS
algorithms
production system & chars.
Hill claimberg
First Best search
A* algorithm
What is Search?
-Search : it is the core component of many intelligent
processes.
-Search is the systematic examination of states to find
path from the start(root) state to the goal state.
-Many traditional search algorithms are used in Al
applications.
-For complex problems, the traditional algorithms are
unable to find the solution within some practical time &
space limits.
-Consequently, many special techniques are developed;
using heuristic functions.
Uninformed search (blind search) — Also called blind,
exhaustive or brute-force Search.
uses no information about the problem to guide the
Fig: tree search/
Blind search/
un informed search
State Space Search
DFS:
S,A,B,D
E,C,G
=S,A,B,D,E,C,G
Bredth First
Search(BFS):
1,2,5,4
2,7,6,9,3
=1,2,5,4,7,6,9,3
Explore vertex
Depth First
Search(DFS):
1,2,3
9,6,7,4,5
=1,2,3,9,6,7,4,5
once starts explore
until ends.
Problem:
BFS,DFS Techniques.
BFS steps:
-to find the path betn unknown
initial to Goal state by BFS we
need the following..
i)data stucture to store
ii)Generate the sequence
iii)draw the BFS state diagram.
1 4 2 3 8 5 7 10 9 6
Assignment :generate BFS,DFS
structure
BFS
8-pixel
fuzzle
problem
LURB
DFS:
steps:
-to find the path betn
unknown initial to Goal
state by DFS we need the
following..
i)stack to store
ii)Generate the
sequence ,which gives us
start to goal states.
iii)draw the DFS state
diagram.
sequence:1,4 etc..
DFS valid sequence:
1,4,3,10,9,2,8,7,5,
6.
like wise ,we will
get many more by
assuming initial
state differently.
Water Jug Problem is a puzzle where two jugs with
different capacities are used to measure a specific
amount of water, using operations like filling,
emptying, and pouring water between the jugs.
Jug 1 Jug 2
analysis
(4 lt cacity) (3 lts capacity)
3
Jug 1 Jug 2
(3 lt (5 lts analysis
cacity) capacity)
1 4 2 3 8 5 7 10 9 6
3404/05/2025
Input: START and GOAL states
/* both OPEN and CLOSED are used as QUEUE data structure
Local variables: OPEN [], CLOSED[], STATE-X, SUCCs, FOUND, EMPTY
Output: YES, or NO
BFS(S):
append(OPEN,START) /* open stack start with first node */
Dr KRB
IF STAE-X = GOAL THEN FOUND= YES
/* if current state-x is goal,then found yes is Goal/
append(OPEN,SUCCs)
//generate all neighbors of the STATE-X If and only if neighbors not in
OPEN ,CLOSED 34
End While
return FOUND.
DFS valid sequence:
1,4,3,10,9,2,8,7,5,
6.
like wise ,we will
get many more by
assuming initial
state differently.
State Space Representation for
water jug
3604/05/2025
problem
Initial State
⮩ We will represent a state of the problem as a
tuple (x, y).
Dr KRB
⮩ Here the initial state is (0, 0).
The goal state is (2, n) for any value of n. 36
37
3804/05/2025
large class of problems.
Dr KRB
3. Requirement of solution: “is Solution is absolute
or relative?
4. Can Solution steps be Ignored? 38
5. Is the problem universe predictable?
Water Jug problem DFS Prolog code:
% Define the capacity of each jug (0,0)
capacity(5, 3).
{1}
% Define the goal state
3904/05/2025
goal(4, _). (5,0)
goal(_, 4). {3}
{2}
% Define the possible moves
move((X, Y), (5, Y)) :- capacity(5, _ ), X < 5. % Fill Jug X (5,3)
move((X, Y), (X, 3)) :- capacity( _, 3), Y < 3. % Fill Jug Y
x {2}
Dr KRB
state is reached
{5}
write('Solution: '), write((X, Y)), nl, write(Visited), nl. {1,2,4}
solve(X, Y, Visited) :- move((X, Y), (X1, Y1), (1,0)
% Apply a move
x {3}
{1,2}
\+ member((X1, Y1), Visited), % Ensure the state has not been
visited x (1,3) 39
write(Visited), nl, {1,2,4}
{5}
solve(X1, Y1, [(X1, Y1) | Visited]). % Recursively search for a
solution
x (4,0) Goal State
% Initiate the solution search from the initial state
JUG J1(5 lts) JUG J2 (3 Lts) capacity of Jugs
4104/05/2025
[(0,0)]
[(5,0), (0,0)]
[(5,3), (5,0), (0,0)]
[(0,3), (5,3), (5,0), (0,0)]
[(3,0), (0,3), (5,3), (5,0), (0,0)]
Solution: 4,0
Dr KRB
[(4,0), (1,3), (1,0), (0,1), (5,1), (3,3), (3,0), (0,3), (5,3), (5,0), (0,0)]
true
41
Water Jug problem using BFS
42