You are on page 1of 0

45

Algorithm : Generate-and-Test
1. Generateapossiblesolution.
2. Test to seeif this is actually asolutionby comparing
thechosepoint or theendpoint of thechosen path to
theset of acceptablegoal states.
3. If asolutionhasbeenfound, quit. Otherwise, returnto
step1.
Algorithm : Simple Hill-Climbing
46
1. Evaluate the initial state. If it is also a goal state, then return it and quit.
Otherwise, continue with the initial state as the current state.
2. Loop until a solution is found or until there are no new operators left
to be applied in the current state:
(a) Select an operator that has not yet been applied to the current state and
apply it to produce a new state.
(b) Evaluate the new state.
(i) If it is a goal state, then return it and quit.
(ii) If it is not a goal state but it is better than the current state, then make it the current
state.
(iii) If it is not better than the current state, then continue in the loop.
Algorithm : Steepest-Ascent Hill Climbing
47
1. Evaluatetheinitial state. If it isalsoagoal state, thenreturnit andquit.
Otherwise,continuewiththeinitialstateasthecurrentstate.
2. Loopuntil asolutionisfoundor until acompleteiterationproducesno
changetocurrentstate:
(a) Let SUCCbeastatesuchthatanypossiblesuccessorof thecurrentstatewill
bebetterthanSUCC.
(b)Foreachoperatorthatappliestothecurrentstatedo:
(i) Applytheoperatorandgenerateanewstate.
(ii)Evaluatethenewstate. Ifitisagoal state,thenreturnitandquit. Ifnot,compare
ittoSUCC. If itisbetter, thensetSUCCtothisstate. If itisnotbetter, leaveSUCC
alone.
(c)IftheSUCCisbetterthancurrentstate,thensetcurrentstatetoSUCC.
Hill-Climbing Dangers
48
Local maximum
Plateau
Ridge
A Hill-Climbing Problem
49
Three Possible Moves
50
A Best-First Search
53
Algorithm : Best-First Search
54
1. StartwithOPENcontainingjusttheinitial state.
2.Until agoal isfoundortherearenonodesleftonOPENdo:
(a)PickthembestnodeonOPEN.
(b)Generateitssuccessors.
(c)Foreachsuccessordo:
(i)If it hasnot beengeneratedbefore, evaluateit, addit toOPEN, andrecordits
parent.
(ii) If it hasbeengeneratedbefore, changetheparent if thisnewpathisbetter
thanthepreviousone. Inthat case, updatethecost of gettingto thisnode
andtoanysuccessorsthatthisnodemayalready,have.
Algorithm : A* Algorithm
1. 1. Start withOPENcontainingonlytheinitial node. Set that nodesg
valueto0, itsh valuetowhateveritis,anditsf valuetoh+0orh. Set
CLOSEDtotheemptylist.
2. Until agoal nodeisfound, repeat thefollowingprocedure. If thereare
nonodesonOPEN, report failure. Otherwise, pickthenodeonOPEN
withthelowestf value. Call itBESTNODE. RemoveitfromOPEN. Place
it onCLOSED. Seeif BESTNODEisagoal node. If so, exit andreport a
solution. Otherwisegeneratethesuccessorsof BESTNODEbut do not
set BESTNODE to point to them yet. For each SUCCESSOR do the
following:
a) SetSUCCESSORtopointbacktoBESTNODE.
b) Compute g(SUCCESSOR)=g(BESTNODE) + the cost of getting from
BESTNODEtoSUCCESSOR.
Cont.
c) Seeif SUCCESSORisthesameasanynodeonOPEN. If socall that node
OLD. Since this node already exists in the graph, we can throw
SUCCESSOR away and add OLDto the list of BESTNODEs successors.
NowwemustdecidewhetherOLDsparentlinkshouldberesettopoint
toBESTNODE. Itshouldbeif thepathwehavejustfoundtoSUCCESSOR
is cheaper than the current best path to OLD. So see whether it is
cheaper to get to OLD via its current parent or to SUCCESSOR via
BESTNODE by comparing their g values. If OLD is cheaper then do
nothing. If SUCCESSOR ischeaper, thenreset OLDsparent linktopoint
to BESTNODE, record the new cheaper path in g(OLD), and update
f(OLD).
Cont.
d) If SUCCESSORwasnot onOPEN, seeif isonCLOSED. If so, call thenode
on CLOSED OLD and add OLD to the list of BESTNODEs successors.
Checktoseeifthenewpathortheoldpathisbetterjustasinstep2(c).
And set the parent link andgand f values. If we have just founda
better path to OLD, we must propagate the improvement to OLDs
successors. To propagate the new cost downward do a depth first
traversal of the tree starting at OLD changing each nodes g value
terminating each branch when you reach either a node with no
successorsoranodetowhichanequivalent orbetterpathhasalready
beenfound.
e) If SUCCESSORwasnotalreadyoneitherOPENorCLOSED, thenputiton
OPEN and add it to the list of BESTNODEs successors. Compute
f(SUCCESSOR)=g(SUCCESSOR)+h(SUCCESSOR).
55
56
A Simple AND-OR Graph
58
AND-OR Graphs
59
Algorithm : Problem Reduction
60
1. Initializethegraphtothestartingnode.
2. 2. Loop until the startingnode is labeled SOLVED or until its cost goes
aboveFUTILITY:
(a) Traverse the graph, startingat the initial nodeand followingthecurrent best path,
and accumulate the set of nodes that are on that path and have not yet been
expandedor labeledassolved.
(b) Pickoneof theseunexpandednodesandexpandit. If therearenosuccessors, assign
FUTILITYasthevalueof thisnode. Otherwise, additssuccessorstothegraphandfor
eachof themcomputef (useonlyh andignoreg, for reasonswediscussbelow). If
of anynodeis0, markthat nodeasSOLVED.
(c) Changethef estimateof thenewlyexpandednodeto reflect thenewinformation
providedbyitssuccessors. Propagatethischangebackwardthroughthegraph. If any
nodecontainsasuccessor arcwhosedescendantsareall solved, label thenodeitself
asSOLVED. At eachnodethat isvisitedwhilegoingupthegraph, decidewhichof its
successor arcsisthemost promisingandmarkit aspart of thecurrent best path.
The Operation of Problem Reduction
61
A Longer Path May Be Better
62
Interacting Subgoals
63
Algorithm : AO* Algorithm
1. Let GRAPHconsist onlyof thenoderepresentingtheinitial state. ( call
thisnodeINIT). Computeh(INIT).
2. Until INITislabeledSOLVEDoruntil INITshvaluebecomesgreaterthan
FUTILITY,repeatthefollowingprocedure:
a)TracethelabeledarcsfromINITandselect forexpansiononeof theasyet
unexpandednodesthatoccursonthispath. Call theselectednodeNODE.
b) Generatethesuccessorsof NODE. If therearenone, thenassignFUTILITY
as the hvalue of NODE. This is equivalent to sayingthat NODE is not
solvable. If there are successors then for eachone (calledSUCCESSOR)
thatisnotalsoanancestorofNODEdothefollowing:
i) AddSUCCESSORtoGRAPH.
ii) if SUCCESSOR is a terminal node, label it SOLVED and assign it an
hvalueof0.
iii)ifSUCCESSORisnotaterminal node,computeitshvalue.
c) Propagatethenewly discoveredinformationupthegraphbydoingthe
following: let Sbe a set of nodes that have been labeled SOLVEDor
whose hvalue have been changed and so need to have values
propagatedbacktotheir parents. InitializeStoNODE. Until Sisempty,
repeatthefollowingprocedure:
i) IfpossibleselectfromSanodenoneofwhose
descendantsinGRAPHoccursinS. if thereis no suchnodeselect any
nodefromS. Call thisnodeCURRENTandremoveitfromS.
ii) Computethecostof eachof thearcsemerging fromCURRENT. Thecostof
eacharcisequal tothesumof thehvaluesof eachof thenodesat the
endof thearcpluscost of thearc. AssignasCURRENTs newhvaluethe
minimumofthecostsjustcomputedforthearcsemerging fromit.
iii) Markthebest pathout of CURRENTbymarkingthearc that hadthe
minimumcostascomputedinthepreviousstep.
iv) MarkCURRENTSOLVEDif all of thenodesconnected throughthenew
labeledarchavebeenlabeledSOLVED.
v) If CURRENThasbeenlabeledSOLVEDorif thecost of CURRENTwasjust
changedthenitsnewstatusmust bepropagatedbackupthegraph. So
addall theancestorsofCURRENTtoS.
An Unnecessary Backward Propagation
64
A Necessary Backward Propagation
65
Algorithm : Constraint Satisfaction
66
1. Propagate available constraints. To do this, first set OPEN to the set of all objects that must have
values assigned to themin a complete solution. Then do until an inconsistency is detected or until
OPENisempty:
(a) Select anobject OBfromOPEN. Strengthenasmuchaspossibletheset of constraintsthat applyto
OB.
(b) If thisset isdifferent fromtheset that wasassignedthelast timeOBwasexaminedor if thisisthe
first timeOBhasbeenexamined, thenaddtoOPENall objectsthat shareanyconstraintswithOB.
(c) RemoveOBfromOPEN.
2. If theunionof theconstraintsdiscoveredabovedefinesasolution, thenquit andreport thesolution.
3. If theunionof theconstraintsdiscoveredabovedefinesacontradiction, thenreturnfailure.
4. If neither of theaboveoccurs, thenit isnecessarytomakeaguessat somethinginorder toproceed.
Todothis, loopuntil asolutionisfoundor all possiblesolutionshavebeeneliminated:
(a) Select an object whose value is not yet determined and select a way of strengthening the
constraintsonthat object.
(b) Recursively invoke constraint satisfaction with the current set of constraints augmented by the
strengtheningconstraint just selected.
A Cryptarithmetic Problem
67
Solving a Cryptarithmetic Problem
68
69
A Robots Operators
70
A Difference Table
The Progress of the Means-Ends Analysis
Methods
71
Algorithm : Means-Ends Analysis
72
1. CompareCURRENTtoGOAL. Iftherearenodifferencesbetweenthemthenreturn.
2. Otherwise, select themost important differenceandreduceit by doingthefollowing
until successorfailureissignaled:
(a) Select anasyet untriedoperator Othat isapplicabletothecurrent difference. If there
arenosuchoperators,thensignal failure.
(b)AttempttoapplyOtoCURRENT. Generatedescriptionsoftwostates: O-START, astatein
whichOspreconditionsaresatisfiedandO-RESULT, thestatethatwouldresultifOwere
appliedinOSTART.
(c)If
(FIRST-PARTMEA(CURRENT, O-START))
and
(LAST-PARTMEMO-RESULT, GOAL))
aresuccessful,thensignal successandreturntheresultofconcatenating
FIRST-PART, O, andLAST-PART.
Exercise 5
73
74
Exercise 6
Exercise 9
75
76
Exercise 10

You might also like