@ohtaman/washi 0.1.2 → 0.2.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 +76 -2
- package/README.md +76 -2
- package/README.zh-CN.md +76 -2
- package/dist/browser/highs-worker.js +2 -2
- package/dist/browser/{highs-loader-T47YOyos.js → loader-CVt4CloI.js} +2 -2
- package/dist/browser/solvers/glpk.js +1057 -0
- package/dist/browser/solvers/glpk.min.js +1 -0
- package/dist/browser/solvers/z3-built.js +8245 -0
- package/dist/browser/solvers/z3-built.wasm +4 -0
- package/dist/browser/solvers/z3.js +7528 -0
- package/dist/browser/solvers/z3.min.js +5 -0
- package/dist/browser/washi.js +142 -476
- package/dist/browser/washi.min.js +3 -3
- package/dist/lib/async-mutex-Duo4jwzn.js +195 -0
- package/dist/lib/constraint-XWdn0ID9.js +93 -0
- package/dist/lib/highs-worker.js +2 -2
- package/dist/lib/{highs-loader-Blb99785.js → loader-Dti0v9yC.js} +1 -1
- package/dist/lib/registry-DksqCSjI.js +32 -0
- package/dist/lib/solvers/glpk.js +153 -2
- package/dist/lib/solvers/z3-assets.js +1 -0
- package/dist/lib/solvers/z3-built.js +8245 -0
- package/dist/lib/solvers/z3-built.wasm +4 -0
- package/dist/lib/solvers/z3.js +451 -2
- package/dist/lib/washi.js +400 -91
- package/dist/types/index.d.ts +2 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modeler/index.d.ts +1 -1
- package/dist/types/modeler/index.d.ts.map +1 -1
- package/dist/types/modeler/model.d.ts +1 -1
- package/dist/types/modeler/model.d.ts.map +1 -1
- package/dist/types/modeler/solvers/glpk/index.d.ts +3 -0
- package/dist/types/modeler/solvers/glpk/index.d.ts.map +1 -0
- package/dist/types/modeler/solvers/glpk/loader.d.ts +16 -0
- package/dist/types/modeler/solvers/glpk/loader.d.ts.map +1 -0
- package/dist/types/modeler/solvers/glpk/solver.d.ts +26 -0
- package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -0
- package/dist/types/modeler/solvers/glpk.d.ts +1 -21
- package/dist/types/modeler/solvers/glpk.d.ts.map +1 -1
- package/dist/types/{highs-assets.d.ts → modeler/solvers/highs/assets.d.ts} +1 -1
- package/dist/types/modeler/solvers/highs/assets.d.ts.map +1 -0
- package/dist/types/modeler/solvers/highs/browser-runtime.d.ts +2 -0
- package/dist/types/modeler/solvers/highs/browser-runtime.d.ts.map +1 -0
- package/dist/types/modeler/solvers/highs/index.d.ts +6 -0
- package/dist/types/modeler/solvers/highs/index.d.ts.map +1 -0
- package/dist/types/{highs-loader.d.ts → modeler/solvers/highs/loader.d.ts} +2 -2
- package/dist/types/modeler/solvers/highs/loader.d.ts.map +1 -0
- package/dist/types/{highs-node-runtime.d.ts → modeler/solvers/highs/node-runtime.d.ts} +1 -1
- package/dist/types/modeler/solvers/highs/node-runtime.d.ts.map +1 -0
- package/dist/types/modeler/solvers/highs/solver.d.ts +33 -0
- package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -0
- package/dist/types/modeler/solvers/highs/worker-client.d.ts +13 -0
- package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -0
- package/dist/types/{highs-worker-factory.d.ts → modeler/solvers/highs/worker-factory.d.ts} +1 -1
- package/dist/types/modeler/solvers/highs/worker-factory.d.ts.map +1 -0
- package/dist/types/modeler/solvers/highs/worker.d.ts +2 -0
- package/dist/types/modeler/solvers/highs/worker.d.ts.map +1 -0
- package/dist/types/modeler/solvers/highs.d.ts +1 -31
- package/dist/types/modeler/solvers/highs.d.ts.map +1 -1
- package/dist/types/modeler/solvers/index.d.ts +0 -2
- package/dist/types/modeler/solvers/index.d.ts.map +1 -1
- package/dist/types/modeler/solvers/mock.d.ts +1 -0
- package/dist/types/modeler/solvers/mock.d.ts.map +1 -1
- package/dist/types/modeler/solvers/registry.d.ts +1 -2
- package/dist/types/modeler/solvers/registry.d.ts.map +1 -1
- package/dist/types/modeler/solvers/z3/assets.d.ts +11 -0
- package/dist/types/modeler/solvers/z3/assets.d.ts.map +1 -0
- package/dist/types/modeler/solvers/z3/index.d.ts +3 -0
- package/dist/types/modeler/solvers/z3/index.d.ts.map +1 -0
- package/dist/types/modeler/solvers/z3/loader.d.ts +44 -0
- package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -0
- package/dist/types/modeler/solvers/z3/solver.d.ts +34 -0
- package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -0
- package/dist/types/modeler/solvers/z3.d.ts +1 -35
- package/dist/types/modeler/solvers/z3.d.ts.map +1 -1
- package/package.json +19 -5
- package/dist/browser/_washi-optional-engine-282Ug7Gw.js +0 -7
- package/dist/lib/glpk-5cUpjyb9.js +0 -135
- package/dist/lib/z3-C6GeIicJ.js +0 -509
- package/dist/types/glpk-loader.d.ts +0 -8
- package/dist/types/glpk-loader.d.ts.map +0 -1
- package/dist/types/highs-assets.d.ts.map +0 -1
- package/dist/types/highs-browser-runtime.d.ts +0 -2
- package/dist/types/highs-browser-runtime.d.ts.map +0 -1
- package/dist/types/highs-loader.d.ts.map +0 -1
- package/dist/types/highs-node-runtime.d.ts.map +0 -1
- package/dist/types/highs-worker-client.d.ts +0 -12
- package/dist/types/highs-worker-client.d.ts.map +0 -1
- package/dist/types/highs-worker-factory.d.ts.map +0 -1
- package/dist/types/highs-worker.d.ts +0 -2
- package/dist/types/highs-worker.d.ts.map +0 -1
- /package/dist/browser/{highs-browser-runtime-D13gHOT5.js → browser-runtime-D13gHOT5.js} +0 -0
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
//#region node_modules/async-mutex/index.mjs
|
|
2
|
+
var e = /* @__PURE__ */ Error("timeout while waiting for mutex to become available"), t = /* @__PURE__ */ Error("mutex already locked"), n = /* @__PURE__ */ Error("request for lock canceled"), r = function(e, t, n, r) {
|
|
3
|
+
function i(e) {
|
|
4
|
+
return e instanceof n ? e : new n(function(t) {
|
|
5
|
+
t(e);
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
return new (n ||= Promise)(function(n, a) {
|
|
9
|
+
function o(e) {
|
|
10
|
+
try {
|
|
11
|
+
c(r.next(e));
|
|
12
|
+
} catch (e) {
|
|
13
|
+
a(e);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function s(e) {
|
|
17
|
+
try {
|
|
18
|
+
c(r.throw(e));
|
|
19
|
+
} catch (e) {
|
|
20
|
+
a(e);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function c(e) {
|
|
24
|
+
e.done ? n(e.value) : i(e.value).then(o, s);
|
|
25
|
+
}
|
|
26
|
+
c((r = r.apply(e, t || [])).next());
|
|
27
|
+
});
|
|
28
|
+
}, i = class {
|
|
29
|
+
constructor(e, t = n) {
|
|
30
|
+
if (this._maxConcurrency = e, this._cancelError = t, this._queue = [], this._waiters = [], e <= 0) throw Error("semaphore must be initialized to a positive value");
|
|
31
|
+
this._value = e;
|
|
32
|
+
}
|
|
33
|
+
acquire() {
|
|
34
|
+
let e = this.isLocked(), t = new Promise((e, t) => this._queue.push({
|
|
35
|
+
resolve: e,
|
|
36
|
+
reject: t
|
|
37
|
+
}));
|
|
38
|
+
return e || this._dispatch(), t;
|
|
39
|
+
}
|
|
40
|
+
runExclusive(e) {
|
|
41
|
+
return r(this, void 0, void 0, function* () {
|
|
42
|
+
let [t, n] = yield this.acquire();
|
|
43
|
+
try {
|
|
44
|
+
return yield e(t);
|
|
45
|
+
} finally {
|
|
46
|
+
n();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
waitForUnlock() {
|
|
51
|
+
return r(this, void 0, void 0, function* () {
|
|
52
|
+
return this.isLocked() ? new Promise((e) => this._waiters.push({ resolve: e })) : Promise.resolve();
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
isLocked() {
|
|
56
|
+
return this._value <= 0;
|
|
57
|
+
}
|
|
58
|
+
release() {
|
|
59
|
+
if (this._maxConcurrency > 1) throw Error("this method is unavailable on semaphores with concurrency > 1; use the scoped release returned by acquire instead");
|
|
60
|
+
if (this._currentReleaser) {
|
|
61
|
+
let e = this._currentReleaser;
|
|
62
|
+
this._currentReleaser = void 0, e();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
cancel() {
|
|
66
|
+
this._queue.forEach((e) => e.reject(this._cancelError)), this._queue = [];
|
|
67
|
+
}
|
|
68
|
+
_dispatch() {
|
|
69
|
+
let e = this._queue.shift();
|
|
70
|
+
if (!e) return;
|
|
71
|
+
let t = !1;
|
|
72
|
+
this._currentReleaser = () => {
|
|
73
|
+
t || (t = !0, this._value++, this._resolveWaiters(), this._dispatch());
|
|
74
|
+
}, e.resolve([this._value--, this._currentReleaser]);
|
|
75
|
+
}
|
|
76
|
+
_resolveWaiters() {
|
|
77
|
+
this._waiters.forEach((e) => e.resolve()), this._waiters = [];
|
|
78
|
+
}
|
|
79
|
+
}, a = function(e, t, n, r) {
|
|
80
|
+
function i(e) {
|
|
81
|
+
return e instanceof n ? e : new n(function(t) {
|
|
82
|
+
t(e);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return new (n ||= Promise)(function(n, a) {
|
|
86
|
+
function o(e) {
|
|
87
|
+
try {
|
|
88
|
+
c(r.next(e));
|
|
89
|
+
} catch (e) {
|
|
90
|
+
a(e);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function s(e) {
|
|
94
|
+
try {
|
|
95
|
+
c(r.throw(e));
|
|
96
|
+
} catch (e) {
|
|
97
|
+
a(e);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
function c(e) {
|
|
101
|
+
e.done ? n(e.value) : i(e.value).then(o, s);
|
|
102
|
+
}
|
|
103
|
+
c((r = r.apply(e, t || [])).next());
|
|
104
|
+
});
|
|
105
|
+
}, o = class {
|
|
106
|
+
constructor(e) {
|
|
107
|
+
this._semaphore = new i(1, e);
|
|
108
|
+
}
|
|
109
|
+
acquire() {
|
|
110
|
+
return a(this, void 0, void 0, function* () {
|
|
111
|
+
let [, e] = yield this._semaphore.acquire();
|
|
112
|
+
return e;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
runExclusive(e) {
|
|
116
|
+
return this._semaphore.runExclusive(() => e());
|
|
117
|
+
}
|
|
118
|
+
isLocked() {
|
|
119
|
+
return this._semaphore.isLocked();
|
|
120
|
+
}
|
|
121
|
+
waitForUnlock() {
|
|
122
|
+
return this._semaphore.waitForUnlock();
|
|
123
|
+
}
|
|
124
|
+
release() {
|
|
125
|
+
this._semaphore.release();
|
|
126
|
+
}
|
|
127
|
+
cancel() {
|
|
128
|
+
return this._semaphore.cancel();
|
|
129
|
+
}
|
|
130
|
+
}, s = function(e, t, n, r) {
|
|
131
|
+
function i(e) {
|
|
132
|
+
return e instanceof n ? e : new n(function(t) {
|
|
133
|
+
t(e);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return new (n ||= Promise)(function(n, a) {
|
|
137
|
+
function o(e) {
|
|
138
|
+
try {
|
|
139
|
+
c(r.next(e));
|
|
140
|
+
} catch (e) {
|
|
141
|
+
a(e);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
function s(e) {
|
|
145
|
+
try {
|
|
146
|
+
c(r.throw(e));
|
|
147
|
+
} catch (e) {
|
|
148
|
+
a(e);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function c(e) {
|
|
152
|
+
e.done ? n(e.value) : i(e.value).then(o, s);
|
|
153
|
+
}
|
|
154
|
+
c((r = r.apply(e, t || [])).next());
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
function c(t, n, r = e) {
|
|
158
|
+
return {
|
|
159
|
+
acquire: () => new Promise((e, i) => s(this, void 0, void 0, function* () {
|
|
160
|
+
let a = !1, o = setTimeout(() => {
|
|
161
|
+
a = !0, i(r);
|
|
162
|
+
}, n);
|
|
163
|
+
try {
|
|
164
|
+
let n = yield t.acquire();
|
|
165
|
+
a ? (Array.isArray(n) ? n[1] : n)() : (clearTimeout(o), e(n));
|
|
166
|
+
} catch (e) {
|
|
167
|
+
a || (clearTimeout(o), i(e));
|
|
168
|
+
}
|
|
169
|
+
})),
|
|
170
|
+
runExclusive(e) {
|
|
171
|
+
return s(this, void 0, void 0, function* () {
|
|
172
|
+
let t = () => void 0;
|
|
173
|
+
try {
|
|
174
|
+
let n = yield this.acquire();
|
|
175
|
+
return Array.isArray(n) ? (t = n[1], yield e(n[0])) : (t = n, yield e());
|
|
176
|
+
} finally {
|
|
177
|
+
t();
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
release() {
|
|
182
|
+
t.release();
|
|
183
|
+
},
|
|
184
|
+
cancel() {
|
|
185
|
+
return t.cancel();
|
|
186
|
+
},
|
|
187
|
+
waitForUnlock: () => t.waitForUnlock(),
|
|
188
|
+
isLocked: () => t.isLocked()
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function l(e, n = t) {
|
|
192
|
+
return c(e, 0, n);
|
|
193
|
+
}
|
|
194
|
+
//#endregion
|
|
195
|
+
export { t as E_ALREADY_LOCKED, n as E_CANCELED, e as E_TIMEOUT, o as Mutex, i as Semaphore, l as tryAcquire, c as withTimeout };
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
//#region src/modeler/boolean-expr.ts
|
|
2
|
+
var e = 0, t = class {
|
|
3
|
+
and(e) {
|
|
4
|
+
return new r("and", [this, e]);
|
|
5
|
+
}
|
|
6
|
+
or(e) {
|
|
7
|
+
return new r("or", [this, e]);
|
|
8
|
+
}
|
|
9
|
+
implies(e) {
|
|
10
|
+
return new r("implies", [this, e]);
|
|
11
|
+
}
|
|
12
|
+
xor(e) {
|
|
13
|
+
return new r("xor", [this, e]);
|
|
14
|
+
}
|
|
15
|
+
not() {
|
|
16
|
+
return new r("not", [this]);
|
|
17
|
+
}
|
|
18
|
+
}, n = class extends t {
|
|
19
|
+
id;
|
|
20
|
+
name;
|
|
21
|
+
value = null;
|
|
22
|
+
constructor(t) {
|
|
23
|
+
super(), this.id = ++e, this.name = t || `p_${this.id}`;
|
|
24
|
+
}
|
|
25
|
+
toString() {
|
|
26
|
+
return this.name;
|
|
27
|
+
}
|
|
28
|
+
}, r = class extends t {
|
|
29
|
+
op;
|
|
30
|
+
children;
|
|
31
|
+
constructor(e, t) {
|
|
32
|
+
super(), this.op = e, this.children = t;
|
|
33
|
+
}
|
|
34
|
+
toString() {
|
|
35
|
+
return this.op === "not" ? `not(${this.children[0].toString()})` : `(${this.children.map((e) => e.toString()).join(` ${this.op} `)})`;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
function i(...e) {
|
|
39
|
+
if (e.length === 0) throw Error("and() requires at least one expression");
|
|
40
|
+
return new r("and", e);
|
|
41
|
+
}
|
|
42
|
+
function a(...e) {
|
|
43
|
+
if (e.length === 0) throw Error("or() requires at least one expression");
|
|
44
|
+
return new r("or", e);
|
|
45
|
+
}
|
|
46
|
+
function o(e) {
|
|
47
|
+
return new r("not", [e]);
|
|
48
|
+
}
|
|
49
|
+
function s(e, t) {
|
|
50
|
+
return new r("implies", [e, t]);
|
|
51
|
+
}
|
|
52
|
+
function c(...e) {
|
|
53
|
+
if (e.length === 0) throw Error("xor() requires at least one expression");
|
|
54
|
+
return new r("xor", e);
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/modeler/constraint.ts
|
|
58
|
+
var l = 0, u = class {
|
|
59
|
+
id;
|
|
60
|
+
lhs;
|
|
61
|
+
sense;
|
|
62
|
+
rhs;
|
|
63
|
+
name;
|
|
64
|
+
slack = null;
|
|
65
|
+
dual = null;
|
|
66
|
+
constructor(e, t, n, r) {
|
|
67
|
+
this.id = ++l, this.lhs = e, this.sense = t, this.rhs = n, this.name = r || `c_${this.id}`;
|
|
68
|
+
}
|
|
69
|
+
get pi() {
|
|
70
|
+
return this.dual;
|
|
71
|
+
}
|
|
72
|
+
and(e) {
|
|
73
|
+
return new r("and", [this, e]);
|
|
74
|
+
}
|
|
75
|
+
or(e) {
|
|
76
|
+
return new r("or", [this, e]);
|
|
77
|
+
}
|
|
78
|
+
implies(e) {
|
|
79
|
+
return new r("implies", [this, e]);
|
|
80
|
+
}
|
|
81
|
+
xor(e) {
|
|
82
|
+
return new r("xor", [this, e]);
|
|
83
|
+
}
|
|
84
|
+
not() {
|
|
85
|
+
return new r("not", [this]);
|
|
86
|
+
}
|
|
87
|
+
toString() {
|
|
88
|
+
let e = this.sense === "==" ? "=" : this.sense;
|
|
89
|
+
return `${this.name}: ${this.lhs.toString()} ${e} ${this.rhs}`;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
//#endregion
|
|
93
|
+
export { i as a, a as c, n as i, c as l, t as n, s as o, r, o as s, u as t };
|
package/dist/lib/highs-worker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as e } from "./
|
|
2
|
-
//#region src/highs
|
|
1
|
+
import { c as e } from "./loader-Dti0v9yC.js";
|
|
2
|
+
//#region src/modeler/solvers/highs/worker.ts
|
|
3
3
|
self.onmessage = async (t) => {
|
|
4
4
|
let { type: n, id: r, lpString: i, options: a } = t.data;
|
|
5
5
|
if (n === "SOLVE") try {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getBundledWasmUrl as e } from "./highs-assets.js";
|
|
2
2
|
import { loadNodeHighs as t } from "./highs-node-runtime.js";
|
|
3
|
-
//#region src/highs
|
|
3
|
+
//#region src/modeler/solvers/highs/loader.ts
|
|
4
4
|
var n = "https://cdn.jsdelivr.net/npm/highs@1.15.3/build/highs.wasm", r = null, i = null, a = null;
|
|
5
5
|
function o(e) {
|
|
6
6
|
a = e, r = null, i = null;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/modeler/solvers/registry.ts
|
|
2
|
+
var e = Symbol.for("washi.solverRegistry"), t = Symbol.for("washi.defaultSolverFactory"), n = globalThis;
|
|
3
|
+
n[e] || (n[e] = /* @__PURE__ */ new Map());
|
|
4
|
+
var r = n[e];
|
|
5
|
+
function i(e, t) {
|
|
6
|
+
r.set(e.toLowerCase(), t);
|
|
7
|
+
}
|
|
8
|
+
function a(e) {
|
|
9
|
+
if (typeof e == "string") {
|
|
10
|
+
let i = r.get(e.toLowerCase());
|
|
11
|
+
if (!i) throw Error(`Solver '${e}' is not registered.`);
|
|
12
|
+
n[t] = i;
|
|
13
|
+
} else n[t] = typeof e == "function" ? e : () => e;
|
|
14
|
+
}
|
|
15
|
+
function o(e, i) {
|
|
16
|
+
if (!e) {
|
|
17
|
+
let e = n[t] || r.get("highs");
|
|
18
|
+
if (!e) throw Error(`No default solver available. Available solvers: ${s().join(", ")}`);
|
|
19
|
+
return e(i);
|
|
20
|
+
}
|
|
21
|
+
if (typeof e == "string") {
|
|
22
|
+
let t = e.toLowerCase(), n = r.get(t);
|
|
23
|
+
if (!n) throw Error(t === "glpk" ? `Solver 'glpk' not found. Available solvers: ${s().join(", ")}. Please import '@ohtaman/washi/solvers/glpk' before selecting this solver.` : t === "z3" ? `Solver 'z3' not found. Available solvers: ${s().join(", ")}. Please import '@ohtaman/washi/solvers/z3' before selecting this solver.` : `Solver '${e}' not found. Available solvers: ${s().join(", ")}`);
|
|
24
|
+
return n(i);
|
|
25
|
+
}
|
|
26
|
+
return e;
|
|
27
|
+
}
|
|
28
|
+
function s() {
|
|
29
|
+
return Array.from(r.keys());
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { a as i, s as n, i as r, o as t };
|
package/dist/lib/solvers/glpk.js
CHANGED
|
@@ -1,2 +1,153 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { r as e } from "../registry-DksqCSjI.js";
|
|
2
|
+
//#region src/modeler/solvers/glpk/loader.ts
|
|
3
|
+
var t = null, n = null;
|
|
4
|
+
async function r() {
|
|
5
|
+
if (t) return t;
|
|
6
|
+
let e = (async () => {
|
|
7
|
+
let e = typeof process < "u" && process.versions && process.versions.node && process.type !== "renderer";
|
|
8
|
+
try {
|
|
9
|
+
if (e) {
|
|
10
|
+
let e = await import(
|
|
11
|
+
/* webpackIgnore: true */
|
|
12
|
+
/* @vite-ignore */
|
|
13
|
+
"glpk.js/node"
|
|
14
|
+
), t = await (e.default || e)();
|
|
15
|
+
return n = t, t;
|
|
16
|
+
}
|
|
17
|
+
let t = await import("glpk.js"), r = await (t.default || t)();
|
|
18
|
+
return n = r, r;
|
|
19
|
+
} catch (e) {
|
|
20
|
+
throw Error("[WaSHI] Could not load GLPK. Install the optional glpk.js dependency before selecting this solver.", { cause: e });
|
|
21
|
+
}
|
|
22
|
+
})();
|
|
23
|
+
return e.catch(() => {
|
|
24
|
+
t === e && (t = null, n = null);
|
|
25
|
+
}), t = e, e;
|
|
26
|
+
}
|
|
27
|
+
function i() {
|
|
28
|
+
if (n && typeof n.terminate == "function") try {
|
|
29
|
+
n.terminate();
|
|
30
|
+
} catch {}
|
|
31
|
+
n = null, t = null;
|
|
32
|
+
}
|
|
33
|
+
function a() {
|
|
34
|
+
i();
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/modeler/solvers/glpk/solver.ts
|
|
38
|
+
var o = class e {
|
|
39
|
+
static capabilities = {
|
|
40
|
+
supportsMIP: !0,
|
|
41
|
+
supportsQP: !1
|
|
42
|
+
};
|
|
43
|
+
name = "GLPK";
|
|
44
|
+
version = "5.0.0";
|
|
45
|
+
capabilities = e.capabilities;
|
|
46
|
+
options;
|
|
47
|
+
constructor(e = {}) {
|
|
48
|
+
this.options = e;
|
|
49
|
+
}
|
|
50
|
+
async solve(e, t, n = {}) {
|
|
51
|
+
let i = {
|
|
52
|
+
...this.options,
|
|
53
|
+
...n
|
|
54
|
+
}, a = await r(), { nameToVar: o, nameToConstraint: s } = t, c = /* @__PURE__ */ new Map();
|
|
55
|
+
for (let [e, t] of o.entries()) c.set(t, e);
|
|
56
|
+
let l = /* @__PURE__ */ new Map();
|
|
57
|
+
for (let [e, t] of s.entries()) l.set(t, e);
|
|
58
|
+
let u = [], d = "linearTerms" in e.objective ? e.objective.linearTerms : e.objective.terms;
|
|
59
|
+
if (d) for (let [e, t] of d) {
|
|
60
|
+
if (Math.abs(t) < 1e-12) continue;
|
|
61
|
+
let n = c.get(e) || e.name;
|
|
62
|
+
u.push({
|
|
63
|
+
name: n,
|
|
64
|
+
coef: Number(t)
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
let f = [];
|
|
68
|
+
for (let t of e.constraints) {
|
|
69
|
+
let e = l.get(t) || t.name || `c_${f.length + 1}`, n = [];
|
|
70
|
+
for (let [e, r] of t.lhs.terms) {
|
|
71
|
+
if (Math.abs(r) < 1e-12) continue;
|
|
72
|
+
let t = c.get(e) || e.name;
|
|
73
|
+
n.push({
|
|
74
|
+
name: t,
|
|
75
|
+
coef: Number(r)
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
let r;
|
|
79
|
+
r = t.sense === "==" ? {
|
|
80
|
+
type: a.GLP_FX,
|
|
81
|
+
lb: t.rhs,
|
|
82
|
+
ub: t.rhs
|
|
83
|
+
} : t.sense === "<=" ? {
|
|
84
|
+
type: a.GLP_UP,
|
|
85
|
+
lb: -Infinity,
|
|
86
|
+
ub: t.rhs
|
|
87
|
+
} : {
|
|
88
|
+
type: a.GLP_LO,
|
|
89
|
+
lb: t.rhs,
|
|
90
|
+
ub: Infinity
|
|
91
|
+
}, f.push({
|
|
92
|
+
name: e,
|
|
93
|
+
vars: n,
|
|
94
|
+
bnds: r
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
let p = [], m = [], h = [];
|
|
98
|
+
for (let t of e.variables) {
|
|
99
|
+
let e = c.get(t) || t.name;
|
|
100
|
+
t.type === "Binary" ? p.push(e) : t.type === "Integer" && m.push(e);
|
|
101
|
+
let n = t.lb, r = t.ub, i;
|
|
102
|
+
i = n === -Infinity && r === Infinity ? a.GLP_FR : n !== -Infinity && r === Infinity ? a.GLP_LO : n === -Infinity && r !== Infinity ? a.GLP_UP : n === r ? a.GLP_FX : a.GLP_DB, h.push({
|
|
103
|
+
name: e,
|
|
104
|
+
type: i,
|
|
105
|
+
lb: n === -Infinity ? 0 : n,
|
|
106
|
+
ub: r === Infinity ? 0 : r
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
let g = {
|
|
110
|
+
name: e.name || "GLPK_Model",
|
|
111
|
+
objective: {
|
|
112
|
+
direction: e.sense === "Maximize" ? a.GLP_MAX : a.GLP_MIN,
|
|
113
|
+
name: "obj",
|
|
114
|
+
vars: u
|
|
115
|
+
},
|
|
116
|
+
subjectTo: f
|
|
117
|
+
};
|
|
118
|
+
h.length > 0 && (g.bounds = h), p.length > 0 && (g.binaries = p), m.length > 0 && (g.generals = m);
|
|
119
|
+
let _ = {
|
|
120
|
+
msglev: i.verbose ? a.GLP_MSG_ALL : a.GLP_MSG_OFF,
|
|
121
|
+
presol: i.presolve !== "off"
|
|
122
|
+
};
|
|
123
|
+
typeof i.timeLimit == "number" && (_.tmlim = i.timeLimit), typeof i.mipGap == "number" && (_.mipgap = i.mipGap);
|
|
124
|
+
let v = performance.now(), y = await a.solve(g, _), b = (performance.now() - v) / 1e3, x = y?.result?.status, S;
|
|
125
|
+
S = x === a.GLP_OPT ? "Optimal" : x === a.GLP_FEAS ? "Feasible" : x === a.GLP_INFEAS || x === a.GLP_NOFEAS ? "Infeasible" : x === a.GLP_UNBND ? "Unbounded" : "Optimal";
|
|
126
|
+
let C = y?.result?.z, w = typeof C == "number" ? C + e.objective.constant : null, T = {}, E = y?.result?.vars || {};
|
|
127
|
+
for (let [e, t] of Object.entries(E)) {
|
|
128
|
+
let n = o.get(e), r = n ? n.name : e;
|
|
129
|
+
T[r] = typeof t == "number" ? Math.abs(t) < 1e-9 ? 0 : t : 0;
|
|
130
|
+
}
|
|
131
|
+
for (let t of e.variables) T[t.name] === void 0 && (T[t.name] = 0);
|
|
132
|
+
let D = {};
|
|
133
|
+
if (y?.result?.dual) for (let [e, t] of Object.entries(y.result.dual)) {
|
|
134
|
+
let n = s.get(e), r = n ? n.name : e;
|
|
135
|
+
D[r] = Number(t);
|
|
136
|
+
}
|
|
137
|
+
return {
|
|
138
|
+
status: S,
|
|
139
|
+
objectiveValue: w,
|
|
140
|
+
values: T,
|
|
141
|
+
duals: D,
|
|
142
|
+
runTime: y?.time || b,
|
|
143
|
+
logs: [`GLPK solved in ${(y?.time || b) * 1e3} ms.`],
|
|
144
|
+
raw: y
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
function s() {
|
|
149
|
+
e("glpk", (e) => new o(e));
|
|
150
|
+
}
|
|
151
|
+
s();
|
|
152
|
+
//#endregion
|
|
153
|
+
export { o as GLPKSolver, r as getGlpk, s as registerGLPKSolver, a as resetGlpkCache, i as terminateGlpk };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function getBundledZ3AssetUrls() { return { jsUrl: new URL("./z3-built.js", import.meta.url).href, wasmUrl: new URL("./z3-built.wasm", import.meta.url).href }; }
|