Skip to content

生産計画問題 (LP / MIP) ​

問題クラスソルバー主な APIリンク
線形計画・整数計画 (LP / MIP)HiGHS (標準)m.integer(), m.constraint(), c, expr

限られたリソース(木材・労働時間など)の制約を守りながら、どの製品をいくつ生産すれば総利益が最大になるかを求める古典的な最適化問題です。

数理モデルの定式化 ​

椅子(chairs)の生産数を xx、机(tables)の生産数を yy とします。

Maximize45x+80y(総利益)Subject to5x+20y≤400(マホガニー材の上限)10x+15y≤450(木工労働時間の上限)x,y≥0,x,y∈Z\begin{aligned} \text{Maximize} \quad & 45x + 80y & (\text{総利益}) \\ \text{Subject to} \quad & 5x + 20y \le 400 & (\text{マホガニー材の上限}) \\ & 10x + 15y \le 450 & (\text{木工労働時間の上限}) \\ & x, y \ge 0, \quad x, y \in \mathbb{Z} \end{aligned}

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();
Playground で開く →

Released under the MIT License.