@ohtaman/washi 0.8.0 → 0.8.1
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 +22 -24
- package/README.md +20 -22
- package/README.zh-CN.md +25 -27
- package/dist/browser/{__vite-browser-external-rTVKos2U.js → solvers/highs-__vite-browser-external-Dn-83hnF.js} +1 -1
- package/dist/browser/{browser-runtime-AG5QFtKf.js → solvers/highs-browser-runtime-0Bgq5ksG.js} +1 -1
- package/dist/browser/{loader-i3FnqMes.js → solvers/highs-loader-BLY3wzDH.js} +25 -18
- package/dist/browser/{highs-worker.js → solvers/highs-worker.js} +1 -1
- package/dist/browser/solvers/highs.js +1414 -0
- package/dist/browser/washi.js +1090 -1473
- package/dist/browser/washi.min.js +4 -4
- package/dist/lib/solvers/glpk.js +34 -32
- package/dist/lib/{highs-node-runtime.js → solvers/highs-node-runtime.js} +1 -1
- package/dist/lib/solvers/highs.js +410 -0
- package/dist/lib/solvers/lp-writer-CLScMFbS.js +115 -0
- package/dist/lib/solvers/pumpkin-node-runtime.js +1 -1
- package/dist/lib/solvers/pumpkin-worker.js +1 -1
- package/dist/lib/solvers/pumpkin.js +247 -1146
- package/dist/lib/solvers/registry-CrYRRk9q.js +907 -0
- package/dist/lib/solvers/types-BGqPkxwu.js +12 -0
- package/dist/lib/solvers/z3.js +125 -123
- package/dist/lib/washi.js +2426 -1340
- package/dist/types/index.d.ts +1 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modeler/index.d.ts +0 -1
- package/dist/types/modeler/index.d.ts.map +1 -1
- package/dist/types/modeler/model.d.ts +6 -7
- package/dist/types/modeler/model.d.ts.map +1 -1
- package/dist/types/modeler/solvers/index.d.ts +2 -1
- package/dist/types/modeler/solvers/index.d.ts.map +1 -1
- package/dist/types/modeler/solvers/registry.d.ts.map +1 -1
- package/docs/examples/diet-sensitivity.md +33 -14
- package/docs/examples/ecommerce-coupons.md +17 -9
- package/docs/examples/index.md +34 -30
- package/docs/examples/knapsack.md +11 -5
- package/docs/examples/portfolio-qp.md +21 -8
- package/docs/examples/production.md +10 -5
- package/docs/examples/project-scheduling.md +25 -12
- package/docs/examples/shift-scheduling.md +27 -19
- package/docs/examples/smt-security.md +27 -12
- package/docs/examples/transportation.md +23 -13
- package/docs/examples/traveling-salesperson.md +34 -22
- package/docs/examples/unsat-core.md +27 -15
- package/docs/examples/vehicle-routing.md +74 -28
- package/docs/getting-started/ai-agents.md +129 -90
- package/docs/getting-started/coding-agents.md +60 -41
- package/docs/getting-started/cross-origin.md +27 -14
- package/docs/getting-started/index.md +23 -16
- package/docs/getting-started/runtimes.md +70 -40
- package/docs/guide/constraint-programming.md +74 -44
- package/docs/guide/constraints.md +71 -39
- package/docs/guide/decomposition.md +72 -42
- package/docs/guide/expressions.md +79 -48
- package/docs/guide/formulation-tips.md +46 -27
- package/docs/guide/objectives.md +55 -31
- package/docs/guide/unsat-core.md +56 -53
- package/docs/guide/variables.md +61 -28
- package/docs/solvers/custom-solver.md +155 -119
- package/docs/solvers/glpk.md +58 -17
- package/docs/solvers/highs.md +115 -43
- package/docs/solvers/index.md +33 -26
- package/docs/solvers/pumpkin.md +71 -63
- package/docs/solvers/z3.md +63 -25
- package/llms-full.txt +1623 -953
- package/llms.txt +125 -93
- package/package.json +29 -20
- package/skills/washi/SKILL.md +43 -22
- package/dist/browser/solvers/pumpkin.min.js +0 -1
- package/dist/lib/registry-dx7x4e5c.js +0 -1694
- /package/dist/browser/{highs.wasm → solvers/highs.wasm} +0 -0
- /package/dist/browser/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
- /package/dist/lib/{__vite-browser-external-oLchLuMx.js → solvers/__vite-browser-external-oLchLuMx.js} +0 -0
- /package/dist/lib/{highs-assets.js → solvers/highs-assets.js} +0 -0
- /package/dist/lib/{highs-browser-runtime.js → solvers/highs-browser-runtime.js} +0 -0
- /package/dist/lib/{highs-runtime.js → solvers/highs-runtime.js} +0 -0
- /package/dist/lib/{highs-worker-factory.js → solvers/highs-worker-factory.js} +0 -0
- /package/dist/lib/{highs-worker.js → solvers/highs-worker.js} +0 -0
- /package/dist/lib/{highs.wasm → solvers/highs.wasm} +0 -0
- /package/dist/lib/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
- /package/dist/lib/{loader-CDpPXN_F.js → solvers/loader-CDpPXN_F.js} +0 -0
- /package/dist/lib/solvers/{pumpkin-loader-Ow74Fa1B.js → loader-Ow74Fa1B.js} +0 -0
- /package/dist/lib/{rolldown-runtime-DtPi1Y-2.js → solvers/rolldown-runtime-DtPi1Y-2.js} +0 -0
package/README.ja.md
CHANGED
|
@@ -17,27 +17,27 @@
|
|
|
17
17
|
<a href="https://www.npmjs.com/package/@ohtaman/washi"><img src="https://img.shields.io/npm/v/@ohtaman/washi?color=crimson&label=npm" alt="npm version" /></a>
|
|
18
18
|
<a href="https://github.com/ohtaman/washi/actions/workflows/distribution.yml"><img src="https://github.com/ohtaman/washi/actions/workflows/distribution.yml/badge.svg" alt="CI Status" /></a>
|
|
19
19
|
<a href="https://washi.ohtaman.dev/ja/"><img src="https://img.shields.io/badge/docs-online-blue" alt="docs" /></a>
|
|
20
|
-
<a href="https://washi.ohtaman.dev/demo
|
|
20
|
+
<a href="https://washi.ohtaman.dev/demo/?lang=ja"><img src="https://img.shields.io/badge/demo-playground-brightgreen" alt="live demo" /></a>
|
|
21
21
|
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="license" /></a>
|
|
22
22
|
</p>
|
|
23
23
|
</div>
|
|
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**(`{ solver: "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
|
-
- **ソルバー非依存**: 追加依存なしの同梱 **HiGHS**(LP/MIP/QP)・**Pumpkin**(CP
|
|
33
|
+
- **ソルバー非依存**: 追加依存なしの同梱 **HiGHS**(LP/MIP/QP)・**Pumpkin**(CP)に加え、オプションの **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/) · [ブラウザデモ](https://washi.ohtaman.dev/demo
|
|
40
|
+
- **[ショーケース](https://washi.ohtaman.dev/ja/showcase/) · [ブラウザデモ](https://washi.ohtaman.dev/demo/?lang=ja) · [数理最適化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
|
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
|
|
48
48
|
```bash
|
|
49
49
|
npm install @ohtaman/washi
|
|
50
|
-
# HiGHS (LP/MIP/QP) と Pumpkin (CP
|
|
50
|
+
# HiGHS (LP/MIP/QP, デフォルト) と Pumpkin (CP, { solver: "pumpkin" }) は追加依存・追加インポートなしでそのまま使えます
|
|
51
51
|
|
|
52
52
|
# オプションの peer-dependency ソルバープラグイン
|
|
53
53
|
npm install z3-solver # SMT 論理制約・実数を含む厳密 Unsat Core 診断を使う場合
|
|
@@ -78,13 +78,13 @@ console.log(`生産量: x=${x.value}, y=${y.value} (最大利益: $${m.objective
|
|
|
78
78
|
|
|
79
79
|
| ソルバー | ライセンス | 対応クラス | 主な用途 | 導入方法 |
|
|
80
80
|
| :--- | :--- | :--- | :--- | :--- |
|
|
81
|
-
| **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | MIT | LP, MIP, 凸QP |
|
|
82
|
-
| **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** | MIT | CP
|
|
81
|
+
| **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | MIT | LP, MIP, 凸QP | 数値最適化・矛盾診断(制約緩和) | 同梱デフォルト(追加依存・インポート不要) |
|
|
82
|
+
| **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** | MIT | CP(Lazy Clause Generation), 論理, 有界整数 | スケジューリング・有界整数の `unsatCore` | 同梱(`{ solver: "pumpkin" }`、追加依存・インポート不要) |
|
|
83
83
|
| **[Z3](https://github.com/Z3Prover/z3)** | MIT | SMT, SAT, 論理, MIP | 論理ルール・充足判定・厳密な `unsatCore` | `npm install z3-solver` + `import "@ohtaman/washi/solvers/z3"` |
|
|
84
84
|
| **[GLPK](https://www.gnu.org/software/glpk/)** | GPL-3.0 | LP, MIP | 線形・混合整数最適化 | `npm install glpk.js` + `import "@ohtaman/washi/solvers/glpk"` |
|
|
85
85
|
| **Mock** | MIT | — | テスト用の決定論的な模擬応答 | 標準搭載 (`MockSolver`) |
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
同梱の HiGHS(既定)と Pumpkin(`{ solver: "pumpkin" }`)は追加インポートなしでそのまま切り替えられます。オプションの `{ solver: "z3" }`・`{ solver: "glpk" }` は対応プラグインを import した上で指定します。なお、ソルバー固有のクラスや WASM 設定関数(`HighsSolver`, `setHighsWasmUrl`, `PumpkinSolver`, `setPumpkinWasmUrl` 等)は `@ohtaman/washi/solvers/{highs,pumpkin,z3,glpk}` に配置されています。
|
|
88
88
|
|
|
89
89
|
---
|
|
90
90
|
|
|
@@ -139,11 +139,10 @@ console.log(`Tech: ${x.value?.toFixed(2)}, Bonds: ${y.value?.toFixed(2)}`);
|
|
|
139
139
|
|
|
140
140
|
### 3. 制約プログラミング & スケジューリング (Pumpkin)
|
|
141
141
|
|
|
142
|
-
同梱の **Pumpkin
|
|
142
|
+
同梱の **Pumpkin**(`{ solver: "pumpkin" }`)を使うと、追加依存や追加インポートなしで有界整数スケジューリングや CP グローバル制約(`disjoint`, `distinct`, `cumulative`, `allowed`)を求解できます:
|
|
143
143
|
|
|
144
144
|
```ts
|
|
145
145
|
import { Model, expr, disjoint, distinct, minimize } from "@ohtaman/washi";
|
|
146
|
-
import "@ohtaman/washi/solvers/pumpkin";
|
|
147
146
|
|
|
148
147
|
const m = new Model("WorkshopCP", { solver: "pumpkin" });
|
|
149
148
|
const start = m.integer(["cut", "weld", "paint"] as const, { lb: 0, ub: 20, prefix: "start" });
|
|
@@ -169,14 +168,14 @@ console.log(`Makespan: ${m.objectiveValue}h (paint starts at ${start.paint.value
|
|
|
169
168
|
### 4. 論理ルール & 矛盾診断 (`m.check`)
|
|
170
169
|
|
|
171
170
|
論理条件(`m.bool`, `implies`)を含むモデルの充足可能性を判定し、矛盾時の原因制約を特定します:
|
|
172
|
-
- **HiGHS(標準)**:
|
|
173
|
-
- **Pumpkin(同梱)**:
|
|
171
|
+
- **HiGHS(標準)**: 緩和すれば実行可能になる制約集合(`res.conflicts`)を特定します。
|
|
172
|
+
- **Pumpkin(同梱)**: 有界整数・真偽値モデルに対して、厳密な**充足不能コア**(`res.unsatCore` / `res.conflicts`)を抽出します。
|
|
174
173
|
- **Z3**: 連続変数・実数演算を含む厳密な SMT **充足不能コア**(`res.unsatCore` / `res.conflicts`)を抽出します。
|
|
175
174
|
|
|
176
175
|
```ts
|
|
177
176
|
import { Model, implies, expr } from "@ohtaman/washi";
|
|
178
|
-
//
|
|
179
|
-
// import "@ohtaman/washi/solvers/z3"; // Continuous 変数を含む厳密 SMT unsatCore
|
|
177
|
+
// { solver: "pumpkin" } なら追加インポートなしで有界整数・真偽値の厳密 unsatCore を抽出
|
|
178
|
+
// import "@ohtaman/washi/solvers/z3"; // Continuous 変数を含む厳密 SMT unsatCore(オプション)
|
|
180
179
|
|
|
181
180
|
const m = new Model("StaffingRules");
|
|
182
181
|
const engineers = m.integer("engineers", { lb: 0, ub: 20 });
|
|
@@ -198,29 +197,28 @@ console.log(res.conflicts); // HiGHS: ["rush_required"]
|
|
|
198
197
|
|
|
199
198
|
## 🌐 ブラウザ & Web Worker での利用方法
|
|
200
199
|
|
|
201
|
-
- **バンドラー (Vite / webpack 5)**: `import { Model } from "@ohtaman/washi"`
|
|
202
|
-
- **単体 ESM / script タグ / CDN**: `dist/browser/` 一式(`highs.wasm`、`solvers/pumpkin.wasm` や Worker を含む)を配信するか、CDN の URL
|
|
200
|
+
- **バンドラー (Vite / webpack 5)**: `import { Model } from "@ohtaman/washi"` でそのまま動作します。通常オリジン(`http://` / `https://`)のブラウザでは、**HiGHS** と **Pumpkin** は標準で専用 Web Worker 上で実行されます(`file://` などの不透明オリジンでは自動的に `{ useWorker: false }` になり、明示的に `{ useWorker: false }` を渡してメインスレッドで実行することも可能です)。
|
|
201
|
+
- **単体 ESM / script タグ / CDN**: `dist/browser/` 一式(`solvers/highs.wasm`、`solvers/pumpkin.wasm` や Worker を含む)を配信するか、CDN の URL を指定して読み込みます。`washi.js` と `washi.min.js` のどちらも HiGHS と Pumpkin の両方を内蔵しています。
|
|
203
202
|
|
|
204
203
|
```html
|
|
205
|
-
<!-- ブラウザ ESM -->
|
|
204
|
+
<!-- ブラウザ ESM(HiGHS・Pumpkin の両方を利用可能) -->
|
|
206
205
|
<script type="module">
|
|
207
206
|
import { Model } from "./washi/washi.js";
|
|
208
|
-
//
|
|
209
|
-
// import "./washi/solvers/pumpkin.js"; // 同梱 CP/LCG (COOP/COEP 不要)
|
|
207
|
+
// オプションプラグイン:
|
|
210
208
|
// import "./washi/solvers/glpk.js"; // オプション GLPK プラグイン
|
|
211
|
-
// import "./washi/solvers/z3.js"; // オプション Z3
|
|
209
|
+
// import "./washi/solvers/z3.js"; // オプション Z3 プラグイン(下の注記を参照)
|
|
212
210
|
const m = new Model();
|
|
213
211
|
await m.solve();
|
|
214
212
|
</script>
|
|
215
213
|
|
|
216
|
-
<!-- script タグ / CodePen (グローバル Washi
|
|
214
|
+
<!-- script タグ / CodePen (グローバル Washi を公開、HiGHS・Pumpkin 同梱) -->
|
|
217
215
|
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/washi.min.js"></script>
|
|
218
216
|
<!-- オプションプラグインスクリプト (window.Washi に自動登録): -->
|
|
219
|
-
<!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/
|
|
217
|
+
<!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/glpk.min.js"></script> -->
|
|
220
218
|
```
|
|
221
219
|
|
|
222
220
|
> [!NOTE]
|
|
223
|
-
> **ブラウザでの Z3 利用**: Z3 の WebAssembly は `SharedArrayBuffer`
|
|
221
|
+
> **ブラウザでの Z3 利用**: Z3 の WebAssembly は `SharedArrayBuffer` を使用するため、**Secure Context**(`HTTPS` または `localhost`)と Cross-Origin Isolation ヘッダー(`Cross-Origin-Opener-Policy: same-origin` および `Cross-Origin-Embedder-Policy: require-corp`)が必要です。詳細は [Cross-Origin Isolation 設定](docs/ja/getting-started/cross-origin.md) および [`examples/distribution/`](examples/distribution/README.md) を参照してください。**HiGHS**・**Pumpkin**・**GLPK** はこれらのヘッダーなしで動作します。
|
|
224
222
|
|
|
225
223
|
---
|
|
226
224
|
|
|
@@ -235,7 +233,7 @@ console.log(res.conflicts); // HiGHS: ["rush_required"]
|
|
|
235
233
|
WaSHI は、数理最適化および自動推論分野の素晴らしいオープンソースソフトウェアの上に成り立っています:
|
|
236
234
|
|
|
237
235
|
- **[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 で開発された
|
|
236
|
+
- **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** — デルフト工科大学 ConSol Lab により Rust で開発された Lazy Clause Generation(LCG)制約プログラミングソルバーであり、WaSHI の同梱 CP および `unsatCore` エンジンを支えています。
|
|
239
237
|
- **[Z3 Theorem Prover](https://github.com/Z3Prover/z3)**([`z3-solver`](https://www.npmjs.com/package/z3-solver))— Microsoft Research により開発された SMT ソルバーであり、オプションの論理充足判定および `unsatCore` 矛盾診断プラグインを支えています。
|
|
240
238
|
- **[GLPK](https://www.gnu.org/software/glpk/) & [`glpk.js`](https://github.com/jvail/glpk.js)** — オプションの GPL-3.0 LP / MIP ソルバープラグインを支えています。
|
|
241
239
|
- **[PuLP](https://github.com/coin-or/pulp)** — WaSHI の直感的な代数モデリング API 設計に大きな着想を与えました。
|
package/README.md
CHANGED
|
@@ -24,13 +24,13 @@
|
|
|
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 bundled **HiGHS** (default) and **Pumpkin** (
|
|
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** (`{ solver: "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 bundled zero-dependency **HiGHS** (LP/MIP/QP) and **Pumpkin** (CP
|
|
33
|
+
- **Solver-Independent**: Use bundled zero-dependency **HiGHS** (LP/MIP/QP) and **Pumpkin** (CP), 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
|
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
|
|
48
48
|
```bash
|
|
49
49
|
npm install @ohtaman/washi
|
|
50
|
-
# HiGHS (LP/MIP/QP) and Pumpkin (CP
|
|
50
|
+
# HiGHS (LP/MIP/QP, default) and Pumpkin (CP, { solver: "pumpkin" }) are bundled with zero extra dependencies or plugin imports
|
|
51
51
|
|
|
52
52
|
# Optional peer-dependency solver plugins
|
|
53
53
|
npm install z3-solver # For SMT logic & exact real/integer unsat core diagnosis
|
|
@@ -78,13 +78,13 @@ console.log(`Produce: x=${x.value}, y=${y.value} (Profit: $${m.objectiveValue})`
|
|
|
78
78
|
|
|
79
79
|
| Solver | License | Problem Classes | Primary Use Case | Setup |
|
|
80
80
|
| :--- | :--- | :--- | :--- | :--- |
|
|
81
|
-
| **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | MIT | LP, MIP, Convex QP | Numerical optimization &
|
|
82
|
-
| **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** | MIT | CP
|
|
81
|
+
| **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | MIT | LP, MIP, Convex QP | Numerical optimization & conflict diagnosis (constraint relaxation) | Bundled default (zero deps, no extra import) |
|
|
82
|
+
| **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** | MIT | CP (Lazy Clause Generation), Logic, Bounded Integer | Combinatorial scheduling & bounded-integer `unsatCore` | Bundled (`{ solver: "pumpkin" }`, zero deps, no extra import) |
|
|
83
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
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"` |
|
|
85
85
|
| **Mock** | MIT | — | Deterministic unit & integration testing | Built-in (`MockSolver`) |
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
Switch between bundled HiGHS (default) and Pumpkin with `{ solver: "pumpkin" }` out of the box, or pass `{ solver: "z3" }` / `{ solver: "glpk" }` after importing the corresponding optional plugin. Solver-specific classes and loader helpers (`HighsSolver`, `setHighsWasmUrl`, `PumpkinSolver`, `setPumpkinWasmUrl`, etc.) live under `@ohtaman/washi/solvers/{highs,pumpkin,z3,glpk}`.
|
|
88
88
|
|
|
89
89
|
---
|
|
90
90
|
|
|
@@ -139,11 +139,10 @@ console.log(`Tech: ${x.value?.toFixed(2)}, Bonds: ${y.value?.toFixed(2)}`);
|
|
|
139
139
|
|
|
140
140
|
### 3. Constraint Programming & Disjunctive Scheduling (Pumpkin)
|
|
141
141
|
|
|
142
|
-
Use bundled **Pumpkin** (
|
|
142
|
+
Use bundled **Pumpkin** (`{ solver: "pumpkin" }`) for bounded integer scheduling and CP global constraints (`disjoint`, `distinct`, `cumulative`, `allowed`) with zero external dependencies or extra imports:
|
|
143
143
|
|
|
144
144
|
```ts
|
|
145
145
|
import { Model, expr, disjoint, distinct, minimize } from "@ohtaman/washi";
|
|
146
|
-
import "@ohtaman/washi/solvers/pumpkin";
|
|
147
146
|
|
|
148
147
|
const m = new Model("WorkshopCP", { solver: "pumpkin" });
|
|
149
148
|
const start = m.integer(["cut", "weld", "paint"] as const, { lb: 0, ub: 20, prefix: "start" });
|
|
@@ -169,14 +168,14 @@ console.log(`Makespan: ${m.objectiveValue}h (paint starts at ${start.paint.value
|
|
|
169
168
|
### 4. Logic & Conflict Diagnosis (`m.check`)
|
|
170
169
|
|
|
171
170
|
Express logical implications and diagnose why a model is infeasible:
|
|
172
|
-
- **HiGHS (default)**:
|
|
173
|
-
- **Pumpkin (bundled)**: Extracts
|
|
171
|
+
- **HiGHS (default)**: Identifies constraints whose relaxation restores feasibility (`res.conflicts`).
|
|
172
|
+
- **Pumpkin (bundled)**: Extracts an exact **unsatisfiable core** (`res.unsatCore` / `res.conflicts`) for bounded integer and boolean models.
|
|
174
173
|
- **Z3**: Extracts an exact SMT **unsatisfiable core** (`res.unsatCore` / `res.conflicts`) including continuous and rational arithmetic.
|
|
175
174
|
|
|
176
175
|
```ts
|
|
177
176
|
import { Model, implies, expr } from "@ohtaman/washi";
|
|
178
|
-
//
|
|
179
|
-
// import "@ohtaman/washi/solvers/z3";
|
|
177
|
+
// Pass { solver: "pumpkin" } for bundled bounded-int/bool exact unsatCore (no extra import)
|
|
178
|
+
// import "@ohtaman/washi/solvers/z3"; // Optional: exact SMT unsatCore including Continuous vars
|
|
180
179
|
|
|
181
180
|
const m = new Model("StaffingRules");
|
|
182
181
|
const engineers = m.integer("engineers", { lb: 0, ub: 20 });
|
|
@@ -198,29 +197,28 @@ console.log(res.conflicts); // HiGHS: ["rush_required"]
|
|
|
198
197
|
|
|
199
198
|
## 🌐 Browser & Web Worker Usage
|
|
200
199
|
|
|
201
|
-
- **Bundlers (Vite / webpack 5)**: `import { Model } from "@ohtaman/washi"` works out of the box.
|
|
202
|
-
- **Standalone ESM / Script Tag / CDN**: Serve `dist/browser/` (including `highs.wasm`, `solvers/pumpkin.wasm`, and worker chunks) or load from a CDN.
|
|
200
|
+
- **Bundlers (Vite / webpack 5)**: `import { Model } from "@ohtaman/washi"` works out of the box. On standard browser origins (`http://` / `https://`), **HiGHS** and **Pumpkin** run in dedicated Web Workers by default (opaque origins such as `file://` default to `{ useWorker: false }`, and you can pass `{ useWorker: false }` explicitly for main-thread execution).
|
|
201
|
+
- **Standalone ESM / Script Tag / CDN**: Serve `dist/browser/` (including `solvers/highs.wasm`, `solvers/pumpkin.wasm`, and worker chunks) or load from a CDN. `washi.js` and `washi.min.js` both include HiGHS and Pumpkin out of the box.
|
|
203
202
|
|
|
204
203
|
```html
|
|
205
|
-
<!-- Browser ESM -->
|
|
204
|
+
<!-- Browser ESM (includes both HiGHS and Pumpkin) -->
|
|
206
205
|
<script type="module">
|
|
207
206
|
import { Model } from "./washi/washi.js";
|
|
208
|
-
//
|
|
209
|
-
// import "./washi/solvers/pumpkin.js"; // Bundled CP/LCG (zero COOP/COEP)
|
|
207
|
+
// Optional solver plugins:
|
|
210
208
|
// import "./washi/solvers/glpk.js"; // Optional GLPK plugin
|
|
211
|
-
// import "./washi/solvers/z3.js"; // Optional Z3 plugin (
|
|
209
|
+
// import "./washi/solvers/z3.js"; // Optional Z3 plugin (see note below)
|
|
212
210
|
const m = new Model();
|
|
213
211
|
await m.solve();
|
|
214
212
|
</script>
|
|
215
213
|
|
|
216
|
-
<!-- Classic Script / CodePen (exposes global Washi) -->
|
|
214
|
+
<!-- Classic Script / CodePen (exposes global Washi with both HiGHS and Pumpkin) -->
|
|
217
215
|
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/washi.min.js"></script>
|
|
218
216
|
<!-- Optional solver plugin scripts (auto-register on window.Washi): -->
|
|
219
|
-
<!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/
|
|
217
|
+
<!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/glpk.min.js"></script> -->
|
|
220
218
|
```
|
|
221
219
|
|
|
222
220
|
> [!NOTE]
|
|
223
|
-
> **Z3 in the Browser**: Because Z3's WebAssembly build uses `SharedArrayBuffer`, browsers require Cross-Origin Isolation (`
|
|
221
|
+
> **Z3 in the Browser**: Because Z3's WebAssembly build uses `SharedArrayBuffer`, browsers require a **Secure Context** (`HTTPS` or `localhost`) and Cross-Origin Isolation headers (`Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp`). See the [Cross-Origin Isolation Guide](docs/getting-started/cross-origin.md) and [`examples/distribution/`](examples/distribution/README.md). **HiGHS**, **Pumpkin**, and **GLPK** work without Cross-Origin Isolation headers.
|
|
224
222
|
|
|
225
223
|
---
|
|
226
224
|
|
|
@@ -235,7 +233,7 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md) for local development setup, running te
|
|
|
235
233
|
WaSHI stands on the shoulders of the open-source mathematical optimization and automated reasoning communities:
|
|
236
234
|
|
|
237
235
|
- **[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
|
|
236
|
+
- **[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 and `unsatCore` engine.
|
|
239
237
|
- **[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.
|
|
240
238
|
- **[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.
|
|
241
239
|
- **[PuLP](https://github.com/coin-or/pulp)** — Inspiring WaSHI's declarative algebraic modeling ergonomics.
|
package/README.zh-CN.md
CHANGED
|
@@ -17,27 +17,27 @@
|
|
|
17
17
|
<a href="https://www.npmjs.com/package/@ohtaman/washi"><img src="https://img.shields.io/npm/v/@ohtaman/washi?color=crimson&label=npm" alt="npm version" /></a>
|
|
18
18
|
<a href="https://github.com/ohtaman/washi/actions/workflows/distribution.yml"><img src="https://github.com/ohtaman/washi/actions/workflows/distribution.yml/badge.svg" alt="CI Status" /></a>
|
|
19
19
|
<a href="https://washi.ohtaman.dev/zh/"><img src="https://img.shields.io/badge/docs-online-blue" alt="docs" /></a>
|
|
20
|
-
<a href="https://washi.ohtaman.dev/demo
|
|
20
|
+
<a href="https://washi.ohtaman.dev/demo/?lang=zh"><img src="https://img.shields.io/badge/demo-playground-brightgreen" alt="live demo" /></a>
|
|
21
21
|
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="license" /></a>
|
|
22
22
|
</p>
|
|
23
23
|
</div>
|
|
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**(`{ solver: "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
|
-
- **求解器无关**:内置零外部依赖的 **HiGHS**(LP/MIP/QP)与 **Pumpkin**(CP
|
|
33
|
+
- **求解器无关**:内置零外部依赖的 **HiGHS**(LP/MIP/QP)与 **Pumpkin**(CP),并支持按需加载 **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/) · [浏览器演示](https://washi.ohtaman.dev/demo
|
|
40
|
+
- **[案例展示](https://washi.ohtaman.dev/zh/showcase/) · [浏览器演示](https://washi.ohtaman.dev/demo/?lang=zh) · [数理优化 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
|
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
|
|
48
48
|
```bash
|
|
49
49
|
npm install @ohtaman/washi
|
|
50
|
-
# HiGHS (LP/MIP/QP) 与 Pumpkin (CP
|
|
50
|
+
# HiGHS (LP/MIP/QP, 默认) 与 Pumpkin (CP, { solver: "pumpkin" }) 均已内置打包,无需额外依赖或插件导入
|
|
51
51
|
|
|
52
52
|
# 可选 peer-dependency 求解器插件
|
|
53
53
|
npm install z3-solver # 用于 SMT 逻辑与包含连续变量的精确冲突诊断
|
|
@@ -65,8 +65,8 @@ const x = m.integer("桌子", { lb: 0 });
|
|
|
65
65
|
const y = m.integer("椅子", { lb: 0 });
|
|
66
66
|
|
|
67
67
|
m.objective(maximize(expr`30 * ${x} + 50 * ${y}`));
|
|
68
|
-
m.constraint(expr`${x} + 2 * ${y} <= 40`, "
|
|
69
|
-
m.constraint(expr`2 * ${x} + ${y} <= 50`, "
|
|
68
|
+
m.constraint(expr`${x} + 2 * ${y} <= 40`, "木材上限");
|
|
69
|
+
m.constraint(expr`2 * ${x} + ${y} <= 50`, "劳动力上限");
|
|
70
70
|
|
|
71
71
|
await m.solve();
|
|
72
72
|
console.log(`生产计划: x=${x.value}, y=${y.value} (最大利润: $${m.objectiveValue})`);
|
|
@@ -78,13 +78,13 @@ console.log(`生产计划: x=${x.value}, y=${y.value} (最大利润: $${m.object
|
|
|
78
78
|
|
|
79
79
|
| 求解器 | 许可证 | 支持问题类型 | 主要用途 | 引入方式 |
|
|
80
80
|
| :--- | :--- | :--- | :--- | :--- |
|
|
81
|
-
| **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | MIT | LP, MIP, 凸QP |
|
|
82
|
-
| **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** | MIT | CP
|
|
81
|
+
| **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | MIT | LP, MIP, 凸QP | 数值优化与冲突诊断(约束松弛) | 内置默认(零额外依赖、无需导入插件) |
|
|
82
|
+
| **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** | MIT | CP(惰性子句生成), 逻辑, 有界整数 | 组合调度与有界整数 `unsatCore` | 内置(`{ solver: "pumpkin" }`,零额外依赖、无需导入插件) |
|
|
83
83
|
| **[Z3](https://github.com/Z3Prover/z3)** | MIT | SMT, SAT, 逻辑, MIP | 逻辑规则、可满足性判定与精确 `unsatCore` | `npm install z3-solver` + `import "@ohtaman/washi/solvers/z3"` |
|
|
84
84
|
| **[GLPK](https://www.gnu.org/software/glpk/)** | GPL-3.0 | LP, MIP | 线性与混合整数规划 | `npm install glpk.js` + `import "@ohtaman/washi/solvers/glpk"` |
|
|
85
85
|
| **Mock** | MIT | — | 单元与集成测试模拟响应 | 内置 (`MockSolver`) |
|
|
86
86
|
|
|
87
|
-
|
|
87
|
+
内置的 HiGHS(默认)与 Pumpkin(`{ solver: "pumpkin" }`)可直接切换而无需额外导入;若使用可选插件 `{ solver: "z3" }` 或 `{ solver: "glpk" }`,请先导入对应插件模块。各求解器专属类与配置函数(如 `HighsSolver`、`setHighsWasmUrl`、`PumpkinSolver`、`setPumpkinWasmUrl` 等)均位于 `@ohtaman/washi/solvers/{highs,pumpkin,z3,glpk}`。
|
|
88
88
|
|
|
89
89
|
---
|
|
90
90
|
|
|
@@ -137,13 +137,12 @@ await m.solve();
|
|
|
137
137
|
console.log(`Tech: ${x.value?.toFixed(2)}, Bonds: ${y.value?.toFixed(2)}`);
|
|
138
138
|
```
|
|
139
139
|
|
|
140
|
-
### 3.
|
|
140
|
+
### 3. 约束规划与无重叠排程 (Pumpkin)
|
|
141
141
|
|
|
142
|
-
使用内置的 **Pumpkin
|
|
142
|
+
使用内置的 **Pumpkin**(`{ solver: "pumpkin" }`)求解有界整数调度与 CP 全局约束(`disjoint`、`distinct`、`cumulative`、`allowed`),无需任何额外依赖或导入:
|
|
143
143
|
|
|
144
144
|
```ts
|
|
145
145
|
import { Model, expr, disjoint, distinct, minimize } from "@ohtaman/washi";
|
|
146
|
-
import "@ohtaman/washi/solvers/pumpkin";
|
|
147
146
|
|
|
148
147
|
const m = new Model("WorkshopCP", { solver: "pumpkin" });
|
|
149
148
|
const start = m.integer(["cut", "weld", "paint"] as const, { lb: 0, ub: 20, prefix: "start" });
|
|
@@ -169,14 +168,14 @@ console.log(`Makespan: ${m.objectiveValue}h (paint starts at ${start.paint.value
|
|
|
169
168
|
### 4. 逻辑规则与冲突诊断 (`m.check`)
|
|
170
169
|
|
|
171
170
|
表达逻辑蕴含规则并排查不可行原因:
|
|
172
|
-
- **HiGHS
|
|
173
|
-
- **Pumpkin
|
|
171
|
+
- **HiGHS(默认)**:定位松弛后可恢复可行性的约束集合(`res.conflicts`)。
|
|
172
|
+
- **Pumpkin(内置)**:为有界整数与布尔模型提取精确的**不可满足核心**(`res.unsatCore` / `res.conflicts`)。
|
|
174
173
|
- **Z3**:提取包含连续变量与有理数算术的精确 **SMT 不可满足核心**(`res.unsatCore` / `res.conflicts`)。
|
|
175
174
|
|
|
176
175
|
```ts
|
|
177
176
|
import { Model, implies, expr } from "@ohtaman/washi";
|
|
178
|
-
//
|
|
179
|
-
// import "@ohtaman/washi/solvers/z3";
|
|
177
|
+
// 传入 { solver: "pumpkin" } 即可直接提取有界整数/布尔精确 unsatCore(无需额外导入)
|
|
178
|
+
// import "@ohtaman/washi/solvers/z3"; // 可选:支持含连续变量的精确 SMT unsatCore
|
|
180
179
|
|
|
181
180
|
const m = new Model("StaffingRules");
|
|
182
181
|
const engineers = m.integer("engineers", { lb: 0, ub: 20 });
|
|
@@ -198,29 +197,28 @@ console.log(res.conflicts); // HiGHS: ["rush_required"]
|
|
|
198
197
|
|
|
199
198
|
## 🌐 浏览器与 Web Worker 使用指南
|
|
200
199
|
|
|
201
|
-
- **打包工具 (Vite / webpack 5)**:直接 `import { Model } from "@ohtaman/washi"`
|
|
202
|
-
- **原生 ESM / Script 标签 / CDN**:部署 `dist/browser/` 目录(含 `highs.wasm`、`solvers/pumpkin.wasm` 与 Worker 资源)或从 CDN
|
|
200
|
+
- **打包工具 (Vite / webpack 5)**:直接 `import { Model } from "@ohtaman/washi"` 即可。在标准源(`http://` / `https://`)的浏览器环境中,**HiGHS** 与 **Pumpkin** 默认在专用 Web Worker 中求解(`file://` 等不透明源会自动回退到 `{ useWorker: false }`,也可显式传入 `{ useWorker: false }` 在主线程执行)。
|
|
201
|
+
- **原生 ESM / Script 标签 / CDN**:部署 `dist/browser/` 目录(含 `solvers/highs.wasm`、`solvers/pumpkin.wasm` 与 Worker 资源)或从 CDN 加载。`washi.js` 与 `washi.min.js` 均已开箱内置 HiGHS 与 Pumpkin。
|
|
203
202
|
|
|
204
203
|
```html
|
|
205
|
-
<!-- 浏览器原生 ESM -->
|
|
204
|
+
<!-- 浏览器原生 ESM(同时包含 HiGHS 与 Pumpkin) -->
|
|
206
205
|
<script type="module">
|
|
207
206
|
import { Model } from "./washi/washi.js";
|
|
208
|
-
//
|
|
209
|
-
// import "./washi/solvers/pumpkin.js"; // 内置 CP/LCG(免 COOP/COEP)
|
|
207
|
+
// 可选求解器插件:
|
|
210
208
|
// import "./washi/solvers/glpk.js"; // 可选 GLPK 插件
|
|
211
|
-
// import "./washi/solvers/z3.js"; // 可选 Z3
|
|
209
|
+
// import "./washi/solvers/z3.js"; // 可选 Z3 插件(见下方说明)
|
|
212
210
|
const m = new Model();
|
|
213
211
|
await m.solve();
|
|
214
212
|
</script>
|
|
215
213
|
|
|
216
|
-
<!-- Script 标签 / CodePen (挂载全局变量 Washi) -->
|
|
214
|
+
<!-- Script 标签 / CodePen (挂载全局变量 Washi,同时包含 HiGHS 与 Pumpkin) -->
|
|
217
215
|
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/washi.min.js"></script>
|
|
218
216
|
<!-- 可选求解器插件脚本(自动注册到 window.Washi): -->
|
|
219
|
-
<!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/
|
|
217
|
+
<!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/glpk.min.js"></script> -->
|
|
220
218
|
```
|
|
221
219
|
|
|
222
220
|
> [!NOTE]
|
|
223
|
-
> **浏览器中使用 Z3**:Z3 的 WebAssembly 引擎依赖 `SharedArrayBuffer
|
|
221
|
+
> **浏览器中使用 Z3**:Z3 的 WebAssembly 引擎依赖 `SharedArrayBuffer`,需要 **Secure Context**(`HTTPS` 或 `localhost`)以及跨源隔离响应头(`Cross-Origin-Opener-Policy: same-origin` 与 `Cross-Origin-Embedder-Policy: require-corp`)。详见[跨源隔离指南](docs/zh/getting-started/cross-origin.md)与 [`examples/distribution/`](examples/distribution/README.md)。**HiGHS**、**Pumpkin** 与 **GLPK** 均无需跨源隔离响应头即可运行。
|
|
224
222
|
|
|
225
223
|
---
|
|
226
224
|
|
|
@@ -235,7 +233,7 @@ console.log(res.conflicts); // HiGHS: ["rush_required"]
|
|
|
235
233
|
WaSHI 的诞生离不开数理优化与自动推理开源社区的卓越工作:
|
|
236
234
|
|
|
237
235
|
- **[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
|
|
236
|
+
- **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** — 由代尔夫特理工大学(TU Delft)ConSol Lab 使用 Rust 开发的惰性子句生成(Lazy Clause Generation, LCG)约束规划求解器,驱动了 WaSHI 内置的 CP 与 `unsatCore` 引擎。
|
|
239
237
|
- **[Z3 Theorem Prover](https://github.com/Z3Prover/z3)**([`z3-solver`](https://www.npmjs.com/package/z3-solver))— 由 Microsoft Research 研发,驱动了 WaSHI 可选的 SMT 可满足性判定与精确 `unsatCore` 冲突诊断插件。
|
|
240
238
|
- **[GLPK](https://www.gnu.org/software/glpk/) & [`glpk.js`](https://github.com/jvail/glpk.js)** — 驱动了 WaSHI 可选的 GPL-3.0 LP / MIP 求解器插件。
|
|
241
239
|
- **[PuLP](https://github.com/coin-or/pulp)** — 启发了 WaSHI 声明式代数建模 API 的设计。
|
|
@@ -441,39 +441,46 @@ function h(e = {}) {
|
|
|
441
441
|
if (e.objectiveOffset !== void 0 && (typeof e.objectiveOffset != "number" || !Number.isFinite(e.objectiveOffset))) throw Error(`Invalid HiGHS option "objectiveOffset" (${String(e.objectiveOffset)}): expected a finite number.`);
|
|
442
442
|
if (e.wasmUrl !== void 0 && e.wasmUrl !== null && (typeof e.wasmUrl != "string" || e.wasmUrl === "")) throw Error("Invalid HiGHS option \"wasmUrl\": expected a non-empty string or null.");
|
|
443
443
|
}
|
|
444
|
-
var g = null, _ = null, v = null;
|
|
445
|
-
function
|
|
446
|
-
|
|
444
|
+
var g = null, _ = null, v = null, y = null;
|
|
445
|
+
function b(e) {
|
|
446
|
+
y = e, g = null, _ = null, v = null;
|
|
447
447
|
}
|
|
448
|
-
function
|
|
449
|
-
return
|
|
448
|
+
function x() {
|
|
449
|
+
return y;
|
|
450
450
|
}
|
|
451
|
-
|
|
452
|
-
return e
|
|
451
|
+
function S(e) {
|
|
452
|
+
return e.length >= 4 && e[0] === 0 && e[1] === 97 && e[2] === 115 && e[3] === 109;
|
|
453
453
|
}
|
|
454
|
-
async function
|
|
455
|
-
|
|
454
|
+
async function C(e) {
|
|
455
|
+
return e || y || n();
|
|
456
|
+
}
|
|
457
|
+
async function w(e = {}) {
|
|
458
|
+
let t = await C(e.wasmUrl);
|
|
456
459
|
return {
|
|
457
460
|
isNode: !1,
|
|
458
461
|
wasmUrl: t,
|
|
459
462
|
key: t ?? "node"
|
|
460
463
|
};
|
|
461
464
|
}
|
|
462
|
-
async function
|
|
463
|
-
let {
|
|
465
|
+
async function T(e = {}) {
|
|
466
|
+
let { key: t } = await w(e);
|
|
467
|
+
return v === t;
|
|
468
|
+
}
|
|
469
|
+
async function E(e = {}) {
|
|
470
|
+
let { isNode: t, wasmUrl: n, key: i } = await w(e);
|
|
464
471
|
if (g && _ === i) return g;
|
|
465
|
-
_ = i;
|
|
472
|
+
_ = i, v = null;
|
|
466
473
|
let a = null;
|
|
467
474
|
return a = (async () => {
|
|
468
|
-
let e = t ? await r() : (await import("./browser-runtime-
|
|
475
|
+
let e = t ? await r() : (await import("./highs-browser-runtime-0Bgq5ksG.js")).default;
|
|
469
476
|
return t ? await e() : await e({ locateFile: (e) => e.endsWith(".wasm") ? n : e });
|
|
470
|
-
})().then((e) => e).catch((e) => {
|
|
471
|
-
g === a && (g = null, _ = null);
|
|
477
|
+
})().then((e) => (g === a && (v = i), e)).catch((e) => {
|
|
478
|
+
g === a && (g = null, _ = null, v = null);
|
|
472
479
|
let t = e instanceof Error ? e.message : String(e);
|
|
473
480
|
throw Error(`[WaSHI] Failed to initialize HiGHS${n ? ` from "${n}"` : ""}. Deploy the package's WASM asset or explicitly set wasmUrl; no CDN fallback is attempted. ${t}`, { cause: e });
|
|
474
481
|
}), g = a, a;
|
|
475
482
|
}
|
|
476
|
-
async function
|
|
483
|
+
async function D(e, t = {}) {
|
|
477
484
|
if (h(t), t.signal?.aborted) return {
|
|
478
485
|
result: {
|
|
479
486
|
Status: "Interrupted",
|
|
@@ -485,7 +492,7 @@ async function w(e, t = {}) {
|
|
|
485
492
|
},
|
|
486
493
|
runTime: 0
|
|
487
494
|
};
|
|
488
|
-
let n = await
|
|
495
|
+
let n = await E(t);
|
|
489
496
|
if (t.signal?.aborted) return {
|
|
490
497
|
result: {
|
|
491
498
|
Status: "Interrupted",
|
|
@@ -674,4 +681,4 @@ async function w(e, t = {}) {
|
|
|
674
681
|
};
|
|
675
682
|
}
|
|
676
683
|
//#endregion
|
|
677
|
-
export {
|
|
684
|
+
export { n as _, C as a, h as c, f as d, a as f, t as g, l as h, S as i, c as l, o as m, x as n, b as o, d as p, T as r, D as s, E as t, s as u };
|