@ohtaman/washi 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -34
- package/dist/browser/{__vite-browser-external-rTVKos2U.js → solvers/highs-__vite-browser-external-Dn-83hnF.js} +1 -1
- package/dist/browser/{browser-runtime-AG5QFtKf.js → solvers/highs-browser-runtime-0Bgq5ksG.js} +1 -1
- package/dist/browser/{loader-i3FnqMes.js → solvers/highs-loader-BLY3wzDH.js} +25 -18
- package/dist/browser/{highs-worker.js → solvers/highs-worker.js} +1 -1
- package/dist/browser/solvers/highs.js +1414 -0
- package/dist/browser/washi.js +1090 -1473
- package/dist/browser/washi.min.js +4 -4
- package/dist/lib/solvers/glpk.js +34 -32
- package/dist/lib/{highs-node-runtime.js → solvers/highs-node-runtime.js} +1 -1
- package/dist/lib/solvers/highs.js +410 -0
- package/dist/lib/solvers/lp-writer-CLScMFbS.js +115 -0
- package/dist/lib/solvers/pumpkin-node-runtime.js +1 -1
- package/dist/lib/solvers/pumpkin-worker.js +1 -1
- package/dist/lib/solvers/pumpkin.js +247 -1146
- package/dist/lib/solvers/registry-CrYRRk9q.js +907 -0
- package/dist/lib/solvers/types-BGqPkxwu.js +12 -0
- package/dist/lib/solvers/z3.js +125 -123
- package/dist/lib/washi.js +2426 -1340
- package/dist/types/index.d.ts +1 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modeler/index.d.ts +0 -1
- package/dist/types/modeler/index.d.ts.map +1 -1
- package/dist/types/modeler/model.d.ts +6 -7
- package/dist/types/modeler/model.d.ts.map +1 -1
- package/dist/types/modeler/solvers/index.d.ts +2 -1
- package/dist/types/modeler/solvers/index.d.ts.map +1 -1
- package/dist/types/modeler/solvers/registry.d.ts.map +1 -1
- package/docs/examples/diet-sensitivity.md +33 -14
- package/docs/examples/ecommerce-coupons.md +17 -9
- package/docs/examples/index.md +34 -30
- package/docs/examples/knapsack.md +11 -5
- package/docs/examples/portfolio-qp.md +21 -8
- package/docs/examples/production.md +10 -5
- package/docs/examples/project-scheduling.md +25 -12
- package/docs/examples/shift-scheduling.md +27 -19
- package/docs/examples/smt-security.md +27 -12
- package/docs/examples/transportation.md +23 -13
- package/docs/examples/traveling-salesperson.md +34 -22
- package/docs/examples/unsat-core.md +27 -15
- package/docs/examples/vehicle-routing.md +74 -28
- package/docs/getting-started/ai-agents.md +129 -90
- package/docs/getting-started/coding-agents.md +60 -41
- package/docs/getting-started/cross-origin.md +27 -14
- package/docs/getting-started/index.md +23 -16
- package/docs/getting-started/runtimes.md +70 -40
- package/docs/guide/constraint-programming.md +74 -44
- package/docs/guide/constraints.md +71 -39
- package/docs/guide/decomposition.md +72 -42
- package/docs/guide/expressions.md +79 -48
- package/docs/guide/formulation-tips.md +46 -27
- package/docs/guide/objectives.md +55 -31
- package/docs/guide/unsat-core.md +56 -53
- package/docs/guide/variables.md +61 -28
- package/docs/solvers/custom-solver.md +155 -119
- package/docs/solvers/glpk.md +58 -17
- package/docs/solvers/highs.md +115 -43
- package/docs/solvers/index.md +33 -26
- package/docs/solvers/pumpkin.md +71 -63
- package/docs/solvers/z3.md +63 -25
- package/llms-full.txt +1623 -953
- package/llms.txt +125 -93
- package/package.json +29 -22
- package/skills/washi/SKILL.md +43 -22
- package/README.ja.md +0 -248
- package/README.zh-CN.md +0 -248
- package/dist/browser/solvers/pumpkin.min.js +0 -1
- package/dist/lib/registry-dx7x4e5c.js +0 -1694
- /package/dist/browser/{highs.wasm → solvers/highs.wasm} +0 -0
- /package/dist/browser/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
- /package/dist/lib/{__vite-browser-external-oLchLuMx.js → solvers/__vite-browser-external-oLchLuMx.js} +0 -0
- /package/dist/lib/{highs-assets.js → solvers/highs-assets.js} +0 -0
- /package/dist/lib/{highs-browser-runtime.js → solvers/highs-browser-runtime.js} +0 -0
- /package/dist/lib/{highs-runtime.js → solvers/highs-runtime.js} +0 -0
- /package/dist/lib/{highs-worker-factory.js → solvers/highs-worker-factory.js} +0 -0
- /package/dist/lib/{highs-worker.js → solvers/highs-worker.js} +0 -0
- /package/dist/lib/{highs.wasm → solvers/highs.wasm} +0 -0
- /package/dist/lib/{highs.wasm.LICENSE → solvers/highs.wasm.LICENSE} +0 -0
- /package/dist/lib/{loader-CDpPXN_F.js → solvers/loader-CDpPXN_F.js} +0 -0
- /package/dist/lib/solvers/{pumpkin-loader-Ow74Fa1B.js → loader-Ow74Fa1B.js} +0 -0
- /package/dist/lib/{rolldown-runtime-DtPi1Y-2.js → solvers/rolldown-runtime-DtPi1Y-2.js} +0 -0
package/README.zh-CN.md
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
<div align="center">
|
|
2
|
-
<picture>
|
|
3
|
-
<source media="(prefers-color-scheme: dark)" srcset="./assets/washi-header-dark.png">
|
|
4
|
-
<source media="(prefers-color-scheme: light)" srcset="./assets/washi-header-light.png">
|
|
5
|
-
<img alt="WaSHI - TypeScript 数理优化建模器" src="./assets/washi-header-light.png" width="420" />
|
|
6
|
-
</picture>
|
|
7
|
-
<p><strong>TypeScript 数理优化建模器</strong></p>
|
|
8
|
-
<p>
|
|
9
|
-
<em>线性规划 (LP) • 混合整数规划 (MIP) • 凸二次规划 (QP) • 约束规划 (CP) • SMT逻辑约束与冲突诊断</em>
|
|
10
|
-
</p>
|
|
11
|
-
<p>
|
|
12
|
-
<a href="./README.md">English</a> •
|
|
13
|
-
<a href="./README.ja.md">日本語</a> •
|
|
14
|
-
<a href="./README.zh-CN.md">简体中文</a>
|
|
15
|
-
</p>
|
|
16
|
-
<p>
|
|
17
|
-
<a href="https://www.npmjs.com/package/@ohtaman/washi"><img src="https://img.shields.io/npm/v/@ohtaman/washi?color=crimson&label=npm" alt="npm version" /></a>
|
|
18
|
-
<a href="https://github.com/ohtaman/washi/actions/workflows/distribution.yml"><img src="https://github.com/ohtaman/washi/actions/workflows/distribution.yml/badge.svg" alt="CI Status" /></a>
|
|
19
|
-
<a href="https://washi.ohtaman.dev/zh/"><img src="https://img.shields.io/badge/docs-online-blue" alt="docs" /></a>
|
|
20
|
-
<a href="https://washi.ohtaman.dev/demo/"><img src="https://img.shields.io/badge/demo-playground-brightgreen" alt="live demo" /></a>
|
|
21
|
-
<a href="./LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="license" /></a>
|
|
22
|
-
</p>
|
|
23
|
-
</div>
|
|
24
|
-
|
|
25
|
-
---
|
|
26
|
-
|
|
27
|
-
**WaSHI** (WebAssembly-backed, Solver-independent, High-level modeling Interface) 是面向 TypeScript / JavaScript 的数理优化与约束编程代数建模器,受到 Python **PuLP** 的启发。你可以在应用代码中定义变量、目标函数和约束,并在 Node.js 或浏览器本地使用内置 **HiGHS**(默认)和 **Pumpkin**(`@ohtaman/washi/solvers/pumpkin`),或按需加载 **Z3**、**GLPK** 插件进行求解。
|
|
28
|
-
|
|
29
|
-
## ✨ 核心特性
|
|
30
|
-
|
|
31
|
-
- **直观的代数语法**:通过 `` expr`30 * ${x} + 50 * ${y} <= 40` `` 与求和、点积(`sum`, `dot`)清晰编写公式与约束。
|
|
32
|
-
- **跨 Node.js 与浏览器本地运行**:基于 WebAssembly,无需单独部署 Python 服务或本地编译 C/C++。
|
|
33
|
-
- **求解器无关**:内置零外部依赖的 **HiGHS**(LP/MIP/QP)与 **Pumpkin**(CP/LCG),并支持按需加载 **Z3**、**GLPK** 插件或自定义求解器适配器。
|
|
34
|
-
- **可满足性判定与冲突诊断**:支持逻辑与算术约束的可满足性判定,并在模型不可行时定位矛盾约束。
|
|
35
|
-
- **大规模分解算法**:内置列生成法与 Benders 分解支持。
|
|
36
|
-
|
|
37
|
-
## 📚 文档与链接
|
|
38
|
-
|
|
39
|
-
- **[在线文档](https://washi.ohtaman.dev/zh/)**:建模指南、求解器说明与运行环境配置
|
|
40
|
-
- **[案例展示](https://washi.ohtaman.dev/zh/showcase/) · [浏览器演示](https://washi.ohtaman.dev/demo/) · [数理优化 N 题训练](https://washi.ohtaman.dev/exercises/?lang=zh)**:在线体验交互式应用、浏览器建模演练场与 N 题实战训练营
|
|
41
|
-
- **[示例目录](https://washi.ohtaman.dev/zh/examples/)**:各类问题的建模示例与可运行源码([`examples/`](examples/README.md))
|
|
42
|
-
- **[Agent Skill (`SKILL.md`)](skills/washi/SKILL.md) · [`llms.txt`](https://washi.ohtaman.dev/llms.txt) / [`llms-full.txt`](https://washi.ohtaman.dev/llms-full.txt)**:面向 AI 编程助手的技能定义与机器可读文档
|
|
43
|
-
|
|
44
|
-
---
|
|
45
|
-
|
|
46
|
-
## 📦 安装与快速开始
|
|
47
|
-
|
|
48
|
-
```bash
|
|
49
|
-
npm install @ohtaman/washi
|
|
50
|
-
# HiGHS (LP/MIP/QP) 与 Pumpkin (CP/LCG, @ohtaman/washi/solvers/pumpkin) 已内置打包,无需额外依赖
|
|
51
|
-
|
|
52
|
-
# 可选 peer-dependency 求解器插件
|
|
53
|
-
npm install z3-solver # 用于 SMT 逻辑与包含连续变量的精确冲突诊断
|
|
54
|
-
npm install glpk.js # 用于 GLPK 求解器 (GPL-3.0)
|
|
55
|
-
|
|
56
|
-
# 可选:为 AI 编程助手(Claude Code, Cursor, Codex 等)安装建模技能
|
|
57
|
-
npx skills add ohtaman/washi
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
```ts
|
|
61
|
-
import { Model, expr, maximize } from "@ohtaman/washi";
|
|
62
|
-
|
|
63
|
-
const m = new Model("木工产品利润最大化");
|
|
64
|
-
const x = m.integer("桌子", { lb: 0 });
|
|
65
|
-
const y = m.integer("椅子", { lb: 0 });
|
|
66
|
-
|
|
67
|
-
m.objective(maximize(expr`30 * ${x} + 50 * ${y}`));
|
|
68
|
-
m.constraint(expr`${x} + 2 * ${y} <= 40`, "wood_limit");
|
|
69
|
-
m.constraint(expr`2 * ${x} + ${y} <= 50`, "labor_limit");
|
|
70
|
-
|
|
71
|
-
await m.solve();
|
|
72
|
-
console.log(`生产计划: x=${x.value}, y=${y.value} (最大利润: $${m.objectiveValue})`);
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
## ⚙️ 求解器概览
|
|
78
|
-
|
|
79
|
-
| 求解器 | 许可证 | 支持问题类型 | 主要用途 | 引入方式 |
|
|
80
|
-
| :--- | :--- | :--- | :--- | :--- |
|
|
81
|
-
| **[HiGHS](https://github.com/ERGO-Code/HiGHS)** | MIT | LP, MIP, 凸QP | 数值优化与弹性冲突修复诊断 | 默认内置(零额外依赖) |
|
|
82
|
-
| **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** | MIT | CP, LCG, 逻辑, 有界整数 | 组合调度与免 COOP/COEP 的 `unsatCore` | `import "@ohtaman/washi/solvers/pumpkin"`(内置 WASM,零额外依赖) |
|
|
83
|
-
| **[Z3](https://github.com/Z3Prover/z3)** | MIT | SMT, SAT, 逻辑, MIP | 逻辑规则、可满足性判定与精确 `unsatCore` | `npm install z3-solver` + `import "@ohtaman/washi/solvers/z3"` |
|
|
84
|
-
| **[GLPK](https://www.gnu.org/software/glpk/)** | GPL-3.0 | LP, MIP | 线性与混合整数规划 | `npm install glpk.js` + `import "@ohtaman/washi/solvers/glpk"` |
|
|
85
|
-
| **Mock** | MIT | — | 单元与集成测试模拟响应 | 内置 (`MockSolver`) |
|
|
86
|
-
|
|
87
|
-
导入对应插件后,可在 `new Model(...)`、`m.solve(...)` 或 `m.check(...)` 中传入 `{ solver: "pumpkin" }`、`{ solver: "z3" }` 或 `{ solver: "glpk" }`。
|
|
88
|
-
|
|
89
|
-
---
|
|
90
|
-
|
|
91
|
-
## 🚀 常用用法示例
|
|
92
|
-
|
|
93
|
-
### 1. 求和、点积(`sum` / `dot`)与条件约束
|
|
94
|
-
|
|
95
|
-
使用 `dot` / `sum` 组合线性表达式,并通过 `m.indicator()` 表达条件规则:
|
|
96
|
-
|
|
97
|
-
```ts
|
|
98
|
-
import { Model, expr, minimize } from "@ohtaman/washi";
|
|
99
|
-
|
|
100
|
-
const m = new Model("TransportPlanning");
|
|
101
|
-
const factories = ["Tokyo", "Osaka"];
|
|
102
|
-
const stores = ["StoreA", "StoreB"];
|
|
103
|
-
const costs = {
|
|
104
|
-
Tokyo: { StoreA: 4, StoreB: 7 },
|
|
105
|
-
Osaka: { StoreA: 8, StoreB: 3 },
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
const open = m.binary(factories);
|
|
109
|
-
const ship = m.continuous(factories, stores, { lb: 0, ub: 500 });
|
|
110
|
-
|
|
111
|
-
// 若东京工厂关闭 (open["Tokyo"] == 0),从东京工厂发出的总运输量必须为 0
|
|
112
|
-
m.indicator(open["Tokyo"], expr`sum(${ship["Tokyo"]}) <= 0`, { activeValue: 0 });
|
|
113
|
-
m.constraint(expr`${ship["Tokyo"]["StoreA"]} + ${ship["Osaka"]["StoreA"]} >= 100`, "demand_A");
|
|
114
|
-
|
|
115
|
-
m.objective(minimize(expr`dot(${costs}, ${ship})`));
|
|
116
|
-
await m.solve();
|
|
117
|
-
|
|
118
|
-
console.log("Tokyo -> StoreA:", ship["Tokyo"]["StoreA"].value);
|
|
119
|
-
```
|
|
120
|
-
|
|
121
|
-
### 2. 凸二次规划 (QP)
|
|
122
|
-
|
|
123
|
-
在线性约束下最小化二次目标函数:
|
|
124
|
-
|
|
125
|
-
```ts
|
|
126
|
-
import { Model, expr, minimize } from "@ohtaman/washi";
|
|
127
|
-
|
|
128
|
-
const m = new Model("PortfolioQP");
|
|
129
|
-
const x = m.continuous("tech", { lb: 0, ub: 1 });
|
|
130
|
-
const y = m.continuous("bonds", { lb: 0, ub: 1 });
|
|
131
|
-
|
|
132
|
-
m.constraint(expr`${x} + ${y} == 1`, "budget");
|
|
133
|
-
m.constraint(expr`0.14 * ${x} + 0.04 * ${y} >= 0.08`, "min_return");
|
|
134
|
-
m.objective(minimize(expr`0.04 * ${x}^2 + 0.005 * ${y}^2`));
|
|
135
|
-
|
|
136
|
-
await m.solve();
|
|
137
|
-
console.log(`Tech: ${x.value?.toFixed(2)}, Bonds: ${y.value?.toFixed(2)}`);
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### 3. 约束规划与析取调度 (Pumpkin)
|
|
141
|
-
|
|
142
|
-
使用内置的 **Pumpkin**(`@ohtaman/washi/solvers/pumpkin`)求解有界整数调度与 CP 全局约束(`disjoint`、`distinct`、`cumulative`、`allowed`),无需任何额外依赖:
|
|
143
|
-
|
|
144
|
-
```ts
|
|
145
|
-
import { Model, expr, disjoint, distinct, minimize } from "@ohtaman/washi";
|
|
146
|
-
import "@ohtaman/washi/solvers/pumpkin";
|
|
147
|
-
|
|
148
|
-
const m = new Model("WorkshopCP", { solver: "pumpkin" });
|
|
149
|
-
const start = m.integer(["cut", "weld", "paint"] as const, { lb: 0, ub: 20, prefix: "start" });
|
|
150
|
-
const bench = m.integer(["cut", "weld", "paint"] as const, { lb: 1, ub: 3, prefix: "bench" });
|
|
151
|
-
|
|
152
|
-
m.constraint(
|
|
153
|
-
disjoint([
|
|
154
|
-
{ start: start.cut, duration: 4 },
|
|
155
|
-
{ start: start.weld, duration: 3 },
|
|
156
|
-
{ start: start.paint, duration: 2 },
|
|
157
|
-
]),
|
|
158
|
-
"single_line"
|
|
159
|
-
);
|
|
160
|
-
m.constraint(expr`${start.cut} + 4 <= ${start.weld}`, "cut_before_weld");
|
|
161
|
-
m.constraint(expr`${start.weld} + 3 <= ${start.paint}`, "weld_before_paint");
|
|
162
|
-
m.constraint(distinct(bench), "unique_benches");
|
|
163
|
-
|
|
164
|
-
m.objective(minimize(expr`${start.paint} + 2`));
|
|
165
|
-
await m.solve();
|
|
166
|
-
console.log(`Makespan: ${m.objectiveValue}h (paint starts at ${start.paint.value}h)`);
|
|
167
|
-
```
|
|
168
|
-
|
|
169
|
-
### 4. 逻辑规则与冲突诊断 (`m.check`)
|
|
170
|
-
|
|
171
|
-
表达逻辑蕴含规则并排查不可行原因:
|
|
172
|
-
- **HiGHS(默认)**:提取**弹性修复集合**(`res.conflicts`),即松弛后可恢复可行性的约束。
|
|
173
|
-
- **Pumpkin(内置)**:为有界整数与布尔模型提取尺度无关的**不可满足核心**(`res.unsatCore` / `res.conflicts`),**无需 `COOP`/`COEP` 响应头**。
|
|
174
|
-
- **Z3**:提取包含连续变量与有理数算术的精确 **SMT 不可满足核心**(`res.unsatCore` / `res.conflicts`)。
|
|
175
|
-
|
|
176
|
-
```ts
|
|
177
|
-
import { Model, implies, expr } from "@ohtaman/washi";
|
|
178
|
-
// import "@ohtaman/washi/solvers/pumpkin"; // 内置:免 COOP/COEP 的 unsatCore(有界整数/布尔)
|
|
179
|
-
// import "@ohtaman/washi/solvers/z3"; // 可选:支持含连续变量的精确 SMT unsatCore
|
|
180
|
-
|
|
181
|
-
const m = new Model("StaffingRules");
|
|
182
|
-
const engineers = m.integer("engineers", { lb: 0, ub: 20 });
|
|
183
|
-
const budget = m.continuous("budget", { lb: 0, ub: 100000 });
|
|
184
|
-
const rush = m.bool("rush");
|
|
185
|
-
|
|
186
|
-
m.constraint(expr`8000 * ${engineers} <= ${budget}`, "budget_limit");
|
|
187
|
-
m.constraint(rush, "rush_required");
|
|
188
|
-
m.constraint(implies(rush, expr`${engineers} >= 8`), "rush_staffing");
|
|
189
|
-
m.constraint(expr`${budget} <= 50000`, "budget_cap"); // 冲突: 8人 * $8,000 > $50,000
|
|
190
|
-
m.constraint(expr`${engineers} >= 1`, "min_staff"); // 无关规则
|
|
191
|
-
|
|
192
|
-
const res = await m.check(); // 或 await m.check({ solver: "z3" })
|
|
193
|
-
console.log(res.status); // "Unsat"
|
|
194
|
-
console.log(res.conflicts); // HiGHS: ["rush_required"]
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
---
|
|
198
|
-
|
|
199
|
-
## 🌐 浏览器与 Web Worker 使用指南
|
|
200
|
-
|
|
201
|
-
- **打包工具 (Vite / webpack 5)**:直接 `import { Model } from "@ohtaman/washi"` 即可。**HiGHS** 与 **Pumpkin** 默认均在专用 Web Worker 中求解(传入 `{ useWorker: false }` 可在主线程执行),且**无需 `COOP`/`COEP` 响应头**。
|
|
202
|
-
- **原生 ESM / Script 标签 / CDN**:部署 `dist/browser/` 目录(含 `highs.wasm`、`solvers/pumpkin.wasm` 与 Worker 资源)或从 CDN 加载。
|
|
203
|
-
|
|
204
|
-
```html
|
|
205
|
-
<!-- 浏览器原生 ESM -->
|
|
206
|
-
<script type="module">
|
|
207
|
-
import { Model } from "./washi/washi.js";
|
|
208
|
-
// 内置或可选求解器插件:
|
|
209
|
-
// import "./washi/solvers/pumpkin.js"; // 内置 CP/LCG(免 COOP/COEP)
|
|
210
|
-
// import "./washi/solvers/glpk.js"; // 可选 GLPK 插件
|
|
211
|
-
// import "./washi/solvers/z3.js"; // 可选 Z3 插件(需 COOP/COEP)
|
|
212
|
-
const m = new Model();
|
|
213
|
-
await m.solve();
|
|
214
|
-
</script>
|
|
215
|
-
|
|
216
|
-
<!-- Script 标签 / CodePen (挂载全局变量 Washi) -->
|
|
217
|
-
<script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/washi.min.js"></script>
|
|
218
|
-
<!-- 可选求解器插件脚本(自动注册到 window.Washi): -->
|
|
219
|
-
<!-- <script src="https://cdn.jsdelivr.net/npm/@ohtaman/washi/dist/browser/solvers/pumpkin.min.js"></script> -->
|
|
220
|
-
```
|
|
221
|
-
|
|
222
|
-
> [!NOTE]
|
|
223
|
-
> **浏览器中使用 Z3**:Z3 的 WebAssembly 引擎依赖 `SharedArrayBuffer`,需要配置跨源隔离响应头(`COOP: same-origin` 与 `COEP: require-corp`)。详见[跨源隔离指南](docs/zh/getting-started/cross-origin.md)与 [`examples/distribution/`](examples/distribution/README.md)。**HiGHS**、**Pumpkin**(包括有界整数/布尔模型的 `unsatCore`)和 **GLPK** 均无需跨源隔离响应头即可运行。
|
|
224
|
-
|
|
225
|
-
---
|
|
226
|
-
|
|
227
|
-
## 🤝 参与开发与贡献
|
|
228
|
-
|
|
229
|
-
关于本地开发、运行测试与基准测试、重新构建 WebAssembly 资源以及发布流程,请参阅 [CONTRIBUTING.md](./CONTRIBUTING.md)。
|
|
230
|
-
|
|
231
|
-
---
|
|
232
|
-
|
|
233
|
-
## 🙏 致谢
|
|
234
|
-
|
|
235
|
-
WaSHI 的诞生离不开数理优化与自动推理开源社区的卓越工作:
|
|
236
|
-
|
|
237
|
-
- **[HiGHS](https://highs.dev/)**([`ERGO-Code/HiGHS`](https://github.com/ERGO-Code/HiGHS))— 发源于爱丁堡大学、由 Julian Hall、Qi Huangfu、Ivet Galabova、Leona Gottwald、Michael Feldmeier 及社区贡献者共同打造的高性能开源 LP / MIP / 凸 QP 求解器,驱动了 WaSHI 的内置默认引擎(*Huangfu & Hall, Mathematical Programming Computation, 2018*, [DOI: 10.1007/s12532-017-0130-5](https://doi.org/10.1007/s12532-017-0130-5))。
|
|
238
|
-
- **[Pumpkin](https://github.com/ConSol-Lab/Pumpkin)** — 由代尔夫特理工大学(TU Delft)ConSol Lab 使用 Rust 开发的惰性子句生成(LCG)约束规划求解器,驱动了 WaSHI 内置的 CP/LCG 与免 `COOP`/`COEP` `unsatCore` 引擎。
|
|
239
|
-
- **[Z3 Theorem Prover](https://github.com/Z3Prover/z3)**([`z3-solver`](https://www.npmjs.com/package/z3-solver))— 由 Microsoft Research 研发,驱动了 WaSHI 可选的 SMT 可满足性判定与精确 `unsatCore` 冲突诊断插件。
|
|
240
|
-
- **[GLPK](https://www.gnu.org/software/glpk/) & [`glpk.js`](https://github.com/jvail/glpk.js)** — 驱动了 WaSHI 可选的 GPL-3.0 LP / MIP 求解器插件。
|
|
241
|
-
- **[PuLP](https://github.com/coin-or/pulp)** — 启发了 WaSHI 声明式代数建模 API 的设计。
|
|
242
|
-
|
|
243
|
-
---
|
|
244
|
-
|
|
245
|
-
## 📄 许可证
|
|
246
|
-
|
|
247
|
-
- **`@ohtaman/washi`**: [MIT 许可证](./LICENSE)
|
|
248
|
-
- **内置与可选引擎**: HiGHS (MIT)、Pumpkin (MIT)、Z3 (MIT)、GLPK (GPL-3.0)。完整许可说明请参阅 [THIRD_PARTY_LICENSES.md](./THIRD_PARTY_LICENSES.md)。
|
|
@@ -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})({});
|