CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are...

30
CSP Yaron Kassner Winter 2013

Transcript of CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are...

Page 1: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

CSP

Yaron KassnerWinter 2013

Page 2: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

Reminder

• Arc Consistency: the domains of pairs of variables are consistent.

• k-consistency: the domains of every k variables are consistent.

• AC3 – an algorithm that reduces the domains of variables by enforcing arc-consistency.

Page 3: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

Reminder

• CSP problems can be solved using search.• Heuristics:

– assign the variable with the minimum number of remaining values

– Most constraining variable – choose the variable that constrains the most variables.

– choose the least-constraining-value: the value that is inconsistent with as few other values as possible.

• Forward checking – after assignment, reduce domain of neighboring variables.

• MAC – maintain arc-consistency: do a back-tracking search, and fix arc consistency after every assignment.

Page 4: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

AC-3 complexity

Page 5: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

Example: Cryptarithmetic Problem

TWO+ TWO _____ FOUR

O

R

C1

W

U

C2

T

F

0 1

0 1

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

1 2 3 4 5 6 7 8 9

C3 0 1

3C F

C3 C2 C1

Page 6: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TWO+ TWO _____ 1OUR

O

R

C1

W

U

C2

T

F

0 1

0 1

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

0 1 2 3 4 5 6 7 8 9

1

C3 1

Characters are distinct

1 C2 C1

Example: Cryptarithmetic Problem

Page 7: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TWO+ TWO _____ 1OUR

O

R

C1

W

U

C2

T

F

0 1

0 1

0 2 3 4 5 6 7 8 9

0 2 3 4 5 6 7 8 9

0 2 3 4 5 6 7 8 9

0 2 3 4 5 6 7 8 9

0 2 3 4 5 6 7 8 9

1

C3 1

%10O O R O R

1 C2 C1Example: Cryptarithmetic Problem

Page 8: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TWO+ TWO _____ 1OUR

O

R

C1

W

U

C2

T

F

0 1

0 1

0 2 3 4 5 6 7 8 9

2 3 4 5 6 7 8 9

0 2 4 6 8

0 2 3 4 5 6 7 8 9

0 2 3 4 5 6 7 8 9

1

C3 1

1 C2 C1

2 9T T C

Example: Cryptarithmetic Problem

Page 9: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TWO+ TWO _____ 1OUR

O

R

C1

W

U

C2

T

F

0 1

0 1

5 6 7 8 9

2 3 4 5 6 7 8 9

0 2 4 6 8

0 2 3 4 5 6 7 8 9

0 2 3 4 5 6 7 8 9

1

C3 1

1 C2 C1

2 %10T T C O

Example: Cryptarithmetic Problem

Page 10: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TWO+ TWO _____ 1OUR

O

R

C1

W

U

C2

T

F

0 1

0 1

6 7 8 9

2 3 4 5 6 7 8 9

0 2 4 6 8

0 2 3 4 5 6 7 8 9

0 2 3 4 5 6 7 8 9

1

C3 1

1 C2 C1

MRVLCV

Example: Cryptarithmetic Problem

Page 11: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TWO+ TWO _____ 1OUR

O

R

C1

W

U

C2

T

F

1

0 1

6 7 8 9

2 3 4 5 6 7 8 9

0 2 4 6 8

0 2 3 4 5 6 7 8 9

0 2 3 4 5 6 7 8 9

1

C3 1

1 1 C1

1 %10 ,T T O T O

Example: Cryptarithmetic Problem

Page 12: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TWO+ TWO _____ 1OUR

O

R

C1

W

U

C2

T

F

1

0 1

6 7 8

3 5 7

0 2 4 6 8

0 2 3 4 5 6 7 8 9

0 2 3 4 5 6 7 8 9

1

C3 1

1 1 C1

%10O O R

Example: Cryptarithmetic Problem

Page 13: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TWO+ TWO _____ 1OUR

O

R

C1

W

U

C2

T

F

1

0 1

6 7 8

3 5 7

0 4 6

0 2 3 4 5 6 7 8 9

0 2 3 4 5 6 7 8 9

1

C3 1

1 1 C1

1 9W W C

Example: Cryptarithmetic Problem

Page 14: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TWO+ TWO _____ 1OUR

O

R

C1

W

U

C2

T

F

1

0 1

6 7 8

3 5 7

0 4 6

5 6 7 8 9

0 2 3 4 5 6 7 8 9

1

C3 1

1 1 C1

MRVLCV

Example: Cryptarithmetic Problem

Page 15: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TWO+ TWO _____ 1OUR

O

R

C1

W

U

C2

T

F

1

0

6 7 8

3 5 7

0 4 6

5 6 7 8 9

0 2 3 4 5 6 7 8 9

1

C3 1

1 1 0

10O O

Example: Cryptarithmetic Problem

Page 16: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TW3+ TW3 _____ 13UR

O

R

C1

W

U

C2

T

F

1

0

6 7 8

3

0 4 6

5 6 7 8 9

0 2 3 4 5 6 7 8 9

1

C3 1

1 1 0

3 3 R

Example: Cryptarithmetic Problem

Page 17: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TW3+ TW3 _____ 13U6

O

R

C1

W

U

C2

T

F

1

0

6 7 8

3

6

5 6 7 8 9

0 2 3 4 5 6 7 8 9

1

C3 1

1 1 0

1 10 3T T

Example: Cryptarithmetic Problem

Page 18: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

6W3+ 6W3 _____ 13U6

O

R

C1

W

U

C2

T

F

1

0

6

3

6

5 6 7 8 9

0 2 3 4 5 6 7 8 9

1

C3 1

1 1 0

אחורה גלגול

Example: Cryptarithmetic Problem

Page 19: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TWO+ TWO _____ 1OUR

O

R

C1

W

U

C2

T

F

1

0 1

6 7 8

3 5 7

0 4 6

5 6 7 8 9

0 2 3 4 5 6 7 8 9

1

C3 1

1 1 C1

MRV

Example: Cryptarithmetic Problem

Page 20: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TWO+ TWO _____ 1OUR

O

R

C1

W

U

C2

T

F

1

1

6 7 8

3 5 7

0 4 6

5 6 7 8 9

0 2 3 4 5 6 7 8 9

1

C3 1

1 1 1

9O O

Example: Cryptarithmetic Problem

Page 21: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TWO+ TWO _____ 1OUR

O

R

C1

W

U

C2

T

F

1

1

6 7 8

5 7

0 4 6

5 6 7 8 9

0 2 3 4 5 6 7 8 9

1

C3 1

1 1 1

10O O R

Example: Cryptarithmetic Problem

Page 22: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TWO+ TWO _____ 1OUR

O

R

C1

W

U

C2

T

F

1

1

6 7 8

5 7

0 4

5 6 7 8 9

0 2 3 4 5 6 7 8 9

1

C3 1

1 1 1

1 10W W U

Example: Cryptarithmetic Problem

Page 23: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TWO+ TWO _____ 1OUR

O

R

C1

W

U

C2

T

F

1

1

6 7 8

5 7

0 4

6 7 8

3 5 7

1

C3 1

1 1 1

1 10T T O

Example: Cryptarithmetic Problem

Page 24: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

TWO+ TWO _____ 1OUR

O

R

C1

W

U

C2

T

F

1

1

7 8

5 7

0 4

6 7 8

3 5 7

1

C3 1

1 1 1

MRVLCV

Example: Cryptarithmetic Problem

Page 25: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

8WO+ 8WO _____ 1OUR

O

R

C1

W

U

C2

T

F

1

1

8

5 7

0 4

6 7 8

3 5 7

1

C3 1

1 1 1

Example: Cryptarithmetic Problem

Page 26: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

8W7+ 8W7 _____ 17UR

O

R

C1

W

U

C2

T

F

1

1

8

7

0 4

6 7 8

3 5 7

1

C3 1

1 1 1

Example: Cryptarithmetic Problem

Page 27: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

8W7+ 8W7 _____ 17U4

O

R

C1

W

U

C2

T

F

1

1

8

7

4

6 7 8

3 5 7

1

C3 1

1 1 1

Distinct character values

Example: Cryptarithmetic Problem

Page 28: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

867+ 867 _____ 17U4

O

R

C1

W

U

C2

T

F

1

1

8

7

4

6

3 5

1

C3 1

1 1 1Example: Cryptarithmetic Problem

Page 29: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

867+ 867 _____ 1734

O

R

C1

W

U

C2

T

F

1

1

8

7

4

6

3

1

C3 1

1 1 1Example: Cryptarithmetic Problem

Page 30: CSP Yaron Kassner Winter 2013. Reminder Arc Consistency: the domains of pairs of variables are consistent. k-consistency: the domains of every k variables.

Example: Zebra puzzle

• http://www.youtube.com/watch?v=_dcsqBY04OY

• Some kind of MAC.