@ohtaman/washi 0.8.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.
- package/README.ja.md +22 -24
- package/README.md +20 -22
- package/README.zh-CN.md +25 -27
- package/dist/browser/{__vite-browser-external-rTVKos2U.js → solvers/highs-__vite-browser-external-Dn-83hnF.js} +1 -1
- package/dist/browser/{browser-runtime-AG5QFtKf.js → solvers/highs-browser-runtime-0Bgq5ksG.js} +1 -1
- package/dist/browser/{loader-i3FnqMes.js → solvers/highs-loader-BLY3wzDH.js} +25 -18
- package/dist/browser/{highs-worker.js → solvers/highs-worker.js} +1 -1
- package/dist/browser/solvers/highs.js +1414 -0
- package/dist/browser/washi.js +1090 -1473
- package/dist/browser/washi.min.js +4 -4
- package/dist/lib/solvers/glpk.js +34 -32
- package/dist/lib/{highs-node-runtime.js → solvers/highs-node-runtime.js} +1 -1
- package/dist/lib/solvers/highs.js +410 -0
- package/dist/lib/solvers/lp-writer-CLScMFbS.js +115 -0
- package/dist/lib/solvers/pumpkin-node-runtime.js +1 -1
- package/dist/lib/solvers/pumpkin-worker.js +1 -1
- package/dist/lib/solvers/pumpkin.js +247 -1146
- package/dist/lib/solvers/registry-CrYRRk9q.js +907 -0
- package/dist/lib/solvers/types-BGqPkxwu.js +12 -0
- package/dist/lib/solvers/z3.js +125 -123
- package/dist/lib/washi.js +2426 -1340
- package/dist/types/index.d.ts +1 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modeler/index.d.ts +0 -1
- package/dist/types/modeler/index.d.ts.map +1 -1
- package/dist/types/modeler/model.d.ts +6 -7
- package/dist/types/modeler/model.d.ts.map +1 -1
- package/dist/types/modeler/solvers/index.d.ts +2 -1
- package/dist/types/modeler/solvers/index.d.ts.map +1 -1
- package/dist/types/modeler/solvers/registry.d.ts.map +1 -1
- package/docs/examples/diet-sensitivity.md +33 -14
- package/docs/examples/ecommerce-coupons.md +17 -9
- package/docs/examples/index.md +34 -30
- package/docs/examples/knapsack.md +11 -5
- package/docs/examples/portfolio-qp.md +21 -8
- package/docs/examples/production.md +10 -5
- package/docs/examples/project-scheduling.md +25 -12
- package/docs/examples/shift-scheduling.md +27 -19
- package/docs/examples/smt-security.md +27 -12
- package/docs/examples/transportation.md +23 -13
- package/docs/examples/traveling-salesperson.md +34 -22
- package/docs/examples/unsat-core.md +27 -15
- package/docs/examples/vehicle-routing.md +74 -28
- package/docs/getting-started/ai-agents.md +129 -90
- package/docs/getting-started/coding-agents.md +60 -41
- package/docs/getting-started/cross-origin.md +27 -14
- package/docs/getting-started/index.md +23 -16
- package/docs/getting-started/runtimes.md +70 -40
- package/docs/guide/constraint-programming.md +74 -44
- package/docs/guide/constraints.md +71 -39
- package/docs/guide/decomposition.md +72 -42
- package/docs/guide/expressions.md +79 -48
- package/docs/guide/formulation-tips.md +46 -27
- package/docs/guide/objectives.md +55 -31
- package/docs/guide/unsat-core.md +56 -53
- package/docs/guide/variables.md +61 -28
- package/docs/solvers/custom-solver.md +155 -119
- package/docs/solvers/glpk.md +58 -17
- package/docs/solvers/highs.md +115 -43
- package/docs/solvers/index.md +33 -26
- package/docs/solvers/pumpkin.md +71 -63
- package/docs/solvers/z3.md +63 -25
- package/llms-full.txt +1623 -953
- package/llms.txt +125 -93
- package/package.json +29 -20
- package/skills/washi/SKILL.md +43 -22
- package/dist/browser/solvers/pumpkin.min.js +0 -1
- package/dist/lib/registry-dx7x4e5c.js +0 -1694
- /package/dist/browser/{highs.wasm → solvers/highs.wasm} +0 -0
- /package/dist/browser/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
- /package/dist/lib/{__vite-browser-external-oLchLuMx.js → solvers/__vite-browser-external-oLchLuMx.js} +0 -0
- /package/dist/lib/{highs-assets.js → solvers/highs-assets.js} +0 -0
- /package/dist/lib/{highs-browser-runtime.js → solvers/highs-browser-runtime.js} +0 -0
- /package/dist/lib/{highs-runtime.js → solvers/highs-runtime.js} +0 -0
- /package/dist/lib/{highs-worker-factory.js → solvers/highs-worker-factory.js} +0 -0
- /package/dist/lib/{highs-worker.js → solvers/highs-worker.js} +0 -0
- /package/dist/lib/{highs.wasm → solvers/highs.wasm} +0 -0
- /package/dist/lib/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
- /package/dist/lib/{loader-CDpPXN_F.js → solvers/loader-CDpPXN_F.js} +0 -0
- /package/dist/lib/solvers/{pumpkin-loader-Ow74Fa1B.js → loader-Ow74Fa1B.js} +0 -0
- /package/dist/lib/{rolldown-runtime-DtPi1Y-2.js → solvers/rolldown-runtime-DtPi1Y-2.js} +0 -0
package/skills/washi/SKILL.md
CHANGED
|
@@ -5,7 +5,7 @@ description: Formulate, inspect, solve, and verify mathematical optimization (LP
|
|
|
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, CP
|
|
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,15 +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** (
|
|
19
|
-
| **CP/LCG Bounded Integer, Scheduling & Global Constraints** (`distinct`, `disjoint`, `cumulative`, `allowed`, `at`, `max`/`min`/`abs`, `!=`, `
|
|
20
|
-
| **SMT Propositional Logic** (`BoolVar`, `and`, `or`, `not`, `implies`, `xor`) | **HiGHS** (auto 0-1 MIP), **Pumpkin** (bounded int), or **Z3** (native SMT incl. `Continuous`) |
|
|
21
|
-
| **Infeasibility / Conflict Diagnosis** (`conflicts` / `unsatCore`) | **HiGHS** (
|
|
22
|
-
| **LP / MIP with GLPK** (GPL-3.0; no QP or `
|
|
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" })` |
|
|
23
23
|
|
|
24
24
|
- **Browser runtime notes**:
|
|
25
|
-
- HiGHS
|
|
26
|
-
-
|
|
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`).
|
|
27
28
|
|
|
28
29
|
---
|
|
29
30
|
|
|
@@ -36,15 +37,18 @@ Select the solver engine and execution method that match the problem class:
|
|
|
36
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.
|
|
37
38
|
2. **Build expressions (`expr`, `sum`, `dot`, `max`, `min`, `abs`, `at`)**:
|
|
38
39
|
- Linear expression (`LinExpr`): `` expr`30 * ${x} + 50 * ${y} - 10` ``, `` expr`dot(${profit}, ${qty}) - 20 * ${lineOpen}` ``
|
|
39
|
-
- Piecewise-linear &
|
|
40
|
-
-
|
|
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).
|
|
41
43
|
- 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?)`
|
|
43
|
-
- CP global constraints &
|
|
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" }`).
|
|
44
47
|
3. **Register objective and named constraints**:
|
|
45
48
|
- Constructing an `expr` or `.le()` / `.ge()` / `.eq()` / `.lt()` / `.gt()` / `.ne()` object does **not** attach it to the model.
|
|
46
49
|
- Register the objective with `m.objective(maximize(e))` or `m.objective(minimize(e))`.
|
|
47
|
-
- Register every constraint with a descriptive name
|
|
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`.
|
|
48
52
|
|
|
49
53
|
---
|
|
50
54
|
|
|
@@ -52,7 +56,9 @@ Select the solver engine and execution method that match the problem class:
|
|
|
52
56
|
|
|
53
57
|
Before solving or when debugging formulation bugs:
|
|
54
58
|
|
|
55
|
-
-
|
|
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.
|
|
56
62
|
|
|
57
63
|
---
|
|
58
64
|
|
|
@@ -66,8 +72,9 @@ Never report a model solution as final without executing the verification step:
|
|
|
66
72
|
- If `report.valid === false`, inspect `report.violations`, `report.missingVariables`, `report.uncheckedConstraints`, and `report.maxViolation`.
|
|
67
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.
|
|
68
74
|
2. **When a model is infeasible (`"Infeasible"` or `"Unsat"`)**:
|
|
69
|
-
- Run `const res = await m.check()`
|
|
70
|
-
- When `res.status === "Unsat"`, inspect `res.conflicts` (also stored on `m.conflicts`). On
|
|
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.
|
|
71
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).
|
|
72
79
|
|
|
73
80
|
---
|
|
@@ -187,11 +194,10 @@ export async function diagnoseAndVerifyWithZ3() {
|
|
|
187
194
|
}
|
|
188
195
|
```
|
|
189
196
|
|
|
190
|
-
### Recipe 4: Pumpkin CP Scheduling (`disjoint`, `distinct`) &
|
|
197
|
+
### Recipe 4: Pumpkin CP Scheduling (`disjoint`, `distinct`) & `unsatCore` Verification
|
|
191
198
|
|
|
192
199
|
```ts
|
|
193
200
|
import { Model, expr, disjoint, distinct, implies, minimize } from "@ohtaman/washi";
|
|
194
|
-
import "@ohtaman/washi/solvers/pumpkin";
|
|
195
201
|
|
|
196
202
|
export async function solveAndDiagnoseWithPumpkin() {
|
|
197
203
|
// Part A: Bounded-integer CP scheduling with native global propagators
|
|
@@ -215,7 +221,7 @@ export async function solveAndDiagnoseWithPumpkin() {
|
|
|
215
221
|
const status = await cpModel.solve();
|
|
216
222
|
const report = cpModel.verify();
|
|
217
223
|
|
|
218
|
-
// Part B:
|
|
224
|
+
// Part B: Bounded-integer & boolean unsatCore diagnosis
|
|
219
225
|
const unsatModel = new Model("PolicyConflict", { solver: "pumpkin" });
|
|
220
226
|
const vip = unsatModel.bool("vip");
|
|
221
227
|
const discount = unsatModel.integer("discount", { lb: 0, ub: 50 });
|
|
@@ -243,11 +249,26 @@ export async function solveAndDiagnoseWithPumpkin() {
|
|
|
243
249
|
|
|
244
250
|
## 6. Guardrails & Common Pitfalls
|
|
245
251
|
|
|
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
|
|
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`).
|
|
247
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`.
|
|
248
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.
|
|
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
255
|
- **Practical OR formulation guardrails**:
|
|
251
256
|
- **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
|
|
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.
|
|
253
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()` |
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var WashiPumpkin=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.defineProperty,n=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},r=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r};function i(e,t){let n=e.id,r=t.id;return n<=r?`${n}:${r}`:`${r}:${n}`}var a=class e{kind=`quadratic`;linearTerms;quadTerms;constant;nonlinearTerms;constructor(e=new Map,t=new Map,n=0,r=[]){this.linearTerms=new Map(e),this.quadTerms=new Map;for(let[e,n]of t)this.quadTerms.set(e,{...n});this.constant=n,this.nonlinearTerms=r.filter(e=>e.coeff!==0).map(e=>({atom:l(e.atom),coeff:e.coeff}))}hasNonlinearTerms(){return this.nonlinearTerms.length>0}clone(){return new e(this.linearTerms,this.quadTerms,this.constant,this.nonlinearTerms)}getQuadCoeff(e,t){let n=i(e,t),r=this.quadTerms.get(n);return r?r.coeff:0}add(t){if(x(t))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);let n=this.clone();if(typeof t==`number`)return n.constant+=t,n;if(t instanceof e){for(let[e,r]of t.quadTerms){let t=n.quadTerms.get(e),i=(t?t.coeff:0)+r.coeff;i===0?n.quadTerms.delete(e):n.quadTerms.set(e,{var1:r.var1,var2:r.var2,coeff:i})}for(let[e,r]of t.linearTerms){let t=(n.linearTerms.get(e)??0)+r;t===0?n.linearTerms.delete(e):n.linearTerms.set(e,t)}if(n.constant+=t.constant,Array.isArray(t.nonlinearTerms))for(let e of t.nonlinearTerms)e.coeff!==0&&n.nonlinearTerms.push({atom:l(e.atom),coeff:e.coeff});return n}if(`terms`in t&&t.terms instanceof Map){for(let[e,r]of t.terms){let t=(n.linearTerms.get(e)??0)+r;t===0?n.linearTerms.delete(e):n.linearTerms.set(e,t)}if(n.constant+=t.constant,Array.isArray(t.nonlinearTerms))for(let e of t.nonlinearTerms)e.coeff!==0&&n.nonlinearTerms.push({atom:l(e.atom),coeff:e.coeff});return n}let r=t,i=(n.linearTerms.get(r)??0)+1;return i===0?n.linearTerms.delete(r):n.linearTerms.set(r,i),n}sub(e){if(x(e))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);return typeof e==`number`?this.add(-e):this.add(e.mul(-1))}mul(t){if(x(t))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);if(typeof t==`number`){let n=this.linearTerms.size>0||this.quadTerms.size>0||this.nonlinearTerms.length>0,r=this.constant===0&&n?0:this.constant*t;if(this.constant!==0&&t!==0&&r===0)throw Error(`Constant multiplication underflows to zero.`);let i=new e(new Map,new Map,r);for(let[e,n]of this.linearTerms){let r=n*t;if(n!==0&&t!==0&&r===0)throw Error(`Coefficient multiplication underflows to zero.`);r!==0&&i.linearTerms.set(e,r)}for(let[e,n]of this.quadTerms){let r=n.coeff*t;if(n.coeff!==0&&t!==0&&r===0)throw Error(`Coefficient multiplication underflows to zero.`);r!==0&&i.quadTerms.set(e,{var1:n.var1,var2:n.var2,coeff:r})}if(t!==0)for(let e of this.nonlinearTerms){let n=e.coeff*t;if(e.coeff!==0&&n===0)throw Error(`Coefficient multiplication underflows to zero.`);n!==0&&i.nonlinearTerms.push({atom:l(e.atom),coeff:n})}return i}let n=`id`in t&&`name`in t&&!(`terms`in t)&&!(`quadTerms`in t),r=`quadTerms`in t?t.quadTerms.size:0,i=!n&&`nonlinearTerms`in t&&Array.isArray(t.nonlinearTerms)?t.nonlinearTerms.length:0,a=n?new Map([[t,1]]):`quadTerms`in t?t.linearTerms:t.terms,o=n?0:t.constant;if(this.nonlinearTerms.length>0){if(!n&&r===0&&a.size===0&&i===0)return this.mul(o);throw Error(`Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.`)}if(i>0){if(this.quadTerms.size===0&&this.linearTerms.size===0){let n=t.mul(this.constant);return`quadTerms`in n?n:new e(n.terms,new Map,n.constant,n.nonlinearTerms)}throw Error(`Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.`)}if(this.quadTerms.size>0&&(r>0||a.size>0)||r>0&&this.linearTerms.size>0)throw Error(`Multiplication creates a non-linear term of degree > 2 (not allowed in MILP/LP/QP)`);if(r===0&&a.size===0)return this.mul(o);if(this.quadTerms.size===0&&this.linearTerms.size===0&&!n){let n=t.mul(this.constant);return`quadTerms`in n?n:new e(n.terms,new Map,n.constant,n.nonlinearTerms)}return e.multiplyLinearTerms(this.constant,this.linearTerms,o,a)}div(t){let n=e.extractScalarDivisor(t,`QuadExpr.div()`);return this.mul(1/n)}neg(){return this.mul(-1)}get value(){let e=this.constant;for(let[t,n]of this.linearTerms){if(t.value===null)return null;e+=n*t.value}for(let t of this.quadTerms.values()){if(t.var1.value===null||t.var2.value===null)return null;e+=t.coeff*t.var1.value*t.var2.value}for(let t of this.nonlinearTerms){let n=d(t.atom);if(n===null)return null;e+=t.coeff*n}return e}le(e,t){return this.toConstraint(`<=`,e,t)}ge(e,t){return this.toConstraint(`>=`,e,t)}eq(e,t){return this.toConstraint(`==`,e,t)}lt(e,t){return this.toDiscreteComparison(`<`,e,t)}gt(e,t){return this.toDiscreteComparison(`>`,e,t)}ne(e,t){return this.toDiscreteComparison(`!=`,e,t)}toDiscreteComparison(e,t,n){if(this.quadTerms.size>0)throw Error(`Quadratic expressions are not supported in discrete comparisons (${e}): quadratic terms are only allowed in objectives.`);let r=new m(this.linearTerms,this.constant,this.nonlinearTerms);return e===`<`?r.lt(t,n):e===`>`?r.gt(t,n):r.ne(t,n)}toConstraint(e,t,n){if(this.quadTerms.size>0)throw Error(`Quadratic expressions are not supported in linear constraints (${e}): quadratic terms are only allowed in objectives.`);let r=new m(this.linearTerms,this.constant,this.nonlinearTerms);return e===`<=`?r.le(t,n):e===`>=`?r.ge(t,n):r.eq(t,n)}and(e){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical 'and': expected a BoolVar, Constraint, or BoolOp.`)}or(e){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical 'or': expected a BoolVar, Constraint, or BoolOp.`)}implies(e){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical 'implies': expected a BoolVar, Constraint, or BoolOp.`)}xor(e){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical 'xor': expected a BoolVar, Constraint, or BoolOp.`)}not(){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical 'not': expected a BoolVar, Constraint, or BoolOp.`)}toString(){let e=[],t=!0;for(let n of this.quadTerms.values()){let r=n.coeff,i=r>=0?t?``:`+ `:`- `,a=Math.abs(r),o=a===1?``:`${a} `;n.var1===n.var2?e.push(`${i}${o}${n.var1.name}^2`):e.push(`${i}${o}${n.var1.name} * ${n.var2.name}`),t=!1}for(let[n,r]of this.linearTerms){let i=r>=0?t?``:`+ `:`- `,a=Math.abs(r),o=a===1?``:`${a} `;e.push(`${i}${o}${n.name}`),t=!1}if(this.nonlinearTerms.length>0){let n=new m(new Map,0,this.nonlinearTerms).toString();n!==`0`&&(e.push(t?n:n.startsWith(`-`)?`- ${n.slice(2)}`:`+ ${n}`),t=!1)}if(this.constant!==0||e.length===0){let n=this.constant>=0?t?``:`+ `:`- `;e.push(`${n}${Math.abs(this.constant)}`)}return e.join(` `)||`0`}static fromProduct(t,n,r=1){let a=new e;if(r===0)return a;let o=i(t,n);return a.quadTerms.set(o,{var1:t.id<=n.id?t:n,var2:t.id<=n.id?n:t,coeff:r}),a}static multiplyLinearTerms(t,n,r,i){let a=n.size>0||i.size>0,o=(t===0||r===0)&&a?0:t*r;if(t!==0&&r!==0&&o===0)throw Error(`Constant multiplication underflows to zero.`);let s=new e(new Map,new Map,o===0?0:o);if(r!==0)for(let[e,t]of n){let n=t*r;if(t!==0&&n===0)throw Error(`Coefficient multiplication underflows to zero.`);n!==0&&s.linearTerms.set(e,n)}if(t!==0)for(let[e,n]of i){let r=s.linearTerms.get(e)??0,i=n*t;if(n!==0&&i===0)throw Error(`Coefficient multiplication underflows to zero.`);let a=r+i;a===0?s.linearTerms.delete(e):s.linearTerms.set(e,a)}for(let[t,r]of n)for(let[n,a]of i){let i=r*a;if(r!==0&&a!==0&&i===0)throw Error(`Coefficient multiplication underflows to zero.`);s=s.add(e.fromProduct(t,n,i))}return s}static extractScalarDivisor(e,t){if(x(e))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);if(typeof e==`number`){if(e===0)throw Error(`Division by zero in ${t}`);return e}let n=`quadTerms`in e?e.linearTerms.size:e.terms.size,r=`quadTerms`in e?e.quadTerms.size:0,i=`nonlinearTerms`in e&&Array.isArray(e.nonlinearTerms)?e.nonlinearTerms.length:0;if(n>0||r>0||i>0)throw Error(`Cannot divide by variable in expression`);if(e.constant===0)throw Error(`Division by zero in ${t}`);return e.constant}},o=0;function s(e){if(e===void 0)return`Continuous`;if(typeof e==`string`){let t=e.toLowerCase();if(t===`binary`||t===`bin`)return`Binary`;if(t===`integer`||t===`int`)return`Integer`;if(t===`continuous`||t===`cont`)return`Continuous`}throw Error(`Invalid variable type "${String(e)}": expected "Continuous", "Integer", or "Binary".`)}var c=class{id;_name;prefix;hasExplicitName;ownerModel=null;_type;_lb;_ub;_initialValue;value=null;reducedCost=null;constructor(e={}){this.id=++o;let t=typeof e.name==`string`?e.name.trim():``,n=typeof e.prefix==`string`?e.prefix.trim():``;this.prefix=n.length>0?n:`x`,this.hasExplicitName=t.length>0,this._name=this.hasExplicitName?t:`${this.prefix}_${this.id}`,this._type=s(e.type),this._type===`Binary`?(this._lb=0,this._ub=1):(this._lb=e.lb===void 0?0:e.lb,this._ub=e.ub===void 0?1/0:e.ub),this._initialValue=e.initialValue===void 0?void 0:Object.is(e.initialValue,-0)?0:e.initialValue,this._initialValue!==void 0&&v(this)}get name(){return this._name}get type(){return this._type}set type(e){let t=s(e);this._type!==t&&(this._type=t,g(this.ownerModel))}get lb(){return this._lb}set lb(e){Object.is(this._lb,e)||(this._lb=e,g(this.ownerModel))}get ub(){return this._ub}set ub(e){Object.is(this._ub,e)||(this._ub=e,g(this.ownerModel))}get initialValue(){return this._initialValue}set initialValue(e){let t=e!==void 0&&Object.is(e,-0)?0:e;Object.is(this._initialValue,t)||(this._initialValue=t,g(this.ownerModel))}_assignModelName(e){this._name=e}mul(e){return typeof e==`number`?new m(new Map([[this,1]]),0).mul(e):new a(new Map([[this,1]]),new Map,0).mul(e)}add(e){return e instanceof a?e.add(this):new m(new Map([[this,1]]),0).add(e)}sub(e){return e instanceof a?e.neg().add(this):new m(new Map([[this,1]]),0).sub(e)}neg(){return this.mul(-1)}le(e,t){return new m(new Map([[this,1]]),0).le(e,t)}ge(e,t){return new m(new Map([[this,1]]),0).ge(e,t)}eq(e,t){return new m(new Map([[this,1]]),0).eq(e,t)}lt(e,t){return new m(new Map([[this,1]]),0).lt(e,t)}gt(e,t){return new m(new Map([[this,1]]),0).gt(e,t)}ne(e,t){return new m(new Map([[this,1]]),0).ne(e,t)}toString(){return this.name}};function l(e){switch(e.kind){case`abs`:return{kind:`abs`,arg:e.arg.clone()};case`max`:return{kind:`max`,args:e.args.map(e=>e.clone())};case`min`:return{kind:`min`,args:e.args.map(e=>e.clone())};case`at`:return{kind:`at`,array:e.array.map(e=>e.clone()),index:e.index.clone(),discreteVars:new Set(e.discreteVars)}}}function u(e){switch(e.kind){case`abs`:return`abs(${e.arg.toString()})`;case`max`:return`max(${e.args.map(e=>e.toString()).join(`, `)})`;case`min`:return`min(${e.args.map(e=>e.toString()).join(`, `)})`;case`at`:return`at([${e.array.map(e=>e.toString()).join(`, `)}], ${e.index.toString()})`}}function d(e){switch(e.kind){case`abs`:{let t=e.arg.value;return t===null?null:Math.abs(t)}case`max`:{let t=-1/0;for(let n of e.args){let e=n.value;if(e===null)return null;e>t&&(t=e)}return t}case`min`:{let t=1/0;for(let n of e.args){let e=n.value;if(e===null)return null;e<t&&(t=e)}return t}case`at`:{let t=e.index.value;if(t===null||!Number.isFinite(t))return null;let n=Math.round(t);return Math.abs(t-n)>1e-6||n<0||n>=e.array.length?null:e.array[n].value}}}function f(e){return e instanceof c||typeof e==`object`&&!!e&&!x(e)&&typeof e.id==`number`&&typeof e.name==`string`&&typeof e.lb==`number`&&typeof e.ub==`number`&&typeof e.type==`string`&&typeof e.mul==`function`}function p(e,t,n=new Set){if(typeof e==`number`){if(!Number.isSafeInteger(e))throw Error(`${t} requires Integer or Binary variables and integer constants/coefficients, but received constant ${e}.`);return n}if(x(e))throw Error(`${t} cannot accept a Constraint comparison.`);if(e instanceof a||`quadTerms`in e&&e.quadTerms instanceof Map&&`linearTerms`in e&&e.linearTerms instanceof Map&&typeof e.constant==`number`){let r=e;if(r.quadTerms.size>0)throw Error(`${t} does not support quadratic expressions.`);return p(new m(r.linearTerms,r.constant,r.nonlinearTerms??[]),t,n)}if(f(e)){if(e.type!==`Integer`&&e.type!==`Binary`)throw Error(`${t} requires Integer or Binary variables, but involves Continuous variable "${e.name}".`);return n.add(e),n}if(`terms`in e&&e.terms instanceof Map){let r=e,i=r.constant??0;if(!Number.isSafeInteger(i))throw Error(`${t} requires Integer or Binary variables and integer constants/coefficients, but received constant ${i}.`);for(let[e,i]of r.terms)if(i!==0){if(e.type!==`Integer`&&e.type!==`Binary`)throw Error(`${t} requires Integer or Binary variables, but involves Continuous variable "${e.name}".`);if(!Number.isSafeInteger(i))throw Error(`${t} requires integer coefficients, but variable "${e.name}" has coefficient ${i}.`);n.add(e)}for(let e of r.nonlinearTerms??[]){if(e.coeff===0)continue;if(!Number.isSafeInteger(e.coeff))throw Error(`${t} requires integer coefficients on nonlinear expressions, received ${e.coeff}.`);let r=e.atom;if(r.kind===`abs`)p(r.arg,t,n);else if(r.kind===`max`||r.kind===`min`)for(let e of r.args)p(e,t,n);else if(r.kind===`at`){p(r.index,t,n);for(let e of r.array)p(e,t,n)}}return n}throw Error(`${t} expected an integer-valued scalar expression.`)}var m=class e{kind=`linear`;terms;constant;nonlinearTerms;constructor(e=new Map,t=0,n=[]){this.terms=new Map(e),this.constant=t,this.nonlinearTerms=n.filter(e=>e.coeff!==0).map(e=>({atom:l(e.atom),coeff:e.coeff}))}hasNonlinearTerms(){return this.nonlinearTerms.length>0}setTerm(e,t){return t===0?this.terms.delete(e):this.terms.set(e,t),this}addTerm(e,t){let n=(this.terms.get(e)??0)+t;return n===0?this.terms.delete(e):this.terms.set(e,n),this}clone(){return new e(this.terms,this.constant,this.nonlinearTerms)}add(e){if(x(e))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);if(e instanceof a)return e.add(this);let t=this.clone();if(typeof e==`number`)t.constant+=e;else if(`terms`in e){for(let[n,r]of e.terms){let e=(t.terms.get(n)??0)+r;e===0?t.terms.delete(n):t.terms.set(n,e)}if(t.constant+=e.constant,Array.isArray(e.nonlinearTerms))for(let n of e.nonlinearTerms)n.coeff!==0&&t.nonlinearTerms.push({atom:l(n.atom),coeff:n.coeff})}else{let n=(t.terms.get(e)??0)+1;n===0?t.terms.delete(e):t.terms.set(e,n)}return t}sub(e){if(x(e))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);return e instanceof a?e.neg().add(this):typeof e==`number`?this.add(-e):this.add(e.mul(-1))}mul(t){if(x(t))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);if(typeof t==`number`){let n=this.terms.size>0||this.nonlinearTerms.length>0,r=this.constant===0&&n?0:this.constant*t;if(this.constant!==0&&t!==0&&r===0)throw Error(`Constant multiplication underflows to zero.`);let i=new e(new Map,r);for(let[e,n]of this.terms){let r=n*t;if(n!==0&&t!==0&&r===0)throw Error(`Coefficient multiplication underflows to zero.`);r!==0&&i.terms.set(e,r)}if(t!==0)for(let e of this.nonlinearTerms){let n=e.coeff*t;if(e.coeff!==0&&n===0)throw Error(`Coefficient multiplication underflows to zero.`);n!==0&&i.nonlinearTerms.push({atom:l(e.atom),coeff:n})}return i}if(t instanceof c||typeof t==`object`&&t&&`id`in t&&!(`terms`in t)&&!(`quadTerms`in t)){if(this.hasNonlinearTerms())throw Error(`Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.`);return a.multiplyLinearTerms(this.constant,this.terms,0,new Map([[t,1]]))}if(t instanceof a){let e=t.linearTerms.size>0||t.quadTerms.size>0||t.hasNonlinearTerms();if(this.hasNonlinearTerms()){if(!e)return this.mul(t.constant);throw Error(`Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.`)}if(t.hasNonlinearTerms()){if(this.terms.size===0)return t.mul(this.constant);throw Error(`Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.`)}return this.terms.size===0?t.mul(this.constant):new a(this.terms,new Map,this.constant).mul(t)}let n=Array.isArray(t.nonlinearTerms)&&t.nonlinearTerms.length>0;if(this.hasNonlinearTerms()){if(t.terms.size===0&&!n)return this.mul(t.constant);throw Error(`Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.`)}if(n){if(this.terms.size===0)return t.mul(this.constant);throw Error(`Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.`)}return this.terms.size===0?t.mul(this.constant):t.terms.size===0?this.mul(t.constant):a.multiplyLinearTerms(this.constant,this.terms,t.constant,t.terms)}div(e){let t=a.extractScalarDivisor(e,`LinExpr.div()`);return this.mul(1/t)}neg(){return this.mul(-1)}get value(){let e=this.constant;for(let[t,n]of this.terms){if(t.value===null)return null;e+=n*t.value}for(let t of this.nonlinearTerms){let n=d(t.atom);if(n===null)return null;e+=t.coeff*n}return e}le(e,t){return this.toConstraint(`<=`,e,t)}ge(e,t){return this.toConstraint(`>=`,e,t)}eq(e,t){return this.toConstraint(`==`,e,t)}lt(e,t){return this.toDiscreteComparison(`<`,e,t)}gt(e,t){return this.toDiscreteComparison(`>`,e,t)}ne(e,t){return this.toDiscreteComparison(`!=`,e,t)}toDiscreteComparison(e,t,n){if(t instanceof b||typeof t==`object`&&t&&`sense`in t&&`lhs`in t)throw Error(`Cannot compare against a Constraint in (${e}): expected a finite integer, discrete Var, or discrete LinExpr.`);let r=`discrete ${e}`,i=new Set;p(this,r,i),p(t,r,i);let a=this.toConstraint(e===`<`?`<=`:e===`>`?`>=`:`!=`,t,n);if(e===`<`){let e=a.rhs-1;if(!Number.isSafeInteger(e))throw Error(`Discrete comparison (<) adjusted right-hand side (${e}) exceeds safe integer range.`);a.rhs=e}else if(e===`>`){let e=a.rhs+1;if(!Number.isSafeInteger(e))throw Error(`Discrete comparison (>) adjusted right-hand side (${e}) exceeds safe integer range.`);a.rhs=e}else if(!Number.isSafeInteger(a.rhs))throw Error(`Discrete comparison (!=) adjusted right-hand side (${a.rhs}) exceeds safe integer range.`);return a._setDiscreteVars(i),a}toConstraint(t,n,r){let i=this.clone(),o=0;if(typeof n==`number`)o=n;else if(n instanceof b||typeof n==`object`&&n&&`sense`in n&&`lhs`in n)throw Error(`Cannot compare against a Constraint in (${t}): expected a number, Var, or LinExpr.`);else if(n instanceof a||typeof n==`object`&&n&&`quadTerms`in n){let r=n;if(r.quadTerms.size>0)throw Error(`Quadratic expressions are not supported in linear constraints (${t}): quadratic terms are only allowed in objectives.`);i=i.sub(new e(r.linearTerms,0,r.nonlinearTerms??[])),o=r.constant}else`terms`in n?(i=i.sub(new e(n.terms,0,n.nonlinearTerms??[])),o=n.constant):i=i.sub(n);let s=o-i.constant;return i.constant=0,new b(i,t,s,r)}and(e){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==, !=, <, >) in logical 'and': expected a BoolVar, Constraint, or BoolOp.`)}or(e){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==, !=, <, >) in logical 'or': expected a BoolVar, Constraint, or BoolOp.`)}implies(e){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==, !=, <, >) in logical 'implies': expected a BoolVar, Constraint, or BoolOp.`)}xor(e){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==, !=, <, >) in logical 'xor': expected a BoolVar, Constraint, or BoolOp.`)}not(){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==, !=, <, >) in logical 'not': expected a BoolVar, Constraint, or BoolOp.`)}toString(){let e=[],t=!0;for(let[n,r]of this.terms){let i=r>=0?t?``:`+ `:`- `,a=Math.abs(r),o=a===1?``:`${a} `;e.push(`${i}${o}${n.name}`),t=!1}for(let n of this.nonlinearTerms){let r=n.coeff,i=r>=0?t?``:`+ `:`- `,a=Math.abs(r),o=a===1?``:`${a} `;e.push(`${i}${o}${u(n.atom)}`),t=!1}if(this.constant!==0||e.length===0){let n=this.constant>=0?t?``:`+ `:`- `;e.push(`${n}${Math.abs(this.constant)}`)}return e.join(` `)||`0`}},h=new WeakMap;function g(e){e&&h.get(e)?.()}var _=1e-6;function v(e){if(typeof e.lb!=`number`||Number.isNaN(e.lb))throw Error(`Variable "${e.name}" has invalid lower bound: ${e.lb} (NaN or non-numeric bound is not allowed).`);if(e.lb===1/0)throw Error(`Variable "${e.name}" has invalid lower bound: +Infinity is not allowed as a lower bound.`);if(typeof e.ub!=`number`||Number.isNaN(e.ub))throw Error(`Variable "${e.name}" has invalid upper bound: ${e.ub} (NaN or non-numeric bound is not allowed).`);if(e.ub===-1/0)throw Error(`Variable "${e.name}" has invalid upper bound: -Infinity is not allowed as an upper bound.`);if(e.lb>e.ub)throw Error(`Variable "${e.name}" has invalid bounds: lower bound (${e.lb}) is strictly greater than upper bound (${e.ub}).`);if(e.initialValue!==void 0){if(typeof e.initialValue!=`number`||!Number.isFinite(e.initialValue))throw Error(`Variable "${e.name}" has invalid initialValue: ${String(e.initialValue)} (initialValue must be a finite number).`);let t=e.type===`Binary`?Math.max(0,e.lb):e.lb,n=e.type===`Binary`?Math.min(1,e.ub):e.ub;if(e.initialValue<t-1e-6||e.initialValue>n+1e-6)throw Error(`Variable "${e.name}" has initialValue (${e.initialValue}) outside its bounds [${t}, ${n}] (tolerance ${_}).`);if(e.type===`Integer`||e.type===`Binary`){let r=Math.round(e.initialValue);if(Math.abs(e.initialValue-r)>1e-6||r<t||r>n)throw Error(`Variable "${e.name}" of type "${e.type}" has non-integral or out-of-domain initialValue: ${e.initialValue} (must be within ${_} of an integer in [${t}, ${n}]).`)}}}var y=0,b=class e{kind=`constraint`;id;_lhs;_sense;_rhs;_name;hasExplicitName;ownerModel=null;_indicatorOrigin;_indicatorSnapshot;_discreteVars;slack=null;dual=null;addTerm(e,t){return t===0?this:(this._indicatorOrigin=void 0,this._indicatorSnapshot=void 0,this._lhs.addTerm(e,t),g(this.ownerModel),this)}setTerm(e,t){return this._indicatorOrigin=void 0,this._indicatorSnapshot=void 0,this._lhs.setTerm(e,t),g(this.ownerModel),this}constructor(e,t,n,r){this.id=++y,this._lhs=e,this._sense=t,this._rhs=n;let i=typeof r==`string`?r.trim():void 0;i&&i.length>0?(this._name=i,this.hasExplicitName=!0):(this._name=`c_${this.id}`,this.hasExplicitName=!1)}get lhs(){return this._lhs}set lhs(e){this._lhs!==e&&(this._indicatorOrigin=void 0,this._indicatorSnapshot=void 0,this._lhs=e,g(this.ownerModel))}get sense(){return this._sense}set sense(e){if(e===`!=`&&!Number.isSafeInteger(this._rhs))throw Error(`Discrete "!=" in constraint "${this._name}" requires a safe integer RHS, received ${this._rhs}.`);this._sense!==e&&(this._indicatorOrigin=void 0,this._indicatorSnapshot=void 0,this._sense=e,g(this.ownerModel))}get rhs(){return this._rhs}set rhs(e){if(this._sense===`!=`&&!Number.isSafeInteger(e))throw Error(`Discrete "!=" in constraint "${this._name}" requires a safe integer RHS, received ${e}.`);Object.is(this._rhs,e)||(this._indicatorOrigin=void 0,this._indicatorSnapshot=void 0,this._rhs=e,g(this.ownerModel))}get name(){return this._name}set name(e){this._name!==e&&(this._name=e,g(this.ownerModel)),this.hasExplicitName=!0}get _indicatorMeta(){let e=this._indicatorOrigin,t=this._indicatorSnapshot;if(!e||!t)return;if(this._lhs!==t.lhsRef||this._sense!==t.sense||!Object.is(this._rhs,t.rhs)||!Object.is(this._lhs.constant,t.constant)||this._lhs.nonlinearTerms.length>0||this._lhs.terms.size!==t.terms.size){this._indicatorOrigin=void 0,this._indicatorSnapshot=void 0;return}for(let[e,n]of t.terms)if(!this._lhs.terms.has(e)||!Object.is(this._lhs.terms.get(e),n)){this._indicatorOrigin=void 0,this._indicatorSnapshot=void 0;return}let n=e.targetRhs-(e.targetLhs.constant??0),r=0;for(let[t,n]of e.targetLhs.terms){if(n===0)continue;let i=e.targetSense===`<=`?n>0?t.ub:t.lb:n>0?t.lb:t.ub;if(!Number.isFinite(i)||(r+=n*i,!Number.isFinite(r)))return}if(!((e.targetSense===`<=`?r-n:n-r)>e.derivedM+1e-9))return e}_setIndicatorOrigin(e){if(!e){this._indicatorOrigin=void 0,this._indicatorSnapshot=void 0;return}this._indicatorOrigin=e,this._indicatorSnapshot={lhsRef:this._lhs,terms:new Map(this._lhs.terms),constant:this._lhs.constant,sense:this._sense,rhs:this._rhs}}get _requiredDiscreteVars(){return this._discreteVars}_setDiscreteVars(e){this._discreteVars=e}_assignModelName(e,t){this._name=e,this.hasExplicitName=t}and(e){return new w(`and`,[this,e])}or(e){return new w(`or`,[this,e])}implies(e){return new w(`implies`,[this,e])}xor(e){return new w(`xor`,[this,e])}not(){return new w(`not`,[this])}add(e){throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`)}sub(e){throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`)}mul(e){throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`)}div(e){throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`)}neg(){throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`)}le(e,t){throw Error(`Cannot compare a Constraint in (<=): expected a number, Var, or LinExpr.`)}ge(e,t){throw Error(`Cannot compare a Constraint in (>=): expected a number, Var, or LinExpr.`)}eq(e,t){throw Error(`Cannot compare a Constraint in (==): expected a number, Var, or LinExpr.`)}lt(e,t){throw Error(`Cannot compare a Constraint in (<): expected a number, Var, or LinExpr.`)}gt(e,t){throw Error(`Cannot compare a Constraint in (>): expected a number, Var, or LinExpr.`)}ne(e,t){throw Error(`Cannot compare a Constraint in (!=): expected a number, Var, or LinExpr.`)}get value(){throw Error(`Cannot read numeric value of a Constraint: expected a Var, LinExpr, or QuadExpr.`)}get constant(){throw Error(`Cannot read numeric constant of a Constraint: expected a LinExpr or QuadExpr.`)}clone(){let t=new e(this._lhs.clone(),this._sense,this._rhs,this.hasExplicitName?this._name:void 0);return this._discreteVars&&t._setDiscreteVars(new Set(this._discreteVars)),t}toString(){let e=this.sense===`==`?`=`:this.sense;return`${this.name}: ${this.lhs.toString()} ${e} ${this.rhs}`}};function x(e){return e instanceof b||typeof e==`object`&&!!e&&`sense`in e&&`lhs`in e&&`rhs`in e}var ee=0;function S(e,t){if(e instanceof C||e instanceof b)return e;throw typeof e==`object`&&e&&(`terms`in e||`quadTerms`in e)?Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical operator "${t}". Use a comparison constraint such as expr\`\${x} <= 10\` or a BoolVar/BoolExpr.`):typeof e==`object`&&e&&`id`in e&&`name`in e&&`lb`in e&&`ub`in e&&!(`sense`in e)?Error(`Invalid operand passed to logical operator "${t}": expected a BoolVar, BoolExpr, or Constraint, but received numeric variable "${e.name}". Use m.bool() for propositional variables, add a comparison such as expr\`\${x} == 1\`, or use m.indicator(binVar, constraint) for 0-1 Big-M indicator constraints.`):Error(`Invalid operand passed to logical operator "${t}": expected a BoolVar, BoolExpr, or Constraint.`)}var C=class{and(e){return new w(`and`,[this,S(e,`and`)])}or(e){return new w(`or`,[this,S(e,`or`)])}implies(e){return new w(`implies`,[this,S(e,`implies`)])}xor(e){return new w(`xor`,[this,S(e,`xor`)])}not(){return new w(`not`,[this])}},te=class extends C{id;type=`Boolean`;name;value=null;constructor(e){super(),this.id=++ee,this.name=e||`p_${this.id}`}toString(){return this.name}},w=class extends C{op;children;constructor(e,t){super(),this.op=e,this.children=t.map(t=>S(t,e))}toString(){return this.op===`not`?`not(${this.children[0].toString()})`:`(${this.children.map(e=>e.toString()).join(` ${this.op} `)})`}},ne=class extends C{spec;discreteVars;constructor(e,t){super(),this.spec=e,this.discreteVars=t}toString(){switch(this.spec.kind){case`distinct`:return`distinct(${this.spec.args.map(e=>e.toString()).join(`, `)})`;case`disjoint`:return`disjoint([${this.spec.tasks.map(e=>`{ start: ${e.start.toString()}, duration: ${e.duration} }`).join(`, `)}])`;case`cumulative`:return`cumulative([${this.spec.tasks.map(e=>`{ start: ${e.start.toString()}, duration: ${e.duration}, demand: ${e.demand} }`).join(`, `)}], ${this.spec.capacity})`;case`allowed`:return`allowed([${this.spec.vars.map(e=>e.toString()).join(`, `)}], [${this.spec.tuples.map(e=>`[${e.join(`, `)}]`).join(`, `)}])`}}};function re(e){if(e===void 0)return`Minimize`;if(typeof e==`string`){let t=e.toLowerCase();if(t===`maximize`)return`Maximize`;if(t===`minimize`)return`Minimize`}throw Error(`Invalid optimization sense "${String(e)}": expected "Maximize", "Minimize", "maximize", or "minimize".`)}var T=Symbol.for(`washi.solverRegistry`),E=globalThis;E[T]||(E[T]=new Map);var ie=E[T];function ae(e,t){ie.set(e.toLowerCase(),t)}var oe=typeof document<`u`?document.currentScript?.src:null,se=oe?new URL(`.`,oe).href:null;function D(e){if(!se)throw Error(`[WaSHI] Load the browser IIFE using an external script src, or use the browser ESM build.`);return new URL(e,se).href}function O(){return D(`pumpkin.wasm`)}function ce(){function e(e){let t,n;try{let r=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),i=g,a=_.check_json(r,i);return t=a[0],n=a[1],o(a[0],a[1])}finally{_.__wbindgen_free(t,n,1)}}function t(e,t){let n,r;try{let i=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),s=g,c=_.check_with_callback(i,s,u(t)?0:a(t));return n=c[0],r=c[1],o(c[0],c[1])}finally{_.__wbindgen_free(n,r,1)}}function n(e){let t,n;try{let r=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),i=g,a=_.solve_json(r,i);return t=a[0],n=a[1],o(a[0],a[1])}finally{_.__wbindgen_free(t,n,1)}}function r(e,t,n){let r,i;try{let s=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),c=g,l=_.solve_with_callback(s,c,u(t)?0:a(t),u(n)?0:a(n));return r=l[0],i=l[1],o(l[0],l[1])}finally{_.__wbindgen_free(r,i,1)}}function i(){return{__proto__:null,"./pumpkin_bg.js":{__proto__:null,__wbg___wbindgen_boolean_get_4f1baf9a00be3c74:function(e){let t=e,n=typeof t==`boolean`?t:void 0;return u(n)?16777215:+!!n},__wbg___wbindgen_is_undefined_be5b34249ff1fc15:function(e){return e===void 0},__wbg___wbindgen_throw_4c88d8bf264fd984:function(e,t){throw Error(o(e,t))},__wbg_call_40b008ba32f73991:function(){return l(function(e,t){return e.call(t)},arguments)},__wbg_call_a410eb4b59ed5965:function(){return l(function(e,t,n){return e.call(t,n)},arguments)},__wbg_now_e7c6795a7f81e10f:function(e){return e.now()},__wbg_performance_7e4e4494fdc9d07a:function(e){return e.performance},__wbg_static_accessor_GLOBAL_THIS_003ee833af9699fc:function(){let e=typeof globalThis>`u`?void 0:globalThis;return u(e)?0:a(e)},__wbg_static_accessor_GLOBAL_e4293fb22cbe77da:function(){let e=typeof globalThis>`u`?void 0:globalThis;return u(e)?0:a(e)},__wbg_static_accessor_SELF_53bb20457401453d:function(){let e=typeof self>`u`?void 0:self;return u(e)?0:a(e)},__wbg_static_accessor_WINDOW_b5e0810bfecb7feb:function(){let e=typeof window>`u`?void 0:window;return u(e)?0:a(e)},__wbindgen_generic_0000000000000001:function(e,t){return o(e,t)},__wbindgen_init_externref_table:function(){let e=_.__wbindgen_externrefs;e.set(0,void 0),e.set(1024,void 0),e.set(1025,null),e.set(1026,!0),e.set(1027,!1)}}}}function a(e){let t=_.__externref_table_alloc();return _.__wbindgen_externrefs.set(t,e),t}function o(e,t){return e>>>=0,m(c().subarray(e,e+t))}let s=null;function c(){return(s===null||s.byteLength===0)&&(s=new Uint8Array(_.memory.buffer)),s}function l(e,t){try{return e.apply(this,t)}catch(e){let t=a(e);_.__wbindgen_exn_store(t)}}function u(e){return e==null}function d(e,t,n){if(n===void 0){let n=h.encode(e),r=t(n.length,1)>>>0;return c().subarray(r,r+n.length).set(n),g=n.length,r}let r=e.length,i=t(r,1)>>>0,a=c(),o=0;for(;o<r;o++){let t=e.charCodeAt(o);if(t>127)break;a[i+o]=t}if(o!==r){o!==0&&(e=e.slice(o)),i=n(i,r,r=o+e.length*3,1)>>>0;let t=c().subarray(i+o,i+r),a=h.encodeInto(e,t);o+=a.written,i=n(i,r,o,1)>>>0}return g=o,i}let f=new TextDecoder(`utf-8`,{ignoreBOM:!0});f.decode();let p=0;function m(e){return p+=e.length,p>=2146435072&&(f=new TextDecoder(`utf-8`,{ignoreBOM:!0}),f.decode(),p=e.length),f.decode(e)}let h=new TextEncoder;`encodeInto`in h||(h.encodeInto=function(e,t){let n=h.encode(e);return t.set(n),{read:e.length,written:n.length}});let g=0,_;function v(e,t){if(_=e.exports,s=null,!_||!(_.memory instanceof WebAssembly.Memory)||typeof _.__wbindgen_start!=`function`||typeof _.__wbindgen_malloc!=`function`||typeof _.__wbindgen_free!=`function`||typeof _.check_json!=`function`||typeof _.check_with_callback!=`function`||typeof _.solve_json!=`function`||typeof _.solve_with_callback!=`function`)throw Error(`[WaSHI] Invalid Pumpkin WebAssembly module: missing expected solver exports.`);return _.__wbindgen_start(),_}async function y(e,t){if(typeof Response==`function`&&e instanceof Response){if(!e.ok)throw Error(`failed to fetch Wasm: ${e.status} ${e.statusText} fetching '${e.url}'`);if(typeof WebAssembly.instantiateStreaming==`function`)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if(n(e.type)&&e.headers.get(`Content-Type`)!==`application/wasm`)console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",t);else throw t}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}{let n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}function n(e){switch(e){case`basic`:case`cors`:case`default`:return!0}return!1}}let b;async function x(e){return _===void 0?(b===void 0&&(b=ee(e),b.catch(()=>{b=void 0})),b):_}async function ee(e){e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn(`using deprecated parameters for the initialization function; pass a single object instead`));let t=i();(typeof e==`string`||typeof Request==`function`&&e instanceof Request||typeof URL==`function`&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:r}=await y(await e,t);return v(n,r)}return{check_json:e,check_with_callback:t,solve_json:n,solve_with_callback:r,__wbg_init:x}}async function le(e){let t=ce();return await t.__wbg_init({module_or_path:e}),{check_json:t.check_json,check_with_callback:t.check_with_callback,solve_json:t.solve_json,solve_with_callback:t.solve_with_callback}}var ue=r({readBundledPumpkinWasmBytes:()=>fe,readPumpkinWasmFileUrl:()=>de});async function de(){throw Error(`This distribution is for browsers. Use the npm entry in Node.js.`)}async function fe(){throw Error(`This distribution is for browsers. Use the npm entry in Node.js.`)}var k=n((()=>{})),pe=4,A=null,j=new Map,M=new Set,N=0,me=null;function he(e){me=e}function ge(){return!1}function P(e){return e.byteLength>=8&&e[0]===0&&e[1]===97&&e[2]===115&&e[3]===109}function _e(e){if(e!==null&&typeof e!=`string`)throw Error(`Invalid pumpkin.wasm URL: expected string or null, got ${typeof e}.`);if(e===``)throw Error(`Invalid pumpkin.wasm URL: expected non-empty string or null (received empty string "").`);e!==A&&(A=e,I())}function F(){return A}function ve(){return A??O()}function I(){N++,j.clear(),M.clear(),me?.()}function ye(e){let t=xe(e)??`__bundled__`;return M.has(t)}function L(){if(typeof Worker>`u`||typeof window>`u`||typeof Worker.prototype.unref==`function`)return!1;let e=typeof window.origin==`string`?window.origin:(()=>{try{return window.location?.origin}catch{return}})();return!(!e||e===`null`||e.startsWith(`file:`))}async function be(e){if(typeof fetch!=`function`)throw Error(`[WaSHI] Global fetch() is unavailable to load Pumpkin WebAssembly from "${e}"; no CDN fallback is attempted.`);let t;try{t=await fetch(e)}catch(t){throw Error(`[WaSHI] Failed to fetch pumpkin.wasm from "${e}" (no CDN fallback is attempted): ${t instanceof Error?t.message:String(t)}. Ensure pumpkin.wasm is hosted cleanly or call setPumpkinWasmUrl(url).`)}if(!t.ok)throw Error(`[WaSHI] Failed to fetch pumpkin.wasm from "${e}": HTTP ${t.status} ${t.statusText}; no CDN fallback is attempted.`);let n=t.headers?.get(`content-type`)?.toLowerCase()??``;if(n.includes(`text/html`))throw Error(`[WaSHI] Invalid response while loading pumpkin.wasm from "${e}": received HTML ("${n}") instead of a WebAssembly binary; no CDN fallback is attempted.`);let r=await t.arrayBuffer(),i=new Uint8Array(r);if(!P(i))throw Error(`[WaSHI] Invalid WebAssembly binary loaded from "${e}": expected \\0asm magic header; no CDN fallback is attempted.`);return i}function xe(e){if(e===void 0)return A;if(e!==null&&typeof e!=`string`)throw Error(`Invalid pumpkin.wasm URL: expected string or null, got ${typeof e}.`);if(e===``)throw Error(`Invalid pumpkin.wasm URL: expected non-empty string or null (received empty string "").`);return e}async function Se(e){if(e!==null){if(ge()&&e.startsWith(`file://`)){let{readPumpkinWasmFileUrl:t}=await Promise.resolve().then(()=>(k(),ue)),n=await t(new URL(e));if(!P(n))throw Error(`[WaSHI] Invalid WebAssembly binary at "${e}": expected \\0asm magic header.`);return n}return be(e)}if(ge()&&typeof window>`u`){let{readBundledPumpkinWasmBytes:e}=await Promise.resolve().then(()=>(k(),ue)),t=await e();if(!P(t))throw Error(`[WaSHI] Bundled pumpkin.wasm on disk has an invalid WebAssembly magic header.`);return t}return be(O())}async function R(e){let t=xe(e),n=t??`__bundled__`,r=j.get(n);if(r)return j.delete(n),j.set(n,r),r;let i=N,a=null;for(a=(async()=>{try{let e=await le(await Se(t));return N===i&&j.get(n)===a&&M.add(n),e}catch(e){throw N===i&&(M.delete(n),j.get(n)===a&&j.delete(n)),t!==null&&e instanceof Error&&e.message.includes(`Invalid Pumpkin WebAssembly module`)?Error(`[WaSHI] Invalid Pumpkin WebAssembly module loaded from "${t}" (${e.message}); no CDN fallback is attempted.`):e}})();j.size>=pe;){let e=j.keys().next().value;if(e===void 0)break;j.delete(e),M.delete(e)}return j.set(n,a),a}function z(){let e=D(`pumpkin-worker.js`),t=typeof window.origin==`string`?window.origin:window.location?.origin;if(new URL(e).origin===t)return new Worker(e,{type:`module`});let n=URL.createObjectURL(new Blob([`import `+JSON.stringify(e)+`;`],{type:`text/javascript`}));try{let e=new Worker(n,{type:`module`}),t=()=>URL.revokeObjectURL(n);return e.addEventListener(`message`,t,{once:!0}),e.addEventListener(`error`,t,{once:!0}),e}catch(e){throw URL.revokeObjectURL(n),e}}function B(e){if(e===``)throw Error(`Invalid pumpkin.wasm URL: expected non-empty string or null (received empty string "").`);if(e!=null&&typeof e!=`string`)throw Error(`Invalid pumpkin.wasm URL: expected string or null, got ${typeof e}.`)}function V(e){return{status:`Unknown`,values:[],boolValues:[],runTime:Math.max((performance.now()-e)/1e3,1e-6)}}function H(e,t){let n=Math.max((performance.now()-e)/1e3,1e-6);return t?{status:`Feasible`,terminationStatus:`Interrupted`,objectiveValue:t.objectiveValue,values:t.values,boolValues:t.boolValues,runTime:n}:{status:`Unknown`,terminationStatus:`Interrupted`,objectiveValue:null,values:[],boolValues:[],runTime:n}}function Ce(e={}){let t=e.workerFactory??z,n=null,r=1,i=null,a=[],o=new Set,s=!1;B(e.wasmUrl);let c=e=>(B(e),typeof e==`string`?e:`__bundled__`),l=e=>{let t=c(e);for(o.delete(t),o.add(t);o.size>4;){let e=o.keys().next().value;if(e===void 0)break;o.delete(e)}},u=()=>{o.clear(),n&&=(n.onmessage=null,n.onerror=null,n.onmessageerror=null,n.terminate(),null)},d=e=>{i===e&&(i=null),e.cleanupAbort?.()},f=(e,t)=>{d(e),e.resolve(t),v()},p=(e,t)=>{d(e),e.resolve(t),v()},m=(e,t)=>{d(e),e.reject(t),v()},h=e=>{e.type===`check`?f(e,V(e.startTimeMs)):p(e,H(e.startTimeMs,e.lastIncumbent))},g=(e,t,n)=>{if(typeof e!=`string`)throw Error(`Pumpkin worker response is missing canonical responseJson string.`);let r=JSON.parse(e);if(!r)throw Error(`Pumpkin worker returned an empty success payload.`);if(r.error)throw Error(r.error);return{...r,runTime:typeof t==`number`?t:Math.max((performance.now()-n)/1e3,1e-6)}},_=()=>{if(n)return n;let e=t();return e.onmessage=t=>{let r=t.data,a=i;if(n===e&&r&&a&&r.id===a.id){if(r.type===`SOLVE_PROGRESS`){if(a.type!==`solve`)return;try{if(typeof r.payloadJson!=`string`)throw Error(`Pumpkin worker SOLVE_PROGRESS is missing canonical payloadJson string.`);let t=JSON.parse(r.payloadJson);if(!t)throw Error(`Pumpkin worker SOLVE_PROGRESS returned an empty incumbent payload.`);if(a.lastIncumbent=t,a.onProgress){let e=typeof r.elapsedTime==`number`?r.elapsedTime:Math.max((performance.now()-a.startTimeMs)/1e3,1e-6);a.onProgress({elapsedTime:e,elapsedSeconds:e,objectiveValue:t.objectiveValue})}if(n!==e||i!==a)return;a.signal?.aborted&&(u(),h(a))}catch(t){n===e&&i===a&&(u(),m(a,t))}return}if(r.type===`CHECK_SUCCESS`){if(a.type!==`check`){u(),m(a,Error(`Received "CHECK_SUCCESS" for a solve task.`));return}try{let e=g(r.responseJson,r.runTime,a.startTimeMs);l(a.wasmUrl),f(a,e)}catch(t){n===e&&i===a&&(u(),m(a,t))}return}if(r.type===`SOLVE_SUCCESS`){if(a.type!==`solve`){u(),m(a,Error(`Received "SOLVE_SUCCESS" for a check task.`));return}try{let e=g(r.responseJson,r.runTime,a.startTimeMs);l(a.wasmUrl),p(a,e)}catch(t){n===e&&i===a&&(u(),m(a,t))}return}if(r.type===`SOLVER_ERROR`){let e=typeof r.error==`string`?r.error:`Pumpkin worker execution failed.`;m(a,Error(e))}}},e.onerror=t=>{if(n!==e)return;let r=i;if(u(),r){let e=t?.message||`Pumpkin Web Worker encountered an unexpected error.`;m(r,Error(e))}},e.onmessageerror=()=>{if(n!==e)return;let t=i;u(),t&&m(t,Error(`Failed to deserialize message from Pumpkin Web Worker.`))},n=e,e},v=()=>{if(!(i||s))for(;a.length>0;){let e=a.shift();if(e.signal?.aborted){e.type===`check`?e.resolve(V(e.startTimeMs)):e.resolve(H(e.startTimeMs,e.lastIncumbent));continue}if(i=e,e.startTimeMs=performance.now(),e.signal){let t=()=>{i===e&&(u(),h(e))};e.signal.addEventListener(`abort`,t,{once:!0}),e.cleanupAbort=()=>e.signal?.removeEventListener(`abort`,t)}try{_().postMessage({id:e.id,type:e.type,requestJson:e.requestJson,wasmUrl:e.wasmUrl})}catch(t){i===e&&(u(),m(e,t))}return}},y=t=>{let n=t===void 0?e.wasmUrl===void 0?F():e.wasmUrl:t;return B(n),n??null},b=e=>new Promise((t,n)=>{a.push(e(t,n)),v()});return{check(e,t){if(s)return Promise.reject(Error(`[WaSHI] Pumpkin worker client has been disposed.`));if(t?.signal?.aborted)return Promise.resolve(V(performance.now()));let n=y(e.wasmUrl);return b((i,a)=>({id:r++,type:`check`,requestJson:e.requestJson,wasmUrl:n,signal:t?.signal,startTimeMs:performance.now(),lastIncumbent:null,resolve:i,reject:a}))},solve(e,t){if(s)return Promise.reject(Error(`[WaSHI] Pumpkin worker client has been disposed.`));if(t?.signal?.aborted)return Promise.resolve(H(performance.now(),null));let n=y(e.wasmUrl);return b((i,a)=>({id:r++,type:`solve`,requestJson:e.requestJson,wasmUrl:n,signal:t?.signal,onProgress:t?.onProgress,startTimeMs:performance.now(),lastIncumbent:null,resolve:i,reject:a}))},isWarmed(e){return!s&&n!==null&&o.has(c(y(e)))},dispose(){for(s=!0,u();a.length>0;){let e=a.shift();e.cleanupAbort?.(),e.reject(Error(`[WaSHI] Pumpkin worker client disposed.`))}if(i){let e=i;i=null,e.cleanupAbort?.(),e.reject(Error(`[WaSHI] Pumpkin worker client disposed.`))}}}}var U=null;function W(){return U||(U=Ce(),he(()=>{U&&=(U.dispose(),null)})),U}function we(){U&&=(U.dispose(),null)}function Te(e={}){return B(e.wasmUrl),e.useWorker??L()?U!==null&&U.isWarmed(e.wasmUrl):ye(e.wasmUrl)}async function Ee(e={}){let{signal:t}=e;if(B(e.wasmUrl),t?.aborted)return{cached:!1};if(Te(e))return{cached:!0};let n=!!(e.useWorker??L()),r=e.wasmUrl===void 0?F():e.wasmUrl;return n?(await W().check({requestJson:JSON.stringify({vars:[],boolVars:[],constraints:[],logicalConstraints:[],auxPropagators:[],timeLimitMs:null}),wasmUrl:r},{signal:t}),{cached:!1}):t?(await new Promise((e,n)=>{let i=!1,a=()=>{i||(i=!0,e())};t.addEventListener(`abort`,a,{once:!0}),R(r).then(()=>{t.removeEventListener(`abort`,a),i||(i=!0,e())},e=>{t.removeEventListener(`abort`,a),i||(i=!0,n(e))})}),{cached:!1}):(await R(r),{cached:!1})}var G=1073741823,K=2147483646,q=1e-6;function J(e){return Object.is(e,-0)||e===0?0:e}function Y(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function X(e,t){if(typeof e!=`number`||Number.isNaN(e))throw Error(`PumpkinSolver encountered non-finite numeric value in ${t}.`);if(!Number.isFinite(e))throw Error(`PumpkinSolver only supports bounded finite integers (${t}: got ${e}).`);if(!Number.isInteger(e))throw Error(`PumpkinSolver only supports integer values (${t}: got ${e}).`);let n=J(e);if(n<-1073741823||n>G)throw Error(`Value out of Pumpkin safe 32-bit integer range [-${G}, ${G}] (${t}: got ${n}).`);return n}function De(e){if(e===void 0||e===1/0)return null;if(typeof e!=`number`||Number.isNaN(e)||e<0||!Number.isFinite(e))throw Error(`Invalid timeLimit (${String(e)}): expected a finite non-negative number of seconds.`);if(e===0)return 0;let t=Math.round(e*1e3);if(t>2**53-1)throw Error(`timeLimit (${e}s) exceeds safe millisecond range.`);return Math.max(1,t)}function Z(e){return e instanceof a||typeof e==`object`&&!!e&&`quadTerms`in e}function Oe(e,t,n){if(e.initialValue===void 0)return;if(typeof e.initialValue!=`number`||!Number.isFinite(e.initialValue))throw Error(`Variable "${e.name}" has invalid initialValue: ${String(e.initialValue)} (initialValue must be a finite number).`);if(e.initialValue<t-q||e.initialValue>n+q)throw Error(`Variable "${e.name}" has initialValue (${e.initialValue}) outside its bounds [${t}, ${n}] (tolerance ${q}).`);let r=J(Math.round(e.initialValue));if(Math.abs(e.initialValue-r)>q||r<t||r>n)throw Error(`Variable "${e.name}" of type "${e.type}" has non-integral or out-of-domain initialValue: ${e.initialValue} (must be within ${q} of an integer in [${t}, ${n}]).`);return X(r,`initialValue of variable "${e.name}"`)}function ke(e){let t=[],n=new Map,r=!1;for(let i=0;i<e.length;i++){let a=e[i],o=String(a.type).toLowerCase();if(o===`continuous`||o===`cont`)throw Error(`PumpkinSolver does not support Continuous variable "${a.name}". Use an Integer or Binary variable, or select a MIP/SMT solver.`);if(n.set(a,i),o===`binary`||o===`bin`){if(typeof a.lb!=`number`||Number.isNaN(a.lb)||typeof a.ub!=`number`||Number.isNaN(a.ub))throw Error(`PumpkinSolver encountered non-finite numeric value in bounds of variable "${a.name}".`);if(a.lb===1/0||a.ub===-1/0||a.lb>a.ub)throw Error(`Variable "${a.name}" has invalid bounds lb (${a.lb}) > ub (${a.ub}).`);if(Number.isFinite(a.lb)&&!Number.isInteger(a.lb)||Number.isFinite(a.ub)&&!Number.isInteger(a.ub))throw Error(`PumpkinSolver only supports integer values (bounds of binary variable "${a.name}").`);let e=a.lb===-1/0?0:Math.max(0,J(a.lb)),n=a.ub===1/0?1:Math.min(1,J(a.ub)),i=Oe(a,e,n);e>n?(r=!0,t.push({name:a.name,lb:0,ub:1})):t.push(i===void 0?{name:a.name,lb:e,ub:n}:{name:a.name,lb:e,ub:n,initialValue:i});continue}let s=X(a.lb,`lower bound of variable "${a.name}"`),c=X(a.ub,`upper bound of variable "${a.name}"`);if(s>c)throw Error(`Variable "${a.name}" has invalid bounds lb (${s}) > ub (${c}).`);let l=Oe(a,s,c);t.push(l===void 0?{name:a.name,lb:s,ub:c}:{name:a.name,lb:s,ub:c,initialValue:l})}return{vars:t,varIndexMap:n,hasEmptyDomain:r}}function Ae(e,t,n){let r=0;function i(e,n,i){let a=X(e,`internal ${i} lb`),o=X(n,`internal ${i} ub`),s=t.length;return t.push({name:`__pumpkin_${i}_${++r}`,lb:a,ub:o,internal:!0}),s}function a(n,r,i){let a=new Map;for(let[t,r]of n.entries()){let n=e.get(t);if(n===void 0)throw Error(`Variable "${t.name}" in ${i} is not registered in the model.`);if(typeof r!=`number`||!Number.isFinite(r))throw Error(`Invalid non-finite coefficient for "${t.name}" in ${i}.`);if(!Number.isInteger(r))throw Error(`PumpkinSolver only supports integer coefficients (variable "${t.name}" in ${i} has ${r}).`);let o=(a.get(n)??0)+J(r);if(!Number.isSafeInteger(o))throw Error(`Coefficient sum overflow for "${t.name}" in ${i}.`);a.set(n,o)}for(let e of r){let t=(a.get(e.varIndex)??0)+J(e.coeff);if(!Number.isSafeInteger(t))throw Error(`Coefficient sum overflow in ${i}.`);a.set(e.varIndex,t)}let o=[],s=0;for(let[e,n]of a.entries()){let r=J(n);if(r===0)continue;let a=t[e];X(r,`coefficient of "${a.name}" in ${i}`);let c=r*a.lb,l=r*a.ub;if(X(c,`scaled lower bound of "${a.name}" in ${i}`),X(l,`scaled upper bound of "${a.name}" in ${i}`),s+=Math.max(Math.abs(c),Math.abs(l)),s>K)throw Error(`Linear expression magnitude in ${i} exceeds Pumpkin safe 32-bit propagator overflow limit.`);o.push({varIndex:e,coeff:r})}return{terms:o,sumMaxAbs:s}}function o(e,n,r){let i=n,a=n;for(let n of e){let e=t[n.varIndex],r=n.coeff*e.lb,o=n.coeff*e.ub;i+=Math.min(r,o),a+=Math.max(r,o)}return{lb:X(J(i),`lower bound of ${r}`),ub:X(J(a),`upper bound of ${r}`)}}function s(e,r,a){switch(e.kind){case`abs`:{let o=l(e.arg,r,`${a} abs()`),s=t[o],c=i(s.lb<=0&&s.ub>=0?0:Math.min(Math.abs(s.lb),Math.abs(s.ub)),Math.max(Math.abs(s.lb),Math.abs(s.ub)),`abs`);return n.push({kind:`abs`,argVar:o,outVar:c,owner:r}),c}case`max`:{let o=e.args.map((e,t)=>l(e,r,`${a} max()[${t}]`)),s=i(Math.max(...o.map(e=>t[e].lb)),Math.max(...o.map(e=>t[e].ub)),`max`);return n.push({kind:`max`,argVars:o,outVar:s,owner:r}),s}case`min`:{let o=e.args.map((e,t)=>l(e,r,`${a} min()[${t}]`)),s=i(Math.min(...o.map(e=>t[e].lb)),Math.min(...o.map(e=>t[e].ub)),`min`);return n.push({kind:`min`,argVars:o,outVar:s,owner:r}),s}case`at`:{let o=l(e.index,r,`${a} at() index`),s=e.array.map((e,t)=>l(e,r,`${a} at()[${t}]`)),c=i(Math.min(...s.map(e=>t[e].lb)),Math.max(...s.map(e=>t[e].ub)),`elem`);return n.push({kind:`element`,indexVar:o,arrayVars:s,outVar:c,owner:r}),c}}}function c(e,t,n,r=!1){if(typeof e.constant!=`number`||!Number.isFinite(e.constant))throw Error(`Invalid non-finite constant in ${n}.`);let i;if(r)i=J(e.constant);else{if(!Number.isInteger(e.constant))throw Error(`PumpkinSolver only supports integer constants (${n}: got ${e.constant}).`);i=X(J(e.constant),`constant of ${n}`)}let o=[];if(Array.isArray(e.nonlinearTerms))for(let r of e.nonlinearTerms){if(r.coeff===0)continue;if(typeof r.coeff!=`number`||!Number.isFinite(r.coeff)||!Number.isInteger(r.coeff))throw Error(`PumpkinSolver only supports safe integer coefficients in ${n} (got ${r.coeff}).`);let e=X(J(r.coeff),`nonlinear coefficient in ${n}`),i=s(r.atom,t,n);o.push({varIndex:i,coeff:e})}let{terms:c,sumMaxAbs:l}=a(e.terms,o,n);return{terms:c,constant:i,sumMaxAbs:l}}function l(e,r,a){let{terms:s,constant:l}=c(e,r,a);if(s.length===1&&s[0].coeff===1&&l===0)return s[0].varIndex;let{lb:u,ub:d}=o(s,l,a),f=i(u,d,`expr`);if(s.length>0){let e=[...s,{varIndex:f,coeff:-1}],i=X(J(-l),`linearEq RHS in ${a}`),o=e.reduce((e,n)=>{let r=t[n.varIndex];return e+Math.max(Math.abs(n.coeff*r.lb),Math.abs(n.coeff*r.ub))},0);if(Math.abs(i)+o>K)throw Error(`Linear expression magnitude in ${a} exceeds Pumpkin safe 32-bit propagator overflow limit.`);n.push({kind:`linearEq`,terms:e,rhs:i,owner:r})}return f}function u(e,t,n,r){if(typeof t!=`number`||!Number.isFinite(t))throw Error(`Invalid non-finite RHS in ${r}.`);if(!Number.isInteger(t))throw Error(`PumpkinSolver only supports integer RHS (${r}: got ${t}).`);let{terms:i,constant:a,sumMaxAbs:o}=c(e,n,r),s=X(J(t-a),`RHS of ${r}`);if(Math.abs(s)+o>K)throw Error(`Linear expression magnitude in ${r} exceeds Pumpkin safe 32-bit propagator overflow limit.`);return{terms:i,rhs:s}}return{lowerLinExpr:c,materializeExprToVarIndex:l,serializeConstraintSide:u}}function Q(e,t,n,r,i){if(r.has(e)||e instanceof te||typeof e==`object`&&e&&`name`in e&&`id`in e&&!(`op`in e)&&!(`lhs`in e)&&!(`spec`in e)){let t=e,n=r.get(t);if(n===void 0)throw Error(`Boolean variable "${t.name}" in ${i} is not registered in the model.`);return{kind:`boolVar`,index:n}}if(e instanceof b||`lhs`in e&&`sense`in e&&`rhs`in e){let r=e;if(Z(r.lhs))throw Error(`PumpkinSolver does not support quadratic constraints inside ${i}.`);let{terms:a,rhs:o}=t.serializeConstraintSide(r.lhs,r.rhs,n,i);return{kind:`linear`,terms:a,sense:r.sense,rhs:o}}if(e instanceof ne||typeof e==`object`&&e&&`spec`in e&&typeof e.spec==`object`){let r=e.spec;switch(r.kind){case`distinct`:return{kind:`allDifferent`,vars:r.args.map((e,r)=>t.materializeExprToVarIndex(e,n,`${i} distinct()[${r}]`))};case`disjoint`:return{kind:`disjunctive`,tasks:r.tasks.map((e,r)=>({startVar:t.materializeExprToVarIndex(e.start,n,`${i} disjoint()[${r}]`),duration:X(e.duration,`duration of ${i} disjoint()[${r}]`)}))};case`cumulative`:return{kind:`cumulative`,tasks:r.tasks.map((e,r)=>({startVar:t.materializeExprToVarIndex(e.start,n,`${i} cumulative()[${r}]`),duration:X(e.duration,`duration of ${i} cumulative()[${r}]`),demand:X(e.demand,`demand of ${i} cumulative()[${r}]`)})),capacity:X(r.capacity,`capacity of ${i} cumulative()`)};case`allowed`:return{kind:`table`,vars:r.vars.map((e,r)=>t.materializeExprToVarIndex(e,n,`${i} allowed() vars[${r}]`)),tuples:r.tuples.map((e,t)=>e.map((e,n)=>X(e,`tuple[${t}][${n}] in ${i}`)))}}}if(e instanceof w||`op`in e&&`children`in e){let a=e;switch(a.op){case`and`:return{kind:`and`,children:a.children.map(e=>Q(e,t,n,r,i))};case`or`:return{kind:`or`,children:a.children.map(e=>Q(e,t,n,r,i))};case`not`:if(a.children.length!==1)throw Error(`Invalid 'not' operator arity in ${i}.`);return{kind:`not`,child:Q(a.children[0],t,n,r,i)};case`implies`:if(a.children.length!==2)throw Error(`Invalid 'implies' operator arity in ${i}.`);return{kind:`implies`,left:Q(a.children[0],t,n,r,i),right:Q(a.children[1],t,n,r,i)};case`xor`:return{kind:`xor`,children:a.children.map(e=>Q(e,t,n,r,i))};default:throw Error(`Unsupported logical operator "${String(a.op)}" in ${i}.`)}}throw Error(`Unsupported logical constraint node in ${i}.`)}function je(e){let{vars:t,varIndexMap:n,hasEmptyDomain:r}=ke(e.variables),i=[],a=Ae(n,t,i),o=e.boolVars??[],s=new Map,c=[];for(let e=0;e<o.length;e++)s.set(o[e],e),c.push(o[e].name);let l=[];for(let t=0;t<e.constraints.length;t++){let r=e.constraints[t],i=`constraint "${r.name}"`,o={kind:`constraint`,index:t};if(r._indicatorMeta){let e=r._indicatorMeta,t=n.get(e.binVar);if(t===void 0)throw Error(`Indicator binary variable "${e.binVar.name}" in ${i} is not registered in the model.`);let{terms:s,rhs:c}=a.serializeConstraintSide(e.targetLhs,e.targetRhs,o,i);l.push({name:r.name,terms:s,sense:e.targetSense,rhs:c,indicator:{binVarIndex:t,activeValue:e.activeValue}});continue}if(Z(r.lhs))throw Error(`PumpkinSolver does not support quadratic constraints (${i}).`);let{terms:s,rhs:c}=a.serializeConstraintSide(r.lhs,r.rhs,o,i);l.push({name:r.name,terms:s,sense:r.sense,rhs:c})}let u=[],d=e.logicalConstraints??[];for(let e=0;e<d.length;e++){let t=d[e],n=`logical constraint "${t.name}"`,r={kind:`logic`,index:e},i=Q(t.expr,a,r,s,n);u.push({name:t.name,expr:i})}return{vars:t,boolVars:c,constraints:l,logicalConstraints:u,auxPropagators:i,varIndexMap:n,lowerer:a,hasEmptyDomain:r}}function Me(e,t,n){let r={};if(e)for(let[t,n]of e)Y(r,t,J(n));let i;if(t&&t.length>0){i={};for(let[e,a]of t)Y(i,e,a),n&&Y(r,e,+!!a)}return{values:r,...i===void 0?{}:{boolValues:i}}}function Ne(e,t){let n={};if(e)for(let[t,r]of e)Y(n,t,J(r));if(t)for(let[e,r]of t)Y(n,e,r);return n}var Pe=new Set([`presolve`,`relativeGap`,`absoluteGap`,`threads`,`verbose`,`outputFlag`]),Fe=new Set([`timeLimit`,`wasmUrl`,`useWorker`,`signal`,`onProgress`,`relax`]);function Ie(e={}){if(e.relax!==void 0){if(typeof e.relax!=`boolean`)throw Error(`Invalid Pumpkin option "relax": expected boolean, got ${typeof e.relax}.`);if(e.relax===!0)throw Error(`PumpkinSolver does not support LP relaxation (relax: true). Use a simplex/IPM solver such as HiGHS or GLPK.`)}for(let t of Pe)if(e[t]!==void 0)throw Error(`PumpkinSolver does not support option "${t}".`);for(let[t,n]of Object.entries(e))if(n!==void 0&&!Fe.has(t))throw Error(`PumpkinSolver does not support option "${t}".`);if(e.useWorker!==void 0&&typeof e.useWorker!=`boolean`)throw Error(`Invalid Pumpkin option "useWorker": expected boolean, got ${typeof e.useWorker}.`);if(e.onProgress!==void 0&&typeof e.onProgress!=`function`)throw Error(`Invalid Pumpkin option "onProgress": expected function, got ${typeof e.onProgress}.`)}function Le(e){if(e.wasmUrl!==void 0&&e.wasmUrl!==null&&typeof e.wasmUrl!=`string`)throw Error(`Invalid pumpkin.wasm URL: expected string or null, got ${typeof e.wasmUrl}.`);if(e.wasmUrl===``)throw Error(`Invalid pumpkin.wasm URL: expected non-empty string or null (received empty string "").`);return e.wasmUrl===void 0?F():e.wasmUrl}var Re=class e{static capabilities={supportsMIP:!0,supportsQP:!1,supportsQCQP:!1,supportsSMT:!1,supportsLogicalConstraints:!0,supportsUnsatCore:!0,supportsWarmStart:!0};name=`pumpkin`;options;capabilities=e.capabilities;constructor(e={}){this.options=e}async check(e,t={}){let n={...this.options,...t};Ie(n);let r=Le(n),i=De(n.timeLimit),a=je(e);if(n.signal?.aborted)return{status:`Unknown`,values:{},runTime:0};if(a.hasEmptyDomain)return{status:`Unsat`,values:{},unsatCore:[],conflicts:[],runTime:1e-6};let o=JSON.stringify({vars:a.vars,boolVars:a.boolVars,constraints:a.constraints,logicalConstraints:a.logicalConstraints,auxPropagators:a.auxPropagators,timeLimitMs:i}),s=n.useWorker??L(),c;if(s)c=await W().check({requestJson:o,wasmUrl:r},{signal:n.signal});else{let e=await R(r);if(n.signal?.aborted)return{status:`Unknown`,values:{},runTime:0};let t=performance.now(),i=e.check_with_callback(o,()=>!!n.signal?.aborted),a=Math.max((performance.now()-t)/1e3,1e-6);if(c=JSON.parse(i),c.runTime=a,c.error)throw Error(c.error)}let l=c.runTime??0;if(c.status===`Sat`)return{status:`Sat`,values:Ne(c.values,c.boolValues),runTime:l};if(c.status===`Unsat`){let e=c.unsatCore?[...c.unsatCore]:[];return{status:`Unsat`,values:{},unsatCore:e,conflicts:e,runTime:l}}return{status:`Unknown`,values:{},runTime:l}}async solve(e,t={}){let n={...this.options,...t};Ie(n);let r=Le(n),i=De(n.timeLimit),a=re(e.sense),o=je(e);if(Z(e.objective))throw Error(`PumpkinSolver does not support quadratic objective expressions (QuadExpr). Use a QP solver such as HiGHS.`);let s=e.objective;if(typeof s.constant!=`number`||!Number.isFinite(s.constant))throw Error(`Invalid non-finite objective constant.`);let c=J(s.constant),{terms:l,sumMaxAbs:u}=o.lowerer.lowerLinExpr(s,{kind:`objective`},`objective expression`,!0);if(u>G)throw Error(`Objective expression magnitude (${u}) exceeds Pumpkin safe 32-bit integer range [-${G}, ${G}].`);if(n.signal?.aborted)return{status:`Unknown`,terminationStatus:`Interrupted`,hasPrimalSolution:!1,objectiveValue:null,values:{},runTime:0};if(o.hasEmptyDomain)return{status:`Infeasible`,terminationStatus:`Infeasible`,hasPrimalSolution:!1,objectiveValue:null,values:{},runTime:1e-6};let d=JSON.stringify({vars:o.vars,boolVars:o.boolVars,constraints:o.constraints,logicalConstraints:o.logicalConstraints,auxPropagators:o.auxPropagators,sense:a,objectiveTerms:l,objectiveConstant:c,timeLimitMs:i}),f=n.useWorker??L(),p=n.onProgress,m=0,h=p?e=>{m++,p(e)}:void 0,g;if(f)g=await W().solve({requestJson:d,wasmUrl:r},{signal:n.signal,onProgress:h});else{let e=await R(r);if(n.signal?.aborted)return{status:`Unknown`,terminationStatus:`Interrupted`,hasPrimalSolution:!1,objectiveValue:null,values:{},runTime:0};let t=performance.now(),i=null,a=n.signal,o=h?e=>{try{let n=JSON.parse(e),r=Math.max((performance.now()-t)/1e3,1e-6);return h({elapsedTime:r,elapsedSeconds:r,objectiveValue:n.objectiveValue}),!!a?.aborted}catch(e){return i=e,!0}}:null,s=a?()=>!!a.aborted:null,c=e.solve_with_callback(d,o,s);if(i!==null)throw i;let l=Math.max((performance.now()-t)/1e3,1e-6);if(g=JSON.parse(c),g.runTime=l,g.error)throw Error(g.error)}let _=g.status===`Optimal`||g.status===`Feasible`,v=typeof g.objectiveValue==`number`?J(g.objectiveValue):null,y=g.runTime??0;_&&m===0&&h&&h({elapsedTime:y,elapsedSeconds:y,...v===null?{}:{objectiveValue:v}});let b=_?Me(g.values,g.boolValues,!0):{values:{}};return{status:g.status,terminationStatus:g.terminationStatus,hasPrimalSolution:_,objectiveValue:v,values:b.values,...b.boolValues===void 0?{}:{boolValues:b.boolValues},runTime:y}}};function $(e){ae(`pumpkin`,t=>new Re(t??e))}return $(),e.PumpkinSolver=Re,e.createPumpkinWorker=z,e.createPumpkinWorkerClient=Ce,e.disposeSharedPumpkinWorkerClient=we,e.getAssetUrl=D,e.getBundledPumpkinWasmUrl=O,e.getPumpkinWasmUrl=F,e.getSharedPumpkinWorkerClient=W,e.isPumpkinRuntimeCached=ye,e.isPumpkinWarmed=Te,e.isValidWasmHeader=P,e.loadPumpkinRuntime=R,e.registerPumpkinSolver=$,e.registerPumpkinWorkerResetHook=he,e.resetPumpkinLoader=I,e.resolvePumpkinWasmUrl=ve,e.setPumpkinWasmUrl=_e,e.shouldUseWorker=L,e.warmupPumpkin=Ee,e})({});
|