380 likes | 503 Views
Relaxation and Hybrid constraint processing. Different relaxation techniques Some popular hybrid techniques. Relaxation. Node consistency Forward check Lookahead check AC1 AC3 Path-consistency. Running example. The 4-houses puzzle:.
E N D
Relaxation and Hybrid constraint processing Different relaxation techniques Some popular hybrid techniques
Relaxation Node consistency Forward check Lookahead check AC1 AC3 Path-consistency
Running example • The 4-houses puzzle: • 4 families A, B, C and D live next to each other in houses numbered 1, 2, 3 and 4. • Dlives in a house with lower number thanB, • Blives next toAin a house with higher number, • There is at least one house betweenBandC, • Ddoes not live in the house with number2, • Cdoes not live in the house with number4. • Which family lives in which house ?
Representation: • The variables: A, B, C and D • The domains: dA = dB = dC = dD = { 1, 2, 3, 4} • Constraints: • unary: • c(C) =C 4 • c(D) =D 2 • binary: • c(A,B) =B=A + 1 • c(A,C) =A C • c(B,D) =DB • c(A,D) = A D • c(B,C) = |B-C| 1 • c(C,D) = C D
dC = { 1, 2, 3} dD = { 1, 3, 4} Node-consistency: • Or: 1-consistency • (only 1 variable is involved) • Unary constraints are eliminated through domain- reductions: • c(C) =C 4 • c(D) =D 2
{ 1, 2, 3, 4} { 1, 2, 3, 4} B=A + 1 A B A D A C DB |B-C| 1 C D C D { 1, 2, 3} { 1, 3, 4} The constraint network:
Weak relaxation Forward Check Lookahead Check
{ 1, 2, 3, 4} {2} B=A + 1 A B A D A C DB |B-C| 1 C D C D { 1, 2, 3} { 1, 3, 4} Forward Check: • Assume we fix the value for 1 variable zi: zi = a • Forward Check(zi) = • activate each constraint c(zi, zj) or c(zj, zi) once to remove the inconsistent values for zi = a • Our example: assume A = 2 :
{ 1, 2, 3, 4} {2} B=A + 1 A B A D A C DB |B-C| 1 C D C D { 1, 2, 3} { 1, 3, 4} Forward check: weak consistency • Requires that 1 variable already obtained a value • suggests use in combination with backtracking • Does not produce a consistent state • not all relaxation is done
Look ahead check A stronger (weak) relaxation method
{ 1, 2, 3, 4} { 1, 2, 3, 4} B=A + 1 A B A D A C DB |B-C| 1 C D C D { 1, 2, 3} { 1, 3, 4} Look ahead Check: • Look Ahead Check = • activate each constraint c(zi, zj) exactly once to remove the inconsistent values from the domains Di and Dj. • Our example:
{ 2, 3, 4} { 1, 2, 3} B=A + 1 A B A D A C DB |B-C| 1 C D C D { 1, 2, 3} { 1, 3, 4} Example continued: • The 3 other constraints:
{ 3, 4} { 1, 2, 3} B=A + 1 A B A D A C DB |B-C| 1 C D C D { 1, 2} { 1, 3} Look ahead: final results: • Still does not produce a consistent state • not all relaxation is done • Result may depend on the order in which constraints are dealt with. • Removing some values first may allow to find others inconsistent
Arc consistency techniques Techniques that reduce domains to a state that is consistent for each constraint (or arc). Also called: 2-consistency techniques
AC 1 (Mackworth) AC1: Repeat Deletion_occurred:= false ; Look ahead check; If some value was removed from some domain then Deletion_occurred:= true Until(notDeletion_occurred) • Forces Look ahead to reach a consistent state • by reactivating Look ahead until consistency
{ 3, 4} { 1, 2, 3, 4} { 1, 2, 3, 4} { 1, 2, 3} B=A + 1 B=A + 1 A B A B A D A D A C A C DB DB |B-C| 1 |B-C| 1 C D C D C D C D { 1, 2} { 1, 2, 3} { 1, 3} { 1, 3, 4} The example (1): • First pass (== Look ahead check): • Deletion_occurred:= true
{ 3, 4} { 3, 4} { 1, 2, 3} { 2, 3} B=A + 1 B=A + 1 A A B B A D A D A C A C DB DB |B-C| 1 |B-C| 1 C C D D C D C D { 1, 2} { 1, 2} { 1, 3} { 1, 3} The example (2): • Second pass: • Deletion_occurred:= true
{ 3, 4} { 2, 3} B=A + 1 A B A D A C DB |B-C| 1 C D C D { 1, 2} { 1, 3} The example (3): • Third pass: • Deletion_occurred:= false • Result: A (2 or 3) , B (3 or 4), C (1 or 2), D (1 or 3) • Consistent, but NOT REALLY A SOLUTION !!
Whilenot empty(QUEUE) DO If some value was removed from Dx (or Dy) thenadd all other constraints involving x (or y) to QUEUE; AC-3 (Mackworth)More efficient arc-consistency: AC3: QUEUE:= {all constraints in the problem} Remove c(x,y) from QUEUE; Remove all inconsistent values from domains Dx and Dy with respect to c(x,y); End-While
{ 1, 2, 3, 4} { 1, 2, 3, 4} B=A + 1 A B A D A C DB |B-C| 1 All already inQUEUE ! C D C D { 1, 2, 3} { 1, 3, 4} The example (1): • QUEUE = {c(A,B), c(A,C), c(A,D), c(B,C), c(B,D), c(C,D)}: • To be added: c(A,C), c(A,D), c(B,C), c(B,D) • QUEUE = {c(A,C), c(A,D), c(B,C), c(B,D), c(C,D)}
{ 2, 3, 4} { 1, 2, 3} B=A + 1 A B A D A C DB |B-C| 1 C D C D { 1, 2, 3} { 1, 3, 4} The example (2): • QUEUE = {c(A,C), c(A,D), c(B,C), c(B,D), c(C,D)}: • QUEUE = {c(B,C), c(B,D), c(C,D)}
{ 2, 3, 4} { 1, 2, 3} B=A + 1 A B A D A C DB |B-C| 1 C D C D { 1, 2, 3} { 1, 3, 4} The example (3): • QUEUE = {c(B,C), c(B,D), c(C,D)}: • To be added: c(A,B), c(A,C), c(B,D), c(C,D) • QUEUE = {c(B,D), c(C,D), c(A,B), c(A,C)}
{ 3, 4} { 1, 2, 3} B=A + 1 A B A D A C DB |B-C| 1 C D C D { 1, 2} { 1, 3, 4} The example (4): • QUEUE = {c(B,D), c(C,D), c(A,B), c(A,C)}: • To be added: c(A,D), c(C,D) • QUEUE = {c(C,D), c(A,B), c(A,C), c(A,D)}
{ 3, 4} { 1, 2, 3} B=A + 1 A B A D A C DB |B-C| 1 C D C D { 1, 2} { 1, 3} The example (5): • QUEUE = {c(C,D), c(A,B), c(A,C), c(A,D)}: • To be added: c(A,C), c(A,D) • QUEUE = {c(A,C), c(A,D)}
{ 3, 4} { 2, 3} B=A + 1 A B A D A C DB |B-C| 1 C D C D { 1, 2} { 1, 3} The example (6): • QUEUE = {c(A,C), c(A,D)}: • QUEUE = empty STOP !
Comparison: • Same result: full arc-consistency: • A = {2,3}, B = {3,4}, C= {1,2}, D = {1,3} • Efficiency: • AC1: • 3 times 6 checks = 18 • AC3: • 9 constraint checks
{ 1, 2, 3, 4} Example: { 1, 2, 3, 4} B=A + 1 A B A D A C DB |B-C| 1 C D C D { 1, 2, 3} { 1, 3, 4} K-consistency: • 1-consistency (node-consistency): • unary constraints (on 1 variable) are consistent • 2-consistency (arc-consistency): • binary constraints (on 2 variables) are consistent • 3-consistency: • all constraints involving 3 variables are consistent • A value remains in the domain if there are consistent values in the domains of the 2 other variables (for all connecting constraints)
Practicality of k-consistency: • Checking k-consistency for k 2 is very hard to do efficiently !! • Example: 4-consistency for the 4-houses puzzle is equivalent to finding solutions to the original problem.
Hybrid constraint processing Combine the power of exhaustive (backtrack) search with (relaxation) pruning
Forward checking Backtracking combined with Forward Check
Forward checking: Forward Checking: ExecuteStandard Backtracking BUT After each assignment of a value to a variable ziDO Forward Check(zi)
A 1 3 2 {3} {2} {1} {1,2,3,4} {1,2,3,4} {1,2,3,4} B=A+1 B=A+1 A A A B B B AC AC B=A+1 AD AD AC AD C C C D D D {1,3,4} {1,3,4} {1,3,4} {1,2,3} {1,2,3} {1,2,3} B B B 3 4 2 {2} {3} A B |B-C|1 D B C D {3} {1} {2} {4} {1,3,4} {1,3} A A B B |B-C|1 |B-C|1 C C 1 2 D B D B C C D D 1 {1,4} {3,4} {2,3} {1,2} {3} {3} {4} {4} {4} {3} A B A A B B CD CD CD D C {1} {1} D D C C {2} {1} {1} {1} Forward checking at work fail fail fail success
Lookahead checking Backtracking combined with Look ahead check
After each assignment of a value to some variable DO Lookahead checking: Lookahead Checking: Look Ahead Check ; ExecuteStandard Backtracking BUT Look Ahead Check
{1,2,3,4} {1,2,3,4} B=A+1 A B AC AD D B |B-C|1 {3} {3,4} C CD D B=A+1 {1,2,3} {1,3,4} A B AC AD D B A |B-C|1 1 3 C CD D {1,2} {1,3} {1} {3,4} 2 B=A+1 B A B 4 C D {3} {4} A B |B-C|1 {1,3} {1,2} D B C CD D {2} {1} C {2} {3,4} 2 B=A+1 A B AC {3} {4} AD D B A B |B-C|1 C CD D {1,2} {1,3} C CD D {2} {1} Lookahead checking at work fail fail success
Which is best? • Forward checking: • does less consistency checking • has more branching • closer to backtracking • Lookahead checking: • spends more work on consistency • tries less alternative values • Usually: forward checking is best trade-off • For VERY strongly constrainted problems: • Lookahead checking is needed to prune more
Applications: • All combinatorial search problems • Scheduling problems: • Ex.: reschedule the trains when some railway problem has occurred • Rostering problems: • Ex.: compute work-shifts, given various expertise constraints and personal preferences • Production planning: • Ex.: schedule the optimal workfloor traversal • Loading problems: • Ex.: optimize truck-space given various types of loads
4*X - 3*Y Z + 2 YES ! X3 - 3*Y Z2 + 2 NO ! Alternative techniques • Linear programming • numerical techniques for solving systems of linear equations (and inequalities) + optimization problems • Ex.: simplex algorithm • Works VERY well for ‘linear’ constraints • Works, but not VERY well, for discrete problems • In such cases: Constraint Processing is a better option • Also: for constraint problems on non-numerical data !