270 likes | 281 Views
Explore incomplete inference techniques like node consistency and arc consistency in constraint satisfaction problems. Understand how hybrid algorithms optimize search processes.
E N D
CSPHybrid algorithms = search + incomplete inference Pedro Meseguer IIIA-CSIC Bellaterra, Spain
Overview Incomplete Inference • Motivation: solving subnetworks • Node consistency • Arc consistency • Constraint propagation • Generalized arc consistency Hybrid algorithms • Forward checking • Maintaining arc consistency CSP: Incomplete Inference
Inference: P P’ Inference legal operations on variables, domains, constraints • P’ is equivalent to P: Sol(P) = Sol(P’) • P’ is presumablyeasier to solve than P • smaller search space • constraints are more explicit Inference can be: • complete: produces the solutionadaptive consistency • incomplete: requires further searcharc consistency CSP: Incomplete Inference
Incomplete Inference: Local Consistency • P constraint network of n variables: Is P solvable ? • Simpler problem: • P1i, P2j, P3k,…subnetworks of P of 1, 2, 3,…variables • Are they solvable? • YES, but there are values that do not appear in any solution they can be removed from P • NO, P has no solution • #vars in subnet: 1 2 3 ……. • node arc path consistency consistency consistency • Empty domain: P has no solution !! CSP: Incomplete Inference
Unitary constraint on xi NC Algorithm: procedure NC-1 (X,D,C) forall xiX do forall a Dido if a Rithen Di:= Di-{a}; Di := DiRi i: 1,…, n Node Consistency (NC) NC: • Variable xiis node consistent iff every value of Di is allowed by Ri • P is NC iff every variable is NC CSP: Incomplete Inference
Binary Arc Consistency (AC) AC: • Constraint Cij is directional arc consistent (ij) iff for all aDi there is bDj such that (a, b)Rij • Constraint Cij is AC iff it is directional AC in both directions • A problem is AC iff every constraint is AC CSP: Incomplete Inference
Microstructure: permitted Xk c a b AC ¬AC ¬AC AC Xi Xj a a b b c c AC ¬AC AC: Example CSP: Incomplete Inference
Example: X1 X2 blue, red ≠ blue ≠ ≠ blue,red,green X3 X4 blue, green ≠ Filtering by Arc Consistency • If for aDi there not exists bDj such that (a, b)Rij,a can be removed from Di (a will not be in any sol) • Domain filtering: • Remove arc-inconsistent values • Until no changes CSP: Incomplete Inference
function revise (i,j variable): bool; change := FALSE; for all aDido if ¬$bDj st (a,b)Rij then Di :=Di - {a}; change :=TRUE; return change; Function revise(i,j) • Functionrevise(i,j): • Rij becomes directional arc-consistent • it may remove values of Di • iterate over other constraints Complexity: O(d2) CSP: Incomplete Inference
1 2 3 x1x2x3 1 2 3 1 2 3 1 2 3 x1x2x3 x1x2x3 x1x2x3 Example: 3-queens c12 is not arc-consistent because value 2 of d1 c21 is not arc-consistent because value 2 of d2 c32 is not arc-consistent because value 2 of d3 CSP: Incomplete Inference
AC Constraint Propagation • AC(c): procedure to make c arc consistent • To make P arc-consistent, process each constraint ? c1c2 … cr c1c2 … cr c1c2 … cr c1c2 … cr • But AC(c) may render other constraints arc-inconsistent • To make P arc-consistent, iterate: • Apply AC on {c1,c2,…,cr } • Until no changes in domains: fix point CSP: Incomplete Inference
1 2 3 1 2 3 1 2 3 x1x2x3 x1x2x3 x1x2x3 1 2 3 1 2 3 1 2 3 this makes c13 arc-inconsistent x1x2x3 x1x2x3 x1x2x3 domain d1 empty no solution !! Example: 3-queens value 2 of d3 was removed(to make c23 arc-consistent) c13 is not arc-consistent because value 1 of d1 c13 is not arc-consistent because value 3 of d1 CSP: Incomplete Inference
x + y = 9 2x + 4y = 24 x + y = 9 x + y = 9 x + y = 9 x + y = 9 x + y = 9 2x + 4y = 24 2x + 4y = 24 2x + 4y = 24 2x + 4y = 24 2x + 4y = 24 2x + 4y = 24 x + y = 9 x 0 1 2 3 4 5 6 7 8 9 x 0 1 2 3 4 5 6 7 8 9 x 0 1 2 3 4 5 6 7 8 9 x 0 1 2 3 4 5 6 7 8 9 x 0 1 2 3 4 5 6 7 8 9 x 0 1 2 3 4 5 6 7 8 9 y 0 1 2 3 4 5 6 7 8 9 y 0 1 2 3 4 5 6 7 8 9 y 0 1 2 3 4 5 6 7 8 9 y 0 1 2 3 4 5 6 7 8 9 y 0 1 2 3 4 5 6 7 8 9 y 0 1 2 3 4 5 6 7 8 9 x + y = 9 2x + 4y = 24 x + y = 9 2x + 4y = 24 Example: Equations on Integers fix point CSP: Incomplete Inference
revise(k,m)removes a b Xm Xp revise(k,m) procedure AC-3 (G) Q := {(i,j)|(i,j)arc(G)i≠j} while Q≠Ø do pop arc (k,m) from Q if revise(k,m) then Q:=Q{(i,k)|(i,k)arc(G)i≠k,i≠m} a, b, c, . . Xk Xq Xr AC-3: AC Algorithm • Arcs to revisit?Arcs no longer AC because a, b removal • If arc was AC, after revise(k,m) • (k,_): it remains AC • (_,k): it may not be AC • Complexity: d 2ed2 : O(ed3) • times per constraint #constraints revise CSP: Incomplete Inference
Local Consistency Levels • Nogood: forbidden tuple of values • In the initial constraints • Discovered during search / local consistency process Local consistency levels: nogood size • Node consistency: 1-consistency 0 • Arc consistency: 2-consistency 1 • Path consistency: 3-consistency 2 • ….. • K-consistency: K-1 removes values from domains discovers forbidden value pairs discovers forbidden value combinations CSP: Incomplete Inference
domain filtering inference • If P is arc-consistent P has solution Generalized Arc Consistency • c is arc-consistent iff: every possible value of every variable in var (c) appears in rel(c) • If c is not arc-consistent because a Dx : • a will not be in any solution • a can be removed: DxDx – {a} • if Dx becomes empty, P has no solution • P is arc-consistent iff: every constraint is arc-consistent incompleteinference !! CSP: Incomplete Inference
Hybrids: Search + Incomplete Inference Idea: • Search: backtracking(could be non-chronological) • Inference: at each node, incomplete inference on some constraints • New nogoods (implicit constraints) discovered • If nogood in current branch backtrack Effect: • Search tree reduced: less nodes to explore • Inference at each node: more work per node • Trade-off to find the right balance CSP: Search + Inference
Hybrids: Search + AC Idea: • Search: backtracking(could be non-chronological) • Inference: at each node, AC on some constraints • AC discovers nogoods of size 1 • Values not AC are eliminated Effect: • Future domains reduced: less nodes to explore • AC at each node: more work per node • Very beneficial: reduces thrashing CSP: Search + Inference
Forward Checking FC is a combination of: • Search: backtracking • Inference: at each node, AC on constraints with assigned and unassigned variables When a domain becomes empty : • No solutions following current branch • Prune current branch and backtrack Caution: • Values removed by AC at level i, have to be restored when bactracking at level i or above CSP: Search + Inference
1 2 3 4 1 2 3 4 1 2 3 4 Q Q Q Q Q Q x1 x2 x3 x4 x1 x2 x3 x4 x1 x2 x3 x4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 Q Q Q Q Q Q Q Q Q Q Q Q x1 x2 x3 x4 x1 x2 x3 x4 x1 x2 x3 x4 x1 x2 x3 x4 x1 x2 x3 x4 x1 x2 x3 x4 Q Q Q Q Q 2 1 Q Q 4 3 4 1 2 3 4 1 2 3 4 1 2 Q Q Q Q x1 x2 x3 x4 x1 x2 x3 x4 Q 3 solution 8 nodes Example: FC on 4-queens x1 x2 x3 x4 CSP: Search + Inference
Lex variableordering Binary Forward Checking: Code function FC (i,Past,[Di,…,Dn]): bool; for all aDi do xi:=a; if i=n then return TRUE; else C’:={Cij|CijC, i<j}; NewD:=AC({xi,..,xn},[{a},Di+1,..,Dn],C’); if ØNewD then if FC(i+1,Past{xi},NewD) return TRUE; return FALSE; CSP: Search + Inference
Maintaining Arc Consistency MAC is a combination of: • Search: backtracking • Inference: at each node, AC on all constraints • Preprocess: subproblems are AC When a domain becomes empty : • No solutions following current branch • Prune current branch and backtrack Caution: • Values removed by AC at level i, have to be restored when bactracking at level i or above CSP: Search + Inference
Q Q Q empty domain Q MAC vs FC: AC on futures AC (2,3) AC (2,3) AC (3,4) CSP: Search + Inference
x1 x2 x3 x4 2 1 4 Q Q Q Q Q 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 1 Q Q Q Q Q Q Q Q Q Q Q x1 x2 x3 x4 x1 x2 x3 x4 x1 x2 x3 x4 x1 x2 x3 x4 x1 x2 x3 x4 3 5 nodes solution Example: MAC on 4-queens x1 x2 x3 x4 CSP: Search + Inference
Example: x =a x≠a y=b y≠b z=c z≠c z=d z≠d y=f y≠f MAC: Binary Search Tree Binary tree of subproblems: • at each level • variable x, two options: x= a (assignment)x ≠ a (refutation) • DFS traversal: at each node, AC of current subproblem • you can change variable without exhausting values! CSP: Search + Inference
Q x1 1 x1 1 x1 2 x2 4 Q Q x3 1 Q Q Q Q x4 3 Q Q Q solution Q Example: MAC on 4-queens Q CSP: Search + Inference
Lex variableordering MAC: Code function MAC (i, [D1,…,Dn]): bool; for j:=i+1,..,n do D’j:=Dj; for all aDi do /* xi:=a */ D’i:={a}; if i=n then return TRUE else NewD:=AC(X,[D1,..,Di-1,D’i,..,D’n],C); if ØNewD then if MAC(i+1,NewD) return TRUE; Di := Di - {a}; /* xi:≠a */ D’i:= Di; NewD:=AC(X,[D1,..,Di-1,D’i,..,D’n],C); if Ø NewD then exit loop else for j:=i+1,..,n do D’j:=NewD[j]; return FALSE; CSP: Search + Inference