@ohtaman/washi 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/README.ja.md +139 -418
  2. package/README.md +139 -418
  3. package/README.zh-CN.md +139 -418
  4. package/THIRD_PARTY_LICENSES.md +39 -4
  5. package/dist/browser/__vite-browser-external-rTVKos2U.js +7 -0
  6. package/dist/browser/browser-runtime-AG5QFtKf.js +2021 -0
  7. package/dist/browser/highs-worker.js +26 -11
  8. package/dist/browser/highs.wasm +0 -0
  9. package/dist/browser/{loader-DewlSho8.js → loader-i3FnqMes.js} +183 -149
  10. package/dist/browser/solvers/glpk.js +289 -238
  11. package/dist/browser/solvers/glpk.min.js +1 -1
  12. package/dist/browser/solvers/pumpkin-_washi-pumpkin-node-runtime-CEKUDK6d.js +9 -0
  13. package/dist/browser/solvers/pumpkin-loader-CvdaKxf4.js +320 -0
  14. package/dist/browser/solvers/pumpkin-worker.js +45 -0
  15. package/dist/browser/solvers/pumpkin.js +1777 -0
  16. package/dist/browser/solvers/pumpkin.min.js +1 -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 +3828 -1315
  22. package/dist/browser/washi.min.js +5 -3
  23. package/dist/lib/__vite-browser-external-oLchLuMx.js +7 -0
  24. package/dist/lib/highs-browser-runtime.js +1846 -1618
  25. package/dist/lib/highs-runtime.js +16 -2
  26. package/dist/lib/highs-worker.js +26 -11
  27. package/dist/lib/highs.wasm +0 -0
  28. package/dist/lib/{loader-BZUQNvh4.js → loader-CDpPXN_F.js} +138 -116
  29. package/dist/lib/registry-dx7x4e5c.js +1694 -0
  30. package/dist/lib/rolldown-runtime-DtPi1Y-2.js +13 -0
  31. package/dist/lib/solvers/glpk.js +161 -121
  32. package/dist/lib/solvers/pumpkin-assets.js +1 -0
  33. package/dist/lib/solvers/pumpkin-loader-Ow74Fa1B.js +311 -0
  34. package/dist/lib/solvers/pumpkin-node-runtime.js +15 -0
  35. package/dist/lib/solvers/pumpkin-worker-factory.js +1 -0
  36. package/dist/lib/solvers/pumpkin-worker.js +45 -0
  37. package/dist/lib/solvers/pumpkin.js +1767 -0
  38. package/dist/lib/solvers/pumpkin.wasm +0 -0
  39. package/dist/lib/solvers/pumpkin.wasm.LICENSE +21 -0
  40. package/dist/lib/solvers/z3.js +486 -306
  41. package/dist/lib/washi.js +3054 -1202
  42. package/dist/types/decomposition/benders.d.ts.map +1 -1
  43. package/dist/types/index.d.ts +3 -3
  44. package/dist/types/index.d.ts.map +1 -1
  45. package/dist/types/modeler/boolean-expr.d.ts +137 -29
  46. package/dist/types/modeler/boolean-expr.d.ts.map +1 -1
  47. package/dist/types/modeler/constraint.d.ts +40 -4
  48. package/dist/types/modeler/constraint.d.ts.map +1 -1
  49. package/dist/types/modeler/expression.d.ts +176 -28
  50. package/dist/types/modeler/expression.d.ts.map +1 -1
  51. package/dist/types/modeler/index.d.ts +5 -6
  52. package/dist/types/modeler/index.d.ts.map +1 -1
  53. package/dist/types/modeler/linearizer.d.ts +11 -2
  54. package/dist/types/modeler/linearizer.d.ts.map +1 -1
  55. package/dist/types/modeler/lp-writer.d.ts.map +1 -1
  56. package/dist/types/modeler/model.d.ts +97 -130
  57. package/dist/types/modeler/model.d.ts.map +1 -1
  58. package/dist/types/modeler/parser.d.ts +25 -5
  59. package/dist/types/modeler/parser.d.ts.map +1 -1
  60. package/dist/types/modeler/quad-expr.d.ts +8 -2
  61. package/dist/types/modeler/quad-expr.d.ts.map +1 -1
  62. package/dist/types/modeler/solution-validator.d.ts +12 -12
  63. package/dist/types/modeler/solution-validator.d.ts.map +1 -1
  64. package/dist/types/modeler/solvers/glpk/loader.d.ts +4 -0
  65. package/dist/types/modeler/solvers/glpk/loader.d.ts.map +1 -1
  66. package/dist/types/modeler/solvers/glpk/solver.d.ts +2 -2
  67. package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
  68. package/dist/types/modeler/solvers/highs/driver.d.ts.map +1 -1
  69. package/dist/types/modeler/solvers/highs/loader.d.ts +8 -6
  70. package/dist/types/modeler/solvers/highs/loader.d.ts.map +1 -1
  71. package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
  72. package/dist/types/modeler/solvers/highs/worker-client.d.ts +16 -0
  73. package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
  74. package/dist/types/modeler/solvers/mock.d.ts +2 -3
  75. package/dist/types/modeler/solvers/mock.d.ts.map +1 -1
  76. package/dist/types/modeler/solvers/pumpkin/assets.d.ts +2 -0
  77. package/dist/types/modeler/solvers/pumpkin/assets.d.ts.map +1 -0
  78. package/dist/types/modeler/solvers/pumpkin/index.d.ts +6 -0
  79. package/dist/types/modeler/solvers/pumpkin/index.d.ts.map +1 -0
  80. package/dist/types/modeler/solvers/pumpkin/loader.d.ts +40 -0
  81. package/dist/types/modeler/solvers/pumpkin/loader.d.ts.map +1 -0
  82. package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts +3 -0
  83. package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts.map +1 -0
  84. package/dist/types/modeler/solvers/pumpkin/solver.d.ts +23 -0
  85. package/dist/types/modeler/solvers/pumpkin/solver.d.ts.map +1 -0
  86. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts +74 -0
  87. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts.map +1 -0
  88. package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts +3 -0
  89. package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts.map +1 -0
  90. package/dist/types/modeler/solvers/pumpkin/worker.d.ts +7 -0
  91. package/dist/types/modeler/solvers/pumpkin/worker.d.ts.map +1 -0
  92. package/dist/types/modeler/solvers/pumpkin.d.ts +2 -0
  93. package/dist/types/modeler/solvers/pumpkin.d.ts.map +1 -0
  94. package/dist/types/modeler/solvers/registry.d.ts.map +1 -1
  95. package/dist/types/modeler/solvers/types.d.ts +9 -9
  96. package/dist/types/modeler/solvers/types.d.ts.map +1 -1
  97. package/dist/types/modeler/solvers/z3/loader.d.ts +4 -0
  98. package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
  99. package/dist/types/modeler/solvers/z3/solver.d.ts +2 -15
  100. package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -1
  101. package/dist/types/modeler/types.d.ts +12 -15
  102. package/dist/types/modeler/types.d.ts.map +1 -1
  103. package/dist/types/modeler/validation.d.ts +26 -2
  104. package/dist/types/modeler/validation.d.ts.map +1 -1
  105. package/dist/types/modeler/variable.d.ts +9 -5
  106. package/dist/types/modeler/variable.d.ts.map +1 -1
  107. package/docs/examples/diet-sensitivity.md +15 -14
  108. package/docs/examples/ecommerce-coupons.md +15 -22
  109. package/docs/examples/index.md +20 -13
  110. package/docs/examples/knapsack.md +8 -7
  111. package/docs/examples/portfolio-qp.md +11 -4
  112. package/docs/examples/production.md +4 -4
  113. package/docs/examples/project-scheduling.md +106 -0
  114. package/docs/examples/shift-scheduling.md +23 -7
  115. package/docs/examples/smt-security.md +17 -4
  116. package/docs/examples/transportation.md +46 -19
  117. package/docs/examples/traveling-salesperson.md +29 -45
  118. package/docs/examples/unsat-core.md +16 -5
  119. package/docs/examples/vehicle-routing.md +10 -8
  120. package/docs/getting-started/ai-agents.md +114 -34
  121. package/docs/getting-started/coding-agents.md +158 -0
  122. package/docs/getting-started/cross-origin.md +56 -28
  123. package/docs/getting-started/index.md +36 -66
  124. package/docs/getting-started/runtimes.md +98 -69
  125. package/docs/guide/constraint-programming.md +141 -0
  126. package/docs/guide/constraints.md +100 -44
  127. package/docs/guide/decomposition.md +141 -273
  128. package/docs/guide/expressions.md +125 -42
  129. package/docs/guide/formulation-tips.md +212 -0
  130. package/docs/guide/objectives.md +70 -64
  131. package/docs/guide/unsat-core.md +44 -23
  132. package/docs/guide/variables.md +56 -48
  133. package/docs/solvers/custom-solver.md +18 -13
  134. package/docs/solvers/highs.md +41 -25
  135. package/docs/solvers/index.md +13 -7
  136. package/docs/solvers/pumpkin.md +163 -0
  137. package/docs/solvers/z3.md +4 -1
  138. package/llms-full.txt +1732 -860
  139. package/llms.txt +59 -36
  140. package/package.json +40 -13
  141. package/skills/washi/SKILL.md +91 -35
  142. package/dist/browser/_washi-node-only-BvRk9kiK.js +0 -0
  143. package/dist/browser/browser-runtime-TLCY0hkc.js +0 -1793
  144. package/dist/lib/_washi-node-only-BvRk9kiK.js +0 -0
  145. package/dist/lib/registry-C20sxTwm.js +0 -964
  146. package/docs/ja/getting-started/ai-agents.md +0 -270
  147. package/docs/zh/getting-started/ai-agents.md +0 -270
package/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
  <picture>
3
3
  <source media="(prefers-color-scheme: dark)" srcset="./assets/washi-header-dark.png">
4
4
  <source media="(prefers-color-scheme: light)" srcset="./assets/washi-header-light.png">
5
- <img alt="WaSHI - Algebraic Modeler for Mathematical Optimization &amp; Constraint Programming" src="./assets/washi-header-light.png" width="420" />
5
+ <img alt="WaSHI - Mathematical Optimization Modeler in TypeScript" src="./assets/washi-header-light.png" width="420" />
6
6
  </picture>
7
- <p><strong>Algebraic Modeler for Mathematical Optimization &amp; Constraint Programming</strong></p>
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> •
@@ -16,19 +16,46 @@
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
- <a href="https://ohtaman.github.io/washi/"><img src="https://img.shields.io/badge/docs-online-blue" alt="docs" /></a>
20
- <a href="https://ohtaman.github.io/washi/demo/"><img src="https://img.shields.io/badge/demo-playground-brightgreen" alt="live demo" /></a>
19
+ <a href="https://washi.ohtaman.dev/"><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>
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) is an algebraic modeler for mathematical optimization and constraint programming in 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 mathematical optimization and constraint programming in TypeScript and JavaScript, inspired by Python's **PuLP**. Define variables, objectives, and constraints in application code, and solve them locally in Node.js or the browser using bundled **HiGHS** (default) and **Pumpkin** (`@ohtaman/washi/solvers/pumpkin`), or optional **Z3** and **GLPK** plugins.
28
28
 
29
- 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.
29
+ ## ✨ Key Features
30
30
 
31
- [Documentation](https://ohtaman.github.io/washi/) · [Try the browser demo](https://ohtaman.github.io/washi/demo/) · [AI Agent Quick-Reference](docs/getting-started/ai-agents.md) · [Agent Skill (`SKILL.md`)](skills/washi/SKILL.md) · [Browse example source code](https://github.com/ohtaman/washi/blob/main/examples/README.md) · [ESM / script / CodePen examples](https://github.com/ohtaman/washi/blob/main/examples/distribution/README.md)
31
+ - **Natural Algebraic Syntax**: Write expressions and constraints directly with `` expr`30 * ${x} + 50 * ${y} <= 40` ``, `sum`, and `dot`.
32
+ - **Runs in Node.js & Browsers**: Powered by WebAssembly—no Python service or native C/C++ build required.
33
+ - **Solver-Independent**: Use bundled zero-dependency **HiGHS** (LP/MIP/QP) and **Pumpkin** (CP/LCG), optional **Z3** and **GLPK** plugins, or custom solver adapters.
34
+ - **Satisfiability & Conflict Diagnosis**: Check logical/arithmetic feasibility and pinpoint contradictory constraints when a model is infeasible.
35
+ - **Decomposition Methods**: Built-in support for Column Generation and Benders Decomposition on large-scale problems.
36
+
37
+ ## 📚 Documentation & Links
38
+
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/) · [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
43
+
44
+ ---
45
+
46
+ ## 📦 Installation & Quick Start
47
+
48
+ ```bash
49
+ npm install @ohtaman/washi
50
+ # HiGHS (LP/MIP/QP) and Pumpkin (CP/LCG, @ohtaman/washi/solvers/pumpkin) are bundled with zero extra dependencies
51
+
52
+ # Optional peer-dependency solver plugins
53
+ npm install z3-solver # For SMT logic & exact real/integer unsat core diagnosis
54
+ npm install glpk.js # For GLPK solver (GPL-3.0)
55
+
56
+ # Optional skill for AI coding agents (Claude Code, Cursor, Codex, etc.)
57
+ npx skills add ohtaman/washi
58
+ ```
32
59
 
33
60
  ```ts
34
61
  import { Model, expr, maximize } from "@ohtaman/washi";
@@ -47,481 +74,175 @@ console.log(`Produce: x=${x.value}, y=${y.value} (Profit: $${m.objectiveValue})`
47
74
 
48
75
  ---
49
76
 
50
- ## 🎯 What WaSHI provides
51
-
52
- 1. **Algebraic model construction**: Formulate optimization models using domain-specific variable constructors (`m.binary`, `m.integer`, `m.continuous`), unified tagged template literals (`expr`), vector aggregations (`dot`, `sum`), and first-class constraints (`m.constraint`). Because JavaScript lacks operator overloading, `` expr`...` `` parses infix math (`+`, `-`, `*`, `^2`, `<=`, `>=`, `==`) while binding interpolated `${...}` values directly as typed `Var` or expression references—similar to parameterized SQL templates—preserving static type checking, IDE refactoring, and indexed variable lookups (`${flow[i][j]}`).
53
- 2. **Solver adapters**: Use a common modeling API with HiGHS, Z3, or GLPK, or [register your own adapter](https://github.com/ohtaman/washi/blob/main/docs/solvers/custom-solver.md). Choose an engine that supports the model's problem class; the adapters do not make every solver support every feature.
54
- 3. **Local execution and WebAssembly distribution**: With the local solver adapters, solving runs in the application without a separate Python service or native C/C++ build—removing backend provisioning as a bottleneck when shipping interactive tools or combining mathematical optimization with in-browser LLMs (e.g., WebGPU / WebLLM) on the client. Browser deployments must include the generated JS, Worker, and WASM assets. Offline use also requires those resources to be available locally or cached. Z3 has additional browser isolation requirements.
55
- 4. **Named constraints and conflict diagnosis**: Explicitly check satisfiability (`m.check()`) and inspect conflicting constraints (`conflicts` / `unsatCore`) to investigate infeasibilities: built-in HiGHS isolates an **elastic repair set** (`conflicts`, constraints requiring relaxation to restore feasibility), while Z3 extracts an **unsatisfiable core** (`unsatCore` / `conflicts`, a mutually contradictory constraint subset; minimality is not guaranteed).
56
- 5. **Advanced decomposition methods**: Overcome combinatorial bottlenecks in monolithic MIP formulations (cutting stock, vehicle routing/VRP, traveling salesperson/TSP, and two-stage facility planning) using first-class decomposition orchestrators (`master.solveColumnGeneration`, `master.solveBenders`). WaSHI coordinates dual shadow prices, pricing subproblems, and Benders cut generation via clean callback orchestrators and linking constraints (`sub.link(...)`).
77
+ ## ⚙️ Solvers
57
78
 
58
- Model construction and translation are WaSHI's responsibility. Supported problem classes, numerical behavior, and solve time depend on the selected solver, its settings, and the problem. Modeling overhead and solver execution time should be measured separately; a result for one model is not a general performance guarantee.
59
-
60
- ---
61
-
62
- ## ⚙️ Solver adapters and capabilities
63
-
64
- | Adapter | Engine license | Supported problem classes | Engine role | Integration |
79
+ | Solver | License | Problem Classes | Primary Use Case | Setup |
65
80
  | :--- | :--- | :--- | :--- | :--- |
66
- | **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | **MIT** | **LP, MIP, convex QP** | Numerical optimization | Built-in default |
67
- | **[Z3](https://github.com/Z3Prover/z3)** (via [`z3-solver`](https://www.npmjs.com/package/z3-solver)) | **MIT** | **SMT, SAT, logic, MIP** | Satisfiability checks, unsatisfiable cores, optimization | Optional plugin (`@ohtaman/washi/solvers/z3`) |
68
- | **[GLPK](https://www.gnu.org/software/glpk/)** (via [`glpk.js`](https://www.npmjs.com/package/glpk.js)) | **GPL-3.0** | **LP, MIP** | Linear and mixed-integer optimization | Optional plugin (`@ohtaman/washi/solvers/glpk`) |
69
- | **Mock** | **MIT** | — | Simulated solver responses for integration tests | Built-in; does not solve the model |
81
+ | **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | MIT | LP, MIP, Convex QP | Numerical optimization & elastic conflict repair | Built-in default (zero extra deps) |
82
+ | **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** | MIT | CP, LCG, Logic, Bounded Integer | Combinatorial scheduling & zero-COOP/COEP `unsatCore` | `import "@ohtaman/washi/solvers/pumpkin"` (bundled WASM, zero deps) |
83
+ | **[Z3](https://github.com/Z3Prover/z3)** | MIT | SMT, SAT, Logic, MIP | Logical rules, satisfiability & exact `unsatCore` | `npm install z3-solver` + `import "@ohtaman/washi/solvers/z3"` |
84
+ | **[GLPK](https://www.gnu.org/software/glpk/)** | GPL-3.0 | LP, MIP | Linear & mixed-integer optimization | `npm install glpk.js` + `import "@ohtaman/washi/solvers/glpk"` |
85
+ | **Mock** | MIT | — | Deterministic unit & integration testing | Built-in (`MockSolver`) |
70
86
 
71
- ---
87
+ Pass `{ solver: "pumpkin" }`, `{ solver: "z3" }`, or `{ solver: "glpk" }` to `new Model(...)`, `m.solve(...)`, or `m.check(...)` after importing the plugin.
72
88
 
73
- ## 📦 Installation
89
+ ---
74
90
 
75
- ```bash
76
- # npm
77
- npm install @ohtaman/washi
91
+ ## 🚀 Usage Examples
78
92
 
79
- # pnpm
80
- pnpm add @ohtaman/washi
93
+ ### 1. Sums, Dot Products (`sum` / `dot`) & Conditional Constraints
81
94
 
82
- # yarn
83
- yarn add @ohtaman/washi
95
+ Combine indexed variables with `dot` / `sum` and express conditional rules with `m.indicator()`:
84
96
 
85
- # bun
86
- bun add @ohtaman/washi
87
- ```
97
+ ```ts
98
+ import { Model, expr, minimize } from "@ohtaman/washi";
88
99
 
89
- *(Optional)* To use Z3 or GLPK solvers, install their respective packages:
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
+ };
90
107
 
91
- ```bash
92
- npm install z3-solver # For SMT and unsat core diagnosis
93
- npm install glpk.js # For GLPK solver (GPL-3.0)
94
- ```
108
+ const open = m.binary(factories);
109
+ const ship = m.continuous(factories, stores, { lb: 0, ub: 500 });
95
110
 
96
- *(Optional)* For AI coding agents (Claude Code, Antigravity, Cursor, Codex, etc.), install the portable [`skills/washi/SKILL.md`](skills/washi/SKILL.md) workflow directly via the `skills` CLI or copy it from the installed package:
111
+ // If Tokyo is closed (open["Tokyo"] == 0), total shipment from Tokyo must be 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");
97
114
 
98
- ```bash
99
- # Install via the open skills CLI (skills.sh / vercel-labs/skills)
100
- npx skills add ohtaman/washi
115
+ m.objective(minimize(expr`dot(${costs}, ${ship})`));
116
+ await m.solve();
101
117
 
102
- # Or manually copy the packaged skill into your project's agent directory
103
- mkdir -p .agents/skills/washi
104
- cp node_modules/@ohtaman/washi/skills/washi/SKILL.md .agents/skills/washi/SKILL.md
118
+ console.log("Tokyo -> StoreA:", ship["Tokyo"]["StoreA"].value);
105
119
  ```
106
120
 
107
- ---
108
-
109
- ## 🚀 Usage Guide
121
+ ### 2. Convex Quadratic Programming (QP)
110
122
 
111
- ### 1. Multidimensional Variables, Indicator Constraints & Solution Validation
112
-
113
- Construct 1D dictionaries or 2D matrices of variables in a single call, express conditional Big-M logic with `m.indicator()`, monitor live progress (`onProgress`), and independently verify solutions with `m.validateSolution()`:
123
+ Minimize a quadratic objective subject to linear constraints:
114
124
 
115
125
  ```ts
116
- import { Model, expr } from "@ohtaman/washi";
117
-
118
- const m = new Model("FacilityPlanning");
119
-
120
- // 1D dictionary of binary variables
121
- const openCity = m.binary(["Tokyo", "Osaka", "Nagoya"]);
122
-
123
- // 2D transport flow matrix: [Factory] x [Store]
124
- const flow = m.continuous(["F1", "F2"], ["StoreA", "StoreB"], { lb: 0, ub: 1000 });
125
-
126
- // 2D coordinate grid (e.g. 8x8 chessboard)
127
- const board = m.binary(8, 8, { prefix: "queen" });
128
-
129
- // Conditional Big-M constraint: if openCity["Tokyo"] == 0, flow["F1"]["StoreA"] <= 0
130
- // (Omit M to let WaSHI automatically derive a tight Big-M from finite variable bounds)
131
- m.indicator(openCity["Tokyo"], expr`${flow["F1"]["StoreA"]} <= 0`, {
132
- activeValue: 0,
133
- name: "tokyo_closed_no_flow",
134
- });
135
-
136
- // Solve with optional progress callback & AbortSignal cancellation
137
- const controller = new AbortController();
138
- await m.solve({
139
- signal: controller.signal,
140
- onProgress: (ev) => {
141
- // Live branch-and-bound metrics: ev.elapsedTime, ev.objectiveValue, ev.objectiveBound, ev.mipGap
142
- },
143
- });
144
-
145
- // Independently verify variable bounds, integrality, and linear/logical constraints
146
- const report = m.validateSolution();
147
- console.log("Solution valid?", report.valid);
148
- ```
126
+ import { Model, expr, minimize } from "@ohtaman/washi";
149
127
 
150
- ---
151
-
152
- ### 2. Portfolio Risk Minimization (Convex Quadratic Programming)
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 });
153
131
 
154
- Minimize investment risk based on a covariance matrix subject to return and budget constraints:
155
-
156
- ```ts
157
- import { Model, QuadExpr, sum, dot, minimize, expr } from "@ohtaman/washi";
158
-
159
- const m = new Model("MarkowitzPortfolio");
160
- const assets = ["Tech", "Bonds", "RealEstate"];
161
- const returns = [0.14, 0.04, 0.08];
162
-
163
- // Decision variables: portfolio allocation weights (0 to 1)
164
- const w = m.continuous(assets, { lb: 0, ub: 1 });
165
-
166
- // 1. Fully invested budget: sum(w) == 1.0
167
- m.constraint(expr`${sum(assets, (a) => w[a])} == 1.0`, "budget");
168
-
169
- // 2. Minimum target return: portfolio return >= 8.5%
170
- const retMap = Object.fromEntries(assets.map((a, i) => [a, returns[i]]));
171
- m.constraint(expr`${dot(retMap, w)} >= 0.085`, "min_return");
172
-
173
- // 3. Covariance risk matrix
174
- const cov = [
175
- [0.040, 0.002, 0.015],
176
- [0.002, 0.005, 0.002],
177
- [0.015, 0.002, 0.025],
178
- ];
179
-
180
- // Quadratic objective: w^T * Cov * w
181
- let risk = new QuadExpr();
182
- for (let i = 0; i < assets.length; i++) {
183
- for (let j = 0; j < assets.length; j++) {
184
- risk = risk.add(w[assets[i]].mul(w[assets[j]]).mul(cov[i][j]));
185
- }
186
- }
187
- m.objective(minimize(risk));
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`));
188
135
 
189
136
  await m.solve();
190
- console.log(`Minimal Variance: ${m.objectiveValue?.toFixed(6)}`);
191
- assets.forEach((name) => {
192
- console.log(` ${name}: ${((w[name].value || 0) * 100).toFixed(2)}%`);
193
- });
137
+ console.log(`Tech: ${x.value?.toFixed(2)}, Bonds: ${y.value?.toFixed(2)}`);
194
138
  ```
195
139
 
196
- ---
197
-
198
- ### 3. SMT Logic & Rule Engines (with Z3)
140
+ ### 3. Constraint Programming & Disjunctive Scheduling (Pumpkin)
199
141
 
200
- Express boolean variables, propositional connectives (`and`, `or`, `implies`, `not`, `xor`), and mixed arithmetic rules:
142
+ Use bundled **Pumpkin** (`@ohtaman/washi/solvers/pumpkin`) for bounded integer scheduling and CP global constraints (`disjoint`, `distinct`, `cumulative`, `allowed`) with zero external dependencies:
201
143
 
202
144
  ```ts
203
- import { Model, not, expr } from "@ohtaman/washi";
204
- import "@ohtaman/washi/solvers/z3";
205
-
206
- const m = new Model({ name: "SmartSecurityRules" });
207
-
208
- const isNight = m.bool("isNight");
209
- const motion = m.bool("motion");
210
- const alarm = m.bool("alarm");
211
- const siren = m.bool("siren");
212
- const lux = m.integer("lux", { lb: 0 });
213
-
214
- // Logical rules
215
- m.constraint(lux.le(50).implies(isNight), "dark_implies_night");
216
- m.constraint(motion.and(isNight).and(alarm).implies(siren), "alarm_rule");
217
-
218
- // Current sensor observations
219
- m.constraint(expr`${lux} <= 10`, "sensor_dark");
220
- m.constraint(motion, "sensor_motion");
221
- m.constraint(alarm, "alarm_on");
222
-
223
- // Check satisfiability and deduce state without an objective function
224
- const res = await m.check({ solver: "z3" });
225
-
226
- console.log(`Satisfiable? ${res.status === "Sat"}`); // true
227
- console.log(`Siren active? ${m.values.get("siren")}`); // true
145
+ import { Model, expr, disjoint, distinct, minimize } from "@ohtaman/washi";
146
+ import "@ohtaman/washi/solvers/pumpkin";
147
+
148
+ const m = new Model("WorkshopCP", { solver: "pumpkin" });
149
+ const start = m.integer(["cut", "weld", "paint"] as const, { lb: 0, ub: 20, prefix: "start" });
150
+ const bench = m.integer(["cut", "weld", "paint"] as const, { lb: 1, ub: 3, prefix: "bench" });
151
+
152
+ m.constraint(
153
+ disjoint([
154
+ { start: start.cut, duration: 4 },
155
+ { start: start.weld, duration: 3 },
156
+ { start: start.paint, duration: 2 },
157
+ ]),
158
+ "single_line"
159
+ );
160
+ m.constraint(expr`${start.cut} + 4 <= ${start.weld}`, "cut_before_weld");
161
+ m.constraint(expr`${start.weld} + 3 <= ${start.paint}`, "weld_before_paint");
162
+ m.constraint(distinct(bench), "unique_benches");
163
+
164
+ m.objective(minimize(expr`${start.paint} + 2`));
165
+ await m.solve();
166
+ console.log(`Makespan: ${m.objectiveValue}h (paint starts at ${start.paint.value}h)`);
228
167
  ```
229
168
 
230
- ---
231
-
232
- ### 4. Conflict Diagnosis (`conflicts` / `unsatCore`)
169
+ ### 4. Logic & Conflict Diagnosis (`m.check`)
233
170
 
234
- When business rules or constraints contradict each other, diagnose infeasibilities to pinpoint where to intervene:
235
- - **Built-in HiGHS & GLPK**: `await m.check()` uses a single-solve elastic slack formulation ($\min \sum s_i$) to isolate `res.conflicts`—the **repair set** of constraints whose relaxation restores feasibility, without requiring extra dependencies.
236
- - **Z3**: `await m.check({ solver: "z3" })` provides exact SMT **unsatisfiable-core** extraction (`res.unsatCore` and `res.conflicts`), returning a mutually contradictory constraint subset.
171
+ Express logical implications and diagnose why a model is infeasible:
172
+ - **HiGHS (default)**: Isolates an **elastic repair set** (`res.conflicts`)—constraints whose relaxation restores feasibility.
173
+ - **Pumpkin (bundled)**: Extracts a scale-invariant **unsatisfiable core** (`res.unsatCore` / `res.conflicts`) for bounded integer and boolean models with **zero `COOP`/`COEP` headers**.
174
+ - **Z3**: Extracts an exact SMT **unsatisfiable core** (`res.unsatCore` / `res.conflicts`) including continuous and rational arithmetic.
237
175
 
238
176
  ```ts
239
- import { Model, expr } from "@ohtaman/washi";
177
+ import { Model, implies, expr } from "@ohtaman/washi";
178
+ // import "@ohtaman/washi/solvers/pumpkin"; // Bundled zero-COOP/COEP unsatCore (bounded int/bool)
179
+ // import "@ohtaman/washi/solvers/z3"; // Optional: exact SMT unsatCore including Continuous vars
240
180
 
241
- const m = new Model("ConflictDiagnosis");
181
+ const m = new Model("StaffingRules");
242
182
  const engineers = m.integer("engineers", { lb: 0, ub: 20 });
243
183
  const budget = m.continuous("budget", { lb: 0, ub: 100000 });
244
- const rushDelivery = m.bool("rushDelivery");
184
+ const rush = m.bool("rush");
245
185
 
246
- // Rule 1: Each engineer costs $8,000
247
186
  m.constraint(expr`8000 * ${engineers} <= ${budget}`, "budget_limit");
187
+ m.constraint(rush, "rush_required");
188
+ m.constraint(implies(rush, expr`${engineers} >= 8`), "rush_staffing");
189
+ m.constraint(expr`${budget} <= 50000`, "budget_cap"); // Conflict: 8 * $8,000 > $50,000
190
+ m.constraint(expr`${engineers} >= 1`, "min_staff"); // Unrelated rule
248
191
 
249
- // Rule 2: Customer requires rush delivery
250
- m.constraint(rushDelivery, "rush_required");
251
-
252
- // Rule 3: Rush delivery requires at least 8 engineers
253
- m.constraint(rushDelivery.implies(engineers.ge(8)), "rush_staffing_rule");
254
-
255
- // Rule 4: Hard board budget cap of $50,000 (Conflict: 8 * $8000 = $64,000 > $50,000!)
256
- m.constraint(expr`${budget} <= 50000`, "strict_board_budget_cap");
257
-
258
- // Rule 5: Innocent bystander rule
259
- m.constraint(expr`${engineers} >= 1`, "minimum_one_employee");
260
-
261
- // 1. Elastic repair diagnosis with default HiGHS
262
- const res = await m.check();
263
-
264
- console.log(`Status: ${res.status}`); // "Unsat"
265
- console.log("Repair set (relaxed constraints):", res.conflicts);
266
- // Output with HiGHS: ["rush_required"]
267
- // (Relaxing rush_required restores feasibility; innocent rules like minimum_one_employee are untouched)
268
-
269
- // 2. Or exact SMT unsatisfiable core with Z3 (import "@ohtaman/washi/solvers/z3")
270
- // const z3Res = await m.check({ solver: "z3" });
271
- // console.log("Contradictory core:", z3Res.unsatCore);
272
- // Output with Z3: ["budget_limit", "rush_required", "rush_staffing_rule", "strict_board_budget_cap"]
273
- ```
274
-
275
- ---
276
-
277
- ### 5. Solving with GLPK (GPL-3.0)
278
-
279
- To use the GNU Linear Programming Kit (GLPK) solver plugin:
280
-
281
- ```ts
282
- import { Model, expr, maximize } from "@ohtaman/washi";
283
- import "@ohtaman/washi/solvers/glpk";
284
-
285
- const m = new Model({ solver: "glpk" });
286
- const x = m.integer("x", { lb: 0 });
287
- const y = m.integer("y", { lb: 0 });
288
-
289
- m.objective(maximize(expr`30 * ${x} + 50 * ${y}`));
290
- m.constraint(expr`${x} + 2 * ${y} <= 40`, "wood_limit");
291
- m.constraint(expr`2 * ${x} + ${y} <= 50`, "labor_limit");
292
-
293
- const status = await m.solve();
294
- console.log(`Status: ${status}`); // "Optimal"
295
- console.log(`Objective: ${m.objectiveValue}`); // 1100
296
- ```
297
-
298
- ---
299
-
300
- ### 6. Vector Operations & Fast Dot Product
301
-
302
- Cleanly compute 1D/2D linear combinations without nested loops:
303
-
304
- ```ts
305
- import { Model, dot, minimize } from "@ohtaman/washi";
306
-
307
- const m = new Model();
308
- const factories = ["Tokyo", "Osaka"];
309
- const stores = ["StoreA", "StoreB"];
310
-
311
- const costs = {
312
- Tokyo: { StoreA: 4, StoreB: 7 },
313
- Osaka: { StoreA: 8, StoreB: 3 },
314
- };
315
-
316
- const ship = m.continuous(factories, stores);
317
-
318
- // Total transportation cost in one line:
319
- m.objective(minimize(dot(costs, ship)));
320
- await m.solve();
321
-
322
- // Extract all optimal variable values as a structured object
323
- const solution = m.getValues(ship);
324
- console.log(solution);
192
+ const res = await m.check(); // Or: await m.check({ solver: "z3" })
193
+ console.log(res.status); // "Unsat"
194
+ console.log(res.conflicts); // HiGHS: ["rush_required"]
325
195
  ```
326
196
 
327
197
  ---
328
198
 
329
199
  ## 🌐 Browser & Web Worker Usage
330
200
 
331
- The default HiGHS engine uses the package's WASM asset. There is **no automatic CDN fallback**. Node.js uses the installed HiGHS runtime; Vite and webpack 5 can discover the package-relative WASM and Worker references when building a browser application.
332
-
333
- ### npm with a bundler
334
-
335
- ```typescript
336
- import { Model } from "@ohtaman/washi";
337
- const model = new Model();
338
- // Define variables, objective and constraints.
339
- await model.solve();
340
- ```
341
-
342
- No manual WASM copy or URL configuration is needed in the tested Vite / webpack builds. Other bundlers and SSR need their own integration checks; call the browser solver on the client. Worker execution is the browser default. Use `model.solve({ useWorker: false })` for a simple main-thread demo; a long solve will block the UI.
343
-
344
- ### Browser ESM without an application build
345
-
346
- Serve the **entire `dist/browser` directory**, including its JS chunks, `highs.wasm` and Worker. No import map is needed:
201
+ - **Bundlers (Vite / webpack 5)**: `import { Model } from "@ohtaman/washi"` works out of the box. Both **HiGHS** and **Pumpkin** run in dedicated Web Workers by default (pass `{ useWorker: false }` for main-thread execution) and require **no `COOP`/`COEP` headers**.
202
+ - **Standalone ESM / Script Tag / CDN**: Serve `dist/browser/` (including `highs.wasm`, `solvers/pumpkin.wasm`, and worker chunks) or load from a CDN.
347
203
 
348
204
  ```html
205
+ <!-- Browser ESM -->
349
206
  <script type="module">
350
207
  import { Model } from "./washi/washi.js";
351
- const model = new Model();
352
- // Define variables, objective and constraints.
353
- await model.solve({ useWorker: false });
354
- </script>
355
- ```
356
-
357
- ### Plain script / CodePen
358
-
359
- The package also includes `dist/browser/washi.min.js`, which exports the `Washi` global. Put that file's URL in CodePen's External Scripts, or use a script tag:
360
-
361
- ```html
362
- <script src="./washi/washi.min.js"></script>
363
- <script>
364
- const model = new Washi.Model();
365
- // Define variables, objective and constraints.
366
- model.solve({ useWorker: false }).then(status => console.log(status));
367
- </script>
368
- ```
369
-
370
- For CDN usage, replace the local URL with `https://cdn.jsdelivr.net/npm/@ohtaman/washi@<version>/dist/browser/washi.min.js` (specifying a compatible release version once published). For ESM use the corresponding `dist/browser/washi.js` URL. Selecting the CDN URL is an explicit choice; local copies never switch to a CDN.
371
-
372
- ### Solver Plugins in the Browser (GLPK & Z3)
373
-
374
- The browser distribution includes pre-bundled, standalone solver plugins under `dist/browser/solvers/`:
375
- - **GLPK**: `dist/browser/solvers/glpk.js` (ESM) and `dist/browser/solvers/glpk.min.js` (IIFE, registers global `WashiGLPK`)
376
- - **Z3**: `dist/browser/solvers/z3.js` (ESM) and `dist/browser/solvers/z3.min.js` (IIFE, registers global `WashiZ3`), accompanied by `z3-built.js` and `z3-built.wasm`
377
-
378
- #### Browser ESM with GLPK
379
- ```html
380
- <script type="module">
381
- import { Model, maximize } from "./washi/washi.js";
382
- import "./washi/solvers/glpk.js";
383
-
384
- const model = new Model({ solver: "glpk" });
385
- const x = model.continuous("x", { lb: 0, ub: 10 });
386
- model.objective(maximize(x));
387
- await model.solve();
388
- console.log("GLPK status:", model.status);
208
+ // Bundled / optional solver plugins:
209
+ // import "./washi/solvers/pumpkin.js"; // Bundled CP/LCG (zero COOP/COEP)
210
+ // import "./washi/solvers/glpk.js"; // Optional GLPK plugin
211
+ // import "./washi/solvers/z3.js"; // Optional Z3 plugin (requires COOP/COEP)
212
+ const m = new Model();
213
+ await m.solve();
389
214
  </script>
390
- ```
391
215
 
392
- #### Plain Script with GLPK
393
- ```html
394
- <script src="./washi/washi.min.js"></script>
395
- <script src="./washi/solvers/glpk.min.js"></script>
396
- <script>
397
- const model = new Washi.Model({ solver: "glpk" });
398
- const x = model.continuous("x", { lb: 0, ub: 10 });
399
- model.objective(Washi.maximize(x));
400
- model.solve().then(status => console.log("GLPK status:", status));
401
- </script>
216
+ <!-- Classic Script / CodePen (exposes global Washi) -->
217
+ <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/washi.min.js"></script>
218
+ <!-- Optional solver plugin scripts (auto-register on window.Washi): -->
219
+ <!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/pumpkin.min.js"></script> -->
402
220
  ```
403
221
 
404
222
  > [!NOTE]
405
- > **Z3 in Browser Environments & Cross-Origin Isolation**:
406
- > Because the Z3 WebAssembly engine uses multithreading (`SharedArrayBuffer`), modern browsers require cross-origin isolation (`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 [Runtime Environments Guide](docs/getting-started/runtimes.md) for full details on static hosting, `coi-serviceworker.js`, offline/intranet deployment, CSP (`worker-src blob:`), and custom WASM URLs (`setHighsWasmUrl`).
407
-
408
- Complete standalone examples for ESM, script tags, and CodePen are available in [`examples/distribution/`](examples/distribution/README.md).
223
+ > **Z3 in the Browser**: Because Z3's WebAssembly build uses `SharedArrayBuffer`, browsers require Cross-Origin Isolation (`COOP: same-origin` and `COEP: require-corp`). See the [Cross-Origin Isolation Guide](docs/getting-started/cross-origin.md) and [`examples/distribution/`](examples/distribution/README.md). **HiGHS**, **Pumpkin** (including `unsatCore` on bounded integers/booleans), and **GLPK** require no Cross-Origin Isolation headers.
409
224
 
410
225
  ---
411
226
 
412
- ## 🛠️ Custom Solvers & Extensibility
413
-
414
- WaSHI features a decoupled, pluggable solver architecture. You can easily build and register your own custom solver adapter (e.g., for cloud REST optimizers, WebAssembly engines, or proprietary solvers):
227
+ ## 🤝 Contributing
415
228
 
416
- - See the complete [Custom Solver Developer Guide](docs/solvers/custom-solver.md) for step-by-step tutorials, complete API contracts (`Solver`, `SolveModelData`, `CheckModelData`, `SolverResult`), and testing best practices.
229
+ See [CONTRIBUTING.md](./CONTRIBUTING.md) for local development setup, running tests and benchmarks, rebuilding WebAssembly assets, and the release workflow.
417
230
 
418
231
  ---
419
232
 
420
- ## 📚 Documentation
233
+ ## 🙏 Acknowledgments
421
234
 
422
- Full documentation is available at **[ohtaman.github.io/washi](https://ohtaman.github.io/washi/)** and in the repository's [`docs/`](docs/) directory:
235
+ WaSHI stands on the shoulders of the open-source mathematical optimization and automated reasoning communities:
423
236
 
424
- - **Getting Started**: [Quick Start](docs/getting-started/index.md) · [AI Agent Quick-Reference](docs/getting-started/ai-agents.md) · [Runtime Environments](docs/getting-started/runtimes.md) · [Cross-Origin Isolation (Z3)](docs/getting-started/cross-origin.md)
425
- - **Modeling Guide**: [Variables (`Var`, `BoolVar`)](docs/guide/variables.md) · [Expressions (`expr`, `sum`, `dot`)](docs/guide/expressions.md) · [Constraints & Logic (`indicator`, SMT)](docs/guide/constraints.md) · [Objectives & Solving (`solve`, `validateSolution`)](docs/guide/objectives.md) · [Feasibility & Unsat Core (`check`)](docs/guide/unsat-core.md) · [Decomposition (`solveColumnGeneration`, `solveBenders`)](docs/guide/decomposition.md)
426
- - **Solvers**: [Solver Overview](docs/solvers/index.md) · [HiGHS](docs/solvers/highs.md) · [Z3](docs/solvers/z3.md) · [GLPK](docs/solvers/glpk.md) · [Custom Solvers](docs/solvers/custom-solver.md)
427
-
428
- ---
429
-
430
- ## 💻 Examples and browser demo
431
-
432
- Start with the [example gallery](https://github.com/ohtaman/washi/blob/main/examples/README.md) or the [online Example & Feature Finder](https://ohtaman.github.io/washi/examples/), which organize examples by problem category and by WaSHI API feature.
433
-
434
- | Category | Example | What it demonstrates | Solver |
435
- | :--- | :--- | :--- | :--- |
436
- | **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`) | HiGHS |
437
- | **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 |
438
- | **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 |
439
- | **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 |
440
- | **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 |
441
- | **Decomposition** | [Vehicle routing (CVRP)](https://github.com/ohtaman/washi/blob/main/examples/node/13-vehicle-routing-column-generation.ts) | Column Generation (Dantzig-Wolfe): pricing feasible vehicle routes from dual shadow prices | HiGHS |
442
- | **Decomposition** | [Traveling salesperson (TSP)](https://github.com/ohtaman/washi/blob/main/examples/node/14-traveling-salesperson-benders.ts) | Benders Decomposition (DFJ): lazy subtour elimination constraints via feasibility cuts | HiGHS |
443
- | **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 |
444
- | **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 |
445
- | **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 |
446
-
447
- [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.
448
-
449
- To run examples locally, clone the repository and install its development dependencies first:
450
-
451
- ```bash
452
- git clone https://github.com/ohtaman/washi.git
453
- cd washi
454
- npm ci
455
- npx tsx examples/node/01-production-planning.ts
456
- npx tsx examples/node/09-transportation-problem.ts
457
- npx tsx examples/node/10-diet-sensitivity.ts
458
- npx tsx examples/node/11-shift-scheduling.ts
459
- npx tsx examples/node/12-ecommerce-coupon-optimizer.ts
460
- npx tsx examples/node/13-vehicle-routing-column-generation.ts
461
- npx tsx examples/node/14-traveling-salesperson-benders.ts
462
-
463
- # Local browser demo: http://localhost:5173/demo/
464
- npm run dev
465
- ```
466
-
467
- The example sources import the repository's `src/` modules. In an application using the published package, import `@ohtaman/washi` and the required solver plugin instead.
468
-
469
- ---
470
-
471
- ## 🧪 Testing & Reproducible Benchmarks
472
-
473
- Run the repository's unit and integration tests, and build the distributions:
474
-
475
- ```bash
476
- # Run all unit and integration tests
477
- npm test
478
-
479
- # Build production bundle and TypeScript declarations
480
- npm run build
481
- ```
482
-
483
- ### Optional Reproducible Benchmarks
484
-
485
- To measure modeling and solver phases on deterministic `small-lp` (24 variables, 18 constraints) and `scheduling-mip` (315 variables, 231 constraints, including rebuilt `initialValue` warm starts) scenarios without mixing performance timings into correctness test thresholds:
486
-
487
- ```bash
488
- # Run Node.js in-process WASM benchmarks (HiGHS and GLPK, 5 warm iterations by default)
489
- npm run bench
490
-
491
- # Customize iteration count or emit structured JSON
492
- node scripts/run-benchmarks.mjs --iterations=10 --json
493
-
494
- # Also measure headless Chromium Web Worker execution (requires Playwright Chromium)
495
- node scripts/run-benchmarks.mjs --browser
496
- ```
497
-
498
- - **Explicit phase boundaries**: Reports cold runtime initialization (`coldRuntimeInitMs`, `coldFirstSolveMs`) separately from repeated warm-runtime measurements (`modelBuildMs`, `validationMs`, `lpSerializationMs` for LP-string adapters or `symbolMapMs` for structured adapters, `resultMappingMs` via `MockSolver`, `adapterSolveMs`, and `endToEndSolveMs`). Timings are measured directly per phase and are never subtracted to estimate "native solver time".
499
- - **Distinct execution environments**: Node.js in-process WASM (`usesBrowserWorker: false`) and Browser Web Worker execution (`usesBrowserWorker: true`, which includes Worker lifecycle and `postMessage` structured-clone transfer) are reported as separate environments, not interchangeable baselines.
500
-
501
- ### Rebuilding HiGHS WebAssembly & Release Workflow
502
-
503
- 1. **Rebuilding / Updating HiGHS WebAssembly Assets (`highs.config.json`)**:
504
- ```bash
505
- # Compile ERGO-Code/HiGHS to public/highs.wasm + runtime.js and update SHA-256 hashes in highs.config.json
506
- npm run build:highs-wasm
507
-
508
- # After merging to main, upload the updated assets to the highs-<version> GitHub Release tag
509
- # so on-demand downloads (scripts/ensure-highs-wasm.mjs) match highs.config.json SHA-256 hashes:
510
- gh release upload highs-v1.15.1 public/highs.wasm src/modeler/solvers/highs/runtime.js --clobber
511
- ```
512
- Alternatively, trigger the **Build HiGHS WebAssembly** workflow (`.github/workflows/build-wasm.yml`) via `workflow_dispatch` with `create_release: true`, then download the `highs-wasm-assets` workflow artifact (`public/highs.wasm`, `src/modeler/solvers/highs/runtime.js`, and `highs.config.json`) and commit those updated files to `main` so repository checksums stay synchronized with the published Release assets.
513
-
514
- 2. **Publishing `@ohtaman/washi` to npm**:
515
- - Merging to `main` automatically deploys the updated documentation and web demo to GitHub Pages (`.github/workflows/deploy-demo.yml`), but does **not** publish to npm automatically.
516
- - To publish a new version to npm, bump `"version"` in `package.json` on `main` and publish a GitHub Release (e.g., `gh release create v0.5.1 --generate-notes`). Publishing the GitHub Release triggers `.github/workflows/publish-npm.yml`, which runs unit and Playwright distribution checks before publishing to npm via OIDC Trusted Publishing.
237
+ - **[HiGHS](https://highs.dev/)** ([`ERGO-Code/HiGHS`](https://github.com/ERGO-Code/HiGHS)) — High-performance open-source optimization software for LP, MIP, and Convex QP initiated at the University of Edinburgh by Julian Hall, Qi Huangfu, Ivet Galabova, Leona Gottwald, Michael Feldmeier, and contributors, which powers WaSHI's built-in default solver (*Huangfu & Hall, Mathematical Programming Computation, 2018*, [DOI: 10.1007/s12532-017-0130-5](https://doi.org/10.1007/s12532-017-0130-5)).
238
+ - **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** — Lazy Clause Generation (LCG) constraint programming solver developed in Rust by ConSol Lab (TU Delft), powering WaSHI's bundled CP/LCG and zero-`COOP`/`COEP` `unsatCore` engine.
239
+ - **[Z3 Theorem Prover](https://github.com/Z3Prover/z3)** ([`z3-solver`](https://www.npmjs.com/package/z3-solver)) — Developed at Microsoft Research, powering WaSHI's optional SMT satisfiability and exact `unsatCore` conflict diagnosis plugin.
240
+ - **[GLPK](https://www.gnu.org/software/glpk/) & [`glpk.js`](https://github.com/jvail/glpk.js)** — Powering WaSHI's optional GPL-3.0 LP/MIP solver plugin.
241
+ - **[PuLP](https://github.com/coin-or/pulp)** — Inspiring WaSHI's declarative algebraic modeling ergonomics.
517
242
 
518
243
  ---
519
244
 
520
245
  ## 📄 License
521
246
 
522
247
  - **`@ohtaman/washi`**: [MIT License](./LICENSE)
523
- - **HiGHS** (default engine, [ERGO-Code/HiGHS](https://github.com/ERGO-Code/HiGHS)): MIT License
524
- - **Z3** (optional plugin via [`z3-solver`](https://www.npmjs.com/package/z3-solver)): MIT License
525
- - **GLPK** (optional plugin via [`glpk.js`](https://www.npmjs.com/package/glpk.js)): GPL-3.0 License
526
-
527
- See [THIRD_PARTY_LICENSES.md](./THIRD_PARTY_LICENSES.md) for full attribution and license details of bundled/peer optimization engines.
248
+ - **Bundled / Optional Engines**: HiGHS (MIT), Pumpkin (MIT), Z3 (MIT), GLPK (GPL-3.0). See [THIRD_PARTY_LICENSES.md](./THIRD_PARTY_LICENSES.md) for full details.