@ohtaman/washi 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +58 -19
- package/README.md +58 -19
- package/README.zh-CN.md +58 -19
- package/THIRD_PARTY_LICENSES.md +34 -1
- package/dist/browser/__vite-browser-external-rTVKos2U.js +7 -0
- package/dist/browser/browser-runtime-AG5QFtKf.js +2021 -0
- package/dist/browser/highs-worker.js +26 -11
- package/dist/browser/highs.wasm +0 -0
- package/dist/browser/{loader-DewlSho8.js → loader-i3FnqMes.js} +183 -149
- package/dist/browser/solvers/glpk.js +289 -238
- package/dist/browser/solvers/glpk.min.js +1 -1
- package/dist/browser/solvers/pumpkin-_washi-pumpkin-node-runtime-CEKUDK6d.js +9 -0
- package/dist/browser/solvers/pumpkin-loader-CvdaKxf4.js +320 -0
- package/dist/browser/solvers/pumpkin-worker.js +45 -0
- package/dist/browser/solvers/pumpkin.js +1777 -0
- package/dist/browser/solvers/pumpkin.min.js +1 -0
- package/dist/browser/solvers/pumpkin.wasm +0 -0
- package/dist/browser/solvers/pumpkin.wasm.LICENSE +21 -0
- package/dist/browser/solvers/z3.js +1600 -1335
- package/dist/browser/solvers/z3.min.js +2 -2
- package/dist/browser/washi.js +3374 -1377
- package/dist/browser/washi.min.js +5 -3
- package/dist/lib/__vite-browser-external-oLchLuMx.js +7 -0
- package/dist/lib/highs-browser-runtime.js +1846 -1618
- package/dist/lib/highs-runtime.js +16 -2
- package/dist/lib/highs-worker.js +26 -11
- package/dist/lib/highs.wasm +0 -0
- package/dist/lib/{loader-BZUQNvh4.js → loader-CDpPXN_F.js} +138 -116
- package/dist/lib/registry-dx7x4e5c.js +1694 -0
- package/dist/lib/rolldown-runtime-DtPi1Y-2.js +13 -0
- package/dist/lib/solvers/glpk.js +161 -121
- package/dist/lib/solvers/pumpkin-assets.js +1 -0
- package/dist/lib/solvers/pumpkin-loader-Ow74Fa1B.js +311 -0
- package/dist/lib/solvers/pumpkin-node-runtime.js +15 -0
- package/dist/lib/solvers/pumpkin-worker-factory.js +1 -0
- package/dist/lib/solvers/pumpkin-worker.js +45 -0
- package/dist/lib/solvers/pumpkin.js +1767 -0
- package/dist/lib/solvers/pumpkin.wasm +0 -0
- package/dist/lib/solvers/pumpkin.wasm.LICENSE +21 -0
- package/dist/lib/solvers/z3.js +486 -306
- package/dist/lib/washi.js +2563 -1154
- package/dist/types/decomposition/benders.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modeler/boolean-expr.d.ts +137 -29
- package/dist/types/modeler/boolean-expr.d.ts.map +1 -1
- package/dist/types/modeler/constraint.d.ts +40 -4
- package/dist/types/modeler/constraint.d.ts.map +1 -1
- package/dist/types/modeler/expression.d.ts +129 -2
- package/dist/types/modeler/expression.d.ts.map +1 -1
- package/dist/types/modeler/index.d.ts +4 -5
- package/dist/types/modeler/index.d.ts.map +1 -1
- package/dist/types/modeler/linearizer.d.ts +11 -2
- package/dist/types/modeler/linearizer.d.ts.map +1 -1
- package/dist/types/modeler/lp-writer.d.ts.map +1 -1
- package/dist/types/modeler/model.d.ts +85 -124
- package/dist/types/modeler/model.d.ts.map +1 -1
- package/dist/types/modeler/parser.d.ts.map +1 -1
- package/dist/types/modeler/quad-expr.d.ts +8 -2
- package/dist/types/modeler/quad-expr.d.ts.map +1 -1
- package/dist/types/modeler/solution-validator.d.ts +12 -12
- package/dist/types/modeler/solution-validator.d.ts.map +1 -1
- package/dist/types/modeler/solvers/glpk/loader.d.ts +4 -0
- package/dist/types/modeler/solvers/glpk/loader.d.ts.map +1 -1
- package/dist/types/modeler/solvers/glpk/solver.d.ts +2 -2
- package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/driver.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/loader.d.ts +8 -6
- package/dist/types/modeler/solvers/highs/loader.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/worker-client.d.ts +16 -0
- package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
- package/dist/types/modeler/solvers/mock.d.ts +2 -3
- package/dist/types/modeler/solvers/mock.d.ts.map +1 -1
- package/dist/types/modeler/solvers/pumpkin/assets.d.ts +2 -0
- package/dist/types/modeler/solvers/pumpkin/assets.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/index.d.ts +6 -0
- package/dist/types/modeler/solvers/pumpkin/index.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/loader.d.ts +40 -0
- package/dist/types/modeler/solvers/pumpkin/loader.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts +3 -0
- package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/solver.d.ts +23 -0
- package/dist/types/modeler/solvers/pumpkin/solver.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts +74 -0
- package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts +3 -0
- package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin/worker.d.ts +7 -0
- package/dist/types/modeler/solvers/pumpkin/worker.d.ts.map +1 -0
- package/dist/types/modeler/solvers/pumpkin.d.ts +2 -0
- package/dist/types/modeler/solvers/pumpkin.d.ts.map +1 -0
- package/dist/types/modeler/solvers/registry.d.ts.map +1 -1
- package/dist/types/modeler/solvers/types.d.ts +7 -9
- package/dist/types/modeler/solvers/types.d.ts.map +1 -1
- package/dist/types/modeler/solvers/z3/loader.d.ts +4 -0
- package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
- package/dist/types/modeler/solvers/z3/solver.d.ts +2 -15
- package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -1
- package/dist/types/modeler/types.d.ts +12 -15
- package/dist/types/modeler/types.d.ts.map +1 -1
- package/dist/types/modeler/validation.d.ts +26 -2
- package/dist/types/modeler/validation.d.ts.map +1 -1
- package/dist/types/modeler/variable.d.ts +9 -5
- package/dist/types/modeler/variable.d.ts.map +1 -1
- package/docs/examples/index.md +6 -1
- package/docs/examples/project-scheduling.md +106 -0
- package/docs/examples/shift-scheduling.md +3 -0
- package/docs/examples/smt-security.md +1 -0
- package/docs/examples/traveling-salesperson.md +1 -1
- package/docs/examples/unsat-core.md +3 -2
- package/docs/getting-started/ai-agents.md +94 -25
- package/docs/getting-started/coding-agents.md +158 -0
- package/docs/getting-started/cross-origin.md +2 -2
- package/docs/getting-started/index.md +40 -41
- package/docs/getting-started/runtimes.md +42 -18
- package/docs/guide/constraint-programming.md +141 -0
- package/docs/guide/constraints.md +64 -14
- package/docs/guide/decomposition.md +59 -59
- package/docs/guide/expressions.md +42 -10
- package/docs/guide/formulation-tips.md +6 -6
- package/docs/guide/objectives.md +65 -62
- package/docs/guide/unsat-core.md +36 -27
- package/docs/guide/variables.md +30 -17
- package/docs/solvers/custom-solver.md +18 -13
- package/docs/solvers/highs.md +18 -23
- package/docs/solvers/index.md +12 -6
- package/docs/solvers/pumpkin.md +163 -0
- package/docs/solvers/z3.md +2 -2
- package/llms-full.txt +944 -314
- package/llms.txt +43 -22
- package/package.json +38 -11
- package/skills/washi/SKILL.md +79 -27
- package/dist/browser/_washi-node-only-BvRk9kiK.js +0 -0
- package/dist/browser/browser-runtime-TLCY0hkc.js +0 -1793
- package/dist/lib/_washi-node-only-BvRk9kiK.js +0 -0
- package/dist/lib/registry-D7TZ3Wh_.js +0 -1034
- package/docs/ja/getting-started/ai-agents.md +0 -280
- package/docs/zh/getting-started/ai-agents.md +0 -280
package/docs/solvers/highs.md
CHANGED
|
@@ -16,26 +16,6 @@ In `@ohtaman/washi`, HiGHS runs entirely in WebAssembly compiled directly from o
|
|
|
16
16
|
|
|
17
17
|
---
|
|
18
18
|
|
|
19
|
-
## Architecture & WebAssembly Runtime
|
|
20
|
-
|
|
21
|
-
WaSHI compiles official HiGHS C++ source directly to WebAssembly (`highs.wasm`) with `-fwasm-exceptions` and single-threaded universal portability (`-DHIGHS_NO_DEFAULT_THREADS=ON`). By interfacing directly with HiGHS's native C API (`highs_c_api.h`), WaSHI achieves zero-copy solution extraction via typed array views on WebAssembly linear memory, rapid upstream release tracking, and a self-contained zero-dependency distribution.
|
|
22
|
-
|
|
23
|
-
### Callbacks & Solver Interactivity
|
|
24
|
-
|
|
25
|
-
- **Progress Monitoring & Cancellation (Supported)**:
|
|
26
|
-
Through HiGHS's internal logging and interrupt hooks, WaSHI provides real-time progress callbacks (`onProgress`) and cooperative mid-solve cancellation via standard `AbortSignal`.
|
|
27
|
-
- **Dynamic Cuts / Lazy Constraints (Not 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`).
|
|
36
|
-
|
|
37
|
-
---
|
|
38
|
-
|
|
39
19
|
## Supported Problem Classes
|
|
40
20
|
|
|
41
21
|
### 1. Linear Programming (LP)
|
|
@@ -85,8 +65,8 @@ const controller = new AbortController();
|
|
|
85
65
|
|
|
86
66
|
await model.solve({
|
|
87
67
|
timeLimit: 60.0, // Maximum solve time in seconds
|
|
88
|
-
|
|
89
|
-
|
|
68
|
+
relativeGap: 0.001, // Terminate when within 0.1% of global optimality
|
|
69
|
+
absoluteGap: 1.0, // Absolute MIP optimality gap tolerance
|
|
90
70
|
presolve: "on", // Presolve control ("on" | "off" | "choose")
|
|
91
71
|
outputFlag: true, // Output internal simplex / branch-and-bound logs (output_flag)
|
|
92
72
|
signal: controller.signal,
|
|
@@ -99,7 +79,7 @@ await model.solve({
|
|
|
99
79
|
if (model.hasPrimalSolution) {
|
|
100
80
|
console.log(
|
|
101
81
|
`Usable solution (${model.status}, termination: ${model.terminationStatus}):`,
|
|
102
|
-
`obj = ${model.objectiveValue}, gap = ${((model.
|
|
82
|
+
`obj = ${model.objectiveValue}, gap = ${((model.relativeGap ?? 0) * 100).toFixed(2)}%`
|
|
103
83
|
);
|
|
104
84
|
}
|
|
105
85
|
```
|
|
@@ -126,6 +106,21 @@ const syncModel = new Model({
|
|
|
126
106
|
|
|
127
107
|
---
|
|
128
108
|
|
|
109
|
+
## Architecture & WebAssembly Runtime
|
|
110
|
+
|
|
111
|
+
WaSHI compiles official HiGHS C++ source directly to WebAssembly (`highs.wasm`) with `-fwasm-exceptions` and single-threaded universal portability (`-DHIGHS_NO_DEFAULT_THREADS=ON`). By interfacing directly with HiGHS's native C API (`highs_c_api.h`), WaSHI achieves zero-copy solution extraction via typed array views on WebAssembly linear memory, rapid upstream release tracking, and a self-contained zero-dependency distribution.
|
|
112
|
+
|
|
113
|
+
Bundled `highs.wasm` and `runtime.js` artifacts are tracked and verified via SHA-256 checksums in `highs.config.json`. Maintainers rebuilding HiGHS from source can follow the instructions in [`CONTRIBUTING.md`](https://github.com/ohtaman/washi/blob/main/CONTRIBUTING.md#4-rebuilding-webassembly-assets--release-workflow).
|
|
114
|
+
|
|
115
|
+
### Callbacks & Solver Interactivity
|
|
116
|
+
|
|
117
|
+
- **Progress Monitoring & Cancellation (Supported)**:
|
|
118
|
+
Through HiGHS's internal logging and interrupt hooks, WaSHI provides real-time progress callbacks (`onProgress`) and cooperative mid-solve cancellation via standard `AbortSignal`.
|
|
119
|
+
- **Dynamic Cuts / Lazy Constraints (Not Exposed in WASM Driver)**:
|
|
120
|
+
WaSHI's HiGHS WebAssembly C API driver currently binds logging, progress, interrupt, and incumbent callbacks and does not expose in-tree lazy constraint or user cut callbacks across the WASM-to-JS boundary. For problems requiring dynamic subtour elimination or Benders decomposition, use [`await m.solveBenders({ subproblem })`](../guide/decomposition.md#benders-decomposition-solvebenders) (or a manual outer cutting-plane loop: solve $\to$ detect violation $\to$ `model.constraint(...)` $\to$ re-solve), which iteratively separates cuts and converges to the same exact optimal solution.
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
129
124
|
## References & Upstream Links
|
|
130
125
|
|
|
131
126
|
- **Official Website**: [https://highs.dev/](https://highs.dev/)
|
package/docs/solvers/index.md
CHANGED
|
@@ -9,8 +9,9 @@ WaSHI is designed around a pluggable, decoupled solver architecture. You formula
|
|
|
9
9
|
| Solver | Engine License | Problem Classes | Best For | Status in WaSHI |
|
|
10
10
|
| :--- | :--- | :--- | :--- | :--- |
|
|
11
11
|
| **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | **MIT** | **LP, MIP, Convex QP** | Industrial-scale optimization, operations research, finance | **Built-in default** (zero configuration) |
|
|
12
|
-
| **[
|
|
13
|
-
| **[
|
|
12
|
+
| **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** | **MIT** | **CP, LCG, Logic, Bounded Integer** | Disjunctive scheduling, CP global constraints, zero-COOP/COEP `unsatCore` | **Bundled plugin** (`@ohtaman/washi/solvers/pumpkin`, zero external deps) |
|
|
13
|
+
| **[Z3](https://github.com/Z3Prover/z3)** (via [`z3-solver`](https://www.npmjs.com/package/z3-solver)) | **MIT** | **SMT, SAT, Logic, MIP** | Propositional logic, conflict diagnosis (`unsatCore`), rule engines | Optional peer plugin (`@ohtaman/washi/solvers/z3`, requires `z3-solver`) |
|
|
14
|
+
| **[GLPK](https://www.gnu.org/software/glpk/)** (via [`glpk.js`](https://www.npmjs.com/package/glpk.js)) | **GPL-3.0** | **LP, MIP** | Academic benchmarks, legacy GLPK compatibility | Optional peer plugin (`@ohtaman/washi/solvers/glpk`, requires `glpk.js`) |
|
|
14
15
|
| **Mock** | **MIT** | *Any* | Ultra-fast unit testing in CI without loading WebAssembly | Built-in |
|
|
15
16
|
|
|
16
17
|
---
|
|
@@ -23,13 +24,17 @@ Specify the solver by name when creating your `Model`:
|
|
|
23
24
|
// 1. Built-in HiGHS (default)
|
|
24
25
|
const m1 = new Model({ solver: "highs" });
|
|
25
26
|
|
|
26
|
-
// 2.
|
|
27
|
+
// 2. Pumpkin CP/LCG solver (bundled WASM, zero COOP/COEP)
|
|
28
|
+
import "@ohtaman/washi/solvers/pumpkin";
|
|
29
|
+
const m2 = new Model({ solver: "pumpkin" });
|
|
30
|
+
|
|
31
|
+
// 3. Z3 SMT solver
|
|
27
32
|
import "@ohtaman/washi/solvers/z3";
|
|
28
|
-
const
|
|
33
|
+
const m3 = new Model({ solver: "z3" });
|
|
29
34
|
|
|
30
|
-
//
|
|
35
|
+
// 4. GLPK solver
|
|
31
36
|
import "@ohtaman/washi/solvers/glpk";
|
|
32
|
-
const
|
|
37
|
+
const m4 = new Model({ solver: "glpk" });
|
|
33
38
|
```
|
|
34
39
|
|
|
35
40
|
---
|
|
@@ -37,6 +42,7 @@ const m3 = new Model({ solver: "glpk" });
|
|
|
37
42
|
## Solver Guides
|
|
38
43
|
|
|
39
44
|
- [HiGHS Guide](./highs.md): Background Web Worker execution, MIP tolerances, and Convex QP solving.
|
|
45
|
+
- [Pumpkin Guide](./pumpkin.md): Bundled LCG constraint programming, background Web Worker execution, CP global constraints, warm starts, and zero-COOP/COEP `unsatCore`.
|
|
40
46
|
- [Z3 Guide](./z3.md): SMT assertions, logic modeling, and Unsat Core analysis.
|
|
41
47
|
- [GLPK Guide](./glpk.md): GLPK adapter, GPL-3.0 licensing considerations, and browser usage.
|
|
42
48
|
- [Custom Solvers](./custom-solver.md): Step-by-step developer tutorial for integrating proprietary or cloud REST solvers.
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
# Pumpkin Constraint Programming Solver
|
|
2
|
+
|
|
3
|
+
**Pumpkin** is a Lazy Clause Generation (LCG) constraint programming solver developed in pure Rust by ConSol Lab at TU Delft ([ConSol-Lab/Pumpkin](https://github.com/ConSol-Lab/Pumpkin) · [docs.rs/pumpkin-core](https://docs.rs/pumpkin-core)). WaSHI compiles Pumpkin (`v0.5.0`) directly to WebAssembly and bundles it in `@ohtaman/washi/solvers/pumpkin` with zero external runtime dependencies.
|
|
4
|
+
|
|
5
|
+
Unlike multi-threaded WASM engines, Pumpkin runs as a single-threaded WebAssembly instance inside a Web Worker (or directly in Node.js) and **does not require Cross-Origin Isolation (`COOP` / `COEP`) headers** in browsers.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Key Features in WaSHI
|
|
10
|
+
|
|
11
|
+
- **Bundled & Zero External Dependencies**: `pumpkin.wasm` (`~1.4 MB`) is shipped directly with `@ohtaman/washi` and tree-shaken into `@ohtaman/washi/solvers/pumpkin`—no separate `npm install` peer dependency or Rust toolchain required.
|
|
12
|
+
- **Permissive MIT License**: 100% commercially friendly, including all transitive Rust WASM dependencies (`MIT`, `Apache-2.0`, `Unicode-3.0`).
|
|
13
|
+
- **Background Web Worker & Zero `COOP` / `COEP`**: Runs in a dedicated Web Worker on HTTP(S) origins without `SharedArrayBuffer` or Cross-Origin Isolation headers, keeping UI rendering responsive while working in standard static hosts and third-party iframes.
|
|
14
|
+
- **Native CP Global Constraints & Propagators**: Lowers `distinct()` (`all_different` via pairwise `binary_not_equals` in Pumpkin `v0.5.0`), `disjoint()` (`disjunctive_strict` Vilím edge-finding), `cumulative()` (time-table filtering), `allowed()` / `not(allowed())` (`table` / `negative_table`), `at()` (`element`), `max()` / `min()` / `abs()` (`maximum` / `minimum` / `absolute`), discrete `!=` (`not_equals`), and `m.indicator()` (with `M` omitted, via `implied_by`) directly to Pumpkin constraints.
|
|
15
|
+
- **Zero-`COOP` / `COEP` Unsat Core Diagnosis**: `await model.check({ solver: "pumpkin" })` extracts conflicting named rules (`unsatCore` / `conflicts`) over bounded integer and boolean constraints in standard browser contexts.
|
|
16
|
+
- **Warm-Start Support (`initialValue`)**: Supports non-binding primal initial value hints (`initialValue`, `supportsWarmStart: true`) on bounded `Integer` and `Binary` variables in both `solve()` and `check()` via Pumpkin's `WarmStart` brancher (kept distinct from solved `Var.value`).
|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## Supported Problem Classes
|
|
21
|
+
|
|
22
|
+
> [!TIP]
|
|
23
|
+
> **HiGHS vs. Pumpkin vs. Z3**:
|
|
24
|
+
> - Use **HiGHS** (`{ solver: "highs" }`) for Continuous LPs, Convex QPs, or large linear-relaxation-dominated MILPs.
|
|
25
|
+
> - Use **Pumpkin** (`{ solver: "pumpkin" }`) for disjunctive scheduling, CP global constraints, bounded integer + propositional logic models, and zero-`COOP`/`COEP` `unsatCore` extraction.
|
|
26
|
+
> - Use **Z3** (`{ solver: "z3" }`) when you need continuous variables inside `implies(...)` / `not(...)` or arbitrary real-valued SMT arithmetic.
|
|
27
|
+
|
|
28
|
+
### 1. Disjunctive Scheduling & Global CP Constraints (`model.solve()`)
|
|
29
|
+
|
|
30
|
+
Model unary/cumulative resource scheduling, precedence logic (`implies`, `not`), and global predicates (`disjoint`, `distinct`, `cumulative`, `allowed`, `at`, `max`, `min`, `abs`) directly over bounded integers:
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
import { Model, disjoint, expr, implies, minimize, not } from "@ohtaman/washi";
|
|
34
|
+
import "@ohtaman/washi/solvers/pumpkin";
|
|
35
|
+
|
|
36
|
+
const model = new Model("SchedulingStep", { solver: "pumpkin" });
|
|
37
|
+
|
|
38
|
+
const s1 = model.integer("start_job1", { lb: 0, ub: 20 });
|
|
39
|
+
const s2 = model.integer("start_job2", { lb: 0, ub: 20 });
|
|
40
|
+
const job1First = model.bool("job1_first");
|
|
41
|
+
|
|
42
|
+
model.constraint(
|
|
43
|
+
disjoint([
|
|
44
|
+
{ start: s1, duration: 6 },
|
|
45
|
+
{ start: s2, duration: 4 },
|
|
46
|
+
]),
|
|
47
|
+
"single_machine"
|
|
48
|
+
);
|
|
49
|
+
model.constraint(implies(job1First, expr`${s1} + 6 <= ${s2}`), "job1_before_job2");
|
|
50
|
+
model.constraint(implies(not(job1First), expr`${s2} + 4 <= ${s1}`), "job2_before_job1");
|
|
51
|
+
|
|
52
|
+
model.objective(minimize(expr`${s1} + ${s2}`));
|
|
53
|
+
await model.solve();
|
|
54
|
+
|
|
55
|
+
console.log(`Status: ${model.status}, s1=${s1.value}, s2=${s2.value}`);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### 2. Satisfiability & Unsat Core Diagnosis (`model.check()`)
|
|
59
|
+
|
|
60
|
+
Call `await model.check()` to verify satisfiability over integer linear constraints, CP global constraints, and nested propositional logic (`and`, `or`, `not`, `implies`, `xor`), and isolate conflicting named rules (`conflicts` / `unsatCore`) when unsatisfiable:
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
import { Model, expr, implies } from "@ohtaman/washi";
|
|
64
|
+
import "@ohtaman/washi/solvers/pumpkin";
|
|
65
|
+
|
|
66
|
+
const model = new Model("PolicyConflict", { solver: "pumpkin" });
|
|
67
|
+
const vip = model.bool("vip");
|
|
68
|
+
const seats = model.integer("seats", { lb: 0, ub: 20 });
|
|
69
|
+
|
|
70
|
+
model.constraint(vip, "vip_active");
|
|
71
|
+
model.constraint(implies(vip, expr`${seats} >= 8`), "vip_seats");
|
|
72
|
+
model.constraint(expr`${seats} <= 5`, "room_cap");
|
|
73
|
+
|
|
74
|
+
const result = await model.check();
|
|
75
|
+
if (result.status === "Unsat") {
|
|
76
|
+
console.log("Conflicting rules:", result.conflicts); // also on result.unsatCore / model.unsatCore
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## Solver Options
|
|
83
|
+
|
|
84
|
+
Pass solver options into `model.solve()` or `model.check()`:
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
const controller = new AbortController();
|
|
88
|
+
|
|
89
|
+
await model.solve({
|
|
90
|
+
timeLimit: 30.0, // Maximum solve time in seconds
|
|
91
|
+
signal: controller.signal,
|
|
92
|
+
onProgress: (ev) => {
|
|
93
|
+
console.log(`Elapsed: ${ev.elapsedTime.toFixed(1)}s, Best: ${ev.objectiveValue}`);
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Always check hasPrimalSolution when timeLimit or AbortSignal is used:
|
|
98
|
+
if (model.hasPrimalSolution) {
|
|
99
|
+
console.log(
|
|
100
|
+
`Usable solution (${model.status}, termination: ${model.terminationStatus}):`,
|
|
101
|
+
`obj = ${model.objectiveValue}`
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Domain & API Preconditions
|
|
109
|
+
|
|
110
|
+
Pumpkin is strictly a **bounded integer & boolean CP/LCG solver**. Unsupported constructs are rejected with explicit errors rather than silent rounding or fallbacks:
|
|
111
|
+
|
|
112
|
+
- **Bounded integer / binary / boolean variables only**: All `Var` instances must be finite integers (`Integer` or `Binary`) with `lb` and `ub` within `[-(2^30 - 1), 2^30 - 1]`. Unbounded integers (`-Infinity` / `Infinity`) and `Continuous` variables throw an explicit error.
|
|
113
|
+
- **Integer linear arithmetic**: Constraint coefficients, adjusted RHS values (`rhs - lhs.constant`), and scaled variable bounds must be exact integers within safe signed 32-bit range (`|rhs| + sum_i max(|c_i * lb_i|, |c_i * ub_i|) <= 2^31 - 2`). Objective constants (`f64`) may be fractional.
|
|
114
|
+
- **Unsupported features**: `QuadExpr` objectives/constraints, `Continuous` variables, unbounded variables, and `relax: true` throw explicit errors.
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Worker & WASM Configuration in Browsers
|
|
119
|
+
|
|
120
|
+
By default in browsers, `@ohtaman/washi/solvers/pumpkin` resolves the bundled `pumpkin.wasm` and spawns `pumpkin-worker.js` in a dedicated Web Worker on HTTP(S) origins (falling back to main-thread execution on `file:` URLs or opaque-origin sandboxed iframes).
|
|
121
|
+
|
|
122
|
+
To execute synchronously on the main thread (or in environments where Web Workers are prohibited), pass `useWorker: false` to `model.solve()` / `model.check()` or instantiate `PumpkinSolver`:
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
import { Model } from "@ohtaman/washi";
|
|
126
|
+
import { PumpkinSolver, setPumpkinWasmUrl } from "@ohtaman/washi/solvers/pumpkin";
|
|
127
|
+
|
|
128
|
+
// Option 1: Per solve / check call
|
|
129
|
+
await model.solve({ useWorker: false });
|
|
130
|
+
|
|
131
|
+
// Option 2: When instantiating the solver
|
|
132
|
+
const syncModel = new Model({
|
|
133
|
+
solver: new PumpkinSolver({ useWorker: false }),
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Host pumpkin.wasm at a custom path or CDN (globally or per call via { wasmUrl }):
|
|
137
|
+
setPumpkinWasmUrl("/assets/wasm/pumpkin.wasm");
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
If `pumpkin.wasm` cannot be loaded or returns an HTML SPA fallback instead of a WebAssembly binary, Pumpkin rejects explicitly with the attempted URL and performs **no silent CDN fallback**.
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Architecture & WebAssembly Runtime
|
|
145
|
+
|
|
146
|
+
WaSHI compiles its Rust WebAssembly wrapper (`wasm/pumpkin`, linking `pumpkin-core`, `pumpkin-constraints`, `pumpkin-propagators`, and `pumpkin-conflict-resolvers` `v0.5.0` to `wasm32-unknown-unknown`) directly to `pumpkin.wasm` with `wasm-bindgen` bindings.
|
|
147
|
+
|
|
148
|
+
Bundled `pumpkin.wasm` and `runtime.js` / `runtime.d.ts` artifacts are tracked and verified via SHA-256 checksums in `pumpkin.config.json`. Maintainers rebuilding Pumpkin from source can follow the instructions in [`CONTRIBUTING.md`](https://github.com/ohtaman/washi/blob/main/CONTRIBUTING.md#4-rebuilding-webassembly-assets--release-workflow).
|
|
149
|
+
|
|
150
|
+
### Callbacks & Solver Interactivity
|
|
151
|
+
|
|
152
|
+
- **Progress Monitoring & Cancellation (Supported)**:
|
|
153
|
+
During `solve()`, Pumpkin emits real-time incumbent progress callbacks (`onProgress`, providing `elapsedTime` and `objectiveValue`) and honors `AbortSignal`: browser Web Worker execution supports preemptive mid-solve Worker termination and queue cancellation, while main-thread and Node.js runs poll cooperative `should_abort` checkpoints across branching and termination hooks.
|
|
154
|
+
- **Exact Discrete Optimality**:
|
|
155
|
+
As an exact LCG solver over finite integer domains, Pumpkin proves optimality via nogood clause learning and objective-bound strengthening (`LinearSatUnsat`) rather than LP relaxation tolerances (`relativeGap`, `absoluteGap`, or `presolve`).
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
## References & Upstream Links
|
|
160
|
+
|
|
161
|
+
- **Modeling Guide & Walkthrough**: [Constraint Programming (CP) Modeling](../guide/constraint-programming.md) · [Resource-Constrained Project Scheduling (RCPSP)](../examples/project-scheduling.md)
|
|
162
|
+
- **Source Repository**: [ConSol-Lab/Pumpkin](https://github.com/ConSol-Lab/Pumpkin) (MIT License — ConSol Lab, TU Delft)
|
|
163
|
+
- **Rust Crate & API Docs**: [docs.rs/pumpkin-core](https://docs.rs/pumpkin-core) · [crates.io/crates/pumpkin-core](https://crates.io/crates/pumpkin-core)
|
package/docs/solvers/z3.md
CHANGED
|
@@ -24,7 +24,7 @@ npm install z3-solver
|
|
|
24
24
|
Z3 can perform exact rational arithmetic without floating-point inaccuracies.
|
|
25
25
|
|
|
26
26
|
> [!TIP]
|
|
27
|
-
> **Z3
|
|
27
|
+
> **Z3 vs. Pumpkin vs. HiGHS**: Z3 excels at satisfiability checking (`m.check()`), formal policy verification, implications with continuous or fractional antecedents (`` implies(expr`${temp} <= 50.5`, alarm) ``), and scale-invariant `unsatCore` extraction over mixed continuous/integer theories. For bounded-integer and boolean models where `COOP`/`COEP` headers or `z3-solver` are undesirable, bundled **Pumpkin** (`@ohtaman/washi/solvers/pumpkin`) provides native propositional logic and `unsatCore` extraction without `SharedArrayBuffer`. For numerical LP, MIP, or Convex QP optimization with objective functions over tens or hundreds of variables, use the built-in **HiGHS** solver (`m.solve()`), whose simplex relaxations and branch-and-bound cutting planes are orders of magnitude faster than `Z3.Optimize`. Or combine them in a hybrid pipeline: verify/diagnose rules with Z3 or Pumpkin `m.check()`, then optimize costs with HiGHS `m.solve()`.
|
|
28
28
|
|
|
29
29
|
---
|
|
30
30
|
|
|
@@ -71,7 +71,7 @@ if (result.status === "Unsat") {
|
|
|
71
71
|
|
|
72
72
|
## Browser Security Note
|
|
73
73
|
|
|
74
|
-
In browser environments, the Z3 WASM engine relies on pthreads and `SharedArrayBuffer`, which require cross-origin isolation headers (`COOP` / `COEP`). See the [Cross-Origin Isolation Guide](../getting-started/cross-origin.md) for detailed setup.
|
|
74
|
+
In browser environments, the Z3 WASM engine relies on pthreads and `SharedArrayBuffer`, which require cross-origin isolation headers (`COOP` / `COEP`). See the [Cross-Origin Isolation Guide](../getting-started/cross-origin.md) for detailed setup. If your model uses only bounded integers and booleans and you cannot configure `COOP` / `COEP` headers (or want zero external dependencies), use the bundled [Pumpkin solver](./pumpkin.md) (`@ohtaman/washi/solvers/pumpkin`) instead.
|
|
75
75
|
|
|
76
76
|
## Runtime Failures and Thread Cleanup
|
|
77
77
|
|