0% found this document useful (0 votes)
17 views7 pages

NPTEL AI CSP 2025 Week 04 Algorithms

The document outlines various algorithms for solving Constraint Satisfaction Problems, including Backtracking, Adaptive-Consistency, Generalized-Look-Ahead, and several others. Each algorithm is presented with a structured approach detailing the steps involved in selecting values and managing domains. The focus is on syntactic variations derived from Rina Dechter's work in Constraint Processing.

Uploaded by

Shreyan Saha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views7 pages

NPTEL AI CSP 2025 Week 04 Algorithms

The document outlines various algorithms for solving Constraint Satisfaction Problems, including Backtracking, Adaptive-Consistency, Generalized-Look-Ahead, and several others. Each algorithm is presented with a structured approach detailing the steps involved in selecting values and managing domains. The focus is on syntactic variations derived from Rina Dechter's work in Constraint Processing.

Uploaded by

Shreyan Saha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Constraint Satisfaction Problems

Week 4 – Algorithms
Prepared by S. Baskaran

The algorithms presented below are simple syntactic variations of the


algorithms from the book Constraint Processing by Rina Dechter.

Backtracking(R = (X, D, C))


1 i←1
2 D0i ← copy of Di
3 while 1 ≤ i ≤ N
4 xi ← Select-Value
5 if xi is null  value not found
6 then i ← i – 1  backtrack
7 else i ← i + 1  step forward
8 D0i ← copy of Di if i ≤ N

9 if i = 0
10 then return failure
11 else return instantiated values of [x1 , x2 , . . . , xN ]

Select-Value
12 past-values ← instantiated values of [x1 , x2 , . . . , xi–1 ]
13 while D0i is not empty
14 a ← remove one value from D0i
15 if Consistent(past-values, xi ← a)  local assignment
16 return a
17 return null
Adaptive-Consistency(R = (X, D, C), d = [x1 , x2 , . . . , xN ])
 Partition the constraints into bucket1 , bucket2 , . . . , bucketN
1 for each k ← N down to 1
2 put in bucketk all unplaced constraints having xk in its scope

 Eliminate variables, create new relations, tighten existing relations


3 for each k ← N down to 1
4 for all constraints RS1 , RS2 , . . . , RSM in bucketk
5 S ← (S1 ∪ S2 ∪ . . . ∪ SM ) \ { xk }  Scope
6 RS ← πS (RS1 ./ RS2 ./ . . . ./ RSM )  Eliminate variable xk

7 if RS is empty
8 then return empty network  No solution
9 else put RS in the bucket of the latest variable in S

10 return R0 = (X, D, (bucket1 ∪ . . . ∪ bucketN ))  Backtrack-free network


Generalized-Look-Ahead(R = (X, D, C))
1 D0i ← copy of Di , for 1 ≤ i ≤ N
2 i←1
3 while 1 ≤ i ≤ N
4 xi ← Select-Value-xxx  plugin a suitable procedure
5 if xi is null  value not found
6 then i ← i – 1  backtrack
7 for each k > i  restore future domains
8 0
reset Dk to before xi was last instantiated
9 else i ← i + 1  step forward

10 if i = 0
11 then return failure
12 else return instantiated values of [x1 , x2 , . . . , xN ]
Forward-Checking(R = (X, D, C))
1 D0i ← copy of Di , for 1 ≤ i ≤ N
2 i←1
3 while 1 ≤ i ≤ N
4 xi ← Select-Value-Forward-Checking
5 if xi is null  value not found
6 then i ← i – 1  backtrack
7 for each k > i  restore future domains
8 0
reset Dk to before xi was last instantiated
9 else i ← i + 1  step forward

10 if i = 0
11 then return failure
12 else return instantiated values of [x1 , x2 , . . . , xN ]

Select-Value-Forward-Checking
13 past-values ← instantiated values of [x1 , x2 , . . . , xi–1 ]
14 while D0i is not empty
15 a ← remove one value from D0i

16 dead-end ← false
17 for each k > i and not dead-end  prune future domains
18 for each value b in D0k  prune domain
19 if not Consistent(past-values, xi ← a, xk ← b)
20 remove b from D0k  prune value
21 if D0k is empty
22 dead-end ← true

23 if not dead-end
24 return a

25 for each k > i


26 reset D0k to before value a was selected

27 return null  no consistent value


Partial-Look-Ahead(R = (X, D, C))
1 D0i ← copy of Di , for 1 ≤ i ≤ N
2 i←1
3 while 1 ≤ i ≤ N
4 xi ← Select-Value-Arc-Consistency
5 if xi is null  value not found
6 then i ← i – 1  backtrack
7 for each k > i  restore future domains
8 0
reset Dk to before xi was last instantiated
9 else i ← i + 1  step forward

10 if i = 0
11 then return failure
12 else return instantiated values of [x1 , x2 , . . . , xN ]

Select-Value-Partial-Look-Ahead
13 past-values ← instantiated values of [x1 , x2 , . . . , xi–1 ]
14 while D0i is not empty
15 a ← remove one value from D0i

 single pass of directional arc-consistency over future variables


16 for each j ← (i + 1) to N
17 for each k ← (j + 1) to N
18 for each value b in D0j
19 if there exists c in D0k such that
Consistent(past-values, xi ← a, xj ← b, xk ← c)
20 then continue
21 else remove b from D0j

22 if any future domain is empty


23 then for each j > i
24 reset D0j to before value a was selected
25 else return a

26 return null  no consistent value


Full-Look-Ahead(R = (X, D, C))
1 D0i ← copy of Di , for 1 ≤ i ≤ N
2 i←1
3 while 1 ≤ i ≤ N
4 xi ← Select-Value-Arc-Consistency
5 if xi is null  value not found
6 then i ← i – 1  backtrack
7 for each k > i  restore future domains
8 0
reset Dk to before xi was last instantiated
9 else i ← i + 1  step forward

10 if i = 0
11 then return failure
12 else return instantiated values of [x1 , x2 , . . . , xN ]

Select-Value-Full-Look-Ahead
13 past-values ← instantiated values of [x1 , x2 , . . . , xi–1 ]
14 while D0i is not empty
15 a ← remove one value from D0i

 single pass over every ordered pair of future variables


16 for all j such that i < j ≤ N
17 for all k such that k 6= j and i < k ≤ N
18 for each value b in D0j
19 if there exists c in D0k such that
Consistent(past-values, xi ← a, xj ← b, xk ← c)
20 then continue
21 else remove b from D0j

22 if any future domain is empty


23 then for each j > i
24 reset D0j to before value a was selected
25 else return a

26 return null  no consistent value


Arc-Consistency-Look-Ahead(R = (X, D, C))
1 D0i ← copy of Di , for 1 ≤ i ≤ N
2 i←1
3 while 1 ≤ i ≤ N
4 xi ← Select-Value-Arc-Consistency
5 if xi is null  value not found
6 then i ← i – 1  backtrack
7 for each k > i  restore future domains
8 0
reset Dk to before xi was last instantiated
9 else i ← i + 1  step forward

10 if i = 0
11 then return failure
12 else return instantiated values of [x1 , x2 , . . . , xN ]

Select-Value-Arc-Consistency
13 past-values ← instantiated values of [x1 , x2 , . . . , xi–1 ]
14 while D0i is not empty
15 a ← remove one value from D0i

16 repeat
17 removed-value ← false
18 for all j such that i < j ≤ N
19 for all k such that k 6= j and i < k ≤ N
20 for each value b in D0j
21 if there exists c in D0k such that
Consistent(past-values, xi ← a, xj ← b, xk ← c)
22 then continue
23 else remove b from D0j
24 removed-value ← true
25 until removed-value is false

26 if any future domain is empty


27 then for each j > i
28 reset D0j to before value a was selected
29 else return a

30 return null  no consistent value

You might also like