@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
@@ -2,7 +2,7 @@
2
2
 
3
3
  This guide describes how to build, test, and distribute custom solver plugins for **WaSHI** (`@ohtaman/washi`).
4
4
 
5
- WaSHI features a pluggable, decoupled solver architecture. Core `@ohtaman/washi` bundles only the zero-config HiGHS WASM engine and a Mock solver. Any third-party solver—whether implemented in WebAssembly, native C++, a Web Worker, or an external cloud REST/RPC backend—can be registered and used through the unified `Model` API.
5
+ WaSHI features a pluggable, decoupled solver architecture. Core `@ohtaman/washi` bundles the zero-config HiGHS WASM engine and a Mock solver, while `@ohtaman/washi/solvers/pumpkin` provides a bundled CP/LCG WASM plugin. Any third-party solver—whether implemented in WebAssembly, native C++, a Web Worker, or an external cloud REST/RPC backend—can be registered and used through the unified `Model` API.
6
6
 
7
7
  ---
8
8
 
@@ -13,6 +13,7 @@ graph TD
13
13
  A[WaSHI Model] --> B[Solver Registry Map Symbol.for]
14
14
  B --> C[HiGHS WASM Engine Core]
15
15
  B --> D[Mock Solver Core]
16
+ B --> H[Pumpkin WASM Plugin @ohtaman/washi/solvers/pumpkin]
16
17
  B --> E[GLPK Plugin @ohtaman/washi/solvers/glpk]
17
18
  B --> F[Z3 SMT Plugin @ohtaman/washi/solvers/z3]
18
19
  B --> G[Your Custom Solver Plugin]
@@ -69,7 +70,7 @@ export interface Solver {
69
70
  * Main solve method for LP, MIP, QP, and SMT optimization models.
70
71
  *
71
72
  * @param modelData Typed in-memory model structure (variables, constraints, objective, sense, boolVars, logicalConstraints)
72
- * @param options Runtime execution options (timeLimit, mipGap, verbose, signal, onProgress, etc.)
73
+ * @param options Runtime execution options (timeLimit, relativeGap, absoluteGap, verbose, signal, onProgress, etc.)
73
74
  */
74
75
  solve(
75
76
  modelData: SolveModelData,
@@ -119,7 +120,7 @@ export interface SolveModelData extends CheckModelData {
119
120
 
120
121
  Custom solvers declare their supported features using `capabilities`. Before dispatching `solve()` or `check()`, `Model` validates:
121
122
  - `supportsQP === false` when the objective contains quadratic terms (`QuadExpr`),
122
- - when the model contains logical constraints (`m.logicalConstraints`) and the solver does not support SMT (`supportsSMT !== true`), `Model` automatically linearizes them into equivalent 0-1 MIP binary variables and linear constraints via `linearizeModelForMip`, and
123
+ - when the model contains logical constraints (added via `m.constraint(...)`, appearing in `m.constraints` with `kind: "logical"` and passed to solvers in `modelData.logicalConstraints`) and the solver supports neither native logical constraints (`supportsLogicalConstraints !== true`) nor SMT (`supportsSMT !== true`), `Model` automatically linearizes them into equivalent 0-1 MIP binary variables and linear constraints via `linearizeModelForMip`, and
123
124
  - `supportsWarmStart !== true` when any variable has a primal `initialValue` set.
124
125
 
125
126
  ```typescript
@@ -136,6 +137,9 @@ export interface SolverCapabilities {
136
137
  /** Supports satisfiability modulo theories / boolean logic constraints */
137
138
  supportsSMT?: boolean;
138
139
 
140
+ /** Supports native boolean/propositional logical constraints (`BoolVar`, `and`, `or`, `not`, `implies`, `xor`) without SMT continuous theories */
141
+ supportsLogicalConstraints?: boolean;
142
+
139
143
  /** Supports extracting an unsatisfiable core (conflicting constraint subset) */
140
144
  supportsUnsatCore?: boolean;
141
145
 
@@ -153,8 +157,11 @@ export interface SolverOptions {
153
157
  /** Time limit in seconds */
154
158
  timeLimit?: number;
155
159
 
156
- /** Relative MIP optimality gap tolerance */
157
- mipGap?: number;
160
+ /** Relative MIP optimality gap tolerance (e.g. 0.01 for 1%) */
161
+ relativeGap?: number;
162
+
163
+ /** Absolute MIP optimality gap tolerance */
164
+ absoluteGap?: number;
158
165
 
159
166
  /** Enable solver console logging */
160
167
  verbose?: boolean;
@@ -172,7 +179,7 @@ export interface SolverOptions {
172
179
 
173
180
  ### Optional LP Serialization & Symbol-Mapping Helpers
174
181
 
175
- Solvers that consume structured JS/WASM data (such as `GLPKSolver` and `Z3Solver`) work directly with `SolveModelData` / `CheckModelData`.
182
+ Solvers that consume structured JS/WASM data (such as `PumpkinSolver`, `GLPKSolver`, and `Z3Solver`) work directly with `SolveModelData` / `CheckModelData`.
176
183
  If your adapter targets a backend that requires CPLEX/HiGHS LP text or restricted identifier syntax, WaSHI exports opt-in helpers:
177
184
 
178
185
  - `generateLpString(modelData): LpExportResult` — serializes `modelData` into a CPLEX LP format string (`lpString`) along with collision-safe symbol lookup maps (`nameToVar`, `nameToConstraint`).
@@ -215,13 +222,10 @@ export interface SolverResult {
215
222
  objectiveBound?: number;
216
223
 
217
224
  /** Relative MIP optimality gap when provided by the solver */
218
- relGap?: number;
219
-
220
- /** Alias for relGap: relative MIP optimality gap when provided by the solver */
221
- mipGap?: number;
225
+ relativeGap?: number;
222
226
 
223
227
  /** Absolute MIP optimality gap |objectiveValue - objectiveBound| (computed automatically when both are finite) */
224
- absGap?: number;
228
+ absoluteGap?: number;
225
229
 
226
230
  /** Variable primal values keyed by canonical variable name (non-finite values are ignored) */
227
231
  values: Record<string, number>;
@@ -317,7 +321,8 @@ export class CloudSolver implements Solver {
317
321
  body: JSON.stringify({
318
322
  lp: lpString,
319
323
  timeLimit: options.timeLimit,
320
- mipGap: options.mipGap,
324
+ relativeGap: options.relativeGap,
325
+ absoluteGap: options.absoluteGap,
321
326
  }),
322
327
  signal: options.signal,
323
328
  });
@@ -515,7 +520,7 @@ describe("Custom Solver Integration", () => {
515
520
  const status = await model.solve();
516
521
  expect(status).toBe("Optimal");
517
522
  expect(x.value).toBe(2);
518
- const c1 = model.getConstraintByName("budget");
523
+ const c1 = model.constraints.get("budget");
519
524
  expect(c1?.dual).toBe(2);
520
525
  } finally {
521
526
  fetchSpy.mockRestore();
@@ -1,6 +1,6 @@
1
1
  # HiGHS Solver Engine
2
2
 
3
- **HiGHS** is high-performance mathematical optimization software developed at the University of Edinburgh ([ERGO-Code/HiGHS](https://github.com/ERGO-Code/HiGHS)). It is widely recognized as the state-of-the-art open-source solver for Linear Programming (LP), Mixed-Integer Programming (MIP), and Convex Quadratic Programming (QP).
3
+ **HiGHS** is high-performance mathematical optimization software initiated at the University of Edinburgh ([highs.dev](https://highs.dev/) · [ERGO-Code/HiGHS](https://github.com/ERGO-Code/HiGHS)). It is widely recognized as the state-of-the-art open-source solver for Linear Programming (LP), Mixed-Integer Programming (MIP), and Convex Quadratic Programming (QP).
4
4
 
5
5
  In `@ohtaman/washi`, HiGHS runs entirely in WebAssembly compiled directly from official upstream source ([ERGO-Code/HiGHS](https://github.com/ERGO-Code/HiGHS)) using its native C API (`highs_c_api.h`), providing zero-config execution across Node.js, Web Workers, and browsers without third-party wrapper dependencies.
6
6
 
@@ -10,32 +10,12 @@ In `@ohtaman/washi`, HiGHS runs entirely in WebAssembly compiled directly from o
10
10
 
11
11
  - **Built-in & Zero-Config**: Bundled directly with `@ohtaman/washi` with zero external runtime dependencies. No separate peer dependency or C++ compiler required.
12
12
  - **Permissive MIT License**: 100% commercially friendly.
13
- - **Web Worker Multithreading**: Automatically offloads intensive solving to background Web Workers in browser environments to avoid freezing the UI thread.
13
+ - **Background Web Worker Execution**: Automatically offloads solving to a dedicated Web Worker in browser environments to avoid freezing the UI thread.
14
14
  - **Warm-Start Support (`initialValue`)**: Supports passing variable primal initial value hints (`initialValue`) to HiGHS `setSolution` for warm starting.
15
15
  - **Fast WASM Execution**: Runs the directly compiled 32-bit WebAssembly binary at near-native speed.
16
16
 
17
17
  ---
18
18
 
19
- ## Architecture & WebAssembly Runtime
20
-
21
- WaSHI compiles official HiGHS C++ source directly to WebAssembly (`highs.wasm`) with `-fwasm-exceptions` and single-threaded universal portability (`-DHIGHS_NO_DEFAULT_THREADS=ON`). By interfacing directly with HiGHS's native C API (`highs_c_api.h`), WaSHI achieves zero-copy solution extraction via typed array views on WebAssembly linear memory, rapid upstream release tracking, and a self-contained zero-dependency distribution.
22
-
23
- ### Callbacks & Solver Interactivity
24
-
25
- - **Progress Monitoring & Cancellation (Supported)**:
26
- Through HiGHS's internal logging and interrupt hooks, WaSHI provides real-time progress callbacks (`onProgress`) and cooperative mid-solve cancellation via standard `AbortSignal`.
27
- - **Dynamic Cuts / Lazy Constraints (Not Supported in WASM Wrapper)**:
28
- The upstream WebAssembly wrapper intentionally excludes low-level native callback type 8 (`MIP lazy constraints`) due to WASM-to-JS boundary and synchronous memory safety constraints. For problems requiring subtour elimination or Benders decomposition, use an **iterative cutting-plane loop** (solve $\to$ detect violation $\to$ `model.constraint(...)` $\to$ re-solve).
29
-
30
- ### WebAssembly Asset Lifecycle & On-Demand Builds
31
-
32
- HiGHS's WebAssembly binary (`public/highs.wasm`) and runtime driver (`runtime.js`) are managed via `highs.config.json` with cryptographic SHA-256 verification:
33
- - **Zero-Friction Verification**: Build and distribution pipelines run `node scripts/ensure-highs-wasm.mjs`, verifying local assets in milliseconds before bundling.
34
- - **On-Demand Release Download**: When assets are missing or updated, `ensure-highs-wasm.mjs` automatically downloads verified binaries from official GitHub Release assets.
35
- - **Compiling from Source**: When updating HiGHS or modifying compiler flags, run `npm run build:highs-wasm` with the Emscripten SDK (`emcc`), CMake, and Ninja installed, and upload the rebuilt assets to the `highs-<version>` GitHub Release tag (`gh release upload highs-v1.15.1 public/highs.wasm src/modeler/solvers/highs/runtime.js --clobber`) so on-demand downloads match `highs.config.json` (or run `.github/workflows/build-wasm.yml` and commit the `highs-wasm-assets` artifact including `highs.config.json`).
36
-
37
- ---
38
-
39
19
  ## Supported Problem Classes
40
20
 
41
21
  ### 1. Linear Programming (LP)
@@ -60,7 +40,7 @@ const count = model.integer("count", { lb: 0, ub: 50 });
60
40
  ```
61
41
 
62
42
  ### 3. Convex Quadratic Programming (QP)
63
- Solves quadratic objective functions subject to linear constraints:
43
+ Solves continuous models with convex quadratic objective functions subject to linear constraints:
64
44
 
65
45
  ```typescript
66
46
  // Minimize risk/variance uniformly using expr:
@@ -71,6 +51,9 @@ model.objective(minimize(expr`0.5 * ${x}^2 + 0.5 * ${y}^2`));
71
51
  // model.objective(minimize(quadObj));
72
52
  ```
73
53
 
54
+ > [!NOTE]
55
+ > **Continuous Convex QP Only**: HiGHS solves Convex QP models where **all** model variables are continuous (`m.continuous`), with a positive semi-definite quadratic matrix $\mathbf{Q}$ when minimizing (or negative semi-definite when maximizing). Mixed-Integer Quadratic Programming (**MIQP**—any model combining a quadratic objective with `Integer`, `Binary`, or `BoolVar` variables) and quadratic constraints (**QCP**) are not supported; to model products of binary decisions in MILP, see [Formulation Patterns & Tips](../guide/formulation-tips.md).
56
+
74
57
  ---
75
58
 
76
59
  ## Solver Options
@@ -82,8 +65,8 @@ const controller = new AbortController();
82
65
 
83
66
  await model.solve({
84
67
  timeLimit: 60.0, // Maximum solve time in seconds
85
- mipGap: 0.001, // Terminate when within 0.1% of global optimality (alias: relGap)
86
- absGap: 1.0, // Absolute MIP optimality gap tolerance
68
+ relativeGap: 0.001, // Terminate when within 0.1% of global optimality
69
+ absoluteGap: 1.0, // Absolute MIP optimality gap tolerance
87
70
  presolve: "on", // Presolve control ("on" | "off" | "choose")
88
71
  outputFlag: true, // Output internal simplex / branch-and-bound logs (output_flag)
89
72
  signal: controller.signal,
@@ -91,6 +74,14 @@ await model.solve({
91
74
  console.log(`Elapsed: ${ev.elapsedTime.toFixed(1)}s, Best: ${ev.objectiveValue}`);
92
75
  },
93
76
  });
77
+
78
+ // Always check hasPrimalSolution when timeLimit or AbortSignal is used:
79
+ if (model.hasPrimalSolution) {
80
+ console.log(
81
+ `Usable solution (${model.status}, termination: ${model.terminationStatus}):`,
82
+ `obj = ${model.objectiveValue}, gap = ${((model.relativeGap ?? 0) * 100).toFixed(2)}%`
83
+ );
84
+ }
94
85
  ```
95
86
 
96
87
  ---
@@ -113,3 +104,28 @@ const syncModel = new Model({
113
104
  });
114
105
  ```
115
106
 
107
+ ---
108
+
109
+ ## Architecture & WebAssembly Runtime
110
+
111
+ WaSHI compiles official HiGHS C++ source directly to WebAssembly (`highs.wasm`) with `-fwasm-exceptions` and single-threaded universal portability (`-DHIGHS_NO_DEFAULT_THREADS=ON`). By interfacing directly with HiGHS's native C API (`highs_c_api.h`), WaSHI achieves zero-copy solution extraction via typed array views on WebAssembly linear memory, rapid upstream release tracking, and a self-contained zero-dependency distribution.
112
+
113
+ Bundled `highs.wasm` and `runtime.js` artifacts are tracked and verified via SHA-256 checksums in `highs.config.json`. Maintainers rebuilding HiGHS from source can follow the instructions in [`CONTRIBUTING.md`](https://github.com/ohtaman/washi/blob/main/CONTRIBUTING.md#4-rebuilding-webassembly-assets--release-workflow).
114
+
115
+ ### Callbacks & Solver Interactivity
116
+
117
+ - **Progress Monitoring & Cancellation (Supported)**:
118
+ Through HiGHS's internal logging and interrupt hooks, WaSHI provides real-time progress callbacks (`onProgress`) and cooperative mid-solve cancellation via standard `AbortSignal`.
119
+ - **Dynamic Cuts / Lazy Constraints (Not Exposed in WASM Driver)**:
120
+ WaSHI's HiGHS WebAssembly C API driver currently binds logging, progress, interrupt, and incumbent callbacks and does not expose in-tree lazy constraint or user cut callbacks across the WASM-to-JS boundary. For problems requiring dynamic subtour elimination or Benders decomposition, use [`await m.solveBenders({ subproblem })`](../guide/decomposition.md#benders-decomposition-solvebenders) (or a manual outer cutting-plane loop: solve $\to$ detect violation $\to$ `model.constraint(...)` $\to$ re-solve), which iteratively separates cuts and converges to the same exact optimal solution.
121
+
122
+ ---
123
+
124
+ ## References & Upstream Links
125
+
126
+ - **Official Website**: [https://highs.dev/](https://highs.dev/)
127
+ - **Official Documentation**: [https://ergo-code.github.io/HiGHS/](https://ergo-code.github.io/HiGHS/)
128
+ - **Source Repository**: [ERGO-Code/HiGHS](https://github.com/ERGO-Code/HiGHS) (MIT License)
129
+ - **Academic Citation**: If you cite HiGHS in academic or technical publications, please reference the foundational paper requested by the HiGHS authors:
130
+ > Q. Huangfu and J. A. J. Hall, *"Parallelizing the dual revised simplex method"*, Mathematical Programming Computation, 10 (1), 119–142, 2018. DOI: [10.1007/s12532-017-0130-5](https://doi.org/10.1007/s12532-017-0130-5)
131
+
@@ -9,8 +9,9 @@ WaSHI is designed around a pluggable, decoupled solver architecture. You formula
9
9
  | Solver | Engine License | Problem Classes | Best For | Status in WaSHI |
10
10
  | :--- | :--- | :--- | :--- | :--- |
11
11
  | **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | **MIT** | **LP, MIP, Convex QP** | Industrial-scale optimization, operations research, finance | **Built-in default** (zero configuration) |
12
- | **[Z3](https://github.com/Z3Prover/z3)** (via [`z3-solver`](https://www.npmjs.com/package/z3-solver)) | **MIT** | **SMT, SAT, Logic, MIP** | Propositional logic, conflict diagnosis (`unsatCore`), rule engines | Optional plugin (`@ohtaman/washi/solvers/z3`) |
13
- | **[GLPK](https://www.gnu.org/software/glpk/)** (via [`glpk.js`](https://www.npmjs.com/package/glpk.js)) | **GPL-3.0** | **LP, MIP** | Academic benchmarks, legacy GLPK compatibility | Optional plugin (`@ohtaman/washi/solvers/glpk`) |
12
+ | **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** | **MIT** | **CP, LCG, Logic, Bounded Integer** | Disjunctive scheduling, CP global constraints, zero-COOP/COEP `unsatCore` | **Bundled plugin** (`@ohtaman/washi/solvers/pumpkin`, zero external deps) |
13
+ | **[Z3](https://github.com/Z3Prover/z3)** (via [`z3-solver`](https://www.npmjs.com/package/z3-solver)) | **MIT** | **SMT, SAT, Logic, MIP** | Propositional logic, conflict diagnosis (`unsatCore`), rule engines | Optional peer plugin (`@ohtaman/washi/solvers/z3`, requires `z3-solver`) |
14
+ | **[GLPK](https://www.gnu.org/software/glpk/)** (via [`glpk.js`](https://www.npmjs.com/package/glpk.js)) | **GPL-3.0** | **LP, MIP** | Academic benchmarks, legacy GLPK compatibility | Optional peer plugin (`@ohtaman/washi/solvers/glpk`, requires `glpk.js`) |
14
15
  | **Mock** | **MIT** | *Any* | Ultra-fast unit testing in CI without loading WebAssembly | Built-in |
15
16
 
16
17
  ---
@@ -23,20 +24,25 @@ Specify the solver by name when creating your `Model`:
23
24
  // 1. Built-in HiGHS (default)
24
25
  const m1 = new Model({ solver: "highs" });
25
26
 
26
- // 2. Z3 SMT solver
27
+ // 2. Pumpkin CP/LCG solver (bundled WASM, zero COOP/COEP)
28
+ import "@ohtaman/washi/solvers/pumpkin";
29
+ const m2 = new Model({ solver: "pumpkin" });
30
+
31
+ // 3. Z3 SMT solver
27
32
  import "@ohtaman/washi/solvers/z3";
28
- const m2 = new Model({ solver: "z3" });
33
+ const m3 = new Model({ solver: "z3" });
29
34
 
30
- // 3. GLPK solver
35
+ // 4. GLPK solver
31
36
  import "@ohtaman/washi/solvers/glpk";
32
- const m3 = new Model({ solver: "glpk" });
37
+ const m4 = new Model({ solver: "glpk" });
33
38
  ```
34
39
 
35
40
  ---
36
41
 
37
42
  ## Solver Guides
38
43
 
39
- - [HiGHS Guide](./highs.md): Web Worker multithreading, MIP tolerances, and QP solving.
44
+ - [HiGHS Guide](./highs.md): Background Web Worker execution, MIP tolerances, and Convex QP solving.
45
+ - [Pumpkin Guide](./pumpkin.md): Bundled LCG constraint programming, background Web Worker execution, CP global constraints, warm starts, and zero-COOP/COEP `unsatCore`.
40
46
  - [Z3 Guide](./z3.md): SMT assertions, logic modeling, and Unsat Core analysis.
41
47
  - [GLPK Guide](./glpk.md): GLPK adapter, GPL-3.0 licensing considerations, and browser usage.
42
48
  - [Custom Solvers](./custom-solver.md): Step-by-step developer tutorial for integrating proprietary or cloud REST solvers.
@@ -0,0 +1,163 @@
1
+ # Pumpkin Constraint Programming Solver
2
+
3
+ **Pumpkin** is a Lazy Clause Generation (LCG) constraint programming solver developed in pure Rust by ConSol Lab at TU Delft ([ConSol-Lab/Pumpkin](https://github.com/ConSol-Lab/Pumpkin) · [docs.rs/pumpkin-core](https://docs.rs/pumpkin-core)). WaSHI compiles Pumpkin (`v0.5.0`) directly to WebAssembly and bundles it in `@ohtaman/washi/solvers/pumpkin` with zero external runtime dependencies.
4
+
5
+ Unlike multi-threaded WASM engines, Pumpkin runs as a single-threaded WebAssembly instance inside a Web Worker (or directly in Node.js) and **does not require Cross-Origin Isolation (`COOP` / `COEP`) headers** in browsers.
6
+
7
+ ---
8
+
9
+ ## Key Features in WaSHI
10
+
11
+ - **Bundled & Zero External Dependencies**: `pumpkin.wasm` (`~1.4 MB`) is shipped directly with `@ohtaman/washi` and tree-shaken into `@ohtaman/washi/solvers/pumpkin`—no separate `npm install` peer dependency or Rust toolchain required.
12
+ - **Permissive MIT License**: 100% commercially friendly, including all transitive Rust WASM dependencies (`MIT`, `Apache-2.0`, `Unicode-3.0`).
13
+ - **Background Web Worker & Zero `COOP` / `COEP`**: Runs in a dedicated Web Worker on HTTP(S) origins without `SharedArrayBuffer` or Cross-Origin Isolation headers, keeping UI rendering responsive while working in standard static hosts and third-party iframes.
14
+ - **Native CP Global Constraints & Propagators**: Lowers `distinct()` (`all_different` via pairwise `binary_not_equals` in Pumpkin `v0.5.0`), `disjoint()` (`disjunctive_strict` Vilím edge-finding), `cumulative()` (time-table filtering), `allowed()` / `not(allowed())` (`table` / `negative_table`), `at()` (`element`), `max()` / `min()` / `abs()` (`maximum` / `minimum` / `absolute`), discrete `!=` (`not_equals`), and `m.indicator()` (with `M` omitted, via `implied_by`) directly to Pumpkin constraints.
15
+ - **Zero-`COOP` / `COEP` Unsat Core Diagnosis**: `await model.check({ solver: "pumpkin" })` extracts conflicting named rules (`unsatCore` / `conflicts`) over bounded integer and boolean constraints in standard browser contexts.
16
+ - **Warm-Start Support (`initialValue`)**: Supports non-binding primal initial value hints (`initialValue`, `supportsWarmStart: true`) on bounded `Integer` and `Binary` variables in both `solve()` and `check()` via Pumpkin's `WarmStart` brancher (kept distinct from solved `Var.value`).
17
+
18
+ ---
19
+
20
+ ## Supported Problem Classes
21
+
22
+ > [!TIP]
23
+ > **HiGHS vs. Pumpkin vs. Z3**:
24
+ > - Use **HiGHS** (`{ solver: "highs" }`) for Continuous LPs, Convex QPs, or large linear-relaxation-dominated MILPs.
25
+ > - Use **Pumpkin** (`{ solver: "pumpkin" }`) for disjunctive scheduling, CP global constraints, bounded integer + propositional logic models, and zero-`COOP`/`COEP` `unsatCore` extraction.
26
+ > - Use **Z3** (`{ solver: "z3" }`) when you need continuous variables inside `implies(...)` / `not(...)` or arbitrary real-valued SMT arithmetic.
27
+
28
+ ### 1. Disjunctive Scheduling & Global CP Constraints (`model.solve()`)
29
+
30
+ Model unary/cumulative resource scheduling, precedence logic (`implies`, `not`), and global predicates (`disjoint`, `distinct`, `cumulative`, `allowed`, `at`, `max`, `min`, `abs`) directly over bounded integers:
31
+
32
+ ```typescript
33
+ import { Model, disjoint, expr, implies, minimize, not } from "@ohtaman/washi";
34
+ import "@ohtaman/washi/solvers/pumpkin";
35
+
36
+ const model = new Model("SchedulingStep", { solver: "pumpkin" });
37
+
38
+ const s1 = model.integer("start_job1", { lb: 0, ub: 20 });
39
+ const s2 = model.integer("start_job2", { lb: 0, ub: 20 });
40
+ const job1First = model.bool("job1_first");
41
+
42
+ model.constraint(
43
+ disjoint([
44
+ { start: s1, duration: 6 },
45
+ { start: s2, duration: 4 },
46
+ ]),
47
+ "single_machine"
48
+ );
49
+ model.constraint(implies(job1First, expr`${s1} + 6 <= ${s2}`), "job1_before_job2");
50
+ model.constraint(implies(not(job1First), expr`${s2} + 4 <= ${s1}`), "job2_before_job1");
51
+
52
+ model.objective(minimize(expr`${s1} + ${s2}`));
53
+ await model.solve();
54
+
55
+ console.log(`Status: ${model.status}, s1=${s1.value}, s2=${s2.value}`);
56
+ ```
57
+
58
+ ### 2. Satisfiability & Unsat Core Diagnosis (`model.check()`)
59
+
60
+ Call `await model.check()` to verify satisfiability over integer linear constraints, CP global constraints, and nested propositional logic (`and`, `or`, `not`, `implies`, `xor`), and isolate conflicting named rules (`conflicts` / `unsatCore`) when unsatisfiable:
61
+
62
+ ```typescript
63
+ import { Model, expr, implies } from "@ohtaman/washi";
64
+ import "@ohtaman/washi/solvers/pumpkin";
65
+
66
+ const model = new Model("PolicyConflict", { solver: "pumpkin" });
67
+ const vip = model.bool("vip");
68
+ const seats = model.integer("seats", { lb: 0, ub: 20 });
69
+
70
+ model.constraint(vip, "vip_active");
71
+ model.constraint(implies(vip, expr`${seats} >= 8`), "vip_seats");
72
+ model.constraint(expr`${seats} <= 5`, "room_cap");
73
+
74
+ const result = await model.check();
75
+ if (result.status === "Unsat") {
76
+ console.log("Conflicting rules:", result.conflicts); // also on result.unsatCore / model.unsatCore
77
+ }
78
+ ```
79
+
80
+ ---
81
+
82
+ ## Solver Options
83
+
84
+ Pass solver options into `model.solve()` or `model.check()`:
85
+
86
+ ```typescript
87
+ const controller = new AbortController();
88
+
89
+ await model.solve({
90
+ timeLimit: 30.0, // Maximum solve time in seconds
91
+ signal: controller.signal,
92
+ onProgress: (ev) => {
93
+ console.log(`Elapsed: ${ev.elapsedTime.toFixed(1)}s, Best: ${ev.objectiveValue}`);
94
+ },
95
+ });
96
+
97
+ // Always check hasPrimalSolution when timeLimit or AbortSignal is used:
98
+ if (model.hasPrimalSolution) {
99
+ console.log(
100
+ `Usable solution (${model.status}, termination: ${model.terminationStatus}):`,
101
+ `obj = ${model.objectiveValue}`
102
+ );
103
+ }
104
+ ```
105
+
106
+ ---
107
+
108
+ ## Domain & API Preconditions
109
+
110
+ Pumpkin is strictly a **bounded integer & boolean CP/LCG solver**. Unsupported constructs are rejected with explicit errors rather than silent rounding or fallbacks:
111
+
112
+ - **Bounded integer / binary / boolean variables only**: All `Var` instances must be finite integers (`Integer` or `Binary`) with `lb` and `ub` within `[-(2^30 - 1), 2^30 - 1]`. Unbounded integers (`-Infinity` / `Infinity`) and `Continuous` variables throw an explicit error.
113
+ - **Integer linear arithmetic**: Constraint coefficients, adjusted RHS values (`rhs - lhs.constant`), and scaled variable bounds must be exact integers within safe signed 32-bit range (`|rhs| + sum_i max(|c_i * lb_i|, |c_i * ub_i|) <= 2^31 - 2`). Objective constants (`f64`) may be fractional.
114
+ - **Unsupported features**: `QuadExpr` objectives/constraints, `Continuous` variables, unbounded variables, and `relax: true` throw explicit errors.
115
+
116
+ ---
117
+
118
+ ## Worker & WASM Configuration in Browsers
119
+
120
+ By default in browsers, `@ohtaman/washi/solvers/pumpkin` resolves the bundled `pumpkin.wasm` and spawns `pumpkin-worker.js` in a dedicated Web Worker on HTTP(S) origins (falling back to main-thread execution on `file:` URLs or opaque-origin sandboxed iframes).
121
+
122
+ To execute synchronously on the main thread (or in environments where Web Workers are prohibited), pass `useWorker: false` to `model.solve()` / `model.check()` or instantiate `PumpkinSolver`:
123
+
124
+ ```typescript
125
+ import { Model } from "@ohtaman/washi";
126
+ import { PumpkinSolver, setPumpkinWasmUrl } from "@ohtaman/washi/solvers/pumpkin";
127
+
128
+ // Option 1: Per solve / check call
129
+ await model.solve({ useWorker: false });
130
+
131
+ // Option 2: When instantiating the solver
132
+ const syncModel = new Model({
133
+ solver: new PumpkinSolver({ useWorker: false }),
134
+ });
135
+
136
+ // Host pumpkin.wasm at a custom path or CDN (globally or per call via { wasmUrl }):
137
+ setPumpkinWasmUrl("/assets/wasm/pumpkin.wasm");
138
+ ```
139
+
140
+ If `pumpkin.wasm` cannot be loaded or returns an HTML SPA fallback instead of a WebAssembly binary, Pumpkin rejects explicitly with the attempted URL and performs **no silent CDN fallback**.
141
+
142
+ ---
143
+
144
+ ## Architecture & WebAssembly Runtime
145
+
146
+ WaSHI compiles its Rust WebAssembly wrapper (`wasm/pumpkin`, linking `pumpkin-core`, `pumpkin-constraints`, `pumpkin-propagators`, and `pumpkin-conflict-resolvers` `v0.5.0` to `wasm32-unknown-unknown`) directly to `pumpkin.wasm` with `wasm-bindgen` bindings.
147
+
148
+ Bundled `pumpkin.wasm` and `runtime.js` / `runtime.d.ts` artifacts are tracked and verified via SHA-256 checksums in `pumpkin.config.json`. Maintainers rebuilding Pumpkin from source can follow the instructions in [`CONTRIBUTING.md`](https://github.com/ohtaman/washi/blob/main/CONTRIBUTING.md#4-rebuilding-webassembly-assets--release-workflow).
149
+
150
+ ### Callbacks & Solver Interactivity
151
+
152
+ - **Progress Monitoring & Cancellation (Supported)**:
153
+ During `solve()`, Pumpkin emits real-time incumbent progress callbacks (`onProgress`, providing `elapsedTime` and `objectiveValue`) and honors `AbortSignal`: browser Web Worker execution supports preemptive mid-solve Worker termination and queue cancellation, while main-thread and Node.js runs poll cooperative `should_abort` checkpoints across branching and termination hooks.
154
+ - **Exact Discrete Optimality**:
155
+ As an exact LCG solver over finite integer domains, Pumpkin proves optimality via nogood clause learning and objective-bound strengthening (`LinearSatUnsat`) rather than LP relaxation tolerances (`relativeGap`, `absoluteGap`, or `presolve`).
156
+
157
+ ---
158
+
159
+ ## References & Upstream Links
160
+
161
+ - **Modeling Guide & Walkthrough**: [Constraint Programming (CP) Modeling](../guide/constraint-programming.md) · [Resource-Constrained Project Scheduling (RCPSP)](../examples/project-scheduling.md)
162
+ - **Source Repository**: [ConSol-Lab/Pumpkin](https://github.com/ConSol-Lab/Pumpkin) (MIT License — ConSol Lab, TU Delft)
163
+ - **Rust Crate & API Docs**: [docs.rs/pumpkin-core](https://docs.rs/pumpkin-core) · [crates.io/crates/pumpkin-core](https://crates.io/crates/pumpkin-core)
@@ -23,6 +23,9 @@ npm install z3-solver
23
23
  3. **Exact Mathematical Guarantees**:
24
24
  Z3 can perform exact rational arithmetic without floating-point inaccuracies.
25
25
 
26
+ > [!TIP]
27
+ > **Z3 vs. Pumpkin vs. HiGHS**: Z3 excels at satisfiability checking (`m.check()`), formal policy verification, implications with continuous or fractional antecedents (`` implies(expr`${temp} <= 50.5`, alarm) ``), and scale-invariant `unsatCore` extraction over mixed continuous/integer theories. For bounded-integer and boolean models where `COOP`/`COEP` headers or `z3-solver` are undesirable, bundled **Pumpkin** (`@ohtaman/washi/solvers/pumpkin`) provides native propositional logic and `unsatCore` extraction without `SharedArrayBuffer`. For numerical LP, MIP, or Convex QP optimization with objective functions over tens or hundreds of variables, use the built-in **HiGHS** solver (`m.solve()`), whose simplex relaxations and branch-and-bound cutting planes are orders of magnitude faster than `Z3.Optimize`. Or combine them in a hybrid pipeline: verify/diagnose rules with Z3 or Pumpkin `m.check()`, then optimize costs with HiGHS `m.solve()`.
28
+
26
29
  ---
27
30
 
28
31
  ## Basic Usage
@@ -68,7 +71,7 @@ if (result.status === "Unsat") {
68
71
 
69
72
  ## Browser Security Note
70
73
 
71
- In browser environments, the Z3 WASM engine relies on pthreads and `SharedArrayBuffer`, which require cross-origin isolation headers (`COOP` / `COEP`). See the [Cross-Origin Isolation Guide](../getting-started/cross-origin.md) for detailed setup.
74
+ In browser environments, the Z3 WASM engine relies on pthreads and `SharedArrayBuffer`, which require cross-origin isolation headers (`COOP` / `COEP`). See the [Cross-Origin Isolation Guide](../getting-started/cross-origin.md) for detailed setup. If your model uses only bounded integers and booleans and you cannot configure `COOP` / `COEP` headers (or want zero external dependencies), use the bundled [Pumpkin solver](./pumpkin.md) (`@ohtaman/washi/solvers/pumpkin`) instead.
72
75
 
73
76
  ## Runtime Failures and Thread Cleanup
74
77