Employee Scheduling
developers.google.com
developers.google.com
I wrote a schedule for a team of ~20 co-workers for a 24/7 support shop. This required people change shifts / sleep schedules often.
The schedule was a point of contention for years.
After I volunteered to write the schedules, in 3 months I had everyone happy.
It was not hard.....but....
The catch was that I did it manually for a month at a time with a wide ranging amount of changing priorities that would be hard to program ... and the key was COMMUNICATION, and working with people and their personal preferences.
Like if someone comes to me and says "what if we... did X with the schedule". I could tell them how to do that and not to right away. The code would have to be changed / rewritten and tested and fail at it each time... so much mess.
Especially when scheduling other humans... the humans being scheduled can smell a computer scheduling a mile away and IMO they expect the worst at that point. They're not necessarily wrong.
I dunno. Computers are pretty good at this one too, on different kinds of variance and weights.
The largest problem I see is that everyone is discussing "either or" on this thread, while the clear winner is both.
They are very much not the same thing and the dynamic nature of keeping people happy and filling a schedule is extremely difficult to account for with software.
I do think that software speeds up some parts of the process, but like so many automated processes, it's computer assistance, not computer intelligence.
Even if you can get competence, you may want to automate it anyways. I'm currently working in health, and I recently visited a radiology center that claimed it took a full year to get front desk staff fully up to speed. Understanding the full scheduling requirements for all scans, some medicare rules that influence scheduling, and how to handle all the various problems, takes a long time. They live in terror of having front desk staff leave, because a quick replacement is impossible.
You could try http://jeffreykingston.id.au/khe/ which is free.
You can try it online at http://jeffreykingston.id.au/cgi-bin/hseval.cgi
It is still the most intricate software I’ve ever written in my 25 years of software dev, and I wrote it in high school.
I remember struggling with running out of RAM on the 4 megabyte school PCs.
So late night shifts are generally undesirable, but required to be covered and so you really want to spread them out. Having said that for some folks they'd rather do a bunch in a row, others spread them out. Some folks mind them less than others.
Just making the math decide that an even number across the whole team is 'fair' always leads to some weirdness no matter how it works out.
So a weekend night shift might be 3 days of work then 4 off. That's awesome for a guy whose vacation starts the following week because he gets more time off. He might actually WANT that. So in that case a night shift is desirable and makes the guy happier.
Another person might not want that or not have a vacation... so his point of view might differ. But maybe next weekend he feels differently.
And that's just one given weekend shift with somewhat unpredictable results.
The real key though is not just noting how the variables change wildly it is that keeping those guys happy, being flexible for them... makes them MORE willing to take a rough shift now and then. That's even HARDER to quantify, but EXTREMELY valuable.
And of course my ability to walk up to a dude, explain the situation, he trusts me because I've done this before / him favors is just something a computer that fires off an email just can't do.
We ended up deciding we needed to build our own tool and have also started to sell it https://happy.tools/
Quite often, people are looking for the right set of constraints to apply so they're kind of running a meta problem on top of the NSP. How many back-to-back shifts should I allow? Should people's shifts always start at the same time? Can I give some people regular 9-5 schedules? All of the above questions will decrease the strict optimality of the solution, but increase the happiness and long term retention of your workforce. Thus, the question really become, how much do each of these cost in terms of optimality and what are the tradeoffs.
We've found that developing a very fast heuristic algorithm for the NSP allows people to iterate quickly on these types of questions (even though it's not quite as optimal as a SAT solver). We use a greedy algorithm with a heuristic that is relatively specific to our problem domain to ensure that we have a reasonable combination of speed and optimality.
Here is an open-source column generation solver that currently achieves the best solutions on that benchmark: https://github.com/PetterS/monolith/tree/master/minimum/line...
For column generation, specifically, the routine that generates the columns incorporates a lot of problem-specific information. The rest of the solver is more general.
Here's the web interface to the nurse scheduler: https://forio.com/app/showcase/nurse-scheduling/
and here are some other optimization examples: https://forio.com/products/epicenter/example-applications/
Thursday, 02:00 to 08:00 — Emergency
Thursday, 08:00 to 12:00 — Oncology
Thursday, 12:00 to 18:00 — Oncology
Friday, 08:00 to 12:00 — EmergencyIn several solutions, a nurse works shift 2 one day, then shift 0 the next. In fact, Nurse 3 keeps getting stuck with the back to back shifts.
The example doesn't mention back to back shifts, only that a nurse can at most work one shift a day which in turn implies the constraint that no nurse can work shifts back to back (in the same day).
One could easily add the constraint that a nurse scheduled on shift 2 cannot work shift 0 the next day.
We had a few different algorithm iterations. One of our biggest learnings was that it's hard to build a generalized auto-scheduling algorithm. While most companies have similar needs at a surface level - things like local labor laws, cross-functional roles, breaks, and business quirks mean that you end up customizing the algorithm for most customers.
For the best auto-scheduling - Kronos is the incumbent, and Legion.co is probably the most advanced disruptor.
Have you done any further scheduling related work since Staffjoy?
A question becomes "how many new employees could we handle?".
I looked at some solutions, but landed on an Excel spreadsheet with a small macro for spreadsheet setup, conditional formatting to call out an employee being allocated to 2 positions on the same shift, and a visual way to show for each operator, how long it takes to be fully trained. HR or a manager can setup training schedules by manually allocating people to training slots.
There were some constraints the business wanted (train on machine #1 before #2, do 2 days of training if you haven't already trained on _x_ machine). They would have been hard to accommodate in a way the end user could configure, so I have a notes section they can fill in (and they have to manually observe these constraints).
Totally open to other ideas people have on how to approach the proble.
Of course, you could build or buy a web app that handles this specific scenario more powerfully and scaleably, but if this is a quarterly problem rather than a everyday problem then the additional overhead of the different interface / logins may not be worthwhile.
My only comments would be
1) macros are too hard for nontechnical users in my experience, even just w/r/t setup (excel prompts you a security warning to enable macros that is scary). I think you could maybe do this using the what-if analysis tables, simple ifelse formulas, and conditional formatting.
2) another improvement might be a cloud-based version where there is a link at which others can easily view + collaborate, like Google Sheets or Airtable. I think Excel is supposed to have this feature as part of the 365 subscription but I've never used it.
Your problem sounds like a JSP (job shop scheduling problem). If it is you could use MiniZinc https://www.minizinc.org/ and look at Håkan Kjellstrans MiniZinc page http://www.hakank.org/minizinc/, it has a couple of different JSP models.
It's rather easy to generate a schedule and most of the feasible variants are available online already (there aren't infinite possibilities on how to schedule shifts) - you fit it to a 7 day or a 28 day (or a multiple of 7) cycle and then copy paste.
The scheduling challenges occur when people need to take unexpected vacations or during vacation period when staffing is low.
Another challenge is the skill level of the individual employees which is usually not binary - can do work / cannot do work - since employees come to work to perform tasks and they don't always learn all of the tasks the first day.
<disclaimer>I work in a company that deals exclusively with OR. This means that we might be overly specialized for this product.</disclaimer>
I see OR-Tools as an educational product. The tool is easy to start tinkering with and it has superb documentation - even for people not specialized in combinatorial optimization.
I've used the LP solver [0] for real problems (not on a massive scale), but it worked very nice. Basically a scheduling problem where we very quickly could give the user a pretty decent solution as a starting point that they then could customise. Dramatically shortened the time for the user for that process, compared to the previous random/heuristic "solution" we give.
Will it find the shortest path in a graph faster than your Dijkstra implementation? No, leave the simple problems to hand-rolled code. Can it run e.g. TSP faster than a dedicated TSP solver written by an expert? No, but it sure will beat what you or I can code up of TSP over a week. These things have great heuristics and can solve/approximate a very wide of variety of NP-hard problems much better than you could yourself.
I've used the CP solver to plan sports tournament schedules (make sure everybody gets equal time on the streamed field, make sure that special team that arrives with the late train doesn't have the first game, nobody has to play two games in a row, etc.). I made the mistake of using the Python frontend (which is much worse documented than the C++ API), but otherwise, it was a good experience. Constraint programming feels a bit odd at first, though.
1. https://nb.paulbutler.org/optimizing-plots-with-tsp-solver/
As with all discrete optimization problems, a large part of performance and scalability comes down to how well you model the problem. Using a framework gives you the flexibility to focus on modeling and the ability to easily extend your problem to satisfy new constraints without the burden of maintaining an optimization algorithm. Generally speaking, there's no point in reinventing what's more than likely a worse wheel.
OR-tools is a state of the art OR framework. The CP-SAT solver has consistently won the Minizinc challenge the last few years and the routing library is a great local search framework.
It's also worth mentioning the fantastic OscaR, a Scala CP/CBLS library which I've used extensively in my masters thesis on vehicle routing. Gecode is another solid CP solver. Minizinc is an interesting project that aims to create a unified language to interface with a lot of different solvers (CP, SAT, MIP)
Usually the time horizon for solving these kinds of problems is on the scale of minutes/hours so the tool chain isn't optimized for that time span.
We ended up requiring users to adjust their queries a little to make it easier to spot the targeted preintersections. This seemed like a decent trade-off considering the latency impact of the alternative.
It can't solve every problem, but it can solve many more than you think, and there's an active research area around using them for solving problems.
Are the needs of most small/medium businesses currently being met in this area or is there an opportunity for providing tools in this space ?
Static details include things like local labour laws, skill constraints, unions etc.
Dynamic details include things like allowing employees to state preferences, swap shifts (while respecting labour laws), call in sick etc. without having to reshuffle everything.
There probably are quite a few submarkets (geographies/industries/sizes) that don't have tools; whether you can make money is a different question.
Part of the problem is that some senior physicians do whatever they want and aren't interested in playing fair. They'll call her the day before a holiday and tell her they're not coming in, and my sister is left trying to figure out the least shitty way to cover the gap.
it's really simple.
Discrete optimization and constraint programming can be a bit difficult to get into. There are two great free online courses on Coursera that do a good job at introducing the topic.
Discrete Optimization
https://www.coursera.org/learn/discrete-optimization
I don't remember the exact content of this course but I believe it covers the basics in a few different methodologies.
Basic Modeling for Discrete Optimization
https://www.coursera.org/learn/basic-modeling
This is a great course by Peter Stuckey that uses MiniZinc. The MiniZinc programming language is a great starting point that teaches you to think of solving discrete optimization problems only in terms of modelling the problem.
Håkan Kjellerstrands blog is another great resource
It contains hundreds of different models for a large variety of different solvers. Chances are that he has created a model for your solver for a similar problem.
Two books worth mentioning are:
Handbook of Constraint Programming
Principles of Constraint Programming
Other solvers/frameworks:
The OscaR library
https://bitbucket.org/oscarlib/oscar/wiki/Home
My personal favorite. An OR framework written entirely in Scala. As such it's an absolute joy to work with and the internals are (relatively speaking) easier to understand.
GeCode
Another extremely potent solver. Exclusively CP based.
Mini-CP
https://minicp.readthedocs.io/en/latest/
An extremly lightweight CP solver, designed for educational purposed to expose how a CP solver works without obfuscating performance optimizations found in research/production solvers.
MiniZinc
A solver agnostic constraint modelling languages, designed to interface a given optimization model with different solvers.
A few notable researches:
Phil Kilby
Pascal Van Hentenryck
Paul Shaw
Laurent Perron - OR-tools
Peter Stuckey - MiniZinc
Pierre Schaus - OscaR, Mini-CP
Renaud Hartert - OscaR
I also want to make a plug for the work of the Uppsala University optimization group
http://www.it.uu.se/research/group/optimisation/
Especially the work of Pierre Flener, Gustav Björdal and Justin Pearson who I've had the pleasure to work with during my masters thesis on vehicle routing using CP.
I'll have to play with this.
Here's an open source solver for a fun presumably-NP casual video game:
https://github.com/asah/tents-and-trees
As with other solvers, it can be a little difficult to debug, so I recommend starting small and adding constraints and known test examples.
Edit: Someone smarter than me says it better below :)
Can someone who's tested this stuff out advise on how many deliveries it can handle at a time? The examples only list trivial problems, but that might just be to keep the examples short.
(No, I don't mean within Google, although they solve scheduling problems there as well.)
EDIT: There are articles:
https://cloud.google.com/press-releases/2020/0120/lufthansa
https://www.cnbc.com/2020/01/19/lufthansa-taps-googles-cloud...
The big challenge in making something like this actually work, are not the fancy hightech bits. Dealing with humdrum data integrations and torrential rates of change in rules and constraints, sourced from hundreds of mostly non-technical people across dozens of independent departments is where it gets hard.
From what I've seen, solving problems with a good enough solution with a 1h time limit is usually doable up to about 1000-3000 on standard hardware.
See issue number 1 for the semantic web, social network Radiojade:
https://github.com/foundpatterns
https://en.m.wikipedia.org/wiki/Constraint_Handling_Rules
I need your help with finishing it though. Contact me on LinkedIn
The above is something I actually worked on before.. The bitter irony, is they all just traded their vacation weeks as it came up anyway.
http://www.hakank.org/google_or_tools/nqueens.py
http://www.hakank.org/google_or_tools/nqueens2.py
http://www.hakank.org/google_or_tools/nqueens3.py
for inspiration
(Also: Thanks for your links to my site.)
Scheduling isn't an easy problem to solve in the real world vs the lab where there are far less constraints and consequences for getting it wrong. Kronos (kronos.com) is the recognized leader in this space and even their software has a hard time keeping it all straight.
Gee, I got started in OR (operations research) at FedEx, covered a lot from some of the best people in grad school, taught it as a prof in B-school, and applied it to US national security and some commercial problems.
Good to see the interest in some of the flight operations work for Lufthansa -- I was considering (no great progress) some of those problems at FedEx!
One commercial problem was allocating marketing resources for some banks. I was given the formulation, 0-1 integer linear programming with 600,000 variables and 40,000 constraints. I derived some non-linear duality theory, used the IBM OSL (Optimization Subroutine Library), and in 500 iterations found a feasible solution with the objective function guaranteed to be within 0.025% of optimality!
Another commercial problem was some more marketing optimization. It was also 0-1 integer linear programming, but surprisingly it was just a problem in least cost network flows. That is also linear programming, but there the simplex algorithm takes on a special form where a basis is a spanning tree of arcs in the network. A simplex pivot is to add an arc to the tree, thus, yielding a circuit, and running flow around the circuit in the direction that saves money and removing from the circuit, thus, making a tree again, one of the first arcs where the flow goes to zero. There is a cute variation of the algorithm due to W. Cunningham (one of my profs) based on his strongly feasible basis, that avoids cycling.
A super nice point about the simplex problem on least cost network flows is if all the arc capacities are whole numbers and if start with an integer basic feasible solution, then the simplex algorithm will automatically maintain an integer basic feasible solution and terminate with an integer solution. It is good to suspect that a lot of integer linear programming problems are actually just such network flow problems or nearly so.
Once I used that stuff to say, for NASA, how to assign signals to satellite channels to minimize some signal interference -- it was an example of the bottleneck assignment problem which should be solvable very quickly by some post optimality tweaking with the network simplex algorithm.
I enjoyed using the IBM OSL, but IBM withdrew it from marketing in about 2003, maybe in favor of marketing C-PLEX. But it appears that at about 2004 IBM donated the source of the OSL (with lots of pieces, network flow, stochastic programming, etc.) to Riverware which might distribute the open source.
I got started with the OSL when I was in an AI group at IBM's Watson lab where the OSL was written. The Watson lab long had some high expertise in optimization -- Gomory (cutting planes, Gilmore-Gomory column generation, etc.) was head of the lab; there was Phil Wolfe (the Wolfe dual, etc.), Ellis Johnson (group theory and integer programming), etc.
So, in particular, if still want to do some OR and optimization, get some quite well written software, and save some money, then might look into getting all the IBM OSL code open source.
Could you elaborate on why that was perceived to be the case ?
It seems like the number of applications is very large and I suspect the technology is under-exploited outside of very large organizations.
But the optimization of operations research was different, e.g., less central use of calculus: Some of the surprising history is in a book review at
https://www.jstor.org/stable/2975180?seq=1#page_scan_tab_con...
And that is not really the beginnings of such things since there was the Kantorovich work on the cutting stock problem.
In that book review will see that linear programming (LP) had a launch as a big splash. Broadly it appeared that LP was so close to so many important practical problems -- military, commercial, maybe more -- that it was bound to become a big thing for a long time. And, can check, IIRC several Nobel prizes in Economics were given for LP and more topics in optimization applied to economics.
And there are connections with two sided optimization, i.e., the theory of two person games (e.g., paper, scissors, rock) since the basic saddle point result, IIRC first proved by von Neumann, follows easily from the duality part of basic theory of LP. So, again LP looked good.
Can't leave out the Hugh Everett work: He had a company around DC working on military problems -- best allocation of resources. Everett's theorem is a cute version of Lagrange multipliers and supposedly the foundation of his Lambda Corporation. Yes, that Everett, physics student of J. Wheeler where Everett worked up the many worlds interpretation of quantum mechanics.
Operations research had a more general big push during WWII, e.g., with some of the work of F. Dyson.
So, by the 1950s, it looked like operations research (OR) and its tools of optimization, especially LP, were to be big things.
Problems:
(1) Real Problems. What real problems were to be solved? Too commonly the problems were not really linear or were linear but linear integer (which led to the question of P versus NP).
(2) Data. Too often it was a struggle to get the needed real data.
(3) Software. The IBM OSL I mentioned was good software, and so are C-PLEX, Gurobi, and more, but in the 1950s the software situation was grim.
(4) Computing. The 1950s computers, e.g., the IBM 709, were clumsy to use, slow, and expensive.
Then (1)-(4) too easily resulted in projects with not so good fits with reality, over budget, and later than promised. Reputation fell.
Another problem, no surprise, was that the real business problem commonly evolved faster than the optimization software could keep up.
But for selected and sufficiently valuable applications, e.g., running an oil refinery, by 1970 LP could be a big money maker.
There were claims that companies that mixed animal feed did well with LP in, say, the 1970s or so.
In the 1980s the situation on LP software and computing was good enough to permit some better -- project time and budget -- results on real problems.
By the 1980s, B-school accreditation called for a course in LP. So, a lot of B-school students got a good introduction to LP.
But there was very little down to essentially no instruction to turn out well skilled professionals in OR or LP. The college profs concentrated on publishing papers, e.g., about P versus NP, and were discouraged from working on real, non-academic problems from outside academics, i.e., were not like MDs in medical teaching/research hospitals who were also clinical and professional. So, the OR/LP workers who were available still needed some years of hands on experience to become competent professionals for important practical applications.
The standard attitude in the C-suites was a special case of C-suite attitudes more generally -- don't spend money on chancy, risky stuff. Instead, if there is to be a development project, then time, budget, good ROI, etc. needed to be reliable. So, in the C-suites, LP and OR got reputations as "dead fields", flops. Or maybe no middle manager ever got fired declining to pursue an OR/LP project. Neither the C-suite nor a middle manager wanted to have their career at risk from an OR/LP project they didn't understand.
The problem of P versus NP also hurt: Or, the dream was that in business we should need only to formulate an optimization problem, type that into some software to get the problem ready for some solver software, and then have the solver produce an optimal solution quickly and reliably. Well, with the P versus NP issue, we saw that at least for now such a solver was asking for too much.
[My experience was that it was usually necessary and effective to take the problems one by one and exploit special structure.]
Giving up that way was mostly a mistake: If the real business problem is a $100 million project, an optimal solution might save $15 million, the problem is a case of NP-complete so that saving all the $15 million to the last penny, guaranteed, in reasonable time, is also in this particular case (not necessarily the worst case of the P versus NP issue) not reasonable but saving $14 million is reasonable, then still commonly people regarded the challenge of P versus NP and showing that anything about optimization for the real problem was unreasonable and would also believe that the challenge of P versus NP meant that the $14 million was also beyond hope. People just gave up.
But in broad terms from 100,000 feet up, the original observation that business needs optimization was correct then and still, now. For such problems, a lot of what has long been known in LP and optimization more generally is uniquely powerful, relevant stuff.
So, there's money to be saved.
The main question is, do C-suites want to fund the relevant projects?
My guess is that the C-suites and middle managers have not changed much and, no, rarely want to fund the relevant projects.
https://github.com/ralaruri/Pmedian/blob/master/PMedianRamzi...
You always have two people trading shifts but never telling anyone. Then the one who was supposed to work doesn't show up they forgot they traded shifts.
Human nature is half the problem.
Algorithms like this look cool but can end up being too rigid for many real-world scenarios. You can’t just take the output and force everyone to follow that schedule.
Tell them that it is critical someone fills every one of their shifts, but it needn't be them. Employees will end up bartering, swapping, paying for others to fill their shift, etc. Overall, most shifts will get filled, and most people will be happy.
You run the small risk that an employee will deliberately use the ability to swap to work some illegal shift pattern, and then prosecute you over it. So far, it's never gone far.
The only time people get upset is if someone trades a bunch of shifts, then quits. People who don't like that have the option of just not swapping shifts though.
But there was a schedule for everyone.
Usually the sorta places that need shift scheduling also require you to check in before your shift and will only pay for the hours that you worked, often those places have some sorts biometric check in mechanism, your suggestion doesn’t seem very practical in light of that.
I only kick up a fuss if someone shows up to do a shift who isn't even an employee.
You run the scheduler software, then send each employee a text message saying "We're offering you a shift Monday at 9am for 8 hours. Accept?". After 24 hours, rerun the scheduler with accepted/denied shifts as constraints, and repeat till all shifts are filled.
Obviously you may not end up with optimal schedules when people start denying shifts, but you get pretty close.
When a particular shift gets denied by more than ~3 people, they normally give a ~30% pay boost for that shift to get it filled.
On the page above the linked page, on Google’s OR tools, there is mention that their tools won four gold medals in the MiniZinc completions.
> Resource scheduling, CSP (Constraint Satisfaction programming)
CSP: https://en.wikipedia.org/wiki/Constraint_satisfaction_proble...
Scheduling (production processes):
https://en.wikipedia.org/wiki/Scheduling_(production_process...
Scheduling (computing):
https://en.wikipedia.org/wiki/Scheduling_(computing)
... To an OS, a process thread has a priority and sometimes a CPU affinity.
From http://markmail.org/search/?q=list%3Aorg.python.omaha+pysche... :
Pyschedule:
- Src: https://github.com/timnon/pyschedule
From https://github.com/timnon/pyschedule :
> pyschedule is python package to compute resource-constrained task schedules. Some features are:
- precedence relations: e.g. task A should be done before task B
- resource requirements: e.g. task A can be done by resource X or Y
- resource capacities: e.g. resource X can only process a few tasks
Previous use-cases include:
- school timetables: assign teachers to classes
- beer brewing: assign equipment to brewing stages
- sport schedules: assign stadiums to games
... https://en.wikipedia.org/wiki/Slurm_Workload_Manager :
> Slurm is the workload manager on about 60% of the TOP500 supercomputers.[1]
Slurm uses a best fit algorithm based on Hilbert curve scheduling or fat tree network topology in order to optimize locality of task assignments on parallel computers.[2]
... https://en.wikipedia.org/wiki/Hilbert_curve_scheduling :
> [...] the Hilbert curve scheduling method turns a multidimensional task allocation problem into a one-dimensional space filling problem using Hilbert curves, assigning related tasks to locations with higher levels of proximity.[1] Other space filling curves may also be used in various computing applications for similar purposes.[2]