cse 573: artificial intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-csp.pdf ·...
TRANSCRIPT
![Page 1: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/1.jpg)
CSE573:ArtificialIntelligenceConstraintSatisfactionProblemsFactored(akaStructured)Search
[WithmanyslidesbyDanKleinandPieterAbbeel (UCBerkeley)availableathttp://ai.berkeley.edu.]
![Page 2: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/2.jpg)
FinalPresentations§ 21groups/40people/110min
§ Minustransfers&tournamentreplay
§ Presentations(withquestions)§ Onepersongroups 2.5min§ Twopersongroups 4.5min§ Threepersongroups 6.5min
§ Everyoneshouldspeak(unlessOOT)§ Rehearse§ AddURLforslidestog-doc
§ https://docs.google.com/spreadsheets/d/1Qt5BW0DkSAg6Q4MOM98jSSwjR2wTZpi5i01XdT0X-fs/edit#gid=02
![Page 3: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/3.jpg)
Finalreport
§ Defaultproject~2pages§ Otherprojects~6pages
§ Experiments§ Lessonslearned§ http://courses.cs.washington.edu/courses/cse573/17wi/reports.html
§ Everyone§ Seenoteonappendices– dynamics&externalcode
3
![Page 4: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/4.jpg)
AITopics
§ Search§ Problemspaces§ BFS,DFS,UCS,A*(treeandgraph),localsearch§ CompletenessandOptimality§ Heuristics:admissibilityandconsistency;patternDBs
§ CSPs§ Constraintgraphs,backtrackingsearch§ Forwardchecking,AC3constraintpropagation,ordering
heuristics§ Games
§ Minimax,Alpha-betapruning,§ Expectimax§ EvaluationFunctions
§ MDPs§ Bellmanequations§ Valueiteration,policyiteration
§ Reinforcement Learning§ Exploration vs Exploitation§ Model-based vs. model-free§ Q-learning§ Linear value function approx.
§ Hidden Markov Models§ Markov chains, DBNs§ Forward algorithm§ Particle Filters
§ POMDPs§ Belief space§ Piecewise linear approximation to value fun
§ Beneficial AI§ Bayesian Networks
§ Basic definition, independence (d-sep)§ Variable elimination§ Sampling (rejection, importance)
§ Learning§ BN parameters with complete data§ Search thru space of BN structures§ Expectation maximization
![Page 5: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/5.jpg)
Whatisintelligence?
§ (bounded)Rationality§ Agenthasaperformancemeasuretooptimize§ Givenitsstateofknowledge§ Chooseoptimalaction§ Withlimitedcomputationalresources
§ Human-likeintelligence/behavior
![Page 6: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/6.jpg)
State-SpaceSearch§ Xasasearchproblem
§ states,actions,transitions,cost,goal-test§ Typesofsearch
§ uninformedsystematic:oftenslow§ DFS,BFS,uniform-cost,iterativedeepening
§ Heuristic-guided:better§ Greedybestfirst,A*§ Relaxationleadstoheuristics
§ Local: fast,fewerguarantees;oftenlocaloptimal§ Hillclimbingandvariations§ SimulatedAnnealing:globaloptimal
§ (Local)BeamSearch
![Page 7: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/7.jpg)
WhichAlgorithm?
§ A*, Manhattan Heuristic:
![Page 8: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/8.jpg)
AdversarialSearch
![Page 9: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/9.jpg)
AdversarialSearch
§ AND/ORsearchspace(max,min)§ minimax objectivefunction§ minimax algorithm(~dfs)
§ alpha-betapruning
§ Utilityfunctionforpartialsearch§ Learningutilityfunctionsbyplayingwithitself
§ Openings/Endgamedatabases
![Page 10: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/10.jpg)
PolicyIteration§ Leti =0§ Initializeπi(s)torandomactions§ Repeat
§ Step1:Policyevaluation:§ Initializek=0;Forall s,V0
π (s)=0§ RepeatuntilVπ converges
§ Foreachstates,
§ Letk+=1§ Step2:Policyimprovement:
§ Foreachstate,s,
§ Ifπi ==πi+1 thenit’soptimal;returnit.§ Elseleti +=1
![Page 11: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/11.jpg)
Example
Initializeπ0to “alwaysgoright”
Performpolicyevaluation
PerformpolicyimprovementIteratethroughstates ?
?
?
Haspolicychanged?
Yes!i +=1
![Page 12: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/12.jpg)
Example
π1says“alwaysgoup”
Performpolicyevaluation
PerformpolicyimprovementIteratethroughstates ?
?
?
Haspolicychanged?
No!Wehavetheoptimalpolicy
![Page 13: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/13.jpg)
ReinforcementLearning
§ Forall s,a§ InitializeQ(s,a)=0
§ RepeatForeverWhere are you? s.Choose some action aExecute it in real world: transition =(s, a, r, s’)Do update:
![Page 14: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/14.jpg)
ApproximateQ-Learning
§ Interpretationassearch§ Adjustweightsofactivefeatures§ E.g.,ifsomethingunexpectedlybadhappens,blametheactivefeatures
§ Forall s,a§ Initializewi=0
§ RepeatForeverWhere are you? s.Choose some action aExecute it in real world: transition =(s, a, r, s’)Do updates:
![Page 15: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/15.jpg)
ApproximateQ-Learning
§ Q-learningwithlinearQ-functions:
§ Intuitiveinterpretation:§ Adjustweightsofactivefeatures§ E.g.,ifsomethingunexpectedlybadhappens,blamethefeaturesthatwereactive:
disprefer allstateswiththatstate’sfeatures
Old way: Exact Q’s
Now: Approximate Q’s
![Page 16: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/16.jpg)
WhatisSearchFor?
§ Planning:sequencesofactions§ Thepathtothegoal istheimportantthing§ Pathshavevariouscosts,depths§ Assumelittleaboutproblemstructure
§ Identification:assignmentstovariables§ Thegoalitselfisimportant,notthepath§ Allpathsatthesamedepth(forsomeformulations)
![Page 17: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/17.jpg)
ConstraintSatisfactionProblems
CSPs are structured (factored) identification problems
![Page 18: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/18.jpg)
ConstraintSatisfactionProblems
§ Standardsearchproblems:§ Stateisa“blackbox”:arbitrarydatastructure§ Goaltestcanbeanyfunctionoverstates§ Successorfunctioncanalsobeanything
§ Constraintsatisfactionproblems(CSPs):§ Aspecialsubsetofsearchproblems§ StateisdefinedbyvariablesXi withvaluesfroma
domainD (sometimesD dependsoni)§ Goaltestisasetofconstraintsspecifyingallowable
combinationsofvaluesforsubsetsofvariables
§ MakinguseofCSPformulationallowsforoptimizedalgorithms§ Typicalexampleoftradinggeneralityforutility(inthis
case,speed)
![Page 19: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/19.jpg)
ConstraintSatisfactionProblems
§ Constraintsatisfactionproblems(CSPs):§ Aspecialsubsetofsearchproblems§ StateisdefinedbyvariablesXi withvaluesfroma
domainD (sometimesD dependsoni)§ Goaltestisasetofconstraintsspecifyingallowable
combinationsofvaluesforsubsetsofvariables
§ “Factoring”thestatespace
§ Representingthestatespaceinaknowledgerepresentation
![Page 20: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/20.jpg)
CSPExample:N-Queens
§ Formulation1:§ Variables:§ Domains:§ Constraints
![Page 21: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/21.jpg)
CSPExample:N-Queens
§ Formulation2:§ Variables:
§ Domains:
§ Constraints:
Implicit:
Explicit:
![Page 22: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/22.jpg)
CSPExample:Sudoku
§ Variables:§ Each(open)square
§ Domains:§ {1,2,…,9}
§ Constraints:
9-wayalldiff foreachrow9-wayalldiff foreachcolumn
9-wayalldiffforeachregion(orcanhaveabunchofpairwiseinequalityconstraints)
![Page 23: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/23.jpg)
PropositionalLogic
§ Variables:§ Domains:§ Constraints:
propositionalvariables{T,F}logicalformula
![Page 24: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/24.jpg)
CSPExample:MapColoring
§ Variables:
§ Domains:
§ Constraints:adjacentregionsmusthavedifferentcolors
§ Solutionsareassignmentssatisfyingallconstraints,e.g.:
Implicit:
Explicit:
![Page 25: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/25.jpg)
ConstraintGraphs
![Page 26: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/26.jpg)
ConstraintGraphs
§ BinaryCSP:eachconstraintrelates(atmost)twovariables
§ Binaryconstraintgraph:nodesarevariables,arcsshowconstraints
§ General-purposeCSPalgorithmsusethegraphstructuretospeedupsearch.E.g.,Tasmaniaisanindependentsubproblem!
![Page 27: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/27.jpg)
Example:Cryptarithmetic
§ Variables:
§ Domains:
§ Constraints:
![Page 28: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/28.jpg)
29
ChineseConstraintNetwork
Soup
Total Cost< $40
ChickenDish
Vegetable
RiceSeafood
Pork Dish
Appetizer
Must beHot&Sour
No Peanuts
No Peanuts
NotChow Mein
Not BothSpicy
![Page 29: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/29.jpg)
Real-WorldCSPs
§ Assignmentproblems:e.g.,whoteacheswhatclass§ Timetablingproblems:e.g.,whichclassisofferedwhenandwhere?§ Hardwareconfiguration§ Gateassignmentinairports§ SpaceShuttleRepair§ Transportationscheduling§ Factoryscheduling§ …lotsmore!
![Page 30: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/30.jpg)
Example:TheWaltzAlgorithm
§ TheWaltzalgorithmisforinterpretinglinedrawingsofsolidpolyhedra as3Dobjects
§ AnearlyexampleofanAIcomputationposedasaCSP
?
![Page 31: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/31.jpg)
WaltzonSimpleScenes
§ Assumeallobjects:§ Havenoshadowsorcracks§ Three-facedvertices§ “Generalposition”:nojunctionschangewithsmallmovementsoftheeye.
§ Theneachlineonimageisoneofthefollowing:§ Boundaryline(edgeofanobject)(>)withrighthandofarrowdenoting“solid”andlefthanddenoting“space”
§ Interiorconvexedge(+)§ Interiorconcaveedge(-)
![Page 32: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/32.jpg)
LegalJunctions
§ Onlycertainjunctionsarephysicallypossible§ HowcanweformulateaCSPtolabelanimage?§ Variables:edges§ Domains:>,<,+,-§ Constraints:legaljunctiontypes
![Page 33: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/33.jpg)
SlightProblem:Localvs GlobalConsistency
37
![Page 34: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/34.jpg)
VarietiesofCSPs
![Page 35: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/35.jpg)
VarietiesofCSPVariables
§ DiscreteVariables§ Finitedomains
§ Sized meansO(dn) completeassignments§ E.g.,BooleanCSPs,includingBooleansatisfiability (NP-complete)
§ Infinitedomains(integers,strings,etc.)§ E.g.,jobscheduling,variablesarestart/endtimesforeachjob§ Linearconstraintssolvable,nonlinearundecidable
§ Continuousvariables§ E.g.,start/endtimesforHubbleTelescopeobservations§ Linearconstraintssolvableinpolynomialtimebylinear
programmethods(seeCSE521forabitofLPtheory)
![Page 36: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/36.jpg)
VarietiesofCSPConstraints
§ VarietiesofConstraints§ Unaryconstraintsinvolveasinglevariable(equivalentto
reducingdomains),e.g.:
§ Binaryconstraintsinvolvepairsofvariables,e.g.:
§ Higher-orderconstraintsinvolve3ormorevariables:e.g.,cryptarithmetic columnconstraints
§ Preferences(softconstraints):§ E.g.,redisbetterthangreen§ Oftenrepresentable byacostforeachvariableassignment§ Givesconstrainedoptimizationproblems§ (We’llignoretheseuntilwegettoBayes’nets)
![Page 37: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/37.jpg)
SolvingCSPs
![Page 38: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/38.jpg)
CSPasSearch
§ States§ Operators§ InitialState§ GoalState
![Page 39: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/39.jpg)
StandardDepthFirstSearch
![Page 40: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/40.jpg)
StandardSearchFormulation
§ StandardsearchformulationofCSPs
§ Statesdefinedbythevaluesassignedsofar(partialassignments)§ Initialstate:theemptyassignment,{}§ Successorfunction:assignavaluetoanunassignedvariable
§ Goaltest:thecurrentassignmentiscompleteandsatisfiesallconstraints
§ We’llstartwiththestraightforward,naïveapproach,thenimproveit
![Page 41: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/41.jpg)
BacktrackingSearch
![Page 42: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/42.jpg)
BacktrackingSearch
§ BacktrackingsearchisthebasicuninformedalgorithmforsolvingCSPs
§ Idea1:Onevariableatatime§ Variableassignmentsarecommutative,sofixordering§ I.e.,[WA=redthenNT=green]sameas[NT=greenthenWA=red]§ Onlyneedtoconsiderassignmentstoasinglevariableateachstep
§ Idea2:Checkconstraintsasyougo§ I.e.consideronlyvalueswhichdonotconflictpreviousassignments§ Mighthavetodosomecomputationtochecktheconstraints§ “Incrementalgoaltest”
§ Depth-firstsearchwiththesetwoimprovementsiscalledbacktrackingsearch
§ Cansolven-queensforn» 25
![Page 43: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/43.jpg)
BacktrackingExample
![Page 44: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/44.jpg)
BacktrackingSearch
§ Whatarethechoicepoints?
[Demo:coloring-- backtracking]
![Page 45: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/45.jpg)
BacktrackingSearch
§ Kindofdepthfirstsearch§ Isitcomplete?
![Page 46: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/46.jpg)
ImprovingBacktracking
§ General-purposeideasgivehugegainsinspeed
§ Ordering:§ Whichvariableshouldbeassignednext?§ Inwhatordershoulditsvaluesbetried?
§ Filtering:Canwedetectinevitablefailureearly?
§ Structure:Canweexploittheproblemstructure?
![Page 47: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/47.jpg)
Filtering
![Page 48: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/48.jpg)
§ Filtering:Keeptrackofdomainsforunassignedvariablesandcrossoffbadoptions§ Forwardchecking:Crossoffvaluesthatviolateaconstraintwhenaddedtotheexisting
assignment
Filtering:ForwardChecking
WASANT Q
NSWV
[Demo:coloring-- forwardchecking]
![Page 49: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/49.jpg)
Filtering:ConstraintPropagation
§ Forwardcheckingonlypropagatesinformationfromassignedtounassigned§ Itdoesn'tcatchwhentwounassignedvariableshavenoconsistentassignment:
§ NTandSAcannotbothbeblue!§ Whydidn’twedetectthisyet?§ Constraintpropagation:reasonfromconstrainttoconstraint
WA SA
NT Q
NSW
V
![Page 50: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/50.jpg)
ConsistencyofaSingleArc
§ AnarcX® Yisconsistent iff foreveryxinthetailthereissomeyintheheadwhichcouldbeassignedwithoutviolatingaconstraint
§ Forwardchecking:Enforcingconsistencyofarcspointingtoeachnewassignment
Deletefromthetail!
WA SA
NT Q
NSW
V
![Page 51: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/51.jpg)
ArcConsistencyofanEntireCSP§ Asimpleformofpropagationmakessureallarcsareconsistent:
§ Important:IfXlosesavalue,neighborsofXneedtoberechecked!§ Arcconsistencydetectsfailureearlier thanforwardchecking§ Canberunasapreprocessoror aftereachassignment§ What’sthedownside ofenforcingarcconsistency?
WA SANT Q
NSW
V
![Page 52: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/52.jpg)
AC-3algorithmforArcConsistency
§ Runtime:O(n2d3),canbereducedtoO(n2d2)§ …butdetectingall possiblefutureproblemsisNP-hard– why?
[Demo:CSPapplet(madeavailablebyaispace.org)-- n-queens]
![Page 53: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/53.jpg)
LimitationsofArcConsistency
§ Afterenforcingarcconsistency:§ Canhaveonesolutionleft§ Canhavemultiplesolutionsleft§ Canhavenosolutionsleft
(andnotknowit)
§ EvenwithArcConsistencyyoustillneedbacktrackingsearch!§ Couldrunatevenstepofthatsearch§ Usuallybettertorunitonce,beforesearch
Whatwentwronghere?
![Page 54: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/54.jpg)
VideoofDemoColoring– BacktrackingwithForwardChecking–ComplexGraph
![Page 55: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/55.jpg)
VideoofDemoColoring– BacktrackingwithArcConsistency–ComplexGraph
![Page 56: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/56.jpg)
K-Consistency
![Page 57: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/57.jpg)
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)
![Page 58: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/58.jpg)
StrongK-Consistency
§ Strongk-consistency:alsok-1,k-2,…1consistent
§ Claim:strongn-consistencymeanswecansolvewithoutbacktracking!
§ Why?§ Chooseanyassignmenttoanyvariable§ Chooseanewvariable§ By2-consistency,thereisachoiceconsistentwiththefirst§ Chooseanewvariable§ By3-consistency,thereisachoiceconsistentwiththefirst2§ …
![Page 59: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/59.jpg)
Ordering
![Page 60: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/60.jpg)
BacktrackingSearch
![Page 61: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/61.jpg)
Ordering:MinimumRemainingValues
§ VariableOrdering:Minimumremainingvalues(MRV):§ Choosethevariablewiththefewestlegalleftvaluesinitsdomain
§ Whyminratherthanmax?§ Alsocalled“mostconstrainedvariable”§ “Fail-fast”ordering
![Page 62: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/62.jpg)
§ Tie-breakeramongMRVvariables§ Whatistheveryfirststatetocolor?(Allhave3valuesremaining.)
§ Maximumdegreeheuristic:§ Choosethevariableparticipatinginthemostconstraintsonremainingvariables
§ Whymostratherthanfewestconstraints?
Ordering:MaximumDegree
![Page 63: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/63.jpg)
Ordering:LeastConstrainingValue
§ ValueOrdering:LeastConstrainingValue§ Givenachoiceofvariable,choosetheleastconstrainingvalue
§ I.e.,theonethatrulesoutthefewestvaluesintheremainingvariables
§ Notethatitmaytakesomecomputationtodeterminethis!(E.g.,rerunningfiltering)
§ Whyleastratherthanmost?
§ Combiningtheseorderingideasmakes1000queensfeasible
![Page 64: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/64.jpg)
RationaleforMRV,MD,LCV
§ Wewanttoenterthemostpromisingbranch,butwealsowanttodetectfailurequickly
§ MRV+MD:§ Choosethevariablethatismostlikelytocausefailure§ Itmustbeassignedatsomepoint,soifitisdoomedtofail,bettertofindoutsoon
§ LCV:§ Wehopeourearlyvaluechoicesdonotdoomustofailure§ Choosethevaluethatismostlikelytosucceed
![Page 65: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/65.jpg)
Trapped
§ Pacman istrapped!Heissurroundedbymysteriouscorridors,eachofwhichleadstoeitherapit(P),aghost(G),oranexit(E).Inordertoescape,heneedstofigureoutwhichcorridors,ifany,leadtoanexitandfreedom,ratherthanthecertaindoomofapitoraghost.
§ Theonesignofwhatliesbehindthecorridorsisthewind:apitproducesastrongbreeze(S)andanexitproducesaweakbreeze(W),whileaghostdoesn’tproduceanybreezeatall.Unfortunately,Pacman cannotmeasurethestrengthofthebreezeataspecificcorridor.Instead,hecanstandbetweentwoadjacentcorridorsandfeelthemaxofthetwobreezes.Forexample,ifhestandsbetweenapitandanexithewillsenseastrong(S)breeze,whileifhestandsbetweenanexitandaghost,hewillsenseaweak(W)breeze.Themeasurementsforallintersectionsareshowninthefigurebelow.
§ Also,whilethetotalnumberofexitsmightbezero,one,ormore,Pacmanknowsthattwoneighboringsquareswillnotbothbeexits.
75
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
�
�
�
�
�
�
�
�
�
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
Variables?
![Page 66: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/66.jpg)
Trapped
76
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
�
�
�
�
�
�
�
�
�
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
Variables? X1, … X6Domains {P, G, E}
§ Pacman istrapped!Heissurroundedbymysteriouscorridors,eachofwhichleadstoeitherapit(P),aghost(G),oranexit(E).Inordertoescape,heneedstofigureoutwhichcorridors,ifany,leadtoanexitandfreedom,ratherthanthecertaindoomofapitoraghost.
§ Theonesignofwhatliesbehindthecorridorsisthewind:apitproducesastrongbreeze(S)andanexitproducesaweakbreeze(W),whileaghostdoesn’tproduceanybreezeatall.Unfortunately,Pacman cannotmeasurethestrengthofthebreezeataspecificcorridor.Instead,hecanstandbetweentwoadjacentcorridorsandfeelthemaxofthetwobreezes.Forexample,ifhestandsbetweenapitandanexithewillsenseastrong(S)breeze,whileifhestandsbetweenanexitandaghost,hewillsenseaweak(W)breeze.Themeasurementsforallintersectionsareshowninthefigurebelow.
§ Also,whilethetotalnumberofexitsmightbezero,one,ormore,Pacmanknowsthattwoneighboringsquareswillnotbothbeexits.
![Page 67: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/67.jpg)
Trapped
§ Apitproducesastrongbreeze(S)andanexitproducesaweakbreeze(W),whileaghostdoesn’tproduceanybreezeatall.
§ Pacmanfeelsthemaxofthetwobreezes.§ thetotalnumberofexitsmightbezero,one,ormore,§ twoneighboringsquareswillnotbothbeexits.
77
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
�
�
�
�
�
�
�
�
�
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
Variables? X1, … X6Domains {P, G, E}
Constraints?
![Page 68: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/68.jpg)
Trapped
§ Apitproducesastrongbreeze(S)andanexitproducesaweakbreeze(W),whileaghostdoesn’tproduceanybreezeatall.
§ Pacman feelsthemaxofthetwobreezes.§ thetotalnumberofexitsmightbezero,one,ormore,§ twoneighboringsquareswillnotbothbeexits.
78
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
�
�
�
�
�
�
�
�
�
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
Constraints?
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
X1 = P or X2= P
Xi = E nand Xi+1|7 = E
X3 = E or X4= EX5 = P or X6= PX2 = E or X3= EX4 = P or X5= P
X6 = P or X1= P
Also! X2 =/= PX3 =/= PX4 =/= P
![Page 69: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/69.jpg)
Trapped
§ Apitproducesastrongbreeze(S)andanexitproducesaweakbreeze(W),whileaghostdoesn’tproduceanybreezeatall.
§ Pacman feelsthemaxofthetwobreezes.§ thetotalnumberofexitsmightbezero,one,ormore,§ twoneighboringsquareswillnotbothbeexits.
79
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
�
�
�
�
�
�
�
�
�
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
Arc consistent?
Constraints?
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
X1 = P or X2= P
Xi = E nand Xi+1|7 = E
X3 = E or X4= EX5 = P or X6= PX2 = E or X3= EX4 = P or X5= P
X6 = P or X1= P
Also! X2 =/= PX3 =/= PX4 =/= P
![Page 70: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/70.jpg)
Trapped
§ Apitproducesastrongbreeze(S)andanexitproducesaweakbreeze(W),whileaghostdoesn’tproduceanybreezeatall.
§ Pacman feelsthemaxofthetwobreezes.§ thetotalnumberofexitsmightbezero,one,ormore,§ twoneighboringsquareswillnotbothbeexits.
80
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
�
�
�
�
�
�
�
�
�
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
Arc consistent?
Constraints?
2 CSPs: Trapped Pacman
Pacman is trapped! He is surrounded by mysterious corridors, each of which leads to either a pit (P), a ghost(G), or an exit (E). In order to escape, he needs to figure out which corridors, if any, lead to an exit and freedom,rather than the certain doom of a pit or a ghost.
The one sign of what lies behind the corridors is the wind: a pit produces a strong breeze (S) and an exitproduces a weak breeze (W), while a ghost doesn’t produce any breeze at all. Unfortunately, Pacman cannotmeasure the strength of the breeze at a specific corridor. Instead, he can stand between two adjacent corridorsand feel the max of the two breezes. For example, if he stands between a pit and an exit he will sense a strong(S) breeze, while if he stands between an exit and a ghost, he will sense a weak (W) breeze. The measurementsfor all intersections are shown in the figure below.
Also, while the total number of exits might be zero, one, or more, Pacman knows that two neighboring squareswill not both be exits.
Pacman models this problem using variables Xi for each corridor i and domains P, G, and E.
1. State the binary and/or unary constraints for this CSP (either implicitly or explicitly).
2. Cross out the values from the domains of the variables that will be deleted in enforcing arc consistency.
X1 P G E
X2 P G E
X3 P G E
X4 P G E
X5 P G E
X6 P G E
2
MRV heuristic?X1 = P or X2= P
Xi = E nand Xi+1|7 = E
X3 = E or X4= EX5 = P or X6= PX2 = E or X3= EX4 = P or X5= P
X6 = P or X1= P
Also! X2 =/= PX3 =/= PX4 =/= P
![Page 71: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/71.jpg)
Structure
![Page 72: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/72.jpg)
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
![Page 73: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/73.jpg)
Tree-StructuredCSPs
§ Theorem:iftheconstraintgraphhasnoloops,theCSPcanbesolvedinO(nd2)time§ ComparetogeneralCSPs,whereworst-casetimeisO(dn)
§ Thispropertyalsoappliestoprobabilisticreasoning(later):anexampleoftherelationbetweensyntacticrestrictionsandthecomplexityofreasoning
![Page 74: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/74.jpg)
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?)
![Page 75: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/75.jpg)
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
![Page 76: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/76.jpg)
ConnectiontoBayesNets
![Page 77: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/77.jpg)
BayesNetExample:AlarmNetwork
Burglary Earthqk
Alarm
Johncalls
Marycalls
B P(B)
+b 0.001
-b 0.999
E P(E)
+e 0.002
-e 0.998
B E A P(A|B,E)
+b +e +a 0.95+b +e -a 0.05+b -e +a 0.94+b -e -a 0.06-b +e +a 0.29-b +e -a 0.71-b -e +a 0.001-b -e -a 0.999
A J P(J|A)
+a +j 0.9+a -j 0.1-a +j 0.05-a -j 0.95
A M P(M|A)
+a +m 0.7+a -m 0.3-a +m 0.01-a -m 0.99
![Page 78: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/78.jpg)
MoreComplexBayes’ Net:AutoDiagnosis
![Page 79: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/79.jpg)
HiddenMarkovModel(TreeStructured)
§ AnHMMisdefinedby:§ Initialdistribution:§ Transitions:§ Emissions:
P(R1 )0.6
Rt-1 tf
P(Rt | Rt-1 )0.70.1
Rttf
P(Ut | Rt )0.90.2
![Page 80: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/80.jpg)
ForwardAlgorithm
Umbr1=T Umbr2=T
Rain0 Rain1 Rain2
B(x0=r)=0.5
P(R1 )0.5
Rt-1 tf
P(Rt | Rt-1 )0.80.6
Rttf
P(Ut | Rt )0.90.3
B
0(Xt+1) =
X
xt
P (X 0|xt
)B(xt
)
B’(x1=r) = 0.7
B(x1=r)=0.875
B’(x2=r) = P(x2=r | x1=r)*0.875 + P(x2=r | x1=s)*0.125= 0.8*0.875 + 0.6*0.125= 0.775
B(x1=r)∝ 0.9*0.775=0.6975B(x1=s)∝ 0.3*0.225=0.0675
Divideby0.765tonormalizeB(x1=r)=0.912
B(Xt+1) /Xt+1 P (et+1|Xt+1)B0(Xt+1)
B(Xt+1) /Xt+1 P (et+1|Xt+1)B0(Xt+1)
![Page 81: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/81.jpg)
MoreComplexHMMInference
§ ForwardBackward§ Computesmarginalprobabilitiesofall hiddenstatesgivensequenceofobservations
P(xt = value)
![Page 82: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/82.jpg)
MoreComplexHMMInference
§ ForwardBackward§ Computesmarginalprobabilities ofallhiddenstatesgivensequenceofobservations
§ Viterbi§ Computesmostlikelysequenceofstates
valuevaluevaluevalue value
![Page 83: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/83.jpg)
ImprovingStructure
![Page 84: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/84.jpg)
NearlyTree-StructuredCSPs
§ Conditioning:instantiateavariable,pruneitsneighbors'domains
§ Cutset conditioning:instantiate(inallways)asetofvariablessuchthattheremainingconstraintgraphisatree
§ Cutset sizecgivesruntimeO((dc)(n-c)d2),veryfastforsmallc
![Page 85: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/85.jpg)
Cutset Conditioning
SA
SA SA SA
Instantiatethecutset(allpossibleways)
ComputeresidualCSPforeachassignment
SolvetheresidualCSPs(treestructured)
Chooseacutset
![Page 86: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/86.jpg)
Cutset Quiz
§ Findthesmallestcutset forthegraphbelow.
![Page 87: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/87.jpg)
LocalSearchforCSPs
![Page 88: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/88.jpg)
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
![Page 89: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/89.jpg)
Example:4-Queens
§ States:4queensin4columns(44 =256states)§ Operators:movequeenincolumn§ Goaltest:noattacks§ Evaluation:c(n)=numberofattacks
[Demo:n-queens– iterativeimprovement(L5D1)][Demo:coloring– iterativeimprovement]
![Page 90: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/90.jpg)
PerformanceofMin-Conflicts
§ Givenrandominitialstate,cansolven-queensinalmostconstanttimeforarbitrarynwithhighprobability(e.g.,n=10,000,000)!
§ Thesameappearstobetrueforanyrandomly-generatedCSPexcept inanarrowrangeoftheratio
![Page 91: CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf · § Heuristics: admissibility and consistency; pattern DBs § CSPs § Constraint](https://reader033.vdocument.in/reader033/viewer/2022042710/5f5d66db8cc1ce6696580bf9/html5/thumbnails/91.jpg)
Summary:CSPs
§ CSPsareaspecialkindofsearchproblem:§ Statesarepartialassignments§ Goaltestdefinedbyconstraints
§ Basicsolution:backtrackingsearch
§ Speed-ups:§ Ordering§ Filtering§ Structure(cutset conditioning)
§ Iterativemin-conflictsisofteneffectiveinpractice