Upload
others
View
4
Download
0
Embed Size (px)
Citation preview
CS343H:HonorsArtificialIntelligenceConstraintSatisfactionProblems
Prof.PeterStone
TheUniversityofTexasatAustin[TheseslidesarebasedonthoseofDanKleinandPieterAbbeelforCS188IntrotoAIatUCBerkeley.AllCS188materialsareavailableathttp://ai.berkeley.edu.]
WhatisSearchFor?
▪ Assumptionsabouttheworld:asingleagent,deterministicactions,fullyobservedstate,discretestatespace
▪ Planning:sequencesofactions▪ Thepathtothegoalistheimportantthing▪ Pathshavevariouscosts,depths▪ Heuristicsgiveproblem-specificguidance
▪ Identification:assignmentstovariables▪ Thegoalitselfisimportant,notthepath▪ Allpathsatthesamedepth(forsomeformulations)▪ CSPsarespecializedforidentificationproblems
ConstraintSatisfactionProblems
ConstraintSatisfactionProblems
▪ Standardsearchproblems:▪ Stateisa“blackbox”:arbitrarydatastructure▪ Goaltestcanbeanyfunctionoverstates▪ Successorfunctioncanalsobeanything
▪ Constraintsatisfactionproblems(CSPs):▪ Aspecialsubsetofsearchproblems▪ StateisdefinedbyvariablesXiwithvaluesfroma
domainD (sometimesDdependsoni)▪ Goaltestisasetofconstraintsspecifyingallowable
combinationsofvaluesforsubsetsofvariables
▪ Allowsusefulgeneral-purposealgorithmswithmorepowerthanstandardsearchalgorithms
CSPExamples
Example:MapColoring
▪ Variables:
▪ Domains:
▪ Constraints:adjacentregionsmusthavedifferentcolors
▪ Solutionsareassignmentssatisfyingallconstraints,e.g.:
Implicit:
Explicit:
Example:N-Queens
▪ Formulation1:▪ Variables:▪ Domains:▪ Constraints
Example:N-Queens
▪ Formulation2:▪ Variables:
▪ Domains:
▪ Constraints:Implicit:
Explicit:
ConstraintGraphs
ConstraintGraphs
▪ BinaryCSP:eachconstraintrelates(atmost)twovariables
▪ Binaryconstraintgraph:nodesarevariables,arcsshowconstraints
▪ General-purposeCSPalgorithmsusethegraphstructuretospeedupsearch.E.g.,Tasmaniaisanindependentsubproblem!
Example:Cryptarithmetic
▪ Variables:
▪ Domains:
▪ Constraints:
Example:Sudoku
▪ Variables:▪ Each(open)square
▪ Domains:▪ {1,2,…,9}
▪ Constraints:
9-wayalldiffforeachrow
9-wayalldiffforeachcolumn
9-wayalldiffforeachregion
(orcanhaveabunchofpairwiseinequalityconstraints)
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
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)
Real-WorldCSPs
▪ Assignmentproblems:e.g.,whoteacheswhatclass▪ Timetablingproblems:e.g.,whichclassisofferedwhenandwhere?▪ Hardwareconfiguration▪ Transportationscheduling▪ Factoryscheduling▪ Circuitlayout▪ Faultdiagnosis▪ …lotsmore!
▪ Manyreal-worldproblemsinvolvereal-valuedvariables…
SolvingCSPs
StandardSearchFormulation
▪ StandardsearchformulationofCSPs
▪ Statesdefinedbythevaluesassignedsofar(partialassignments)▪ Initialstate:theemptyassignment,{}▪ Successorfunction:assignavaluetoanunassignedvariable
▪ Goaltest:thecurrentassignmentiscompleteandsatisfiesallconstraints
▪ We’llstartwiththestraightforward,naïveapproach,thenimproveit
SearchMethods
▪ WhatwouldBFSdo?
▪ WhatwouldDFSdo?
Demo:DFSCSP
SearchMethods
▪ WhatwouldBFSdo?
▪ WhatwouldDFSdo?
▪ Whatproblemsdoesnaïvesearchhave?
BacktrackingSearch
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
BacktrackingExample
BacktrackingSearch
▪ Backtracking=DFS+variable-ordering+fail-on-violation
Demo:Backtracking
ImprovingBacktracking
▪ General-purposeideasgivehugegainsinspeed
▪ Ordering:▪ Whichvariableshouldbeassignednext?▪ Inwhatordershoulditsvaluesbetried?
▪ Filtering:Canwedetectinevitablefailureearly?
▪ Structure:Canweexploittheproblemstructure?
▪ Filtering:Keeptrackofdomainsforunassignedvariablesandcrossoffbadoptions▪ Forwardchecking:Crossoffvaluesthatviolateaconstraintwhenaddedtotheexisting
assignment
Filtering:ForwardChecking
WASANT Q
NSW
V
Demo:BacktrackingwithForwardChecking
Filtering:ConstraintPropagation
▪ Forwardcheckingpropagatesinformationfromassignedtounassignedvariables,butdoesn'tprovideearlydetectionforallfailures:
▪ NTandSAcannotbothbeblue!▪ Whydidn’twedetectthisyet?▪ Constraintpropagation:reasonfromconstrainttoconstraint
WA SA
NT Q
NSW
V
ConsistencyofASingleArc
▪ AnarcX→ Yisconsistentiffforeveryxinthetailthereissomeyintheheadwhichcouldbeassignedwithoutviolatingaconstraint
▪ Forwardchecking:Enforcingconsistencyofarcspointingtoeachnewassignment
Deletefromthetail!
WA SA
NT Q
NSW
V
ArcConsistencyofanEntireCSP
▪ Asimpleformofpropagationmakessureallarcsareconsistent:
▪ Important:IfXlosesavalue,neighborsofXneedtoberechecked!▪ Arcconsistencydetectsfailureearlierthanforwardchecking▪ Canberunasapreprocessororaftereachassignment▪ What’sthedownsideofenforcingarcconsistency?
Remember:Deletefromthetail!
WA SA
NT Q
NSW
V
EnforcingArcConsistencyinaCSP
▪ Runtime:O(n2d3),canbereducedtoO(n2d2)▪ …butdetectingallpossiblefutureproblemsisNP-hard–why?
Demo:Arcconsistency
LimitationsofArcConsistency
▪ Afterenforcingarcconsistency:▪ Canhaveonesolutionleft▪ Canhavemultiplesolutionsleft▪ Canhavenosolutionsleft(andnotknowit)
▪ Arcconsistencystillrunsinsideabacktrackingsearch! Whatwent
wronghere?
Ordering
Ordering:MinimumRemainingValues
▪ VariableOrdering:Minimumremainingvalues(MRV):▪ Choosethevariablewiththefewestlegalleftvaluesinitsdomain
▪ Whyminratherthanmax?▪ Alsocalled“mostconstrainedvariable”▪ “Fail-fast”ordering
Ordering:LeastConstrainingValue
▪ ValueOrdering:LeastConstrainingValue▪ Givenachoiceofvariable,choosetheleastconstrainingvalue
▪ I.e.,theonethatrulesoutthefewestvaluesintheremainingvariables
▪ Notethatitmaytakesomecomputationtodeterminethis!(E.g.,rerunningfiltering)
▪ Whyleastratherthanmost?
▪ Combiningtheseorderingideasmakes 1000queensfeasible