Optimisation lab: linear, integer and constraint models with PuLP and OR-Tools on one private Ubuntu VM

This lab gives each student the solvers an operations research team uses, in one Ubuntu VM. The student writes a decision as a model, a goal and some limits, hands it to a solver, and reads the answer: the status first, then the plan, then what each limit is worth. Two models the student writes are marked by a script that runs them on instances the student never sees.

Nothing is installed on the student’s computer. PuLP with the CBC solver comes from Ubuntu’s archive, and Google’s OR-Tools, with its CP-SAT constraint solver, is installed from PyPI into the VM the first time it starts. The operations research module solves its problems with SciPy in the JupyterLab lab, and this lab is the place a student meets the modelling tools and solvers used in practice.

What students learn

How a decision becomes a model. A linear programme in PuLP makes tables and chairs from limited wood, hours and storage, and the report shows the status, the plan, the slack of each limit and its shadow price, which says which limit is worth buying more of. An integer programme chooses whole projects: the same model is solved with fractions allowed and without, and rounding the first answer breaks a limit. A CP-SAT model makes a nurse rota from rules and wishes, and reads OPTIMAL, FEASIBLE or INFEASIBLE from the solver.

The five parts

First a linear programme: lp.py is run and its status, plan and shadow prices are read, then a limit is changed and the profit is compared with the shadow price. Second whole numbers: integer.py solves the same kind of model with and without fractions. Third a constraint model: shifts.py makes a rota with CP-SAT, and the student adds a rule and breaks one. Fourth the three models changed by hand. Fifth two models the student writes, plan.py and rota.py, from a comment that says exactly what each must read and print. Everything the student edits is in the folder optimisation, and README.md in the home folder says what to do and gives none of the answers.

Run it in your browser

VM labs are set as a lab task in a module, and the sample is on the lab’s page. The machine is small: one CPU, 1 GB of memory and 10 GB of disk. A model solves in well under a second.

  1. Add the lab. In a module you teach, add a task and choose the Ubuntu VM lab card. The page shows a short description of the machine instead of a compose file.
  2. Start from the sample. The page offers ready-made labs to start from. Choose Optimisation. Using a sample replaces the text, and Undo brings yours back.
  3. Publish and start your own copy. Publish, then Start. The lab’s own setup script installs PuLP, the CBC and GLPK solvers and OR-Tools from Ubuntu’s archive and from PyPI, and writes the opt helper, the models to work on and the README, the first time the VM starts, in a minute or two.
  4. Open the terminal. Open its terminal and read README.md in the home folder. Nothing opens in the browser: the lab is the terminal.

A basic lesson on this lab

Optimisation Basics is a small lesson worked in this lab, which is an Ubuntu VM. It has a hook, an I can outcome, key words, a starter, a check after each idea, a common mistake and an exit check, and each step has a Run button that types its command into the machine’s terminal. A student runs the linear programme and reads its shadow prices, runs the integer programme to see why rounding fails, and runs the rota.

The lesson looks around and leaves the lab’s own task, the two models, to the student, so it hands out no answers.

How it is marked

The lab has a check. It runs on a copy of the saved machine and runs plan.py on three project-selection instances it draws afresh. The profit the program prints must be the best there is, which the check finds by trying every plan, the plan must obey the budget and the hours, and the bound must match what a different solver, GLPK, says the same model is worth with fractions allowed. It runs rota.py on two nurse rotas it draws afresh and on one that cannot be met: the cost must be the fewest broken wishes the check works out by another method, every rule of the rota is checked, and the impossible one must say INFEASIBLE. The programs run as the student, and the check counts that each really called a solver. A program that starts another program, or has no PuLP or OR-Tools in it, is refused. The first line of what the check printed says why.

  1. Hand it out. Assign the lab like any task, with a due date if you want one. Each student gets a VM of their own, kept between sessions.
  2. Run the check. On a student’s row in the class list, press Run the check. It starts a copy of their saved machine that is not saved back, runs the lab’s check script as root and shows whether it passed, what it printed and when. The student is not told the result.
  3. Mark it. Read the first line of what the check printed: it says what is not right, such as a best plan that is worth less than the best one, or a rota that breaks more wishes than it has to. Send the work back with a reason if it needs more.

The definition on GitHub

The file is the whole lab definition, the same text the platform runs: size, setup script, helper command, the models to work on, the README and the check. Copy it and change the numbers or the problems to make a longer lab.

Try this lab, and what it costs

A free personal account can work through the basic lessons in this lab, with enough free credit each month to follow most lessons and no card. For a class, a school or college has its first 365 days free for up to 50 students, then pays per student a year, with every lab included and staff free.

Questions people ask

Does the lab need a licence?
No. OR-Tools is Apache-2.0, PuLP is MIT, and the CBC and GLPK solvers are open source (EPL and GPL). They are installed on the student’s VM when it starts, from Ubuntu’s archive and from PyPI, so we distribute none of them.
Why two tools, and how does this differ from the SciPy in the operations research module?
PuLP writes linear and integer programmes and hands them to a solver such as CBC. OR-Tools CP-SAT is a constraint solver, good at rotas, timetables and routes. SciPy’s linprog is a linear programme solver only. The module teaches the method with SciPy, and this lab lets a student run the tools used for bigger problems, and for whole numbers.
Can students harm anything?
Only their own copy. The machine of a visitor without an account reaches Ubuntu’s archive and the Python package index and nothing else, and if a student breaks a file, opt reset puts it back as it was given.
Was the lab tested in a real student VM?
The setup, the lesson’s commands and the check, with each way of faking it, were run in a real Ubuntu 26.04 container standing in for the VM, on an arm64 machine. PyPI has OR-Tools wheels for both arm64 and amd64, but a booted student VM and the amd64 install are worth one try before a class.