@ohtaman/washi 0.7.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/README.ja.md +60 -23
  2. package/README.md +59 -22
  3. package/README.zh-CN.md +62 -25
  4. package/THIRD_PARTY_LICENSES.md +34 -1
  5. package/dist/browser/solvers/glpk.js +289 -238
  6. package/dist/browser/solvers/glpk.min.js +1 -1
  7. package/dist/browser/solvers/highs-__vite-browser-external-Dn-83hnF.js +7 -0
  8. package/dist/browser/solvers/highs-browser-runtime-0Bgq5ksG.js +2021 -0
  9. package/dist/browser/{loader-DewlSho8.js → solvers/highs-loader-BLY3wzDH.js} +190 -149
  10. package/dist/browser/solvers/highs-worker.js +54 -0
  11. package/dist/browser/solvers/highs.js +1414 -0
  12. package/dist/browser/solvers/highs.wasm +0 -0
  13. package/dist/browser/solvers/pumpkin-_washi-pumpkin-node-runtime-CEKUDK6d.js +9 -0
  14. package/dist/browser/solvers/pumpkin-loader-CvdaKxf4.js +320 -0
  15. package/dist/browser/solvers/pumpkin-worker.js +45 -0
  16. package/dist/browser/solvers/pumpkin.js +1777 -0
  17. package/dist/browser/solvers/pumpkin.wasm +0 -0
  18. package/dist/browser/solvers/pumpkin.wasm.LICENSE +21 -0
  19. package/dist/browser/solvers/z3.js +1600 -1335
  20. package/dist/browser/solvers/z3.min.js +2 -2
  21. package/dist/browser/washi.js +3313 -1699
  22. package/dist/browser/washi.min.js +5 -3
  23. package/dist/lib/solvers/__vite-browser-external-oLchLuMx.js +7 -0
  24. package/dist/lib/solvers/glpk.js +174 -132
  25. package/dist/lib/solvers/highs-browser-runtime.js +2413 -0
  26. package/dist/lib/{highs-node-runtime.js → solvers/highs-node-runtime.js} +1 -1
  27. package/dist/lib/solvers/highs-runtime.js +16 -0
  28. package/dist/lib/solvers/highs-worker.js +54 -0
  29. package/dist/lib/solvers/highs.js +410 -0
  30. package/dist/lib/solvers/highs.wasm +0 -0
  31. package/dist/lib/{loader-BZUQNvh4.js → solvers/loader-CDpPXN_F.js} +138 -116
  32. package/dist/lib/solvers/loader-Ow74Fa1B.js +311 -0
  33. package/dist/lib/solvers/lp-writer-CLScMFbS.js +115 -0
  34. package/dist/lib/solvers/pumpkin-assets.js +1 -0
  35. package/dist/lib/solvers/pumpkin-node-runtime.js +15 -0
  36. package/dist/lib/solvers/pumpkin-worker-factory.js +1 -0
  37. package/dist/lib/solvers/pumpkin-worker.js +45 -0
  38. package/dist/lib/solvers/pumpkin.js +868 -0
  39. package/dist/lib/solvers/pumpkin.wasm +0 -0
  40. package/dist/lib/solvers/pumpkin.wasm.LICENSE +21 -0
  41. package/dist/lib/solvers/registry-CrYRRk9q.js +907 -0
  42. package/dist/lib/solvers/rolldown-runtime-DtPi1Y-2.js +13 -0
  43. package/dist/lib/solvers/types-BGqPkxwu.js +12 -0
  44. package/dist/lib/solvers/z3.js +489 -307
  45. package/dist/lib/washi.js +3905 -1410
  46. package/dist/types/decomposition/benders.d.ts.map +1 -1
  47. package/dist/types/index.d.ts +4 -5
  48. package/dist/types/index.d.ts.map +1 -1
  49. package/dist/types/modeler/boolean-expr.d.ts +137 -29
  50. package/dist/types/modeler/boolean-expr.d.ts.map +1 -1
  51. package/dist/types/modeler/constraint.d.ts +40 -4
  52. package/dist/types/modeler/constraint.d.ts.map +1 -1
  53. package/dist/types/modeler/expression.d.ts +129 -2
  54. package/dist/types/modeler/expression.d.ts.map +1 -1
  55. package/dist/types/modeler/index.d.ts +4 -6
  56. package/dist/types/modeler/index.d.ts.map +1 -1
  57. package/dist/types/modeler/linearizer.d.ts +11 -2
  58. package/dist/types/modeler/linearizer.d.ts.map +1 -1
  59. package/dist/types/modeler/lp-writer.d.ts.map +1 -1
  60. package/dist/types/modeler/model.d.ts +86 -126
  61. package/dist/types/modeler/model.d.ts.map +1 -1
  62. package/dist/types/modeler/parser.d.ts.map +1 -1
  63. package/dist/types/modeler/quad-expr.d.ts +8 -2
  64. package/dist/types/modeler/quad-expr.d.ts.map +1 -1
  65. package/dist/types/modeler/solution-validator.d.ts +12 -12
  66. package/dist/types/modeler/solution-validator.d.ts.map +1 -1
  67. package/dist/types/modeler/solvers/glpk/loader.d.ts +4 -0
  68. package/dist/types/modeler/solvers/glpk/loader.d.ts.map +1 -1
  69. package/dist/types/modeler/solvers/glpk/solver.d.ts +2 -2
  70. package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
  71. package/dist/types/modeler/solvers/highs/driver.d.ts.map +1 -1
  72. package/dist/types/modeler/solvers/highs/loader.d.ts +8 -6
  73. package/dist/types/modeler/solvers/highs/loader.d.ts.map +1 -1
  74. package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
  75. package/dist/types/modeler/solvers/highs/worker-client.d.ts +16 -0
  76. package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
  77. package/dist/types/modeler/solvers/index.d.ts +2 -1
  78. package/dist/types/modeler/solvers/index.d.ts.map +1 -1
  79. package/dist/types/modeler/solvers/mock.d.ts +2 -3
  80. package/dist/types/modeler/solvers/mock.d.ts.map +1 -1
  81. package/dist/types/modeler/solvers/pumpkin/assets.d.ts +2 -0
  82. package/dist/types/modeler/solvers/pumpkin/assets.d.ts.map +1 -0
  83. package/dist/types/modeler/solvers/pumpkin/index.d.ts +6 -0
  84. package/dist/types/modeler/solvers/pumpkin/index.d.ts.map +1 -0
  85. package/dist/types/modeler/solvers/pumpkin/loader.d.ts +40 -0
  86. package/dist/types/modeler/solvers/pumpkin/loader.d.ts.map +1 -0
  87. package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts +3 -0
  88. package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts.map +1 -0
  89. package/dist/types/modeler/solvers/pumpkin/solver.d.ts +23 -0
  90. package/dist/types/modeler/solvers/pumpkin/solver.d.ts.map +1 -0
  91. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts +74 -0
  92. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts.map +1 -0
  93. package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts +3 -0
  94. package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts.map +1 -0
  95. package/dist/types/modeler/solvers/pumpkin/worker.d.ts +7 -0
  96. package/dist/types/modeler/solvers/pumpkin/worker.d.ts.map +1 -0
  97. package/dist/types/modeler/solvers/pumpkin.d.ts +2 -0
  98. package/dist/types/modeler/solvers/pumpkin.d.ts.map +1 -0
  99. package/dist/types/modeler/solvers/types.d.ts +7 -9
  100. package/dist/types/modeler/solvers/types.d.ts.map +1 -1
  101. package/dist/types/modeler/solvers/z3/loader.d.ts +4 -0
  102. package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
  103. package/dist/types/modeler/solvers/z3/solver.d.ts +2 -15
  104. package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -1
  105. package/dist/types/modeler/types.d.ts +12 -15
  106. package/dist/types/modeler/types.d.ts.map +1 -1
  107. package/dist/types/modeler/validation.d.ts +26 -2
  108. package/dist/types/modeler/validation.d.ts.map +1 -1
  109. package/dist/types/modeler/variable.d.ts +9 -5
  110. package/dist/types/modeler/variable.d.ts.map +1 -1
  111. package/docs/examples/diet-sensitivity.md +33 -14
  112. package/docs/examples/ecommerce-coupons.md +17 -9
  113. package/docs/examples/index.md +36 -27
  114. package/docs/examples/knapsack.md +11 -5
  115. package/docs/examples/portfolio-qp.md +21 -8
  116. package/docs/examples/production.md +10 -5
  117. package/docs/examples/project-scheduling.md +119 -0
  118. package/docs/examples/shift-scheduling.md +29 -18
  119. package/docs/examples/smt-security.md +27 -11
  120. package/docs/examples/transportation.md +23 -13
  121. package/docs/examples/traveling-salesperson.md +34 -22
  122. package/docs/examples/unsat-core.md +27 -14
  123. package/docs/examples/vehicle-routing.md +74 -28
  124. package/docs/getting-started/ai-agents.md +190 -82
  125. package/docs/getting-started/coding-agents.md +177 -0
  126. package/docs/getting-started/cross-origin.md +27 -14
  127. package/docs/getting-started/index.md +49 -43
  128. package/docs/getting-started/runtimes.md +94 -40
  129. package/docs/guide/constraint-programming.md +171 -0
  130. package/docs/guide/constraints.md +115 -33
  131. package/docs/guide/decomposition.md +118 -88
  132. package/docs/guide/expressions.md +106 -43
  133. package/docs/guide/formulation-tips.md +47 -28
  134. package/docs/guide/objectives.md +102 -75
  135. package/docs/guide/unsat-core.md +62 -50
  136. package/docs/guide/variables.md +81 -35
  137. package/docs/solvers/custom-solver.md +163 -122
  138. package/docs/solvers/glpk.md +58 -17
  139. package/docs/solvers/highs.md +124 -57
  140. package/docs/solvers/index.md +33 -20
  141. package/docs/solvers/pumpkin.md +171 -0
  142. package/docs/solvers/z3.md +63 -25
  143. package/llms-full.txt +2232 -932
  144. package/llms.txt +144 -91
  145. package/package.json +55 -19
  146. package/skills/washi/SKILL.md +107 -34
  147. package/dist/browser/_washi-node-only-BvRk9kiK.js +0 -0
  148. package/dist/browser/browser-runtime-TLCY0hkc.js +0 -1793
  149. package/dist/browser/highs-worker.js +0 -39
  150. package/dist/browser/highs.wasm +0 -0
  151. package/dist/lib/_washi-node-only-BvRk9kiK.js +0 -0
  152. package/dist/lib/highs-browser-runtime.js +0 -2185
  153. package/dist/lib/highs-runtime.js +0 -2
  154. package/dist/lib/highs-worker.js +0 -39
  155. package/dist/lib/highs.wasm +0 -0
  156. package/dist/lib/registry-D7TZ3Wh_.js +0 -1034
  157. package/docs/ja/getting-started/ai-agents.md +0 -280
  158. package/docs/zh/getting-started/ai-agents.md +0 -280
  159. /package/dist/browser/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
  160. /package/dist/lib/{highs-assets.js → solvers/highs-assets.js} +0 -0
  161. /package/dist/lib/{highs-worker-factory.js → solvers/highs-worker-factory.js} +0 -0
  162. /package/dist/lib/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
@@ -1,6 +1,15 @@
1
1
  # GLPK Solver Engine
2
2
 
3
- The **GNU Linear Programming Kit (GLPK)** is a long-standing, robust simplex and interior-point solver package intended for solving large-scale linear programming (LP) and mixed integer programming (MIP).
3
+ The **GNU Linear Programming Kit (GLPK)** is an open-source simplex and branch-and-cut solver for Linear Programming (LP) and Mixed-Integer Programming (MIP).
4
+
5
+ ---
6
+
7
+ ## When to Choose GLPK vs. HiGHS
8
+
9
+ | Scenario | Recommended Solver | Why |
10
+ | :--- | :--- | :--- |
11
+ | **General LP or MIP optimization** | **[HiGHS](./highs.md)** (default) | Bundled under MIT, faster on MIP, non-blocking Web Worker, warm starts, and full LP duals/slacks/reduced costs. |
12
+ | **Academic benchmarks or cross-checking GLPK models** | **GLPK** (`@ohtaman/washi/solvers/glpk`) | Matches GNU GLPK 5.0 behavior when reproducing existing GLPK benchmarks or verifying results across solvers. |
4
13
 
5
14
  ---
6
15
 
@@ -16,16 +25,18 @@ npm install glpk.js
16
25
 
17
26
  ## Licensing Consideration (GPL-3.0)
18
27
 
19
- GLPK is licensed under the **GNU General Public License v3.0 (GPL-3.0)**.
28
+ GLPK is licensed under the **GNU General Public License v3.0 (GPL-3.0)**:
20
29
 
21
30
  - Because WaSHI is MIT-licensed, `glpk.js` is **never bundled statically** in the core package.
22
- - It is dynamically imported only if you explicitly register or invoke `@ohtaman/washi/solvers/glpk`.
23
- - Ensure your project's distribution requirements comply with the GPL-3.0 license when shipping products that bundle GLPK.
31
+ - It is loaded dynamically only when you explicitly import `@ohtaman/washi/solvers/glpk`.
32
+ - Verify that your distribution strategy complies with GPL-3.0 before shipping products that bundle GLPK.
24
33
 
25
34
  ---
26
35
 
27
36
  ## Basic Usage
28
37
 
38
+ Import `@ohtaman/washi/solvers/glpk` once to register the `"glpk"` solver, then build and solve LP or MIP models using the standard `Model` API:
39
+
29
40
  ```typescript
30
41
  import { Model, expr, maximize } from "@ohtaman/washi";
31
42
  import "@ohtaman/washi/solvers/glpk";
@@ -36,31 +47,61 @@ const x = model.continuous("x", { lb: 0, ub: 10 });
36
47
  const y = model.continuous("y", { lb: 0, ub: 20 });
37
48
 
38
49
  model.objective(maximize(expr`3 * ${x} + 2 * ${y}`));
39
- model.constraint(expr`${x} + ${y} <= 15`, "cap");
50
+ const cap = model.constraint(expr`${x} + ${y} <= 15`, "cap");
40
51
 
41
52
  await model.solve();
42
53
 
43
- console.log("GLPK Status:", model.status);
44
- console.log("Objective:", model.objectiveValue);
54
+ console.log("GLPK Status:", model.status); // Optimal
55
+ console.log("Objective:", model.objectiveValue); // 40
56
+ console.log("Shadow price:", cap.dual); // 2
45
57
  ```
46
58
 
47
59
  ---
48
60
 
61
+ ## Solver Options & Execution Model
62
+
63
+ WaSHI's `useWorker: true` option is not supported on GLPK and throws an `Error`. In browsers, `glpk.js` automatically runs in its own internal Web Worker (call `terminateGlpk()` from `@ohtaman/washi/solvers/glpk` to shut it down), while in Node.js it executes synchronously on the main thread. In all environments, `signal` is checked only before solving begins and cannot interrupt an in-flight solve.
64
+
65
+ ### Supported Options
66
+
67
+ | Option | Type | Description |
68
+ | :--- | :--- | :--- |
69
+ | `timeLimit` | `number` | Maximum solve time in seconds (`tmlim`). |
70
+ | `relativeGap` | `number` | Relative MIP optimality gap tolerance (`mipgap`). |
71
+ | `presolve` | `"on" \| "off" \| "choose"` | Controls GLPK presolve (enabled by default; `"off"` disables it, `"on"` and `"choose"` enable it). |
72
+ | `verbose` | `boolean` | Enables GLPK console logging (`false` by default). |
73
+ | `relax` | `boolean` | Solves the continuous LP relaxation of a MIP model. |
74
+ | `signal` | `AbortSignal` | Checked before execution starts (cannot interrupt an in-flight solve). |
75
+ | `onProgress` | `(ev) => void` | Invoked during MIP branch-and-cut callbacks, or once when the solve completes. |
76
+
77
+ ### Unsupported Options & Features (Throw at Runtime)
78
+
79
+ - **`outputFlag`**: Throws an `Error`. Use `verbose: true` instead.
80
+ - **Other unsupported options**: `absoluteGap`, `threads`, `useWorker: true`, and unknown option keys throw an `Error`.
81
+ - **Unsupported model features**: Setting `initialValue` warm starts or a `QuadExpr` quadratic objective throws an `Error`.
82
+
83
+ ---
84
+
49
85
  ## Result Semantics & Status Mapping
50
86
 
51
87
  ### Solver Statuses
52
- GLPK return codes are mapped strictly to WaSHI `SolverStatus`:
53
- - `GLP_OPT` (5) $\to$ `"Optimal"`
54
- - `GLP_FEAS` (2) $\to$ `"Feasible"` (feasible MIP incumbent found)
55
- - `GLP_INFEAS` (3) / `GLP_NOFEAS` (4) $\to$ `"Infeasible"`
56
- - `GLP_UNBND` (6) $\to$ `"Unbounded"`
57
- - `GLP_UNDEF` (1) and unrecognized/missing statuses $\to$ `"Unknown"` (never misclassified as `"Optimal"`)
88
+
89
+ GLPK return codes map strictly to WaSHI `SolverStatus`:
90
+
91
+ | GLPK Code | WaSHI Status | Meaning |
92
+ | :--- | :--- | :--- |
93
+ | `GLP_OPT` (5) | `"Optimal"` | Proven optimal solution found. |
94
+ | `GLP_FEAS` (2) | `"Feasible"` | Feasible solution found (optimality not proven). |
95
+ | `GLP_INFEAS` (3) / `GLP_NOFEAS` (4) | `"Infeasible"` | No feasible solution exists. |
96
+ | `GLP_UNBND` (6) | `"Unbounded"` | Objective is unbounded. |
97
+ | `GLP_UNDEF` (1) / other | `"Unknown"` | Undefined or unrecognized status (never mapped to `"Optimal"`). |
58
98
 
59
99
  ### Solution Availability
60
- - Variable values (`model.values`, `var.value`) and objective values (`model.objectiveValue`) are exposed **only** when a valid primal solution is available (`"Optimal"` or `"Feasible"`).
61
- - For unsuccessful or non-optimal solves (`Infeasible`, `Unbounded`, `Unknown`, `Error`), `model.objectiveValue` is `null` and variable values remain `null` without fabricating fake all-zero solutions.
100
+
101
+ - Variable values (`model.values`, `var.value`) and `model.objectiveValue` are populated only for `"Optimal"` or `"Feasible"` outcomes.
102
+ - On `"Infeasible"`, `"Unbounded"`, `"Unknown"`, or `"Error"` outcomes, `model.objectiveValue` and variable values remain `null`.
62
103
 
63
104
  ### Differences Between LP and MIP
64
- - **Linear Programming (LP)**: Solved using the simplex algorithm. Dual values (shadow prices via `constraint.dual`) and slacks are populated for optimal solutions.
65
- - **Mixed-Integer Programming (MIP)**: Solved using the branch-and-cut algorithm. Produces integer-feasible primal variable solutions; dual values are mathematically undefined for discrete optimization and omitted.
66
105
 
106
+ - **Linear Programming (LP)**: Solved via simplex. For sensitivity information on optimal solutions, only constraint duals (`c.dual`) are populated; `c.slack` and `v.reducedCost` remain `null`.
107
+ - **Mixed-Integer Programming (MIP)**: Solved via branch-and-cut. MIP models do not produce LP duals, and `glpk.js` does not expose MIP dual bounds or gaps (`objectiveBound`, `relativeGap`, and `absoluteGap` remain `undefined`).
@@ -1,45 +1,32 @@
1
1
  # HiGHS Solver Engine
2
2
 
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).
3
+ **HiGHS** is an open-source mathematical optimization solver started at the University of Edinburgh ([highs.dev](https://highs.dev/) · [ERGO-Code/HiGHS](https://github.com/ERGO-Code/HiGHS)). It solves Linear Programming (LP), Mixed-Integer Programming (MIP), and convex Quadratic Programming (QP) problems.
4
4
 
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.
5
+ In `@ohtaman/washi`, HiGHS is the built-in default solver under the MIT license. It ships as a single-threaded WebAssembly binary with zero external dependencies, runs in Node.js and browser Web Workers, and requires no `SharedArrayBuffer` or `COOP`/`COEP` headers (see [Cross-Origin Isolation](../getting-started/cross-origin.md)).
6
6
 
7
7
  ---
8
8
 
9
- ## Key Features in WaSHI
9
+ ## When to Choose HiGHS
10
10
 
11
- - **Built-in & Zero-Config**: Bundled directly with `@ohtaman/washi` with zero external runtime dependencies. No separate peer dependency or C++ compiler required.
12
- - **Permissive MIT License**: 100% commercially friendly.
13
- - **Background Web Worker Execution**: Automatically offloads solving to a dedicated Web Worker in browser environments to avoid freezing the UI thread.
14
- - **Warm-Start Support (`initialValue`)**: Supports passing variable primal initial value hints (`initialValue`) to HiGHS `setSolution` for warm starting.
15
- - **Fast WASM Execution**: Runs the directly compiled 32-bit WebAssembly binary at near-native speed.
11
+ | Problem Type | Recommended Solver | Why |
12
+ | :--- | :--- | :--- |
13
+ | **LP, MIP, or continuous convex QP** | **HiGHS** (default) | Bundled under MIT, fast numerical solving, LP duals/slacks/reduced costs, and MIP warm starts. |
14
+ | **Bounded-integer Constraint Programming (CP)** | **[Pumpkin](./pumpkin.md)** | Native `disjoint`, `cumulative`, `distinct`, and `unsatCore` without Cross-Origin Isolation headers. |
15
+ | **Logical rules with `Continuous` variables** | **[Z3](./z3.md)** | Exact arithmetic inside logical operators and mixed continuous/integer `unsatCore`. |
16
+ | **GNU GLPK compatibility or benchmarking** | **[GLPK](./glpk.md)** | Optional GPL-3.0 peer dependency for cross-checking legacy GLPK models. |
16
17
 
17
- ---
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 Exposed in WASM Driver)**:
28
- 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.
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 WaSHI's 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`).
18
+ > [!TIP]
19
+ > Start with **HiGHS** for almost all numerical optimization models. Switch to **Pumpkin** or **Z3** when you need native CP propagation or Satisfiability Modulo Theories (SMT) conflict diagnosis.
36
20
 
37
21
  ---
38
22
 
39
23
  ## Supported Problem Classes
40
24
 
25
+ HiGHS uses a single `Model` interface across continuous, discrete, and quadratic problems. Choose the variable types and objective form that match your problem class.
26
+
41
27
  ### 1. Linear Programming (LP)
42
- Solves continuous problems via Primal and Dual Simplex algorithms or Interior Point (IPM) methods. After solving, you can inspect constraint shadow prices (`c.dual`), slacks (`c.slack`), and variable reduced costs (`v.reducedCost`):
28
+
29
+ LP models use continuous variables, linear constraints, and a linear objective. HiGHS solves them with simplex or interior-point methods, populating `c.dual` shadow prices, `c.slack` slacks, and `v.reducedCost` reduced costs:
43
30
 
44
31
  ```typescript
45
32
  import { Model, expr, maximize } from "@ohtaman/washi";
@@ -47,83 +34,164 @@ import { Model, expr, maximize } from "@ohtaman/washi";
47
34
  const model = new Model({ solver: "highs" });
48
35
  const x = model.continuous("x", { lb: 0 });
49
36
  const y = model.continuous("y", { lb: 0 });
37
+
50
38
  model.objective(maximize(expr`10 * ${x} + 6 * ${y}`));
51
- model.constraint(expr`${x} + ${y} <= 100`, "cap");
39
+ const cap = model.constraint(expr`${x} + ${y} <= 100`, "cap");
40
+
52
41
  await model.solve();
42
+ console.log(model.status, model.objectiveValue, cap.dual, cap.slack);
53
43
  ```
54
44
 
55
- ### 2. Mixed-Integer Linear Programming (MIP)
56
- Solves discrete problems using Branch-and-Bound and cutting plane techniques:
45
+ ### 2. Mixed-Integer Programming (MIP)
46
+
47
+ MIP models include `model.integer()` or `model.binary()` variables (optionally combined with continuous variables) and accept warm-start hints via `initialValue`. HiGHS solves them via branch-and-cut and reports `objectiveBound`, `relativeGap`, and `absoluteGap`:
57
48
 
58
49
  ```typescript
59
- const count = model.integer("count", { lb: 0, ub: 50 });
50
+ import { Model, expr, maximize } from "@ohtaman/washi";
51
+
52
+ const mipModel = new Model({ solver: "highs" });
53
+ const count = mipModel.integer("count", { lb: 0, ub: 50 });
54
+ const open = mipModel.binary("open");
55
+
56
+ mipModel.objective(maximize(expr`12 * ${count} - 100 * ${open}`));
57
+ mipModel.constraint(expr`${count} <= 50 * ${open}`, "link");
58
+
59
+ await mipModel.solve();
60
+ console.log(mipModel.status, count.value, open.value);
60
61
  ```
61
62
 
62
63
  ### 3. Convex Quadratic Programming (QP)
63
- Solves continuous models with convex quadratic objective functions subject to linear constraints:
64
+
65
+ QP models optimize a convex quadratic objective (or concave when maximizing) over continuous variables subject to linear constraints:
64
66
 
65
67
  ```typescript
66
- // Minimize risk/variance uniformly using expr:
67
- model.objective(minimize(expr`0.5 * ${x}^2 + 0.5 * ${y}^2`));
68
+ import { Model, expr, minimize } from "@ohtaman/washi";
68
69
 
69
- // Or programmatically with .mul():
70
- // const quadObj = x.mul(x).mul(0.5).add(y.mul(y).mul(0.5));
71
- // model.objective(minimize(quadObj));
70
+ const qpModel = new Model({ solver: "highs" });
71
+ const x = qpModel.continuous("x", { lb: 0 });
72
+ const y = qpModel.continuous("y", { lb: 0 });
73
+
74
+ qpModel.constraint(expr`${x} + ${y} >= 10`, "demand");
75
+ qpModel.objective(minimize(expr`0.5 * ${x}^2 + 0.5 * ${y}^2`));
76
+
77
+ await qpModel.solve();
78
+ console.log(qpModel.status, qpModel.objectiveValue, x.value, y.value);
79
+ // Optimal 25 5 5
72
80
  ```
73
81
 
74
82
  > [!NOTE]
75
- > **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).
83
+ > **Continuous convex QP only**: Every variable in a QP model must be continuous (`model.continuous()`). When minimizing, the quadratic matrix $\mathbf{Q}$ must be positive semi-definite; when maximizing, it must be negative semi-definite.
84
+ >
85
+ > Mixed-Integer Quadratic Programming and quadratic constraints are not supported. To linearize products of binary variables as a MIP, see [Formulation Patterns & Tips](../guide/formulation-tips.md).
76
86
 
77
87
  ---
78
88
 
79
89
  ## Solver Options
80
90
 
81
- Pass solver options into `model.solve()`:
91
+ Pass execution options into `model.solve()` or the `HighsSolver` constructor. HiGHS validates option keys strictly and throws an `Error` on unsupported keys so misconfigurations fail early.
92
+
93
+ ### Supported Options
94
+
95
+ | Option | Type | Description |
96
+ | :--- | :--- | :--- |
97
+ | `timeLimit` | `number` | Maximum solve time in seconds. |
98
+ | `relativeGap` | `number` | Stop when the relative MIP optimality gap falls within this tolerance. |
99
+ | `absoluteGap` | `number` | Stop when the absolute MIP optimality gap falls within this tolerance. |
100
+ | `presolve` | `"on" \| "off" \| "choose"` | Controls model presolve before optimization. |
101
+ | `outputFlag` | `boolean` | Enables internal solver logs (`false` by default). |
102
+ | `relax` | `boolean` | Solves the continuous LP relaxation of a MIP model without modifying variable declarations. |
103
+ | `useWorker` | `boolean` | Runs HiGHS in a browser Web Worker (`true` by default in browsers; falls back to `false` on `file:` URLs or opaque origins). Passing `useWorker: true` in Node.js throws an `Error`. |
104
+ | `wasmUrl` | `string` | Overrides the `highs.wasm` asset URL for this call (call `setHighsWasmUrl(null)` to reset to the bundled binary). |
105
+ | `signal` | `AbortSignal` | Cancels an in-flight solve. In a browser Web Worker, aborts preemptively and returns the last captured MIP incumbent if available; on the main thread or in Node.js, cancels cooperatively. |
106
+ | `onProgress` | `(ev) => void` | Receives live elapsed time, primal objective, dual bound, and gap updates. |
107
+
108
+ HiGHS also accepts these passthrough limit keys: `mip_max_nodes`, `mip_max_improving_sols`, `mip_max_leaves`, `simplex_iteration_limit`, and `ipm_iteration_limit`.
109
+
110
+ ### Unsupported Options (Throw at Runtime)
111
+
112
+ - `verbose`: Throws an `Error`. Use `outputFlag: true` instead.
113
+ - `threads`: Throws an `Error` because HiGHS WebAssembly runs single-threaded.
114
+ - Unknown option keys: Any unrecognized key throws an `Error`.
115
+
116
+ ### Example with Time Limit, Progress, and Cancellation
82
117
 
83
118
  ```typescript
119
+ import { Model, expr, maximize } from "@ohtaman/washi";
120
+
121
+ const model = new Model({ solver: "highs" });
122
+ const x = model.integer("x", { lb: 0, ub: 100 });
123
+ const y = model.integer("y", { lb: 0, ub: 100 });
124
+ model.objective(maximize(expr`10 * ${x} + 6 * ${y}`));
125
+ model.constraint(expr`${x} + ${y} <= 100`, "cap");
126
+
84
127
  const controller = new AbortController();
85
128
 
86
129
  await model.solve({
87
- timeLimit: 60.0, // Maximum solve time in seconds
88
- mipGap: 0.001, // Terminate when within 0.1% of global optimality (alias: relGap)
89
- absGap: 1.0, // Absolute MIP optimality gap tolerance
90
- presolve: "on", // Presolve control ("on" | "off" | "choose")
91
- outputFlag: true, // Output internal simplex / branch-and-bound logs (output_flag)
130
+ timeLimit: 60.0,
131
+ relativeGap: 0.001,
132
+ absoluteGap: 1.0,
133
+ presolve: "on",
134
+ outputFlag: true,
92
135
  signal: controller.signal,
93
136
  onProgress: (ev) => {
94
137
  console.log(`Elapsed: ${ev.elapsedTime.toFixed(1)}s, Best: ${ev.objectiveValue}`);
95
138
  },
96
139
  });
97
140
 
98
- // Always check hasPrimalSolution when timeLimit or AbortSignal is used:
99
141
  if (model.hasPrimalSolution) {
100
142
  console.log(
101
- `Usable solution (${model.status}, termination: ${model.terminationStatus}):`,
102
- `obj = ${model.objectiveValue}, gap = ${((model.relGap ?? 0) * 100).toFixed(2)}%`
143
+ `Solution (${model.status}, termination: ${model.terminationStatus}):`,
144
+ `obj = ${model.objectiveValue}, gap = ${((model.relativeGap ?? 0) * 100).toFixed(2)}%`
103
145
  );
104
146
  }
105
147
  ```
106
148
 
107
149
  ---
108
150
 
109
- ## Worker & WASM Configuration in Browsers
151
+ ## Web Worker & WASM Configuration in Browsers
110
152
 
111
- By default in browsers, WaSHI spawns a dedicated Web Worker to execute HiGHS in the background so UI rendering stays responsive and `onProgress` / `AbortSignal` work seamlessly.
153
+ In browsers, WaSHI runs HiGHS inside a dedicated Web Worker by default. This keeps UI rendering responsive and allows `onProgress` updates and `AbortSignal` cancellation during long solves.
112
154
 
113
- If you need to run synchronously on the main thread (or in environments where Web Workers are prohibited), pass `useWorker: false` to `model.solve()` or instantiate `HighsSolver`:
155
+ To run on the main thread (for example, in environments that restrict Web Workers) or serve `highs.wasm` from a custom path, configure `useWorker`, `setHighsWasmUrl`, or `wasmUrl`:
114
156
 
115
157
  ```typescript
116
- import { Model, HighsSolver } from "@ohtaman/washi";
158
+ import { Model, expr, maximize } from "@ohtaman/washi";
159
+ import { HighsSolver, setHighsWasmUrl } from "@ohtaman/washi/solvers/highs";
160
+
161
+ // Configure a custom WASM URL globally (pass null to restore the bundled asset)
162
+ setHighsWasmUrl("/assets/wasm/highs.wasm");
117
163
 
118
- // Option 1: Per solve call
119
- await model.solve({ useWorker: false });
164
+ const model = new Model({ solver: "highs" });
165
+ const x = model.continuous("x", { lb: 0, ub: 10 });
166
+ model.objective(maximize(expr`${x}`));
167
+
168
+ // Option 1: Disable the Web Worker or override wasmUrl per solve call
169
+ await model.solve({ useWorker: false, wasmUrl: "/assets/wasm/highs.wasm" });
120
170
 
121
- // Option 2: When instantiating the solver
171
+ // Option 2: Configure defaults on a HighsSolver instance
122
172
  const syncModel = new Model({
123
173
  solver: new HighsSolver({ useWorker: false }),
124
174
  });
125
175
  ```
126
176
 
177
+ If `highs.wasm` fails to load or returns an HTML error page, WaSHI throws an error with the attempted URL instead of silently falling back to an external CDN.
178
+
179
+ ---
180
+
181
+ ## Architecture & WebAssembly Runtime
182
+
183
+ > [!NOTE]
184
+ > This optional section covers internal WebAssembly packaging details for maintainers and advanced integrators.
185
+
186
+ WaSHI compiles official HiGHS C++ sources directly to 32-bit WebAssembly (`highs.wasm`) with `-fwasm-exceptions` and `-DHIGHS_NO_DEFAULT_THREADS=ON`. The driver calls HiGHS's native C API (`highs_c_api.h`) directly, using typed-array views over linear memory for zero-copy solution extraction and `setSolution` for MIP warm starts.
187
+
188
+ Bundled `highs.wasm` and `runtime.js` artifacts are verified against SHA-256 checksums in `highs.config.json`. Maintainers rebuilding HiGHS from source can follow [`CONTRIBUTING.md`](https://github.com/ohtaman/washi/blob/main/CONTRIBUTING.md#4-rebuilding-webassembly-assets--release-workflow).
189
+
190
+ ### Callbacks & Solver Interactivity
191
+
192
+ - **Progress & cancellation**: Supported through HiGHS's logging and interrupt callbacks (`onProgress` and `AbortSignal`).
193
+ - **Dynamic cuts & lazy constraints**: Not exposed inside the branch-and-bound tree across the WASM boundary. For subtour elimination or Benders decomposition, use [`await m.solveBenders({ subproblem })`](../guide/decomposition.md#benders-decomposition-solvebenders) or an outer cutting-plane loop.
194
+
127
195
  ---
128
196
 
129
197
  ## References & Upstream Links
@@ -131,6 +199,5 @@ const syncModel = new Model({
131
199
  - **Official Website**: [https://highs.dev/](https://highs.dev/)
132
200
  - **Official Documentation**: [https://ergo-code.github.io/HiGHS/](https://ergo-code.github.io/HiGHS/)
133
201
  - **Source Repository**: [ERGO-Code/HiGHS](https://github.com/ERGO-Code/HiGHS) (MIT License)
134
- - **Academic Citation**: If you cite HiGHS in academic or technical publications, please reference the foundational paper requested by the HiGHS authors:
202
+ - **Academic Citation**: Please cite the foundational HiGHS paper when referencing HiGHS in publications:
135
203
  > 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)
136
-
@@ -1,42 +1,55 @@
1
1
  # Solvers Overview
2
2
 
3
- WaSHI is designed around a pluggable, decoupled solver architecture. You formulate mathematical models using a unified algebraic API, then solve them with the engine best suited for your problem class.
3
+ WaSHI uses a pluggable solver architecture. You write a model once with the unified algebraic API, then run it with the backend that matches your problem class and runtime constraints.
4
4
 
5
5
  ---
6
6
 
7
- ## ⚡ Solvers Matrix & Comparison
7
+ ## Solvers Matrix & Comparison
8
8
 
9
- | Solver | Engine License | Problem Classes | Best For | Status in WaSHI |
9
+ | Solver | License | Problem Classes & Domains | Best For | Packaging & Preconditions |
10
10
  | :--- | :--- | :--- | :--- | :--- |
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`) |
14
- | **Mock** | **MIT** | *Any* | Ultra-fast unit testing in CI without loading WebAssembly | Built-in |
11
+ | **[HiGHS](./highs.md)** | **MIT** | **LP, MIP, Convex QP** (continuous, integer, boolean) | Production optimization, operations research, portfolio QP | **Bundled default** (zero extra deps, no extra import; subpath API: `@ohtaman/washi/solvers/highs`) |
12
+ | **[Pumpkin](./pumpkin.md)** | **MIT** | **CP, Propositional Logic** (bounded integer & boolean only; no `Continuous`) | Non-overlapping scheduling, CP global constraints, discrete `unsatCore` | **Bundled** (`{ solver: "pumpkin" }`, zero extra deps, no extra import; subpath API: `@ohtaman/washi/solvers/pumpkin`) |
13
+ | **[Z3](./z3.md)** (`z3-solver`) | **MIT** | **SMT, SAT, LP/MIP** (continuous, integer, boolean) | Logical rules with continuous variables or decimal coefficients, mixed continuous/integer `unsatCore` diagnosis | **Optional peer** (`@ohtaman/washi/solvers/z3`, requires `z3-solver`); browsers require a Secure Context (`HTTPS`/`localhost`) and `COOP`/`COEP` headers |
14
+ | **[GLPK](./glpk.md)** (`glpk.js`) | **GPL-3.0** | **LP, MIP** (continuous, integer) | Academic benchmarks, legacy GLPK compatibility | **Optional peer** (`@ohtaman/washi/solvers/glpk`, requires `glpk.js`; note GPL-3.0 license) |
15
+ | **Mock** (`MockSolver`) | **MIT** | *Any* (fixed-response stub) | Fast CI unit tests without loading WebAssembly | **Built-in** (`solver: "mock"` or `new MockSolver(...)`) |
15
16
 
16
17
  ---
17
18
 
18
19
  ## Selecting a Solver
19
20
 
20
- Specify the solver by name when creating your `Model`:
21
+ Bundled **HiGHS** (default) and **Pumpkin** (`{ solver: "pumpkin" }`) are ready out of the box with no extra imports. For optional peer plugins (**Z3** and **GLPK**), import the plugin at the top of your module, then choose a solver when constructing `Model` or per call in `solve()` / `check()`:
21
22
 
22
23
  ```typescript
23
- // 1. Built-in HiGHS (default)
24
- const m1 = new Model({ solver: "highs" });
25
-
26
- // 2. Z3 SMT solver
24
+ import { Model, MockSolver, expr, maximize } from "@ohtaman/washi";
27
25
  import "@ohtaman/washi/solvers/z3";
28
- const m2 = new Model({ solver: "z3" });
29
-
30
- // 3. GLPK solver
31
26
  import "@ohtaman/washi/solvers/glpk";
32
- const m3 = new Model({ solver: "glpk" });
27
+
28
+ // 1. Default solver on Model (HiGHS is bundled & default; Pumpkin works with { solver: "pumpkin" })
29
+ const m = new Model({ solver: "highs" });
30
+ const x = m.integer("x", { lb: 0, ub: 10 });
31
+ m.objective(maximize(expr`${x}`));
32
+
33
+ // 2. Override solver per solve() or check() call
34
+ await m.solve({ solver: "highs" });
35
+ await m.solve({ solver: "glpk" });
36
+ // check() ignores the objective and checks constraint satisfiability only
37
+ await m.check({ solver: "pumpkin" });
38
+ await m.check({ solver: "z3" });
39
+
40
+ // 3. Deterministic unit testing without WebAssembly
41
+ const mock = new MockSolver({ status: "Optimal", objectiveValue: 10, values: { x: 10 } });
42
+ await m.solve({ solver: mock });
33
43
  ```
34
44
 
45
+ See [Conflict Diagnosis, Validation & Debugging](../guide/unsat-core.md) for full `MockSolver` testing patterns.
46
+
35
47
  ---
36
48
 
37
49
  ## Solver Guides
38
50
 
39
- - [HiGHS Guide](./highs.md): Background Web Worker execution, MIP tolerances, and Convex QP solving.
40
- - [Z3 Guide](./z3.md): SMT assertions, logic modeling, and Unsat Core analysis.
41
- - [GLPK Guide](./glpk.md): GLPK adapter, GPL-3.0 licensing considerations, and browser usage.
42
- - [Custom Solvers](./custom-solver.md): Step-by-step developer tutorial for integrating proprietary or cloud REST solvers.
51
+ - [HiGHS Solver Guide](./highs.md): Background Web Worker execution, MIP tolerances, Convex QP solving, and progress callbacks.
52
+ - [Pumpkin Solver Guide](./pumpkin.md): Bundled CP / Lazy Clause Generation (LCG) solver, global constraints, warm starts, and discrete `unsatCore` diagnosis.
53
+ - [Z3 Solver Guide](./z3.md): SMT logical constraints, `Continuous` / decimal rules, `unsatCore` extraction, and browser `COOP`/`COEP` setup.
54
+ - [GLPK Solver Guide](./glpk.md): GLPK adapter setup, GPL-3.0 licensing notes, and status mapping.
55
+ - [Custom Solvers](./custom-solver.md): Developer guide for integrating commercial/proprietary, cloud REST, or custom WASM solvers.
@@ -0,0 +1,171 @@
1
+ # Pumpkin Constraint Programming Solver
2
+
3
+ **Pumpkin** is an open-source Constraint Programming (CP) solver written in Rust and maintained by [ConSol-Lab/Pumpkin](https://github.com/ConSol-Lab/Pumpkin). WaSHI bundles Pumpkin (`v0.5.0`, `pumpkin.wasm`, ~2.1 MB) under the MIT license alongside HiGHS with zero extra packages—pass `{ solver: "pumpkin" }` out of the box without any extra plugin import (advanced APIs such as `PumpkinSolver` and `setPumpkinWasmUrl()` are available from `@ohtaman/washi/solvers/pumpkin`).
4
+
5
+ Because Pumpkin runs single-threaded, browsers do not need `SharedArrayBuffer` or `COOP`/`COEP` headers (see [Cross-Origin Isolation](../getting-started/cross-origin.md)).
6
+
7
+ ---
8
+
9
+ ## When to Choose Pumpkin
10
+
11
+ | Problem Type | Recommended Solver | Why |
12
+ | :--- | :--- | :--- |
13
+ | **Scheduling, resource caps, & discrete global constraints** | **Pumpkin** (`{ solver: "pumpkin" }`) | Native propagation for `disjoint`, `cumulative`, `distinct`, and `allowed` with zero extra setup. |
14
+ | **Browser `unsatCore` without `COOP`/`COEP`** | **Pumpkin** (`m.check({ solver: "pumpkin" })`) | Extracts conflicting named constraints on bounded integer and boolean models in any static site or iframe. |
15
+ | **Linear, Mixed-Integer, & Convex Quadratic Programming** | **[HiGHS](./highs.md)** (default) | Supports continuous variables, duals and slacks, convex quadratic objectives, and continuous relaxation. |
16
+ | **Logical rules with `Continuous` variables** | **[Z3](./z3.md)** | Handles real-valued inequalities inside logical operators and mixed continuous/integer `unsatCore`. |
17
+
18
+ ---
19
+
20
+ ## Supported Modeling Primitives
21
+
22
+ - **Native CP & global constraints**: `disjoint()`, `cumulative()`, `distinct()`, `allowed()`, `at()`, `max()`, `min()`, `abs()`, discrete `!=`, and `m.indicator()`.
23
+ - **Native propositional logic**: `model.bool()`, `and()`, `or()`, `not()`, `implies()`, and `xor()`.
24
+ - **Warm starts (`initialValue`)**: Accepts starting value hints on `model.integer()` and `model.binary()` variables.
25
+
26
+ ---
27
+
28
+ ## Usage Examples
29
+
30
+ Pumpkin is pre-registered in `@ohtaman/washi` with no extra import required—just pass `{ solver: "pumpkin" }` to `new Model()`, `model.solve()`, or `model.check()`. Use `model.solve()` to optimize an integer objective over bounded integer and boolean variables, or use `model.check()` to verify satisfiability and inspect conflicting constraints.
31
+
32
+ ### 1. Scheduling & Global Constraints (`model.solve()`)
33
+
34
+ ```typescript
35
+ import { Model, disjoint, expr, implies, minimize, not } from "@ohtaman/washi";
36
+
37
+ const model = new Model("SchedulingStep", { solver: "pumpkin" });
38
+
39
+ const s1 = model.integer("start_job1", { lb: 0, ub: 20 });
40
+ const s2 = model.integer("start_job2", { lb: 0, ub: 20 });
41
+ const job1First = model.bool("job1_first");
42
+
43
+ model.constraint(
44
+ disjoint([
45
+ { start: s1, duration: 6 },
46
+ { start: s2, duration: 4 },
47
+ ]),
48
+ "single_machine"
49
+ );
50
+ // Optional: reify the chosen order in job1First (disjoint already enforces non-overlap)
51
+ model.constraint(implies(job1First, expr`${s1} + 6 <= ${s2}`), "job1_before_job2");
52
+ model.constraint(implies(not(job1First), expr`${s2} + 4 <= ${s1}`), "job2_before_job1");
53
+
54
+ model.objective(minimize(expr`${s1} + ${s2}`));
55
+ await model.solve();
56
+
57
+ console.log(`Status: ${model.status}, s1=${s1.value}, s2=${s2.value}`);
58
+ // Status: Optimal, s1=4, s2=0
59
+ ```
60
+
61
+ ### 2. Conflict Diagnosis (`model.check()`)
62
+
63
+ ```typescript
64
+ import { Model, expr, implies } from "@ohtaman/washi";
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); // or result.unsatCore / model.unsatCore
77
+ // ["vip_active", "vip_seats", "room_cap"]
78
+ }
79
+ ```
80
+
81
+ ---
82
+
83
+ ## Solver Options
84
+
85
+ Pass execution options into `model.solve()`, `model.check()`, or `new PumpkinSolver(options)`:
86
+
87
+ | Option | Type | Description |
88
+ | :--- | :--- | :--- |
89
+ | `timeLimit` | `number` | Maximum solve or check time in seconds. |
90
+ | `useWorker` | `boolean` | Runs Pumpkin in a browser Web Worker (`true` by default in browsers; falls back to `false` on `file:` URLs or opaque origins). Passing `useWorker: true` in Node.js throws an `Error`. |
91
+ | `wasmUrl` | `string \| null` | Overrides the `pumpkin.wasm` asset URL (`null` uses the bundled binary; call `setPumpkinWasmUrl()` to set a global URL). |
92
+ | `signal` | `AbortSignal` | Cancels an in-flight call. In a browser Web Worker, aborts preemptively and preserves the last captured incumbent if available; on the main thread or in Node.js, cancels cooperatively at checkpoints. |
93
+ | `onProgress` | `(ev) => void` | Receives live elapsed time and incumbent objective updates (`solve()` only; ignored by `check()`). |
94
+
95
+ > [!NOTE]
96
+ > Pumpkin is a discrete CP solver: LP sensitivity fields (`c.dual`, `c.slack`, `v.reducedCost`) remain `null`, and MIP bound/gap fields (`objectiveBound`, `relativeGap`, `absoluteGap`) remain `undefined`.
97
+
98
+ ```typescript
99
+ import { Model, expr, minimize } from "@ohtaman/washi";
100
+
101
+ const model = new Model("TimedSearch", { solver: "pumpkin" });
102
+ const x = model.integer("x", { lb: 0, ub: 100 });
103
+ const y = model.integer("y", { lb: 0, ub: 100 });
104
+ model.constraint(expr`${x} + ${y} >= 40`, "min_total");
105
+ model.objective(minimize(expr`2 * ${x} + 3 * ${y}`));
106
+
107
+ const controller = new AbortController();
108
+
109
+ await model.solve({
110
+ timeLimit: 30.0,
111
+ signal: controller.signal,
112
+ onProgress: (ev) => {
113
+ console.log(`Elapsed: ${ev.elapsedTime.toFixed(1)}s, Best: ${ev.objectiveValue}`);
114
+ },
115
+ });
116
+
117
+ if (model.hasPrimalSolution) {
118
+ console.log(
119
+ `Solution (${model.status}, termination: ${model.terminationStatus}):`,
120
+ `obj = ${model.objectiveValue}`
121
+ );
122
+ }
123
+ ```
124
+
125
+ ---
126
+
127
+ ## Requirements & Limitations {#domain-api-preconditions}
128
+
129
+ Pumpkin solves **bounded integer and boolean** models only. Unsupported variables, values, or options fail fast by throwing a runtime `Error`:
130
+
131
+ - **Bounded integers only**: Every `Integer` variable must have finite integer bounds in $[-(2^{30} - 1),\, 2^{30} - 1]$ (`Binary` variables are bounded to 0/1); `Continuous` variables and infinite bounds on `Integer` variables throw an `Error`.
132
+ - **Integer coefficients & scaled bounds**: Constraint coefficients, adjusted right-hand sides (`rhs - lhs.constant`), and scaled variable bounds must be exact integers in $[-(2^{30} - 1),\, 2^{30} - 1]$.
133
+ - **Constraint magnitude sum**: In each constraint, the adjusted right-hand side magnitude plus the sum of worst-case term magnitudes ($|\text{coeff}| \times \max(|\mathrm{lb}|, |\mathrm{ub}|)$) must not exceed $2^{31} - 2$.
134
+ - **Stricter objective bound**: Objective coefficients must be integers whose worst-case scaled term magnitudes sum to at most $2^{30} - 1$; objective constants may be fractional.
135
+ - **Unsupported model features**: `QuadExpr` objectives or constraints and `relax: true` throw a runtime `Error`.
136
+ - **Unsupported options**: `relativeGap`, `absoluteGap`, `presolve`, `threads`, `verbose`, `outputFlag`, and unknown option keys throw a runtime `Error`.
137
+
138
+ ---
139
+
140
+ ## Browser Worker & WASM Hosting
141
+
142
+ By default in browsers, Pumpkin loads `pumpkin.wasm` inside a dedicated Web Worker. On `file:` URLs or sandboxed iframes without an origin, it falls back to the main thread automatically.
143
+
144
+ To force main-thread execution or serve `pumpkin.wasm` from a custom URL:
145
+
146
+ ```typescript
147
+ import { Model, expr, minimize } from "@ohtaman/washi";
148
+ import { PumpkinSolver, setPumpkinWasmUrl } from "@ohtaman/washi/solvers/pumpkin";
149
+
150
+ // Set a custom WASM URL globally (or pass { wasmUrl } to solve() / check())
151
+ setPumpkinWasmUrl("/assets/wasm/pumpkin.wasm");
152
+
153
+ const model = new Model({ solver: "pumpkin" });
154
+ const x = model.integer("x", { lb: 0, ub: 10 });
155
+ model.objective(minimize(expr`${x}`));
156
+
157
+ // Option 1: Force main-thread execution for a single call
158
+ await model.solve({ useWorker: false });
159
+
160
+ // Option 2: Configure defaults on a PumpkinSolver instance
161
+ const syncModel = new Model({ solver: new PumpkinSolver({ useWorker: false }) });
162
+ ```
163
+
164
+ If `pumpkin.wasm` fails to load or returns an HTML fallback page, WaSHI throws an error with the attempted URL instead of silently falling back to a CDN.
165
+
166
+ ---
167
+
168
+ ## References
169
+
170
+ - [Constraint Programming (CP) Modeling](../guide/constraint-programming.md) · [Resource-Constrained Project Scheduling (RCPSP)](../examples/project-scheduling.md)
171
+ - [ConSol-Lab/Pumpkin](https://github.com/ConSol-Lab/Pumpkin) · [`CONTRIBUTING.md` (rebuilding WASM)](https://github.com/ohtaman/washi/blob/main/CONTRIBUTING.md#4-rebuilding-webassembly-assets--release-workflow)