topic 12 cp and gecode
play

Topic 12: CP and Gecode (Version of 13th November 2020) Pierre - PowerPoint PPT Presentation

Topic 12: CP and Gecode (Version of 13th November 2020) Pierre Flener Optimisation Group Department of Information Technology Uppsala University Sweden Course 1DL441: Combinatorial Optimisation and Constraint Programming, whose part 1 is


  1. Topic 12: CP and Gecode (Version of 13th November 2020) Pierre Flener 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

  2. Outline 1. Constraint Programming (CP) 2. MiniZinc to Gecode Constraint Program- 3. linear ming (CP) MiniZinc to 4. element Gecode 5. MiniModel linear element 6. distinct , nvalues , count MiniModel 7. binpacking distinct , nvalues , count 8. cumulative , unary binpacking 9. circuit , path cumulative , unary 10. extensional circuit , path 11. channel extensional 12. precede channel precede COCP/M4CO 12 - 2 -

  3. Outline 1. Constraint Programming (CP) 2. MiniZinc to Gecode Constraint Program- 3. linear ming (CP) MiniZinc to 4. element Gecode 5. MiniModel linear element 6. distinct , nvalues , count MiniModel 7. binpacking distinct , nvalues , count 8. cumulative , unary binpacking 9. circuit , path cumulative , unary 10. extensional circuit , path 11. channel extensional 12. precede channel precede COCP/M4CO 12 - 3 -

  4. Reminder from Topic 1: Introduction A solving technology offers methods and tools for: Constraint Program- what: Modelling constraint problems in declarative language. ming (CP) MiniZinc to and / or Gecode linear how: Solving constraint problems intelligently: element MiniModel • Search: Explore the space of candidate solutions. distinct , nvalues , count • Inference: Reduce the space of candidate solutions. binpacking • Relaxation: Exploit solutions to easier problems. cumulative , unary circuit , A solver is a software that takes a model & data as path input and tries to solve the modelled problem instance. extensional channel precede COCP/M4CO 12 - 4 -

  5. Constraint Programming Technology Constraint programming (CP) offers methods and tools for: what: Modelling constraint problems in a high-level language. Constraint Program- ming (CP) and MiniZinc to Gecode how: Solving constraint problems intelligently by: linear • either default systematic search upon pushing a button element MiniModel • or systematic search guided by a user-given strategy distinct , • or local search guided by a user-given strategy nvalues , count with lots of inference, called propagation in the case of binpacking systematic search, but yet little relaxation. cumulative , unary Slogan of CP: circuit , path extensional Constraint Program = Model [ + Search ] channel precede COCP/M4CO 12 - 5 -

  6. CP Solving = Inference + Search A CP solver conducts search interleaved with inference: Constraint Program- ming (CP) MiniZinc to Gecode linear element MiniModel distinct , nvalues , count binpacking cumulative , unary circuit , path extensional Each constraint has an inference algorithm. channel precede COCP/M4CO 12 - 6 -

  7. Inference for One Constraint: Propagator Example Consider the constraint C ONNECTED ([ C 1 , . . . , C n ]) , which Constraint Program- imposes max one stretch per colour among the n variables. ming (CP) MiniZinc to Gecode From the following current partial valuation for n = 6: linear element C 3 C 6 MiniModel distinct , a propagator (under systematic search) of the C ONNECTED nvalues , predicate can infer that C 3 = red and C 6 �∈ { red , black } : count binpacking C 6 cumulative , unary circuit , ☞ A propagator deletes the impossible values path from the current domains of the variables, extensional and thereby accelerates otherwise blind search. channel precede COCP/M4CO 12 - 7 -

  8. Roadmap For CP by systematic search: Topic 13: Consistency ☞ A consistency is the Constraint targeted characterisation of the domain values Program- ming (CP) kept by a propagator (a musician) for a constraint, MiniZinc to but correctness of the solver (the whole orchestra) Gecode must not depend on enforcing it. linear Topic 14: Propagation ☞ We define the really needed element post-conditions of each propagator, and we use them MiniModel distinct , to design a Propagate algorithm (for the conductor) nvalues , that decides which propagator to run when. count binpacking Topic 15: Search ☞ We design an Explore algorithm cumulative , (for the conductor) that calls Propagate and a brancher. unary Topic 16: Propagators ☞ We design a few propagators: circuit , path linear , element , distinct , extensional , . . . extensional For CP by local search: channel Topic 17: Constraint-Based Local Search precede COCP/M4CO 12 - 8 -

  9. Outline 1. Constraint Programming (CP) 2. MiniZinc to Gecode Constraint Program- 3. linear ming (CP) MiniZinc to 4. element Gecode 5. MiniModel linear element 6. distinct , nvalues , count MiniModel 7. binpacking distinct , nvalues , count 8. cumulative , unary binpacking 9. circuit , path cumulative , unary 10. extensional circuit , path 11. channel extensional 12. precede channel precede COCP/M4CO 12 - 9 -

  10. Mind the Gap With Gecode, which is a C++ library, one writes Constraint an imperative program that states (or: posts) — via Program- any combination of sequential, conditional, iterative, ming (CP) MiniZinc to and recursive composition — the declarative Gecode constraints, which are then given to the solver via linear propagators enforcing chosen consistencies. element MiniModel Gecode indexes from 0, and MiniZinc indexes from 1. distinct , nvalues , count Gecode does not automatically coerce Booleans (truth binpacking is 1, and falsity is 0) into integers, and MiniZinc does. cumulative , unary circuit , For lighter syntax, we here omit the first argument (a path space reference, often *this ) from Gecode snippets. extensional channel precede COCP/M4CO 12 - 10 -

  11. Reification A MiniZinc reified constraint, such as r <-> x < y , where r is a variable of type bool , is modelled in Gecode Constraint by appending the reifying variable r , of type Reify , as an Program- ming (CP) additional argument to the used constraint predicate: MiniZinc to Gecode rel(x,IRT LE,y,r) linear element Careful: Not all constraints are reifiable, as in all CP solvers! MiniModel We will use the following definition and notation: distinct , nvalues , count Definition binpacking The reification of a constraint γ ( . . . ) is cumulative , unary the constraint r ⇔ γ ( . . . ) , where r is a “Boolean” variable, circuit , with the truth of γ ( . . . ) represented by 1 and its falsity by 0. path extensional Propagation may be poor: ☞ see Topic 16: Propagators. channel precede COCP/M4CO 12 - 11 -

  12. Inference: Propagator and Consistency A MiniZinc inference annotation (recall Topic 8: Inference & Search in CP & LCG) to a constraint, bounds or domain , Constraint Program- is modelled in Gecode by appending the consistency as an ming (CP) additional argument to the used constraint predicate. MiniZinc to Gecode The options for integer decision variables are value linear consistency ( IPL VAL ), bounds consistency ( IPL BND ), element MiniModel and domain consistency ( IPL DOM ), consistency being distinct , called integer propagation level (IPL) in Gecode, one of nvalues , count them being the default ( IPL DEF ) if no consistency is given. binpacking For example: cumulative , unary circuit , distinct(X,IPL DOM) path extensional ☞ For details, see Topic 13: Consistency. channel precede COCP/M4CO 12 - 12 -

  13. Search: Selection Strategies Constraint A MiniZinc search annotation (recall Topic 8: Inference & Program- ming (CP) Search in CP & LCG) to an objective, such as MiniZinc to int_search(X,first_fail,indomain_min) , Gecode is modelled in Gecode by specifying or writing a brancher. linear element MiniModel distinct , For example: nvalues , count binpacking branch(X,INT VAR SIZE MIN(),INT VAL MIN()) cumulative , unary ☞ For details, see Topic 15: Search. circuit , path extensional channel precede COCP/M4CO 12 - 13 -

  14. Outline 1. Constraint Programming (CP) 2. MiniZinc to Gecode Constraint Program- 3. linear ming (CP) MiniZinc to 4. element Gecode 5. MiniModel linear element 6. distinct , nvalues , count MiniModel 7. binpacking distinct , nvalues , count 8. cumulative , unary binpacking 9. circuit , path cumulative , unary 10. extensional circuit , path 11. channel extensional 12. precede channel precede COCP/M4CO 12 - 14 -

  15. The linear Predicate A MiniZinc linear constraint, such as the linear equality constraint sum(i in 1..n)(A[i]*X[i]) = d , can be Constraint modelled in Gecode by using its reifiable linear predicate: Program- ming (CP) Definition MiniZinc to Gecode A linear ([ a 1 , . . . , a n ] , [ x 1 , . . . , x n ] , R , d ) constraint, with linear [ a 1 , . . . , a n ] a sequence of non-zero integer constants, element [ x 1 , . . . , x n ] a sequence of integer variables, MiniModel distinct , R in { <, ≤ , = , � = , ≥ , > } , and nvalues , count d an integer constant, binpacking � n � cumulative , � unary holds iff the linear relation a i · x i R d holds. circuit , i = 1 � n path � extensional � Also, linear ([ x 1 , . . . , x n ] , R , d ) holds iff x i R d . channel i = 1 precede COCP/M4CO 12 - 15 -

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend