生産計画問題 (LP / MIP)
| 問題クラス | ソルバー | 主な API | リンク |
|---|---|---|---|
| 線形計画・整数計画 (LP / MIP) | HiGHS (標準) | m.integer(), m.constraint(), c, expr |
限られたリソース(木材・労働時間など)の制約を守りながら、どの製品をいくつ生産すれば総利益が最大になるかを求める古典的な最適化問題です。
数理モデルの定式化
椅子(chairs)の生産数を 、机(tables)の生産数を とします。
WaSHI による実装
typescript
import { Model, expr, c, maximize } from "@ohtaman/washi";
async function runProductionOptimization() {
const m = new Model("FactoryProduction");
// 決定変数: 椅子と机の生産数 (非負整数)
const chairs = m.integer("chairs", { lb: 0 });
const tables = m.integer("tables", { lb: 0 });
// 目的関数: 総利益の最大化 ($45/椅子, $80/机)
m.objective(maximize(expr`45 * ${chairs} + 80 * ${tables}`));
// リソース制約: m.constraint と c による宣言的記述 (メソッドチェーン可能)
m.constraint(c`5 * ${chairs} + 20 * ${tables} <= 400`, "mahogany_limit")
.constraint(c`10 * ${chairs} + 15 * ${tables} <= 450`, "labor_limit");
const status = await m.solve();
console.log(`Status: ${status}`);
console.log(`Optimal Profit: $${m.objectiveValue}`);
console.log(`Chairs: ${chairs.value}, Tables: ${tables.value}`);
}
runProductionOptimization();