Automatic Conference Scheduling with PuLP EuroPython 2017 - - PowerPoint PPT Presentation

automatic conference scheduling with pulp
SMART_READER_LITE
LIVE PREVIEW

Automatic Conference Scheduling with PuLP EuroPython 2017 - - PowerPoint PPT Presentation

Automatic Conference Scheduling with PuLP EuroPython 2017 EuroPython 2017 Rimini, Italy Rimini, Italy Marc-Andr Lemburg :: eGenix.com GmbH (c) 2017 eGenix.com Software, Skills and Services GmbH, info@egenix.com Speaker Introduction


slide-1
SLIDE 1

(c) 2017 eGenix.com Software, Skills and Services GmbH, info@egenix.com

EuroPython 2017 EuroPython 2017 Rimini, Italy Rimini, Italy

Marc-André Lemburg :: eGenix.com GmbH

Automatic Conference Scheduling with PuLP

slide-2
SLIDE 2

2:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Speaker Introduction

Marc-André Lemburg

– Python since 1994 – Studied Mathematics – eGenix.com GmbH – Senior Software Architect – Consultant / Trainer – Python Core Developer – EuroPython Society – Python Software Foundation – Based in Düsseldorf, Germany

slide-3
SLIDE 3

3:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Linear Programming

  • Term from “Operations Research” in mathematics

– “Programming” means: find an optimal solution for a planing problem – “Linear”, because only linear relationships are addressed, e.g. y = a*x + b

  • Careful:

– Problem usually easy to understand – Finding solutions can be very hard

slide-4
SLIDE 4

4:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Linear Programming

  • Integer Programming

– Additional restriction: values may only be integers, not floats – In practice: often a mix of linear + integer programming – Often: exponential runtime

  • Examples

– Knapsack problem – Traveling salesman problem – Project optimization (dependencies, resources) – Conference Scheduling

slide-5
SLIDE 5

5:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Linear Programming

  • Mathematics

– Variables: x1, x2, …, xn (float or integer) – Linear target function (objective) – Rules for valid solutions (constraints) of the form: with constants ai and b – Goal: find an (optimal) solution x, which fulfills all constraints and minimizes (or maximizes) the objective

slide-6
SLIDE 6

6:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

PuLP: A COIN-OR project

  • COIN-OR

– Library for operations research – PuLP is a Python Interface for the LP part of COIN-OR – COIN-OR comes with a few LP solvers – http://www.coin-or.org/

  • PuLP – LP Solver Front-End

– Standardized interface for LP solvers – Comes with a slow solver (great for development) – Faster: GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI – https://projects.coin-or.org/PuLP

slide-7
SLIDE 7

7:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

PuLP: Datatypes

  • LpProblem

– Defines the LP problem – Holds the constraints and objective function – Interface to the LP Solver (external)

  • LpVariable

– Abstracts an LP variable (with name) – Values will be changed by the solver – Float or integer – Defines the permitted variable value range

slide-8
SLIDE 8

8:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

PuLP: Datatypes

  • LpConstraint – Constraint rule

– Form: affine function OP numeric term OP can be one of: <=, =, >= – Can have a name (for debugging)

… some more (e.g. elastic constraints)

slide-9
SLIDE 9

9:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

PuLP: Documentation

  • Not that great :-(

– Package documentation: https://pythonhosted.org/PuLP/index.html Incomplete, misses details. – Source code: https://github.com/coin-or/pulp/blob/master/src/pulp/ – Some blog posts:

https://scaron.info/blog/linear-programming-in-python-with-pulp.html http://benalexkeen.com/linear-programming-with-python-and-pulp/

slide-10
SLIDE 10

10:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

PuLP: Example Conference Scheduling

  • Inspiration:

– Talk from David MacIver at PyCon UK 2016 https://www.youtube.com/watch?v=OkusHEBOhmQ

  • Use case:

– Help with scheduling EuroPython 2017 or later

slide-11
SLIDE 11

11:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

PuLP: Example Conference Scheduling

  • Goal:

– Simplify scheduling – Optimize speaker (and attendee) satisfaction

  • Constraints:

– Multiple rooms of different sizes – Talk slots of varying lengths (e.g. 30min / 45min) – Talks with varying lengths – Speakers cannot give two talks at the same time – Speakers may have availability constraints

slide-12
SLIDE 12

12:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Conference data: rooms and talks

slide-13
SLIDE 13

13:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Conference data: talk slots

slide-14
SLIDE 14

14:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

LP problem and variables

slide-15
SLIDE 15

15:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Constraints for talk slots Only assign one talk per slot

slide-16
SLIDE 16

16:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Constraints for talks We need to assign all talks Talks must fit the talk slots

slide-17
SLIDE 17

17:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Special constraints Speaker not always available

slide-18
SLIDE 18

18:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

More problems: How to prevent overlaps Different slots per room More than one talk per speaker

slide-19
SLIDE 19

19:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

More problems: How to prevent overlaps

slide-20
SLIDE 20

20:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Solution: Divide slots into smaller standard blocks Add new variables

slide-21
SLIDE 21

21:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Solution: Define some helper mappings

slide-22
SLIDE 22

22:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Solution: Link slots and blocks

slide-23
SLIDE 23

23:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Constraint: More than one talk per speaker Using blocks, you can now define the constraint:

slide-24
SLIDE 24

24:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Finally: Define objective function & run solver

slide-25
SLIDE 25

25:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Show the result

slide-26
SLIDE 26

26:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Show the result: Raw data

slide-27
SLIDE 27

27:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Show the result: As Schedule

slide-28
SLIDE 28

28:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

More possibilities

  • Use room capacities and attendee preferences
  • Add tracks:

Group talks by topic (preferably in a single room)

  • When having to apply changes after publication of the schedule (new

constraints, speaker cancellations): Minimize changes

slide-29
SLIDE 29

29:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Difficulty: Finding a suitable model

  • LP only supports linear combinations

– Constraints of the form xi * xj are not supported – Dynamic dependencies are hard to model – “Programming” is declarative (as in e.g. SQL), not imperative (as in e.g. Python)

  • Models have great influence on runtime
slide-30
SLIDE 30

30:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

PuLP: Summary of gotchas

  • LpVariable var doesn’t always behave like a Python number

– LpBinary variables can assume values outside their valid value range {0, 1} during solving better: test for (var > 0) – if var: is always true, when not running in the solver better: if pulp.value(var):

  • LpProblem can fail to deliver a result

– assert problem.status == 1

  • Conclusion: Always test your solver !
slide-31
SLIDE 31

31:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Faster than PuLP

  • CVXOPT - Python software for convex optimization

– http://cvxopt.org/ – Uses a different API than PuLP – Much better documentation – Up to 10-70x faster than PuLP

https://scaron.info/blog/linear-programming-in-python-with-cvxopt.html

  • CVXPY - Python-embedded modeling language for convex optimization

problems

– http://www.cvxpy.org/

  • PICOS - Python Interface for conic optimization solvers

– http://picos.zib.de/

slide-32
SLIDE 32

32:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Conference scheduling using Python

  • PyCon UK: Conference Scheduler

– https://github.com/PyconUK/ConferenceScheduler – Documentation: http://conference-scheduler.readthedocs.io/ – Fairly new: only 2 months old – Uses PuLP, completely automated

  • Alexander tried to use it for EuroPython 2017:

failed due to exponential runtime

slide-33
SLIDE 33

33:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Conference scheduling using Python

  • EuroPython 2017 Scheduler

– Written by Alexander Hendorf – Doesn’t use PuLP, but a similar model to the PyCon UK one – Works based on clustering + random shuffling + human touch

slide-34
SLIDE 34

34:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Thank you for your attention !

Beautiful is better than ugly.

slide-35
SLIDE 35

35:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Contact

eGenix.com m So Software, Skills s and Se Serv rvices s GmbH Marc-André Lemburg Pastor-Löh-Str. 48 D-40764 Langenfeld Germany eMail: mal@egenix.com Phone: +49 211 9304112 Fax: +49 211 3005250 Web: http://www.egenix.com/

slide-36
SLIDE 36

(c) 2017 eGenix.com Software, Skills and Services GmbH, info@egenix.com

EuroPython 2017 EuroPython 2017 Rimini, Italy Rimini, Italy

Marc-André Lemburg :: eGenix.com GmbH

Automatic Conference Scheduling with PuLP

slide-37
SLIDE 37

2:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Speaker Introduction

Marc-André Lemburg

– Python since 1994 – Studied Mathematics – eGenix.com GmbH – Senior Software Architect – Consultant / Trainer – Python Core Developer – EuroPython Society – Python Software Foundation – Based in Düsseldorf, Germany

slide-38
SLIDE 38

3:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Linear Programming

  • Term from “Operations Research” in mathematics

– “Programming” means: find an optimal solution for a planing problem – “Linear”, because only linear relationships are addressed, e.g. y = a*x + b

  • Careful:

– Problem usually easy to understand – Finding solutions can be very hard

slide-39
SLIDE 39

4:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Linear Programming

  • Integer Programming

– Additional restriction: values may only be integers, not floats – In practice: often a mix of linear + integer programming – Often: exponential runtime

  • Examples

– Knapsack problem – Traveling salesman problem – Project optimization (dependencies, resources) – Conference Scheduling

slide-40
SLIDE 40

5:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Linear Programming

  • Mathematics

– Variables: x1, x2, …, xn (float or integer) – Linear target function (objective) – Rules for valid solutions (constraints) of the form: with constants ai and b – Goal: find an (optimal) solution x, which fulfills all constraints and minimizes (or maximizes) the objective

slide-41
SLIDE 41

6:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

PuLP: A COIN-OR project

  • COIN-OR

– Library for operations research – PuLP is a Python Interface for the LP part of COIN-OR – COIN-OR comes with a few LP solvers – http://www.coin-or.org/

  • PuLP – LP Solver Front-End

– Standardized interface for LP solvers – Comes with a slow solver (great for development) – Faster: GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI – https://projects.coin-or.org/PuLP

slide-42
SLIDE 42

7:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

PuLP: Datatypes

  • LpProblem

– Defines the LP problem – Holds the constraints and objective function – Interface to the LP Solver (external)

  • LpVariable

– Abstracts an LP variable (with name) – Values will be changed by the solver – Float or integer – Defines the permitted variable value range

slide-43
SLIDE 43

8:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

PuLP: Datatypes

  • LpConstraint – Constraint rule

– Form: affine function OP numeric term OP can be one of: <=, =, >= – Can have a name (for debugging)

… some more (e.g. elastic constraints)

slide-44
SLIDE 44

9:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

PuLP: Documentation

  • Not that great :-(

– Package documentation: https://pythonhosted.org/PuLP/index.html Incomplete, misses details. – Source code: https://github.com/coin-or/pulp/blob/master/src/pulp/ – Some blog posts:

https://scaron.info/blog/linear-programming-in-python-with-pulp.html http://benalexkeen.com/linear-programming-with-python-and-pulp/

slide-45
SLIDE 45

10:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

PuLP: Example Conference Scheduling

  • Inspiration:

– Talk from David MacIver at PyCon UK 2016 https://www.youtube.com/watch?v=OkusHEBOhmQ

  • Use case:

– Help with scheduling EuroPython 2017 or later

slide-46
SLIDE 46

11:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

PuLP: Example Conference Scheduling

  • Goal:

– Simplify scheduling – Optimize speaker (and attendee) satisfaction

  • Constraints:

– Multiple rooms of different sizes – Talk slots of varying lengths (e.g. 30min / 45min) – Talks with varying lengths – Speakers cannot give two talks at the same time – Speakers may have availability constraints

slide-47
SLIDE 47

12:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Conference data: rooms and talks

slide-48
SLIDE 48

13:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Conference data: talk slots

slide-49
SLIDE 49

14:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

LP problem and variables

slide-50
SLIDE 50

15:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Constraints for talk slots Only assign one talk per slot

slide-51
SLIDE 51

16:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Constraints for talks We need to assign all talks Talks must fit the talk slots

slide-52
SLIDE 52

17:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Special constraints Speaker not always available

slide-53
SLIDE 53

18:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

More problems: How to prevent overlaps Different slots per room More than one talk per speaker

slide-54
SLIDE 54

19:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

More problems: How to prevent overlaps

slide-55
SLIDE 55

20:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Solution: Divide slots into smaller standard blocks Add new variables

slide-56
SLIDE 56

21:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Solution: Define some helper mappings

slide-57
SLIDE 57

22:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Solution: Link slots and blocks

slide-58
SLIDE 58

23:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Constraint: More than one talk per speaker Using blocks, you can now define the constraint:

slide-59
SLIDE 59

24:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Finally: Define objective function & run solver

slide-60
SLIDE 60

25:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Show the result

slide-61
SLIDE 61

26:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Show the result: Raw data

slide-62
SLIDE 62

27:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Show the result: As Schedule

slide-63
SLIDE 63

28:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

More possibilities

  • Use room capacities and attendee preferences
  • Add tracks:

Group talks by topic (preferably in a single room)

  • When having to apply changes after publication of the schedule (new

constraints, speaker cancellations): Minimize changes

slide-64
SLIDE 64

29:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Difficulty: Finding a suitable model

  • LP only supports linear combinations

– Constraints of the form xi * xj are not supported – Dynamic dependencies are hard to model – “Programming” is declarative (as in e.g. SQL), not imperative (as in e.g. Python)

  • Models have great influence on runtime
slide-65
SLIDE 65

30:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

PuLP: Summary of gotchas

  • LpVariable var doesn’t always behave like a Python number

– LpBinary variables can assume values outside their valid value range {0, 1} during solving better: test for (var > 0) – if var: is always true, when not running in the solver better: if pulp.value(var):

  • LpProblem can fail to deliver a result

– assert problem.status == 1

  • Conclusion: Always test your solver !
slide-66
SLIDE 66

31:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Faster than PuLP

  • CVXOPT - Python software for convex optimization

– http://cvxopt.org/ – Uses a different API than PuLP – Much better documentation – Up to 10-70x faster than PuLP

https://scaron.info/blog/linear-programming-in-python-with-cvxopt.html

  • CVXPY - Python-embedded modeling language for convex optimization

problems

– http://www.cvxpy.org/

  • PICOS - Python Interface for conic optimization solvers

– http://picos.zib.de/

slide-67
SLIDE 67

32:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Conference scheduling using Python

  • PyCon UK: Conference Scheduler

– https://github.com/PyconUK/ConferenceScheduler – Documentation: http://conference-scheduler.readthedocs.io/ – Fairly new: only 2 months old – Uses PuLP, completely automated

  • Alexander tried to use it for EuroPython 2017:

failed due to exponential runtime

slide-68
SLIDE 68

33:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Conference scheduling using Python

  • EuroPython 2017 Scheduler

– Written by Alexander Hendorf – Doesn’t use PuLP, but a similar model to the PyCon UK one – Works based on clustering + random shuffling + human touch

slide-69
SLIDE 69

34:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Thank you for your attention !

Beautiful is better than ugly.

slide-70
SLIDE 70

35:35 (c) 2017 eGenix.com GmbH, info@egenix.com Conference 2017

Contact

eGenix ix.c .com So Software, Sk , Skill ills a and Se Servic ices G GmbH Marc-André Lemburg Pastor-Löh-Str. 48 D-40764 Langenfeld Germany eMail: mal@egenix.com Phone: +49 211 9304112 Fax: +49 211 3005250 Web: http://www.egenix.com/