Skip to content

Constraint programming

Some schedules have so many rules that finding any plan that works is the hard part. Constraint programming is built for exactly that.

  • Free 30-minute call
  • No commitment
  • You own the code
Tools
OR-Tools, CP Optimizer, CP-SAT
Used in
5 documented use cases
Delivery
Documented source code, yours to keep

In short: Constraint programming (CP) is a method for problems with many hard rules, such as rotas and timetables. Each rule crosses out the options that can’t work, until only plans remain that keep every rule.

The problem

You build next month’s rota. Every shift needs cover, and every nurse has a contract and days off. No night shift may run straight into an early one. Most of the week goes into finding a version that keeps every rule. Whether it’s also a good version hardly comes up.

What changes

Today, you move shifts by hand until the rota finally keeps every rule. Our model finds a rota that keeps every rule, then keeps improving it. You start from a plan that already works and spend your time on the decisions only you can make.

How it works

Constraint programming (CP) works differently from mixed-integer programming (MILP). MILP writes the plan as equations and searches for the cheapest one. CP looks at the possible values of each decision, such as which shifts Anna can take. Each rule quickly crosses out the values that can’t work. Every choice narrows the next, until only feasible plans remain, the ones that keep every rule.

That makes CP strong on combinatorial problems such as rotas, timetables and product configurations. In these, the number of combinations explodes, and many rules must always be kept. We build on OR-Tools CP-SAT and IBM CP Optimizer. You get a plan that keeps every one of those rules.

CP-SAT or a MILP solver?

Most comparisons online end with “it depends”. Mostly it depends on what your rules are about. CP-SAT shines when the rules are about time and order. A shift or a job becomes an interval with a start, an end and a length. One NoOverlap rule then says a machine never runs two jobs at once, where MILP would need a stack of on-off rules.

Two catches are worth knowing before you start. The OR-Tools documentation says CP-SAT works with whole numbers only. So we convert prices with cents or times with decimals, for example 2.50 francs into 250 cents. And size matters. INFORMS is the operations research society. On its forum, one practitioner reports that CP-SAT coped with his problem up to a few hundred thousand variables, the single decisions in the model.

The honest boundary: sometimes the goal matters more than keeping the rules, for example when cost counts most. Then MILP is often stronger. MILP also calculates a bound, a value that no plan can beat. Its bound is usually closer to the best plan, so it can show sooner that a plan is the best. When we can’t tell up front, we run both on a week of your own data and let the results decide.

When it isn’t the answer

The honest boundary: sometimes the goal matters more than keeping the rules, for example when cost counts most. Then MILP is often stronger.

Common questions.

Something else? Ask us directly.

It optimises. An answer on Operations Research Stack Exchange calls CP-SAT a full integer programming solver. It names the same building blocks that MILP solvers use: presolve, cuts and a linear relaxation. The same answer says CP-SAT is weaker at listing every feasible plan. It also advises running CP-SAT with eight threads, so give it several processor cores.

Hard rules stay rules: the plan must keep them. Soft rules become penalties in the goal, so every missed wish costs points. You decide how many points each wish is worth. A missed day off can count less than an unfair split of weekends, for example. The solver then keeps as many wishes as the hard rules allow, and the report shows which ones it missed.

Rarely in one piece. A year usually splits into months or weeks, with yearly totals such as holidays carried from one piece to the next. Some very large rotas are solved as MILP models, a method that writes the plan as equations. For those, answers on Operations Research Stack Exchange point to column generation, which builds the plan from whole shift patterns. We test on one month of your data before scaling up.

Because proving that a rota is the best possible can take far longer than finding a very good one. The OR-Tools documentation recommends setting a limit for exactly that reason. When time runs out, you get the best plan found so far. We pick the limit from your planning window, not from a default.

Sometimes they can, and then we’ll say so. Standard tools are built for an average problem, though. With Constraint programming, we start from yours: its size, its rules and the exceptions nobody wrote down. That is why the plan fits your operation better.

You don’t need either to start. We build the model from the data you’ve got, messy or not, and cleaning it up is part of the job. You get a documented system your team can maintain, and we train them until they can run it long after we’ve left.

It starts with a free 30-minute call about your operation and the model that would fit it. Then we build a working prototype and run it on your numbers. You’ll see results before you commit to anything bigger.

Tell us what you’re planning.

In a free 30-minute call with a specialist, you find out whether optimisation can help.

  • Free, no commitment
  • You talk to a specialist directly
  • A clear go or no-go