+ All Categories
Home > Documents > Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real...

Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real...

Date post: 02-Jun-2020
Category:
Upload: others
View: 8 times
Download: 0 times
Share this document with a friend
62
Integer Linear Programming [email protected] HTTP://BLOG.ADAMFURMANEK.PL @FURMANEKADAM
Transcript
Page 1: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Integer Linear [email protected]

HT TP://BLOG.ADAMFURMANEK.PL

@FURMANEKADAM

Page 2: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

About me

.NET developer for 5 years.

Scala Developer at Amazon.

Blogger, public speaker.

Author of .NET Internals Cookbook.

http://blog.adamfurmanek.pl

[email protected]

furmanekadam

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 2

Page 3: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

AgendaDeclarative programming at a glance.

Some theory.

Real life example.

Implementation consideration.

Summary.

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 3

Page 4: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Declarative programming

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 4

Page 5: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Declarative programmingParadigm that expresses the logic of a computation without describing its control flow.

Declarative programming often considers programs as theories of a formal logic, and computations as deductions in that logic space.

A high-level program that describes what a computation should perform.

SELECT * FROM Orders

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 5

Page 6: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Declarative programming β€” why?Decouples problem formulation from solving process.

Solving part can be replaced without modifying the formulation.

Easier to optimise algorithms for because β€žthe goal” is understandable for the machine.

Can be used with little to no programming skills.

Sometimes we don’t know how to solve it.

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 6

Page 7: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Example β€” RTS gameWe are playing RTS game.

We are allowed to hire footmen and archers.

Every footman costs 10 gold and 30 food. Every archer costs 20 gold, 25 food, and 10 wood.

Footman’s attack is equal to 5, archer’s attack is equal to 7.

Our population limit is set to 200 units. Every footman β€žcosts” 1 unit, every archer β€žcosts” 2 units.

We have 1000 gold, 1000 food, and 200 wood. We want to get strongest possible army.

07.02.2020 09:11 ADAM FURMANEK 7

Page 8: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

UnitsGold Food Wood

Footman 10 30 0

Archer 20 25 10

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 8

Attack Unit count

Footman 5 1

Archer 7 2

Available gold Available food Available wood Max units count

Constraint 1000 1000 200 200

Page 9: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

VariablesVariables:

𝑓 βˆ’ π‘“π‘œπ‘œπ‘‘π‘šπ‘’π‘›π‘Ž βˆ’ π‘Žπ‘Ÿπ‘β„Žπ‘’π‘Ÿπ‘ 

Constraints:

𝑓 + 2 β‹… π‘Ž ≀ 200 // population10 β‹… 𝑓 + 20 β‹… π‘Ž ≀ 1000 // gold30 β‹… 𝑓 + 25 β‹… π‘Ž ≀ 1000 // food

10 β‹… π‘Ž ≀ 200 // wood

Target value:5 β‹… 𝑓 + 7 β‹… π‘Ž

07.02.2020 09:11 ADAM FURMANEK 9

Page 10: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 10

Page 11: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Example

07.02.2020 09:11 ADAM FURMANEK 11

Page 12: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Example

07.02.2020 09:11 ADAM FURMANEK 12

Page 13: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

ExampleVariables:

𝑆, 𝐸, 𝑁, 𝐷,𝑀, 𝑂, 𝑅, π‘Œ ∈ 0,… , 9 and all different

Constraints:1000𝑆 + 100𝐸 + 10𝑁 + 𝐷 +1000𝑀 + 100𝑂 + 10𝑅 + 𝐸 =10000𝑀 + 1000𝑂 + 100𝑁 + 10𝐸 + π‘Œ

07.02.2020 09:11 ADAM FURMANEK 13

Page 14: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Example

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 14

Page 15: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Real life examplesRTS game = factory production allocation:

β—¦ We have available resources

β—¦ We have facitilies

β—¦ We want to plan work to maximize the production

Send more money = pattern recognition:β—¦ We know structure of a problem but doesn’t understand the latent factors

Floor tiling = microchip transistor layout:β—¦ We have transistors and gates of given size

β—¦ We want to minimize heat emission and the board size

Others: BTS placement, power plant rooms layout, scheduling systems, items personalization and many more.

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 15

Page 16: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Some theoryMIXED INTEGER LINEAR PROGRAMMING

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 16

Page 17: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 17

Page 18: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Mixed Integer Linear ProgrammingProgramming in mathematics means finding a solution to optimization problem.

Linear Programming is a class of a problems with only linear constraints and with linear cost function.

Mixed Integer Linear Programming is a class of a problems with integer constraint for some of variables.

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 18

Page 19: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

ConstraintsWe can add two variables:

π‘Ž + 𝑏

We can multiply variable by constant:

5 β‹… π‘Ž

We can constrain variable with lower/upper bound:

π‘Ž ≀ 7

We cannot multiply variables:π‘Ž β‹… 𝑏

We cannot use strict constraings (greater than, less than, not equal)

π‘Ž < 10

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 19

Page 20: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Cost functionNotice that not hiring anyone was also a solution!

Problem may have zero, one, multiple or infinitely many solutions. We need to compare them.

We use cost function to specify which one of them is the best.

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 20

Page 21: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Cutting plane method

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 21

Page 22: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

AlgorithmsBasic algorithms:β—¦ Cutting plane methods – we solve the problem without integer constraints

(continuous version of the problem), and next we cut the plane to get smaller problem

β—¦ Branch and bound – we solve the problem without integer constraints, and next we bound some variables and perform next iteration

MILP is NP-complete and we sometimes use heuristics:β—¦ Tabu search

β—¦ Simulated annealing

β—¦ Ant colony optimization

07.02.2020 09:11 ADAM FURMANEK 22

Page 23: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

What can we do?WE WILL IMPLEMENT

Boole’s logic.

Multiplication.

Comparison operators.

WE WILL NOT IMPLEMENT

Arithmetic: division, remainder, exponentation, roots.

Comparisons: min, max, absolute value.

Number theory: factorial, GCD.

Algorithms: if condition, sorting, loops, lexicographical comparisons, Gray’s code, linear regression.

Set operators: SOS type 1 and 2, approximation.

Graph operators: MST, vertex/edge cover, max flow, connectivity, shortest path, TSP.

Turing machine.

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 23

Page 24: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Conjunction β€” AND operator (&&)

We have two variables: π‘Ž, 𝑏.

We want to create variable π‘₯ which is π‘₯ = π‘Ž && 𝑏.

Formula:

0 ≀ π‘Ž + 𝑏 βˆ’ 2π‘₯ ≀ 1

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 24

Page 25: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Conjunction β€” AND operator (&&)

If both π‘Ž and 𝑏 are 1 then π‘₯ must be 1.

If π‘₯ was 0:

0 ≀ 1 + 1 βˆ’ 2 β‹… 0 ≀ 1

0 ≀ 2 βˆ’ 0 ≀ 1

0 ≀ 2 ≀ 1

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 25

0 ≀ π‘Ž + 𝑏 βˆ’ 2π‘₯ ≀ 1

Page 26: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Conjunction β€” AND operator (&&)

If both π‘Ž and 𝑏 are 1 then π‘₯ must be 1.

If π‘₯ is 1:

0 ≀ 1 + 1 βˆ’ 2 β‹… 1 ≀ 1

0 ≀ 2 βˆ’ 2 ≀ 1

0 ≀ 0 ≀ 1

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 26

0 ≀ π‘Ž + 𝑏 βˆ’ 2π‘₯ ≀ 1

Page 27: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Conjunction β€” AND operator (&&)

If either π‘Ž or 𝑏 is 1 then π‘₯ must be 0.

If π‘₯ was 1:

0 ≀ 1 + 0 βˆ’ 2 β‹… 1 ≀ 1

0 ≀ 1 βˆ’ 2 ≀ 1

0 ≀ βˆ’1 ≀ 1

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 27

0 ≀ π‘Ž + 𝑏 βˆ’ 2π‘₯ ≀ 1

Page 28: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Conjunction β€” AND operator (&&)

If either π‘Ž or 𝑏 is 1 then π‘₯ must be 0.

If π‘₯ is 0:

0 ≀ 1 + 0 βˆ’ 2 β‹… 0 ≀ 1

0 ≀ 1 βˆ’ 0 ≀ 1

0 ≀ 1 ≀ 1

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 28

0 ≀ π‘Ž + 𝑏 βˆ’ 2π‘₯ ≀ 1

Page 29: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Conjunction β€” AND operator (&&)

If both π‘Ž or 𝑏 are 0 then π‘₯ must be 0.

If π‘₯ was 1:

0 ≀ 0 + 0 βˆ’ 2 β‹… 1 ≀ 1

0 ≀ 0 βˆ’ 2 ≀ 1

0 ≀ βˆ’2 ≀ 1

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 29

0 ≀ π‘Ž + 𝑏 βˆ’ 2π‘₯ ≀ 1

Page 30: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Conjunction β€” AND operator (&&)

If both π‘Ž or 𝑏 are 0 then π‘₯ must be 0.

If π‘₯ is 0:

0 ≀ 0 + 0 βˆ’ 2 β‹… 0 ≀ 1

0 ≀ 0 βˆ’ 0 ≀ 1

0 ≀ 0 ≀ 1

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 30

0 ≀ π‘Ž + 𝑏 βˆ’ 2π‘₯ ≀ 1

Page 31: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Conjunction β€” AND operator (&&)

If both π‘Ž and 𝑏 are 1 then π‘₯ must be 1.

If either π‘Ž or 𝑏 is 1 then π‘₯ must be 0.

If both π‘Ž or 𝑏 are 0 then π‘₯ must be 0.

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 31

0 ≀ π‘Ž + 𝑏 βˆ’ 2π‘₯ ≀ 1

Page 32: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Conjunction & DisjunctionTwo variables conjunction:

0 ≀ π‘Ž + 𝑏 βˆ’ 2π‘₯ ≀ 1

𝑛 variables conjunction:0 ≀ π‘Ž1 + π‘Ž2 + π‘Ž3 + …+ π‘Žπ‘› βˆ’ 𝑛π‘₯ ≀ 𝑛 βˆ’ 1

Two variables disjunction:βˆ’1 ≀ π‘Ž + 𝑏 βˆ’ 2π‘₯ ≀ 0

𝑛 variables disjunction goes the same way

07.02.2020 09:11 ADAM FURMANEK 32

Page 33: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Negation, exclusive or, implication

Negation:π‘₯ = 1 βˆ’ π‘Ž

Implication:π‘Ž β‡’ 𝑏 ≑ ~π‘Ž ∨ 𝑏

Exclusive or:~π‘Ž ∧ 𝑏 ∨ (π‘Ž ∧ ~𝑏)

07.02.2020 09:11 ADAM FURMANEK 33

Page 34: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 34

Multiplication of two binary variables is their conjunction.

π‘Ž β‹… 𝑏 ≑ π‘Ž ∧ 𝑏

Page 35: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Multiplication of integer variablesMultiplication is possible when we know the maximum possible value of a variable.

We set the upper bound and perform the long multiplication.

It is rather slow approach, it requires 𝑂(𝑛2) temporary variables.

07.02.2020 09:11 ADAM FURMANEK 35

Page 36: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Value decompositionWe decompose the variable to extract digits.

We assume the maximum possible value, because we need to know the number of digits.

Decomposition is straghtforward:

𝑏 = 𝑏0 + 2 β‹… 𝑏1 + 4 β‹… 𝑏2 + 8 β‹… 𝑏3 + …+ 2π‘›βˆ’1 β‹… π‘π‘›βˆ’1

07.02.2020 09:11 ADAM FURMANEK 36

Page 37: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 37

Page 38: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 38

Page 39: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Multiplicationπ‘Ž β‹… 𝑏 =π‘Ž0 ∧ 𝑏0 + 2 β‹… π‘Ž0 ∧ b1 + 4 β‹… a0 ∧ 𝑏2 + …+ 2π‘›βˆ’1 β‹… π‘Ž0 ∧ π‘π‘›βˆ’1

+2 β‹… π‘Ž1 ∧ 𝑏0 + 2 β‹… π‘Ž1 ∧ 𝑏1 + 4 β‹… π‘Ž1 ∧ 𝑏2 +β‹―2π‘›βˆ’1 β‹… (π‘Ž1 ∧ π‘π‘›βˆ’1)+4 β‹… π‘Ž2 ∧ 𝑏0 + 2 β‹… π‘Ž2 ∧ 𝑏1 + 4 β‹… π‘Ž2 ∧ 𝑏2 + …+ 2π‘›βˆ’1 β‹… π‘Ž2 ∧ bnβˆ’1+β‹―+ 2π‘›βˆ’1( π‘Žπ‘›βˆ’1 ∧ 𝑏0 + 2 β‹… π‘Žπ‘›βˆ’1 ∧ 𝑏1 + 4 β‹… π‘Žπ‘›βˆ’1 ∧ 𝑏2 + …+ 2π‘›βˆ’1 β‹… π‘Žπ‘›βˆ’1 ∧ π‘π‘›βˆ’1 )

It can be represented as:

π‘Ž β‹… 𝑏 =

𝑖=0

π‘›βˆ’1

2𝑖

𝑗=0

π‘›βˆ’1

2π‘—π‘Žπ‘– ∧ 𝑏𝑗

07.02.2020 09:11 ADAM FURMANEK 39

Page 40: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Comparison operators

To calculate whether π‘Ž > 𝑏 we can use:

0 ≀ 𝑏 βˆ’ π‘Ž + 2π‘›βˆ’1π‘₯ ≀ 2π‘›βˆ’1 βˆ’ 1

To check whether numbers differ:π‘₯ = π‘Ž > 𝑏 ∨ (𝑏 > π‘Ž)

07.02.2020 09:11 ADAM FURMANEK 40

Page 41: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

There are libraries doing that!

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 41

https://github.com/afish/MilpManager

Page 42: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Scheduling SystemREAL LIFE EXAMPLE

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 42

Page 43: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

IdeaAt the beginning of every term students must be assigned to classes.

It is hard to make them happy because some of them work, some of them prefer to sleep long, some of them prefer to have lots of days off.

We can try to represent the requirements as a MILP program and find the optimal solution.

07.02.2020 09:11 ADAM FURMANEK 43

Page 44: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

UsageWe ask students to assign preferences points to every possible class.

The more points assigned the more student wants to be assigned to that class.

We need to take care of rooms occupancy limits, collisions etc.

07.02.2020 09:11 ADAM FURMANEK 44

Page 45: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

ScheduleWe are given a schedule of classes in courses

Every class has associated day (Monday – Friday), hour (e.g., 9:30 AM) and duration (e.g., 1:30 hrs).

Every class has associated room with occupancy limit.

07.02.2020 09:11 ADAM FURMANEK 45

Page 46: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

ConstraintsVariables.

Exactly one class in one course.

Collisions.

Rooms occupancy limits.

Cost function.

07.02.2020 09:11 ADAM FURMANEK 46

Page 47: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

VariablesFor every person, every course, every class we declare binary variable.

Value 1 means that the student is assigned to this class.

We define:π‘₯π‘π‘œπ‘’π‘Ÿπ‘ π‘’,π‘π‘™π‘Žπ‘ π‘ ,𝑠𝑑𝑒𝑑𝑒𝑛𝑑

07.02.2020 09:11 ADAM FURMANEK 47

Page 48: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Exactly one class for a studentEvery student must attend exactly one class in course.

For every course we need to assign student to exactly one class.

αˆ₯

π‘π‘œπ‘’π‘Ÿπ‘ π‘’,𝑠𝑑𝑒𝑑𝑒𝑛𝑑

π‘π‘™π‘Žπ‘ π‘ 

π‘₯π‘π‘œπ‘’π‘Ÿπ‘ π‘’,π‘π‘™π‘Žπ‘ π‘ ,𝑠𝑑𝑒𝑑𝑒𝑛𝑑 = 1

07.02.2020 09:11 ADAM FURMANEK 48

Page 49: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

CollisionsStudent cannot be in two places at the same time.

αˆ₯ π‘π‘œπ‘’π‘Ÿπ‘ π‘’1, π‘π‘™π‘Žπ‘ π‘ 1 , π‘π‘œπ‘’π‘Ÿπ‘ π‘’2, π‘π‘™π‘Žπ‘ π‘ 2 π‘π‘œπ‘™π‘™π‘–π‘‘π‘–π‘›π‘”

αˆ₯

𝑠𝑑𝑒𝑑𝑒𝑛𝑑

π‘₯π‘π‘œπ‘’π‘Ÿπ‘ π‘’1,π‘π‘™π‘Žπ‘ π‘ 1,𝑠𝑑𝑒𝑑𝑒𝑛𝑑 + π‘₯π‘π‘œπ‘’π‘Ÿπ‘ π‘’2,π‘π‘™π‘Žπ‘ π‘ 2,𝑠𝑑𝑒𝑑𝑒𝑛𝑑 ≀ 1

07.02.2020 09:11 ADAM FURMANEK 49

Page 50: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Room occupancy limitEvery room has an occupancy limit.

αˆ₯

π‘π‘œπ‘’π‘Ÿπ‘ π‘’,π‘π‘™π‘Žπ‘ π‘ 

𝑠𝑑𝑒𝑑𝑒𝑛𝑑

π‘₯π‘π‘œπ‘’π‘Ÿπ‘ π‘’,π‘π‘™π‘Žπ‘ π‘ ,𝑠𝑑𝑒𝑑𝑒𝑛𝑑 ≀ π‘ π‘π‘œπ‘’π‘Ÿπ‘ π‘’,π‘π‘™π‘Žπ‘ π‘ 

where π‘ π‘π‘œπ‘’π‘Ÿπ‘ π‘’,π‘π‘™π‘Žπ‘ π‘  means the size of the room

07.02.2020 09:11 ADAM FURMANEK 50

Page 51: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Preferences cost functionEvery student assigned points to classes. We want to maximize the sum of those points.

π‘π‘œπ‘’π‘Ÿπ‘ π‘’,π‘π‘™π‘Žπ‘ π‘ ,𝑠𝑑𝑒𝑑𝑒𝑛𝑑

π‘π‘π‘œπ‘’π‘Ÿπ‘ π‘’,π‘π‘™π‘Žπ‘ π‘ ,𝑠𝑑𝑒𝑑𝑒𝑛𝑑 β‹… π‘₯π‘π‘œπ‘’π‘Ÿπ‘ π‘’,π‘π‘™π‘Žπ‘ π‘ ,𝑠𝑑𝑒𝑑𝑒𝑛𝑑

where π‘π‘π‘œπ‘’π‘Ÿπ‘ π‘’,π‘π‘™π‘Žπ‘ π‘ ,𝑠𝑑𝑒𝑑𝑒𝑛𝑑 means number of points

07.02.2020 09:11 ADAM FURMANEK 51

Page 52: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

What now?Students: 150

Courses: 15

Classes: 9 per course

Problem size: ~40 000 variables.

Solving time: 2 seconds.

This solution is optimal, we won’t get any better than that!

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 52

Page 53: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Implementation consideration

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 53

Page 54: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 54

Page 55: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Licenses

Various approaches:β—¦License per workstationβ—¦License per personβ—¦Licensing server with tickets

Licenses for universities and research work.

Licenses for students.

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 55

Page 56: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 56

Page 57: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 57

https://neos-server.org/neos/solvers/index.html

Page 58: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Beyond MILP

SAT/SMT.

Quadratic programming.

Prolog.

Specialized models for various problems.

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 58

Page 59: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

SummaryDeclarative programming allows you to focus on a problem, not on an algorithm!

If something is slow β€” just replace the solver.

There are many models, choose as powerful as you can (to make modelling easy) and as primitive as possible (to make solving fast).

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 59

Page 60: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

Q&A

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 60

Page 61: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

ReferencesAlexander Schrijver β€” β€žTheory of Linear and Integer Programming”

Dennis Yurichev β€” β€žSAT/SMT by example”

Adam Furmanek – β€ž.NET Internals Cookbook”

http://blog.adamfurmanek.pl/2015/08/22/ilp-part-1/ β€” a lot about ILP

https://github.com/afish/MilpManager β€” library for modelling

https://neos-server.org/neos/solvers/index.html β€” NEOS cloud for solving problems

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 61

Page 62: Integer Linear Programming - Adam Furmanek...Declarative programming at a glance. Some theory. Real life example. Implementation consideration. Summary. 07.02.2020 INTEGER LINEAR PROGRAMMING,

[email protected]

HT TP://BLOG.ADAMFURMANEK.PL

@FURMANEKADAM

07.02.2020 INTEGER LINEAR PROGRAMMING, ADAM FURMANEK 62


Recommended