@ohtaman/washi 0.6.0 → 0.8.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 (147) hide show
  1. package/README.ja.md +139 -418
  2. package/README.md +139 -418
  3. package/README.zh-CN.md +139 -418
  4. package/THIRD_PARTY_LICENSES.md +39 -4
  5. package/dist/browser/__vite-browser-external-rTVKos2U.js +7 -0
  6. package/dist/browser/browser-runtime-AG5QFtKf.js +2021 -0
  7. package/dist/browser/highs-worker.js +26 -11
  8. package/dist/browser/highs.wasm +0 -0
  9. package/dist/browser/{loader-DewlSho8.js → loader-i3FnqMes.js} +183 -149
  10. package/dist/browser/solvers/glpk.js +289 -238
  11. package/dist/browser/solvers/glpk.min.js +1 -1
  12. package/dist/browser/solvers/pumpkin-_washi-pumpkin-node-runtime-CEKUDK6d.js +9 -0
  13. package/dist/browser/solvers/pumpkin-loader-CvdaKxf4.js +320 -0
  14. package/dist/browser/solvers/pumpkin-worker.js +45 -0
  15. package/dist/browser/solvers/pumpkin.js +1777 -0
  16. package/dist/browser/solvers/pumpkin.min.js +1 -0
  17. package/dist/browser/solvers/pumpkin.wasm +0 -0
  18. package/dist/browser/solvers/pumpkin.wasm.LICENSE +21 -0
  19. package/dist/browser/solvers/z3.js +1600 -1335
  20. package/dist/browser/solvers/z3.min.js +2 -2
  21. package/dist/browser/washi.js +3828 -1315
  22. package/dist/browser/washi.min.js +5 -3
  23. package/dist/lib/__vite-browser-external-oLchLuMx.js +7 -0
  24. package/dist/lib/highs-browser-runtime.js +1846 -1618
  25. package/dist/lib/highs-runtime.js +16 -2
  26. package/dist/lib/highs-worker.js +26 -11
  27. package/dist/lib/highs.wasm +0 -0
  28. package/dist/lib/{loader-BZUQNvh4.js → loader-CDpPXN_F.js} +138 -116
  29. package/dist/lib/registry-dx7x4e5c.js +1694 -0
  30. package/dist/lib/rolldown-runtime-DtPi1Y-2.js +13 -0
  31. package/dist/lib/solvers/glpk.js +161 -121
  32. package/dist/lib/solvers/pumpkin-assets.js +1 -0
  33. package/dist/lib/solvers/pumpkin-loader-Ow74Fa1B.js +311 -0
  34. package/dist/lib/solvers/pumpkin-node-runtime.js +15 -0
  35. package/dist/lib/solvers/pumpkin-worker-factory.js +1 -0
  36. package/dist/lib/solvers/pumpkin-worker.js +45 -0
  37. package/dist/lib/solvers/pumpkin.js +1767 -0
  38. package/dist/lib/solvers/pumpkin.wasm +0 -0
  39. package/dist/lib/solvers/pumpkin.wasm.LICENSE +21 -0
  40. package/dist/lib/solvers/z3.js +486 -306
  41. package/dist/lib/washi.js +3054 -1202
  42. package/dist/types/decomposition/benders.d.ts.map +1 -1
  43. package/dist/types/index.d.ts +3 -3
  44. package/dist/types/index.d.ts.map +1 -1
  45. package/dist/types/modeler/boolean-expr.d.ts +137 -29
  46. package/dist/types/modeler/boolean-expr.d.ts.map +1 -1
  47. package/dist/types/modeler/constraint.d.ts +40 -4
  48. package/dist/types/modeler/constraint.d.ts.map +1 -1
  49. package/dist/types/modeler/expression.d.ts +176 -28
  50. package/dist/types/modeler/expression.d.ts.map +1 -1
  51. package/dist/types/modeler/index.d.ts +5 -6
  52. package/dist/types/modeler/index.d.ts.map +1 -1
  53. package/dist/types/modeler/linearizer.d.ts +11 -2
  54. package/dist/types/modeler/linearizer.d.ts.map +1 -1
  55. package/dist/types/modeler/lp-writer.d.ts.map +1 -1
  56. package/dist/types/modeler/model.d.ts +97 -130
  57. package/dist/types/modeler/model.d.ts.map +1 -1
  58. package/dist/types/modeler/parser.d.ts +25 -5
  59. package/dist/types/modeler/parser.d.ts.map +1 -1
  60. package/dist/types/modeler/quad-expr.d.ts +8 -2
  61. package/dist/types/modeler/quad-expr.d.ts.map +1 -1
  62. package/dist/types/modeler/solution-validator.d.ts +12 -12
  63. package/dist/types/modeler/solution-validator.d.ts.map +1 -1
  64. package/dist/types/modeler/solvers/glpk/loader.d.ts +4 -0
  65. package/dist/types/modeler/solvers/glpk/loader.d.ts.map +1 -1
  66. package/dist/types/modeler/solvers/glpk/solver.d.ts +2 -2
  67. package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
  68. package/dist/types/modeler/solvers/highs/driver.d.ts.map +1 -1
  69. package/dist/types/modeler/solvers/highs/loader.d.ts +8 -6
  70. package/dist/types/modeler/solvers/highs/loader.d.ts.map +1 -1
  71. package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
  72. package/dist/types/modeler/solvers/highs/worker-client.d.ts +16 -0
  73. package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
  74. package/dist/types/modeler/solvers/mock.d.ts +2 -3
  75. package/dist/types/modeler/solvers/mock.d.ts.map +1 -1
  76. package/dist/types/modeler/solvers/pumpkin/assets.d.ts +2 -0
  77. package/dist/types/modeler/solvers/pumpkin/assets.d.ts.map +1 -0
  78. package/dist/types/modeler/solvers/pumpkin/index.d.ts +6 -0
  79. package/dist/types/modeler/solvers/pumpkin/index.d.ts.map +1 -0
  80. package/dist/types/modeler/solvers/pumpkin/loader.d.ts +40 -0
  81. package/dist/types/modeler/solvers/pumpkin/loader.d.ts.map +1 -0
  82. package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts +3 -0
  83. package/dist/types/modeler/solvers/pumpkin/node-runtime.d.ts.map +1 -0
  84. package/dist/types/modeler/solvers/pumpkin/solver.d.ts +23 -0
  85. package/dist/types/modeler/solvers/pumpkin/solver.d.ts.map +1 -0
  86. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts +74 -0
  87. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts.map +1 -0
  88. package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts +3 -0
  89. package/dist/types/modeler/solvers/pumpkin/worker-factory.d.ts.map +1 -0
  90. package/dist/types/modeler/solvers/pumpkin/worker.d.ts +7 -0
  91. package/dist/types/modeler/solvers/pumpkin/worker.d.ts.map +1 -0
  92. package/dist/types/modeler/solvers/pumpkin.d.ts +2 -0
  93. package/dist/types/modeler/solvers/pumpkin.d.ts.map +1 -0
  94. package/dist/types/modeler/solvers/registry.d.ts.map +1 -1
  95. package/dist/types/modeler/solvers/types.d.ts +9 -9
  96. package/dist/types/modeler/solvers/types.d.ts.map +1 -1
  97. package/dist/types/modeler/solvers/z3/loader.d.ts +4 -0
  98. package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
  99. package/dist/types/modeler/solvers/z3/solver.d.ts +2 -15
  100. package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -1
  101. package/dist/types/modeler/types.d.ts +12 -15
  102. package/dist/types/modeler/types.d.ts.map +1 -1
  103. package/dist/types/modeler/validation.d.ts +26 -2
  104. package/dist/types/modeler/validation.d.ts.map +1 -1
  105. package/dist/types/modeler/variable.d.ts +9 -5
  106. package/dist/types/modeler/variable.d.ts.map +1 -1
  107. package/docs/examples/diet-sensitivity.md +15 -14
  108. package/docs/examples/ecommerce-coupons.md +15 -22
  109. package/docs/examples/index.md +20 -13
  110. package/docs/examples/knapsack.md +8 -7
  111. package/docs/examples/portfolio-qp.md +11 -4
  112. package/docs/examples/production.md +4 -4
  113. package/docs/examples/project-scheduling.md +106 -0
  114. package/docs/examples/shift-scheduling.md +23 -7
  115. package/docs/examples/smt-security.md +17 -4
  116. package/docs/examples/transportation.md +46 -19
  117. package/docs/examples/traveling-salesperson.md +29 -45
  118. package/docs/examples/unsat-core.md +16 -5
  119. package/docs/examples/vehicle-routing.md +10 -8
  120. package/docs/getting-started/ai-agents.md +114 -34
  121. package/docs/getting-started/coding-agents.md +158 -0
  122. package/docs/getting-started/cross-origin.md +56 -28
  123. package/docs/getting-started/index.md +36 -66
  124. package/docs/getting-started/runtimes.md +98 -69
  125. package/docs/guide/constraint-programming.md +141 -0
  126. package/docs/guide/constraints.md +100 -44
  127. package/docs/guide/decomposition.md +141 -273
  128. package/docs/guide/expressions.md +125 -42
  129. package/docs/guide/formulation-tips.md +212 -0
  130. package/docs/guide/objectives.md +70 -64
  131. package/docs/guide/unsat-core.md +44 -23
  132. package/docs/guide/variables.md +56 -48
  133. package/docs/solvers/custom-solver.md +18 -13
  134. package/docs/solvers/highs.md +41 -25
  135. package/docs/solvers/index.md +13 -7
  136. package/docs/solvers/pumpkin.md +163 -0
  137. package/docs/solvers/z3.md +4 -1
  138. package/llms-full.txt +1732 -860
  139. package/llms.txt +59 -36
  140. package/package.json +40 -13
  141. package/skills/washi/SKILL.md +91 -35
  142. package/dist/browser/_washi-node-only-BvRk9kiK.js +0 -0
  143. package/dist/browser/browser-runtime-TLCY0hkc.js +0 -1793
  144. package/dist/lib/_washi-node-only-BvRk9kiK.js +0 -0
  145. package/dist/lib/registry-C20sxTwm.js +0 -964
  146. package/docs/ja/getting-started/ai-agents.md +0 -270
  147. package/docs/zh/getting-started/ai-agents.md +0 -270
@@ -1,22 +1,37 @@
1
- import { a as e } from "./loader-DewlSho8.js";
1
+ import { a as e, t } from "./loader-i3FnqMes.js";
2
2
  //#region src/modeler/solvers/highs/worker.ts
3
- self.onmessage = async (t) => {
4
- let { type: n, id: r, lpString: i, options: a, reportProgress: o } = t.data;
5
- if (n === "SOLVE") try {
6
- let { result: t, runTime: n } = await e(i, {
7
- ...a,
8
- ...o ? {
3
+ self.onmessage = async (n) => {
4
+ let { type: r, id: i, lpString: a, options: o, reportProgress: s } = n.data;
5
+ if (r === "WARMUP") {
6
+ try {
7
+ await t(o), self.postMessage({
8
+ type: "WARMUP_SUCCESS",
9
+ id: i
10
+ });
11
+ } catch (e) {
12
+ self.postMessage({
13
+ type: "WARMUP_ERROR",
14
+ id: i,
15
+ error: e?.message || String(e)
16
+ });
17
+ }
18
+ return;
19
+ }
20
+ if (r === "SOLVE") try {
21
+ let { result: t, runTime: n } = await e(a, {
22
+ ...o,
23
+ ...s ? {
9
24
  onProgress: (e) => {
10
25
  self.postMessage({
11
26
  type: "SOLVE_PROGRESS",
12
- id: r,
27
+ id: i,
13
28
  progress: e
14
29
  });
15
30
  },
16
31
  onIncumbent: (e) => {
17
32
  self.postMessage({
18
33
  type: "SOLVE_INCUMBENT",
19
- id: r,
34
+ id: i,
20
35
  incumbent: e
21
36
  });
22
37
  }
@@ -24,14 +39,14 @@ self.onmessage = async (t) => {
24
39
  });
25
40
  self.postMessage({
26
41
  type: "SOLVE_SUCCESS",
27
- id: r,
42
+ id: i,
28
43
  result: t,
29
44
  runTime: n
30
45
  });
31
46
  } catch (e) {
32
47
  self.postMessage({
33
48
  type: "SOLVE_ERROR",
34
- id: r,
49
+ id: i,
35
50
  error: e?.message || String(e)
36
51
  });
37
52
  }
Binary file
@@ -8,8 +8,13 @@ function n() {
8
8
  return t("highs.wasm");
9
9
  }
10
10
  //#endregion
11
+ //#region \0washi-node-runtime
12
+ function r() {
13
+ throw Error("This distribution is for browsers. Use the npm entry in Node.js.");
14
+ }
15
+ //#endregion
11
16
  //#region src/modeler/solvers/highs/driver.ts
12
- function r(e, t, n) {
17
+ function i(e, t, n) {
13
18
  if (n <= 0 || !t) return /* @__PURE__ */ new Float64Array();
14
19
  let r = e.wasmMemory ? e.wasmMemory.buffer : e.HEAPF64 ? e.HEAPF64.buffer : e.HEAP8?.buffer;
15
20
  if (r) return new Float64Array(r, t, n).slice();
@@ -17,15 +22,15 @@ function r(e, t, n) {
17
22
  for (let r = 0; r < n; r++) i[r] = e.getValue(t + r * 8, "double");
18
23
  return i;
19
24
  }
20
- var i = class extends Error {
25
+ var a = class extends Error {
21
26
  constructor(e) {
22
27
  super(e), this.name = "HighsError";
23
28
  }
24
- }, a = class extends i {
29
+ }, o = class extends a {
25
30
  constructor(e) {
26
31
  super(e), this.name = "HighsUnsupportedOptionError";
27
32
  }
28
- }, o = {
33
+ }, s = {
29
34
  0: "Not Set",
30
35
  1: "Load error",
31
36
  2: "Model error",
@@ -45,7 +50,7 @@ var i = class extends Error {
45
50
  16: "Solution limit reached",
46
51
  17: "Interrupted",
47
52
  18: "Memory limit reached"
48
- }, s = {
53
+ }, c = {
49
54
  callbackType: {
50
55
  logging: 0,
51
56
  simplexInterrupt: 1,
@@ -84,7 +89,7 @@ var i = class extends Error {
84
89
  interrupt: 17
85
90
  }
86
91
  };
87
- function c(e) {
92
+ function l(e) {
88
93
  return {
89
94
  create: e.cwrap("Highs_create", "number", []),
90
95
  destroy: e.cwrap("Highs_destroy", "void", ["number"]),
@@ -178,7 +183,7 @@ function c(e) {
178
183
  stopCallback: e.cwrap("Highs_stopCallback", "number", ["number", "number"])
179
184
  };
180
185
  }
181
- var l = 0, u = class {
186
+ var u = 0, d = class {
182
187
  highs;
183
188
  module;
184
189
  bindings;
@@ -189,7 +194,7 @@ var l = 0, u = class {
189
194
  }
190
195
  changeObjectiveOffset(e) {
191
196
  let t = this.bindings.changeObjectiveOffset(this.highs, e);
192
- if (t !== 0) throw new i(`Highs_changeObjectiveOffset failed with status ${t}`);
197
+ if (t !== 0) throw new a(`Highs_changeObjectiveOffset failed with status ${t}`);
193
198
  }
194
199
  getObjectiveOffset() {
195
200
  let e = this.module._malloc(8);
@@ -201,7 +206,7 @@ var l = 0, u = class {
201
206
  }
202
207
  options = { set: (e, t) => {
203
208
  let n = -1;
204
- if (typeof t == "boolean" ? n = this.bindings.setBoolOptionValue(this.highs, e, +!!t) : typeof t == "number" ? Number.isInteger(t) ? (n = this.bindings.setIntOptionValue(this.highs, e, t), n !== 0 && (n = this.bindings.setDoubleOptionValue(this.highs, e, t))) : n = this.bindings.setDoubleOptionValue(this.highs, e, t) : typeof t == "string" && (n = this.bindings.setStringOptionValue(this.highs, e, t)), n !== 0) throw new a(`Option "${e}" with value ${JSON.stringify(t)} is not supported or invalid in HiGHS`);
209
+ if (typeof t == "boolean" ? n = this.bindings.setBoolOptionValue(this.highs, e, +!!t) : typeof t == "number" ? Number.isInteger(t) ? (n = this.bindings.setIntOptionValue(this.highs, e, t), n !== 0 && (n = this.bindings.setDoubleOptionValue(this.highs, e, t))) : n = this.bindings.setDoubleOptionValue(this.highs, e, t) : typeof t == "string" && (n = this.bindings.setStringOptionValue(this.highs, e, t)), n !== 0) throw new o(`Option "${e}" with value ${JSON.stringify(t)} is not supported or invalid in HiGHS`);
205
210
  } };
206
211
  getDimensions() {
207
212
  return {
@@ -229,7 +234,7 @@ var l = 0, u = class {
229
234
  try {
230
235
  for (let r = 0; r < t; r++) this.module.setValue(n + r * 8, e.colValue[r], "double");
231
236
  let r = this.bindings.setSolution(this.highs, n, 0, 0, 0);
232
- if (r !== 0) throw new i(`Highs_setSolution failed with status ${r}`);
237
+ if (r !== 0) throw new a(`Highs_setSolution failed with status ${r}`);
233
238
  } finally {
234
239
  this.module._free(n);
235
240
  }
@@ -239,25 +244,26 @@ var l = 0, u = class {
239
244
  let t = e.indices.length, n = this.module._malloc(t * 4), r = this.module._malloc(t * 8);
240
245
  try {
241
246
  for (let i = 0; i < t; i++) this.module.setValue(n + i * 4, e.indices[i], "i32"), this.module.setValue(r + i * 8, e.values[i], "double");
242
- let a = this.bindings.setSparseSolution(this.highs, t, n, r);
243
- if (a !== 0) throw new i(`Highs_setSparseSolution failed with status ${a}`);
247
+ let i = this.bindings.setSparseSolution(this.highs, t, n, r);
248
+ if (i !== 0) throw new a(`Highs_setSparseSolution failed with status ${i}`);
244
249
  } finally {
245
250
  this.module._free(n), this.module._free(r);
246
251
  }
247
252
  return;
248
253
  }
249
- throw new i("Invalid argument to setSolution (expected { colValue } or { indices, values })");
254
+ throw new a("Invalid argument to setSolution (expected { colValue } or { indices, values })");
250
255
  }
251
256
  run(e) {
252
257
  let t = 0, n = [];
253
- if (e && typeof this.module.addFunction == "function") {
254
- t = this.module.addFunction((t, n, i, a) => {
258
+ if (e) {
259
+ if (typeof this.module.addFunction != "function") throw new a("HiGHS WebAssembly runtime does not support module.addFunction; progress and interrupt callbacks are unavailable.");
260
+ t = this.module.addFunction((t, n, r, a) => {
255
261
  let o = e[t];
256
262
  if (!o) return;
257
263
  let s = {};
258
- if (i) {
259
- let e = this.module.getValue(i + 8, "double"), t = this.module.getValue(i + 16, "i32"), n = this.module.getValue(i + 20, "i32"), a = this.module.getValue(i + 24, "i32"), o = this.module.getValue(i + 32, "double"), c = Number(this.module.getValue(i + 40, "i32")), l = Number(this.module.getValue(i + 48, "i32")), u = this.module.getValue(i + 56, "double"), d = this.module.getValue(i + 64, "double"), f = this.module.getValue(i + 72, "double"), p = this.module.getValue(i + 80, "i32"), m = this.module.getValue(i + 84, "i32"), h;
260
- p && m > 0 && (h = r(this.module, p, m)), s = {
264
+ if (r) {
265
+ let e = this.module.getValue(r + 8, "double"), t = this.module.getValue(r + 16, "i32"), n = this.module.getValue(r + 20, "i32"), a = this.module.getValue(r + 24, "i32"), o = this.module.getValue(r + 32, "double"), c = Number(this.module.getValue(r + 40, "i32")), l = Number(this.module.getValue(r + 48, "i32")), u = this.module.getValue(r + 56, "double"), d = this.module.getValue(r + 64, "double"), f = this.module.getValue(r + 72, "double"), p = this.module.getValue(r + 80, "i32"), m = this.module.getValue(r + 84, "i32"), h;
266
+ p && m > 0 && (h = i(this.module, p, m)), s = {
261
267
  running_time: e,
262
268
  simplex_iteration_count: t,
263
269
  ipm_iteration_count: n,
@@ -314,19 +320,19 @@ var l = 0, u = class {
314
320
  } finally {
315
321
  this.module._free(n);
316
322
  }
317
- throw new i(`Info item "${e}" not available or unknown in HiGHS`);
323
+ throw new a(`Info item "${e}" not available or unknown in HiGHS`);
318
324
  } };
319
325
  getSolution() {
320
- let e = this.getDimensions(), t = e.numCols > 0 ? this.module._malloc(e.numCols * 8) : 0, n = e.numCols > 0 ? this.module._malloc(e.numCols * 8) : 0, i = e.numRows > 0 ? this.module._malloc(e.numRows * 8) : 0, a = e.numRows > 0 ? this.module._malloc(e.numRows * 8) : 0;
326
+ let e = this.getDimensions(), t = e.numCols > 0 ? this.module._malloc(e.numCols * 8) : 0, n = e.numCols > 0 ? this.module._malloc(e.numCols * 8) : 0, r = e.numRows > 0 ? this.module._malloc(e.numRows * 8) : 0, a = e.numRows > 0 ? this.module._malloc(e.numRows * 8) : 0;
321
327
  try {
322
- return this.bindings.getSolution(this.highs, t, n, i, a), {
323
- colValue: r(this.module, t, e.numCols),
324
- colDual: r(this.module, n, e.numCols),
325
- rowValue: r(this.module, i, e.numRows),
326
- rowDual: r(this.module, a, e.numRows)
328
+ return this.bindings.getSolution(this.highs, t, n, r, a), {
329
+ colValue: i(this.module, t, e.numCols),
330
+ colDual: i(this.module, n, e.numCols),
331
+ rowValue: i(this.module, r, e.numRows),
332
+ rowDual: i(this.module, a, e.numRows)
327
333
  };
328
334
  } finally {
329
- t && this.module._free(t), n && this.module._free(n), i && this.module._free(i), a && this.module._free(a);
335
+ t && this.module._free(t), n && this.module._free(n), r && this.module._free(r), a && this.module._free(a);
330
336
  }
331
337
  }
332
338
  getObjectiveValue() {
@@ -346,29 +352,29 @@ var l = 0, u = class {
346
352
  [Symbol.dispose]() {
347
353
  this.destroy();
348
354
  }
349
- }, d = class {
355
+ }, f = class {
350
356
  module;
351
357
  bindings;
352
- constants = s;
358
+ constants = c;
353
359
  errors = {
354
- HighsError: i,
355
- HighsUnsupportedOptionError: a
360
+ HighsError: a,
361
+ HighsUnsupportedOptionError: o
356
362
  };
357
363
  constructor(e) {
358
- this.module = e, this.bindings = c(e);
364
+ this.module = e, this.bindings = l(e);
359
365
  }
360
366
  withModel(e, t) {
361
- let n = this.bindings.create(), r = new u(this.module, this.bindings, n), a = `/model_${++l}.${e.format}`;
362
- if (!this.module.FS) throw new i("Emscripten FS is not initialized on this HiGHS module instance");
367
+ let n = this.bindings.create(), r = new d(this.module, this.bindings, n), i = `/model_${++u}.${e.format}`;
368
+ if (!this.module.FS) throw new a("Emscripten FS is not initialized on this HiGHS module instance");
363
369
  let o = this.module.FS;
364
370
  try {
365
- o.writeFile(a, e.data);
366
- let s = this.bindings.readModel(n, a);
367
- if (s !== 0) throw new i(`Failed to load ${e.format.toUpperCase()} model into HiGHS (status ${s})`);
371
+ o.writeFile(i, e.data);
372
+ let s = this.bindings.readModel(n, i);
373
+ if (s !== 0) throw new a(`Failed to load ${e.format.toUpperCase()} model into HiGHS (status ${s})`);
368
374
  return t(r);
369
375
  } finally {
370
376
  try {
371
- o.unlink(a);
377
+ o.unlink(i);
372
378
  } catch {}
373
379
  r.destroy();
374
380
  }
@@ -378,9 +384,7 @@ var l = 0, u = class {
378
384
  format: "lp",
379
385
  data: e
380
386
  }, (e) => {
381
- for (let [n, r] of Object.entries(t)) try {
382
- e.options.set(n, r);
383
- } catch {}
387
+ for (let [n, r] of Object.entries(t)) e.options.set(n, r);
384
388
  e.run();
385
389
  let n = e.getModelStatus(), r = e.getDimensions(), i = e.getSolution(), a = {};
386
390
  for (let t = 0; t < r.numCols; t++) {
@@ -393,39 +397,84 @@ var l = 0, u = class {
393
397
  };
394
398
  }
395
399
  return {
396
- Status: o[n] ?? "Unknown",
400
+ Status: s[n] ?? "Unknown",
397
401
  StatusCode: n,
398
402
  ObjectiveValue: e.getObjectiveValue(),
399
403
  Columns: a
400
404
  };
401
405
  });
402
406
  }
403
- }, f = null, p = null, m = null;
404
- function h(e) {
405
- m = e, f = null, p = null;
407
+ }, p = [
408
+ "mip_max_nodes",
409
+ "mip_max_improving_sols",
410
+ "mip_max_leaves",
411
+ "simplex_iteration_limit",
412
+ "ipm_iteration_limit"
413
+ ], m = /* @__PURE__ */ new Set([
414
+ "timeLimit",
415
+ "outputFlag",
416
+ "presolve",
417
+ "solver",
418
+ "relativeGap",
419
+ "absoluteGap",
420
+ "wasmUrl",
421
+ "signal",
422
+ "onProgress",
423
+ "onIncumbent",
424
+ "relax",
425
+ "useWorker",
426
+ "objectiveOffset",
427
+ "initialValues",
428
+ ...p
429
+ ]);
430
+ function h(e = {}) {
431
+ if (e.threads !== void 0) throw Error("Solver \"HiGHS\" does not support option \"threads\" (HiGHS WebAssembly runs single-threaded).");
432
+ if (e.verbose !== void 0) throw Error("Solver \"HiGHS\" does not support option \"verbose\"; use \"outputFlag\" instead.");
433
+ for (let [t, n] of Object.entries(e)) if (n !== void 0 && !m.has(t)) throw Error(`Solver "HiGHS" does not support option "${t}".`);
434
+ if (e.useWorker !== void 0 && typeof e.useWorker != "boolean") throw Error(`Invalid HiGHS option "useWorker": expected boolean, got ${typeof e.useWorker}.`);
435
+ if (e.outputFlag !== void 0 && typeof e.outputFlag != "boolean") throw Error(`Invalid HiGHS option "outputFlag": expected boolean, got ${typeof e.outputFlag}.`);
436
+ if (e.relax !== void 0 && typeof e.relax != "boolean") throw Error(`Invalid HiGHS option "relax": expected boolean, got ${typeof e.relax}.`);
437
+ if (e.presolve !== void 0 && e.presolve !== "on" && e.presolve !== "off" && e.presolve !== "choose") throw Error(`Invalid HiGHS option "presolve" (${String(e.presolve)}): expected "on", "off", or "choose".`);
438
+ if (e.timeLimit !== void 0 && (typeof e.timeLimit != "number" || !Number.isFinite(e.timeLimit) || e.timeLimit < 0)) throw Error(`Invalid HiGHS option "timeLimit" (${String(e.timeLimit)}): expected a finite non-negative number of seconds.`);
439
+ if (e.relativeGap !== void 0 && (typeof e.relativeGap != "number" || !Number.isFinite(e.relativeGap) || e.relativeGap < 0)) throw Error(`Invalid HiGHS option "relativeGap" (${String(e.relativeGap)}): expected a finite non-negative number.`);
440
+ if (e.absoluteGap !== void 0 && (typeof e.absoluteGap != "number" || !Number.isFinite(e.absoluteGap) || e.absoluteGap < 0)) throw Error(`Invalid HiGHS option "absoluteGap" (${String(e.absoluteGap)}): expected a finite non-negative number.`);
441
+ if (e.objectiveOffset !== void 0 && (typeof e.objectiveOffset != "number" || !Number.isFinite(e.objectiveOffset))) throw Error(`Invalid HiGHS option "objectiveOffset" (${String(e.objectiveOffset)}): expected a finite number.`);
442
+ if (e.wasmUrl !== void 0 && e.wasmUrl !== null && (typeof e.wasmUrl != "string" || e.wasmUrl === "")) throw Error("Invalid HiGHS option \"wasmUrl\": expected a non-empty string or null.");
406
443
  }
407
- function g() {
408
- return m;
444
+ var g = null, _ = null, v = null;
445
+ function y(e) {
446
+ v = e, g = null, _ = null;
409
447
  }
410
- async function _(e) {
411
- return e || m || n();
448
+ function b() {
449
+ return v;
412
450
  }
413
- async function v(e = {}) {
414
- let t = await _(e.wasmUrl), n = t ?? "node";
415
- if (f && p === n) return f;
416
- p = n;
417
- let r = (async () => {
418
- let e = (await import("./browser-runtime-TLCY0hkc.js")).default;
419
- return await e({ locateFile: (e) => e.endsWith(".wasm") ? t : e });
420
- })().catch((e) => {
421
- f === r && (f = null, p = null);
422
- let n = e instanceof Error ? e.message : String(e);
423
- 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 });
424
- });
425
- return f = r, r;
451
+ async function x(e) {
452
+ return e || v || n();
426
453
  }
427
- async function y(e, t = {}) {
428
- if (t.signal?.aborted) return {
454
+ async function S(e = {}) {
455
+ let t = await x(e.wasmUrl);
456
+ return {
457
+ isNode: !1,
458
+ wasmUrl: t,
459
+ key: t ?? "node"
460
+ };
461
+ }
462
+ async function C(e = {}) {
463
+ let { isNode: t, wasmUrl: n, key: i } = await S(e);
464
+ if (g && _ === i) return g;
465
+ _ = i;
466
+ let a = null;
467
+ return a = (async () => {
468
+ let e = t ? await r() : (await import("./browser-runtime-AG5QFtKf.js")).default;
469
+ return t ? await e() : await e({ locateFile: (e) => e.endsWith(".wasm") ? n : e });
470
+ })().then((e) => e).catch((e) => {
471
+ g === a && (g = null, _ = null);
472
+ let t = e instanceof Error ? e.message : String(e);
473
+ throw Error(`[WaSHI] Failed to initialize HiGHS${n ? ` from "${n}"` : ""}. Deploy the package's WASM asset or explicitly set wasmUrl; no CDN fallback is attempted. ${t}`, { cause: e });
474
+ }), g = a, a;
475
+ }
476
+ async function w(e, t = {}) {
477
+ if (h(t), t.signal?.aborted) return {
429
478
  result: {
430
479
  Status: "Interrupted",
431
480
  StatusCode: 17,
@@ -436,7 +485,7 @@ async function y(e, t = {}) {
436
485
  },
437
486
  runTime: 0
438
487
  };
439
- let n = await v(t);
488
+ let n = await C(t);
440
489
  if (t.signal?.aborted) return {
441
490
  result: {
442
491
  Status: "Interrupted",
@@ -449,86 +498,76 @@ async function y(e, t = {}) {
449
498
  runTime: 0
450
499
  };
451
500
  let r = performance.now(), i = { output_flag: t.outputFlag ?? !1 };
452
- 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);
453
- for (let e of [
454
- "mip_max_nodes",
455
- "mip_max_improving_sols",
456
- "mip_max_leaves",
457
- "simplex_iteration_limit",
458
- "ipm_iteration_limit"
459
- ]) t[e] !== void 0 && (i[e] = t[e]);
460
- let a = typeof t.objectiveOffset == "number" && Number.isFinite(t.objectiveOffset) ? t.objectiveOffset : 0, s = t.initialValues, c = !1;
461
- if (s) {
462
- for (let [e, t] of Object.entries(s)) if (t !== void 0) {
501
+ 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.relativeGap !== void 0 && (i.mip_rel_gap = t.relativeGap), t.absoluteGap !== void 0 && (i.mip_abs_gap = t.absoluteGap);
502
+ for (let e of p) t[e] !== void 0 && (i[e] = t[e]);
503
+ let a = t.objectiveOffset ?? 0, o = t.initialValues, c = !1;
504
+ if (o) {
505
+ for (let [e, t] of Object.entries(o)) if (t !== void 0) {
463
506
  if (typeof t != "number" || !Number.isFinite(t)) throw Error(`Invalid initial value for column "${e}": ${String(t)} (must be a finite number).`);
464
507
  c = !0;
465
508
  }
466
509
  }
467
- if (typeof n.withModel == "function") return {
510
+ if (typeof n.withModel != "function") throw Error("[WaSHI] HiGHS runtime is missing required withModel() API (legacy highs.solve fallback has been removed).");
511
+ return {
468
512
  result: n.withModel({
469
513
  format: "lp",
470
514
  data: e
471
515
  }, (e) => {
472
- if (a !== 0 && typeof e.changeObjectiveOffset == "function") {
516
+ let l = !1;
517
+ if (a !== 0) {
518
+ if (typeof e.changeObjectiveOffset != "function") throw Error("[WaSHI] HiGHS runtime does not support changeObjectiveOffset() for non-zero objectiveOffset.");
473
519
  let t = typeof e.getObjectiveOffset == "function" ? e.getObjectiveOffset() : 0;
474
- e.changeObjectiveOffset(t + a);
475
- }
476
- for (let [t, r] of Object.entries(i)) try {
477
- e.options.set(t, r);
478
- } catch (e) {
479
- if (e?.name !== "HighsUnsupportedOptionError" && !(n.errors?.HighsUnsupportedOptionError && e instanceof n.errors.HighsUnsupportedOptionError)) throw e;
520
+ e.changeObjectiveOffset(t + a), l = !0;
480
521
  }
481
- let l = e.getDimensions(), u = [], d = !1;
482
- for (let t = 0; t < l.numCols; t++) {
522
+ for (let [t, n] of Object.entries(i)) e.options.set(t, n);
523
+ let u = e.getDimensions(), d = [], f = !1;
524
+ for (let t = 0; t < u.numCols; t++) {
483
525
  let n = e.getColIntegrality(t);
484
- n !== 0 && (d = !0), u.push({
526
+ n !== 0 && (f = !0), d.push({
485
527
  name: e.getColName(t),
486
528
  type: n === 1 ? "Integer" : "Continuous"
487
529
  });
488
530
  }
489
- if (c && s) {
531
+ if (c && o) {
490
532
  if (typeof e.setSolution != "function") throw Error("HiGHS runtime does not support setting primal initial values (setSolution is unavailable).");
491
533
  let t = /* @__PURE__ */ new Map();
492
- for (let e = 0; e < l.numCols; e++) t.set(u[e].name, e);
493
- for (let [e, n] of Object.entries(s)) if (n !== void 0 && !t.has(e)) throw Error(`Unknown column "${e}" in initialValues (column does not exist in the HiGHS LP model).`);
534
+ for (let e = 0; e < u.numCols; e++) t.set(d[e].name, e);
535
+ 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).`);
494
536
  let n = [], r = [];
495
- for (let e = 0; e < l.numCols; e++) {
496
- let t = u[e].name;
497
- if (Object.prototype.hasOwnProperty.call(s, t)) {
498
- let i = s[t];
537
+ for (let e = 0; e < u.numCols; e++) {
538
+ let t = d[e].name;
539
+ if (Object.prototype.hasOwnProperty.call(o, t)) {
540
+ let i = o[t];
499
541
  i !== void 0 && (n.push(e), r.push(i));
500
542
  }
501
543
  }
502
- n.length > 0 && (n.length === l.numCols ? e.setSolution({ colValue: r }) : e.setSolution({
544
+ n.length > 0 && (n.length === u.numCols ? e.setSolution({ colValue: r }) : e.setSolution({
503
545
  indices: n,
504
546
  values: r
505
547
  }));
506
548
  }
507
- let f = null, p = null, m = 0, h = (e) => {
549
+ let p = null, m = null, h = 0, g = (e) => {
508
550
  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 = {
509
551
  elapsedTime: n,
510
552
  elapsedSeconds: n,
511
553
  ...i === void 0 ? {} : { objectiveValue: i },
512
554
  ...a === void 0 ? {} : { objectiveBound: a },
513
- ...o === void 0 ? {} : {
514
- relGap: o,
515
- mipGap: o
516
- },
517
- ...s === void 0 ? {} : { absGap: s },
555
+ ...o === void 0 ? {} : { relativeGap: o },
556
+ ...s === void 0 ? {} : { absoluteGap: s },
518
557
  ...c === void 0 ? {} : { nodes: c },
519
558
  ...l === void 0 ? {} : { iterations: l },
520
559
  ...u === void 0 ? {} : { message: u }
521
560
  };
522
- return p = d, d;
523
- }, g = (e) => {
561
+ return m = d, d;
562
+ }, _ = (e) => {
524
563
  let n = e?.data;
525
564
  if (!n || !(n.mip_solution instanceof Float64Array)) return;
526
565
  let r = n.mip_solution, i = {};
527
- for (let e = 0; e < u.length && e < r.length; e++) Object.defineProperty(i, u[e].name, {
566
+ for (let e = 0; e < d.length && e < r.length; e++) Object.defineProperty(i, d[e].name, {
528
567
  value: {
529
568
  Index: e,
530
- Type: u[e].type,
531
- Name: u[e].name,
569
+ Type: d[e].type,
570
+ Name: d[e].name,
532
571
  Primal: r[e]
533
572
  },
534
573
  enumerable: !0,
@@ -536,13 +575,13 @@ async function y(e, t = {}) {
536
575
  configurable: !0
537
576
  });
538
577
  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;
539
- Number.isFinite(a) && (f = {
578
+ Number.isFinite(a) && (p = {
540
579
  objectiveValue: a,
541
580
  ...typeof n.mip_dual_bound == "number" && Number.isFinite(n.mip_dual_bound) ? { mipDualBound: n.mip_dual_bound } : {},
542
581
  ...typeof n.mip_gap == "number" && Number.isFinite(n.mip_gap) ? { mipGap: n.mip_gap } : {},
543
582
  columns: i
544
- }, t.onIncumbent?.(f));
545
- }, _ = !1;
583
+ }, t.onIncumbent?.(p));
584
+ }, v = !1;
546
585
  if (t.signal || t.onProgress || t.onIncumbent) {
547
586
  let r = n.constants?.callbackType ?? {
548
587
  logging: 0,
@@ -554,90 +593,85 @@ async function y(e, t = {}) {
554
593
  mipInterrupt: 6
555
594
  }, i = (e) => {
556
595
  if (t.signal?.aborted) {
557
- _ = !0, e.interrupt();
596
+ v = !0, e.interrupt();
558
597
  return;
559
598
  }
560
- t.onProgress && (m++, t.onProgress(h(e)), t.signal?.aborted && (_ = !0, e.interrupt()));
599
+ t.onProgress && (h++, t.onProgress(g(e)), t.signal?.aborted && (v = !0, e.interrupt()));
561
600
  }, a = {
562
601
  [r.simplexInterrupt]: i,
563
602
  [r.ipmInterrupt]: i,
564
603
  [r.mipInterrupt]: i,
565
604
  [r.mipImprovingSolution]: (e) => {
566
- g(e), t.onProgress && !t.signal?.aborted && (m++, t.onProgress(h(e)));
605
+ _(e), t.onProgress && !t.signal?.aborted && (h++, t.onProgress(g(e)));
567
606
  },
568
607
  [r.mipLogging]: (e) => {
569
- t.onProgress && !t.signal?.aborted && (m++, t.onProgress(h(e)));
608
+ t.onProgress && !t.signal?.aborted && (h++, t.onProgress(g(e)));
570
609
  }
571
610
  };
572
611
  e.run(a);
573
612
  } else e.run();
574
- let v = e.getModelStatus();
575
- _ && (v = 17);
576
- let y = o[v] ?? "Unknown", b = 0, x = 0;
613
+ let y = e.getModelStatus();
614
+ v && (y = 17);
615
+ let b = s[y] ?? "Unknown", x = 0, S = 0;
577
616
  try {
578
- b = Number(e.info.get("primal_solution_status"));
617
+ x = Number(e.info.get("primal_solution_status"));
579
618
  } catch {}
580
619
  try {
581
- x = Number(e.info.get("dual_solution_status"));
620
+ S = Number(e.info.get("dual_solution_status"));
582
621
  } catch {}
583
- let S = n.constants?.solutionStatus?.feasible ?? 2, C = b === S, w = x === S, T = C || w ? e.getSolution() : null, E = C, D = {};
584
- if (!C && f !== null) E = !0, D = f.columns;
585
- else for (let e = 0; e < l.numCols; e++) {
586
- let t = u[e], n = {
622
+ let C = n.constants?.solutionStatus?.feasible ?? 2, w = x === C, T = S === C, E = w || T ? e.getSolution() : null, D = w, O = {};
623
+ if (!w && p !== null) D = !0, O = p.columns;
624
+ else for (let e = 0; e < u.numCols; e++) {
625
+ let t = d[e], n = {
587
626
  Index: e,
588
627
  Type: t.type,
589
628
  Name: t.name
590
629
  };
591
- C && T && (n.Primal = T.colValue[e]), !d && w && T && (n.Dual = T.colDual[e]), Object.defineProperty(D, t.name, {
630
+ w && E && (n.Primal = E.colValue[e]), !f && T && E && (n.Dual = E.colDual[e]), Object.defineProperty(O, t.name, {
592
631
  value: n,
593
632
  enumerable: !0,
594
633
  writable: !0,
595
634
  configurable: !0
596
635
  });
597
636
  }
598
- let O = [];
599
- for (let t = 0; t < l.numRows; t++) {
637
+ let k = [];
638
+ for (let t = 0; t < u.numRows; t++) {
600
639
  let n = e.getRowName(t), r = {
601
640
  Index: t,
602
641
  Name: n
603
642
  };
604
- C && T && (r.Primal = T.rowValue[t]), !d && w && T && (r.Dual = T.rowDual[t]), O.push(r);
643
+ w && E && (r.Primal = E.rowValue[t]), !f && T && E && (r.Dual = E.rowDual[t]), k.push(r);
605
644
  }
606
- let k = C ? e.getObjectiveValue() : f === null ? NaN : f.objectiveValue, A, j;
607
- if (d) {
645
+ let A = w ? e.getObjectiveValue() : p === null ? NaN : p.objectiveValue, j, M;
646
+ if (f) {
608
647
  try {
609
648
  let t = Number(e.info.get("mip_dual_bound"));
610
- Number.isFinite(t) && (A = t);
649
+ Number.isFinite(t) && (j = t);
611
650
  } catch {}
612
- A === void 0 && p && p.objectiveBound !== void 0 && (A = p.objectiveBound);
651
+ j === void 0 && m && m.objectiveBound !== void 0 && (j = m.objectiveBound);
613
652
  try {
614
653
  let t = Number(e.info.get("mip_gap"));
615
- Number.isFinite(t) && (j = t);
654
+ Number.isFinite(t) && (M = t);
616
655
  } catch {}
617
- j === void 0 && p && p.relGap !== void 0 && (j = p.relGap);
656
+ M === void 0 && m && m.relativeGap !== void 0 && (M = m.relativeGap);
618
657
  }
619
658
  return {
620
- Status: o[v] ?? y,
621
- StatusCode: v,
622
- PrimalSolutionStatus: b,
623
- DualSolutionStatus: x,
624
- HasPrimalSolution: E,
625
- IsMip: d,
626
- ObjectiveValue: k,
627
- ObjectiveOffsetApplied: a !== 0,
628
- MipDualBound: A,
629
- MipGap: j,
630
- Columns: D,
631
- Rows: O
659
+ Status: s[y] ?? b,
660
+ StatusCode: y,
661
+ PrimalSolutionStatus: x,
662
+ DualSolutionStatus: S,
663
+ HasPrimalSolution: D,
664
+ IsMip: f,
665
+ ObjectiveValue: A,
666
+ ObjectiveOffsetApplied: l,
667
+ MipDualBound: j,
668
+ MipGap: M,
669
+ Columns: O,
670
+ Rows: k
632
671
  };
633
672
  }),
634
673
  runTime: (performance.now() - r) / 1e3
635
674
  };
636
- if (c) throw Error("HiGHS runtime does not support setting primal initial values (withModel/setSolution is unavailable).");
637
- return {
638
- result: n.solve(e, i),
639
- runTime: (performance.now() - r) / 1e3
640
- };
641
675
  }
642
676
  //#endregion
643
- export { y as a, h as i, g as n, d as o, _ as r, t as s, v as t };
677
+ export { w as a, t as c, y as i, b as n, h as o, x as r, f as s, C as t };