@ohtaman/washi 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -34
- package/dist/browser/{__vite-browser-external-rTVKos2U.js → solvers/highs-__vite-browser-external-Dn-83hnF.js} +1 -1
- package/dist/browser/{browser-runtime-AG5QFtKf.js → solvers/highs-browser-runtime-0Bgq5ksG.js} +1 -1
- package/dist/browser/{loader-i3FnqMes.js → solvers/highs-loader-BLY3wzDH.js} +25 -18
- package/dist/browser/{highs-worker.js → solvers/highs-worker.js} +1 -1
- package/dist/browser/solvers/highs.js +1414 -0
- package/dist/browser/washi.js +1090 -1473
- package/dist/browser/washi.min.js +4 -4
- package/dist/lib/solvers/glpk.js +34 -32
- package/dist/lib/{highs-node-runtime.js → solvers/highs-node-runtime.js} +1 -1
- package/dist/lib/solvers/highs.js +410 -0
- package/dist/lib/solvers/lp-writer-CLScMFbS.js +115 -0
- package/dist/lib/solvers/pumpkin-node-runtime.js +1 -1
- package/dist/lib/solvers/pumpkin-worker.js +1 -1
- package/dist/lib/solvers/pumpkin.js +247 -1146
- package/dist/lib/solvers/registry-CrYRRk9q.js +907 -0
- package/dist/lib/solvers/types-BGqPkxwu.js +12 -0
- package/dist/lib/solvers/z3.js +125 -123
- package/dist/lib/washi.js +2426 -1340
- package/dist/types/index.d.ts +1 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modeler/index.d.ts +0 -1
- package/dist/types/modeler/index.d.ts.map +1 -1
- package/dist/types/modeler/model.d.ts +6 -7
- package/dist/types/modeler/model.d.ts.map +1 -1
- package/dist/types/modeler/solvers/index.d.ts +2 -1
- package/dist/types/modeler/solvers/index.d.ts.map +1 -1
- package/dist/types/modeler/solvers/registry.d.ts.map +1 -1
- package/docs/examples/diet-sensitivity.md +33 -14
- package/docs/examples/ecommerce-coupons.md +17 -9
- package/docs/examples/index.md +34 -30
- package/docs/examples/knapsack.md +11 -5
- package/docs/examples/portfolio-qp.md +21 -8
- package/docs/examples/production.md +10 -5
- package/docs/examples/project-scheduling.md +25 -12
- package/docs/examples/shift-scheduling.md +27 -19
- package/docs/examples/smt-security.md +27 -12
- package/docs/examples/transportation.md +23 -13
- package/docs/examples/traveling-salesperson.md +34 -22
- package/docs/examples/unsat-core.md +27 -15
- package/docs/examples/vehicle-routing.md +74 -28
- package/docs/getting-started/ai-agents.md +129 -90
- package/docs/getting-started/coding-agents.md +60 -41
- package/docs/getting-started/cross-origin.md +27 -14
- package/docs/getting-started/index.md +23 -16
- package/docs/getting-started/runtimes.md +70 -40
- package/docs/guide/constraint-programming.md +74 -44
- package/docs/guide/constraints.md +71 -39
- package/docs/guide/decomposition.md +72 -42
- package/docs/guide/expressions.md +79 -48
- package/docs/guide/formulation-tips.md +46 -27
- package/docs/guide/objectives.md +55 -31
- package/docs/guide/unsat-core.md +56 -53
- package/docs/guide/variables.md +61 -28
- package/docs/solvers/custom-solver.md +155 -119
- package/docs/solvers/glpk.md +58 -17
- package/docs/solvers/highs.md +115 -43
- package/docs/solvers/index.md +33 -26
- package/docs/solvers/pumpkin.md +71 -63
- package/docs/solvers/z3.md +63 -25
- package/llms-full.txt +1623 -953
- package/llms.txt +125 -93
- package/package.json +29 -22
- package/skills/washi/SKILL.md +43 -22
- package/README.ja.md +0 -248
- package/README.zh-CN.md +0 -248
- package/dist/browser/solvers/pumpkin.min.js +0 -1
- package/dist/lib/registry-dx7x4e5c.js +0 -1694
- /package/dist/browser/{highs.wasm → solvers/highs.wasm} +0 -0
- /package/dist/browser/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
- /package/dist/lib/{__vite-browser-external-oLchLuMx.js → solvers/__vite-browser-external-oLchLuMx.js} +0 -0
- /package/dist/lib/{highs-assets.js → solvers/highs-assets.js} +0 -0
- /package/dist/lib/{highs-browser-runtime.js → solvers/highs-browser-runtime.js} +0 -0
- /package/dist/lib/{highs-runtime.js → solvers/highs-runtime.js} +0 -0
- /package/dist/lib/{highs-worker-factory.js → solvers/highs-worker-factory.js} +0 -0
- /package/dist/lib/{highs-worker.js → solvers/highs-worker.js} +0 -0
- /package/dist/lib/{highs.wasm → solvers/highs.wasm} +0 -0
- /package/dist/lib/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
- /package/dist/lib/{loader-CDpPXN_F.js → solvers/loader-CDpPXN_F.js} +0 -0
- /package/dist/lib/solvers/{pumpkin-loader-Ow74Fa1B.js → loader-Ow74Fa1B.js} +0 -0
- /package/dist/lib/{rolldown-runtime-DtPi1Y-2.js → solvers/rolldown-runtime-DtPi1Y-2.js} +0 -0
package/docs/solvers/glpk.md
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
# GLPK Solver Engine
|
|
2
2
|
|
|
3
|
-
The **GNU Linear Programming Kit (GLPK)** is
|
|
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
|
|
23
|
-
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
61
|
-
-
|
|
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`).
|
package/docs/solvers/highs.md
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
# HiGHS Solver Engine
|
|
2
2
|
|
|
3
|
-
**HiGHS** is
|
|
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
|
|
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
|
-
##
|
|
9
|
+
## When to Choose HiGHS
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
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
|
|
36
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
47
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
|
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
|
|
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,
|
|
68
|
-
relativeGap: 0.001,
|
|
69
|
-
absoluteGap: 1.0,
|
|
70
|
-
presolve: "on",
|
|
71
|
-
outputFlag: true,
|
|
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
|
-
`
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
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:
|
|
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:
|
|
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
|
-
|
|
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
|
|
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
|
|
118
|
-
|
|
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**:
|
|
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
|
-
|
package/docs/solvers/index.md
CHANGED
|
@@ -1,48 +1,55 @@
|
|
|
1
1
|
# Solvers Overview
|
|
2
2
|
|
|
3
|
-
WaSHI
|
|
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
|
-
##
|
|
7
|
+
## Solvers Matrix & Comparison
|
|
8
8
|
|
|
9
|
-
| Solver |
|
|
9
|
+
| Solver | License | Problem Classes & Domains | Best For | Packaging & Preconditions |
|
|
10
10
|
| :--- | :--- | :--- | :--- | :--- |
|
|
11
|
-
| **[HiGHS](
|
|
12
|
-
| **[Pumpkin](
|
|
13
|
-
| **[Z3](
|
|
14
|
-
| **[GLPK](
|
|
15
|
-
| **Mock** | **MIT** | *Any*
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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,
|
|
45
|
-
- [Pumpkin Guide](./pumpkin.md): Bundled
|
|
46
|
-
- [Z3 Guide](./z3.md): SMT
|
|
47
|
-
- [GLPK Guide](./glpk.md): GLPK adapter, GPL-3.0 licensing
|
|
48
|
-
- [Custom Solvers](./custom-solver.md):
|
|
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.
|