constraint satisfaction problems - wuwei lan · § binary csp: each constraint relates (at most)...

Post on 15-Jul-2020

5 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

ConstraintSatisfactionProblems

§ Standardsearchproblems:§ Stateisa“blackbox”:arbitrarydatastructure§ Goaltestcanbeanyfunctionoverstates§ Successorfunctioncanalsobeanything

§ Constraintsatisfactionproblems(CSPs):§ Aspecialsubsetofsearchproblems§ StateisdefinedbyvariablesXi withvaluesfroma

domainD (sometimesD dependsoni)§ Goaltestisasetofconstraintsspecifyingallowable

combinationsofvaluesforsubsetsofvariables

§ Simpleexampleofaformalrepresentationlanguage

§ 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:

WaltzonSimpleScenes

§ Assumeallobjects:§ Havenoshadowsorcracks§ Three-facedvertices§ “Generalposition”:nojunctionschangewithsmallmovementsoftheeye.

§ Theneachlineonimageisoneofthefollowing:§ Boundaryline(edgeofanobject)(®)withrighthandofarrowdenoting“solid”andlefthanddenoting“space”

§ Interiorconvexedge(+)§ Interiorconcaveedge(-)

6

LegalJunctions

§ Onlycertainjunctionsarephysicallypossible

§ HowcanweformulateaCSPtolabelanimage?

§ Variables:vertices§ Domains:junctionlabels§ Constraints:bothendsofaline

shouldhavethesamelabel

7

x

y(x,y) in

, , …

ConstraintGraphs

§ BinaryCSP:eachconstraintrelates(atmost)twovariables

§ Binaryconstraintgraph:nodesarevariables,arcsshowconstraints

§ General-purposeCSPalgorithmsusethegraphstructuretospeedupsearch.E.g.,Tasmaniaisanindependentsubproblem!

[Demo:CSPapplet(madeavailablebyaispace.org)-- n-queens]

Example:Cryptarithmetic

§ Variables:

§ Domains:

§ Constraints:

Real-WorldCSPs

§ Schedulingproblems:e.g.,whencanweallmeet?§ Timetablingproblems:e.g.,whichclassisofferedwhenandwhere?§ Assignmentproblems:e.g.,whoteacheswhatclass§ Hardwareconfiguration§ Transportationscheduling§ Factoryscheduling§ Circuitlayout§ Faultdiagnosis§ …lotsmore!

§ Manyreal-worldproblemsinvolvereal-valuedvariables…

StandardSearchFormulation

§ StandardsearchformulationofCSPs

§ Statesdefinedbythevaluesassignedsofar(partialassignments)§ Initialstate:theemptyassignment,{}§ Successorfunction:assignavaluetoanunassignedvariable

§ Goaltest:thecurrentassignmentiscompleteandsatisfiesallconstraints

§ We’llstartwiththestraightforward,naïveapproach,thenimproveit

BacktrackingSearch

§ BacktrackingsearchisthebasicuninformedalgorithmforsolvingCSPs

§ Idea1:Onevariableatatime§ Variableassignmentsarecommutative,sofixordering§ I.e.,[WA=redthenNT=green]sameas[NT=greenthenWA=red]§ Onlyneedtoconsiderassignmentstoasinglevariableateachstep

§ Idea2:Checkconstraintsasyougo§ I.e.consideronlyvalueswhichdonotconflictwithpreviousassignments§ Mighthavetodosomecomputationtochecktheconstraints§ “Incrementalgoaltest”

§ Depth-firstsearchwiththesetwoimprovementsiscalledbacktrackingsearch(notthebestname)

§ Cansolven-queensforn» 25

BacktrackingExample

BacktrackingSearch

§ Backtracking=DFS+variable-ordering+fail-on-violation§ Whatarethechoicepoints?

[Demo:coloring-- backtracking]

ImprovingBacktracking

§ General-purposeideasgivehugegainsinspeed

§ Filtering:Canwedetectinevitablefailureearly?

§ Ordering:§ Whichvariableshouldbeassignednext?§ Inwhatordershoulditsvaluesbetried?

§ Structure:Canweexploittheproblemstructure?

ImprovingBacktracking

From https://kti.mff.cuni.cz/~bartak/constraints/propagation.html

Filtering

§ Filtering:Keeptrackofdomainsforunassignedvariablesandcrossoffbadoptions§ Forwardchecking:Crossoffvaluesthatviolateaconstraintwhenaddedtotheexisting

assignment

Filtering:ForwardChecking

WASANT Q

NSWV

[Demo:coloring-- forwardchecking]

VideoofDemoColoring– BacktrackingwithForwardChecking

Filtering:ConstraintPropagation

§ Forwardcheckingpropagatesinformationfromassignedtounassignedvariables,butdoesn'tprovideearlydetectionforallfailures:

§ NTandSAcannotbothbeblue!§ Whydidn’twedetectthisyet?§ Constraintpropagation:reasonfromconstrainttoconstraint

WA SA

NT Q

NSW

V

ConsistencyofASingleArc

§ AnarcX® Yisconsistent iff foreveryxinthetailthereissomeyintheheadwhichcouldbeassignedwithoutviolatingaconstraint

§ 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:CSPapplet(madeavailablebyaispace.org)-- n-queens]

LimitationsofArcConsistency

§ Afterenforcingarcconsistency:§ Canhaveonesolutionleft§ Canhavemultiplesolutionsleft§ Canhavenosolutionsleft(andnotknowit)

§ Arcconsistencystillrunsinsideabacktrackingsearch!

Whatwentwronghere?

[Demo:coloring-- arcconsistency][Demo:coloring-- forwardchecking]

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?

§ Combiningtheseorderingideasmakes1000queensfeasible

[Demo:coloring– backtracking+AC+ordering]

top related