47
Constraint processing Constraint processing An efficient alternative for An efficient alternative for search search

Constraint processing

  • Upload
    tacita

  • View
    46

  • Download
    0

Embed Size (px)

DESCRIPTION

Constraint processing. An efficient alternative for search. Constraint Processing: Overview. Illustrating the idea with examples: Numerical constraint nets, Spreadsheets. Defining constraint problems Techniques for solving them: A variety of backtracking techniques - PowerPoint PPT Presentation

Citation preview

Page 1: Constraint processing

Constraint processingConstraint processing

An efficient alternative for searchAn efficient alternative for search

Page 2: Constraint processing

2

Constraint Processing: OverviewConstraint Processing: Overview

Illustrating the idea with examples:Illustrating the idea with examples: Numerical constraint nets, SpreadsheetsNumerical constraint nets, Spreadsheets

Defining constraint problemsDefining constraint problems Techniques for solving them:Techniques for solving them:

A variety of backtracking techniquesA variety of backtracking techniques Consistency and relaxationConsistency and relaxation Hybrid constraint techniquesHybrid constraint techniques

Some applications: Some applications: Understanding line drawingsUnderstanding line drawings Disambiguating natural languageDisambiguating natural language

Page 3: Constraint processing

X

A

B

X

C D

Variable box

Multiply box

1.1

Ex.: Numerical constraint netsEx.: Numerical constraint netsGiven any set of equations:

There is an associated constraint net:

C = A * B D = C * B B = 1.1

3300 36303000

Page 4: Constraint processing

X

A

B

X

C D

Variable box

Multiply box

1.1

There is an associated constraint net:

Numerical constraint nets (2)Numerical constraint nets (2)

33003000 3630

Page 5: Constraint processing

5

Example: Spreadsheets Example: Spreadsheets A B

1 Ratio X 1.2

2 Ratio Y 1.1

4 1th year

5 Income X 3000

6 Income Y 5000

7 Expenses 9000

C D

2nd year 3rd year

8 Total

= B1 * B5 = B1 * C5

= B2 * B6= B2 * C6

= B7 = C7

= B5+B6 -B7

= C5+C6 - C7

=D5+D6 -D7

Page 6: Constraint processing

6

Spreadsheets (2) Spreadsheets (2) A B

1 Ratio X 1.2

2 Ratio Y 1.1

4 1th year

5 Income X 3000

6 Income Y 5000

7 Expenses 9000

C D

2nd year 3rd year

8 Total

= B1 * B5 = B1 * C5

= B2 * B6= B2 * C6

= B7 = C7

= B5+B6 -B7

= C5+C6 - C7

=D5+D6 -D7

= B1 * B5 = B1 * C53600 4320

= B2 * B6= B2 * C65500 6050

= B7 = C79000 9000

-B7 - C7 -D7= B5+B6= C5+C6 =D5+D6 - 1000 100 1370

Page 7: Constraint processing

X

A

B

X

C D

Variable box

Multiply box

1.1

There is an associated constraint net:

Numerical constraint nets (3)Numerical constraint nets (3)

3630 OR4840

2000OR3000

44004000

Page 8: Constraint processing

Defining Constraint problemsDefining Constraint problems

DefinitionDefinition

File rougeFile rouge

Page 9: Constraint processing

9

Defining Constraint problemsDefining Constraint problems DefinitionDefinition:: A constraint problem (or consistent A constraint problem (or consistent

labeling problem) consists of:labeling problem) consists of: a finite set of variables: a finite set of variables: z1z1, , z2z2, … , , … , znzn for each variable: an associated finite domain for each variable: an associated finite domain

of possible values of possible values didi = { = {aiai11,,aiai22, … , , … , aiainini}} for each two variables for each two variables zizi, , zjzj, , ii jj, a constraint , a constraint

c(zi, zj)c(zi, zj) exex.: .: zizi zjzj zizi ++ ii zjzj -- jj we restrict ourselves to binary CPSwe restrict ourselves to binary CPS

Problem:Problem: build efficient techniques to assign to build efficient techniques to assign to each each zizi a value a value aiaijj from its domain from its domain didi such that all such that all c(zi, zj)c(zi, zj) are true. are true.

Page 10: Constraint processing

10

Example: q-queens:Example: q-queens:

… … is a solutionis a solution

Given:Given: a q X q chess board a q X q chess board Problem:Problem: find (all possible) ways of placing q find (all possible) ways of placing q

queens on the board, such that queens on the board, such that no 2 queenno 2 queens s attackattack each other. each other.

4-queens:4-queens:

Page 11: Constraint processing

11

Confused q-queens:Confused q-queens:

= identical, BUT each = identical, BUT each 2 queens MUST attack2 queens MUST attack each each other.other.

C-4-queens:C-4-queens:

Page 12: Constraint processing

12

Constraint formulation?Constraint formulation?

Q-queens and C-q-queens define a set of Q-queens and C-q-queens define a set of constraint problems:constraint problems: depends on choice of domains, constraintsdepends on choice of domains, constraints

One possibility:One possibility:

for each queen: a variable for each queen: a variable zizi for each for each zizi, domain , domain didi is all possible board is all possible board

positions:positions: didi = { (1,1), (1,2), …, (1,q), (2,1), (2,2), … } = { (1,1), (1,2), …, (1,q), (2,1), (2,2), … }

c(zi, zj)c(zi, zj) = row( = row(zizi) ) row( row(zjzj) ) col( col(zizi) ) col( col(zjzj)) |row( |row(zizi) ) -- row( row(zjzj)| )| |col( |col(zizi) ) -- col( col(zjzj)|)|

Page 13: Constraint processing

13

A ‘better’ formulation:A ‘better’ formulation: We agree that each queen is placed on a specific row:We agree that each queen is placed on a specific row:

z1z1

z2z2

z3z3

z4z4

11 22 33 44

for queen on row i: a variable for queen on row i: a variable zizi

The representation:The representation:

for each for each zizi, domain , domain didi = { 1, 2, … , q} = { 1, 2, … , q} c(zi, zj)c(zi, zj) = = zizi zjzj | |zizi -- zjzj| | | |ii -- jj||

Page 14: Constraint processing

14

Notes on C-q-queens:Notes on C-q-queens: For C-q-queens, the new second representation For C-q-queens, the new second representation

defines a slightly different problem:defines a slightly different problem:

… … is no longer a solutionis no longer a solution

Now C-q-queens always Now C-q-queens always has q+2 solutionshas q+2 solutions ! !

Advantage for complexity studies.Advantage for complexity studies.

Exception:Exception: q = 3: q = 3:

are extraare extra

Page 15: Constraint processing

Representing the searchRepresenting the search

Or-tree representationOr-tree representation

Constraint NetworksConstraint Networks

Page 16: Constraint processing

16

The OR-tree representation:The OR-tree representation:Select an order on the variables: Select an order on the variables: z1z1, , z2z2, …, , …, znzn

z1z1 . . . . . . . . . . . . . . . . . . a1a111 a1 a122 … … … … … … … … … … … … … … a1a1n1n1

z2z2 . . . . . . . . . . . . . . . . . . a2a211 a2 a222 … … … … a2a2n2n2

c(c(z1z1,,z2z2)) . . . . . . . x v … … v. . . . . . . x v … … v

z3z3 . . . . . . . . . . a3a311 a3 a322 … … … … … … a3a3n3n3

c(c(z1z1,,z3z3)) . . . v v … … … x. . . v v … … … x c(c(z2z2,,z3z3)) . . . x v … … … . . . x v … … …

Page 17: Constraint processing

17

OR-tree: explicitlyOR-tree: explicitly

For each layer (i) in the OR-tree:For each layer (i) in the OR-tree:

Create a branch for every possible Create a branch for every possible assignment assignment to to zizi

Verify all constraints Verify all constraints c(c(zjzj, , zizi),), jj ii If all constraints are satisfied, proceed to level If all constraints are satisfied, proceed to level i+1i+1

NOTENOTE: this is only a representation for the search: this is only a representation for the search search itself consists of building a (small) part search itself consists of building a (small) part of this tree (as in search techniques)of this tree (as in search techniques)

Page 18: Constraint processing

18

Constraint NetworksConstraint Networks

z2z2

z1z1

z3z3

z4z4

c(c(z1z1,,z2z2)) c(c(z1z1,,z4z4))

c(c(z1z1,,z3z3))

c(c(z2z2,,z3z3)) c(c(z3z3,,z4z4))

c(c(z2z2,,z4z4))

{a1{a111, a1, a122, …, a1, …, a1n1n1}}

{a4{a411, a4, a422, …, a4, …, a4n4n4}}{a2{a211, a2, a222, …, a2, …, a2n2n2}}

{a3{a311, a3, a322, …, a3, …, a3n3n3}}

+ relaxation+ relaxation = select an arc (constraint) and = select an arc (constraint) and remove remove the inconsistent domain the inconsistent domain valuesvalues

Page 19: Constraint processing

19

z2z2

z1z1

z3z3

z4z4

c(c(z1z1,,z2z2)) c(c(z1z1,,z4z4))

c(c(z1z1,,z3z3))

c(c(z2z2,,z3z3)) c(c(z3z3,,z4z4))

c(c(z2z2,,z4z4))

{a1{a111, a1, a122, …, a1, …, a1n1n1}}

{a4{a411, a4, a422, …, a4, …, a4n4n4}}{a2{a211, a2, a222, …, a2, …, a2n2n2}}

{a3{a311, a3, a322, …, a3, …, a3n3n3}}

Relaxation:Relaxation:

c(c(z1z1,,z4z4))

a4a411

c(a1c(a1ii, a4, a411) is ) is nevernever true! true!

Page 20: Constraint processing

Backtrack algorithmsBacktrack algorithms

Chronological BacktrackingChronological Backtracking

BackjumpingBackjumping

BackmarkingBackmarking

Intelligent BacktrackingIntelligent Backtracking

Dynamic Search RearrangementDynamic Search Rearrangement

Page 21: Constraint processing

21

ExampleExample: 4-queens:: 4-queens:

Chronological BacktrackingChronological BacktrackingTraverse the OR-tree depth-first, left-to-right.Traverse the OR-tree depth-first, left-to-right.

z1z1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1

z2z2 . . . . . . . . . . . . . . 11 c(c(z1z1,,z2z2)) . . . . x. . . . x

22xx

33vv

z3z3 . . . . . . . . . . . . . . . . 1. . . . . . 1 c(c(z1z1,,z3z3)) . . . . . . . . x. . . . . . . . x

22vv

c(c(z2z2,,z3z3)) . . . . . . . . . . . x. . . . . . . . . . . x

33vvxx

44vvxx

44vv

11xx

22vvvv

z4z4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 2 3 4. . . . . . . . . . . . . . . . . . . . 1 2 3 4 c(c(z1z1,,z4z4)) . . . . . . . . . . . . . . . . . . . . . . x v v x. . . . . . . . . . . . . . . . . . . . . . x v v x c(c(z2z2,,z4z4)) . . . . . . . . . . . . . . . . . . . . . . . . x v . . . . . . . . . . . . . . . . . . . . . . . . x v c(c(z3z3,,z4z4)) . . . . . . . . . . . . . . . . . . . . . . . . . . . x. . . . . . . . . . . . . . . . . . . . . . . . . . . x

Page 22: Constraint processing

22

The backtrack algorithm:The backtrack algorithm:Backtr(Backtr( depthdepth ))

ForFor kk= 1 = 1 toto n ndepthdepth dodo zzdepthdepth := a := adepthdepth,,kk ; ; Check all constraints c(zCheck all constraints c(zii, z, zdepthdepth) ) with 1 with 1 ii depthdepth until one fails; until one fails; IfIf none failed none failed thenthen

IfIf depthdepth = n = n thenthen return( z1, z2, … , zn)return( z1, z2, … , zn)

End-ForEnd-For

ElseElse depthdepth := := depthdepth + 1; + 1; Backtr( Backtr( depth depth )) ; ; depthdepth := := depthdepth - 1; - 1;

CallCall : Backtr( 1 ) : Backtr( 1 )

zzdepthdepth . . . . . . . . aadepth,kdepth,k c(c(z1z1,,zzdepthdepth)) . . . v. . . v c(c(z2z2,,zzdepthdepth)) . . . x. . . x c(z1,zdepth) . . . v c(z2,zdepth) . . . x c(c(z1z1,,zzdepthdepth)) . . . v. . . v c(c(z2z2,,zzdepthdepth)) . . . v. . . v

c(c(zzdepth-1depth-1,,zzdepthdepth)) vv

zzdepth+1depth+1 . . . . aadepth+1,1depth+1,1

Page 23: Constraint processing

Backjumping Backjumping

Avoid trashingAvoid trashing

Page 24: Constraint processing

24

Trashing:Trashing: ExampleExample: c-4-queens:: c-4-queens:

z1z1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2

z2z2 . . . . . . . . . . . . . . 11 c(c(z1z1,,z2z2)) . . . . v. . . . v

22vv

33vv

z3z3 . . . . . . . .

c(c(z2z2,,z3z3)) . . . . . . . . c(c(z1z1,,z3z3)) . . . .

44xx

z4z4 . . . . . . c(c(z1z1,,z4z4)) . . . . c(c(z2z2,,z4z4)) . . . . . .

c(c(z3z3,,z4z4)) . . . . . . . . . . . . . . .. . . . . . . . . . . . . . .

11xx

22vvvv

33xx

44vvxx

11xx

22vvvv

33xx

44vvxx

11xx

22vvvv

33xx

44vvvv

11xx

22vvxx

33xx

44xx

11xx

22vvvvvv

33xx

44xx

11xx

22vvxx

33xx

44xx

11xx

22vvxx

33xx

44xx

Only z1 and z2 are tested against the Only z1 and z2 are tested against the values of z4: z3 is not even considered!values of z4: z3 is not even considered!

UselessUselessto backtrackto backtrackover z3 !over z3 !

RedundantRedundantcomputation !computation !

Page 25: Constraint processing

25

Trashing: solutionTrashing: solution

z1z1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2

z2z2 . . . . . . . . . . . . . . 11 c(c(z1z1,,z2z2)) . . . . v. . . . v

22vv

33vv

z3z3 . . . . . . . .

c(c(z2z2,,z3z3)) . . . . . . . . c(c(z1z1,,z3z3)) . . . .

44xx

z4z4 . . . . . . c(c(z1z1,,z4z4)) . . . . c(c(z2z2,,z4z4)) . . . . . .

c(c(z3z3,,z4z4)) . . . . . . . . . . . . . . .. . . . . . . . . . . . . . .

11xx

22vvvv

33xx

44vvxx

11xx

22vvvv

33xx

44vvxx

11xx

22vvvv

33xx

44vvvv

11xx

22vvxx

33xx

44xx

11xx

22vvvvvv

33xx

44xx

11xx

22vvxx

33xx

44xx

11xx

22vvxx

33xx

44xx

BackjumpBackjump

Page 26: Constraint processing

26

Trashing:Trashing: Another occurrenceAnother occurrence

z1z1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2

z2z2 . . . . . . . . . . . . . . 11 c(c(z1z1,,z2z2)) . . . . v. . . . v

22vv

33vv

z3z3 . . . . . . . .

c(c(z2z2,,z3z3)) . . . . . . . . c(c(z1z1,,z3z3)) . . . .

44xx

z4z4 . . . . . . c(c(z1z1,,z4z4)) . . . . c(c(z2z2,,z4z4)) . . . . . .

c(c(z3z3,,z4z4)) . . . . . . . . . . . . . . .. . . . . . . . . . . . . . .

11xx

22vvvv

33xx

44vvxx

11xx

22vvvv

33xx

44vvxx

11xx

22vvvv

33xx

44vvvv

11xx

22vvxx

33xx

44xx

11xx

22vvvvvv

33xx

44xx

11xx

22vvxx

33xx

44xx

11xx

22vvxx

33xx

44xx

BackjumpBackjump

Page 27: Constraint processing

27

Backjumping (Gaschnig’78)Backjumping (Gaschnig’78)

IfIf all the assignments to all the assignments to zi zi fail,fail,

The principle:The principle:

andand c(zk, zi)c(zk, zi) is the deepest constraint causing the fail is the deepest constraint causing the fail

ThenThen backjumpbackjump to change the assignment of to change the assignment of zkzk

zizi . . . . . . . . . . . . . . . . . . . . . . . ai. . . . . . . . . . . . . ai11 ai ai22 ... ai ... ainini

c(c(z1z1,,zizi)) . . . . . . . . . . . . . . . . . x v v x. . . . . . . . . . . . . . . . . x v v x c(c(z2z2,,zizi)) . . . . . . . . . . . . . . . . . . . x v . . . . . . . . . . . . . . . . . . . x v

c(c(zkzk,,zizi)) . . . . . . . . . . . . . . . . . . . . . . x. . . . . . . . . . . . . . . . . . . . . . x… … … …

allallfail !fail !

deepest fail-level: kdeepest fail-level: k

Page 28: Constraint processing

28

The backjump algorithm:The backjump algorithm:BackJ(BackJ( depthdepth, out: , out: jumpbackjumpback ))

ForFor k= 1 k= 1 toto n ndepthdepth dodo zzdepthdepth := a := adepth,kdepth,k ; ; Check all constraints c(zCheck all constraints c(zii, z, zdepthdepth) ) with 1 with 1 i i depth until one fails; depth until one fails;

IfIf none failed none failed thenthenIfIf depth = n depth = n thenthen return( z1, z2, … , zn)return( z1, z2, … , zn)

End-ForEnd-For

c(c(z1z1,,zzdepthdepth)) . . . v. . . v c(c(z2z2,,zzdepthdepth)) . . . x. . . x

zzdepthdepth . . . . . . . . aadepth,kdepth,k

checkdepthcheckdepthkk = 2 = 2

zzdepthdepth . . . . . . . . aadepth,ldepth,l c(c(z1z1,,zzdepthdepth)) . . . v. . . v c(c(z2z2,,zzdepthdepth)) . . . v. . . v

c(c(zzmm,,zzdepthdepth)) . . . . . . xx

checkdepthcheckdepthll = m = m

checkdepthcheckdepthkk := deepest i checked;:= deepest i checked;

ElseElse depth := depth + 1;depth := depth + 1; BackJ( depth, BackJ( depth, jumpbackjumpback);); depth := depth - 1;depth := depth - 1; IfIf jumpbackjumpbackdepthdepth thenthen return;return;

jumpbackjumpback := max(:= max(checkdepthcheckdepthkk))

Page 29: Constraint processing

BackmarkingBackmarking

Avoiding other redundanciesAvoiding other redundancies

Page 30: Constraint processing

30

More redundant checks:More redundant checks:

z1z1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2

z2z2 . . . . . . . . . . . . . . 11 c(c(z1z1,,z2z2)) . . . . v. . . . v

22vv

33vv

z3z3 . . . . . . . .

c(c(z2z2,,z3z3)) . . . . . . . . c(c(z1z1,,z3z3)) . . . .

44xx

z4z4 . . . . . . c(c(z1z1,,z4z4)) . . . . c(c(z2z2,,z4z4)) . . . . . .

c(c(z3z3,,z4z4)) . . . . . . . . . . . . . . .. . . . . . . . . . . . . . .

11xx

22vvvv

33xx

44vvxx

11xx

22vvvv

33xx

44vvxx

11xx

22vvvv

33xx

44vvvv

11xx

22vvxx

33xx

44xx

11xx

22vvvvvv

33xx

44xx

11xx

22vvxx

33xx

44xx

11xx

22vvxx

33xx

44xx

z1 is checkedz1 is checkedagainst z3against z3

BUT we only back-BUT we only back-track over z2 !track over z2 !

Page 31: Constraint processing

31

Occur very often:Occur very often:

z1z1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2

z2z2 . . . . . . . . . . . . . . 11 c(c(z1z1,,z2z2)) . . . . v. . . . v

22vv

33vv

z3z3 . . . . . . . .

c(c(z2z2,,z3z3)) . . . . . . . . c(c(z1z1,,z3z3)) . . . .

44xx

z4z4 . . . . . . c(c(z1z1,,z4z4)) . . . . c(c(z2z2,,z4z4)) . . . . . .

c(c(z3z3,,z4z4)) . . . . . . . . . . . . . . .. . . . . . . . . . . . . . .

11xx

22vvvv

33xx

44vvxx

11xx

22vvvv

33xx

44vvxx

11xx

22vvvv

33xx

44vvvv

11xx

22vvxx

33xx

44xx

11xx

22vvvvvv

33xx

44xx

11xx

22vvxx

33xx

44xx

11xx

22vvxx

33xx

44xx

Page 32: Constraint processing

32

Trashing compared to Trashing compared to Redundant Checks:Redundant Checks:

z4z4 . . . . . . c(c(z1z1,,z4z4)) . . . . c(c(z2z2,,z4z4)) . . . . . . c(c(z3z3,,z4z4))

11xx

22vvxx

33xx

44xx

Only when a complete Only when a complete BLOCKBLOCK of checks of checks FAILSFAILS..

Trashing:Trashing:

Also for Also for SUCCESSFULSUCCESSFUL checks and for the checks and for the checks performed on checks performed on 1 ROW1 ROW only. only.

Redundant Checks:Redundant Checks:

z3z3 . . . . . . . .

c(c(z2z2,,z3z3)) . . . . . . . . c(c(z1z1,,z3z3)) . . . .

11xx

22vvvv

33xx

44vvxx

11xx

22vvvv

33xx

44vvxx

Page 33: Constraint processing

33

Avoiding redundant checks:Avoiding redundant checks: 2 approaches:2 approaches:

1. TABULATION:1. TABULATION: lemma generation lemma generation (store results of checks in a table)(store results of checks in a table)

+ lemma application + lemma application (table look-up for new (table look-up for new checks)checks)

improves speed to some extentimproves speed to some extent but does not but does not reallyreally avoid the redundant checks avoid the redundant checks

increases the storage requirementsincreases the storage requirements

2. BACKMARKING:2. BACKMARKING:

~ ~ TOTALLYTOTALLY speed saving speed saving (no redundant checks)(no redundant checks) only limited space-overhead only limited space-overhead (2 arrays)(2 arrays)

Page 34: Constraint processing

34

Backmarking (Gaschnig ‘77):Backmarking (Gaschnig ‘77): The 2 arrays:The 2 arrays:

zkzk . . . . . . . .

c(c(z2z2,,zkzk)) . . . . . . . . c(c(z1z1,,zkzk)) . . . .

akak11 xx

akak22 vv xx

… … vv vv … … vv

akaknknk vv xx

akak11 …… akaknknk

c(c(zzk-1k-1,,zkzk)) . . . . . . . . . . . . . . . .

= checkdepth= checkdepthzk, lzk, l..

Checkdepth(k,l):Checkdepth(k,l):

checkdepthcheckdepthzk,1zk,1 = 1 = 1

checkdepthcheckdepthzk,2zk,2 = 2 = 2checkdepthcheckdepthzk,…zk,… = k-1= k-1

checkdepthcheckdepthzk,nkzk,nk = 2 = 2

akak22

Page 35: Constraint processing

35

Backmarking (Gaschnig ‘77):Backmarking (Gaschnig ‘77): The 2nd array:The 2nd array:

zkzk . . . . . . . .

c(c(z2z2,,zkzk)) . . . . . . . . c(c(z1z1,,zkzk)) . . . .

akak11 xx

akak22 vv vv

… … vv vv … … vv

akaknknk vv xx

akak11 …… akaknknk

c(c(zzk-1k-1,,zkzk)) . . . . . . . . . . . . . . . .

akak22

= to which (lowest) level did we backup = to which (lowest) level did we backup between between visiting these 2 blocks for zk.visiting these 2 blocks for zk.

Backup(k):Backup(k):

zk-1zk-1

zk-2zk-2

Page 36: Constraint processing

36

A property of CheckdepthA property of Checkdepthk,lk,l

The last check needs to The last check needs to be a be a FAILFAIL..

Otherwise, checking Otherwise, checking would have continued !would have continued !

The last check can be The last check can be either either failfail or or succeedsucceed..

IfIf Checkdepth Checkdepth k,lk,l k-1: k-1:

IfIf Checkdepth Checkdepth k,lk,l = k-1: = k-1:

zk zk . . . . ak,l. . . . ak,lc(c(z1z1,,zkzk) . . v) . . vc(c(z2z2,,zkzk) . . v) . . v … …c(c(zk-1zk-1,,zkzk) . x/v ) . x/v

zk zk . . . . ak,l. . . . ak,lc(c(z1z1,,zkzk) . . v) . . vc(c(z2z2,,zkzk) . . v) . . v … …c(c(zizi,,zkzk) . . . x) . . . x

Page 37: Constraint processing

37

Properties of Checkdepth versus Properties of Checkdepth versus Backup (1):Backup (1):

IfIf checkdepth (k,l)checkdepth (k,l) backup(k)backup(k) : :

checkdepth(k,l) checkdepth(k,l) k-1

The assignment The assignment ak,lak,l to to zkzk caused caused failfail the the previous time, and it will cause previous time, and it will cause fail againfail again this time (at the same depth)this time (at the same depth)

zk zk . . . . . . . ak,l. . . . . . . ak,lc(c(z1z1,,zkzk) . . . . . v) . . . . . vc(c(z2z2,,zkzk) . . . . . v) . . . . . v … …c(c(zizi,,zkzk) . . . . . .x) . . . . . .x … …c(c(zk-1zk-1,,zkzk))

checkdepth(k,l)checkdepth(k,l)

backup(k)backup(k)

Page 38: Constraint processing

38

Properties of Checkdepth versus Properties of Checkdepth versus Backup (2):Backup (2):

IfIf checkdepth (k,l)checkdepth (k,l) backup(k)backup(k) : :

zk zk . . . . . . . ak,l. . . . . . . ak,lc(c(z1z1,,zkzk) . . . . . v) . . . . . vc(c(z2z2,,zkzk) . . . . . v) . . . . . v … …c(c(zizi,,zkzk) . . . . . .v) . . . . . .v … … c(c(zjzj,,zkzk) . . . . v/x) . . . . v/x checkdepth(k,l)checkdepth(k,l)

backup(k)backup(k)

All checks for variables All checks for variables zmzm, with , with mm lower lower thanthan backup(k)backup(k) succeededsucceeded before and will before and will succeed againsucceed again. .

Page 39: Constraint processing

39

The Backmark algorithm:The Backmark algorithm:BackM(BackM( depthdepth, out: , out: checkdepthcheckdepth,, backup backup ))

ForFor k= 1 k= 1 toto n ndepthdepth dodo zzdepthdepth := a := adepth,kdepth,k ; ;

Check all constraints c(zCheck all constraints c(zii, z, zdepthdepth) with ) with 1 1 i i depth until one fails; depth until one fails;

IfIf none failed none failed thenthen… … … … … …

End-ForEnd-For

IfIf checkdepthcheckdepth((depthdepth,,kk) ) backupbackup((depthdepth))ThenThen

11backupbackup((depthdepth))

*property 1 applied**property 1 applied*

*property 2 applied**property 2 applied*

Page 40: Constraint processing

40

z1z1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2

Backmarking at work:Backmarking at work:

z2z2 . . . . . . . . . . . . . . 11 c(c(z1z1,,z2z2)) . . . . v. . . . v

z3z3 . . . . . . . .

c(c(z2z2,,z3z3)) . . . . . . . . c(c(z1z1,,z3z3)) . . . .

11xx

22vvvv

z4z4 . . . . . . c(c(z1z1,,z4z4)) . . . . c(c(z2z2,,z4z4)) . . . . . .

11xx

22vvxx

33xx

44xx

33xx

44vvxx

vv22

vv

11xx

22vv

11xx

22vv

33xx

44xx

vvvv c(c(z3z3,,z4z4)) . . . . . . . . .. . . . . . . . .

33xx

44vvxx

Page 41: Constraint processing

41

At a much later stage:At a much later stage:

33vv

11xx

22vvvv

33xx

44vvvv

11xx

22vvxx

33xx

44xx

11xx

22vvxx

33xx

44xx

z1z1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2

z2z2 . . . . . . . . . . . . . . c(c(z1z1,,z2z2)) . . . . . . . .

z3z3 . . . . . . . .

c(c(z2z2,,z3z3)) . . . . . . . . c(c(z1z1,,z3z3)) . . . .

z4z4 . . . . . . c(c(z1z1,,z4z4)) . . . . c(c(z2z2,,z4z4)) . . . . . . c(c(z3z3,,z4z4)) . . . . . . . . .. . . . . . . . .

44xx

33

Page 42: Constraint processing

42

Discussion and results:Discussion and results:Note:Note: initial values for initial values for checkdepth(k,l)checkdepth(k,l) and and

backup(k)backup(k) are all are all 11 Experimental results:Experimental results:

For c-4-queens problemFor c-4-queens problem

BTBT BJBJ BMBM

NodesNodes

ChecksChecks

2929 2727 2929

160160 139139 9090

Overall:Overall: BackMarking = best algorithm (not absolute)BackMarking = best algorithm (not absolute)

Combining BJ and BM? YES !Combining BJ and BM? YES ! But does not produce the combined optimisation.But does not produce the combined optimisation.

Page 43: Constraint processing

Dynamic Search rearrangementDynamic Search rearrangement

Page 44: Constraint processing

44

Dynamic search rearrangementDynamic search rearrangement = any backtrack algorithm= any backtrack algorithm

++ select the order of the variables in the tree select the order of the variables in the tree

dynamically dynamically

Purpose:Purpose:

Decrease the size of the tree due to the Decrease the size of the tree due to the “first-fail “first-fail principle”principle”

IfIf assigning a value to assigning a value to zizi is more likely to fail than is more likely to fail than assigning to assigning to zjzj: :

Then:Then: assing to assing to zizi first. first.

The The first-fail principlefirst-fail principle::

Page 45: Constraint processing

45

Effect?Effect? 1. Suppose our guess was right… 1. Suppose our guess was right…

zizi . . . . . . c(c(z1z1,,zizi)) . . . . c(c(z2z2,,zizi)) . . x . . x

ai1ai1vvxx

… … aikaik xx

zjzj . . . . . . c(c(z1z1,,zjzj)) . . . . c(c(z2z2,,zjzj) . . ) . .

aj1aj1 vv vv

aj2aj2 xx

ajlajl vv vv

ai1ai1vvxx

… … aikaik xx

ai1ai1vvxx

… … aikaik xx

zizi . . . . . . c(c(z1z1,,zizi)) . . . . c(c(z2z2,,zizi)) . .

Done Done

Smaller search tree !Smaller search tree !

… … then we gain in any case then we gain in any case

Page 46: Constraint processing

46

Effect (2)?Effect (2)? 2. Suppose our guess was only partly right … 2. Suppose our guess was only partly right …

ai1ai1vvvv

… … aikaik xx

ai1ai1vvvv

… … aikaik xx

zizi . . . . . . c(c(z1z1,,zizi)) . . . . c(c(z2z2,,zizi)) . .

Less checks are redone !Less checks are redone ! … … we still gain: we still gain:

Assingment to zi does not fail, but Assingment to zi does not fail, but has less successes !has less successes !

zjzj . . . . . . c(c(z1z1,,zjzj)) . . . . c(c(z2z2,,zjzj) . . ) . .

aj1aj1 vv vv

aj2aj2 xx

ajlajl vv vv

zizi . . . . . . c(c(z1z1,,zizi)) . . . . c(c(z2z2,,zizi)) . . x . . x

ai1ai1vvvv

… … aikaik xx

zjzj . . . . . . c(c(z1z1,,zjzj)) . . . . c(c(z2z2,,zjzj) . . ) . .

aj1aj1 vv vv

aj2aj2 xx

ajlajl vv vv

Page 47: Constraint processing

47

Some general first-fail heuristics:Some general first-fail heuristics: Select the variable with the Select the variable with the smallest domainsmallest domain first first decreases the branching factor (less possibilities -> probably decreases the branching factor (less possibilities -> probably

less successes)less successes)

Select the variable with the Select the variable with the highest number of highest number of non-trivial constraintsnon-trivial constraints first: first:

z2z2

z1z1

z3z3

z4z4

c(c(z1z1,,z2z2)) c(c(z1z1,,z4z4) = ) = “true”“true”c(c(z1z1,,z3z3))

““true”true” = c( = c(z2z2,,z3z3)) c(c(z3z3,,z4z4) = ) = “true”“true”c(c(z2z2,,z4z4))

++ Heuristics based on problem at hand. Heuristics based on problem at hand.