@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/llms.txt
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
> WaSHI: TypeScript & JavaScript algebraic modeler for Mathematical Optimization & Constraint Programming (LP, MILP, QP, CP, SMT) powered by WebAssembly (HiGHS, Pumpkin, Z3, GLPK)
|
|
4
4
|
|
|
5
|
-
**WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) brings
|
|
5
|
+
**WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) brings Python PuLP-style algebraic modeling to TypeScript and JavaScript.
|
|
6
6
|
|
|
7
7
|
- Full single-file documentation reference: [llms-full.txt](llms-full.txt)
|
|
8
8
|
- Canonical AI agent modeling quick-reference: [docs/getting-started/ai-agents.md](docs/getting-started/ai-agents.md)
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
|
|
12
12
|
## 1. Package Imports & Deployment
|
|
13
13
|
|
|
14
|
-
### Node.js
|
|
14
|
+
### Node.js, Bun, & Bundlers (Vite, Webpack, Next.js)
|
|
15
15
|
|
|
16
16
|
```ts
|
|
17
17
|
import {
|
|
@@ -34,11 +34,13 @@ import {
|
|
|
34
34
|
not,
|
|
35
35
|
implies,
|
|
36
36
|
xor,
|
|
37
|
-
setHighsWasmUrl,
|
|
38
37
|
} from "@ohtaman/washi";
|
|
39
38
|
|
|
40
|
-
// Bundled
|
|
41
|
-
|
|
39
|
+
// Bundled solvers: HiGHS (default) and Pumpkin (`{ solver: "pumpkin" }`) work out of the box with zero extra imports.
|
|
40
|
+
// Import solver subpaths only when configuring engine-specific classes or custom WASM URLs:
|
|
41
|
+
// import { HighsSolver, setHighsWasmUrl } from "@ohtaman/washi/solvers/highs";
|
|
42
|
+
// import { PumpkinSolver, setPumpkinWasmUrl } from "@ohtaman/washi/solvers/pumpkin";
|
|
43
|
+
|
|
42
44
|
// Optional solver plugins (require installing peer dependencies first):
|
|
43
45
|
// npm install z3-solver
|
|
44
46
|
import "@ohtaman/washi/solvers/z3";
|
|
@@ -48,34 +50,47 @@ import "@ohtaman/washi/solvers/glpk";
|
|
|
48
50
|
|
|
49
51
|
### Browser ESM & Classic Script Tags
|
|
50
52
|
|
|
51
|
-
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
- Z3 plugin: `<script src="./washi/solvers/z3.min.js"></script>` (registers `"z3"`, exposes `WashiZ3`)
|
|
53
|
+
Classic `<script>` tags load immediately invoked function expression (`IIFE`) bundles that attach a global namespace to `window` (optional solver plugins auto-register when `window.Washi` is present). Assuming `dist/browser/` is hosted at `./washi/`:
|
|
54
|
+
|
|
55
|
+
| Solver | Browser ESM (`<script type="module">`) | Classic `<script>` IIFE |
|
|
56
|
+
| --- | --- | --- |
|
|
57
|
+
| **Core (HiGHS & Pumpkin)** | `import { Model, expr, maximize } from "./washi/washi.js";` | `<script src="./washi/washi.min.js"></script>` (global `Washi`) |
|
|
58
|
+
| **HiGHS** *(subpath API)* | `import { HighsSolver, setHighsWasmUrl } from "./washi/solvers/highs.js";` | Bundled in `washi.min.js` (pass `{ wasmUrl }` per call) |
|
|
59
|
+
| **Pumpkin** *(subpath API)* | `import { PumpkinSolver, setPumpkinWasmUrl } from "./washi/solvers/pumpkin.js";` | Bundled in `washi.min.js` (pass `{ wasmUrl }` per call) |
|
|
60
|
+
| **GLPK** *(optional)* | `import "./washi/solvers/glpk.js";` | `<script src="./washi/solvers/glpk.min.js"></script>` (`WashiGLPK`) |
|
|
61
|
+
| **Z3** *(optional)* | `import "./washi/solvers/z3.js";` | `<script src="./washi/solvers/z3.min.js"></script>` (`WashiZ3`) |
|
|
61
62
|
|
|
62
63
|
### WebAssembly Asset & Runtime Rules
|
|
63
64
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
65
|
+
#### Bundled WASM & Custom Asset URLs
|
|
66
|
+
|
|
67
|
+
- **Automatic resolution**: In Node.js and bundler builds, WaSHI resolves `.wasm` assets under `solvers/` relative to the module with no CDN fallback.
|
|
68
|
+
- **Browser self-hosting**: Deploy `dist/browser/` intact (entry scripts, `solvers/` runtime/worker/WASM assets, and chunks). Requests that hit missing URLs or HTML SPA fallbacks fail immediately and report the attempted URL.
|
|
69
|
+
- **Custom browser URLs**: Call `setHighsWasmUrl(url)` (from `@ohtaman/washi/solvers/highs`) or `setPumpkinWasmUrl(url)` (from `@ohtaman/washi/solvers/pumpkin`), or pass `{ wasmUrl }` to `m.solve()` / `m.check()`. This override is ignored for HiGHS in Node.js, while Pumpkin accepts `file://` URLs in Node.js. For Z3, call `setZ3Assets({ jsUrl, wasmUrl })` (from `@ohtaman/washi/solvers/z3`) or pass `{ z3JsUrl, z3WasmUrl }`.
|
|
70
|
+
|
|
71
|
+
#### Browser Security & Cross-Origin Isolation
|
|
72
|
+
|
|
73
|
+
- **HiGHS, Pumpkin, and GLPK**: Run in standard browser contexts without `SharedArrayBuffer` or isolation headers.
|
|
74
|
+
- **Z3 browser preconditions**: Z3 uses `SharedArrayBuffer` multithreading, so browsers require a Secure Context (`window.isSecureContext === true`, HTTPS or `localhost`) and `window.crossOriginIsolated === true`.
|
|
75
|
+
- **Required Z3 headers**: Serve the document with `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp` (`COOP`/`COEP`). Cross-origin script and WASM assets also require `Cross-Origin-Resource-Policy: cross-origin` (`CORP`) or valid CORS headers (`Access-Control-Allow-Origin`), depending on the request mode.
|
|
76
|
+
- **Fail-fast check & no auto-injected Service Worker**: Importing `@ohtaman/washi` never injects a Service Worker. `m.solve()` and `m.check()` with Z3 reject immediately if a secure context or Cross-Origin Isolation is missing.
|
|
77
|
+
|
|
78
|
+
#### Web Workers & Cancellation (`AbortSignal`)
|
|
79
|
+
|
|
80
|
+
- **Default Workers**: On standard browser origins (`window.origin !== "null"`), HiGHS and Pumpkin default to Web Workers (`useWorker: true`). On opaque origins (`window.origin === "null"`, such as `file://` pages or sandboxed iframes without `allow-same-origin`), both default to `useWorker: false`.
|
|
81
|
+
- **Worker cancellation**: Pre-solve cancellation (`signal.aborted`) works on all solvers, and `{ signal }` terminates in-flight HiGHS and Pumpkin Workers immediately.
|
|
82
|
+
- **Main-thread & Node.js cancellation**: HiGHS checks `signal` during `onProgress` callbacks, Pumpkin polls `signal` at search checkpoints, and GLPK/Z3 only check `signal` before starting.
|
|
83
|
+
|
|
84
|
+
#### Solver Capabilities, Options, & Validation Errors
|
|
85
|
+
|
|
86
|
+
| Solver | Problem Classes | Accepted Options | Throws On |
|
|
87
|
+
| --- | --- | --- | --- |
|
|
88
|
+
| **HiGHS** *(default)* | Linear (`LP`), mixed-integer (`MIP`), and convex quadratic (`QP`) | `timeLimit`, `presolve`, `relativeGap`, `absoluteGap`, `outputFlag`, `relax`, `useWorker`, `wasmUrl`, `signal`, `onProgress` | `threads`, `verbose` (use `outputFlag`), unknown keys, MIQP (quadratic objective with integer/binary/boolean variables) |
|
|
89
|
+
| **Pumpkin** | Constraint Programming (`CP`), bounded discrete `unsatCore` | `timeLimit`, `useWorker`, `wasmUrl`, `signal`, `onProgress` | `relax: true`, `presolve`, `relativeGap`, `absoluteGap`, `threads`, `verbose`, `outputFlag`, unknown keys, `Continuous` variables, unbounded variables or bounds outside `[-(2^30 - 1), 2^30 - 1]`, fractional coefficients/RHS, `QuadExpr` |
|
|
90
|
+
| **Z3** | Satisfiability Modulo Theories (`SMT`), continuous/discrete `unsatCore` | `signal`, `onProgress`, `z3JsUrl`, `z3WasmUrl` | `relax: true`, `useWorker: true`, `timeLimit`, `presolve`, `relativeGap`, `absoluteGap`, `threads`, `verbose`, `outputFlag`, unknown keys, `QuadExpr`, variable `initialValue` |
|
|
91
|
+
| **GLPK** | `LP`, `MIP` | `timeLimit`, `presolve`, `relativeGap`, `verbose`, `relax`, `signal`, `onProgress` | `useWorker: true`, `absoluteGap`, `threads`, `outputFlag` (use `verbose`), unknown keys, `QuadExpr`, variable `initialValue` |
|
|
92
|
+
|
|
93
|
+
Warm-start hints live on variables (`initialValue`), not `solve()`/`check()` options; see Step 1 below for solver support.
|
|
79
94
|
|
|
80
95
|
---
|
|
81
96
|
|
|
@@ -93,7 +108,7 @@ const x = m.continuous("x", { lb: 0, ub: 100 });
|
|
|
93
108
|
const y = m.continuous("y", { lb: 0, ub: 100 });
|
|
94
109
|
const n = m.integer("n", { lb: 0, ub: 10 });
|
|
95
110
|
const b = m.binary("b");
|
|
96
|
-
const flag = m.bool("flag"); // Propositional boolean (auto 0-1 MIP on HiGHS/GLPK, native
|
|
111
|
+
const flag = m.bool("flag"); // Propositional boolean (auto 0-1 MIP on HiGHS/GLPK, native CP/SMT on Pumpkin/Z3)
|
|
97
112
|
|
|
98
113
|
// Indexed variable containers:
|
|
99
114
|
// - Numeric dimension -> Array
|
|
@@ -104,30 +119,40 @@ const byItem = m.integer(["desk", "chair"] as const, { lb: 0 }); // Record<"desk
|
|
|
104
119
|
const mixed = m.binary(["A", "B"] as const, 3); // Record<"A" | "B", Var[]>
|
|
105
120
|
```
|
|
106
121
|
|
|
107
|
-
- **
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
- Supported by **HiGHS** and **Pumpkin** (`supportsWarmStart: true`); solvers without warm-start support (**GLPK**, **Z3**) throw an error if any variable has `initialValue !== undefined`.
|
|
122
|
+
- **Primal hints**: Numeric variable constructors and `v.initialValue` accept a finite starting value, validated against `[lb, ub]` and checked for integrality (tolerance `1e-6`), and kept distinct from the solved `v.value`.
|
|
123
|
+
- **Hint semantics**: Complete or partial warm starts do not fix variables, add hard constraints, or guarantee solver acceptance or speedup.
|
|
124
|
+
- **Warm-start support**: Supported by HiGHS and Pumpkin (`supportsWarmStart: true`). GLPK and Z3 throw if any variable has `initialValue` set.
|
|
111
125
|
|
|
112
126
|
### Step 2: Build Expressions (`expr`, `sum`, `dot`, `max`, `min`, `abs`, `at`)
|
|
113
127
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
128
|
+
#### Unified `expr` Template Tag
|
|
129
|
+
|
|
130
|
+
| Form | Examples | Notes |
|
|
131
|
+
| --- | --- | --- |
|
|
132
|
+
| Linear (`LinExpr`) | `` expr`30 * ${x} + 50 * ${n} - 10` ``, `` expr`dot(${profit}, ${byItem}) - 20 * ${b}` `` | Also supports `` expr`sum((${price} - ${cost}) * ${byItem})` ``. |
|
|
133
|
+
| Piecewise & element | `` expr`max(${vec}) + sum(abs(${vec} - ${target}))` ``, `` expr`at(${costs}, ${idx})` `` | `at()` enforces `0 <= idx < costs.length` on 0-based integer `idx`. Convex uses (e.g., minimizing `max`/`abs`) stay pure LP on HiGHS/GLPK; non-convex contexts require finite bounds. |
|
|
134
|
+
| Quadratic (`QuadExpr`) | `` expr`${x}^2 + 2 * ${x} * ${y} + ${y}^2` ``, `` expr`sum((${vec} - ${target})^2)` `` | Supported on HiGHS for convex QP objectives over continuous variables (`m.continuous`); MIQP and quadratic constraints are rejected, and other solvers reject `QuadExpr`. |
|
|
135
|
+
| Constraint (`Constraint`) | `` expr`${x} + 2 * ${n} <= 40` ``, `` expr`sum(${byItem}) <= 100` `` | Supports `<=`, `>=`, `==`, `=`, plus integer-only `<`, `>`, `!=`. |
|
|
136
|
+
|
|
137
|
+
#### Aggregations & Fluent Methods
|
|
138
|
+
|
|
139
|
+
- **`sum(containerOrItems, mapper?)`**: Sums a 1D/2D `Array`, `Iterable`, or plain object (`Record`) of variables, expressions, or numbers, optionally transforming each item with `mapper`. Inside `` expr`sum(...)` ``, element-wise `+`, `-`, `*`, `/`, `^2`, and `abs(...)` also work.
|
|
140
|
+
- **`dot(a, b)`**: Computes the inner product of matching 1D arrays, 2D arrays (Frobenius inner product $\sum_{i,j} A_{i,j} B_{i,j}$), plain objects, or mixed `Array`/`Record` containers.
|
|
141
|
+
- **Fluent arithmetic & comparisons**: `.add()`, `.sub()`, `.mul()`, `.div(scalar)`, `.neg()`, plus `.le()`, `.ge()`, `.eq()`, and integer-only `.lt()`, `.gt()`, `.ne()` (all taking `(rhs, name?)`; continuous/fractional operands throw on strict/not-equal comparisons).
|
|
142
|
+
|
|
143
|
+
#### CP Global Constraints & Boolean Logic
|
|
144
|
+
|
|
145
|
+
| Helper | Purpose | Solver Lowering |
|
|
146
|
+
| --- | --- | --- |
|
|
147
|
+
| `distinct(...args)` | All variables take pairwise distinct values | Native on Pumpkin and Z3; pairwise `!=` on HiGHS/GLPK. |
|
|
148
|
+
| `disjoint(tasks)` | Non-overlapping intervals (`{ start, duration }`) | Native scheduling propagator on Pumpkin; linearized on MIP solvers. |
|
|
149
|
+
| `cumulative(tasks, capacity)` | Shared resource capacity (`{ start, duration, demand }`) | Native propagator on Pumpkin; MIP time-indexed encoding enforces a horizon memory guard. |
|
|
150
|
+
| `allowed(vars, tuples)` | Restrict variable tuples to an allowed table | Native table propagator on Pumpkin; linearized on MIP solvers. |
|
|
151
|
+
| `and`, `or`, `not`, `implies`, `xor` | Composable boolean logic (standalone or fluent) | Native on Pumpkin and Z3; linearized to 0-1 MIP on HiGHS/GLPK (negated continuous constraints throw on MIP—use `{ solver: "z3" }` or reformulate with boolean variables). |
|
|
127
152
|
|
|
128
153
|
### Step 3: Register Objective & Constraints on the Model
|
|
129
154
|
|
|
130
|
-
Constructing an `expr` or `.le()`
|
|
155
|
+
Constructing an expression or constraint via `expr` or `.le()` does **not** attach it to the model until you call `m.constraint(...)` or `m.objective(...)`. In `m.indicator()`, omitting `options.M` derives tight Big-M bounds for MIP solvers while keeping native indicator lowering on Pumpkin and Z3:
|
|
131
156
|
|
|
132
157
|
```ts
|
|
133
158
|
// Set objective using maximize() or minimize()
|
|
@@ -136,22 +161,29 @@ m.objective(maximize(expr`30 * ${x} + 50 * ${n}`));
|
|
|
136
161
|
// Register constraints on the model (returns the registered Constraint / BoolExpr or array)
|
|
137
162
|
const limit = m.constraint(expr`${x} + 2 * ${n} <= 40`, "resource_limit");
|
|
138
163
|
|
|
139
|
-
// Indicator constraint (
|
|
164
|
+
// Indicator constraint (b === 1 => x <= 50; Big-M on MIP, native on Pumpkin/Z3)
|
|
140
165
|
m.indicator(b, expr`${x} <= 50`, { activeValue: 1, name: "cap_when_b" });
|
|
141
166
|
```
|
|
142
167
|
|
|
143
168
|
### Step 4: Execute (`solve` or `check`) & Verify (`verify`)
|
|
144
169
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
- **
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
170
|
+
#### Optimization (`await m.solve(options?)`)
|
|
171
|
+
|
|
172
|
+
- **Return value**: Returns `SolverStatus` (`"Optimal"`, `"Feasible"`, `"Infeasible"`, `"Unbounded"`, `"TimeLimit"`, `"IterationLimit"`, `"Error"`, `"Unknown"`, `"NotSolved"`, `"Sat"`, or `"Unsat"`).
|
|
173
|
+
- **Status semantics**: Optimization solvers return `"Feasible"` when a limit or abort terminates the solve with a valid primal incumbent. `"Sat"` and `"Unsat"` apply to satisfiability or custom solver adapters.
|
|
174
|
+
- **Reading results**: Check `m.hasPrimalSolution`, then read `x.value`, `` expr`...`.value ``, `m.objectiveValue`, `constr.dual`, `constr.slack`, and `x.reducedCost`. `m.values` (like `m.variables` and `m.constraints`) is a `ReadonlyMap<string, number | boolean>` (use `.get(name)`), unlike `CheckResult.values` and `m.solution.values` (`Record`).
|
|
175
|
+
- **Independent verification**: `m.verify()` checks primal feasibility—finiteness, bounds, integrality, and constraints—returning `VerificationReport` (`{ valid, complete, maxViolation, violations }`) without recomputing `m.objectiveValue`.
|
|
176
|
+
|
|
177
|
+
#### Satisfiability & Conflict Diagnosis (`await m.check(options?)`)
|
|
178
|
+
|
|
179
|
+
- **Return value**: Returns `CheckResult` (`{ status: "Sat" | "Unsat" | "Unknown", values: Record<string, number | boolean>, conflicts?: readonly string[], unsatCore?: readonly string[], runTime?: number }`).
|
|
180
|
+
- **HiGHS & GLPK**: Diagnose linear and logical conflicts in `conflicts` via slack relaxation, leaving `unsatCore` as `undefined`.
|
|
181
|
+
- **Pumpkin & Z3**: Extract an exact unsatisfiable core into both `unsatCore` and `conflicts`. Use Pumpkin for bounded integer/boolean models and Z3 when continuous or fractional constraints are present.
|
|
182
|
+
- **Bounds caveat**: Variable bounds `lb`/`ub` and binary domains are asserted directly, so `unsatCore` reports constraint names that conflict *together with those variable bounds* (not guaranteed minimal).
|
|
183
|
+
|
|
184
|
+
#### Concurrent Mutation Rule
|
|
185
|
+
|
|
186
|
+
- Mutating variables, constraints, or the objective while an `m.solve()` or `m.check()` call is pending invalidates the in-flight run and rejects the stale promise.
|
|
155
187
|
|
|
156
188
|
---
|
|
157
189
|
|
|
@@ -160,11 +192,11 @@ m.indicator(b, expr`${x} <= 50`, { activeValue: 1, name: "cap_when_b" });
|
|
|
160
192
|
1. DO NOT pass a Constraint to m.objective() or arithmetic methods:
|
|
161
193
|
- `` WRONG: m.objective(maximize(expr`${x} <= 10` as any)); -> throws Error ``
|
|
162
194
|
- `` WRONG: expr`${x} + 1`.add(expr`${y} <= 5` as any); -> throws Error ``
|
|
163
|
-
2. DO NOT pass
|
|
195
|
+
2. DO NOT pass a bare arithmetic expression without a comparison operator (<=, >=, ==, etc.) to m.constraint():
|
|
164
196
|
- `` WRONG: m.constraint(expr`${x} + ${y}` as any); -> throws Error ``
|
|
165
|
-
3. DO NOT use quadratic terms
|
|
197
|
+
3. DO NOT use quadratic terms in constraints:
|
|
166
198
|
- `` WRONG: expr`${x}^2 <= 10`; -> throws Error ("Quadratic constraints are not supported") ``
|
|
167
|
-
4. DO NOT use retired aliases
|
|
199
|
+
4. DO NOT use retired aliases:
|
|
168
200
|
- Use `expr` instead of retired `c` template tag
|
|
169
201
|
- Use `m.constraint(...)` instead of `m.constrain(...)` or `m.add(...)`
|
|
170
202
|
- Use `m.objective(maximize(...))` / `m.objective(minimize(...))` / `m.objective()` instead of `m.maximize(...)` / `m.minimize(...)` / `m.setObjective(...)` / `m.objectiveExpr`
|
|
@@ -182,43 +214,43 @@ m.indicator(b, expr`${x} <= 50`, { activeValue: 1, name: "cap_when_b" });
|
|
|
182
214
|
|
|
183
215
|
### Getting Started
|
|
184
216
|
|
|
185
|
-
- [AI Coding Agent Quick-Reference Guide](docs/getting-started/ai-agents.md): This document is the **
|
|
186
|
-
- [Introduction & Installation](docs/getting-started/index.md): **WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) brings
|
|
187
|
-
- [Runtime Environments & Deployment](docs/getting-started/runtimes.md): WaSHI runs across JavaScript and TypeScript runtimes
|
|
188
|
-
- [Cross-Origin Isolation (Z3 & Browsers)](docs/getting-started/cross-origin.md):
|
|
217
|
+
- [AI Coding Agent Quick-Reference Guide](docs/getting-started/ai-agents.md): This document is the **modeling quick reference** for AI coding agents and developers building optimization or satisfiability models with `@ohtaman/washi`.
|
|
218
|
+
- [Introduction & Installation](docs/getting-started/index.md): **WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) brings Python PuLP-style algebraic modeling to TypeScript and JavaScript.
|
|
219
|
+
- [Runtime Environments & Deployment](docs/getting-started/runtimes.md): WaSHI runs across JavaScript and TypeScript runtimes and deployment targets without native solver compilation.
|
|
220
|
+
- [Cross-Origin Isolation (Z3 & Browsers)](docs/getting-started/cross-origin.md): Running the Z3 solver in a browser requires two browser security conditions: a **Secure Context** and **Cross-Origin Isolation**.
|
|
189
221
|
|
|
190
222
|
### Modeling Guide
|
|
191
223
|
|
|
192
|
-
- [Variables & Domains](docs/guide/variables.md): Variables represent the
|
|
193
|
-
- [Expressions (`expr`, `sum`, `dot`)](docs/guide/expressions.md): Mathematical expressions
|
|
194
|
-
- [Constraints (`m.constraint` & `m.indicator`)](docs/guide/constraints.md): Constraints
|
|
195
|
-
- [Objectives & Solving (`m.solve` & `m.check`)](docs/guide/objectives.md): The objective function defines the goal of mathematical optimization
|
|
196
|
-
- [Conflict Diagnosis (`unsatCore`), Validation & Debugging](docs/guide/unsat-core.md): When
|
|
197
|
-
- [Constraint Programming (CP) Modeling](docs/guide/constraint-programming.md): WaSHI
|
|
198
|
-
- [Decomposition Methods (`solveColumnGeneration` & `solveBenders`)](docs/guide/decomposition.md):
|
|
199
|
-
- [Formulation Patterns & Optimization Tips](docs/guide/formulation-tips.md):
|
|
224
|
+
- [Variables & Domains](docs/guide/variables.md): Variables represent the unknown decision quantities in an optimization or logical model.
|
|
225
|
+
- [Expressions (`expr`, `sum`, `dot`)](docs/guide/expressions.md): Mathematical expressions combine decision variables and numeric coefficients into linear, quadratic, or piecewise-linear formulas.
|
|
226
|
+
- [Constraints (`m.constraint` & `m.indicator`)](docs/guide/constraints.md): Constraints define the rules that every valid solution must satisfy.
|
|
227
|
+
- [Objectives & Solving (`m.solve` & `m.check`)](docs/guide/objectives.md): The objective function defines the goal of mathematical optimization, such as maximizing profit, minimizing cost, or minimizing quadratic variance.
|
|
228
|
+
- [Conflict Diagnosis (`unsatCore`), Validation & Debugging](docs/guide/unsat-core.md): When `m.solve()` returns `"Infeasible"`, it proves that no solution satisfies every rule, but does not tell you *which* rules clash.
|
|
229
|
+
- [Constraint Programming (CP) Modeling](docs/guide/constraint-programming.md): WaSHI lets you write both Mathematical Optimization (LP / MIP / QP) and Constraint Programming (CP) models with the same TypeScript API.
|
|
230
|
+
- [Decomposition Methods (`solveColumnGeneration` & `solveBenders`)](docs/guide/decomposition.md): Both helpers are also exported as standalone functions—`solveColumnGeneration({ master, ...
|
|
231
|
+
- [Formulation Patterns & Optimization Tips](docs/guide/formulation-tips.md): The preceding guide pages cover WaSHI's core APIs (`Model`, `expr`, `m.constraint`, `m.solve`).
|
|
200
232
|
|
|
201
233
|
### Solvers
|
|
202
234
|
|
|
203
|
-
- [Solvers Overview](docs/solvers/index.md): WaSHI
|
|
204
|
-
- [HiGHS Solver Engine](docs/solvers/highs.md): **HiGHS** is
|
|
205
|
-
- [Pumpkin Constraint Programming Solver](docs/solvers/pumpkin.md): **Pumpkin** is
|
|
206
|
-
- [Z3 SMT Solver Engine](docs/solvers/z3.md): **Z3** is
|
|
207
|
-
- [GLPK Solver Engine](docs/solvers/glpk.md): The **GNU Linear Programming Kit (GLPK)** is
|
|
208
|
-
- [WaSHI Custom Solver Developer Guide](docs/solvers/custom-solver.md): This guide
|
|
235
|
+
- [Solvers Overview](docs/solvers/index.md): WaSHI uses a pluggable solver architecture.
|
|
236
|
+
- [HiGHS Solver Engine](docs/solvers/highs.md): **HiGHS** is an open-source mathematical optimization solver started at the University of Edinburgh (highs.dev · ERGO-Code/HiGHS).
|
|
237
|
+
- [Pumpkin Constraint Programming Solver](docs/solvers/pumpkin.md): **Pumpkin** is an open-source Constraint Programming (CP) solver written in Rust and maintained by ConSol-Lab/Pumpkin.
|
|
238
|
+
- [Z3 SMT Solver Engine](docs/solvers/z3.md): **Z3** is an open-source theorem prover and Satisfiability Modulo Theories (SMT) solver from Microsoft Research.
|
|
239
|
+
- [GLPK Solver Engine](docs/solvers/glpk.md): 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).
|
|
240
|
+
- [WaSHI Custom Solver Developer Guide](docs/solvers/custom-solver.md): This guide explains how to build, test, and distribute custom solver plugins for **WaSHI** (`@ohtaman/washi`).
|
|
209
241
|
|
|
210
242
|
### Examples
|
|
211
243
|
|
|
212
244
|
- [Examples & API Finder](docs/examples/index.md): Explore runnable optimization and logic formulations built with WaSHI.
|
|
213
|
-
- [Production Planning (
|
|
214
|
-
- [0-1 Knapsack Problem (Binary MIP)](docs/examples/knapsack.md): The 0-1 Knapsack problem is
|
|
215
|
-
- [Transportation & Allocation Network (LP)](docs/examples/transportation.md): The transportation problem
|
|
216
|
-
- [Diet Problem & Sensitivity Analysis (LP Duals & Slacks)](docs/examples/diet-sensitivity.md):
|
|
217
|
-
- [Staff Shift Scheduling & Conflict Diagnosis (MIP + Z3)](docs/examples/shift-scheduling.md):
|
|
218
|
-
- [E-Commerce Cart & Coupon Optimizer (Indicator MIP)](docs/examples/ecommerce-coupons.md):
|
|
219
|
-
- [Portfolio Optimization (QP)](docs/examples/portfolio-qp.md): The Markowitz mean-variance
|
|
220
|
-
- [Resource-Constrained Project Scheduling (CP / Pumpkin)](docs/examples/project-scheduling.md): The **Resource-Constrained Project Scheduling Problem (RCPSP)**
|
|
221
|
-
- [SMT Security Policies](docs/examples/smt-security.md): Satisfiability Modulo Theories (SMT) combines
|
|
222
|
-
- [Conflict Diagnosis (Unsat Core)](docs/examples/unsat-core.md):
|
|
223
|
-
- [Capacitated Vehicle Routing Problem (CVRP, 50 Customers via Column Generation)](docs/examples/vehicle-routing.md):
|
|
224
|
-
- [Traveling Salesperson Problem (TSP via Benders Decomposition)](docs/examples/traveling-salesperson.md): The **Traveling Salesperson Problem (TSP)**
|
|
245
|
+
- [Production Planning (Integer Programming / MIP)](docs/examples/production.md): Production planning is a classic optimization problem.
|
|
246
|
+
- [0-1 Knapsack Problem (Binary MIP)](docs/examples/knapsack.md): The 0-1 Knapsack problem is a fundamental combinatorial optimization problem.
|
|
247
|
+
- [Transportation & Allocation Network (LP)](docs/examples/transportation.md): The **transportation problem** decides how many units to ship from each factory to each store.
|
|
248
|
+
- [Diet Problem & Sensitivity Analysis (LP Duals & Slacks)](docs/examples/diet-sensitivity.md): We determine daily servings ($0 \le x_i \le 4$, continuous) for each of 6 foods to minimize daily cost.
|
|
249
|
+
- [Staff Shift Scheduling & Conflict Diagnosis (MIP + Z3)](docs/examples/shift-scheduling.md): In staff shift scheduling, vacation requests often collide with minimum headcount or senior coverage rules, causing a Mixed-Integer Programming (MIP) solver to return `"Infeasible"`.
|
|
250
|
+
- [E-Commerce Cart & Coupon Optimizer (Indicator MIP)](docs/examples/ecommerce-coupons.md): E-commerce checkouts often combine minimum spend thresholds, category discounts, mutually exclusive coupons, and per-order coupon caps.
|
|
251
|
+
- [Portfolio Optimization (QP)](docs/examples/portfolio-qp.md): The Markowitz mean-variance model is a classic problem in quantitative finance.
|
|
252
|
+
- [Resource-Constrained Project Scheduling (CP / Pumpkin)](docs/examples/project-scheduling.md): The **Resource-Constrained Project Scheduling Problem (RCPSP)** schedules project tasks to minimize the maximum completion time, known as the **makespan**.
|
|
253
|
+
- [SMT Security Policies](docs/examples/smt-security.md): **Satisfiability Modulo Theories (SMT)** combines Boolean logic with arithmetic inequalities such as integer bounds and linear comparisons.
|
|
254
|
+
- [Conflict Diagnosis (Unsat Core)](docs/examples/unsat-core.md): A standard optimization call (`m.solve()`) only reports `"Infeasible"` when constraints clash.
|
|
255
|
+
- [Capacitated Vehicle Routing Problem (CVRP, 50 Customers via Column Generation)](docs/examples/vehicle-routing.md): This **Capacitated Vehicle Routing Problem (CVRP)** variant minimizes the number of delivery vehicles needed to serve every customer.
|
|
256
|
+
- [Traveling Salesperson Problem (TSP via Benders Decomposition)](docs/examples/traveling-salesperson.md): The **Traveling Salesperson Problem (TSP)** finds the shortest closed tour that visits every city once and returns to the starting city.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohtaman/washi",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2",
|
|
4
4
|
"description": "WaSHI: TypeScript & JavaScript algebraic modeler for Mathematical Optimization & Constraint Programming (LP, MILP, QP, CP, SMT) powered by WebAssembly (HiGHS, Pumpkin, Z3, GLPK)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/lib/washi.js",
|
|
@@ -12,49 +12,58 @@
|
|
|
12
12
|
"import": "./dist/lib/washi.js",
|
|
13
13
|
"default": "./dist/lib/washi.js"
|
|
14
14
|
},
|
|
15
|
-
"./highs
|
|
15
|
+
"./solvers/highs": {
|
|
16
|
+
"types": "./dist/types/modeler/solvers/highs/index.d.ts",
|
|
17
|
+
"import": "./dist/lib/solvers/highs.js",
|
|
18
|
+
"default": "./dist/lib/solvers/highs.js"
|
|
19
|
+
},
|
|
20
|
+
"./solvers/highs.wasm": "./dist/lib/solvers/highs.wasm",
|
|
21
|
+
"./solvers/pumpkin": {
|
|
22
|
+
"types": "./dist/types/modeler/solvers/pumpkin/index.d.ts",
|
|
23
|
+
"import": "./dist/lib/solvers/pumpkin.js",
|
|
24
|
+
"default": "./dist/lib/solvers/pumpkin.js"
|
|
25
|
+
},
|
|
26
|
+
"./solvers/pumpkin.wasm": "./dist/lib/solvers/pumpkin.wasm",
|
|
16
27
|
"./solvers/z3": {
|
|
17
28
|
"types": "./dist/types/modeler/solvers/z3/index.d.ts",
|
|
18
29
|
"import": "./dist/lib/solvers/z3.js",
|
|
19
30
|
"default": "./dist/lib/solvers/z3.js"
|
|
20
31
|
},
|
|
32
|
+
"./solvers/z3-built.js": "./dist/lib/solvers/z3-built.js",
|
|
33
|
+
"./solvers/z3-built.wasm": "./dist/lib/solvers/z3-built.wasm",
|
|
21
34
|
"./solvers/glpk": {
|
|
22
35
|
"types": "./dist/types/modeler/solvers/glpk/index.d.ts",
|
|
23
36
|
"import": "./dist/lib/solvers/glpk.js",
|
|
24
37
|
"default": "./dist/lib/solvers/glpk.js"
|
|
25
38
|
},
|
|
26
|
-
"./solvers/pumpkin": {
|
|
27
|
-
"types": "./dist/types/modeler/solvers/pumpkin/index.d.ts",
|
|
28
|
-
"import": "./dist/lib/solvers/pumpkin.js",
|
|
29
|
-
"default": "./dist/lib/solvers/pumpkin.js"
|
|
30
|
-
},
|
|
31
|
-
"./solvers/pumpkin.wasm": "./dist/lib/solvers/pumpkin.wasm",
|
|
32
39
|
"./browser": {
|
|
33
40
|
"types": "./dist/types/index.d.ts",
|
|
34
41
|
"import": "./dist/browser/washi.js",
|
|
35
42
|
"default": "./dist/browser/washi.js"
|
|
36
43
|
},
|
|
37
44
|
"./browser/washi.min.js": "./dist/browser/washi.min.js",
|
|
38
|
-
"./browser/solvers/
|
|
39
|
-
"types": "./dist/types/modeler/solvers/
|
|
40
|
-
"import": "./dist/browser/solvers/
|
|
41
|
-
"default": "./dist/browser/solvers/
|
|
45
|
+
"./browser/solvers/highs": {
|
|
46
|
+
"types": "./dist/types/modeler/solvers/highs/index.d.ts",
|
|
47
|
+
"import": "./dist/browser/solvers/highs.js",
|
|
48
|
+
"default": "./dist/browser/solvers/highs.js"
|
|
49
|
+
},
|
|
50
|
+
"./browser/solvers/pumpkin": {
|
|
51
|
+
"types": "./dist/types/modeler/solvers/pumpkin/index.d.ts",
|
|
52
|
+
"import": "./dist/browser/solvers/pumpkin.js",
|
|
53
|
+
"default": "./dist/browser/solvers/pumpkin.js"
|
|
42
54
|
},
|
|
43
|
-
"./browser/solvers/glpk.min.js": "./dist/browser/solvers/glpk.min.js",
|
|
44
55
|
"./browser/solvers/z3": {
|
|
45
56
|
"types": "./dist/types/modeler/solvers/z3/index.d.ts",
|
|
46
57
|
"import": "./dist/browser/solvers/z3.js",
|
|
47
58
|
"default": "./dist/browser/solvers/z3.js"
|
|
48
59
|
},
|
|
49
60
|
"./browser/solvers/z3.min.js": "./dist/browser/solvers/z3.min.js",
|
|
50
|
-
"./browser/solvers/
|
|
51
|
-
"types": "./dist/types/modeler/solvers/
|
|
52
|
-
"import": "./dist/browser/solvers/
|
|
53
|
-
"default": "./dist/browser/solvers/
|
|
61
|
+
"./browser/solvers/glpk": {
|
|
62
|
+
"types": "./dist/types/modeler/solvers/glpk/index.d.ts",
|
|
63
|
+
"import": "./dist/browser/solvers/glpk.js",
|
|
64
|
+
"default": "./dist/browser/solvers/glpk.js"
|
|
54
65
|
},
|
|
55
|
-
"./browser/solvers/
|
|
56
|
-
"./solvers/z3-built.js": "./dist/lib/solvers/z3-built.js",
|
|
57
|
-
"./solvers/z3-built.wasm": "./dist/lib/solvers/z3-built.wasm"
|
|
66
|
+
"./browser/solvers/glpk.min.js": "./dist/browser/solvers/glpk.min.js"
|
|
58
67
|
},
|
|
59
68
|
"files": [
|
|
60
69
|
"dist/lib",
|
|
@@ -69,8 +78,6 @@
|
|
|
69
78
|
"llms.txt",
|
|
70
79
|
"llms-full.txt",
|
|
71
80
|
"README.md",
|
|
72
|
-
"README.ja.md",
|
|
73
|
-
"README.zh-CN.md",
|
|
74
81
|
"LICENSE",
|
|
75
82
|
"THIRD_PARTY_LICENSES.md"
|
|
76
83
|
],
|