@ohtaman/washi 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +58 -19
- package/README.md +58 -19
- package/README.zh-CN.md +58 -19
- package/THIRD_PARTY_LICENSES.md +34 -1
- package/dist/browser/__vite-browser-external-rTVKos2U.js +7 -0
- package/dist/browser/browser-runtime-AG5QFtKf.js +2021 -0
- package/dist/browser/highs-worker.js +26 -11
- package/dist/browser/highs.wasm +0 -0
- package/dist/browser/{loader-DewlSho8.js → loader-i3FnqMes.js} +183 -149
- package/dist/browser/solvers/glpk.js +289 -238
- package/dist/browser/solvers/glpk.min.js +1 -1
- package/dist/browser/solvers/pumpkin-_washi-pumpkin-node-runtime-CEKUDK6d.js +9 -0
- package/dist/browser/solvers/pumpkin-loader-CvdaKxf4.js +320 -0
- package/dist/browser/solvers/pumpkin-worker.js +45 -0
- package/dist/browser/solvers/pumpkin.js +1777 -0
- package/dist/browser/solvers/pumpkin.min.js +1 -0
- package/dist/browser/solvers/pumpkin.wasm +0 -0
- package/dist/browser/solvers/pumpkin.wasm.LICENSE +21 -0
- package/dist/browser/solvers/z3.js +1600 -1335
- package/dist/browser/solvers/z3.min.js +2 -2
- package/dist/browser/washi.js +3374 -1377
- package/dist/browser/washi.min.js +5 -3
- package/dist/lib/__vite-browser-external-oLchLuMx.js +7 -0
- package/dist/lib/highs-browser-runtime.js +1846 -1618
- package/dist/lib/highs-runtime.js +16 -2
- package/dist/lib/highs-worker.js +26 -11
- package/dist/lib/highs.wasm +0 -0
- package/dist/lib/{loader-BZUQNvh4.js → loader-CDpPXN_F.js} +138 -116
- package/dist/lib/registry-dx7x4e5c.js +1694 -0
- package/dist/lib/rolldown-runtime-DtPi1Y-2.js +13 -0
- package/dist/lib/solvers/glpk.js +161 -121
- package/dist/lib/solvers/pumpkin-assets.js +1 -0
- package/dist/lib/solvers/pumpkin-loader-Ow74Fa1B.js +311 -0
- package/dist/lib/solvers/pumpkin-node-runtime.js +15 -0
- package/dist/lib/solvers/pumpkin-worker-factory.js +1 -0
- package/dist/lib/solvers/pumpkin-worker.js +45 -0
- package/dist/lib/solvers/pumpkin.js +1767 -0
- package/dist/lib/solvers/pumpkin.wasm +0 -0
- package/dist/lib/solvers/pumpkin.wasm.LICENSE +21 -0
- package/dist/lib/solvers/z3.js +486 -306
- package/dist/lib/washi.js +2563 -1154
- package/dist/types/decomposition/benders.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modeler/boolean-expr.d.ts +137 -29
- package/dist/types/modeler/boolean-expr.d.ts.map +1 -1
- package/dist/types/modeler/constraint.d.ts +40 -4
- package/dist/types/modeler/constraint.d.ts.map +1 -1
- package/dist/types/modeler/expression.d.ts +129 -2
- package/dist/types/modeler/expression.d.ts.map +1 -1
- package/dist/types/modeler/index.d.ts +4 -5
- package/dist/types/modeler/index.d.ts.map +1 -1
- package/dist/types/modeler/linearizer.d.ts +11 -2
- package/dist/types/modeler/linearizer.d.ts.map +1 -1
- package/dist/types/modeler/lp-writer.d.ts.map +1 -1
- package/dist/types/modeler/model.d.ts +85 -124
- package/dist/types/modeler/model.d.ts.map +1 -1
- package/dist/types/modeler/parser.d.ts.map +1 -1
- package/dist/types/modeler/quad-expr.d.ts +8 -2
- package/dist/types/modeler/quad-expr.d.ts.map +1 -1
- package/dist/types/modeler/solution-validator.d.ts +12 -12
- package/dist/types/modeler/solution-validator.d.ts.map +1 -1
- package/dist/types/modeler/solvers/glpk/loader.d.ts +4 -0
- package/dist/types/modeler/solvers/glpk/loader.d.ts.map +1 -1
- package/dist/types/modeler/solvers/glpk/solver.d.ts +2 -2
- package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/driver.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/loader.d.ts +8 -6
- package/dist/types/modeler/solvers/highs/loader.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/worker-client.d.ts +16 -0
- package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
- package/dist/types/modeler/solvers/mock.d.ts +2 -3
- package/dist/types/modeler/solvers/mock.d.ts.map +1 -1
- package/dist/types/modeler/solvers/pumpkin/assets.d.ts +2 -0
- package/dist/types/modeler/solvers/pumpkin/assets.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/index.d.ts +6 -0
- package/dist/types/modeler/solvers/pumpkin/index.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/loader.d.ts +40 -0
- package/dist/types/modeler/solvers/pumpkin/loader.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts +3 -0
- package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/solver.d.ts +23 -0
- package/dist/types/modeler/solvers/pumpkin/solver.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts +74 -0
- package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts +3 -0
- package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/worker.d.ts +7 -0
- package/dist/types/modeler/solvers/pumpkin/worker.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin.d.ts +2 -0
- package/dist/types/modeler/solvers/pumpkin.d.ts.map +1 -0
- package/dist/types/modeler/solvers/registry.d.ts.map +1 -1
- package/dist/types/modeler/solvers/types.d.ts +7 -9
- package/dist/types/modeler/solvers/types.d.ts.map +1 -1
- package/dist/types/modeler/solvers/z3/loader.d.ts +4 -0
- package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
- package/dist/types/modeler/solvers/z3/solver.d.ts +2 -15
- package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -1
- package/dist/types/modeler/types.d.ts +12 -15
- package/dist/types/modeler/types.d.ts.map +1 -1
- package/dist/types/modeler/validation.d.ts +26 -2
- package/dist/types/modeler/validation.d.ts.map +1 -1
- package/dist/types/modeler/variable.d.ts +9 -5
- package/dist/types/modeler/variable.d.ts.map +1 -1
- package/docs/examples/index.md +6 -1
- package/docs/examples/project-scheduling.md +106 -0
- package/docs/examples/shift-scheduling.md +3 -0
- package/docs/examples/smt-security.md +1 -0
- package/docs/examples/traveling-salesperson.md +1 -1
- package/docs/examples/unsat-core.md +3 -2
- package/docs/getting-started/ai-agents.md +94 -25
- package/docs/getting-started/coding-agents.md +158 -0
- package/docs/getting-started/cross-origin.md +2 -2
- package/docs/getting-started/index.md +40 -41
- package/docs/getting-started/runtimes.md +42 -18
- package/docs/guide/constraint-programming.md +141 -0
- package/docs/guide/constraints.md +64 -14
- package/docs/guide/decomposition.md +59 -59
- package/docs/guide/expressions.md +42 -10
- package/docs/guide/formulation-tips.md +6 -6
- package/docs/guide/objectives.md +65 -62
- package/docs/guide/unsat-core.md +36 -27
- package/docs/guide/variables.md +30 -17
- package/docs/solvers/custom-solver.md +18 -13
- package/docs/solvers/highs.md +18 -23
- package/docs/solvers/index.md +12 -6
- package/docs/solvers/pumpkin.md +163 -0
- package/docs/solvers/z3.md +2 -2
- package/llms-full.txt +944 -314
- package/llms.txt +43 -22
- package/package.json +38 -11
- package/skills/washi/SKILL.md +79 -27
- package/dist/browser/_washi-node-only-BvRk9kiK.js +0 -0
- package/dist/browser/browser-runtime-TLCY0hkc.js +0 -1793
- package/dist/lib/_washi-node-only-BvRk9kiK.js +0 -0
- package/dist/lib/registry-D7TZ3Wh_.js +0 -1034
- package/docs/ja/getting-started/ai-agents.md +0 -280
- package/docs/zh/getting-started/ai-agents.md +0 -280
package/README.ja.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
</picture>
|
|
7
7
|
<p><strong>TypeScript 数理最適化モデラー</strong></p>
|
|
8
8
|
<p>
|
|
9
|
-
<em>線形計画 (LP) • 混合整数計画 (MIP) • 凸二次計画 (QP) • SMT論理制約 & 矛盾診断</em>
|
|
9
|
+
<em>線形計画 (LP) • 混合整数計画 (MIP) • 凸二次計画 (QP) • 制約プログラミング (CP) • SMT論理制約 & 矛盾診断</em>
|
|
10
10
|
</p>
|
|
11
11
|
<p>
|
|
12
12
|
<a href="./README.md">English</a> •
|
|
@@ -24,22 +24,22 @@
|
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
27
|
-
**WaSHI**(WebAssembly-backed, Solver-independent, High-level modeling Interface)は、Python の **PuLP** に着想を得た、数理最適化と制約プログラミングのための TypeScript / JavaScript 向け代数モデラーです。変数・目的関数・制約をアプリケーションコードで記述し、Node.js
|
|
27
|
+
**WaSHI**(WebAssembly-backed, Solver-independent, High-level modeling Interface)は、Python の **PuLP** に着想を得た、数理最適化と制約プログラミングのための TypeScript / JavaScript 向け代数モデラーです。変数・目的関数・制約をアプリケーションコードで記述し、Node.js やブラウザ上で標準同梱の **HiGHS**(デフォルト)・**Pumpkin**(`@ohtaman/washi/solvers/pumpkin`)、あるいはオプションの **Z3**・**GLPK** を使ってそのまま求解できます。
|
|
28
28
|
|
|
29
29
|
## ✨ 主な特徴
|
|
30
30
|
|
|
31
31
|
- **直感的な数式記述**: `` expr`30 * ${x} + 50 * ${y} <= 40` `` や総和・内積(`sum`, `dot`)で数式と制約を簡潔に書けます。
|
|
32
32
|
- **Node.js・ブラウザで完結**: WebAssembly ベースのため、Python サーバーや C/C++ のネイティブビルドなしで動作します。
|
|
33
|
-
- **ソルバー非依存**:
|
|
33
|
+
- **ソルバー非依存**: 追加依存なしの同梱 **HiGHS**(LP/MIP/QP)・**Pumpkin**(CP/LCG)に加え、オプションの **Z3**・**GLPK** や独自ソルバーへ切り替えられます。
|
|
34
34
|
- **充足判定と矛盾診断**: 論理・数値制約の充足可能性判定や、実行不能(Infeasible)になった原因制約の特定に対応しています。
|
|
35
35
|
- **大規模問題の分解法**: 列生成法やベンダーズ分解などの分解アルゴリズムをサポートしています。
|
|
36
36
|
|
|
37
37
|
## 📚 ドキュメント & リンク
|
|
38
38
|
|
|
39
39
|
- **[ドキュメント](https://washi.ohtaman.dev/ja/)**: モデリングガイド・ソルバー仕様・環境別の導入手順
|
|
40
|
-
- **[ショーケース](https://washi.ohtaman.dev/ja/showcase/)
|
|
40
|
+
- **[ショーケース](https://washi.ohtaman.dev/ja/showcase/) · [ブラウザデモ](https://washi.ohtaman.dev/demo/) · [数理最適化N本ノック](https://washi.ohtaman.dev/exercises/?lang=ja)**: ブラウザ上で動くデモアプリ集・プレイグラウンド・N本ノックを体験できます
|
|
41
41
|
- **[サンプル集](https://washi.ohtaman.dev/ja/examples/)**: 課題別の実践レシピと実行可能なサンプルコード([`examples/`](examples/README.md))
|
|
42
|
-
- **[
|
|
42
|
+
- **[Agent Skill (`SKILL.md`)](skills/washi/SKILL.md) · [`llms.txt`](https://washi.ohtaman.dev/llms.txt) / [`llms-full.txt`](https://washi.ohtaman.dev/llms-full.txt)**: AI コーディングエージェント向けのスキル定義・機械可読ドキュメント
|
|
43
43
|
|
|
44
44
|
---
|
|
45
45
|
|
|
@@ -47,9 +47,10 @@
|
|
|
47
47
|
|
|
48
48
|
```bash
|
|
49
49
|
npm install @ohtaman/washi
|
|
50
|
+
# HiGHS (LP/MIP/QP) と Pumpkin (CP/LCG, @ohtaman/washi/solvers/pumpkin) は追加依存なしで同梱されています
|
|
50
51
|
|
|
51
|
-
#
|
|
52
|
-
npm install z3-solver # SMT
|
|
52
|
+
# オプションの peer-dependency ソルバープラグイン
|
|
53
|
+
npm install z3-solver # SMT 論理制約・実数を含む厳密 Unsat Core 診断を使う場合
|
|
53
54
|
npm install glpk.js # GLPK ソルバーを使う場合 (GPL-3.0)
|
|
54
55
|
|
|
55
56
|
# AI コーディングエージェント用スキル (Claude Code, Cursor, Codex 等)
|
|
@@ -77,12 +78,13 @@ console.log(`生産量: x=${x.value}, y=${y.value} (最大利益: $${m.objective
|
|
|
77
78
|
|
|
78
79
|
| ソルバー | ライセンス | 対応クラス | 主な用途 | 導入方法 |
|
|
79
80
|
| :--- | :--- | :--- | :--- | :--- |
|
|
80
|
-
| **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | MIT | LP, MIP, 凸QP | 数値最適化・エラスティック矛盾修復 |
|
|
81
|
-
| **[
|
|
82
|
-
| **[
|
|
81
|
+
| **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | MIT | LP, MIP, 凸QP | 数値最適化・エラスティック矛盾修復 | 標準搭載(追加依存なし) |
|
|
82
|
+
| **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** | MIT | CP, LCG, 論理, 有界整数 | スケジューリング・COOP/COEP不要の `unsatCore` | `import "@ohtaman/washi/solvers/pumpkin"`(WASM同梱・追加依存なし) |
|
|
83
|
+
| **[Z3](https://github.com/Z3Prover/z3)** | MIT | SMT, SAT, 論理, MIP | 論理ルール・充足判定・厳密な `unsatCore` | `npm install z3-solver` + `import "@ohtaman/washi/solvers/z3"` |
|
|
84
|
+
| **[GLPK](https://www.gnu.org/software/glpk/)** | GPL-3.0 | LP, MIP | 線形・混合整数最適化 | `npm install glpk.js` + `import "@ohtaman/washi/solvers/glpk"` |
|
|
83
85
|
| **Mock** | MIT | — | テスト用の決定論的な模擬応答 | 標準搭載 (`MockSolver`) |
|
|
84
86
|
|
|
85
|
-
プラグインを import した上で、`new Model(...)`・`m.solve(...)`・`m.check(...)` に `{ solver: "
|
|
87
|
+
プラグインを import した上で、`new Model(...)`・`m.solve(...)`・`m.check(...)` に `{ solver: "pumpkin" }`・`{ solver: "z3" }`・`{ solver: "glpk" }` を渡して切り替えます。
|
|
86
88
|
|
|
87
89
|
---
|
|
88
90
|
|
|
@@ -135,15 +137,46 @@ await m.solve();
|
|
|
135
137
|
console.log(`Tech: ${x.value?.toFixed(2)}, Bonds: ${y.value?.toFixed(2)}`);
|
|
136
138
|
```
|
|
137
139
|
|
|
138
|
-
### 3.
|
|
140
|
+
### 3. 制約プログラミング & スケジューリング (Pumpkin)
|
|
141
|
+
|
|
142
|
+
同梱の **Pumpkin**(`@ohtaman/washi/solvers/pumpkin`)を使うと、追加依存なしで有界整数スケジューリングや CP グローバル制約(`disjoint`, `distinct`, `cumulative`, `allowed`)を求解できます:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import { Model, expr, disjoint, distinct, minimize } from "@ohtaman/washi";
|
|
146
|
+
import "@ohtaman/washi/solvers/pumpkin";
|
|
147
|
+
|
|
148
|
+
const m = new Model("WorkshopCP", { solver: "pumpkin" });
|
|
149
|
+
const start = m.integer(["cut", "weld", "paint"] as const, { lb: 0, ub: 20, prefix: "start" });
|
|
150
|
+
const bench = m.integer(["cut", "weld", "paint"] as const, { lb: 1, ub: 3, prefix: "bench" });
|
|
151
|
+
|
|
152
|
+
m.constraint(
|
|
153
|
+
disjoint([
|
|
154
|
+
{ start: start.cut, duration: 4 },
|
|
155
|
+
{ start: start.weld, duration: 3 },
|
|
156
|
+
{ start: start.paint, duration: 2 },
|
|
157
|
+
]),
|
|
158
|
+
"single_line"
|
|
159
|
+
);
|
|
160
|
+
m.constraint(expr`${start.cut} + 4 <= ${start.weld}`, "cut_before_weld");
|
|
161
|
+
m.constraint(expr`${start.weld} + 3 <= ${start.paint}`, "weld_before_paint");
|
|
162
|
+
m.constraint(distinct(bench), "unique_benches");
|
|
163
|
+
|
|
164
|
+
m.objective(minimize(expr`${start.paint} + 2`));
|
|
165
|
+
await m.solve();
|
|
166
|
+
console.log(`Makespan: ${m.objectiveValue}h (paint starts at ${start.paint.value}h)`);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 4. 論理ルール & 矛盾診断 (`m.check`)
|
|
139
170
|
|
|
140
171
|
論理条件(`m.bool`, `implies`)を含むモデルの充足可能性を判定し、矛盾時の原因制約を特定します:
|
|
141
172
|
- **HiGHS(標準)**: 緩和すれば実行可能になる**修復集合**(`res.conflicts`)を特定します。
|
|
142
|
-
- **
|
|
173
|
+
- **Pumpkin(同梱)**: 有界整数・真偽値モデルに対して、**COOP/COEP ヘッダー不要**でスケール不変な**充足不能コア**(`res.unsatCore` / `res.conflicts`)を抽出します。
|
|
174
|
+
- **Z3**: 連続変数・実数演算を含む厳密な SMT **充足不能コア**(`res.unsatCore` / `res.conflicts`)を抽出します。
|
|
143
175
|
|
|
144
176
|
```ts
|
|
145
177
|
import { Model, implies, expr } from "@ohtaman/washi";
|
|
146
|
-
// import "@ohtaman/washi/solvers/
|
|
178
|
+
// import "@ohtaman/washi/solvers/pumpkin"; // COOP/COEP 不要の unsatCore(有界整数・真偽値)
|
|
179
|
+
// import "@ohtaman/washi/solvers/z3"; // Continuous 変数を含む厳密 SMT unsatCore
|
|
147
180
|
|
|
148
181
|
const m = new Model("StaffingRules");
|
|
149
182
|
const engineers = m.integer("engineers", { lb: 0, ub: 20 });
|
|
@@ -165,24 +198,29 @@ console.log(res.conflicts); // HiGHS: ["rush_required"]
|
|
|
165
198
|
|
|
166
199
|
## 🌐 ブラウザ & Web Worker での利用方法
|
|
167
200
|
|
|
168
|
-
- **バンドラー (Vite / webpack 5)**: `import { Model } from "@ohtaman/washi"`
|
|
169
|
-
- **単体 ESM / script タグ / CDN**: `dist/browser/` 一式(`highs.wasm` や Worker を含む)を配信するか、CDN の URL を指定して読み込みます。
|
|
201
|
+
- **バンドラー (Vite / webpack 5)**: `import { Model } from "@ohtaman/washi"` でそのまま動作します。**HiGHS** と **Pumpkin** はいずれもブラウザで標準で専用 Web Worker 上で実行され(メインスレッドで実行する場合は `{ useWorker: false }` を指定)、**COOP/COEP ヘッダーは不要**です。
|
|
202
|
+
- **単体 ESM / script タグ / CDN**: `dist/browser/` 一式(`highs.wasm`、`solvers/pumpkin.wasm` や Worker を含む)を配信するか、CDN の URL を指定して読み込みます。
|
|
170
203
|
|
|
171
204
|
```html
|
|
172
205
|
<!-- ブラウザ ESM -->
|
|
173
206
|
<script type="module">
|
|
174
207
|
import { Model } from "./washi/washi.js";
|
|
175
|
-
//
|
|
208
|
+
// 同梱・オプションプラグイン:
|
|
209
|
+
// import "./washi/solvers/pumpkin.js"; // 同梱 CP/LCG (COOP/COEP 不要)
|
|
210
|
+
// import "./washi/solvers/glpk.js"; // オプション GLPK プラグイン
|
|
211
|
+
// import "./washi/solvers/z3.js"; // オプション Z3 プラグイン (COOP/COEP 必要)
|
|
176
212
|
const m = new Model();
|
|
177
213
|
await m.solve();
|
|
178
214
|
</script>
|
|
179
215
|
|
|
180
216
|
<!-- script タグ / CodePen (グローバル Washi を公開) -->
|
|
181
217
|
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/washi.min.js"></script>
|
|
218
|
+
<!-- オプションプラグインスクリプト (window.Washi に自動登録): -->
|
|
219
|
+
<!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/pumpkin.min.js"></script> -->
|
|
182
220
|
```
|
|
183
221
|
|
|
184
222
|
> [!NOTE]
|
|
185
|
-
> **ブラウザでの Z3 利用**: Z3 の WebAssembly は `SharedArrayBuffer` を使用するため、Cross-Origin Isolation(`COOP: same-origin` / `COEP: require-corp`)が必要です。詳細は [Cross-Origin Isolation 設定](docs/ja/getting-started/cross-origin.md) および [`examples/distribution/`](examples/distribution/README.md)
|
|
223
|
+
> **ブラウザでの Z3 利用**: Z3 の WebAssembly は `SharedArrayBuffer` を使用するため、Cross-Origin Isolation(`COOP: same-origin` / `COEP: require-corp`)が必要です。詳細は [Cross-Origin Isolation 設定](docs/ja/getting-started/cross-origin.md) および [`examples/distribution/`](examples/distribution/README.md) を参照してください。**HiGHS**、**Pumpkin**(有界整数・真偽値に対する `unsatCore` を含む)、および **GLPK** は Cross-Origin Isolation ヘッダーなしで動作します。
|
|
186
224
|
|
|
187
225
|
---
|
|
188
226
|
|
|
@@ -197,6 +235,7 @@ console.log(res.conflicts); // HiGHS: ["rush_required"]
|
|
|
197
235
|
WaSHI は、数理最適化および自動推論分野の素晴らしいオープンソースソフトウェアの上に成り立っています:
|
|
198
236
|
|
|
199
237
|
- **[HiGHS](https://highs.dev/)**([`ERGO-Code/HiGHS`](https://github.com/ERGO-Code/HiGHS))— エディンバラ大学の Julian Hall 氏、Qi Huangfu 氏、Ivet Galabova 氏、Leona Gottwald 氏、Michael Feldmeier 氏をはじめとする開発チームによる高性能なオープンソース LP / MIP / 凸 QP ソルバーであり、WaSHI の標準エンジンを支えています(*Huangfu & Hall, Mathematical Programming Computation, 2018*, [DOI: 10.1007/s12532-017-0130-5](https://doi.org/10.1007/s12532-017-0130-5))。
|
|
238
|
+
- **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** — デルフト工科大学 ConSol Lab により Rust で開発された LCG(Lazy Clause Generation)制約プログラミングソルバーであり、WaSHI の同梱 CP/LCG および COOP/COEP 不要な `unsatCore` エンジンを支えています。
|
|
200
239
|
- **[Z3 Theorem Prover](https://github.com/Z3Prover/z3)**([`z3-solver`](https://www.npmjs.com/package/z3-solver))— Microsoft Research により開発された SMT ソルバーであり、オプションの論理充足判定および `unsatCore` 矛盾診断プラグインを支えています。
|
|
201
240
|
- **[GLPK](https://www.gnu.org/software/glpk/) & [`glpk.js`](https://github.com/jvail/glpk.js)** — オプションの GPL-3.0 LP / MIP ソルバープラグインを支えています。
|
|
202
241
|
- **[PuLP](https://github.com/coin-or/pulp)** — WaSHI の直感的な代数モデリング API 設計に大きな着想を与えました。
|
|
@@ -206,4 +245,4 @@ WaSHI は、数理最適化および自動推論分野の素晴らしいオー
|
|
|
206
245
|
## 📄 ライセンス
|
|
207
246
|
|
|
208
247
|
- **`@ohtaman/washi`**: [MIT ライセンス](./LICENSE)
|
|
209
|
-
- **同梱・外部ソルバー**: HiGHS (MIT)、Z3 (MIT)、GLPK (GPL-3.0)。詳細は [THIRD_PARTY_LICENSES.md](./THIRD_PARTY_LICENSES.md) を参照してください。
|
|
248
|
+
- **同梱・外部ソルバー**: HiGHS (MIT)、Pumpkin (MIT)、Z3 (MIT)、GLPK (GPL-3.0)。詳細は [THIRD_PARTY_LICENSES.md](./THIRD_PARTY_LICENSES.md) を参照してください。
|
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
</picture>
|
|
7
7
|
<p><strong>Mathematical Optimization Modeler in TypeScript</strong></p>
|
|
8
8
|
<p>
|
|
9
|
-
<em>Linear Programming (LP) • Mixed-Integer Programming (MIP) • Convex Quadratic Programming (QP) • SMT & Conflict Diagnosis</em>
|
|
9
|
+
<em>Linear Programming (LP) • Mixed-Integer Programming (MIP) • Convex Quadratic Programming (QP) • Constraint Programming (CP) • SMT & Conflict Diagnosis</em>
|
|
10
10
|
</p>
|
|
11
11
|
<p>
|
|
12
12
|
<a href="./README.md">English</a> •
|
|
@@ -24,22 +24,22 @@
|
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
27
|
-
**WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) is an algebraic modeler for mathematical optimization and constraint programming in TypeScript and JavaScript, inspired by Python's **PuLP**. Define variables, objectives, and constraints in application code, and solve them locally in Node.js or the browser using **HiGHS** (default), **Z3
|
|
27
|
+
**WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) is an algebraic modeler for mathematical optimization and constraint programming in TypeScript and JavaScript, inspired by Python's **PuLP**. Define variables, objectives, and constraints in application code, and solve them locally in Node.js or the browser using bundled **HiGHS** (default) and **Pumpkin** (`@ohtaman/washi/solvers/pumpkin`), or optional **Z3** and **GLPK** plugins.
|
|
28
28
|
|
|
29
29
|
## ✨ Key Features
|
|
30
30
|
|
|
31
31
|
- **Natural Algebraic Syntax**: Write expressions and constraints directly with `` expr`30 * ${x} + 50 * ${y} <= 40` ``, `sum`, and `dot`.
|
|
32
32
|
- **Runs in Node.js & Browsers**: Powered by WebAssembly—no Python service or native C/C++ build required.
|
|
33
|
-
- **Solver-Independent**: Use
|
|
33
|
+
- **Solver-Independent**: Use bundled zero-dependency **HiGHS** (LP/MIP/QP) and **Pumpkin** (CP/LCG), optional **Z3** and **GLPK** plugins, or custom solver adapters.
|
|
34
34
|
- **Satisfiability & Conflict Diagnosis**: Check logical/arithmetic feasibility and pinpoint contradictory constraints when a model is infeasible.
|
|
35
35
|
- **Decomposition Methods**: Built-in support for Column Generation and Benders Decomposition on large-scale problems.
|
|
36
36
|
|
|
37
37
|
## 📚 Documentation & Links
|
|
38
38
|
|
|
39
39
|
- **[Documentation](https://washi.ohtaman.dev/)**: Modeling guide, solver references, and deployment guides
|
|
40
|
-
- **[Interactive Showcase](https://washi.ohtaman.dev/showcase/)
|
|
40
|
+
- **[Interactive Showcase](https://washi.ohtaman.dev/showcase/) · [Browser Playground](https://washi.ohtaman.dev/demo/) · [Optimization N Exercises](https://washi.ohtaman.dev/exercises/)**: Try live optimization apps, practice interactive modeling workouts, and edit models in the browser
|
|
41
41
|
- **[Examples](https://washi.ohtaman.dev/examples/)**: Problem recipes and runnable Node.js / browser scripts ([`examples/`](examples/README.md))
|
|
42
|
-
- **[
|
|
42
|
+
- **[Agent Skill (`SKILL.md`)](skills/washi/SKILL.md) · [`llms.txt`](https://washi.ohtaman.dev/llms.txt) / [`llms-full.txt`](https://washi.ohtaman.dev/llms-full.txt)**: Workflow skill and machine-readable docs for AI coding agents
|
|
43
43
|
|
|
44
44
|
---
|
|
45
45
|
|
|
@@ -47,9 +47,10 @@
|
|
|
47
47
|
|
|
48
48
|
```bash
|
|
49
49
|
npm install @ohtaman/washi
|
|
50
|
+
# HiGHS (LP/MIP/QP) and Pumpkin (CP/LCG, @ohtaman/washi/solvers/pumpkin) are bundled with zero extra dependencies
|
|
50
51
|
|
|
51
|
-
# Optional solver plugins
|
|
52
|
-
npm install z3-solver # For SMT logic & unsat core diagnosis
|
|
52
|
+
# Optional peer-dependency solver plugins
|
|
53
|
+
npm install z3-solver # For SMT logic & exact real/integer unsat core diagnosis
|
|
53
54
|
npm install glpk.js # For GLPK solver (GPL-3.0)
|
|
54
55
|
|
|
55
56
|
# Optional skill for AI coding agents (Claude Code, Cursor, Codex, etc.)
|
|
@@ -77,12 +78,13 @@ console.log(`Produce: x=${x.value}, y=${y.value} (Profit: $${m.objectiveValue})`
|
|
|
77
78
|
|
|
78
79
|
| Solver | License | Problem Classes | Primary Use Case | Setup |
|
|
79
80
|
| :--- | :--- | :--- | :--- | :--- |
|
|
80
|
-
| **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | MIT | LP, MIP, Convex QP | Numerical optimization & elastic conflict repair | Built-in default |
|
|
81
|
-
| **[
|
|
82
|
-
| **[
|
|
81
|
+
| **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | MIT | LP, MIP, Convex QP | Numerical optimization & elastic conflict repair | Built-in default (zero extra deps) |
|
|
82
|
+
| **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** | MIT | CP, LCG, Logic, Bounded Integer | Combinatorial scheduling & zero-COOP/COEP `unsatCore` | `import "@ohtaman/washi/solvers/pumpkin"` (bundled WASM, zero deps) |
|
|
83
|
+
| **[Z3](https://github.com/Z3Prover/z3)** | MIT | SMT, SAT, Logic, MIP | Logical rules, satisfiability & exact `unsatCore` | `npm install z3-solver` + `import "@ohtaman/washi/solvers/z3"` |
|
|
84
|
+
| **[GLPK](https://www.gnu.org/software/glpk/)** | GPL-3.0 | LP, MIP | Linear & mixed-integer optimization | `npm install glpk.js` + `import "@ohtaman/washi/solvers/glpk"` |
|
|
83
85
|
| **Mock** | MIT | — | Deterministic unit & integration testing | Built-in (`MockSolver`) |
|
|
84
86
|
|
|
85
|
-
Pass `{ solver: "
|
|
87
|
+
Pass `{ solver: "pumpkin" }`, `{ solver: "z3" }`, or `{ solver: "glpk" }` to `new Model(...)`, `m.solve(...)`, or `m.check(...)` after importing the plugin.
|
|
86
88
|
|
|
87
89
|
---
|
|
88
90
|
|
|
@@ -135,15 +137,46 @@ await m.solve();
|
|
|
135
137
|
console.log(`Tech: ${x.value?.toFixed(2)}, Bonds: ${y.value?.toFixed(2)}`);
|
|
136
138
|
```
|
|
137
139
|
|
|
138
|
-
### 3.
|
|
140
|
+
### 3. Constraint Programming & Disjunctive Scheduling (Pumpkin)
|
|
141
|
+
|
|
142
|
+
Use bundled **Pumpkin** (`@ohtaman/washi/solvers/pumpkin`) for bounded integer scheduling and CP global constraints (`disjoint`, `distinct`, `cumulative`, `allowed`) with zero external dependencies:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import { Model, expr, disjoint, distinct, minimize } from "@ohtaman/washi";
|
|
146
|
+
import "@ohtaman/washi/solvers/pumpkin";
|
|
147
|
+
|
|
148
|
+
const m = new Model("WorkshopCP", { solver: "pumpkin" });
|
|
149
|
+
const start = m.integer(["cut", "weld", "paint"] as const, { lb: 0, ub: 20, prefix: "start" });
|
|
150
|
+
const bench = m.integer(["cut", "weld", "paint"] as const, { lb: 1, ub: 3, prefix: "bench" });
|
|
151
|
+
|
|
152
|
+
m.constraint(
|
|
153
|
+
disjoint([
|
|
154
|
+
{ start: start.cut, duration: 4 },
|
|
155
|
+
{ start: start.weld, duration: 3 },
|
|
156
|
+
{ start: start.paint, duration: 2 },
|
|
157
|
+
]),
|
|
158
|
+
"single_line"
|
|
159
|
+
);
|
|
160
|
+
m.constraint(expr`${start.cut} + 4 <= ${start.weld}`, "cut_before_weld");
|
|
161
|
+
m.constraint(expr`${start.weld} + 3 <= ${start.paint}`, "weld_before_paint");
|
|
162
|
+
m.constraint(distinct(bench), "unique_benches");
|
|
163
|
+
|
|
164
|
+
m.objective(minimize(expr`${start.paint} + 2`));
|
|
165
|
+
await m.solve();
|
|
166
|
+
console.log(`Makespan: ${m.objectiveValue}h (paint starts at ${start.paint.value}h)`);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 4. Logic & Conflict Diagnosis (`m.check`)
|
|
139
170
|
|
|
140
171
|
Express logical implications and diagnose why a model is infeasible:
|
|
141
172
|
- **HiGHS (default)**: Isolates an **elastic repair set** (`res.conflicts`)—constraints whose relaxation restores feasibility.
|
|
142
|
-
- **
|
|
173
|
+
- **Pumpkin (bundled)**: Extracts a scale-invariant **unsatisfiable core** (`res.unsatCore` / `res.conflicts`) for bounded integer and boolean models with **zero `COOP`/`COEP` headers**.
|
|
174
|
+
- **Z3**: Extracts an exact SMT **unsatisfiable core** (`res.unsatCore` / `res.conflicts`) including continuous and rational arithmetic.
|
|
143
175
|
|
|
144
176
|
```ts
|
|
145
177
|
import { Model, implies, expr } from "@ohtaman/washi";
|
|
146
|
-
// import "@ohtaman/washi/solvers/
|
|
178
|
+
// import "@ohtaman/washi/solvers/pumpkin"; // Bundled zero-COOP/COEP unsatCore (bounded int/bool)
|
|
179
|
+
// import "@ohtaman/washi/solvers/z3"; // Optional: exact SMT unsatCore including Continuous vars
|
|
147
180
|
|
|
148
181
|
const m = new Model("StaffingRules");
|
|
149
182
|
const engineers = m.integer("engineers", { lb: 0, ub: 20 });
|
|
@@ -165,24 +198,29 @@ console.log(res.conflicts); // HiGHS: ["rush_required"]
|
|
|
165
198
|
|
|
166
199
|
## 🌐 Browser & Web Worker Usage
|
|
167
200
|
|
|
168
|
-
- **Bundlers (Vite / webpack 5)**: `import { Model } from "@ohtaman/washi"` works out of the box.
|
|
169
|
-
- **Standalone ESM / Script Tag / CDN**: Serve `dist/browser/` (including `highs.wasm` and worker chunks) or load from a CDN.
|
|
201
|
+
- **Bundlers (Vite / webpack 5)**: `import { Model } from "@ohtaman/washi"` works out of the box. Both **HiGHS** and **Pumpkin** run in dedicated Web Workers by default (pass `{ useWorker: false }` for main-thread execution) and require **no `COOP`/`COEP` headers**.
|
|
202
|
+
- **Standalone ESM / Script Tag / CDN**: Serve `dist/browser/` (including `highs.wasm`, `solvers/pumpkin.wasm`, and worker chunks) or load from a CDN.
|
|
170
203
|
|
|
171
204
|
```html
|
|
172
205
|
<!-- Browser ESM -->
|
|
173
206
|
<script type="module">
|
|
174
207
|
import { Model } from "./washi/washi.js";
|
|
175
|
-
//
|
|
208
|
+
// Bundled / optional solver plugins:
|
|
209
|
+
// import "./washi/solvers/pumpkin.js"; // Bundled CP/LCG (zero COOP/COEP)
|
|
210
|
+
// import "./washi/solvers/glpk.js"; // Optional GLPK plugin
|
|
211
|
+
// import "./washi/solvers/z3.js"; // Optional Z3 plugin (requires COOP/COEP)
|
|
176
212
|
const m = new Model();
|
|
177
213
|
await m.solve();
|
|
178
214
|
</script>
|
|
179
215
|
|
|
180
216
|
<!-- Classic Script / CodePen (exposes global Washi) -->
|
|
181
217
|
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/washi.min.js"></script>
|
|
218
|
+
<!-- Optional solver plugin scripts (auto-register on window.Washi): -->
|
|
219
|
+
<!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/pumpkin.min.js"></script> -->
|
|
182
220
|
```
|
|
183
221
|
|
|
184
222
|
> [!NOTE]
|
|
185
|
-
> **Z3 in the Browser**: Because Z3's WebAssembly build uses `SharedArrayBuffer`, browsers require Cross-Origin Isolation (`COOP: same-origin` and `COEP: require-corp`). See the [Cross-Origin Isolation Guide](docs/getting-started/cross-origin.md) and [`examples/distribution/`](examples/distribution/README.md).
|
|
223
|
+
> **Z3 in the Browser**: Because Z3's WebAssembly build uses `SharedArrayBuffer`, browsers require Cross-Origin Isolation (`COOP: same-origin` and `COEP: require-corp`). See the [Cross-Origin Isolation Guide](docs/getting-started/cross-origin.md) and [`examples/distribution/`](examples/distribution/README.md). **HiGHS**, **Pumpkin** (including `unsatCore` on bounded integers/booleans), and **GLPK** require no Cross-Origin Isolation headers.
|
|
186
224
|
|
|
187
225
|
---
|
|
188
226
|
|
|
@@ -197,6 +235,7 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md) for local development setup, running te
|
|
|
197
235
|
WaSHI stands on the shoulders of the open-source mathematical optimization and automated reasoning communities:
|
|
198
236
|
|
|
199
237
|
- **[HiGHS](https://highs.dev/)** ([`ERGO-Code/HiGHS`](https://github.com/ERGO-Code/HiGHS)) — High-performance open-source optimization software for LP, MIP, and Convex QP initiated at the University of Edinburgh by Julian Hall, Qi Huangfu, Ivet Galabova, Leona Gottwald, Michael Feldmeier, and contributors, which powers WaSHI's built-in default solver (*Huangfu & Hall, Mathematical Programming Computation, 2018*, [DOI: 10.1007/s12532-017-0130-5](https://doi.org/10.1007/s12532-017-0130-5)).
|
|
238
|
+
- **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** — Lazy Clause Generation (LCG) constraint programming solver developed in Rust by ConSol Lab (TU Delft), powering WaSHI's bundled CP/LCG and zero-`COOP`/`COEP` `unsatCore` engine.
|
|
200
239
|
- **[Z3 Theorem Prover](https://github.com/Z3Prover/z3)** ([`z3-solver`](https://www.npmjs.com/package/z3-solver)) — Developed at Microsoft Research, powering WaSHI's optional SMT satisfiability and exact `unsatCore` conflict diagnosis plugin.
|
|
201
240
|
- **[GLPK](https://www.gnu.org/software/glpk/) & [`glpk.js`](https://github.com/jvail/glpk.js)** — Powering WaSHI's optional GPL-3.0 LP/MIP solver plugin.
|
|
202
241
|
- **[PuLP](https://github.com/coin-or/pulp)** — Inspiring WaSHI's declarative algebraic modeling ergonomics.
|
|
@@ -206,4 +245,4 @@ WaSHI stands on the shoulders of the open-source mathematical optimization and a
|
|
|
206
245
|
## 📄 License
|
|
207
246
|
|
|
208
247
|
- **`@ohtaman/washi`**: [MIT License](./LICENSE)
|
|
209
|
-
- **Bundled / Optional Engines**: HiGHS (MIT), Z3 (MIT), GLPK (GPL-3.0). See [THIRD_PARTY_LICENSES.md](./THIRD_PARTY_LICENSES.md) for full details.
|
|
248
|
+
- **Bundled / Optional Engines**: HiGHS (MIT), Pumpkin (MIT), Z3 (MIT), GLPK (GPL-3.0). See [THIRD_PARTY_LICENSES.md](./THIRD_PARTY_LICENSES.md) for full details.
|
package/README.zh-CN.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
</picture>
|
|
7
7
|
<p><strong>TypeScript 数理优化建模器</strong></p>
|
|
8
8
|
<p>
|
|
9
|
-
<em>线性规划 (LP) • 混合整数规划 (MIP) • 凸二次规划 (QP) • SMT逻辑约束与冲突诊断</em>
|
|
9
|
+
<em>线性规划 (LP) • 混合整数规划 (MIP) • 凸二次规划 (QP) • 约束规划 (CP) • SMT逻辑约束与冲突诊断</em>
|
|
10
10
|
</p>
|
|
11
11
|
<p>
|
|
12
12
|
<a href="./README.md">English</a> •
|
|
@@ -24,22 +24,22 @@
|
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
27
|
-
**WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) 是面向 TypeScript / JavaScript 的数理优化与约束编程代数建模器,受到 Python **PuLP** 的启发。你可以在应用代码中定义变量、目标函数和约束,并在 Node.js
|
|
27
|
+
**WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) 是面向 TypeScript / JavaScript 的数理优化与约束编程代数建模器,受到 Python **PuLP** 的启发。你可以在应用代码中定义变量、目标函数和约束,并在 Node.js 或浏览器本地使用内置 **HiGHS**(默认)和 **Pumpkin**(`@ohtaman/washi/solvers/pumpkin`),或按需加载 **Z3**、**GLPK** 插件进行求解。
|
|
28
28
|
|
|
29
29
|
## ✨ 核心特性
|
|
30
30
|
|
|
31
31
|
- **直观的代数语法**:通过 `` expr`30 * ${x} + 50 * ${y} <= 40` `` 与求和、点积(`sum`, `dot`)清晰编写公式与约束。
|
|
32
32
|
- **跨 Node.js 与浏览器本地运行**:基于 WebAssembly,无需单独部署 Python 服务或本地编译 C/C++。
|
|
33
|
-
-
|
|
33
|
+
- **求解器无关**:内置零外部依赖的 **HiGHS**(LP/MIP/QP)与 **Pumpkin**(CP/LCG),并支持按需加载 **Z3**、**GLPK** 插件或自定义求解器适配器。
|
|
34
34
|
- **可满足性判定与冲突诊断**:支持逻辑与算术约束的可满足性判定,并在模型不可行时定位矛盾约束。
|
|
35
35
|
- **大规模分解算法**:内置列生成法与 Benders 分解支持。
|
|
36
36
|
|
|
37
37
|
## 📚 文档与链接
|
|
38
38
|
|
|
39
39
|
- **[在线文档](https://washi.ohtaman.dev/zh/)**:建模指南、求解器说明与运行环境配置
|
|
40
|
-
- **[案例展示](https://washi.ohtaman.dev/zh/showcase/)
|
|
40
|
+
- **[案例展示](https://washi.ohtaman.dev/zh/showcase/) · [浏览器演示](https://washi.ohtaman.dev/demo/) · [数理优化 N 题训练](https://washi.ohtaman.dev/exercises/?lang=zh)**:在线体验交互式应用、浏览器建模演练场与 N 题实战训练营
|
|
41
41
|
- **[示例目录](https://washi.ohtaman.dev/zh/examples/)**:各类问题的建模示例与可运行源码([`examples/`](examples/README.md))
|
|
42
|
-
- **[
|
|
42
|
+
- **[Agent Skill (`SKILL.md`)](skills/washi/SKILL.md) · [`llms.txt`](https://washi.ohtaman.dev/llms.txt) / [`llms-full.txt`](https://washi.ohtaman.dev/llms-full.txt)**:面向 AI 编程助手的技能定义与机器可读文档
|
|
43
43
|
|
|
44
44
|
---
|
|
45
45
|
|
|
@@ -47,9 +47,10 @@
|
|
|
47
47
|
|
|
48
48
|
```bash
|
|
49
49
|
npm install @ohtaman/washi
|
|
50
|
+
# HiGHS (LP/MIP/QP) 与 Pumpkin (CP/LCG, @ohtaman/washi/solvers/pumpkin) 已内置打包,无需额外依赖
|
|
50
51
|
|
|
51
|
-
#
|
|
52
|
-
npm install z3-solver # 用于 SMT
|
|
52
|
+
# 可选 peer-dependency 求解器插件
|
|
53
|
+
npm install z3-solver # 用于 SMT 逻辑与包含连续变量的精确冲突诊断
|
|
53
54
|
npm install glpk.js # 用于 GLPK 求解器 (GPL-3.0)
|
|
54
55
|
|
|
55
56
|
# 可选:为 AI 编程助手(Claude Code, Cursor, Codex 等)安装建模技能
|
|
@@ -77,12 +78,13 @@ console.log(`生产计划: x=${x.value}, y=${y.value} (最大利润: $${m.object
|
|
|
77
78
|
|
|
78
79
|
| 求解器 | 许可证 | 支持问题类型 | 主要用途 | 引入方式 |
|
|
79
80
|
| :--- | :--- | :--- | :--- | :--- |
|
|
80
|
-
| **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | MIT | LP, MIP, 凸QP | 数值优化与弹性冲突修复诊断 |
|
|
81
|
-
| **[
|
|
82
|
-
| **[
|
|
81
|
+
| **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | MIT | LP, MIP, 凸QP | 数值优化与弹性冲突修复诊断 | 默认内置(零额外依赖) |
|
|
82
|
+
| **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** | MIT | CP, LCG, 逻辑, 有界整数 | 组合调度与免 COOP/COEP 的 `unsatCore` | `import "@ohtaman/washi/solvers/pumpkin"`(内置 WASM,零额外依赖) |
|
|
83
|
+
| **[Z3](https://github.com/Z3Prover/z3)** | MIT | SMT, SAT, 逻辑, MIP | 逻辑规则、可满足性判定与精确 `unsatCore` | `npm install z3-solver` + `import "@ohtaman/washi/solvers/z3"` |
|
|
84
|
+
| **[GLPK](https://www.gnu.org/software/glpk/)** | GPL-3.0 | LP, MIP | 线性与混合整数规划 | `npm install glpk.js` + `import "@ohtaman/washi/solvers/glpk"` |
|
|
83
85
|
| **Mock** | MIT | — | 单元与集成测试模拟响应 | 内置 (`MockSolver`) |
|
|
84
86
|
|
|
85
|
-
导入对应插件后,可在 `new Model(...)`、`m.solve(...)` 或 `m.check(...)` 中传入 `{ solver: "z3" }` 或 `{ solver: "glpk" }`。
|
|
87
|
+
导入对应插件后,可在 `new Model(...)`、`m.solve(...)` 或 `m.check(...)` 中传入 `{ solver: "pumpkin" }`、`{ solver: "z3" }` 或 `{ solver: "glpk" }`。
|
|
86
88
|
|
|
87
89
|
---
|
|
88
90
|
|
|
@@ -135,15 +137,46 @@ await m.solve();
|
|
|
135
137
|
console.log(`Tech: ${x.value?.toFixed(2)}, Bonds: ${y.value?.toFixed(2)}`);
|
|
136
138
|
```
|
|
137
139
|
|
|
138
|
-
### 3.
|
|
140
|
+
### 3. 约束规划与析取调度 (Pumpkin)
|
|
141
|
+
|
|
142
|
+
使用内置的 **Pumpkin**(`@ohtaman/washi/solvers/pumpkin`)求解有界整数调度与 CP 全局约束(`disjoint`、`distinct`、`cumulative`、`allowed`),无需任何额外依赖:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
import { Model, expr, disjoint, distinct, minimize } from "@ohtaman/washi";
|
|
146
|
+
import "@ohtaman/washi/solvers/pumpkin";
|
|
147
|
+
|
|
148
|
+
const m = new Model("WorkshopCP", { solver: "pumpkin" });
|
|
149
|
+
const start = m.integer(["cut", "weld", "paint"] as const, { lb: 0, ub: 20, prefix: "start" });
|
|
150
|
+
const bench = m.integer(["cut", "weld", "paint"] as const, { lb: 1, ub: 3, prefix: "bench" });
|
|
151
|
+
|
|
152
|
+
m.constraint(
|
|
153
|
+
disjoint([
|
|
154
|
+
{ start: start.cut, duration: 4 },
|
|
155
|
+
{ start: start.weld, duration: 3 },
|
|
156
|
+
{ start: start.paint, duration: 2 },
|
|
157
|
+
]),
|
|
158
|
+
"single_line"
|
|
159
|
+
);
|
|
160
|
+
m.constraint(expr`${start.cut} + 4 <= ${start.weld}`, "cut_before_weld");
|
|
161
|
+
m.constraint(expr`${start.weld} + 3 <= ${start.paint}`, "weld_before_paint");
|
|
162
|
+
m.constraint(distinct(bench), "unique_benches");
|
|
163
|
+
|
|
164
|
+
m.objective(minimize(expr`${start.paint} + 2`));
|
|
165
|
+
await m.solve();
|
|
166
|
+
console.log(`Makespan: ${m.objectiveValue}h (paint starts at ${start.paint.value}h)`);
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### 4. 逻辑规则与冲突诊断 (`m.check`)
|
|
139
170
|
|
|
140
171
|
表达逻辑蕴含规则并排查不可行原因:
|
|
141
172
|
- **HiGHS(默认)**:提取**弹性修复集合**(`res.conflicts`),即松弛后可恢复可行性的约束。
|
|
142
|
-
- **
|
|
173
|
+
- **Pumpkin(内置)**:为有界整数与布尔模型提取尺度无关的**不可满足核心**(`res.unsatCore` / `res.conflicts`),**无需 `COOP`/`COEP` 响应头**。
|
|
174
|
+
- **Z3**:提取包含连续变量与有理数算术的精确 **SMT 不可满足核心**(`res.unsatCore` / `res.conflicts`)。
|
|
143
175
|
|
|
144
176
|
```ts
|
|
145
177
|
import { Model, implies, expr } from "@ohtaman/washi";
|
|
146
|
-
// import "@ohtaman/washi/solvers/
|
|
178
|
+
// import "@ohtaman/washi/solvers/pumpkin"; // 内置:免 COOP/COEP 的 unsatCore(有界整数/布尔)
|
|
179
|
+
// import "@ohtaman/washi/solvers/z3"; // 可选:支持含连续变量的精确 SMT unsatCore
|
|
147
180
|
|
|
148
181
|
const m = new Model("StaffingRules");
|
|
149
182
|
const engineers = m.integer("engineers", { lb: 0, ub: 20 });
|
|
@@ -165,24 +198,29 @@ console.log(res.conflicts); // HiGHS: ["rush_required"]
|
|
|
165
198
|
|
|
166
199
|
## 🌐 浏览器与 Web Worker 使用指南
|
|
167
200
|
|
|
168
|
-
- **打包工具 (Vite / webpack 5)**:直接 `import { Model } from "@ohtaman/washi"`
|
|
169
|
-
- **原生 ESM / Script 标签 / CDN**:部署 `dist/browser/` 目录(含 `highs.wasm` 与 Worker 资源)或从 CDN 加载。
|
|
201
|
+
- **打包工具 (Vite / webpack 5)**:直接 `import { Model } from "@ohtaman/washi"` 即可。**HiGHS** 与 **Pumpkin** 默认均在专用 Web Worker 中求解(传入 `{ useWorker: false }` 可在主线程执行),且**无需 `COOP`/`COEP` 响应头**。
|
|
202
|
+
- **原生 ESM / Script 标签 / CDN**:部署 `dist/browser/` 目录(含 `highs.wasm`、`solvers/pumpkin.wasm` 与 Worker 资源)或从 CDN 加载。
|
|
170
203
|
|
|
171
204
|
```html
|
|
172
205
|
<!-- 浏览器原生 ESM -->
|
|
173
206
|
<script type="module">
|
|
174
207
|
import { Model } from "./washi/washi.js";
|
|
175
|
-
//
|
|
208
|
+
// 内置或可选求解器插件:
|
|
209
|
+
// import "./washi/solvers/pumpkin.js"; // 内置 CP/LCG(免 COOP/COEP)
|
|
210
|
+
// import "./washi/solvers/glpk.js"; // 可选 GLPK 插件
|
|
211
|
+
// import "./washi/solvers/z3.js"; // 可选 Z3 插件(需 COOP/COEP)
|
|
176
212
|
const m = new Model();
|
|
177
213
|
await m.solve();
|
|
178
214
|
</script>
|
|
179
215
|
|
|
180
216
|
<!-- Script 标签 / CodePen (挂载全局变量 Washi) -->
|
|
181
217
|
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/washi.min.js"></script>
|
|
218
|
+
<!-- 可选求解器插件脚本(自动注册到 window.Washi): -->
|
|
219
|
+
<!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/pumpkin.min.js"></script> -->
|
|
182
220
|
```
|
|
183
221
|
|
|
184
222
|
> [!NOTE]
|
|
185
|
-
> **浏览器中使用 Z3**:Z3 的 WebAssembly 引擎依赖 `SharedArrayBuffer`,需要配置跨源隔离响应头(`COOP: same-origin` 与 `COEP: require-corp`)。详见[跨源隔离指南](docs/zh/getting-started/cross-origin.md)与 [`examples/distribution/`](examples/distribution/README.md)
|
|
223
|
+
> **浏览器中使用 Z3**:Z3 的 WebAssembly 引擎依赖 `SharedArrayBuffer`,需要配置跨源隔离响应头(`COOP: same-origin` 与 `COEP: require-corp`)。详见[跨源隔离指南](docs/zh/getting-started/cross-origin.md)与 [`examples/distribution/`](examples/distribution/README.md)。**HiGHS**、**Pumpkin**(包括有界整数/布尔模型的 `unsatCore`)和 **GLPK** 均无需跨源隔离响应头即可运行。
|
|
186
224
|
|
|
187
225
|
---
|
|
188
226
|
|
|
@@ -197,6 +235,7 @@ console.log(res.conflicts); // HiGHS: ["rush_required"]
|
|
|
197
235
|
WaSHI 的诞生离不开数理优化与自动推理开源社区的卓越工作:
|
|
198
236
|
|
|
199
237
|
- **[HiGHS](https://highs.dev/)**([`ERGO-Code/HiGHS`](https://github.com/ERGO-Code/HiGHS))— 发源于爱丁堡大学、由 Julian Hall、Qi Huangfu、Ivet Galabova、Leona Gottwald、Michael Feldmeier 及社区贡献者共同打造的高性能开源 LP / MIP / 凸 QP 求解器,驱动了 WaSHI 的内置默认引擎(*Huangfu & Hall, Mathematical Programming Computation, 2018*, [DOI: 10.1007/s12532-017-0130-5](https://doi.org/10.1007/s12532-017-0130-5))。
|
|
238
|
+
- **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** — 由代尔夫特理工大学(TU Delft)ConSol Lab 使用 Rust 开发的惰性子句生成(LCG)约束规划求解器,驱动了 WaSHI 内置的 CP/LCG 与免 `COOP`/`COEP` `unsatCore` 引擎。
|
|
200
239
|
- **[Z3 Theorem Prover](https://github.com/Z3Prover/z3)**([`z3-solver`](https://www.npmjs.com/package/z3-solver))— 由 Microsoft Research 研发,驱动了 WaSHI 可选的 SMT 可满足性判定与精确 `unsatCore` 冲突诊断插件。
|
|
201
240
|
- **[GLPK](https://www.gnu.org/software/glpk/) & [`glpk.js`](https://github.com/jvail/glpk.js)** — 驱动了 WaSHI 可选的 GPL-3.0 LP / MIP 求解器插件。
|
|
202
241
|
- **[PuLP](https://github.com/coin-or/pulp)** — 启发了 WaSHI 声明式代数建模 API 的设计。
|
|
@@ -206,4 +245,4 @@ WaSHI 的诞生离不开数理优化与自动推理开源社区的卓越工作
|
|
|
206
245
|
## 📄 许可证
|
|
207
246
|
|
|
208
247
|
- **`@ohtaman/washi`**: [MIT 许可证](./LICENSE)
|
|
209
|
-
- **内置与可选引擎**: HiGHS (MIT)、Z3 (MIT)、GLPK (GPL-3.0)。完整许可说明请参阅 [THIRD_PARTY_LICENSES.md](./THIRD_PARTY_LICENSES.md)。
|
|
248
|
+
- **内置与可选引擎**: HiGHS (MIT)、Pumpkin (MIT)、Z3 (MIT)、GLPK (GPL-3.0)。完整许可说明请参阅 [THIRD_PARTY_LICENSES.md](./THIRD_PARTY_LICENSES.md)。
|
package/THIRD_PARTY_LICENSES.md
CHANGED
|
@@ -69,7 +69,7 @@ THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|
|
69
69
|
- **Package**: [`glpk.js`](https://www.npmjs.com/package/glpk.js)
|
|
70
70
|
- **License**: **GNU General Public License v3.0 (GPL-3.0)**
|
|
71
71
|
- **Upstream Repository**: [jvail/glpk.js](https://github.com/jvail/glpk.js)
|
|
72
|
-
- **Notice**: WaSHI isolates GLPK support into an optional subpath export (`@ohtaman/washi/solvers/glpk`). It is loaded dynamically only when explicitly opted in by the user. If your application requires a strictly permissive license (e.g., proprietary enterprise deployments), stick to the default **HiGHS** (MIT) or **Z3** (MIT) engines.
|
|
72
|
+
- **Notice**: WaSHI isolates GLPK support into an optional subpath export (`@ohtaman/washi/solvers/glpk`). It is loaded dynamically only when explicitly opted in by the user. If your application requires a strictly permissive license (e.g., proprietary enterprise deployments), stick to the default **HiGHS** (MIT), bundled **Pumpkin** (MIT), or **Z3** (MIT) engines.
|
|
73
73
|
|
|
74
74
|
```text
|
|
75
75
|
GNU GENERAL PUBLIC LICENSE
|
|
@@ -82,3 +82,36 @@ of this license document, but changing it is not allowed.
|
|
|
82
82
|
For the full license text of GPL-3.0, please refer to:
|
|
83
83
|
https://www.gnu.org/licenses/gpl-3.0.txt
|
|
84
84
|
```
|
|
85
|
+
|
|
86
|
+
---
|
|
87
|
+
|
|
88
|
+
## 4. Pumpkin Constraint Programming Solver (Bundled Solver Plugin)
|
|
89
|
+
|
|
90
|
+
- **Role**: Bundled Lazy Clause Generation (LCG) Constraint Programming Solver (WebAssembly)
|
|
91
|
+
- **License**: **MIT License**
|
|
92
|
+
- **Upstream Repository**: [ConSol-Lab/Pumpkin](https://github.com/ConSol-Lab/Pumpkin)
|
|
93
|
+
- **Bundled Asset**: Directly compiled from upstream crates (`pumpkin-core`, `pumpkin-constraints`, `pumpkin-conflict-resolvers` `v0.5.0`) to WebAssembly and shipped with WaSHI (`@ohtaman/washi/solvers/pumpkin`); transitive Rust WASM dependencies are strictly permissive (`MIT`, `Apache-2.0`, `Unicode-3.0`).
|
|
94
|
+
|
|
95
|
+
```text
|
|
96
|
+
MIT License
|
|
97
|
+
|
|
98
|
+
Copyright (c) 2024 ConSol Lab (TU Delft) / Pumpkin Developers and Contributors
|
|
99
|
+
|
|
100
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
101
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
102
|
+
in the Software without restriction, including without limitation the rights
|
|
103
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
104
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
105
|
+
furnished to do so, subject to the following conditions:
|
|
106
|
+
|
|
107
|
+
The above copyright notice and this permission notice shall be included in all
|
|
108
|
+
copies or substantial portions of the Software.
|
|
109
|
+
|
|
110
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
111
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
112
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
113
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
114
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
115
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
116
|
+
SOFTWARE.
|
|
117
|
+
```
|