Chapter 00: Introduction - Uppsala Universityuser.it.uu.se/~pierref/courses/AD3/slides/00... ·...

62
Chapter 00: Introduction (Version of 20th January 2020) Pierre Flener Department of Information Technology Computing Science Division Uppsala University Sweden Course 1DL481: Algorithms and Data Structures 3 (AD3)

Transcript of Chapter 00: Introduction - Uppsala Universityuser.it.uu.se/~pierref/courses/AD3/slides/00... ·...

Chapter 00: Introduction(Version of 20th January 2020)

Pierre Flener

Department of Information TechnologyComputing Science Division

Uppsala UniversitySweden

Course 1DL481:Algorithms and Data Structures 3 (AD3)

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Outline

1 The End of Course AD2

2 Combinatorial OptimisationConstraint ProblemsSolving TechnologiesModellingSolving

3 Course AD3ContentsNew ConceptsLearning OutcomesOrganisation

AD3 - 2 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Outline

1 The End of Course AD2

2 Combinatorial OptimisationConstraint ProblemsSolving TechnologiesModellingSolving

3 Course AD3ContentsNew ConceptsLearning OutcomesOrganisation

AD3 - 3 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

In a decision problem we seek a ‘yes’ / ‘no’ answer to anexistence question. An instance is given by its input data.

Example (Travelling salesperson: Decision TSP)Given a map and n cities, is there a route visiting each cityonce, returning to the starting city, and costing at most c ?

A decision problem R is:in NP if a witness to a ‘yes’ instance is checkable intime polynomial in the instance size: checking is in P;NP-complete if it is in NP and there is a reduction fromeach problem Q in NP, transforming in polytime eachinstance of Q into an instance of R of the same answer.

It is believed that NP-complete problems are intractable(or: hard), requiring super-polynomial time to solve exactly.

ExampleTSP is NP-complete as a witness is checkable in O(n) timeand NP-complete Hamiltonian-Cycle problem reduces to it.

AD3 - 4 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

In a satisfaction problem we seek a witness for ‘yes’ answer.

Example (Satisfaction TSP)Given a map and n cities, find a route visiting each cityonce, returning to the starting city, and costing at most c.

In an optimisation problem we seek an optimal witnessaccording to some objective function for a ‘yes’ answer.

Example (Optimisation TSP)Given a map and n cities, find a cheapest route visitingeach city once and returning to the starting city.

In addition to decision problems that are at least as hard asevery NP problem (as every NP problem reduces to them),satisfaction and optimisation problems with NP-completedecision versions are often also said to be NP-hard:they are unlikely to be easier than their decision versions.

AD3 - 5 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

What Now?

Several courses at Uppsala University teach techniques foraddressing NP-hard optimisation and satisfaction problems:

1TD184 Continuous Optimisation (period 2)

1DL451 Modelling for Combinatorial Optimisation (period 1)

1DL441 Comb’l Opti. and Constraint Programming (period 1+2)

1DL481 Algorithms and Data Structures 3 (period 3)

NP-hardness is not where the fun ends, but where it begins!

AD3 - 6 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Example (Optimisation TSP over n cities)A brute-force algorithm evaluates all n! candidate routes:

A computer of today evaluates 106 routes / second:n time11 40 seconds14 1 day18 203 years20 77k years

Planck time is shortest useful interval: ≈ 5.4 · 10−44 s;a Planck computer would evaluate 1.8 · 1043 routes / s:

n time37 0.7 seconds41 20 days48 1.5 · age of universe

The dynamic program by Bellman-Held-Karp “only” takesO(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, andit beats the O(n!) algo on the Planck computer for n ≥ 44.

AD3 - 7 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Intelligent Search upon NP-Hardness

Do not give up but try to stay ahead of the curve: there is aninstance size until which an exact algorithm is fast enough!

10 14 27 35 44 48100

105108

1013

1018

1 day1 year

age of universe

n! (today) n! (Planck)

n2 · 2n (today)

ntime

(s):

log

scal

e!

Concorde TSP Solver beats Bellman-Held-Karp exact algo:it uses approximation and stochastic local search algos,but it can sometimes prove the exactness (optimality) of itssolutions. The largest instance it has solved exactly, in 136CPU years in 2006, has 85,900 cities! + Let the fun begin!

AD3 - 8 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Outline

1 The End of Course AD2

2 Combinatorial OptimisationConstraint ProblemsSolving TechnologiesModellingSolving

3 Course AD3ContentsNew ConceptsLearning OutcomesOrganisation

AD3 - 9 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Optimisation

Optimisation is a science of service:to scientists, to engineers, to artists, and to society.

AD3 - 10 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Outline

1 The End of Course AD2

2 Combinatorial OptimisationConstraint ProblemsSolving TechnologiesModellingSolving

3 Course AD3ContentsNew ConceptsLearning OutcomesOrganisation

AD3 - 11 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Example (Agricultural experiment design)plot1 plot2 plot3 plot4 plot5 plot6 plot7

barleycorn

milletoatsrye

speltwheat

Constraints to be satisfied:1 Equal growth load: Every plot grows 3 grains.2 Equal sample size: Every grain is grown in 3 plots.3 Balance: Every grain pair is grown in 1 common plot.

Instance: 7 plots, 7 grains, 3 grains/plot, 3 plots/grain, balance 1.

AD3 - 12 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Example (Agricultural experiment design)plot1 plot2 plot3 plot4 plot5 plot6 plot7

barley 3 3 3 – – – –corn 3 – – 3 3 – –

millet 3 – – – – 3 3oats – 3 – 3 – 3 –rye – 3 – – 3 – 3

spelt – – 3 3 – – 3wheat – – 3 – 3 3 –

Constraints to be satisfied:1 Equal growth load: Every plot grows 3 grains.2 Equal sample size: Every grain is grown in 3 plots.3 Balance: Every grain pair is grown in 1 common plot.

Instance: 7 plots, 7 grains, 3 grains/plot, 3 plots/grain, balance 1.

AD3 - 12 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Example (Doctor rostering)

Mon Tue Wed Thu Fri Sat SunDoctor ADoctor BDoctor CDoctor DDoctor E

Constraints to be satisfied:1 #doctors-on-call / day = 12 #operations / workday ≤ 23 #operations / week ≥ 74 #appointments / week ≥ 45 day off after operation day6 . . .

Objective function to be minimised:Cost: . . .

AD3 - 13 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Example (Doctor rostering)

Mon Tue Wed Thu Fri Sat SunDoctor A call none oper none oper none noneDoctor B app call none oper none none callDoctor C oper none call app app call noneDoctor D app oper none call oper none noneDoctor E oper none oper none call none none

Constraints to be satisfied:1 #doctors-on-call / day = 12 #operations / workday ≤ 23 #operations / week ≥ 74 #appointments / week ≥ 45 day off after operation day6 . . .

Objective function to be minimised:Cost: . . .

AD3 - 13 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Example (Vehicle routing: Parcel delivery)Given a depot with parcels for clients and a vehicle fleet,find which vehicle visits which client when.

Constraints to be satisfied:1 All parcels are delivered on time.2 No vehicle is overloaded.3 Driver regulations are respected.4 . . .

Objective function to be minimised:Cost: the total fuel consumption and driver salary.

AD3 - 14 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Application Areas

School timetabling Sports tournament design

Vehicle routing Container packing

AD3 - 15 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Applications in Programming and Testing

Robot-task sequencing Sensor-net configuration

Compiler design Base-station testing

AD3 - 16 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Applications in Air Traffic Management

Demand vs capacity Airspace sectorisation

Contingency planningFlow Time Span Hourly RateFrom: Arlanda 00:00 – 09:00 3To: west, south 09:00 – 18:00 5

18:00 – 24:00 2From: Arlanda 00:00 – 12:00 4To: east, north 12:00 – 24:00 3. . . . . . . . .

Workload balancing

AD3 - 17 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Applications in Biology and Medicine

Phylogenetic supertree Haplotype inference

Medical image analysis Doctor rostering

gy

AD3 - 18 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

DefinitionsIn a constraint problem, values have to be found for all theunknowns, called variables (in the mathematical sense)and ranging over given sets called domains, so that:

All the given constraints on the variables are satisfied.Optionally: A given objective function on the variableshas an optimal value: minimal cost or maximal profit.

DefinitionA candidate solution to a constraint problem assigns toeach variable a value within its domain; it is:

feasible if all the constraints are satisfied;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 optimalsolution to an optimisation problem is feasible and optimal.

AD3 - 19 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Search spaces are often larger than the universe!

Many important real-life problems are NP-hard or worse:their real-life instances can only be solved exactly and fastenough by intelligent search, unless P = NP.

NP-hardness is not where the fun ends, but where it begins!

AD3 - 20 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Outline

1 The End of Course AD2

2 Combinatorial OptimisationConstraint ProblemsSolving TechnologiesModellingSolving

3 Course AD3ContentsNew ConceptsLearning OutcomesOrganisation

AD3 - 21 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

A solving technology offers methods and tools for:

what: Modelling constraint problems in declarative language.

and / or

how: Solving constraint problems intelligently:

• Search: Explore the space of candidate solutions.

• Inference: Reduce the space of candidate solutions.

• Relaxation: Exploit solutions to easier problems.

A solver is a program that takes a model & data asinput and tries to solve that problem instance.

Combinatorial (= discrete) optimisation covers satisfactionand optimisation problems, for variables over discrete sets.

AD3 - 22 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Outline

1 The End of Course AD2

2 Combinatorial OptimisationConstraint ProblemsSolving TechnologiesModellingSolving

3 Course AD3ContentsNew ConceptsLearning OutcomesOrganisation

AD3 - 23 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Example (Agricultural experiment design, AED)plot1 plot2 plot3 plot4 plot5 plot6 plot7

barley 3 3 3 – – – –corn 3 – – 3 3 – –

millet 3 – – – – 3 3oats – 3 – 3 – 3 –rye – 3 – – 3 – 3

spelt – – 3 3 – – 3wheat – – 3 – 3 3 –

Constraints to be satisfied:1 Equal growth load: Every plot grows 3 grains.2 Equal sample size: Every grain is grown in 3 plots.3 Balance: Every grain pair is grown in 1 common plot.

Instance: 7 plots, 7 grains, 3 grains/plot, 3 plots/grain, balance 1.

General term: balanced incomplete block design (BIBD).

AD3 - 24 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Example (Agricultural experiment design, AED)plot1 plot2 plot3 plot4 plot5 plot6 plot7

barley 1 1 1 0 0 0 0corn 1 0 0 1 1 0 0

millet 1 0 0 0 0 1 1oats 0 1 0 1 0 1 0rye 0 1 0 0 1 0 1

spelt 0 0 1 1 0 0 1wheat 0 0 1 0 1 1 0

Constraints to be satisfied:1 Equal growth load: Every plot grows 3 grains.2 Equal sample size: Every grain is grown in 3 plots.3 Balance: Every grain pair is grown in 1 common plot.

Instance: 7 plots, 7 grains, 3 grains/plot, 3 plots/grain, balance 1.

General term: balanced incomplete block design (BIBD).

AD3 - 24 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

In a BIBD, the plots are blocks and the grains are varieties:

Example (BIBD integer model: 3 1 and – 0)

-3 enum Varieties; enum Blocks;-2 int: blockSize; int: sampleSize; int: balance;-1 array[Varieties,Blocks] of var 0..1: BIBD;0 solve satisfy;1 constraint forall(b in Blocks)

(blockSize = count(BIBD[..,b], 1));2 constraint forall(v in Varieties)

(sampleSize = count(BIBD[v,..], 1));3 constraint forall(v, w in Varieties where v < w)

(balance = count([BIBD[v,b]*BIBD[w,b] | b in Blocks], 1));

Example (Instance data for our AED)

-3 Varieties = {barley,...,wheat}; Blocks = {plot1,...,plot7};-2 blockSize = 3; sampleSize = 3; balance = 1;

AD3 - 25 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Reconsider the model fragment:3 constraint forall(v, w in Varieties where v < w)

(balance = count([BIBD[v,b]*BIBD[w,b] | b in Blocks], 1));

This constraint is declarative (and by the way non-linear),so read it using only the verb “to be” or synonyms thereof:

for all two ordered varieties v and w,the count of blocks bwhose product BIBD[v,b] * BIBD[w,b] is 1must equal balance

The constraint is not procedural:for all two ordered varieties v and w,we first count the blocks bwhose product BIBD[v,b] * BIBD[w,b] is 1,and then we check if that count equals balance

The latter reading is appropriate for solution checking, butsolution finding performs no such procedural summation.

AD3 - 26 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Example (Idea for another BIBD model)barley {plot1,plot2,plot3

,plot4,plot5,plot6,plot7

}corn {plot1,

plot2,plot3,

plot4,plot5

,plot6,plot7

}millet {plot1,

plot2,plot3,plot4,plot5,

plot6,plot7}oats {

plot1,

plot2,

plot3,

plot4,

plot5,

plot6

,plot7

}rye {

plot1,

plot2,

plot3,plot4,

plot5,

plot6,

plot7}spelt {

plot1,plot2,

plot3,plot4,

plot5,plot6,

plot7}wheat {

plot1,plot2,

plot3,

plot4,

plot5,plot6

,plot7

}

Constraints to be satisfied:1 Equal growth load: Every plot grows 3 grains.2 Equal sample size: Every grain is grown in 3 plots.3 Balance: Every grain pair is grown in 1 common plot.

AD3 - 27 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Example (BIBD set model: a block set per variety)

-3 enum Varieties; enum Blocks;-2 int: blockSize; int: sampleSize; int: balance;-1 array[Varieties] of var set of Blocks: BIBD;0 solve satisfy;1 constraint forall(b in Blocks)

(blockSize = sum(v in Varieties)(b in BIBD[v]));2 constraint forall(v in Varieties)

(sampleSize = card(BIBD[v]));3 constraint forall(v, w in Varieties where v < w)

(balance = card(BIBD[v] intersect BIBD[w]));

Example (Instance data for our AED)

-3 Varieties = {barley,...,wheat}; Blocks = {plot1,...,plot7};-2 blockSize = 3; sampleSize = 3; balance = 1;

AD3 - 28 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Example (Doctor rostering)

Mon Tue Wed Thu Fri Sat SunDoctor ADoctor BDoctor CDoctor DDoctor E

Constraints to be satisfied:1 #doctors-on-call / day = 12 #operations / workday ≤ 23 #operations / week ≥ 74 #appointments / week ≥ 45 day off after operation day6 . . .

Objective function to be minimised:Cost: . . .

AD3 - 29 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Example (Doctor rostering)

Mon Tue Wed Thu Fri Sat SunDoctor A call none oper none oper none noneDoctor B app call none oper none none callDoctor C oper none call app app call noneDoctor D app oper none call oper none noneDoctor E oper none oper none call none none

Constraints to be satisfied:1 #doctors-on-call / day = 12 #operations / workday ≤ 23 #operations / week ≥ 74 #appointments / week ≥ 45 day off after operation day6 . . .

Objective function to be minimised:Cost: . . .

AD3 - 29 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Example (Doctor rostering)

-3 set of int: Days; % d mod 7 = 1 iff d is a Monday-2 enum Doctors;-1 enum ShiftTypes = {app, call, oper, none};0 array[Doctors,Days] of var ShiftTypes: Roster;1 solve minimize ...; % plug in an objective function2 constraint forall(d in Days)

(count(Roster[..,d],call) = 1);3 constraint forall(d in Days where d mod 7 in 1..5)

(count(Roster[..,d],oper) <= 2);4 constraint count(Roster,oper) >= 7;5 constraint count(Roster,app) >= 4;6 constraint forall(d in Doctors)

(regular(Roster[d,..], "((oper none)|app|call|none)*"));7 ... % other constraints

Example (Instance data for our hospital unit)

-3 Days = 1..7;-2 Doctors = {Dr_A, Dr_B, Dr_C, Dr_D, Dr_E};

AD3 - 30 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Example (Sudoku)

83 6

7 9 25 7

4 5 71 3

1 6 88 5 1

9 4

8 1 2 7 5 3 6 4 99 4 3 6 8 2 1 7 56 7 5 4 9 1 2 8 31 5 4 2 3 7 8 9 63 6 9 8 4 5 7 2 12 8 7 1 6 9 5 3 45 2 1 9 7 4 3 6 84 3 8 5 2 6 9 1 77 9 6 3 1 8 4 5 2

-2 array[1..9,1..9] of var 1..9: Sudoku;-1 ... % load the hints0 solve satisfy;1 constraint forall(row in 1..9)

(alldifferent(Sudoku[row,..]));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]));

AD3 - 31 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Modelling Languages

The following fully declarative modelling languages arepowerful enough to encode NP-hard problems:

Boolean satisfiability solving (SAT): satisfy a set ofdisjunctions of possibly negated Boolean variables.Mixed integer programming (MIP): satisfy a set oflinear equalities (=) and inequalities (<, ≤, ≥, >), butnot disequalities (6=), over real-number variables andinteger variables weighted by real-number constants,such that a linear objective function is optimised.SAT modulo theories (SMT) & constraint programming(CP) do not have such small standardised low-levelmodelling languages, but enable the higher level of theprevious sample models.+ In course 1DL451: Modelling, we use such higher-level models to drive CP, MIP, SAT, SMT, . . . solvers.

AD3 - 32 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Outline

1 The End of Course AD2

2 Combinatorial OptimisationConstraint ProblemsSolving TechnologiesModellingSolving

3 Course AD3ContentsNew ConceptsLearning OutcomesOrganisation

AD3 - 33 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Examples (Solving technologies)With general-purpose solvers, taking model&data as input:

Boolean satisfiability (SAT)SAT modulo theories (SMT)(Mixed) integer linear programming (IP & MIP)Constraint programming (CP). . .Hybrid technologies (LCG = CP + SAT, . . . )

Methodologies, usually without modelling and solvers:Dynamic programming (DP)Greedy algorithmsApproximation algorithmsStochastic local search (SLS)Genetic algorithms (GA). . .

AD3 - 34 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Examples (Solving technologies)With general-purpose solvers, taking model&data as input:

Boolean satisfiability (SAT) in AD3SAT modulo theories (SMT) in AD3(Mixed) integer linear programming (IP & MIP) in AD3Constraint programming (CP) in 1DL441: COCP. . .Hybrid technologies (LCG = CP + SAT, . . . )

Methodologies, usually without modelling and solvers:Dynamic programming (DP) in 1DL231: AD2Greedy algorithms in 1DL231: AD2Approximation algorithms in AD3Stochastic local search (SLS) in AD3Genetic algorithms (GA). . .

AD3 - 34 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Solvers

Black-box solvers (for SAT, SMT, IP, MIP, . . . )have general-purpose search + inference + relaxationthat is difficult to influence by the modeller.

+ AD3

Glass-box solvers (for CP, LCG, . . . )have general-purpose search + inference + relaxationthat is easy to influence, if desired, by the modeller.

+ 1DL441: COCP

Special-purpose solvers (for TSP, . . . )exist for pure problems (without side constraints).

AD3 - 35 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Correctness Is Not Enough for Models

AD3 - 36 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Modelling is an Art

There are good & bad models for each constraint problem:+ AD3 and 1DL451: Modelling

Different models of a problem may take different timeon the same solver for the same instance.

Different models of a problem may scale differentlyon the same solver for instances of growing size.

Different solvers may take different timeon the same instance on the same model.

Good modellers are worth their weight in gold!

Use solvers: based on decades of cutting-edge research,they are very hard to beat on exact solving.

AD3 - 37 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Outline

1 The End of Course AD2

2 Combinatorial OptimisationConstraint ProblemsSolving TechnologiesModellingSolving

3 Course AD3ContentsNew ConceptsLearning OutcomesOrganisation

AD3 - 38 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Outline

1 The End of Course AD2

2 Combinatorial OptimisationConstraint ProblemsSolving TechnologiesModellingSolving

3 Course AD3ContentsNew ConceptsLearning OutcomesOrganisation

AD3 - 39 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Common Thread: Coping with NP-Hardness

1 Mixed integer programming (MIP)2 Stochastic local search (SLS)3 Amortised analysis (CLRS3: Chapter 17)4 Probabilistic analysis (Chapter 5)5 Randomised algorithms: (Chapter 5)

universal hashing, . . . (Section 11.3.3)6 Proving NP-completeness by reduction (Chapter 34)7 Boolean satisfiability (SAT)8 SAT modulo theories (SMT)9 Approximation algorithms (Chapter 35)

CLRS3 Textbook:Introduction to Algorithms (3rd edition) (errata).T. H. Cormen, Ch. E. Leiserson, R. L. Rivest, and C. Stein.The MIT Press, 2009.

AD3 - 40 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Outline

1 The End of Course AD2

2 Combinatorial OptimisationConstraint ProblemsSolving TechnologiesModellingSolving

3 Course AD3ContentsNew ConceptsLearning OutcomesOrganisation

AD3 - 41 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

In a probabilistic algorithm analysis, we use probabilitytheory: knowing or assuming the distribution of the inputs,we compute the average-case time (as opposed to theworst-case time) of a deterministic algorithm.

ExampleThe brute-force string matching algorithm for finding alloccurrences of a pattern P of length m within a text T oflength n ≥ m takes O(n −m + 1) time on average when Pand T are random strings, but this is a completelyunreasonable assumption. (Chapter 32 in CLRS3)

Probabilistic analysis helps gain insight into a problem andhelps design an efficient algorithm for it, when we have areasonable assumption on the distribution of the inputs.

AD3 - 42 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

A randomised algorithm (as opposed to a deterministicalgorithm) itself makes random choices, independently ofthe actual distribution of the inputs. We refer to the time of arandomised algorithm as expected time (not: average time).

ExamplesA randomised algorithm by Karger-Klein-Tarjan (1993)computes in O(V + E) expected time a minimumspanning tree (MST) of a connected undirected graphwith vertex set V and edge set E . (Chapter 23)A randomised algorithm computes in O(m) expectedtime a prime number larger than m for fingerprinting inthe Rabin-Karp string matcher. (Chapter 32)

Many randomised algorithms have no worst-case input!

AD3 - 43 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

In an amortised analysis, we compute the worst-case timeof a chain of data-structure operations, and average it overthe operations. We refer to this time as an amortised time(as opposed to an average-case time, as no probability isused here, and the possibly non-tight worst-case time).

ExamplesA chain of m find-and-compress-paths or union-by-rankoperations on disjoint sets of n items takes O(m · lg∗ n)time, where lg∗ n ≤ 5 in practice. (Chapter 21)In a Fibonacci heap of n items, extracting a minimumtakes O(lg n) amortised time, and decreasing a keytakes O(1) amortised time. (Chapter 19; not in AD2)Prim’s MST algorithm takes at worst O(E + V lgV )time when using a Fibonacci heap. (Chapter 23)

AD3 - 44 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Dealing in polynomial time with (instances of) optimisationproblems where brute-force or exact solving is too costly:

A greedy algorithm builds a feasible solution variableby variable, making locally optimal choices in the hopeof reaching an optimal solution. Greedy algorithmsbuild either provably optimal solutions (for example,Prim’s MST algorithm and Dijkstra’s single-sourceshortest paths algorithm) or at-best optimal solutions.A local search algorithm repairs a possibly infeasiblecandidate solution, by reassigning some variables atevery iteration, until an allocated resource (such as aniteration count or a time budget) is exhausted, in thehope of reaching a feasible or even optimal solution.An approximation algorithm for an NP-hard problembuilds a feasible solution whose objective value isprovably within a known factor of the optimum.

All techniques are orthogonal: there exist randomised localsearch algorithms, greedy approximation algorithms, etc.

AD3 - 45 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Outline

1 The End of Course AD2

2 Combinatorial OptimisationConstraint ProblemsSolving TechnologiesModellingSolving

3 Course AD3ContentsNew ConceptsLearning OutcomesOrganisation

AD3 - 46 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

In order to pass, the student must be able to:

analyse NP-completeness of an algorithmic problem;

use advanced algorithm analysis methods, such asamortised analysis and probabilistic analysis;

use advanced algorithm design methods in order toapproach hard algorithmic problems in a pragmaticway, such as by using:• randomised algorithms: universal hashing, . . .• approximation algorithms• local search: simulated annealing, tabu search, . . .• mixed integer programming (MIP)• Boolean satisfiability (SAT)• SAT modulo theories (SMT)

present & discuss topics related to the course contentorally and in writing with a skill appropriate for the levelof education + written reports & oral presentation!

AD3 - 47 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Outline

1 The End of Course AD2

2 Combinatorial OptimisationConstraint ProblemsSolving TechnologiesModellingSolving

3 Course AD3ContentsNew ConceptsLearning OutcomesOrganisation

AD3 - 48 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Course Organisation & Time Budget

Period 3: January to March, budget = 133.3 hours:

1 presentation, by student-chosen duo team on examtopic of their choice: budget = 15 h / student (pass / fail)

12 lectures, including a mandatory guest lecture,plus 3 mandatory student-led presentation sessionson exam topics: budget = 21 hours

2 assignments with 3 help sessions, 1 grading session,1 solution session per assignment, on 2 problems eachon non-exam topics, by student-chosen duo team:budget = avg 30 hours / assignment / student (2 credits)

1 written closed-book exam of 3 hours,to be done alone: budget = 37.3 hours (3 credits)

Prerequisites: Algorithms & Data Structures 2 (AD2)(course 1DL231) or equivalent

AD3 - 49 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Examination

Modelling / programming, experimenting, and reporting:

Mixed integer programming (MIP): Assignment 1

Stochastic local search (SLS): Assignment 1

Boolean satisfiability (SAT): Assignment 2

SAT modulo theories (SMT): Assignment 2

Exercises drawn from a published list of exam questions:

Amortised analysis and probabilistic analysis: exam

Randomised algorithms: exam

NP-completeness: 50% threshold at exam

Approximation algorithms: exam

AD3 - 50 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

2 Assignment Cycles of 3 Weeks

Let Di be the deadline of Assignment i , with i ∈ 1..2:

Di − 16: publication & all needed material taught: start!

Di − 14: help session a: attendance recommended

Di − 7: help session b: attendance recommended

Di − 2: help session c: attendance recommended

Di ± 0: submission, by 13:00 Swedish time on a Friday

Di + 4 by 16:00: initial score aij ∈ 0..5 pointsfor each Problem j of Assignment i , with j ∈ 1..2

Di + 5: teamwise oral grading session on Problems jfor some aij ∈ {1,2}: possibility of earning 1 extra pointfor final score; otherwise final score = initial score

Di + 5 = Di+1 − 14: solution session & help session a

AD3 - 51 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

2 Assignment Credits & Overall Influence

Let aij be final score on Problem j of Asgmt i , with i , j ∈ 1..2:

20% threshold: ∀i , j ∈ 1..2 : aij ≥ 20% · 5 = 1No catastrophic failure on individual problems

30% threshold: ∀i : ai = ai1 + ai2 ≥ 30% · (5 + 5) = 3Can offset partial failure on problems or assignments

50% threshold: a = a1 + a2 ≥ 50% · 2 · (5 + 5) = 10The formula for grades 3..5 is at the course homepage

Worth going full-blast: The assignment score a ismeshed with the exam score e in order to determinethe overall course grade in 3..5 , if 10 ≤ a ≤ 20 and10 ≤ e ≤ 20; see the formula at the course homepage

AD3 - 52 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Caution!

There is a huge jump from AD2 (or equivalent)— with its mostly (pseudo-)polytime algorithms —to AD3, where only NP-hard problems are considered.

Especially the MIP, SAT, and SMT modellingare totally unlike anything most of you have ever seen,and this takes time to wrap one’s head around.

Ease or success with the assignments in AD2 does notimply the same ease or the same level of success withthe assignments in AD3: the help sessions are stronglyrecommended, and there is almost no internet help.

AD3 - 53 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Presentation

Topic:

Propose a well-cited, well-published, & peer-reviewedacademic paper on an algorithm or a data structureor an NP-completeness / hardness reductionwithin the exam topics of this course.

Ask us, if need be.

Deadlines:

Thu 27 Feb 2020 by 13:00: upload topic proposal

Wed 04 Mar 2020 by 17:00: secure topic approval

Wed 11 Mar 2020: present and upload slides by 18:00

The length & order of presentations will be fixed in due time.

AD3 - 54 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

Assignment and Presentation Rules

Register teams by Sun 26 Jan at 23:59 at Student Portal:Duo teams: Two consenting partners sign up at portalSolo teams: Apply to head teacher, who rarely agreesRandom partner? Assent to TA, else you’re bounced

Other considerations:Why (not) like this? Why no email reply? See FAQsPartner swapping: Allowed, but to be declared to TAPartner scores may differ if no-show or passivityNo freeloader: Implicit honour declaration in reportsthat each partner can individually explain everything;random checks will be made by usNo plagiarism: Implicit honour declaration in reports;extremely powerful detection tools will be used by us;suspected cases of using or providing will be reported

AD3 - 55 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

How To Communicate by Email?

To email the assistant or the head teacher:

If you have a question about the lecture materialor course organisation, then contact the headteacher. An immediate answer will be given right beforeand after lectures, as well as during their breaks.

If you have a question about the assignmentsor infrastructure, then contact the assistant at a helpor solution session for an immediate answer; shortclarification questions (that is: not about modelling orprogramming issues) that are emailed to the assistantand trigger short reply times are answered as soon aspossible during working days and hours; no answermeans that you should go to a help session:almost all the assistant’s budgeted time is allocated tograding and to the help, grading, and solution sessions.

AD3 - 56 -

The End ofCourse AD2

CombinatorialOptimisationConstraint Problems

Solving Technologies

Modelling

Solving

Course AD3Contents

New Concepts

Learning Outcomes

Organisation

What Has Changed Since Last Time?

Changes triggered by the previous course evaluation:

Assignment 1, Problem 2: a skeleton code is provided.

Guidelines for the presentations are provided.

Changes also wanted by the head teacher and assistant:

Assignment 1: order of Problems 1 and 2 is inverted.

The skeleton codes are c©opyrighted: never publish!

AD3 - 57 -