@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
package/dist/lib/washi-logo.png
DELETED
|
Binary file
|
package/dist/lib/washi-logo.svg
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 240 240" fill="none">
|
|
2
|
-
<defs>
|
|
3
|
-
<!-- Facet 1: Crimson Red (Warm / Craft) -->
|
|
4
|
-
<linearGradient id="craneRedTop" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
5
|
-
<stop offset="0%" stop-color="#FF385C" />
|
|
6
|
-
<stop offset="100%" stop-color="#E11D48" />
|
|
7
|
-
</linearGradient>
|
|
8
|
-
<linearGradient id="craneRedBottom" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
9
|
-
<stop offset="0%" stop-color="#BE123C" />
|
|
10
|
-
<stop offset="100%" stop-color="#881337" />
|
|
11
|
-
</linearGradient>
|
|
12
|
-
<linearGradient id="craneRedNeck" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
13
|
-
<stop offset="0%" stop-color="#FB7185" />
|
|
14
|
-
<stop offset="100%" stop-color="#E11D48" />
|
|
15
|
-
</linearGradient>
|
|
16
|
-
|
|
17
|
-
<!-- Facet 2: Center Origami Transition (Purple / Logic) -->
|
|
18
|
-
<linearGradient id="craneBodyLeft" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
19
|
-
<stop offset="0%" stop-color="#E11D48" />
|
|
20
|
-
<stop offset="100%" stop-color="#9333EA" />
|
|
21
|
-
</linearGradient>
|
|
22
|
-
<linearGradient id="craneBodyRight" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
23
|
-
<stop offset="0%" stop-color="#9333EA" />
|
|
24
|
-
<stop offset="100%" stop-color="#4F46E5" />
|
|
25
|
-
</linearGradient>
|
|
26
|
-
|
|
27
|
-
<!-- Facet 3: Electric Indigo (Cool / Tech & Solver) -->
|
|
28
|
-
<linearGradient id="craneIndigoTop" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
29
|
-
<stop offset="0%" stop-color="#6366F1" />
|
|
30
|
-
<stop offset="100%" stop-color="#4F46E5" />
|
|
31
|
-
</linearGradient>
|
|
32
|
-
<linearGradient id="craneIndigoBottom" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
33
|
-
<stop offset="0%" stop-color="#4338CA" />
|
|
34
|
-
<stop offset="100%" stop-color="#312E81" />
|
|
35
|
-
</linearGradient>
|
|
36
|
-
<linearGradient id="craneIndigoTail" x1="0%" y1="0%" x2="100%" y2="100%">
|
|
37
|
-
<stop offset="0%" stop-color="#818CF8" />
|
|
38
|
-
<stop offset="100%" stop-color="#4F46E5" />
|
|
39
|
-
</linearGradient>
|
|
40
|
-
</defs>
|
|
41
|
-
|
|
42
|
-
<g id="washi-origami-symbol" stroke="#FFFFFF" stroke-opacity="0.2" stroke-width="0.8" stroke-linejoin="round">
|
|
43
|
-
<!-- 1. Left Neck & Head (Origami fold) -->
|
|
44
|
-
<polygon points="120,110 75,35 60,50 95,120" fill="url(#craneRedNeck)" />
|
|
45
|
-
<polygon points="75,35 60,50 50,42" fill="#E11D48" />
|
|
46
|
-
|
|
47
|
-
<!-- 2. Right Tail (Origami fold) -->
|
|
48
|
-
<polygon points="120,110 165,35 145,120" fill="url(#craneIndigoTail)" />
|
|
49
|
-
|
|
50
|
-
<!-- 3. Left Wing (Main Upper Facet) -->
|
|
51
|
-
<polygon points="120,110 15,55 95,145" fill="url(#craneRedTop)" />
|
|
52
|
-
<!-- Left Wing (Under Facet) -->
|
|
53
|
-
<polygon points="15,55 95,145 70,170" fill="url(#craneRedBottom)" />
|
|
54
|
-
|
|
55
|
-
<!-- 4. Right Wing (Main Upper Facet) -->
|
|
56
|
-
<polygon points="120,110 225,55 145,145" fill="url(#craneIndigoTop)" />
|
|
57
|
-
<!-- Right Wing (Under Facet) -->
|
|
58
|
-
<polygon points="225,55 145,145 170,170" fill="url(#craneIndigoBottom)" />
|
|
59
|
-
|
|
60
|
-
<!-- 5. Center Diamond Keel (Polytope Core) -->
|
|
61
|
-
<polygon points="120,110 95,145 120,195" fill="url(#craneBodyLeft)" />
|
|
62
|
-
<polygon points="120,110 145,145 120,195" fill="url(#craneBodyRight)" />
|
|
63
|
-
|
|
64
|
-
<!-- 6. Extreme Points / Optimal Mathematical Vertices -->
|
|
65
|
-
<circle cx="15" cy="55" r="4" fill="#FFFFFF" stroke="#E11D48" stroke-width="2" />
|
|
66
|
-
<circle cx="225" cy="55" r="4" fill="#FFFFFF" stroke="#4F46E5" stroke-width="2" />
|
|
67
|
-
<circle cx="120" cy="195" r="4" fill="#FFFFFF" stroke="#9333EA" stroke-width="2" />
|
|
68
|
-
<circle cx="120" cy="110" r="3" fill="#FFFFFF" stroke="#C026D3" stroke-width="1.5" />
|
|
69
|
-
</g>
|
|
70
|
-
</svg>
|
package/dist/lib/z3-C8g-PtmP.js
DELETED
|
@@ -1,582 +0,0 @@
|
|
|
1
|
-
import { t as e } from "./glpk-BC32ZaPG.js";
|
|
2
|
-
//#region src/modeler/boolean-expr.ts
|
|
3
|
-
var t = 0, n = class {
|
|
4
|
-
and(e) {
|
|
5
|
-
return new i("and", [this, e]);
|
|
6
|
-
}
|
|
7
|
-
or(e) {
|
|
8
|
-
return new i("or", [this, e]);
|
|
9
|
-
}
|
|
10
|
-
implies(e) {
|
|
11
|
-
return new i("implies", [this, e]);
|
|
12
|
-
}
|
|
13
|
-
xor(e) {
|
|
14
|
-
return new i("xor", [this, e]);
|
|
15
|
-
}
|
|
16
|
-
not() {
|
|
17
|
-
return new i("not", [this]);
|
|
18
|
-
}
|
|
19
|
-
}, r = class extends n {
|
|
20
|
-
id;
|
|
21
|
-
name;
|
|
22
|
-
value = null;
|
|
23
|
-
constructor(e) {
|
|
24
|
-
super(), this.id = ++t, this.name = e || `p_${this.id}`;
|
|
25
|
-
}
|
|
26
|
-
toString() {
|
|
27
|
-
return this.name;
|
|
28
|
-
}
|
|
29
|
-
}, i = class extends n {
|
|
30
|
-
op;
|
|
31
|
-
children;
|
|
32
|
-
constructor(e, t) {
|
|
33
|
-
super(), this.op = e, this.children = t;
|
|
34
|
-
}
|
|
35
|
-
toString() {
|
|
36
|
-
return this.op === "not" ? `not(${this.children[0].toString()})` : `(${this.children.map((e) => e.toString()).join(` ${this.op} `)})`;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
function a(...e) {
|
|
40
|
-
if (e.length === 0) throw Error("and() requires at least one expression");
|
|
41
|
-
return new i("and", e);
|
|
42
|
-
}
|
|
43
|
-
function o(...e) {
|
|
44
|
-
if (e.length === 0) throw Error("or() requires at least one expression");
|
|
45
|
-
return new i("or", e);
|
|
46
|
-
}
|
|
47
|
-
function s(e) {
|
|
48
|
-
return new i("not", [e]);
|
|
49
|
-
}
|
|
50
|
-
function c(e, t) {
|
|
51
|
-
return new i("implies", [e, t]);
|
|
52
|
-
}
|
|
53
|
-
function l(...e) {
|
|
54
|
-
if (e.length === 0) throw Error("xor() requires at least one expression");
|
|
55
|
-
return new i("xor", e);
|
|
56
|
-
}
|
|
57
|
-
//#endregion
|
|
58
|
-
//#region src/modeler/constraint.ts
|
|
59
|
-
var u = 0, d = class {
|
|
60
|
-
id;
|
|
61
|
-
lhs;
|
|
62
|
-
sense;
|
|
63
|
-
rhs;
|
|
64
|
-
name;
|
|
65
|
-
slack = null;
|
|
66
|
-
dual = null;
|
|
67
|
-
constructor(e, t, n, r) {
|
|
68
|
-
this.id = ++u, this.lhs = e, this.sense = t, this.rhs = n, this.name = r || `c_${this.id}`;
|
|
69
|
-
}
|
|
70
|
-
get pi() {
|
|
71
|
-
return this.dual;
|
|
72
|
-
}
|
|
73
|
-
and(e) {
|
|
74
|
-
return new i("and", [this, e]);
|
|
75
|
-
}
|
|
76
|
-
or(e) {
|
|
77
|
-
return new i("or", [this, e]);
|
|
78
|
-
}
|
|
79
|
-
implies(e) {
|
|
80
|
-
return new i("implies", [this, e]);
|
|
81
|
-
}
|
|
82
|
-
xor(e) {
|
|
83
|
-
return new i("xor", [this, e]);
|
|
84
|
-
}
|
|
85
|
-
not() {
|
|
86
|
-
return new i("not", [this]);
|
|
87
|
-
}
|
|
88
|
-
toString() {
|
|
89
|
-
let e = this.sense === "==" ? "=" : this.sense;
|
|
90
|
-
return `${this.name}: ${this.lhs.toString()} ${e} ${this.rhs}`;
|
|
91
|
-
}
|
|
92
|
-
}, f = "https://cdn.jsdelivr.net/npm/highs@1.15.3/build/highs.wasm", p = null, m = null;
|
|
93
|
-
function h(e) {
|
|
94
|
-
m = e, p = null;
|
|
95
|
-
}
|
|
96
|
-
function g() {
|
|
97
|
-
return m;
|
|
98
|
-
}
|
|
99
|
-
function _(e) {
|
|
100
|
-
return e.length >= 4 && e[0] === 0 && e[1] === 97 && e[2] === 115 && e[3] === 109;
|
|
101
|
-
}
|
|
102
|
-
async function v(e) {
|
|
103
|
-
try {
|
|
104
|
-
let t = await fetch(e, { headers: { Range: "bytes=0-3" } });
|
|
105
|
-
if (!t.ok || (t.headers.get("content-type") || "").includes("text/html")) return !1;
|
|
106
|
-
if (!t.body) return !0;
|
|
107
|
-
let n = t.body.getReader(), { value: r, done: i } = await n.read();
|
|
108
|
-
return await n.cancel(), i || !r || r.length < 4 ? !1 : _(r);
|
|
109
|
-
} catch {
|
|
110
|
-
return !1;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
async function y(e) {
|
|
114
|
-
if (e) return e;
|
|
115
|
-
if (m) return m;
|
|
116
|
-
let t = typeof window < "u" ? new URL("/highs.wasm", window.location.origin).href : typeof self < "u" && self.location ? new URL("highs.wasm", self.location.href).href : "/highs.wasm";
|
|
117
|
-
return await v(t) ? t : (typeof console < "u" && console.info && console.info(`[WaSHI] Local highs.wasm not found or invalid at "${t}". Automatically falling back to official CDN: ${f}`), f);
|
|
118
|
-
}
|
|
119
|
-
async function b(e = {}) {
|
|
120
|
-
return p || (p = (async () => {
|
|
121
|
-
let t = await import("highs"), n = t.default || t;
|
|
122
|
-
if (typeof process < "u" && process.versions && process.versions.node && process.type !== "renderer") return await n();
|
|
123
|
-
let r = await y(e.wasmUrl);
|
|
124
|
-
return await n({ locateFile: (e) => e.endsWith(".wasm") ? r : e });
|
|
125
|
-
})(), p);
|
|
126
|
-
}
|
|
127
|
-
async function x(e, t = {}) {
|
|
128
|
-
let n = await b(t), r = performance.now(), i = { output_flag: t.outputFlag ?? !1 };
|
|
129
|
-
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), {
|
|
130
|
-
result: n.solve(e, i),
|
|
131
|
-
runTime: (performance.now() - r) / 1e3
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
//#endregion
|
|
135
|
-
//#region src/highs-worker-client.ts
|
|
136
|
-
var S = null, C = 0, w = /* @__PURE__ */ new Map();
|
|
137
|
-
function T() {
|
|
138
|
-
if (typeof window > "u" || typeof Worker > "u") return null;
|
|
139
|
-
if (!S) try {
|
|
140
|
-
S = new Worker(new URL(
|
|
141
|
-
/* @vite-ignore */
|
|
142
|
-
"/assets/highs-worker-DeDWU6KI.js",
|
|
143
|
-
"" + import.meta.url
|
|
144
|
-
), { type: "module" }), S.onmessage = (e) => {
|
|
145
|
-
let { type: t, id: n, result: r, runTime: i, error: a } = e.data, o = w.get(n);
|
|
146
|
-
o && (w.delete(n), t === "SOLVE_SUCCESS" ? o.resolve({
|
|
147
|
-
result: r,
|
|
148
|
-
runTime: i
|
|
149
|
-
}) : o.reject(Error(a || "Worker solve failed")));
|
|
150
|
-
}, S.onerror = (e) => {
|
|
151
|
-
console.error("HiGHS Web Worker error:", e);
|
|
152
|
-
};
|
|
153
|
-
} catch (e) {
|
|
154
|
-
console.warn("Could not instantiate Web Worker, falling back to main thread:", e), S = null;
|
|
155
|
-
}
|
|
156
|
-
return S;
|
|
157
|
-
}
|
|
158
|
-
async function E(e, t = {}) {
|
|
159
|
-
let n = t.useWorker ?? typeof window < "u" ? T() : null;
|
|
160
|
-
if (!n) return x(e, t);
|
|
161
|
-
let r = await y(t.wasmUrl), i = {
|
|
162
|
-
...t,
|
|
163
|
-
wasmUrl: r
|
|
164
|
-
}, a = `req_${++C}`;
|
|
165
|
-
return new Promise((t, r) => {
|
|
166
|
-
w.set(a, {
|
|
167
|
-
resolve: t,
|
|
168
|
-
reject: r
|
|
169
|
-
}), n.postMessage({
|
|
170
|
-
type: "SOLVE",
|
|
171
|
-
id: a,
|
|
172
|
-
lpString: e,
|
|
173
|
-
options: i
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
//#endregion
|
|
178
|
-
//#region src/modeler/solvers/highs.ts
|
|
179
|
-
var D = class e {
|
|
180
|
-
static capabilities = {
|
|
181
|
-
supportsMIP: !0,
|
|
182
|
-
supportsQP: !0
|
|
183
|
-
};
|
|
184
|
-
name = "HiGHS";
|
|
185
|
-
version = "1.15.3";
|
|
186
|
-
capabilities = e.capabilities;
|
|
187
|
-
options;
|
|
188
|
-
constructor(e = {}) {
|
|
189
|
-
this.options = e;
|
|
190
|
-
}
|
|
191
|
-
async solve(e, t, n = {}) {
|
|
192
|
-
let r = {
|
|
193
|
-
...this.options,
|
|
194
|
-
...n
|
|
195
|
-
}, { lpString: i, nameToVar: a, nameToConstraint: o } = t, { result: s, runTime: c } = await E(i, r), l = s.Status || "Unknown", u;
|
|
196
|
-
u = l.includes("Optimal") ? "Optimal" : l.includes("Infeasible") ? "Infeasible" : l.includes("Unbounded") ? "Unbounded" : l.includes("TimeLimit") || l.includes("Time limit") ? "TimeLimit" : l.includes("IterationLimit") ? "IterationLimit" : "Optimal";
|
|
197
|
-
let d = s.ObjectiveValue, f = typeof d == "number" ? d + e.objective.constant : null, p = {}, m = {}, h = {}, g = {};
|
|
198
|
-
if (s.Columns) for (let [e, t] of Object.entries(s.Columns)) {
|
|
199
|
-
let n = a.get(e);
|
|
200
|
-
if (n) {
|
|
201
|
-
let e = Math.abs(t.Primal) < 1e-9 ? 0 : t.Primal;
|
|
202
|
-
p[n.name] = e, t.Dual !== void 0 && (h[n.name] = Math.abs(t.Dual) < 1e-9 ? 0 : t.Dual);
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
if (s.Rows) {
|
|
206
|
-
let e = Array.isArray(s.Rows) ? s.Rows : Object.values(s.Rows);
|
|
207
|
-
for (let t of e) {
|
|
208
|
-
let e = t.Name, n = o.get(e);
|
|
209
|
-
if (n && (t.Dual !== void 0 && (m[n.name] = Math.abs(t.Dual) < 1e-9 ? 0 : t.Dual), t.Primal !== void 0)) {
|
|
210
|
-
let e = n.rhs - t.Primal;
|
|
211
|
-
g[n.name] = Math.abs(e) < 1e-9 ? 0 : e;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
return {
|
|
216
|
-
status: u,
|
|
217
|
-
objectiveValue: f,
|
|
218
|
-
values: p,
|
|
219
|
-
reducedCosts: h,
|
|
220
|
-
duals: m,
|
|
221
|
-
slacks: g,
|
|
222
|
-
runTime: c,
|
|
223
|
-
raw: s
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
}, O = D, k = class {
|
|
227
|
-
name;
|
|
228
|
-
capabilities;
|
|
229
|
-
options;
|
|
230
|
-
constructor(e = {}) {
|
|
231
|
-
this.name = e.name || "MockSolver", this.capabilities = e.capabilities || {
|
|
232
|
-
supportsMIP: !0,
|
|
233
|
-
supportsQP: !0
|
|
234
|
-
}, this.options = e;
|
|
235
|
-
}
|
|
236
|
-
async solve(e, t, n = {}) {
|
|
237
|
-
let r = {
|
|
238
|
-
...this.options,
|
|
239
|
-
...n
|
|
240
|
-
};
|
|
241
|
-
return r.delayMs && r.delayMs > 0 && await new Promise((e) => setTimeout(e, r.delayMs)), {
|
|
242
|
-
status: r.status || "Optimal",
|
|
243
|
-
objectiveValue: r.objectiveValue ?? 0,
|
|
244
|
-
values: r.values || {},
|
|
245
|
-
reducedCosts: r.reducedCosts,
|
|
246
|
-
duals: r.duals,
|
|
247
|
-
slacks: r.slacks,
|
|
248
|
-
runTime: .001,
|
|
249
|
-
raw: { mock: !0 }
|
|
250
|
-
};
|
|
251
|
-
}
|
|
252
|
-
}, A = /* @__PURE__ */ new Map();
|
|
253
|
-
A.set("highs", (e) => new D(e)), A.set("glpk", (t) => new e(t)), A.set("mock", (e) => new k(e));
|
|
254
|
-
var j = (e) => new D(e);
|
|
255
|
-
function M(e, t) {
|
|
256
|
-
A.set(e.toLowerCase(), t);
|
|
257
|
-
}
|
|
258
|
-
function N(e) {
|
|
259
|
-
if (typeof e == "string") {
|
|
260
|
-
let t = A.get(e.toLowerCase());
|
|
261
|
-
if (!t) throw Error(`Solver '${e}' is not registered.`);
|
|
262
|
-
j = t;
|
|
263
|
-
} else j = typeof e == "function" ? e : () => e;
|
|
264
|
-
}
|
|
265
|
-
function P(e, t) {
|
|
266
|
-
if (!e) return j(t);
|
|
267
|
-
if (typeof e == "string") {
|
|
268
|
-
let n = A.get(e.toLowerCase());
|
|
269
|
-
if (!n) throw Error(`Solver '${e}' not found. Available solvers: ${F().join(", ")}`);
|
|
270
|
-
return n(t);
|
|
271
|
-
}
|
|
272
|
-
return e;
|
|
273
|
-
}
|
|
274
|
-
function F() {
|
|
275
|
-
return Array.from(A.keys());
|
|
276
|
-
}
|
|
277
|
-
//#endregion
|
|
278
|
-
//#region src/modeler/solvers/z3.ts
|
|
279
|
-
var I = null;
|
|
280
|
-
async function L() {
|
|
281
|
-
return I ||= (async () => {
|
|
282
|
-
try {
|
|
283
|
-
return await (await import("z3-solver")).init();
|
|
284
|
-
} catch (e) {
|
|
285
|
-
throw Error(`Failed to load z3-solver. Ensure it is installed: npm install z3-solver. Error: ${e instanceof Error ? e.message : String(e)}`);
|
|
286
|
-
}
|
|
287
|
-
})(), I;
|
|
288
|
-
}
|
|
289
|
-
var R = class {
|
|
290
|
-
name = "z3";
|
|
291
|
-
capabilities = {
|
|
292
|
-
supportsMIP: !0,
|
|
293
|
-
supportsQP: !1,
|
|
294
|
-
supportsSMT: !0,
|
|
295
|
-
supportsUnsatCore: !0
|
|
296
|
-
};
|
|
297
|
-
createContextTranslator(e) {
|
|
298
|
-
let t = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
|
|
299
|
-
function a(n) {
|
|
300
|
-
if (!t.has(n.name)) {
|
|
301
|
-
let r = n.type === "Continuous" || n.type === "CONTINUOUS" ? e.Real.const(n.name) : e.Int.const(n.name);
|
|
302
|
-
t.set(n.name, r);
|
|
303
|
-
}
|
|
304
|
-
return t.get(n.name);
|
|
305
|
-
}
|
|
306
|
-
function o(t) {
|
|
307
|
-
if (!n.has(t.name)) {
|
|
308
|
-
let r = e.Bool.const(t.name);
|
|
309
|
-
n.set(t.name, r);
|
|
310
|
-
}
|
|
311
|
-
return n.get(t.name);
|
|
312
|
-
}
|
|
313
|
-
function s(t) {
|
|
314
|
-
let n = null;
|
|
315
|
-
if (t && t.terms) for (let [e, r] of t.terms.entries()) {
|
|
316
|
-
let t = a(e).mul(r);
|
|
317
|
-
n = n === null ? t : n.add(t);
|
|
318
|
-
}
|
|
319
|
-
let r = t && typeof t.constant == "number" ? t.constant : 0;
|
|
320
|
-
if (r !== 0 || n === null) {
|
|
321
|
-
let t = e.Real.val(r);
|
|
322
|
-
n = n === null ? t : n.add(t);
|
|
323
|
-
}
|
|
324
|
-
return n;
|
|
325
|
-
}
|
|
326
|
-
function c(t) {
|
|
327
|
-
let n = null;
|
|
328
|
-
if (t.linearTerms) for (let [e, r] of t.linearTerms.entries()) {
|
|
329
|
-
let t = a(e).mul(r);
|
|
330
|
-
n = n === null ? t : n.add(t);
|
|
331
|
-
}
|
|
332
|
-
if (t.quadTerms) for (let e of t.quadTerms.values()) {
|
|
333
|
-
let t = a(e.var1), r = a(e.var2), i = t.mul(r).mul(e.coeff);
|
|
334
|
-
n = n === null ? i : n.add(i);
|
|
335
|
-
}
|
|
336
|
-
let r = t && typeof t.constant == "number" ? t.constant : 0;
|
|
337
|
-
if (r !== 0 || n === null) {
|
|
338
|
-
let t = e.Real.val(r);
|
|
339
|
-
n = n === null ? t : n.add(t);
|
|
340
|
-
}
|
|
341
|
-
return n;
|
|
342
|
-
}
|
|
343
|
-
function l(e) {
|
|
344
|
-
let t = e.lhs instanceof Object && "quadTerms" in e.lhs ? c(e.lhs) : s(e.lhs), n = typeof e.rhs == "number" ? e.rhs : 0;
|
|
345
|
-
return e.sense === "<=" ? t.le(n) : e.sense === ">=" ? t.ge(n) : t.eq(n);
|
|
346
|
-
}
|
|
347
|
-
function u(t) {
|
|
348
|
-
if (t instanceof r) return o(t);
|
|
349
|
-
if (t instanceof d) return l(t);
|
|
350
|
-
if (t instanceof i) switch (t.op) {
|
|
351
|
-
case "and": return e.And(...t.children.map(u));
|
|
352
|
-
case "or": return e.Or(...t.children.map(u));
|
|
353
|
-
case "not": return e.Not(u(t.children[0]));
|
|
354
|
-
case "implies": return e.Implies(u(t.children[0]), u(t.children[1]));
|
|
355
|
-
case "xor": return e.Xor(u(t.children[0]), u(t.children[1]));
|
|
356
|
-
default: throw Error(`Unsupported boolean operation: ${t.op}`);
|
|
357
|
-
}
|
|
358
|
-
throw Error(`Unknown logic element: ${String(t)}`);
|
|
359
|
-
}
|
|
360
|
-
function f(e) {
|
|
361
|
-
if (!e) return 0;
|
|
362
|
-
if (typeof e.asNumber == "function") return e.asNumber();
|
|
363
|
-
let t = e.toString();
|
|
364
|
-
if (t.startsWith("(/ ")) {
|
|
365
|
-
let e = t.slice(3, -1).trim().split(/\s+/);
|
|
366
|
-
if (e.length === 2) return Number(e[0]) / Number(e[1]);
|
|
367
|
-
}
|
|
368
|
-
return Number(t);
|
|
369
|
-
}
|
|
370
|
-
return {
|
|
371
|
-
getVarAst: a,
|
|
372
|
-
getBoolVarAst: o,
|
|
373
|
-
translateLinExpr: s,
|
|
374
|
-
translateQuadExpr: c,
|
|
375
|
-
translateConstraint: l,
|
|
376
|
-
translateBoolExpr: u,
|
|
377
|
-
parseAstValue: f,
|
|
378
|
-
varAstMap: t,
|
|
379
|
-
boolVarAstMap: n
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
async check(e, t = {}) {
|
|
383
|
-
if (typeof window < "u" && window.document !== void 0) return this.fallbackCheck(e);
|
|
384
|
-
try {
|
|
385
|
-
let { Context: t } = await L(), n = new t(`check_${Date.now()}_${Math.random().toString(36).substring(2, 7)}`), r = new n.Solver(), i = this.createContextTranslator(n), a = e.variables || e.vars || [], o = e.boolVars || [], s = e.constraints || [], c = e.logicalConstraints || [];
|
|
386
|
-
for (let e of a) {
|
|
387
|
-
let t = i.getVarAst(e);
|
|
388
|
-
e.lb !== -Infinity && r.add(t.ge(e.lb)), e.ub !== Infinity && r.add(t.le(e.ub)), (e.type === "Binary" || e.type === "BINARY") && (r.add(t.ge(0)), r.add(t.le(1)));
|
|
389
|
-
}
|
|
390
|
-
for (let e of s) {
|
|
391
|
-
let t = i.translateConstraint(e), a = n.Bool.const(e.name);
|
|
392
|
-
r.addAndTrack(t, a);
|
|
393
|
-
}
|
|
394
|
-
for (let e = 0; e < c.length; e++) {
|
|
395
|
-
let t = c[e], a = t && t.name || `lc_${e + 1}`, o = t && t.expr || t, s = i.translateBoolExpr(o), l = n.Bool.const(a);
|
|
396
|
-
r.addAndTrack(s, l);
|
|
397
|
-
}
|
|
398
|
-
let l = (await r.check()).toString();
|
|
399
|
-
if (l === "sat") {
|
|
400
|
-
let e = r.model(), t = {};
|
|
401
|
-
for (let n of a) {
|
|
402
|
-
let r = i.getVarAst(n), a = e.eval(r);
|
|
403
|
-
t[n.name] = i.parseAstValue(a);
|
|
404
|
-
}
|
|
405
|
-
for (let n of o) {
|
|
406
|
-
let r = i.getBoolVarAst(n), a = e.eval(r);
|
|
407
|
-
t[n.name] = a.toString() === "true";
|
|
408
|
-
}
|
|
409
|
-
return {
|
|
410
|
-
status: "Sat",
|
|
411
|
-
values: t
|
|
412
|
-
};
|
|
413
|
-
}
|
|
414
|
-
if (l === "unsat") {
|
|
415
|
-
let e = r.unsatCore(), t = [], n = typeof e.length == "function" ? e.length() : e.length;
|
|
416
|
-
for (let r = 0; r < n; r++) t.push(e.get(r).toString());
|
|
417
|
-
return {
|
|
418
|
-
status: "Unsat",
|
|
419
|
-
values: {},
|
|
420
|
-
unsatCore: t
|
|
421
|
-
};
|
|
422
|
-
}
|
|
423
|
-
return {
|
|
424
|
-
status: "Unknown",
|
|
425
|
-
values: {}
|
|
426
|
-
};
|
|
427
|
-
} catch {
|
|
428
|
-
return this.fallbackCheck(e);
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
fallbackCheck(e) {
|
|
432
|
-
let t = performance.now(), n = e.variables || e.vars || [], a = e.boolVars || [], o = e.constraints || [], s = e.logicalConstraints || [];
|
|
433
|
-
function c(e, t) {
|
|
434
|
-
let n = e.constant || 0;
|
|
435
|
-
if (e.terms && e.terms instanceof Map) for (let [r, i] of e.terms.entries()) {
|
|
436
|
-
let e = typeof r == "string" ? r : r.name;
|
|
437
|
-
n += i * (t.get(e) ?? 0);
|
|
438
|
-
}
|
|
439
|
-
return n;
|
|
440
|
-
}
|
|
441
|
-
function l(e, t) {
|
|
442
|
-
let n = c(e.lhs, t), r = 1e-6;
|
|
443
|
-
return e.sense === "<=" ? n <= e.rhs + r : e.sense === ">=" ? n >= e.rhs - r : e.sense === "==" && Math.abs(n - e.rhs) <= r;
|
|
444
|
-
}
|
|
445
|
-
function u(e, t, n) {
|
|
446
|
-
if (e instanceof r) return t.get(e.name) ?? !1;
|
|
447
|
-
if (e instanceof d) return l(e, n);
|
|
448
|
-
if (e instanceof i) switch (e.op) {
|
|
449
|
-
case "and": return e.children.every((e) => u(e, t, n));
|
|
450
|
-
case "or": return e.children.some((e) => u(e, t, n));
|
|
451
|
-
case "not": return !u(e.children[0], t, n);
|
|
452
|
-
case "implies": return !u(e.children[0], t, n) || u(e.children[1], t, n);
|
|
453
|
-
case "xor": return u(e.children[0], t, n) !== u(e.children[1], t, n);
|
|
454
|
-
}
|
|
455
|
-
return !1;
|
|
456
|
-
}
|
|
457
|
-
let f = /* @__PURE__ */ new Map();
|
|
458
|
-
for (let e of n) {
|
|
459
|
-
let t = /* @__PURE__ */ new Set();
|
|
460
|
-
e.lb !== -Infinity && t.add(e.lb), e.ub !== Infinity && t.add(e.ub), t.add(0);
|
|
461
|
-
for (let n of o) if (n.lhs.terms && n.lhs.terms.has(e)) {
|
|
462
|
-
let r = n.lhs.terms.get(e) || 1, i = (n.rhs - (n.lhs.constant || 0)) / r;
|
|
463
|
-
t.add(i), t.add(i - 1), t.add(i + 1);
|
|
464
|
-
}
|
|
465
|
-
for (let n of s) {
|
|
466
|
-
let r = n.expr || n, a = (n) => {
|
|
467
|
-
if (n instanceof d) {
|
|
468
|
-
if (n.lhs.terms && n.lhs.terms.has(e)) {
|
|
469
|
-
let r = n.lhs.terms.get(e) || 1, i = (n.rhs - (n.lhs.constant || 0)) / r;
|
|
470
|
-
t.add(i), t.add(i - 1), t.add(i + 1);
|
|
471
|
-
}
|
|
472
|
-
} else n instanceof i && n.children.forEach(a);
|
|
473
|
-
};
|
|
474
|
-
a(r);
|
|
475
|
-
}
|
|
476
|
-
if ((e.type === "Integer" || e.type === "INTEGER") && e.lb >= 0 && e.ub <= 25) for (let n = e.lb; n <= e.ub; n++) t.add(n);
|
|
477
|
-
f.set(e.name, Array.from(t).filter((t) => t >= (e.lb ?? -Infinity) && t <= (e.ub ?? Infinity)));
|
|
478
|
-
}
|
|
479
|
-
function p(e, t) {
|
|
480
|
-
let r = a.map((e) => e.name), i = 1 << r.length, o = n.map((e) => e.name), s = [/* @__PURE__ */ new Map()];
|
|
481
|
-
for (let e of o) {
|
|
482
|
-
let t = f.get(e) || [0], n = [];
|
|
483
|
-
for (let r of s) for (let i of t) {
|
|
484
|
-
let t = new Map(r);
|
|
485
|
-
t.set(e, i), n.push(t);
|
|
486
|
-
}
|
|
487
|
-
s = n.slice(0, 500);
|
|
488
|
-
}
|
|
489
|
-
for (let n = 0; n < i; n++) {
|
|
490
|
-
let i = /* @__PURE__ */ new Map();
|
|
491
|
-
for (let e = 0; e < r.length; e++) i.set(r[e], !!(n & 1 << e));
|
|
492
|
-
for (let n of s) if (e.every((e) => l(e, n)) && t.every((e) => u(e.expr, i, n))) return {
|
|
493
|
-
isSat: !0,
|
|
494
|
-
boolMap: i,
|
|
495
|
-
numMap: n
|
|
496
|
-
};
|
|
497
|
-
}
|
|
498
|
-
return { isSat: !1 };
|
|
499
|
-
}
|
|
500
|
-
let m = s.map((e, t) => ({
|
|
501
|
-
name: e?.name || `lc_${t + 1}`,
|
|
502
|
-
expr: e?.expr || e
|
|
503
|
-
})), h = p(o, m), g = (performance.now() - t) / 1e3;
|
|
504
|
-
if (h.isSat && h.boolMap && h.numMap) {
|
|
505
|
-
let e = {};
|
|
506
|
-
for (let [t, n] of h.numMap.entries()) e[t] = n;
|
|
507
|
-
for (let [t, n] of h.boolMap.entries()) e[t] = n;
|
|
508
|
-
return {
|
|
509
|
-
status: "Sat",
|
|
510
|
-
values: e,
|
|
511
|
-
runTime: g
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
let _ = [];
|
|
515
|
-
for (let e = 0; e < o.length; e++) p(o.filter((t, n) => n !== e), m).isSat && _.push(o[e].name);
|
|
516
|
-
for (let e = 0; e < m.length; e++) p(o, m.filter((t, n) => n !== e)).isSat && _.push(m[e].name);
|
|
517
|
-
return {
|
|
518
|
-
status: "Unsat",
|
|
519
|
-
values: {},
|
|
520
|
-
unsatCore: _.length > 0 ? _ : o.map((e) => e.name),
|
|
521
|
-
runTime: g
|
|
522
|
-
};
|
|
523
|
-
}
|
|
524
|
-
async solve(e, t, n = {}) {
|
|
525
|
-
if (!(e.objective !== null && e.objective !== void 0 && ("terms" in e.objective && e.objective.terms.size > 0 || "quadTerms" in e.objective && e.objective.quadTerms.length > 0 || e.objective.offset && e.objective.offset !== 0))) {
|
|
526
|
-
let t = await this.check(e, n), r = {};
|
|
527
|
-
for (let [e, n] of Object.entries(t.values)) r[e] = typeof n == "boolean" ? +!!n : n;
|
|
528
|
-
return {
|
|
529
|
-
status: t.status === "Sat" ? "Optimal" : t.status === "Unsat" ? "Infeasible" : "Error",
|
|
530
|
-
objectiveValue: 0,
|
|
531
|
-
values: r
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
let { Context: r } = await L(), i = new r(`opt_${Date.now()}_${Math.random().toString(36).substring(2, 7)}`), a = new i.Optimize(), o = this.createContextTranslator(i), s = e.variables || e.vars || [], c = e.boolVars || [], l = e.constraints || [], u = e.logicalConstraints || [];
|
|
535
|
-
for (let e of s) {
|
|
536
|
-
let t = o.getVarAst(e);
|
|
537
|
-
e.lb !== -Infinity && a.add(t.ge(e.lb)), e.ub !== Infinity && a.add(t.le(e.ub)), (e.type === "Binary" || e.type === "BINARY") && (a.add(t.ge(0)), a.add(t.le(1)));
|
|
538
|
-
}
|
|
539
|
-
for (let e of l) {
|
|
540
|
-
let t = o.translateConstraint(e);
|
|
541
|
-
a.add(t);
|
|
542
|
-
}
|
|
543
|
-
for (let e of u) {
|
|
544
|
-
let t = e && e.expr || e, n = o.translateBoolExpr(t);
|
|
545
|
-
a.add(n);
|
|
546
|
-
}
|
|
547
|
-
let d = e.objective instanceof Object && "quadTerms" in e.objective ? o.translateQuadExpr(e.objective) : o.translateLinExpr(e.objective);
|
|
548
|
-
(e.sense || "MINIMIZE").toUpperCase() === "MAXIMIZE" ? a.maximize(d) : a.minimize(d);
|
|
549
|
-
let f = (await a.check()).toString();
|
|
550
|
-
if (f === "sat") {
|
|
551
|
-
let e = a.model(), t = {};
|
|
552
|
-
for (let n of s) {
|
|
553
|
-
let r = o.getVarAst(n), i = e.eval(r);
|
|
554
|
-
t[n.name] = o.parseAstValue(i);
|
|
555
|
-
}
|
|
556
|
-
for (let n of c) {
|
|
557
|
-
let r = o.getBoolVarAst(n), i = e.eval(r);
|
|
558
|
-
t[n.name] = +(i.toString() === "true");
|
|
559
|
-
}
|
|
560
|
-
return {
|
|
561
|
-
status: "Optimal",
|
|
562
|
-
objectiveValue: o.parseAstValue(e.eval(d)),
|
|
563
|
-
values: t
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
return f === "unsat" ? {
|
|
567
|
-
status: "Infeasible",
|
|
568
|
-
objectiveValue: null,
|
|
569
|
-
values: {}
|
|
570
|
-
} : {
|
|
571
|
-
status: "Error",
|
|
572
|
-
objectiveValue: null,
|
|
573
|
-
values: {}
|
|
574
|
-
};
|
|
575
|
-
}
|
|
576
|
-
};
|
|
577
|
-
function z() {
|
|
578
|
-
M("z3", () => new R());
|
|
579
|
-
}
|
|
580
|
-
z();
|
|
581
|
-
//#endregion
|
|
582
|
-
export { c as C, l as E, a as S, o as T, x as _, M as a, i as b, O as c, b as d, g as f, h as g, y as h, F as i, D as l, v as m, z as n, N as o, _ as p, P as r, k as s, R as t, f as u, d as v, s as w, r as x, n as y };
|