Upload
others
View
1
Download
0
Embed Size (px)
Citation preview
1
CSE473:ArtificialIntelligenceConstraintSatisfactionProblemsIIIFactored(akaStructured)Search
[WithmanyslidesbyDanKleinandPieterAbbeel (UCBerkeley)availableathttp://ai.berkeley.edu.]
BacktrackingSearch
§ BacktrackingsearchisthebasicuninformedalgorithmforsolvingCSPs
§ StartwithDepthFirstSearch§ “backtrackingsearch”ISaKindofdepthfirstsearchwiththese2details:
§ Idea1:Onevariableatatime§ Variableassignmentsarecommutative,sofixordering§ I.e.,[WA=redthenNT=green]sameas[NT=greenthenWA=red]§ Onlyneedtoconsiderassignmentstoasinglevariableateachstep
§ Idea2:Checkconstraintsasyougo§ I.e.consideronlyvalueswhichdonotconflictpreviousassignments§ Mighthavetodosomecomputationtochecktheconstraints§ “Incrementalgoaltest”
§ Cansolven-queensforn» 25
2
ImprovingBacktracking
§ General-purposeideasgivehugegainsinspeed
§ Ordering:§ Whichvariableshouldbeassignednext?§ Inwhatordershoulditsvaluesbetried?
§ Filtering:Canwedetectinevitablefailureearly?
§ Structure:Canweexploittheproblemstructure?
§ Filtering:Keeptrackofdomainsforunassignedvariablesandcrossoffbadoptions§ Forwardchecking:Crossoffvaluesthatviolateaconstraintwhenaddedtotheexisting
assignment
Filtering:ForwardChecking
WASANT Q
NSWV
[Demo:coloring-- forwardchecking]
3
ConsistencyofaSingleArc
§ AnarcX® Yisconsistent iff foreveryxinthetailthereissomeyintheheadwhichcouldbeassignedwithoutviolatingaconstraint
§ Forwardchecking:Enforcingconsistencyofarcspointingtoeachnewassignment
Deletefromthetail!
WA SA
NT Q
NSW
V
ArcConsistencyofanEntireCSP§ Asimpleformofpropagationmakessureallarcsareconsistent:
§ Important:IfXlosesavalue,neighborsofXneedtoberechecked!§ Arcconsistencydetectsfailureearlier thanforwardchecking§ Canberunasapreprocessoror aftereachassignment§ What’sthedownside ofenforcingarcconsistency?
WA SANT Q
NSW
V
4
AC-3algorithmforArcConsistency
§ Runtime:O(n2d3),canbereducedtoO(n2d2)§ …butdetectingall possiblefutureproblemsisNP-hard– why?
[Demo:CSPapplet(madeavailablebyaispace.org)-- n-queens]
LimitationsofArcConsistency
§ Afterenforcingarcconsistency:§ Canhaveonesolutionleft§ Canhavemultiplesolutionsleft§ Canhavenosolutionsleft
(andnotknowit)
§ EvenwithArcConsistencyyoustillneedbacktrackingsearch!§ Couldrunatevenstepofthatsearch§ Usuallybettertorunitonce,beforesearch
Whatwentwronghere?
5
VideoofDemoArcConsistency– CSPApplet– nQueens
VideoofDemoColoring– BacktrackingwithForwardChecking–ComplexGraph
6
VideoofDemoColoring– BacktrackingwithArcConsistency–ComplexGraph
K-Consistency
7
K-Consistency§ Increasingdegreesofconsistency
§ 1-Consistency(NodeConsistency):Eachsinglevariable’sdomainhasavaluewhichmeetsthatvariablesunaryconstraints
§ 2-Consistency(ArcConsistency):Foreachpairofvariables,anyconsistentassignmenttoonecanbeextendedtotheother
§ 3-Consistency(PathConsistency):Foreverysetof3vars,anyconsistentassignmentto2ofthevariablescanbeextendedtothethirdvar
§ K-Consistency:Foreachknodes,anyconsistentassignmenttok-1canbeextendedtothekth node.
§ Higherkmoreexpensivetocompute
§ (Youneedtoknowthealgorithmfork=2case:arcconsistency)
StrongK-Consistency
§ Strongk-consistency:alsok-1,k-2,…1consistent
§ Claim:strongn-consistencymeanswecansolvewithoutbacktracking!
§ Why?§ Chooseanyassignmenttoanyvariable§ Chooseanewvariable§ By2-consistency,thereisachoiceconsistentwiththefirst§ Chooseanewvariable§ By3-consistency,thereisachoiceconsistentwiththefirst2§ …
8
Ordering
BacktrackingSearch
9
Ordering:MinimumRemainingValues
§ VariableOrdering:Minimumremainingvalues(MRV):§ Choosethevariablewiththefewestlegalleftvaluesinitsdomain
§ Whyminratherthanmax?§ Alsocalled“mostconstrainedvariable”§ “Fail-fast”ordering
§ Tie-breakeramongMRVvariables§ Whatistheveryfirststatetocolor?(Allhave3valuesremaining.)
§ Maximumdegreeheuristic:§ Choosethevariableparticipatinginthemostconstraintsonremainingvariables
§ Whymostratherthanfewestconstraints?
Ordering:MaximumDegree
10
Ordering:LeastConstrainingValue
§ ValueOrdering:LeastConstrainingValue§ Givenachoiceofvariable,choosetheleastconstrainingvalue
§ I.e.,theonethatrulesoutthefewestvaluesintheremainingvariables
§ Notethatitmaytakesomecomputationtodeterminethis!(E.g.,rerunningfiltering)
§ Whyleastratherthanmost?
§ Combiningtheseorderingideasmakes1000queensfeasible
RationaleforMRV,MD,LCV
§ Wewanttoenterthemostpromisingbranch,butwealsowanttodetectfailurequickly
§ MRV+MD:§ Choosethevariablethatismostlikelytocausefailure§ Itmustbeassignedatsomepoint,soifitisdoomedtofail,bettertofindoutsoon
§ LCV:§ Wehopeourearlyvaluechoicesdonotdoomustofailure§ Choosethevaluethatismostlikelytosucceed
11
Structure
ProblemStructure
§ Extremecase:independentsubproblems§ Example:Tasmaniaandmainlanddonotinteract
§ Independentsubproblems areidentifiableasconnectedcomponentsofconstraintgraph
§ Supposeagraphofnvariablescanbebrokenintosubproblems ofonlycvariables:§ Worst-casesolutioncostisO((n/c)(dc)),linearinn§ E.g.,n=80,d=2,c=20§ 280 =4billionyearsat10millionnodes/sec§ (4)(220)=0.4secondsat10millionnodes/sec
12
Tree-StructuredCSPs
§ Theorem:iftheconstraintgraphhasnoloops,theCSPcanbesolvedinO(nd2)time§ ComparetogeneralCSPs,whereworst-casetimeisO(dn)
§ Thispropertyalsoappliestoprobabilisticreasoning(later):anexampleoftherelationbetweensyntacticrestrictionsandthecomplexityofreasoning
Tree-StructuredCSPs§ Algorithmfortree-structuredCSPs:
§ Order:Choosearootvariable,ordervariablessothatparentsprecedechildren
§ Removebackward:Fori =n:2,applyRemoveInconsistent(Parent(Xi),Xi)§ Assignforward:Fori =1:n,assignXi consistentlywithParent(Xi)
§ Runtime:O(nd2)(why?)
13
Tree-StructuredCSPs
§ Claim1:Afterbackwardpass,allroot-to-leafarcsareconsistent§ Proof:EachX®YwasmadeconsistentatonepointandY’sdomaincouldnothave
beenreducedthereafter(becauseY’schildrenwereprocessedbeforeY)
§ Claim2:Ifroot-to-leafarcsareconsistent,forwardassignmentwillnotbacktrack§ Proof:Inductiononposition
§ Whydoesn’tthisalgorithmworkwithcyclesintheconstraintgraph?
§ Note:we’llseethisbasicideaagainwithBayes’nets
ImprovingStructure
14
NearlyTree-StructuredCSPs
§ Conditioning:instantiateavariable,pruneitsneighbors'domains
§ Cutset conditioning:instantiate(inallways)asetofvariablessuchthattheremainingconstraintgraphisatree
§ Cutset sizecgivesruntimeO((dc)(n-c)d2),veryfastforsmallc
Cutset Conditioning
SA
SA SA SA
Instantiatethecutset(allpossibleways)
ComputeresidualCSPforeachassignment
SolvetheresidualCSPs(treestructured)
Chooseacutset
15
Cutset Quiz
§ Findthesmallestcutset forthegraphbelow.
LocalSearchforCSPs
16
IterativeAlgorithmsforCSPs
§ Localsearchmethodstypicallyworkwith“complete”states,i.e.,allvariablesassigned
§ ToapplytoCSPs:§ Takeanassignmentwithunsatisfiedconstraints§ Operatorsreassignvariablevalues§ Nofringe!Liveontheedge.
§ Algorithm:Whilenotsolved,§ Variableselection:randomlyselectanyconflictedvariable§ Valueselection:min-conflictsheuristic:
§ Chooseavaluethatviolatesthefewestconstraints§ I.e.,hillclimbwithh(n)=totalnumberofviolatedconstraints
Example:4-Queens
§ States:4queensin4columns(44 =256states)§ Operators:movequeenincolumn§ Goaltest:noattacks§ Evaluation:c(n)=numberofattacks
[Demo:n-queens– iterativeimprovement(L5D1)][Demo:coloring– iterativeimprovement]
17
PerformanceofMin-Conflicts
§ Givenrandominitialstate,cansolven-queensinalmostconstanttimeforarbitrarynwithhighprobability(e.g.,n=10,000,000)!
§ Thesameappearstobetrueforanyrandomly-generatedCSPexcept inanarrowrangeoftheratio
Summary:CSPs
§ CSPsareaspecialkindofsearchproblem:§ Statesarepartialassignments§ Goaltestdefinedbyconstraints
§ Basicsolution:backtrackingsearch
§ Speed-ups:§ Ordering§ Filtering§ Structure(cutset conditioning)
§ Iterativemin-conflictsisofteneffectiveinpractice