@ohtaman/washi 0.7.0 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/README.ja.md +60 -23
  2. package/README.md +59 -22
  3. package/README.zh-CN.md +62 -25
  4. package/THIRD_PARTY_LICENSES.md +34 -1
  5. package/dist/browser/solvers/glpk.js +289 -238
  6. package/dist/browser/solvers/glpk.min.js +1 -1
  7. package/dist/browser/solvers/highs-__vite-browser-external-Dn-83hnF.js +7 -0
  8. package/dist/browser/solvers/highs-browser-runtime-0Bgq5ksG.js +2021 -0
  9. package/dist/browser/{loader-DewlSho8.js → solvers/highs-loader-BLY3wzDH.js} +190 -149
  10. package/dist/browser/solvers/highs-worker.js +54 -0
  11. package/dist/browser/solvers/highs.js +1414 -0
  12. package/dist/browser/solvers/highs.wasm +0 -0
  13. package/dist/browser/solvers/pumpkin-_washi-pumpkin-node-runtime-CEKUDK6d.js +9 -0
  14. package/dist/browser/solvers/pumpkin-loader-CvdaKxf4.js +320 -0
  15. package/dist/browser/solvers/pumpkin-worker.js +45 -0
  16. package/dist/browser/solvers/pumpkin.js +1777 -0
  17. package/dist/browser/solvers/pumpkin.wasm +0 -0
  18. package/dist/browser/solvers/pumpkin.wasm.LICENSE +21 -0
  19. package/dist/browser/solvers/z3.js +1600 -1335
  20. package/dist/browser/solvers/z3.min.js +2 -2
  21. package/dist/browser/washi.js +3313 -1699
  22. package/dist/browser/washi.min.js +5 -3
  23. package/dist/lib/solvers/__vite-browser-external-oLchLuMx.js +7 -0
  24. package/dist/lib/solvers/glpk.js +174 -132
  25. package/dist/lib/solvers/highs-browser-runtime.js +2413 -0
  26. package/dist/lib/{highs-node-runtime.js → solvers/highs-node-runtime.js} +1 -1
  27. package/dist/lib/solvers/highs-runtime.js +16 -0
  28. package/dist/lib/solvers/highs-worker.js +54 -0
  29. package/dist/lib/solvers/highs.js +410 -0
  30. package/dist/lib/solvers/highs.wasm +0 -0
  31. package/dist/lib/{loader-BZUQNvh4.js → solvers/loader-CDpPXN_F.js} +138 -116
  32. package/dist/lib/solvers/loader-Ow74Fa1B.js +311 -0
  33. package/dist/lib/solvers/lp-writer-CLScMFbS.js +115 -0
  34. package/dist/lib/solvers/pumpkin-assets.js +1 -0
  35. package/dist/lib/solvers/pumpkin-node-runtime.js +15 -0
  36. package/dist/lib/solvers/pumpkin-worker-factory.js +1 -0
  37. package/dist/lib/solvers/pumpkin-worker.js +45 -0
  38. package/dist/lib/solvers/pumpkin.js +868 -0
  39. package/dist/lib/solvers/pumpkin.wasm +0 -0
  40. package/dist/lib/solvers/pumpkin.wasm.LICENSE +21 -0
  41. package/dist/lib/solvers/registry-CrYRRk9q.js +907 -0
  42. package/dist/lib/solvers/rolldown-runtime-DtPi1Y-2.js +13 -0
  43. package/dist/lib/solvers/types-BGqPkxwu.js +12 -0
  44. package/dist/lib/solvers/z3.js +489 -307
  45. package/dist/lib/washi.js +3905 -1410
  46. package/dist/types/decomposition/benders.d.ts.map +1 -1
  47. package/dist/types/index.d.ts +4 -5
  48. package/dist/types/index.d.ts.map +1 -1
  49. package/dist/types/modeler/boolean-expr.d.ts +137 -29
  50. package/dist/types/modeler/boolean-expr.d.ts.map +1 -1
  51. package/dist/types/modeler/constraint.d.ts +40 -4
  52. package/dist/types/modeler/constraint.d.ts.map +1 -1
  53. package/dist/types/modeler/expression.d.ts +129 -2
  54. package/dist/types/modeler/expression.d.ts.map +1 -1
  55. package/dist/types/modeler/index.d.ts +4 -6
  56. package/dist/types/modeler/index.d.ts.map +1 -1
  57. package/dist/types/modeler/linearizer.d.ts +11 -2
  58. package/dist/types/modeler/linearizer.d.ts.map +1 -1
  59. package/dist/types/modeler/lp-writer.d.ts.map +1 -1
  60. package/dist/types/modeler/model.d.ts +86 -126
  61. package/dist/types/modeler/model.d.ts.map +1 -1
  62. package/dist/types/modeler/parser.d.ts.map +1 -1
  63. package/dist/types/modeler/quad-expr.d.ts +8 -2
  64. package/dist/types/modeler/quad-expr.d.ts.map +1 -1
  65. package/dist/types/modeler/solution-validator.d.ts +12 -12
  66. package/dist/types/modeler/solution-validator.d.ts.map +1 -1
  67. package/dist/types/modeler/solvers/glpk/loader.d.ts +4 -0
  68. package/dist/types/modeler/solvers/glpk/loader.d.ts.map +1 -1
  69. package/dist/types/modeler/solvers/glpk/solver.d.ts +2 -2
  70. package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
  71. package/dist/types/modeler/solvers/highs/driver.d.ts.map +1 -1
  72. package/dist/types/modeler/solvers/highs/loader.d.ts +8 -6
  73. package/dist/types/modeler/solvers/highs/loader.d.ts.map +1 -1
  74. package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
  75. package/dist/types/modeler/solvers/highs/worker-client.d.ts +16 -0
  76. package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
  77. package/dist/types/modeler/solvers/index.d.ts +2 -1
  78. package/dist/types/modeler/solvers/index.d.ts.map +1 -1
  79. package/dist/types/modeler/solvers/mock.d.ts +2 -3
  80. package/dist/types/modeler/solvers/mock.d.ts.map +1 -1
  81. package/dist/types/modeler/solvers/pumpkin/assets.d.ts +2 -0
  82. package/dist/types/modeler/solvers/pumpkin/assets.d.ts.map +1 -0
  83. package/dist/types/modeler/solvers/pumpkin/index.d.ts +6 -0
  84. package/dist/types/modeler/solvers/pumpkin/index.d.ts.map +1 -0
  85. package/dist/types/modeler/solvers/pumpkin/loader.d.ts +40 -0
  86. package/dist/types/modeler/solvers/pumpkin/loader.d.ts.map +1 -0
  87. package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts +3 -0
  88. package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts.map +1 -0
  89. package/dist/types/modeler/solvers/pumpkin/solver.d.ts +23 -0
  90. package/dist/types/modeler/solvers/pumpkin/solver.d.ts.map +1 -0
  91. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts +74 -0
  92. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts.map +1 -0
  93. package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts +3 -0
  94. package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts.map +1 -0
  95. package/dist/types/modeler/solvers/pumpkin/worker.d.ts +7 -0
  96. package/dist/types/modeler/solvers/pumpkin/worker.d.ts.map +1 -0
  97. package/dist/types/modeler/solvers/pumpkin.d.ts +2 -0
  98. package/dist/types/modeler/solvers/pumpkin.d.ts.map +1 -0
  99. package/dist/types/modeler/solvers/types.d.ts +7 -9
  100. package/dist/types/modeler/solvers/types.d.ts.map +1 -1
  101. package/dist/types/modeler/solvers/z3/loader.d.ts +4 -0
  102. package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
  103. package/dist/types/modeler/solvers/z3/solver.d.ts +2 -15
  104. package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -1
  105. package/dist/types/modeler/types.d.ts +12 -15
  106. package/dist/types/modeler/types.d.ts.map +1 -1
  107. package/dist/types/modeler/validation.d.ts +26 -2
  108. package/dist/types/modeler/validation.d.ts.map +1 -1
  109. package/dist/types/modeler/variable.d.ts +9 -5
  110. package/dist/types/modeler/variable.d.ts.map +1 -1
  111. package/docs/examples/diet-sensitivity.md +33 -14
  112. package/docs/examples/ecommerce-coupons.md +17 -9
  113. package/docs/examples/index.md +36 -27
  114. package/docs/examples/knapsack.md +11 -5
  115. package/docs/examples/portfolio-qp.md +21 -8
  116. package/docs/examples/production.md +10 -5
  117. package/docs/examples/project-scheduling.md +119 -0
  118. package/docs/examples/shift-scheduling.md +29 -18
  119. package/docs/examples/smt-security.md +27 -11
  120. package/docs/examples/transportation.md +23 -13
  121. package/docs/examples/traveling-salesperson.md +34 -22
  122. package/docs/examples/unsat-core.md +27 -14
  123. package/docs/examples/vehicle-routing.md +74 -28
  124. package/docs/getting-started/ai-agents.md +190 -82
  125. package/docs/getting-started/coding-agents.md +177 -0
  126. package/docs/getting-started/cross-origin.md +27 -14
  127. package/docs/getting-started/index.md +49 -43
  128. package/docs/getting-started/runtimes.md +94 -40
  129. package/docs/guide/constraint-programming.md +171 -0
  130. package/docs/guide/constraints.md +115 -33
  131. package/docs/guide/decomposition.md +118 -88
  132. package/docs/guide/expressions.md +106 -43
  133. package/docs/guide/formulation-tips.md +47 -28
  134. package/docs/guide/objectives.md +102 -75
  135. package/docs/guide/unsat-core.md +62 -50
  136. package/docs/guide/variables.md +81 -35
  137. package/docs/solvers/custom-solver.md +163 -122
  138. package/docs/solvers/glpk.md +58 -17
  139. package/docs/solvers/highs.md +124 -57
  140. package/docs/solvers/index.md +33 -20
  141. package/docs/solvers/pumpkin.md +171 -0
  142. package/docs/solvers/z3.md +63 -25
  143. package/llms-full.txt +2232 -932
  144. package/llms.txt +144 -91
  145. package/package.json +55 -19
  146. package/skills/washi/SKILL.md +107 -34
  147. package/dist/browser/_washi-node-only-BvRk9kiK.js +0 -0
  148. package/dist/browser/browser-runtime-TLCY0hkc.js +0 -1793
  149. package/dist/browser/highs-worker.js +0 -39
  150. package/dist/browser/highs.wasm +0 -0
  151. package/dist/lib/_washi-node-only-BvRk9kiK.js +0 -0
  152. package/dist/lib/highs-browser-runtime.js +0 -2185
  153. package/dist/lib/highs-runtime.js +0 -2
  154. package/dist/lib/highs-worker.js +0 -39
  155. package/dist/lib/highs.wasm +0 -0
  156. package/dist/lib/registry-D7TZ3Wh_.js +0 -1034
  157. package/docs/ja/getting-started/ai-agents.md +0 -280
  158. package/docs/zh/getting-started/ai-agents.md +0 -280
  159. /package/dist/browser/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
  160. /package/dist/lib/{highs-assets.js → solvers/highs-assets.js} +0 -0
  161. /package/dist/lib/{highs-worker-factory.js → solvers/highs-worker-factory.js} +0 -0
  162. /package/dist/lib/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
@@ -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) 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
 
@@ -15,14 +15,16 @@ Select the solver engine and execution method that match the problem class:
15
15
 
16
16
  | Problem Class | Recommended Solver | Setup & Import | Execution Method |
17
17
  | :--- | :--- | :--- | :--- |
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
- | **SMT Propositional Logic** (`BoolVar`, `and`, `or`, `not`, `implies`, `xor`) | **HiGHS** (auto 0-1 MIP) or **Z3** (native SMT) | Built-in for HiGHS; `npm install z3-solver` + `import "@ohtaman/washi/solvers/z3"` for Z3 | `await m.solve()` or `await m.check()` |
20
- | **Infeasibility / Conflict Diagnosis** (`conflicts` / `unsatCore`) | **HiGHS** (elastic slack `conflicts`) or **Z3** (`unsatCore`) | Built-in for HiGHS; `import "@ohtaman/washi/solvers/z3"` for Z3 | `await m.check()` |
21
- | **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" })` |
18
+ | **LP / MIP / Convex QP** (`m.indicator()` Big-M, `initialValue` warm starts; only HiGHS supports `QuadExpr` objectives) | **HiGHS** (default) | Bundled (`import { Model } from "@ohtaman/washi"`) | `await m.solve()` |
19
+ | **CP / Lazy Clause Generation (LCG) Bounded Integer, Scheduling & Global Constraints** (`distinct`, `disjoint`, `cumulative`, `allowed`, `at`, `max`/`min`/`abs`, `!=`, `initialValue` warm starts; integer bounds `[-(2^30 - 1), 2^30 - 1]`, throws on `Continuous`/fractional) | **Pumpkin** | Bundled (`import { Model } from "@ohtaman/washi"`, no extra import) | `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`) | Bundled for HiGHS & 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** (relaxation `conflicts`), **Pumpkin** (bounded int/bool `unsatCore`), or **Z3** (`unsatCore`) | Bundled for HiGHS & Pumpkin; `import "@ohtaman/washi/solvers/z3"` for Z3 | `await m.check()` |
22
+ | **LP / MIP with GLPK** (GPL-3.0; no QP, `initialValue`, or `useWorker: true`) | **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
- - 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`).
25
+ - **HiGHS** and **Pumpkin** load bundled `.wasm` and Worker assets relative to the bundle (no external CDN fallback; `useWorker: false` by default on opaque origins such as `file://`).
26
+ - **HiGHS**, **Pumpkin**, and **GLPK** all run without `COOP`/`COEP` headers (**GLPK** is an optional peer dependency that rejects `useWorker: true`).
27
+ - **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
28
 
27
29
  ---
28
30
 
@@ -33,25 +35,30 @@ Select the solver engine and execution method that match the problem class:
33
35
  - Propositional boolean (`BoolVar`): `m.bool(nameOrDims)`
34
36
  - Indexed containers: pass a count (`number` -> `Var[]` / `Var[][]`) or key array (`readonly string[]` -> `Record<K, Var>` / `Record<R, Record<C, Var>>`).
35
37
  - 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`)**:
38
+ 2. **Build expressions (`expr`, `sum`, `dot`, `max`, `min`, `abs`, `at`)**:
37
39
  - Linear expression (`LinExpr`): `` expr`30 * ${x} + 50 * ${y} - 10` ``, `` expr`dot(${profit}, ${qty}) - 20 * ${lineOpen}` ``
38
- - 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)
39
- - Linear constraint (`Constraint`): `` expr`${x} + 2 * ${y} <= 40` ``, `` expr`sum(${qty}) <= 100` `` (supports `<=`, `>=`, `==`, `=`)
40
- - 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)
41
- - Propositional logic: `and(...)`, `or(...)`, `not(...)`, `implies(a, b)`, `xor(a, b)` (or fluent `.and()`, `.or()`, `.not()`, `.implies()`, `.xor()`). Automatically linearized into 0-1 MIP binary variables and linear constraints on HiGHS/GLPK, or solved natively on Z3.
40
+ - Piecewise-linear & element lookup: `abs(...)`, `max(...)`, `min(...)`, and 0-based `at(array, index)` work standalone or inside `expr` (including element-wise containers such as `` expr`sum(abs(${w} - ${target}))` `` and `` expr`max(abs(${pred} - ${actual}))` ``).
41
+ - Piecewise lowering: Convex directions (`minimize`/`<=` on `max`/`abs`, `maximize`/`>=` on `min`) lower to pure LP epigraphs with zero binaries on HiGHS/GLPK. Non-convex or equality contexts require finite bounds in MIP, and map natively to Pumpkin (`maximum`/`minimum`/`absolute`/`element`) and Z3 (`If`).
42
+ - Quadratic expression (`QuadExpr`, **objectives only**): `` expr`${x}^2 + 2 * ${x} * ${y} + ${y}^2` ``, `` expr`sum((${xVec} - ${target})^2)` `` (purely continuous models on HiGHS; `Pumpkin`, `Z3`, and `GLPK` throw, and MIQP with integer/binary/boolean variables is not supported).
43
+ - Constraint (`Constraint`): `` expr`${x} + 2 * ${y} <= 40` ``, `` expr`sum(${qty}) <= 100` `` (supports `<=`, `>=`, `==`, `=`, plus discrete integer-only `<`, `>`, `!=` and `.lt()`, `.gt()`, `.ne()`).
44
+ - Vector & Record aggregations: `sum(containerOrItems, mapper?)` accepts 1D/2D `Array`, `Iterable`, and `Record` directly (no `Object.values()` needed), and `expr` supports element-wise container arithmetic (`+`, `-`, `*`, `/`, `^2`). `dot(a, b)` computes 1D inner products or 2D Frobenius inner products.
45
+ - CP global constraints & logic: `distinct(...)`, `disjoint(tasks)`, `cumulative(tasks, capacity)`, and `allowed(vars, tuples)` return composable `BoolExpr`s alongside `and(...)`, `or(...)`, `not(...)`, `implies(a, b)`, and `xor(a, b)`.
46
+ - Backend lowering: Z3 and Pumpkin solve global/logical constraints natively, while HiGHS/GLPK auto-linearize them into MIP (`cumulative` enforces a MIP horizon memory guard above 5,000 span or 25,000 pulse variables and recommends `{ solver: "pumpkin" }`).
42
47
  3. **Register objective and named constraints**:
43
- - Constructing an `expr` or `.le()` / `.ge()` / `.eq()` object does **not** attach it to the model.
48
+ - Constructing an `expr` or `.le()` / `.ge()` / `.eq()` / `.lt()` / `.gt()` / `.ne()` object does **not** attach it to the model.
44
49
  - Register the objective with `m.objective(maximize(e))` or `m.objective(minimize(e))`.
45
- - 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" })`. Descriptive names are essential for LP inspection and conflict diagnosis (`conflicts` / `unsatCore`).
50
+ - Named constraints: Register every constraint with a descriptive name via `const limit = m.constraint(c, "resource_limit")` (returns the registered `Constraint` / `BoolExpr`, or an array for batch inputs). Names are essential for LP inspection and conflict diagnosis (`conflicts` / `unsatCore`).
51
+ - Indicator constraints: Register conditional constraints via `m.indicator(binVar, c, { activeValue: 1, name: "cap_when_open" })`. When `options.M` is omitted, HiGHS/GLPK and `toLpString()` derive a tight Big-M from finite bounds, while Pumpkin lowers natively via `implied_by` and Z3 via `ctx.Implies`.
46
52
 
47
53
  ---
48
54
 
49
- ## 3. Model Inspection (`validateIntegrity` & `toLpString`)
55
+ ## 3. Model Inspection (`toLpString`)
50
56
 
51
57
  Before solving or when debugging formulation bugs:
52
58
 
53
- - **`m.validateIntegrity()`**: Validates variable ownership (variables and constraints cannot be shared across `Model` instances), bound sanity (`lb <= ub`, finite `initialValue` within bounds/integrality tolerance `1e-6`), and finite objective/constraint coefficients.
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.
59
+ - **Integrity check & LP export**: `m.toLpString()` validates model integrity (variable ownership across `Model` instances, `lb <= ub`, finite `initialValue` within bounds/integrality tolerance `1e-6`, and finite coefficients) and exports the numeric LP / MIP / QP formulation in CPLEX LP format (`Maximize` / `Minimize`, `Subject To`, `Bounds`, `General`, `Binary`, `End`).
60
+ - **What to check**: Inspect the exported text to confirm objective sense, signs, coefficients, and right-hand sides match the mathematical specification.
61
+ - **Scope caveat**: Propositional `BoolVar`s and logical/CP constraints (`BoolExpr`) are omitted from CPLEX LP output.
55
62
 
56
63
  ---
57
64
 
@@ -61,19 +68,20 @@ Never report a model solution as final without executing the verification step:
61
68
 
62
69
  1. **After `const status = await m.solve(options?)`**:
63
70
  - Verify `status === "Optimal"` (or `status === "Feasible"` / `m.hasPrimalSolution === true` when solver limits apply).
64
- - Call `const report = m.validateSolution()` and assert `report.valid === true`.
71
+ - Call `const report = m.verify()` and assert `report.valid === true`.
65
72
  - If `report.valid === false`, inspect `report.violations`, `report.missingVariables`, `report.uncheckedConstraints`, and `report.maxViolation`.
66
- - Note: `m.validateSolution()` 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.
73
+ - 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
74
  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 unsat core).
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 asserts 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).
75
+ - Run `const res = await m.check()` for built-in HiGHS diagnosis (single-solve elastic slack relaxation), `await m.check({ solver: "pumpkin" })` for bounded integer/boolean `unsatCore`, or `await m.check({ solver: "z3" })` for exact SMT `unsatCore` including `Continuous`/fractional constraints.
76
+ - When `res.status === "Unsat"`, inspect `res.conflicts` (also stored on `m.conflicts`). On Z3 and Pumpkin, both `res.unsatCore` and `res.conflicts` report a contradictory subset of constraints.
77
+ - On HiGHS, `res.conflicts` lists constraints whose relaxation restores feasibility, and `res.unsatCore` is intentionally `undefined` because an elastic relaxation repair set is not an unsatisfiable core proof.
78
+ - 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
79
 
72
80
  ---
73
81
 
74
82
  ## 5. Executable Workflow Recipes
75
83
 
76
- ### Recipe 1: MIP Formulation, `toLpString()` Inspection & `validateSolution()` Verification
84
+ ### Recipe 1: MIP Formulation, `toLpString()` Inspection & `verify()` Verification
77
85
 
78
86
  ```ts
79
87
  import { Model, expr, dot, sum, maximize } from "@ohtaman/washi";
@@ -96,21 +104,20 @@ export async function solveAndVerifyMip() {
96
104
  name: "closed_line_zero_output",
97
105
  });
98
106
 
99
- // 1. Pre-solve integrity & LP formulation inspection
100
- m.validateIntegrity();
107
+ // 1. Pre-solve integrity validation & LP formulation inspection
101
108
  const lpText = m.toLpString();
102
109
 
103
110
  // 2. Solve with default HiGHS solver
104
111
  const status = await m.solve();
105
112
 
106
113
  // 3. Mandatory independent solution verification
107
- const report = m.validateSolution();
114
+ const report = m.verify();
108
115
 
109
116
  return {
110
117
  status,
111
118
  lpText,
112
119
  objectiveValue: m.objectiveValue,
113
- quantities: m.getValues(qty),
120
+ quantities: { desk: qty.desk.value, chair: qty.chair.value },
114
121
  lineOpen: lineOpen.value,
115
122
  valid: report.valid,
116
123
  maxViolation: report.maxViolation,
@@ -133,7 +140,7 @@ export async function solveAndVerifyQp() {
133
140
 
134
141
  const lpText = m.toLpString();
135
142
  const status = await m.solve();
136
- const report = m.validateSolution();
143
+ const report = m.verify();
137
144
 
138
145
  return {
139
146
  status,
@@ -174,7 +181,7 @@ export async function diagnoseAndVerifyWithZ3() {
174
181
  satModel.constraint(expr`${discountSat} <= 25`, "campaign_cap");
175
182
 
176
183
  const satRes = await satModel.check();
177
- const report = satModel.validateSolution();
184
+ const report = satModel.verify();
178
185
 
179
186
  return {
180
187
  unsatStatus: unsatRes.status,
@@ -187,15 +194,81 @@ export async function diagnoseAndVerifyWithZ3() {
187
194
  }
188
195
  ```
189
196
 
197
+ ### Recipe 4: Pumpkin CP Scheduling (`disjoint`, `distinct`) & `unsatCore` Verification
198
+
199
+ ```ts
200
+ import { Model, expr, disjoint, distinct, implies, minimize } from "@ohtaman/washi";
201
+
202
+ export async function solveAndDiagnoseWithPumpkin() {
203
+ // Part A: Bounded-integer CP scheduling with native global propagators
204
+ const cpModel = new Model("WorkshopSchedule", { solver: "pumpkin" });
205
+ const start = cpModel.integer(["cut", "weld", "paint"] as const, { lb: 0, ub: 20, prefix: "start" });
206
+ const bench = cpModel.integer(["cut", "weld", "paint"] as const, { lb: 1, ub: 3, prefix: "bench" });
207
+
208
+ cpModel.constraint(
209
+ disjoint([
210
+ { start: start.cut, duration: 4 },
211
+ { start: start.weld, duration: 3 },
212
+ { start: start.paint, duration: 2 },
213
+ ]),
214
+ "single_line"
215
+ );
216
+ cpModel.constraint(expr`${start.cut} + 4 <= ${start.weld}`, "cut_before_weld");
217
+ cpModel.constraint(expr`${start.weld} + 3 <= ${start.paint}`, "weld_before_paint");
218
+ cpModel.constraint(distinct(bench), "unique_benches");
219
+ cpModel.objective(minimize(expr`${start.paint} + 2`));
220
+
221
+ const status = await cpModel.solve();
222
+ const report = cpModel.verify();
223
+
224
+ // Part B: Bounded-integer & boolean unsatCore diagnosis
225
+ const unsatModel = new Model("PolicyConflict", { solver: "pumpkin" });
226
+ const vip = unsatModel.bool("vip");
227
+ const discount = unsatModel.integer("discount", { lb: 0, ub: 50 });
228
+
229
+ unsatModel.constraint(vip, "customer_is_vip");
230
+ unsatModel.constraint(implies(vip, expr`${discount} >= 20`), "vip_min_discount");
231
+ unsatModel.constraint(expr`${discount} <= 10`, "campaign_cap");
232
+
233
+ const unsatRes = await unsatModel.check();
234
+
235
+ return {
236
+ status,
237
+ makespan: cpModel.objectiveValue,
238
+ starts: { cut: start.cut.value, weld: start.weld.value, paint: start.paint.value },
239
+ benches: { cut: bench.cut.value, weld: bench.weld.value, paint: bench.paint.value },
240
+ valid: report.valid,
241
+ unsatStatus: unsatRes.status,
242
+ conflicts: unsatRes.conflicts,
243
+ unsatCore: unsatRes.unsatCore,
244
+ };
245
+ }
246
+ ```
247
+
190
248
  ---
191
249
 
192
250
  ## 6. Guardrails & Common Pitfalls
193
251
 
194
- - **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`).
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 `=`) or `BoolExpr` (never a bare `LinExpr`).
252
+ - **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"`). Only HiGHS supports `QuadExpr` objectives (`Pumpkin`, `Z3`, and `GLPK` throw), and HiGHS requires Convex QP models to contain only continuous variables (`m.continuous`).
253
+ - **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
254
  - **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.setObjective`), `await m.solve()` (not `m.optimize`), `.le()` / `.ge()` / `.eq()` (not `.lessThanOrEqual()`), `.value` / `m.getValues(...)` (not `.getValue()`), and `m.variables` / `m.constraints` (not `m.vars` / `m.constrs`).
198
255
  - **Practical OR formulation guardrails**:
199
256
  - **Prefer inequalities (`>=` / `<=`) over `==`** for demand coverage and capacity limits when costs are non-negative; reserve `==` for flow conservation or normalization identities.
200
- - **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.
257
+ - **Provide finite `lb` and `ub` bounds** on variables inside `m.indicator(...)` and omit `M`: WaSHI derives a tight Big-M from finite bounds and **throws an error** if any required bound is infinite.
201
258
  - **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"`.
259
+
260
+ ### Retired Aliases (Do Not Use)
261
+
262
+ | Use | Avoid (Retired) |
263
+ | :--- | :--- |
264
+ | `expr` | `c` |
265
+ | `m.constraint(...)` | `m.constrain`, `m.add` |
266
+ | `m.objective(maximize(...))` / `m.objective()` | `m.maximize`, `m.setObjective`, `m.objectiveExpr` |
267
+ | `await m.solve()` | `m.optimize` |
268
+ | `m.verify()` | `m.validateSolution()` |
269
+ | `m.column(...)` | `m.addColumn(...)` |
270
+ | `.le()` / `.ge()` / `.eq()` / `.lt()` / `.gt()` / `.ne()` | `.lessThanOrEqual()` |
271
+ | `.value` | `m.getValues(...)`, `.getValue()` |
272
+ | `m.variables` / `m.constraints` (`ReadonlyMap` with `.get(...)` / `.size`) | `m.vars`, `m.constrs`, `m.boolVars`, `m.logicalConstraints`, `m.numVars`, `m.numConstrs`, `get*ByName()` |
273
+ | `relativeGap` / `absoluteGap` | `relGap`, `mipGap`, `absGap` |
274
+ | Automatic validation in `solve()`, `check()`, `toLpString()` | `m.validateIntegrity()` |
File without changes