@ohtaman/washi 0.5.0 → 0.6.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 (86) hide show
  1. package/README.ja.md +55 -20
  2. package/README.md +55 -20
  3. package/README.zh-CN.md +55 -20
  4. package/THIRD_PARTY_LICENSES.md +3 -4
  5. package/dist/browser/_washi-node-only-BvRk9kiK.js +0 -0
  6. package/dist/browser/browser-runtime-TLCY0hkc.js +1793 -0
  7. package/dist/browser/highs-worker.js +1 -1
  8. package/dist/browser/highs.wasm +0 -0
  9. package/dist/browser/highs.wasm.LICENSE +1 -2
  10. package/dist/browser/loader-DewlSho8.js +643 -0
  11. package/dist/browser/solvers/glpk.js +1 -1
  12. package/dist/browser/solvers/glpk.min.js +1 -1
  13. package/dist/browser/solvers/z3.js +7 -1
  14. package/dist/browser/solvers/z3.min.js +1 -1
  15. package/dist/browser/washi.js +1096 -444
  16. package/dist/browser/washi.min.js +3 -4
  17. package/dist/lib/_washi-node-only-BvRk9kiK.js +0 -0
  18. package/dist/lib/highs-browser-runtime.js +2120 -4124
  19. package/dist/lib/highs-node-runtime.js +24 -1
  20. package/dist/lib/highs-runtime.js +2 -0
  21. package/dist/lib/highs-worker.js +1 -1
  22. package/dist/lib/highs.wasm +0 -0
  23. package/dist/lib/highs.wasm.LICENSE +1 -2
  24. package/dist/lib/loader-BZUQNvh4.js +649 -0
  25. package/dist/lib/{registry-BEfvpZW3.js → registry-C20sxTwm.js} +54 -41
  26. package/dist/lib/solvers/glpk.js +2 -2
  27. package/dist/lib/solvers/z3.js +1 -1
  28. package/dist/lib/washi.js +973 -305
  29. package/dist/types/decomposition/benders.d.ts +32 -0
  30. package/dist/types/decomposition/benders.d.ts.map +1 -0
  31. package/dist/types/decomposition/column-generation.d.ts +34 -0
  32. package/dist/types/decomposition/column-generation.d.ts.map +1 -0
  33. package/dist/types/decomposition/index.d.ts +4 -0
  34. package/dist/types/decomposition/index.d.ts.map +1 -0
  35. package/dist/types/decomposition/types.d.ts +230 -0
  36. package/dist/types/decomposition/types.d.ts.map +1 -0
  37. package/dist/types/index.d.ts +4 -3
  38. package/dist/types/index.d.ts.map +1 -1
  39. package/dist/types/modeler/boolean-expr.d.ts.map +1 -1
  40. package/dist/types/modeler/constraint.d.ts +11 -0
  41. package/dist/types/modeler/constraint.d.ts.map +1 -1
  42. package/dist/types/modeler/expression.d.ts +10 -0
  43. package/dist/types/modeler/expression.d.ts.map +1 -1
  44. package/dist/types/modeler/index.d.ts +2 -1
  45. package/dist/types/modeler/index.d.ts.map +1 -1
  46. package/dist/types/modeler/linearizer.d.ts +15 -0
  47. package/dist/types/modeler/linearizer.d.ts.map +1 -0
  48. package/dist/types/modeler/lp-writer.d.ts +3 -1
  49. package/dist/types/modeler/lp-writer.d.ts.map +1 -1
  50. package/dist/types/modeler/model.d.ts +147 -2
  51. package/dist/types/modeler/model.d.ts.map +1 -1
  52. package/dist/types/modeler/solvers/highs/browser-runtime.d.ts +2 -1
  53. package/dist/types/modeler/solvers/highs/browser-runtime.d.ts.map +1 -1
  54. package/dist/types/modeler/solvers/highs/driver.d.ts +232 -0
  55. package/dist/types/modeler/solvers/highs/driver.d.ts.map +1 -0
  56. package/dist/types/modeler/solvers/highs/index.d.ts +1 -0
  57. package/dist/types/modeler/solvers/highs/index.d.ts.map +1 -1
  58. package/dist/types/modeler/solvers/highs/loader.d.ts +4 -4
  59. package/dist/types/modeler/solvers/highs/loader.d.ts.map +1 -1
  60. package/dist/types/modeler/solvers/highs/node-runtime.d.ts +2 -1
  61. package/dist/types/modeler/solvers/highs/node-runtime.d.ts.map +1 -1
  62. package/dist/types/modeler/solvers/highs/solver.d.ts +1 -1
  63. package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
  64. package/dist/types/modeler/solvers/types.d.ts +2 -0
  65. package/dist/types/modeler/solvers/types.d.ts.map +1 -1
  66. package/dist/types/modeler/types.d.ts +27 -0
  67. package/dist/types/modeler/types.d.ts.map +1 -1
  68. package/docs/examples/index.md +4 -0
  69. package/docs/examples/traveling-salesperson.md +173 -0
  70. package/docs/examples/vehicle-routing.md +206 -0
  71. package/docs/getting-started/ai-agents.md +8 -4
  72. package/docs/guide/constraints.md +1 -1
  73. package/docs/guide/decomposition.md +399 -0
  74. package/docs/guide/unsat-core.md +10 -3
  75. package/docs/ja/getting-started/ai-agents.md +8 -4
  76. package/docs/solvers/custom-solver.md +1 -1
  77. package/docs/solvers/highs.md +25 -3
  78. package/docs/solvers/index.md +3 -3
  79. package/docs/zh/getting-started/ai-agents.md +8 -4
  80. package/llms-full.txt +831 -15
  81. package/llms.txt +9 -5
  82. package/package.json +17 -14
  83. package/skills/washi/SKILL.md +8 -8
  84. package/dist/browser/browser-runtime-D13gHOT5.js +0 -4189
  85. package/dist/browser/loader-CtaDHef_.js +0 -273
  86. package/dist/lib/loader-DmNC_UNk.js +0 -279
@@ -1,273 +0,0 @@
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 };
@@ -1,279 +0,0 @@
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 };