You are on page 1of 40

-------------------------------------------------------------------------------------------------------

ARTIFICIAL INTELLIGENCE
VI SEMESTER CSE
UNIT-I
-----------------------------------------------------------------------------------------
1.1 INTRODUCTION
1.1.1 What is AI?
1.1.2 The fo!"atio!s of A#tifi$ia% I!te%%i&e!$e.
1.1.' The (isto#) of A#tifi$ia% I!te%%i&e!$e
1.1.* The state of a#t
1.2 INTELLIGENT AGENTS
1.2.1 A&e!ts a!" e!+i#o!,e!ts
1.2.2 Goo" -eha+io# . The $o!$e/t of #atio!a%it)
1.2.' The !at#e of e!+i#o!,e!ts
1.2.* St#$t#e of a&e!ts

1.' SOLVING 0RO1LEMS 12 SEARC(ING
1.'.1 0#o-%e, So%+i!& A&e!ts
1.'.1.1We%% "efi!e" /#o-%e,s a!" so%tio!s
1.'.2 E3a,/%e /#o-%e,s
1.'.2.1 To) /#o-%e,s
1.'.2.2 Rea% 4o#%" /#o-%e,s
1.'.' Sea#$hi!& fo# so%tio!s
1.'.* U!i!fo#,e" sea#$h st#ate&ies
1.'.*.1 1#ea"th-fi#st sea#$h
1.'.*.2 U!ifo#,-$ost sea#$h
1.'.*.' De/th-fi#st sea#$h
1.'.*.* De/th %i,ite" sea#$h
1.'.*.5 Ite#ati+e-"ee/e!i!& "e/th fi#st sea#$h
1.'.*.6 1i-"i#e$tio!a% sea#$h
1.'.*.7 Co,/a#i!& !i!fo#,e" sea#$h st#ate&ies
1.'.5 A+oi"i!& #e/eate" states
1.'.6 Sea#$hi!& 4ith /a#tia% i!fo#,atio!
1.1 I!t#o"$tio! to AI
1.1.1 What is A#tifi$ia% I!te%%i&e!$e?
A#tifi$ia% I!te%%i&e!$e is the branch of computer science concerned with making computers
behave like humans.
As per Elaine Rich and Kevin Knight, Artificial Intelligence is defined as the study of how
to make computers do things which at the moment people do better.
!a"or AI te#tbooks define artificial intelligence as $the study and design of intelligent agents,$
where an i!te%%i&e!t a&e!t is a system that /e#$ei+es its e!+i#o!,e!t and ta8es a$tio!s
which ma#imi%es its chances of success. 9oh! M$Ca#th), who coined the term in &'(),
defines AI as $the science and engineering of making intelligent machines,especially
intelligent computer programs.$
*he definitions of AI according to some te#t books are categori%ed into four approaches and are
summari%ed in the table below +
S)ste,s that thi!8 %i8e h,a!s
*he e#citing new effort to make computers
think , machines with minds,in the full and
literal sense.-.augeland,&'/(0
S)ste,s that thi!8 #atio!a%%)
*he study of mental faculties through the use of
computer models.
-1harniak and !c2ermont,&'/(0
S)ste,s that a$t %i8e h,a!s
*he art of creating machines that perform
functions that re3uire intelligence when
performed by people.-Kur%weil,&''40
S)ste,s that a$t #atio!a%%)
:1omputational intelligence is the study of the
design of intelligent agents.-5oole et al.,&''/0
*he four approaches in more detail are as follows +
;a< A$ti!& h,a!%) . The T#i!& Test a//#oa$h
o *est proposed by Alan *uring in &'(4
o *he computer is asked 3uestions by a human interrogator.
*he computer passes the test if a human interrogator,after posing some written 3uestions,cannot tell
whether the written responses come from a person or not. 5rogramming a computer to pass
,the computer need to possess the following capabilities +
Nat#a% %a!&a&e /#o$essi!& to enable it to communicate successfully in English.
=!o4%e"&e #e/#ese!tatio! to store what it knows or hears
Ato,ate" #easo!i!& to use the stored information to answer 3uestions and to draw
new conclusions.
Ma$hi!e %ea#!i!& to adapt to new circumstances and to detect and e#trapolate
patterns
*o pass the complete *uring *est,the computer will need
Co,/te# +isio! to perceive the ob"ects,and
Ro-oti$s to manipulate ob"ects and move about.
;-<Thi!8i!& h,a!%) . The $o&!iti+e ,o"e%i!& a//#oa$h
6e need to get inside actual working of the human mind +
-a0 through introspection 7 trying to capture our own thoughts as they go by8
-b0 through psychological e#periments
Allen 9ewell and .erbert :imon,who developed G0S,the Ge!e#a% 0#o-%e, So%+e#
tried to trace the reasoning steps to traces of human sub"ects solving the same problems.
*he interdisciplinary field of $o&!iti+e s$ie!$e brings together computer models from AI
and e#perimental techni3ues from psychology to try to construct precise and testable
theories of the workings of the human mind

;$< Thi!8i!& #atio!a%%) . The :%a4s of tho&ht a//#oa$h>
*he ;reek philosopher Aristotle was one of the first to attempt to codify right
thinking,that is irrefuatable reasoning processes. .is s)%%o&is, provided patterns for
argument structures that always yielded correct conclusions when given correct premises<for
e#ample,:ocrates is a man8all men are mortal8therefore :ocrates is mortal..
*hese laws of thought were supposed to govern the operation of the mind8their study initiated a
field called %o&i$.
;"<A$ti!& #atio!a%%) . The #atio!a% a&e!t a//#oa$h
An a&e!t is something that acts. 1omputer agents are not mere programs ,but they are e#pected to
have the following attributes also + -a0 operating under autonomous control, -b0 perceiving
their environment, -c0 persisting over a prolonged time period, -e0 adapting to change.
A #atio!a% a&e!t is one that acts so as to achieve the best outcome.
1.1.2 The fo!"atio!s of A#tifi$ia% I!te%%i&e!$e
*he various disciplines that contributed ideas,viewpoints,and techni3ues to AI are given
below +
0hi%oso/h);*2? 1.C. @ /#ese!t<
Aristotle -=/>?=@@ A.1.0 was the first to formulate a precise set of laws governing the rational part
of the mind. .e developed an informal system of syllogisms for proper reasoning,which
allowed one to generate conclusions mechanically,given initial premises.
1omputer .uman Arain
1omputational units
:torage units
1ycle time
Aandwidth
!emory updatesBsec
& 15C,&4
/
gates
&4
&4
bits RA!
&4
&&
bits disk
&4
?'
sec
&4
&4
bitsBsec
&4
'
&4
&&
neurons
&4
&&
neurons
&4
&>
synapses
&4
?=
sec
&4
&>
bitsBsec
&4
&>
Ta-%e 1.1 A crude comparison of the raw computational resources available to computers-circa
@44= 0 and brain. *he computerDs numbers have increased by at least by a factor of &4 every few
years. *he brainDs numbers have not changed for the last &4,444 years.
Arains and digital computers perform 3uite different tasks and have different properties. *ablere &.&
shows that there are &4444 times more neurons in the typical human brain than there are gates in
the 15C of a typical high?end computer. !ooreDs Eaw predicts that the 15CDs gate count will e3ual
the brainDs neuron count around @4@4.
0s)$o%o&);1?7A @ /#ese!t<
*he origin of scientific psychology are traced back to the wok if ;erman physiologist .ermann von
.elmholt%-&/@&?&/'>0 and his student 6ilhelm 6undt-&/=@ 7 &'@40
In &/F',6undt opened the first laboratory of e#perimental psychology at the university of Eeip%ig.
In C:,the development of computer modeling led to the creation of the field of $o&!iti+e s$ie!$e.
*he field can be said to have started at the workshop in :eptember &'() at !I*.
Co,/te# e!&i!ee#i!& ;1A*B-/#ese!t<
Gor artificial intelligence to succeed, we need two things+ intelligence and an artifact. *he computer has been
the artifact of choice.
A1 also owes a debt to the software side of computer science, which has supplied the operating systems,
programming languages, and tools needed to write modern programs
Co!t#o% theo#) a!" C)-e#!eti$s ;1A*?-/#ese!t<
Ktesibios of Ale#andria -c. @(4 A.c.0 built the first self?controlling machine+ a water clock with a regulator
that kept the flow of water running through it at a constant, predictable pace. !odern control theory,
especially the branch known as stochastic optimal control, has as its goal the design of systems that
ma#imi%e an o-Ce$ti+e f!$tio! over time.
Li!&isti$s ;1A57-/#ese!t<
!odem linguistics and AI, then, were $born$ at about the same time, and grew up together, intersecting in a
hybrid field called $o,/tatio!a% %i!&isti$s or !at#a% %a!&a&e /#o$essi!&.
1.1.' The (isto#) of A#tifi$ia% I!te%%i&e!$e
The &estatio! of a#tifi$ia% i!te%%i&e!$e ;1A*'-1A55<
*here were a number of early e#amples of work that can be characteri%ed as AI, but it was Alan *uring who
first articulated a complete vision of A& in his &'(4 article $1omput?ing !achinery and Intelligence.$
*herein, he introduced the *uring test, machine learning, genetic algorithms, and reinforcement learning.
The -i#th of a#tifi$ia% i!te%%i&e!$e ;1A56<
!c1arthy convinced !insky, 1laude :hannon, and 9athaniel Rochester to help him bring together C.:.
researchers interested in automata theory, neural nets, and the study of intelligence. *hey organi%ed a two?
month workshop at 2artmouth in the summer of &'(). 5erhaps the longest?lasting thing to come out of the
workshop was an agreement to adopt !c1arthyHs new name for the field+ a#tifi$ia% i!te%%i&e!$e.
Ea#%) e!thsias,D &#eat e3/e$tatio!s ;1A52-1A6A<
*he early years of A& were full of successes?in a limited way.
Ge!e#a% 0#o-%e, So%+e# -G0S0 was a computer program created in &'(F by .erbert :imon and
Allen 9ewell to build a universal problem solver machine. *he order in which the program considered
subgoals and possible actions was similar to that in which humans approached the same problems. *hus,
;5: was probably the first program to embody the $thinking humanly$ approach. At IA!, 9athaniel
Rochester and his colleagues produced some of the first A& programs. .erbert ;elernter -&'('0 constructed
the ;eometry *heorem 5rover, which was able to prove theorems that many students of mathematics would
find 3uite tricky. Eisp was invented by Iohn !c1arthy in &'(/ while he was at the !assachusetts
Institute of *echnology -!I*0. In &')=, !c1arthy started the AI lab at :tanford. *om EvansHs A9AEJ;K
program -&')/0 solved geometric analogy problems that appear in IL tests, such as the one in Gigure &.&
Fi&#e 1.1 *he *om EvanDs A9AEJ;K program could solve geometric analogy problems as
shown.
A "ose of #ea%it) ;1A66-1A7'<
Grom the beginning, AI researchers were not shy about making predictions of their coming successes. *he
following statement by .erbert :imon in &'(F is often 3uoted+
It is not my aim to surprise or shock you?but the simplest way I can summari%e is to say that there
are now in the world machines that think, that learn and that create. !oreover, their ability to do
these things is going to increase rapidly until?in a visible future?the range of problems they can
handle will be coe#tensive with the range to which the human mind has been applied.
=!o4%e"&e--ase" s)ste,s. The 8e) to /o4e#? ;1A6A-1A7A<
De!"#a% was an influential pioneer pro"ect in artificial intelligence -AI0 of the &')4s, and the
computer software e3/e#t s)ste, that it produced. Its primary aim was to help organic chemists in
identifying unknown organic molecules, by analy%ing their mass spectra and using knowledge of
chemistry. It was done at :tanford Cniversity by Edward Geigenbaum, Aruce Auchanan, Ioshua
Eederberg, and 1arl 2"erassi.
A1 -e$o,es a! i!"st#) ;1A?B-/#ese!t<
In &'/&, the Iapanese announced the $Gifth ;eneration$ pro"ect, a &4?year plan to build intelligent computers
running 5rolog. Jverall, the A& industry boomed from a few million dollars in &'/4 to billions of dollars in
&'//.
The #et#! of !e#a% !et4o#8s ;1A?6-/#ese!t<
5sychologists including 2avid Rumelhart and ;eoff .inton continued the study of neural?net models of
memory.
A1 -e$o,es a s$ie!$e ;1A?7-/#ese!t<
In recent years, approaches based on hi""e! Ma#8o+ ,o"e%s -.!!s0 have come to dominate the area.
:peech technology and the related field of handwritten character recognition are already making the
transition to widespread industrial and consumer applications.
*he 1a)esia! !et4o#8 formalism was invented to allow efficient representation of, and rigorous reasoning
with, uncertain knowledge.
The e,e#&e!$e of i!te%%i&e!t a&e!ts ;1AA5-/#ese!t<
Jne of the most important environments for intelligent agents is the Internet.
1.1.* The state of a#t .
What $a! A1 "o to"a)?
Ato!o,os /%a!!i!& a!" s$he"%i!&. A hundred million miles from Earth, 9A:AHs
Remote Agent program became the first on?board autonomous planning program to control
the scheduling of operations for a spacecraft -Ionsson et al., @4440. Remote Agent generated
plans from high?level goals specified from the ground, and it monitored the operation of the
spacecraft as the plans were e#ecuted?detecting, diagnosing, and recovering from problems
as they occurred.
Ga,e /%a)i!&. IA!Hs 2eep Alue became the first computer program to defeat the
world champion in a chess match when it bested ;arry Kasparov by a score of =.( to @.( in
an e#hibition match -;oodman and Keene, &''F0.
Ato!o,os $o!t#o%. *he AEMI99 computer vision system was trained to steer a car
to keep it following a lane. It was placed in 1!CHs 9AMEAA computer?controlled minivan
and used to navigate across the Cnited :tates?for @/(4 miles it was in control of steering the
vehicle '/N of the time.
Dia&!osis. !edical diagnosis programs based on probabilistic analysis have been able
to perform at the level of an e#pert physician in several areas of medicine.
Lo&isti$s 0%a!!i!&. 2uring the 5ersian ;ulf crisis of &''&, C.:. forces deployed a
2ynamic Analysis and Replanning *ool, 2AR* -1ross and 6alker, &''>0, to do automated
logistics planning and scheduling for transportation. *his involved up to (4,444 vehicles,
cargo, and people at a time, and had to account for starting points, destinations, routes, and
conflict resolution among all parameters. *he AI planning techni3ues allowed a plan to be
generated in hours that would have taken weeks with older methods. *he 2efense Advanced
Research 5ro"ect Agency -2AR5A0 stated that this single application more than paid back
2AR5AHs =4?year investment in AI.
Ro-oti$s. !any surgeons now use robot assistants in microsurgery. .ip9av -2i;ioia
et al., &'')0 is a system that uses computer vision techni3ues to create a three?dimensional
model of a patientHs internal anatomy and then uses robotic control to guide the insertion of a
hip replacement prosthesis.
La!&a&e !"e#sta!"i!& a!" /#o-%e, so%+i!&. 5RJMERA -Eittman et al., &'''0 is a
computer program that solves crossword pu%%les better than most humans, using constraints
on possible word fillers, a large database of past pu%%les, and a variety of information sources
including dictionaries and online databases such as a list of movies and the actors that appear
in them.
1.2 INTELLIGENT AGENTS
1.2.1 A&e!ts a!" e!+i#o!,e!ts
An a&e!t is anything that can be viewed as perceiving its e!+i#o!,e!t through se!so#s and
SENSOR acting upon that environment through a$tato#s. *his simple idea is illustrated in Gigure &.@.
o A human agent has eyes, ears, and other organs for sensors and hands, legs, mouth, and other body
parts for actuators.
o A robotic agent might have cameras and infrared range finders for sensors and various motors for
actuators.
o A software agent receives keystrokes, file contents, and network packets as sensory inputs and acts
on the environment by displaying on the screen, writing files, and sending network packets.
Fi&#e 1.2 Agents interact with environments through sensors and actuators.

0e#$e/t
6e use the term /e#$e/t to refer to the agentHs perceptual inputs at any given instant.
0e#$e/t SeEe!$e
An agentHs /e#$e/t seEe!$e is the complete history of everything the agent has ever perceived.
A&e!t f!$tio!
!athematically speaking, we say that an agentHs behavior is described by the a&e!t f!$tio!
that maps any given percept se3uence to an action.
A&e!t /#o&#a,
Internally, *he agent function for an artificial agent will be implemented by an a&e!t /#o&#a,. It is
important to keep these two ideas distinct. *he agent function is an abstract mathematical
description8 the agent program is a concrete implementation, running on the agent architecture.
*o illustrate these ideas, we will use a very simple e#ample?the vacuum?cleaner world
shown in Gigure &.=. *his particular world has "ust two locations+ s3uares A and A. *he vacuum
agent perceives which s3uare it is in and whether there is dirt in the s3uare. It can choose to move
left, move right, suck up the dirt, or do nothing. Jne very simple agent function is the following+ if
the current s3uare is dirty, then suck, otherwise move to the other s3uare. A partial tabulation of this
agent function is shown in Gigure &.>.
Fi&#e 1.' A vacuum?cleaner world with "ust two
locations.
A&e!t f!$tio!
0e#$e/t SeEe!$e A$tio!
OA, 1leanP Right
OA, 2irtyP :uck
OA, 1leanP Eeft
OA, 2irtyP :uck
OA, 1leanP, OA, 1leanP Right
OA, 1leanP, OA, 2irtyP :uck
,
Fi&#e 1.* 5artial tabulation of a
simple agent function for the
vacuum?cleaner world shown in
Gigure &.=.
Ratio!a% A&e!t
A #atio!a% a&e!t is one that does the right thing?conceptually speaking, every entry in
the table for the agent function is filled out correctly. Jbviously, doing the right thing is
better than doing the wrong thing. *he right action is the one that will cause the agent to be
most successful.
0e#fo#,a!$e ,eas#es
A /e#fo#,a!$e ,eas#e embodies the $#ite#io! fo# s$$ess of an agentHs behavior. 6hen
an agent is plunked down in an environment, it generates a se3uence of actions according
to the percepts it receives. *his se3uence of actions causes the environment to go through a
se3uence of states. If the se3uence is desirable, then the agent has performed well.
Ratio!a%it)
6hat is rational at any given time depends on four things+
o *he performance measure that defines the criterion of success.
o *he agentHs prior knowledge of the environment.
o *he actions that the agent can perform.
o *he agentHs percept se3uence to date.
*his leads to a "efi!itio! of a #atio!a% a&e!t.
For each possible percept sequence, a rational agent should select an action that is ex-
pected to maximize its performance measure, given the evidence provided by the percept
sequence and whatever built-in knowledge the agent has.
O,!is$ie!$eD %ea#!i!&D a!" ato!o,)
An o,!is$ie!t a&e!t knows the actual outcome of its actions and can act accordingly8 but
omniscience is impossible in reality.
2oing actions in order to modify future percepts?sometimes called i!fo#,atio! &athe#i!&?is
an important part of rationality.
Jur definition re3uires a rational agent not only to gather information, but also to %ea#!
as much as possible from what it perceives.
*o the e#tent that an agent relies on the prior knowledge of its designer rather than
on its own percepts, we say that the agent lacks autonomy. A rational agent should be
ato!o,os?it should learn what it can to compensate for partial or incorrect prior knowledge.
Tas8 e!+i#o!,e!ts
6e must think about tas8 e!+i#o!,e!tsD which are essentially the $/#o-%e,s$ to which rational agents are
the $so%tio!s.$
S/e$if)i!& the tas8 e!+i#o!,e!t
*he rationality of the simple vacuum?cleaner agent, needs specification of
o the performance measure
o the environment
o the agentHs actuators and sensors.
0EAS
All these are grouped together under the heading of the tas8 e!+i#o!,e!t.
6e call this the 0EAS -5erformance, Environment, Actuators, :ensors0 description.
In designing an agent, the first step must always be to specify the task environment as fully
as possible.
A&e!t T)/e 0e#fo#,a!$e
Meas#e
E!+i#o!,e!ts A$tato#s Se!so#s
*a#i driver :afe+ fast, legal,
comfortable trip,
ma#imi%e profits
Roads,other
traffic,pedestrians,
customers
:teering,accelerator,
brake,
:ignal,horn,display
1ameras,sonar,
:peedometer,;5:,
Jdometer,engine
sensors,keyboards,
accelerometer
Fi&#e 1.5 5EA: description of the task environment for an automated ta#i.
Fi&#e 1.6 E#amples of agent types and their 5EA: descriptions.
0#o/e#ties of tas8 e!+i#o!,e!ts
o Gully observable vs. partially observable
o 2eterministic vs. stochastic
o Episodic vs. se3uential
o :tatic vs. dynamic
o 2iscrete vs. continuous
o :ingle agent vs. multiagent
F%%) o-se#+a-%e vs. /a#tia%%) o-se#+a-%e.
If an agentHs sensors give it access to the complete state of the environment at each
point in time, then we say that the task environment is fully observable. A task envi?
ronment is effectively fully observable if the sensors detect all aspects that are relevant
to the choice of action8
An environment might be partially observable because of noisy and inaccurate sensors or because
parts of the state are simplly missing from the sensor data.
Dete#,i!isti$ vs. sto$hasti$.
If the ne#t state of the environment is completely determined by the current state and
the action e#ecuted by the agent, then we say the environment is deterministic8 other?
wise, it is stochastic.
E/iso"i$ vs. seEe!tia%
In an e/iso"i$ tas8 e!+i#o!,e!t, the agentHs e#perience is divided into atomic episodes.
Each episode consists of the agent perceiving and then performing a single action. 1ru?
cially, the ne#t episode does not depend on the actions taken in previous episodes.
Gor e#ample, an agent that has to spot defective parts on an assembly line bases each decision on
the current part, regardless of previous decisions8
In seEe!tia% e!+i#o!,e!ts, on the other hand, the current decision
could affect all future decisions. 1hess and ta#i driving are se3uential+
Dis$#ete vs. $o!ti!os.
*he discreteBcontinuous distinction can be applied to the state of the environment, to
the way time is handled, and to the percepts and actions of the agent. Gor e#ample, a
discrete?state environment such as a chess game has a finite number of distinct states.
1hess also has a discrete set of percepts and actions. *a#i driving is a continuous?
state and continuous?time problem+ the speed and location of the ta#i and of the other
vehicles sweep through a range of continuous values and do so smoothly over time.
*a#i?driving actions are also continuous -steering angles, etc.0.
Si!&%e a&e!t vs. ,%tia&e!t.
An agent solving a crossword pu%%le by itself is clearly in a
single?agent environment, whereas an agent playing chess is in a two?agent environ?
ment.
As one might e#pect, the hardest case is partially observable, stochastic, sequential, dynamic,
continuous, and multiagent.
Gigure &.F lists the properties of a number of familiar environments.
Fi&#e 1.7 E#amples of task environments and their characteristics.
A&e!t /#o&#a,s
*he agent programs all have the same skeleton+ they take the current percept as input from the
sensors and return an action to the actuatom) 9otice the difference between the a&e!t /#o&#a,,
which takes the current percept as input, and the a&e!t f!$tio!, which takes the entire percept
history. *he agent program takes "ust the current percept as input because nothing more is available
from the environment8 if the agentHs actions depend on the entire percept se3uence, the agent will
have to remember the percepts.
F!$tio! *AAEE?2RIME9QA;E9*-percept0 #et#!s an action
stati$+ percepts, a se3uence initially empty
table, a table of actions, inde#ed by percept se3uence
append percept to the end of percepts
action EJJKC5-percepts, table0
#et#! action
Fi&#e 1.? *he *AAEE?2RIME9?A;E9* program is invoked for each new percept and
returns a! action each time.
2rawbacks+
R Ta-%e %oo8/ of percept?action pairs defining all possible condition?action rules necessary
to interact in an environment
R 0#o-%e,s
7 *oo big to generate and to store -1hess has about &4S&@4 states, for e#ample0
7 9o knowledge of non?perceptual parts of the current state
7 9ot adaptive to changes in the environment8 re3uires entire table to be updated if
changes occur
7 Eooping+ 1anHt make actions conditional
R *ake a long time to build the table
R 9o autonomy
R Even with learning, need a long time to learn the table entries
So,e A&e!t T)/es
R Ta-%e-"#i+e! a&e!ts
7 use a percept se3uenceBaction table in memory to find the ne#t action. *hey are
implemented by a -large0 %oo8/ ta-%e.
R Si,/%e #ef%e3 a&e!ts
7 are based on $o!"itio!-a$tio! #%es, implemented with an appropriate production
system. *hey are stateless devices which do not have memory of past world states.
R A&e!ts 4ith ,e,o#)
7 have i!te#!a% state, which is used to keep track of past states of the world.
R A&e!ts 4ith &oa%s
7 are agents that, in addition to state information, have &oa% i!fo#,atio! that describes
desirable situations. Agents of this kind take future events into consideration.
R Uti%it)--ase" a&e!ts
7 base their decisions on $%assi$ a3io,ati$ ti%it) theo#) in order to act rationally.
Si,/%e Ref%e3 A&e!t
*he simplest kind of agent is the si,/%e #ef%e3 a&e!t. *hese agents select actions on the basis of the
current percept, ignoring the rest of the percept history. Gor e#ample, the vacuum agent whose agent function
is tabulated in Gigure &.&4 is a simple refle# agent, because its decision is based only on the current location
and on whether that contains dirt.
o :elect action on the basis of only the current percept.
E.g. the vacuum?agent
o Earge reduction in possible perceptBaction situations-ne#t page0.
o Implemented through condition-action rules
If dirty then suck
A Si,/%e Ref%e3 A&e!t. S$he,a
Fi&#e 1.A :chematic diagram of a simple refle# agent.
f!$tio! :I!5EE?REGEET?A;E9*-percept0 #et#!s an action
stati$+ rules, a set of condition?action rules
state I9*ER5RE*?I95C*-percept0
rule RCEE?!A*1.-state, rule0
action RCEE?A1*IJ9OruleP
return action
Fi&#e 1.1B A simple refle# agent. It acts according to a rule whose condition matches
the current state, as defined by the percept.
function REFLEX-VACUUM-AGENT ([location, status]) return an action
if status == Dirty then return Suck
ele if location == A then return Right
ele if location == B then return Left
Fi&#e 1.11 *he agent program for a simple refle# agent in the two?state vacuum environment. *his
program implements the agent function tabulated in the figure &.>.
Characteristics
o Jnly works if the environment is fully observable.
o Eacking history, easily get stuck in infinite loops
o Jne solution is to randomi%e actions
o
Mo"e%--ase" #ef%e3 a&e!ts
*he most effective way to handle partial observability is for the agent to keep track of the part of
the world it can't see now. *hat is, the agent should maintain some sort of i!te#!a% state that
depends on the percept history and thereby reflects at least some of the unobserved aspects of the
current state.
Cpdating this internal state information as time goes by re3uires two kinds of knowledge to be
encoded in the agent program. Girst, we need some information about how the world evolves
independently of the agent?for e#ample, that an overtaking car generally will be closer behind than
it was a moment ago. :econd, we need some information about how the agentHs own actions affect
the world?for e#ample, that when the agent turns the steering wheel clockwise, the car turns to the
right or that after driving for five minutes northbound on the freeway one is usually about five miles
north of where one was five minutes ago. *his knowledge about $how the world working ? whether
implemented in simple Aoolean circuits or in complete scientific theories?is called a ,o"e% of the
world. An agent that uses such a !J2EE?AA:E2 model is called a ,o"e%--ase" a&e!t.
Fi&#e 1.12 A model based refle# agent
f!$tio! REGEET?A;E9*?6I*.?:*A*E-percept0 #et#!s an action
stati$+ rules, a set of condition?action rules
state, a description of the current world state
action, the most recent action.
state C52A*E?:*A*E-state, action, percept0
rule RCEE?!A*1.-state, rule0
action RCEE?A1*IJ9OruleP
return action
Fi&#e 1.1' !odel based refle# agent. It keeps track of the current state of the world using an internal
model. It then chooses an action in the same way as the refle# agent.
Goa%--ase" a&e!ts
Knowing about the current state of the environment is not always enough to decide what to do. Gor e#ample, at a
road "unction, the ta#i can turn left, turn right, or go straight on. *he correct decision depends on where the ta#i is
trying to get to. In other words, as well as a current state description, the agent needs some sort of &oa%
information that describes situations that are desirable?for e#ample, being at the passengerHs destination. *he agent
program can combine this with information about the results of possible actions -the same information as
was used to update internal state in the refle# agent0 in order to choose actions that achieve the goal. Gigure
&.&= shows the goal?based agentHs structure.
Fi&#e 1.1* A goal based agent
Uti%it)--ase" a&e!ts
;oals alone are not really enough to generate high?3uality behavior in most environments. Gor
e#ample, there are many action se3uences that will get the ta#i to its destination -thereby achieving
the goal0 but some are 3uicker, safer, more reliable, or cheaper than others. ;oals "ust provide a
crude binary distinction between $happy$ and $unhappy$ states, whereas a more general
/e#fo#,a!$e ,eas#e should allow a comparison of different world states according to e#actly
how happy they would make the agent if they could be achieved. Aecause $happy$ does not sound
very scientific, the customary terminology is to say that if one world state is preferred to another,
then it has higher ti%it) for the agent.
Fi&#e 1.15 A model?based, utility?based agent. It uses a model of the world, along with
a utility function that measures its preferences among states of the world. *hen it chooses the
action that leads to the best e#pected utility, where e#pected utility is computed by averaging
over all possible outcome states, weighted by the probability of the outcome.
R 1ertain goals can be reached in different ways.
7 :ome are better, have a higher utility.
R Ctility function maps a -se3uence of0 state-s0 onto a real number.
R Improves on goals+
7 :electing between conflicting goals
7 :elect appropriately between several goals based on likelihood of success.
Fi&#e 1.16 A general model of learning agents.
R All agents can improve their performance through %ea#!i!&.
A learning agent can be divided into four conceptual components, as shown in Gigure &.&(
*he most important distinction is between the %ea#!i!& e%e,e!t, which is responsible for making
improvements, and the /e#fo#,a!$e e%e,e!t, which is responsible for selecting e#ternal actions.
*he performance element is what we have previously considered to be the entire agent+ it takes in
percepts and decides on actions. *he learning element uses feedback from the $#iti$ on how the
agent is doing and determines how the performance element should be modified to do better in the
future.
*he last component of the learning agent is the /#o-%e, &e!e#ato#. It is responsible
for suggesting actions that will lead to new and i!fo#,ati+e e3/e#ie!$es. Aut if the agent is willing
to e#plore a little, it might discover much better actions for the long run. *he problem
generatorHs "ob is to suggest these e3/%o#ato#) a$tio!s. *his is what scientists do when they
carry out e#periments.
S,,a#). I!te%%i&e!t A&e!ts
R An a&e!t perceives and acts in an environment, has an architecture, and is implemented by
an agent program.
R *ask environment 7 0EAS ;0erformanceD Environment, Actuators, Sensors<
R *he most challenging environments are inaccessible, nondeterministic, dynamic, and
continuous.
R An i"ea% a&e!t always chooses the action which ma#imi%es its e#pected performance, given
its percept se3uence so far.
R An a&e!t /#o&#a, maps from percept to action and updates internal state.
7 Ref%e3 a&e!ts respond immediately to percepts.
R simple refle# agents
R model?based refle# agents
7 Goa%--ase" a&e!ts act in order to achieve their goal-s0.
7 Uti%it)--ase" a&e!ts ma#imi%e their own utility function.
R All agents can improve their performance through %ea#!i!&.
1.'.1 0#o-%e, So%+i!& -) Sea#$h
An important aspect of intelligence is goal-based problem solving.
*he so%tio! of many /#o-%e,s can be described by finding a seEe!$e of a$tio!s that lead to a
desirable &oa%. Each action changes the state and the aim is to find the se3uence of actions and
states that lead from the initial -start0 state to a final -goal0 state.
A well?defined problem can be described by+
I!itia% state
O/e#ato# o# s$$esso# f!$tio! ? for any state # returns s-#0, the set of states reachable
from # with one action
State s/a$e ? all states reachable from initial by any se3uence of actions
0ath ? se3uence through state space
0ath $ost ? function that assigns a cost to a path. 1ost of a path is the sum of costs of
individual actions along the path
Goa% test ? test to determine if at goal state
What is Sea#$h?
Sea#$h is the systematic e#amination of states to find path from the sta#tF#oot state to the &oa%
state.
*he set of possible states, together with operators defining their connectivity constitute the search
space.
*he output of a search algorithm is a solution, that is, a path from the initial state to a state that
satisfies the goal test.
0#o-%e,-so%+i!& a&e!ts.
A 5roblem solving agent is a &oa%--ase" agent . It decide what to do by finding se3uence of actions
that lead to desirable states. *he agent can adopt a goal and aim at satisfying it.
*o illustrate the agentDs behavior ,let us take an e#ample where our agent is in the city of
Arad,which is in Romania. *he agent has to adopt a &oa% of getting to Aucharest.
Goa% fo#,%atio!,based on the current situation and the agentDs performance measure,is the first
step in problem solving.
*he agentDs task is to find out which se3uence of actions will get to a goal state.
0#o-%e, fo#,%atio! is the process of deciding what actions and states to consider given a goal.
E!a"#le$ Route %n&in' #ro(le"
Referrin' to %'ure )*)+
Jn holiday in Romania + currently in Arad.
Glight leaves tomorrow from Aucharest
Fo#,%ate &oa%+ be in Aucharest
Fo#,%ate /#o-%e,+
states+ various cities
a$tio!s+ drive between cities
Fi!" so%tio!+
se3uence of cities, e.g., Arad, :ibiu, Gagaras, Aucharest
5roblem formulation
A /#o-%e, is defined by four items+
i!itia% state e.g., at Arad$
s$$esso# f!$tio! :-#0 U set of action?state pairs
e.g., :-Arad0 U VOArad ?W Xerind8XerindP,,.Y
&oa% test, can be
e#plicit, e.g., # U at Aucharest$
implicit, e.g., 9o2irt-#0
/ath $ost -additive0
e.g., sum of distances, number of actions e#ecuted, etc.
c-#8 a8 y0 is the step cost, assumed to be WU 4
A so%tio! is a se3uence of actions leading from the initial state to a goal state.
Fi&#e 1.17 ;oal formulation and problem formulation
Sea#$h
An agent with several immediate options of unknown value can decide what to do by e#amining
different possible se3uences of actions that leads to the states of known value,and then choosing the
best se3uence. *he process of looking for se3uences actions from the current state to reach the goal
state is called sea#$h.
*he sea#$h a%&o#ith, takes a /#o-%e, as i!/t and returns a so%tio! in the form of a$tio!
seEe!$e. Jnce a solution is found,the e3e$tio! /hase consists of carrying out the recommended
action..
Gigure &.&/ shows a simple formulate,search,e#ecute design for the agent. Jnce solution has been
e#ecuted,the agent will formulate a new goal.
f!$tio! :I!5EE?5RJAEE!?:JEMI9;?A;E9*- percept0 #et#!s an action
i!/ts + percept, a percept
stati$+ seq, an action se3uence, initially empty
state, some description of the current world state
goal, a goal, initially null
problem, a problem formulation
state C52A*E?:*A*E-state, percept0
if se3 is empty the! "o
goal GJR!CEA*E?;JAE-state0
problem GJR!CEA*E?5RJAEE!-state, goal0
seq :EAR1.- problem0
action GIR:*-seq08
seq RE:*-se30
#et#! action
Fi&#e 1.1? A :imple problem solving agent. It first formulates a &oa% and a
/#o-%e,,searches for a se3uence of actions that would solve a problem,and e#ecutes the actions
one at a time.
*he agent design assumes the Environment is
R Stati$ + *he entire process carried out without paying attention to changes that
might be occurring in the environment.
R O-se#+a-%e . *he initial state is known and the agentDs sensor detects all aspects that
are relevant to the choice of action
R Dis$#ete . 6ith respect to the state of the environment and percepts and actions so
that alternate courses of action can be taken
R Dete#,i!isti$ . *he ne#t state of the environment is completely determined by the
current state and the actions e#ecuted by the agent. :olutions to the problem are
single se3uence of actions
An agent carries out its plan with eye closed. *his is called an open loop system because ignoring
the percepts breaks the loop between the agent and the environment.
1.'.1.1 We%%-"efi!e" /#o-%e,s a!" so%tio!s
A /#o-%e, can be formally defined by fo# $o,/o!e!ts+
*he i!itia% state that the agent starts in . *he initial state for our agent of e#ample problem is
described by n!"rad#
A S$$esso# F!$tio! returns the possible a$tio!s available to the agent. ;iven a state
#,:C11E::JR?G9-#0 returns a set of Vaction,successorY ordered pairs where each action is
one of the legal actions in state #,and each successor is a state that can be reached from # by
applying the action.
Gor e#ample,from the state In-Arad0,the successor function for the Romania problem would
return
V O;o-:ibiu0,In-:ibiu0P,O;o-*imisoara0,In-*imisoara0P,O;o-Xerind0,In-Xerind0P Y
State S/a$e + *he set of all states reachable from the initial state. *he state space forms a
graph in which the nodes are states and the arcs between nodes are actions.
A /ath in the state space is a se3uence of states connected by a se3uence of actions.
*hr &oa% test determines whether the given state is a goal state.
A /ath $ost function assigns numeric cost to each action. Gor the Romania problem the cost
of path might be its length in kilometers.
*he ste/ $ost of taking action a to go from state # to state y is denoted by c-#,a,y0. *he step
cost for Romania are shown in figure &.&/. It is assumed that the step costs are non negative.
A so%tio! to the problem is a path from the initial state to a goal state.
An o/ti,a% so%tio! has the lowest path cost among all solutions.
Fi&#e 1.1A A simplified Road !ap of part of Romania
1.'.2 EGAM0LE 0RO1LEMS
*he problem solving approach has been applied to a vast array of task environments. :ome
best known problems are summari%ed below. *hey are distinguished as toy or real?world
problems
A to) /#o-%e, is intended to illustrate various problem solving methods. It can be easily
used by different researchers to compare the performance of algorithms.
A #ea% 4o#%" /#o-%e, is one whose solutions people actually care about.
1.'.2.1 TO2 0RO1LEMS
Va$, Wo#%" E3a,/%e
o States+ *he agent is in one of two locations.,each of which might or might not contain dirt.
*hus there are @ # @
@
U / possible world states.
o I!itia% state+ Any state can be designated as initial state.
o S$$esso# f!$tio! + *his generates the legal states that results from trying the three actions
-left, right, suck0. *he complete state space is shown in figure @.=
o Goa% Test + *his tests whether all the s3uares are clean.
o 0ath test + Each step costs one ,so that the the path cost is the number of steps in the path.
Va$, Wo#%" State S/a$e
Fi&#e 1.2B *he state space for the vacuum world.
Arcs denote actions+ E U Eeft,R U Right,: U :uck
The ?-/HH%e
An /?pu%%le consists of a =#= board with eight numbered tiles and a blank space. A tile ad"acent to
the balank space can slide into the space. *he ob"ect is to reach the goal state ,as shown in figure @.>
E3a,/%e. The ?-/HH%e
Fi&#e 1.21 A typical instance of /?pu%%le.
*he problem formulation is as follows +
o States + A state description specifies the location of each of the eight tiles and the blank in
one of the nine s3uares.
o I!itia% state + Any state can be designated as the initial state. It can be noted that any given
goal can be reached from e#actly half of the possible initial states.
o S$$esso# f!$tio! + *his generates the legal states that result from trying the four
actions-blank moves Eeft,Right,Cp or down0.
o Goa% Test + *his checks whether the state matches the goal configuration shown in figure
@.>.-Jther goal configurations are possible0
o 0ath $ost + Each step costs &,so the path cost is the number of steps in the path.
o
The ??/HH%e belongs to the family of s%i"i!&--%o$8 /HH%es,which are often used as test
problems for new search algorithms in AI. *his general class is known as 95?complete.
*he ??/HH%e has 'ZB@ U &/&,>>4 reachable states and is easily solved.
*he 15 /HH%e - > # > board 0 has around &.= trillion states,an the random instances can be
solved optimally in few milli seconds by the best search algorithms.
*he 2*-/HH%e -on a ( # ( board0 has around &4
@(
states ,and random instances are still 3uite
difficult to solve optimally with current machines and algorithms.
/?3ueens problem
*he goal of /?3ueens problem is to place / 3ueens on the chessboard such that no 3ueen
attacks any other.-A 3ueen attacks any piece in the same row,column or diagonal0.
Gigure @.( shows an attempted solution that fails+ the 3ueen in the right most column is
attacked by the 3ueen at the top left.
An I!$#e,e!ta% fo#,%atio! involves operators that augments the state description,starting
with an empty state.for /?3ueens problem,this means each action adds a 3ueen to the state.
A $o,/%ete-state fo#,%atio! starts with all / 3ueens on the board and move them around.
In either case the path cost is of no interest because only the final state counts.
Fi&#e 1.22 /?3ueens problem
*he first incremental formulation one might try is the following +
o States + Any arrangement of 4 to / 3ueens on board is a state.
o I!itia% state + 9o 3ueen on the board.
o S$$esso# f!$tio! + Add a 3ueen to any empty s3uare.
o Goa% Test + / 3ueens are on the board,none attacked.
In this formulation,we have )>.)=,(F U = # &4
&>
possible se3uences to investigate.
A better formulation would prohibit placing a 3ueen in any s3uare that is already attacked. +
o States + Arrangements of n 3ueens - 4 [U n [ U / 0 ,one per column in the left most
columns ,with no 3ueen attacking another are states.
o S$$esso# f!$tio! + Add a 3ueen to any s3uare in the left most empty column such that it is
not attacked by any other 3ueen.
*his formulation reduces the /?3ueen state space from = # &4
&>
to "ust @4(F,and solutions are
easy to find.
Gor the &44 3ueens the initial formulation has roughly &4
>44
states whereas the improved
formulation has about &4
(@
states. *his is a huge reduction,but the improved state space is still
too big for the algorithms to handle.
1.'.2.2 REAL-WORLD 0RO1LEMS
ROUTE-FINDING 0RO1LEM
Route?finding problem is defined in terms of specified locations and transitions along links
between them. Route?finding algorithms are used in a variety of applications,such as routing in
computer networks,military operations planning,and air line travel planning systems.
AIRLINE TRAVEL 0RO1LEM
*he ai#%i!e t#a+e% /#o-%e, is specifies as follows .
o States . Each is represented by a location-e.g.,an airport0 and the current time.
o I!itia% state . *his is specified by the problem.
o S$$esso# f!$tio! . *his returns the states resulting from taking any scheduled
flight-further specified by seat class and location0,leaving later than the current time plus
the within?airport transit time,from the current airport to another.
o Goa% Test . Are we at the destination by some prespecified time\
o 0ath $ost . *his depends upon the monetary cost,waiting time,flight time,customs and
immigration procedures,seat 3uality,time of dat,type of air plane,fre3uent?flyer mileage
awards, and so on.

TOURING 0RO1LEMS
To#i!& /#o-%e,s are closely related to route?finding problems,but with an important difference.
1onsider for e#ample,the problem,Misit every city at least once as shown in Romania map.
As with route?finding the actions correspond to trips between ad"acent cities. *he state space,
however,is 3uite different.
*he initial state would be In Aucharest8 visitedVAucharestY.
A typical intermediate state would be In Maslui8visited VAucharest,Cr%iceni,MasluiY.
*he goal test would check whether the agent is in Aucharest and all @4 cities have been visited.
T(E TRAVELLING SALES0ERSON 0RO1LEM;TS0<
Is a touring problem in which each city must be visited e#actly once. *he aim is to find the
shortest tour.*he problem is known to be N0-ha#". Enormous efforts have been e#pended to
improve the capabilities of *:5 algorithms. *hese algorithms are also used in tasks such as
planning movements of ato,ati$ $i#$it--oa#" "#i%%s and of sto$8i!& ,a$hi!es on shop
floors.
VLSI %a)ot
A VLSI %a)ot problem re3uires positioning millions of components and connections on a chip
to minimi%e area ,minimi%e circuit delays,minimi%e stray capacitances,and ma#imi%e
manufacturing yield. *he layout problem is split into two parts + $e%% %a)ot and $ha!!e%
#oti!&.
RO1OT !a+i&atio!
RO1OT !a+i&atio! is a generali%ation of the route?finding problem. Rather than a discrete set
of routes,a robot can move in a continuous space with an infinite set of possible actions and
states. Gor a circular Robot moving on a flat surface,the space is essentially two?dimensional.
6hen the robot has arms and legs or wheels that also must be controlled,the search space
becomes multi?dimensional. Advanced techni3ues are re3uired to make the search space finite.
AUTOMATIC ASSEM1L2 SEIUENCING
*he e#ample includes assembly of intricate ob"ects such as electric motors. *he aim in assembly
problems is to find the order in which to assemble the parts of some ob"ects. If the wrong order
is choosen,there will be no way to add some part later without undoing somework already done.
Another important assembly problem is protein design,in which the goal is to find a se3uence of
Amino acids that will be fold into a three?dimensional protein with the right properties to cure
some disease.
INTERNET SEARC(ING
In recent years there has been increased demand for software robots that perform Internet
searching.,looking for answers to 3uestions,for related information,or for shopping deals. *he
searching techni3ues consider internet as a graph of nodes-pages0 connected by links.
1.'.' SEARC(ING FOR SOLUTIONS
SEARC( TREE
.aving formulated some /#o-%e,s,we now need to so%+e them. *his is done by a sea#$h through
the state s/a$e. A sea#$h t#ee is generated by the i!itia% state and the s$$esso# f!$tio! that
together define the state s/a$e. In general,we may have a search graph rather than a search
tree,when the same state can be reached from multiple paths.
Gigure &.@= shows some of the e#pansions in the search tree for finding a route from Arad to
Aucharest.
Fi&#e 1.2' 5artial search trees for finding a route from Arad to Aucharest. 9odes that have
been e#panded are shaded.8 nodes that have been generated but not yet e#panded are outlined in
bold8nodes that have not yet been generated are shown in faint dashed line
*he root of the search tree is a sea#$h !o"e corresponding to the initial state,In-Arad0. *he first
step is to test whether this is a &oa% state. *he current state is e#panded by applying the successor
function to the current state,thereby generating a new set of states. In this case,we get three new
states+ In-:ibiu0,In-*imisoara0,and In-Xerind0. 9ow we must choose which of these three
possibilities to consider further. *his is the essense of search? following up one option now and
putting the others aside for latter,in case the first choice does not lead to a solution.
Sea#$h st#ate&) . *he general tree?search algorithm is described informally in Gigure &.@>
.
T#ee Sea#$h
Fi&#e 1.2* An informal description of the general tree?search algorithm
*he choice of which state to e#pand is determined by the sea#$h st#ate&). *here are an infinite
number paths in this state space ,so the search tree has an infinite number of !o"es.
A !o"e is a data structure with five components +
o :*A*E + a state in the state space to which the node corresponds8
o 5ARE9*?9J2E + the node in the search tree that generated this node8
o A1*IJ9 + the action that was applied to the parent to generate the node8
o 5A*.?1J:* +the cost,denoted by g-n0,of the path from initial state to the node,as
indicated by the parent pointers8 and
o 2E5*. + the number of steps along the path from the initial state.
It is important to remember the distinction between nodes and states. A node is a book keeping
data structure used to represent the search tree. A state corresponds to configuration of the world.
Fi&#e 1.25 9odes are data structures from which the search tree is
constructed. Each has a parent,a state, Arrows point from child to parent.
Gringe
Gringe is a collection of nodes that have been generated but not yet been e#panded. Each element
of the fringe is a leaf node,that is,a node with no successors in the tree. *he fringe of each tree
consists of those nodes with bold outlines.
*he collection of these nodes is implemented as a Eee.
*he general tree search algorithm is shown in Gigure @.'
Fi&#e 1.26 *he general *ree search algorithm
*he operations specified in Gigure &.@) on a 3ueue are as follows+
o MA=E-IUEUE;e%e,e!tDJ< creates a 3ueue with the given element-s0.
o EM0T2?;Eee< returns true only if there are no more elements in the 3ueue.
o FIRST;Eee< returns GIR:*-3ueue0 and removes it from the 3ueue.
o INSERT;e%e,e!tDEee< inserts an element into the 3ueue and returns the resulting
3ueue.
o INSERT-ALL;e%e,e!tsDEee< inserts a set of elements into the 3ueue and returns the
resulting 3ueue.
MEASURING 0RO1LEM-SOLVING 0ERFORMANCE
*he output of problem?solving algorithm is either failure or a solution.-:ome algorithms might
struck in an infinite loop and never return an output.
*he algorithmDs performance can be measured in four ways +
o Co,/%ete!ess + Is the algorithm guaranteed to find a solution when there is one\
o O/ti,a%it) + 2oes the strategy find the optimal solution
o Ti,e $o,/%e3it) + .ow long does it take to find a solution\
o S/a$e $o,/%e3it) + .ow much memory is needed to perform the search\
1.'.* UNINFORMED SEARC( STRATGES
U!i!fo#,e" Sea#$h St#ate&ies have no additional information about states beyond that provided
in the /#o-%e, "efi!itio!.
St#ate&ies that know whether one non goal state is more promising than another are called
I!fo#,e" sea#$h o# he#isti$ sea#$h strategies.
*here are five uninformed search strategies as given below.
o Areadth?first search
o Cniform?cost search
o 2epth?first search
o 2epth?limited search
o Iterative deepening search
&.=.>.& Areadth?first search
Areadth?first search is a simple strategy in which the root node is e#panded first,then all
successors of the root node are e#panded ne#t,then their successors,and so on. In general,all the
nodes are e#panded at a given depth in the search tree before any nodes at the ne#t level are
e#panded.
Areath?first?search is implemented by calling *REE?:EAR1. with an empty fringe that is a
first?in?first?out-GIGJ0 3ueue,assuring that the nodes that are visited first will be e#panded first.
In otherwards,calling *REE?:EAR1.-problem,GIGJ?LCECE-00 results in breadth?first?search.
*he GIGJ 3ueue puts all newly generated successors at the end of the 3ueue,which means that
:hallow nodes are e#panded before deeper nodes.
Fi&#e 1.27 Areadth?first search on a simple binary tree. At each stage ,the node to be e#panded ne#t is
indicated by a marker.
0#o/e#ties of -#ea"th-fi#st-sea#$h
Fi&#e 1.2? Areadth?first?search properties
Fi&#e 1.2A *ime and memory re3uirements for breadth?first?search.
*he numbers shown assume branch factor of b U &4 8 &4,444
nodesBsecond8 &444 bytesBnode
Ti,e $o,/%e3it) fo# 1FS
Assume every state has b successors. *he root of the search tree generates b nodes at the first
level,each of which generates b more nodes,for a total of b
@
at the second level. Each of these
generates b more nodes,yielding b
=
nodes at the third level,and so on. 9ow suppose,that the
solution is at depth d. In the worst case,we would e#pand all but the last node at level
d,generating b
d]&
? b nodes at level d]&.
*hen the total number of nodes generated is
b ] b
@
] b
=
] ,] b
d
] - b
d]&
] b0 U J-b
d]&0.
Every node that is generated must remain in memory,because it is either part of the fringe or is an
ancestor of a fringe node. *he space compleity is,therefore ,the same as the time comple#ity
1.'.*.2 UNIFORM-COST SEARC(
Instead of e#panding the shallowest node,!ifo#,-$ost sea#$h e#pands the node n with the
lowest path cost. uniform?cost search does not care about the number of steps a path has,but only
about their total cost.
Fi&#e 1.'B 5roperties of Cniform?cost?search
2.5.1.' DE0T(-FIRST-SEARC(
2epth?first?search always e#pands the deepest node in the current fringe of the search tree. *he
progress of the search is illustrated in figure &.=&. *he search proceeds immediately to the
deepest level of the search tree,where the nodes have no successors. As those nodes are
e#panded,they are dropped from the fringe,so then the search backs up to the ne#t shallowest
node that still has une#plored successors.
Fi&#e 1.'1 2epth?first?search on a binary tree. 9odes that have been e#panded and have no
descendants in the fringe can be removed from the memory8these are shown in black. 9odes at
depth = are assumed to have no successors and ! is the only goal node.
*his strategy can be implemented by *REE?:EAR1. with a last?in?first?out -EIGJ0 3ueue,also
known as a stack.
2epth?first?search has very modest memory re3uirements.It needs to store only a single path
from the root to a leaf node,along with the remaining une#panded sibling nodes for each node on
the path. Jnce the node has been e#panded,it can be removed from the memory,as soon as its
descendants have been fully e#plored-Refer Gigure @.&@0.
Gor a state space with a branching factor b and ma#imum depth m,depth?first?search re3uires
storage of only bm ] & nodes.
Csing the same assumptions as Gigure @.&&,and assuming that nodes at the same depth as the goal
node have no successors,we find the depth?first?search would re3uire &&/ kilobytes instead of &4
petabytes,a factor of &4 billion times less space.
D#a4-a$8 of De/th-fi#st-sea#$h
*he drawback of depth?first?search is that it can make a wrong choice and get stuck going down
very long-or even infinite0 path when a different choice would lead to solution near the root of the
search tree. Gor e#ample ,depth?first?search will e#plore the entire left subtree even if node 1 is a
goal node.
1AC=TRAC=ING SEARC(
A variant of depth?first search called backtracking search uses less memory and only one successor
is generated at a time rather than all successors.8 Jnly J-m0 memory is needed rather than J-bm0
1.'.*.* DE0T(-LIMITED-SEARC(
*he problem of unbounded trees can be alleviated by supplying depth?first?search with a pre?
determined depth limit l.*hat is,nodes at depth l are treated as if they have no successors. *his
approach is called "e/th-%i,ite"-sea#$h. *he depth limit soves the infinite path problem.
2epth limited search will be nonoptimal if we choose l W d. Its time comple#ity is J-b
l
0 and its
space compleiy is J-bl0. 2epth?first?search can be viewed as a special case of depth?limited search
with l U oo
:ometimes,depth limits can be based on knowledge of the problem. Gor,e#ample,on the map of
Romania there are @4 cities. *herefore,we know that if there is a solution.,it must be of length &' at
the longest,:o l U &4 is a possible choice. .owever,it oocan be shown that any city can be reached
from any other city in at most ' steps. *his number known as the "ia,ete# of the state space,gives
us a better depth limit.
2epth?limited?search can be implemented as a simple modification to the general tree?search
algorithm or to the recursive depth?first?search algorithm. *he pseudocode for recursive depth?
limited?search is shown in Gigure &.=@.
It can be noted that the above algorithm can terminate with two kinds of failure + the standard
failure value indicates no solution8 the cutoff value indicates no solution within the depth limit.
2epth?limited search U depth?first search with depth limit l,
returns cut off if any path is cut off by depth limit
f!$tio! 2epth?Eimited?:earch- problem, limit0 #et#!s a solutionBfailBcutoff
#et#! Recursive?2E:-!ake?9ode-Initial?:tateOproblemP0, problem, limit0
f!$tio! Recursive?2E:-node, problem, limit0 returns solutionBfailBcutoff
cutoff?occurred\ false
if ;oal?*est-problem,:tateOnodeP0 then #et#! :olution-node0
e%se if 2epthOnodeP U limit the! #et#! cutoff
e%se fo# ea$h successor i! E#pand-node, problem0 "o
result Recursive?2E:-successor, problem, limit0
if result U cutoff then cutoffQoccurred\ true
e%se if result not U failure the! #et#! result
if cutoffQoccurred\ then return cutoff e%se #et#! failure
Fi&#e 1.'2 Recursive implementation of 2epth?limited?search+
1.'.*.5 ITERATIVE DEE0ENING DE0T(-FIRST SEARC(
Iterative deepening search -or iterative?deepening?depth?first?search0 is a general strategy often
used in combination with depth?first?search,that finds the better depth limit. It does this by
gradually increasing the limit 7 first 4,then &,then @, and so on 7 until a goal is found. *his will
occur when the depth limit reaches d,the depth of the shallowest goal node. *he algorithm is shown
in Gigure @.&>.
Iterative deepening combines the benefits of depth?first and breadth?first?search
Eike depth?first?search,its memory re3uirements are modest8J-bd0 to be precise.
Eike Areadth?first?search,it is complete when the branching factor is finite and optimal when the
path cost is a non decreasing function of the depth of the node.
Gigure @.&( shows the four iterations of I*ERA*IME?2EE5E9I9;Q:EAR1. on a binary search
tree,where the solution is found on the fourth iteration.
Fi&#e 1.'' *he ite#ati+e "ee/e!i!& sea#$h a%&o#ith, ,which repeatedly applies depth?limited?
search with increasing limits. It terminates when a solution is found or if the depth limited search
resturns failure,meaning that no solution e#ists.
Fi&#e 1.'* Gour iterations of iterative deepening search on a binary tree
Iterative search is not as wasteful as it might seem
Fi&#e 1.'5
Iterative search is not as wasteful as it might seem
,ro#ertie of iterati-e &ee#enin' earch
Fi'ure )*./
Iterative deepening search
S
S
A D
S
S
A D
S
S
A D
1 D A E
Eimit U 4
Eimit U &
Eimit U @
In general,iterative deepening is the prefered uninformed search method when there is a
large search space and the depth of solution is not known.
1.'.*.6 1i"i#e$tio!a% Sea#$h
*he idea behind bidirectional search is to run two simultaneous searches 7
one forward from he initial state and
the other backward from the goal,
stopping when the two searches meet in the middle -Gigure &.=F0
*he motivation is that b
dB@
] b
dB@
much less than ,or in the figure ,the area of the two small circles is
less than the area of one big circle centered on the start and reaching to the goal.
Fi&#e 1.'7 A schematic view of a bidirectional search that is about to succeed,when a
Aranch from the :tart node meets a Aranch from the goal node.
1.'.*.7 Co,/a#i!& U!i!fo#,e" Sea#$h St#ate&ies
Gigure &.=/ compares search strategies in terms of the four evaluation criteria .
Fi&#e 1.'? Evaluation of search strategies,b is the branching factor8 d is the depth of the
shallowest solution8 m is the ma#imum depth of the search tree8 l is the depth limit. :uperscript
caveats are as follows+
a
complete if b is finite8
b
complete if step costs WU E for positive E8
c
optimal if step costs are all identical8
d
if both directions use breadth?first search.
1.'.5 AVOIDING RE0EATED STATES
In searching,time is wasted by e#panding states that have already been encountered and
e#panded before. Gor some problems repeated states are unavoidable. *he search trees for these
problems are infinite. If we prune some of the repeated states,we can cut the search tree down to
finite si%e. 1onsidering search tree upto a fi#ed depth,eliminating repeated states yields an
e#ponential reduction in search cost.
Repeated states ,can cause a solvable problem to become unsolvable if the algorithm does not detect
them.
Repeated states can be the source of great inefficiency+ identical sub trees will be e#plored many
timesZ
Fi&#e 1.'A
Fi&#e 1.*B
1
1
C C C
C
A
A
1
C
Fi&#e 1.*1 *he ;eneral graph search algorithm. *he set closed can be implemented with a hash
table to allow efficient checking for repeated states.
2o not return to the previous state.
R 2o not create paths with cycles.
R 2o not generate the same state twice.
? :tore states in a hash table.
- 1heck for repeated states.
o Csing more memory in order to check repeated state
o "lgorithms that forget their history are doomed to repeat it.
o !aintain 1lose?Eist beside Jpen?Eist-fringe0
St#ate&ies fo# a+oi"i!& #e/eate" states
6e can modify the general *REE?:EAR1. algorithm to include the data structure called the
$%ose" %ist ,which stores every e#panded node. *he fringe of une#panded nodes is called the o/e!
%ist.
If the current node matches a node on the closed list,it is discarded instead of being e#panded.
*he new algorithm is called ;RA5.?:EAR1. and much more efficient than *REE?:EAR1.. *he
worst case time and space re3uirements may be much smaller than J-b
d
0.
1.'.6 SEARC(ING WIT( 0ARTIAL INFORMATION
o 2ifferent types of incompleteness lead to three distinct problem types+
o Se!so#%ess /#o-%e,s -conformant0+ If the agent has no sensors at all
o Co!ti!&e!$) /#o-%e,+ if the environment if partially observable or if
action are uncertain -adversarial0
o E3/%o#atio! /#o-%e,s+ 6hen the states and actions of the environment
are unknown.
o 9o sensor
o Initial :tate-&,@,=,>,(,),F,/0
o After action ORightP the state -@,>,),/0
o After action O:uckP the state ->, /0
o After action OEeftP the state -=,F0
o After action O:uckP the state -/0
o Answer + ORight,:uck,Eeft,:uckP coerce the world into state F without any
sensor
o Aelief :tate+ :uch state that agent belief to be there
-:EI2E F0 5artial knowledge of states and actions+
sensorless or conformant problem
Agent may have no idea where it is8 solution -if any0 is a se3uence.
contingency problem
5ercepts provide new information about current state8 solution is a tree or
policy8 often interleave search and e#ecution.
If uncertainty is caused by actions of another agent+ adversarial problem
exploration problem
6hen states and actions of the environment are unknown.
Gigure
Gigure
1ontingency, start in V&,=Y.
!urphyDs law, :uck can dirty a clean carpet.
Eocal sensing+ dirt, location only.
5ercept U OE,2irtyP UV&,=Y
O:uckP U V(,FY
ORightP UV),/Y
O:uckP in V)YUV/Y -:uccess0
AC* O:uckP in V/Y U failure
:olution\\
Aelief?state+ no fi#ed action se3uence guarantees solution
Rela# re3uirement+
O$uck, %ight, if &%,dirty' then $uckP
:elect actions based on contingencies arising during e#ecution.
*ime and space comple#ity are always considered with respect to some measure of the problem
difficulty. In theoretical computer science ,the typical measure is the si%e of the state space.
In AI,where the graph is represented implicitly by the initial state and successor function,the
comple#ity is e#pressed in terms of three 3uantities+
-,the -#a!$hi!& fa$to# or ma#imum number of successors of any node8
",the "e/th of the sha%%o4est &oa% !o"e8 and
,,the ,a3i,, %e!&th of any path in the state space.
Sea#$h-$ost ? typically depends upon the time comple#ity but can also include the term for
memory usage.
Tota%@$ost @ It combines the search?cost and the path cost of the solution found.

You might also like