0% found this document useful (0 votes)
18 views42 pages

Artificial Intelligence

The document covers the fundamentals of Artificial Intelligence, focusing on state space search and heuristic search techniques. It defines search as a systematic examination of states to find a path from an initial state to a goal state, detailing various search algorithms like BFS and DFS. Additionally, it discusses the components of state space search, formalizing problems, and the application of heuristic methods in solving complex problems.

Uploaded by

datascience2427
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views42 pages

Artificial Intelligence

The document covers the fundamentals of Artificial Intelligence, focusing on state space search and heuristic search techniques. It defines search as a systematic examination of states to find a path from an initial state to a goal state, detailing various search algorithms like BFS and DFS. Additionally, it discusses the components of state space search, formalizing problems, and the application of heuristic methods in solving complex problems.

Uploaded by

datascience2427
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 42

UNIT 2.

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

-set of all possible states in space


it is representation of a
system
-its decision making & problem
solving methode.
-uses short cuts / calculated guess to
provide enough solutions.
SSS:
- This approach can be used to solve a
set of all
variety of -AI issues, including....possible
states in a
pathfinding, space to reac
goal in a
solving puzzles, shortcut.
case:1
h(x,y)=min(x,y) =>h(10,50)=min(10,50)=10;
now path decided by decision making for the
agent to travel.
case:2
consider new path 0-20-10-goal :30.
it may happan practically,may miss shotest path.
state space search may not gives optimizes solution.
Define problem as State
Space Search
A State Space essentially consists
of a set of nodes representing each
state of the problem, arcs between
representing the legal moves from
one state to another,
Initial state and a Goal state:
Search is the process of
considering various possible
sequences of operators applied to
the Initial State, and finding
sequence which ends in a goal
state.
The search problem is to find a
sequence of actions which
transitions the agent from the
Initial state to a Goal state.
Components of State Space Search

A problem can be represented in terms of the following key


components:
a. State Space
- The set of all possible configurations (states) that the system
can achieve.
- A state represents a unique situation or condition in the
problem domain.
b. Initial State
- The starting point of the problem. It defines the configuration
at the beginning of the search.
c. Goal State(s)
- One or more desired states that satisfy the problem's solution
requirements.
d. Operators
- Actions or transitions that move the system from one state to
another.
- These can be physical actions, logical transformations, or any
operation relevant to the problem.
e. Path
- A sequence of states connected by operators leading from the
initial state to a goal state.
f. Cost (optional)
- If applicable, each transition (operator) may have an associated
cost, and the goal may be to find the least-cost path.
g. An Agent — It is a program that makes decision and takes action
to change the state so that the agent can move to the new state.
h.Task/Plan — To make sequence of moves/actions that makes
agent to get a desire goal state. This is also called as solution plan.
A search problem,
represented by sequence of actions of

4-tuple {S. so, A, G} is called a


Solution Plan.
S- Full set of states in space( here 23)
S0 -initial state.
A-Si to Sj
i.e set of operations/transitions from
i to j state to reach goal.
its also represented as P={A0….An}
G- Final Goal state/states always G⊆S
The Solution Plan is a path from the
Initial state to a Goal state.

tuple :is an ordered sequence of values


tuple :is an ordered sequence of values
The Solution Plan is a path from the Initial state to a Goal state.
A plan P is a sequence of actions, P = {A0, A1, … , AN} which leads to
traversing a number of states {s0, s1, … , sN+1 ∈ G}.
A sequence of states is called a Path.

The cost of a path is a positive number. The path cost is computed


by taking, the sum of the costs of each action.
let A-B = 5 ;B-E = 3
So the path cost from A to E, A-B-E, is 5+3 = 8.
Goal Directed Agent/Single Agent Search An agent is software
which does some specific action to achieve goal.
A Goal Directed Agent aims to achieve certain goals.
An agent tries to reach to the goal using some actions.
Each state is an abstract representation of the agent's environment
and that abstraction denotes a configuration of the agent.
Formalizing Problems as State Space Search

To define a problem formally:


i. Identify the states: Clearly define what a state looks like.
ii. Determine the initial state: Specify where the search
begins.
iii. Define the goal condition: What makes a state a "goal"?
iv. Describe the operators: List possible actions or
transitions.
v. Evaluate paths and costs (if relevant): Specify any
metrics for comparing solutions.
Search Strategies

Once the state space is defined, search algorithms are employed to


explore it.
Common strategies include:

- Uninformed Search: Blindly explores the space


(ex: Breadth-First Search, Depth-First Search).

- Informed Search: Uses heuristics to guide the search


(ex: A*, Greedy Search).
classification of search
algorithms
Classification of search
Algorithms
17

Dr KRB II B.Tech(aiml) IIs MRECW 1704/05/2025


BFS:
S
A,B
C,D,G,H
E,F,I
K
=S,A,B,C,D,G,H,E,F,I,K

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.

let 1 initial and then start


explore the vertex.
sequence:1,4,2
append Queue:
1 4 2

now cencel vertex 1,start


explore 4
1 4 2

repeat the procedure until


sequence:1,4,2......
finishes all states.
BFS
Sequence:1,4,2,3,8,5,7,10,9,6

its valid sequence among many by


choosing start state differently.
Final Queue

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.

let 1 initial state and then


start .
put in sequence then store
in stack and then suspend
in state diagram.
explore the vertex 1 one
side only ie 4,suspend 1 and
add itsequence and stack.

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)

0,1,2,3 ..n AIM of the Problem


Get 2 lts
(no matter)
0 0 initially empty
4 0 Fill J1 with water
4 3 then fill jug J2 with water
0 3 empty the J1
3 0 shift J2 to J1 all water
3 3 again fill J2 full
4 2 fill J1 from J2 by pouring until full.
0 2 empty J1
2 0 shift J2 to J1
Jug 1 Jug 2
(3 lt (5 lts analysis
cacity) capacity)

Get 3 lts 4 lts


AIM of the Problem
0 0 initially empty
3 0 fill J1
3 5 fill jug 2 with water
0 5 empty J1
3 2 shift J2 to J1 all water
0 2 empty J1
2 0 shift J1 from J2
2 5 fill J2
3 4 shift J2 to J1 until full
Draw the state diagram for BFS
& DFS J1 J2
0 0
0
3
5
3
5
0
2
3
2
0
0
2
5
2

3
Jug 1 Jug 2
(3 lt (5 lts analysis
cacity) capacity)

Get 3 lts 4 lts AIM of the Problem


0 0 initially empty
3 0 fill J1
3 5 fill jug 2 with water
0 5 empty J1
3 2 shift J2 to J1 all water
0 2 empty J1
2 0 shift J1 from J2
2 5 fill J2
3 4 shift J2 to J1 until full
BFS
Sequence:1,4,2,3,8,5,7,10,9,6

its valid sequence among many by


choosing start state differently.
Final Queue

1 4 2 3 8 5 7 10 9 6

BFS algorithm needs: start,goal states


for Conn: open ,action close,queue for data storage
open-not a goal(action..fwd)-until found-create a loop.
open-may be goal-found-success.
break the loop.
return-found
Un-Informed/Blind Search :
• Breadth First Search(BFS):
Algorithm BFS:

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 */

II B.Tech(aiml) IIs MRECW


CLOSED = [ ] /* closed nothing */
FOUND = NO /* goal found no */
FOUND = NO /* goal found no */
While( OPEN != EMPTY and FOUND = YES)
/*to open=nothing avilable & goal found */
STATE-X = remove(OPEN) /*remove open from current state */

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).

II B.Tech(aiml) IIs MRECW


where x represents the amount of water in the
4-gallon jug and
y represents the amount of water in the 3-
gallon jug.
⮩ Note that 0 ≤ x ≤ 4, and 0 ≤ y ≤ 3.

Dr KRB
⮩ Here the initial state is (0, 0).
The goal state is (2, n) for any value of n. 36

tuple : an ordered sequence of


values
Production Rules

37

Dr KRB II B.Tech(aiml) IIs MRECW 3704/05/2025


Problem
characteristics
Heuristic search is a very general method applicable to a

3804/05/2025
large class of problems.

In order to choose the most appropriate method for a


particular problem it is necessary to analyze the problem
along several key dimensions.

II B.Tech(aiml) IIs MRECW


 Decomposability of a problem
1. Role of Knowledge:
2. Consistency of a KB “Knowledge Base” used in
solution:

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}

move((X, Y), (0, Y)) :- X > 0. % Empty Jug X (0,3)


move((X, Y), (X, 0)) :- Y > 0. % Empty Jug Y {1,4} {5}

II B.Tech(aiml) IIs MRECW


move((X, Y), (X1, 3)) :- X + Y >= 3, X1 is X - (3 - Y). % Pour
Jug X to Jug Y
move((X, Y), (5, Y1)) :- X + Y >= 5, Y1 is Y - (5 - X). % Pour x (3,0)
{3}
Jug Y to Jug X
move((X, Y), (0, Y1)) :- X + Y < 3, Y1 is X + Y. % Pour Jug X to (3,3)
Jug Y {7}
{1,2,4}
move((X, Y), (X1, 0)) :- X + Y < 4, X1 is X + Y. % Pour Jug Y to
Jug X (5,1)
% Define the depth-first search algorithm
x {2}
solve(X, Y, Visited) :- goal(X, Y), % Check if the goal (0,1)

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

4 lts 0 lts or any AIM


0 0 Empty jugs J1,J2
5 0 Fill J1
5 3 Fill J2
0 3 Empty J1
3 0 shift J2 to J1
3 3 fill J2
5 1 shift J2 to J1
0 1 Empty J1
1 0 J2 to J1
1 3 fill J2
4 0 shift J2 to J1
OUTPUT:

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)]

II B.Tech(aiml) IIs MRECW


[(3,3), (3,0), (0,3), (5,3), (5,0), (0,0)]
[(5,1), (3,3), (3,0), (0,3), (5,3), (5,0), (0,0)]
[(0,1), (5,1), (3,3), (3,0), (0,3), (5,3), (5,0), (0,0)]
[(1,0), (0,1), (5,1), (3,3), (3,0), (0,3), (5,3), (5,0), (0,0)]
[(1,3), (1,0), (0,1), (5,1), (3,3), (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

Dr KRB II B.Tech(aiml) IIs MRECW 4204/05/2025

You might also like