CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial...

73
CSE 473: Ar+ficial Intelligence Constraint Sa+sfac+on Problems Instructor: Luke Ze@lemoyer University of Washington [These slides were created by Dan Klein and Pieter Abbeel for CS188 Intro to AI at UC Berkeley. All CS188 materials are available at h@p://ai.berkeley.edu.]

Transcript of CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial...

Page 1: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

CSE473:Ar+ficialIntelligenceConstraintSa+sfac+onProblems

Instructor:LukeZe@lemoyer

UniversityofWashington[TheseslideswerecreatedbyDanKleinandPieterAbbeelforCS188IntrotoAIatUCBerkeley.AllCS188materialsareavailableath@p://ai.berkeley.edu.]

Page 2: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

WhatisSearchFor?§  Assump+onsabouttheworld:asingleagent,determinis+cac+ons,fullyobserved

state,discretestatespace

§  Planning:sequencesofac+ons§  Thepathtothegoalistheimportantthing§  Pathshavevariouscosts,depths§  Heuris+csgiveproblem-specificguidance

§  Iden+fica+on:assignmentstovariables§  Thegoalitselfisimportant,notthepath§  Allpathsatthesamedepth(forsomeformula+ons)§  CSPsarespecializedforiden+fica+onproblems

Page 3: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

ConstraintSa+sfac+onProblems

Page 4: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

ConstraintSa+sfac+onProblems

§  Standardsearchproblems:§  Stateisa“blackbox”:arbitrarydatastructure§  Goaltestcanbeanyfunc+onoverstates§  Successorfunc+oncanalsobeanything

§  Constraintsa+sfac+onproblems(CSPs):§  Aspecialsubsetofsearchproblems§  StateisdefinedbyvariablesXiwithvaluesfroma

domainD (some+mesDdependsoni)§  Goaltestisasetofconstraintsspecifyingallowable

combina+onsofvaluesforsubsetsofvariables

§  Simpleexampleofaformalrepresenta-onlanguage

§  Allowsusefulgeneral-purposealgorithmswithmorepowerthanstandardsearchalgorithms

Page 5: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

CSPExamples

Page 6: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Example:MapColoring

§  Variables:

§  Domains:

§  Constraints:adjacentregionsmusthavedifferentcolors

§  Solu+onsareassignmentssa+sfyingallconstraints,e.g.:

Implicit:

Explicit:

Page 7: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Example:N-Queens

§  Formula+on1:§  Variables:§  Domains:§  Constraints

Page 8: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Example:N-Queens

§  Formula+on2:§  Variables:

§  Domains:

§  Constraints:Implicit:

Explicit:

Page 9: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

ConstraintGraphs

Page 10: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

ConstraintGraphs

§  BinaryCSP:eachconstraintrelates(atmost)twovariables

§  Binaryconstraintgraph:nodesarevariables,arcsshowconstraints

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

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

Page 11: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

ScreenshotofDemoN-Queens

Page 12: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Example:Cryptarithme+c

§  Variables:

§  Domains:

§  Constraints:

Page 13: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Example:Sudoku

§  Variables:§  Each(open)square

§  Domains:§  {1,2,…,9}

§  Constraints:

9-wayalldiffforeachrow

9-wayalldiffforeachcolumn

9-wayalldiffforeachregion

(orcanhaveabunchofpairwiseinequalityconstraints)

Page 14: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Example:TheWaltzAlgorithm

§  TheWaltzalgorithmisforinterpre+nglinedrawingsofsolidpolyhedraas3Dobjects

§  AnearlyexampleofanAIcomputa+onposedasaCSP

? §  Approach:

§  Eachintersec+onisavariable§  Adjacentintersec+onsimposeconstraints

oneachother§  Solu+onsarephysicallyrealizable3D

interpreta+ons

Page 15: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Example:TheWaltzAlgorithm

§  TheWaltzalgorithmisforinterpre+nglinedrawingsofsolidpolyhedraas3Dobjects

§  AnearlyexampleofanAIcomputa+onposedasaCSP

§  Approach:§  Eachintersec+onisavariable§  Adjacentintersec+onsimposeconstraints

oneachother§  Solu+onsarephysicallyrealizable3D

interpreta+ons

?

Page 16: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Varie+esofCSPsandConstraints

Page 17: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Varie+esofCSPs

§  DiscreteVariables§  Finitedomains

§  SizedmeansO(dn)completeassignments§  E.g.,BooleanCSPs,includingBooleansa+sfiability(NP-complete)

§  Infinitedomains(integers,strings,etc.)§  E.g.,jobscheduling,variablesarestart/end+mesforeachjob§  Linearconstraintssolvable,nonlinearundecidable

§  Con+nuousvariables§  E.g.,start/end+mesforHubbleTelescopeobserva+ons§  Linearconstraintssolvableinpolynomial+mebyLPmethods

(seecs170forabitofthistheory)

Page 18: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Varie+esofConstraints

§  Varie+esofConstraints§  Unaryconstraintsinvolveasinglevariable(equivalentto

reducingdomains),e.g.:

§  Binaryconstraintsinvolvepairsofvariables,e.g.:

§  Higher-orderconstraintsinvolve3ormorevariables:e.g.,cryptarithme+ccolumnconstraints

§  Preferences(somconstraints):§  E.g.,redisbe@erthangreen§  Omenrepresentablebyacostforeachvariableassignment§  Givesconstrainedop+miza+onproblems§  (We’llignoretheseun+lwegettoBayes’nets)

Page 19: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Real-WorldCSPs

§  Assignmentproblems:e.g.,whoteacheswhatclass§  Timetablingproblems:e.g.,whichclassisofferedwhenandwhere?§  Hardwareconfigura+on§  Transporta+onscheduling§  Factoryscheduling§  Circuitlayout§  Faultdiagnosis§  …lotsmore!

§  Manyreal-worldproblemsinvolvereal-valuedvariables…

Page 20: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

SolvingCSPs

Page 21: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

StandardSearchFormula+on

§  Standardsearchformula+onofCSPs

§  Statesdefinedbythevaluesassignedsofar(par+alassignments)§  Ini+alstate:theemptyassignment,{}§  Successorfunc+on:assignavaluetoanunassignedvariable

§  Goaltest:thecurrentassignmentiscompleteandsa+sfiesallconstraints

§  We’llstartwiththestraighqorward,naïveapproach,thenimproveit

Page 22: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

SearchMethods

§  WhatwouldBFSdo?

§  WhatwouldDFSdo?

§  Whatproblemsdoesnaïvesearchhave?

[Demo:coloring--dfs]

Page 23: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

VideoofDemo

Coloring--DFS

Page 24: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

BacktrackingSearch

Page 25: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

BacktrackingSearch

§  BacktrackingsearchisthebasicuninformedalgorithmforsolvingCSPs

§  Idea1:Onevariableata+me§  Variableassignmentsarecommuta+ve,sofixordering§  I.e.,[WA=redthenNT=green]sameas[NT=greenthenWA=red]§  Onlyneedtoconsiderassignmentstoasinglevariableateachstep

§  Idea2:Checkconstraintsasyougo§  I.e.consideronlyvalueswhichdonotconflictpreviousassignments§  Mighthavetodosomecomputa+ontochecktheconstraints§  “Incrementalgoaltest”

§  Depth-firstsearchwiththesetwoimprovementsiscalledbacktrackingsearch(notthebestname)

§  Cansolven-queensforn≈25

Page 26: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

BacktrackingExample

Page 27: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

BacktrackingSearch

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

[Demo:coloring--backtracking]

Page 28: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

VideoofDemo

Coloring–Backtracking

Page 29: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

VideoofDemo

Coloring–Backtracking

Page 30: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

ImprovingBacktracking

§  General-purposeideasgivehugegainsinspeed§  …butit’salls+llNP-hard

§  Filtering:Canwedetectinevitablefailureearly?

§  Ordering:§  Whichvariableshouldbeassignednext?(MRV)§  Inwhatordershoulditsvaluesbetried?(LCV)

§  Structure:Canweexploittheproblemstructure?

Page 31: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

ArcConsistencyandBeyond

Page 32: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

ForwardChecking

§  Idea:Keeptrackofremaininglegalvaluesforunassignedvariables(usingimmediateconstraints)

§  Idea:Terminatewhenanyvariablehasnolegalvalues

WA SA NT Q

NSW V

Page 33: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

ForwardChecking

Page 34: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

AreWeDone?

Page 35: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

ConstraintPropaga+on

§  Forwardcheckingpropagatesinforma+onfromassignedtoadjacentunassignedvariables,butdoesn'tdetectmoredistantfailures:

WA SA NT Q

NSW V

§  NT and SA cannot both be blue! §  Why didn’t we detect this yet? §  Constraint propagation repeatedly enforces constraints (locally)

Page 36: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

ArcConsistencyofanEn+reCSP§  Asimpleformofpropaga+onmakessureallarcsaresimultaneouslyconsistent:

§  Arcconsistencydetectsfailureearlierthanforwardchecking§  Important:IfXlosesavalue,neighborsofXneedtoberechecked!§  Mustrerunamereachassignment!

Remember:Deletefromthetail!

WA SA

NT Q

NSW

V

Page 37: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

ConstraintPropaga+on

Page 38: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

AreWeDone?

Page 39: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Limita+onsofArcConsistency

§  Amerenforcingarcconsistency:§  Canhaveonesolu+onlem§  Canhavemul+plesolu+onslem§  Canhavenosolu+onslem(andnotknowit)

§  Arcconsistencys+llrunsinsideabacktrackingsearch!

Whatwentwronghere?

Page 40: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Ordering:MinimumRemainingValues

§  Minimumremainingvalues(MRV):§  Choosethevariablewiththefewestlegalvalues

§  Whyminratherthanmax?§  Alsocalled“mostconstrainedvariable”§  “Fail-fast”ordering

Page 41: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Ordering:DegreeHeuris+c

§  Tie-breakeramongMRVvariables§  Degreeheuris+c:

§  Choosethevariablepar+cipa+nginthemostconstraintsonremainingvariables

§  Whymostratherthanfewestconstraints?

Page 42: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Ordering:LeastConstrainingValue

§  Givenachoiceofvariable:§  Choosetheleastconstrainingvalue§  Theonethatrulesoutthefewestvaluesinthe

remainingvariables§  Notethatitmaytakesomecomputa+onto

determinethis!

§  Whyleastratherthanmost?

§  Combiningtheseheuris+csmakes1000queensfeasible

Page 43: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Propaga+onwithOrdering

Page 44: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

K-Consistency

Page 45: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

K-Consistency§  Increasingdegreesofconsistency

§  1-Consistency(NodeConsistency):Eachsinglenode’sdomainhasavaluewhichmeetsthatnode’sunaryconstraints

§  2-Consistency(ArcConsistency):Foreachpairofnodes,anyconsistentassignmenttoonecanbeextendedtotheother

§  K-Consistency:Foreachknodes,anyconsistentassignmenttok-1canbeextendedtothekthnode.

§  Higherkmoreexpensivetocompute

§  (Youneedtoknowthek=2case:arcconsistency)

Page 46: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

StrongK-Consistency

§  Strongk-consistency:alsok-1,k-2,…1consistent

§  Claim:strongn-consistencymeanswecansolvewithoutbacktracking!

§  Why?§  Chooseanyassignmenttoanyvariable§  Chooseanewvariable§  By2-consistency,thereisachoiceconsistentwiththefirst§  Chooseanewvariable§  By3-consistency,thereisachoiceconsistentwiththefirst2§  …

§  Lotsofmiddlegroundbetweenarcconsistencyandn-consistency!(e.g.k=3,calledpathconsistency)

Page 47: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Structure

Page 48: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

ProblemStructure

§  Extremecase:independentsubproblems§  Example:Tasmaniaandmainlanddonotinteract

§  Independentsubproblemsareiden+fiableasconnectedcomponentsofconstraintgraph

§  Supposeagraphofnvariablescanbebrokenintosubproblemsofonlycvariables:§  Worst-casesolu+oncostisO((n/c)(dc)),linearinn§  E.g.,n=80,d=2,c=20§  280=4billionyearsat10millionnodes/sec§  (4)(220)=0.4secondsat10millionnodes/sec

Page 49: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Tree-StructuredCSPs

§  Theorem:iftheconstraintgraphhasnoloops,theCSPcanbesolvedinO(nd2)+me§  ComparetogeneralCSPs,whereworst-case+meisO(dn)

§  Thispropertyalsoappliestoprobabilis+creasoning(earlier):anexampleoftherela+onbetweensyntac+crestric+onsandthecomplexityofreasoning

Page 50: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Tree-StructuredCSPs§  Algorithmfortree-structuredCSPs:

§  Order:Choosearootvariable,ordervariablessothatparentsprecedechildren

§  Removebackward:Fori=n:2,applyRemoveInconsistent(Parent(Xi),Xi)§  Assignforward:Fori=1:n,assignXiconsistentlywithParent(Xi)

§  Run+me:O(nd2)(why?)

Page 51: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Tree-StructuredCSPs

§  Claim1:Amerbackwardpass,allroot-to-leafarcsareconsistent§  Proof:EachX→YwasmadeconsistentatonepointandY’sdomaincouldnothave

beenreducedthereamer(becauseY’schildrenwereprocessedbeforeY)

§  Claim2:Ifroot-to-leafarcsareconsistent,forwardassignmentwillnotbacktrack§  Proof:Induc+ononposi+on

§  Whydoesn’tthisalgorithmworkwithcyclesintheconstraintgraph?

§  Note:samebasicideaasvariableelimina+oninBayes’nets

Page 52: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

ImprovingStructure

Page 53: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

NearlyTree-StructuredCSPs

Page 54: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

NearlyTree-StructuredCSPs

§  Condi+oning:instan+ateavariable,pruneitsneighbors'domains

§  Cutsetcondi+oning:instan+ate(inallways)asetofvariablessuchthattheremainingconstraintgraphisatree

§  Cutsetsizecgivesrun+meO((dc)(n-c)d2),veryfastforsmallc

Page 55: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

CutsetCondi+oning

SA

SA SA SA

Instan+atethecutset(allpossibleways)

ComputeresidualCSPforeachassignment

SolvetheresidualCSPs(treestructured)

Chooseacutset

Page 56: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

CutsetQuiz

§  Findthesmallestcutsetforthegraphbelow.

Page 57: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

TreeDecomposi+on*§  Idea:createatree-structuredgraphofmega-variables§  Eachmega-variableencodespartoftheoriginalCSP§  Subproblemsoverlaptoensureconsistentsolu+ons

M1 M2 M3 M4

{(WA=r,SA=g,NT=b), (WA=b,SA=r,NT=g), …}

{(NT=r,SA=g,Q=b), (NT=b,SA=g,Q=r), …}

Agree: (M1,M2) ∈ {((WA=g,SA=g,NT=g), (NT=g,SA=g,Q=g)), …}

Agree on shared vars

NT

SA

≠ WA

≠ ≠

Q

SA

≠ NT

≠ ≠

Agree on shared vars

NSW

SA

≠ Q

≠ ≠

Agree on shared vars

V

SA

≠ NSW

≠ ≠

Page 58: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Itera+veImprovement

Page 59: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Itera+veAlgorithmsforCSPs

§  Localsearchmethodstypicallyworkwith“complete”states,i.e.,allvariablesassigned

§  ToapplytoCSPs:§  Takeanassignmentwithunsa+sfiedconstraints§  Operatorsreassignvariablevalues§  Nofringe!Liveontheedge.

§  Algorithm:Whilenotsolved,§  Variableselec+on:randomlyselectanyconflictedvariable§  Valueselec+on:min-conflictsheuris+c:

§  Chooseavaluethatviolatesthefewestconstraints§  I.e.,hillclimbwithh(n)=totalnumberofviolatedconstraints

Page 60: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Example:4-Queens

§  States:4queensin4columns(44=256states)§  Operators:movequeenincolumn§  Goaltest:noa@acks§  Evalua+on:c(n)=numberofa@acks

[Demo:n-queens–itera+veimprovement(L5D1)][Demo:coloring–itera+veimprovement]

Page 61: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

VideoofDemoItera+veImprovement–nQueens

Page 62: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

VideoofDemoItera+veImprovement–Coloring

Page 63: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

PerformanceofMin-Conflicts

§  Givenrandomini+alstate,cansolven-queensinalmostconstant+meforarbitrarynwithhighprobability(e.g.,n=10,000,000)!

§  Thesameappearstobetrueforanyrandomly-generatedCSPexceptinanarrowrangeofthera+o

Page 64: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Summary:CSPs

§  CSPsareaspecialkindofsearchproblem:§  Statesarepar+alassignments§  Goaltestdefinedbyconstraints

§  Basicsolu+on:backtrackingsearch

§  Speed-ups:§  Ordering§  Filtering§  Structure

§  Itera+vemin-conflictsisomeneffec+veinprac+ce

Page 65: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

LocalSearch

Page 66: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

LocalSearch

§  Treesearchkeepsunexploredalterna+vesonthefringe(ensurescompleteness)

§  Localsearch:improveasingleop+onun+lyoucan’tmakeitbe@er(nofringe!)

§  Newsuccessorfunc+on:localchanges

§  Generallymuchfasterandmorememoryefficient(butincompleteandsubop+mal)

Page 67: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

HillClimbing

§  Simple,generalidea:§  Startwherever§  Repeat:movetothebestneighboringstate§  Ifnoneighborsbe@erthancurrent,quit

§  What’sbadaboutthisapproach?§  Complete?§  Op+mal?

§  What’sgoodaboutit?

Page 68: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

HillClimbingDiagram

Page 69: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

HillClimbingQuiz

Star+ngfromX,wheredoyouendup?

Star+ngfromY,wheredoyouendup?Star+ngfromZ,wheredoyouendup?

Page 70: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

SimulatedAnnealing§  Idea:Escapelocalmaximabyallowingdownhillmoves

§  Butmakethemrareras+megoeson

70

Page 71: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

SimulatedAnnealing

§  Theore+calguarantee:§  Sta+onarydistribu+on:§  IfTdecreasedslowlyenough,willconvergetoop+malstate!

§  Isthisaninteres+ngguarantee?

§  Soundslikemagic,butrealityisreality:§  Themoredownhillstepsyouneedtoescapealocalop+mum,thelesslikelyyouaretoevermakethemallinarow

§  Peoplethinkhardaboutridgeoperatorswhichletyoujumparoundthespaceinbe@erways

Page 72: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Gene+cAlgorithms

§  Gene+calgorithmsuseanaturalselec+onmetaphor§  KeepbestNhypothesesateachstep(selec+on)basedonafitnessfunc+on§  Alsohavepairwisecrossoveroperators,withop+onalmuta+ontogivevariety

§  Possiblythemostmisunderstood,misapplied(andevenmaligned)techniquearound

Page 73: CSE 473: Ar+ficial Intelligence - University of Washington · 2018-03-04 · CSE 473: Ar+ficial Intelligence Constraint Sasfac+on Problems Instructor: Luke Ze@lemoyer University

Example:N-Queens

§  Whydoescrossovermakesensehere?§  Whenwouldn’titmakesense?§  Whatwouldmuta+onbe?§  Whatwouldagoodfitnessfunc+onbe?