@ohtaman/washi 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +138 -122
- package/README.md +138 -122
- package/README.zh-CN.md +140 -124
- package/dist/browser/solvers/glpk.js +10 -2
- package/dist/browser/solvers/glpk.min.js +1 -1
- package/dist/browser/solvers/z3.js +34 -12
- package/dist/browser/solvers/z3.min.js +2 -2
- package/dist/browser/washi.js +562 -397
- package/dist/browser/washi.min.js +4 -4
- package/dist/lib/{constraint-XWdn0ID9.js → constraint-BRuB3ooC.js} +0 -3
- package/dist/lib/solvers/glpk.js +10 -2
- package/dist/lib/solvers/z3.js +35 -10
- package/dist/lib/washi.js +562 -412
- package/dist/types/index.d.ts +5 -7
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modeler/constraint.d.ts +0 -3
- package/dist/types/modeler/constraint.d.ts.map +1 -1
- package/dist/types/modeler/expression.d.ts +23 -12
- package/dist/types/modeler/expression.d.ts.map +1 -1
- package/dist/types/modeler/index.d.ts +2 -4
- package/dist/types/modeler/index.d.ts.map +1 -1
- package/dist/types/modeler/model.d.ts +123 -40
- package/dist/types/modeler/model.d.ts.map +1 -1
- package/dist/types/modeler/parser.d.ts +9 -8
- package/dist/types/modeler/parser.d.ts.map +1 -1
- package/dist/types/modeler/quad-expr.d.ts +3 -1
- package/dist/types/modeler/quad-expr.d.ts.map +1 -1
- package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/solver.d.ts +1 -1
- package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
- package/dist/types/modeler/solvers/types.d.ts +1 -1
- package/dist/types/modeler/solvers/z3/loader.d.ts +12 -0
- package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
- package/dist/types/modeler/types.d.ts +8 -3
- package/dist/types/modeler/types.d.ts.map +1 -1
- package/dist/types/modeler/variable.d.ts +7 -6
- package/dist/types/modeler/variable.d.ts.map +1 -1
- package/package.json +11 -3
- package/dist/types/modeler/mip-compat.d.ts +0 -43
- package/dist/types/modeler/mip-compat.d.ts.map +0 -1
- package/dist/types/modeler/pulp-compat.d.ts +0 -67
- package/dist/types/modeler/pulp-compat.d.ts.map +0 -1
package/dist/lib/washi.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c } from "./constraint-
|
|
1
|
+
import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c } from "./constraint-BRuB3ooC.js";
|
|
2
2
|
import { i as l, n as u, r as d, t as f } from "./registry-DksqCSjI.js";
|
|
3
3
|
import { a as p, c as m, i as h, n as g, o as _, r as v, s as y, t as b } from "./loader-Dti0v9yC.js";
|
|
4
4
|
import { createHighsWorker as ee } from "./highs-worker-factory.js";
|
|
@@ -18,12 +18,17 @@ var x = Object.defineProperty, te = Object.getOwnPropertyDescriptor, ne = Object
|
|
|
18
18
|
return e;
|
|
19
19
|
}, w = (e, t, n) => (C(e, t, "default"), n && C(n, t, "default"));
|
|
20
20
|
//#endregion
|
|
21
|
+
//#region src/modeler/types.ts
|
|
22
|
+
function T(e) {
|
|
23
|
+
return e && e.toLowerCase() === "maximize" ? "Maximize" : "Minimize";
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
21
26
|
//#region src/modeler/quad-expr.ts
|
|
22
|
-
function
|
|
27
|
+
function E(e, t) {
|
|
23
28
|
let n = e.id, r = t.id;
|
|
24
29
|
return n <= r ? `${n}:${r}` : `${r}:${n}`;
|
|
25
30
|
}
|
|
26
|
-
var
|
|
31
|
+
var D = class e {
|
|
27
32
|
linearTerms;
|
|
28
33
|
quadTerms;
|
|
29
34
|
constant;
|
|
@@ -36,7 +41,7 @@ var E = class e {
|
|
|
36
41
|
return new e(this.linearTerms, this.quadTerms, this.constant);
|
|
37
42
|
}
|
|
38
43
|
getQuadCoeff(e, t) {
|
|
39
|
-
let n =
|
|
44
|
+
let n = E(e, t), r = this.quadTerms.get(n);
|
|
40
45
|
return r ? r.coeff : 0;
|
|
41
46
|
}
|
|
42
47
|
add(t) {
|
|
@@ -71,20 +76,45 @@ var E = class e {
|
|
|
71
76
|
return typeof t == "number" ? this.add(-t) : t instanceof e ? this.add(t.neg()) : ("terms" in t && t.terms instanceof Map, this.add(t.mul(-1)));
|
|
72
77
|
}
|
|
73
78
|
mul(t) {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
let
|
|
77
|
-
|
|
79
|
+
if (typeof t == "number") {
|
|
80
|
+
let n = new e(/* @__PURE__ */ new Map(), /* @__PURE__ */ new Map(), this.constant * t);
|
|
81
|
+
for (let [e, r] of this.linearTerms) {
|
|
82
|
+
let i = r * t;
|
|
83
|
+
Math.abs(i) >= 1e-12 && n.linearTerms.set(e, i);
|
|
84
|
+
}
|
|
85
|
+
for (let [e, r] of this.quadTerms) {
|
|
86
|
+
let i = r.coeff * t;
|
|
87
|
+
Math.abs(i) >= 1e-12 && n.quadTerms.set(e, {
|
|
88
|
+
var1: r.var1,
|
|
89
|
+
var2: r.var2,
|
|
90
|
+
coeff: i
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return n;
|
|
78
94
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
95
|
+
if ("id" in t && "name" in t && !("terms" in t) && !("quadTerms" in t)) {
|
|
96
|
+
if (this.quadTerms.size > 0) throw Error("Multiplication creates a non-linear term of degree > 2 (not allowed in MILP/LP/QP)");
|
|
97
|
+
let n = new e();
|
|
98
|
+
Math.abs(this.constant) >= 1e-12 && n.linearTerms.set(t, this.constant);
|
|
99
|
+
for (let [r, i] of this.linearTerms) n = n.add(e.fromProduct(r, t, i));
|
|
100
|
+
return n;
|
|
86
101
|
}
|
|
87
|
-
|
|
102
|
+
let n = t, r = "quadTerms" in n ? n.quadTerms.size : 0, i = "quadTerms" in n ? n.linearTerms : n.terms;
|
|
103
|
+
if (this.quadTerms.size > 0 && (r > 0 || i.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)");
|
|
104
|
+
if (r === 0 && i.size === 0) return this.mul(n.constant);
|
|
105
|
+
if (this.quadTerms.size === 0 && this.linearTerms.size === 0) {
|
|
106
|
+
let t = n.mul(this.constant);
|
|
107
|
+
if (t instanceof e) return t;
|
|
108
|
+
let r = new e();
|
|
109
|
+
r.constant = t.constant;
|
|
110
|
+
for (let [e, n] of t.terms) r.linearTerms.set(e, n);
|
|
111
|
+
return r;
|
|
112
|
+
}
|
|
113
|
+
let a = new e();
|
|
114
|
+
if (a.constant = this.constant * n.constant, Math.abs(n.constant) >= 1e-12) for (let [e, t] of this.linearTerms) a.linearTerms.set(e, (a.linearTerms.get(e) || 0) + t * n.constant);
|
|
115
|
+
if (Math.abs(this.constant) >= 1e-12) for (let [e, t] of i) a.linearTerms.set(e, (a.linearTerms.get(e) || 0) + t * this.constant);
|
|
116
|
+
for (let [t, n] of this.linearTerms) for (let [r, o] of i) a = a.add(e.fromProduct(t, r, n * o));
|
|
117
|
+
return a;
|
|
88
118
|
}
|
|
89
119
|
div(e) {
|
|
90
120
|
if (Math.abs(e) < 1e-12) throw Error("Division by zero in QuadExpr.div()");
|
|
@@ -108,15 +138,31 @@ var E = class e {
|
|
|
108
138
|
getValue() {
|
|
109
139
|
return this.value;
|
|
110
140
|
}
|
|
141
|
+
toString() {
|
|
142
|
+
let e = [], t = !0;
|
|
143
|
+
for (let n of this.quadTerms.values()) {
|
|
144
|
+
let r = n.coeff, i = r >= 0 ? t ? "" : "+ " : "- ", a = Math.abs(r), o = a === 1 ? "" : `${a} `;
|
|
145
|
+
n.var1 === n.var2 ? e.push(`${i}${o}${n.var1.name}^2`) : e.push(`${i}${o}${n.var1.name} * ${n.var2.name}`), t = !1;
|
|
146
|
+
}
|
|
147
|
+
for (let [n, r] of this.linearTerms) {
|
|
148
|
+
let i = r >= 0 ? t ? "" : "+ " : "- ", a = Math.abs(r), o = a === 1 ? "" : `${a} `;
|
|
149
|
+
e.push(`${i}${o}${n.name}`), t = !1;
|
|
150
|
+
}
|
|
151
|
+
if (this.constant !== 0 || e.length === 0) {
|
|
152
|
+
let n = this.constant >= 0 ? t ? "" : "+ " : "- ";
|
|
153
|
+
e.push(`${n}${Math.abs(this.constant)}`);
|
|
154
|
+
}
|
|
155
|
+
return e.join(" ") || "0";
|
|
156
|
+
}
|
|
111
157
|
static fromProduct(t, n, r = 1) {
|
|
112
|
-
let i = new e(), a =
|
|
158
|
+
let i = new e(), a = E(t, n);
|
|
113
159
|
return i.quadTerms.set(a, {
|
|
114
160
|
var1: t.id <= n.id ? t : n,
|
|
115
161
|
var2: t.id <= n.id ? n : t,
|
|
116
162
|
coeff: r
|
|
117
163
|
}), i;
|
|
118
164
|
}
|
|
119
|
-
},
|
|
165
|
+
}, O = class e {
|
|
120
166
|
terms;
|
|
121
167
|
constant;
|
|
122
168
|
constructor(e = /* @__PURE__ */ new Map(), t = 0) {
|
|
@@ -126,7 +172,7 @@ var E = class e {
|
|
|
126
172
|
return new e(this.terms, this.constant);
|
|
127
173
|
}
|
|
128
174
|
add(e) {
|
|
129
|
-
if (e instanceof
|
|
175
|
+
if (e instanceof D) return e.add(this);
|
|
130
176
|
let t = this.clone();
|
|
131
177
|
if (typeof e == "number") t.constant += e;
|
|
132
178
|
else if ("terms" in e) {
|
|
@@ -142,7 +188,7 @@ var E = class e {
|
|
|
142
188
|
return t;
|
|
143
189
|
}
|
|
144
190
|
sub(e) {
|
|
145
|
-
return e instanceof
|
|
191
|
+
return e instanceof D ? e.neg().add(this) : typeof e == "number" ? this.add(-e) : ("terms" in e, this.add(e.mul(-1)));
|
|
146
192
|
}
|
|
147
193
|
mul(t) {
|
|
148
194
|
if (typeof t == "number") {
|
|
@@ -153,9 +199,27 @@ var E = class e {
|
|
|
153
199
|
}
|
|
154
200
|
return n;
|
|
155
201
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
202
|
+
if (t instanceof M || typeof t == "object" && t && "id" in t && !("terms" in t) && !("quadTerms" in t)) {
|
|
203
|
+
let e = t, n = new D();
|
|
204
|
+
Math.abs(this.constant) >= 1e-12 && n.linearTerms.set(e, this.constant);
|
|
205
|
+
for (let [t, r] of this.terms) n = n.add(D.fromProduct(t, e, r));
|
|
206
|
+
return n;
|
|
207
|
+
}
|
|
208
|
+
if (t instanceof D) {
|
|
209
|
+
if (t.quadTerms.size > 0 && this.terms.size > 0) throw Error("Multiplication creates a non-linear term of degree > 2 (not allowed in MILP/LP/QP)");
|
|
210
|
+
if (this.terms.size === 0) return t.mul(this.constant);
|
|
211
|
+
let e = new D();
|
|
212
|
+
if (e.constant = this.constant * t.constant, Math.abs(t.constant) >= 1e-12) for (let [n, r] of this.terms) e.linearTerms.set(n, (e.linearTerms.get(n) || 0) + r * t.constant);
|
|
213
|
+
if (Math.abs(this.constant) >= 1e-12) for (let [n, r] of t.linearTerms) e.linearTerms.set(n, (e.linearTerms.get(n) || 0) + r * this.constant);
|
|
214
|
+
for (let [n, r] of this.terms) for (let [i, a] of t.linearTerms) e = e.add(D.fromProduct(n, i, r * a));
|
|
215
|
+
return e;
|
|
216
|
+
}
|
|
217
|
+
if (this.terms.size === 0) return t.mul(this.constant);
|
|
218
|
+
if (t.terms.size === 0) return this.mul(t.constant);
|
|
219
|
+
let n = new D();
|
|
220
|
+
if (n.constant = this.constant * t.constant, Math.abs(t.constant) >= 1e-12) for (let [e, r] of this.terms) n.linearTerms.set(e, (n.linearTerms.get(e) || 0) + r * t.constant);
|
|
221
|
+
if (Math.abs(this.constant) >= 1e-12) for (let [e, r] of t.terms) n.linearTerms.set(e, (n.linearTerms.get(e) || 0) + r * this.constant);
|
|
222
|
+
for (let [e, r] of this.terms) for (let [i, a] of t.terms) n = n.add(D.fromProduct(e, i, r * a));
|
|
159
223
|
return n;
|
|
160
224
|
}
|
|
161
225
|
div(e) {
|
|
@@ -213,27 +277,113 @@ var E = class e {
|
|
|
213
277
|
return e.join(" ") || "0";
|
|
214
278
|
}
|
|
215
279
|
};
|
|
216
|
-
function
|
|
217
|
-
let n = /* @__PURE__ */ new Map(), r = 0
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
280
|
+
function k(e, t) {
|
|
281
|
+
let n = /* @__PURE__ */ new Map(), r = 0;
|
|
282
|
+
function i(e) {
|
|
283
|
+
if (e != null) {
|
|
284
|
+
if (typeof e == "number") r += e;
|
|
285
|
+
else if (typeof e == "object" && "terms" in e) {
|
|
286
|
+
let t = e;
|
|
287
|
+
for (let [e, r] of t.terms) {
|
|
288
|
+
let t = n.get(e) || 0;
|
|
289
|
+
n.set(e, t + r);
|
|
290
|
+
}
|
|
291
|
+
r += t.constant;
|
|
292
|
+
} else {
|
|
293
|
+
let t = e, r = n.get(t) || 0;
|
|
294
|
+
n.set(t, r + 1);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
if (typeof e == "number") {
|
|
299
|
+
let n = e, r = t;
|
|
300
|
+
for (let e = 0; e < n; e++) i(r(e, e));
|
|
301
|
+
} else {
|
|
302
|
+
let n = 0;
|
|
303
|
+
for (let r of e) i(t ? t(r, n++) : r);
|
|
304
|
+
}
|
|
305
|
+
for (let [e, t] of n) Math.abs(t) < 1e-12 && n.delete(e);
|
|
306
|
+
return new O(n, r);
|
|
307
|
+
}
|
|
308
|
+
function A(e, t) {
|
|
309
|
+
let n = /* @__PURE__ */ new Map(), r = 0;
|
|
310
|
+
function i(e) {
|
|
311
|
+
return typeof e == "object" && !!e && typeof e.id == "number" && typeof e.name == "string" && typeof e.mul == "function" && typeof e.le == "function";
|
|
312
|
+
}
|
|
313
|
+
function a(e) {
|
|
314
|
+
return i(e) || e instanceof O || e instanceof D;
|
|
315
|
+
}
|
|
316
|
+
function o(e, t) {
|
|
317
|
+
if (typeof t == "number") r += e * t;
|
|
318
|
+
else if (t instanceof O) {
|
|
319
|
+
for (let [r, i] of t.terms) {
|
|
320
|
+
let t = n.get(r) || 0;
|
|
321
|
+
n.set(r, t + e * i);
|
|
226
322
|
}
|
|
227
|
-
r += t.constant;
|
|
228
|
-
} else if (
|
|
229
|
-
let
|
|
230
|
-
n.set(
|
|
323
|
+
r += e * t.constant;
|
|
324
|
+
} else if (i(t)) {
|
|
325
|
+
let r = t, i = n.get(r) || 0;
|
|
326
|
+
n.set(r, i + e);
|
|
327
|
+
} else throw Error("Cannot multiply number by non-variable/expression operand in dot().");
|
|
328
|
+
}
|
|
329
|
+
function s(e) {
|
|
330
|
+
return typeof e == "object" && !!e && !Array.isArray(e) && !a(e);
|
|
331
|
+
}
|
|
332
|
+
function c(e, t, n = "") {
|
|
333
|
+
if (e === void 0 || t === void 0 || e === null || t === null) throw Error(`Nullish or undefined operand encountered in dot() at '${n || "root"}'.`);
|
|
334
|
+
if (typeof e == "number") {
|
|
335
|
+
o(e, t);
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
if (typeof t == "number") {
|
|
339
|
+
o(t, e);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
if (Array.isArray(e) || Array.isArray(t)) {
|
|
343
|
+
if (Array.isArray(e) && Array.isArray(t)) {
|
|
344
|
+
if (e.length !== t.length) throw Error(`Array length mismatch in dot() at '${n || "root"}': received lengths ${e.length} and ${t.length}.`);
|
|
345
|
+
for (let r = 0; r < e.length; r++) c(e[r], t[r], n ? `${n}[${r}]` : `[${r}]`);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
let r = Array.isArray(e) ? e : t, i = Array.isArray(e) ? t : e;
|
|
349
|
+
if (s(i)) {
|
|
350
|
+
let a = Object.keys(i);
|
|
351
|
+
if (a.length > 0 && a.every((e) => /^\d+$/.test(e))) {
|
|
352
|
+
if (a.length !== r.length) throw Error(`Array length mismatch in dot() at '${n || "root"}': array has length ${r.length}, but object has ${a.length} indices.`);
|
|
353
|
+
let o = [];
|
|
354
|
+
for (let e = 0; e < r.length; e++) !(e in i) && !(String(e) in i) && o.push(e);
|
|
355
|
+
if (o.length > 0) throw Error(`Key mismatch in dot() at '${n || "root"}': missing indices [${o.join(", ")}] in numeric record.`);
|
|
356
|
+
for (let i = 0; i < r.length; i++) c(e[i], t[i], n ? `${n}[${i}]` : `[${i}]`);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
throw Error(`Type mismatch in dot() at '${n || "root"}': one operand is an Array while the other is an Object with keys [${a.slice(0, 5).join(", ")}].`);
|
|
360
|
+
}
|
|
361
|
+
throw Error(`Type mismatch in dot() at '${n || "root"}': one operand is an Array while the other is not.`);
|
|
362
|
+
}
|
|
363
|
+
if (s(e) && s(t)) {
|
|
364
|
+
let r = Object.keys(e), i = Object.keys(t), a = r.filter((e) => !(e in t)), o = i.filter((t) => !(t in e));
|
|
365
|
+
if (a.length > 0 || o.length > 0) {
|
|
366
|
+
let e = [];
|
|
367
|
+
throw a.length > 0 && e.push(`missing in second operand: [${a.join(", ")}]`), o.length > 0 && e.push(`missing in first operand: [${o.join(", ")}]`), Error(`Key mismatch in dot() at '${n || "root"}': ${e.join("; ")}.`);
|
|
368
|
+
}
|
|
369
|
+
for (let i of r) c(e[i], t[i], n ? `${n}.${i}` : i);
|
|
370
|
+
return;
|
|
231
371
|
}
|
|
372
|
+
throw Error(`Unsupported operand types in dot() at '${n || "root"}'.`);
|
|
232
373
|
}
|
|
374
|
+
c(e, t);
|
|
233
375
|
for (let [e, t] of n) Math.abs(t) < 1e-12 && n.delete(e);
|
|
234
|
-
return new
|
|
376
|
+
return new O(n, r);
|
|
377
|
+
}
|
|
378
|
+
//#endregion
|
|
379
|
+
//#region src/modeler/variable.ts
|
|
380
|
+
var j = 0;
|
|
381
|
+
function ie(e) {
|
|
382
|
+
if (!e) return "Continuous";
|
|
383
|
+
let t = e.toLowerCase();
|
|
384
|
+
return t === "binary" || t === "bin" ? "Binary" : t === "integer" || t === "int" ? "Integer" : "Continuous";
|
|
235
385
|
}
|
|
236
|
-
var
|
|
386
|
+
var M = class e {
|
|
237
387
|
id;
|
|
238
388
|
name;
|
|
239
389
|
type;
|
|
@@ -242,48 +392,49 @@ var k = O, A = O, ie = 0, j = class e {
|
|
|
242
392
|
value = null;
|
|
243
393
|
reducedCost = null;
|
|
244
394
|
constructor(e = {}) {
|
|
245
|
-
this.id = ++
|
|
246
|
-
}
|
|
247
|
-
get x() {
|
|
248
|
-
return this.value;
|
|
249
|
-
}
|
|
250
|
-
get varValue() {
|
|
251
|
-
return this.value;
|
|
395
|
+
this.id = ++j, this.name = e.name || `x_${this.id}`, this.type = ie(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);
|
|
252
396
|
}
|
|
253
397
|
mul(t) {
|
|
254
|
-
if (typeof t == "number") return new
|
|
255
|
-
if (t instanceof e) return
|
|
256
|
-
|
|
398
|
+
if (typeof t == "number") return new O(/* @__PURE__ */ new Map([[this, t]]), 0);
|
|
399
|
+
if (t instanceof e) return D.fromProduct(this, t, 1);
|
|
400
|
+
if (t instanceof D) {
|
|
401
|
+
if (t.quadTerms.size > 0) throw Error("Multiplication creates a non-linear term of degree > 2 (not allowed in MILP/LP/QP)");
|
|
402
|
+
let e = new D();
|
|
403
|
+
Math.abs(t.constant) >= 1e-12 && e.linearTerms.set(this, t.constant);
|
|
404
|
+
for (let [n, r] of t.linearTerms) e = e.add(D.fromProduct(this, n, r));
|
|
405
|
+
return e;
|
|
406
|
+
}
|
|
407
|
+
let n = new D();
|
|
257
408
|
Math.abs(t.constant) >= 1e-12 && n.linearTerms.set(this, t.constant);
|
|
258
409
|
for (let [e, r] of t.terms) {
|
|
259
|
-
let t =
|
|
410
|
+
let t = D.fromProduct(this, e, r);
|
|
260
411
|
n = n.add(t);
|
|
261
412
|
}
|
|
262
413
|
return n;
|
|
263
414
|
}
|
|
264
415
|
add(e) {
|
|
265
|
-
return e instanceof
|
|
416
|
+
return e instanceof D ? e.add(this) : new O(/* @__PURE__ */ new Map([[this, 1]]), 0).add(e);
|
|
266
417
|
}
|
|
267
418
|
sub(e) {
|
|
268
|
-
return e instanceof
|
|
419
|
+
return e instanceof D ? e.neg().add(this) : new O(/* @__PURE__ */ new Map([[this, 1]]), 0).sub(e);
|
|
269
420
|
}
|
|
270
421
|
neg() {
|
|
271
422
|
return this.mul(-1);
|
|
272
423
|
}
|
|
273
424
|
le(e, t) {
|
|
274
|
-
return new
|
|
425
|
+
return new O(/* @__PURE__ */ new Map([[this, 1]]), 0).le(e, t);
|
|
275
426
|
}
|
|
276
427
|
lessThanOrEqual(e, t) {
|
|
277
428
|
return this.le(e, t);
|
|
278
429
|
}
|
|
279
430
|
ge(e, t) {
|
|
280
|
-
return new
|
|
431
|
+
return new O(/* @__PURE__ */ new Map([[this, 1]]), 0).ge(e, t);
|
|
281
432
|
}
|
|
282
433
|
greaterThanOrEqual(e, t) {
|
|
283
434
|
return this.ge(e, t);
|
|
284
435
|
}
|
|
285
436
|
eq(e, t) {
|
|
286
|
-
return new
|
|
437
|
+
return new O(/* @__PURE__ */ new Map([[this, 1]]), 0).eq(e, t);
|
|
287
438
|
}
|
|
288
439
|
equalTo(e, t) {
|
|
289
440
|
return this.eq(e, t);
|
|
@@ -310,9 +461,16 @@ function ae(e) {
|
|
|
310
461
|
type: "MINUS",
|
|
311
462
|
value: "-"
|
|
312
463
|
}), n++;
|
|
313
|
-
else if (i === "*") t.push({
|
|
464
|
+
else if (i === "*") n + 1 < r && e[n + 1] === "*" ? (t.push({
|
|
465
|
+
type: "CARET",
|
|
466
|
+
value: "**"
|
|
467
|
+
}), n += 2) : (t.push({
|
|
314
468
|
type: "STAR",
|
|
315
469
|
value: "*"
|
|
470
|
+
}), n++);
|
|
471
|
+
else if (i === "^") t.push({
|
|
472
|
+
type: "CARET",
|
|
473
|
+
value: "^"
|
|
316
474
|
}), n++;
|
|
317
475
|
else if (i === "/") t.push({
|
|
318
476
|
type: "SLASH",
|
|
@@ -350,7 +508,24 @@ function ae(e) {
|
|
|
350
508
|
}
|
|
351
509
|
return t;
|
|
352
510
|
}
|
|
353
|
-
|
|
511
|
+
function oe(e, t) {
|
|
512
|
+
return e instanceof D ? e.add(t) : t instanceof D ? t.add(e) : e.add(t);
|
|
513
|
+
}
|
|
514
|
+
function se(e, t) {
|
|
515
|
+
return e instanceof D ? e.sub(t) : t instanceof D ? t.neg().add(e) : e.sub(t);
|
|
516
|
+
}
|
|
517
|
+
function N(e, t) {
|
|
518
|
+
let n = e instanceof D ? e.quadTerms : /* @__PURE__ */ new Map(), r = t instanceof D ? t.quadTerms : /* @__PURE__ */ new Map(), i = e instanceof D ? e.linearTerms : e.terms, a = t instanceof D ? t.linearTerms : t.terms;
|
|
519
|
+
if (n.size > 0 && (r.size > 0 || a.size > 0) || r.size > 0 && (n.size > 0 || i.size > 0)) throw Error("Multiplication creates a non-linear term of degree > 2 (not allowed in MILP/LP/QP)");
|
|
520
|
+
if (n.size === 0 && i.size === 0) return t.mul(e.constant);
|
|
521
|
+
if (r.size === 0 && a.size === 0) return e.mul(t.constant);
|
|
522
|
+
let o = new D();
|
|
523
|
+
if (o.constant = e.constant * t.constant, Math.abs(t.constant) >= 1e-12) for (let [e, n] of i) o.linearTerms.set(e, (o.linearTerms.get(e) || 0) + n * t.constant);
|
|
524
|
+
if (Math.abs(e.constant) >= 1e-12) for (let [t, n] of a) o.linearTerms.set(t, (o.linearTerms.get(t) || 0) + n * e.constant);
|
|
525
|
+
for (let [e, t] of i) for (let [n, r] of a) o = o.add(D.fromProduct(e, n, t * r));
|
|
526
|
+
return o;
|
|
527
|
+
}
|
|
528
|
+
var ce = class {
|
|
354
529
|
tokens;
|
|
355
530
|
pos = 0;
|
|
356
531
|
resolver;
|
|
@@ -371,11 +546,11 @@ var oe = class {
|
|
|
371
546
|
for (; this.pos < this.tokens.length;) {
|
|
372
547
|
let t = this.peek();
|
|
373
548
|
if (!t) break;
|
|
374
|
-
if (t.type === "PLUS") this.consume(), e = e
|
|
375
|
-
else if (t.type === "MINUS") this.consume(), e = e
|
|
549
|
+
if (t.type === "PLUS") this.consume(), e = oe(e, this.parseTerm());
|
|
550
|
+
else if (t.type === "MINUS") this.consume(), e = se(e, this.parseTerm());
|
|
376
551
|
else break;
|
|
377
552
|
}
|
|
378
|
-
return e;
|
|
553
|
+
return e instanceof D && e.quadTerms.size === 0 ? new O(e.linearTerms, e.constant) : e;
|
|
379
554
|
}
|
|
380
555
|
parseTerm() {
|
|
381
556
|
let e = this.parseFactor();
|
|
@@ -385,57 +560,83 @@ var oe = class {
|
|
|
385
560
|
if (t.type === "STAR") {
|
|
386
561
|
this.consume();
|
|
387
562
|
let t = this.parseFactor();
|
|
388
|
-
e =
|
|
563
|
+
e = N(e, t);
|
|
389
564
|
} else if (t.type === "SLASH") {
|
|
390
565
|
this.consume();
|
|
391
|
-
let t = this.parseFactor();
|
|
392
|
-
if (
|
|
566
|
+
let t = this.parseFactor(), n = t instanceof D ? t.linearTerms : t.terms, r = t instanceof D ? t.quadTerms.size : 0;
|
|
567
|
+
if (n.size > 0 || r > 0) throw Error("Cannot divide by variable in expression");
|
|
393
568
|
if (Math.abs(t.constant) < 1e-12) throw Error("Division by zero in expression");
|
|
394
569
|
e = e.div(t.constant);
|
|
395
570
|
} else break;
|
|
396
571
|
}
|
|
397
572
|
return e;
|
|
398
573
|
}
|
|
399
|
-
multiplyExpressions(e, t) {
|
|
400
|
-
if (e.terms.size > 0 && t.terms.size > 0) throw Error("Multiplication of two variables creates a non-linear term (not allowed in MILP/LP)");
|
|
401
|
-
return e.terms.size === 0 ? t.mul(e.constant) : e.mul(t.constant);
|
|
402
|
-
}
|
|
403
574
|
parseFactor() {
|
|
404
575
|
let e = this.peek();
|
|
405
576
|
if (!e) throw Error("Unexpected end of expression");
|
|
406
577
|
if (e.type === "PLUS") return this.consume(), this.parseFactor();
|
|
407
578
|
if (e.type === "MINUS") return this.consume(), this.parseFactor().neg();
|
|
579
|
+
let t;
|
|
408
580
|
if (e.type === "NUMBER") {
|
|
409
581
|
this.consume();
|
|
410
|
-
let
|
|
411
|
-
if (this.peek()?.type === "IDENT") {
|
|
412
|
-
let e
|
|
413
|
-
|
|
582
|
+
let n = parseFloat(e.value);
|
|
583
|
+
if (this.peek()?.type === "IDENT" || this.peek()?.type === "LPAREN") {
|
|
584
|
+
let e;
|
|
585
|
+
if (this.peek()?.type === "IDENT") {
|
|
586
|
+
let t = this.consume(), n = this.resolve(t.value);
|
|
587
|
+
e = n instanceof M || "id" in n && !("terms" in n) && !("quadTerms" in n) ? new O(/* @__PURE__ */ new Map([[n, 1]]), 0) : n.clone();
|
|
588
|
+
} else this.consume("LPAREN"), e = this.parseExpression(), this.consume("RPAREN");
|
|
589
|
+
return this.applyPower(e).mul(n);
|
|
414
590
|
}
|
|
415
|
-
|
|
416
|
-
}
|
|
417
|
-
|
|
591
|
+
t = new O(/* @__PURE__ */ new Map(), n);
|
|
592
|
+
} else if (e.type === "IDENT") {
|
|
593
|
+
this.consume();
|
|
594
|
+
let n = this.resolve(e.value);
|
|
595
|
+
t = n instanceof M || "id" in n && !("terms" in n) && !("quadTerms" in n) ? new O(/* @__PURE__ */ new Map([[n, 1]]), 0) : n.clone();
|
|
596
|
+
} else if (e.type === "LPAREN") this.consume("LPAREN"), t = this.parseExpression(), this.consume("RPAREN");
|
|
597
|
+
else throw Error(`Unexpected token '${e.value}' in expression`);
|
|
598
|
+
return this.applyPower(t);
|
|
599
|
+
}
|
|
600
|
+
applyPower(e) {
|
|
601
|
+
if (this.peek()?.type !== "CARET") return e;
|
|
602
|
+
let t = [];
|
|
603
|
+
for (; this.peek()?.type === "CARET";) {
|
|
604
|
+
this.consume();
|
|
605
|
+
let e = this.peek();
|
|
606
|
+
if (!e || e.type !== "NUMBER") throw Error("Exponent must be a non-negative integer number");
|
|
418
607
|
this.consume();
|
|
419
|
-
let
|
|
420
|
-
|
|
608
|
+
let n = parseFloat(e.value);
|
|
609
|
+
if (!Number.isInteger(n) || n < 0) throw Error("Exponent must be a non-negative integer");
|
|
610
|
+
t.push(n);
|
|
421
611
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
612
|
+
let n = t[t.length - 1];
|
|
613
|
+
for (let e = t.length - 2; e >= 0; e--) n = t[e] ** +n;
|
|
614
|
+
if (!Number.isFinite(n) || n < 0) throw Error("Exponent creates an invalid or out-of-range power");
|
|
615
|
+
let r = e instanceof D, i = r ? e.quadTerms.size : 0, a = r ? e.linearTerms.size : e.terms.size;
|
|
616
|
+
if (i === 0 && a === 0) {
|
|
617
|
+
let t = e.constant ** +n;
|
|
618
|
+
return new O(/* @__PURE__ */ new Map(), t);
|
|
426
619
|
}
|
|
427
|
-
|
|
620
|
+
if (n === 0) return new O(/* @__PURE__ */ new Map(), 1);
|
|
621
|
+
if (n === 1) return e;
|
|
622
|
+
if (n === 2) return N(e, e);
|
|
623
|
+
throw Error(`Exponent ${n} creates a non-linear term of degree > 2 (not allowed in MILP/LP/QP)`);
|
|
428
624
|
}
|
|
429
|
-
|
|
625
|
+
getRemainingToken() {
|
|
626
|
+
return this.peek();
|
|
627
|
+
}
|
|
628
|
+
resolve(e) {
|
|
430
629
|
let t = this.resolver(e);
|
|
431
630
|
if (!t) throw Error(`Unknown variable '${e}' in expression`);
|
|
432
631
|
return t;
|
|
433
632
|
}
|
|
434
633
|
};
|
|
435
|
-
function
|
|
436
|
-
|
|
634
|
+
function P(e, t) {
|
|
635
|
+
let n = new ce(ae(e), t), r = n.parseExpression(), i = n.getRemainingToken();
|
|
636
|
+
if (i) throw Error(`Unexpected token '${i.value}' after expression in "${e}"`);
|
|
637
|
+
return r;
|
|
437
638
|
}
|
|
438
|
-
function
|
|
639
|
+
function F(e, t, n) {
|
|
439
640
|
let r = e.match(/(<=|>=|==|=<|=>|=)/);
|
|
440
641
|
if (!r) throw Error(`Constraint must contain a comparison operator (<=, >=, ==, =): "${e}"`);
|
|
441
642
|
let i = r[0], a = r.index, o = e.substring(0, a).trim(), s = e.substring(a + i.length).trim(), c;
|
|
@@ -443,20 +644,19 @@ function N(e, t, n) {
|
|
|
443
644
|
else if (i === ">=" || i === "=>") c = ">=";
|
|
444
645
|
else if (i === "==" || i === "=") c = "==";
|
|
445
646
|
else throw Error(`Unsupported operator "${i}"`);
|
|
446
|
-
let l =
|
|
447
|
-
|
|
647
|
+
let l = P(o, t), u = P(s, t);
|
|
648
|
+
if (l instanceof D && l.quadTerms.size > 0 || u instanceof D && u.quadTerms.size > 0) throw Error("Quadratic constraints are not supported (only linear constraints are allowed in MILP/LP/QP)");
|
|
649
|
+
let d = l instanceof D ? new O(l.linearTerms, l.constant) : l, f = u instanceof D ? new O(u.linearTerms, u.constant) : u;
|
|
650
|
+
return c === "<=" ? d.le(f, n) : c === ">=" ? d.ge(f, n) : d.eq(f, n);
|
|
448
651
|
}
|
|
449
|
-
function
|
|
652
|
+
function I(e, t) {
|
|
450
653
|
let n = /* @__PURE__ */ new Map(), r = "";
|
|
451
654
|
for (let i = 0; i < e.length; i++) if (r += e[i], i < t.length) {
|
|
452
655
|
let e = t[i];
|
|
453
656
|
if (typeof e == "number") r += `(${e})`;
|
|
454
|
-
else if (e instanceof
|
|
455
|
-
let t = `
|
|
657
|
+
else if (e instanceof M || e instanceof O || e instanceof D || typeof e == "object" && e && ("id" in e || "terms" in e || "quadTerms" in e)) {
|
|
658
|
+
let t = `__ph_${i}__`;
|
|
456
659
|
n.set(t, e), r += t;
|
|
457
|
-
} else if (e instanceof D) {
|
|
458
|
-
`${i}`, r += `(${e.toString()})`;
|
|
459
|
-
for (let [t] of e.terms) n.set(t.name, t);
|
|
460
660
|
}
|
|
461
661
|
}
|
|
462
662
|
return {
|
|
@@ -464,42 +664,42 @@ function P(e, t) {
|
|
|
464
664
|
resolver: (e) => n.get(e)
|
|
465
665
|
};
|
|
466
666
|
}
|
|
467
|
-
function
|
|
468
|
-
let { fullText: n, resolver: r } =
|
|
469
|
-
return
|
|
667
|
+
function L(e, ...t) {
|
|
668
|
+
let { fullText: n, resolver: r } = I(e, t);
|
|
669
|
+
return F(n, r);
|
|
470
670
|
}
|
|
471
|
-
function
|
|
472
|
-
let { fullText: n, resolver: r } =
|
|
473
|
-
return /(<=|>=|==|=<|=>|=)/.test(n) ?
|
|
671
|
+
function R(e, ...t) {
|
|
672
|
+
let { fullText: n, resolver: r } = I(e, t);
|
|
673
|
+
return /(<=|>=|==|=<|=>|=)/.test(n) ? F(n, r) : P(n, r);
|
|
474
674
|
}
|
|
475
675
|
//#endregion
|
|
476
676
|
//#region src/modeler/lp-writer.ts
|
|
477
|
-
function
|
|
677
|
+
function z(e, t, n) {
|
|
478
678
|
let r = e.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
479
679
|
return /^[0-9]/.test(r) && (r = `${t}_${r}`), (!r || r.length === 0) && (r = `${t}_${n}`), r;
|
|
480
680
|
}
|
|
481
|
-
function
|
|
681
|
+
function B(e) {
|
|
482
682
|
let { sense: t, objective: n, constraints: r, variables: i } = e, a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Set();
|
|
483
683
|
for (let e of i) {
|
|
484
|
-
let t =
|
|
684
|
+
let t = z(e.name, "x", e.id), n = t, r = 1;
|
|
485
685
|
for (; c.has(n);) n = `${t}_${r++}`;
|
|
486
686
|
c.add(n), o.set(e, n), a.set(n, e);
|
|
487
687
|
}
|
|
488
688
|
let l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Map();
|
|
489
689
|
for (let e of r) {
|
|
490
|
-
let t =
|
|
690
|
+
let t = z(e.name, "c", e.id), n = t, r = 1;
|
|
491
691
|
for (; l.has(n);) n = `${t}_${r++}`;
|
|
492
692
|
l.add(n), u.set(e, n), s.set(n, e);
|
|
493
693
|
}
|
|
494
694
|
let d = [];
|
|
495
|
-
d.push(t === "
|
|
496
|
-
let f = [], p = !0, m = n instanceof
|
|
695
|
+
d.push(t && t.toLowerCase() === "maximize" ? "Maximize" : "Minimize");
|
|
696
|
+
let f = [], p = !0, m = n instanceof D ? n.linearTerms : n.terms;
|
|
497
697
|
if (m) for (let [e, t] of m) {
|
|
498
698
|
if (Math.abs(t) < 1e-12) continue;
|
|
499
699
|
let n = o.get(e), r = t >= 0 ? p ? "" : "+ " : "- ", i = Math.abs(t), a = i === 1 ? "" : `${i} `;
|
|
500
700
|
f.push(`${r}${a}${n}`), p = !1;
|
|
501
701
|
}
|
|
502
|
-
if (n instanceof
|
|
702
|
+
if (n instanceof D && n.quadTerms.size > 0) {
|
|
503
703
|
let e = [], t = !0;
|
|
504
704
|
for (let r of n.quadTerms.values()) {
|
|
505
705
|
if (Math.abs(r.coeff) < 1e-12) continue;
|
|
@@ -551,41 +751,41 @@ function F(e) {
|
|
|
551
751
|
}
|
|
552
752
|
//#endregion
|
|
553
753
|
//#region src/modeler/solvers/highs/worker-client.ts
|
|
554
|
-
var
|
|
555
|
-
function
|
|
754
|
+
var V = null, le = 0, H = /* @__PURE__ */ new Map();
|
|
755
|
+
function ue() {
|
|
556
756
|
if (typeof window > "u" || typeof Worker > "u") return null;
|
|
557
|
-
if (!
|
|
558
|
-
|
|
559
|
-
let e =
|
|
560
|
-
|
|
561
|
-
let { type: t, id: n, result: r, runTime: i, error: a } = e.data, o =
|
|
562
|
-
o && (
|
|
757
|
+
if (!V) try {
|
|
758
|
+
V = ee();
|
|
759
|
+
let e = V;
|
|
760
|
+
V.onmessage = (e) => {
|
|
761
|
+
let { type: t, id: n, result: r, runTime: i, error: a } = e.data, o = H.get(n);
|
|
762
|
+
o && (H.delete(n), t === "SOLVE_SUCCESS" ? o.resolve({
|
|
563
763
|
result: r,
|
|
564
764
|
runTime: i
|
|
565
765
|
}) : o.reject(Error(a || "Worker solve failed")));
|
|
566
766
|
};
|
|
567
767
|
let t = (t) => {
|
|
568
|
-
if (
|
|
569
|
-
|
|
570
|
-
for (let e of
|
|
571
|
-
|
|
768
|
+
if (V === e) {
|
|
769
|
+
V = null, e.terminate();
|
|
770
|
+
for (let e of H.values()) e.reject(t);
|
|
771
|
+
H.clear();
|
|
572
772
|
}
|
|
573
773
|
};
|
|
574
|
-
|
|
774
|
+
V.onerror = (e) => t(/* @__PURE__ */ Error(`[WaSHI] HiGHS Worker failed to load or execute. Check Worker assets, CORS and CSP. ${e?.message || ""}`)), V.onmessageerror = () => t(/* @__PURE__ */ Error("[WaSHI] Could not deserialize the HiGHS Worker response."));
|
|
575
775
|
} catch {
|
|
576
|
-
|
|
776
|
+
V = null;
|
|
577
777
|
}
|
|
578
|
-
return
|
|
778
|
+
return V;
|
|
579
779
|
}
|
|
580
|
-
async function
|
|
581
|
-
let n = await _(t.wasmUrl), r = t.useWorker ?? typeof window < "u" ?
|
|
780
|
+
async function U(e, t = {}) {
|
|
781
|
+
let n = await _(t.wasmUrl), r = t.useWorker ?? typeof window < "u" ? ue() : null;
|
|
582
782
|
if (!r) return m(e, t);
|
|
583
783
|
let i = {
|
|
584
784
|
...t,
|
|
585
785
|
wasmUrl: n
|
|
586
|
-
}, a = `req_${++
|
|
786
|
+
}, a = `req_${++le}`;
|
|
587
787
|
return new Promise((t, n) => {
|
|
588
|
-
|
|
788
|
+
H.set(a, {
|
|
589
789
|
resolve: t,
|
|
590
790
|
reject: n
|
|
591
791
|
});
|
|
@@ -597,13 +797,13 @@ async function R(e, t = {}) {
|
|
|
597
797
|
options: i
|
|
598
798
|
});
|
|
599
799
|
} catch (e) {
|
|
600
|
-
|
|
800
|
+
H.delete(a), n(e);
|
|
601
801
|
}
|
|
602
802
|
});
|
|
603
803
|
}
|
|
604
804
|
//#endregion
|
|
605
805
|
//#region src/modeler/solvers/highs/solver.ts
|
|
606
|
-
function
|
|
806
|
+
function W(e) {
|
|
607
807
|
if (typeof e != "string") return "Unknown";
|
|
608
808
|
let t = e.trim();
|
|
609
809
|
if (!t) return "Unknown";
|
|
@@ -632,7 +832,7 @@ function z(e) {
|
|
|
632
832
|
let n = t.toLowerCase();
|
|
633
833
|
return n.includes("infeasible") && n.includes("unbounded") ? "Unknown" : n.includes("infeasible") ? "Infeasible" : n.includes("unbounded") ? "Unbounded" : n.includes("time limit") || n.includes("timelimit") ? "TimeLimit" : n.includes("iteration limit") || n.includes("iterationlimit") ? "IterationLimit" : n.includes("error") ? "Error" : n === "optimal" ? "Optimal" : "Unknown";
|
|
634
834
|
}
|
|
635
|
-
var
|
|
835
|
+
var G = class e {
|
|
636
836
|
static capabilities = {
|
|
637
837
|
supportsMIP: !0,
|
|
638
838
|
supportsQP: !0
|
|
@@ -648,7 +848,18 @@ var B = class e {
|
|
|
648
848
|
let r = {
|
|
649
849
|
...this.options,
|
|
650
850
|
...n
|
|
651
|
-
}, { lpString: i, nameToVar: a, nameToConstraint: o } = t, { result: s, runTime: c } = await
|
|
851
|
+
}, { lpString: i, nameToVar: a, nameToConstraint: o } = t, { result: s, runTime: c } = await U(i, r), l = W(s?.Status);
|
|
852
|
+
if (l === "Infeasible" || l === "Unbounded") return {
|
|
853
|
+
status: l,
|
|
854
|
+
objectiveValue: null,
|
|
855
|
+
values: {},
|
|
856
|
+
reducedCosts: {},
|
|
857
|
+
duals: {},
|
|
858
|
+
slacks: {},
|
|
859
|
+
runTime: c,
|
|
860
|
+
raw: s
|
|
861
|
+
};
|
|
862
|
+
let u = s.ObjectiveValue, d = typeof u == "number" ? u + e.objective.constant : null, f = {}, p = {}, m = {}, h = {};
|
|
652
863
|
if (s.Columns) for (let [e, t] of Object.entries(s.Columns)) {
|
|
653
864
|
let n = a.get(e);
|
|
654
865
|
if (n) {
|
|
@@ -677,53 +888,53 @@ var B = class e {
|
|
|
677
888
|
raw: s
|
|
678
889
|
};
|
|
679
890
|
}
|
|
680
|
-
},
|
|
681
|
-
function
|
|
682
|
-
d("highs", (e) => new
|
|
891
|
+
}, K = G;
|
|
892
|
+
function q() {
|
|
893
|
+
d("highs", (e) => new G(e)), l((e) => new G(e));
|
|
683
894
|
}
|
|
684
|
-
|
|
895
|
+
q();
|
|
685
896
|
//#endregion
|
|
686
897
|
//#region src/modeler/solvers/highs/index.ts
|
|
687
|
-
var
|
|
688
|
-
HiGHS: () =>
|
|
689
|
-
HighsSolver: () =>
|
|
898
|
+
var J = /* @__PURE__ */ S({
|
|
899
|
+
HiGHS: () => K,
|
|
900
|
+
HighsSolver: () => G,
|
|
690
901
|
OFFICIAL_HIGHS_CDN_WASM_URL: () => b,
|
|
691
902
|
getHighs: () => g,
|
|
692
903
|
getHighsWasmUrl: () => v,
|
|
693
904
|
isValidWasmHeader: () => h,
|
|
694
|
-
mapHighsStatus: () =>
|
|
905
|
+
mapHighsStatus: () => W,
|
|
695
906
|
probeWasmUrl: () => p,
|
|
696
|
-
registerHighsSolver: () =>
|
|
907
|
+
registerHighsSolver: () => q,
|
|
697
908
|
resolveBrowserWasmUrl: () => _,
|
|
698
909
|
setHighsWasmUrl: () => y,
|
|
699
|
-
solveLp: () =>
|
|
910
|
+
solveLp: () => U,
|
|
700
911
|
solveLpWithHighs: () => m
|
|
701
912
|
});
|
|
702
|
-
import * as
|
|
703
|
-
w(
|
|
704
|
-
import * as
|
|
705
|
-
w(
|
|
913
|
+
import * as de from "./highs-worker-factory.js";
|
|
914
|
+
w(J, de);
|
|
915
|
+
import * as fe from "./highs-assets.js";
|
|
916
|
+
w(J, fe);
|
|
706
917
|
//#endregion
|
|
707
918
|
//#region src/modeler/solvers/highs.ts
|
|
708
|
-
var
|
|
709
|
-
HiGHS: () =>
|
|
710
|
-
HighsSolver: () =>
|
|
919
|
+
var Y = /* @__PURE__ */ S({
|
|
920
|
+
HiGHS: () => K,
|
|
921
|
+
HighsSolver: () => G,
|
|
711
922
|
OFFICIAL_HIGHS_CDN_WASM_URL: () => b,
|
|
712
923
|
getHighs: () => g,
|
|
713
924
|
getHighsWasmUrl: () => v,
|
|
714
925
|
isValidWasmHeader: () => h,
|
|
715
|
-
mapHighsStatus: () =>
|
|
926
|
+
mapHighsStatus: () => W,
|
|
716
927
|
probeWasmUrl: () => p,
|
|
717
|
-
registerHighsSolver: () =>
|
|
928
|
+
registerHighsSolver: () => q,
|
|
718
929
|
resolveBrowserWasmUrl: () => _,
|
|
719
930
|
setHighsWasmUrl: () => y,
|
|
720
|
-
solveLp: () =>
|
|
931
|
+
solveLp: () => U,
|
|
721
932
|
solveLpWithHighs: () => m
|
|
722
933
|
});
|
|
723
|
-
w(
|
|
934
|
+
w(Y, J);
|
|
724
935
|
//#endregion
|
|
725
936
|
//#region src/modeler/solvers/mock.ts
|
|
726
|
-
var
|
|
937
|
+
var X = class {
|
|
727
938
|
name;
|
|
728
939
|
capabilities;
|
|
729
940
|
options;
|
|
@@ -750,37 +961,37 @@ var G = class {
|
|
|
750
961
|
};
|
|
751
962
|
}
|
|
752
963
|
};
|
|
753
|
-
function
|
|
754
|
-
d("mock", (e) => new
|
|
964
|
+
function Z() {
|
|
965
|
+
d("mock", (e) => new X(e));
|
|
755
966
|
}
|
|
756
|
-
|
|
967
|
+
Z();
|
|
757
968
|
//#endregion
|
|
758
969
|
//#region src/modeler/solvers/index.ts
|
|
759
|
-
var
|
|
760
|
-
HiGHS: () =>
|
|
761
|
-
HighsSolver: () =>
|
|
762
|
-
MockSolver: () =>
|
|
970
|
+
var Q = /* @__PURE__ */ S({
|
|
971
|
+
HiGHS: () => K,
|
|
972
|
+
HighsSolver: () => G,
|
|
973
|
+
MockSolver: () => X,
|
|
763
974
|
OFFICIAL_HIGHS_CDN_WASM_URL: () => b,
|
|
764
975
|
getHighs: () => g,
|
|
765
976
|
getHighsWasmUrl: () => v,
|
|
766
977
|
getSolver: () => f,
|
|
767
978
|
isValidWasmHeader: () => h,
|
|
768
979
|
listAvailableSolvers: () => u,
|
|
769
|
-
mapHighsStatus: () =>
|
|
980
|
+
mapHighsStatus: () => W,
|
|
770
981
|
probeWasmUrl: () => p,
|
|
771
|
-
registerHighsSolver: () =>
|
|
772
|
-
registerMockSolver: () =>
|
|
982
|
+
registerHighsSolver: () => q,
|
|
983
|
+
registerMockSolver: () => Z,
|
|
773
984
|
registerSolver: () => d,
|
|
774
985
|
resolveBrowserWasmUrl: () => _,
|
|
775
986
|
setDefaultSolver: () => l,
|
|
776
987
|
setHighsWasmUrl: () => y,
|
|
777
|
-
solveLp: () =>
|
|
988
|
+
solveLp: () => U,
|
|
778
989
|
solveLpWithHighs: () => m
|
|
779
990
|
});
|
|
780
|
-
w(
|
|
991
|
+
w(Q, Y);
|
|
781
992
|
//#endregion
|
|
782
993
|
//#region src/modeler/model.ts
|
|
783
|
-
var
|
|
994
|
+
var $ = class {
|
|
784
995
|
name;
|
|
785
996
|
sense;
|
|
786
997
|
objective;
|
|
@@ -791,6 +1002,8 @@ var J = class {
|
|
|
791
1002
|
unsatCore = [];
|
|
792
1003
|
values = /* @__PURE__ */ new Map();
|
|
793
1004
|
varMapByName = /* @__PURE__ */ new Map();
|
|
1005
|
+
boolVarMapByName = /* @__PURE__ */ new Map();
|
|
1006
|
+
boolVarPrefixCounters = /* @__PURE__ */ new Map();
|
|
794
1007
|
constrMapByName = /* @__PURE__ */ new Map();
|
|
795
1008
|
status = "NotSolved";
|
|
796
1009
|
objectiveValue = null;
|
|
@@ -802,7 +1015,7 @@ var J = class {
|
|
|
802
1015
|
n = typeof e == "string" ? {
|
|
803
1016
|
...t,
|
|
804
1017
|
name: e
|
|
805
|
-
} : e, this.name = n.name || "OptimizationModel", this.sense = n.sense
|
|
1018
|
+
} : e, this.name = n.name || "OptimizationModel", this.sense = T(n.sense), this.objective = new O(), n.solver && (this.solver = f(n.solver));
|
|
806
1019
|
}
|
|
807
1020
|
get vars() {
|
|
808
1021
|
return this.variables;
|
|
@@ -816,70 +1029,120 @@ var J = class {
|
|
|
816
1029
|
get numConstrs() {
|
|
817
1030
|
return this.constraints.length;
|
|
818
1031
|
}
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
1032
|
+
createDomainVars(e, t, n, r) {
|
|
1033
|
+
if (typeof n == "number" || Array.isArray(n)) {
|
|
1034
|
+
let i = typeof t == "number" ? Array.from({ length: t }, (e, t) => t) : t, a = typeof n == "number" ? Array.from({ length: n }, (e, t) => t) : n, o = r || {}, s = o.prefix || o.name || "x", c = {};
|
|
1035
|
+
for (let t of i) {
|
|
1036
|
+
c[t] = {};
|
|
1037
|
+
for (let n of a) c[t][n] = this.addVar({
|
|
1038
|
+
...o,
|
|
1039
|
+
type: e,
|
|
1040
|
+
name: `${s}_${t}_${n}`
|
|
1041
|
+
});
|
|
1042
|
+
}
|
|
1043
|
+
return c;
|
|
1044
|
+
}
|
|
1045
|
+
if (typeof t == "string") {
|
|
1046
|
+
let r = n || {};
|
|
1047
|
+
return this.addVar({
|
|
1048
|
+
...r,
|
|
1049
|
+
type: e,
|
|
1050
|
+
name: t
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
let i = n || {}, a = i.prefix || i.name;
|
|
1054
|
+
if (typeof t == "number") {
|
|
1055
|
+
let n = [], r = a || "x";
|
|
1056
|
+
for (let a = 0; a < t; a++) n.push(this.addVar({
|
|
1057
|
+
...i,
|
|
1058
|
+
type: e,
|
|
1059
|
+
name: `${r}_${a}`
|
|
1060
|
+
}));
|
|
1061
|
+
return n;
|
|
1062
|
+
}
|
|
1063
|
+
if (Array.isArray(t) || t && typeof t[Symbol.iterator] == "function") {
|
|
1064
|
+
let n = {};
|
|
1065
|
+
for (let r of t) {
|
|
1066
|
+
let t = a ? `${a}_${r}` : `${r}`;
|
|
1067
|
+
n[r] = this.addVar({
|
|
1068
|
+
...i,
|
|
1069
|
+
type: e,
|
|
1070
|
+
name: t
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
return n;
|
|
1074
|
+
}
|
|
1075
|
+
throw Error(`Invalid arguments provided for ${e.toLowerCase()} variable creation`);
|
|
1076
|
+
}
|
|
1077
|
+
binary(e, t, n) {
|
|
1078
|
+
return this.createDomainVars("Binary", e, t, n);
|
|
1079
|
+
}
|
|
1080
|
+
integer(e, t, n) {
|
|
1081
|
+
return this.createDomainVars("Integer", e, t, n);
|
|
1082
|
+
}
|
|
1083
|
+
continuous(e, t, n) {
|
|
1084
|
+
return this.createDomainVars("Continuous", e, t, n);
|
|
1085
|
+
}
|
|
1086
|
+
bool(e, t, n) {
|
|
832
1087
|
if (typeof t == "number" || Array.isArray(t)) {
|
|
833
|
-
let r = typeof e == "number" ? Array.from({ length: e }, (e, t) => t) : e, i = typeof t == "number" ? Array.from({ length: t }, (e, t) => t) : t, a = n || {}, o = a.prefix || a.name || "
|
|
1088
|
+
let r = typeof e == "number" ? Array.from({ length: e }, (e, t) => t) : e, i = typeof t == "number" ? Array.from({ length: t }, (e, t) => t) : t, a = n || {}, o = a.prefix || a.name || "p", s = {};
|
|
834
1089
|
for (let e of r) {
|
|
835
1090
|
s[e] = {};
|
|
836
|
-
for (let t of i) s[e][t] = this.
|
|
837
|
-
...a,
|
|
838
|
-
name: `${o}_${e}_${t}`
|
|
839
|
-
});
|
|
1091
|
+
for (let t of i) s[e][t] = this.createBoolVar(`${o}_${e}_${t}`);
|
|
840
1092
|
}
|
|
841
1093
|
return s;
|
|
842
1094
|
}
|
|
1095
|
+
if (typeof e == "string" || e === void 0) return this.createBoolVar(e);
|
|
843
1096
|
let r = t || {}, i = r.prefix || r.name;
|
|
844
1097
|
if (typeof e == "number") {
|
|
845
|
-
let t = [], n = i || "
|
|
846
|
-
for (let
|
|
847
|
-
...r,
|
|
848
|
-
name: `${n}_${i}`
|
|
849
|
-
}));
|
|
1098
|
+
let t = [], n = i || "p";
|
|
1099
|
+
for (let r = 0; r < e; r++) t.push(this.createBoolVar(this.getNextBoolVarName(n)));
|
|
850
1100
|
return t;
|
|
851
1101
|
}
|
|
852
|
-
{
|
|
1102
|
+
if (Array.isArray(e) || e && typeof e[Symbol.iterator] == "function") {
|
|
853
1103
|
let t = {};
|
|
854
1104
|
for (let n of e) {
|
|
855
1105
|
let e = i ? `${i}_${n}` : `${n}`;
|
|
856
|
-
t[n] = this.
|
|
857
|
-
...r,
|
|
858
|
-
name: e
|
|
859
|
-
});
|
|
1106
|
+
t[n] = this.createBoolVar(e);
|
|
860
1107
|
}
|
|
861
1108
|
return t;
|
|
862
1109
|
}
|
|
1110
|
+
throw Error("Invalid arguments provided for boolean variable creation");
|
|
863
1111
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
1112
|
+
hasVarName(e) {
|
|
1113
|
+
return this.varMapByName.has(e) || this.boolVarMapByName.has(e);
|
|
1114
|
+
}
|
|
1115
|
+
getNextBoolVarName(e) {
|
|
1116
|
+
let t = this.boolVarPrefixCounters.get(e) ?? 0, n = `${e}_${t}`;
|
|
1117
|
+
for (; this.hasVarName(n);) t++, n = `${e}_${t}`;
|
|
1118
|
+
return this.boolVarPrefixCounters.set(e, t + 1), n;
|
|
1119
|
+
}
|
|
1120
|
+
createBoolVar(e) {
|
|
1121
|
+
let t = typeof e == "string" ? e.trim() : void 0, r = t && t.length > 0 ? t : this.getNextBoolVarName("p");
|
|
1122
|
+
if (this.hasVarName(r)) throw Error(`Variable with name '${r}' already exists in model`);
|
|
1123
|
+
let i = new n(r);
|
|
1124
|
+
return this.boolVars.push(i), this.boolVarMapByName.set(i.name, i), i;
|
|
1125
|
+
}
|
|
1126
|
+
addVar(e) {
|
|
1127
|
+
let t = e || {}, n = typeof t.name == "string" ? t.name.trim() : void 0, r = n && n.length > 0 ? n : void 0, i = new M({
|
|
1128
|
+
...t,
|
|
1129
|
+
name: r
|
|
1130
|
+
});
|
|
1131
|
+
if (this.hasVarName(i.name)) throw Error(`Variable with name '${i.name}' already exists in model`);
|
|
1132
|
+
return this.variables.push(i), this.varMapByName.set(i.name, i), i;
|
|
874
1133
|
}
|
|
875
1134
|
getVarByName(e) {
|
|
876
1135
|
return this.varMapByName.get(e);
|
|
877
1136
|
}
|
|
1137
|
+
getBoolVarByName(e) {
|
|
1138
|
+
return this.boolVarMapByName.get(e);
|
|
1139
|
+
}
|
|
878
1140
|
getConstraintByName(e) {
|
|
879
1141
|
return this.constrMapByName.get(e);
|
|
880
1142
|
}
|
|
881
1143
|
setObjective(e, t) {
|
|
882
|
-
|
|
1144
|
+
if (e instanceof c) throw Error("Cannot set objective to a constraint comparison (<=, >=, ==). Did you mean to use m.constrain(expr`... <= ...`)? For objectives, supply an unconstrained expression like expr`45 * ${x} + 80 * ${y}`.");
|
|
1145
|
+
t && (this.sense = T(t)), this.objective = typeof e == "string" ? P(e, (e) => this.getVarByName(e)) : typeof e == "number" ? new O(/* @__PURE__ */ new Map(), e) : e instanceof D || "terms" in e ? e.clone() : new O(/* @__PURE__ */ new Map([[e, 1]]), 0);
|
|
883
1146
|
}
|
|
884
1147
|
maximize(e) {
|
|
885
1148
|
this.setObjective(e, "Maximize");
|
|
@@ -887,11 +1150,29 @@ var J = class {
|
|
|
887
1150
|
minimize(e) {
|
|
888
1151
|
this.setObjective(e, "Minimize");
|
|
889
1152
|
}
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
1153
|
+
constrain(e, t) {
|
|
1154
|
+
if (Array.isArray(e)) {
|
|
1155
|
+
for (let t of e) this.constrain(t);
|
|
1156
|
+
return this;
|
|
1157
|
+
}
|
|
1158
|
+
if (e instanceof D) throw Error("Cannot add a quadratic expression without a comparison operator (<=, >=, ==) as a constraint. Quadratic constraints are not supported (only linear constraints are allowed in MILP/LP/QP).");
|
|
1159
|
+
if (e instanceof O) throw Error("Cannot add a linear expression without a comparison operator (<=, >=, ==) as a constraint. Use expr`... <= ...` or .le(), .ge(), .eq().");
|
|
1160
|
+
return this.addConstraint(e, t), this;
|
|
1161
|
+
}
|
|
1162
|
+
getValues(e) {
|
|
1163
|
+
if (e == null) return null;
|
|
1164
|
+
if (e instanceof M || e instanceof n) return e.value;
|
|
1165
|
+
if (Array.isArray(e)) return e.map((e) => this.getValues(e));
|
|
1166
|
+
if (typeof e == "object") {
|
|
1167
|
+
let t = {};
|
|
1168
|
+
for (let [n, r] of Object.entries(e)) t[n] = this.getValues(r);
|
|
1169
|
+
return t;
|
|
1170
|
+
}
|
|
1171
|
+
return null;
|
|
893
1172
|
}
|
|
894
1173
|
addConstraint(e, t) {
|
|
1174
|
+
if (e instanceof D) throw Error("Cannot add a quadratic expression without a comparison operator (<=, >=, ==) as a constraint. Quadratic constraints are not supported (only linear constraints are allowed in MILP/LP/QP).");
|
|
1175
|
+
if (e instanceof O) throw Error("Cannot add a linear expression without a comparison operator (<=, >=, ==) as a constraint. Use expr`... <= ...` or .le(), .ge(), .eq().");
|
|
895
1176
|
if (e instanceof i) {
|
|
896
1177
|
let n = t || `lc_${this.logicalConstraints.length + 1}`;
|
|
897
1178
|
return this.logicalConstraints.push({
|
|
@@ -900,47 +1181,43 @@ var J = class {
|
|
|
900
1181
|
}), e;
|
|
901
1182
|
}
|
|
902
1183
|
let n;
|
|
903
|
-
if (typeof e == "string" ? n =
|
|
1184
|
+
if (typeof e == "string" ? n = F(e, (e) => this.getVarByName(e), t) : (n = e, t && (n.name = t)), this.constrMapByName.has(n.name)) throw Error(`Constraint with name '${n.name}' already exists in model`);
|
|
904
1185
|
return this.constraints.push(n), this.constrMapByName.set(n.name, n), n;
|
|
905
1186
|
}
|
|
906
|
-
addConstr(e, t) {
|
|
907
|
-
return this.addConstraint(e, t);
|
|
908
|
-
}
|
|
909
|
-
addConstrs(e) {
|
|
910
|
-
return e.map((e) => this.addConstraint(e));
|
|
911
|
-
}
|
|
912
1187
|
add(e, t) {
|
|
913
1188
|
if (Array.isArray(e)) {
|
|
914
1189
|
for (let t of e) this.add(t);
|
|
915
1190
|
return this;
|
|
916
1191
|
}
|
|
917
|
-
return e instanceof
|
|
918
|
-
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
if (
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
1192
|
+
return e instanceof M ? (this.varMapByName.has(e.name) || (this.variables.push(e), this.varMapByName.set(e.name, e)), this) : (this.addConstraint(e, t), this);
|
|
1193
|
+
}
|
|
1194
|
+
indicator(e, t, n = {}) {
|
|
1195
|
+
if (t instanceof D) throw Error("Quadratic expressions or constraints are not supported in indicator constraints (only linear constraints are allowed).");
|
|
1196
|
+
if (!("sense" in t) || !("lhs" in t)) throw Error("Invalid constraint expression passed to indicator(). Expression must include a comparison operator (<=, >=, ==).");
|
|
1197
|
+
let r = t, i = n.activeValue === void 0 ? 1 : n.activeValue, a = n.M === void 0 ? 1e5 : n.M, o = n.name || `ind_${e.name}_${r.name}`, s = [], { lhs: c, sense: l, rhs: u } = r;
|
|
1198
|
+
if (i === 1) {
|
|
1199
|
+
if (l === "<=" || l === "==") {
|
|
1200
|
+
let t = this.addConstraint(c.add(e.mul(a)).le(u + a), l === "==" ? `${o}_le` : o);
|
|
1201
|
+
s.push(t);
|
|
925
1202
|
}
|
|
926
|
-
if (
|
|
927
|
-
let t = this.addConstraint(
|
|
928
|
-
|
|
1203
|
+
if (l === ">=" || l === "==") {
|
|
1204
|
+
let t = this.addConstraint(c.sub(e.mul(a)).ge(u - a), l === "==" ? `${o}_ge` : o);
|
|
1205
|
+
s.push(t);
|
|
929
1206
|
}
|
|
930
1207
|
} else {
|
|
931
|
-
if (
|
|
932
|
-
let t = this.addConstraint(
|
|
933
|
-
|
|
1208
|
+
if (l === "<=" || l === "==") {
|
|
1209
|
+
let t = this.addConstraint(c.sub(e.mul(a)).le(u), l === "==" ? `${o}_le` : o);
|
|
1210
|
+
s.push(t);
|
|
934
1211
|
}
|
|
935
|
-
if (
|
|
936
|
-
let t = this.addConstraint(
|
|
937
|
-
|
|
1212
|
+
if (l === ">=" || l === "==") {
|
|
1213
|
+
let t = this.addConstraint(c.add(e.mul(a)).ge(u), l === "==" ? `${o}_ge` : o);
|
|
1214
|
+
s.push(t);
|
|
938
1215
|
}
|
|
939
1216
|
}
|
|
940
|
-
return
|
|
1217
|
+
return s;
|
|
941
1218
|
}
|
|
942
1219
|
toLpString() {
|
|
943
|
-
let { lpString: e } =
|
|
1220
|
+
let { lpString: e } = B({
|
|
944
1221
|
name: this.name,
|
|
945
1222
|
sense: this.sense,
|
|
946
1223
|
objective: this.objective,
|
|
@@ -951,7 +1228,8 @@ var J = class {
|
|
|
951
1228
|
}
|
|
952
1229
|
async optimize(e, t) {
|
|
953
1230
|
let n, r;
|
|
954
|
-
if (e && typeof e == "object" && "solve" in e && typeof e.solve == "function" ? (n = e, r = t || {}) : typeof e == "function" ? (n = new e(t), r = t || {}) : typeof e == "string" ? (n = f(e, t), r = t || {}) : (r = { ...e }, r.solver ? (n = f(r.solver, r), delete r.solver) : n = this.solver || f()), this.objective instanceof
|
|
1231
|
+
if (e && typeof e == "object" && "solve" in e && typeof e.solve == "function" ? (n = e, r = t || {}) : typeof e == "function" ? (n = new e(t), r = t || {}) : typeof e == "string" ? (n = f(e, t), r = t || {}) : (r = { ...e }, r.solver ? (n = f(r.solver, r), delete r.solver) : n = this.solver || f()), this.objective instanceof D && this.objective.quadTerms.size > 0 && n.capabilities?.supportsQP === !1) throw Error(`Solver "${n.name}" does not support quadratic objectives (QP). Please use a QP-capable solver such as HiGHS or Clarabel.`);
|
|
1232
|
+
if (this.logicalConstraints.length > 0 && n.capabilities?.supportsSMT !== !0) throw Error(`Solver "${n.name}" does not support SMT / logical constraints (or, implies, not, xor). Please use an SMT-capable solver such as Z3.`);
|
|
955
1233
|
let i = {
|
|
956
1234
|
name: this.name,
|
|
957
1235
|
sense: this.sense,
|
|
@@ -960,13 +1238,23 @@ var J = class {
|
|
|
960
1238
|
variables: this.variables,
|
|
961
1239
|
logicalConstraints: this.logicalConstraints,
|
|
962
1240
|
boolVars: this.boolVars
|
|
963
|
-
}, a =
|
|
1241
|
+
}, a = B(i), o = await n.solve(i, a, r);
|
|
964
1242
|
this.runTime = o.runTime ?? 0, this.status = o.status, this.objectiveValue = o.objectiveValue ?? null;
|
|
965
1243
|
let s = {}, c = {}, l = {}, u = {};
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1244
|
+
this.values.clear();
|
|
1245
|
+
for (let e of this.variables) e.value = null, e.reducedCost = null;
|
|
1246
|
+
for (let e of this.boolVars) e.value = null;
|
|
1247
|
+
for (let e of this.constraints) e.dual = null, e.slack = null;
|
|
1248
|
+
if (a?.nameToVar) for (let e of a.nameToVar.values()) e.value = null, e.reducedCost = null;
|
|
1249
|
+
if (a?.nameToConstraint) for (let e of a.nameToConstraint.values()) e.dual = null, e.slack = null;
|
|
1250
|
+
if (o.values && o.status !== "Infeasible" && o.status !== "Unbounded") {
|
|
1251
|
+
for (let [e, t] of Object.entries(o.values)) if (typeof t == "number" && !Number.isNaN(t)) {
|
|
1252
|
+
this.values.set(e, t);
|
|
1253
|
+
let n = this.getVarByName(e) || a.nameToVar.get(e);
|
|
1254
|
+
n && (n.value = t, s[n.name] = t);
|
|
1255
|
+
let r = this.boolVars.find((t) => t.name === e);
|
|
1256
|
+
r && (r.value = !!t);
|
|
1257
|
+
}
|
|
970
1258
|
}
|
|
971
1259
|
if (o.reducedCosts) for (let [e, t] of Object.entries(o.reducedCosts)) {
|
|
972
1260
|
let n = this.getVarByName(e) || a.nameToVar.get(e);
|
|
@@ -1005,21 +1293,26 @@ var J = class {
|
|
|
1005
1293
|
constraints: this.constraints,
|
|
1006
1294
|
logicalConstraints: this.logicalConstraints
|
|
1007
1295
|
}, r);
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1296
|
+
this.status = e.status, this.runTime = e.runTime ?? 0, this.unsatCore = e.unsatCore || [], this.values.clear();
|
|
1297
|
+
for (let e of this.variables) e.value = null;
|
|
1298
|
+
for (let e of this.boolVars) e.value = null;
|
|
1299
|
+
if (e.values && e.status === "Sat") for (let [t, n] of Object.entries(e.values)) {
|
|
1300
|
+
this.values.set(t, n);
|
|
1301
|
+
let e = this.getVarByName(t);
|
|
1302
|
+
e && typeof n == "number" && (e.value = n);
|
|
1303
|
+
let r = this.boolVars.find((e) => e.name === t);
|
|
1304
|
+
r && (r.value = !!n);
|
|
1015
1305
|
}
|
|
1016
1306
|
return e;
|
|
1017
1307
|
}
|
|
1018
1308
|
let i = this.objective, a = this.sense;
|
|
1019
1309
|
try {
|
|
1020
|
-
this.objective = new
|
|
1310
|
+
this.objective = new O(), this.sense = "Minimize";
|
|
1021
1311
|
let e = await this.optimize(n, r), t = e === "Optimal" || e === "Feasible", i = e === "Infeasible", a = {};
|
|
1022
|
-
|
|
1312
|
+
if (t) {
|
|
1313
|
+
for (let e of this.variables) e.value !== null && (a[e.name] = e.value);
|
|
1314
|
+
for (let e of this.boolVars) e.value !== null && (a[e.name] = e.value);
|
|
1315
|
+
}
|
|
1023
1316
|
return {
|
|
1024
1317
|
status: t ? "Sat" : i ? "Unsat" : "Unknown",
|
|
1025
1318
|
values: a,
|
|
@@ -1029,190 +1322,47 @@ var J = class {
|
|
|
1029
1322
|
this.objective = i, this.sense = a;
|
|
1030
1323
|
}
|
|
1031
1324
|
}
|
|
1032
|
-
}, Y = "Minimize", me = "Maximize", he = "Continuous", ge = "Integer", _e = "Binary", ve = {
|
|
1033
|
-
Optimal: "Optimal",
|
|
1034
|
-
Feasible: "Feasible",
|
|
1035
|
-
Infeasible: "Infeasible",
|
|
1036
|
-
Unbounded: "Unbounded",
|
|
1037
|
-
TimeLimit: "Not Solved (Time Limit)",
|
|
1038
|
-
IterationLimit: "Not Solved (Iteration Limit)",
|
|
1039
|
-
Error: "Error",
|
|
1040
|
-
NotSolved: "Not Solved",
|
|
1041
|
-
Sat: "Sat",
|
|
1042
|
-
Unsat: "Unsat",
|
|
1043
|
-
Unknown: "Unknown"
|
|
1044
|
-
}, ye = class e extends j {
|
|
1045
|
-
constructor(e, t, n, r = "Continuous") {
|
|
1046
|
-
super({
|
|
1047
|
-
name: e,
|
|
1048
|
-
lb: t === void 0 ? 0 : t,
|
|
1049
|
-
ub: n === void 0 ? Infinity : n,
|
|
1050
|
-
type: r
|
|
1051
|
-
});
|
|
1052
|
-
}
|
|
1053
|
-
static dicts(t, n, r, i, a = "Continuous") {
|
|
1054
|
-
let o = {};
|
|
1055
|
-
for (let s of n) {
|
|
1056
|
-
let n = `${t}_${s}`;
|
|
1057
|
-
o[s] = new e(n, r, i, a);
|
|
1058
|
-
}
|
|
1059
|
-
return o;
|
|
1060
|
-
}
|
|
1061
|
-
};
|
|
1062
|
-
function be(e) {
|
|
1063
|
-
return e == null ? null : typeof e == "number" ? e : e.value;
|
|
1064
|
-
}
|
|
1065
|
-
var xe = class {
|
|
1066
|
-
model;
|
|
1067
|
-
constructor(e = "NoName", t = Y) {
|
|
1068
|
-
this.model = new J({
|
|
1069
|
-
name: e,
|
|
1070
|
-
sense: t
|
|
1071
|
-
});
|
|
1072
|
-
}
|
|
1073
|
-
get name() {
|
|
1074
|
-
return this.model.name;
|
|
1075
|
-
}
|
|
1076
|
-
get sense() {
|
|
1077
|
-
return this.model.sense;
|
|
1078
|
-
}
|
|
1079
|
-
set sense(e) {
|
|
1080
|
-
this.model.sense = e;
|
|
1081
|
-
}
|
|
1082
|
-
get objective() {
|
|
1083
|
-
return this.model.objective;
|
|
1084
|
-
}
|
|
1085
|
-
get variables() {
|
|
1086
|
-
return this.model.variables;
|
|
1087
|
-
}
|
|
1088
|
-
get constraints() {
|
|
1089
|
-
return this.model.constraints;
|
|
1090
|
-
}
|
|
1091
|
-
get status() {
|
|
1092
|
-
return this.model.status;
|
|
1093
|
-
}
|
|
1094
|
-
get objectiveValue() {
|
|
1095
|
-
return this.model.objectiveValue;
|
|
1096
|
-
}
|
|
1097
|
-
addVariable(e) {
|
|
1098
|
-
return this.model.getVarByName(e.name) || (this.model.variables.push(e), this.model.varMapByName.set(e.name, e)), e;
|
|
1099
|
-
}
|
|
1100
|
-
setObjective(e) {
|
|
1101
|
-
if (typeof e == "object" && e) {
|
|
1102
|
-
if ("terms" in e) for (let [t] of e.terms) this.addVariable(t);
|
|
1103
|
-
else e instanceof j && this.addVariable(e);
|
|
1104
|
-
}
|
|
1105
|
-
this.model.setObjective(e);
|
|
1106
|
-
}
|
|
1107
|
-
addConstraint(e, t) {
|
|
1108
|
-
if (typeof e == "object" && e && "lhs" in e) for (let [t] of e.lhs.terms) this.addVariable(t);
|
|
1109
|
-
return this.model.addConstraint(e, t);
|
|
1110
|
-
}
|
|
1111
|
-
add(e, t) {
|
|
1112
|
-
typeof e == "string" ? /(<=|>=|==|=<|=>|=)/.test(e) ? this.addConstraint(e, t) : this.setObjective(e) : e instanceof c ? this.addConstraint(e, t) : this.setObjective(e);
|
|
1113
|
-
}
|
|
1114
|
-
async solve(e, t) {
|
|
1115
|
-
return this.model.optimize(e, t);
|
|
1116
|
-
}
|
|
1117
|
-
toLpString() {
|
|
1118
|
-
return this.model.toLpString();
|
|
1119
|
-
}
|
|
1120
|
-
}, X = "Minimize", Z = "Maximize", Q = "Binary", Se = "Integer", Ce = "Continuous";
|
|
1121
|
-
function we(e) {
|
|
1122
|
-
return {
|
|
1123
|
-
expr: e,
|
|
1124
|
-
sense: Z
|
|
1125
|
-
};
|
|
1126
|
-
}
|
|
1127
|
-
function Te(e) {
|
|
1128
|
-
return {
|
|
1129
|
-
expr: e,
|
|
1130
|
-
sense: X
|
|
1131
|
-
};
|
|
1132
|
-
}
|
|
1133
|
-
var $ = class extends J {
|
|
1134
|
-
constructor(e = "MipModel", t = X) {
|
|
1135
|
-
super({
|
|
1136
|
-
name: e,
|
|
1137
|
-
sense: t
|
|
1138
|
-
});
|
|
1139
|
-
}
|
|
1140
|
-
add_var(e = {}) {
|
|
1141
|
-
return this.addVar({
|
|
1142
|
-
name: e.name,
|
|
1143
|
-
type: e.var_type,
|
|
1144
|
-
lb: e.lb,
|
|
1145
|
-
ub: e.ub
|
|
1146
|
-
});
|
|
1147
|
-
}
|
|
1148
|
-
set objective_spec(e) {
|
|
1149
|
-
this.setObjective(e.expr, e.sense);
|
|
1150
|
-
}
|
|
1151
|
-
get objective_value() {
|
|
1152
|
-
return this.objectiveValue;
|
|
1153
|
-
}
|
|
1154
|
-
add_constr(e, t) {
|
|
1155
|
-
return this.addConstraint(e, t);
|
|
1156
|
-
}
|
|
1157
1325
|
};
|
|
1158
1326
|
w(/* @__PURE__ */ S({
|
|
1159
|
-
BINARY: () => Q,
|
|
1160
1327
|
BoolExpr: () => i,
|
|
1161
1328
|
BoolOp: () => o,
|
|
1162
1329
|
BoolVar: () => n,
|
|
1163
|
-
CONTINUOUS: () => Ce,
|
|
1164
1330
|
Constraint: () => c,
|
|
1165
|
-
HiGHS: () =>
|
|
1166
|
-
HighsSolver: () =>
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
LpContinuous: () => he,
|
|
1171
|
-
LpInteger: () => ge,
|
|
1172
|
-
LpMaximize: () => me,
|
|
1173
|
-
LpMinimize: () => Y,
|
|
1174
|
-
LpProblem: () => xe,
|
|
1175
|
-
LpStatus: () => ve,
|
|
1176
|
-
LpVariable: () => ye,
|
|
1177
|
-
MAXIMIZE: () => Z,
|
|
1178
|
-
MINIMIZE: () => X,
|
|
1179
|
-
MipModel: () => $,
|
|
1180
|
-
MockSolver: () => G,
|
|
1181
|
-
Model: () => J,
|
|
1331
|
+
HiGHS: () => K,
|
|
1332
|
+
HighsSolver: () => G,
|
|
1333
|
+
LinExpr: () => O,
|
|
1334
|
+
MockSolver: () => X,
|
|
1335
|
+
Model: () => $,
|
|
1182
1336
|
OFFICIAL_HIGHS_CDN_WASM_URL: () => b,
|
|
1183
|
-
QuadExpr: () =>
|
|
1184
|
-
Var: () =>
|
|
1337
|
+
QuadExpr: () => D,
|
|
1338
|
+
Var: () => M,
|
|
1185
1339
|
and: () => e,
|
|
1186
|
-
c: () =>
|
|
1187
|
-
|
|
1188
|
-
|
|
1340
|
+
c: () => L,
|
|
1341
|
+
dot: () => A,
|
|
1342
|
+
expr: () => R,
|
|
1343
|
+
generateLpString: () => B,
|
|
1189
1344
|
getHighs: () => g,
|
|
1190
1345
|
getHighsWasmUrl: () => v,
|
|
1191
1346
|
getSolver: () => f,
|
|
1192
1347
|
implies: () => a,
|
|
1193
1348
|
isValidWasmHeader: () => h,
|
|
1194
1349
|
listAvailableSolvers: () => u,
|
|
1195
|
-
|
|
1196
|
-
mapHighsStatus: () => z,
|
|
1197
|
-
maximize: () => we,
|
|
1198
|
-
minimize: () => Te,
|
|
1350
|
+
mapHighsStatus: () => W,
|
|
1199
1351
|
not: () => s,
|
|
1200
1352
|
or: () => t,
|
|
1201
|
-
parseConstraint: () =>
|
|
1202
|
-
parseExpr: () =>
|
|
1353
|
+
parseConstraint: () => F,
|
|
1354
|
+
parseExpr: () => P,
|
|
1203
1355
|
probeWasmUrl: () => p,
|
|
1204
|
-
registerHighsSolver: () =>
|
|
1205
|
-
registerMockSolver: () =>
|
|
1356
|
+
registerHighsSolver: () => q,
|
|
1357
|
+
registerMockSolver: () => Z,
|
|
1206
1358
|
registerSolver: () => d,
|
|
1207
1359
|
resolveBrowserWasmUrl: () => _,
|
|
1208
1360
|
setDefaultSolver: () => l,
|
|
1209
1361
|
setHighsWasmUrl: () => y,
|
|
1210
|
-
solveLp: () =>
|
|
1362
|
+
solveLp: () => U,
|
|
1211
1363
|
solveLpWithHighs: () => m,
|
|
1212
|
-
sum: () =>
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
xsum: () => k
|
|
1216
|
-
}), q);
|
|
1364
|
+
sum: () => k,
|
|
1365
|
+
xor: () => r
|
|
1366
|
+
}), Q);
|
|
1217
1367
|
//#endregion
|
|
1218
|
-
export {
|
|
1368
|
+
export { i as BoolExpr, o as BoolOp, n as BoolVar, c as Constraint, K as HiGHS, G as HighsSolver, O as LinExpr, X as MockSolver, $ as Model, b as OFFICIAL_HIGHS_CDN_WASM_URL, D as QuadExpr, M as Var, e as and, L as c, A as dot, R as expr, B as generateLpString, g as getHighs, v as getHighsWasmUrl, f as getSolver, a as implies, h as isValidWasmHeader, u as listAvailableSolvers, T as normalizeSense, s as not, t as or, F as parseConstraint, P as parseExpr, p as probeWasmUrl, d as registerSolver, _ as resolveBrowserWasmUrl, l as setDefaultSolver, y as setHighsWasmUrl, m as solveLpWithHighs, k as sum, r as xor };
|