Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] =...

72
fc

Transcript of Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] =...

Page 1: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

fc

Page 2: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)

• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

A solution is 3--3--2--1

Remember how bt thrashed?

Page 3: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 V3V4V5V6V7V8V9V10

Page 4: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3V4V5V6V7V8V9V10

Page 5: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4V5V6V7V8V9V10

Page 6: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5V6V7V8V9V10

Page 7: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 1V6V7V8V9V10

Page 8: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 1V6 = 1V7V8V9V10

Page 9: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 1V6 = 1V7 = 1V8V9V10

Page 10: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 1V6 = 1V7 = 2V8V9V10

Page 11: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 1V6 = 1V7 = 3V8V9V10

Page 12: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 1V6 = 2V7V8V9V10

Page 13: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 1V6 = 2V7 = 1V8V9V10

Page 14: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 1V6 = 2V7 = 2V8V9V10

Page 15: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 1V6 = 2V7 = 3V8V9V10

Page 16: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 1V6 = 3V7 V8V9V10

Page 17: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 1V6 = 3V7 = 1V8V9V10

Page 18: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 1V6 = 3V7 = 2V8V9V10

Page 19: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 1V6 = 3V7 = 3V8V9V10

Page 20: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 2V6 V7 V8V9V10

Page 21: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 2V6 = 1V7 V8V9V10

Page 22: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 2V6 = 1V7 = 1V8V9V10

Page 23: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 2V6 = 1V7 = 2V8V9V10

Page 24: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 2V6 = 1V7 = 3V8V9V10

Page 25: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 2V6 = 2V7 V8V9V10

Page 26: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 2V6 = 2V7 = 1V8V9V10

Page 27: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 2V6 = 2V7 = 2V8V9V10

Page 28: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 2V6 = 2V7 = 3V8V9V10

Page 29: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Consider the following problem (csp5)• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

V1 = 1V2 = 1V3 = 1V4 = 1V5 = 2V6 = 3V7V8V9V10

Page 30: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Thrashing:

Slavishly repeating the same set of actions with the same set of outcomes.

Can we minimise thrashing?

Page 31: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Forward Checking

Rather than checking backwards (from current to past)check forwards (from current to future)

• When we instantiate v[i] with a value x• remove from the d[j] values inconsistent with v[i] = x• where j is in the future

Consequently, when we instantiate v[i] we know it is compatiblewith the past

Page 32: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1 V2 V3V4V5V6V7V8V9V10

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

D1 = {1,2,3}D2 = {1,2,3}D3 = {1,2,3}D4 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D7 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 33: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1 := 1V2 V3V4V5V6V7V8V9V10

• instantiate V1 with value 1

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

• remove from D4 incompatible values {2,3}

D1 = {1,2,3}D2 = {1,2,3}D3 = {1,2,3}D4 = {1}D5 = {1,2,3}D6 = {1,2,3}D7 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 34: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1 := 1V2 := 1V3V4V5V6V7V8V9V10

• instantiate V2 with value 1

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

• no forward checking to perform

D1 = {1,2,3}D2 = {1,2,3}D3 = {1,2,3}D4 = {1}D5 = {1,2,3}D6 = {1,2,3}D7 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 35: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1 := 1V2 := 1V3 := 1V4V5V6V7V8V9V10

• instantiate V3 with value 1

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1current variable

• no forward checking to perform

D1 = {1,2,3}D2 = {1,2,3}D3 = {1,2,3}D4 = {1}D5 = {1,2,3}D6 = {1,2,3}D7 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 36: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1 := 1V2 := 1V3 := 1V4 := 1V5V6V7V8V9V10

• instantiate V4 with value 1 (no choice!)

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

• remove from D7 incompatible values {1,2,3}

D1 = {1,2,3}D2 = {1,2,3}D3 = {1,2,3}D4 = {1}D5 = {1,2,3}D6 = {1,2,3}D7 = {}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Dead end!

Page 37: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1 := 1V2 := 1V3 := 2V4V5V6V7V8V9V10

• backtrack to v3

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

D1 = {1,2,3}D2 = {1,2,3}D3 = {2,3}D4 = {1}D5 = {1,2,3}D6 = {1,2,3}D7 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 38: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Look at fc demo using csp5set system.verbose := 3 andexplicitly call label, unlabel and look

[LATER: Also try bt4, cbj, and fc on csp7 (crytal maze)]

Page 39: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

We are still going to thrash!

But, could you see how we could “heuristically” exploit the FC information?

Page 40: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1 := 1V2 V3V4V5V6V7V8V9V10

• instantiate V1 with value 1

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

• remove from D4 incompatible values {2,3}

D1 = {1,2,3}D2 = {1,2,3}D3 = {1,2,3}D4 = {1}D5 = {1,2,3}D6 = {1,2,3}D7 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Why not select V4 immediately after V1?

Page 41: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1 := 1V4 V2V3V5V6V7V8V9V10

• select as current variable the variable with smallest domain

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

• instantiate V4

D1 = {1,2,3}D4 = {1}D2 = {1,2,3}D3 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D7 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 42: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1 := 1V4 := 1V2V3V5V6V7V8V9V10

• select as current variable the variable with smallest domain

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

• instantiate V4• check forwards, against V7• domain wipe out! Backtrack!

D1 = {1,2,3}D4 = {1}D2 = {1,2,3}D3 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D7 = {}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 43: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1 := 1V4 := 1V2V3V5V6V7V8V9V10

• backtrack

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

• return values to V7 removed by V4

D1 = {1,2,3}D4 = {1}D2 = {1,2,3}D3 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D7 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 44: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1 := 1V4 V2V3V5V6V7V8V9V10

• backtrack

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

• remove from V4 the value it currently has

D1 = {1,2,3}D4 = {}D2 = {1,2,3}D3 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D7 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 45: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1 := 1V4 V2V3V5V6V7V8V9V10

• backtrack!

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

• V4 has a domain wipe out!

D1 = {1,2,3}D4 = {}D2 = {1,2,3}D3 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D7 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 46: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1 := 1V4 V2V3V5V6V7V8V9V10

• backtrack!

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

• return to V4 values removed by V1

D1 = {1,2,3}D4 = {1,2,3}D2 = {1,2,3}D3 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D7 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 47: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1 V4 V2V3V5V6V7V8V9V10

• backtrack!

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

• remove the value V1 currently has from its domain

D1 = {2,3}D4 = {1,2,3}D2 = {1,2,3}D3 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D7 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 48: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1:= 2V4 V2V3V5V6V7V8V9V10

• instantiate V1 with next value

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

• check forwards to V4

D1 = {2,3}D4 = {2}D2 = {1,2,3}D3 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D7 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 49: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1:= 2V4 V2V3V5V6V7V8V9V10

• select variable with smallest domain

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1current variable

D1 = {2,3}D4 = {2}D2 = {1,2,3}D3 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D7 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 50: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1:= 2V4:= 2V2V3V5V6V7V8V9V10

• instantiate V4

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1current variable

D1 = {2,3}D4 = {2}D2 = {1,2,3}D3 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D7 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 51: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1:= 2V4:= 2V2V3V5V6V7V8V9V10

• check forwards to V7

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1current variable

D1 = {2,3}D4 = {2}D2 = {1,2,3}D3 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D7 = {1}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 52: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1:= 2V4:= 2V7V2V3V5V6V8V9V10

• select variable with smallest domain

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

D1 = {2,3}D4 = {2}D7 = {1}D3 = {1,2,3}D3 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 53: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1:= 2V4:= 2V7:= 1V2V3V5V6V8V9V10

• instantiate current variable

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

D1 = {2,3}D4 = {2}D7 = {1}D3 = {1,2,3}D3 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 54: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1:= 2V4:= 2V7:= 1V2V3V5V6V8V9V10

• check forwards

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

D1 = {2,3}D4 = {2}D7 = {1}D3 = {1,2,3}D3 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {}

Page 55: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1:= 2V4:= 2V7:= 1V2V3V5V6V8V9V10

• domain wipeout! Backtrack!

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable

D1 = {2,3}D4 = {2}D7 = {1}D3 = {1,2,3}D3 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {}

Page 56: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

V1V4V7V2V3V5V6V8V9V10

• backtrack to V1

Forward checking• variables V[1] to V[10]• uniform domains D[1] to D[10] = {1,2,3}• constraints

• V[1] = V[4]• V[4] > V[7]• V[7] = V[10] + 1

current variable D1 = {3}D4 = {1,2,32}D7 = {1,2,3}D3 = {1,2,3}D3 = {1,2,3}D5 = {1,2,3}D6 = {1,2,3}D8 = {1,2,3}D9 = {1,2,3}D10 = {1,2,3}

Page 57: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

That was a dvo, a dynamic variable ordering heuristic

select next the variable with smallest current domainaka sdf, mrv, ff

dvo

Was it a good heuristic?If so, why was it a good heuristic?Will it always be a good heuristic?Can you think of a situation where it will be a bad heuristic?Could you use this heuristic with bt or with cbj?

Page 58: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Is forward checking always better than backward checking?That is, is fc better than bt (cbj) always

Does fc entirely eliminate thrashing?

Could we incorporate cbj into fc?That is check forwards and jump back?

Page 59: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Forward Checking

1

2

3

4

5

6

7

9

8

NOTE: arrows go forward!

Page 60: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Forward Checking

1

2

3

4

5

6

7

9

8

Variables 1 to 9Domains {A,B}Constraints/nogoods:{(1/A,9/A),(3A/,4/A), (4/B,6/A), (6/B,9/B)}

State is:1/A2/A3/A4/B5/A6/B7/{A,B}8/{A,B}9/{}

Page 61: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Forward Checking

1

2

3

4

5

6

7

9

8

Variables 1 to 9Domains {A,B}Constraints/nogoods:{(1/A,9/A),(3A/,4/A), (4/B,6/A), (6/B,9/B)}

State is:1/A2/A3/A4/B5/A6/B7/{A,B}8/{A,B)9/{}

Possible action:Backjump to V4 so that V6can then take value A

Backjump (step) to V3 so that V4 can take value A and Then V6 can take A also

Page 62: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

1

2

3

4

5

6

7

9

8

Without backjumpingFC can thrash!

Replace 5 with a collectionof variables with large domainsto convince yourself

Page 63: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

The mechanics of FC

• assume we have n variables each with domain of m values• two dimensional array fcRed[1..n][1..n]

• if v[i] checks forwards against v[j] and removes values • then fcRed[i][j] := true

• two dimensional array disallowed[1..n][1..m]• if v[i] removes value x from domain of v[j] • then disallowed[j][x] := i

• i.e. the “culprit” for x removed from domain[j] is v[i]

When we uninstantiate v[i] we must undo the effects of forward checking

for j in (i+1 .. n) if fcRed[i][j] // variable v[i] disallows values in v[j] then for x in (1 .. m) if disallowed[j][x] = i // this is a value disallowed by v[i] then domain[j] := domain[j] U {x} // return a disallowed value

Reversible Variables

Page 64: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]
Page 65: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]
Page 66: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]
Page 67: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Check Forwards, Jump Back!

1

2

3

4

5

6

7

9

8

•There are no values in cd[6] compatible with v[9]• get more values into cd[9] (undo v[1]?) OR• get more values into cd[6] (undo v[4])

• … and if that doesn’t work? undo v[3] so cd[4] gets value compatible with cd[6] that is then compatible with cd[9]

Page 68: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Check forwards and jump back?

• assume we have n variables each with domain of m values• two dimensional array fcRed[1..n][1..n]

• if v[i] checks forwards against v[j] and removes values • then fcRed[i][j] := true

• two dimensional array disallowed[1..n][1..m]• if v[i] removes value x from domain of v[j] • then disallowed[j][x] := i

If v[i] := x wipes out domain[j]then confSet[i] := confSet[i] U variables checking against v[j]

If we backtrack from v[i]jump back to v[h], where h is the deepest variablein confSet[i] U variables forward checking against v[i]

Why?

Page 69: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

Lets look at the crystal maze puzzle again!csp7.cl

use bt4, cbj, and fc!

Page 70: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

See source codeclairExamples/fc.cl

Page 71: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]

• why FC?• Fail 1st?

• Does FC suggest heuristics?• Static?• Dynamic

• But FC still thrashes!• We saw that

• FC could be worse than BT!• An example

• Could we combine FC with CBJ?

Page 72: Fc. Consider the following problem (csp5) variables V[1] to V[10] uniform domains D[1] to D[10] = {1,2,3} constraints V[1] = V[4] V[4] > V[7] V[7] = V[10]