@ohtaman/washi 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.ja.md +138 -122
  2. package/README.md +138 -122
  3. package/README.zh-CN.md +140 -124
  4. package/dist/browser/solvers/glpk.js +10 -2
  5. package/dist/browser/solvers/glpk.min.js +1 -1
  6. package/dist/browser/solvers/z3.js +34 -12
  7. package/dist/browser/solvers/z3.min.js +2 -2
  8. package/dist/browser/washi.js +562 -397
  9. package/dist/browser/washi.min.js +4 -4
  10. package/dist/lib/{constraint-XWdn0ID9.js → constraint-BRuB3ooC.js} +0 -3
  11. package/dist/lib/solvers/glpk.js +10 -2
  12. package/dist/lib/solvers/z3.js +35 -10
  13. package/dist/lib/washi.js +562 -412
  14. package/dist/types/index.d.ts +5 -7
  15. package/dist/types/index.d.ts.map +1 -1
  16. package/dist/types/modeler/constraint.d.ts +0 -3
  17. package/dist/types/modeler/constraint.d.ts.map +1 -1
  18. package/dist/types/modeler/expression.d.ts +23 -12
  19. package/dist/types/modeler/expression.d.ts.map +1 -1
  20. package/dist/types/modeler/index.d.ts +2 -4
  21. package/dist/types/modeler/index.d.ts.map +1 -1
  22. package/dist/types/modeler/model.d.ts +123 -40
  23. package/dist/types/modeler/model.d.ts.map +1 -1
  24. package/dist/types/modeler/parser.d.ts +9 -8
  25. package/dist/types/modeler/parser.d.ts.map +1 -1
  26. package/dist/types/modeler/quad-expr.d.ts +3 -1
  27. package/dist/types/modeler/quad-expr.d.ts.map +1 -1
  28. package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
  29. package/dist/types/modeler/solvers/highs/solver.d.ts +1 -1
  30. package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
  31. package/dist/types/modeler/solvers/types.d.ts +1 -1
  32. package/dist/types/modeler/solvers/z3/loader.d.ts +12 -0
  33. package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
  34. package/dist/types/modeler/types.d.ts +8 -3
  35. package/dist/types/modeler/types.d.ts.map +1 -1
  36. package/dist/types/modeler/variable.d.ts +7 -6
  37. package/dist/types/modeler/variable.d.ts.map +1 -1
  38. package/package.json +11 -3
  39. package/dist/types/modeler/mip-compat.d.ts +0 -43
  40. package/dist/types/modeler/mip-compat.d.ts.map +0 -1
  41. package/dist/types/modeler/pulp-compat.d.ts +0 -67
  42. package/dist/types/modeler/pulp-compat.d.ts.map +0 -1
@@ -66,9 +66,6 @@ var l = 0, u = class {
66
66
  constructor(e, t, n, r) {
67
67
  this.id = ++l, this.lhs = e, this.sense = t, this.rhs = n, this.name = r || `c_${this.id}`;
68
68
  }
69
- get pi() {
70
- return this.dual;
71
- }
72
69
  and(e) {
73
70
  return new r("and", [this, e]);
74
71
  }
@@ -109,7 +109,7 @@ var o = class e {
109
109
  let g = {
110
110
  name: e.name || "GLPK_Model",
111
111
  objective: {
112
- direction: e.sense === "Maximize" ? a.GLP_MAX : a.GLP_MIN,
112
+ direction: e.sense && e.sense.toLowerCase() === "maximize" ? a.GLP_MAX : a.GLP_MIN,
113
113
  name: "obj",
114
114
  vars: u
115
115
  },
@@ -122,7 +122,15 @@ var o = class e {
122
122
  };
123
123
  typeof i.timeLimit == "number" && (_.tmlim = i.timeLimit), typeof i.mipGap == "number" && (_.mipgap = i.mipGap);
124
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";
125
+ if (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", S === "Infeasible" || S === "Unbounded") return {
126
+ status: S,
127
+ objectiveValue: null,
128
+ values: {},
129
+ duals: {},
130
+ slacks: {},
131
+ runTime: b,
132
+ raw: y
133
+ };
126
134
  let C = y?.result?.z, w = typeof C == "number" ? C + e.objective.constant : null, T = {}, E = y?.result?.vars || {};
127
135
  for (let [e, t] of Object.entries(E)) {
128
136
  let n = o.get(e), r = n ? n.name : e;
@@ -1,4 +1,4 @@
1
- import { i as e, r as t, t as n } from "../constraint-XWdn0ID9.js";
1
+ import { i as e, r as t, t as n } from "../constraint-BRuB3ooC.js";
2
2
  import { r } from "../registry-DksqCSjI.js";
3
3
  import { getBundledZ3AssetUrls as i } from "./z3-assets.js";
4
4
  //#region src/modeler/solvers/z3/loader.ts
@@ -110,11 +110,16 @@ function b() {
110
110
  }
111
111
  async function x(e, t) {
112
112
  try {
113
- let n = await fetch(e, {
113
+ let n = null;
114
+ try {
115
+ let t = await fetch(e, { method: "HEAD" });
116
+ t.ok && (n = t);
117
+ } catch {}
118
+ if (n ||= await fetch(e, {
114
119
  method: "GET",
115
- headers: { Range: "bytes=0-3" }
116
- });
117
- if (!n.ok) throw Error(`server responded with HTTP status ${n.status} (${n.statusText || "Not Found"})`);
120
+ headers: { Range: "bytes=0-3" },
121
+ cache: "no-store"
122
+ }), !n.ok) throw Error(`server responded with HTTP status ${n.status} (${n.statusText || "Not Found"})`);
118
123
  if ((n.headers.get("content-type") || "").includes("text/html")) throw Error(`server responded with "text/html" instead of expected ${t} (check SPA fallback routing)`);
119
124
  } catch (n) {
120
125
  throw Error(`[WaSHI] Failed to load Z3 asset (${t}) from "${e}": ${n.message || String(n)}. Deploy local assets with correct MIME types; no CDN fallback is attempted.`, { cause: n });
@@ -137,10 +142,30 @@ function S(e = {}) {
137
142
  }
138
143
  async function C(e) {
139
144
  let t = globalThis;
140
- if (typeof t.initZ3 == "function") return t.initZ3;
141
- if (typeof document < "u") await new Promise((t, n) => {
142
- let r = document.createElement("script");
143
- r.src = e, r.crossOrigin = "anonymous", r.onload = () => t(), r.onerror = () => n(/* @__PURE__ */ Error(`[WaSHI] Failed to load Z3 runtime script from "${e}".`)), document.head.appendChild(r);
145
+ if (t.global === void 0 && (t.global = t), typeof t.initZ3 == "function") return t.initZ3;
146
+ if (typeof document < "u") await new Promise((n, r) => {
147
+ let i = null, a = (e) => {
148
+ try {
149
+ let t = typeof document < "u" && document.baseURI ? document.baseURI : void 0, n = new URL(e, t);
150
+ return n.origin + n.pathname;
151
+ } catch {
152
+ return e;
153
+ }
154
+ }, o = a(e), s = (t) => {
155
+ t.filename && (a(t.filename) === o || t.filename === e || t.filename.endsWith(o) || o.endsWith(t.filename)) && (i = t.error || t.message);
156
+ }, c = typeof window < "u" && typeof window.addEventListener == "function";
157
+ c && window.addEventListener("error", s);
158
+ let l = document.createElement("script");
159
+ l.src = e, l.crossOrigin = "anonymous", l.onload = () => {
160
+ if (c && window.removeEventListener("error", s), typeof t.initZ3 != "function" && i) {
161
+ let t = i instanceof Error ? `${i.name}: ${i.message}` : typeof i == "string" ? i : i?.message ? `${i.name ? i.name + ": " : ""}${i.message}` : String(i);
162
+ r(/* @__PURE__ */ Error(`[WaSHI] Failed to evaluate Z3 runtime script from "${e}": ${t}`));
163
+ return;
164
+ }
165
+ n();
166
+ }, l.onerror = () => {
167
+ c && window.removeEventListener("error", s), r(/* @__PURE__ */ Error(`[WaSHI] Failed to load Z3 runtime script from "${e}".`));
168
+ }, document.head.appendChild(l);
144
169
  });
145
170
  else if (typeof globalThis.importScripts == "function") globalThis.importScripts(e);
146
171
  else throw Error("[WaSHI] Cannot load z3-built.js in this environment: neither document nor importScripts is available.");
@@ -448,4 +473,4 @@ function D() {
448
473
  }
449
474
  D();
450
475
  //#endregion
451
- export { E as Z3Solver, T as killZ3Threads, w as loadZ3, g as notifyZ3WorkerError, h as registerZ3ErrorHandler, D as registerZ3Solver, y as resetZ3LoaderCache, S as resolveZ3AssetUrls, v as setZ3Assets, p as unlockAllZ3Semaphores, b as validateZ3BrowserEnvironment };
476
+ export { E as Z3Solver, C as ensureInitZ3Loaded, T as killZ3Threads, w as loadZ3, g as notifyZ3WorkerError, x as probeAssetUrl, h as registerZ3ErrorHandler, D as registerZ3Solver, y as resetZ3LoaderCache, S as resolveZ3AssetUrls, v as setZ3Assets, p as unlockAllZ3Semaphores, b as validateZ3BrowserEnvironment };