0% found this document useful (0 votes)
16 views

Artificial Intelligence Unit 1

Artificial intelligence notes

Uploaded by

athifaparveez429
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)
16 views

Artificial Intelligence Unit 1

Artificial intelligence notes

Uploaded by

athifaparveez429
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/ 25

Unit 2

PROBLEM SOLVING BY SEARCHING

Introduction
To successfully design and implement search algorithms, a programmer must
beable to analyze and predict their behavior. Questions that need to be answered
include:

Is the problem solver guaranteed to find a solution?


Will the problem solver always terminate, or can it become caught in an infinite
loop?
When a solution is found, is it guaranteed to be optimal?
What is the complexity of the search process in terms of time usage? Memory
usage?
How can the interpreter most effectively reduce search complexity?
How can an interpreter be designed to most effectively utilize a representation
language?
The theory of statespace search is our primary tool for answering these questions.
By representing a problemn as a state space graph, we can use graph theory to analyze
the structure and complexity of both the problem and the search procedures that we
employ to solve it.
A graph consists of a set of nodes and a set of arcs or links connecting pairs of
nodes. In the state space model of problem solving, the nodes of a graphs are taken
to represent discrete states in a problem-solving process, such as the result of logical
inferences or the different configurations of agame board. The arcs of the graph
represent transactions between the states. These transactions correspond to logical
Interences or legal moves ofa game. In expert systems, for example, states describe
knowledge of a problem instances at some stage of a reasoning process. Expert
knowledge in the form of if.then rules, allows us to generate new information; the
act of applying a rule is represented as an arc between states.
24 Artificial Intelligence & ApPplications

Graph theory is our best toolfor reasoning about the structure ofobjects and the.
relations. The swiss mathematician Leonhard Euler invented graph theory to sol
the "bridges of Konigsberg problem". The city of Konigsberg occupied both banl
andtwo islands of a river. The islands and the riverbanks were connected by seven
bridges, as indicated in below figure.

Figure : The city ofKonigsberg

Figure : Graph of the


The bridges of Konigsberg bridge system
crosses each bridgeKonigsberg
exactly
problem asks if there is a walk around the
once.
walk and doubtedthat it was Although the residents had failed to findcity that
a form of
graph theory, Eulerpossible, no one had proved its such a
shown in figure. The created an alternative
by the nodes ofa riverbanks (rbl and rb2)) and islands
impossibility.
representation for theDevising
graph; the bridges are (il and i2) are map, as
(b1,b2,..,b7). represented by labeled arcs betweendescribed
nodes
Alternatively,
calculus. we
The connect may represent the Konigsberg
two land masses are predicate corresponds to an arcbridge system using predicate
connect predicates, oneconnected
for each
by a
particular bridge.
of the graph,
Each asserting u
bridge
direction in which the bridge may be requiresS tW
Connect(i1,i2,b1) Connect((ii2l,,rib1,1,b1)b2)
Connect(rbl,il,b2) Connect crossed:
Problem Solving by Searching 25

Connect(rbl,i1,b3) Connect(il,rb1,b3)
Connect(rbl,i2,b4) Connect(i2,rb1,b4)
Connect(rb2,i1,b5) Connect(il,rb2,b5)
Connect(rb2,i1,b6) Connect(il,rb2,b6)
Connect(rb2,i2,b7) Connect(i2,rb2,b7)
A further predicate expression, connect(x,y,z)=connect(y,x,z), indicating that
any bridgecan be crossed in either direction.
In proving that the walk was impossible Euler focused on the degreeof the nodes
of the graph, observing that a node could be of either even or odd degree. An even
degree node has an even number of arcs joining it to the neighboring nodes. An odd
degree node has an odd number of arcs. With the exception of beginning and ending
nodes, the desired walk would have to leave each node exactly as often as it entered
it. Nodes of the odd degree could be used only as the beginning or ending of the
walk, because such nodes could be crossed only a certain number of times before
they proved to be a dead end. The traveler could not exit the node without using a
previously traveled arc.
Euler noted that unless a graph contained either exactly zero or two nodes of
odd degree, the walk was impossible. If there were two odd-degree nodes, the walk
could start at the first and end at the second; if there were no nodes ofodd degree, the
walk could begin and end at the same node. The walk isnot possible for the graphs
containing any other number of nodes of odd degree, as is the case of Konigsberg.
This problem is now called finding an Euler path through a graph.

PROBLEM SOLVINGAGENTS
The reflex agents are known as the simplest agents because they directly map
states into actions. Unfortunately, these agents fail to operate in an environment
where the mapping is too large to store and learn. Goal-based agent, on the other
hand, considers future actions and the desired outcomes. Here, we will discuss one
type of goal-based agent known as a problem-solving agent, which uses atomic
representation with no internal states visible to the problem-solving algorithms.

Problem-solving agent
The problem-solving agent perfoms precisely by defining problems and its
several solutions.

According to psychology, "a problem-solving refers to a state where


we wish to reach to a definite goal from a present state or condition."
Artincla inteltlgence & Applicaho
26

computer science, a problem-solving is a part of artil.


According to
a number of teehniques su
intelligence which encompassesproblem.
algorithms, heuristics to solve a
agent and foxue
Therefore, a problem-solving agent is agoal-driven
on satisfying the goal.
PROBLEM DEFINITION
four thíngs:
To build a system to solve a particular problem, we necd to do
(i) Define the problem precisely. This definition must include specification
the initial situation and also inal situations which constitute (i.e) acceptat
solution to the problem.
(ii) Analyze the problem (i.e) important features have an immense (i.c) huy
impact on the appropriateness of varioustechníqucs for solving the probler:
(ii)Isolate and represent the knowledge to solve the problem.
(iv)Choose the best problem - solving techniques and apply it to the particula
problem.
Steps performed by Problem-solving agent
Goal Formulation: It is the first and simplest step in
It organizes the steps/sequence required to formulate problem-solving
one goal out o
multiple goals as well as actions to achieve that goal. Goal formulatior
is based on the current situation and the
agent's performance measure
(discussed below).
Problem Formulation: It is the
which decides what actions should most important step of
be taken to achieve the problem-solving
There are following five components formulated goal
involved in problem formulation:
Initial State: It is the starting state or initial step
of the agent towards its goal.
Actions: It is the description of the possible
Transition Model: It describes what actions available to the agent.
each action does.
Goal Test: It determines if the
" Path cost: It given state is a goal state.
assigns numeric cost to each path that
a
problem solving agent selects a cost function, follows the goal. The
measure. Remember, an optimal which reflects its performance
the solutions. solution has the lowest path cost among a
Note: Initial state, actions, and
the problem
implicitly. transition model
of a problem istogether define the state-space o
reached from the initial State-space a set of all states which can b
forms a directed map or state followed by any sequence of actions.
graph where nodes are the The state-spact
states, links between the nodes
Problemn Solving by Searching 27

are actions, and the path is a sequence of states connected by the sequence of actions.
. Search: It identifies all the best possible sequence of actions to reach the goal
state from the current state. It takes a problem as an input and returns solution
as its output.
" Solution: It finds the best algorithm out of various algorithms,which may be
proven as the best optimal solution.
Execution: It executes the best optimalsolution from the searching algorithms
to reach the goal state from the current state.
State Space Representation of Problems
In thestate space representation ofa problem, the nodes of a graph correspond to
partial problem solution states and the arcs correspond to steps in a problem-solving
process. State space searchcharacterizes problem solving as the process of finding a
solution path from the start state to goal state.

DEFINITION

STATE SPACE SEARCH


A state space is represented by a four-tuple [N,S,A,GD], where:
N is the set of nodes or states of the graph. These correspond to the states in a
problem-solving process.
A is the set of arcs or links between nodes. These corresponds to the steps in a
problem-solving process.
S, a non empty subset ofN,contains the start state(s) of the problem.
GD, a nonempty subset of N, contains the goal state(s) of the problem.
These states in GD are described using either:
1. A measurable property of the states encountered in the search.
2. A property of the path developed in the search, for example, the transition
costs for the arcs of the path.
Asolution path is a path through this graph from a node is S to a node in GD.
A goal may describe a state, such as a winning boærd in tic-tac-toe or a goal
configuration in the 8-puzzle. Alternatively, a goal can describe some property of
the solution path itself. In the traveling sales problem, search terminates when the
"shortest path is found through all nodes of the graph.
Application.
Intelligence& Problem So
Artncial
games. Both
of.simple The stat
28
the state space the above definition,
exemplify type I in the probler
8-puzzle conditions of 2.
Tic-tac-toeand thc
demonstrate
termination description oftype to each of

these
examples problem, has a goal follows tha
salesperson
The traveling
Example 1: TIC-TAC-TOE the figure. Example
tic-tac-toe appears in
representation of In the
The state space spaces on
different p
that place
played.
###f###ft#E#

### # # # # # # # # #

## ###E # # # # # #
Figure : Portion of the state space for tic-tac-toe.
The start state is an empty board, and the termination of goal description is a
board state having three Xs in a row, column or diagonal (assuming that the goal is
a win for X). The path from the start to a goal state gives the
series of moves in a
winning game.
The states in the space are all the different
game can have. Of course, although there are configurations of Xs and Os that the
3 ways to arrange
A nut
nine spaces, most of them could never
occur in actual game, Arcs {blank, X, O} i m e
by legal moves of the game, are generated p
alternating
location. The state space is a graph rather between placing an X and O in an unuseo to provic
and deeper levels can be then a tree, as somne
in the state space, reached by different paths. Howeyer states on the thiro The
because the directed arcs of the there are no cycles around
undone. It is
No checkingimpossible to "go graph do not
for cycles in pathback up" the structure once a stateallow
a move tO 15-puzz
has been
property
search.
is called a generation necessary.
directed acyclic graph, isor DAG, and Aisgraph structure reache
with this Althe
common in state space right, pr
Spa much si
the defi
legal me
Problem Solving by Searching 29

The state space representation provides a means of determining the complexity of


the problem. In tic-tac-toe, there are ninefirst moves with eight possíble responses
to each of them, followed by seven possible responses to each of these, and so on. It
follows that 9x8x7x... or 9! Different paths can be generated.
Example 2: THE 8-PUZZLE
In the /5-puzzle of figure (a), 15 differently numbered tiles are fitted in to sixteen
spaces on a grid. One space is left blank so that tiles can bemoved around to form
different patterns. The goal is to find a series of moves of tiles into the blank space
that place the board in a goal configuration.Thís is a common gane that most of us
played.
1 2 4

12 13 14

11 15 6

10 9 8

15-puzzle
1 2 3

8 4

8-puzzle
Fig (a) : The 15-puzle and 8-puzzle
A number of interesting aspects of this game have made it useful to researchers
in problem solving. The state space is large enough to be interesting but is not
completely intractable. Game states are easy to represent. The game is rich enough
to provide a number of interesting heuristics.
The 8-puzzle is a 3 x 3 version of 15-puzzle in which eight tiles can be moved
around in nine spaces. Because it generates a smaller state space then the full
15-puzzle.
Although in the physical puzzle moves are made by moving tiles ("move the 7 tile
right,provided the blank is to the right of the tile" or move the 3 tile down"), itis
much simpler to think in terms of "moving the blank space" instead. This simplifies
the definition of move rules because there are eight tiles but only a single blank. The
legal mnoves are:
Artificial Intelligence
& Applicattons
Problem

30

blank up
Move the right’
Move the blankdown l
blank
Move the
blank left it does not move the blank
Move the make sure that
applicable at all times: for
must
In order to
apply a move, we
moves are not example,
the board.
Therefore, all four
corners only two moves are possible.
is in one of the
when the blank 8-puzzel, it is possible t
state and goal state for the couli
If we specify the beginningof theproblem-solving process (figure b). States The r
give a state space accounting
simple 3 x 3 array.
indicatin
be represented using a unlike tic-tac. the mile
8-puzzle is a graph, but
As with tic-tac-toe, the state spacetheforstate space is a particular state or board convenie
toe, cycles are possible. The GD of the search terminates. The path although
configuration. When this state is found on a path,
moves.
from the start to the goal is the desired series of The
A
possible
7 6 (Note th.
8
state. Th

1
Figur
3
and com
2 6 2 6 2 cities are
complex
7 4 A 7
1
1 where N
6
6 1 76 6
78 7
2 6 8 2 8 5 2 5 2

Fig (b) : State space of 8-puzzle


generated by moveblank" operations
Example 3: THE TRAVELLING
Supposea sales SALESPERSON
of the problem is to person has five cities to visit and then must
city, and then find the shortest path to the return home. The goa
returningto sales
the starting city. to person
problem.
Figure below givestravel,
an visiting eaci
instance of thi

Figure
31
Problem Solving by Searching

problem.
Figure: An instance of the traveling sales person
and each arc is labeled with a weight
The nodes of the graph represent cities, cost might be a representation of
indicating the cost of traveling that arc. This
cost of an air flight between two cities. For
the miles necessary in car travel or
in city A and will return there,
convenience, we assume the sales person lives (n-1) cities.
cities to
although this assumption reduces the problem of n
of 450 miles, is an example of a
The path [A,D,C,B,E,A, with associated cost
complete circuit with minimum cost.
possible circuit. The goal description requires a
(Note that the goaldescription is a property of the entire path, rather then of a single
definition of state space search).
state. This is a goal description of type 2 from the
paths may be generated
Figure below shows one way in which possible solution
next states are added until all
and conmpared. Beginning with node A, possiblegoal is the lowest-cost path. The
cities are included and the path returns home. The
problem is (N-1)!,
complexity of exhaustive search in the traveling salesperson
where N is the number of cities in the graph.

Figure :Search of the traveling salesperson problemn. Each arc is marked with
the total weight of all paths from the start node (4) to its endpoint.
direction.
two per
A Jefferson.
working
and Thomas consider
search successive on legal order. chain
subgoals
subgoals, whatwhat
generation,
parents, Some untilwhich
changing
Searchstate.
begins instance
Data-Driven
working As Data-driven the Strategies only isthe
An In 32
an moves conditions
of (we A
that along goal, This rules data-driven state
A[A,E,D,B,C,A], one closest
Thomas simple Jefferson."A th
example e moves alternative are with strategy
This hope!) towards
worked a rules until for in path
search through problem finds approach to or tun space
the ancestorspace produce the the for unvisited
assumptions and reasoning or(we mustlegal and to for
Jefferson
required of the rules search. it
used given may
a State be
forward back the
subgoals hope!) approach generates search, goal controlling
may
his solution of rule is moves Goal-Driven tried! at
lines effect a called be by be
from descendents. confirming new leading proceeds facts or a
city."
be that takes Search true th e searched Space cost
path was it sometimes from
from let searched isto works could is rules
a
a could fact
togoal-driven to path of The
of
the will
born us
Thomas search the from possible: search
path a the the a Search 375
Thomas "" that continues, use to by goal in "nearest
estimate
be or given produce facts that problem Search
data
back them. be generate two
would about strategy
denying leads moved applying called miles.
constructs
about Jefferson in of satisfies back
twdirect
o facts reasoning, of to to take directions:
Jefferson neighbor"
examine 250 the the tothe athe These
working to This
length directions, a goal, tothe more forward
and
linkage the can of goal; facts the
years size or goal,problem generate the rules method the Artficlal
statement have the conditions goal new a
would 10. starting although goal data.from path
goal-driven
problem. and or of
backward toset path
on ago; of between on chaining,
As the backward the that facts.facts of
condition. the is
the starting chains and according
through
figur, Intelligence
the
each th e this legal highly
examineorder space
if with problem. given
we complexity "I applies it become we This to
the am does
person Thomas backwardreasoning through goalwant produce moves the efficient,
assume
ofsearched with chaining. process data to
more a so problem
2° This new and the &
descendent" th e in to graph
has the and or ofa Applicatio
ancesto
states, of rules backwarc successiv determin: solve. continue new as ule
25 Jeffersot Thomas "T" finds goals, rules probls
exaet! in search. through focuses there: of
yeal eac facts solve <«
an' anc
Data-driventhrough 3. 2.
Goal-driven the thatchildren
tree. neonle Problem
2 1. 1. decision
Goal-driven Problem bothThus,
there
DENDRAL
knowledge program,ata-driven
organic There
to
anapproach. data
data system
problems All problem, case, axioms.
order Problem much more of
example, thusThereformulated.
theoremin A rend
use relevant a a goal directions per Solving
(such
or or goal
produce systematic a
are nostsearch goal-driven
only smallereffective are search solvers is family, to
search
compounds
the are attempt to data to or based have
an a provide as often search
rules those for the can a by
of facts of large hypothesis
be In
enormous large
PROSPECTOR is example, are then total is have
chemistry, the eliminate in
an proved.
fashion, a
suggested on yield back themoreSearching
and to appropriate
fit search
number data
and thus that search not
number increasing the been
find athis thepruning numbermathematics exponential from than
based given high-level eliminate uses are given structure
what mold ar e a number Many is written
number necessary wide can mnostconforming using
them would
the two
isexpert given knowledge of given if:
information of to help but the of
anon by range rules number diagnostic "T
children.
their potential minerals or problems branches must ofspace. of rules theorem of examine
example Dipmeter presenting in
interpretation. complexity.
using would
of system rules in the
the to guide
possible
formula, of be
used these that
of the
initial confirm
of
diagnostic In problem cach
of
goals, ar e data
acquired that branches,
to examine on If
of that programs, in ofthe conclusions a match systems problem
prover, we
a likely a which: the acquisition. mathematics produce
may of th e
this. particular collectionproblem desired or data- assume
structures. mass finds but System space. to order
For to deny tests by be goal-driven the
reasoning. be fewer
there making considerstatement
for andgoal-driven
the whichbe the applied a solved.
spectrographic any Interpretation
statement. goal given facts example,
or of an
molecular problem
structure of particular
analyze that of acan nodes. 340
However, are found particular problem In goals. average
organic interpret data to theorem of
potential nodes
medical
be a theorem goal-driven
to
only guide applied. the or
at and the Early the can Note,
instance. solver. of of
compound, a site) a
geological asking hypothesis. entire prover, problem goal approaches;
the data, few the diagnosis isselection diagnoses easily however, the only
Doctors
mass ways fit search In usuallyset search is familythree
and The the the this and 33
of for the be
examined.
Begin
first_search;
Function
breadth beenopenwhose of Breadth order there to
Closed1;
(Start];
Open
:= := progress We the are a 34
determines
Breadth-first tree/graph. A problem 3.
childrenimplement A,next are Breadth-First
considered; search Data-driven
first B, noFigure : little Itthese.few of
through level.
C, more to is
have search D, There
algorithm spectrographic
the A
search
guide dimaffiy cult
breadth-first E,states Graph Breadth-first
breadth-firstF, are and search be
order not the search known to
been state
algorithm G,explores
to for tw o must
Depth-First uses form data
of H, be
examined.the space. I,
Breadth-first
explored
possibilities
and
determine the
along initially a on
search J,
graph goal a
search. K, the knowledge
lines
Open, L, space Depth-first or
of at Search about compound
The using M, he a for the known hypothesis.
Closed lists
order lists,
N,tgiven
above in & e
thorder and the
O, Depth-first a search.order to allow
states P,
level-by-level possible
be
in constraints
records in open Q, level
figure In Artificial
which which
in true.
that R, DENDRAL
using
does which structure
and considersS, search
states
stateshave T, the states found
closed, U. the
been fashion.
algorithm to
DENDRAL,of Intelligence
that are examples
nodes are in a
renmoved the the eliminate
generated
haye to examined compound &
keep states Only of for
given atlon,Applico
alrea0) move the example all
rou trac in gran in dat
wher but
"frontier" have hrst state. (already
goalEach searched
because left.the adds state End.
causing (FIFO)
9. 8. 7. 6. 5. 4. 3. 1.
Figure and open A states
Childare Return
FAIL Problem
_search.
not open open open open open open 2.
open
successivetrace While
them
transition End
been so the the This data Begin
of =[E,
= =(D, = = = the appear IfX
below on =
[H, [G, (F, of to Remove open Solving
the The [C, (B, [A]; condition
entire search structure.
discovered until breadth biases open. begin
Else
is #
searchillustrates I, H, G, F, E, D, C, number,
closed on operators. EndDiscard PutonX
Put Generate a
J, I, H, G, F, E,D]; 0 by
states either K,L, graph either to generatedby goal
leftmost
J, I, H, G,F]; search
be Note remaining do
Searching
at J, closed= of States then
K, I,closed H]; first breadth-first. children
any byon U M, L, K, J]; represents
1 without theopen closed;
children
the is closed while" thatEach
stage the
open L];
closed search toward returnstate
or are children
algorithm,
graphfound N]; (asM]
closed= [A] open
iteration
closed= [B , finding closed) added inference rules,
legal of of from
and and L = = an
of or on loop the XSUCCESS
is (D, [C, A]
iteration Child is if
X; open,
that closed above open already the states on
(E, C, B, the isare maintained to
produces already
Note (G , graph nostates right
closed D, A] the call
figure F, B, desired
discarded.
are longer that
that
) E, on C,
A] of right end on it
open); the of that X;
records D, B, have asall open
of
highlighted.after
open above goal:
satisfied of
C, A] have open
children
the a
moves
B,
closed while" If been queue, or
six the
records
states A] figure the already list closed;
iterations loop.(open=) search
algorithm on
and of of
already States
= appears open or
the [F, been
first-in-first-out the a
removed game,
E, isU has
states not of discovered the state
D, the failed. terminates
visited. breadth as then or
C, desired longest,
shaded on below. other
X
B, it from 35
the has and
A]
ConsiderDepth storing is of of found a
requiredstates the It pathfound path frombefore
Figure 36
is from Because
the
firstancestor states.often along along of going
the on
for the equal the start :
search
graph a the breadth-first Graph
current a
Foruseful better
or start deeper
state.
information
solution, shortest
presented example, greater
algorithm
topath, Breadth-first state into of
path keep above
length. path,
it note the to search the open
in along can to other the figure
aalgorithm any space,
the goal;
be that Because goal and
with informnation states search considers
below returned all closed at
all
breadth state.
each visited simply states iteration
figure.
encountered
there therefore
Furthermore, arevery are
state. by on e
tstates
he first discards is highlighted 6
open no ofbreadth-first first
algorithm. search is node Artifnclal
are and
chanceguaranteed areached
second
any because at
kept closed Intelligence
doesduplicate cach
states. that along
This on time
closed.besides not duplicate to level search.
can are all find the &
maintain states
found shortest of Applie
be If the
the states the States
done the areshorte
name alon: gran,
pati a fir: pa': on
b lis ar:
of states
R.
J, ofíntoasdesce
th Probl
the Succ Begi Func depthopen op
6. 5. 4. 3. 2. 1. End. In In
state.
goalthe
successive End. Begin
first_search;
Function
depth-first
depth order. open of R.
J,descendants
states ofinto
6. a
Problem
7. 5. 4. 3. 2. I. FAIL
AReturn Closed
While [Start];
=0; Open := open. In In
open open open open open open open as this state the
trace End; Begin indepth-first
RemoveIf open Opena the scarch
can Solving
= stack
algorithm,
= = = = = = iteration
[T, [L, [S, (K, [E, [B, [AJ; of begin graph are
Else isX be
C, depth Put
Put Generate #] directs is space
examined
F, F, L, L, F,closed EndDiscard a maintained found by
C, C, F, F, C,D}; goal
leftmost in search,
of remaining X do the the Searching
D]; D}; C, C,D]; first_search on whenever
closed = the then scarch
closed
closed= D]; D]closed ; children
closed;
children descendant order are
[]"while" beforewhen
its
closedclosed returnstate
children toward as sublings A,
= [A] a
[L, (S, on of of from stack B, this any state a
= =[B,A] loop the XSUCCESS states E, is of
S, K,[K, [E, X; open,
if the or considered. possible.
K,
K, E, E, B, is
graph on
already its is
left most aare examined;
A]
B, indicated call LIFO
S,sublings.
E, B, B, A] L,
A] A] of end it recently added T,Only
on data F,
above of X; Depth-first
search
by open and M,
Depth-first
open structure. all
figure generatedremoved C,when
single a or G, of
closed; N, no its
appears
line. The further
H, search
children
state from 0,
Assuming organization examines
producing P,the goes
below. the descendants
U, and
left
D, deepertheir
Each I, 37
end
isU a of Q,
Advantages1 Advantages
2. 1. Figure to
algorithm And 38
Breadth-first examined.Depth-first
very with Depth-first that path
treespace Depth-First reconstruct firstFigure 11. 10. 9. 8
: so
long has are Graph search. onopen open open open
depth-first must at
of all. stored.so of
store below until
-[G, = =[E, =
time,
Breadth-First search This be the The [C, [M,
search far ofabove
search examined This search
Depth-First path
a either H,
record shows DJ: C,C,
been D]:
perhaps
searching, is This contents D]; D],
can contrasts may
particularly generatedrequires
that closed
U
closed
will figure of the closed= is as
stop contrast and led the graph
forever, not to find discovered
of = isL
from M, =
when level with
a search closed at parent the [already [T,
which search
get less iteration
significant solution must with of [C, F
beforetrapped breadth-first
any n memory are
start openabove M,E,T, T, L,
along S,
may or
be
before breadth-first L, onK,
one highlighted state and
figure open
stored.
without S, E,
closed;
the
follow 6 with
exploring of to =
L, K, B,
of ifany since closed
path themmany depth-first a at O. S, E, A]
search goaleach the K,closedB, Artificial
a nodes
examining
actually search, only E, A]
single, aacceptable is state.state, aresixth
blind found. the B, Intelligence=
on in search. highlighted. AJ (F
which nodes allowingiteration
terminates
unfruitfulalley. level much where T,
L,
solutions States S,
This nall all on of &
of the K,
+
parts The the Applcation
the ofthe E,
path
in I on
Contrast- can he
tcurrer algorith deanth B,
a ex1s ofsear ope sean.
stat for tre A)
Algorithm
Search A SearchA* Greedy 2. Problem
" " search.
" searchA* " "goal thatat
optimal
faster.
result
problemefficiently.
heuristic solve
A* function
theheuristic
It A* involving
This the perfect
formulated result
A* the starting "firstheuristic A* ofBFS
the This node the moment.
Withinbestthe Greedy shorter
search, have
ones Thismore, unless If there that
has Best-First there Solving
search search countheuristicrequest, search advantages
sortofsearch
combined makes is ifspecial are has
point limit and best-first which
guarantecdthere is
function.This resembles a loops no by
algorithm is with computation is DFS. breadth-first
solution, then
succCSsors.
A*
littlest snappier.limit. by
the stateh(n), the andtherefore
of may are care (1.e., Searching
which Ituses first Search
features h(n), most algorithmweighted most thereliably search
cost This g(n). and search find multiple
already by is
finds two expended a
search and UCS it
consistently heuristic the state
commonly in chasefinds deal Itcostestimations. picks algorithm
Algorithm long a This
the ofcost ingraphs,
termswhich beside has algorithm, the fact
solutions,
to been has
algorithm
shortest UCS AI th e with the path is
to count solidifiedshow closest that to a a
ofdistance
an limit
and reachknown that briefest the way always examined. successortest
particular
informed knownup
tolonger
path expands
it issue andwhich cost we a then
expands greedy the features at solution search for
suggestscan ituses path selects such
through node form and capably. the kind searches. expand is paths a
appears
estimated Thismninimal is problem that
search g(n)th(n) through less center a
less best-first n of time. of of the the inguaranteed
are situation. is
the from interest
trees
and UCSbest-first The one
contrasts also
search best-first point best node trail never
search algorithm the part solution in
find
instead BFS by one
search, the and n by which depth-first search if
tree chase heuristic
then. which of
explored
start the from grants to of
space search. insatiableinterest. the with will find
and fosimplest
r Itis appears its
bystate of space
the is tree.
g(n). depth-hrst beancestors)
it.
providesusing which best-first function.
usthe closest to
until
g(n). It gives a earliest It to found.Further
uses path It using best uses take blend
the best 39
it is all
Disadvantages Advantages Step Step
to cach
iflist.
For Step
iii. i . i. iii. i . i. functionStep stops. and Step
Algorithm lowest
the not Stepl:
approximation. 3: At
nodes The A* and It This A*A* 6:back 5:then 4: 2: " "
does Return Else Select Check Place value each
search
Expand (g+h), number.
fitnessnode.
a In A°
mainsearch algorithm search compute Solution.
cheapest the
Estimated ofcost
in pointer of point algorithm A*
not successorn',if th e of Hence
the to node the if A* search
drawback
algorithm always algorithm algorithm noden if
memory, Step node node starting
the search f(n), in
which
evaluation n
can OPEN and the wecan
algorithm,
2. is from is
and n similar
produce solve reflects
already check is node search
the
so ofhas is is generate goal the list combine
A*
it some optimal the algorithm
is very function OPEN is in space, f(n) we to
is best the whether
in node empty the
not the use UCS
memory OPEN startnode both
complexity shortestcomplexalgorithm
practical and lowest all then OPEN fromreach
Cost
n to
list terminates only = searchexcept
for n> or state. g(n) costs
complete. and
of which
return not,
g(n) n» is its list. those
requirement problems. already
and heuristicas that
CLOSED, successors, if +
for issues. path than following, Artificlal
value. place success has the when node it
various as h(n)
other the list uses
it in as
mostly into the smallest and is the is wellIntelligence
g(n)+h(n)
as search then and empty expanded node
goal fromreach
Cost tO
large-scale OPEN goal and
it Open stop, as
keeps it put node
based should value node this the
algorithms. then
or n
list. otherwise n cost
into which sum instead &
CLOSED is to
problems. all on ofevaluatio return Applicaion.
be the found. is to
genera heuristi attache have calledreal of
close failur of
lis
Problem Solving by Searching
41

Example
In this example, we will traverse the given
graph using the A* algorithmn. The
heuristic value of all states is given in the below table so we will calculate the
f(n) of each state using theformula f(n)= g(n) + h(n),
reach any node from start state. where g(n) is the cost to
eHere we will use OPEN and CLOSED list.
State h(n)

B
G
C
10

Solution:
Initialization: {(S, 5)}
Iteration1: {(S--> A, 4),(S-->G, 10)}
Iteration2: {(S--> A-->C, 4), (S--> A-->B, 7), (S-->G, 10)}
lteration3: {(S--> A-->C--->G, 6), (S--> A-->C--->D, 11), (S->A->B, 7), (S-->G,
10)}
Iteration 4will givethe final result, as S-->A--->C-->Git provides the optimal path
with cost 6.
A0* Algorithm in Artificial Intelligence
" Our real-life situations can't be exactly decomposed into either AND tree or
OR tree but is alwaysa combination of both.
So, we need an AO* algorithm where O stands for ordered'. A0* algorithm
represents a part ofthe search graph.
Artificial Intelligence &
42
Applications
AO* algorithm is given as follows
Step-1: Create an initial graph with a single node (start node).
Step-2: Transverse the graph following the current path, accumulating node thhat ha
not yet beenexpanded or solved.
Step-3: Select any of these nodes and explore it. If it has no successors then cal
tbis value-FUTILITY else calculate f (n) for cach of the successors.
Step-4: If f'(n) =0, then mark the node as SOLVED.
Step-5: Change the value of f (n)for the newly created node to reflect its successow
by backpropagation.
Step-6: Whenever possible use the most promising routes, If a node is marked a
SOLVED thenmark the parent node as SOLVED.
Step-7: If the starting node is SOLVED or value is greater than FUTILITY then stor
else repeatfrom Step-2.
HEURISTIC SEARCH
Introduction
George polya defines heuristic as the study of the methods and rules of discovery
and invention". The word heuristic comes fromn the Greek word called eurisco, which
means I discovered", Which is also the origin of eureka, derived from Archimedes
he shouted "Eureka", meaning I have found it". In state space search, heuristics are
formalized as rules for choosing those branches in astate space that are most likely
to lead to an acceptable problem solution.
AIproblem solvers employee heuristics in two basic situations:
1. A problem may not have an exact solution because of inherent ambiguities
in the problem statement or available data. Medical diagnosis is an example
of this. A given set of symptoms may have several possible causes; doctors
use heuristics to choose the most likely diagnosis and formulate a plane
of treatment. [Vision is another example of an inherently inexact problem
Visual scenes are often ambiguous, allowing multiple interpretations of the
connectedness, extent, and orientation of objects. Optical illusions exemplify
these ambiguities. Vision system typically use heuristics to select the most
likely of several possible interpretations of any given scene].
2. A problem may have an exact solution, but the computational cost of finding
it may be prohibitive. In many problems (such as chess), state space growti
is combinatorially explosive, with the number of possible states increasing
exponentially or factorially with the depth of the search.
A heuristic is only an informed guess of the next step to be taken in solving
problem. It is useful to think of heuristic algorithms as constituting of two parts. The
heuristic measure and the algorithm that uses it to search the state space.
Problem Solving by Searching 43

An Algorithmfor Heuristic Search


Best-First search:
Best-first search uses lists to maintain states: open to keep track of the current
fringe of the scarch and closed to record states already visited. An added step in the
algorithm orders the states on open according to sonme heuristic estimate of their
*closeness* to a goal.
Function best first_search;
Begin
Open = [Start];
Closed =[];
While open #[]do
Begin
Remove the leftmost state from open, call it X;
IfX =goal then return the path fromn Start to X
Else begin
Generate children of x;
For each child of X do
Case
The child is not on open or closed:
Begin
Assign the child a heuristic value;
Add the child to open
End;
The child is already on open:
If the child was reached by a shortest path
Then give the state on open the shorter path
The child is already on closed:
If the child was reached by a shorter path then
Begin
Remove the state from closed;
Addthe child to open
End;
End;
Put X on closed;
Re-order states on open by heuristicmerit (best leftmost)
End;
Return FAIL
End.
At each iteration, best first search removes the first element from the
If it meets the goal conditions, the algorithm returns the solution path that
open list.
lead to the
Applicatlon.
Artificial Inteligence &

algorithm applies all matchi.


a goal, the is
element on open is not descendants. Ifa child state alrcady o
records the shorte
goal. If the first or operators to generateits that the state
productionrules algorithmn checks to make
sure
are not retained. By updatin.
closed, the
open or partial solution paths.
Duplicate states they are
rediscovered, th.
when
of the two history of nodes on openand closedgoal.
the ancestor to a
more likely to find a shorter path open, and th.
algorithm is evaluation to the states on
applies a heuristic bcs!
Best first search then
values of those states. This brings the natur.
to the heuristic estimates are heuristic in
list is sorted accordingopen. Note that because these
space. WVhen open
states to the front ofexamined may be from any level of the state
the next state to be
list, it is often referred to as priority queue.
is maintained as a sorted heuristic evaluations attached
hypothetical state space with generatcd
Figure below shows a with attached evaluation arethose actually
states indicatcd
to some of its states. The expanded by heuristic search algorithm are
in best first search. The states is
does not search all of the space. The goal of best first search
in bold; note that it
few states as possible.
to find the goal state by looking at as

Figure : Heuristic search ofa hypothetical state space.


A trace of the execution ofbest first search on this
Pis the goal, states along the path to P tend to have graph appears below. Suppos
is fallible: the state O has a lower value low heuristic values. The heuris
than the goal itself and is examined first.
1. open [AS]; closed =[]
2. evaluate A5;
open
3.evaluate B4; open = [B4,C4,D6]; closed =[AS]
[C4,E5,F5,D6]; closed= [B4, AS]
Problem Solving by Searching 45

4. evaluate C4; open =[H3,G4, ES,F5,D6]; closed =


[C4,B4, AS]
e evaluate H3; open = (O2,P3, G4, E5,FS,D6]; closed =
[H3,C4,B4, A5]
6evaluate O2; open =l P3, G4, E5,FS,D6]; closed = [O2,H3,C4,B4, AS]
7. evaluate P3; the solution is found.
Figure below shows the space as it appears after the fifth iteration of the while
loop. The states contained in open and closed are indicated. Open records the current
fontier of the search and closed records states already considered.

Figure: Heuristic search ofa hypothetical state space with open and closed states
highlighted.
The best first search algorithm always selects the most promising state on open
for further expansion. However, as it is using a heuristic that may prove erroneous,
open. In the event
it does not abandon all the other states but maintains them on
algorithm will
a heuristic leads the search down a path that proves incorrect, the
open and shifts
eventually retrieve some previously generated, "next best" state from
(fig), after the children of
its focus toanother part of the space. In the above example search shifted its focus to
state B were found to have poor heuristic evaluations, the
algorithm need to retun
state C. the children of B were kept on open in the case the
to them later.

Hill Climbing
available for evaluating
Hill climbing is used when a good heuristicfunction is you
States but when no other useful knowledge is available. For example: Suppose
You simply
downtown.
re in an unfamiliar city without a map and you want to get
Artificial ntelligence & Applicatlons

states are those in which this distance ix


desirable
buildings and the
aim at the tall
minimized.
Algorithm:
Simple HillClimbing climbing is as follows:
simplest way to implement hill state, then return it and quit
The also a goal
Evaluate the initial state. If it is as the current state.
1 the initial state
Otherwise, continue with are no new operators left to A
there
solution is found or until
2. Loop until a
applied in the current state: been applied to the current state an:
that has not yet
a) Select an operator state.
apply it toproduce a new
b) Evaluate the new state.
it and quit.
i. If it is a goal state then return state, then make
ii. If it is not a goal state
but it is better than the current
it the current state.
then continue in the loop.
ii. If it is not better than the current state,
To know how hillclimbing works, considerheuristicthe puzzle of four colored blocks
function that describes hoy
To solve the problem, we first need to define a
One such function is simpl
close a particular configuration is to being a solution. A solution to the
the sum of the number of different colors on each of the four sides.
describa
puzzle will have a value of 16. Next we need to define a set or rules that
ways of transforming one configuration into another. Actually, one rule will suffice
Itsays simply picka block and rotate it 90 degrees in any direction. Having provided
these definitions, the next step is to generate a starting configuration. This can eithe
be done at random or with the aid of the heuristic function. Now hillclimbing Cai
begin we generate a new state by selecting a block and rotating it. If the resultm
state is better, then we keep it. If not, we return to the previous state and try a difieret
perturbation.

EXCERISES
Short Answer Questions
1. What is internal
2.
representation in artificial intelligence?
Mention the properties of internal
3 What are heuristic search representation.
4. Briefly explain techniques in AI?
greedy best first search.
What is Means end
analysis?
Problem Solving by Searching 47

6. What is A* search algorithm?


7. Writethe advantages of A* search algorithm.
8. Write the demerits of A* search algorithm.
9. Give example for A* search algorithm.
10. What is game playing for artificial intelligence?
Long Answer Questions
1. Explain the Properties of Internal Representation.
2. Write the heuristicsearchtechniques inArtificial Intelligence.
3. Briefly explain Greedy best first search.
4. Briefly explain means-ends analysis in AI.
5 Write A* search algorithm.
6. Write AO* algorithm.
7 Write the min-max search procedure.
8. Write the Pseudo-code for Alpha-beta Pruning.
9. Explain game playing.
10. Write the advantages and dis-advantages of A* search.

You might also like