Topic 1: Introduction 1 (Version of 20th September 2021)
Pierre Flener and Jean-Noel¨ 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
1Based partly on material by Guido Tack Optimisation
Constraint Problems
Combinatorial Optimisation
Modelling (in MiniZinc)
Solving
The MiniZinc Toolchain
Course Information Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Optimisation and CP Contact
Optimisation is a science of service: to scientists, to engineers, to artists, and to society.
COCP/M4CO 1 - 2 - MiniZinc Challenge 2015: Some Winners Problem & Model Backend & Solver Technology Costas array Mistral CP capacitated VRP iZplus hybrid Constraint Problems GFD schedule Chuffed LCG Combinatorial grid colouring MiniSAT(ID) hybrid Optimisation instruction scheduling Chuffed LCG Modelling (in MiniZinc) large scheduling Google OR-Tools.cp CP Solving application mapping JaCoP CP The MiniZinc Toolchain multi-knapsack mzn-cplex MIP
Course portfolio design fzn-oscar-cbls CBLS Information Part 1: Modelling for open stacks Chuffed LCG Combinatorial Optimisation project planning Chuffed LCG Part 2: Combinatorial Optimisation and CP radiation mzn-gurobi MIP Contact satellite management mzn-gurobi MIP time-dependent TSP G12.FD CP zephyrus configuration mzn-cplex MIP
COCP/M4CO 1 - 3 - Outline
1. Constraint Problems Constraint Problems Combinatorial 2. Combinatorial Optimisation Optimisation
Modelling (in MiniZinc) 3. Modelling (in MiniZinc)
Solving
The MiniZinc 4. Solving Toolchain Course 5. The MiniZinc Toolchain Information Part 1: Modelling for Combinatorial Optimisation 6. Course Information Part 2: Combinatorial Optimisation and CP Part 1: Modelling for Combinatorial Optimisation Contact Part 2: Combinatorial Optimisation and CP Contact
COCP/M4CO 1 - 4 - Outline
1. Constraint Problems Constraint Problems Combinatorial 2. Combinatorial Optimisation Optimisation
Modelling (in MiniZinc) 3. Modelling (in MiniZinc)
Solving
The MiniZinc 4. Solving Toolchain Course 5. The MiniZinc Toolchain Information Part 1: Modelling for Combinatorial Optimisation 6. Course Information Part 2: Combinatorial Optimisation and CP Part 1: Modelling for Combinatorial Optimisation Contact Part 2: Combinatorial Optimisation and CP Contact
COCP/M4CO 1 - 5 - Example (Agricultural experiment design) plot1 plot2 plot3 plot4 plot5 plot6 plot7 barley Constraint Problems corn
Combinatorial millet Optimisation oats Modelling rye (in MiniZinc) spelt Solving wheat The MiniZinc Toolchain
Course Constraints to be satisfied: Information Part 1: Modelling for 1 Equal growth load: Every plot grows 3 grains. Combinatorial Optimisation Part 2: Combinatorial 2 Equal sample size: Every grain is grown in 3 plots. Optimisation and CP Contact 3 Balance: Every grain pair is grown in 1 common plot. Instance: 7 plots, 7 grains, 3 grains/plot, 3 plots/grain, balance 1.
COCP/M4CO 1 - 6 - Example (Agricultural experiment design) plot1 plot2 plot3 plot4 plot5 plot6 plot7 barley ✓ ✓ ✓ – – – – Constraint Problems corn ✓ – – ✓ ✓ – –
Combinatorial millet ✓ – – – – ✓ ✓ Optimisation oats – ✓ – ✓ – ✓ – Modelling rye – ✓ – – ✓ – ✓ (in MiniZinc) spelt – – ✓ ✓ – – ✓ Solving wheat – – ✓ – ✓ ✓ – The MiniZinc Toolchain
Course Constraints to be satisfied: Information Part 1: Modelling for 1 Equal growth load: Every plot grows 3 grains. Combinatorial Optimisation Part 2: Combinatorial 2 Equal sample size: Every grain is grown in 3 plots. Optimisation and CP Contact 3 Balance: Every grain pair is grown in 1 common plot. Instance: 7 plots, 7 grains, 3 grains/plot, 3 plots/grain, balance 1.
COCP/M4CO 1 - 6 - Example (Doctor rostering) Mon Tue Wed Thu Fri Sat Sun Doctor A Doctor B Constraint Problems Doctor C Combinatorial Doctor D Optimisation Doctor E Modelling (in MiniZinc) Constraints to be satisfied: Solving 1 #on-call doctors / day = 1 The MiniZinc Toolchain 2 #operating drs / weekday ≤ 2 Course Information 3 #operating drs / week ≥ 7 Part 1: Modelling for Combinatorial Optimisation 4 #appointed drs / week ≥ 4 Part 2: Combinatorial Optimisation and CP 5 day off after operation day Contact 6 ... Objective function to be minimised: Cost: . . .
COCP/M4CO 1 - 7 - Example (Doctor rostering) Mon Tue Wed Thu Fri Sat Sun Doctor A call none oper none oper none none Doctor B appt call none oper none none call Constraint Problems Doctor C oper none call appt appt call none Combinatorial Doctor D appt oper none call oper none none Optimisation Doctor E oper none oper none call none none Modelling (in MiniZinc) Constraints to be satisfied: Solving 1 #on-call doctors / day = 1 The MiniZinc Toolchain 2 #operating drs / weekday ≤ 2 Course Information 3 #operating drs / week ≥ 7 Part 1: Modelling for Combinatorial Optimisation 4 #appointed drs / week ≥ 4 Part 2: Combinatorial Optimisation and CP 5 day off after operation day Contact 6 ... Objective function to be minimised: Cost: . . .
COCP/M4CO 1 - 7 - Example (Vehicle routing: parcel delivery) Given a depot with parcels for clients and a vehicle fleet, find which vehicle visits which client when.
Constraint Problems Constraints to be satisfied:
Combinatorial 1 All parcels are delivered on time. Optimisation 2 No vehicle is overloaded. Modelling (in MiniZinc) 3 Driver regulations are respected. Solving 4 ... The MiniZinc Toolchain Objective function to be minimised: Course Information Cost: the total fuel consumption and driver salary. Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Optimisation and CP Contact Example (Travelling salesperson: optimisation TSP) Given a map and cities, find a shortest route visiting each city once and returning to the starting city.
COCP/M4CO 1 - 8 - Applications in Air Traffic Management
Demand vs capacity Airspace sectorisation Constraint Problems
Combinatorial Optimisation
Modelling (in MiniZinc)
Solving
The MiniZinc Toolchain Contingency planning Workload balancing Course Flow Time Span Hourly Rate Information From: Arlanda 00:00 – 09:00 3 Part 1: Modelling for Combinatorial To: west, south 09:00 – 18:00 5 Optimisation 18:00 – 24:00 2 Part 2: Combinatorial From: Arlanda 00:00 – 12:00 4 Optimisation and CP To: east, north 12:00 – 24:00 3 Contact ......
COCP/M4CO 1 - 9 - Example (Air-traffic demand-capacity balancing) Reroute flights, in height and speed, so as to balance the workload of air traffic controllers in a multi-sector airspace:
Constraint Problems
Combinatorial Optimisation
Modelling (in MiniZinc)
Solving
The MiniZinc Toolchain
Course Information Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Optimisation and CP Contact
COCP/M4CO 1 - 10 - Example (Airspace sectorisation) Given an airspace split Find a colouring of the cells into c cells, a targeted into s connected convex sec-
Constraint number s of sectors, and tors, with minimal imbalance Problems flight schedules. of the workloads of their air Combinatorial Optimisation traffic controllers.
Modelling (in MiniZinc)
Solving
The MiniZinc Toolchain
Course Information Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Optimisation and CP Contact
There are sc possible colourings, but very few optimally satisfy the constraints: is intelligent search necessary?
COCP/M4CO 1 - 11 - gy
Applications in Biology and Medicine
Phylogenetic supertree Haplotype inference Constraint Problems
Combinatorial Optimisation
Modelling (in MiniZinc)
Solving
The MiniZinc Toolchain
Course Medical image analysis Doctor rostering Information Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Optimisation and CP Contact
COCP/M4CO 1 - 12 - Example (What supertree is maximally consistent with several given trees that share some species?)
Constraint Problems
Combinatorial Optimisation
Modelling (in MiniZinc)
Solving
The MiniZinc Toolchain
Course Information Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Optimisation and CP Contact
COCP/M4CO 1 - 13 - Example (Haplotype inference by pure parsimony) Given n child genotypes, with homo- & heterozygous sites:
··· Constraint A C/G T C A/T C Problems ··· Combinatorial Optimisation A/T G T C/G A C
Modelling ··· (in MiniZinc) Solving find a minimal set of (at most 2 · n) parent haplotypes: The MiniZinc Toolchain ··· Course A C T C T C Information ··· Part 1: Modelling for Combinatorial Optimisation A G T C A C Part 2: Combinatorial Optimisation and CP ··· Contact T G T G A C ···
so that each given genotype conflates 2 found haplotypes.
COCP/M4CO 1 - 14 - Applications in Programming and Testing
Robot programming Sensor-net configuration Constraint Problems
Combinatorial Optimisation
Modelling (in MiniZinc)
Solving The MiniZinc Compiler design Base-station testing Toolchain
Course Information Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Optimisation and CP Contact
COCP/M4CO 1 - 15 - Other Application Areas
School timetabling Sports tournament design
Constraint Problems
Combinatorial Optimisation
Modelling (in MiniZinc)
Solving
The MiniZinc Toolchain
Course Security: SQL injection? Container packing Information Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Optimisation and CP Contact
COCP/M4CO 1 - 16 - Definitions In a constraint problem, values have to be found for all the unknowns, called variables (in the mathematical sense) and ranging over given sets called domains, so that: Constraint Problems All the given constraints on the variables are satisfied. Combinatorial Optimisation Optionally: A given objective function on the variables Modelling has an optimal value: minimal cost or maximal profit. (in MiniZinc)
Solving
The MiniZinc Definitions Toolchain A candidate solution to a constraint problem maps each Course Information variable to a value within its domain; it is: Part 1: Modelling for Combinatorial Optimisation feasible if all the constraints are satisfied; Part 2: Combinatorial Optimisation and CP Contact optimal if the objective function takes an optimal value. The search space consists of all candidate solutions. A solution to a satisfaction problem is feasible. An optimal solution to an optimisation problem is feasible and optimal.
COCP/M4CO 1 - 17 - P =? NP (Cook, 1971; Levin, 1973)
This is one of the seven Millennium Prize problems Constraint of the Clay Mathematics Institute (Massachusetts, USA), Problems each worth 1 million US$. Combinatorial Optimisation Informally: Modelling (in MiniZinc) P = class of problems that need no search to be solved Solving NP = class of problems that might need search to solve The MiniZinc Toolchain P = class of problems with easy-to-compute solutions Course Information NP = class of problems with easy-to-check solutions Part 1: Modelling for Combinatorial Thus: Can search always be avoided (P = NP), Optimisation Part 2: Combinatorial Optimisation and CP or is search sometimes necessary (P ̸= NP)? Contact Problems that are solvable in polynomial time (in the input size) are considered tractable, or easy. Problems requiring super-polynomial time are considered intractable, or hard.
COCP/M4CO 1 - 18 - NP Completeness: Examples
Given a digraph (V , E):
Constraint Examples Problems
Combinatorial Finding a shortest path takes O(V · E) time and is in P. Optimisation
Modelling Determining the existence of a simple path (which has (in MiniZinc) distinct vertices), from a given single source, that has Solving at least a given number ℓ of edges is NP-complete. The MiniZinc Toolchain Hence finding a longest path seems hard: increase ℓ
Course starting from a trivial lower bound, until answer is ‘no’. Information Part 1: Modelling for Combinatorial Optimisation Examples Part 2: Combinatorial Optimisation and CP Contact Finding an Euler tour (which visits each edge once) takes O(E) time and is thus in P. Determining the existence of a Hamiltonian cycle (which visits each vertex once) is NP-complete.
COCP/M4CO 1 - 19 - NP Completeness: More Examples
Examples Constraint 2-SAT: Determining the satisfiability of a conjunction of Problems disjunctions of 2 Boolean literals is in P. Combinatorial Optimisation 3-SAT: Determining the satisfiability of a conjunction of Modelling (in MiniZinc) disjunctions of 3 Boolean literals is NP-complete. Solving SAT: Determining the satisfiability of a formula over The MiniZinc Toolchain Boolean literals is NP-complete. Course Clique: Determining the existence of a clique (complete Information Part 1: Modelling for Combinatorial subgraph) of a given size in a graph is NP-complete. Optimisation Part 2: Combinatorial Vertex Cover: Determining the existence of a vertex Optimisation and CP Contact cover (a vertex subset with at least one endpoint for all edges) of a given size in a graph is NP-complete. Subset Sum: Determining the existence of a subset, of a given set, that has a given sum is NP-complete. COCP/M4CO 1 - 20 - Search spaces are often larger than the universe!
Constraint Problems
Combinatorial Optimisation
Modelling (in MiniZinc)
Solving
The MiniZinc Toolchain
Course Information Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Optimisation and CP Many important real-life problems are NP-hard or worse: Contact their real-life instances can only be solved exactly and fast enough by intelligent search, unless P = NP. NP-hardness is not where the fun ends, but where it begins!
COCP/M4CO 1 - 21 - Example (Optimisation TSP over n cities) A brute-force algorithm evaluates all n! candidate routes: A computer of today evaluates 106 routes / second: n time Constraint Problems 11 40 seconds Combinatorial 14 1 day Optimisation 18 203 years Modelling 20 77k years (in MiniZinc) −44 Solving Planck time is shortest useful interval: ≈ 5.4 · 10 s; 43 The MiniZinc a Planck computer would evaluate 1.8 · 10 routes / s: Toolchain n time Course Information 37 0.7 seconds Part 1: Modelling for Combinatorial 41 20 days Optimisation Part 2: Combinatorial 48 1.5 · age of universe Optimisation and CP Contact The dynamic program by Bellman-Held-Karp “only” takes O(n2 · 2n) time: a computer of today takes a day for n = 27, a year for n = 35, the age of the universe for n = 67, and it beats the O(n!) algo on the Planck computer for n ≥ 44.
COCP/M4CO 1 - 22 - Intelligent Search upon NP-Hardness
Do not give up but try to stay ahead of the curve: there is an instance size until which an exact algorithm is fast enough! Constraint Problems n! (today) n! (Planck) Combinatorial 18 Optimisation 10 age of universe Modelling 13 (in MiniZinc) 10 n2 · 2n (today) Solving 108 1 year The MiniZinc 5 Toolchain 10 1 day Course Information 100 Part 1: Modelling for time (s): log scale! n Combinatorial Optimisation 10 14 27 35 44 48 Part 2: Combinatorial Optimisation and CP Contact The Concorde TSP Solver beats the Bellman-Held-Karp exact algo: it uses approximation & local-search algorithms, but it can sometimes prove the exactness (optimality) of its solutions. The largest instance it has solved exactly, in 136 CPU years in 2006, has 85,900 cities! ☞ Let the fun begin! COCP/M4CO 1 - 23 - Outline
1. Constraint Problems Constraint Problems Combinatorial 2. Combinatorial Optimisation Optimisation
Modelling (in MiniZinc) 3. Modelling (in MiniZinc)
Solving
The MiniZinc 4. Solving Toolchain Course 5. The MiniZinc Toolchain Information Part 1: Modelling for Combinatorial Optimisation 6. Course Information Part 2: Combinatorial Optimisation and CP Part 1: Modelling for Combinatorial Optimisation Contact Part 2: Combinatorial Optimisation and CP Contact
COCP/M4CO 1 - 24 - A solving technology offers methods and tools for:
what: Modelling constraint problems in declarative language.
and / or Constraint Problems
Combinatorial how: Solving constraint problems intelligently: Optimisation • Modelling Search: Explore the space of candidate solutions. (in MiniZinc) • Inference: Reduce the space of candidate solutions. Solving The MiniZinc • Relaxation: Exploit solutions to easier problems. Toolchain
Course Information A solver is a program that takes a model & data as Part 1: Modelling for Combinatorial input and tries to solve the modelled problem instance. Optimisation Part 2: Combinatorial Optimisation and CP Combinatorial (= discrete) optimisation covers satisfaction Contact and optimisation problems, for variables over discrete sets. The ideas in this course extend to continuous optimisation, to soft optimisation, and to stochastic optimisation.
COCP/M4CO 1 - 25 - Examples (Solving technologies) With general-purpose solvers, taking model&data as input: Boolean satisfiability (SAT)
Constraint SAT (resp. optimisation) modulo theories (SMT & OMT) Problems (Mixed) integer linear programming (IP & MIP) Combinatorial Optimisation Constraint programming (CP) ☞ part 2 of 1DL441 Modelling (in MiniZinc) ... Solving Hybrid technologies (LCG = CP + SAT, . . . ) The MiniZinc Toolchain Methodologies, usually without modelling and solvers: Course Information Dynamic programming (DP) Part 1: Modelling for Combinatorial Optimisation Greedy algorithms Part 2: Combinatorial Optimisation and CP Contact Approximation algorithms Local search (LS) Genetic algorithms (GA) ... COCP/M4CO 1 - 26 - Outline
1. Constraint Problems Constraint Problems Combinatorial 2. Combinatorial Optimisation Optimisation
Modelling (in MiniZinc) 3. Modelling (in MiniZinc)
Solving
The MiniZinc 4. Solving Toolchain Course 5. The MiniZinc Toolchain Information Part 1: Modelling for Combinatorial Optimisation 6. Course Information Part 2: Combinatorial Optimisation and CP Part 1: Modelling for Combinatorial Optimisation Contact Part 2: Combinatorial Optimisation and CP Contact
COCP/M4CO 1 - 27 - What vs How
Example Constraint Problems Consider the problem of sorting an array A of n numbers
Combinatorial into an array S of increasing-or-equal numbers. Optimisation Modelling A formal specification is: (in MiniZinc) Solving sort(A, S) ≡ permutation(A, S) ∧ increasing(S) The MiniZinc Toolchain
Course saying S must be a permutation of A in increasing order. Information Part 1: Modelling for Combinatorial Seen as a generate-and-test algorithm, it takes O(n!) time, Optimisation Part 2: Combinatorial Optimisation and CP but it can be refined into the existing O(n log n) algorithms. Contact A specification is a declarative description of what problem is to be solved. An algorithm is an imperative description of how to solve the problem (efficiently).
COCP/M4CO 1 - 28 - Modelling vs Programming
problem Constraint Problems
Combinatorial Optimisation
Modelling (in MiniZinc) specification Solving
The MiniZinc what? (declarative) how? (imperative) Toolchain
Course Information Part 1: Modelling for Combinatorial model algorithm Optimisation Part 2: Combinatorial Optimisation and CP Contact automatic! manual!
program program
COCP/M4CO 1 - 29 - Example (Sudoku)
8 8 1 2 7 5 3 6 4 9 3 6 9 4 3 6 8 2 1 7 5
Constraint 7 9 2 6 7 5 4 9 1 2 8 3 Problems 5 7 1 5 4 2 3 7 8 9 6 Combinatorial 4 5 7 3 6 9 8 4 5 7 2 1 Optimisation 1 3 2 8 7 1 6 9 5 3 4 Modelling 1 6 8 5 2 1 9 7 4 3 6 8 (in MiniZinc) 8 5 1 4 3 8 5 2 6 9 1 7 Solving 9 4 7 9 6 3 1 8 4 5 2 The MiniZinc Toolchain A Sudoku is a 9-by-9 array of integers in the range 1..9. Course Information Some of the elements are provided as parameters. Part 1: Modelling for Combinatorial The remaining elements are unknowns Optimisation Part 2: Combinatorial that have to satisfy the following constraints: Optimisation and CP Contact 1 the elements in each row are all different; 2 the elements in each column are all different; 3 the elements in each 3-by-3 block are all different.
COCP/M4CO 1 - 30 - Example (Sudoku) Constraint Problems
Combinatorial Optimisation
Modelling (in MiniZinc)
Solving
The MiniZinc Toolchain
Course Information Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Optimisation and CP Contact
COCP/M4CO 1 - 31 - Example (Sudoku)
8 8 1 2 7 5 3 6 4 9 3 6 9 4 3 6 8 2 1 7 5 7 9 2 6 7 5 4 9 1 2 8 3 Constraint Problems 5 7 1 5 4 2 3 7 8 9 6 4 5 7 3 6 9 8 4 5 7 2 1 Combinatorial Optimisation 1 3 2 8 7 1 6 9 5 3 4
Modelling 1 6 8 5 2 1 9 7 4 3 6 8 (in MiniZinc) 8 5 1 4 3 8 5 2 6 9 1 7 Solving 9 4 7 9 6 3 1 8 4 5 2 The MiniZinc Toolchain -2 array[1..9,1..9] of var 1..9: Sudoku; Course -1 Information Part 1: Modelling for 0 solve satisfy; Combinatorial Optimisation 1 constraint forall(row in 1..9) Part 2: Combinatorial Optimisation and CP (alldifferent(Sudoku[row,..])); Contact 2 constraint forall(col in 1..9) (alldifferent(Sudoku[..,col])); 3 constraint forall(i,j in {0,3,6}) (alldifferent(Sudoku[i+1..i+3,j+1..j+3]));
COCP/M4CO 1 - 32 - Example (Agricultural experiment design, AED) plot1 plot2 plot3 plot4 plot5 plot6 plot7 barley ✓ ✓ ✓ – – – – corn ✓ – – ✓ ✓ – – Constraint Problems millet ✓ – – – – ✓ ✓ Combinatorial oats – ✓ – ✓ – ✓ – Optimisation rye – ✓ – – ✓ – ✓ Modelling (in MiniZinc) spelt – – ✓ ✓ – – ✓ ✓ ✓ ✓ Solving wheat – – – –
The MiniZinc Toolchain Constraints to be satisfied: Course 1 Information Equal growth load: Every plot grows 3 grains. Part 1: Modelling for Combinatorial 2 Equal sample size: Every grain is grown in 3 plots. Optimisation Part 2: Combinatorial Optimisation and CP 3 Balance: Every grain pair is grown in 1 common plot. Contact Instance: 7 plots, 7 grains, 3 grains/plot, 3 plots/grain, balance 1.
General term: balanced incomplete block design(BIBD).
COCP/M4CO 1 - 33 - Example (Agricultural experiment design, AED) plot1 plot2 plot3 plot4 plot5 plot6 plot7 barley 1 1 1 0 0 0 0 corn 1 0 0 1 1 0 0 Constraint Problems millet 1 0 0 0 0 1 1 Combinatorial oats 0 1 0 1 0 1 0 Optimisation rye 0 1 0 0 1 0 1 Modelling (in MiniZinc) spelt 0 0 1 1 0 0 1
Solving wheat 0 0 1 0 1 1 0
The MiniZinc Toolchain Constraints to be satisfied: Course 1 Information Equal growth load: Every plot grows 3 grains. Part 1: Modelling for Combinatorial 2 Equal sample size: Every grain is grown in 3 plots. Optimisation Part 2: Combinatorial Optimisation and CP 3 Balance: Every grain pair is grown in 1 common plot. Contact Instance: 7 plots, 7 grains, 3 grains/plot, 3 plots/grain, balance 1.
General term: balanced incomplete block design(BIBD).
COCP/M4CO 1 - 33 - In a BIBD, the plots are blocks and the grains are varieties:
Example (BIBD integer model: ✓ ⇝ 1 and – ⇝ 0)
Constraint -3 enum Varieties; enum Blocks; Problems -2 int: blockSize; int: sampleSize; int: balance; Combinatorial -1 array[Varieties,Blocks] of var 0..1: BIBD; Optimisation 0 solve satisfy; Modelling 1 constraint forall(b in Blocks) (in MiniZinc) (blockSize = sum(BIBD[..,b]));
Solving 2 constraint forall(v in Varieties) (sampleSize = sum(BIBD[v,..])); The MiniZinc constraint forall(v, w in Varieties where v < w) Toolchain 3 (balance = sum([BIBD[v,b]*BIBD[w,b] | b in Blocks])); Course Information Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Example (Instance data for our AED) Optimisation and CP Contact -3 Varieties = {barley,...,wheat}; Blocks = {plot1,...,plot7}; -2 blockSize = 3; sampleSize = 3; balance = 1;
COCP/M4CO 1 - 34 - Using the count abstraction instead of sum:
Example (BIBD integer model: ✓ ⇝ 1 and – ⇝ 0)
Constraint -3 enum Varieties; enum Blocks; Problems -2 int: blockSize; int: sampleSize; int: balance; Combinatorial -1 array[Varieties,Blocks] of var 0..1: BIBD; Optimisation 0 solve satisfy; Modelling 1 constraint forall(b in Blocks) (in MiniZinc) (blockSize = count(BIBD[..,b], 1));
Solving 2 constraint forall(v in Varieties) (sampleSize = count(BIBD[v,..], 1)); The MiniZinc constraint forall(v, w in Varieties where v < w) Toolchain 3 (balance = count([BIBD[v,b]*BIBD[w,b] | b in Blocks], 1)); Course Information Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Example (Instance data for our AED) Optimisation and CP Contact -3 Varieties = {barley,...,wheat}; Blocks = {plot1,...,plot7}; -2 blockSize = 3; sampleSize = 3; balance = 1;
COCP/M4CO 1 - 35 - Using the count abstraction over linear expressions:
Example (BIBD integer model: ✓ ⇝ 1 and – ⇝ 0)
Constraint -3 enum Varieties; enum Blocks; Problems -2 int: blockSize; int: sampleSize; int: balance; Combinatorial -1 array[Varieties,Blocks] of var 0..1: BIBD; Optimisation 0 solve satisfy; Modelling 1 constraint forall(b in Blocks) (in MiniZinc) (blockSize = count(BIBD[..,b], 1));
Solving 2 constraint forall(v in Varieties) (sampleSize = count(BIBD[v,..], 1)); The MiniZinc constraint forall(v, w in Varieties where v < w) Toolchain 3 (balance = count([BIBD[v,b]+BIBD[w,b] | b in Blocks], 2)); Course Information Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Example (Instance data for our AED) Optimisation and CP Contact -3 Varieties = {barley,...,wheat}; Blocks = {plot1,...,plot7}; -2 blockSize = 3; sampleSize = 3; balance = 1;
COCP/M4CO 1 - 36 - Reconsider the model fragment:
2 constraint forall(v in Varieties) (sampleSize = count(BIBD[v,..], 1)); This constraint is declarative (and by the way non-linear), Constraint Problems so read it using only the verb “to be” or synonyms thereof:
Combinatorial Optimisation for all varieties v, Modelling the count of occurrences of 1 in row v of BIBD (in MiniZinc) must equal sampleSize Solving
The MiniZinc Toolchain The constraint is not procedural: Course Information v Part 1: Modelling for for all varieties , Combinatorial Optimisation we first count the occurrences of 1 in row v Part 2: Combinatorial Optimisation and CP and then check if that count equals sampleSize Contact
The latter reading is appropriate for solution checking, but solution finding performs no such procedural counting.
COCP/M4CO 1 - 37 - , plot4, plot5, plot6, plot7 plot2, plot3, , plot6, plot7 plot2, plot3, plot4, plot5, plot1, plot3, plot5, , plot7 plot1, plot3, plot4, plot6, plot1, plot2, plot5, plot6, plot1, plot2, plot4, , plot7
Example (Idea for another BIBD model) barley {plot1, plot2, plot3 } Constraint corn {plot1, plot4, plot5 } Problems
Combinatorial millet {plot1, plot6, plot7} Optimisation oats { plot2, plot4, plot6 } Modelling (in MiniZinc) rye { plot2, plot5, plot7}
Solving spelt { plot3, plot4, plot7} The MiniZinc wheat { plot3, plot5, plot6 } Toolchain Course Constraints to be satisfied: Information Part 1: Modelling for Combinatorial 1 Equal growth load: Every plot grows 3 grains. Optimisation Part 2: Combinatorial Optimisation and CP 2 Equal sample size: Every grain is grown in 3 plots. Contact 3 Balance: Every grain pair is grown in 1 common plot.
COCP/M4CO 1 - 38 - Example (BIBD set model: a block set per variety)
-3 enum Varieties; enum Blocks; Constraint -2 int: blockSize; int: sampleSize; int: balance; Problems -1 array[Varieties] of var set of Blocks: BIBD; Combinatorial 0 solve satisfy; Optimisation 1 constraint forall(b in Blocks) Modelling (blockSize = sum(v in Varieties)(b in BIBD[v])); (in MiniZinc) 2 constraint forall(v in Varieties)
Solving (sampleSize = card(BIBD[v])); 3 constraint forall(v, w in Varieties where v < w) The MiniZinc (balance = card(BIBD[v] intersect BIBD[w])); Toolchain
Course Information Part 1: Modelling for Combinatorial Example (Instance data for our AED) Optimisation Part 2: Combinatorial Optimisation and CP -3 Varieties = {barley,...,wheat}; Blocks = {plot1,...,plot7}; Contact -2 blockSize = 3; sampleSize = 3; balance = 1;
COCP/M4CO 1 - 39 - Example (Doctor rostering) Mon Tue Wed Thu Fri Sat Sun Doctor A call none oper none oper none none Doctor B appt call none oper none none call Constraint Problems Doctor C oper none call appt appt call none Combinatorial Doctor D appt oper none call oper none none Optimisation Doctor E oper none oper none call none none Modelling (in MiniZinc) Constraints to be satisfied: Solving 1 #on-call doctors / day = 1 The MiniZinc Toolchain 2 #operating drs / weekday ≤ 2 Course Information 3 #operating drs / week ≥ 7 Part 1: Modelling for Combinatorial Optimisation 4 #appointed drs / week ≥ 4 Part 2: Combinatorial Optimisation and CP 5 day off after operation day Contact 6 ... Objective function to be minimised: Cost: . . .
COCP/M4CO 1 - 40 - Example (Doctor rostering)
-4 set of int: Days;%d mod7=1 iffd isa Monday -3 enum Doctors; -2 enum ShiftTypes = {appt, call, oper, none}; Constraint -1 array[Doctors,Days] of var ShiftTypes: Roster; Problems 0 solve minimize ...;% plug in an objective function Combinatorial 1 constraint forall(d in Days) Optimisation (count(Roster[..,d],call) = 1); Modelling 2 constraint forall(d in Days whered mod7 in 1..5) (in MiniZinc) (count(Roster[..,d],oper) <= 2); Solving 3 constraint count(Roster,oper) >= 7; The MiniZinc 4 constraint count(Roster,appt) >= 4; Toolchain 5 constraint forall(d in Doctors) Course (regular(Roster[d,..],"((oper none)|appt|call|none) *")); Information 6 ...% other constraints Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Optimisation and CP Contact Example (Instance data for our small hospital unit)
-4 Days = 1..7; -3 Doctors = {Dr_A, Dr_B, Dr_C, Dr_D, Dr_E};
COCP/M4CO 1 - 41 - Using variables as indices within arrays: black magic?!
Constraint Problems Example (Job allocation at minimal salary cost) Combinatorial Optimisation Given jobs Jobs and the salaries of work applicants Apps, Modelling (in MiniZinc) find a work applicant for each job
Solving such that some constraints (on the qualifications of the
The MiniZinc work applicants for the jobs, on workload distribution, etc) Toolchain are satisfied and the total salary cost is minimal: Course Information 1 array[Apps] of 0..1000: Salary;% Salary[a]/job bya Part 1: Modelling for Combinatorial 2 array[Jobs] of var Apps: Worker;% jobj by Worker[j] Optimisation Part 2: Combinatorial 3 solve minimize sum(j in Jobs)(Salary[Worker[j]]); Optimisation and CP Contact 4 constraint ...;% qualifications, workload, etc
COCP/M4CO 1 - 42 - 128.8 162.6 BRU LUX
1 array[Cities,Cities] of float: Dist;% instance data 2 array[Cities] of var Cities: Next;% fromc to Next[c] 3 solve minimize sum(c in Cities)(Dist[c,Next[c]]); 4 constraint circuit(Next); 5 constraint ...;% side constraints, if any
Using variables as indices within arrays: black magic?!
Example (Vehicle routing: backbone model) Constraint Problems
Combinatorial BRU AMS Optimisation enum Cities = {AMS,BRU,LUX,CDG} Modelling (in MiniZinc) AMS BRU LUX CDG Solving Next: The MiniZinc Toolchain CDG LUX
Course Information Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Optimisation and CP Contact
COCP/M4CO 1 - 43 - 128.8 162.6
1 array[Cities,Cities] of float: Dist;% instance data 2 array[Cities] of var Cities: Next;% fromc to Next[c] 3 solve minimize sum(c in Cities)(Dist[c,Next[c]]); 4 constraint circuit(Next); 5 constraint ...;% side constraints, if any
Using variables as indices within arrays: black magic?!
Example (Vehicle routing: backbone model) Constraint Problems 85.2 Combinatorial BRU AMS Optimisation enum Cities = {AMS,BRU,LUX,CDG} Modelling (in MiniZinc) AMS BRU LUX CDG Solving Next: BRU AMS CDG LUX The MiniZinc alldifferent(Next) Toolchain So is too weak! CDG LUX 146.7 Course Information Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Optimisation and CP Contact
COCP/M4CO 1 - 43 - 1 array[Cities,Cities] of float: Dist;% instance data 2 array[Cities] of var Cities: Next;% fromc to Next[c] 3 solve minimize sum(c in Cities)(Dist[c,Next[c]]); 4 constraint circuit(Next); 5 constraint ...;% side constraints, if any
Using variables as indices within arrays: black magic?!
Example (Vehicle routing: backbone model) Constraint Problems 85.2 Combinatorial BRU AMS Optimisation enum Cities = {AMS,BRU,LUX,CDG} Modelling (in MiniZinc) AMS BRU LUX CDG 128.8 162.6 Solving Next: BRU CDG AMS LUX The MiniZinc circuit(Next) Toolchain Let us use instead: CDG LUX 146.7 Course Information Part 1: Modelling for Combinatorial Optimisation Part 2: Combinatorial Optimisation and CP Contact
COCP/M4CO 1 - 43 - Using variables as indices within arrays: black magic?!
Example (Vehicle routing: backbone model) Constraint Problems 85.2 Combinatorial BRU AMS Optimisation enum Cities = {AMS,BRU,LUX,CDG} Modelling (in MiniZinc) AMS BRU LUX CDG 128.8 162.6 Solving Next: BRU CDG AMS LUX The MiniZinc circuit(Next) Toolchain Let us use instead: CDG LUX 146.7 Course Information 1 array[Cities,Cities] of float: Dist;% instance data Part 1: Modelling for Combinatorial Optimisation 2 array[Cities] of var Cities: Next;% fromc to Next[c] Part 2: Combinatorial 3 solve minimize sum(c in Cities)(Dist[c,Next[c]]); Optimisation and CP Contact 4 constraint circuit(Next); 5 constraint ...;% side constraints, if any
COCP/M4CO 1 - 43 - Toy Example: 8-Queens
Constraint Problems Can one place 8 queens onto an 8 × 8 chessboard so that Combinatorial all queens are in distinct rows, columns, and diagonals? Optimisation
Modelling
(in MiniZinc)
Solving