@ohtaman/washi 0.4.0 → 0.5.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 (97) hide show
  1. package/README.ja.md +100 -107
  2. package/README.md +98 -105
  3. package/README.zh-CN.md +101 -108
  4. package/dist/browser/highs-worker.js +21 -3
  5. package/dist/browser/loader-CtaDHef_.js +273 -0
  6. package/dist/browser/solvers/glpk.js +433 -286
  7. package/dist/browser/solvers/glpk.min.js +1 -1
  8. package/dist/browser/solvers/z3.js +1002 -981
  9. package/dist/browser/solvers/z3.min.js +2 -2
  10. package/dist/browser/washi.js +2129 -676
  11. package/dist/browser/washi.min.js +4 -4
  12. package/dist/lib/highs-worker.js +21 -3
  13. package/dist/lib/loader-DmNC_UNk.js +279 -0
  14. package/dist/lib/registry-BEfvpZW3.js +951 -0
  15. package/dist/lib/solvers/glpk.js +201 -90
  16. package/dist/lib/solvers/z3.js +399 -259
  17. package/dist/lib/washi.js +1627 -988
  18. package/dist/types/index.d.ts +4 -4
  19. package/dist/types/index.d.ts.map +1 -1
  20. package/dist/types/modeler/big-m.d.ts +75 -0
  21. package/dist/types/modeler/big-m.d.ts.map +1 -0
  22. package/dist/types/modeler/boolean-expr.d.ts +103 -14
  23. package/dist/types/modeler/boolean-expr.d.ts.map +1 -1
  24. package/dist/types/modeler/constraint.d.ts +36 -9
  25. package/dist/types/modeler/constraint.d.ts.map +1 -1
  26. package/dist/types/modeler/expression.d.ts +113 -28
  27. package/dist/types/modeler/expression.d.ts.map +1 -1
  28. package/dist/types/modeler/index.d.ts +10 -6
  29. package/dist/types/modeler/index.d.ts.map +1 -1
  30. package/dist/types/modeler/lp-writer.d.ts +27 -2
  31. package/dist/types/modeler/lp-writer.d.ts.map +1 -1
  32. package/dist/types/modeler/model.d.ts +478 -131
  33. package/dist/types/modeler/model.d.ts.map +1 -1
  34. package/dist/types/modeler/objective.d.ts +59 -0
  35. package/dist/types/modeler/objective.d.ts.map +1 -0
  36. package/dist/types/modeler/parser.d.ts +34 -10
  37. package/dist/types/modeler/parser.d.ts.map +1 -1
  38. package/dist/types/modeler/quad-expr.d.ts +26 -7
  39. package/dist/types/modeler/quad-expr.d.ts.map +1 -1
  40. package/dist/types/modeler/solution-validator.d.ts +93 -0
  41. package/dist/types/modeler/solution-validator.d.ts.map +1 -0
  42. package/dist/types/modeler/solvers/glpk/solver.d.ts +26 -2
  43. package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
  44. package/dist/types/modeler/solvers/highs/loader.d.ts +36 -11
  45. package/dist/types/modeler/solvers/highs/loader.d.ts.map +1 -1
  46. package/dist/types/modeler/solvers/highs/solver.d.ts +11 -4
  47. package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
  48. package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
  49. package/dist/types/modeler/solvers/mock.d.ts +14 -5
  50. package/dist/types/modeler/solvers/mock.d.ts.map +1 -1
  51. package/dist/types/modeler/solvers/types.d.ts +71 -11
  52. package/dist/types/modeler/solvers/types.d.ts.map +1 -1
  53. package/dist/types/modeler/solvers/z3/loader.d.ts +2 -3
  54. package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
  55. package/dist/types/modeler/solvers/z3/solver.d.ts +15 -5
  56. package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -1
  57. package/dist/types/modeler/types.d.ts +59 -1
  58. package/dist/types/modeler/types.d.ts.map +1 -1
  59. package/dist/types/modeler/validation.d.ts +56 -0
  60. package/dist/types/modeler/validation.d.ts.map +1 -0
  61. package/dist/types/modeler/variable.d.ts +48 -14
  62. package/dist/types/modeler/variable.d.ts.map +1 -1
  63. package/docs/examples/diet-sensitivity.md +90 -0
  64. package/docs/examples/ecommerce-coupons.md +106 -0
  65. package/docs/examples/index.md +53 -0
  66. package/docs/examples/knapsack.md +60 -0
  67. package/docs/examples/portfolio-qp.md +83 -0
  68. package/docs/examples/production.md +51 -0
  69. package/docs/examples/shift-scheduling.md +175 -0
  70. package/docs/examples/smt-security.md +74 -0
  71. package/docs/examples/transportation.md +90 -0
  72. package/docs/examples/unsat-core.md +64 -0
  73. package/docs/getting-started/ai-agents.md +267 -0
  74. package/docs/getting-started/cross-origin.md +87 -0
  75. package/docs/getting-started/index.md +116 -0
  76. package/docs/getting-started/runtimes.md +227 -0
  77. package/docs/guide/constraints.md +177 -0
  78. package/docs/guide/expressions.md +204 -0
  79. package/docs/guide/objectives.md +170 -0
  80. package/docs/guide/unsat-core.md +147 -0
  81. package/docs/guide/variables.md +188 -0
  82. package/docs/ja/getting-started/ai-agents.md +266 -0
  83. package/docs/solvers/custom-solver.md +525 -0
  84. package/docs/solvers/glpk.md +66 -0
  85. package/docs/solvers/highs.md +93 -0
  86. package/docs/solvers/index.md +42 -0
  87. package/docs/solvers/z3.md +78 -0
  88. package/docs/zh/getting-started/ai-agents.md +266 -0
  89. package/llms-full.txt +3249 -0
  90. package/llms.txt +197 -0
  91. package/package.json +18 -5
  92. package/skills/washi/SKILL.md +197 -0
  93. package/dist/browser/loader-CVt4CloI.js +0 -58
  94. package/dist/lib/async-mutex-Duo4jwzn.js +0 -195
  95. package/dist/lib/constraint-BRuB3ooC.js +0 -90
  96. package/dist/lib/loader-Dti0v9yC.js +0 -50
  97. package/dist/lib/registry-DksqCSjI.js +0 -32
@@ -1,9 +1,27 @@
1
- import { c as e } from "./loader-Dti0v9yC.js";
1
+ import { c as e } from "./loader-DmNC_UNk.js";
2
2
  //#region src/modeler/solvers/highs/worker.ts
3
3
  self.onmessage = async (t) => {
4
- let { type: n, id: r, lpString: i, options: a } = t.data;
4
+ let { type: n, id: r, lpString: i, options: a, reportProgress: o } = t.data;
5
5
  if (n === "SOLVE") try {
6
- let { result: t, runTime: n } = await e(i, a);
6
+ let { result: t, runTime: n } = await e(i, {
7
+ ...a,
8
+ ...o ? {
9
+ onProgress: (e) => {
10
+ self.postMessage({
11
+ type: "SOLVE_PROGRESS",
12
+ id: r,
13
+ progress: e
14
+ });
15
+ },
16
+ onIncumbent: (e) => {
17
+ self.postMessage({
18
+ type: "SOLVE_INCUMBENT",
19
+ id: r,
20
+ incumbent: e
21
+ });
22
+ }
23
+ } : {}
24
+ });
7
25
  self.postMessage({
8
26
  type: "SOLVE_SUCCESS",
9
27
  id: r,
@@ -0,0 +1,279 @@
1
+ import { getBundledWasmUrl as e } from "./highs-assets.js";
2
+ import { loadNodeHighs as t } from "./highs-node-runtime.js";
3
+ //#region src/modeler/solvers/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
+ var f = {
43
+ 0: "Not Set",
44
+ 1: "Load error",
45
+ 2: "Model error",
46
+ 3: "Presolve error",
47
+ 4: "Solve error",
48
+ 5: "Postsolve error",
49
+ 6: "Empty",
50
+ 7: "Optimal",
51
+ 8: "Infeasible",
52
+ 9: "Primal infeasible or unbounded",
53
+ 10: "Unbounded",
54
+ 11: "Bound on objective reached",
55
+ 12: "Target for objective reached",
56
+ 13: "Time limit reached",
57
+ 14: "Iteration limit reached",
58
+ 15: "Unknown",
59
+ 16: "Solution limit reached",
60
+ 17: "Interrupted",
61
+ 18: "Memory limit reached"
62
+ };
63
+ async function p(e, t = {}) {
64
+ if (t.signal?.aborted) return {
65
+ result: {
66
+ Status: "Interrupted",
67
+ StatusCode: 17,
68
+ HasPrimalSolution: !1,
69
+ ObjectiveValue: NaN,
70
+ Columns: {},
71
+ Rows: []
72
+ },
73
+ runTime: 0
74
+ };
75
+ let n = await d(t);
76
+ if (t.signal?.aborted) return {
77
+ result: {
78
+ Status: "Interrupted",
79
+ StatusCode: 17,
80
+ HasPrimalSolution: !1,
81
+ ObjectiveValue: NaN,
82
+ Columns: {},
83
+ Rows: []
84
+ },
85
+ runTime: 0
86
+ };
87
+ let r = performance.now(), i = { output_flag: t.outputFlag ?? !1 };
88
+ 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 ? t.mipGap !== void 0 && (i.mip_rel_gap = t.mipGap) : i.mip_rel_gap = t.relGap, t.absGap !== void 0 && (i.mip_abs_gap = t.absGap);
89
+ for (let e of [
90
+ "mip_max_nodes",
91
+ "mip_max_improving_sols",
92
+ "mip_max_leaves",
93
+ "simplex_iteration_limit",
94
+ "ipm_iteration_limit"
95
+ ]) t[e] !== void 0 && (i[e] = t[e]);
96
+ let a = typeof t.objectiveOffset == "number" && Number.isFinite(t.objectiveOffset) ? t.objectiveOffset : 0, o = t.initialValues, s = !1;
97
+ if (o) {
98
+ for (let [e, t] of Object.entries(o)) if (t !== void 0) {
99
+ if (typeof t != "number" || !Number.isFinite(t)) throw Error(`Invalid initial value for column "${e}": ${String(t)} (must be a finite number).`);
100
+ s = !0;
101
+ }
102
+ }
103
+ if (typeof n.withModel == "function") return {
104
+ result: n.withModel({
105
+ format: "lp",
106
+ data: e
107
+ }, (e) => {
108
+ if (a !== 0 && typeof e.changeObjectiveOffset == "function") {
109
+ let t = typeof e.getObjectiveOffset == "function" ? e.getObjectiveOffset() : 0;
110
+ e.changeObjectiveOffset(t + a);
111
+ }
112
+ for (let [t, r] of Object.entries(i)) try {
113
+ e.options.set(t, r);
114
+ } catch (e) {
115
+ if (e?.name !== "HighsUnsupportedOptionError" && !(n.errors?.HighsUnsupportedOptionError && e instanceof n.errors.HighsUnsupportedOptionError)) throw e;
116
+ }
117
+ let c = e.getDimensions(), l = [], u = !1;
118
+ for (let t = 0; t < c.numCols; t++) {
119
+ let n = e.getColIntegrality(t);
120
+ n !== 0 && (u = !0), l.push({
121
+ name: e.getColName(t),
122
+ type: n === 1 ? "Integer" : "Continuous"
123
+ });
124
+ }
125
+ if (s && o) {
126
+ if (typeof e.setSolution != "function") throw Error("HiGHS runtime does not support setting primal initial values (setSolution is unavailable).");
127
+ let t = /* @__PURE__ */ new Map();
128
+ for (let e = 0; e < c.numCols; e++) t.set(l[e].name, e);
129
+ for (let [e, n] of Object.entries(o)) if (n !== void 0 && !t.has(e)) throw Error(`Unknown column "${e}" in initialValues (column does not exist in the HiGHS LP model).`);
130
+ let n = [], r = [];
131
+ for (let e = 0; e < c.numCols; e++) {
132
+ let t = l[e].name;
133
+ if (Object.prototype.hasOwnProperty.call(o, t)) {
134
+ let i = o[t];
135
+ i !== void 0 && (n.push(e), r.push(i));
136
+ }
137
+ }
138
+ n.length > 0 && (n.length === c.numCols ? e.setSolution({ colValue: r }) : e.setSolution({
139
+ indices: n,
140
+ values: r
141
+ }));
142
+ }
143
+ let d = null, p = null, m = 0, h = (e) => {
144
+ let t = e?.data ?? {}, n = typeof t.running_time == "number" && Number.isFinite(t.running_time) ? t.running_time : (performance.now() - r) / 1e3, i = typeof t.mip_primal_bound == "number" && Number.isFinite(t.mip_primal_bound) ? t.mip_primal_bound : typeof t.objective_function_value == "number" && Number.isFinite(t.objective_function_value) ? t.objective_function_value : void 0, a = typeof t.mip_dual_bound == "number" && Number.isFinite(t.mip_dual_bound) ? t.mip_dual_bound : void 0, o = typeof t.mip_gap == "number" && Number.isFinite(t.mip_gap) ? t.mip_gap : void 0, s = i !== void 0 && a !== void 0 ? Math.abs(i - a) : void 0, c = typeof t.mip_node_count == "bigint" ? Number(t.mip_node_count) : typeof t.mip_node_count == "number" && Number.isFinite(t.mip_node_count) ? t.mip_node_count : void 0, l = typeof t.mip_total_lp_iterations == "bigint" ? Number(t.mip_total_lp_iterations) : typeof t.simplex_iteration_count == "number" && Number.isFinite(t.simplex_iteration_count) ? t.simplex_iteration_count : typeof t.ipm_iteration_count == "number" && Number.isFinite(t.ipm_iteration_count) ? t.ipm_iteration_count : void 0, u = typeof e?.message == "string" && e.message.trim().length > 0 ? e.message.trim() : void 0, d = {
145
+ elapsedTime: n,
146
+ elapsedSeconds: n,
147
+ ...i === void 0 ? {} : { objectiveValue: i },
148
+ ...a === void 0 ? {} : { objectiveBound: a },
149
+ ...o === void 0 ? {} : {
150
+ relGap: o,
151
+ mipGap: o
152
+ },
153
+ ...s === void 0 ? {} : { absGap: s },
154
+ ...c === void 0 ? {} : { nodes: c },
155
+ ...l === void 0 ? {} : { iterations: l },
156
+ ...u === void 0 ? {} : { message: u }
157
+ };
158
+ return p = d, d;
159
+ }, g = (e) => {
160
+ let n = e?.data;
161
+ if (!n || !(n.mip_solution instanceof Float64Array)) return;
162
+ let r = n.mip_solution, i = {};
163
+ for (let e = 0; e < l.length && e < r.length; e++) Object.defineProperty(i, l[e].name, {
164
+ value: {
165
+ Index: e,
166
+ Type: l[e].type,
167
+ Name: l[e].name,
168
+ Primal: r[e]
169
+ },
170
+ enumerable: !0,
171
+ writable: !0,
172
+ configurable: !0
173
+ });
174
+ let a = typeof n.objective_function_value == "number" && Number.isFinite(n.objective_function_value) ? n.objective_function_value : typeof n.mip_primal_bound == "number" && Number.isFinite(n.mip_primal_bound) ? n.mip_primal_bound : NaN;
175
+ Number.isFinite(a) && (d = {
176
+ objectiveValue: a,
177
+ ...typeof n.mip_dual_bound == "number" && Number.isFinite(n.mip_dual_bound) ? { mipDualBound: n.mip_dual_bound } : {},
178
+ ...typeof n.mip_gap == "number" && Number.isFinite(n.mip_gap) ? { mipGap: n.mip_gap } : {},
179
+ columns: i
180
+ }, t.onIncumbent?.(d));
181
+ }, _ = !1;
182
+ if (t.signal || t.onProgress || t.onIncumbent) {
183
+ let r = n.constants?.callbackType ?? {
184
+ logging: 0,
185
+ simplexInterrupt: 1,
186
+ ipmInterrupt: 2,
187
+ mipSolution: 3,
188
+ mipImprovingSolution: 4,
189
+ mipLogging: 5,
190
+ mipInterrupt: 6
191
+ }, i = (e) => {
192
+ if (t.signal?.aborted) {
193
+ _ = !0, e.interrupt();
194
+ return;
195
+ }
196
+ t.onProgress && (m++, t.onProgress(h(e)), t.signal?.aborted && (_ = !0, e.interrupt()));
197
+ }, a = {
198
+ [r.simplexInterrupt]: i,
199
+ [r.ipmInterrupt]: i,
200
+ [r.mipInterrupt]: i,
201
+ [r.mipImprovingSolution]: (e) => {
202
+ g(e), t.onProgress && !t.signal?.aborted && (m++, t.onProgress(h(e)));
203
+ },
204
+ [r.mipLogging]: (e) => {
205
+ t.onProgress && !t.signal?.aborted && (m++, t.onProgress(h(e)));
206
+ }
207
+ };
208
+ e.run(a);
209
+ } else e.run();
210
+ let v = e.getModelStatus();
211
+ _ && (v = 17);
212
+ let y = f[v] ?? "Unknown", b = 0, x = 0;
213
+ try {
214
+ b = Number(e.info.get("primal_solution_status"));
215
+ } catch {}
216
+ try {
217
+ x = Number(e.info.get("dual_solution_status"));
218
+ } catch {}
219
+ let S = n.constants?.solutionStatus?.feasible ?? 2, C = b === S, w = x === S, T = C || w ? e.getSolution() : null, E = C, D = {};
220
+ if (!C && d !== null) E = !0, D = d.columns;
221
+ else for (let e = 0; e < c.numCols; e++) {
222
+ let t = l[e], n = {
223
+ Index: e,
224
+ Type: t.type,
225
+ Name: t.name
226
+ };
227
+ C && T && (n.Primal = T.colValue[e]), !u && w && T && (n.Dual = T.colDual[e]), Object.defineProperty(D, t.name, {
228
+ value: n,
229
+ enumerable: !0,
230
+ writable: !0,
231
+ configurable: !0
232
+ });
233
+ }
234
+ let O = [];
235
+ for (let t = 0; t < c.numRows; t++) {
236
+ let n = e.getRowName(t), r = {
237
+ Index: t,
238
+ Name: n
239
+ };
240
+ C && T && (r.Primal = T.rowValue[t]), !u && w && T && (r.Dual = T.rowDual[t]), O.push(r);
241
+ }
242
+ let k = C ? e.getObjectiveValue() : d === null ? NaN : d.objectiveValue, A, j;
243
+ if (u) {
244
+ try {
245
+ let t = Number(e.info.get("mip_dual_bound"));
246
+ Number.isFinite(t) && (A = t);
247
+ } catch {}
248
+ A === void 0 && p && p.objectiveBound !== void 0 && (A = p.objectiveBound);
249
+ try {
250
+ let t = Number(e.info.get("mip_gap"));
251
+ Number.isFinite(t) && (j = t);
252
+ } catch {}
253
+ j === void 0 && p && p.relGap !== void 0 && (j = p.relGap);
254
+ }
255
+ return {
256
+ Status: f[v] ?? y,
257
+ StatusCode: v,
258
+ PrimalSolutionStatus: b,
259
+ DualSolutionStatus: x,
260
+ HasPrimalSolution: E,
261
+ IsMip: u,
262
+ ObjectiveValue: k,
263
+ ObjectiveOffsetApplied: a !== 0,
264
+ MipDualBound: A,
265
+ MipGap: j,
266
+ Columns: D,
267
+ Rows: O
268
+ };
269
+ }),
270
+ runTime: (performance.now() - r) / 1e3
271
+ };
272
+ if (s) throw Error("HiGHS runtime does not support setting primal initial values (withModel/setSolution is unavailable).");
273
+ return {
274
+ result: n.solve(e, i),
275
+ runTime: (performance.now() - r) / 1e3
276
+ };
277
+ }
278
+ //#endregion
279
+ export { l as a, p as c, c as i, d as n, u as o, s as r, o as s, n as t };