@ohtaman/washi 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/README.md +9 -10
  2. package/THIRD_PARTY_LICENSES.md +4 -4
  3. package/dist/{browser/washi.js → core-b430-tAc.js} +656 -661
  4. package/dist/solvers/browser-_washi-browser-node-runtime-BOEcR5J2.js +28 -0
  5. package/dist/solvers/browser-browser-worker-CT6498Is.js +13 -0
  6. package/dist/{lib/solvers/loader-b5PNpCmX.js → solvers/browser-loader-D21chr4P.js} +12 -23
  7. package/dist/{lib/solvers/loader-DCtyxsfF.js → solvers/browser-loader-DWFhT0yY.js} +13 -13
  8. package/dist/solvers/browser-lp-writer-DH_1sdsF.js +115 -0
  9. package/dist/solvers/glpk.js +310 -0
  10. package/dist/{lib/solvers/glpk.js → solvers/glpk.node.js} +5 -9
  11. package/dist/{lib/solvers/__vite-browser-external-oLchLuMx.js → solvers/highs-browser-__vite-browser-external-Cu-Zq4Hm.js} +1 -1
  12. package/dist/solvers/highs-browser-runtime.js +2410 -0
  13. package/dist/{lib/solvers → solvers}/highs-node-runtime.js +1 -1
  14. package/dist/{lib/solvers → solvers}/highs-worker.js +2 -2
  15. package/dist/{lib/solvers → solvers}/highs.js +64 -70
  16. package/dist/{browser/solvers/highs-loader-Csn3-0tq.js → solvers/highs.node.js} +520 -138
  17. package/dist/solvers/node-browser-worker-CN93BPoO.js +54 -0
  18. package/dist/{lib/solvers/lp-writer-CLScMFbS.js → solvers/node-lp-writer-CqMLgMIk.js} +1 -1
  19. package/dist/solvers/node-node-runtime-BUlNfXvx.js +10 -0
  20. package/dist/solvers/node-registry-CrYRRk9q.js +907 -0
  21. package/dist/solvers/node-types-BGqPkxwu.js +12 -0
  22. package/dist/{lib/solvers → solvers}/pumpkin-node-runtime.js +1 -1
  23. package/dist/{browser/solvers → solvers}/pumpkin-worker.js +2 -1
  24. package/dist/{lib/solvers → solvers}/pumpkin.js +174 -164
  25. package/dist/solvers/pumpkin.node.js +1228 -0
  26. package/dist/{lib/solvers → solvers}/z3.js +123 -120
  27. package/dist/types/core.d.ts +11 -0
  28. package/dist/types/core.d.ts.map +1 -0
  29. package/dist/types/index.d.ts +3 -4
  30. package/dist/types/index.d.ts.map +1 -1
  31. package/dist/types/modeler/core.d.ts +14 -0
  32. package/dist/types/modeler/core.d.ts.map +1 -0
  33. package/dist/types/modeler/index.d.ts +1 -13
  34. package/dist/types/modeler/index.d.ts.map +1 -1
  35. package/dist/types/modeler/model.d.ts +1 -1
  36. package/dist/types/modeler/model.d.ts.map +1 -1
  37. package/dist/types/modeler/solvers/browser-worker.d.ts +17 -0
  38. package/dist/types/modeler/solvers/browser-worker.d.ts.map +1 -0
  39. package/dist/types/modeler/solvers/glpk/loader.d.ts +2 -2
  40. package/dist/types/modeler/solvers/glpk/node-runtime.d.ts +5 -0
  41. package/dist/types/modeler/solvers/glpk/node-runtime.d.ts.map +1 -0
  42. package/dist/types/modeler/solvers/highs/worker-client.d.ts +5 -5
  43. package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
  44. package/dist/types/modeler/solvers/pumpkin/loader.d.ts +0 -4
  45. package/dist/types/modeler/solvers/pumpkin/loader.d.ts.map +1 -1
  46. package/dist/types/modeler/solvers/pumpkin/solver.d.ts.map +1 -1
  47. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts +4 -3
  48. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts.map +1 -1
  49. package/dist/types/modeler/solvers/types.d.ts +5 -1
  50. package/dist/types/modeler/solvers/types.d.ts.map +1 -1
  51. package/dist/types/modeler/solvers/z3/loader.d.ts +3 -8
  52. package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
  53. package/dist/types/modeler/solvers/z3/solver.d.ts +3 -2
  54. package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -1
  55. package/dist/types/modeler/types.d.ts +18 -3
  56. package/dist/types/modeler/types.d.ts.map +1 -1
  57. package/dist/washi.js +4 -0
  58. package/dist/washi.min.js +6 -0
  59. package/dist/washi.node.js +4 -0
  60. package/docs/getting-started/ai-agents.md +23 -22
  61. package/docs/getting-started/coding-agents.md +26 -17
  62. package/docs/getting-started/cross-origin.md +2 -1
  63. package/docs/getting-started/index.md +3 -1
  64. package/docs/getting-started/runtimes.md +53 -63
  65. package/docs/guide/objectives.md +3 -3
  66. package/docs/solvers/custom-solver.md +4 -9
  67. package/docs/solvers/glpk.md +2 -0
  68. package/docs/solvers/highs.md +8 -10
  69. package/docs/solvers/index.md +1 -1
  70. package/docs/solvers/pumpkin.md +7 -7
  71. package/docs/solvers/z3.md +18 -1
  72. package/llms-full.txt +124 -118
  73. package/llms.txt +23 -22
  74. package/package.json +31 -64
  75. package/skills/washi/SKILL.md +18 -18
  76. package/skills/washi/references/single-html.md +7 -12
  77. package/dist/browser/solvers/glpk.js +0 -1263
  78. package/dist/browser/solvers/glpk.min.js +0 -1
  79. package/dist/browser/solvers/highs-__vite-browser-external-xcxOpLMD.js +0 -7
  80. package/dist/browser/solvers/highs-browser-runtime-ccRmE4qj.js +0 -2021
  81. package/dist/browser/solvers/highs-worker.js +0 -55
  82. package/dist/browser/solvers/highs.js +0 -1454
  83. package/dist/browser/solvers/pumpkin-_washi-pumpkin-node-runtime-CEKUDK6d.js +0 -9
  84. package/dist/browser/solvers/pumpkin-loader-BI3n3dWO.js +0 -401
  85. package/dist/browser/solvers/pumpkin.js +0 -1796
  86. package/dist/browser/solvers/z3-built.js +0 -8245
  87. package/dist/browser/solvers/z3-built.wasm +0 -4
  88. package/dist/browser/solvers/z3.js +0 -7842
  89. package/dist/browser/solvers/z3.min.js +0 -5
  90. package/dist/browser/washi.min.js +0 -6
  91. package/dist/lib/solvers/highs-browser-runtime.js +0 -2413
  92. package/dist/lib/solvers/highs.wasm +0 -0
  93. package/dist/lib/solvers/highs.wasm.LICENSE +0 -21
  94. package/dist/lib/solvers/pumpkin-worker.js +0 -47
  95. package/dist/lib/solvers/pumpkin.wasm +0 -0
  96. package/dist/lib/solvers/pumpkin.wasm.LICENSE +0 -21
  97. package/dist/lib/solvers/z3-assets.js +0 -1
  98. package/dist/lib/solvers/z3-built.js +0 -8245
  99. package/dist/lib/solvers/z3-built.wasm +0 -4
  100. package/dist/lib/washi.js +0 -5662
  101. package/dist/types/modeler/solvers/z3/assets.d.ts +0 -11
  102. package/dist/types/modeler/solvers/z3/assets.d.ts.map +0 -1
  103. /package/dist/{lib/solvers/embedded-wasm-CSFlLV5N.js → solvers/browser-embedded-wasm-CSFlLV5N.js} +0 -0
  104. /package/dist/{lib/solvers/registry-CrYRRk9q.js → solvers/browser-registry-CrYRRk9q.js} +0 -0
  105. /package/dist/{lib/solvers/types-BGqPkxwu.js → solvers/browser-types-BGqPkxwu.js} +0 -0
  106. /package/dist/{lib/solvers → solvers}/highs-assets.js +0 -0
  107. /package/dist/{lib/solvers/rolldown-runtime-DtPi1Y-2.js → solvers/highs-browser-rolldown-runtime-DtPi1Y-2.js} +0 -0
  108. /package/dist/{browser/solvers → solvers}/highs-inline.js +0 -0
  109. /package/dist/{lib/solvers → solvers}/highs-runtime.js +0 -0
  110. /package/dist/{lib/solvers → solvers}/highs-worker-factory.js +0 -0
  111. /package/dist/{browser/solvers → solvers}/highs.wasm +0 -0
  112. /package/dist/{browser/solvers → solvers}/highs.wasm.LICENSE +0 -0
  113. /package/dist/{lib/solvers → solvers}/pumpkin-assets.js +0 -0
  114. /package/dist/{browser/solvers → solvers}/pumpkin-inline.js +0 -0
  115. /package/dist/{lib/solvers → solvers}/pumpkin-worker-factory.js +0 -0
  116. /package/dist/{browser/solvers → solvers}/pumpkin.wasm +0 -0
  117. /package/dist/{browser/solvers → solvers}/pumpkin.wasm.LICENSE +0 -0
@@ -0,0 +1,907 @@
1
+ //#region src/modeler/constraint.ts
2
+ var e = 0, t = class t {
3
+ kind = "constraint";
4
+ id;
5
+ _lhs;
6
+ _sense;
7
+ _rhs;
8
+ _name;
9
+ hasExplicitName;
10
+ ownerModel = null;
11
+ _indicatorOrigin;
12
+ _indicatorSnapshot;
13
+ _discreteVars;
14
+ slack = null;
15
+ dual = null;
16
+ addTerm(e, t) {
17
+ return t === 0 ? this : (this._indicatorOrigin = void 0, this._indicatorSnapshot = void 0, this._lhs.addTerm(e, t), u(this.ownerModel), this);
18
+ }
19
+ setTerm(e, t) {
20
+ return this._indicatorOrigin = void 0, this._indicatorSnapshot = void 0, this._lhs.setTerm(e, t), u(this.ownerModel), this;
21
+ }
22
+ constructor(t, n, r, i) {
23
+ this.id = ++e, this._lhs = t, this._sense = n, this._rhs = r;
24
+ let a = typeof i == "string" ? i.trim() : void 0;
25
+ a && a.length > 0 ? (this._name = a, this.hasExplicitName = !0) : (this._name = `c_${this.id}`, this.hasExplicitName = !1);
26
+ }
27
+ get lhs() {
28
+ return this._lhs;
29
+ }
30
+ set lhs(e) {
31
+ this._lhs !== e && (this._indicatorOrigin = void 0, this._indicatorSnapshot = void 0, this._lhs = e, u(this.ownerModel));
32
+ }
33
+ get sense() {
34
+ return this._sense;
35
+ }
36
+ set sense(e) {
37
+ if (e === "!=" && !Number.isSafeInteger(this._rhs)) throw Error(`Discrete "!=" in constraint "${this._name}" requires a safe integer RHS, received ${this._rhs}.`);
38
+ this._sense !== e && (this._indicatorOrigin = void 0, this._indicatorSnapshot = void 0, this._sense = e, u(this.ownerModel));
39
+ }
40
+ get rhs() {
41
+ return this._rhs;
42
+ }
43
+ set rhs(e) {
44
+ if (this._sense === "!=" && !Number.isSafeInteger(e)) throw Error(`Discrete "!=" in constraint "${this._name}" requires a safe integer RHS, received ${e}.`);
45
+ Object.is(this._rhs, e) || (this._indicatorOrigin = void 0, this._indicatorSnapshot = void 0, this._rhs = e, u(this.ownerModel));
46
+ }
47
+ get name() {
48
+ return this._name;
49
+ }
50
+ set name(e) {
51
+ this._name !== e && (this._name = e, u(this.ownerModel)), this.hasExplicitName = !0;
52
+ }
53
+ get _indicatorMeta() {
54
+ let e = this._indicatorOrigin, t = this._indicatorSnapshot;
55
+ if (!e || !t) return;
56
+ 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) {
57
+ this._indicatorOrigin = void 0, this._indicatorSnapshot = void 0;
58
+ return;
59
+ }
60
+ for (let [e, n] of t.terms) if (!this._lhs.terms.has(e) || !Object.is(this._lhs.terms.get(e), n)) {
61
+ this._indicatorOrigin = void 0, this._indicatorSnapshot = void 0;
62
+ return;
63
+ }
64
+ let n = e.targetRhs - (e.targetLhs.constant ?? 0), r = 0;
65
+ for (let [t, n] of e.targetLhs.terms) {
66
+ if (n === 0) continue;
67
+ let i = e.targetSense === "<=" ? n > 0 ? t.ub : t.lb : n > 0 ? t.lb : t.ub;
68
+ if (!Number.isFinite(i) || (r += n * i, !Number.isFinite(r))) return;
69
+ }
70
+ if (!((e.targetSense === "<=" ? r - n : n - r) > e.derivedM + 1e-9)) return e;
71
+ }
72
+ _setIndicatorOrigin(e) {
73
+ if (!e) {
74
+ this._indicatorOrigin = void 0, this._indicatorSnapshot = void 0;
75
+ return;
76
+ }
77
+ this._indicatorOrigin = e, this._indicatorSnapshot = {
78
+ lhsRef: this._lhs,
79
+ terms: new Map(this._lhs.terms),
80
+ constant: this._lhs.constant,
81
+ sense: this._sense,
82
+ rhs: this._rhs
83
+ };
84
+ }
85
+ get _requiredDiscreteVars() {
86
+ return this._discreteVars;
87
+ }
88
+ _setDiscreteVars(e) {
89
+ this._discreteVars = e;
90
+ }
91
+ _assignModelName(e, t) {
92
+ this._name = e, this.hasExplicitName = t;
93
+ }
94
+ and(e) {
95
+ return new s("and", [this, e]);
96
+ }
97
+ or(e) {
98
+ return new s("or", [this, e]);
99
+ }
100
+ implies(e) {
101
+ return new s("implies", [this, e]);
102
+ }
103
+ xor(e) {
104
+ return new s("xor", [this, e]);
105
+ }
106
+ not() {
107
+ return new s("not", [this]);
108
+ }
109
+ add(e) {
110
+ throw Error("Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.");
111
+ }
112
+ sub(e) {
113
+ throw Error("Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.");
114
+ }
115
+ mul(e) {
116
+ throw Error("Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.");
117
+ }
118
+ div(e) {
119
+ throw Error("Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.");
120
+ }
121
+ neg() {
122
+ throw Error("Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.");
123
+ }
124
+ le(e, t) {
125
+ throw Error("Cannot compare a Constraint in (<=): expected a number, Var, or LinExpr.");
126
+ }
127
+ ge(e, t) {
128
+ throw Error("Cannot compare a Constraint in (>=): expected a number, Var, or LinExpr.");
129
+ }
130
+ eq(e, t) {
131
+ throw Error("Cannot compare a Constraint in (==): expected a number, Var, or LinExpr.");
132
+ }
133
+ lt(e, t) {
134
+ throw Error("Cannot compare a Constraint in (<): expected a number, Var, or LinExpr.");
135
+ }
136
+ gt(e, t) {
137
+ throw Error("Cannot compare a Constraint in (>): expected a number, Var, or LinExpr.");
138
+ }
139
+ ne(e, t) {
140
+ throw Error("Cannot compare a Constraint in (!=): expected a number, Var, or LinExpr.");
141
+ }
142
+ get value() {
143
+ throw Error("Cannot read numeric value of a Constraint: expected a Var, LinExpr, or QuadExpr.");
144
+ }
145
+ get constant() {
146
+ throw Error("Cannot read numeric constant of a Constraint: expected a LinExpr or QuadExpr.");
147
+ }
148
+ clone() {
149
+ let e = new t(this._lhs.clone(), this._sense, this._rhs, this.hasExplicitName ? this._name : void 0);
150
+ return this._discreteVars && e._setDiscreteVars(new Set(this._discreteVars)), e;
151
+ }
152
+ toString() {
153
+ let e = this.sense === "==" ? "=" : this.sense;
154
+ return `${this.name}: ${this.lhs.toString()} ${e} ${this.rhs}`;
155
+ }
156
+ };
157
+ function n(e) {
158
+ return e instanceof t || typeof e == "object" && !!e && "sense" in e && "lhs" in e && "rhs" in e;
159
+ }
160
+ //#endregion
161
+ //#region src/modeler/boolean-expr.ts
162
+ var r = 0;
163
+ function i(e, n) {
164
+ if (e instanceof a || e instanceof t) return e;
165
+ throw typeof e == "object" && e && ("terms" in e || "quadTerms" in e) ? Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical operator "${n}". 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 "${n}": 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 "${n}": expected a BoolVar, BoolExpr, or Constraint.`);
166
+ }
167
+ var a = class {
168
+ and(e) {
169
+ return new s("and", [this, i(e, "and")]);
170
+ }
171
+ or(e) {
172
+ return new s("or", [this, i(e, "or")]);
173
+ }
174
+ implies(e) {
175
+ return new s("implies", [this, i(e, "implies")]);
176
+ }
177
+ xor(e) {
178
+ return new s("xor", [this, i(e, "xor")]);
179
+ }
180
+ not() {
181
+ return new s("not", [this]);
182
+ }
183
+ }, o = class extends a {
184
+ id;
185
+ type = "Boolean";
186
+ name;
187
+ value = null;
188
+ constructor(e) {
189
+ super(), this.id = ++r, this.name = e || `p_${this.id}`;
190
+ }
191
+ toString() {
192
+ return this.name;
193
+ }
194
+ }, s = class extends a {
195
+ op;
196
+ children;
197
+ constructor(e, t) {
198
+ super(), this.op = e, this.children = t.map((t) => i(t, e));
199
+ }
200
+ toString() {
201
+ return this.op === "not" ? `not(${this.children[0].toString()})` : `(${this.children.map((e) => e.toString()).join(` ${this.op} `)})`;
202
+ }
203
+ }, c = class extends a {
204
+ spec;
205
+ discreteVars;
206
+ constructor(e, t) {
207
+ super(), this.spec = e, this.discreteVars = t;
208
+ }
209
+ toString() {
210
+ switch (this.spec.kind) {
211
+ case "distinct": return `distinct(${this.spec.args.map((e) => e.toString()).join(", ")})`;
212
+ case "disjoint": return `disjoint([${this.spec.tasks.map((e) => `{ start: ${e.start.toString()}, duration: ${e.duration} }`).join(", ")}])`;
213
+ case "cumulative": return `cumulative([${this.spec.tasks.map((e) => `{ start: ${e.start.toString()}, duration: ${e.duration}, demand: ${e.demand} }`).join(", ")}], ${this.spec.capacity})`;
214
+ case "allowed": return `allowed([${this.spec.vars.map((e) => e.toString()).join(", ")}], [${this.spec.tuples.map((e) => `[${e.join(", ")}]`).join(", ")}])`;
215
+ }
216
+ }
217
+ }, l = /* @__PURE__ */ new WeakMap();
218
+ function u(e) {
219
+ e && l.get(e)?.();
220
+ }
221
+ var d = 1e-6;
222
+ function f(e) {
223
+ 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).`);
224
+ if (e.lb === Infinity) throw Error(`Variable "${e.name}" has invalid lower bound: +Infinity is not allowed as a lower bound.`);
225
+ 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).`);
226
+ if (e.ub === -Infinity) throw Error(`Variable "${e.name}" has invalid upper bound: -Infinity is not allowed as an upper bound.`);
227
+ 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}).`);
228
+ if (e.initialValue !== void 0) {
229
+ 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).`);
230
+ let t = e.type === "Binary" ? Math.max(0, e.lb) : e.lb, n = e.type === "Binary" ? Math.min(1, e.ub) : e.ub;
231
+ 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 ${d}).`);
232
+ if (e.type === "Integer" || e.type === "Binary") {
233
+ let r = Math.round(e.initialValue);
234
+ 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 ${d} of an integer in [${t}, ${n}]).`);
235
+ }
236
+ }
237
+ }
238
+ function p(e) {
239
+ if (e.initialValue === void 0) return;
240
+ if (f(e), e.type === "Integer" || e.type === "Binary") {
241
+ let t = Math.round(e.initialValue);
242
+ return Object.is(t, -0) ? 0 : t;
243
+ }
244
+ let t = Math.min(e.ub, Math.max(e.lb, e.initialValue));
245
+ return Object.is(t, -0) ? 0 : t;
246
+ }
247
+ //#endregion
248
+ //#region src/modeler/variable.ts
249
+ var m = 0;
250
+ function h(e) {
251
+ if (e === void 0) return "Continuous";
252
+ if (typeof e == "string") {
253
+ let t = e.toLowerCase();
254
+ if (t === "binary" || t === "bin") return "Binary";
255
+ if (t === "integer" || t === "int") return "Integer";
256
+ if (t === "continuous" || t === "cont") return "Continuous";
257
+ }
258
+ throw Error(`Invalid variable type "${String(e)}": expected "Continuous", "Integer", or "Binary".`);
259
+ }
260
+ var g = class {
261
+ id;
262
+ _name;
263
+ prefix;
264
+ hasExplicitName;
265
+ ownerModel = null;
266
+ _type;
267
+ _lb;
268
+ _ub;
269
+ _initialValue;
270
+ value = null;
271
+ reducedCost = null;
272
+ constructor(e = {}) {
273
+ this.id = ++m;
274
+ let t = typeof e.name == "string" ? e.name.trim() : "", n = typeof e.prefix == "string" ? e.prefix.trim() : "";
275
+ this.prefix = n.length > 0 ? n : "x", this.hasExplicitName = t.length > 0, this._name = this.hasExplicitName ? t : `${this.prefix}_${this.id}`, this._type = h(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 ? Infinity : e.ub), this._initialValue = e.initialValue === void 0 ? void 0 : Object.is(e.initialValue, -0) ? 0 : e.initialValue, this._initialValue !== void 0 && f(this);
276
+ }
277
+ get name() {
278
+ return this._name;
279
+ }
280
+ get type() {
281
+ return this._type;
282
+ }
283
+ set type(e) {
284
+ let t = h(e);
285
+ this._type !== t && (this._type = t, u(this.ownerModel));
286
+ }
287
+ get lb() {
288
+ return this._lb;
289
+ }
290
+ set lb(e) {
291
+ Object.is(this._lb, e) || (this._lb = e, u(this.ownerModel));
292
+ }
293
+ get ub() {
294
+ return this._ub;
295
+ }
296
+ set ub(e) {
297
+ Object.is(this._ub, e) || (this._ub = e, u(this.ownerModel));
298
+ }
299
+ get initialValue() {
300
+ return this._initialValue;
301
+ }
302
+ set initialValue(e) {
303
+ let t = e !== void 0 && Object.is(e, -0) ? 0 : e;
304
+ Object.is(this._initialValue, t) || (this._initialValue = t, u(this.ownerModel));
305
+ }
306
+ _assignModelName(e) {
307
+ this._name = e;
308
+ }
309
+ mul(e) {
310
+ return typeof e == "number" ? new S(/* @__PURE__ */ new Map([[this, 1]]), 0).mul(e) : new w(/* @__PURE__ */ new Map([[this, 1]]), /* @__PURE__ */ new Map(), 0).mul(e);
311
+ }
312
+ add(e) {
313
+ return e instanceof w ? e.add(this) : new S(/* @__PURE__ */ new Map([[this, 1]]), 0).add(e);
314
+ }
315
+ sub(e) {
316
+ return e instanceof w ? e.neg().add(this) : new S(/* @__PURE__ */ new Map([[this, 1]]), 0).sub(e);
317
+ }
318
+ neg() {
319
+ return this.mul(-1);
320
+ }
321
+ le(e, t) {
322
+ return new S(/* @__PURE__ */ new Map([[this, 1]]), 0).le(e, t);
323
+ }
324
+ ge(e, t) {
325
+ return new S(/* @__PURE__ */ new Map([[this, 1]]), 0).ge(e, t);
326
+ }
327
+ eq(e, t) {
328
+ return new S(/* @__PURE__ */ new Map([[this, 1]]), 0).eq(e, t);
329
+ }
330
+ lt(e, t) {
331
+ return new S(/* @__PURE__ */ new Map([[this, 1]]), 0).lt(e, t);
332
+ }
333
+ gt(e, t) {
334
+ return new S(/* @__PURE__ */ new Map([[this, 1]]), 0).gt(e, t);
335
+ }
336
+ ne(e, t) {
337
+ return new S(/* @__PURE__ */ new Map([[this, 1]]), 0).ne(e, t);
338
+ }
339
+ toString() {
340
+ return this.name;
341
+ }
342
+ };
343
+ //#endregion
344
+ //#region src/modeler/expression.ts
345
+ function _(e) {
346
+ switch (e.kind) {
347
+ case "abs": return {
348
+ kind: "abs",
349
+ arg: e.arg.clone()
350
+ };
351
+ case "max": return {
352
+ kind: "max",
353
+ args: e.args.map((e) => e.clone())
354
+ };
355
+ case "min": return {
356
+ kind: "min",
357
+ args: e.args.map((e) => e.clone())
358
+ };
359
+ case "at": return {
360
+ kind: "at",
361
+ array: e.array.map((e) => e.clone()),
362
+ index: e.index.clone(),
363
+ discreteVars: new Set(e.discreteVars)
364
+ };
365
+ }
366
+ }
367
+ function v(e) {
368
+ switch (e.kind) {
369
+ case "abs": return `abs(${e.arg.toString()})`;
370
+ case "max": return `max(${e.args.map((e) => e.toString()).join(", ")})`;
371
+ case "min": return `min(${e.args.map((e) => e.toString()).join(", ")})`;
372
+ case "at": return `at([${e.array.map((e) => e.toString()).join(", ")}], ${e.index.toString()})`;
373
+ }
374
+ }
375
+ function y(e) {
376
+ switch (e.kind) {
377
+ case "abs": {
378
+ let t = e.arg.value;
379
+ return t === null ? null : Math.abs(t);
380
+ }
381
+ case "max": {
382
+ let t = -Infinity;
383
+ for (let n of e.args) {
384
+ let e = n.value;
385
+ if (e === null) return null;
386
+ e > t && (t = e);
387
+ }
388
+ return t;
389
+ }
390
+ case "min": {
391
+ let t = Infinity;
392
+ for (let n of e.args) {
393
+ let e = n.value;
394
+ if (e === null) return null;
395
+ e < t && (t = e);
396
+ }
397
+ return t;
398
+ }
399
+ case "at": {
400
+ let t = e.index.value;
401
+ if (t === null || !Number.isFinite(t)) return null;
402
+ let n = Math.round(t);
403
+ return Math.abs(t - n) > 1e-6 || n < 0 || n >= e.array.length ? null : e.array[n].value;
404
+ }
405
+ }
406
+ }
407
+ function b(e) {
408
+ return e instanceof g || typeof e == "object" && !!e && !n(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";
409
+ }
410
+ function x(e, t, r = /* @__PURE__ */ new Set()) {
411
+ if (typeof e == "number") {
412
+ if (!Number.isSafeInteger(e)) throw Error(`${t} requires Integer or Binary variables and integer constants/coefficients, but received constant ${e}.`);
413
+ return r;
414
+ }
415
+ if (n(e)) throw Error(`${t} cannot accept a Constraint comparison.`);
416
+ if (e instanceof w || "quadTerms" in e && e.quadTerms instanceof Map && "linearTerms" in e && e.linearTerms instanceof Map && typeof e.constant == "number") {
417
+ let n = e;
418
+ if (n.quadTerms.size > 0) throw Error(`${t} does not support quadratic expressions.`);
419
+ return x(new S(n.linearTerms, n.constant, n.nonlinearTerms ?? []), t, r);
420
+ }
421
+ if (b(e)) {
422
+ if (e.type !== "Integer" && e.type !== "Binary") throw Error(`${t} requires Integer or Binary variables, but involves Continuous variable "${e.name}".`);
423
+ return r.add(e), r;
424
+ }
425
+ if ("terms" in e && e.terms instanceof Map) {
426
+ let n = e, i = n.constant ?? 0;
427
+ if (!Number.isSafeInteger(i)) throw Error(`${t} requires Integer or Binary variables and integer constants/coefficients, but received constant ${i}.`);
428
+ for (let [e, i] of n.terms) if (i !== 0) {
429
+ if (e.type !== "Integer" && e.type !== "Binary") throw Error(`${t} requires Integer or Binary variables, but involves Continuous variable "${e.name}".`);
430
+ if (!Number.isSafeInteger(i)) throw Error(`${t} requires integer coefficients, but variable "${e.name}" has coefficient ${i}.`);
431
+ r.add(e);
432
+ }
433
+ for (let e of n.nonlinearTerms ?? []) {
434
+ if (e.coeff === 0) continue;
435
+ if (!Number.isSafeInteger(e.coeff)) throw Error(`${t} requires integer coefficients on nonlinear expressions, received ${e.coeff}.`);
436
+ let n = e.atom;
437
+ if (n.kind === "abs") x(n.arg, t, r);
438
+ else if (n.kind === "max" || n.kind === "min") for (let e of n.args) x(e, t, r);
439
+ else if (n.kind === "at") {
440
+ x(n.index, t, r);
441
+ for (let e of n.array) x(e, t, r);
442
+ }
443
+ }
444
+ return r;
445
+ }
446
+ throw Error(`${t} expected an integer-valued scalar expression.`);
447
+ }
448
+ var S = class e {
449
+ kind = "linear";
450
+ terms;
451
+ constant;
452
+ nonlinearTerms;
453
+ constructor(e = /* @__PURE__ */ new Map(), t = 0, n = []) {
454
+ this.terms = new Map(e), this.constant = t, this.nonlinearTerms = n.filter((e) => e.coeff !== 0).map((e) => ({
455
+ atom: _(e.atom),
456
+ coeff: e.coeff
457
+ }));
458
+ }
459
+ hasNonlinearTerms() {
460
+ return this.nonlinearTerms.length > 0;
461
+ }
462
+ setTerm(e, t) {
463
+ return t === 0 ? this.terms.delete(e) : this.terms.set(e, t), this;
464
+ }
465
+ addTerm(e, t) {
466
+ let n = (this.terms.get(e) ?? 0) + t;
467
+ return n === 0 ? this.terms.delete(e) : this.terms.set(e, n), this;
468
+ }
469
+ clone() {
470
+ return new e(this.terms, this.constant, this.nonlinearTerms);
471
+ }
472
+ add(e) {
473
+ if (n(e)) throw Error("Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.");
474
+ if (e instanceof w) return e.add(this);
475
+ let t = this.clone();
476
+ if (typeof e == "number") t.constant += e;
477
+ else if ("terms" in e) {
478
+ for (let [n, r] of e.terms) {
479
+ let e = (t.terms.get(n) ?? 0) + r;
480
+ e === 0 ? t.terms.delete(n) : t.terms.set(n, e);
481
+ }
482
+ if (t.constant += e.constant, Array.isArray(e.nonlinearTerms)) for (let n of e.nonlinearTerms) n.coeff !== 0 && t.nonlinearTerms.push({
483
+ atom: _(n.atom),
484
+ coeff: n.coeff
485
+ });
486
+ } else {
487
+ let n = (t.terms.get(e) ?? 0) + 1;
488
+ n === 0 ? t.terms.delete(e) : t.terms.set(e, n);
489
+ }
490
+ return t;
491
+ }
492
+ sub(e) {
493
+ if (n(e)) throw Error("Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.");
494
+ return e instanceof w ? e.neg().add(this) : typeof e == "number" ? this.add(-e) : this.add(e.mul(-1));
495
+ }
496
+ mul(t) {
497
+ if (n(t)) throw Error("Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.");
498
+ if (typeof t == "number") {
499
+ let n = this.terms.size > 0 || this.nonlinearTerms.length > 0, r = this.constant === 0 && n ? 0 : this.constant * t;
500
+ if (this.constant !== 0 && t !== 0 && r === 0) throw Error("Constant multiplication underflows to zero.");
501
+ let i = new e(/* @__PURE__ */ new Map(), r);
502
+ for (let [e, n] of this.terms) {
503
+ let r = n * t;
504
+ if (n !== 0 && t !== 0 && r === 0) throw Error("Coefficient multiplication underflows to zero.");
505
+ r !== 0 && i.terms.set(e, r);
506
+ }
507
+ if (t !== 0) for (let e of this.nonlinearTerms) {
508
+ let n = e.coeff * t;
509
+ if (e.coeff !== 0 && n === 0) throw Error("Coefficient multiplication underflows to zero.");
510
+ n !== 0 && i.nonlinearTerms.push({
511
+ atom: _(e.atom),
512
+ coeff: n
513
+ });
514
+ }
515
+ return i;
516
+ }
517
+ if (t instanceof g || typeof t == "object" && t && "id" in t && !("terms" in t) && !("quadTerms" in t)) {
518
+ if (this.hasNonlinearTerms()) throw Error("Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.");
519
+ return w.multiplyLinearTerms(this.constant, this.terms, 0, /* @__PURE__ */ new Map([[t, 1]]));
520
+ }
521
+ if (t instanceof w) {
522
+ let e = t.linearTerms.size > 0 || t.quadTerms.size > 0 || t.hasNonlinearTerms();
523
+ if (this.hasNonlinearTerms()) {
524
+ if (!e) return this.mul(t.constant);
525
+ throw Error("Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.");
526
+ }
527
+ if (t.hasNonlinearTerms()) {
528
+ if (this.terms.size === 0) return t.mul(this.constant);
529
+ throw Error("Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.");
530
+ }
531
+ return this.terms.size === 0 ? t.mul(this.constant) : new w(this.terms, /* @__PURE__ */ new Map(), this.constant).mul(t);
532
+ }
533
+ let r = Array.isArray(t.nonlinearTerms) && t.nonlinearTerms.length > 0;
534
+ if (this.hasNonlinearTerms()) {
535
+ if (t.terms.size === 0 && !r) return this.mul(t.constant);
536
+ throw Error("Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.");
537
+ }
538
+ if (r) {
539
+ if (this.terms.size === 0) return t.mul(this.constant);
540
+ throw Error("Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.");
541
+ }
542
+ return this.terms.size === 0 ? t.mul(this.constant) : t.terms.size === 0 ? this.mul(t.constant) : w.multiplyLinearTerms(this.constant, this.terms, t.constant, t.terms);
543
+ }
544
+ div(e) {
545
+ let t = w.extractScalarDivisor(e, "LinExpr.div()");
546
+ return this.mul(1 / t);
547
+ }
548
+ neg() {
549
+ return this.mul(-1);
550
+ }
551
+ get value() {
552
+ let e = this.constant;
553
+ for (let [t, n] of this.terms) {
554
+ if (t.value === null) return null;
555
+ e += n * t.value;
556
+ }
557
+ for (let t of this.nonlinearTerms) {
558
+ let n = y(t.atom);
559
+ if (n === null) return null;
560
+ e += t.coeff * n;
561
+ }
562
+ return e;
563
+ }
564
+ le(e, t) {
565
+ return this.toConstraint("<=", e, t);
566
+ }
567
+ ge(e, t) {
568
+ return this.toConstraint(">=", e, t);
569
+ }
570
+ eq(e, t) {
571
+ return this.toConstraint("==", e, t);
572
+ }
573
+ lt(e, t) {
574
+ return this.toDiscreteComparison("<", e, t);
575
+ }
576
+ gt(e, t) {
577
+ return this.toDiscreteComparison(">", e, t);
578
+ }
579
+ ne(e, t) {
580
+ return this.toDiscreteComparison("!=", e, t);
581
+ }
582
+ toDiscreteComparison(e, n, r) {
583
+ if (n instanceof t || typeof n == "object" && n && "sense" in n && "lhs" in n) throw Error(`Cannot compare against a Constraint in (${e}): expected a finite integer, discrete Var, or discrete LinExpr.`);
584
+ let i = `discrete ${e}`, a = /* @__PURE__ */ new Set();
585
+ x(this, i, a), x(n, i, a);
586
+ let o = this.toConstraint(e === "<" ? "<=" : e === ">" ? ">=" : "!=", n, r);
587
+ if (e === "<") {
588
+ let e = o.rhs - 1;
589
+ if (!Number.isSafeInteger(e)) throw Error(`Discrete comparison (<) adjusted right-hand side (${e}) exceeds safe integer range.`);
590
+ o.rhs = e;
591
+ } else if (e === ">") {
592
+ let e = o.rhs + 1;
593
+ if (!Number.isSafeInteger(e)) throw Error(`Discrete comparison (>) adjusted right-hand side (${e}) exceeds safe integer range.`);
594
+ o.rhs = e;
595
+ } else if (!Number.isSafeInteger(o.rhs)) throw Error(`Discrete comparison (!=) adjusted right-hand side (${o.rhs}) exceeds safe integer range.`);
596
+ return o._setDiscreteVars(a), o;
597
+ }
598
+ toConstraint(n, r, i) {
599
+ let a = this.clone(), o = 0;
600
+ if (typeof r == "number") o = r;
601
+ else if (r instanceof t || typeof r == "object" && r && "sense" in r && "lhs" in r) throw Error(`Cannot compare against a Constraint in (${n}): expected a number, Var, or LinExpr.`);
602
+ else if (r instanceof w || typeof r == "object" && r && "quadTerms" in r) {
603
+ let t = r;
604
+ if (t.quadTerms.size > 0) throw Error(`Quadratic expressions are not supported in linear constraints (${n}): quadratic terms are only allowed in objectives.`);
605
+ a = a.sub(new e(t.linearTerms, 0, t.nonlinearTerms ?? [])), o = t.constant;
606
+ } else "terms" in r ? (a = a.sub(new e(r.terms, 0, r.nonlinearTerms ?? [])), o = r.constant) : a = a.sub(r);
607
+ let s = o - a.constant;
608
+ return a.constant = 0, new t(a, n, s, i);
609
+ }
610
+ and(e) {
611
+ throw Error("Cannot use an arithmetic expression without a comparison operator (<=, >=, ==, !=, <, >) in logical 'and': expected a BoolVar, Constraint, or BoolOp.");
612
+ }
613
+ or(e) {
614
+ throw Error("Cannot use an arithmetic expression without a comparison operator (<=, >=, ==, !=, <, >) in logical 'or': expected a BoolVar, Constraint, or BoolOp.");
615
+ }
616
+ implies(e) {
617
+ throw Error("Cannot use an arithmetic expression without a comparison operator (<=, >=, ==, !=, <, >) in logical 'implies': expected a BoolVar, Constraint, or BoolOp.");
618
+ }
619
+ xor(e) {
620
+ throw Error("Cannot use an arithmetic expression without a comparison operator (<=, >=, ==, !=, <, >) in logical 'xor': expected a BoolVar, Constraint, or BoolOp.");
621
+ }
622
+ not() {
623
+ throw Error("Cannot use an arithmetic expression without a comparison operator (<=, >=, ==, !=, <, >) in logical 'not': expected a BoolVar, Constraint, or BoolOp.");
624
+ }
625
+ toString() {
626
+ let e = [], t = !0;
627
+ for (let [n, r] of this.terms) {
628
+ let i = r >= 0 ? t ? "" : "+ " : "- ", a = Math.abs(r), o = a === 1 ? "" : `${a} `;
629
+ e.push(`${i}${o}${n.name}`), t = !1;
630
+ }
631
+ for (let n of this.nonlinearTerms) {
632
+ let r = n.coeff, i = r >= 0 ? t ? "" : "+ " : "- ", a = Math.abs(r), o = a === 1 ? "" : `${a} `;
633
+ e.push(`${i}${o}${v(n.atom)}`), t = !1;
634
+ }
635
+ if (this.constant !== 0 || e.length === 0) {
636
+ let n = this.constant >= 0 ? t ? "" : "+ " : "- ";
637
+ e.push(`${n}${Math.abs(this.constant)}`);
638
+ }
639
+ return e.join(" ") || "0";
640
+ }
641
+ };
642
+ //#endregion
643
+ //#region src/modeler/quad-expr.ts
644
+ function C(e, t) {
645
+ let n = e.id, r = t.id;
646
+ return n <= r ? `${n}:${r}` : `${r}:${n}`;
647
+ }
648
+ var w = class e {
649
+ kind = "quadratic";
650
+ linearTerms;
651
+ quadTerms;
652
+ constant;
653
+ nonlinearTerms;
654
+ constructor(e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map(), n = 0, r = []) {
655
+ this.linearTerms = new Map(e), this.quadTerms = /* @__PURE__ */ new Map();
656
+ for (let [e, n] of t) this.quadTerms.set(e, { ...n });
657
+ this.constant = n, this.nonlinearTerms = r.filter((e) => e.coeff !== 0).map((e) => ({
658
+ atom: _(e.atom),
659
+ coeff: e.coeff
660
+ }));
661
+ }
662
+ hasNonlinearTerms() {
663
+ return this.nonlinearTerms.length > 0;
664
+ }
665
+ clone() {
666
+ return new e(this.linearTerms, this.quadTerms, this.constant, this.nonlinearTerms);
667
+ }
668
+ getQuadCoeff(e, t) {
669
+ let n = C(e, t), r = this.quadTerms.get(n);
670
+ return r ? r.coeff : 0;
671
+ }
672
+ add(t) {
673
+ if (n(t)) throw Error("Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.");
674
+ let r = this.clone();
675
+ if (typeof t == "number") return r.constant += t, r;
676
+ if (t instanceof e) {
677
+ for (let [e, n] of t.quadTerms) {
678
+ let t = r.quadTerms.get(e), i = (t ? t.coeff : 0) + n.coeff;
679
+ i === 0 ? r.quadTerms.delete(e) : r.quadTerms.set(e, {
680
+ var1: n.var1,
681
+ var2: n.var2,
682
+ coeff: i
683
+ });
684
+ }
685
+ for (let [e, n] of t.linearTerms) {
686
+ let t = (r.linearTerms.get(e) ?? 0) + n;
687
+ t === 0 ? r.linearTerms.delete(e) : r.linearTerms.set(e, t);
688
+ }
689
+ if (r.constant += t.constant, Array.isArray(t.nonlinearTerms)) for (let e of t.nonlinearTerms) e.coeff !== 0 && r.nonlinearTerms.push({
690
+ atom: _(e.atom),
691
+ coeff: e.coeff
692
+ });
693
+ return r;
694
+ }
695
+ if ("terms" in t && t.terms instanceof Map) {
696
+ for (let [e, n] of t.terms) {
697
+ let t = (r.linearTerms.get(e) ?? 0) + n;
698
+ t === 0 ? r.linearTerms.delete(e) : r.linearTerms.set(e, t);
699
+ }
700
+ if (r.constant += t.constant, Array.isArray(t.nonlinearTerms)) for (let e of t.nonlinearTerms) e.coeff !== 0 && r.nonlinearTerms.push({
701
+ atom: _(e.atom),
702
+ coeff: e.coeff
703
+ });
704
+ return r;
705
+ }
706
+ let i = t, a = (r.linearTerms.get(i) ?? 0) + 1;
707
+ return a === 0 ? r.linearTerms.delete(i) : r.linearTerms.set(i, a), r;
708
+ }
709
+ sub(e) {
710
+ if (n(e)) throw Error("Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.");
711
+ return typeof e == "number" ? this.add(-e) : this.add(e.mul(-1));
712
+ }
713
+ mul(t) {
714
+ if (n(t)) throw Error("Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.");
715
+ if (typeof t == "number") {
716
+ let n = this.linearTerms.size > 0 || this.quadTerms.size > 0 || this.nonlinearTerms.length > 0, r = this.constant === 0 && n ? 0 : this.constant * t;
717
+ if (this.constant !== 0 && t !== 0 && r === 0) throw Error("Constant multiplication underflows to zero.");
718
+ let i = new e(/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map(), r);
719
+ for (let [e, n] of this.linearTerms) {
720
+ let r = n * t;
721
+ if (n !== 0 && t !== 0 && r === 0) throw Error("Coefficient multiplication underflows to zero.");
722
+ r !== 0 && i.linearTerms.set(e, r);
723
+ }
724
+ for (let [e, n] of this.quadTerms) {
725
+ let r = n.coeff * t;
726
+ if (n.coeff !== 0 && t !== 0 && r === 0) throw Error("Coefficient multiplication underflows to zero.");
727
+ r !== 0 && i.quadTerms.set(e, {
728
+ var1: n.var1,
729
+ var2: n.var2,
730
+ coeff: r
731
+ });
732
+ }
733
+ if (t !== 0) for (let e of this.nonlinearTerms) {
734
+ let n = e.coeff * t;
735
+ if (e.coeff !== 0 && n === 0) throw Error("Coefficient multiplication underflows to zero.");
736
+ n !== 0 && i.nonlinearTerms.push({
737
+ atom: _(e.atom),
738
+ coeff: n
739
+ });
740
+ }
741
+ return i;
742
+ }
743
+ let r = "id" in t && "name" in t && !("terms" in t) && !("quadTerms" in t), i = "quadTerms" in t ? t.quadTerms.size : 0, a = !r && "nonlinearTerms" in t && Array.isArray(t.nonlinearTerms) ? t.nonlinearTerms.length : 0, o = r ? /* @__PURE__ */ new Map([[t, 1]]) : "quadTerms" in t ? t.linearTerms : t.terms, s = r ? 0 : t.constant;
744
+ if (this.nonlinearTerms.length > 0) {
745
+ if (!r && i === 0 && o.size === 0 && a === 0) return this.mul(s);
746
+ throw Error("Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.");
747
+ }
748
+ if (a > 0) {
749
+ if (this.quadTerms.size === 0 && this.linearTerms.size === 0) {
750
+ let n = t.mul(this.constant);
751
+ return "quadTerms" in n ? n : new e(n.terms, /* @__PURE__ */ new Map(), n.constant, n.nonlinearTerms);
752
+ }
753
+ throw Error("Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.");
754
+ }
755
+ if (this.quadTerms.size > 0 && (i > 0 || o.size > 0) || i > 0 && this.linearTerms.size > 0) throw Error("Multiplication creates a non-linear term of degree > 2 (not allowed in MILP/LP/QP)");
756
+ if (i === 0 && o.size === 0) return this.mul(s);
757
+ if (this.quadTerms.size === 0 && this.linearTerms.size === 0 && !r) {
758
+ let n = t.mul(this.constant);
759
+ return "quadTerms" in n ? n : new e(n.terms, /* @__PURE__ */ new Map(), n.constant, n.nonlinearTerms);
760
+ }
761
+ return e.multiplyLinearTerms(this.constant, this.linearTerms, s, o);
762
+ }
763
+ div(t) {
764
+ let n = e.extractScalarDivisor(t, "QuadExpr.div()");
765
+ return this.mul(1 / n);
766
+ }
767
+ neg() {
768
+ return this.mul(-1);
769
+ }
770
+ get value() {
771
+ let e = this.constant;
772
+ for (let [t, n] of this.linearTerms) {
773
+ if (t.value === null) return null;
774
+ e += n * t.value;
775
+ }
776
+ for (let t of this.quadTerms.values()) {
777
+ if (t.var1.value === null || t.var2.value === null) return null;
778
+ e += t.coeff * t.var1.value * t.var2.value;
779
+ }
780
+ for (let t of this.nonlinearTerms) {
781
+ let n = y(t.atom);
782
+ if (n === null) return null;
783
+ e += t.coeff * n;
784
+ }
785
+ return e;
786
+ }
787
+ le(e, t) {
788
+ return this.toConstraint("<=", e, t);
789
+ }
790
+ ge(e, t) {
791
+ return this.toConstraint(">=", e, t);
792
+ }
793
+ eq(e, t) {
794
+ return this.toConstraint("==", e, t);
795
+ }
796
+ lt(e, t) {
797
+ return this.toDiscreteComparison("<", e, t);
798
+ }
799
+ gt(e, t) {
800
+ return this.toDiscreteComparison(">", e, t);
801
+ }
802
+ ne(e, t) {
803
+ return this.toDiscreteComparison("!=", e, t);
804
+ }
805
+ toDiscreteComparison(e, t, n) {
806
+ if (this.quadTerms.size > 0) throw Error(`Quadratic expressions are not supported in discrete comparisons (${e}): quadratic terms are only allowed in objectives.`);
807
+ let r = new S(this.linearTerms, this.constant, this.nonlinearTerms);
808
+ return e === "<" ? r.lt(t, n) : e === ">" ? r.gt(t, n) : r.ne(t, n);
809
+ }
810
+ toConstraint(e, t, n) {
811
+ if (this.quadTerms.size > 0) throw Error(`Quadratic expressions are not supported in linear constraints (${e}): quadratic terms are only allowed in objectives.`);
812
+ let r = new S(this.linearTerms, this.constant, this.nonlinearTerms);
813
+ return e === "<=" ? r.le(t, n) : e === ">=" ? r.ge(t, n) : r.eq(t, n);
814
+ }
815
+ and(e) {
816
+ throw Error("Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical 'and': expected a BoolVar, Constraint, or BoolOp.");
817
+ }
818
+ or(e) {
819
+ throw Error("Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical 'or': expected a BoolVar, Constraint, or BoolOp.");
820
+ }
821
+ implies(e) {
822
+ throw Error("Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical 'implies': expected a BoolVar, Constraint, or BoolOp.");
823
+ }
824
+ xor(e) {
825
+ throw Error("Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical 'xor': expected a BoolVar, Constraint, or BoolOp.");
826
+ }
827
+ not() {
828
+ throw Error("Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical 'not': expected a BoolVar, Constraint, or BoolOp.");
829
+ }
830
+ toString() {
831
+ let e = [], t = !0;
832
+ for (let n of this.quadTerms.values()) {
833
+ let r = n.coeff, i = r >= 0 ? t ? "" : "+ " : "- ", a = Math.abs(r), o = a === 1 ? "" : `${a} `;
834
+ n.var1 === n.var2 ? e.push(`${i}${o}${n.var1.name}^2`) : e.push(`${i}${o}${n.var1.name} * ${n.var2.name}`), t = !1;
835
+ }
836
+ for (let [n, r] of this.linearTerms) {
837
+ let i = r >= 0 ? t ? "" : "+ " : "- ", a = Math.abs(r), o = a === 1 ? "" : `${a} `;
838
+ e.push(`${i}${o}${n.name}`), t = !1;
839
+ }
840
+ if (this.nonlinearTerms.length > 0) {
841
+ let n = new S(/* @__PURE__ */ new Map(), 0, this.nonlinearTerms).toString();
842
+ n !== "0" && (e.push(t ? n : n.startsWith("-") ? `- ${n.slice(2)}` : `+ ${n}`), t = !1);
843
+ }
844
+ if (this.constant !== 0 || e.length === 0) {
845
+ let n = this.constant >= 0 ? t ? "" : "+ " : "- ";
846
+ e.push(`${n}${Math.abs(this.constant)}`);
847
+ }
848
+ return e.join(" ") || "0";
849
+ }
850
+ static fromProduct(t, n, r = 1) {
851
+ let i = new e();
852
+ if (r === 0) return i;
853
+ let a = C(t, n);
854
+ return i.quadTerms.set(a, {
855
+ var1: t.id <= n.id ? t : n,
856
+ var2: t.id <= n.id ? n : t,
857
+ coeff: r
858
+ }), i;
859
+ }
860
+ static multiplyLinearTerms(t, n, r, i) {
861
+ let a = n.size > 0 || i.size > 0, o = (t === 0 || r === 0) && a ? 0 : t * r;
862
+ if (t !== 0 && r !== 0 && o === 0) throw Error("Constant multiplication underflows to zero.");
863
+ let s = new e(/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map(), o === 0 ? 0 : o);
864
+ if (r !== 0) for (let [e, t] of n) {
865
+ let n = t * r;
866
+ if (t !== 0 && n === 0) throw Error("Coefficient multiplication underflows to zero.");
867
+ n !== 0 && s.linearTerms.set(e, n);
868
+ }
869
+ if (t !== 0) for (let [e, n] of i) {
870
+ let r = s.linearTerms.get(e) ?? 0, i = n * t;
871
+ if (n !== 0 && i === 0) throw Error("Coefficient multiplication underflows to zero.");
872
+ let a = r + i;
873
+ a === 0 ? s.linearTerms.delete(e) : s.linearTerms.set(e, a);
874
+ }
875
+ for (let [t, r] of n) for (let [n, a] of i) {
876
+ let i = r * a;
877
+ if (r !== 0 && a !== 0 && i === 0) throw Error("Coefficient multiplication underflows to zero.");
878
+ s = s.add(e.fromProduct(t, n, i));
879
+ }
880
+ return s;
881
+ }
882
+ static extractScalarDivisor(e, t) {
883
+ if (n(e)) throw Error("Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.");
884
+ if (typeof e == "number") {
885
+ if (e === 0) throw Error(`Division by zero in ${t}`);
886
+ return e;
887
+ }
888
+ let r = "quadTerms" in e ? e.linearTerms.size : e.terms.size, i = "quadTerms" in e ? e.quadTerms.size : 0, a = "nonlinearTerms" in e && Array.isArray(e.nonlinearTerms) ? e.nonlinearTerms.length : 0;
889
+ if (r > 0 || i > 0 || a > 0) throw Error("Cannot divide by variable in expression");
890
+ if (e.constant === 0) throw Error(`Division by zero in ${t}`);
891
+ return e.constant;
892
+ }
893
+ }, T = Symbol.for("washi.solverRegistry"), E = Symbol.for("washi.defaultSolverFactory"), D = globalThis;
894
+ D[T] || (D[T] = /* @__PURE__ */ new Map());
895
+ var O = D[T];
896
+ function k(e, t) {
897
+ O.set(e.toLowerCase(), t);
898
+ }
899
+ function A(e) {
900
+ if (typeof e == "string") {
901
+ let t = O.get(e.toLowerCase());
902
+ if (!t) throw Error(`Solver '${e}' is not registered.`);
903
+ D[E] = t;
904
+ } else D[E] = typeof e == "function" ? e : () => e;
905
+ }
906
+ //#endregion
907
+ export { f as a, c, p as i, t as l, A as n, s as o, w as r, o as s, k as t };