70
(c) 2017 eGenix.com Software, Skills and Services GmbH, [email protected] EuroPython 2017 EuroPython 2017 Rimini, Italy Rimini, Italy Marc-André Lemburg :: eGenix.com GmbH Automatic Conference Scheduling with PuLP

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

  • Upload
    dinhtu

  • View
    239

  • Download
    1

Embed Size (px)

Citation preview

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

(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

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

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

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

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

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

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

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

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

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

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 12: 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

12:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

Conference data: rooms and talks

Page 13: 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

13:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

Conference data: talk slots

Page 14: 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

14:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

LP problem and variables

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

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

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

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

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

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

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

21:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

Solution: Define some helper mappings

Page 22: 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

22:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

Solution: Link slots and blocks

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

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

24:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

Finally: Define objective function & run solver

Page 25: 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

25:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

Show the result

Page 26: 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

26:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

Show the result: Raw data

Page 27: 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

27:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

Show the result: As Schedule

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

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

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

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

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

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

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

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

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

(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

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

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

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

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

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

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

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

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

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

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 47: 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

12:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

Conference data: rooms and talks

Page 48: 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

13:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

Conference data: talk slots

Page 49: 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

14:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

LP problem and variables

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

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

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

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

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

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

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

21:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

Solution: Define some helper mappings

Page 57: 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

22:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

Solution: Link slots and blocks

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

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

24:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

Finally: Define objective function & run solver

Page 60: 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

25:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

Show the result

Page 61: 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

26:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

Show the result: Raw data

Page 62: 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

27:35(c) 2017 eGenix.com GmbH, [email protected] Conference 2017

Show the result: As Schedule

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

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

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

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

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

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

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

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

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/