![Page 1: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/1.jpg)
(c) 2017 eGenix.com Software, Skills and Services GmbH, [email protected]
EuroPython 2017EuroPython 2017Rimini, ItalyRimini, Italy
Marc-André Lemburg :: eGenix.com GmbH
Automatic Conference Scheduling with PuLP
![Page 2: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/2.jpg)
2:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 3: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/3.jpg)
3:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 4: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/4.jpg)
4:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 5: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/5.jpg)
5:35(c) 2017 eGenix.com GmbH, [email protected] 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 andminimizes (or maximizes) the objective
![Page 6: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/6.jpg)
6:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 7: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/7.jpg)
7:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 8: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/8.jpg)
8:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
PuLP: Datatypes
• LpConstraint – Constraint rule– Form:
affine function OP numeric termOP can be one of: <=, =, >=
– Can have a name (for debugging)
… some more (e.g. elastic constraints)
![Page 9: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/9.jpg)
9:35(c) 2017 eGenix.com GmbH, [email protected] 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.htmlhttp://benalexkeen.com/linear-programming-with-python-and-pulp/
![Page 10: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/10.jpg)
10:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 11: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/11.jpg)
11:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 15: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/15.jpg)
15:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Constraints for talk slots
Only assign one talk per slot
![Page 16: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/16.jpg)
16:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Constraints for talks
We need to assign all talks
Talks must fit the talk slots
![Page 17: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/17.jpg)
17:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Special constraints
Speaker not always available
![Page 18: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/18.jpg)
18:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
More problems: How to prevent overlaps
Different slots per room
More than one talk per speaker
![Page 19: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/19.jpg)
19:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
More problems: How to prevent overlaps
![Page 20: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/20.jpg)
20:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Solution: Divide slots into smaller standard blocks
Add new variables
![Page 21: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/21.jpg)
21:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Solution: Define some helper mappings
![Page 23: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/23.jpg)
23:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Constraint: More than one talk per speaker
Using blocks, you can now define the constraint:
![Page 24: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/24.jpg)
24:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Finally: Define objective function & run solver
![Page 28: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/28.jpg)
28:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 29: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/29.jpg)
29:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 30: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/30.jpg)
30:35(c) 2017 eGenix.com GmbH, [email protected] 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
solvingbetter: test for (var > 0)
– if var: is always true, when not running in the solverbetter: if pulp.value(var):
• LpProblem can fail to deliver a result– assert problem.status == 1
• Conclusion: Always test your solver !
![Page 31: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/31.jpg)
31:35(c) 2017 eGenix.com GmbH, [email protected] 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/
![Page 32: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/32.jpg)
32:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 33: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/33.jpg)
33:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 34: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/34.jpg)
34:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Thank you for your attention !
Beautiful is better than ugly.
![Page 35: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/35.jpg)
35:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Contact
eGenix.com Software, Skills and Services GmbHMarc-André LemburgPastor-Löh-Str. 48D-40764 LangenfeldGermany
eMail: [email protected]: +49 211 9304112Fax: +49 211 3005250Web: http://www.egenix.com/
![Page 36: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/36.jpg)
(c) 2017 eGenix.com Software, Skills and Services GmbH, [email protected]
EuroPython 2017EuroPython 2017Rimini, ItalyRimini, Italy
Marc-André Lemburg :: eGenix.com GmbH
Automatic Conference Scheduling with PuLP
![Page 37: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/37.jpg)
2:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 38: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/38.jpg)
3:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 39: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/39.jpg)
4:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 40: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/40.jpg)
5:35(c) 2017 eGenix.com GmbH, [email protected] 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 andminimizes (or maximizes) the objective
![Page 41: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/41.jpg)
6:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 42: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/42.jpg)
7:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 43: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/43.jpg)
8:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
PuLP: Datatypes
• LpConstraint – Constraint rule– Form:
affine function OP numeric termOP can be one of: <=, =, >=
– Can have a name (for debugging)
… some more (e.g. elastic constraints)
![Page 44: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/44.jpg)
9:35(c) 2017 eGenix.com GmbH, [email protected] 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.htmlhttp://benalexkeen.com/linear-programming-with-python-and-pulp/
![Page 45: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/45.jpg)
10:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 46: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/46.jpg)
11:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 50: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/50.jpg)
15:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Constraints for talk slots
Only assign one talk per slot
![Page 51: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/51.jpg)
16:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Constraints for talks
We need to assign all talks
Talks must fit the talk slots
![Page 52: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/52.jpg)
17:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Special constraints
Speaker not always available
![Page 53: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/53.jpg)
18:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
More problems: How to prevent overlaps
Different slots per room
More than one talk per speaker
![Page 54: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/54.jpg)
19:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
More problems: How to prevent overlaps
![Page 55: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/55.jpg)
20:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Solution: Divide slots into smaller standard blocks
Add new variables
![Page 56: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/56.jpg)
21:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Solution: Define some helper mappings
![Page 58: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/58.jpg)
23:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Constraint: More than one talk per speaker
Using blocks, you can now define the constraint:
![Page 59: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/59.jpg)
24:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Finally: Define objective function & run solver
![Page 63: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/63.jpg)
28:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 64: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/64.jpg)
29:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 65: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/65.jpg)
30:35(c) 2017 eGenix.com GmbH, [email protected] 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
solvingbetter: test for (var > 0)
– if var: is always true, when not running in the solverbetter: if pulp.value(var):
• LpProblem can fail to deliver a result– assert problem.status == 1
• Conclusion: Always test your solver !
![Page 66: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/66.jpg)
31:35(c) 2017 eGenix.com GmbH, [email protected] 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/
![Page 67: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/67.jpg)
32:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 68: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/68.jpg)
33:35(c) 2017 eGenix.com GmbH, [email protected] 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
![Page 69: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/69.jpg)
34:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Thank you for your attention !
Beautiful is better than ugly.
![Page 70: Automatic Conference Scheduling with PuLP · PDF file– PuLP is a Python Interface for the LP part of COIN-OR ... GLPK (GNU LP Kernel) – Other commercial solvers: CPLEX, GUROBI](https://reader031.vdocuments.us/reader031/viewer/2022020104/5aa224f27f8b9a46238cae59/html5/thumbnails/70.jpg)
35:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017
Contact
eGenix.com Software, Skills and Services GmbHMarc-André LemburgPastor-Löh-Str. 48D-40764 LangenfeldGermany
eMail: [email protected]: +49 211 9304112Fax: +49 211 3005250Web: http://www.egenix.com/