/
1   Foundations of Constraint Processing 1   Foundations of Constraint Processing

1 Foundations of Constraint Processing - PowerPoint Presentation

karlyn-bohler
karlyn-bohler . @karlyn-bohler
Follow
342 views
Uploaded On 2019-11-07

1 Foundations of Constraint Processing - PPT Presentation

1 Foundations of Constraint Processing CSCE421821 Spring 2019 wwwcseunleduchoueiryS19421821 Berthe Y Choueiry Shuweri Avery Hall Room 360 Intelligent Backtracking Algorithms 2 Reading ID: 764129

domain current cbj set current domain set cbj variable conf variables check consistent max checking backtracking future mcl label

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "1 Foundations of Constraint Processing" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

1 Foundations of Constraint ProcessingCSCE421/821, Spring 2019 www.cse.unl.edu/~choueiry/S19-421-821Berthe Y. Choueiry (Shu-we-ri)Avery Hall, Room 360 Intelligent Backtracking Algorithms

2 ReadingRequired readingHybrid Algorithms for the Constraint Satisfaction Problem [Prosser, CI 93]Recommended readingChapters 5 and 6 of Dechter’s textbookTsang, Chapter 5

3 OutlineReview of terminology of search Hybrid backtracking algorithms

4 Backtrack search (BT) Variable/value ordering Variable instantiation (Current) path Current variable Past variables Future variables Shallow/deep levels /nodes Search space / search tree Back-checking Backtracking

5 OutlineReview of terminology of search Hybrid backtracking algorithmsVanilla: BT Improving back steps: {BJ, CBJ} Improving forward step: {BM, FC}

6 Two main mechanisms in BTBacktracking: To recover from dead-ends To go backConsistency checking: To expand consistent paths To move forward

7 BacktrackingTo recover from dead-endsChronological (BT) Intelligent Backjumping (BJ) Conflict directed backjumping (CBJ) With learning algorithms (Dechter Chapt 6.4) Etc.

8 Consistency checkingTo expand consistent pathsBack-checking: against past variablesBackmarking (BM) Look-ahead: against future variables Forward checking (FC) (partial look-ahead) Directional Arc-Consistency (DAC) (partial look-ahead) Maintaining Arc-Consistency (MAC) (full look-ahead)

9 Hybrid algorithmsBacktracking + checking = new hybrids BT BJ CBJ BM BMJ BM-CBJ FC FC-BJ FC-CBJ Evaluation : Empirical: Prosser 93. 450 instances of Zebra Theoretical: Kondrak & Van Beek 95

10 Notations (in Prosser’s paper)Variables: Vi, i in [1, n]Domain: Di = { v i1 , v i2 , …, v iMi } Constraint between V i and V j : C i,j Constraint graph: G Arcs of G : Arc( G ) Instantiation order (static or dynamic)Language primitives: list, push, pushnew, remove, set-difference, union, max-list

11 Main data structuresv: a (1xn) array to store assignmentsv[i] gives the value assigned to ith variable v[0]: pseudo variable (root of tree), backtracking to v[0] indicates insolvability domain[i] : a (1x n ) array to store the original domains of variables current-domain[i] : a (1x n ) array to store the current domains of variables Upon backtracking, current-domain[i] of future variables must be refreshed check(i,j) : a function that checks whether the values assigned to v[i] and v[j] are consistent

12 Generic search: bcsspProcedure bcssp (n, status)Beginconsistent  true status  unknown i  1 While status = unknown Do Begin If consistent Then i  label ( i , consistent ) Else i  unlabel ( i , consistent ) If i > n Then status  “solution”Else If i=0 then status  “impossible”EndEndForward move: x-labelBackward move: x-unlabelInput: i: current variable, consistent: BooleanReturn: i: new current variable

13 Chronological backtracking (BT)Uses bt-label and bt-unlabelbt-label:When v[i] is assigned a value from current-domain[i], we perform back-checking against past variables (check(i,k)) If back-checking succeeds, bt-label returns i+1 If back-checking fails, we remove the assigned value from current-domain[i], assign the next value in current-domain[i], etc. If no other value exists, consistent  nil ( bt-unlabel will be called) bt-unlabel Current level is set to i-1 (notation for current variable: v[h]) For all future variables j: current-domain[j]  domain[j] If domain[h] is not empty, consistent  true ( bt-label will be called) Note: for all past variables g, current-domain[g]  domain[g]

14 BT-labelFunction bt-label(i,consistent): INTEGERBEGINconsistent  false For v[i]  each element of current-domain[i] while not consistent Do Begin consistent  true For h  1 to (i-1) While consistent Do consistent  check(i,h) If not consistent Then current-domain[i]  remove(v[i], current-domain[i]) End If consistent then return(i+1) ELSE return(i) END Terminates: consistent=true, return i+1 consistent=false, current-domain[i]=nil, returns i

15 BT-unlabelFUNCTION bt-unlabel(i,consistent):INTEGERBEGINh  i -1 current-domain[i] domain[i] current-domain[h] remove(v[h],current-domain[h]) consistent  current-domain[h]  nil return(h) END Is called when consistent=false and current-domain[i]=nil Selects v h to backtrack to (Uninstantiates all variables between v h and v i ) Uninstantiates v[h]: removes v[h] from current-domain [h]: Sets consistent to true if current-domain[h]  0 Returns h

16 Example: BT (the dumbest example ever) {1,2,3,4,5} {1,2,3,4,5} {1,2,3,4,5} {1,2,3,4,5} {1,2,3,4,5} V2 V1 V3 V4 V5 C V3,V4 ={(V3=1,V4=3)} C V2,V5 ={(V2=5,V5=1),(V2=5,V5=4)} - v[1] v[2] v[3] v[4] v[5] v[0] 1 1 1 1 2 1 3 4 2 3 4 5 etc…

17 OutlineReview of terminology of search Hybrid backtracking algorithmsVanilla: BTImproving back steps: BJ, CBJ Improving forward step: BM, FC

18 Danger of BT: thrashingBT assumes that the instantiation of v[i] was prevented by a bad choice at (i-1). It tries to change the assignment of v[i-1]When this assumption is wrong, we suffer from thrashing (exploring ‘barren’ parts of solution space)Backjumping (BT) tries to avoid that Jumps to the reason of failure Then proceeds as BT

19 Backjumping (BJ)Tries to reduce thrashing by saving some backtracking effortWhen v[i] is instantiated, BJ remembers v[h], the deepest node of past variables that v[i] has checked against.Uses: max-check[i], global, initialized to 0 At level i, when check(i,h) succeeds max-check[i]  max(max-check[i], h) If current-domain[h] is getting empty, simple chronological backtracking is performed from h BJ jumps then steps! 1 2 3 0 2 3 1 i h-1 h-1 h h h-2 0 0 0 Current variable Past variable

20 BJ: label/unlabelbj-label: same as bt-label, but updates max-check[i]bj-unlabel, same as bt-unlabel butBacktracks to h = max-check[i]Resets max-check[j]  0 for j in [h+1,i]  Important : max-check is the deepest level we checked against , could have been success or could have been failure 1 2 3 0 2 3 1 i h-1 h-1 h h h-2 0 0 0

21 Example: BJ 2 {1,2,3,4,5} {1,2,3,4,5} {1,2,3,4,5} {1,2,3,4,5} {1,2,3,4,5} V2 V1 V3 V4 V5 C V2,V4 ={(V2=1,V4=3)} C V1,V5 ={(V1=1,V 5 =2)} C V2,V5 ={(V2=5,V5=1)} - v[1] v[2] v[3] v[4] v[5] v[0] = 0 1 1 1 1 2 1 3 4 2 3 4 5 Max-check[1] = 0 Max-check[2] = 1 max-check[4] = 3 max-check[5] = 2 V4=1, fails for V2, mc=2 V4=2, fails for V2, mc=2 V4=3, succeeds V5=1, fails for V1, mc=1 V5=2, fails for V2, mc=2 V5=3, fails for V1 V5=4, fails for V1 V5=5, fails for V1

Backtracking 22 Conflict-directed backjumping (CBJ) Backjumping jumps from v[i] to v[h], but then, it steps back from v[h] to v[h-1]  CBJ improves on BJ Jumps from v[i] to v[h] And jumps back again, across conflicts involving both v[i] and v[h] To maintain completeness, we jump back to the level of deepest conflict

23 CBJ: data structureMaintains a conflict set: conf-setconf-set[i] are first initialized to {0}At any point, conf-set[i] is a subset of past variables that are in conflict with i {0} {0} {0} {0} {0} {0} conf-set[g] conf-set[h] conf-set[i] 0 1 2 g h-1 h i conf-set

24 CBJ: conflict-set {x} {3} {1, g, h} {0} {0} {0} conf-set[g] conf-set[h] conf-set[i] 1 2 3 g h-1 h Current variable i Past variables {3,1, g} {x, 3,1} When a check(i,h) fails conf-set[i]  conf-set[i] {h} When current-domain[i] empty Jumps to deepest past variable h in conf-set[i] Updates conf-set[h]  conf-set[h]  (conf-set[i] \{h}) Primitive form of learning (while searching)

25 Example CBJ {1,2,3,4,5} {1,2,3,4,5} {1,2,3,4,5} {1,2,3,4,5} {1,2,3,4,5} V2 V1 V3 V4 V5 {( V 1 =1, V 6 = 3 )} - v[1] v[2] v[3] v[4] v[ 6 ] v[0] = 0 1 1 1 1 2 1 3 2 3 4 5 conf-set[1] = {0} conf-set[2] = {0} conf-set[3] = {0} {( V 4 = 5 , V 6 = 3 )} {( V 2 =1, V 4 = 3 ) , (V2=4, V4=5) } conf-set[6] = {1} {1,2,3,4,5} V6 {( V 1 =1, V 5 = 3 )} conf-set[4] = {2} v[ 5 ] 2 1 3 conf-set[6] = {1} conf-set[6] = {1,4} conf-set[6] = {1,4} conf-set[6] = {1,4} conf-set[4] = {1, 2} conf-set[5] = {1}

CBJ for finding all solutionsAfter finding a solution, if we jump from this last variable, then we may miss some solutions and lose completenessTwo solutions, proposed by Chris Thiel (S08)Using conflict setsUsing cbf of Kondrak, a clear pseudo-codeRationale by Rahul Purandare (S08)We cannot skip any variable without chronologically backtracking to it at least once In fact, exactly once 26

CBJ/All solutions without cbfWhen a solution is found, force the last variable, N, to conflict with everything before itconf-set[N]  {1, 2, ..., N-1}.  This operation, in turn, forces some chronological backtracking as the conf-sets are propagated backward 27

CBJ/All solutions with cbfKondrak proposed to fix the problem using cbf (flag), a 1xn vector i, cbf[i]  0When you find a solution,  i, cbf[i]  1 In unlabel if (cbf[i]=1) Then h  i-1; cbf[i]  0Else h  max-list (conf-set[i]) 28

29 Backtracking: summaryChronological backtrackingSteps back to previous levelNo extra data structures requiredBackjumpingJumps to deepest checked-against variable, then steps back Uses array of integers: max-check[i] Conflict-directed backjumping Jumps across deepest conflicting variables Uses array of sets: conf-set[i]

30 OutlineReview of terminology of search Hybrid backtracking algorithmsVanilla: BTImproving back steps: BJ, CBJ Improving forward step: BM, FC

31 Backmarking: goalTries to reduce amount of consistency checkingSituation:v[i] about to be re-assigned kv[i]k was checked against v[h]gv[h] has not been modified v[h] = g v[i] k k

32 BM: motivationTwo situationsEither (v[i]=k,v[h]=g) has failed  it will fail againOr, (v[i]=k,v[h]=g) was founded consistent  it will remain consistent v[h] = g v[i] k k  v[h] = g v[i] k k In either case, back-checking effort against v[h] can be saved!

33 Data structures for BM: 2 arrays 0 0 0 0 0 0 0 0 0 0 0 0 0 Number of variables n max domain size m Number of variables n maximum checking level: mcl (n x m) Minimum backup level: mbl (n x 1)

34 Maximum checking level 0 0 0 0 0 0 0 0 0 0 0 0 0 Number of variables n max domain size m mcl[i,k] stores the deepest variable that v[i] k checked against mcl[i,k] is a finer version of max-check[i]

35 Minimum backup level Number of variables n mbl[i] gives the shallowest past variable whose value has changed since v[i] was the current variable BM (and all its hybrid) do not allow dynamic variable ordering

36 When mcl[i,k]=mbl[i]=j v[i] k k v[j] mbl[i] = j BM is aware that The deepest variable that (v[i] k) checked against is v[j] Values of variables in the past of v[j] (h<j) have not changed So We do need to check (v[i] k) against the values of the variables between v[j] and v[i] We do not need to check (v[i] k) against the values of the variables in the past of v[j]

37 Type a savings v[h] v[i] k k v[j] mcl[i,k]=h mcl[i,k] < mbl[i]=j When mcl[i,k] < mbl[i], do not check v[i]  k because it will fail

38 Type b savings h v[i] k k v[j] v[g] mcl[i,k]=g mbl[i] = j mcl[i,k]  mbl[i] When mcl[i,k]  mbl[i], do not check (i,h<j) because they will succeed

39 Hybrids of BMmcl can be used to allow backjumping in BJMixing BJ & BM yields BMJavoids redundant consistency checking (types a+b savings) and reduces the number of nodes visited during search (by jumping)Mixing BM & CBJ yields BM-CBJ

40 Problem of BM and its hybrids: warning v[m] v[m] v[g] v[h] v[i] v[g] v[h] v[i] v[m] v[g] v[h] v[i] v[h] v[f] Backjumping from v[i]: v[i] backjumps up to v[g] Backmarking of v[h]: When reconsidering v[h], v[h] will be checked against all f  [m,g) effort could be saved  Phenomenon will worsen with CBJ Problem fixed by Kondrak & van Beek 95 BMJ enjoys only some of the advantages of BM Assume: mbl[h] = m and max-check[i]=max(mcl[i,x])=g

41 Forward checking (FC)Looking ahead: from current variable, consider all future variables and clear from their domains the values that are not consistent with current partial solutionFC makes more work at every instantiation, but will expand fewer nodesWhen FC moves forward, the values in current-domain of future variables are all compatible with past assignment, thus saving backcheckingFC may “wipe out” the domain of a future variable (aka, domain annihilation) and thus discover conflicts early on. FC then backtracks chronologically Goal of FC is to fail early (avoid expanding fruitless subtrees)

42 FC: data structures v[i] v[k] v[l] v[n] v[m] v[j] When v[i] is instantiated, current-domain[j] are filtered for all j connected to i and I < j n reduction[j] store sets of values remove from current-domain[j] by some variable before v[j] reductions[j] = {{a, b}, {c, d, e}, {f, g, h}} future-fc[i] : subset of the future variables that v[i] checks against (redundant) future-fc[i] = {k, j, n} past-fc[i] : past variables that checked against v[i] All these sets are treated like stacks

43 Forward Checking: functionscheck-forwardundo-reductionsupdate-current-domainfc-labelfc-unlabel

44 FC: functionsCheck-Forward(i,j) is called when instantiating v[i]It performs Revise(j,i)Returns false if current-domain[j] is empty, true otherwiseValues removed from current-domain[j] are pushed, as a set, into reductions[j] These values will be popped back if we have to backtrack over v[i] (undo-reductions)

45 FC: functionsupdate-current-domaincurrent-domain[i]  domain[i] \ reductions[i] actually, we have to iterate over reductions, which is a set of setsfc-label Attempts to instantiate current-variable Then filters domains of all future variables (push into reductions) Whenever current-domain of a future variable is wiped-out: v[i] is un-instantiated and domain filtering is undone (pop reductions)

46 Hybrids of FCFC suffers from thrashing: it is based on BTFC-BJ: max-check is integrated in fc-bj-label and fc-bj-unlabelEnjoys advantages of FC and BJ… but suffers malady of BJ (first jumps, then steps back)FC-CBJ: Best algorithm so far fc-cbj-label and fc-cbj-unlabel

47 Consistency checking: summaryChronological backtrackingUses back-checkingNo extra data structuresBackmarkingUses mcl and mbl Two types of consistency-checking savings Forward-checking Works more at every instantiation, but expands fewer subtrees Uses: reductions[i], future-fc[i], past-fc[i]

48 ExperimentsEmpirical evaluations on ZebraRepresentative of design/scheduling problems25 variables, 122 binary constraintsPermutation of variable ordering yields new search spacesVariable ordering: different bandwidth/induced width of graph450 problem instances were generated Each algorithm was applied to each instance Experiments were carried out under static variable ordering

49 Analysis of experimentsAlgorithms compared with respect to:Number of consistency checks (average)FC-CBJ ≼ FC-BJ ≼BM-CBJ ≼ FC ≼ CBJ ≼ BMJ ≼ BM ≼ BJ ≼ BTNumber of nodes visited (average) FC-CBJ ≼ FC-BJ ≼ FC ≼ BM-CBJ ≼ BMJ=BJ ≼ BM=BT CPU time (average) FC-CBJ ≼ FC-BJ ≼ FC ≼ BM-CBJ ≼ CBJ ≼ BMJ ≼ BJ ≼ BT ≼ BM FC-CBJ apparently the champion

50 Additional developmentsOther backtracking algorithms exist:Graph-based backjumping (GBJ), etc. [Dechter]Pseudo-trees [Freuder 85]Other look-ahead techniques exist DAC, MAC, etc. More empirical evaluations over randomly generated problems Theoretical comparisons [Kondrak & van Beek IJCAI’95]

Implementing BT-based algorithmsPreprocessingEnforce NC, do not include in #CC (e.g., Zebra)Normalize all constraints (fapp01-0200-0)Check for empty relations (bqwh-15-106-0_ext)Interrupt as soon as you detect domain wipe outDynamic variable orderingApply domino effect 51