@ohtaman/washi 0.8.1 → 0.8.2

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.md CHANGED
@@ -1,24 +1,24 @@
1
1
  <div align="center">
2
2
  <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="./assets/washi-header-dark.png">
4
- <source media="(prefers-color-scheme: light)" srcset="./assets/washi-header-light.png">
5
- <img alt="WaSHI - Mathematical Optimization Modeler in TypeScript" src="./assets/washi-header-light.png" width="420" />
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://washi.ohtaman.dev/washi-header-dark.png">
4
+ <source media="(prefers-color-scheme: light)" srcset="https://washi.ohtaman.dev/washi-header-light.png">
5
+ <img alt="WaSHI - Mathematical Optimization Modeler in TypeScript" src="https://washi.ohtaman.dev/washi-header-light.png" width="420" />
6
6
  </picture>
7
7
  <p><strong>Mathematical Optimization Modeler in TypeScript</strong></p>
8
8
  <p>
9
9
  <em>Linear Programming (LP) • Mixed-Integer Programming (MIP) • Convex Quadratic Programming (QP) • Constraint Programming (CP) • SMT &amp; Conflict Diagnosis</em>
10
10
  </p>
11
11
  <p>
12
- <a href="./README.md">English</a> •
13
- <a href="./README.ja.md">日本語</a> •
14
- <a href="./README.zh-CN.md">简体中文</a>
12
+ <a href="https://github.com/ohtaman/washi/blob/main/README.md">English</a> •
13
+ <a href="https://github.com/ohtaman/washi/blob/main/README-ja.md">日本語</a> •
14
+ <a href="https://github.com/ohtaman/washi/blob/main/README-zh-CN.md">简体中文</a>
15
15
  </p>
16
16
  <p>
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/"><img src="https://img.shields.io/badge/docs-online-blue" alt="docs" /></a>
20
20
  <a href="https://washi.ohtaman.dev/demo/"><img src="https://img.shields.io/badge/demo-playground-brightgreen" alt="live demo" /></a>
21
- <a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="license" /></a>
21
+ <a href="https://github.com/ohtaman/washi/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="license" /></a>
22
22
  </p>
23
23
  </div>
24
24
 
@@ -38,8 +38,8 @@
38
38
 
39
39
  - **[Documentation](https://washi.ohtaman.dev/)**: Modeling guide, solver references, and deployment guides
40
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
- - **[Examples](https://washi.ohtaman.dev/examples/)**: Problem recipes and runnable Node.js / browser scripts ([`examples/`](examples/README.md))
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
41
+ - **[Examples](https://washi.ohtaman.dev/examples/)**: Problem recipes and runnable Node.js / browser scripts ([`examples/`](https://github.com/ohtaman/washi/blob/main/examples/README.md))
42
+ - **[Agent Skill (`SKILL.md`)](https://github.com/ohtaman/washi/blob/main/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
 
@@ -218,13 +218,13 @@ console.log(res.conflicts); // HiGHS: ["rush_required"]
218
218
  ```
219
219
 
220
220
  > [!NOTE]
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.
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](https://washi.ohtaman.dev/getting-started/cross-origin) and [`examples/distribution/`](https://github.com/ohtaman/washi/blob/main/examples/distribution/README.md). **HiGHS**, **Pumpkin**, and **GLPK** work without Cross-Origin Isolation headers.
222
222
 
223
223
  ---
224
224
 
225
225
  ## 🤝 Contributing
226
226
 
227
- See [CONTRIBUTING.md](./CONTRIBUTING.md) for local development setup, running tests and benchmarks, rebuilding WebAssembly assets, and the release workflow.
227
+ See [CONTRIBUTING.md](https://github.com/ohtaman/washi/blob/main/CONTRIBUTING.md) for local development setup, running tests and benchmarks, rebuilding WebAssembly assets, and the release workflow.
228
228
 
229
229
  ---
230
230
 
@@ -242,5 +242,5 @@ WaSHI stands on the shoulders of the open-source mathematical optimization and a
242
242
 
243
243
  ## 📄 License
244
244
 
245
- - **`@ohtaman/washi`**: [MIT License](./LICENSE)
246
- - **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.
245
+ - **`@ohtaman/washi`**: [MIT License](https://github.com/ohtaman/washi/blob/main/LICENSE)
246
+ - **Bundled / Optional Engines**: HiGHS (MIT), Pumpkin (MIT), Z3 (MIT), GLPK (GPL-3.0). See [THIRD_PARTY_LICENSES.md](https://github.com/ohtaman/washi/blob/main/THIRD_PARTY_LICENSES.md) for full details.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohtaman/washi",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "WaSHI: TypeScript & JavaScript algebraic modeler for Mathematical Optimization & Constraint Programming (LP, MILP, QP, CP, SMT) powered by WebAssembly (HiGHS, Pumpkin, Z3, GLPK)",
5
5
  "type": "module",
6
6
  "main": "./dist/lib/washi.js",
@@ -78,8 +78,6 @@
78
78
  "llms.txt",
79
79
  "llms-full.txt",
80
80
  "README.md",
81
- "README.ja.md",
82
- "README.zh-CN.md",
83
81
  "LICENSE",
84
82
  "THIRD_PARTY_LICENSES.md"
85
83
  ],
package/README.ja.md DELETED
@@ -1,246 +0,0 @@
1
- <div align="center">
2
- <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="./assets/washi-header-dark.png">
4
- <source media="(prefers-color-scheme: light)" srcset="./assets/washi-header-light.png">
5
- <img alt="WaSHI - TypeScript 数理最適化モデラー" src="./assets/washi-header-light.png" width="420" />
6
- </picture>
7
- <p><strong>TypeScript 数理最適化モデラー</strong></p>
8
- <p>
9
- <em>線形計画 (LP) • 混合整数計画 (MIP) • 凸二次計画 (QP) • 制約プログラミング (CP) • SMT論理制約 &amp; 矛盾診断</em>
10
- </p>
11
- <p>
12
- <a href="./README.md">English</a> •
13
- <a href="./README.ja.md">日本語</a> •
14
- <a href="./README.zh-CN.md">简体中文</a>
15
- </p>
16
- <p>
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
- <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
- <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/?lang=ja"><img src="https://img.shields.io/badge/demo-playground-brightgreen" alt="live demo" /></a>
21
- <a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="license" /></a>
22
- </p>
23
- </div>
24
-
25
- ---
26
-
27
- **WaSHI**(WebAssembly-backed, Solver-independent, High-level modeling Interface)は、Python の **PuLP** に着想を得た、数理最適化と制約プログラミングのための TypeScript / JavaScript 向け代数モデラーです。変数・目的関数・制約をアプリケーションコードで記述し、Node.js やブラウザ上で同梱の **HiGHS**(デフォルト)・**Pumpkin**(`{ solver: "pumpkin" }`)、あるいはオプションの **Z3**・**GLPK** を使ってそのまま求解できます。
28
-
29
- ## ✨ 主な特徴
30
-
31
- - **直感的な数式記述**: `` expr`30 * ${x} + 50 * ${y} <= 40` `` や総和・内積(`sum`, `dot`)で数式と制約を簡潔に書けます。
32
- - **Node.js・ブラウザで完結**: WebAssembly ベースのため、Python サーバーや C/C++ のネイティブビルドなしで動作します。
33
- - **ソルバー非依存**: 追加依存なしの同梱 **HiGHS**(LP/MIP/QP)・**Pumpkin**(CP)に加え、オプションの **Z3**・**GLPK** や独自ソルバーへ切り替えられます。
34
- - **充足判定と矛盾診断**: 論理・数値制約の充足可能性判定や、実行不能(Infeasible)になった原因制約の特定に対応しています。
35
- - **大規模問題の分解法**: 列生成法やベンダーズ分解などの分解アルゴリズムをサポートしています。
36
-
37
- ## 📚 ドキュメント & リンク
38
-
39
- - **[ドキュメント](https://washi.ohtaman.dev/ja/)**: モデリングガイド・ソルバー仕様・環境別の導入手順
40
- - **[ショーケース](https://washi.ohtaman.dev/ja/showcase/) · [ブラウザデモ](https://washi.ohtaman.dev/demo/?lang=ja) · [数理最適化N本ノック](https://washi.ohtaman.dev/exercises/?lang=ja)**: ブラウザ上で動くデモアプリ集・プレイグラウンド・N本ノックを体験できます
41
- - **[サンプル集](https://washi.ohtaman.dev/ja/examples/)**: 課題別の実践レシピと実行可能なサンプルコード([`examples/`](examples/README.md))
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
-
44
- ---
45
-
46
- ## 📦 インストール & クイックスタート
47
-
48
- ```bash
49
- npm install @ohtaman/washi
50
- # HiGHS (LP/MIP/QP, デフォルト) と Pumpkin (CP, { solver: "pumpkin" }) は追加依存・追加インポートなしでそのまま使えます
51
-
52
- # オプションの peer-dependency ソルバープラグイン
53
- npm install z3-solver # SMT 論理制約・実数を含む厳密 Unsat Core 診断を使う場合
54
- npm install glpk.js # GLPK ソルバーを使う場合 (GPL-3.0)
55
-
56
- # AI コーディングエージェント用スキル (Claude Code, Cursor, Codex 等)
57
- npx skills add ohtaman/washi
58
- ```
59
-
60
- ```ts
61
- import { Model, expr, maximize } from "@ohtaman/washi";
62
-
63
- const m = new Model("木工製品の利益最大化");
64
- const x = m.integer("机", { lb: 0 });
65
- const y = m.integer("椅子", { lb: 0 });
66
-
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`, "労働力上限");
70
-
71
- await m.solve();
72
- console.log(`生産量: x=${x.value}, y=${y.value} (最大利益: $${m.objectiveValue})`);
73
- ```
74
-
75
- ---
76
-
77
- ## ⚙️ 対応ソルバー
78
-
79
- | ソルバー | ライセンス | 対応クラス | 主な用途 | 導入方法 |
80
- | :--- | :--- | :--- | :--- | :--- |
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
- | **[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"` |
85
- | **Mock** | MIT | — | テスト用の決定論的な模擬応答 | 標準搭載 (`MockSolver`) |
86
-
87
- 同梱の HiGHS(既定)と Pumpkin(`{ solver: "pumpkin" }`)は追加インポートなしでそのまま切り替えられます。オプションの `{ solver: "z3" }`・`{ solver: "glpk" }` は対応プラグインを import した上で指定します。なお、ソルバー固有のクラスや WASM 設定関数(`HighsSolver`, `setHighsWasmUrl`, `PumpkinSolver`, `setPumpkinWasmUrl` 等)は `@ohtaman/washi/solvers/{highs,pumpkin,z3,glpk}` に配置されています。
88
-
89
- ---
90
-
91
- ## 🚀 基本的な使い方
92
-
93
- ### 1. 総和・内積(`sum` / `dot`)と条件付き制約
94
-
95
- `dot` / `sum` による線形式の記述と、`m.indicator()` による条件付き制約:
96
-
97
- ```ts
98
- import { Model, expr, minimize } from "@ohtaman/washi";
99
-
100
- const m = new Model("TransportPlanning");
101
- const factories = ["Tokyo", "Osaka"];
102
- const stores = ["StoreA", "StoreB"];
103
- const costs = {
104
- Tokyo: { StoreA: 4, StoreB: 7 },
105
- Osaka: { StoreA: 8, StoreB: 3 },
106
- };
107
-
108
- const open = m.binary(factories);
109
- const ship = m.continuous(factories, stores, { lb: 0, ub: 500 });
110
-
111
- // 東京工場が閉鎖 (open["Tokyo"] == 0) なら東京工場からの総輸送量は 0
112
- m.indicator(open["Tokyo"], expr`sum(${ship["Tokyo"]}) <= 0`, { activeValue: 0 });
113
- m.constraint(expr`${ship["Tokyo"]["StoreA"]} + ${ship["Osaka"]["StoreA"]} >= 100`, "demand_A");
114
-
115
- m.objective(minimize(expr`dot(${costs}, ${ship})`));
116
- await m.solve();
117
-
118
- console.log("Tokyo -> StoreA:", ship["Tokyo"]["StoreA"].value);
119
- ```
120
-
121
- ### 2. 凸二次計画 (QP)
122
-
123
- 線形制約のもとで二次の目的関数を最小化:
124
-
125
- ```ts
126
- import { Model, expr, minimize } from "@ohtaman/washi";
127
-
128
- const m = new Model("PortfolioQP");
129
- const x = m.continuous("tech", { lb: 0, ub: 1 });
130
- const y = m.continuous("bonds", { lb: 0, ub: 1 });
131
-
132
- m.constraint(expr`${x} + ${y} == 1`, "budget");
133
- m.constraint(expr`0.14 * ${x} + 0.04 * ${y} >= 0.08`, "min_return");
134
- m.objective(minimize(expr`0.04 * ${x}^2 + 0.005 * ${y}^2`));
135
-
136
- await m.solve();
137
- console.log(`Tech: ${x.value?.toFixed(2)}, Bonds: ${y.value?.toFixed(2)}`);
138
- ```
139
-
140
- ### 3. 制約プログラミング & スケジューリング (Pumpkin)
141
-
142
- 同梱の **Pumpkin**(`{ solver: "pumpkin" }`)を使うと、追加依存や追加インポートなしで有界整数スケジューリングや CP グローバル制約(`disjoint`, `distinct`, `cumulative`, `allowed`)を求解できます:
143
-
144
- ```ts
145
- import { Model, expr, disjoint, distinct, minimize } from "@ohtaman/washi";
146
-
147
- const m = new Model("WorkshopCP", { solver: "pumpkin" });
148
- const start = m.integer(["cut", "weld", "paint"] as const, { lb: 0, ub: 20, prefix: "start" });
149
- const bench = m.integer(["cut", "weld", "paint"] as const, { lb: 1, ub: 3, prefix: "bench" });
150
-
151
- m.constraint(
152
- disjoint([
153
- { start: start.cut, duration: 4 },
154
- { start: start.weld, duration: 3 },
155
- { start: start.paint, duration: 2 },
156
- ]),
157
- "single_line"
158
- );
159
- m.constraint(expr`${start.cut} + 4 <= ${start.weld}`, "cut_before_weld");
160
- m.constraint(expr`${start.weld} + 3 <= ${start.paint}`, "weld_before_paint");
161
- m.constraint(distinct(bench), "unique_benches");
162
-
163
- m.objective(minimize(expr`${start.paint} + 2`));
164
- await m.solve();
165
- console.log(`Makespan: ${m.objectiveValue}h (paint starts at ${start.paint.value}h)`);
166
- ```
167
-
168
- ### 4. 論理ルール & 矛盾診断 (`m.check`)
169
-
170
- 論理条件(`m.bool`, `implies`)を含むモデルの充足可能性を判定し、矛盾時の原因制約を特定します:
171
- - **HiGHS(標準)**: 緩和すれば実行可能になる制約集合(`res.conflicts`)を特定します。
172
- - **Pumpkin(同梱)**: 有界整数・真偽値モデルに対して、厳密な**充足不能コア**(`res.unsatCore` / `res.conflicts`)を抽出します。
173
- - **Z3**: 連続変数・実数演算を含む厳密な SMT **充足不能コア**(`res.unsatCore` / `res.conflicts`)を抽出します。
174
-
175
- ```ts
176
- import { Model, implies, expr } from "@ohtaman/washi";
177
- // { solver: "pumpkin" } なら追加インポートなしで有界整数・真偽値の厳密 unsatCore を抽出
178
- // import "@ohtaman/washi/solvers/z3"; // Continuous 変数を含む厳密 SMT unsatCore(オプション)
179
-
180
- const m = new Model("StaffingRules");
181
- const engineers = m.integer("engineers", { lb: 0, ub: 20 });
182
- const budget = m.continuous("budget", { lb: 0, ub: 100000 });
183
- const rush = m.bool("rush");
184
-
185
- m.constraint(expr`8000 * ${engineers} <= ${budget}`, "budget_limit");
186
- m.constraint(rush, "rush_required");
187
- m.constraint(implies(rush, expr`${engineers} >= 8`), "rush_staffing");
188
- m.constraint(expr`${budget} <= 50000`, "budget_cap"); // 矛盾: 8人 * $8,000 > $50,000
189
- m.constraint(expr`${engineers} >= 1`, "min_staff"); // 無関係な制約
190
-
191
- const res = await m.check(); // または await m.check({ solver: "z3" })
192
- console.log(res.status); // "Unsat"
193
- console.log(res.conflicts); // HiGHS: ["rush_required"]
194
- ```
195
-
196
- ---
197
-
198
- ## 🌐 ブラウザ & Web Worker での利用方法
199
-
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 の両方を内蔵しています。
202
-
203
- ```html
204
- <!-- ブラウザ ESM(HiGHS・Pumpkin の両方を利用可能) -->
205
- <script type="module">
206
- import { Model } from "./washi/washi.js";
207
- // オプションプラグイン:
208
- // import "./washi/solvers/glpk.js"; // オプション GLPK プラグイン
209
- // import "./washi/solvers/z3.js"; // オプション Z3 プラグイン(下の注記を参照)
210
- const m = new Model();
211
- await m.solve();
212
- </script>
213
-
214
- <!-- script タグ / CodePen (グローバル Washi を公開、HiGHS・Pumpkin 同梱) -->
215
- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/washi.min.js"></script>
216
- <!-- オプションプラグインスクリプト (window.Washi に自動登録): -->
217
- <!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/glpk.min.js"></script> -->
218
- ```
219
-
220
- > [!NOTE]
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** はこれらのヘッダーなしで動作します。
222
-
223
- ---
224
-
225
- ## 🤝 コントリビューション・開発
226
-
227
- ローカル開発、テスト・ベンチマークの実行、WebAssembly アセットの再ビルド、およびリリース手順については [CONTRIBUTING.md](./CONTRIBUTING.md) を参照してください。
228
-
229
- ---
230
-
231
- ## 🙏 謝辞
232
-
233
- WaSHI は、数理最適化および自動推論分野の素晴らしいオープンソースソフトウェアの上に成り立っています:
234
-
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))。
236
- - **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** — デルフト工科大学 ConSol Lab により Rust で開発された Lazy Clause Generation(LCG)制約プログラミングソルバーであり、WaSHI の同梱 CP および `unsatCore` エンジンを支えています。
237
- - **[Z3 Theorem Prover](https://github.com/Z3Prover/z3)**([`z3-solver`](https://www.npmjs.com/package/z3-solver))— Microsoft Research により開発された SMT ソルバーであり、オプションの論理充足判定および `unsatCore` 矛盾診断プラグインを支えています。
238
- - **[GLPK](https://www.gnu.org/software/glpk/) & [`glpk.js`](https://github.com/jvail/glpk.js)** — オプションの GPL-3.0 LP / MIP ソルバープラグインを支えています。
239
- - **[PuLP](https://github.com/coin-or/pulp)** — WaSHI の直感的な代数モデリング API 設計に大きな着想を与えました。
240
-
241
- ---
242
-
243
- ## 📄 ライセンス
244
-
245
- - **`@ohtaman/washi`**: [MIT ライセンス](./LICENSE)
246
- - **同梱・外部ソルバー**: HiGHS (MIT)、Pumpkin (MIT)、Z3 (MIT)、GLPK (GPL-3.0)。詳細は [THIRD_PARTY_LICENSES.md](./THIRD_PARTY_LICENSES.md) を参照してください。
package/README.zh-CN.md DELETED
@@ -1,246 +0,0 @@
1
- <div align="center">
2
- <picture>
3
- <source media="(prefers-color-scheme: dark)" srcset="./assets/washi-header-dark.png">
4
- <source media="(prefers-color-scheme: light)" srcset="./assets/washi-header-light.png">
5
- <img alt="WaSHI - TypeScript 数理优化建模器" src="./assets/washi-header-light.png" width="420" />
6
- </picture>
7
- <p><strong>TypeScript 数理优化建模器</strong></p>
8
- <p>
9
- <em>线性规划 (LP) • 混合整数规划 (MIP) • 凸二次规划 (QP) • 约束规划 (CP) • SMT逻辑约束与冲突诊断</em>
10
- </p>
11
- <p>
12
- <a href="./README.md">English</a> •
13
- <a href="./README.ja.md">日本語</a> •
14
- <a href="./README.zh-CN.md">简体中文</a>
15
- </p>
16
- <p>
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
- <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
- <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/?lang=zh"><img src="https://img.shields.io/badge/demo-playground-brightgreen" alt="live demo" /></a>
21
- <a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="license" /></a>
22
- </p>
23
- </div>
24
-
25
- ---
26
-
27
- **WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) 是面向 TypeScript / JavaScript 的数理优化与约束编程代数建模器,受到 Python **PuLP** 的启发。你可以在应用代码中定义变量、目标函数和约束,并在 Node.js 或浏览器本地直接使用内置的 **HiGHS**(默认)与 **Pumpkin**(`{ solver: "pumpkin" }`),或按需加载 **Z3**、**GLPK** 插件进行求解。
28
-
29
- ## ✨ 核心特性
30
-
31
- - **直观的代数语法**:通过 `` expr`30 * ${x} + 50 * ${y} <= 40` `` 与求和、点积(`sum`, `dot`)清晰编写公式与约束。
32
- - **跨 Node.js 与浏览器本地运行**:基于 WebAssembly,无需单独部署 Python 服务或本地编译 C/C++。
33
- - **求解器无关**:内置零外部依赖的 **HiGHS**(LP/MIP/QP)与 **Pumpkin**(CP),并支持按需加载 **Z3**、**GLPK** 插件或自定义求解器适配器。
34
- - **可满足性判定与冲突诊断**:支持逻辑与算术约束的可满足性判定,并在模型不可行时定位矛盾约束。
35
- - **大规模分解算法**:内置列生成法与 Benders 分解支持。
36
-
37
- ## 📚 文档与链接
38
-
39
- - **[在线文档](https://washi.ohtaman.dev/zh/)**:建模指南、求解器说明与运行环境配置
40
- - **[案例展示](https://washi.ohtaman.dev/zh/showcase/) · [浏览器演示](https://washi.ohtaman.dev/demo/?lang=zh) · [数理优化 N 题训练](https://washi.ohtaman.dev/exercises/?lang=zh)**:在线体验交互式应用、浏览器建模演练场与 N 题实战训练营
41
- - **[示例目录](https://washi.ohtaman.dev/zh/examples/)**:各类问题的建模示例与可运行源码([`examples/`](examples/README.md))
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
-
44
- ---
45
-
46
- ## 📦 安装与快速开始
47
-
48
- ```bash
49
- npm install @ohtaman/washi
50
- # HiGHS (LP/MIP/QP, 默认) 与 Pumpkin (CP, { solver: "pumpkin" }) 均已内置打包,无需额外依赖或插件导入
51
-
52
- # 可选 peer-dependency 求解器插件
53
- npm install z3-solver # 用于 SMT 逻辑与包含连续变量的精确冲突诊断
54
- npm install glpk.js # 用于 GLPK 求解器 (GPL-3.0)
55
-
56
- # 可选:为 AI 编程助手(Claude Code, Cursor, Codex 等)安装建模技能
57
- npx skills add ohtaman/washi
58
- ```
59
-
60
- ```ts
61
- import { Model, expr, maximize } from "@ohtaman/washi";
62
-
63
- const m = new Model("木工产品利润最大化");
64
- const x = m.integer("桌子", { lb: 0 });
65
- const y = m.integer("椅子", { lb: 0 });
66
-
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`, "劳动力上限");
70
-
71
- await m.solve();
72
- console.log(`生产计划: x=${x.value}, y=${y.value} (最大利润: $${m.objectiveValue})`);
73
- ```
74
-
75
- ---
76
-
77
- ## ⚙️ 求解器概览
78
-
79
- | 求解器 | 许可证 | 支持问题类型 | 主要用途 | 引入方式 |
80
- | :--- | :--- | :--- | :--- | :--- |
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
- | **[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"` |
85
- | **Mock** | MIT | — | 单元与集成测试模拟响应 | 内置 (`MockSolver`) |
86
-
87
- 内置的 HiGHS(默认)与 Pumpkin(`{ solver: "pumpkin" }`)可直接切换而无需额外导入;若使用可选插件 `{ solver: "z3" }` 或 `{ solver: "glpk" }`,请先导入对应插件模块。各求解器专属类与配置函数(如 `HighsSolver`、`setHighsWasmUrl`、`PumpkinSolver`、`setPumpkinWasmUrl` 等)均位于 `@ohtaman/washi/solvers/{highs,pumpkin,z3,glpk}`。
88
-
89
- ---
90
-
91
- ## 🚀 常用用法示例
92
-
93
- ### 1. 求和、点积(`sum` / `dot`)与条件约束
94
-
95
- 使用 `dot` / `sum` 组合线性表达式,并通过 `m.indicator()` 表达条件规则:
96
-
97
- ```ts
98
- import { Model, expr, minimize } from "@ohtaman/washi";
99
-
100
- const m = new Model("TransportPlanning");
101
- const factories = ["Tokyo", "Osaka"];
102
- const stores = ["StoreA", "StoreB"];
103
- const costs = {
104
- Tokyo: { StoreA: 4, StoreB: 7 },
105
- Osaka: { StoreA: 8, StoreB: 3 },
106
- };
107
-
108
- const open = m.binary(factories);
109
- const ship = m.continuous(factories, stores, { lb: 0, ub: 500 });
110
-
111
- // 若东京工厂关闭 (open["Tokyo"] == 0),从东京工厂发出的总运输量必须为 0
112
- m.indicator(open["Tokyo"], expr`sum(${ship["Tokyo"]}) <= 0`, { activeValue: 0 });
113
- m.constraint(expr`${ship["Tokyo"]["StoreA"]} + ${ship["Osaka"]["StoreA"]} >= 100`, "demand_A");
114
-
115
- m.objective(minimize(expr`dot(${costs}, ${ship})`));
116
- await m.solve();
117
-
118
- console.log("Tokyo -> StoreA:", ship["Tokyo"]["StoreA"].value);
119
- ```
120
-
121
- ### 2. 凸二次规划 (QP)
122
-
123
- 在线性约束下最小化二次目标函数:
124
-
125
- ```ts
126
- import { Model, expr, minimize } from "@ohtaman/washi";
127
-
128
- const m = new Model("PortfolioQP");
129
- const x = m.continuous("tech", { lb: 0, ub: 1 });
130
- const y = m.continuous("bonds", { lb: 0, ub: 1 });
131
-
132
- m.constraint(expr`${x} + ${y} == 1`, "budget");
133
- m.constraint(expr`0.14 * ${x} + 0.04 * ${y} >= 0.08`, "min_return");
134
- m.objective(minimize(expr`0.04 * ${x}^2 + 0.005 * ${y}^2`));
135
-
136
- await m.solve();
137
- console.log(`Tech: ${x.value?.toFixed(2)}, Bonds: ${y.value?.toFixed(2)}`);
138
- ```
139
-
140
- ### 3. 约束规划与无重叠排程 (Pumpkin)
141
-
142
- 使用内置的 **Pumpkin**(`{ solver: "pumpkin" }`)求解有界整数调度与 CP 全局约束(`disjoint`、`distinct`、`cumulative`、`allowed`),无需任何额外依赖或导入:
143
-
144
- ```ts
145
- import { Model, expr, disjoint, distinct, minimize } from "@ohtaman/washi";
146
-
147
- const m = new Model("WorkshopCP", { solver: "pumpkin" });
148
- const start = m.integer(["cut", "weld", "paint"] as const, { lb: 0, ub: 20, prefix: "start" });
149
- const bench = m.integer(["cut", "weld", "paint"] as const, { lb: 1, ub: 3, prefix: "bench" });
150
-
151
- m.constraint(
152
- disjoint([
153
- { start: start.cut, duration: 4 },
154
- { start: start.weld, duration: 3 },
155
- { start: start.paint, duration: 2 },
156
- ]),
157
- "single_line"
158
- );
159
- m.constraint(expr`${start.cut} + 4 <= ${start.weld}`, "cut_before_weld");
160
- m.constraint(expr`${start.weld} + 3 <= ${start.paint}`, "weld_before_paint");
161
- m.constraint(distinct(bench), "unique_benches");
162
-
163
- m.objective(minimize(expr`${start.paint} + 2`));
164
- await m.solve();
165
- console.log(`Makespan: ${m.objectiveValue}h (paint starts at ${start.paint.value}h)`);
166
- ```
167
-
168
- ### 4. 逻辑规则与冲突诊断 (`m.check`)
169
-
170
- 表达逻辑蕴含规则并排查不可行原因:
171
- - **HiGHS(默认)**:定位松弛后可恢复可行性的约束集合(`res.conflicts`)。
172
- - **Pumpkin(内置)**:为有界整数与布尔模型提取精确的**不可满足核心**(`res.unsatCore` / `res.conflicts`)。
173
- - **Z3**:提取包含连续变量与有理数算术的精确 **SMT 不可满足核心**(`res.unsatCore` / `res.conflicts`)。
174
-
175
- ```ts
176
- import { Model, implies, expr } from "@ohtaman/washi";
177
- // 传入 { solver: "pumpkin" } 即可直接提取有界整数/布尔精确 unsatCore(无需额外导入)
178
- // import "@ohtaman/washi/solvers/z3"; // 可选:支持含连续变量的精确 SMT unsatCore
179
-
180
- const m = new Model("StaffingRules");
181
- const engineers = m.integer("engineers", { lb: 0, ub: 20 });
182
- const budget = m.continuous("budget", { lb: 0, ub: 100000 });
183
- const rush = m.bool("rush");
184
-
185
- m.constraint(expr`8000 * ${engineers} <= ${budget}`, "budget_limit");
186
- m.constraint(rush, "rush_required");
187
- m.constraint(implies(rush, expr`${engineers} >= 8`), "rush_staffing");
188
- m.constraint(expr`${budget} <= 50000`, "budget_cap"); // 冲突: 8人 * $8,000 > $50,000
189
- m.constraint(expr`${engineers} >= 1`, "min_staff"); // 无关规则
190
-
191
- const res = await m.check(); // 或 await m.check({ solver: "z3" })
192
- console.log(res.status); // "Unsat"
193
- console.log(res.conflicts); // HiGHS: ["rush_required"]
194
- ```
195
-
196
- ---
197
-
198
- ## 🌐 浏览器与 Web Worker 使用指南
199
-
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。
202
-
203
- ```html
204
- <!-- 浏览器原生 ESM(同时包含 HiGHS 与 Pumpkin) -->
205
- <script type="module">
206
- import { Model } from "./washi/washi.js";
207
- // 可选求解器插件:
208
- // import "./washi/solvers/glpk.js"; // 可选 GLPK 插件
209
- // import "./washi/solvers/z3.js"; // 可选 Z3 插件(见下方说明)
210
- const m = new Model();
211
- await m.solve();
212
- </script>
213
-
214
- <!-- Script 标签 / CodePen (挂载全局变量 Washi,同时包含 HiGHS 与 Pumpkin) -->
215
- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/washi.min.js"></script>
216
- <!-- 可选求解器插件脚本(自动注册到 window.Washi): -->
217
- <!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/glpk.min.js"></script> -->
218
- ```
219
-
220
- > [!NOTE]
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** 均无需跨源隔离响应头即可运行。
222
-
223
- ---
224
-
225
- ## 🤝 参与开发与贡献
226
-
227
- 关于本地开发、运行测试与基准测试、重新构建 WebAssembly 资源以及发布流程,请参阅 [CONTRIBUTING.md](./CONTRIBUTING.md)。
228
-
229
- ---
230
-
231
- ## 🙏 致谢
232
-
233
- WaSHI 的诞生离不开数理优化与自动推理开源社区的卓越工作:
234
-
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))。
236
- - **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** — 由代尔夫特理工大学(TU Delft)ConSol Lab 使用 Rust 开发的惰性子句生成(Lazy Clause Generation, LCG)约束规划求解器,驱动了 WaSHI 内置的 CP 与 `unsatCore` 引擎。
237
- - **[Z3 Theorem Prover](https://github.com/Z3Prover/z3)**([`z3-solver`](https://www.npmjs.com/package/z3-solver))— 由 Microsoft Research 研发,驱动了 WaSHI 可选的 SMT 可满足性判定与精确 `unsatCore` 冲突诊断插件。
238
- - **[GLPK](https://www.gnu.org/software/glpk/) & [`glpk.js`](https://github.com/jvail/glpk.js)** — 驱动了 WaSHI 可选的 GPL-3.0 LP / MIP 求解器插件。
239
- - **[PuLP](https://github.com/coin-or/pulp)** — 启发了 WaSHI 声明式代数建模 API 的设计。
240
-
241
- ---
242
-
243
- ## 📄 许可证
244
-
245
- - **`@ohtaman/washi`**: [MIT 许可证](./LICENSE)
246
- - **内置与可选引擎**: HiGHS (MIT)、Pumpkin (MIT)、Z3 (MIT)、GLPK (GPL-3.0)。完整许可说明请参阅 [THIRD_PARTY_LICENSES.md](./THIRD_PARTY_LICENSES.md)。