chronological backtracking bt an example problem 1 2 3 5
play

Chronological Backtracking (BT) An example problem 1 2 3 5 4 - PowerPoint PPT Presentation

Chronological Backtracking (BT) An example problem 1 2 3 5 4 Colour each of the 5 nodes, such that if they are adjacent, they take different colours Representation (csp1) 1 2 3 5 variables v1, v2, v3, v4, and v5 domains d1,


  1. Chronological Backtracking (BT)

  2. An example problem 1 2 3 5 4 Colour each of the 5 nodes, such that if they are adjacent, they take different colours

  3. Representation (csp1) 1 2 3 5 • variables v1, v2, v3, v4, and v5 • domains d1, d2, d3, d4, and d5 • domains are the three colours {R,B,G} 4 • constraints • v1  v2 • v1  v3 • v2  v3 • v2  v5 • v3  v5 • v4  v5 Assign a value to each variable, from its domain, such that the constraints are satisfied CSP = (V,D,C)

  4. Chronological Backtracking (BT) As a pair of mutually recursive functions 1 2 bt-label bt-label(i,v,d,cd,n) 3 begin if i > n 5 then return “solution” else begin consistent := false; for v[i]  cd[i] while ¬consistent 4 do begin consistent := true; i the index of the current variable for h := 1 to i-1 while consistent h the index of a past variable (local) do consistent := check(v,i,h); v an array of variables to be instantiated if ¬consistent d an array of domains then cd[i] := cd[i] \ v[i]; cd an array of current domains end n the number of variables if consistent then bt-label(i+1,v,d,cd,n) constraints are binary. else bt-unlabel(i,v,d,cd,n) consistent is boolean (local) end bt(v,d,n) = for i := 1 to n cd[i] := d[i]; return bt-label(1,v,d,cd,n)

  5. Chronological Backtracking (BT) 1 2 bt-label bt-label(i,v,d,cd,n) 3 begin if i > n 5 then return “solution” else begin consistent := false; for v[i]  cd[i] while ¬consistent 4 do begin consistent := true; for h := 1 to i-1 while consistent Find a consistent instantiation for v[i] do consistent := check(v,i,h); if ¬consistent then cd[i] := cd[i] \ v[i]; end if consistent then bt-label(i+1,v,d,cd,n) else bt-unlabel(i,v,d,cd,n) end

  6. Chronological Backtracking (BT) 1 2 bt-label bt-label(i,v,d,cd,n) 3 begin if i > n 5 then return “solution” else begin consistent := false; for v[i]  cd[i] while ¬consistent 4 do begin consistent := true; for h := 1 to i-1 while consistent check backwards, from current to past do consistent := check(v,i,h); if ¬consistent then cd[i] := cd[i] \ v[i]; end if consistent then bt-label(i+1,v,d,cd,n) else bt-unlabel(i,v,d,cd,n) end

  7. Chronological Backtracking (BT) 1 2 bt-label bt-label(i,v,d,cd,n) 3 begin if i > n 5 then return “solution” else begin consistent := false; for v[i]  cd[i] while ¬consistent 4 do begin consistent := true; for h := 1 to i-1 while consistent do consistent := check(v,i,h); if ¬consistent then cd[i] := cd[i] \ v[i]; end if consistent then bt-label(i+1,v,d,cd,n) recurse else bt-unlabel(i,v,d,cd,n) end

  8. Chronological Backtracking (BT) 1 2 bt-unlabel bt-unlabel(i,v,d,cd,n) 3 begin if i = 0 5 then return “fail” else begin h := i – 1; cd[h] := cd[h] \ v[h]; 4 cd[i] := d[i]; if cd[h] ≠ nil then bt-label(h,v,d,cd,n) else bt-unlabel(h,v,d,cd,n) end end

  9. Chronological Backtracking (BT) 1 2 bt-unlabel bt-unlabel(i,v,d,cd,n) 3 begin if i = 0 5 then return “fail” else begin Past variable h := i – 1; cd[h] := cd[h] \ v[h]; 4 cd[i] := d[i]; if cd[h] ≠ nil then bt-label(h,v,d,cd,n) else bt-unlabel(h,v,d,cd,n) end end

  10. Chronological Backtracking (BT) 1 2 bt-unlabel bt-unlabel(i,v,d,cd,n) 3 begin if i = 0 5 then return “fail” else begin h := i – 1; cd[h] := cd[h] \ v[h]; 4 Reset domain cd[i] := d[i]; (bactrackable/reversible variable) if cd[h] ≠ nil then bt-label(h,v,d,cd,n) else bt-unlabel(h,v,d,cd,n) end end

  11. Chronological Backtracking (BT) 1 2 bt-unlabel bt-unlabel(i,v,d,cd,n) 3 begin if i = 0 5 then return “fail” else begin h := i – 1; cd[h] := cd[h] \ v[h]; 4 cd[i] := d[i]; if cd[h] ≠ nil then bt-label(h,v,d,cd,n) recurse else bt-unlabel(h,v,d,cd,n) end end

  12. Iterative implementation of BT bt-label(i,consistent) begin consistent := false; search(n,status) for v[i] in cd[i] while ¬consitent begin do begin consistent := true; consistent := true; status := “unknown”; for h := 1 to i-1 while consistent i := 1; do consistent := check(v,i,h); while status = “unknown” if ¬consistent do begin then cd[i] := cd[i] \ v[i]; if consistent end; then i := label(i,consistent) if consistent then return i+1 else return I else i := unlabel(i,consistent); end if i > n then status = “solution” else if i = 0 bt-unlabel(i,consistent) then status := “impossible” begin end h := i-1; end cd[i] := d[i]; cd[h] := cd[h] \ v[h]; consistent := cd[h] ≠ nil return h; end This is more realistic. Why?

  13. Chronological Backtracking (BT) 1 2 3 5 4

  14. Three Different Views of Search a trace a tree past, current, future

  15. A Trace of BT (assume domain ordered {R,B,G}) • V[1] := R • backtrack! 1 2 • V[2] := R • check(v[1],v[2]) fails • V[4] := B • V[2] := B • V[5] := R • check(v[1],v[2]) good • check(v[2],v[5]) good • V[3] := R • check(v[3],v[5]) good 3 • check(v[1],v[3]) fails • check(v[4],v[5]) good 5 • V[3] := B • check(v[1],v[3]) good • solution found • check(v[2],v[3]) fails • V[3] := G 4 • check(v[1],v[3]) good • check(v[2],v[3]) good • V[4] := R • V[5] := R • check(v[2],v[5]) good • check(v[3],v[5]) good 1 1 2 2 • check(v[4],v[5]) fails • V[5] := B • check(v[2],v[5]) fails • V[5] := G • check(v[2],v[5]) good 3 3 • check(v[3],v[5]) fails 5 5 16 checks and 12 nodes 4 4

  16. A Tree Trace of BT (assume domain ordered {R,B,G}) 1 2 3 v1 5 v2 4 v3 v4 v5

  17. A Tree Trace of BT (assume domain ordered {R,B,G}) 1 2 3 v1 5 v2 4 v3 v4 v5

  18. A Tree Trace of BT (assume domain ordered {R,B,G}) 1 2 3 v1 5 v2 4 v3 v4 v5

  19. A Tree Trace of BT (assume domain ordered {R,B,G}) 1 2 3 v1 5 v2 4 v3 v4 v5

  20. A Tree Trace of BT (assume domain ordered {R,B,G}) 1 2 3 v1 5 v2 4 v3 v4 v5

  21. A Tree Trace of BT (assume domain ordered {R,B,G}) 1 2 3 v1 5 v2 4 v3 v4 v5

  22. A Tree Trace of BT (assume domain ordered {R,B,G}) 1 2 3 v1 5 v2 4 v3 v4 v5

  23. A Tree Trace of BT (assume domain ordered {R,B,G}) 1 2 3 v1 5 v2 4 v3 v4 v5

  24. A Tree Trace of BT (assume domain ordered {R,B,G}) 1 2 3 v1 5 v2 4 v3 v4 v5

  25. A Tree Trace of BT (assume domain ordered {R,B,G}) 1 2 3 v1 5 v2 4 v3 v4 v5

  26. A Tree Trace of BT (assume domain ordered {R,B,G}) 1 2 3 v1 5 v2 4 v3 v4 v5

  27. A Tree Trace of BT (assume domain ordered {R,B,G}) 1 2 3 v1 5 v2 4 v3 v4 v5

  28. A Tree Trace of BT (assume domain ordered {R,B,G}) 1 2 3 v1 5 v2 4 v3 v4 v5

  29. Another view 1 2 v1 past variables 3 check back 5 v2 current variable v3 4 v4 future variables v5

  30. Can you solve this (csp2)? 1 2 3 5 4

  31. Thrashing? (csp3c) 1 2 3 9 4 8 5 7 6

  32. Thrashing? (csp3c) 1 2 V1 = R v2 = B v3 = G v4 = R 3 v5 = B 9 v6 = R v7 = B v8 = R 4 v9 = conflict 8 The cause of the conflict with v9 is v4, but what will bt do? 5 7 6 Find out how it goes with bt3 and csp4

  33. questions • Why measure checks and nodes? • What is a node anyway? • Who cares about checks? • Why instantiate variables in lex order? • Would a different order make a difference? • How many nodes could there be? • How many checks could there be? • Are all csp’s binary? • How can we represent constraints? • Is it reasonable to separate V from D? • Why not have variables with domains • What is a constraint graph ? • How can (V,D,C) be a graph? • What is BT “thinking about”? i.e. why is it so dumb? • What could we do to make BT smarter? • Is BT doing any inferencing/propagation? • What’s the 1 st reference to BT? • Golomb & Baumert JACM 12, 1965? • The Minataur?

Recommend


More recommend