@ohtaman/washi 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +11 -11
- package/README.md +11 -11
- package/README.zh-CN.md +11 -11
- package/dist/browser/washi.js +311 -208
- package/dist/browser/washi.min.js +4 -4
- package/dist/lib/washi.js +219 -116
- package/dist/types/modeler/expression.d.ts +7 -2
- package/dist/types/modeler/expression.d.ts.map +1 -1
- package/dist/types/modeler/model.d.ts +47 -43
- package/dist/types/modeler/model.d.ts.map +1 -1
- package/dist/types/modeler/parser.d.ts +9 -8
- package/dist/types/modeler/parser.d.ts.map +1 -1
- package/dist/types/modeler/quad-expr.d.ts +3 -1
- package/dist/types/modeler/quad-expr.d.ts.map +1 -1
- package/dist/types/modeler/types.d.ts +1 -1
- package/dist/types/modeler/types.d.ts.map +1 -1
- package/dist/types/modeler/variable.d.ts +6 -0
- package/dist/types/modeler/variable.d.ts.map +1 -1
- package/package.json +2 -2
package/README.ja.md
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
27
|
-
**WaSHI
|
|
27
|
+
**WaSHI**(WebAssembly-backed, Solver-independent, High-level modeling Interface)は、Python の **PuLP** や Julia の **JuMP** に着想を得た、TypeScript / JavaScript 向けの代数モデラーです。アプリケーションのコードで変数・目的関数・数値制約や論理制約を記述できます。WaSHI はモデルの構築、ソルバー向けの変換、変数への結果の反映を担当し、最適化や充足可能性の判定は **HiGHS**・**Z3**・**GLPK** が行います。
|
|
28
28
|
|
|
29
29
|
HiGHS が標準ソルバーで、Z3 と GLPK は任意で追加するプラグインです。Node.js 用とブラウザ用の配布物に WebAssembly アセットを含みます。配信に必要な設定は[ブラウザでの利用方法](#-ブラウザ--web-worker-での利用方法)を参照してください。
|
|
30
30
|
|
|
@@ -207,10 +207,10 @@ import "@ohtaman/washi/solvers/z3";
|
|
|
207
207
|
|
|
208
208
|
const m = new Model({ name: "SmartSecurityRules" });
|
|
209
209
|
|
|
210
|
-
const isNight = m.
|
|
211
|
-
const motion = m.
|
|
212
|
-
const alarm = m.
|
|
213
|
-
const siren = m.
|
|
210
|
+
const isNight = m.bool("isNight");
|
|
211
|
+
const motion = m.bool("motion");
|
|
212
|
+
const alarm = m.bool("alarm");
|
|
213
|
+
const siren = m.bool("siren");
|
|
214
214
|
const lux = m.integer("lux", { lb: 0 });
|
|
215
215
|
|
|
216
216
|
// 論理ルール
|
|
@@ -242,7 +242,7 @@ import "@ohtaman/washi/solvers/z3";
|
|
|
242
242
|
const m = new Model({ name: "ConflictDiagnosis", solver: "z3" });
|
|
243
243
|
const engineers = m.integer("engineers", { lb: 0, ub: 20 });
|
|
244
244
|
const budget = m.continuous("budget", { lb: 0, ub: 100000 });
|
|
245
|
-
const rushDelivery = m.
|
|
245
|
+
const rushDelivery = m.bool("rushDelivery");
|
|
246
246
|
|
|
247
247
|
// ルール 1: エンジニア1人あたり $8,000
|
|
248
248
|
m.constrain(expr`8000 * ${engineers} <= ${budget}`, "budget_limit");
|
|
@@ -377,7 +377,7 @@ CDN から直接読み込む場合は、URL を `https://cdn.jsdelivr.net/npm/@o
|
|
|
377
377
|
import "./washi/solvers/glpk.js";
|
|
378
378
|
|
|
379
379
|
const model = new Model({ solver: "glpk" });
|
|
380
|
-
const x = model.
|
|
380
|
+
const x = model.continuous("x", { lb: 0, ub: 10 });
|
|
381
381
|
model.maximize(x);
|
|
382
382
|
await model.solve();
|
|
383
383
|
console.log("GLPK ステータス:", model.status);
|
|
@@ -390,7 +390,7 @@ CDN から直接読み込む場合は、URL を `https://cdn.jsdelivr.net/npm/@o
|
|
|
390
390
|
<script src="./washi/solvers/glpk.min.js"></script>
|
|
391
391
|
<script>
|
|
392
392
|
const model = new Washi.Model({ solver: "glpk" });
|
|
393
|
-
const x = model.
|
|
393
|
+
const x = model.continuous("x", { lb: 0, ub: 10 });
|
|
394
394
|
model.maximize(x);
|
|
395
395
|
model.solve().then(status => console.log("GLPK ステータス:", status));
|
|
396
396
|
</script>
|
|
@@ -447,12 +447,12 @@ WaSHI は疎結合なプラグイン方式のソルバーアーキテクチャ
|
|
|
447
447
|
| カテゴリ | サンプル | 確認できること | ソルバー |
|
|
448
448
|
| :--- | :--- | :--- | :--- |
|
|
449
449
|
| **基本モデル** | [生産計画](https://github.com/ohtaman/washi/blob/main/examples/node/01-production-planning.ts) | 整数変数、利益の最大化、資源制約 (`expr`, `c`) | HiGHS |
|
|
450
|
-
| **基本モデル** | [輸送・物流ネットワーク](https://github.com/ohtaman/washi/blob/main/examples/node/09-transportation-problem.ts) | 2次元マトリクス変数 (`
|
|
450
|
+
| **基本モデル** | [輸送・物流ネットワーク](https://github.com/ohtaman/washi/blob/main/examples/node/09-transportation-problem.ts) | 2次元マトリクス変数 (`continuous(rows, cols)`) と供給・需要バランス | HiGHS |
|
|
451
451
|
| **基本モデル** | [栄養問題と感度分析](https://github.com/ohtaman/washi/blob/main/examples/node/10-diet-sensitivity.ts) | 潜在価格 (`constr.dual`)、余剰 (`constr.slack`)、被約費用 (`var.reducedCost`) | HiGHS |
|
|
452
452
|
| **実践応用** | [スタッフのシフト作成](https://github.com/ohtaman/washi/blob/main/examples/node/11-shift-scheduling.ts) | 週間シフト最適化と、土曜日の希望休が衝突した際の原因特定 | HiGHS + Z3 |
|
|
453
|
-
| **実践応用** | [ECカートのクーポン最適適用](https://github.com/ohtaman/washi/blob/main/examples/node/12-ecommerce-coupon-optimizer.ts) | 条件付き購入金額閾値 (`
|
|
453
|
+
| **実践応用** | [ECカートのクーポン最適適用](https://github.com/ohtaman/washi/blob/main/examples/node/12-ecommerce-coupon-optimizer.ts) | 条件付き購入金額閾値 (`indicator`)、併用不可ルール、追加購入提案 | HiGHS |
|
|
454
454
|
| **実践応用** | [ポートフォリオ配分](https://github.com/ohtaman/washi/blob/main/examples/node/03-portfolio-qp.ts) | 凸二次目的関数 (`QuadExpr`) と配分の制約 | HiGHS |
|
|
455
|
-
| **論理 / SMT** | [業務ルールの検証](https://github.com/ohtaman/washi/blob/main/examples/node/04-smt-security-rules.ts) | 数値・論理制約 (`
|
|
455
|
+
| **論理 / SMT** | [業務ルールの検証](https://github.com/ohtaman/washi/blob/main/examples/node/04-smt-security-rules.ts) | 数値・論理制約 (`bool`, `implies`) の充足可能性の確認 | Z3 |
|
|
456
456
|
| **論理 / SMT** | [矛盾する制約の診断](https://github.com/ohtaman/washi/blob/main/examples/node/05-unsat-core-diagnosis.ts) | 名前付き制約と Unsat Core (`unsatCore`) | Z3 |
|
|
457
457
|
|
|
458
458
|
[公開ブラウザデモ](https://ohtaman.github.io/washi/demo/)では、モデルを編集して実行できます。ブラウザ標準 ESM、script タグ、CodePen での使い方は[配布形式のサンプル](https://github.com/ohtaman/washi/blob/main/examples/distribution/README.md)を参照してください。Z3 は Cross-Origin Isolation が必要です。詳細は上記のブラウザ要件に記載しています。
|
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
27
|
-
**WaSHI** is an algebraic modeler for TypeScript and JavaScript, inspired by Python's **PuLP** and Julia's **JuMP**. Define variables, objectives, and arithmetic or logical constraints in application code. WaSHI constructs the model, translates it for a solver adapter, and maps results back to your variables. **HiGHS**, **Z3**, and **GLPK** perform the optimization or satisfiability checks.
|
|
27
|
+
**WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) is an algebraic modeler for TypeScript and JavaScript, inspired by Python's **PuLP** and Julia's **JuMP**. Define variables, objectives, and arithmetic or logical constraints in application code. WaSHI constructs the model, translates it for a solver adapter, and maps results back to your variables. **HiGHS**, **Z3**, and **GLPK** perform the optimization or satisfiability checks.
|
|
28
28
|
|
|
29
29
|
HiGHS is the default solver; Z3 and GLPK are optional plugins. The package provides Node.js and browser distributions, including WebAssembly assets. See the [browser integration guide](#-browser--web-worker-usage) for deployment requirements.
|
|
30
30
|
|
|
@@ -207,10 +207,10 @@ import "@ohtaman/washi/solvers/z3";
|
|
|
207
207
|
|
|
208
208
|
const m = new Model({ name: "SmartSecurityRules" });
|
|
209
209
|
|
|
210
|
-
const isNight = m.
|
|
211
|
-
const motion = m.
|
|
212
|
-
const alarm = m.
|
|
213
|
-
const siren = m.
|
|
210
|
+
const isNight = m.bool("isNight");
|
|
211
|
+
const motion = m.bool("motion");
|
|
212
|
+
const alarm = m.bool("alarm");
|
|
213
|
+
const siren = m.bool("siren");
|
|
214
214
|
const lux = m.integer("lux", { lb: 0 });
|
|
215
215
|
|
|
216
216
|
// Logical rules
|
|
@@ -242,7 +242,7 @@ import "@ohtaman/washi/solvers/z3";
|
|
|
242
242
|
const m = new Model({ name: "ConflictDiagnosis", solver: "z3" });
|
|
243
243
|
const engineers = m.integer("engineers", { lb: 0, ub: 20 });
|
|
244
244
|
const budget = m.continuous("budget", { lb: 0, ub: 100000 });
|
|
245
|
-
const rushDelivery = m.
|
|
245
|
+
const rushDelivery = m.bool("rushDelivery");
|
|
246
246
|
|
|
247
247
|
// Rule 1: Each engineer costs $8,000
|
|
248
248
|
m.constrain(expr`8000 * ${engineers} <= ${budget}`, "budget_limit");
|
|
@@ -377,7 +377,7 @@ The browser distribution includes pre-bundled, standalone solver plugins under `
|
|
|
377
377
|
import "./washi/solvers/glpk.js";
|
|
378
378
|
|
|
379
379
|
const model = new Model({ solver: "glpk" });
|
|
380
|
-
const x = model.
|
|
380
|
+
const x = model.continuous("x", { lb: 0, ub: 10 });
|
|
381
381
|
model.maximize(x);
|
|
382
382
|
await model.solve();
|
|
383
383
|
console.log("GLPK status:", model.status);
|
|
@@ -390,7 +390,7 @@ The browser distribution includes pre-bundled, standalone solver plugins under `
|
|
|
390
390
|
<script src="./washi/solvers/glpk.min.js"></script>
|
|
391
391
|
<script>
|
|
392
392
|
const model = new Washi.Model({ solver: "glpk" });
|
|
393
|
-
const x = model.
|
|
393
|
+
const x = model.continuous("x", { lb: 0, ub: 10 });
|
|
394
394
|
model.maximize(x);
|
|
395
395
|
model.solve().then(status => console.log("GLPK status:", status));
|
|
396
396
|
</script>
|
|
@@ -447,12 +447,12 @@ Start with the [example gallery](https://github.com/ohtaman/washi/blob/main/exam
|
|
|
447
447
|
| Category | Example | What it demonstrates | Solver |
|
|
448
448
|
| :--- | :--- | :--- | :--- |
|
|
449
449
|
| **Fundamentals** | [Production planning](https://github.com/ohtaman/washi/blob/main/examples/node/01-production-planning.ts) | Integer variables, a profit objective, and resource constraints (`expr`, `c`) | HiGHS |
|
|
450
|
-
| **Fundamentals** | [Transportation network](https://github.com/ohtaman/washi/blob/main/examples/node/09-transportation-problem.ts) | 2D origin-destination variable matrix (`
|
|
450
|
+
| **Fundamentals** | [Transportation network](https://github.com/ohtaman/washi/blob/main/examples/node/09-transportation-problem.ts) | 2D origin-destination variable matrix (`continuous(rows, cols)`) and flow balance | HiGHS |
|
|
451
451
|
| **Fundamentals** | [Diet & sensitivity analysis](https://github.com/ohtaman/washi/blob/main/examples/node/10-diet-sensitivity.ts) | Shadow prices (`constr.dual`), surpluses (`constr.slack`), and reduced costs (`var.reducedCost`) | HiGHS |
|
|
452
452
|
| **Practical** | [Staff shift scheduling](https://github.com/ohtaman/washi/blob/main/examples/node/11-shift-scheduling.ts) | Weekly roster optimization + diagnosing conflicting Saturday vacation requests | HiGHS + Z3 |
|
|
453
|
-
| **Practical** | [E-commerce coupon optimizer](https://github.com/ohtaman/washi/blob/main/examples/node/12-ecommerce-coupon-optimizer.ts) | Conditional spend thresholds (`
|
|
453
|
+
| **Practical** | [E-commerce coupon optimizer](https://github.com/ohtaman/washi/blob/main/examples/node/12-ecommerce-coupon-optimizer.ts) | Conditional spend thresholds (`indicator`), coupon exclusivity, and add-on recommendations | HiGHS |
|
|
454
454
|
| **Practical** | [Portfolio allocation](https://github.com/ohtaman/washi/blob/main/examples/node/03-portfolio-qp.ts) | A convex quadratic objective (`QuadExpr`) with allocation constraints | HiGHS |
|
|
455
|
-
| **Logic / SMT** | [Business rule checks](https://github.com/ohtaman/washi/blob/main/examples/node/04-smt-security-rules.ts) | Arithmetic and Boolean constraints (`
|
|
455
|
+
| **Logic / SMT** | [Business rule checks](https://github.com/ohtaman/washi/blob/main/examples/node/04-smt-security-rules.ts) | Arithmetic and Boolean constraints (`bool`, `implies`) with satisfiability checking | Z3 |
|
|
456
456
|
| **Logic / SMT** | [Conflict diagnosis](https://github.com/ohtaman/washi/blob/main/examples/node/05-unsat-core-diagnosis.ts) | Named constraints and an unsatisfiable core (`unsatCore`) | Z3 |
|
|
457
457
|
|
|
458
458
|
[Open the hosted demo](https://ohtaman.github.io/washi/demo/) to edit and run models in your browser. For browser ESM, classic script tags, and CodePen, see the [distribution examples](https://github.com/ohtaman/washi/blob/main/examples/distribution/README.md). Z3 requires cross-origin isolation; see the browser requirements above.
|
package/README.zh-CN.md
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
|
|
25
25
|
---
|
|
26
26
|
|
|
27
|
-
**WaSHI** 是面向 TypeScript / JavaScript 的代数建模器,受到 Python **PuLP** 和 Julia **JuMP** 的启发。你可以在应用代码中定义变量、目标函数、算术约束和逻辑约束。WaSHI 负责构建模型、转换为求解器输入,并将结果映射回变量;优化与可满足性检查由 **HiGHS**、**Z3** 和 **GLPK** 完成。
|
|
27
|
+
**WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) 是面向 TypeScript / JavaScript 的代数建模器,受到 Python **PuLP** 和 Julia **JuMP** 的启发。你可以在应用代码中定义变量、目标函数、算术约束和逻辑约束。WaSHI 负责构建模型、转换为求解器输入,并将结果映射回变量;优化与可满足性检查由 **HiGHS**、**Z3** 和 **GLPK** 完成。
|
|
28
28
|
|
|
29
29
|
HiGHS 是默认求解器;Z3 和 GLPK 是可选插件。软件包提供 Node.js 和浏览器分发版本,并包含 WebAssembly 资源。部署要求请参阅[浏览器使用说明](#-浏览器与-web-worker-使用指南)。
|
|
30
30
|
|
|
@@ -207,10 +207,10 @@ import "@ohtaman/washi/solvers/z3";
|
|
|
207
207
|
|
|
208
208
|
const m = new Model({ name: "SmartSecurityRules" });
|
|
209
209
|
|
|
210
|
-
const isNight = m.
|
|
211
|
-
const motion = m.
|
|
212
|
-
const alarm = m.
|
|
213
|
-
const siren = m.
|
|
210
|
+
const isNight = m.bool("isNight");
|
|
211
|
+
const motion = m.bool("motion");
|
|
212
|
+
const alarm = m.bool("alarm");
|
|
213
|
+
const siren = m.bool("siren");
|
|
214
214
|
const lux = m.integer("lux", { lb: 0 });
|
|
215
215
|
|
|
216
216
|
// 规则定义
|
|
@@ -242,7 +242,7 @@ import "@ohtaman/washi/solvers/z3";
|
|
|
242
242
|
const m = new Model({ name: "ConflictDiagnosis", solver: "z3" });
|
|
243
243
|
const engineers = m.integer("engineers", { lb: 0, ub: 20 });
|
|
244
244
|
const budget = m.continuous("budget", { lb: 0, ub: 100000 });
|
|
245
|
-
const rushDelivery = m.
|
|
245
|
+
const rushDelivery = m.bool("rushDelivery");
|
|
246
246
|
|
|
247
247
|
// 规则 1: 每位工程师成本 $8,000
|
|
248
248
|
m.constrain(expr`8000 * ${engineers} <= ${budget}`, "budget_limit");
|
|
@@ -377,7 +377,7 @@ await model.solve();
|
|
|
377
377
|
import "./washi/solvers/glpk.js";
|
|
378
378
|
|
|
379
379
|
const model = new Model({ solver: "glpk" });
|
|
380
|
-
const x = model.
|
|
380
|
+
const x = model.continuous("x", { lb: 0, ub: 10 });
|
|
381
381
|
model.maximize(x);
|
|
382
382
|
await model.solve();
|
|
383
383
|
console.log("GLPK 求解状态:", model.status);
|
|
@@ -390,7 +390,7 @@ await model.solve();
|
|
|
390
390
|
<script src="./washi/solvers/glpk.min.js"></script>
|
|
391
391
|
<script>
|
|
392
392
|
const model = new Washi.Model({ solver: "glpk" });
|
|
393
|
-
const x = model.
|
|
393
|
+
const x = model.continuous("x", { lb: 0, ub: 10 });
|
|
394
394
|
model.maximize(x);
|
|
395
395
|
model.solve().then(status => console.log("GLPK 求解状态:", status));
|
|
396
396
|
</script>
|
|
@@ -447,12 +447,12 @@ WaSHI 采用完全解耦的插件式求解器架构。你可以轻松编写并
|
|
|
447
447
|
| 类别 | 示例 | 展示内容 | 求解器 |
|
|
448
448
|
| :--- | :--- | :--- | :--- |
|
|
449
449
|
| **基础模型** | [生产计划](https://github.com/ohtaman/washi/blob/main/examples/node/01-production-planning.ts) | 整数变量、利润目标与资源约束 (`expr`, `c`) | HiGHS |
|
|
450
|
-
| **基础模型** | [运输与分配网络](https://github.com/ohtaman/washi/blob/main/examples/node/09-transportation-problem.ts) | 二维矩阵变量 (`
|
|
450
|
+
| **基础模型** | [运输与分配网络](https://github.com/ohtaman/washi/blob/main/examples/node/09-transportation-problem.ts) | 二维矩阵变量 (`continuous(rows, cols)`) 与供需平衡 | HiGHS |
|
|
451
451
|
| **基础模型** | [营养问题与灵敏度分析](https://github.com/ohtaman/washi/blob/main/examples/node/10-diet-sensitivity.ts) | 影子价格 (`constr.dual`)、松弛量 (`constr.slack`) 与缩减成本 (`var.reducedCost`) | HiGHS |
|
|
452
452
|
| **实战应用** | [员工排班与冲突诊断](https://github.com/ohtaman/washi/blob/main/examples/node/11-shift-scheduling.ts) | 周排班优化与周六休假冲突诊断 | HiGHS + Z3 |
|
|
453
|
-
| **实战应用** | [购物车优惠券最优组合](https://github.com/ohtaman/washi/blob/main/examples/node/12-ecommerce-coupon-optimizer.ts) | 满减门槛条件约束 (`
|
|
453
|
+
| **实战应用** | [购物车优惠券最优组合](https://github.com/ohtaman/washi/blob/main/examples/node/12-ecommerce-coupon-optimizer.ts) | 满减门槛条件约束 (`indicator`)、互斥规则与凑单推荐 | HiGHS |
|
|
454
454
|
| **实战应用** | [投资组合分配](https://github.com/ohtaman/washi/blob/main/examples/node/03-portfolio-qp.ts) | 凸二次目标函数 (`QuadExpr`) 与分配约束 | HiGHS |
|
|
455
|
-
| **逻辑 / SMT** | [业务规则检查](https://github.com/ohtaman/washi/blob/main/examples/node/04-smt-security-rules.ts) | 算术与逻辑约束 (`
|
|
455
|
+
| **逻辑 / SMT** | [业务规则检查](https://github.com/ohtaman/washi/blob/main/examples/node/04-smt-security-rules.ts) | 算术与逻辑约束 (`bool`, `implies`) 的可满足性检查 | Z3 |
|
|
456
456
|
| **逻辑 / SMT** | [冲突诊断](https://github.com/ohtaman/washi/blob/main/examples/node/05-unsat-core-diagnosis.ts) | 命名约束与 Unsat Core (`unsatCore`) | Z3 |
|
|
457
457
|
|
|
458
458
|
在[在线浏览器演示](https://ohtaman.github.io/washi/demo/)中可以编辑并运行模型。浏览器 ESM、script 标签和 CodePen 的用法请参阅[分发示例](https://github.com/ohtaman/washi/blob/main/examples/distribution/README.md)。Z3 需要跨源隔离;具体要求见上方浏览器说明。
|