@ohtaman/washi 0.7.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.
Files changed (162) hide show
  1. package/README.ja.md +60 -23
  2. package/README.md +59 -22
  3. package/README.zh-CN.md +62 -25
  4. package/THIRD_PARTY_LICENSES.md +34 -1
  5. package/dist/browser/solvers/glpk.js +289 -238
  6. package/dist/browser/solvers/glpk.min.js +1 -1
  7. package/dist/browser/solvers/highs-__vite-browser-external-Dn-83hnF.js +7 -0
  8. package/dist/browser/solvers/highs-browser-runtime-0Bgq5ksG.js +2021 -0
  9. package/dist/browser/{loader-DewlSho8.js → solvers/highs-loader-BLY3wzDH.js} +190 -149
  10. package/dist/browser/solvers/highs-worker.js +54 -0
  11. package/dist/browser/solvers/highs.js +1414 -0
  12. package/dist/browser/solvers/highs.wasm +0 -0
  13. package/dist/browser/solvers/pumpkin-_washi-pumpkin-node-runtime-CEKUDK6d.js +9 -0
  14. package/dist/browser/solvers/pumpkin-loader-CvdaKxf4.js +320 -0
  15. package/dist/browser/solvers/pumpkin-worker.js +45 -0
  16. package/dist/browser/solvers/pumpkin.js +1777 -0
  17. package/dist/browser/solvers/pumpkin.wasm +0 -0
  18. package/dist/browser/solvers/pumpkin.wasm.LICENSE +21 -0
  19. package/dist/browser/solvers/z3.js +1600 -1335
  20. package/dist/browser/solvers/z3.min.js +2 -2
  21. package/dist/browser/washi.js +3313 -1699
  22. package/dist/browser/washi.min.js +5 -3
  23. package/dist/lib/solvers/__vite-browser-external-oLchLuMx.js +7 -0
  24. package/dist/lib/solvers/glpk.js +174 -132
  25. package/dist/lib/solvers/highs-browser-runtime.js +2413 -0
  26. package/dist/lib/{highs-node-runtime.js → solvers/highs-node-runtime.js} +1 -1
  27. package/dist/lib/solvers/highs-runtime.js +16 -0
  28. package/dist/lib/solvers/highs-worker.js +54 -0
  29. package/dist/lib/solvers/highs.js +410 -0
  30. package/dist/lib/solvers/highs.wasm +0 -0
  31. package/dist/lib/{loader-BZUQNvh4.js → solvers/loader-CDpPXN_F.js} +138 -116
  32. package/dist/lib/solvers/loader-Ow74Fa1B.js +311 -0
  33. package/dist/lib/solvers/lp-writer-CLScMFbS.js +115 -0
  34. package/dist/lib/solvers/pumpkin-assets.js +1 -0
  35. package/dist/lib/solvers/pumpkin-node-runtime.js +15 -0
  36. package/dist/lib/solvers/pumpkin-worker-factory.js +1 -0
  37. package/dist/lib/solvers/pumpkin-worker.js +45 -0
  38. package/dist/lib/solvers/pumpkin.js +868 -0
  39. package/dist/lib/solvers/pumpkin.wasm +0 -0
  40. package/dist/lib/solvers/pumpkin.wasm.LICENSE +21 -0
  41. package/dist/lib/solvers/registry-CrYRRk9q.js +907 -0
  42. package/dist/lib/solvers/rolldown-runtime-DtPi1Y-2.js +13 -0
  43. package/dist/lib/solvers/types-BGqPkxwu.js +12 -0
  44. package/dist/lib/solvers/z3.js +489 -307
  45. package/dist/lib/washi.js +3905 -1410
  46. package/dist/types/decomposition/benders.d.ts.map +1 -1
  47. package/dist/types/index.d.ts +4 -5
  48. package/dist/types/index.d.ts.map +1 -1
  49. package/dist/types/modeler/boolean-expr.d.ts +137 -29
  50. package/dist/types/modeler/boolean-expr.d.ts.map +1 -1
  51. package/dist/types/modeler/constraint.d.ts +40 -4
  52. package/dist/types/modeler/constraint.d.ts.map +1 -1
  53. package/dist/types/modeler/expression.d.ts +129 -2
  54. package/dist/types/modeler/expression.d.ts.map +1 -1
  55. package/dist/types/modeler/index.d.ts +4 -6
  56. package/dist/types/modeler/index.d.ts.map +1 -1
  57. package/dist/types/modeler/linearizer.d.ts +11 -2
  58. package/dist/types/modeler/linearizer.d.ts.map +1 -1
  59. package/dist/types/modeler/lp-writer.d.ts.map +1 -1
  60. package/dist/types/modeler/model.d.ts +86 -126
  61. package/dist/types/modeler/model.d.ts.map +1 -1
  62. package/dist/types/modeler/parser.d.ts.map +1 -1
  63. package/dist/types/modeler/quad-expr.d.ts +8 -2
  64. package/dist/types/modeler/quad-expr.d.ts.map +1 -1
  65. package/dist/types/modeler/solution-validator.d.ts +12 -12
  66. package/dist/types/modeler/solution-validator.d.ts.map +1 -1
  67. package/dist/types/modeler/solvers/glpk/loader.d.ts +4 -0
  68. package/dist/types/modeler/solvers/glpk/loader.d.ts.map +1 -1
  69. package/dist/types/modeler/solvers/glpk/solver.d.ts +2 -2
  70. package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
  71. package/dist/types/modeler/solvers/highs/driver.d.ts.map +1 -1
  72. package/dist/types/modeler/solvers/highs/loader.d.ts +8 -6
  73. package/dist/types/modeler/solvers/highs/loader.d.ts.map +1 -1
  74. package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
  75. package/dist/types/modeler/solvers/highs/worker-client.d.ts +16 -0
  76. package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
  77. package/dist/types/modeler/solvers/index.d.ts +2 -1
  78. package/dist/types/modeler/solvers/index.d.ts.map +1 -1
  79. package/dist/types/modeler/solvers/mock.d.ts +2 -3
  80. package/dist/types/modeler/solvers/mock.d.ts.map +1 -1
  81. package/dist/types/modeler/solvers/pumpkin/assets.d.ts +2 -0
  82. package/dist/types/modeler/solvers/pumpkin/assets.d.ts.map +1 -0
  83. package/dist/types/modeler/solvers/pumpkin/index.d.ts +6 -0
  84. package/dist/types/modeler/solvers/pumpkin/index.d.ts.map +1 -0
  85. package/dist/types/modeler/solvers/pumpkin/loader.d.ts +40 -0
  86. package/dist/types/modeler/solvers/pumpkin/loader.d.ts.map +1 -0
  87. package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts +3 -0
  88. package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts.map +1 -0
  89. package/dist/types/modeler/solvers/pumpkin/solver.d.ts +23 -0
  90. package/dist/types/modeler/solvers/pumpkin/solver.d.ts.map +1 -0
  91. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts +74 -0
  92. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts.map +1 -0
  93. package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts +3 -0
  94. package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts.map +1 -0
  95. package/dist/types/modeler/solvers/pumpkin/worker.d.ts +7 -0
  96. package/dist/types/modeler/solvers/pumpkin/worker.d.ts.map +1 -0
  97. package/dist/types/modeler/solvers/pumpkin.d.ts +2 -0
  98. package/dist/types/modeler/solvers/pumpkin.d.ts.map +1 -0
  99. package/dist/types/modeler/solvers/types.d.ts +7 -9
  100. package/dist/types/modeler/solvers/types.d.ts.map +1 -1
  101. package/dist/types/modeler/solvers/z3/loader.d.ts +4 -0
  102. package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
  103. package/dist/types/modeler/solvers/z3/solver.d.ts +2 -15
  104. package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -1
  105. package/dist/types/modeler/types.d.ts +12 -15
  106. package/dist/types/modeler/types.d.ts.map +1 -1
  107. package/dist/types/modeler/validation.d.ts +26 -2
  108. package/dist/types/modeler/validation.d.ts.map +1 -1
  109. package/dist/types/modeler/variable.d.ts +9 -5
  110. package/dist/types/modeler/variable.d.ts.map +1 -1
  111. package/docs/examples/diet-sensitivity.md +33 -14
  112. package/docs/examples/ecommerce-coupons.md +17 -9
  113. package/docs/examples/index.md +36 -27
  114. package/docs/examples/knapsack.md +11 -5
  115. package/docs/examples/portfolio-qp.md +21 -8
  116. package/docs/examples/production.md +10 -5
  117. package/docs/examples/project-scheduling.md +119 -0
  118. package/docs/examples/shift-scheduling.md +29 -18
  119. package/docs/examples/smt-security.md +27 -11
  120. package/docs/examples/transportation.md +23 -13
  121. package/docs/examples/traveling-salesperson.md +34 -22
  122. package/docs/examples/unsat-core.md +27 -14
  123. package/docs/examples/vehicle-routing.md +74 -28
  124. package/docs/getting-started/ai-agents.md +190 -82
  125. package/docs/getting-started/coding-agents.md +177 -0
  126. package/docs/getting-started/cross-origin.md +27 -14
  127. package/docs/getting-started/index.md +49 -43
  128. package/docs/getting-started/runtimes.md +94 -40
  129. package/docs/guide/constraint-programming.md +171 -0
  130. package/docs/guide/constraints.md +115 -33
  131. package/docs/guide/decomposition.md +118 -88
  132. package/docs/guide/expressions.md +106 -43
  133. package/docs/guide/formulation-tips.md +47 -28
  134. package/docs/guide/objectives.md +102 -75
  135. package/docs/guide/unsat-core.md +62 -50
  136. package/docs/guide/variables.md +81 -35
  137. package/docs/solvers/custom-solver.md +163 -122
  138. package/docs/solvers/glpk.md +58 -17
  139. package/docs/solvers/highs.md +124 -57
  140. package/docs/solvers/index.md +33 -20
  141. package/docs/solvers/pumpkin.md +171 -0
  142. package/docs/solvers/z3.md +63 -25
  143. package/llms-full.txt +2232 -932
  144. package/llms.txt +144 -91
  145. package/package.json +55 -19
  146. package/skills/washi/SKILL.md +107 -34
  147. package/dist/browser/_washi-node-only-BvRk9kiK.js +0 -0
  148. package/dist/browser/browser-runtime-TLCY0hkc.js +0 -1793
  149. package/dist/browser/highs-worker.js +0 -39
  150. package/dist/browser/highs.wasm +0 -0
  151. package/dist/lib/_washi-node-only-BvRk9kiK.js +0 -0
  152. package/dist/lib/highs-browser-runtime.js +0 -2185
  153. package/dist/lib/highs-runtime.js +0 -2
  154. package/dist/lib/highs-worker.js +0 -39
  155. package/dist/lib/highs.wasm +0 -0
  156. package/dist/lib/registry-D7TZ3Wh_.js +0 -1034
  157. package/docs/ja/getting-started/ai-agents.md +0 -280
  158. package/docs/zh/getting-started/ai-agents.md +0 -280
  159. /package/dist/browser/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
  160. /package/dist/lib/{highs-assets.js → solvers/highs-assets.js} +0 -0
  161. /package/dist/lib/{highs-worker-factory.js → solvers/highs-worker-factory.js} +0 -0
  162. /package/dist/lib/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
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論理制約 &amp; 矛盾診断</em>
9
+ <em>線形計画 (LP) • 混合整数計画 (MIP) • 凸二次計画 (QP) • 制約プログラミング (CP) • SMT論理制約 &amp; 矛盾診断</em>
10
10
  </p>
11
11
  <p>
12
12
  <a href="./README.md">English</a> •
@@ -17,29 +17,29 @@
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/"><img src="https://img.shields.io/badge/demo-playground-brightgreen" alt="live demo" /></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
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 やブラウザ上で **HiGHS**(標準)・**Z3**・**GLPK** を使ってそのまま求解できます。
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** に加え、オプションの **Z3**・**GLPK** や独自ソルバーへ切り替えられます。
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
- - **[AIエージェント向けガイド](docs/ja/getting-started/ai-agents.md) · [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 コーディングエージェント向けのリファレンス・スキル定義・機械可読ドキュメント
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, { solver: "pumpkin" }) は追加依存・追加インポートなしでそのまま使えます
50
51
 
51
- # オプションのソルバープラグイン
52
- npm install z3-solver # SMT 論理制約・Unsat Core 診断を使う場合
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
- | **[Z3](https://github.com/Z3Prover/z3)** | MIT | SMT, SAT, 論理, MIP | 論理ルール・充足判定・厳密な `unsatCore` | `import "@ohtaman/washi/solvers/z3"` |
82
- | **[GLPK](https://www.gnu.org/software/glpk/)** | GPL-3.0 | LP, MIP | 線形・混合整数最適化 | `import "@ohtaman/washi/solvers/glpk"` |
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"` |
83
85
  | **Mock** | MIT | — | テスト用の決定論的な模擬応答 | 標準搭載 (`MockSolver`) |
84
86
 
85
- プラグインを import した上で、`new Model(...)`・`m.solve(...)`・`m.check(...)` に `{ solver: "z3" }` または `{ solver: "glpk" }` を渡して切り替えます。
87
+ 同梱の HiGHS(既定)と Pumpkin(`{ solver: "pumpkin" }`)は追加インポートなしでそのまま切り替えられます。オプションの `{ solver: "z3" }`・`{ solver: "glpk" }` は対応プラグインを import した上で指定します。なお、ソルバー固有のクラスや WASM 設定関数(`HighsSolver`, `setHighsWasmUrl`, `PumpkinSolver`, `setPumpkinWasmUrl` 等)は `@ohtaman/washi/solvers/{highs,pumpkin,z3,glpk}` に配置されています。
86
88
 
87
89
  ---
88
90
 
@@ -135,15 +137,45 @@ await m.solve();
135
137
  console.log(`Tech: ${x.value?.toFixed(2)}, Bonds: ${y.value?.toFixed(2)}`);
136
138
  ```
137
139
 
138
- ### 3. SMT 論理ルール & 矛盾診断 (`m.check`)
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`)
139
169
 
140
170
  論理条件(`m.bool`, `implies`)を含むモデルの充足可能性を判定し、矛盾時の原因制約を特定します:
141
- - **HiGHS(標準)**: 緩和すれば実行可能になる**修復集合**(`res.conflicts`)を特定します。
142
- - **Z3**: 相互に矛盾している**充足不能コア**(`res.unsatCore` / `res.conflicts`)を抽出します。
171
+ - **HiGHS(標準)**: 緩和すれば実行可能になる制約集合(`res.conflicts`)を特定します。
172
+ - **Pumpkin(同梱)**: 有界整数・真偽値モデルに対して、厳密な**充足不能コア**(`res.unsatCore` / `res.conflicts`)を抽出します。
173
+ - **Z3**: 連続変数・実数演算を含む厳密な SMT **充足不能コア**(`res.unsatCore` / `res.conflicts`)を抽出します。
143
174
 
144
175
  ```ts
145
176
  import { Model, implies, expr } from "@ohtaman/washi";
146
- // import "@ohtaman/washi/solvers/z3"; // 厳密な SMT unsatCore を抽出する場合
177
+ // { solver: "pumpkin" } なら追加インポートなしで有界整数・真偽値の厳密 unsatCore を抽出
178
+ // import "@ohtaman/washi/solvers/z3"; // Continuous 変数を含む厳密 SMT unsatCore(オプション)
147
179
 
148
180
  const m = new Model("StaffingRules");
149
181
  const engineers = m.integer("engineers", { lb: 0, ub: 20 });
@@ -165,24 +197,28 @@ console.log(res.conflicts); // HiGHS: ["rush_required"]
165
197
 
166
198
  ## 🌐 ブラウザ & Web Worker での利用方法
167
199
 
168
- - **バンドラー (Vite / webpack 5)**: `import { Model } from "@ohtaman/washi"` でそのまま動作します。ブラウザでは標準で Web Worker 上で実行されます(メインスレッドで実行する場合は `{ useWorker: false }` を指定)。
169
- - **単体 ESM / script タグ / CDN**: `dist/browser/` 一式(`highs.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 の両方を内蔵しています。
170
202
 
171
203
  ```html
172
- <!-- ブラウザ ESM -->
204
+ <!-- ブラウザ ESM(HiGHS・Pumpkin の両方を利用可能) -->
173
205
  <script type="module">
174
206
  import { Model } from "./washi/washi.js";
175
- // オプションプラグイン: import "./washi/solvers/glpk.js" または "./washi/solvers/z3.js"
207
+ // オプションプラグイン:
208
+ // import "./washi/solvers/glpk.js"; // オプション GLPK プラグイン
209
+ // import "./washi/solvers/z3.js"; // オプション Z3 プラグイン(下の注記を参照)
176
210
  const m = new Model();
177
211
  await m.solve();
178
212
  </script>
179
213
 
180
- <!-- script タグ / CodePen (グローバル Washi を公開) -->
214
+ <!-- script タグ / CodePen (グローバル Washi を公開、HiGHS・Pumpkin 同梱) -->
181
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> -->
182
218
  ```
183
219
 
184
220
  > [!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) を参照してください。
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** はこれらのヘッダーなしで動作します。
186
222
 
187
223
  ---
188
224
 
@@ -197,6 +233,7 @@ console.log(res.conflicts); // HiGHS: ["rush_required"]
197
233
  WaSHI は、数理最適化および自動推論分野の素晴らしいオープンソースソフトウェアの上に成り立っています:
198
234
 
199
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` エンジンを支えています。
200
237
  - **[Z3 Theorem Prover](https://github.com/Z3Prover/z3)**([`z3-solver`](https://www.npmjs.com/package/z3-solver))— Microsoft Research により開発された SMT ソルバーであり、オプションの論理充足判定および `unsatCore` 矛盾診断プラグインを支えています。
201
238
  - **[GLPK](https://www.gnu.org/software/glpk/) & [`glpk.js`](https://github.com/jvail/glpk.js)** — オプションの GPL-3.0 LP / MIP ソルバープラグインを支えています。
202
239
  - **[PuLP](https://github.com/coin-or/pulp)** — WaSHI の直感的な代数モデリング API 設計に大きな着想を与えました。
@@ -206,4 +243,4 @@ WaSHI は、数理最適化および自動推論分野の素晴らしいオー
206
243
  ## 📄 ライセンス
207
244
 
208
245
  - **`@ohtaman/washi`**: [MIT ライセンス](./LICENSE)
209
- - **同梱・外部ソルバー**: HiGHS (MIT)、Z3 (MIT)、GLPK (GPL-3.0)。詳細は [THIRD_PARTY_LICENSES.md](./THIRD_PARTY_LICENSES.md) を参照してください。
246
+ - **同梱・外部ソルバー**: 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 &amp; Conflict Diagnosis</em>
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
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**, or **GLPK**.
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 built-in **HiGHS**, optional **Z3** and **GLPK** plugins, or custom solver adapters.
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
 
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/) & [Browser Playground](https://washi.ohtaman.dev/demo/)**: Try live optimization apps and edit models in the browser
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
- - **[AI Agent Guide](docs/getting-started/ai-agents.md) · [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)**: Compact reference, workflow skill, and machine-readable docs for AI coding agents
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, default) and Pumpkin (CP, { solver: "pumpkin" }) are bundled with zero extra dependencies or plugin imports
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
- | **[Z3](https://github.com/Z3Prover/z3)** | MIT | SMT, SAT, Logic, MIP | Logical rules, satisfiability & exact `unsatCore` | `import "@ohtaman/washi/solvers/z3"` |
82
- | **[GLPK](https://www.gnu.org/software/glpk/)** | GPL-3.0 | LP, MIP | Linear & mixed-integer optimization | `import "@ohtaman/washi/solvers/glpk"` |
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
+ | **[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: "z3" }` or `{ solver: "glpk" }` to `new Model(...)`, `m.solve(...)`, or `m.check(...)` after importing the plugin.
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}`.
86
88
 
87
89
  ---
88
90
 
@@ -135,15 +137,45 @@ await m.solve();
135
137
  console.log(`Tech: ${x.value?.toFixed(2)}, Bonds: ${y.value?.toFixed(2)}`);
136
138
  ```
137
139
 
138
- ### 3. SMT Logic & Conflict Diagnosis (`m.check`)
140
+ ### 3. Constraint Programming & Disjunctive Scheduling (Pumpkin)
141
+
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
+
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. Logic & Conflict Diagnosis (`m.check`)
139
169
 
140
170
  Express logical implications and diagnose why a model is infeasible:
141
- - **HiGHS (default)**: Isolates an **elastic repair set** (`res.conflicts`)—constraints whose relaxation restores feasibility.
142
- - **Z3**: Extracts an **unsatisfiable core** (`res.unsatCore` / `res.conflicts`)—a mutually contradictory subset of constraints.
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.
173
+ - **Z3**: Extracts an exact SMT **unsatisfiable core** (`res.unsatCore` / `res.conflicts`) including continuous and rational arithmetic.
143
174
 
144
175
  ```ts
145
176
  import { Model, implies, expr } from "@ohtaman/washi";
146
- // import "@ohtaman/washi/solvers/z3"; // Optional: for exact SMT unsatCore
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
147
179
 
148
180
  const m = new Model("StaffingRules");
149
181
  const engineers = m.integer("engineers", { lb: 0, ub: 20 });
@@ -165,24 +197,28 @@ console.log(res.conflicts); // HiGHS: ["rush_required"]
165
197
 
166
198
  ## 🌐 Browser & Web Worker Usage
167
199
 
168
- - **Bundlers (Vite / webpack 5)**: `import { Model } from "@ohtaman/washi"` works out of the box. Solves run in a Web Worker by default; pass `{ useWorker: false }` for main-thread execution.
169
- - **Standalone ESM / Script Tag / CDN**: Serve `dist/browser/` (including `highs.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.
170
202
 
171
203
  ```html
172
- <!-- Browser ESM -->
204
+ <!-- Browser ESM (includes both HiGHS and Pumpkin) -->
173
205
  <script type="module">
174
206
  import { Model } from "./washi/washi.js";
175
- // Optional solver plugins: import "./washi/solvers/glpk.js" or "./washi/solvers/z3.js"
207
+ // Optional solver plugins:
208
+ // import "./washi/solvers/glpk.js"; // Optional GLPK plugin
209
+ // import "./washi/solvers/z3.js"; // Optional Z3 plugin (see note below)
176
210
  const m = new Model();
177
211
  await m.solve();
178
212
  </script>
179
213
 
180
- <!-- Classic Script / CodePen (exposes global Washi) -->
214
+ <!-- Classic Script / CodePen (exposes global Washi with both HiGHS and Pumpkin) -->
181
215
  <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/washi.min.js"></script>
216
+ <!-- Optional solver plugin scripts (auto-register on window.Washi): -->
217
+ <!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/glpk.min.js"></script> -->
182
218
  ```
183
219
 
184
220
  > [!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).
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.
186
222
 
187
223
  ---
188
224
 
@@ -197,6 +233,7 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md) for local development setup, running te
197
233
  WaSHI stands on the shoulders of the open-source mathematical optimization and automated reasoning communities:
198
234
 
199
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)).
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.
200
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.
201
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.
202
239
  - **[PuLP](https://github.com/coin-or/pulp)** — Inspiring WaSHI's declarative algebraic modeling ergonomics.
@@ -206,4 +243,4 @@ WaSHI stands on the shoulders of the open-source mathematical optimization and a
206
243
  ## 📄 License
207
244
 
208
245
  - **`@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.
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.
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> •
@@ -17,29 +17,29 @@
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/"><img src="https://img.shields.io/badge/demo-playground-brightgreen" alt="live demo" /></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
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 或浏览器本地使用 **HiGHS**(默认)、**Z3** 或 **GLPK** 求解。
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**,支持按需加载 **Z3**、**GLPK** 插件或自定义求解器适配器。
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
- - **[AI 编程助手快速参考](docs/zh/getting-started/ai-agents.md) · [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 编程助手的速查指南、技能定义与机器可读文档
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, { solver: "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 等)安装建模技能
@@ -64,8 +65,8 @@ const x = m.integer("桌子", { lb: 0 });
64
65
  const y = m.integer("椅子", { lb: 0 });
65
66
 
66
67
  m.objective(maximize(expr`30 * ${x} + 50 * ${y}`));
67
- m.constraint(expr`${x} + 2 * ${y} <= 40`, "wood_limit");
68
- m.constraint(expr`2 * ${x} + ${y} <= 50`, "labor_limit");
68
+ m.constraint(expr`${x} + 2 * ${y} <= 40`, "木材上限");
69
+ m.constraint(expr`2 * ${x} + ${y} <= 50`, "劳动力上限");
69
70
 
70
71
  await m.solve();
71
72
  console.log(`生产计划: x=${x.value}, y=${y.value} (最大利润: $${m.objectiveValue})`);
@@ -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
- | **[Z3](https://github.com/Z3Prover/z3)** | MIT | SMT, SAT, 逻辑, MIP | 逻辑规则、可满足性判定与精确 `unsatCore` | `import "@ohtaman/washi/solvers/z3"` |
82
- | **[GLPK](https://www.gnu.org/software/glpk/)** | GPL-3.0 | LP, MIP | 线性与混合整数规划 | `import "@ohtaman/washi/solvers/glpk"` |
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"` |
83
85
  | **Mock** | MIT | — | 单元与集成测试模拟响应 | 内置 (`MockSolver`) |
84
86
 
85
- 导入对应插件后,可在 `new Model(...)`、`m.solve(...)` 或 `m.check(...)` 中传入 `{ solver: "z3" }` 或 `{ solver: "glpk" }`。
87
+ 内置的 HiGHS(默认)与 Pumpkin(`{ solver: "pumpkin" }`)可直接切换而无需额外导入;若使用可选插件 `{ solver: "z3" }` 或 `{ solver: "glpk" }`,请先导入对应插件模块。各求解器专属类与配置函数(如 `HighsSolver`、`setHighsWasmUrl`、`PumpkinSolver`、`setPumpkinWasmUrl` 等)均位于 `@ohtaman/washi/solvers/{highs,pumpkin,z3,glpk}`。
86
88
 
87
89
  ---
88
90
 
@@ -135,15 +137,45 @@ await m.solve();
135
137
  console.log(`Tech: ${x.value?.toFixed(2)}, Bonds: ${y.value?.toFixed(2)}`);
136
138
  ```
137
139
 
138
- ### 3. SMT 逻辑规则与冲突诊断 (`m.check`)
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`)
139
169
 
140
170
  表达逻辑蕴含规则并排查不可行原因:
141
- - **HiGHS(默认)**:提取**弹性修复集合**(`res.conflicts`),即松弛后可恢复可行性的约束。
142
- - **Z3**:提取精确的 **SMT 不可满足核心**(`res.unsatCore` / `res.conflicts`),即相互矛盾的约束子集。
171
+ - **HiGHS(默认)**:定位松弛后可恢复可行性的约束集合(`res.conflicts`)。
172
+ - **Pumpkin(内置)**:为有界整数与布尔模型提取精确的**不可满足核心**(`res.unsatCore` / `res.conflicts`)。
173
+ - **Z3**:提取包含连续变量与有理数算术的精确 **SMT 不可满足核心**(`res.unsatCore` / `res.conflicts`)。
143
174
 
144
175
  ```ts
145
176
  import { Model, implies, expr } from "@ohtaman/washi";
146
- // import "@ohtaman/washi/solvers/z3"; // 可选:使用 Z3 提取精确 SMT unsatCore
177
+ // 传入 { solver: "pumpkin" } 即可直接提取有界整数/布尔精确 unsatCore(无需额外导入)
178
+ // import "@ohtaman/washi/solvers/z3"; // 可选:支持含连续变量的精确 SMT unsatCore
147
179
 
148
180
  const m = new Model("StaffingRules");
149
181
  const engineers = m.integer("engineers", { lb: 0, ub: 20 });
@@ -165,24 +197,28 @@ console.log(res.conflicts); // HiGHS: ["rush_required"]
165
197
 
166
198
  ## 🌐 浏览器与 Web Worker 使用指南
167
199
 
168
- - **打包工具 (Vite / webpack 5)**:直接 `import { Model } from "@ohtaman/washi"` 即可。浏览器默认在 Web Worker 中求解;传入 `{ useWorker: false }` 可在主线程执行。
169
- - **原生 ESM / Script 标签 / CDN**:部署 `dist/browser/` 目录(含 `highs.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。
170
202
 
171
203
  ```html
172
- <!-- 浏览器原生 ESM -->
204
+ <!-- 浏览器原生 ESM(同时包含 HiGHS 与 Pumpkin) -->
173
205
  <script type="module">
174
206
  import { Model } from "./washi/washi.js";
175
- // 可选求解器插件: import "./washi/solvers/glpk.js" 或 "./washi/solvers/z3.js"
207
+ // 可选求解器插件:
208
+ // import "./washi/solvers/glpk.js"; // 可选 GLPK 插件
209
+ // import "./washi/solvers/z3.js"; // 可选 Z3 插件(见下方说明)
176
210
  const m = new Model();
177
211
  await m.solve();
178
212
  </script>
179
213
 
180
- <!-- Script 标签 / CodePen (挂载全局变量 Washi) -->
214
+ <!-- Script 标签 / CodePen (挂载全局变量 Washi,同时包含 HiGHS 与 Pumpkin) -->
181
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> -->
182
218
  ```
183
219
 
184
220
  > [!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)。
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** 均无需跨源隔离响应头即可运行。
186
222
 
187
223
  ---
188
224
 
@@ -197,6 +233,7 @@ console.log(res.conflicts); // HiGHS: ["rush_required"]
197
233
  WaSHI 的诞生离不开数理优化与自动推理开源社区的卓越工作:
198
234
 
199
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` 引擎。
200
237
  - **[Z3 Theorem Prover](https://github.com/Z3Prover/z3)**([`z3-solver`](https://www.npmjs.com/package/z3-solver))— 由 Microsoft Research 研发,驱动了 WaSHI 可选的 SMT 可满足性判定与精确 `unsatCore` 冲突诊断插件。
201
238
  - **[GLPK](https://www.gnu.org/software/glpk/) & [`glpk.js`](https://github.com/jvail/glpk.js)** — 驱动了 WaSHI 可选的 GPL-3.0 LP / MIP 求解器插件。
202
239
  - **[PuLP](https://github.com/coin-or/pulp)** — 启发了 WaSHI 声明式代数建模 API 的设计。
@@ -206,4 +243,4 @@ WaSHI 的诞生离不开数理优化与自动推理开源社区的卓越工作
206
243
  ## 📄 许可证
207
244
 
208
245
  - **`@ohtaman/washi`**: [MIT 许可证](./LICENSE)
209
- - **内置与可选引擎**: HiGHS (MIT)、Z3 (MIT)、GLPK (GPL-3.0)。完整许可说明请参阅 [THIRD_PARTY_LICENSES.md](./THIRD_PARTY_LICENSES.md)。
246
+ - **内置与可选引擎**: HiGHS (MIT)、Pumpkin (MIT)、Z3 (MIT)、GLPK (GPL-3.0)。完整许可说明请参阅 [THIRD_PARTY_LICENSES.md](./THIRD_PARTY_LICENSES.md)。
@@ -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
+ ```