2 INTELLIGENT AGENTS
function TABLE-DRIVEN-AGENT( ) returns an action static: , a sequence, initially empty
, a table of actions, indexed by percept sequences, initially fully specified append to the end of
LOOKUP( , ) return
Figure 2.8
function REFLEX-VACUUM-AGENT( [ , !" ]) returns an action if !" =# $ % then return& !'
else if( =) then return* (+, else if( =- then return. 0/
Figure 2.10
function SIMPLE-REFLEX-AGENT( ) returns an action static: !1, a set of condition–action rules
2 INTERPRET-INPUT( )
!12 RULE-MATCH( 3 ,!" ) RULE-ACTION[!1 ] return
Figure 2.13
2
function REFLEX-AGENT-WITH-STATE( ) returns an action static: 3 , a description of the current world state
!1 , a set of condition–action rules , the most recent action, initially none
2 UPDATE-STATE( 3 , , )
!12 RULE-MATCH( 3 ,!" ) RULE-ACTION[!1 ] return
Figure 2.16
3 SOLVING PROBLEMS BY SEARCHING
function SIMPLE-PROBLEM-SOLVING-AGENT(4 ) returns an action inputs:4 , a percept
static: 5, an action sequence, initially empty
3 , some description of the current world state
+, a goal, initially null
6 , a problem formulation
2 UPDATE-STATE( 3 , ) if 5 is empty then do
+ FORMULATE-GOAL( )
4 67 FORMULATE-PROBLEM( 3 ,+)
58 SEARCH(6 ) FIRST( 5 )
59 REST(5) return
Figure 3.2
function TREE-SEARCH(6 , 3+% ) returns a solution, or failure initialize the search tree using the initial state of6
loop do
if there are no candidates for expansion then return failure choose a leaf node for expansion according to 3+%
if the node contains a goal state then return the corresponding solution else expand the node and add the resulting nodes to the search tree
Figure 3.9
4
function TREE-SEARCH(6;:0/$1+ ) returns a solution, or failure
/0+1<
INSERT(MAKE-NODE(INITIAL-STATE[6 ]),/$1+ ) loop do
if EMPTY?(/$+1 ) then return failure
=2 REMOVE-FIRST(/0+1 )
if GOAL-TEST[6 ] applied to STATE[>=] succeeds then return SOLUTION(= )
/$1+<
INSERT-ALL(EXPAND(= ,6 ),/$1+ ) function EXPAND(>=:6 ) returns a set of nodes
!? the empty set
for each@ , !1 A in SUCCESSOR-FN[6 ](STATE[>= ]) do
B a new NODE
STATE[]C !1 PARENT-NODE[ ]D>=
ACTION[]E
PATH-COST[] PATH-COST[= ] + STEP-COST(>=, , ) DEPTH[ ] DEPTH[= ] + 1
add to!
return!
Figure 3.12
function DEPTH-LIMITED-SEARCH(4 6 ,06F$ ) returns a solution, or failure/cutoff return RECURSIVE-DLS(MAKE-NODE(INITIAL-STATE[6 ]),6 ,$6F$ ) function RECURSIVE-DLS(>= ,6 ,$6F$ ) returns a solution, or failure/cutoff
!1 G !1 =H2
false
if GOAL-TEST[6 ](STATE[>=]) then return SOLUTION(= ) else if DEPTH[>= ] =06F$ then return!" 3IG
else for each! in EXPAND(= ,6 ) do
!1J 4
RECURSIVE-DLS(! ,6 ,$6F$ ) if !1 =!1 IG then!1 IG !1 =H2 true else if !1 LKM /$!1 then return !"
if!1 IG !1 =H then return!" 3IG else return/$!1
Figure 3.17
6 Chapter 3. Solving Problems by Searching
function ITERATIVE-DEEPENING-SEARCH(6 ) returns a solution, or failure inputs:6 , a problem
for= 0,N 0 toO do
!1J 4
DEPTH-LIMITED-SEARCH(6 ,=4 , ) if !1 LKM cutoff then return!1J
Figure 3.19
function GRAPH-SEARCH(6P:0/$1+ ) returns a solution, or failure
( =Q an empty set
/0+1<
INSERT(MAKE-NODE(INITIAL-STATE[6 ]),/$1+ ) loop do
if EMPTY?(/$+1 ) then return failure
=2 REMOVE-FIRST(/0+1 )
if GOAL-TEST[6 ](STATE[= ]) then return SOLUTION(>= ) if STATE[= ] is not in( = then
add STATE[>= ] to( =
/$1+<
INSERT-ALL(EXPAND(= ,4 6 ),/$1+ )
Figure 3.25
function RECURSIVE-BEST-FIRST-SEARCH(6 ) returns a solution, or failure RBFS(6 , MAKE-NODE(INITIAL-STATE[6 ]),O )
function RBFS(6 ,>= ,/ $6F0 ) returns a solution, or failure and a newR -cost limit if GOAL-TEST[6 ]( 3 ) then return>=
!? EXPAND(= ,6 ) if !4 is empty then return/$!" ,O for each in! do
R [s]TSVUWYX0Z>XI[]\_^]XI[:
R2`
=a0[
repeat
4 the lowestR -value node in! ifR2` acbC/ J$6F$ then return/$J!1 ,R [ ]
J > $de2
the second-lowestR -value among!
!1J
,R [ ] RBFS(4 6 , ,Sgf(h?X/ 06F$ :i $d[) if !1 LKM /$!1 then return !"
Figure 4.6
function HILL-CLIMBING(6 ) returns a state that is a local maximum inputs:6 , a problem
local variables: !14 , a node
>(+,"
, a node
!1 4
MAKE-NODE(INITIAL-STATE[6 ]) loop do
>(+," 8
a highest-valued successor of!1
if VALUE[neighbor]j VALUE[current] then return STATE[!1 4 ]
!14 4DY+,
Figure 4.13
8 Chapter 4. Informed Search and Exploration
function SIMULATED-ANNEALING(6 ,, =!1 ) returns a solution state inputs:6 , a problem
,=!1 , a mapping from time to “temperature”
local variables: !14 , a node
>k
, a node
l
, a “temperature” controlling the probability of downward steps
!1 4
MAKE-NODE(INITIAL-STATE[6 ]) for 4 1 toO do
l
C, =!"
[ ]
if l = 0 then return!" 4
>k
a randomly selected successor of!" 4
mon
VALUE[>k ] – VALUE[!" 4 ] if
mgn
b 0 then!14 4DY k
else!14 4DY k only with probabilitypiq2rBsIt
Figure 4.17
function GENETIC-ALGORITHM("!1 , FITNESS-FN) returns an individual inputs:"!1 , a set of individuals
FITNESS-FN, a function that measures the fitness of an individual repeat
>u "!1(
empty set
loop for from 1 to SIZE("!1 ) do
kv RANDOM-SELECTION("4!"(
, FITNESS-FN)
%w RANDOM-SELECTION("!1( , FITNESS-FN)
,$=Q REPRODUCE(k ,% )
if (small random probability) then,$(=v MUTATE(,0(= ) add,$(= toYu "!1(
"!1 xC>u "!1(
until some individual is fit enough, or enough time has elapsed return the best individual in"!1 , according to FITNESS-FN
function REPRODUCE(k ,% ) returns an individual inputs:k ,% , parent individuals
LENGTH(k )
< random number from 1 to
return APPEND(SUBSTRING(k , 1, ), SUBSTRING(% ,y\{z , ))
Figure 4.21
function ONLINE-DFS-AGENT( ) returns an action inputs: |, a percept that identifies the current state
static: !1 , a table, indexed by action and state, initially empty
!1Y k( =
, a table that lists, for each visited state, the actions not yet tried
!1Y e' 'e =
, a table that lists, for each visited state, the backtracks not yet tried
, , the previous state and action, initially null if GOAL-TEST( |) then return
if | is a new state then!1Yk( = [ |] ACTIONS( |) if is not null then do
!1J
[ ,]D |
add to the front of!1Y e' 'e =
[ |] if!1>k4 =
[ |] is empty then if!1Y e' 'e =
[ |] is empty then return
elsew an action such that !1 [ , |] = POP(!1Y e' 'e =
[ |]) elseL POP(!1Y k( = [ |])
<D |
return
Figure 4.25
function LRTA*-AGENT( |) returns an action inputs: |, a percept that identifies the current state
static: !1 , a table, indexed by action and state, initially empty
}
, a table of cost estimates indexed by state, initially empty
, , the previous state and action, initially null if GOAL-TEST( |) then return
if | is a new state (not in} ) then} [ |]~^ ( |) unless is null
!1J
[ ,]D |
}
[ ] Sofh
ACTIONSI
LRTA*-COST( ,, !" [,],} )
L an action in ACTIONS(|) that minimizes LRTA*-COST(|, , !1 [ ,|],} )
<D
|
return
function LRTA*-COST( , , |,} ) returns a cost estimate if | is undefined then return^?X3i[
else return X3e: : |[g\ ` |a
Figure 4.29
5 CONSTRAINT SATISFACTION PROBLEMS
function BACKTRACKING-SEARCH( ) returns a solution, or failure return RECURSIVE-BACKTRACKING(9 , )
function RECURSIVE-BACKTRACKING( (+e46g4 ,3 ) returns a solution, or failure if(+e6g4 is complete then return (+e46g4
d8 SELECT-UNASSIGNED-VARIABLE(VARIABLES[3 ],(+e6g4 , ) for eachdJ!4 in ORDER-DOMAIN-VALUES(d , +46g4 , ) do
ifdJ!4 is consistent with +46g4 according to CONSTRAINTS[3 ] then add d =d!4 to(+e6g
!1J 4
RECURSIVE-BACKTRACKING((+e6g ,3 ) if!1J LKM /$J!1 then return !1
remove d =d!4 from(+46g return/$J!1
Figure 5.4
10
function AC-3(3 ) returns the CSP, possibly with reduced domains inputs:3 , a binary CSP with variablesi : g :: o
local variables: 5!4!4, a queue of arcs, initially all the arcs in3 while5!4! is not empty do
X
o
:
F
[4 REMOVE-FIRST(5!4!4 )
if REMOVE-INCONSISTENT-VALUES( : ) then for eachV in NEIGHBORS[o] do
add (c : ) to5!4!4
function REMOVE-INCONSISTENT-VALUES( : ) returns true iff we remove a value
6od =v/
for eachk in DOMAIN[ ] do
if no value in DOMAIN[ ] allows (k ,% ) to satisfy the constraint between and then deletek from DOMAIN[ ]; 6od =vD !4
return 6od =
Figure 5.9
function MIN-CONFLICTS( ,6oik ) returns a solution or failure inputs:3 , a constraint satisfaction problem
6oik , the number of steps allowed before giving up
!1 4
an initial complete assignment for for = 1 to6oik do
if!1 is a solution for then return!14
d8 a randomly chosen, conflicted variable from VARIABLES[ ]
d!<
the valued ford that minimizes CONFLICTS(d ,d ,!1 4 ,3 ) setd M dJ!4 in !" 4
return/$J!1
Figure 5.11
6 ADVERSARIAL SEARCH
function MINIMAX-DECISION( ) returns inputs: , current state in game
dw MAX-VALUE(state)
return the in SUCCESSORS( 3 ) with valued function MAX-VALUE( ) returnsF!1 $J$ %dJ!4
if TERMINAL-TEST( ) then return UTILITY( )
dwC
O
for4: in SUCCESSORS( 3 ) do
dw MAX(v, MIN-VALUE( )) returnd
function MIN-VALUE( 3 ) returnsx!1 $0 %dJ!4 if TERMINAL-TEST( ) then return UTILITY( )
dw
O
for4: in SUCCESSORS( 3 ) do
dw MIN(v, MAX-VALUE( )) returnd
Figure 6.4
12
function ALPHA-BETA-SEARCH( ) returns an action inputs: , current state in game
dw MAX-VALUE( , O ,\ O )
return the in SUCCESSORS( 3 ) with valued function MAX-VALUE( , , ) returnsx!" $J$ %Fd!4
inputs: , current state in game
, the value of the best alternative for MAXalong the path to
, the value of the best alternative for MINalong the path to if TERMINAL-TEST( ) then return UTILITY( )
dwC
O
for4: in SUCCESSORS( 3 ) do
dw MAX(v, MIN-VALUE( , , )) if then returnd
MAX( , v) returnd
function MIN-VALUE( 3 , , ) returnsF!1 $$ %d! inputs: , current state in game
, the value of the best alternative for MAXalong the path to
, the value of the best alternative for MINalong the path to if TERMINAL-TEST( ) then return UTILITY( )
dw~\
O
for4: in SUCCESSORS( 3 ) do
dw MIN(v, MAX-VALUE( , , )) ifj then returnd
MIN( , v) returnd
Figure 6.9
7 LOGICAL AGENTS
function KB-AGENT( ) returns an static:¡¢- , a knowledge base
, a counter, initially 0, indicating time TELL(¡¢- , MAKE-PERCEPT-SENTENCE( , ))
ASK(¡¢- , MAKE-ACTION-QUERY( )) TELL(¡¢- , MAKE-ACTION-SENTENCE( , ))
D + 1 return
Figure 7.2
function TT-ENTAILS?(¡¢- , ) returns !4 or/J
inputs:¡¢- , the knowledge base, a sentence in propositional logic
, the query, a sentence in propositional logic
%6g 2
a list of the proposition symbols in¡¢- and return TT-CHECK-ALL(¡N- , ,%6g ,`a)
function TT-CHECK-ALL(¡¢- , ,%6g ,6o=) returns !4 or/ if EMPTY?(%6g ) then
if PL-TRUE?(¡N- ,6o=) then return PL-TRUE?( ,6o=) else return !4
else do
£
FIRST(%6g ); 4 REST(%6g )
return TT-CHECK-ALL(¡¢- , , , EXTEND(£ : !4e:6o=) and TT-CHECK-ALL(¡¢- , , , EXTEND(£ :0/J:6o=)
Figure 7.12
14
function PL-RESOLUTION(¡¢- , ) returns !4 or/
inputs:¡¢- , the knowledge base, a sentence in propositional logic
, the query, a sentence in propositional logic
(!1B the set of clauses in the CNF representation of¡¢-_¤P¥9
Yu¦
9
loop do
for each§ ,§ in(!1 do
Jd4 B
PL-RESOLVE(§ ,§ )
ifde4 contains the empty clause then return !4
Yu¦DYu¨© de
ifYuǻ(!1 then return/
!"<¬(!1?¨cYu
Figure 7.15
function PL-FC-ENTAILS?(¡¢- ,5 ) returns !4 or/
inputs:¡¢- , the knowledge base, a set of propositional Horn clauses
5 , the query, a proposition symbol
local variables: !14 , a table, indexed by clause, initially the number of premises
$/ =
, a table, indexed by symbol, each entry initially/J
+1= , a list of symbols, initially the symbols known to be true in¡¢- while+>=e is not empty do
POP(+1>= ) unless0/ = [ ] do
$/ =
[ ]C !4
for each Horn clause in whose premise appears do decrement!14 [ ]
if!" [ ] = 0 then do
if HEAD[ ] =5 then return !4 PUSH(HEAD[ ],+1>= ) return/
Figure 7.18
16 Chapter 7. Logical Agents
function DPLL-SATISFIABLE?( ) returns !4 or/ inputs: , a sentence in propositional logic
(!1B the set of clauses in the CNF representation of
%6g 2
a list of the proposition symbols in return DPLL(!1 , %6g J,`a)
function DPLL((!1 ,%6g ,6o=) returns ! or/J if every clause in(!1 is true in6o= then return !4 if some clause in!1 is false in6o= then return/J
®
,dJ!42 FIND-PURE-SYMBOL(%6gJ ,!",6o=)
if® is non-null then return DPLL((!1 , %6g J –® , EXTEND(£ :dJ!4:6o=)
®
,dJ!42 FIND-UNIT-CLAUSE((!1 ,6o=)
if® is non-null then return DPLL((!1 , %6g J –® , EXTEND(£ :dJ!4:6o=)
®
FIRST(%6g ); 4 REST(%6gJ)
return DPLL(!1 , , EXTEND(® , !4 ,6o=)) or DPLL(!1 , , EXTEND(® ,/ ,6o=))
Figure 7.21
function WALKSAT((!1, ,6oik ¯y ) returns a satisfying model or/$J!1 inputs:(!1 , a set of clauses in propositional logic
, the probability of choosing to do a “random walk” move, typically around 0.5
6oik ¯y
, number of flips allowed before giving up
6o=e a random assignment of !4 // to the symbols in(!1 for M z to6oik ¯y4 do
if6o= satisfies!1 then return6o=
!"2
a randomly selected clause from(!1 that is false in6o=
with probability flip the value in6o= of a randomly selected symbol from(!1 else flip whichever symbol in!1 maximizes the number of satisfied clauses return/$J!1
Figure 7.23
function PL-WUMPUS-AGENT( ) returns an inputs:4 , a list, [ >, , °i ,+e$ ]
static:¡¢- , a knowledge base, initially containing the “physics” of the wumpus world
k ,% ,34 3 , the agent’s position (initially 1,1) and orientation (initially(+, )
di$$ =
, an array indicating which squares have been visited, initially/ , the agent’s most recent action, initially null
( , an action sequence, initially empty updatek ,% ,4 ,di$$ = based on e if , then TELL(¡¢- ,±?²³´ ) else TELL(¡¢- ,¥±]²³´ ) if °i then TELL(¡¢- ,µN²³´ ) else TELL(¡¢- ,¥µ¢²³´ )
if+J$ then ~+
else if4 is nonempty then POP(( )
else if for some fringe square [,¶ ], ASK(¡¢- ,X¥ £ ³ ¤T¥· ³ [) is !4 or for some fringe square [,¶ ], ASK(¡¢- ,X£ ³¸ · ³ [) is/J then do
4 A*-GRAPH-SEARCH(ROUTE-PROBLEM([k ,% ],34 3 , [,¶ ],di$$ = ))
e POP(( )
else a randomly chosen move return
Figure 7.26
8 FIRST-ORDER LOGIC
18
function UNIFY(k ,% ,¹ ) returns a substitution to makek and% identical inputs:k , a variable, constant, list, or compound
% , a variable, constant, list, or compound
¹ , the substitution built up so far (optional, defaults to empty) if¹ = failure then return failure
else ifk =% then return¹
else if VARIABLE?(k ) then return UNIFY-VAR(k ,% ,¹ ) else if VARIABLE?(% ) then return UNIFY-VAR(% ,k ,¹ ) else if COMPOUND?(k ) and COMPOUND?(% ) then
return UNIFY(ARGS[k ], ARGS[% ], UNIFY(OP[k ], OP[% ],¹ )) else if LIST?(k ) and LIST?(% ) then
return UNIFY(REST[k ], REST[% ], UNIFY(FIRST[k ], FIRST[% ],¹ )) else return failure
function UNIFY-VAR(d ,k ,¹ ) returns a substitution inputs:d, a variable
k , any expression
¹ , the substitution built up so far if dº1d¦»7¹ then return UNIFY(d,k ,¹ ) else if¼ º"d¦»7¹ then return UNIFY(d ,d,¹ ) else if OCCUR-CHECK?(d ,k ) then return failure else return add d /k to¹
Figure 9.2
20 Chapter 9. Inference in First-Order Logic
function FOL-FC-ASK(¡N- , ) returns a substitution or/J inputs:¡¢- , the knowledge base, a set of first-order definite clauses
, the query, an atomic sentence
local variables:>u , the new sentences inferred on each iteration repeat untilYu is empty
>u
9
for each sentence in¡N- do
X
<¤
¤ ½
5[4 STANDARDIZE-APART( )
for each¹ such that SUBST(¹ , ¤ ¤ ) = SUBST(¹ , | ¤ ¤ | ) for some | ::I | in¡N-
5 |
SUBST(¹ ,5 )
if5 | is not a renaming of some sentence already in¡¢- or>u then do add5 | toYu
¾
UNIFY(5 |, ) if
¾
is not/$ then return
¾
addYu to¡¢- return/
Figure 9.5
function FOL-BC-ASK(¡¢- ,+J ,¹ ) returns a set of substitutions inputs:¡¢- , a knowledge base
+
, a list of conjuncts forming a query (¹ already applied)
¹ , the current substitution, initially the empty substitution9
local variables: 4uy, a set of substitutions, initially empty if+ is empty then return¹
5 |
SUBST(¹ , FIRST(+ ))
for each sentence in¡¢- where STANDARDIZE-APART( ) =X P¤ ¤ ½À¿ [ and¹ | UNIFY(5 ,5 |) succeeds
>u +JB
` ::I
BÁREST(+)a
4uyB FOL-BC-ASK(¡¢- ,Yu + , COMPOSE(¹ |,¹ ))¨Â4uy
returnuy
Figure 9.9
procedure APPEND(k ,% ,i° ,4 $4! )
$ GLOBAL-TRAIL-POINTER()
ifk =`a and UNIFY(% ,i° ) then CALL(4 $!4 ) RESET-TRAIL( $)
L NEW-VARIABLE();kà NEW-VARIABLE();°y NEW-VARIABLE()
if UNIFY(ik , [ —k ]) and UNIFY(i° , [ —° ]) then APPEND(k ,% ,° , $4! )
Figure 9.12
procedure OTTER( ,!" )
inputs:, a set of support—clauses defining the problem (a global variable)
!"
, background knowledge potentially relevant to the problem repeat
clause the lightest member of
move(!1 from to!1
PROCESS(INFER((!1 ,!" ), ) until =`a or a refutation has been found function INFER((!1 ,!1 ) returns clauses
resolve(!1 with each member of!"
return the resulting clauses after applying FILTER
procedure PROCESS((!1 ,) for each(!1 in(!1 do
!"2
SIMPLIFY((!1 ) merge identical literals
discard clause if it is a tautology
< [(!1 —]
if(!1 has no literals then a refutation has been found if(!1 has one literal then look for unit refutation
Figure 9.19
10 KNOWLEDGE REPRESENTATION
22
Ä
$ X
)
X
§ :
&"ÅLÆ
[
¤Ç) X
§ :yÈ
Å2¡
[
¤Ç) X
£ :
&"ÅwÆ
[
¤É) X
£
:yÈ
Å2¡
[
¤_Ê +4X
§v
[
¤Ê 3+X
§L
[ ¤ ® YX
£ [ ¤ ®
(YX
£ [
¤¦)
$" XÈ
Å2¡
[
¤É) 0" X
&"ÅwÆ [[
Ë
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
EFFECT:¥ } deX Ê 'ei[ ¤
n
2X
Ê
'e[)
)
2X
-
i'X
Ê
'[
PRECOND:¥ } dXÊ '[
EFFECT:} deX Ê 'ei[
Figure 11.16
function GRAPHPLAN(6 ) returns solution or failure
+e4,v
INITIAL-PLANNING-GRAPH(6 )
+<
GOALS[4 6 ] loop do
if+J all non-mutex in last level of+ 4, then do
!1
EXTRACT-SOLUTION(+e4, ,+ , LENGTH(+e, )) if!" ÐKM /$!1 then returnJ!1
else if NO-SOLUTION-POSSIBLE(+ 4, ) then return/$!1
+4,Ã EXPAND-GRAPH(+ 4, ,6 )
Figure 11.19
26 Chapter 11. Planning
function SATPLAN(6 ,lÒ2ÓÔ ) returns solution or failure inputs:6 , a planning problem
lÒ2ÓÔ
, an upper limit for plan length forl = 0 to lÒ2ÓÔ do
/ ,6o$1+Ã TRANSLATE-TO-SAT(6 ,l )
(+46g 4
SAT-SOLVER(/ ) if +46g4 is not null then
return EXTRACT-SOLUTION( (+e46g4 ,6o$+ ) return/$J!1
Figure 11.22