+ All Categories
Home > Documents > CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf ·...

CSE 573: Artificial Intelligencecourses.cs.washington.edu/courses/cse573/17wi/slides/18-CSP.pdf ·...

Date post: 20-Jul-2020
Category:
Upload: others
View: 12 times
Download: 0 times
Share this document with a friend
91
CSE 573: Artificial Intelligence Constraint Satisfaction Problems Factored (aka Structured) Search [With many slides by Dan Klein and Pieter Abbeel (UC Berkeley) available at http://ai.berkeley.edu.]
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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

§ 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

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

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

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

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

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

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

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

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

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

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

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

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

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

§ 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Summary:CSPs

§ CSPsareaspecialkindofsearchproblem:§ Statesarepartialassignments§ Goaltestdefinedbyconstraints

§ Basicsolution:backtrackingsearch

§ Speed-ups:§ Ordering§ Filtering§ Structure(cutset conditioning)

§ Iterativemin-conflictsisofteneffectiveinpractice


Recommended