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

U 2

This document covers the concepts of state space search and heuristic search techniques in artificial intelligence. It defines key components of state space search, including initial and goal states, operators, and paths, and discusses various search algorithms such as Breadth-First Search (BFS) and Depth-First Search (DFS). Additionally, it includes practical examples like the water jug problem to illustrate the application of these search strategies.

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 PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views42 pages

U 2

This document covers the concepts of state space search and heuristic search techniques in artificial intelligence. It defines key components of state space search, including initial and goal states, operators, and paths, and discusses various search algorithms such as Breadth-First Search (BFS) and Depth-First Search (DFS). Additionally, it includes practical examples like the water jug problem to illustrate the application of these search strategies.

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 PDF, TXT or read online on Scribd
You are on page 1/ 42

Artificial Intelligence UNIT 2.

1
UNIT II
Topics to be Covered. State Space Search and
-Research. Heuristic Search
-state space search. Techniques:
-Defineing a Problem of Defining problems as State
state space search. Space search,Production
-Formalizing Problems as systems and characteristics,
State Space Search. Hill Climberg first and depth
-classification of search first search, Best first search.
algorithms.
-BFS,DFS Problems & solns
-BFS,DFS comarisions-BFS,DFS
algorithms
production system & chars.
Hill claimberg
First Best search
A* algorithm
2
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
search . therefore may not be very efficient. 3
Fig: tree search/
Blind search/
un informed search 4
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.
- This approach can be used to solve a variety of
-AI issues, including....
SSS:
pathfinding, set of all possible
solving puzzles, states in a space to
reac goal in a
playing games, and more. shortcut.

5
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. 6
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. 7
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. 8
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.
9
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.

10
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
11
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.

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

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

14
classification of search algorithms

15
Classification of search Algorithms

16
17

17
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

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

19
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 finishes all


states.
sequence:1,4,2......
20
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

21
Assignment :generate BFS,DFS structure

22
BFS
8-pixel fuzzle
problem

LURB

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

1,4,2,3,8,7,5,9,10,6

24
DFS valid sequence:
1,4,3,10,9,2,8,7,5,6.

25
26
27
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 28
29
Jug 1 Jug 2
analysis
(3 lt cacity) (5 lts 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 30
Draw the state diagram for BFS & DFS
J1 J2
0 0
3 0

3 5

0 5

3 2

0 2

2 0

2 5

3 4
31
Jug 1 Jug 2
analysis
(3 lt cacity) (5 lts 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

33
Un-Informed/Blind Search :
• Breadth First Search(BFS):
Algorithm BFS:
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 */
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 */
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

End While 34
return FOUND.

34
DFS valid sequence:
1,4,3,10,9,2,8,7,5,6.

35
State Space Representation for
water jug problem

⮩ We will represent a state of the problem as a


tuple (x, y).
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.
⮩ 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


36
Production Rules

37

37
Problem characteristics
Heuristic search is a very general method applicable to a 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.

v Decomposability of a problem
1. Role of Knowledge:
2. Consistency of a KB “Knowledge Base” used in solution:
3. Requirement of solution: “is Solution is absolute or
relative?
4. Can Solution steps be Ignored?
5. Is the problem universe predictable? 38

38
Water Jug problem DFS Prolog code:
% Define the capacity of each jug
(0,0)
capacity(5, 3).
{1}
% Define the goal state
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)
x
move((X, Y), (X, 3)) :- capacity( _, 3), Y < 3. % Fill Jug Y
{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}
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 Jug Y to Jug X x (3,0)
move((X, Y), (0, Y1)) :- X + Y < 3, Y1 is X + Y. % Pour Jug X to Jug Y {3}
move((X, Y), (X1, 0)) :- X + Y < 4, X1 is X + Y. % Pour Jug Y to Jug X
% Define the depth-first search algorithm
(3,3)
solve(X, Y, Visited) :- goal(X, Y), % Check if the goal state is reached {1,2,4} {7}
write('Solution: '), write((X, Y)), nl, write(Visited), nl. x (5,1)
solve(X, Y, Visited) :- move((X, Y), (X1, Y1), {2}
% Apply a move (0,1)
\+ member((X1, Y1), Visited), % Ensure the state has not been visited {5}
write(Visited), nl,
{1,2,4}
solve(X1, Y1, [(X1, Y1) | Visited]). % Recursively search for a solution x (1,0)
% Initiate the solution search from the initial state {1,2} {3}
solve :- x 39
(1,3) 39
capacity(XCap, YCap), {1,2,4}
solve(0, 0, [(0, 0)]. {5}

x (4,0) Goal 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 4
0
OUTPUT:
[(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)]
[(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
[(4,0), (1,3), (1,0), (0,1), (5,1), (3,3), (3,0), (0,3), (5,3), (5,0), (0,0)]
true

41

41
Water Jug problem using BFS

42

42

You might also like