@ohtaman/washi 0.8.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 (81) hide show
  1. package/README.ja.md +22 -24
  2. package/README.md +20 -22
  3. package/README.zh-CN.md +25 -27
  4. package/dist/browser/{__vite-browser-external-rTVKos2U.js → solvers/highs-__vite-browser-external-Dn-83hnF.js} +1 -1
  5. package/dist/browser/{browser-runtime-AG5QFtKf.js → solvers/highs-browser-runtime-0Bgq5ksG.js} +1 -1
  6. package/dist/browser/{loader-i3FnqMes.js → solvers/highs-loader-BLY3wzDH.js} +25 -18
  7. package/dist/browser/{highs-worker.js → solvers/highs-worker.js} +1 -1
  8. package/dist/browser/solvers/highs.js +1414 -0
  9. package/dist/browser/washi.js +1090 -1473
  10. package/dist/browser/washi.min.js +4 -4
  11. package/dist/lib/solvers/glpk.js +34 -32
  12. package/dist/lib/{highs-node-runtime.js → solvers/highs-node-runtime.js} +1 -1
  13. package/dist/lib/solvers/highs.js +410 -0
  14. package/dist/lib/solvers/lp-writer-CLScMFbS.js +115 -0
  15. package/dist/lib/solvers/pumpkin-node-runtime.js +1 -1
  16. package/dist/lib/solvers/pumpkin-worker.js +1 -1
  17. package/dist/lib/solvers/pumpkin.js +247 -1146
  18. package/dist/lib/solvers/registry-CrYRRk9q.js +907 -0
  19. package/dist/lib/solvers/types-BGqPkxwu.js +12 -0
  20. package/dist/lib/solvers/z3.js +125 -123
  21. package/dist/lib/washi.js +2426 -1340
  22. package/dist/types/index.d.ts +1 -2
  23. package/dist/types/index.d.ts.map +1 -1
  24. package/dist/types/modeler/index.d.ts +0 -1
  25. package/dist/types/modeler/index.d.ts.map +1 -1
  26. package/dist/types/modeler/model.d.ts +6 -7
  27. package/dist/types/modeler/model.d.ts.map +1 -1
  28. package/dist/types/modeler/solvers/index.d.ts +2 -1
  29. package/dist/types/modeler/solvers/index.d.ts.map +1 -1
  30. package/dist/types/modeler/solvers/registry.d.ts.map +1 -1
  31. package/docs/examples/diet-sensitivity.md +33 -14
  32. package/docs/examples/ecommerce-coupons.md +17 -9
  33. package/docs/examples/index.md +34 -30
  34. package/docs/examples/knapsack.md +11 -5
  35. package/docs/examples/portfolio-qp.md +21 -8
  36. package/docs/examples/production.md +10 -5
  37. package/docs/examples/project-scheduling.md +25 -12
  38. package/docs/examples/shift-scheduling.md +27 -19
  39. package/docs/examples/smt-security.md +27 -12
  40. package/docs/examples/transportation.md +23 -13
  41. package/docs/examples/traveling-salesperson.md +34 -22
  42. package/docs/examples/unsat-core.md +27 -15
  43. package/docs/examples/vehicle-routing.md +74 -28
  44. package/docs/getting-started/ai-agents.md +129 -90
  45. package/docs/getting-started/coding-agents.md +60 -41
  46. package/docs/getting-started/cross-origin.md +27 -14
  47. package/docs/getting-started/index.md +23 -16
  48. package/docs/getting-started/runtimes.md +70 -40
  49. package/docs/guide/constraint-programming.md +74 -44
  50. package/docs/guide/constraints.md +71 -39
  51. package/docs/guide/decomposition.md +72 -42
  52. package/docs/guide/expressions.md +79 -48
  53. package/docs/guide/formulation-tips.md +46 -27
  54. package/docs/guide/objectives.md +55 -31
  55. package/docs/guide/unsat-core.md +56 -53
  56. package/docs/guide/variables.md +61 -28
  57. package/docs/solvers/custom-solver.md +155 -119
  58. package/docs/solvers/glpk.md +58 -17
  59. package/docs/solvers/highs.md +115 -43
  60. package/docs/solvers/index.md +33 -26
  61. package/docs/solvers/pumpkin.md +71 -63
  62. package/docs/solvers/z3.md +63 -25
  63. package/llms-full.txt +1623 -953
  64. package/llms.txt +125 -93
  65. package/package.json +29 -20
  66. package/skills/washi/SKILL.md +43 -22
  67. package/dist/browser/solvers/pumpkin.min.js +0 -1
  68. package/dist/lib/registry-dx7x4e5c.js +0 -1694
  69. /package/dist/browser/{highs.wasm → solvers/highs.wasm} +0 -0
  70. /package/dist/browser/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
  71. /package/dist/lib/{__vite-browser-external-oLchLuMx.js → solvers/__vite-browser-external-oLchLuMx.js} +0 -0
  72. /package/dist/lib/{highs-assets.js → solvers/highs-assets.js} +0 -0
  73. /package/dist/lib/{highs-browser-runtime.js → solvers/highs-browser-runtime.js} +0 -0
  74. /package/dist/lib/{highs-runtime.js → solvers/highs-runtime.js} +0 -0
  75. /package/dist/lib/{highs-worker-factory.js → solvers/highs-worker-factory.js} +0 -0
  76. /package/dist/lib/{highs-worker.js → solvers/highs-worker.js} +0 -0
  77. /package/dist/lib/{highs.wasm → solvers/highs.wasm} +0 -0
  78. /package/dist/lib/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
  79. /package/dist/lib/{loader-CDpPXN_F.js → solvers/loader-CDpPXN_F.js} +0 -0
  80. /package/dist/lib/solvers/{pumpkin-loader-Ow74Fa1B.js → loader-Ow74Fa1B.js} +0 -0
  81. /package/dist/lib/{rolldown-runtime-DtPi1Y-2.js → solvers/rolldown-runtime-DtPi1Y-2.js} +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,25 +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. |
17
+
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.
16
20
 
17
21
  ---
18
22
 
19
23
  ## Supported Problem Classes
20
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
+
21
27
  ### 1. Linear Programming (LP)
22
- 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:
23
30
 
24
31
  ```typescript
25
32
  import { Model, expr, maximize } from "@ohtaman/washi";
@@ -27,58 +34,113 @@ import { Model, expr, maximize } from "@ohtaman/washi";
27
34
  const model = new Model({ solver: "highs" });
28
35
  const x = model.continuous("x", { lb: 0 });
29
36
  const y = model.continuous("y", { lb: 0 });
37
+
30
38
  model.objective(maximize(expr`10 * ${x} + 6 * ${y}`));
31
- model.constraint(expr`${x} + ${y} <= 100`, "cap");
39
+ const cap = model.constraint(expr`${x} + ${y} <= 100`, "cap");
40
+
32
41
  await model.solve();
42
+ console.log(model.status, model.objectiveValue, cap.dual, cap.slack);
33
43
  ```
34
44
 
35
- ### 2. Mixed-Integer Linear Programming (MIP)
36
- 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`:
37
48
 
38
49
  ```typescript
39
- 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);
40
61
  ```
41
62
 
42
63
  ### 3. Convex Quadratic Programming (QP)
43
- 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:
44
66
 
45
67
  ```typescript
46
- // Minimize risk/variance uniformly using expr:
47
- model.objective(minimize(expr`0.5 * ${x}^2 + 0.5 * ${y}^2`));
68
+ import { Model, expr, minimize } from "@ohtaman/washi";
69
+
70
+ const qpModel = new Model({ solver: "highs" });
71
+ const x = qpModel.continuous("x", { lb: 0 });
72
+ const y = qpModel.continuous("y", { lb: 0 });
48
73
 
49
- // Or programmatically with .mul():
50
- // const quadObj = x.mul(x).mul(0.5).add(y.mul(y).mul(0.5));
51
- // model.objective(minimize(quadObj));
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
52
80
  ```
53
81
 
54
82
  > [!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).
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).
56
86
 
57
87
  ---
58
88
 
59
89
  ## Solver Options
60
90
 
61
- 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
62
117
 
63
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
+
64
127
  const controller = new AbortController();
65
128
 
66
129
  await model.solve({
67
- timeLimit: 60.0, // Maximum solve time in seconds
68
- relativeGap: 0.001, // Terminate when within 0.1% of global optimality
69
- absoluteGap: 1.0, // Absolute MIP optimality gap tolerance
70
- presolve: "on", // Presolve control ("on" | "off" | "choose")
71
- 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,
72
135
  signal: controller.signal,
73
136
  onProgress: (ev) => {
74
137
  console.log(`Elapsed: ${ev.elapsedTime.toFixed(1)}s, Best: ${ev.objectiveValue}`);
75
138
  },
76
139
  });
77
140
 
78
- // Always check hasPrimalSolution when timeLimit or AbortSignal is used:
79
141
  if (model.hasPrimalSolution) {
80
142
  console.log(
81
- `Usable solution (${model.status}, termination: ${model.terminationStatus}):`,
143
+ `Solution (${model.status}, termination: ${model.terminationStatus}):`,
82
144
  `obj = ${model.objectiveValue}, gap = ${((model.relativeGap ?? 0) * 100).toFixed(2)}%`
83
145
  );
84
146
  }
@@ -86,38 +148,49 @@ if (model.hasPrimalSolution) {
86
148
 
87
149
  ---
88
150
 
89
- ## Worker & WASM Configuration in Browsers
151
+ ## Web Worker & WASM Configuration in Browsers
90
152
 
91
- 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.
92
154
 
93
- 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`:
94
156
 
95
157
  ```typescript
96
- 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");
163
+
164
+ const model = new Model({ solver: "highs" });
165
+ const x = model.continuous("x", { lb: 0, ub: 10 });
166
+ model.objective(maximize(expr`${x}`));
97
167
 
98
- // Option 1: Per solve call
99
- await model.solve({ useWorker: false });
168
+ // Option 1: Disable the Web Worker or override wasmUrl per solve call
169
+ await model.solve({ useWorker: false, wasmUrl: "/assets/wasm/highs.wasm" });
100
170
 
101
- // Option 2: When instantiating the solver
171
+ // Option 2: Configure defaults on a HighsSolver instance
102
172
  const syncModel = new Model({
103
173
  solver: new HighsSolver({ useWorker: false }),
104
174
  });
105
175
  ```
106
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
+
107
179
  ---
108
180
 
109
181
  ## Architecture & WebAssembly Runtime
110
182
 
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.
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.
112
187
 
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).
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).
114
189
 
115
190
  ### Callbacks & Solver Interactivity
116
191
 
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.
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.
121
194
 
122
195
  ---
123
196
 
@@ -126,6 +199,5 @@ Bundled `highs.wasm` and `runtime.js` artifacts are tracked and verified via SHA
126
199
  - **Official Website**: [https://highs.dev/](https://highs.dev/)
127
200
  - **Official Documentation**: [https://ergo-code.github.io/HiGHS/](https://ergo-code.github.io/HiGHS/)
128
201
  - **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:
202
+ - **Academic Citation**: Please cite the foundational HiGHS paper when referencing HiGHS in publications:
130
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)
131
-
@@ -1,48 +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
- | **[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`) |
15
- | **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(...)`) |
16
16
 
17
17
  ---
18
18
 
19
19
  ## Selecting a Solver
20
20
 
21
- 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()`:
22
22
 
23
23
  ```typescript
24
- // 1. Built-in HiGHS (default)
25
- const m1 = new Model({ solver: "highs" });
26
-
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
24
+ import { Model, MockSolver, expr, maximize } from "@ohtaman/washi";
32
25
  import "@ohtaman/washi/solvers/z3";
33
- const m3 = new Model({ solver: "z3" });
34
-
35
- // 4. GLPK solver
36
26
  import "@ohtaman/washi/solvers/glpk";
37
- const m4 = 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 });
38
43
  ```
39
44
 
45
+ See [Conflict Diagnosis, Validation & Debugging](../guide/unsat-core.md) for full `MockSolver` testing patterns.
46
+
40
47
  ---
41
48
 
42
49
  ## Solver Guides
43
50
 
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`.
46
- - [Z3 Guide](./z3.md): SMT assertions, logic modeling, and Unsat Core analysis.
47
- - [GLPK Guide](./glpk.md): GLPK adapter, GPL-3.0 licensing considerations, and browser usage.
48
- - [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.