@ohtaman/washi 0.3.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 +111 -118
  2. package/README.md +109 -116
  3. package/README.zh-CN.md +112 -119
  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 +2178 -622
  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 +1674 -932
  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 +117 -27
  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 +491 -140
  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 +39 -14
  37. package/dist/types/modeler/parser.d.ts.map +1 -1
  38. package/dist/types/modeler/quad-expr.d.ts +28 -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 +60 -2
  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 +53 -13
  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 +19 -6
  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
@@ -0,0 +1,273 @@
1
+ //#region \0washi-browser-assets
2
+ var e = import.meta.url;
3
+ function t(t) {
4
+ if (!e) throw Error("[WaSHI] Load the browser IIFE using an external script src, or use the browser ESM build.");
5
+ return new URL(t, e).href;
6
+ }
7
+ function n() {
8
+ return t("highs.wasm");
9
+ }
10
+ //#endregion
11
+ //#region src/modeler/solvers/highs/loader.ts
12
+ var r = null, i = null, a = null;
13
+ function o(e) {
14
+ a = e, r = null, i = null;
15
+ }
16
+ function s() {
17
+ return a;
18
+ }
19
+ async function c(e) {
20
+ return e || a || n();
21
+ }
22
+ async function l(e = {}) {
23
+ let t = await c(e.wasmUrl), n = t ?? "node";
24
+ if (r && i === n) return r;
25
+ i = n;
26
+ let a = (async () => {
27
+ let e = (await import("./browser-runtime-D13gHOT5.js")).default;
28
+ return await e({ locateFile: (e) => e.endsWith(".wasm") ? t : e });
29
+ })().catch((e) => {
30
+ r === a && (r = null, i = null);
31
+ let n = e instanceof Error ? e.message : String(e);
32
+ throw Error(`[WaSHI] Failed to initialize HiGHS${t ? ` from "${t}"` : ""}. Deploy the package's WASM asset or explicitly set wasmUrl; no CDN fallback is attempted. ${n}`, { cause: e });
33
+ });
34
+ return r = a, a;
35
+ }
36
+ var u = {
37
+ 0: "Not Set",
38
+ 1: "Load error",
39
+ 2: "Model error",
40
+ 3: "Presolve error",
41
+ 4: "Solve error",
42
+ 5: "Postsolve error",
43
+ 6: "Empty",
44
+ 7: "Optimal",
45
+ 8: "Infeasible",
46
+ 9: "Primal infeasible or unbounded",
47
+ 10: "Unbounded",
48
+ 11: "Bound on objective reached",
49
+ 12: "Target for objective reached",
50
+ 13: "Time limit reached",
51
+ 14: "Iteration limit reached",
52
+ 15: "Unknown",
53
+ 16: "Solution limit reached",
54
+ 17: "Interrupted",
55
+ 18: "Memory limit reached"
56
+ };
57
+ async function d(e, t = {}) {
58
+ if (t.signal?.aborted) return {
59
+ result: {
60
+ Status: "Interrupted",
61
+ StatusCode: 17,
62
+ HasPrimalSolution: !1,
63
+ ObjectiveValue: NaN,
64
+ Columns: {},
65
+ Rows: []
66
+ },
67
+ runTime: 0
68
+ };
69
+ let n = await l(t);
70
+ if (t.signal?.aborted) return {
71
+ result: {
72
+ Status: "Interrupted",
73
+ StatusCode: 17,
74
+ HasPrimalSolution: !1,
75
+ ObjectiveValue: NaN,
76
+ Columns: {},
77
+ Rows: []
78
+ },
79
+ runTime: 0
80
+ };
81
+ let r = performance.now(), i = { output_flag: t.outputFlag ?? !1 };
82
+ 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);
83
+ for (let e of [
84
+ "mip_max_nodes",
85
+ "mip_max_improving_sols",
86
+ "mip_max_leaves",
87
+ "simplex_iteration_limit",
88
+ "ipm_iteration_limit"
89
+ ]) t[e] !== void 0 && (i[e] = t[e]);
90
+ let a = typeof t.objectiveOffset == "number" && Number.isFinite(t.objectiveOffset) ? t.objectiveOffset : 0, o = t.initialValues, s = !1;
91
+ if (o) {
92
+ for (let [e, t] of Object.entries(o)) if (t !== void 0) {
93
+ if (typeof t != "number" || !Number.isFinite(t)) throw Error(`Invalid initial value for column "${e}": ${String(t)} (must be a finite number).`);
94
+ s = !0;
95
+ }
96
+ }
97
+ if (typeof n.withModel == "function") return {
98
+ result: n.withModel({
99
+ format: "lp",
100
+ data: e
101
+ }, (e) => {
102
+ if (a !== 0 && typeof e.changeObjectiveOffset == "function") {
103
+ let t = typeof e.getObjectiveOffset == "function" ? e.getObjectiveOffset() : 0;
104
+ e.changeObjectiveOffset(t + a);
105
+ }
106
+ for (let [t, r] of Object.entries(i)) try {
107
+ e.options.set(t, r);
108
+ } catch (e) {
109
+ if (e?.name !== "HighsUnsupportedOptionError" && !(n.errors?.HighsUnsupportedOptionError && e instanceof n.errors.HighsUnsupportedOptionError)) throw e;
110
+ }
111
+ let c = e.getDimensions(), l = [], d = !1;
112
+ for (let t = 0; t < c.numCols; t++) {
113
+ let n = e.getColIntegrality(t);
114
+ n !== 0 && (d = !0), l.push({
115
+ name: e.getColName(t),
116
+ type: n === 1 ? "Integer" : "Continuous"
117
+ });
118
+ }
119
+ if (s && o) {
120
+ if (typeof e.setSolution != "function") throw Error("HiGHS runtime does not support setting primal initial values (setSolution is unavailable).");
121
+ let t = /* @__PURE__ */ new Map();
122
+ for (let e = 0; e < c.numCols; e++) t.set(l[e].name, e);
123
+ 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).`);
124
+ let n = [], r = [];
125
+ for (let e = 0; e < c.numCols; e++) {
126
+ let t = l[e].name;
127
+ if (Object.prototype.hasOwnProperty.call(o, t)) {
128
+ let i = o[t];
129
+ i !== void 0 && (n.push(e), r.push(i));
130
+ }
131
+ }
132
+ n.length > 0 && (n.length === c.numCols ? e.setSolution({ colValue: r }) : e.setSolution({
133
+ indices: n,
134
+ values: r
135
+ }));
136
+ }
137
+ let f = null, p = null, m = 0, h = (e) => {
138
+ 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 = {
139
+ elapsedTime: n,
140
+ elapsedSeconds: n,
141
+ ...i === void 0 ? {} : { objectiveValue: i },
142
+ ...a === void 0 ? {} : { objectiveBound: a },
143
+ ...o === void 0 ? {} : {
144
+ relGap: o,
145
+ mipGap: o
146
+ },
147
+ ...s === void 0 ? {} : { absGap: s },
148
+ ...c === void 0 ? {} : { nodes: c },
149
+ ...l === void 0 ? {} : { iterations: l },
150
+ ...u === void 0 ? {} : { message: u }
151
+ };
152
+ return p = d, d;
153
+ }, g = (e) => {
154
+ let n = e?.data;
155
+ if (!n || !(n.mip_solution instanceof Float64Array)) return;
156
+ let r = n.mip_solution, i = {};
157
+ for (let e = 0; e < l.length && e < r.length; e++) Object.defineProperty(i, l[e].name, {
158
+ value: {
159
+ Index: e,
160
+ Type: l[e].type,
161
+ Name: l[e].name,
162
+ Primal: r[e]
163
+ },
164
+ enumerable: !0,
165
+ writable: !0,
166
+ configurable: !0
167
+ });
168
+ 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;
169
+ Number.isFinite(a) && (f = {
170
+ objectiveValue: a,
171
+ ...typeof n.mip_dual_bound == "number" && Number.isFinite(n.mip_dual_bound) ? { mipDualBound: n.mip_dual_bound } : {},
172
+ ...typeof n.mip_gap == "number" && Number.isFinite(n.mip_gap) ? { mipGap: n.mip_gap } : {},
173
+ columns: i
174
+ }, t.onIncumbent?.(f));
175
+ }, _ = !1;
176
+ if (t.signal || t.onProgress || t.onIncumbent) {
177
+ let r = n.constants?.callbackType ?? {
178
+ logging: 0,
179
+ simplexInterrupt: 1,
180
+ ipmInterrupt: 2,
181
+ mipSolution: 3,
182
+ mipImprovingSolution: 4,
183
+ mipLogging: 5,
184
+ mipInterrupt: 6
185
+ }, i = (e) => {
186
+ if (t.signal?.aborted) {
187
+ _ = !0, e.interrupt();
188
+ return;
189
+ }
190
+ t.onProgress && (m++, t.onProgress(h(e)), t.signal?.aborted && (_ = !0, e.interrupt()));
191
+ }, a = {
192
+ [r.simplexInterrupt]: i,
193
+ [r.ipmInterrupt]: i,
194
+ [r.mipInterrupt]: i,
195
+ [r.mipImprovingSolution]: (e) => {
196
+ g(e), t.onProgress && !t.signal?.aborted && (m++, t.onProgress(h(e)));
197
+ },
198
+ [r.mipLogging]: (e) => {
199
+ t.onProgress && !t.signal?.aborted && (m++, t.onProgress(h(e)));
200
+ }
201
+ };
202
+ e.run(a);
203
+ } else e.run();
204
+ let v = e.getModelStatus();
205
+ _ && (v = 17);
206
+ let y = u[v] ?? "Unknown", b = 0, x = 0;
207
+ try {
208
+ b = Number(e.info.get("primal_solution_status"));
209
+ } catch {}
210
+ try {
211
+ x = Number(e.info.get("dual_solution_status"));
212
+ } catch {}
213
+ let S = n.constants?.solutionStatus?.feasible ?? 2, C = b === S, w = x === S, T = C || w ? e.getSolution() : null, E = C, D = {};
214
+ if (!C && f !== null) E = !0, D = f.columns;
215
+ else for (let e = 0; e < c.numCols; e++) {
216
+ let t = l[e], n = {
217
+ Index: e,
218
+ Type: t.type,
219
+ Name: t.name
220
+ };
221
+ C && T && (n.Primal = T.colValue[e]), !d && w && T && (n.Dual = T.colDual[e]), Object.defineProperty(D, t.name, {
222
+ value: n,
223
+ enumerable: !0,
224
+ writable: !0,
225
+ configurable: !0
226
+ });
227
+ }
228
+ let O = [];
229
+ for (let t = 0; t < c.numRows; t++) {
230
+ let n = e.getRowName(t), r = {
231
+ Index: t,
232
+ Name: n
233
+ };
234
+ C && T && (r.Primal = T.rowValue[t]), !d && w && T && (r.Dual = T.rowDual[t]), O.push(r);
235
+ }
236
+ let k = C ? e.getObjectiveValue() : f === null ? NaN : f.objectiveValue, A, j;
237
+ if (d) {
238
+ try {
239
+ let t = Number(e.info.get("mip_dual_bound"));
240
+ Number.isFinite(t) && (A = t);
241
+ } catch {}
242
+ A === void 0 && p && p.objectiveBound !== void 0 && (A = p.objectiveBound);
243
+ try {
244
+ let t = Number(e.info.get("mip_gap"));
245
+ Number.isFinite(t) && (j = t);
246
+ } catch {}
247
+ j === void 0 && p && p.relGap !== void 0 && (j = p.relGap);
248
+ }
249
+ return {
250
+ Status: u[v] ?? y,
251
+ StatusCode: v,
252
+ PrimalSolutionStatus: b,
253
+ DualSolutionStatus: x,
254
+ HasPrimalSolution: E,
255
+ IsMip: d,
256
+ ObjectiveValue: k,
257
+ ObjectiveOffsetApplied: a !== 0,
258
+ MipDualBound: A,
259
+ MipGap: j,
260
+ Columns: D,
261
+ Rows: O
262
+ };
263
+ }),
264
+ runTime: (performance.now() - r) / 1e3
265
+ };
266
+ if (s) throw Error("HiGHS runtime does not support setting primal initial values (withModel/setSolution is unavailable).");
267
+ return {
268
+ result: n.solve(e, i),
269
+ runTime: (performance.now() - r) / 1e3
270
+ };
271
+ }
272
+ //#endregion
273
+ export { d as a, o as i, s as n, t as o, c as r, l as t };