@ohtaman/washi 0.1.1 → 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 +49 -21
- package/README.md +49 -21
- package/README.zh-CN.md +49 -21
- 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/{lib/demo → 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 +34 -33
- 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 +1 -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/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 +18 -6
- package/dist/lib/assets/highs-worker-DeDWU6KI.js +0 -3
- package/dist/lib/washi-logo.png +0 -0
- package/dist/lib/washi-logo.svg +0 -70
- package/dist/lib/z3-C8g-PtmP.js +0 -582
|
@@ -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,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { n as
|
|
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
5
|
function D(e, t) {
|
|
5
6
|
let n = e.id, r = t.id;
|
|
@@ -176,11 +177,11 @@ var O = 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;
|
|
@@ -215,7 +216,7 @@ function A(e, t) {
|
|
|
215
216
|
for (let [e, t] of n) Math.abs(t) < 1e-12 && n.delete(e);
|
|
216
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 j = A, M = A, N = 0, P = 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;
|
|
@@ -276,7 +277,7 @@ var j = A, M = A, N = 0, P = 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 F(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;
|
|
@@ -415,7 +416,7 @@ var te = class {
|
|
|
415
416
|
}
|
|
416
417
|
};
|
|
417
418
|
function I(e, t) {
|
|
418
|
-
return new
|
|
419
|
+
return new F(P(e), t).parseExpression();
|
|
419
420
|
}
|
|
420
421
|
function L(e, t, n) {
|
|
421
422
|
let r = e.match(/(<=|>=|==|=<|=>|=)/);
|
|
@@ -433,7 +434,7 @@ function R(e, t) {
|
|
|
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
440
|
} else if (e instanceof k) {
|
|
@@ -551,7 +552,7 @@ var U = 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 k(), e.solver && (this.solver =
|
|
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 U = 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
|
}
|
|
@@ -637,11 +638,11 @@ var U = class {
|
|
|
637
638
|
this.setObjective(e, "Minimize");
|
|
638
639
|
}
|
|
639
640
|
addBoolVar(e) {
|
|
640
|
-
let t = new
|
|
641
|
+
let t = new l(e);
|
|
641
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,
|
|
@@ -663,7 +664,7 @@ var U = 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;
|
|
@@ -700,7 +701,7 @@ var U = 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,
|
|
@@ -711,31 +712,31 @@ var U = class {
|
|
|
711
712
|
boolVars: this.boolVars
|
|
712
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 U = 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,
|
|
@@ -790,7 +791,7 @@ var U = class {
|
|
|
790
791
|
Sat: "Sat",
|
|
791
792
|
Unsat: "Unsat",
|
|
792
793
|
Unknown: "Unknown"
|
|
793
|
-
}, X = class e extends
|
|
794
|
+
}, X = class e extends N {
|
|
794
795
|
constructor(e, t, n, r = "Continuous") {
|
|
795
796
|
super({
|
|
796
797
|
name: e,
|
|
@@ -849,7 +850,7 @@ var ne = 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 ne = 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);
|
|
@@ -905,4 +906,4 @@ var ce = class extends U {
|
|
|
905
906
|
}
|
|
906
907
|
};
|
|
907
908
|
//#endregion
|
|
908
|
-
export { re as BINARY,
|
|
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 };
|