660 likes | 672 Views
This article explores constraint satisfaction problems and constraint solvers, including systematic and local search algorithms. It also discusses different types of constraint propagation and various levels of consistency.
E N D
Logic & AR Summer School, 2002 Constraints and Search Toby WalshCork Constraint Computation Centre (4C) tw@4c.ucc.ie
Constraint satisfaction • Constraint satisfaction problem (CSP) is a triple <V,D,C> where: • V is set of variables • Each X in V has set of values, D_X • Usually assume finite domain • {true,false}, {red,blue,green}, [0,10], … • C is set of constraints Goal: find assignment of values to variables to satisfy all the constraints
Constraint solvers • Two main approaches • Systematic, tree search algorithms • Local search or repair based procedures • Other more exotic possibilities • Hybrid algorithms • Quantum algorithms
Systematic solvers • Tree search • Assign value to variable • Deduce values that must be removed from future/unassigned variables • Constraint propagation • If future variable has no values, backtrack else repeat • Number of choices • Variable to assign next, value to assign Some important refinements like nogood learning, non-chronological backtracking, …
Inference/constraint propagation • Key to much of the success of CP • Systematic solvers do some inference, and some search • Possible to solve problems by inference alone (but this may require exponential space) • Or by search alone (but this may require exponential time) • Therefore combine inference & search to get best of both worlds • Inference is usually enforcing some local consistency
Local consistency • Arc-consistency (AC) • A binary constraint r(X1,X2) is AC iff for every value for X1, there is a consistent value (often called support) for X2 and vice versa E.g. With 0/1 domains and the constraint X1 =/= X2 Value 0 for X1 is supported by value 1 for X2 Value 1 for X1 is supported by value 0 for X2 … • A problem is AC iff every constraint is AC
Enforcing arc-consistency • Remove all values that are not AC (i.e. have no support) • May remove support from other values (often queue based algorithm) • Best AC algorithms (AC7, AC-2000) run in O(ed^2) • Optimal if we know nothing else about the constraints
Enforcing arc-consistency • X2 \= X3 is AC • X1 \= X2 is not AC • X2=1 has no support so can this value can be pruned • X2 \= X3 is now not AC • No support for X3=2 • This value can also be pruned Problem is now AC {1} X1 \= {1,2} {2,3} \= X2 X3
Local consistency • Local consistency =/= global consistency • A problem can be AC but have no (global) solution • E.g. With 0/1 domains X1 =/= X2, X2 =/= X3, X1 =/= X3 Each constraint is AC but the problem is unsatisfiable Should not be surprising. AC was ony polynomial to enforce but global consistency considers the exponential set of possible solutions
Properties of AC • Unique maximal AC subproblem • Or problem is unsatisfiable • Enforcing AC can process constraints in any order • But order does affect (average-case) efficiency
Other types of constraint propagation • (i,j)-consistency [due to Freuder, JACM 85] • Non-empty domains • Any consistent instantiation for i variables can be extended to j others • Describes many different consistency techniques
(i,j)-consistency • Generalization of arc-consistency • AC = (1,1)-consistency • Path-consistency = (2,1)-consistency • Strong path-consistency = AC + PC • Path inverse consistency = (1,2)-consistency
Enforcing (i,j)-consistency • problem is (1,1)-consistent (AC) • BUT is not (2,1)-consistent (PC) • X1=2, X2=3 cannot be extended to X3 • Need to add constraints: not(X1=2 & X2=3) not(X1=2 & X3=3) • Nor is it (1,2)-consistent (PIC) • X1=2 cannot be extended to X2 & X3 (so needs to be deleted) {1,2} X1 \= \= {2,3} {2,3} \= X2 X3
Other types of constraint propagation • Singleton arc-consistency (SAC) • Problem resulting from instantiating any variable can be made AC • Restricted path-consistency (RPC) • AC + if a value has just one support then any third variable has a consistent value NB one of the key features is that we only need prune domains to enforce SAC or RPC. Algorithms can therefore be space efficient.
Other types of consistency • problem is (1,1)-consistent (AC) • BUT is not singleton AC (SAC) • Problem with X1=2 cannot be made AC (so value should be deleted) • Nor is it restricted PC (RPC) • X1=2 has only one support in X2 (the value 3) but X3 then has no consistent values • X1=2 can therefore be deleted {1,2} X1 \= \= {2,3} {2,3} \= X2 X3
Other types of constraint propagation • Neighbourhood inverse consistency (NIC) • For all vals for a var, there are consistent vals for all vars in the immediate neighbourhood • Exponential in the size of the neighbourhood! • Bounds consistency (BC) • With ordered domains • Enforce AC just on max/min elements • On some constraints (eg linear inequalities), BC=AC
Comparing local consistencies • Formal definition of tightness introduced by Debruyne & Bessiere [IJCAI-97] • A-consistency is tighter than B-consistency iff If a problem is A-consistent -> it is B-consistent We write A >= B
Properties • Partial ordering • reflexive A A • transitive A B & B C implies A C • Defined relations • tighter A > B iff A B & not B A • incomparable A @ B iff neither A B nor B A
Comparison of consistency techniques • Exercise for the reader, prove the following identities! Strong PC > SAC > PIC > RPC > AC > BC NIC > PIC NIC @ SAC NIC @ Strong PC NB gaps can reduce search exponentially!
Which to choose? • AC is often chosen • Space efficient Just prune domains (cf PC) • Time efficient • But in some domains, more inference pays • SAC in scheduling • PC for temporal reasoning • …
Non-binary constraint propagation • Most popular is generalized arc-consistency (GAC) • A non-binary constraint is GAC iff for every value for a variable there are consistent values for all other variables in the constraint • We can again prune values that are not supported • GAC = AC on binary constraints
GAC on alldifferent • alldifferent(X1,X2,X3) • Constraint is not GAC • X1=2 cannot be extended • X2 would have to be 3 • No value left then for X3 • X1={1} is GAC {1,2} X1 {2,3} {2,3} X2 X3
Enforcing GAC • Enforcing GAC is expensive in general • GAC schema is O(d^k) On k-ary constraint on vars with domains of size d • Trick is to exploit semantics of constraints • Regin’s all-different algorithm • Achieves GAC in just O(k^2 d^2) On k-ary all different constraint with domains of size d Based on finding matching in “value graph”
GAC-Schema • A generic framework for achieving AC for any kind of constraint (can be non binary).Bessiere and Regin, IJCAI’97 • You just have to say how to compute a solution. • Works incrementality (notion of support).
GAC-Schema: instantiation • List of allowed tuples • List of forbidden tuples • Predicates • Any OR algorithm • Solver re-entrace
GAC-Schema • Idea: tuple = solution of the constraintsupport = valid tuple- while the tuple is valid: do nothing - if the tuple is no longer valid, then search for a new support for the values it contains • a solution (support) can be computed by any algorithm
Example • X(C)={x1,x2,x3} D(xi)={a,b} • T(C)={(a,a,a),(a,b,b),(b,b,a),(b,b,b)}
Example • X(C)={x1,x2,x3} D(xi)={a,b} • T(C)={(a,a,a),(a,b,b),(b,b,a),(b,b,b)} • Support for (x1,a): (a,a,a) is computed and (a,a,a) is added to S(x2,a) and S(x3,a), (x1,a) in (a,a,a) is marked as supported.
Example • X(C)={x1,x2,x3} D(xi)={a,b} • T(C)={(a,a,a),(a,b,b),(b,b,a),(b,b,b)} • Support for (x1,a): (a,a,a) is computed and (a,a,a) is added to S(x2,a) and S(x3,a), (x1,a) in (a,a,a) is marked as supported. • Support for (x2,a): (a,a,a) is in S(x2,a) it is valid, therefore it is a support. (Multidirectionnality). No need to compute a solution
Example • X(C)={x1,x2,x3} D(xi)={a,b} • T(C)={(a,a,a),(a,b,b),(b,b,a),(b,b,b)} • Support for (x1,a): (a,a,a) is computed and (a,a,a) is added to S(x2,a) and S(x3,a), (x1,a) in (a,a,a) is marked as supported. • Value a is removed from x1, then all the tuples in S(x1,a) are no longer valid: (a,a,a) for instance. The validity of the values supported by this tuple must be reconsidered.
Example • X(C)={x1,x2,x3} D(xi)={a,b} • T(C)={(a,a,a),(a,b,b),(b,b,a),(b,b,b)} • Support for (x1,a): (a,a,a) is computed and (a,a,a) is added to S(x2,a) and S(x3,a), (x1,a) in (a,a,a) is marked as supported. • Support for (x1,b): (b,b,a) is computed, and updated ...
GAC-Schema: complexity • CC complexity to check consistency • seek in table, call to OR algorithm • n variables, d values: • for each value: CC • for all values: O(ndCC)
Table Constraint: An example • Configuration problem:5 types of components: {glass, plastic, steel, wood, copper}3 types of bins: {red, blue, green} whose capacity is red 5, blue 5, green 6Constraints:- red can contain glass, cooper, wood- blue can contain glass, steel, cooper- green can contain plastic, copper, wood- wood require plastic; glass exclusive copper- red contains at most 1 of wood- green contains at most 2 of woodFor all the bins there is either no plastic or at least 2 plasticGiven an initial supply of 12 of glass, 10 of plastic, 8 of steel, 12 of wood and 8 of copper; what is the minimum total number of bins?
Table Constraint: results #bk timestandard model 1,361,709 430 Table Constraint 12,659 9.7
Semantics of a constraint • Speed-up the search for a support
Exploiting constraint semantics • Speed-up the search for a support • x < y, D(x)=[0..10000], D(y)=[0..10000] • support for (x,9000) • immediate any value greater than 9000 in D(y)
Semantics of a constraint • Design of an ad-hoc filtering algorithm:x < y : (a) max(x) = max(y) -1(b) min(y) = min(x) +1
Exploiting semantics • Design of an ad-hoc filtering algorithm:x < y : (a) max(x) = max(y) -1(b) min(y) = min(x) +1 • Triggering of the filtering algorithm:no possible pruning of D(x) while max(y) is not modifiedno possible pruning of D(y) while min(x) is not modified
Regin’s alldiff algorithm • Construct the value graph
The value graph: 1 2 3 4 5 6 7 x1 x2 x3 x4 x5 x6 D(x1)={1,2} D(x2)={2,3} D(x3)={1,3} D(x4)={3,4} D(x5)={2,4,5,6} D(x6)={5,6,7}
Alldiff constraint • Construct a flow network
Flow network 1 2 3 4 5 6 7 Default orientation x1 x2 x3 x4 x5 x6 s
Flow network 1 2 3 4 5 6 7 Default orientation x1 x2 x3 x4 x5 x6 t s
Flow network 1 2 3 4 5 6 7 Default orientation x1 x2 x3 x4 x5 x6 t s
Flow network (0,1) 1 2 3 4 5 6 7 Default orientation x1 x2 x3 x4 x5 x6 (0,1) (1,1) t s (6,6)
Alldiff constraint • Construct a flow network • Compute a feasible flow
Flow network (0,1) 1 2 3 4 5 6 7 Default orientation x1 x2 x3 x4 x5 x6 (0,1) (1,1) t s (6,6)
A feasible flow (0,1) 1 2 3 4 5 6 7 Default orientation x1 x2 x3 x4 x5 x6 (0,1) (1,1) t s (6,6)
Alldiff constraint • Construct a flow network • Compute a feasible flow • Construct the residual graph • Reverse direction of arcs on feasible flow (that is, of red arcs)
A feasible flow (0,1) 1 2 3 4 5 6 7 Default orientation x1 x2 x3 x4 x5 x6 (0,1) (1,1) t s (6,6)