@ohtaman/washi 0.6.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 +139 -418
- package/README.md +139 -418
- package/README.zh-CN.md +139 -418
- package/THIRD_PARTY_LICENSES.md +39 -4
- 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 +3828 -1315
- 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 +3054 -1202
- 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 +176 -28
- package/dist/types/modeler/expression.d.ts.map +1 -1
- package/dist/types/modeler/index.d.ts +5 -6
- 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 +97 -130
- package/dist/types/modeler/model.d.ts.map +1 -1
- package/dist/types/modeler/parser.d.ts +25 -5
- 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 +9 -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/diet-sensitivity.md +15 -14
- package/docs/examples/ecommerce-coupons.md +15 -22
- package/docs/examples/index.md +20 -13
- package/docs/examples/knapsack.md +8 -7
- package/docs/examples/portfolio-qp.md +11 -4
- package/docs/examples/production.md +4 -4
- package/docs/examples/project-scheduling.md +106 -0
- package/docs/examples/shift-scheduling.md +23 -7
- package/docs/examples/smt-security.md +17 -4
- package/docs/examples/transportation.md +46 -19
- package/docs/examples/traveling-salesperson.md +29 -45
- package/docs/examples/unsat-core.md +16 -5
- package/docs/examples/vehicle-routing.md +10 -8
- package/docs/getting-started/ai-agents.md +114 -34
- package/docs/getting-started/coding-agents.md +158 -0
- package/docs/getting-started/cross-origin.md +56 -28
- package/docs/getting-started/index.md +36 -66
- package/docs/getting-started/runtimes.md +98 -69
- package/docs/guide/constraint-programming.md +141 -0
- package/docs/guide/constraints.md +100 -44
- package/docs/guide/decomposition.md +141 -273
- package/docs/guide/expressions.md +125 -42
- package/docs/guide/formulation-tips.md +212 -0
- package/docs/guide/objectives.md +70 -64
- package/docs/guide/unsat-core.md +44 -23
- package/docs/guide/variables.md +56 -48
- package/docs/solvers/custom-solver.md +18 -13
- package/docs/solvers/highs.md +41 -25
- package/docs/solvers/index.md +13 -7
- package/docs/solvers/pumpkin.md +163 -0
- package/docs/solvers/z3.md +4 -1
- package/llms-full.txt +1732 -860
- package/llms.txt +59 -36
- package/package.json +40 -13
- package/skills/washi/SKILL.md +91 -35
- 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-C20sxTwm.js +0 -964
- package/docs/ja/getting-started/ai-agents.md +0 -270
- package/docs/zh/getting-started/ai-agents.md +0 -270
package/llms.txt
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
# WaSHI (@ohtaman/washi)
|
|
2
2
|
|
|
3
|
-
> WaSHI:
|
|
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 brings the algebraic modeling style of Python's **PuLP**
|
|
5
|
+
**WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) brings the algebraic modeling style of Python's **PuLP** to the TypeScript and JavaScript ecosystem.
|
|
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)
|
|
@@ -19,6 +19,14 @@ import {
|
|
|
19
19
|
expr,
|
|
20
20
|
sum,
|
|
21
21
|
dot,
|
|
22
|
+
abs,
|
|
23
|
+
max,
|
|
24
|
+
min,
|
|
25
|
+
at,
|
|
26
|
+
distinct,
|
|
27
|
+
disjoint,
|
|
28
|
+
cumulative,
|
|
29
|
+
allowed,
|
|
22
30
|
maximize,
|
|
23
31
|
minimize,
|
|
24
32
|
and,
|
|
@@ -29,6 +37,8 @@ import {
|
|
|
29
37
|
setHighsWasmUrl,
|
|
30
38
|
} from "@ohtaman/washi";
|
|
31
39
|
|
|
40
|
+
// Bundled CP/LCG solver plugin (zero external dependencies; registers "pumpkin"):
|
|
41
|
+
import { setPumpkinWasmUrl } from "@ohtaman/washi/solvers/pumpkin";
|
|
32
42
|
// Optional solver plugins (require installing peer dependencies first):
|
|
33
43
|
// npm install z3-solver
|
|
34
44
|
import "@ohtaman/washi/solvers/z3";
|
|
@@ -40,10 +50,12 @@ import "@ohtaman/washi/solvers/glpk";
|
|
|
40
50
|
|
|
41
51
|
- **Browser ESM**:
|
|
42
52
|
- Core (HiGHS built-in): `import { Model, expr, maximize } from "./washi/washi.js";`
|
|
53
|
+
- Pumpkin plugin: `import "./washi/solvers/pumpkin.js";`
|
|
43
54
|
- GLPK plugin: `import "./washi/solvers/glpk.js";`
|
|
44
55
|
- Z3 plugin: `import "./washi/solvers/z3.js";`
|
|
45
56
|
- **Classic `<script>` / CodePen (IIFE)**:
|
|
46
57
|
- Core: `<script src="./washi/washi.min.js"></script>` (exposes global `Washi`)
|
|
58
|
+
- Pumpkin plugin: `<script src="./washi/solvers/pumpkin.min.js"></script>` (registers `"pumpkin"`, exposes `WashiPumpkin`)
|
|
47
59
|
- GLPK plugin: `<script src="./washi/solvers/glpk.min.js"></script>` (registers `"glpk"`, exposes `WashiGLPK`)
|
|
48
60
|
- Z3 plugin: `<script src="./washi/solvers/z3.min.js"></script>` (registers `"z3"`, exposes `WashiZ3`)
|
|
49
61
|
|
|
@@ -52,7 +64,8 @@ import "@ohtaman/washi/solvers/glpk";
|
|
|
52
64
|
1. **Bundled WASM by default (no implicit CDN fallback)**:
|
|
53
65
|
- In Node.js and modern bundlers, WebAssembly assets resolve relative to the module automatically.
|
|
54
66
|
- In browser deployments, deploy the full `dist/browser/` directory (JS, Worker, and `.wasm` files) together. If a local WASM URL is missing or returns an HTML SPA fallback, initialization fails immediately and reports the attempted URL—it **never** silently switches to a public CDN.
|
|
55
|
-
- In browser runtimes, to load `highs.wasm` from a custom location, call `setHighsWasmUrl("https://.../highs.wasm")` or
|
|
67
|
+
- In browser runtimes, to load `highs.wasm` or `pumpkin.wasm` from a custom location, call `setHighsWasmUrl("https://.../highs.wasm")` (or `await m.solve({ wasmUrl: "https://.../highs.wasm" })`) for HiGHS, or `setPumpkinWasmUrl("https://.../pumpkin.wasm")` (or `await m.solve({ solver: "pumpkin", wasmUrl: "https://.../pumpkin.wasm" })`) for Pumpkin (ignored in Node.js for HiGHS; for Pumpkin in Node.js, bundled local `pumpkin.wasm` is used by default unless overridden with a `file://` URL).
|
|
68
|
+
- **Pumpkin runs without `COOP`/`COEP`**: Unlike Z3, Pumpkin (`@ohtaman/washi/solvers/pumpkin`) uses single-threaded WASM inside a regular Web Worker and does **not** require `SharedArrayBuffer` or Cross-Origin Isolation headers (`COOP`/`COEP`). It requires bounded finite integer/binary variables (`lb`, `ub` in `[-(2^30 - 1), 2^30 - 1]`) and integer linear coefficients/RHS, and supports `initialValue` warm starts across `solve()` and `check()` (no `Continuous`, `QuadExpr`, or `relax: true`).
|
|
56
69
|
2. **Z3 requires a Secure Context, Cross-Origin Isolation, and CORS in browsers**:
|
|
57
70
|
- Z3 WebAssembly uses `SharedArrayBuffer` multithreading. Browser pages running Z3 must run in a secure context (`window.isSecureContext === true`, i.e., HTTPS or `localhost`) and be cross-origin isolated (`window.crossOriginIsolated === true`) by serving:
|
|
58
71
|
- `Cross-Origin-Opener-Policy: same-origin` (on the document)
|
|
@@ -61,8 +74,8 @@ import "@ohtaman/washi/solvers/glpk";
|
|
|
61
74
|
- Importing `@ohtaman/washi` never auto-injects a Service Worker. When a secure context or cross-origin isolation is absent in a browser, Z3 rejects immediately with a descriptive error.
|
|
62
75
|
3. **Web Workers & Cancellation (`AbortSignal`)**:
|
|
63
76
|
- Pre-solve cancellation (`signal.aborted` before execution starts) is supported across all solvers.
|
|
64
|
-
- In browsers where `Worker` is available, HiGHS
|
|
65
|
-
- On main-thread HiGHS (`useWorker: false` or in Node.js), cooperative mid-solve cancellation is supported when `abort()` is triggered synchronously inside an `onProgress` callback at a solver interrupt checkpoint; arbitrary asynchronous aborts from outside cannot preempt a blocked synchronous WASM thread until a callback checkpoint or completion. Single-threaded WASM solvers without interrupt hooks (GLPK, Z3) check `signal` before execution starts.
|
|
77
|
+
- In browsers where `Worker` is available on a non-opaque effective origin (`window.origin !== "null"`), both **HiGHS** and **Pumpkin** run in dedicated Web Workers by default (`useWorker: true`). On opaque effective origins (`window.origin === "null"`, such as `file:` URLs or `sandbox="allow-scripts"` `<iframe>` embeds without `allow-same-origin`), both default to main-thread execution (`useWorker: false`). Passing `{ signal }` to `m.solve({ signal })` or `m.check({ signal })` preemptively terminates an in-flight Worker run (or cancels queued Worker requests).
|
|
78
|
+
- On main-thread HiGHS (`useWorker: false` or in Node.js), cooperative mid-solve cancellation is supported when `abort()` is triggered synchronously inside an `onProgress` callback at a solver interrupt checkpoint; arbitrary asynchronous aborts from outside cannot preempt a blocked synchronous WASM thread until a callback checkpoint or completion. Main-thread / Node.js Pumpkin checks `should_abort` checkpoints across branching and termination hooks. Single-threaded WASM solvers without interrupt hooks (GLPK, Z3) check `signal` before execution starts.
|
|
66
79
|
|
|
67
80
|
---
|
|
68
81
|
|
|
@@ -77,9 +90,10 @@ const m = new Model("ExampleModel");
|
|
|
77
90
|
|
|
78
91
|
// Scalar variables
|
|
79
92
|
const x = m.continuous("x", { lb: 0, ub: 100 });
|
|
93
|
+
const y = m.continuous("y", { lb: 0, ub: 100 });
|
|
80
94
|
const n = m.integer("n", { lb: 0, ub: 10 });
|
|
81
95
|
const b = m.binary("b");
|
|
82
|
-
const flag = m.bool("flag"); // Propositional boolean (
|
|
96
|
+
const flag = m.bool("flag"); // Propositional boolean (auto 0-1 MIP on HiGHS/GLPK, native LCG/SMT on Pumpkin/Z3)
|
|
83
97
|
|
|
84
98
|
// Indexed variable containers:
|
|
85
99
|
// - Numeric dimension -> Array
|
|
@@ -93,47 +107,49 @@ const mixed = m.binary(["A", "B"] as const, 3); // Record<"A" | "B", Var[]>
|
|
|
93
107
|
- **Optional Primal Initial Values (`initialValue?: number`)**:
|
|
94
108
|
- Numeric variable constructors (`m.continuous`, `m.integer`, `m.binary`, and `new Var`) and the mutable `v.initialValue` property accept an optional finite primal hint (validated with tolerance `1e-6` against bounds `[lb, ub]` and integer/binary domains), kept distinct from the solved `v.value`.
|
|
95
109
|
- A start may be complete or partial (e.g., transferred by stable variable names when rebuilding a MIP model). Supplying `initialValue` is a hint only—it does **not** fix the variable, add a hard constraint, or guarantee solver acceptance or a runtime speedup.
|
|
96
|
-
- Supported by **HiGHS** (`supportsWarmStart: true`); solvers without warm-start support (**GLPK**, **Z3**) throw an error if any variable has `initialValue !== undefined`.
|
|
110
|
+
- Supported by **HiGHS** and **Pumpkin** (`supportsWarmStart: true`); solvers without warm-start support (**GLPK**, **Z3**) throw an error if any variable has `initialValue !== undefined`.
|
|
97
111
|
|
|
98
|
-
### Step 2: Build Expressions (`expr`, `sum`, `dot`)
|
|
112
|
+
### Step 2: Build Expressions (`expr`, `sum`, `dot`, `max`, `min`, `abs`, `at`)
|
|
99
113
|
|
|
100
114
|
- **Unified `expr` template tag**:
|
|
101
|
-
- Linear expression (`LinExpr`): `` expr`30 * ${x} + 50 * ${n} - 10` ``
|
|
102
|
-
-
|
|
103
|
-
-
|
|
104
|
-
-
|
|
105
|
-
|
|
106
|
-
- `
|
|
115
|
+
- Linear expression (`LinExpr`): `` expr`30 * ${x} + 50 * ${n} - 10` ``, `` expr`dot(${profit}, ${byItem}) - 20 * ${b}` ``, `` expr`sum((${price} - ${cost}) * ${byItem})` ``
|
|
116
|
+
- Piecewise-linear & element primitives (`max`, `min`, `abs`, `at`, usable inside `expr` or standalone): `` expr`max(${vec}) + sum(abs(${vec} - ${target}))` ``, `` expr`max(abs(${pred} - ${actual}))` ``, `` expr`at(${costs}, ${idx})` `` (0-based integer `idx`, automatically enforcing $0 \le \text{idx} < \text{costs.length}$). On HiGHS/GLPK, convex directions (`minimize` or `<=` on `max`/`abs`, `maximize` or `>=` on `min`) lower to pure continuous LP epigraphs with zero binary variables, while non-convex/equality contexts use exact bounded MIP formulations (finite bounds required); Pumpkin lowers natively (`maximum`/`minimum`/`absolute`/`element`) and Z3 uses native `If` (ITE).
|
|
117
|
+
- Quadratic expression (`QuadExpr`): `` expr`${x}^2 + 2 * ${x} * ${y} + ${y}^2` ``, `` expr`sum((${vec} - ${target})^2)` `` (supported for convex QP objectives on purely continuous models using `m.continuous`; built-in HiGHS does not support MIQP models containing integer, binary, or boolean variables).
|
|
118
|
+
- Constraint (`Constraint`): `` expr`${x} + 2 * ${n} <= 40` ``, `` expr`sum(${byItem}) <= 100` `` (supports `<=`, `>=`, `==`, `=`, plus discrete integer-only `<`, `>`, `!=`).
|
|
119
|
+
- **Aggregations & Element-Wise Container Arithmetic**:
|
|
120
|
+
- `sum(containerOrItems, mapper?)` (usable inside `` expr`sum(...)` `` or standalone `sum(...)`) sums a 1D/2D `Array`, `Iterable`, or plain `Record` of `Var` / `LinExpr` / `number` (without needing `Object.values(record)`), or maps over items/counts via `sum(items, (item, i) => ...)`. Inside `` expr`sum(...)` ``, element-wise container arithmetic (`+`, `-`, `*`, `/`, `^2`) and `abs(...)` mapping are also supported.
|
|
121
|
+
- `dot(a, b)` (usable inside `` expr`dot(${a}, ${b})` `` or standalone `dot(a, b)`) computes the inner product of matching 1D arrays, 2D arrays (`number[][]` / `Var[][]`, computing the Frobenius inner product $\sum_{i,j} A_{i,j} B_{i,j}$), plain records (`Record<string, ...>`), or mixed Array/Record containers in either operand order.
|
|
107
122
|
- **Fluent methods**:
|
|
108
123
|
- Arithmetic (on `LinExpr` and `QuadExpr`; `Var` supports `.add()`, `.sub()`, `.mul()`, `.neg()`): `.add(other)`, `.sub(other)`, `.mul(other)`, `.div(scalar)`, `.neg()`
|
|
109
|
-
- Comparisons (on `Var` and `
|
|
110
|
-
-
|
|
124
|
+
- Comparisons (on `Var`, `LinExpr`, and `QuadExpr`): `.le(rhs, name?)`, `.ge(rhs, name?)`, `.eq(rhs, name?)`, plus discrete integer-only `.lt(rhs, name?)`, `.gt(rhs, name?)`, `.ne(rhs, name?)` (Continuous / fractional operands throw immediately)
|
|
125
|
+
- CP global constraints (`BoolExpr` predicates composable with logical operators): `distinct(...args)` (pairwise `!=` on HiGHS/GLPK, `all_different` via pairwise `binary_not_equals` on Pumpkin `0.5.0`, `ctx.Distinct` on Z3), `disjoint(tasks)` (`{ start, duration }`, native `disjunctive_strict` Vilím edge-finding on Pumpkin), `cumulative(tasks, capacity)` (`{ start, duration, demand }`, native `cumulative` time-table on Pumpkin; MIP time-indexed formulation enforces a horizon memory guard recommending `{ solver: "pumpkin" }`), and `allowed(vars, tuples)` (`table` / `negative_table` on Pumpkin)
|
|
126
|
+
- Boolean logic (on `BoolVar`, `BoolExpr`, and `Constraint`): standalone `and(...)`, `or(...)`, `not(...)`, `implies(a, b)`, `xor(a, b)` and fluent `.and(...)`, `.or(...)`, `.not()`, `.implies(...)`, `.xor(...)`—solved natively on Z3 and Pumpkin (bounded integers) and automatically linearized to 0-1 MIP on HiGHS/GLPK (negated comparison `Constraint`s in `implies` antecedents, `not`, or `xor` use exact $\pm 1$ shifts over integer-valued `Integer`/`Binary` expressions; `Continuous` or non-integer negated `Constraint`s throw on MIP solvers—use `{ solver: "z3" }`, or write ``or(expr`... >= ... + eps`, ...)`` / `m.bool()`)
|
|
111
127
|
|
|
112
128
|
### Step 3: Register Objective & Constraints on the Model
|
|
113
129
|
|
|
114
|
-
Constructing an `expr` or `.le()` object does **not** attach it to the model until you pass it to `m.constraint(...)` or `m.objective(...)
|
|
130
|
+
Constructing an `expr` or `.le()` object does **not** attach it to the model until you pass it to `m.constraint(...)` or `m.objective(...)` (when `options.M` is omitted in `m.indicator()`, HiGHS/GLPK use tight derived Big-M and preserve `toLpString()`, while Pumpkin lowers natively via `implied_by` and Z3 via `ctx.Implies` unless the returned `Constraint` row is subsequently mutated):
|
|
115
131
|
|
|
116
132
|
```ts
|
|
117
133
|
// Set objective using maximize() or minimize()
|
|
118
134
|
m.objective(maximize(expr`30 * ${x} + 50 * ${n}`));
|
|
119
135
|
|
|
120
|
-
// Register constraints on the model
|
|
121
|
-
m.constraint(expr`${x} + 2 * ${n} <= 40`, "resource_limit");
|
|
136
|
+
// Register constraints on the model (returns the registered Constraint / BoolExpr or array)
|
|
137
|
+
const limit = m.constraint(expr`${x} + 2 * ${n} <= 40`, "resource_limit");
|
|
122
138
|
|
|
123
139
|
// Indicator constraint (MIP Big-M reformulation: b === 1 => x <= 50)
|
|
124
140
|
m.indicator(b, expr`${x} <= 50`, { activeValue: 1, name: "cap_when_b" });
|
|
125
141
|
```
|
|
126
142
|
|
|
127
|
-
### Step 4: Execute (`solve` or `check`) & Verify (`
|
|
143
|
+
### Step 4: Execute (`solve` or `check`) & Verify (`verify`)
|
|
128
144
|
|
|
129
145
|
- **Optimization (`await m.solve(options?)`)**:
|
|
130
146
|
- Returns `SolverStatus` (`"Optimal"`, `"Feasible"`, `"Infeasible"`, `"Unbounded"`, `"TimeLimit"`, `"IterationLimit"`, `"Error"`, `"Unknown"`, `"NotSolved"`, `"Sat"`, or `"Unsat"`). Built-in optimization solvers return the optimization statuses (`"Optimal"`, `"Feasible"`, `"Infeasible"`, `"Unbounded"`, `"TimeLimit"`, `"IterationLimit"`, `"Error"`, `"Unknown"`, `"NotSolved"`), where a time-, iteration-, or solution-limited run (or an interrupted solve) that found a valid primal incumbent returns `"Feasible"`; `"Sat"` and `"Unsat"` are included in `SolverStatus` for satisfiability/custom solver adapters (such as `MockSolver`).
|
|
131
|
-
- Read values via `x.value`, `expr`...`.value`, `m.
|
|
132
|
-
- Call `m.
|
|
147
|
+
- Read values via `x.value`, `expr`...`.value`, `m.values`, `m.objectiveValue`, `constr.dual`, `constr.slack`, and `x.reducedCost`, and inspect registered entities via `m.variables` (`ReadonlyMap<string, Var | BoolVar>`) and `m.constraints` (`ReadonlyMap<string, Constraint | LogicalConstraint>`).
|
|
148
|
+
- Call `m.verify()` after solving to independently verify variable finiteness, variable bounds (`lb`/`ub`), integer/binary/boolean domains, linear constraint residuals, and logical constraints (`VerificationReport`: `{ valid, complete, maxViolation, violations, ... }`). Note that `verify()` checks primal feasibility of variables and constraints; it does not recompute or compare `m.objectiveValue`.
|
|
133
149
|
- **Satisfiability & Conflict Diagnosis (`await m.check(options?)`)**:
|
|
134
150
|
- Returns `CheckResult` (`{ status: "Sat" | "Unsat" | "Unknown", values: Record<string, number | boolean>, conflicts?: readonly string[], unsatCore?: readonly string[], runTime?: number }`), where `conflicts` is populated when the model is proven `"Unsat"`.
|
|
135
|
-
- For models containing linear arithmetic constraints or logical constraints (`BoolVar`, `and`, `or`, `implies`, `xor`), `m.check()` works with any solver (including the default HiGHS and GLPK via single-solve elastic slack relaxation, automatically linearizing logical constraints into 0-1 MIP formulation) and diagnoses conflicting constraints as `conflicts` (leaving `unsatCore: undefined` for semantic rigor).
|
|
136
|
-
- Exact
|
|
151
|
+
- For models containing linear arithmetic constraints or logical constraints (`BoolVar`, `and`, `or`, `not`, `implies`, `xor`), `m.check()` works with any solver (including the default HiGHS and GLPK via single-solve elastic slack relaxation, automatically linearizing logical constraints into 0-1 MIP formulation) and diagnoses conflicting constraints as `conflicts` (leaving `unsatCore: undefined` for semantic rigor).
|
|
152
|
+
- Exact unsatisfiable-core extraction (`result.unsatCore` and `result.conflicts`) is provided when using `{ solver: "z3" }` or `{ solver: "pumpkin" }`. Use `"pumpkin"` (`@ohtaman/washi/solvers/pumpkin`) for bounded-integer/propositional models in environments without `COOP`/`COEP` headers, and use `"z3"` when `Continuous` variables or fractional arithmetic are involved. Because Z3 and Pumpkin assert variable bounds (`lb`/`ub`) and binary `{0, 1}` domains directly while tracking registered constraints, `unsatCore` reports a subset of registered constraint names that conflicts *together with the model's fixed variable bounds/domains* (and is not guaranteed minimal).
|
|
137
153
|
- **No concurrent mutation during async solve/check**:
|
|
138
154
|
- Mutating variables, constraints, or the objective while `await m.solve()` or `await m.check()` is pending invalidates the in-flight execution and rejects the stale promise.
|
|
139
155
|
|
|
@@ -148,14 +164,17 @@ m.indicator(b, expr`${x} <= 50`, { activeValue: 1, name: "cap_when_b" });
|
|
|
148
164
|
- `` WRONG: m.constraint(expr`${x} + ${y}` as any); -> throws Error ``
|
|
149
165
|
3. DO NOT use quadratic terms inside linear constraints:
|
|
150
166
|
- `` WRONG: expr`${x}^2 <= 10`; -> throws Error ("Quadratic constraints are not supported") ``
|
|
151
|
-
4. DO NOT use retired aliases (removed in #59 / #81):
|
|
167
|
+
4. DO NOT use retired aliases (removed in #59 / #81 / #236 / #273):
|
|
152
168
|
- Use `expr` instead of retired `c` template tag
|
|
153
169
|
- Use `m.constraint(...)` instead of `m.constrain(...)` or `m.add(...)`
|
|
154
|
-
- Use `m.objective(maximize(...))` / `m.objective(minimize(...))` instead of `m.maximize(...)` / `m.minimize(...)` / `m.setObjective(...)`
|
|
170
|
+
- Use `m.objective(maximize(...))` / `m.objective(minimize(...))` / `m.objective()` instead of `m.maximize(...)` / `m.minimize(...)` / `m.setObjective(...)` / `m.objectiveExpr`
|
|
155
171
|
- Use `await m.solve()` instead of `await m.optimize()`
|
|
172
|
+
- Use `m.verify()` instead of `m.validateSolution()` (and rely on automatic integrity validation in `solve()` / `check()` / `toLpString()` instead of `m.validateIntegrity()`)
|
|
173
|
+
- Use `m.column(...)` instead of `m.addColumn(...)`
|
|
156
174
|
- Use `.le()`, `.ge()`, `.eq()` instead of `.lessThanOrEqual()`, `.greaterThanOrEqual()`, `.equalTo()`
|
|
157
|
-
- Use `.value`
|
|
158
|
-
- Use `m.variables` / `m.constraints` instead of `m.vars` / `m.constrs`
|
|
175
|
+
- Use `.value` instead of `m.getValues(...)` or `expr.getValue()`
|
|
176
|
+
- Use `m.variables` / `m.constraints` (`ReadonlyMap` with `.get()` / `.size`) instead of `m.vars` / `m.constrs` / `m.boolVars` / `m.logicalConstraints` / `m.numVars` / `m.numConstrs` / `get*ByName()`
|
|
177
|
+
- Use `relativeGap` / `absoluteGap` instead of `relGap` / `mipGap` / `absGap`
|
|
159
178
|
|
|
160
179
|
---
|
|
161
180
|
|
|
@@ -164,23 +183,26 @@ m.indicator(b, expr`${x} <= 50`, { activeValue: 1, name: "cap_when_b" });
|
|
|
164
183
|
### Getting Started
|
|
165
184
|
|
|
166
185
|
- [AI Coding Agent Quick-Reference Guide](docs/getting-started/ai-agents.md): This document is the **consumer modeling quick-reference** for AI coding agents and developers building optimization or satisfiability models with `@ohtaman/washi`.
|
|
167
|
-
- [Introduction & Installation](docs/getting-started/index.md): WaSHI brings the algebraic modeling style of Python's **PuLP**
|
|
168
|
-
- [Runtime Environments & Deployment](docs/getting-started/runtimes.md): WaSHI runs across JavaScript and TypeScript runtimes—from Node.js, Bun, and Deno to modern bundlers, vanilla browser `<script>` tags
|
|
169
|
-
- [Cross-Origin Isolation (Z3 & Browsers)](docs/getting-started/cross-origin.md): When running the **Z3** solver
|
|
186
|
+
- [Introduction & Installation](docs/getting-started/index.md): **WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) brings the algebraic modeling style of Python's **PuLP** to the TypeScript and JavaScript ecosystem.
|
|
187
|
+
- [Runtime Environments & Deployment](docs/getting-started/runtimes.md): WaSHI runs across JavaScript and TypeScript runtimes—from Node.js, Bun, and Deno to modern bundlers, static hosting, and vanilla browser `<script>` tags—without native C/C++ compilation.
|
|
188
|
+
- [Cross-Origin Isolation (Z3 & Browsers)](docs/getting-started/cross-origin.md): When running the **Z3** solver inside a web browser, Cross-Origin Isolation HTTP headers are required so the browser enables `SharedArrayBuffer`.
|
|
170
189
|
|
|
171
190
|
### Modeling Guide
|
|
172
191
|
|
|
173
|
-
- [Variables & Domains](docs/guide/variables.md): Variables represent the mathematical decision variables in your optimization model.
|
|
192
|
+
- [Variables & Domains](docs/guide/variables.md): Variables represent the mathematical decision variables in your optimization or logical model.
|
|
174
193
|
- [Expressions (`expr`, `sum`, `dot`)](docs/guide/expressions.md): Mathematical expressions are linear or quadratic combinations of decision variables and numeric coefficients.
|
|
175
194
|
- [Constraints (`m.constraint` & `m.indicator`)](docs/guide/constraints.md): Constraints restrict the feasible solution space of your mathematical or logical model.
|
|
176
195
|
- [Objectives & Solving (`m.solve` & `m.check`)](docs/guide/objectives.md): The objective function defines the goal of mathematical optimization—whether to maximize profits, minimize costs, or minimize quadratic risk variance.
|
|
177
|
-
- [Conflict Diagnosis (`unsatCore`) &
|
|
178
|
-
- [
|
|
196
|
+
- [Conflict Diagnosis (`unsatCore`), Validation & Debugging](docs/guide/unsat-core.md): When building real-world optimization and rule systems, you need to diagnose infeasible models, verify returned solutions, and inspect or unit-test formulations cleanly.
|
|
197
|
+
- [Constraint Programming (CP) Modeling](docs/guide/constraint-programming.md): WaSHI allows you to formulate both **Mathematical Optimization (LP / MIP / Convex QP)** and **Constraint Programming (CP)** problems through the same TypeScript algebraic modeling API (`Model`, `expr`, `sum`, `dot`).
|
|
198
|
+
- [Decomposition Methods (`solveColumnGeneration` & `solveBenders`)](docs/guide/decomposition.md): When monolithic Mixed-Integer Programming (MIP) models have exponentially many candidate patterns or large multi-stage subproblems, WaSHI provides two high-level decomposition orchestrators—`master.solveColumnGeneration()` and `master.solveBenders()`—along with low-level primitives for dual inspection and dynamic model updates.
|
|
199
|
+
- [Formulation Patterns & Optimization Tips](docs/guide/formulation-tips.md): While the preceding Modeling Guide pages cover WaSHI's APIs (`Model`, `expr`, `m.constraint`, `m.solve`, etc.), this page collects standard mathematical optimization formulation patterns and solver tuning techniques frequently used in linear and mixed-integer programming (LP/MIP).
|
|
179
200
|
|
|
180
201
|
### Solvers
|
|
181
202
|
|
|
182
203
|
- [Solvers Overview](docs/solvers/index.md): WaSHI is designed around a pluggable, decoupled solver architecture.
|
|
183
|
-
- [HiGHS Solver Engine](docs/solvers/highs.md): **HiGHS** is high-performance mathematical optimization software
|
|
204
|
+
- [HiGHS Solver Engine](docs/solvers/highs.md): **HiGHS** is high-performance mathematical optimization software initiated at the University of Edinburgh (highs.dev · ERGO-Code/HiGHS).
|
|
205
|
+
- [Pumpkin Constraint Programming Solver](docs/solvers/pumpkin.md): **Pumpkin** is a Lazy Clause Generation (LCG) constraint programming solver developed in pure Rust by ConSol Lab at TU Delft (ConSol-Lab/Pumpkin · docs.rs/pumpkin-core).
|
|
184
206
|
- [Z3 SMT Solver Engine](docs/solvers/z3.md): **Z3** is a theorem prover and Satisfiability Modulo Theories (SMT) solver developed by Microsoft Research.
|
|
185
207
|
- [GLPK Solver Engine](docs/solvers/glpk.md): The **GNU Linear Programming Kit (GLPK)** is a long-standing, robust simplex and interior-point solver package intended for solving large-scale linear programming (LP) and mixed integer programming (MIP).
|
|
186
208
|
- [WaSHI Custom Solver Developer Guide](docs/solvers/custom-solver.md): This guide describes how to build, test, and distribute custom solver plugins for **WaSHI** (`@ohtaman/washi`).
|
|
@@ -195,7 +217,8 @@ m.indicator(b, expr`${x} <= 50`, { activeValue: 1, name: "cap_when_b" });
|
|
|
195
217
|
- [Staff Shift Scheduling & Conflict Diagnosis (MIP + Z3)](docs/examples/shift-scheduling.md): Staff shift scheduling is a classic real-world application of Mixed-Integer Programming in SaaS and workforce management tools.
|
|
196
218
|
- [E-Commerce Cart & Coupon Optimizer (Indicator MIP)](docs/examples/ecommerce-coupons.md): Modern e-commerce checkouts often feature complex promotional rules: minimum spend thresholds, category-specific discounts, stackable vs. mutually exclusive coupons, and maximum coupon limits per order.
|
|
197
219
|
- [Portfolio Optimization (QP)](docs/examples/portfolio-qp.md): The Markowitz mean-variance portfolio optimization problem is the foundation of modern quantitative finance: allocate capital across risky assets to minimize overall portfolio variance (risk) subject to achieving a minimum required expected return.
|
|
220
|
+
- [Resource-Constrained Project Scheduling (CP / Pumpkin)](docs/examples/project-scheduling.md): The **Resource-Constrained Project Scheduling Problem (RCPSP)** models project tasks governed simultaneously by **precedence dependencies**, **unary shared equipment** (disjunctive resource), and **limited renewable team headcount** (cumulative resource).
|
|
198
221
|
- [SMT Security Policies](docs/examples/smt-security.md): Satisfiability Modulo Theories (SMT) combines propositional logic (Boolean SAT) with first-order theories (linear integer arithmetic, real inequalities).
|
|
199
|
-
- [Conflict Diagnosis (Unsat Core)](docs/examples/unsat-core.md): When business rules, budgets, and operational policies grow complex, constraints
|
|
222
|
+
- [Conflict Diagnosis (Unsat Core)](docs/examples/unsat-core.md): When business rules, budgets, and operational policies grow complex, constraints can easily conflict.
|
|
200
223
|
- [Capacitated Vehicle Routing Problem (CVRP, 50 Customers via Column Generation)](docs/examples/vehicle-routing.md): The **Capacitated Vehicle Routing Problem (CVRP)** determines the minimum number of delivery vehicles needed to visit a set of customers, subject to vehicle cargo capacity, maximum customer stops per shift, and route duration limits.
|
|
201
224
|
- [Traveling Salesperson Problem (TSP via Benders Decomposition)](docs/examples/traveling-salesperson.md): The **Traveling Salesperson Problem (TSP)** seeks the shortest closed tour that visits every city in a given set once and returns to the starting city.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohtaman/washi",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "WaSHI:
|
|
3
|
+
"version": "0.8.0",
|
|
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",
|
|
7
7
|
"module": "./dist/lib/washi.js",
|
|
@@ -23,6 +23,12 @@
|
|
|
23
23
|
"import": "./dist/lib/solvers/glpk.js",
|
|
24
24
|
"default": "./dist/lib/solvers/glpk.js"
|
|
25
25
|
},
|
|
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",
|
|
26
32
|
"./browser": {
|
|
27
33
|
"types": "./dist/types/index.d.ts",
|
|
28
34
|
"import": "./dist/browser/washi.js",
|
|
@@ -41,6 +47,12 @@
|
|
|
41
47
|
"default": "./dist/browser/solvers/z3.js"
|
|
42
48
|
},
|
|
43
49
|
"./browser/solvers/z3.min.js": "./dist/browser/solvers/z3.min.js",
|
|
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"
|
|
54
|
+
},
|
|
55
|
+
"./browser/solvers/pumpkin.min.js": "./dist/browser/solvers/pumpkin.min.js",
|
|
44
56
|
"./solvers/z3-built.js": "./dist/lib/solvers/z3-built.js",
|
|
45
57
|
"./solvers/z3-built.wasm": "./dist/lib/solvers/z3-built.wasm"
|
|
46
58
|
},
|
|
@@ -49,8 +61,6 @@
|
|
|
49
61
|
"dist/browser",
|
|
50
62
|
"dist/types",
|
|
51
63
|
"docs/getting-started/ai-agents.md",
|
|
52
|
-
"docs/ja/getting-started/ai-agents.md",
|
|
53
|
-
"docs/zh/getting-started/ai-agents.md",
|
|
54
64
|
"docs/getting-started",
|
|
55
65
|
"docs/guide",
|
|
56
66
|
"docs/solvers",
|
|
@@ -68,22 +78,25 @@
|
|
|
68
78
|
"dev": "vite",
|
|
69
79
|
"ensure:highs": "node scripts/ensure-highs-wasm.mjs",
|
|
70
80
|
"build:highs-wasm": "bash scripts/build-highs-wasm.sh",
|
|
81
|
+
"ensure:pumpkin": "node scripts/ensure-pumpkin-wasm.mjs",
|
|
82
|
+
"build:pumpkin-wasm": "bash scripts/build-pumpkin-wasm.sh",
|
|
71
83
|
"build:demo": "vite build",
|
|
72
84
|
"build:types": "node -e \"import('node:fs').then(fs => fs.rmSync('dist/types', { recursive: true, force: true }))\" && tsc -p tsconfig.lib.json",
|
|
73
|
-
"build:lib": "node scripts/ensure-highs-wasm.mjs && node scripts/build-library.mjs",
|
|
85
|
+
"build:lib": "node scripts/ensure-highs-wasm.mjs && node scripts/ensure-pumpkin-wasm.mjs && node scripts/build-library.mjs",
|
|
74
86
|
"build:llms": "node scripts/generate-llms.mjs",
|
|
75
|
-
"build": "node scripts/ensure-highs-wasm.mjs && npm run build:types && npm run build:lib && npm run build:browser && npm run build:demo",
|
|
76
|
-
"build:site": "node scripts/ensure-highs-wasm.mjs && node scripts/build-site.mjs",
|
|
87
|
+
"build": "node scripts/ensure-highs-wasm.mjs && node scripts/ensure-pumpkin-wasm.mjs && npm run build:types && npm run build:lib && npm run build:browser && npm run build:demo",
|
|
88
|
+
"build:site": "node scripts/ensure-highs-wasm.mjs && node scripts/ensure-pumpkin-wasm.mjs && node scripts/build-site.mjs",
|
|
77
89
|
"docs:dev": "vitepress dev docs",
|
|
78
90
|
"docs:build": "vitepress build docs && node scripts/generate-llms.mjs",
|
|
79
91
|
"docs:preview": "vitepress preview docs",
|
|
80
92
|
"preview": "vite preview",
|
|
81
93
|
"test": "vitest run",
|
|
82
94
|
"test:e2e": "RUN_E2E=1 vitest run test/e2e.test.ts",
|
|
83
|
-
"prepublishOnly": "node scripts/ensure-highs-wasm.mjs && npm run build:types && npm run build:lib && npm run build:browser && npm run build:llms",
|
|
84
|
-
"build:browser": "node scripts/ensure-highs-wasm.mjs && node scripts/build-browser.mjs",
|
|
85
|
-
"test:distribution": "node scripts/ensure-highs-wasm.mjs && npm run build:types && npm run build:lib && npm run build:browser && npm run build:llms && node --experimental-vm-modules scripts/check-distribution.mjs",
|
|
86
|
-
"test:demo": "BASE_URL=/
|
|
95
|
+
"prepublishOnly": "node scripts/ensure-highs-wasm.mjs && node scripts/ensure-pumpkin-wasm.mjs && npm run build:types && npm run build:lib && npm run build:browser && npm run build:llms",
|
|
96
|
+
"build:browser": "node scripts/ensure-highs-wasm.mjs && node scripts/ensure-pumpkin-wasm.mjs && node scripts/build-browser.mjs",
|
|
97
|
+
"test:distribution": "node scripts/ensure-highs-wasm.mjs && node scripts/ensure-pumpkin-wasm.mjs && npm run build:types && npm run build:lib && npm run build:browser && npm run build:llms && node --experimental-vm-modules scripts/check-distribution.mjs",
|
|
98
|
+
"test:demo": "BASE_URL=/ npm run build:demo && node scripts/check-demo-browser.mjs",
|
|
99
|
+
"test:site": "npm run build:site && REQUIRE_SITE_DIST=1 vitest run test/site-seo.test.ts",
|
|
87
100
|
"bench": "node scripts/run-benchmarks.mjs"
|
|
88
101
|
},
|
|
89
102
|
"keywords": [
|
|
@@ -93,15 +106,28 @@
|
|
|
93
106
|
"linear-programming",
|
|
94
107
|
"mixed-integer-programming",
|
|
95
108
|
"quadratic-programming",
|
|
109
|
+
"milp",
|
|
110
|
+
"lp",
|
|
111
|
+
"mip",
|
|
112
|
+
"qp",
|
|
113
|
+
"cp",
|
|
114
|
+
"solver",
|
|
115
|
+
"modeler",
|
|
116
|
+
"scheduling",
|
|
117
|
+
"timetabling",
|
|
96
118
|
"smt",
|
|
97
119
|
"z3",
|
|
98
120
|
"highs",
|
|
121
|
+
"glpk",
|
|
122
|
+
"pumpkin",
|
|
123
|
+
"lcg",
|
|
99
124
|
"pulp",
|
|
100
125
|
"jump",
|
|
101
126
|
"operations-research",
|
|
102
127
|
"wasm",
|
|
103
128
|
"webassembly",
|
|
104
|
-
"typescript"
|
|
129
|
+
"typescript",
|
|
130
|
+
"javascript"
|
|
105
131
|
],
|
|
106
132
|
"author": "",
|
|
107
133
|
"license": "MIT",
|
|
@@ -116,7 +142,7 @@
|
|
|
116
142
|
"bugs": {
|
|
117
143
|
"url": "https://github.com/ohtaman/washi/issues"
|
|
118
144
|
},
|
|
119
|
-
"homepage": "https://
|
|
145
|
+
"homepage": "https://washi.ohtaman.dev/",
|
|
120
146
|
"dependencies": {},
|
|
121
147
|
"peerDependencies": {
|
|
122
148
|
"glpk.js": "^5.0.0",
|
|
@@ -131,6 +157,7 @@
|
|
|
131
157
|
}
|
|
132
158
|
},
|
|
133
159
|
"devDependencies": {
|
|
160
|
+
"@babel/parser": "^7.29.9",
|
|
134
161
|
"@types/node": "^26.6.3",
|
|
135
162
|
"async-mutex": "^0.3.2",
|
|
136
163
|
"glpk.js": "^5.0.0",
|
package/skills/washi/SKILL.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: washi
|
|
3
|
-
description: Formulate, inspect, solve, and verify mathematical optimization (LP, MIP, convex QP) and SMT satisfiability or unsat-core models in TypeScript and JavaScript using @ohtaman/washi (HiGHS, Z3, GLPK).
|
|
3
|
+
description: Formulate, inspect, solve, and verify mathematical optimization (LP, MILP/MIP, convex QP, CP/LCG) and SMT satisfiability or unsat-core models in TypeScript and JavaScript using @ohtaman/washi (HiGHS, Pumpkin, Z3, GLPK) for shift scheduling, timetabling, resource allocation, bin packing, routing, portfolio optimization, and rule conflict diagnosis.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# WaSHI Modeling & Verification Skill
|
|
7
7
|
|
|
8
|
-
Use this skill when building, debugging, or verifying mathematical optimization (LP, MIP, convex QP) or satisfiability (SMT / SAT) models with `@ohtaman/washi`. For the full API reference and browser/bundler deployment rules, see [`docs/getting-started/ai-agents.md`](https://github.com/ohtaman/washi/blob/main/docs/getting-started/ai-agents.md) (available locally at `node_modules/@ohtaman/washi/docs/getting-started/ai-agents.md` in consumer projects or `docs/getting-started/ai-agents.md` in the repository).
|
|
8
|
+
Use this skill when building, debugging, or verifying mathematical optimization (LP, MIP, convex QP, CP/LCG) or satisfiability (SMT / SAT) models with `@ohtaman/washi`. For the full API reference and browser/bundler deployment rules, see [`docs/getting-started/ai-agents.md`](https://github.com/ohtaman/washi/blob/main/docs/getting-started/ai-agents.md) (available locally at `node_modules/@ohtaman/washi/docs/getting-started/ai-agents.md` in consumer projects or `docs/getting-started/ai-agents.md` in the repository).
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
|
@@ -16,12 +16,13 @@ Select the solver engine and execution method that match the problem class:
|
|
|
16
16
|
| Problem Class | Recommended Solver | Setup & Import | Execution Method |
|
|
17
17
|
| :--- | :--- | :--- | :--- |
|
|
18
18
|
| **LP / MIP / Convex QP** (including `m.indicator()` Big-M and `initialValue` warm starts) | **HiGHS** (default) | Built-in (`import { Model } from "@ohtaman/washi"`) | `await m.solve()` |
|
|
19
|
-
| **
|
|
20
|
-
| **
|
|
19
|
+
| **CP/LCG Bounded Integer, Scheduling & Global Constraints** (`distinct`, `disjoint`, `cumulative`, `allowed`, `at`, `max`/`min`/`abs`, `!=`, `unsatCore` without `COOP`/`COEP`) | **Pumpkin** plugin (bundled WASM) | `import "@ohtaman/washi/solvers/pumpkin"` | `await m.solve({ solver: "pumpkin" })` or `await m.check({ solver: "pumpkin" })` |
|
|
20
|
+
| **SMT Propositional Logic** (`BoolVar`, `and`, `or`, `not`, `implies`, `xor`) | **HiGHS** (auto 0-1 MIP), **Pumpkin** (bounded int), or **Z3** (native SMT incl. `Continuous`) | Built-in for HiGHS; `import "@ohtaman/washi/solvers/pumpkin"`; `npm install z3-solver` + `import "@ohtaman/washi/solvers/z3"` for Z3 | `await m.solve()` or `await m.check()` |
|
|
21
|
+
| **Infeasibility / Conflict Diagnosis** (`conflicts` / `unsatCore`) | **HiGHS** (elastic slack `conflicts`), **Pumpkin** (zero-`COOP`/`COEP` `unsatCore`), or **Z3** (`unsatCore`) | Built-in for HiGHS; `import "@ohtaman/washi/solvers/pumpkin"`; `import "@ohtaman/washi/solvers/z3"` | `await m.check()` |
|
|
21
22
|
| **LP / MIP with GLPK** (GPL-3.0; no QP or `initialValue`) | **GLPK** plugin | `npm install glpk.js` + `import "@ohtaman/washi/solvers/glpk"` | `await m.solve({ solver: "glpk" })` |
|
|
22
23
|
|
|
23
24
|
- **Browser runtime notes**:
|
|
24
|
-
- HiGHS and GLPK load local `.wasm` and Worker assets relative to the bundle (never falling back to an external CDN)
|
|
25
|
+
- HiGHS, Pumpkin, and GLPK load local `.wasm` and Worker assets relative to the bundle (never falling back to an external CDN) and work without `COOP`/`COEP`.
|
|
25
26
|
- Z3 uses `SharedArrayBuffer` pthreads and requires `window.isSecureContext === true` and `window.crossOriginIsolated === true` (`Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: require-corp`).
|
|
26
27
|
|
|
27
28
|
---
|
|
@@ -33,25 +34,25 @@ Select the solver engine and execution method that match the problem class:
|
|
|
33
34
|
- Propositional boolean (`BoolVar`): `m.bool(nameOrDims)`
|
|
34
35
|
- Indexed containers: pass a count (`number` -> `Var[]` / `Var[][]`) or key array (`readonly string[]` -> `Record<K, Var>` / `Record<R, Record<C, Var>>`).
|
|
35
36
|
- Provide finite `lb` and `ub` bounds whenever known—especially on variables used in `m.indicator()` so WaSHI can automatically derive a tight Big-M when `M` is omitted.
|
|
36
|
-
2. **Build expressions (`expr`, `sum`, `dot`)**:
|
|
37
|
-
- Linear expression (`LinExpr`): `` expr`30 * ${x} + 50 * ${y} - 10` ``
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
-
|
|
41
|
-
-
|
|
37
|
+
2. **Build expressions (`expr`, `sum`, `dot`, `max`, `min`, `abs`, `at`)**:
|
|
38
|
+
- Linear expression (`LinExpr`): `` expr`30 * ${x} + 50 * ${y} - 10` ``, `` expr`dot(${profit}, ${qty}) - 20 * ${lineOpen}` ``
|
|
39
|
+
- Piecewise-linear & 0-based element lookup: `abs(...)`, `max(...)`, `min(...)`, `at(array, index)` usable inside `expr` (including element-wise containers like `` expr`sum(abs(${w} - ${target}))` `` and `` expr`max(abs(${pred} - ${actual}))` ``) or standalone. Convex directions (`minimize`/`<=` on `max`/`abs`, `maximize`/`>=` on `min`) lower to pure LP epigraphs with zero binaries on HiGHS/GLPK; non-convex/equality contexts require finite bounds in MIP and map natively to Pumpkin (`maximum`/`minimum`/`absolute`/`element`) and Z3 (`If`).
|
|
40
|
+
- Quadratic expression (`QuadExpr`, **objectives only**): `` expr`${x}^2 + 2 * ${x} * ${y} + ${y}^2` ``, `` expr`sum((${xVec} - ${target})^2)` `` (purely continuous models on HiGHS; MIQP with integer/binary/boolean variables is not supported)
|
|
41
|
+
- Constraint (`Constraint`): `` expr`${x} + 2 * ${y} <= 40` ``, `` expr`sum(${qty}) <= 100` `` (supports `<=`, `>=`, `==`, `=`, plus discrete integer-only `<`, `>`, `!=` and `.lt()`, `.gt()`, `.ne()`).
|
|
42
|
+
- Vector & Record aggregations: `sum(containerOrItems, mapper?)` and `dot(a, b)` (both usable inside `expr` or standalone; `sum` accepts 1D/2D `Array`, `Iterable`, and `Record` directly without `Object.values()`, plus element-wise container arithmetic `+`, `-`, `*`, `/`, `^2` inside `expr`; `dot` computes the 1D inner product or 2D Frobenius inner product)
|
|
43
|
+
- CP global constraints & propositional logic: `distinct(...)`, `disjoint(tasks)`, `cumulative(tasks, capacity)`, `allowed(vars, tuples)` return composable `BoolExpr`s alongside `and(...)`, `or(...)`, `not(...)`, `implies(a, b)`, `xor(a, b)` (solved natively on Z3 and Pumpkin, and auto-linearized into MIP on HiGHS/GLPK; `cumulative` enforces a MIP horizon memory guard above 5,000 span / 25,000 pulse vars recommending `{ solver: "pumpkin" }`).
|
|
42
44
|
3. **Register objective and named constraints**:
|
|
43
|
-
- Constructing an `expr` or `.le()` / `.ge()` / `.eq()` object does **not** attach it to the model.
|
|
45
|
+
- Constructing an `expr` or `.le()` / `.ge()` / `.eq()` / `.lt()` / `.gt()` / `.ne()` object does **not** attach it to the model.
|
|
44
46
|
- Register the objective with `m.objective(maximize(e))` or `m.objective(minimize(e))`.
|
|
45
|
-
- Register every constraint with a descriptive name: `m.constraint(c, "resource_limit")` or `m.indicator(binVar, c, { activeValue: 1, name: "cap_when_open" })
|
|
47
|
+
- Register every constraint with a descriptive name: `const limit = m.constraint(c, "resource_limit")` (returns the registered `Constraint` / `BoolExpr`, or array for batch inputs) or `m.indicator(binVar, c, { activeValue: 1, name: "cap_when_open" })` (which uses tight Big-M on HiGHS/GLPK and `toLpString()`, while lowering natively via `implied_by` on Pumpkin and `ctx.Implies` on Z3 when `options.M` is omitted). Descriptive names are essential for LP inspection and conflict diagnosis (`conflicts` / `unsatCore`).
|
|
46
48
|
|
|
47
49
|
---
|
|
48
50
|
|
|
49
|
-
## 3. Model Inspection (`
|
|
51
|
+
## 3. Model Inspection (`toLpString`)
|
|
50
52
|
|
|
51
53
|
Before solving or when debugging formulation bugs:
|
|
52
54
|
|
|
53
|
-
- **`m.
|
|
54
|
-
- **`m.toLpString()`**: Calls `validateIntegrity()` and exports the numeric LP / MIP / QP formulation in standard CPLEX LP format (`Maximize` / `Minimize`, `Subject To`, `Bounds`, `General`, `Binary`, `End`). Inspect this string to confirm objective sense, signs, coefficients, and right-hand sides match the mathematical specification.
|
|
55
|
+
- **`m.toLpString()`**: Automatically validates model integrity (variable ownership across `Model` instances, bound sanity `lb <= ub`, finite `initialValue` within bounds/integrality tolerance `1e-6`, and finite objective/constraint coefficients) and exports the numeric LP / MIP / QP formulation in standard CPLEX LP format (`Maximize` / `Minimize`, `Subject To`, `Bounds`, `General`, `Binary`, `End`). Inspect this string to confirm objective sense, signs, coefficients, and right-hand sides match the mathematical specification.
|
|
55
56
|
|
|
56
57
|
---
|
|
57
58
|
|
|
@@ -61,19 +62,19 @@ Never report a model solution as final without executing the verification step:
|
|
|
61
62
|
|
|
62
63
|
1. **After `const status = await m.solve(options?)`**:
|
|
63
64
|
- Verify `status === "Optimal"` (or `status === "Feasible"` / `m.hasPrimalSolution === true` when solver limits apply).
|
|
64
|
-
- Call `const report = m.
|
|
65
|
+
- Call `const report = m.verify()` and assert `report.valid === true`.
|
|
65
66
|
- If `report.valid === false`, inspect `report.violations`, `report.missingVariables`, `report.uncheckedConstraints`, and `report.maxViolation`.
|
|
66
|
-
- Note: `m.
|
|
67
|
+
- Note: `m.verify()` independently checks variable finiteness, variable bounds (`lb`/`ub`), integrality (`Integer`, `Binary`, `BoolVar`), linear constraint residuals, and logical constraints. It does **not** recompute `m.objectiveValue` or verify natural-language problem coverage.
|
|
67
68
|
2. **When a model is infeasible (`"Infeasible"` or `"Unsat"`)**:
|
|
68
|
-
- Run `const res = await m.check()` (diagnoses with built-in HiGHS via single-solve elastic slack relaxation) or `const res = await m.check({ solver: "z3" })` (for exact SMT
|
|
69
|
-
- When `res.status === "Unsat"`, inspect `res.conflicts` (also stored on `m.conflicts`). On HiGHS, `conflicts` reports the subset of constraints requiring relaxation to restore feasibility (with `unsatCore: undefined` for semantic rigor). On Z3, both `unsatCore` and `conflicts` report the contradictory constraint subset.
|
|
70
|
-
- Because Z3
|
|
69
|
+
- Run `const res = await m.check()` (diagnoses with built-in HiGHS via single-solve elastic slack relaxation), `const res = await m.check({ solver: "pumpkin" })` (for `unsatCore` on bounded integer/boolean models without `COOP`/`COEP` requirements), or `const res = await m.check({ solver: "z3" })` (for exact SMT `unsatCore` including `Continuous`/fractional constraints).
|
|
70
|
+
- When `res.status === "Unsat"`, inspect `res.conflicts` (also stored on `m.conflicts`). On HiGHS, `conflicts` reports the subset of constraints requiring relaxation to restore feasibility (with `unsatCore: undefined` for semantic rigor). On Z3 and Pumpkin, both `unsatCore` and `conflicts` report the contradictory constraint subset.
|
|
71
|
+
- Because Z3 and Pumpkin assert variable bounds (`lb`/`ub`) and binary `{0, 1}` domains directly while tracking named constraints, `res.conflicts` returns a subset of registered constraint names that conflicts *together with the model's fixed variable bounds/domains* (not guaranteed minimal).
|
|
71
72
|
|
|
72
73
|
---
|
|
73
74
|
|
|
74
75
|
## 5. Executable Workflow Recipes
|
|
75
76
|
|
|
76
|
-
### Recipe 1: MIP Formulation, `toLpString()` Inspection & `
|
|
77
|
+
### Recipe 1: MIP Formulation, `toLpString()` Inspection & `verify()` Verification
|
|
77
78
|
|
|
78
79
|
```ts
|
|
79
80
|
import { Model, expr, dot, sum, maximize } from "@ohtaman/washi";
|
|
@@ -88,29 +89,28 @@ export async function solveAndVerifyMip() {
|
|
|
88
89
|
const qty = m.integer(products, { lb: 0, ub: 100 });
|
|
89
90
|
const lineOpen = m.binary("lineOpen");
|
|
90
91
|
|
|
91
|
-
m.objective(maximize(expr
|
|
92
|
-
m.constraint(expr
|
|
93
|
-
m.constraint(expr
|
|
94
|
-
m.indicator(lineOpen, expr
|
|
92
|
+
m.objective(maximize(expr`dot(${profit}, ${qty}) - 20 * ${lineOpen}`));
|
|
93
|
+
m.constraint(expr`dot(${woodPerUnit}, ${qty}) <= 40`, "wood_limit");
|
|
94
|
+
m.constraint(expr`dot(${laborPerUnit}, ${qty}) <= 50`, "labor_limit");
|
|
95
|
+
m.indicator(lineOpen, expr`sum(${qty}) <= 0`, {
|
|
95
96
|
activeValue: 0,
|
|
96
97
|
name: "closed_line_zero_output",
|
|
97
98
|
});
|
|
98
99
|
|
|
99
|
-
// 1. Pre-solve integrity & LP formulation inspection
|
|
100
|
-
m.validateIntegrity();
|
|
100
|
+
// 1. Pre-solve integrity validation & LP formulation inspection
|
|
101
101
|
const lpText = m.toLpString();
|
|
102
102
|
|
|
103
103
|
// 2. Solve with default HiGHS solver
|
|
104
104
|
const status = await m.solve();
|
|
105
105
|
|
|
106
106
|
// 3. Mandatory independent solution verification
|
|
107
|
-
const report = m.
|
|
107
|
+
const report = m.verify();
|
|
108
108
|
|
|
109
109
|
return {
|
|
110
110
|
status,
|
|
111
111
|
lpText,
|
|
112
112
|
objectiveValue: m.objectiveValue,
|
|
113
|
-
quantities:
|
|
113
|
+
quantities: { desk: qty.desk.value, chair: qty.chair.value },
|
|
114
114
|
lineOpen: lineOpen.value,
|
|
115
115
|
valid: report.valid,
|
|
116
116
|
maxViolation: report.maxViolation,
|
|
@@ -133,7 +133,7 @@ export async function solveAndVerifyQp() {
|
|
|
133
133
|
|
|
134
134
|
const lpText = m.toLpString();
|
|
135
135
|
const status = await m.solve();
|
|
136
|
-
const report = m.
|
|
136
|
+
const report = m.verify();
|
|
137
137
|
|
|
138
138
|
return {
|
|
139
139
|
status,
|
|
@@ -174,7 +174,7 @@ export async function diagnoseAndVerifyWithZ3() {
|
|
|
174
174
|
satModel.constraint(expr`${discountSat} <= 25`, "campaign_cap");
|
|
175
175
|
|
|
176
176
|
const satRes = await satModel.check();
|
|
177
|
-
const report = satModel.
|
|
177
|
+
const report = satModel.verify();
|
|
178
178
|
|
|
179
179
|
return {
|
|
180
180
|
unsatStatus: unsatRes.status,
|
|
@@ -187,11 +187,67 @@ export async function diagnoseAndVerifyWithZ3() {
|
|
|
187
187
|
}
|
|
188
188
|
```
|
|
189
189
|
|
|
190
|
+
### Recipe 4: Pumpkin CP Scheduling (`disjoint`, `distinct`) & Zero-COOP/COEP `unsatCore` Verification
|
|
191
|
+
|
|
192
|
+
```ts
|
|
193
|
+
import { Model, expr, disjoint, distinct, implies, minimize } from "@ohtaman/washi";
|
|
194
|
+
import "@ohtaman/washi/solvers/pumpkin";
|
|
195
|
+
|
|
196
|
+
export async function solveAndDiagnoseWithPumpkin() {
|
|
197
|
+
// Part A: Bounded-integer CP scheduling with native global propagators
|
|
198
|
+
const cpModel = new Model("WorkshopSchedule", { solver: "pumpkin" });
|
|
199
|
+
const start = cpModel.integer(["cut", "weld", "paint"] as const, { lb: 0, ub: 20, prefix: "start" });
|
|
200
|
+
const bench = cpModel.integer(["cut", "weld", "paint"] as const, { lb: 1, ub: 3, prefix: "bench" });
|
|
201
|
+
|
|
202
|
+
cpModel.constraint(
|
|
203
|
+
disjoint([
|
|
204
|
+
{ start: start.cut, duration: 4 },
|
|
205
|
+
{ start: start.weld, duration: 3 },
|
|
206
|
+
{ start: start.paint, duration: 2 },
|
|
207
|
+
]),
|
|
208
|
+
"single_line"
|
|
209
|
+
);
|
|
210
|
+
cpModel.constraint(expr`${start.cut} + 4 <= ${start.weld}`, "cut_before_weld");
|
|
211
|
+
cpModel.constraint(expr`${start.weld} + 3 <= ${start.paint}`, "weld_before_paint");
|
|
212
|
+
cpModel.constraint(distinct(bench), "unique_benches");
|
|
213
|
+
cpModel.objective(minimize(expr`${start.paint} + 2`));
|
|
214
|
+
|
|
215
|
+
const status = await cpModel.solve();
|
|
216
|
+
const report = cpModel.verify();
|
|
217
|
+
|
|
218
|
+
// Part B: Zero-COOP/COEP unsatCore diagnosis on bounded integers & booleans
|
|
219
|
+
const unsatModel = new Model("PolicyConflict", { solver: "pumpkin" });
|
|
220
|
+
const vip = unsatModel.bool("vip");
|
|
221
|
+
const discount = unsatModel.integer("discount", { lb: 0, ub: 50 });
|
|
222
|
+
|
|
223
|
+
unsatModel.constraint(vip, "customer_is_vip");
|
|
224
|
+
unsatModel.constraint(implies(vip, expr`${discount} >= 20`), "vip_min_discount");
|
|
225
|
+
unsatModel.constraint(expr`${discount} <= 10`, "campaign_cap");
|
|
226
|
+
|
|
227
|
+
const unsatRes = await unsatModel.check();
|
|
228
|
+
|
|
229
|
+
return {
|
|
230
|
+
status,
|
|
231
|
+
makespan: cpModel.objectiveValue,
|
|
232
|
+
starts: { cut: start.cut.value, weld: start.weld.value, paint: start.paint.value },
|
|
233
|
+
benches: { cut: bench.cut.value, weld: bench.weld.value, paint: bench.paint.value },
|
|
234
|
+
valid: report.valid,
|
|
235
|
+
unsatStatus: unsatRes.status,
|
|
236
|
+
conflicts: unsatRes.conflicts,
|
|
237
|
+
unsatCore: unsatRes.unsatCore,
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
190
242
|
---
|
|
191
243
|
|
|
192
244
|
## 6. Guardrails & Common Pitfalls
|
|
193
245
|
|
|
194
|
-
- **No quadratic constraints**: Quadratic terms (`${x}^2`, `${x} * ${y}`) are only valid in `m.objective(...)
|
|
195
|
-
- **Do not confuse `LinExpr` and `Constraint`**: `m.objective(maximize(...))` requires a `LinExpr`, `QuadExpr`, `Var`, or `number` (never a `Constraint`). `m.constraint(...)` requires a `Constraint` (with `<=`, `>=`, `==`, or
|
|
246
|
+
- **No quadratic constraints or MIQP**: Quadratic terms (`${x}^2`, `${x} * ${y}`) are only valid in `m.objective(...)` (using them in `m.constraint(...)` throws `"Quadratic constraints are not supported"`), and built-in HiGHS requires Convex QP models to contain only continuous variables (`m.continuous`).
|
|
247
|
+
- **Do not confuse `LinExpr` and `Constraint`**: `m.objective(maximize(...))` requires a `LinExpr`, `QuadExpr`, `Var`, or `number` (never a `Constraint`). `m.constraint(...)` requires a `Constraint` (with `<=`, `>=`, `==`, `=`, or integer-only `<`, `>`, `!=`) or `BoolExpr` (`distinct`, `disjoint`, `cumulative`, `allowed`, `and`, `or`, `not`, `implies`, `xor`), never a bare `LinExpr`.
|
|
196
248
|
- **Do not mutate during async solve/check**: Modifying variables, bounds, constraints, or the objective while `await m.solve()` or `await m.check()` is pending invalidates the in-flight run and rejects the promise.
|
|
197
|
-
- **Do not use retired aliases**: Always use `expr` (not `c`), `m.constraint(...)` (not `m.constrain` or `m.add`), `m.objective(maximize(...))` (not `m.maximize` or `m.
|
|
249
|
+
- **Do not use retired aliases**: Always use `expr` (not `c`), `m.constraint(...)` (not `m.constrain` or `m.add`), `m.objective(maximize(...))` / `m.objective()` (not `m.maximize`, `m.setObjective`, or `m.objectiveExpr`), `await m.solve()` (not `m.optimize`), `m.verify()` (not `m.validateSolution()`), `m.column(...)` (not `m.addColumn(...)`), `.le()` / `.ge()` / `.eq()` / `.lt()` / `.gt()` / `.ne()` (not `.lessThanOrEqual()`), `.value` (not `m.getValues(...)` or `.getValue()`), `m.variables` / `m.constraints` as `ReadonlyMap` with `.get(...)` / `.size` (not `m.vars`, `m.constrs`, `m.boolVars`, `m.logicalConstraints`, `m.numVars`, `m.numConstrs`, or `get*ByName()`), and `relativeGap` / `absoluteGap` (not `relGap` / `mipGap` / `absGap`). Also never call retired `m.validateIntegrity()` (integrity validation runs automatically inside `solve()`, `check()`, and `toLpString()`).
|
|
250
|
+
- **Practical OR formulation guardrails**:
|
|
251
|
+
- **Prefer inequalities (`>=` / `<=`) over `==`** for demand coverage and capacity limits when costs are non-negative; reserve `==` for flow conservation or normalization identities.
|
|
252
|
+
- **Provide finite `lb` and `ub` bounds** on variables inside `m.indicator(...)` and omit `M` so WaSHI automatically derives the tightest valid Big-M instead of a loose `1e6` fallback.
|
|
253
|
+
- **Use soft constraints (non-negative slack variables)** with tiered objective penalties for non-rigid business targets (preferred staffing, safety stock, day-off requests) so minor data contention produces a prioritized trade-off rather than `"Infeasible"`.
|
|
File without changes
|