@ohtaman/washi 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +72 -4
- package/README.md +72 -4
- package/README.zh-CN.md +72 -4
- package/dist/browser/_washi-optional-engine-282Ug7Gw.js +7 -0
- package/dist/browser/highs-browser-runtime-D13gHOT5.js +4189 -0
- package/dist/browser/highs-loader-T47YOyos.js +58 -0
- package/dist/browser/highs-worker.js +21 -0
- package/dist/browser/highs.wasm +0 -0
- package/dist/browser/highs.wasm.LICENSE +22 -0
- package/dist/browser/washi.js +1547 -0
- package/dist/browser/washi.min.js +5 -0
- package/dist/lib/{glpk-BC32ZaPG.js → glpk-5cUpjyb9.js} +14 -5
- package/dist/lib/highs-assets.js +1 -0
- package/dist/lib/highs-browser-runtime.js +4189 -0
- package/dist/lib/highs-loader-Blb99785.js +50 -0
- package/dist/lib/highs-node-runtime.js +1 -0
- package/dist/lib/highs-worker-factory.js +1 -0
- package/dist/lib/highs-worker.js +21 -0
- package/dist/lib/highs.wasm +0 -0
- package/dist/lib/solvers/glpk.js +1 -1
- package/dist/lib/solvers/z3.js +2 -2
- package/dist/lib/washi.js +92 -91
- package/dist/lib/z3-C6GeIicJ.js +509 -0
- package/dist/types/glpk-loader.d.ts.map +1 -1
- package/dist/types/highs-assets.d.ts +3 -0
- package/dist/types/highs-assets.d.ts.map +1 -0
- package/dist/types/highs-browser-runtime.d.ts +2 -0
- package/dist/types/highs-browser-runtime.d.ts.map +1 -0
- package/dist/types/highs-loader.d.ts +17 -1
- package/dist/types/highs-loader.d.ts.map +1 -1
- package/dist/types/highs-node-runtime.d.ts +2 -0
- package/dist/types/highs-node-runtime.d.ts.map +1 -0
- package/dist/types/highs-worker-client.d.ts.map +1 -1
- package/dist/types/highs-worker-factory.d.ts +3 -0
- package/dist/types/highs-worker-factory.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs.d.ts +6 -0
- package/dist/types/modeler/solvers/highs.d.ts.map +1 -1
- package/dist/types/modeler/solvers/types.d.ts +1 -1
- package/dist/types/modeler/solvers/types.d.ts.map +1 -1
- package/dist/types/modeler/solvers/z3.d.ts +4 -5
- package/dist/types/modeler/solvers/z3.d.ts.map +1 -1
- package/package.json +20 -7
- package/dist/lib/assets/highs-worker-D57nd9KC.js +0 -3
- package/dist/lib/z3-C5DfllfD.js +0 -562
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { getBundledWasmUrl as e } from "./highs-assets.js";
|
|
2
|
+
import { loadNodeHighs as t } from "./highs-node-runtime.js";
|
|
3
|
+
//#region src/highs-loader.ts
|
|
4
|
+
var n = "https://cdn.jsdelivr.net/npm/highs@1.15.3/build/highs.wasm", r = null, i = null, a = null;
|
|
5
|
+
function o(e) {
|
|
6
|
+
a = e, r = null, i = null;
|
|
7
|
+
}
|
|
8
|
+
function s() {
|
|
9
|
+
return a;
|
|
10
|
+
}
|
|
11
|
+
function c(e) {
|
|
12
|
+
return e.length >= 4 && e[0] === 0 && e[1] === 97 && e[2] === 115 && e[3] === 109;
|
|
13
|
+
}
|
|
14
|
+
async function l(e) {
|
|
15
|
+
try {
|
|
16
|
+
let t = await fetch(e, { headers: { Range: "bytes=0-3" } });
|
|
17
|
+
if (!t.ok || (t.headers.get("content-type") || "").includes("text/html")) return !1;
|
|
18
|
+
if (!t.body) return !0;
|
|
19
|
+
let n = t.body.getReader(), { value: r, done: i } = await n.read();
|
|
20
|
+
return await n.cancel(), i || !r || r.length < 4 ? !1 : c(r);
|
|
21
|
+
} catch {
|
|
22
|
+
return !1;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async function u(t) {
|
|
26
|
+
return t || a || e();
|
|
27
|
+
}
|
|
28
|
+
async function d(e = {}) {
|
|
29
|
+
let n = typeof process < "u" && process.versions?.node && process.type !== "renderer", a = n ? null : await u(e.wasmUrl), o = a ?? "node";
|
|
30
|
+
if (r && i === o) return r;
|
|
31
|
+
i = o;
|
|
32
|
+
let s = (async () => {
|
|
33
|
+
let e = n ? await t() : (await import("./highs-browser-runtime.js")).default;
|
|
34
|
+
return n ? await e() : await e({ locateFile: (e) => e.endsWith(".wasm") ? a : e });
|
|
35
|
+
})().catch((e) => {
|
|
36
|
+
r === s && (r = null, i = null);
|
|
37
|
+
let t = e instanceof Error ? e.message : String(e);
|
|
38
|
+
throw Error(`[WaSHI] Failed to initialize HiGHS${a ? ` from "${a}"` : ""}. Deploy the package's WASM asset or explicitly set wasmUrl; no CDN fallback is attempted. ${t}`, { cause: e });
|
|
39
|
+
});
|
|
40
|
+
return r = s, s;
|
|
41
|
+
}
|
|
42
|
+
async function f(e, t = {}) {
|
|
43
|
+
let n = await d(t), r = performance.now(), i = { output_flag: t.outputFlag ?? !1 };
|
|
44
|
+
return t.timeLimit !== void 0 && (i.time_limit = t.timeLimit), t.presolve !== void 0 && (i.presolve = t.presolve), t.solver !== void 0 && (i.solver = t.solver), t.relGap !== void 0 && (i.mip_rel_gap = t.relGap), t.absGap !== void 0 && (i.mip_abs_gap = t.absGap), {
|
|
45
|
+
result: n.solve(e, i),
|
|
46
|
+
runTime: (performance.now() - r) / 1e3
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { l as a, f as c, c as i, d as n, u as o, s as r, o as s, n as t };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export async function loadNodeHighs() { return (await import(/* webpackIgnore: true */ /* @vite-ignore */ "highs")).default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function createHighsWorker() { return new Worker(new URL("./highs-worker.js", import.meta.url), { type: "module" }); }
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { c as e } from "./highs-loader-Blb99785.js";
|
|
2
|
+
//#region src/highs-worker.ts
|
|
3
|
+
self.onmessage = async (t) => {
|
|
4
|
+
let { type: n, id: r, lpString: i, options: a } = t.data;
|
|
5
|
+
if (n === "SOLVE") try {
|
|
6
|
+
let { result: t, runTime: n } = await e(i, a);
|
|
7
|
+
self.postMessage({
|
|
8
|
+
type: "SOLVE_SUCCESS",
|
|
9
|
+
id: r,
|
|
10
|
+
result: t,
|
|
11
|
+
runTime: n
|
|
12
|
+
});
|
|
13
|
+
} catch (e) {
|
|
14
|
+
self.postMessage({
|
|
15
|
+
type: "SOLVE_ERROR",
|
|
16
|
+
id: r,
|
|
17
|
+
error: e?.message || String(e)
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
//#endregion
|
package/dist/lib/highs.wasm
CHANGED
|
File without changes
|
package/dist/lib/solvers/glpk.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as e } from "../glpk-
|
|
1
|
+
import { t as e } from "../glpk-5cUpjyb9.js";
|
|
2
2
|
export { e as GLPKSolver };
|
package/dist/lib/solvers/z3.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as e, t } from "../z3-
|
|
2
|
-
export {
|
|
1
|
+
import { n as e, r as t, t as n } from "../z3-C6GeIicJ.js";
|
|
2
|
+
export { n as Z3Solver, e as registerZ3Solver, t as resetZ3LoaderCache };
|
package/dist/lib/washi.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as S,
|
|
1
|
+
import { _ as e, a as t, c as n, d as r, f as i, g as a, h as o, i as s, l as c, m as l, n as u, o as d, p as f, s as p, t as m, u as h, v as g, y as _ } from "./z3-C6GeIicJ.js";
|
|
2
|
+
import { a as v, c as y, i as b, n as x, o as S, r as C, s as w, t as T } from "./highs-loader-Blb99785.js";
|
|
3
|
+
import { n as E, t as ee } from "./glpk-5cUpjyb9.js";
|
|
3
4
|
//#region src/modeler/quad-expr.ts
|
|
4
|
-
function
|
|
5
|
+
function D(e, t) {
|
|
5
6
|
let n = e.id, r = t.id;
|
|
6
7
|
return n <= r ? `${n}:${r}` : `${r}:${n}`;
|
|
7
8
|
}
|
|
8
|
-
var
|
|
9
|
+
var O = class e {
|
|
9
10
|
linearTerms;
|
|
10
11
|
quadTerms;
|
|
11
12
|
constant;
|
|
@@ -18,7 +19,7 @@ var T = class e {
|
|
|
18
19
|
return new e(this.linearTerms, this.quadTerms, this.constant);
|
|
19
20
|
}
|
|
20
21
|
getQuadCoeff(e, t) {
|
|
21
|
-
let n =
|
|
22
|
+
let n = D(e, t), r = this.quadTerms.get(n);
|
|
22
23
|
return r ? r.coeff : 0;
|
|
23
24
|
}
|
|
24
25
|
add(t) {
|
|
@@ -91,14 +92,14 @@ var T = class e {
|
|
|
91
92
|
return this.value;
|
|
92
93
|
}
|
|
93
94
|
static fromProduct(t, n, r = 1) {
|
|
94
|
-
let i = new e(), a =
|
|
95
|
+
let i = new e(), a = D(t, n);
|
|
95
96
|
return i.quadTerms.set(a, {
|
|
96
97
|
var1: t.id <= n.id ? t : n,
|
|
97
98
|
var2: t.id <= n.id ? n : t,
|
|
98
99
|
coeff: r
|
|
99
100
|
}), i;
|
|
100
101
|
}
|
|
101
|
-
},
|
|
102
|
+
}, k = class e {
|
|
102
103
|
terms;
|
|
103
104
|
constant;
|
|
104
105
|
constructor(e = /* @__PURE__ */ new Map(), t = 0) {
|
|
@@ -108,7 +109,7 @@ var T = class e {
|
|
|
108
109
|
return new e(this.terms, this.constant);
|
|
109
110
|
}
|
|
110
111
|
add(e) {
|
|
111
|
-
if (e instanceof
|
|
112
|
+
if (e instanceof O) return e.add(this);
|
|
112
113
|
let t = this.clone();
|
|
113
114
|
if (typeof e == "number") t.constant += e;
|
|
114
115
|
else if ("terms" in e) {
|
|
@@ -124,7 +125,7 @@ var T = class e {
|
|
|
124
125
|
return t;
|
|
125
126
|
}
|
|
126
127
|
sub(e) {
|
|
127
|
-
return e instanceof
|
|
128
|
+
return e instanceof O ? e.neg().add(this) : typeof e == "number" ? this.add(-e) : ("terms" in e, this.add(e.mul(-1)));
|
|
128
129
|
}
|
|
129
130
|
mul(t) {
|
|
130
131
|
if (typeof t == "number") {
|
|
@@ -135,9 +136,9 @@ var T = class e {
|
|
|
135
136
|
}
|
|
136
137
|
return n;
|
|
137
138
|
}
|
|
138
|
-
let n = new
|
|
139
|
+
let n = new O();
|
|
139
140
|
Math.abs(this.constant) >= 1e-12 && n.linearTerms.set(t, this.constant);
|
|
140
|
-
for (let [e, r] of this.terms) n = n.add(
|
|
141
|
+
for (let [e, r] of this.terms) n = n.add(O.fromProduct(e, t, r));
|
|
141
142
|
return n;
|
|
142
143
|
}
|
|
143
144
|
div(e) {
|
|
@@ -176,11 +177,11 @@ var T = class e {
|
|
|
176
177
|
equalTo(e, t) {
|
|
177
178
|
return this.eq(e, t);
|
|
178
179
|
}
|
|
179
|
-
toConstraint(t, n,
|
|
180
|
-
let
|
|
181
|
-
typeof n == "number" ?
|
|
182
|
-
let
|
|
183
|
-
return
|
|
180
|
+
toConstraint(t, n, i) {
|
|
181
|
+
let a = this.clone(), o = 0;
|
|
182
|
+
typeof n == "number" ? o = n : "terms" in n ? (a = a.sub(new e(n.terms, 0)), o = n.constant) : a = a.sub(n);
|
|
183
|
+
let s = o - a.constant;
|
|
184
|
+
return a.constant = 0, new r(a, t, s, i);
|
|
184
185
|
}
|
|
185
186
|
toString() {
|
|
186
187
|
let e = [], t = !0;
|
|
@@ -195,7 +196,7 @@ var T = class e {
|
|
|
195
196
|
return e.join(" ") || "0";
|
|
196
197
|
}
|
|
197
198
|
};
|
|
198
|
-
function
|
|
199
|
+
function A(e, t) {
|
|
199
200
|
let n = /* @__PURE__ */ new Map(), r = 0, i = 0;
|
|
200
201
|
for (let a of e) {
|
|
201
202
|
let e = t ? t(a, i++) : a;
|
|
@@ -213,9 +214,9 @@ function D(e, t) {
|
|
|
213
214
|
}
|
|
214
215
|
}
|
|
215
216
|
for (let [e, t] of n) Math.abs(t) < 1e-12 && n.delete(e);
|
|
216
|
-
return new
|
|
217
|
+
return new k(n, r);
|
|
217
218
|
}
|
|
218
|
-
var
|
|
219
|
+
var te = A, j = A, M = 0, N = class e {
|
|
219
220
|
id;
|
|
220
221
|
name;
|
|
221
222
|
type;
|
|
@@ -224,7 +225,7 @@ var O = D, k = D, A = 0, j = class e {
|
|
|
224
225
|
value = null;
|
|
225
226
|
reducedCost = null;
|
|
226
227
|
constructor(e = {}) {
|
|
227
|
-
this.id = ++
|
|
228
|
+
this.id = ++M, this.name = e.name || `x_${this.id}`, this.type = e.type || "Continuous", 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);
|
|
228
229
|
}
|
|
229
230
|
get x() {
|
|
230
231
|
return this.value;
|
|
@@ -233,39 +234,39 @@ var O = D, k = D, A = 0, j = class e {
|
|
|
233
234
|
return this.value;
|
|
234
235
|
}
|
|
235
236
|
mul(t) {
|
|
236
|
-
if (typeof t == "number") return new
|
|
237
|
-
if (t instanceof e) return
|
|
238
|
-
let n = new
|
|
237
|
+
if (typeof t == "number") return new k(/* @__PURE__ */ new Map([[this, t]]), 0);
|
|
238
|
+
if (t instanceof e) return O.fromProduct(this, t, 1);
|
|
239
|
+
let n = new O();
|
|
239
240
|
Math.abs(t.constant) >= 1e-12 && n.linearTerms.set(this, t.constant);
|
|
240
241
|
for (let [e, r] of t.terms) {
|
|
241
|
-
let t =
|
|
242
|
+
let t = O.fromProduct(this, e, r);
|
|
242
243
|
n = n.add(t);
|
|
243
244
|
}
|
|
244
245
|
return n;
|
|
245
246
|
}
|
|
246
247
|
add(e) {
|
|
247
|
-
return e instanceof
|
|
248
|
+
return e instanceof O ? e.add(this) : new k(/* @__PURE__ */ new Map([[this, 1]]), 0).add(e);
|
|
248
249
|
}
|
|
249
250
|
sub(e) {
|
|
250
|
-
return e instanceof
|
|
251
|
+
return e instanceof O ? e.neg().add(this) : new k(/* @__PURE__ */ new Map([[this, 1]]), 0).sub(e);
|
|
251
252
|
}
|
|
252
253
|
neg() {
|
|
253
254
|
return this.mul(-1);
|
|
254
255
|
}
|
|
255
256
|
le(e, t) {
|
|
256
|
-
return new
|
|
257
|
+
return new k(/* @__PURE__ */ new Map([[this, 1]]), 0).le(e, t);
|
|
257
258
|
}
|
|
258
259
|
lessThanOrEqual(e, t) {
|
|
259
260
|
return this.le(e, t);
|
|
260
261
|
}
|
|
261
262
|
ge(e, t) {
|
|
262
|
-
return new
|
|
263
|
+
return new k(/* @__PURE__ */ new Map([[this, 1]]), 0).ge(e, t);
|
|
263
264
|
}
|
|
264
265
|
greaterThanOrEqual(e, t) {
|
|
265
266
|
return this.ge(e, t);
|
|
266
267
|
}
|
|
267
268
|
eq(e, t) {
|
|
268
|
-
return new
|
|
269
|
+
return new k(/* @__PURE__ */ new Map([[this, 1]]), 0).eq(e, t);
|
|
269
270
|
}
|
|
270
271
|
equalTo(e, t) {
|
|
271
272
|
return this.eq(e, t);
|
|
@@ -276,7 +277,7 @@ var O = D, k = D, A = 0, j = class e {
|
|
|
276
277
|
};
|
|
277
278
|
//#endregion
|
|
278
279
|
//#region src/modeler/parser.ts
|
|
279
|
-
function
|
|
280
|
+
function P(e) {
|
|
280
281
|
let t = [], n = 0, r = e.length;
|
|
281
282
|
for (; n < r;) {
|
|
282
283
|
let i = e[n];
|
|
@@ -332,7 +333,7 @@ function M(e) {
|
|
|
332
333
|
}
|
|
333
334
|
return t;
|
|
334
335
|
}
|
|
335
|
-
var
|
|
336
|
+
var F = class {
|
|
336
337
|
tokens;
|
|
337
338
|
pos = 0;
|
|
338
339
|
resolver;
|
|
@@ -394,12 +395,12 @@ var N = class {
|
|
|
394
395
|
let e = this.consume();
|
|
395
396
|
return this.resolveVariable(e.value).mul(t);
|
|
396
397
|
}
|
|
397
|
-
return new
|
|
398
|
+
return new k(/* @__PURE__ */ new Map(), t);
|
|
398
399
|
}
|
|
399
400
|
if (e.type === "IDENT") {
|
|
400
401
|
this.consume();
|
|
401
402
|
let t = this.resolveVariable(e.value);
|
|
402
|
-
return new
|
|
403
|
+
return new k(/* @__PURE__ */ new Map([[t, 1]]), 0);
|
|
403
404
|
}
|
|
404
405
|
if (e.type === "LPAREN") {
|
|
405
406
|
this.consume("LPAREN");
|
|
@@ -414,10 +415,10 @@ var N = class {
|
|
|
414
415
|
return t;
|
|
415
416
|
}
|
|
416
417
|
};
|
|
417
|
-
function
|
|
418
|
-
return new
|
|
418
|
+
function I(e, t) {
|
|
419
|
+
return new F(P(e), t).parseExpression();
|
|
419
420
|
}
|
|
420
|
-
function
|
|
421
|
+
function L(e, t, n) {
|
|
421
422
|
let r = e.match(/(<=|>=|==|=<|=>|=)/);
|
|
422
423
|
if (!r) throw Error(`Constraint must contain a comparison operator (<=, >=, ==, =): "${e}"`);
|
|
423
424
|
let i = r[0], a = r.index, o = e.substring(0, a).trim(), s = e.substring(a + i.length).trim(), c;
|
|
@@ -425,18 +426,18 @@ function F(e, t, n) {
|
|
|
425
426
|
else if (i === ">=" || i === "=>") c = ">=";
|
|
426
427
|
else if (i === "==" || i === "=") c = "==";
|
|
427
428
|
else throw Error(`Unsupported operator "${i}"`);
|
|
428
|
-
let l =
|
|
429
|
+
let l = I(o, t), u = I(s, t);
|
|
429
430
|
return c === "<=" ? l.le(u, n) : c === ">=" ? l.ge(u, n) : l.eq(u, n);
|
|
430
431
|
}
|
|
431
|
-
function
|
|
432
|
+
function R(e, t) {
|
|
432
433
|
let n = /* @__PURE__ */ new Map(), r = "";
|
|
433
434
|
for (let i = 0; i < e.length; i++) if (r += e[i], i < t.length) {
|
|
434
435
|
let e = t[i];
|
|
435
436
|
if (typeof e == "number") r += `(${e})`;
|
|
436
|
-
else if (e instanceof
|
|
437
|
+
else if (e instanceof N) {
|
|
437
438
|
let t = `__v_${i}__`;
|
|
438
439
|
n.set(t, e), r += t;
|
|
439
|
-
} else if (e instanceof
|
|
440
|
+
} else if (e instanceof k) {
|
|
440
441
|
`${i}`, r += `(${e.toString()})`;
|
|
441
442
|
for (let [t] of e.terms) n.set(t.name, t);
|
|
442
443
|
}
|
|
@@ -446,42 +447,42 @@ function I(e, t) {
|
|
|
446
447
|
resolver: (e) => n.get(e)
|
|
447
448
|
};
|
|
448
449
|
}
|
|
449
|
-
function
|
|
450
|
-
let { fullText: n, resolver: r } =
|
|
451
|
-
return
|
|
450
|
+
function z(e, ...t) {
|
|
451
|
+
let { fullText: n, resolver: r } = R(e, t);
|
|
452
|
+
return L(n, r);
|
|
452
453
|
}
|
|
453
|
-
function
|
|
454
|
-
let { fullText: n, resolver: r } =
|
|
455
|
-
return /(<=|>=|==|=<|=>|=)/.test(n) ?
|
|
454
|
+
function B(e, ...t) {
|
|
455
|
+
let { fullText: n, resolver: r } = R(e, t);
|
|
456
|
+
return /(<=|>=|==|=<|=>|=)/.test(n) ? L(n, r) : I(n, r);
|
|
456
457
|
}
|
|
457
458
|
//#endregion
|
|
458
459
|
//#region src/modeler/lp-writer.ts
|
|
459
|
-
function
|
|
460
|
+
function V(e, t, n) {
|
|
460
461
|
let r = e.replace(/[^a-zA-Z0-9_]/g, "_");
|
|
461
462
|
return /^[0-9]/.test(r) && (r = `${t}_${r}`), (!r || r.length === 0) && (r = `${t}_${n}`), r;
|
|
462
463
|
}
|
|
463
|
-
function
|
|
464
|
+
function H(e) {
|
|
464
465
|
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();
|
|
465
466
|
for (let e of i) {
|
|
466
|
-
let t =
|
|
467
|
+
let t = V(e.name, "x", e.id), n = t, r = 1;
|
|
467
468
|
for (; c.has(n);) n = `${t}_${r++}`;
|
|
468
469
|
c.add(n), o.set(e, n), a.set(n, e);
|
|
469
470
|
}
|
|
470
471
|
let l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Map();
|
|
471
472
|
for (let e of r) {
|
|
472
|
-
let t =
|
|
473
|
+
let t = V(e.name, "c", e.id), n = t, r = 1;
|
|
473
474
|
for (; l.has(n);) n = `${t}_${r++}`;
|
|
474
475
|
l.add(n), u.set(e, n), s.set(n, e);
|
|
475
476
|
}
|
|
476
477
|
let d = [];
|
|
477
478
|
d.push(t === "Maximize" ? "Maximize" : "Minimize");
|
|
478
|
-
let f = [], p = !0, m = n instanceof
|
|
479
|
+
let f = [], p = !0, m = n instanceof O ? n.linearTerms : n.terms;
|
|
479
480
|
if (m) for (let [e, t] of m) {
|
|
480
481
|
if (Math.abs(t) < 1e-12) continue;
|
|
481
482
|
let n = o.get(e), r = t >= 0 ? p ? "" : "+ " : "- ", i = Math.abs(t), a = i === 1 ? "" : `${i} `;
|
|
482
483
|
f.push(`${r}${a}${n}`), p = !1;
|
|
483
484
|
}
|
|
484
|
-
if (n instanceof
|
|
485
|
+
if (n instanceof O && n.quadTerms.size > 0) {
|
|
485
486
|
let e = [], t = !0;
|
|
486
487
|
for (let r of n.quadTerms.values()) {
|
|
487
488
|
if (Math.abs(r.coeff) < 1e-12) continue;
|
|
@@ -533,7 +534,7 @@ function B(e) {
|
|
|
533
534
|
}
|
|
534
535
|
//#endregion
|
|
535
536
|
//#region src/modeler/model.ts
|
|
536
|
-
var
|
|
537
|
+
var U = class {
|
|
537
538
|
name;
|
|
538
539
|
sense;
|
|
539
540
|
objective;
|
|
@@ -551,7 +552,7 @@ var V = class {
|
|
|
551
552
|
solution = null;
|
|
552
553
|
solver = null;
|
|
553
554
|
constructor(e = {}) {
|
|
554
|
-
this.name = e.name || "OptimizationModel", this.sense = e.sense || "Minimize", this.objective = new
|
|
555
|
+
this.name = e.name || "OptimizationModel", this.sense = e.sense || "Minimize", this.objective = new k(), e.solver && (this.solver = s(e.solver));
|
|
555
556
|
}
|
|
556
557
|
get vars() {
|
|
557
558
|
return this.variables;
|
|
@@ -573,7 +574,7 @@ var V = class {
|
|
|
573
574
|
lb: n,
|
|
574
575
|
ub: r
|
|
575
576
|
} : e || {};
|
|
576
|
-
let a = new
|
|
577
|
+
let a = new N(i);
|
|
577
578
|
if (this.varMapByName.has(a.name)) throw Error(`Variable with name '${a.name}' already exists in model`);
|
|
578
579
|
return this.variables.push(a), this.varMapByName.set(a.name, a), a;
|
|
579
580
|
}
|
|
@@ -628,7 +629,7 @@ var V = class {
|
|
|
628
629
|
return this.constrMapByName.get(e);
|
|
629
630
|
}
|
|
630
631
|
setObjective(e, t) {
|
|
631
|
-
t && (this.sense = t), this.objective = typeof e == "string" ?
|
|
632
|
+
t && (this.sense = t), this.objective = typeof e == "string" ? I(e, (e) => this.getVarByName(e)) : typeof e == "number" ? new k(/* @__PURE__ */ new Map(), e) : e instanceof O || "terms" in e ? e.clone() : new k(/* @__PURE__ */ new Map([[e, 1]]), 0);
|
|
632
633
|
}
|
|
633
634
|
maximize(e) {
|
|
634
635
|
this.setObjective(e, "Maximize");
|
|
@@ -637,11 +638,11 @@ var V = class {
|
|
|
637
638
|
this.setObjective(e, "Minimize");
|
|
638
639
|
}
|
|
639
640
|
addBoolVar(e) {
|
|
640
|
-
let
|
|
641
|
-
return this.boolVars.push(
|
|
641
|
+
let t = new l(e);
|
|
642
|
+
return this.boolVars.push(t), t;
|
|
642
643
|
}
|
|
643
644
|
addConstraint(e, t) {
|
|
644
|
-
if (e instanceof
|
|
645
|
+
if (e instanceof i) {
|
|
645
646
|
let n = t || `lc_${this.logicalConstraints.length + 1}`;
|
|
646
647
|
return this.logicalConstraints.push({
|
|
647
648
|
name: n,
|
|
@@ -649,7 +650,7 @@ var V = class {
|
|
|
649
650
|
}), e;
|
|
650
651
|
}
|
|
651
652
|
let n;
|
|
652
|
-
if (typeof e == "string" ? n =
|
|
653
|
+
if (typeof e == "string" ? n = L(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`);
|
|
653
654
|
return this.constraints.push(n), this.constrMapByName.set(n.name, n), n;
|
|
654
655
|
}
|
|
655
656
|
addConstr(e, t) {
|
|
@@ -663,7 +664,7 @@ var V = class {
|
|
|
663
664
|
for (let t of e) this.add(t);
|
|
664
665
|
return this;
|
|
665
666
|
}
|
|
666
|
-
return e instanceof
|
|
667
|
+
return e instanceof N ? (this.varMapByName.has(e.name) || (this.variables.push(e), this.varMapByName.set(e.name, e)), this) : (this.addConstraint(e, t), this);
|
|
667
668
|
}
|
|
668
669
|
addIndicator(e, t, n = {}) {
|
|
669
670
|
let r = n.activeValue === void 0 ? 1 : n.activeValue, i = n.M === void 0 ? 1e5 : n.M, a = n.name || `ind_${e.name}_${t.name}`, o = [], { lhs: s, sense: c, rhs: l } = t;
|
|
@@ -689,7 +690,7 @@ var V = class {
|
|
|
689
690
|
return o;
|
|
690
691
|
}
|
|
691
692
|
toLpString() {
|
|
692
|
-
let { lpString: e } =
|
|
693
|
+
let { lpString: e } = H({
|
|
693
694
|
name: this.name,
|
|
694
695
|
sense: this.sense,
|
|
695
696
|
objective: this.objective,
|
|
@@ -700,7 +701,7 @@ var V = class {
|
|
|
700
701
|
}
|
|
701
702
|
async optimize(e, t) {
|
|
702
703
|
let n, r;
|
|
703
|
-
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 =
|
|
704
|
+
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 = s(e, t), r = t || {}) : (r = { ...e }, r.solver ? (n = s(r.solver, r), delete r.solver) : n = this.solver || s()), this.objective instanceof O && 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.`);
|
|
704
705
|
let i = {
|
|
705
706
|
name: this.name,
|
|
706
707
|
sense: this.sense,
|
|
@@ -709,33 +710,33 @@ var V = class {
|
|
|
709
710
|
variables: this.variables,
|
|
710
711
|
logicalConstraints: this.logicalConstraints,
|
|
711
712
|
boolVars: this.boolVars
|
|
712
|
-
}, a =
|
|
713
|
+
}, a = H(i), o = await n.solve(i, a, r);
|
|
713
714
|
this.runTime = o.runTime ?? 0, this.status = o.status, this.objectiveValue = o.objectiveValue ?? null;
|
|
714
|
-
let
|
|
715
|
+
let c = {}, l = {}, u = {}, d = {};
|
|
715
716
|
if (this.values.clear(), o.values) for (let [e, t] of Object.entries(o.values)) {
|
|
716
717
|
this.values.set(e, t);
|
|
717
718
|
let n = this.getVarByName(e) || a.nameToVar.get(e);
|
|
718
|
-
n && (n.value = t,
|
|
719
|
+
n && (n.value = t, c[n.name] = t);
|
|
719
720
|
}
|
|
720
721
|
if (o.reducedCosts) for (let [e, t] of Object.entries(o.reducedCosts)) {
|
|
721
722
|
let n = this.getVarByName(e) || a.nameToVar.get(e);
|
|
722
|
-
n && (n.reducedCost = t,
|
|
723
|
+
n && (n.reducedCost = t, u[n.name] = t);
|
|
723
724
|
}
|
|
724
725
|
if (o.duals) for (let [e, t] of Object.entries(o.duals)) {
|
|
725
726
|
let n = this.getConstraintByName(e) || a.nameToConstraint.get(e);
|
|
726
|
-
n && (n.dual = t,
|
|
727
|
+
n && (n.dual = t, l[n.name] = t);
|
|
727
728
|
}
|
|
728
729
|
if (o.slacks) for (let [e, t] of Object.entries(o.slacks)) {
|
|
729
730
|
let n = this.getConstraintByName(e) || a.nameToConstraint.get(e);
|
|
730
|
-
n && (n.slack = t,
|
|
731
|
+
n && (n.slack = t, d[n.name] = t);
|
|
731
732
|
}
|
|
732
733
|
return this.solution = {
|
|
733
734
|
status: this.status,
|
|
734
735
|
objectiveValue: this.objectiveValue,
|
|
735
|
-
values:
|
|
736
|
-
duals:
|
|
737
|
-
reducedCosts:
|
|
738
|
-
slacks:
|
|
736
|
+
values: c,
|
|
737
|
+
duals: l,
|
|
738
|
+
reducedCosts: u,
|
|
739
|
+
slacks: d,
|
|
739
740
|
runTime: this.runTime,
|
|
740
741
|
raw: o.raw
|
|
741
742
|
}, this.status;
|
|
@@ -745,7 +746,7 @@ var V = class {
|
|
|
745
746
|
}
|
|
746
747
|
async check(e, t) {
|
|
747
748
|
let n, r;
|
|
748
|
-
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 =
|
|
749
|
+
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 = s(e, t), r = t || {}) : (r = { ...e }, r.solver ? (n = s(r.solver, r), delete r.solver) : n = this.solver || s()), 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.`);
|
|
749
750
|
if (typeof n.check == "function") {
|
|
750
751
|
let e = await n.check({
|
|
751
752
|
name: this.name,
|
|
@@ -766,7 +767,7 @@ var V = class {
|
|
|
766
767
|
}
|
|
767
768
|
let i = this.objective, a = this.sense;
|
|
768
769
|
try {
|
|
769
|
-
this.objective = new
|
|
770
|
+
this.objective = new k(), this.sense = "Minimize";
|
|
770
771
|
let e = await this.optimize(n, r), t = e === "Optimal" || e === "Feasible", i = e === "Infeasible", a = {};
|
|
771
772
|
for (let e of this.variables) a[e.name] = e.value ?? 0;
|
|
772
773
|
return {
|
|
@@ -778,7 +779,7 @@ var V = class {
|
|
|
778
779
|
this.objective = i, this.sense = a;
|
|
779
780
|
}
|
|
780
781
|
}
|
|
781
|
-
},
|
|
782
|
+
}, W = "Minimize", G = "Maximize", K = "Continuous", q = "Integer", J = "Binary", Y = {
|
|
782
783
|
Optimal: "Optimal",
|
|
783
784
|
Feasible: "Feasible",
|
|
784
785
|
Infeasible: "Infeasible",
|
|
@@ -790,7 +791,7 @@ var V = class {
|
|
|
790
791
|
Sat: "Sat",
|
|
791
792
|
Unsat: "Unsat",
|
|
792
793
|
Unknown: "Unknown"
|
|
793
|
-
},
|
|
794
|
+
}, X = class e extends N {
|
|
794
795
|
constructor(e, t, n, r = "Continuous") {
|
|
795
796
|
super({
|
|
796
797
|
name: e,
|
|
@@ -808,13 +809,13 @@ var V = class {
|
|
|
808
809
|
return o;
|
|
809
810
|
}
|
|
810
811
|
};
|
|
811
|
-
function
|
|
812
|
+
function Z(e) {
|
|
812
813
|
return e == null ? null : typeof e == "number" ? e : e.value;
|
|
813
814
|
}
|
|
814
|
-
var
|
|
815
|
+
var ne = class {
|
|
815
816
|
model;
|
|
816
|
-
constructor(e = "NoName", t =
|
|
817
|
-
this.model = new
|
|
817
|
+
constructor(e = "NoName", t = W) {
|
|
818
|
+
this.model = new U({
|
|
818
819
|
name: e,
|
|
819
820
|
sense: t
|
|
820
821
|
});
|
|
@@ -849,7 +850,7 @@ var X = class {
|
|
|
849
850
|
setObjective(e) {
|
|
850
851
|
if (typeof e == "object" && e) {
|
|
851
852
|
if ("terms" in e) for (let [t] of e.terms) this.addVariable(t);
|
|
852
|
-
else e instanceof
|
|
853
|
+
else e instanceof N && this.addVariable(e);
|
|
853
854
|
}
|
|
854
855
|
this.model.setObjective(e);
|
|
855
856
|
}
|
|
@@ -858,7 +859,7 @@ var X = class {
|
|
|
858
859
|
return this.model.addConstraint(e, t);
|
|
859
860
|
}
|
|
860
861
|
add(e, t) {
|
|
861
|
-
typeof e == "string" ? /(<=|>=|==|=<|=>|=)/.test(e) ? this.addConstraint(e, t) : this.setObjective(e) : e instanceof
|
|
862
|
+
typeof e == "string" ? /(<=|>=|==|=<|=>|=)/.test(e) ? this.addConstraint(e, t) : this.setObjective(e) : e instanceof r ? this.addConstraint(e, t) : this.setObjective(e);
|
|
862
863
|
}
|
|
863
864
|
async solve(e, t) {
|
|
864
865
|
return this.model.optimize(e, t);
|
|
@@ -866,21 +867,21 @@ var X = class {
|
|
|
866
867
|
toLpString() {
|
|
867
868
|
return this.model.toLpString();
|
|
868
869
|
}
|
|
869
|
-
},
|
|
870
|
-
function
|
|
870
|
+
}, Q = "Minimize", $ = "Maximize", re = "Binary", ie = "Integer", ae = "Continuous";
|
|
871
|
+
function oe(e) {
|
|
871
872
|
return {
|
|
872
873
|
expr: e,
|
|
873
|
-
sense:
|
|
874
|
+
sense: $
|
|
874
875
|
};
|
|
875
876
|
}
|
|
876
|
-
function
|
|
877
|
+
function se(e) {
|
|
877
878
|
return {
|
|
878
879
|
expr: e,
|
|
879
|
-
sense:
|
|
880
|
+
sense: Q
|
|
880
881
|
};
|
|
881
882
|
}
|
|
882
|
-
var
|
|
883
|
-
constructor(e = "MipModel", t =
|
|
883
|
+
var ce = class extends U {
|
|
884
|
+
constructor(e = "MipModel", t = Q) {
|
|
884
885
|
super({
|
|
885
886
|
name: e,
|
|
886
887
|
sense: t
|
|
@@ -905,4 +906,4 @@ var ie = class extends V {
|
|
|
905
906
|
}
|
|
906
907
|
};
|
|
907
908
|
//#endregion
|
|
908
|
-
export {
|
|
909
|
+
export { re as BINARY, i as BoolExpr, f as BoolOp, l as BoolVar, ae as CONTINUOUS, r as Constraint, ee as GLPKSolver, c as HiGHS, h as HighsSolver, ie as INTEGER, k as LinExpr, J as LpBinary, K as LpContinuous, q as LpInteger, G as LpMaximize, W as LpMinimize, ne as LpProblem, Y as LpStatus, X as LpVariable, $ as MAXIMIZE, Q as MINIMIZE, ce as MipModel, n as MockSolver, U as Model, T as OFFICIAL_HIGHS_CDN_WASM_URL, O as QuadExpr, N as Var, m as Z3Solver, o as and, z as c, B as expr, H as generateLpString, E as getGlpk, x as getHighs, C as getHighsWasmUrl, s as getSolver, a as implies, b as isValidWasmHeader, t as listAvailableSolvers, j as lpSum, oe as maximize, se as minimize, e as not, g as or, L as parseConstraint, I as parseExpr, v as probeWasmUrl, d as registerSolver, u as registerZ3Solver, S as resolveBrowserWasmUrl, p as setDefaultSolver, w as setHighsWasmUrl, y as solveLpWithHighs, A as sum, Z as value, _ as xor, te as xsum };
|