鸡尾酒优化:一个整数规划问题
Cocktail Optimization, an Integer Programming Problem

原始链接: https://bunkum.us/2026/06/18/cocktail-ingredients-milp

作者长期以来热衷于整数规划,此前一直依赖自定义的分支定界算法来处理重复数据删除和优化等任务。然而,在尝试使用 Google 的 OR-Tools 和其他混合整数线性规划(MILP)求解器进行车辆路径规划后,作者不得不承认,这些专业级工具的表现远超自己编写的代码。 为了说明这一点,作者重温了一个此前曾用定制算法解决过的鸡尾酒优化问题。作者原本的求解器在处理 30 种配料时表现吃力,不仅需要耗费数分钟才能找到方案,还无法确认是否为最优解;而现代 MILP 求解器(glpk.js)仅用几毫秒就完成了任务。这一经历是一个令人谦卑的提醒:成熟且经过高度工程化的求解器凝聚了数千小时的集体研究成果,个人很难通过自身努力去复制。

关于“将鸡尾酒优化问题视为整数规划问题”的 Hacker News 讨论中,呈现出两种截然不同的观点。 一位用户指出,《迪福德指南》(*Difford's Guide*)是一个现成的实用工具,能够根据现有配料匹配鸡尾酒配方。他们提到,此类平台可以将家庭酒吧的藏酒“游戏化”,往往会促使用户购买新配料以解锁更多配方。 另一位用户则质疑构建定制求解器的必要性,认为现有的开源解决方案(如 HiGHS)在处理线性规划方面已经非常高效。尽管如此,讨论最终以一种有趣的讽刺告终:该项目的复杂性反而激发了其他人尝试构建自己的求解器。
相关文章

原文

June 18, 2026

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 30 ingredients, you can make 29 cocktail(s).

0102030405060708090100↑ Cocktails you can make20406080100120Ingredients on your tray →29

Here’s the shopping list:

Ingredient Number of Cocktails
联系我们 contact @ memedata.com