NPTEL AI CSP 2025 Week 04 Algorithms
NPTEL AI CSP 2025 Week 04 Algorithms
Week 4 – Algorithms
Prepared by S. Baskaran
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
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 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
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
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
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