outline
play

Outline 1. Motivation 2. alldifferent Motivation 3. nvalue - PowerPoint PPT Presentation

Topic 3: Constraint Predicates 1 (Version of 13th November 2020) Pierre Flener, Gustav Bj ordal, and Jean-No el Monette Optimisation Group Department of Information Technology Uppsala University Sweden Course 1DL441: Combinatorial


  1. Topic 3: Constraint Predicates 1 (Version of 13th November 2020) Pierre Flener, Gustav Bj¨ ordal, and Jean-No¨ el Monette Optimisation Group Department of Information Technology Uppsala University Sweden Course 1DL441: Combinatorial Optimisation and Constraint Programming, whose part 1 is Course 1DL451: Modelling for Combinatorial Optimisation 1 Many thanks to Guido Tack for feedback

  2. Outline 1. Motivation 2. alldifferent Motivation 3. nvalue alldifferent nvalue 4. global cardinality global cardinality 5. element element 6. bin packing bin packing 7. knapsack knapsack cumulative , 8. cumulative , disjunctive disjunctive circuit , 9. circuit , subcircuit subcircuit 10. lex lesseq lex lesseq regular , 11. regular , table table Modelling 12. Modelling Checklist Checklist COCP/M4CO 3 - 2 -

  3. Outline 1. Motivation 2. alldifferent Motivation 3. nvalue alldifferent nvalue 4. global cardinality global cardinality 5. element element 6. bin packing bin packing 7. knapsack knapsack cumulative , 8. cumulative , disjunctive disjunctive circuit , 9. circuit , subcircuit subcircuit 10. lex lesseq lex lesseq regular , 11. regular , table table Modelling 12. Modelling Checklist Checklist COCP/M4CO 3 - 3 -

  4. Examples Let A be an array of variables: Motivation An alldifferent(A) constraint holds if and only if alldifferent all the elements of A take different values: nvalue global forall(i,j in index_set(A) where i<j) cardinality (A[i] != A[j]) element bin packing A count(A,v) >= c constraint holds if and only if knapsack the count of occurrences in A of v is at least c , cumulative , disjunctive where v and c can be variables: circuit , subcircuit sum(i in index_set(A))(A[i]=v) >= c lex lesseq regular , table Modelling Checklist COCP/M4CO 3 - 4 -

  5. Definition A definition of a constraint predicate is its semantics, stated in MiniZinc in terms of usually simpler constraint predicates. Motivation Examples alldifferent nvalue See some MiniZinc-provided default definitions at slide 4. global cardinality element Definition bin packing Each use of a predicate is decomposed during flattening by knapsack inlining either its MiniZinc-provided default definition or an cumulative , disjunctive overriding backend-provided solver-specific definition. circuit , subcircuit lex lesseq Examples regular , If a predicate γ on arguments X is supported by a solver, table Modelling then its backend provides γ (X)= γ (X) as specific definition. Checklist COCP/M4CO 3 - 5 -

  6. Motivation: + More compact and intuitive models, because more expressive predicates are available: islands of common combinatorial structure are identified in declarative high-level abstractions. Motivation alldifferent + Faster solving, due to better inference and relaxation, nvalue enabled by more global information in the model, global provided the predicate is a built-in of the used solver. cardinality element Enabling constraint-based modelling: bin packing Constraint predicates over any number of variables go knapsack by many names: global-constraint predicates, cumulative , disjunctive combinatorial-constraint predicates, . . . circuit , subcircuit See https://www.minizinc.org/doc-latest/ lex lesseq en/lib-globals.html and the Global Constraint regular , Catalogue at https://sofdem.github.io/gccat . table Modelling Some predicates cannot be reified, say via bool2int . Checklist COCP/M4CO 3 - 6 -

  7. Outline 1. Motivation 2. alldifferent Motivation 3. nvalue alldifferent nvalue 4. global cardinality global cardinality 5. element element 6. bin packing bin packing 7. knapsack knapsack cumulative , 8. cumulative , disjunctive disjunctive circuit , 9. circuit , subcircuit subcircuit 10. lex lesseq lex lesseq regular , 11. regular , table table Modelling 12. Modelling Checklist Checklist COCP/M4CO 3 - 7 -

  8. The alldifferent Predicate Definition (Lauri` ere, 1978) Motivation An alldifferent(A) constraint holds if and only if all the alldifferent elements of the array A of variables take different values. nvalue Its default definition in MiniZinc is a conjunction of n · ( n − 1 ) global 2 cardinality disequality constraints when A has n elements: element bin packing forall(i,j in index_set(A) where i < j)(A[i] != A[j]) knapsack cumulative , Examples disjunctive circuit , n -queens problem: see Topic 1: Introduction. subcircuit Photo problem: see Topic 2: Basic Modelling. lex lesseq regular , table An alldifferent_except(A,S) constraint allows Modelling multiple occurrences of the exception values in the set S . Checklist COCP/M4CO 3 - 8 -

  9. Outline 1. Motivation 2. alldifferent Motivation 3. nvalue alldifferent nvalue 4. global cardinality global cardinality 5. element element 6. bin packing bin packing 7. knapsack knapsack cumulative , 8. cumulative , disjunctive disjunctive circuit , 9. circuit , subcircuit subcircuit 10. lex lesseq lex lesseq regular , 11. regular , table table Modelling 12. Modelling Checklist Checklist COCP/M4CO 3 - 9 -

  10. The nvalue Predicate Definition (Pachet and Roy, 1999) An nvalue(m,A) constraint holds if and only if variable m Motivation takes the number of distinct values taken by the elements of alldifferent the array A of variables, say 1d and with indices 1..n : nvalue global cardinality |{ A[1] , . . . , A[n] }| = m element bin packing The expression nvalue(A) denotes the number of distinct knapsack values taken by the elements of the array A of variables. cumulative , disjunctive If | A | = n , then nvalue(n,A) means alldifferent(A) : circuit , Always use the most specific available constraint predicate! subcircuit lex lesseq Example regular , table Model 2 of the Warehouse Location Problem: Modelling Checklist see Topic 6: Case Studies. COCP/M4CO 3 - 10 -

  11. Outline 1. Motivation 2. alldifferent Motivation 3. nvalue alldifferent nvalue 4. global cardinality global cardinality 5. element element 6. bin packing bin packing 7. knapsack knapsack cumulative , 8. cumulative , disjunctive disjunctive circuit , 9. circuit , subcircuit subcircuit 10. lex lesseq lex lesseq regular , 11. regular , table table Modelling 12. Modelling Checklist Checklist COCP/M4CO 3 - 11 -

  12. The global_cardinality Predicate Definition (R´ egin, 1996) Motivation A global_cardinality(A,V,C) constraint holds iff alldifferent each variable C[j] has the number of elements of the nvalue array A of variables that take value V[j] . Variants exist. global cardinality Its default definition in MiniZinc includes: element bin packing forall(j in index_set(V))(count(A,V[j]) = C[j]) knapsack It means alldifferent(A) if dom ( C[j] ) = { 0 , 1 } for cumulative , disjunctive each j and V = � i dom ( A[i] ) : circuit , Always use the most specific available predicate! subcircuit lex lesseq regular , Example table Model of the Magic Series problem: see Topic 4: Modelling. Modelling Checklist COCP/M4CO 3 - 12 -

  13. A Common Source of Inefficiency in Models Example Motivation The model snippet alldifferent constraint forall(j in index_set(V)) nvalue (count(A,V[j]) = C[j]); global cardinality should be reformulated, due to the shared array A , into: element bin packing constraint global_cardinality(A,V,C); knapsack cumulative , by applying the default definition backwards: disjunctive at worst, it will be applied forwards while flattening; circuit , subcircuit at best, the invoked solver has better inference. lex lesseq regular , table This advice holds for each global-constraint predicate, Modelling and for all (quantified) constraints over shared variables. Checklist COCP/M4CO 3 - 13 -

  14. Outline 1. Motivation 2. alldifferent Motivation 3. nvalue alldifferent nvalue 4. global cardinality global cardinality 5. element element 6. bin packing bin packing 7. knapsack knapsack cumulative , 8. cumulative , disjunctive disjunctive circuit , 9. circuit , subcircuit subcircuit 10. lex lesseq lex lesseq regular , 11. regular , table table Modelling 12. Modelling Checklist Checklist COCP/M4CO 3 - 14 -

  15. The element Predicate Definition (Van Hentenryck and Carillon, 1988) Motivation alldifferent An element(i,A,e) constraint, where: nvalue A is an array of variables, global cardinality i is an integer variable, and element e is a variable, bin packing holds if and only if A[i] = e . knapsack cumulative , disjunctive circuit , subcircuit For better model readability, the element predicate should lex lesseq not be used, as the functional form A[ φ ] is allowed, even regular , if φ is an integer expression involving at least one variable. table Modelling Checklist COCP/M4CO 3 - 15 -

Recommend


More recommend