Presentation is loading. Please wait.

Presentation is loading. Please wait.

Constraints and Search

Similar presentations


Presentation on theme: "Constraints and Search"— Presentation transcript:

1 Constraints and Search
Logic & AR Summer School, 2002 Constraints and Search Toby Walsh Cork Constraint Computation Centre (4C)

2 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

3 Constraint solvers Two main approaches Other more exotic possibilities
Systematic, tree search algorithms Local search or repair based procedures Other more exotic possibilities Hybrid algorithms Quantum algorithms

4 Systematic solvers Tree search Number of choices
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, …

5 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

6 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

7 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

8 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

9 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

10 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

11 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

12 (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

13 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

14 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.

15 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

16 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

17 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

18 Properties Partial ordering Defined relations reflexive A  A
transitive A  B & B  C implies A  C Defined relations tighter A > B iff A  B & not B  A incomparable B iff neither A  B nor B  A

19 Comparison of consistency techniques
Exercise for the reader, prove the following identities! Strong PC > SAC > PIC > RPC > AC > BC NIC > PIC SAC Strong PC NB gaps can reduce search exponentially!

20 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

21 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

22 GAC on alldifferent alldifferent(X1,X2,X3) {1,2} {2,3} {2,3}
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 X1 {1,2} {2,3} {2,3} X2 X3

23 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”

24 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).

25 GAC-Schema: instantiation
List of allowed tuples List of forbidden tuples Predicates Any OR algorithm Solver re-entrace

26 GAC-Schema Idea: tuple = solution of the constraint support = 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

27 Example X(C)={x1,x2,x3} D(xi)={a,b}
T(C)={(a,a,a),(a,b,b),(b,b,a),(b,b,b)}

28 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.

29 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

30 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.

31 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 ...

32 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)

33 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 6 Constraints: - 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 wood For all the bins there is either no plastic or at least 2 plastic Given 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?

34 Table Constraint: results
#bk time standard model 1,361, Table Constraint 12,

35 Semantics of a constraint
Speed-up the search for a support

36 Exploiting constraint semantics
Speed-up the search for a support x < y, D(x)=[ ], D(y)=[ ] support for (x,9000) immediate any value greater than 9000 in D(y)

37 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

38 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 modified no possible pruning of D(y) while min(x) is not modified

39 Regin’s alldiff algorithm
Construct the value graph

40 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}

41 Alldiff constraint Construct a flow network

42 Flow network 1 2 3 4 5 6 7 Default orientation x1 x2 x3 x4 x5 x6 s

43 Flow network 1 2 3 4 5 6 7 Default orientation x1 x2 x3 x4 x5 x6 t s

44 Flow network 1 2 3 4 5 6 7 Default orientation x1 x2 x3 x4 x5 x6 t s

45 Flow network (0,1) 1 2 3 4 5 6 7 Default orientation x1 x2 x3 x4 x5 x6
(1,1) t s (6,6)

46 Alldiff constraint Construct a flow network Compute a feasible flow

47 Flow network (0,1) 1 2 3 4 5 6 7 Default orientation x1 x2 x3 x4 x5 x6
(1,1) t s (6,6)

48 A feasible flow (0,1) 1 2 3 4 5 6 7 Default orientation x1 x2 x3 x4 x5
(1,1) t s (6,6)

49 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)

50 A feasible flow (0,1) 1 2 3 4 5 6 7 Default orientation x1 x2 x3 x4 x5
(1,1) t s (6,6)

51 Residual graph 1 2 3 4 5 6 7 x1 x2 x3 x4 x5 x6 s orientation

52 Alldiff constraint Construct a flow network Compute a feasible flow
Construct the residual graph Compute the strongly connected components Strongly connected component = maximal subgraph such that if directed path u to v, also from v to u

53 Alldiff constraint Construct a flow network Compute a feasible flow
Construct the residual graph Compute the strongly connected components Strongly connected component = maximal subgraph such that if directed path u to v, also from v to u Exists O(N) algorithm due to Tarjan (1972) = O(n+d)

54 Residual graph 1 2 3 4 5 6 7 x1 x2 x3 x4 x5 x6 s orientation

55 Residual graph 1 2 3 4 5 6 7 x1 x2 x3 x4 x5 x6 s orientation

56 Alldiff constraint Construct a flow network Compute a feasible flow
Construct the residual graph Compute the strongly connected components Remove arcs of flow value 0 (i.e. black arcs) with ends belonging to two different components

57 Residual graph 1 2 3 4 5 6 7 x1 x2 x3 x4 x5 x6 s orientation

58 Residual graph 1 2 3 4 5 6 7 x1 x2 x3 x4 x5 x6 s orientation

59 GAC for all-different Theorem
An arc is deleted from residual graph iff the associated value is not GAC

60 Residual graph 1 2 3 4 5 6 7 x1 x2 x3 x4 x5 x6 s orientation

61 GAC subproblem The value graph: 1 x1 2 D(x1)={1,2} x2 3 D(x2)={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)={4} D(x5)={5,6} D(x6)={5,6,7}

62 Before! The value graph: 1 x1 2 D(x1)={1,2} x2 3 D(x2)={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}

63 Maintaining a local consistency property
Tree search Assign value to variable Enforce some level of local consistency Remove values/add new constraints If any future variable has no values, backtrack else repeat Two popular algorithms Maintaining arc-consistency (MAC) Forward checking (very restricted form of AC maintained)

64 Forward checking Binary constraints (FC) Non-binary constraints
Make constraints involving current variable and one future variable arc-consistent No need to look at any other constraints! Non-binary constraints Several choices as to how to do forward checking

65 Forward checking with non-binary constraints
nFC0 makes AC only those k-ary constraints with k-1 variables set nFC1 applies one pass of AC on constraints and projections involving current var and one future var nFC2 applies one pass of GAC on constraints involving current var and at least one future var nFC3 enforces GAC on this set nFC4 applies one pass of GAC on constraints involving at least one past and one future var nFC5 enforces GAC on this set

66 Summary Constraint solving
Constraint propagation central part of many algorithms Efficient algorithms exist for enforcing local consistency


Download ppt "Constraints and Search"

Similar presentations


Ads by Google