Cocktail Optimization, an Integer Programming Problem

June 18, 2026 | Permalink

I’ve been interested in integer programming problems for a long time (they the most interesting problems in dedupe). In the past, I approached them by writing custom branch-and-bound algorithms.

I have been using Google’s OR Tools for a project that involves a lot of vehicle routing, and I started to wonder how these mixed integer linear programming solvers would do against my lovingly crafted algorithms.

They utterly surpass them. These solvers are technical marvels, containing the congealed knowledge of thousands of hours of research and engineering. Of course my code wasn’t really going to compete.

A few years ago, I wrote a branch-and-bound solver for the problem of maximizing the number of cocktails you can make with certain number of ingredients on your cocktail tray. I was pretty proud of it, but if you set your ingredient budget to 30, it will take many minutes to find the optimum solution, and it would basically never stop looking for a better one.

As you can see below, with glpk.js, it takes milliseconds to find a final optimum.

With ingredients, you can make cocktail(s).

Cocktail Ingredients

Here’s the shopping list:

Ingredient Number of Cocktails