lecture5 - cs.utexas.edu · title: lecture5 created date: 9/17/2018 3:00:55 am
TRANSCRIPT
![Page 1: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/1.jpg)
CS343:ArtificialIntelligenceConstraintSatisfactionProblems
Prof.ScottNiekum
TheUniversityofTexasatAustin[TheseslidesarebasedonthoseofDanKleinandPieterAbbeelforCS188IntrotoAIatUCBerkeley.AllCS188materialsareavailableathttp://ai.berkeley.edu.]
![Page 2: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/2.jpg)
WhatisSearchFor?
▪ Assumptionsabouttheworld:asingleagent,deterministicactions,fullyobservedstate,discretestatespace
▪ Planning:sequencesofactions▪ Thepathtothegoalistheimportantthing▪ Pathshavevariouscosts,depths▪ Heuristicsgiveproblem-specificguidance
▪ Identification:assignmentstovariables▪ Thegoalitselfisimportant,notthepath▪ Allpathsatthesamedepth(forsomeformulations)▪ CSPsarespecializedforidentificationproblems
![Page 3: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/3.jpg)
ConstraintSatisfactionProblems
![Page 4: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/4.jpg)
ConstraintSatisfactionProblems
▪ Standardsearchproblems:▪ Stateisa“blackbox”:arbitrarydatastructure▪ Goaltestcanbeanyfunctionoverstates▪ Successorfunctioncanalsobeanything
▪ Constraintsatisfactionproblems(CSPs):▪ Aspecialsubsetofsearchproblems▪ StateisdefinedbyvariablesXiwithvaluesfroma
domainD (sometimesDdependsoni)▪ Goaltestisasetofconstraintsspecifyingallowable
combinationsofvaluesforsubsetsofvariables
▪ Allowsusefulgeneral-purposealgorithmswithmorepowerthanstandardsearchalgorithms
![Page 5: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/5.jpg)
CSPExamples
![Page 6: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/6.jpg)
Example:MapColoring
▪ Variables:
▪ Domains:
▪ Constraints:adjacentregionsmusthavedifferentcolors
▪ Solutionsareassignmentssatisfyingallconstraints,e.g.:
Implicit:
Explicit:
![Page 7: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/7.jpg)
Example:N-Queens
▪ Formulation1:▪ Variables:▪ Domains:
▪ Constraints
![Page 8: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/8.jpg)
Example:N-Queens
▪ Formulation2:▪ Variables:
▪ Domains:
▪ Constraints:Implicit:
Explicit:
![Page 9: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/9.jpg)
ConstraintGraphs
![Page 10: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/10.jpg)
ConstraintGraphs
▪ BinaryCSP:eachconstraintrelates(atmost)twovariables
▪ Binaryconstraintgraph:nodesarevariables,arcsshowconstraints
▪ General-purposeCSPalgorithmsusethegraphstructuretospeedupsearch.E.g.,Tasmaniaisanindependentsubproblem!
![Page 11: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/11.jpg)
Example:Cryptarithmetic
▪ Variables:
▪ Domains:
▪ Constraints:
![Page 12: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/12.jpg)
Example:Sudoku
▪ Variables:
▪ Each(open)square
▪ Domains:
▪ {1,2,…,9}
▪ Constraints:
9-wayalldiffforeachrow
9-wayalldiffforeachcolumn
9-wayalldiffforeachregion
(orcanhaveabunchofpairwiseinequalityconstraints)
![Page 13: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/13.jpg)
VarietiesofCSPs
▪ DiscreteVariables▪ Finitedomains
▪ SizedmeansO(dn)completeassignments▪ E.g.,BooleanCSPs,includingBooleansatisfiability(NP-complete)
▪ Infinitedomains(integers,strings,etc.)▪ E.g.,jobscheduling,variablesarestart/endtimesforeachjob▪ Linearconstraintssolvable,nonlinearundecidable
▪ Continuousvariables▪ E.g.,start/endtimesforHubbleTelescopeobservations▪ LinearconstraintssolvableinpolynomialtimebyLPmethods
![Page 14: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/14.jpg)
VarietiesofConstraints
▪ VarietiesofConstraints▪ Unaryconstraintsinvolveasinglevariable(equivalenttoreducing
domains),e.g.:
▪ Binaryconstraintsinvolvepairsofvariables,e.g.:
▪ Higher-orderconstraintsinvolve3ormorevariables: e.g.,cryptarithmeticcolumnconstraints
▪ Preferences(softconstraints):▪ E.g.,redisbetterthangreen▪ Oftenrepresentablebyacostforeachvariableassignment▪ Givesconstrainedoptimizationproblems▪ (We’llignoretheseuntilwegettoBayes’nets)
![Page 15: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/15.jpg)
Real-WorldCSPs
▪ Assignmentproblems:e.g.,whoteacheswhatclass▪ Timetablingproblems:e.g.,whichclassisofferedwhenandwhere?▪ Hardwareconfiguration▪ Transportationscheduling▪ Factoryscheduling▪ Circuitlayout▪ Faultdiagnosis▪ …lotsmore!
▪ Manyreal-worldproblemsinvolvereal-valuedvariables…
![Page 16: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/16.jpg)
SolvingCSPs
![Page 17: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/17.jpg)
StandardSearchFormulation
▪ StandardsearchformulationofCSPs
▪ Statesdefinedbythevaluesassignedsofar(partialassignments)▪ Initialstate:theemptyassignment,{}▪ Successorfunction:assignavaluetoanunassignedvariable
▪ Goaltest:thecurrentassignmentiscompleteandsatisfiesallconstraints
▪ We’llstartwiththestraightforward,naïveapproach,thenimproveit
![Page 18: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/18.jpg)
SearchMethods
▪ WhatwouldBFSdo?
▪ WhatwouldDFSdo?
![Page 19: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/19.jpg)
Demo:DFSCSP
![Page 20: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/20.jpg)
SearchMethods
▪ WhatwouldBFSdo?
▪ WhatwouldDFSdo?
▪ Whatproblemsdoesnaïvesearchhave?
![Page 21: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/21.jpg)
BacktrackingSearch
![Page 22: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/22.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-firstsearchwiththesetwoimprovements iscalledbacktrackingsearch(notthebestname)
▪ Cansolven-queensforn≈25
![Page 23: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/23.jpg)
BacktrackingExample
![Page 24: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/24.jpg)
BacktrackingSearch
▪ Backtracking=DFS+variable-ordering+fail-on-violation
![Page 25: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/25.jpg)
Demo:Backtracking
![Page 26: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/26.jpg)
ImprovingBacktracking
▪ General-purposeideasgivehugegainsinspeed
▪ Ordering:▪ Whichvariableshouldbeassignednext?▪ Inwhatordershoulditsvaluesbetried?
▪ Filtering:Canwedetectinevitablefailureearly?
▪ Structure:Canweexploittheproblemstructure?
![Page 27: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/27.jpg)
▪ Filtering:Keeptrackofdomainsforunassignedvariablesandcrossoffbadoptions
▪ Forwardchecking:Crossoffvaluesthatviolateaconstraintwhenaddedtotheexistingassignment
Filtering:ForwardChecking
WASANT Q
NSW
V
![Page 28: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/28.jpg)
Demo:BacktrackingwithForwardChecking
![Page 29: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/29.jpg)
Filtering:ConstraintPropagation
▪ Forwardcheckingpropagatesinformationfromassignedtounassignedvariables,butdoesn'tprovideearlydetectionforallfailures:
▪ NTandSAcannotbothbeblue!▪ Whydidn’twedetectthisyet?▪ Constraintpropagation:reasonfromconstrainttoconstraint
WASA
NT Q
NSW
V
![Page 30: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/30.jpg)
ConsistencyofASingleArc
▪ AnarcX→ Yisconsistentiffforeveryxinthetailthereissomeyintheheadwhichcouldbeassignedwithoutviolatingaconstraint
▪ Forwardchecking:Enforcingconsistencyofarcspointingtoeachnewassignment
Deletefromthetail!
WA SA
NT Q
NSW
V
![Page 31: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/31.jpg)
ArcConsistencyofanEntireCSP
▪ Asimpleformofpropagationmakessureallarcsareconsistent:
▪ Important:IfXlosesavalue,neighborsofXneedtoberechecked!▪ Arcconsistencydetectsfailureearlierthanforwardchecking▪ Canberunasapreprocessororaftereachassignment▪ What’sthedownsideofenforcingarcconsistency?
Remember:Deletefromthetail!
WA SA
NT Q
NSW
V
![Page 32: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/32.jpg)
EnforcingArcConsistencyinaCSP
▪ Runtime:O(n2d3),canbereducedtoO(n2d2)▪ …butdetectingallpossiblefutureproblemsisNP-hard–why?
![Page 33: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/33.jpg)
Demo:Arcconsistency
![Page 34: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/34.jpg)
LimitationsofArcConsistency
▪ Afterenforcingarcconsistency:▪ Canhaveonesolutionleft▪ Canhavemultiplesolutionsleft
▪ Canhavenosolutionsleft(andnotknowit)
▪ Arcconsistencystillrunsinsideabacktrackingsearch! Whatwent
wronghere?
![Page 35: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/35.jpg)
Ordering
![Page 36: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/36.jpg)
Ordering:MinimumRemainingValues
▪ VariableOrdering:Minimumremainingvalues(MRV):▪ Choosethevariablewiththefewestlegalleftvaluesinitsdomain
▪ Whyminratherthanmax?
▪ Alsocalled“mostconstrainedvariable”
▪ “Fail-fast”ordering
![Page 37: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/37.jpg)
Ordering:LeastConstrainingValue
▪ ValueOrdering:LeastConstrainingValue▪ Givenachoiceofvariable,choosetheleastconstrainingvalue
▪ I.e.,theonethatrulesoutthefewestvaluesintheremainingvariables
▪ Notethatitmaytakesomecomputationtodeterminethis!(E.g.,rerunningfiltering)
▪ Whyleastratherthanmost?
▪ Combiningtheseorderingideasmakes 1000queensfeasible
![Page 38: lecture5 - cs.utexas.edu · Title: lecture5 Created Date: 9/17/2018 3:00:55 AM](https://reader036.vdocuments.mx/reader036/viewer/2022081407/6054c7c20607f54ea82e4564/html5/thumbnails/38.jpg)
Demo:Backtracking+ForwardChecking+Ordering