@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
package/dist/lib/washi.js CHANGED
@@ -1,24 +1,24 @@
1
- import { A as e, C as t, D as n, E as r, M as i, N as a, O as o, S as s, T as c, _ as l, a as u, b as d, c as f, d as p, f as m, g as h, h as g, i as _, j as v, k as y, l as b, m as x, n as S, o as C, p as w, r as T, s as E, t as D, u as O, v as k, w as A, x as j, y as ee } from "./registry-BEfvpZW3.js";
2
- import { a as M, c as N, i as P, n as F, o as I, r as L, s as R, t as te } from "./loader-DmNC_UNk.js";
3
- import { createHighsWorker as ne } from "./highs-worker-factory.js";
1
+ import { A as e, C as t, D as n, E as r, M as i, N as a, O as o, S as s, T as c, _ as l, a as u, b as d, c as f, d as p, f as m, g as h, h as g, i as _, j as v, k as y, l as b, m as x, n as S, o as C, p as w, r as T, s as E, t as D, u as O, v as k, w as A, x as j, y as ee } from "./registry-C20sxTwm.js";
2
+ import { a as M, c as N, d as P, f as te, h as ne, i as re, l as ie, m as ae, n as oe, o as F, p as se, r as I, s as L, t as ce, u as le } from "./loader-BZUQNvh4.js";
3
+ import { createHighsWorker as ue } from "./highs-worker-factory.js";
4
4
  //#region \0rolldown/runtime.js
5
- var re = Object.defineProperty, ie = Object.getOwnPropertyDescriptor, ae = Object.getOwnPropertyNames, oe = Object.prototype.hasOwnProperty, se = (e, t) => {
5
+ var de = Object.defineProperty, fe = Object.getOwnPropertyDescriptor, pe = Object.getOwnPropertyNames, me = Object.prototype.hasOwnProperty, he = (e, t) => {
6
6
  let n = {};
7
- for (var r in e) re(n, r, {
7
+ for (var r in e) de(n, r, {
8
8
  get: e[r],
9
9
  enumerable: !0
10
10
  });
11
- return t || re(n, Symbol.toStringTag, { value: "Module" }), n;
12
- }, ce = (e, t, n, r) => {
13
- if (t && typeof t == "object" || typeof t == "function") for (var i = ae(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !oe.call(e, s) && s !== n && re(e, s, {
11
+ return t || de(n, Symbol.toStringTag, { value: "Module" }), n;
12
+ }, ge = (e, t, n, r) => {
13
+ if (t && typeof t == "object" || typeof t == "function") for (var i = pe(t), a = 0, o = i.length, s; a < o; a++) s = i[a], !me.call(e, s) && s !== n && de(e, s, {
14
14
  get: ((e) => t[e]).bind(null, s),
15
- enumerable: !(r = ie(t, s)) || r.enumerable
15
+ enumerable: !(r = fe(t, s)) || r.enumerable
16
16
  });
17
17
  return e;
18
- }, z = (e, t, n) => (ce(e, t, "default"), n && ce(n, t, "default"));
18
+ }, R = (e, t, n) => (ge(e, t, "default"), n && ge(n, t, "default"));
19
19
  //#endregion
20
20
  //#region src/modeler/types.ts
21
- function le(e) {
21
+ function _e(e) {
22
22
  if (e === void 0) return "Minimize";
23
23
  if (typeof e == "string") {
24
24
  let t = e.toLowerCase();
@@ -29,8 +29,8 @@ function le(e) {
29
29
  }
30
30
  //#endregion
31
31
  //#region src/modeler/parser.ts
32
- var ue = /^(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?$/;
33
- function de(e, t) {
32
+ var ve = /^(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?$/;
33
+ function ye(e, t) {
34
34
  let n = [], r = 0, i = e.length;
35
35
  for (; r < i;) {
36
36
  let a = e[r];
@@ -86,7 +86,7 @@ function de(e, t) {
86
86
  for (; r < i && (e[r] === "." || e[r] === "e" || e[r] === "E" || /[0-9]/.test(e[r]));) a += e[r++];
87
87
  }
88
88
  } else for (; r < i && (e[r] === "." || /[0-9]/.test(e[r]));) a += e[r++];
89
- if (!ue.test(a)) throw Error(`Invalid numeric literal '${a}' at position ${t} in: "${e}"`);
89
+ if (!ve.test(a)) throw Error(`Invalid numeric literal '${a}' at position ${t} in: "${e}"`);
90
90
  let o = Number(a);
91
91
  if (!Number.isFinite(o)) throw Error(`Numeric literal '${a}' overflows finite floating-point range in: "${e}"`);
92
92
  if (o === 0 && !/^[0.]+(?:[eE][+-]?\d+)?$/.test(a)) throw Error(`Numeric literal '${a}' underflows to zero at position ${t} in: "${e}"`);
@@ -113,7 +113,7 @@ function de(e, t) {
113
113
  }
114
114
  return n;
115
115
  }
116
- var fe = class {
116
+ var be = class {
117
117
  tokens;
118
118
  pos = 0;
119
119
  resolver;
@@ -214,15 +214,15 @@ var fe = class {
214
214
  return t;
215
215
  }
216
216
  };
217
- function B(e, t, n) {
218
- let r = new fe(de(e, n), t), i = r.parseExpression(), a = r.getRemainingToken();
217
+ function xe(e, t, n) {
218
+ let r = new be(ye(e, n), t), i = r.parseExpression(), a = r.getRemainingToken();
219
219
  if (a) throw Error(`Unexpected token '${a.value}' after expression in "${e}"`);
220
- return _e(i), i;
220
+ return Ee(i), i;
221
221
  }
222
- function pe(e, t) {
223
- return B(e, t);
222
+ function Se(e, t) {
223
+ return xe(e, t);
224
224
  }
225
- function me(e, t, n, r) {
225
+ function Ce(e, t, n, r) {
226
226
  let i = e.match(/(<=|>=|==|=<|=>|=)/);
227
227
  if (!i) throw Error(`Constraint must contain a comparison operator (<=, >=, ==, =): "${e}"`);
228
228
  let a = i[0], o = i.index, s = e.substring(0, o).trim(), c = e.substring(o + a.length).trim(), l;
@@ -230,19 +230,19 @@ function me(e, t, n, r) {
230
230
  else if (a === ">=" || a === "=>") l = ">=";
231
231
  else if (a === "==" || a === "=") l = "==";
232
232
  else throw Error(`Unsupported operator "${a}"`);
233
- let u = B(s, t, r), d = B(c, t, r);
233
+ let u = xe(s, t, r), d = xe(c, t, r);
234
234
  if (u instanceof A && u.quadTerms.size > 0 || d instanceof A && d.quadTerms.size > 0) throw Error("Quadratic constraints are not supported (only linear constraints are allowed in MILP/LP/QP)");
235
235
  let f = u instanceof A ? new j(u.linearTerms, u.constant) : u, p = d instanceof A ? new j(d.linearTerms, d.constant) : d, m;
236
- if (m = l === "<=" ? f.le(p, n) : l === ">=" ? f.ge(p, n) : f.eq(p, n), _e(m.lhs), !Number.isFinite(m.rhs)) throw Error(`Invalid non-finite right-hand side "${m.rhs}" in constraint.`);
236
+ if (m = l === "<=" ? f.le(p, n) : l === ">=" ? f.ge(p, n) : f.eq(p, n), Ee(m.lhs), !Number.isFinite(m.rhs)) throw Error(`Invalid non-finite right-hand side "${m.rhs}" in constraint.`);
237
237
  return m;
238
238
  }
239
- function he(e, t, n) {
240
- return me(e, t, n);
239
+ function we(e, t, n) {
240
+ return Ce(e, t, n);
241
241
  }
242
- function ge(e) {
242
+ function Te(e) {
243
243
  return e instanceof b || e instanceof j || e instanceof A ? !0 : typeof e != "object" || !e ? !1 : "terms" in e && e.terms instanceof Map || "quadTerms" in e && e.quadTerms instanceof Map || "id" in e && "name" in e && "lb" in e && "ub" in e && "type" in e && typeof e.mul == "function";
244
244
  }
245
- function _e(e) {
245
+ function Ee(e) {
246
246
  if ("constant" in e && !Number.isFinite(e.constant)) throw Error(`Invalid non-finite constant "${e.constant}" in expression.`);
247
247
  if ("terms" in e && e.terms instanceof Map) {
248
248
  for (let [, t] of e.terms) if (!Number.isFinite(t)) throw Error(`Invalid non-finite coefficient "${t}" in expression.`);
@@ -254,10 +254,10 @@ function _e(e) {
254
254
  for (let [, t] of e.quadTerms) if (!Number.isFinite(t.coeff)) throw Error(`Invalid non-finite quadratic coefficient "${t.coeff}" in expression.`);
255
255
  }
256
256
  }
257
- function ve(e) {
257
+ function De(e) {
258
258
  return e instanceof c || typeof e == "object" && !!e && "sense" in e && "lhs" in e && "rhs" in e;
259
259
  }
260
- function ye(e, t) {
260
+ function Oe(e, t) {
261
261
  let n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map(), i = e.join(""), a = "__washi_";
262
262
  for (; i.includes(a);) a += "_";
263
263
  let o = "";
@@ -267,9 +267,9 @@ function ye(e, t) {
267
267
  if (!Number.isFinite(e)) throw Error(`Invalid numeric value "${e}" in template expression: interpolated numbers must be finite.`);
268
268
  let t = `${a}num_${i}__`;
269
269
  r.set(t, e), o += `(${t})`;
270
- } else if (ve(e)) throw Error("Cannot interpolate a constraint comparison (<=, >=, ==) inside a template expression: expected a finite number, Var, LinExpr, or QuadExpr.");
271
- else if (ge(e)) {
272
- _e(e);
270
+ } else if (De(e)) throw Error("Cannot interpolate a constraint comparison (<=, >=, ==) inside a template expression: expected a finite number, Var, LinExpr, or QuadExpr.");
271
+ else if (Te(e)) {
272
+ Ee(e);
273
273
  let t = `${a}ph_${i}__`;
274
274
  n.set(t, e), o += ` ${t} `;
275
275
  } else throw Error("Unsupported interpolation value in template expression: expected a finite number, Var, LinExpr, or QuadExpr.");
@@ -280,14 +280,14 @@ function ye(e, t) {
280
280
  numberMap: r
281
281
  };
282
282
  }
283
- function be(e, ...t) {
284
- let { fullText: n, resolver: r, numberMap: i } = ye(e, t);
285
- return /(<=|>=|==|=<|=>|=)/.test(n) ? me(n, r, void 0, i) : B(n, r, i);
283
+ function ke(e, ...t) {
284
+ let { fullText: n, resolver: r, numberMap: i } = Oe(e, t);
285
+ return /(<=|>=|==|=<|=>|=)/.test(n) ? Ce(n, r, void 0, i) : xe(n, r, i);
286
286
  }
287
287
  //#endregion
288
288
  //#region src/modeler/solvers/highs/worker-client.ts
289
- var V = null, xe = 0, H = /* @__PURE__ */ new Map();
290
- function Se(e, t) {
289
+ var z = null, Ae = 0, B = /* @__PURE__ */ new Map();
290
+ function je(e, t) {
291
291
  return e ? {
292
292
  Status: "Interrupted",
293
293
  StatusCode: 17,
@@ -311,8 +311,8 @@ function Se(e, t) {
311
311
  Rows: []
312
312
  };
313
313
  }
314
- function U(e) {
315
- let t = H.values().next().value;
314
+ function Me(e) {
315
+ let t = B.values().next().value;
316
316
  if (t && !t.dispatched) {
317
317
  t.dispatched = !0;
318
318
  try {
@@ -324,30 +324,30 @@ function U(e) {
324
324
  ...t.reportProgress ? { reportProgress: !0 } : {}
325
325
  });
326
326
  } catch (n) {
327
- H.delete(t.id), t.cleanupAbort?.(), t.reject(n), U(e);
327
+ B.delete(t.id), t.cleanupAbort?.(), t.reject(n), Me(e);
328
328
  }
329
329
  }
330
330
  }
331
- function Ce() {
332
- let e = V;
333
- e && (V = null, e.terminate());
334
- for (let e of H.values()) e.dispatched = !1;
335
- if (H.size > 0) {
336
- let e = we();
337
- if (e) U(e);
331
+ function Ne() {
332
+ let e = z;
333
+ e && (z = null, e.terminate());
334
+ for (let e of B.values()) e.dispatched = !1;
335
+ if (B.size > 0) {
336
+ let e = Pe();
337
+ if (e) Me(e);
338
338
  else {
339
339
  let e = /* @__PURE__ */ Error("[WaSHI] Failed to recreate HiGHS Worker after interruption.");
340
- for (let t of Array.from(H.values())) H.delete(t.id), t.cleanupAbort?.(), t.reject(e);
340
+ for (let t of Array.from(B.values())) B.delete(t.id), t.cleanupAbort?.(), t.reject(e);
341
341
  }
342
342
  }
343
343
  }
344
- function we() {
344
+ function Pe() {
345
345
  if (typeof window > "u" || typeof Worker > "u") return null;
346
- if (!V) try {
347
- V = ne();
348
- let e = V;
349
- V.onmessage = (t) => {
350
- let { type: n, id: r, result: i, runTime: a, error: o, progress: s, incumbent: c } = t.data, l = H.get(r);
346
+ if (!z) try {
347
+ z = ue();
348
+ let e = z;
349
+ z.onmessage = (t) => {
350
+ let { type: n, id: r, result: i, runTime: a, error: o, progress: s, incumbent: c } = t.data, l = B.get(r);
351
351
  if (l) {
352
352
  if (n === "SOLVE_PROGRESS") {
353
353
  if (s) {
@@ -355,10 +355,10 @@ function we() {
355
355
  try {
356
356
  l.onProgress?.(s);
357
357
  } catch (e) {
358
- let t = H.get(r);
358
+ let t = B.get(r);
359
359
  if (t) {
360
- let n = H.keys().next().value;
361
- H.delete(r), t.cleanupAbort?.(), n === r && Ce(), t.reject(e);
360
+ let n = B.keys().next().value;
361
+ B.delete(r), t.cleanupAbort?.(), n === r && Ne(), t.reject(e);
362
362
  }
363
363
  }
364
364
  }
@@ -368,41 +368,41 @@ function we() {
368
368
  c && (l.lastIncumbent = c);
369
369
  return;
370
370
  }
371
- H.delete(r), l.cleanupAbort?.(), n === "SOLVE_SUCCESS" ? l.resolve({
371
+ B.delete(r), l.cleanupAbort?.(), n === "SOLVE_SUCCESS" ? l.resolve({
372
372
  result: i,
373
373
  runTime: a
374
- }) : l.reject(Error(o || "Worker solve failed")), V === e && U(e);
374
+ }) : l.reject(Error(o || "Worker solve failed")), z === e && Me(e);
375
375
  }
376
376
  };
377
377
  let t = (t) => {
378
- if (V === e) {
379
- V = null, e.terminate();
380
- for (let e of H.values()) e.cleanupAbort?.(), e.reject(t);
381
- H.clear();
378
+ if (z === e) {
379
+ z = null, e.terminate();
380
+ for (let e of B.values()) e.cleanupAbort?.(), e.reject(t);
381
+ B.clear();
382
382
  }
383
383
  };
384
- V.onerror = (e) => t(/* @__PURE__ */ Error(`[WaSHI] HiGHS Worker failed to load or execute. Check Worker assets, CORS and CSP. ${e?.message || ""}`)), V.onmessageerror = () => t(/* @__PURE__ */ Error("[WaSHI] Could not deserialize the HiGHS Worker response."));
384
+ z.onerror = (e) => t(/* @__PURE__ */ Error(`[WaSHI] HiGHS Worker failed to load or execute. Check Worker assets, CORS and CSP. ${e?.message || ""}`)), z.onmessageerror = () => t(/* @__PURE__ */ Error("[WaSHI] Could not deserialize the HiGHS Worker response."));
385
385
  } catch {
386
- V = null;
386
+ z = null;
387
387
  }
388
- return V;
388
+ return z;
389
389
  }
390
- async function W(e, t = {}) {
390
+ async function V(e, t = {}) {
391
391
  if (t.signal?.aborted) return {
392
- result: Se(),
392
+ result: je(),
393
393
  runTime: 0
394
394
  };
395
- let n = await I(t.wasmUrl);
395
+ let n = await F(t.wasmUrl);
396
396
  if (t.signal?.aborted) return {
397
- result: Se(),
397
+ result: je(),
398
398
  runTime: 0
399
399
  };
400
- let r = t.useWorker ?? typeof window < "u" ? we() : null;
400
+ let r = t.useWorker ?? typeof window < "u" ? Pe() : null;
401
401
  if (!r) return N(e, t);
402
402
  let { signal: i, onProgress: a, ...o } = t, s = {};
403
403
  for (let [e, t] of Object.entries(o)) typeof t != "function" && (s[e] = t);
404
404
  s.wasmUrl = n;
405
- let c = !!(a || i), l = `req_${++xe}`, u = performance.now();
405
+ let c = !!(a || i), l = `req_${++Ae}`, u = performance.now();
406
406
  return new Promise((t, n) => {
407
407
  let o = {
408
408
  id: l,
@@ -416,24 +416,24 @@ async function W(e, t = {}) {
416
416
  };
417
417
  if (i) {
418
418
  let e = () => {
419
- let e = H.get(l);
419
+ let e = B.get(l);
420
420
  if (!e) return;
421
- let t = H.keys().next().value;
422
- H.delete(l), e.cleanupAbort?.(), t === l && Ce();
421
+ let t = B.keys().next().value;
422
+ B.delete(l), e.cleanupAbort?.(), t === l && Ne();
423
423
  let n = (performance.now() - e.startTime) / 1e3;
424
424
  e.resolve({
425
- result: Se(e.lastIncumbent, e.lastProgress),
425
+ result: je(e.lastIncumbent, e.lastProgress),
426
426
  runTime: n
427
427
  });
428
428
  };
429
429
  i.addEventListener("abort", e, { once: !0 }), o.cleanupAbort = () => i.removeEventListener("abort", e);
430
430
  }
431
- H.set(l, o), U(r);
431
+ B.set(l, o), Me(r);
432
432
  });
433
433
  }
434
434
  //#endregion
435
435
  //#region src/modeler/solvers/highs/solver.ts
436
- function G(e, t) {
436
+ function H(e, t) {
437
437
  if (typeof t == "number") switch (t) {
438
438
  case 0: return "NotSolved";
439
439
  case 1:
@@ -492,8 +492,8 @@ function G(e, t) {
492
492
  let r = n.toLowerCase();
493
493
  return r.includes("infeasible") && r.includes("unbounded") ? "InfeasibleOrUnbounded" : r.includes("infeasible") ? "Infeasible" : r.includes("unbounded") ? "Unbounded" : r.includes("time limit") || r.includes("timelimit") ? "TimeLimit" : r.includes("iteration limit") || r.includes("iterationlimit") ? "IterationLimit" : r.includes("solution limit") || r.includes("solutionlimit") ? "SolutionLimit" : r.includes("memory limit") || r.includes("memorylimit") ? "MemoryLimit" : r.includes("bound on objective") ? "ObjectiveBound" : r.includes("target for objective") ? "ObjectiveTarget" : r.includes("interrupt") ? "Interrupted" : r.includes("error") ? "Error" : r === "optimal" ? "Optimal" : "Unknown";
494
494
  }
495
- function K(e, t, n) {
496
- switch (G(e, t)) {
495
+ function U(e, t, n) {
496
+ switch (H(e, t)) {
497
497
  case "Optimal": return "Optimal";
498
498
  case "Infeasible": return "Infeasible";
499
499
  case "Unbounded": return "Unbounded";
@@ -510,14 +510,14 @@ function K(e, t, n) {
510
510
  default: return "Unknown";
511
511
  }
512
512
  }
513
- var q = class e {
513
+ var W = class e {
514
514
  static capabilities = {
515
515
  supportsMIP: !0,
516
516
  supportsQP: !0,
517
517
  supportsWarmStart: !0
518
518
  };
519
519
  name = "HiGHS";
520
- version = "1.15.3";
520
+ version = "1.15.1";
521
521
  capabilities = e.capabilities;
522
522
  options;
523
523
  constructor(e = {}) {
@@ -529,7 +529,7 @@ var q = class e {
529
529
  ...i
530
530
  }, o = e.objective.constant || 0;
531
531
  for (let t of e.variables) d(t);
532
- let { lpString: s, nameToVar: c, nameToConstraint: l } = r ? t : C(e), u = Object.create(null), p = !1, m = /* @__PURE__ */ new Set();
532
+ let { lpString: s, nameToVar: c, nameToConstraint: l } = r ? t : C(e, { relax: a.relax }), u = Object.create(null), p = !1, m = /* @__PURE__ */ new Set();
533
533
  for (let [e, t] of c.entries()) {
534
534
  m.add(t);
535
535
  let n = w(t);
@@ -551,13 +551,13 @@ var q = class e {
551
551
  ...o === 0 ? {} : { objectiveOffset: o },
552
552
  initialValues: p ? u : void 0
553
553
  });
554
- let { result: g, runTime: _ } = await W(s, h), v = g?.ObjectiveOffsetApplied ? 0 : o, y = G(g?.Status, g?.StatusCode), b = typeof g?.IsMip == "boolean" ? g.IsMip : e.variables.some((e) => e.type === "Integer" || e.type === "Binary"), x;
554
+ let { result: g, runTime: _ } = await V(s, h), v = g?.ObjectiveOffsetApplied ? 0 : o, y = H(g?.Status, g?.StatusCode), b = a.relax ? !1 : typeof g?.IsMip == "boolean" ? g.IsMip : e.variables.some((e) => e.type === "Integer" || e.type === "Binary"), x;
555
555
  if (typeof g?.HasPrimalSolution == "boolean") x = g.HasPrimalSolution;
556
556
  else {
557
557
  let e = g?.Columns ? Object.values(g.Columns) : [], t = e.length > 0 && e.some((e) => typeof e?.Primal == "number" && Number.isFinite(e.Primal)), n = typeof g?.ObjectiveValue == "number" && Number.isFinite(g.ObjectiveValue);
558
558
  x = y === "Infeasible" || y === "Unbounded" || y === "InfeasibleOrUnbounded" || y === "Error" || y === "NotSolved" ? !1 : y === "Optimal" || y === "Feasible" ? n || t : n && (e.length === 0 || t);
559
559
  }
560
- let S = K(g?.Status, g?.StatusCode, x), T = null;
560
+ let S = U(g?.Status, g?.StatusCode, x), T = null;
561
561
  x && typeof g?.ObjectiveValue == "number" && Number.isFinite(g.ObjectiveValue) && (T = g.ObjectiveValue + v);
562
562
  let D, O, k;
563
563
  if (typeof g?.MipDualBound == "number" && Number.isFinite(g.MipDualBound) ? D = g.MipDualBound + v : !b && y === "Optimal" && T !== null && (D = T), T !== null && D !== void 0 && Number.isFinite(D) && (k = Math.abs(T - D)), v !== 0 && b && T !== null && D !== void 0 && k !== void 0) {
@@ -632,55 +632,69 @@ var q = class e {
632
632
  raw: g
633
633
  };
634
634
  }
635
- }, J = q;
636
- function Y() {
637
- T("highs", (e) => new q(e)), _((e) => new q(e));
635
+ }, G = W;
636
+ function K() {
637
+ T("highs", (e) => new W(e)), _((e) => new W(e));
638
638
  }
639
- Y();
639
+ K();
640
640
  //#endregion
641
641
  //#region src/modeler/solvers/highs/index.ts
642
- var Te = /* @__PURE__ */ se({
643
- HiGHS: () => J,
644
- HighsSolver: () => q,
645
- OFFICIAL_HIGHS_CDN_WASM_URL: () => te,
646
- getHighs: () => F,
647
- getHighsWasmUrl: () => L,
648
- isValidWasmHeader: () => P,
649
- mapHighsStatus: () => K,
650
- mapHighsTerminationStatus: () => G,
642
+ var Fe = /* @__PURE__ */ he({
643
+ HIGHS_CONSTANTS: () => ie,
644
+ HIGHS_STATUS_NAMES: () => le,
645
+ HiGHS: () => G,
646
+ Highs: () => P,
647
+ HighsError: () => te,
648
+ HighsModel: () => se,
649
+ HighsSolver: () => W,
650
+ HighsUnsupportedOptionError: () => ae,
651
+ OFFICIAL_HIGHS_CDN_WASM_URL: () => ce,
652
+ bindHighsFunctions: () => ne,
653
+ getHighs: () => oe,
654
+ getHighsWasmUrl: () => I,
655
+ isValidWasmHeader: () => re,
656
+ mapHighsStatus: () => U,
657
+ mapHighsTerminationStatus: () => H,
651
658
  probeWasmUrl: () => M,
652
- registerHighsSolver: () => Y,
653
- resolveBrowserWasmUrl: () => I,
654
- setHighsWasmUrl: () => R,
655
- solveLp: () => W,
659
+ registerHighsSolver: () => K,
660
+ resolveBrowserWasmUrl: () => F,
661
+ setHighsWasmUrl: () => L,
662
+ solveLp: () => V,
656
663
  solveLpWithHighs: () => N
657
664
  });
658
- import * as Ee from "./highs-worker-factory.js";
659
- z(Te, Ee);
660
- import * as De from "./highs-assets.js";
661
- z(Te, De);
665
+ import * as Ie from "./highs-worker-factory.js";
666
+ R(Fe, Ie);
667
+ import * as Le from "./highs-assets.js";
668
+ R(Fe, Le);
662
669
  //#endregion
663
670
  //#region src/modeler/solvers/highs.ts
664
- var Oe = /* @__PURE__ */ se({
665
- HiGHS: () => J,
666
- HighsSolver: () => q,
667
- OFFICIAL_HIGHS_CDN_WASM_URL: () => te,
668
- getHighs: () => F,
669
- getHighsWasmUrl: () => L,
670
- isValidWasmHeader: () => P,
671
- mapHighsStatus: () => K,
672
- mapHighsTerminationStatus: () => G,
671
+ var Re = /* @__PURE__ */ he({
672
+ HIGHS_CONSTANTS: () => ie,
673
+ HIGHS_STATUS_NAMES: () => le,
674
+ HiGHS: () => G,
675
+ Highs: () => P,
676
+ HighsError: () => te,
677
+ HighsModel: () => se,
678
+ HighsSolver: () => W,
679
+ HighsUnsupportedOptionError: () => ae,
680
+ OFFICIAL_HIGHS_CDN_WASM_URL: () => ce,
681
+ bindHighsFunctions: () => ne,
682
+ getHighs: () => oe,
683
+ getHighsWasmUrl: () => I,
684
+ isValidWasmHeader: () => re,
685
+ mapHighsStatus: () => U,
686
+ mapHighsTerminationStatus: () => H,
673
687
  probeWasmUrl: () => M,
674
- registerHighsSolver: () => Y,
675
- resolveBrowserWasmUrl: () => I,
676
- setHighsWasmUrl: () => R,
677
- solveLp: () => W,
688
+ registerHighsSolver: () => K,
689
+ resolveBrowserWasmUrl: () => F,
690
+ setHighsWasmUrl: () => L,
691
+ solveLp: () => V,
678
692
  solveLpWithHighs: () => N
679
693
  });
680
- z(Oe, Te);
694
+ R(Re, Fe);
681
695
  //#endregion
682
696
  //#region src/modeler/solvers/mock.ts
683
- var ke = class {
697
+ var ze = class {
684
698
  name;
685
699
  capabilities;
686
700
  options;
@@ -780,44 +794,51 @@ var ke = class {
780
794
  };
781
795
  }
782
796
  };
783
- function Ae() {
784
- T("mock", (e) => new ke(e));
797
+ function Be() {
798
+ T("mock", (e) => new ze(e));
785
799
  }
786
- Ae();
800
+ Be();
787
801
  //#endregion
788
802
  //#region src/modeler/solvers/index.ts
789
- var je = /* @__PURE__ */ se({
790
- HiGHS: () => J,
791
- HighsSolver: () => q,
792
- MockSolver: () => ke,
793
- OFFICIAL_HIGHS_CDN_WASM_URL: () => te,
794
- getHighs: () => F,
795
- getHighsWasmUrl: () => L,
803
+ var Ve = /* @__PURE__ */ he({
804
+ HIGHS_CONSTANTS: () => ie,
805
+ HIGHS_STATUS_NAMES: () => le,
806
+ HiGHS: () => G,
807
+ Highs: () => P,
808
+ HighsError: () => te,
809
+ HighsModel: () => se,
810
+ HighsSolver: () => W,
811
+ HighsUnsupportedOptionError: () => ae,
812
+ MockSolver: () => ze,
813
+ OFFICIAL_HIGHS_CDN_WASM_URL: () => ce,
814
+ bindHighsFunctions: () => ne,
815
+ getHighs: () => oe,
816
+ getHighsWasmUrl: () => I,
796
817
  getSolver: () => D,
797
- isValidWasmHeader: () => P,
818
+ isValidWasmHeader: () => re,
798
819
  listAvailableSolvers: () => S,
799
- mapHighsStatus: () => K,
800
- mapHighsTerminationStatus: () => G,
820
+ mapHighsStatus: () => U,
821
+ mapHighsTerminationStatus: () => H,
801
822
  probeWasmUrl: () => M,
802
- registerHighsSolver: () => Y,
803
- registerMockSolver: () => Ae,
823
+ registerHighsSolver: () => K,
824
+ registerMockSolver: () => Be,
804
825
  registerSolver: () => T,
805
- resolveBrowserWasmUrl: () => I,
826
+ resolveBrowserWasmUrl: () => F,
806
827
  setDefaultSolver: () => _,
807
- setHighsWasmUrl: () => R,
808
- solveLp: () => W,
828
+ setHighsWasmUrl: () => L,
829
+ solveLp: () => V,
809
830
  solveLpWithHighs: () => N
810
831
  });
811
- z(je, Oe);
832
+ R(Ve, Re);
812
833
  //#endregion
813
834
  //#region src/modeler/solution-validator.ts
814
- function Me(e, t) {
835
+ function He(e, t) {
815
836
  if (e === void 0) return 1e-6;
816
837
  if (typeof e != "number" || !Number.isFinite(e) || e < 0) throw Error(`Invalid ${t}: expected a finite non-negative number, received ${String(e)}.`);
817
838
  return e;
818
839
  }
819
- function Ne(e, t = {}) {
820
- let r = Me(t.feasibilityTolerance, "feasibilityTolerance"), i = Me(t.integralityTolerance, "integralityTolerance"), a = t.evaluateLogicalConstraints === void 0 || !!t.evaluateLogicalConstraints, s = t.values !== void 0 && t.values !== null;
840
+ function Ue(e, t = {}) {
841
+ let r = He(t.feasibilityTolerance, "feasibilityTolerance"), i = He(t.integralityTolerance, "integralityTolerance"), a = t.evaluateLogicalConstraints === void 0 || !!t.evaluateLogicalConstraints, s = t.values !== void 0 && t.values !== null;
821
842
  if (t.values !== void 0 && (typeof t.values != "object" || t.values === null || Array.isArray(t.values))) throw Error("Invalid values option: expected a plain object mapping variable names to values.");
822
843
  let l = t.values, u = [], d = Object.create(null), f = [], p = [], m = 0, h = (e) => {
823
844
  typeof e == "number" && !Number.isNaN(e) && e > m && (m = e);
@@ -1191,10 +1212,10 @@ function Ne(e, t = {}) {
1191
1212
  }
1192
1213
  //#endregion
1193
1214
  //#region src/modeler/big-m.ts
1194
- function Pe(e, t) {
1215
+ function We(e, t) {
1195
1216
  if (typeof e != "number" || !Number.isFinite(e) || e <= 0) throw Error(`Invalid Big-M value for indicator constraint "${t}": expected a finite positive number, received ${e}.`);
1196
1217
  }
1197
- function Fe(e, t, n) {
1218
+ function Ge(e, t, n) {
1198
1219
  let r = e.constant === void 0 ? 0 : e.constant;
1199
1220
  if (!Number.isFinite(t) || !Number.isFinite(r)) throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": constraint contains non-finite constant (${r}) or right-hand side (${t}).`);
1200
1221
  let i = t - r;
@@ -1205,8 +1226,8 @@ function Fe(e, t, n) {
1205
1226
  }
1206
1227
  return i;
1207
1228
  }
1208
- function Ie(e, t, n) {
1209
- let r = Fe(e, t, n), i = 0;
1229
+ function q(e, t, n) {
1230
+ let r = Ge(e, t, n), i = 0;
1210
1231
  for (let [t, r] of e.terms) {
1211
1232
  if (r === 0) continue;
1212
1233
  let e;
@@ -1226,8 +1247,8 @@ function Ie(e, t, n) {
1226
1247
  if (!Number.isFinite(o) || !Number.isFinite(r + o)) throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": derived Big-M (${o}) or shifted right-hand side overflows finite floating-point range. Please rescale coefficients/bounds or specify a finite { M } explicitly.`);
1227
1248
  return o;
1228
1249
  }
1229
- function Le(e, t, n) {
1230
- let r = Fe(e, t, n), i = 0;
1250
+ function J(e, t, n) {
1251
+ let r = Ge(e, t, n), i = 0;
1231
1252
  for (let [t, r] of e.terms) {
1232
1253
  if (r === 0) continue;
1233
1254
  let e;
@@ -1247,10 +1268,10 @@ function Le(e, t, n) {
1247
1268
  if (!Number.isFinite(o) || !Number.isFinite(r - o)) throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": derived Big-M (${o}) or shifted right-hand side overflows finite floating-point range. Please rescale coefficients/bounds or specify a finite { M } explicitly.`);
1248
1269
  return o;
1249
1270
  }
1250
- function X(e, t, n, r, i, a, o) {
1271
+ function Y(e, t, n, r, i, a, o) {
1251
1272
  if (!(e instanceof b && (e.type === "Binary" || e.type === "Integer" && e.lb === 0 && e.ub === 1))) throw Error(`Indicator variable "${e?.name ?? String(e)}" must be a Binary variable (or Integer variable with bounds [0, 1]), received "${e?.type ?? typeof e}" with bounds [${e?.lb}, ${e?.ub}].`);
1252
1273
  if (!Number.isFinite(e.lb) || !Number.isFinite(e.ub) || e.lb < 0 || e.ub > 1 || e.lb > e.ub) throw Error(`Binary indicator variable "${e.name}" has invalid bounds [${e.lb}, ${e.ub}]. Binary variables must stay within [0, 1] with lb <= ub.`);
1253
- let s = Fe(t, r, o);
1274
+ let s = Ge(t, r, o);
1254
1275
  if (i !== 0 && i !== 1) throw Error(`Invalid activeValue: ${i}. Indicator activation value must be 0 or 1.`);
1255
1276
  if (n !== "<=" && n !== ">=") throw Error(`Invalid indicator sense for "${o}": expected "<=" or ">=", received "${String(n)}".`);
1256
1277
  if (!Number.isFinite(a) || a < 0) throw Error(`Invalid Big-M value for indicator constraint "${o}": expected a finite non-negative number, received ${a}.`);
@@ -1266,6 +1287,527 @@ function X(e, t, n, r, i, a, o) {
1266
1287
  };
1267
1288
  }
1268
1289
  //#endregion
1290
+ //#region src/modeler/linearizer.ts
1291
+ function X(e, t = 0) {
1292
+ return new j(new Map(e), t);
1293
+ }
1294
+ function Ke(e, t, r, i) {
1295
+ let a = [...e], s = [...r], l = /* @__PURE__ */ new Map(), u = /* @__PURE__ */ new Map();
1296
+ for (let e of r) u.set(e, e.name);
1297
+ let d = new Set(e.map((e) => e.name)), f = 0;
1298
+ function p(e) {
1299
+ let t;
1300
+ do
1301
+ t = `__washi_${e}_${++f}`;
1302
+ while (d.has(t));
1303
+ return d.add(t), t;
1304
+ }
1305
+ for (let e of t) {
1306
+ let t = e.name;
1307
+ d.has(t) ? t = p(`bool_${e.name}`) : d.add(t);
1308
+ let n = new b({
1309
+ name: t,
1310
+ type: "Binary",
1311
+ lb: 0,
1312
+ ub: 1
1313
+ });
1314
+ l.set(e, n), a.push(n);
1315
+ }
1316
+ function m(e, t) {
1317
+ if (e instanceof qe) return e.wrappedVar;
1318
+ if (e instanceof o) {
1319
+ let n = l.get(e);
1320
+ if (!n) throw Error(`Unregistered BoolVar "${e.name}" in logical constraint "${t}".`);
1321
+ return n;
1322
+ }
1323
+ let n = new b({
1324
+ name: p("expr"),
1325
+ type: "Binary",
1326
+ lb: 0,
1327
+ ub: 1
1328
+ });
1329
+ return a.push(n), g(n, e, t), n;
1330
+ }
1331
+ function h(e, t, n, r) {
1332
+ let i = new c(X([
1333
+ [e, 1],
1334
+ [t, -1],
1335
+ [n, -1]
1336
+ ], 0), "<=", 0, `${r}_xor_1`), a = new c(X([
1337
+ [e, 1],
1338
+ [t, -1],
1339
+ [n, 1]
1340
+ ], 0), ">=", 0, `${r}_xor_2`), o = new c(X([
1341
+ [e, 1],
1342
+ [n, -1],
1343
+ [t, 1]
1344
+ ], 0), ">=", 0, `${r}_xor_3`), l = new c(X([
1345
+ [e, 1],
1346
+ [t, 1],
1347
+ [n, 1]
1348
+ ], 0), "<=", 2, `${r}_xor_4`);
1349
+ s.push(i, a, o, l), u.set(i, r), u.set(a, r), u.set(o, r), u.set(l, r);
1350
+ }
1351
+ function g(e, t, r) {
1352
+ if (t instanceof o) {
1353
+ let n = l.get(t), i = new c(X([[e, 1], [n, -1]], 0), "==", 0, `${r}_equiv`);
1354
+ s.push(i), u.set(i, r);
1355
+ return;
1356
+ }
1357
+ if (t instanceof n) {
1358
+ if (t.op === "not") {
1359
+ let n = m(t.children[0], r), i = new c(X([[e, 1], [n, 1]], 0), "==", 1, `${r}_not`);
1360
+ s.push(i), u.set(i, r);
1361
+ return;
1362
+ }
1363
+ if (t.op === "and") {
1364
+ let n = t.children.map((e) => m(e, r));
1365
+ for (let t = 0; t < n.length; t++) {
1366
+ let i = new c(X([[e, 1], [n[t], -1]], 0), "<=", 0, `${r}_and_ub_${t}`);
1367
+ s.push(i), u.set(i, r);
1368
+ }
1369
+ let i = [[e, 1], ...n.map((e) => [e, -1])], a = new c(X(i, 0), ">=", 1 - n.length, `${r}_and_lb`);
1370
+ s.push(a), u.set(a, r);
1371
+ return;
1372
+ }
1373
+ if (t.op === "or") {
1374
+ let n = t.children.map((e) => m(e, r));
1375
+ for (let t = 0; t < n.length; t++) {
1376
+ let i = new c(X([[e, 1], [n[t], -1]], 0), ">=", 0, `${r}_or_lb_${t}`);
1377
+ s.push(i), u.set(i, r);
1378
+ }
1379
+ let i = [[e, 1], ...n.map((e) => [e, -1])], a = new c(X(i, 0), "<=", 0, `${r}_or_ub`);
1380
+ s.push(a), u.set(a, r);
1381
+ return;
1382
+ }
1383
+ if (t.op === "implies") {
1384
+ let n = m(t.children[0], r), i = m(t.children[1], r), a = new c(X([
1385
+ [e, 1],
1386
+ [i, -1],
1387
+ [n, 1]
1388
+ ], 0), ">=", 0, `${r}_imp_1`), o = new c(X([
1389
+ [e, 1],
1390
+ [n, 1],
1391
+ [i, -1]
1392
+ ], 0), "<=", 1, `${r}_imp_2`);
1393
+ s.push(a, o), u.set(a, r), u.set(o, r);
1394
+ return;
1395
+ }
1396
+ if (t.op === "xor") {
1397
+ if (t.children.length === 0) {
1398
+ let t = new c(X([[e, 1]], 0), "==", 0, `${r}_xor_empty`);
1399
+ s.push(t), u.set(t, r);
1400
+ return;
1401
+ }
1402
+ if (t.children.length === 1) {
1403
+ let n = m(t.children[0], r), i = new c(X([[e, 1], [n, -1]], 0), "==", 0, `${r}_xor_single`);
1404
+ s.push(i), u.set(i, r);
1405
+ return;
1406
+ }
1407
+ let n = t.children.map((e) => m(e, r)), i = n[0];
1408
+ for (let e = 1; e < n.length - 1; e++) {
1409
+ let t = new b({
1410
+ name: p(`xor_fold_${e}`),
1411
+ type: "Binary",
1412
+ lb: 0,
1413
+ ub: 1
1414
+ });
1415
+ a.push(t), h(t, i, n[e], `${r}_xor_fold_${e}`), i = t;
1416
+ }
1417
+ h(e, i, n[n.length - 1], r);
1418
+ return;
1419
+ }
1420
+ }
1421
+ throw Error(`Unsupported logical element in equivalence linearization: ${t}`);
1422
+ }
1423
+ for (let e of i) {
1424
+ let t = e.name, n = e.expr;
1425
+ _(n, t);
1426
+ }
1427
+ function _(e, t) {
1428
+ if (e instanceof o) {
1429
+ let n = l.get(e), r = new c(X([[n, 1]], 0), ">=", 1, t);
1430
+ s.push(r), u.set(r, t);
1431
+ return;
1432
+ }
1433
+ if (e instanceof n) {
1434
+ if (e.op === "not") {
1435
+ let n = e.children[0];
1436
+ if (n instanceof o) {
1437
+ let e = l.get(n), r = new c(X([[e, 1]], 0), "<=", 0, t);
1438
+ s.push(r), u.set(r, t);
1439
+ return;
1440
+ }
1441
+ let r = m(n, t), i = new c(X([[r, 1]], 0), "<=", 0, t);
1442
+ s.push(i), u.set(i, t);
1443
+ return;
1444
+ }
1445
+ if (e.op === "and") {
1446
+ for (let n = 0; n < e.children.length; n++) _(e.children[n], `${t}_and_${n}`);
1447
+ return;
1448
+ }
1449
+ if (e.op === "or") {
1450
+ if (e.children.every((e) => e instanceof o || e instanceof n)) {
1451
+ let n = e.children.map((e) => m(e, t)).map((e) => [e, 1]), r = new c(X(n, 0), ">=", 1, t);
1452
+ s.push(r), u.set(r, t);
1453
+ return;
1454
+ }
1455
+ let r = [];
1456
+ for (let n = 0; n < e.children.length; n++) {
1457
+ let i = e.children[n], o = new b({
1458
+ name: p(`or_branch_${n}`),
1459
+ type: "Binary",
1460
+ lb: 0,
1461
+ ub: 1
1462
+ });
1463
+ if (a.push(o), r.push(o), i instanceof c) v(o, i, 1, `${t}_or_branch_${n}`, t);
1464
+ else {
1465
+ let e = m(i, t), r = new c(X([[o, 1], [e, -1]], 0), "<=", 0, `${t}_or_bool_${n}`);
1466
+ s.push(r), u.set(r, t);
1467
+ }
1468
+ }
1469
+ let i = r.map((e) => [e, 1]), l = new c(X(i, 0), ">=", 1, t);
1470
+ s.push(l), u.set(l, t);
1471
+ return;
1472
+ }
1473
+ if (e.op === "xor") {
1474
+ if (e.children.length === 0) {
1475
+ let e = new b({
1476
+ name: p("unsat"),
1477
+ type: "Binary",
1478
+ lb: 0,
1479
+ ub: 0
1480
+ });
1481
+ a.push(e);
1482
+ let n = new c(X([[e, 1]], 0), ">=", 1, t);
1483
+ s.push(n), u.set(n, t);
1484
+ return;
1485
+ }
1486
+ if (e.children.length === 1) {
1487
+ _(e.children[0], t);
1488
+ return;
1489
+ }
1490
+ let n = e.children.map((e) => m(e, t));
1491
+ if (n.length === 2) {
1492
+ let e = new c(X([[n[0], 1], [n[1], 1]], 0), "==", 1, t);
1493
+ s.push(e), u.set(e, t);
1494
+ return;
1495
+ }
1496
+ let r = n[0];
1497
+ for (let e = 1; e < n.length - 1; e++) {
1498
+ let i = new b({
1499
+ name: p(`xor_fold_${e}`),
1500
+ type: "Binary",
1501
+ lb: 0,
1502
+ ub: 1
1503
+ });
1504
+ a.push(i), h(i, r, n[e], `${t}_xor_fold_${e}`), r = i;
1505
+ }
1506
+ let i = n[n.length - 1], o = new c(X([[r, 1], [i, 1]], 0), "==", 1, t);
1507
+ s.push(o), u.set(o, t);
1508
+ return;
1509
+ }
1510
+ if (e.op === "implies") {
1511
+ let [r, i] = e.children;
1512
+ if (r instanceof c && r.lhs.terms.size === 1 && r.lhs.constant === 0) {
1513
+ let [[e, n]] = Array.from(r.lhs.terms.entries());
1514
+ if ((e.type === "Binary" || e.type === "Integer" && e.lb === 0 && e.ub === 1) && n === 1) {
1515
+ let n = null;
1516
+ if (r.sense === "==" && r.rhs === 1 ? n = 1 : r.sense === "==" && r.rhs === 0 || r.sense === "<=" && r.rhs === 0 ? n = 0 : r.sense === ">=" && r.rhs === 1 && (n = 1), n !== null && i instanceof c) {
1517
+ v(e, i, n, t, t);
1518
+ return;
1519
+ }
1520
+ }
1521
+ }
1522
+ let d;
1523
+ if (r instanceof c ? (d = new b({
1524
+ name: p("ante"),
1525
+ type: "Binary",
1526
+ lb: 0,
1527
+ ub: 1
1528
+ }), a.push(d), v(d, r, 1, `${t}_ante_active`, t)) : d = m(r, t), i instanceof c) {
1529
+ v(d, i, 1, t, t);
1530
+ return;
1531
+ }
1532
+ if (i instanceof o) {
1533
+ let e = l.get(i), n = new c(X([[e, 1], [d, -1]], 0), ">=", 0, t);
1534
+ s.push(n), u.set(n, t);
1535
+ return;
1536
+ }
1537
+ if (i instanceof n) {
1538
+ if (i.op === "and") {
1539
+ for (let e = 0; e < i.children.length; e++) _(new n("implies", [d instanceof b ? new qe(d) : r, i.children[e]]), `${t}_and_${e}`);
1540
+ return;
1541
+ }
1542
+ if (i.op === "not") {
1543
+ let e = i.children[0], n = m(e, t), r = new c(X([[d, 1], [n, 1]], 0), "<=", 1, t);
1544
+ s.push(r), u.set(r, t);
1545
+ return;
1546
+ }
1547
+ let e = m(i, t), a = new c(X([[e, 1], [d, -1]], 0), ">=", 0, t);
1548
+ s.push(a), u.set(a, t);
1549
+ return;
1550
+ }
1551
+ }
1552
+ }
1553
+ throw Error(`Unsupported top-level logical constraint "${t}": ${e}`);
1554
+ }
1555
+ function v(e, t, n, r, i) {
1556
+ let { lhs: a, sense: o, rhs: l } = t;
1557
+ if (o === "<=" || o === ">=") {
1558
+ let t = Y(e, a, o, l, n, o === "<=" ? q(a, l, r) : J(a, l, r), r), d = new c(t.lhs, o, t.rhs, r);
1559
+ s.push(d), u.set(d, i);
1560
+ } else {
1561
+ let t = q(a, l, `${r}_le`), o = J(a, l, `${r}_ge`), d = Y(e, a, "<=", l, n, t, `${r}_le`), f = Y(e, a, ">=", l, n, o, `${r}_ge`), p = new c(d.lhs, "<=", d.rhs, `${r}_le`), m = new c(f.lhs, ">=", f.rhs, `${r}_ge`);
1562
+ s.push(p, m), u.set(p, i), u.set(m, i);
1563
+ }
1564
+ }
1565
+ return {
1566
+ variables: a,
1567
+ constraints: s,
1568
+ boolVarToBinary: l,
1569
+ constraintToOriginalName: u
1570
+ };
1571
+ }
1572
+ var qe = class extends o {
1573
+ wrappedVar;
1574
+ constructor(e) {
1575
+ super(e.name), this.wrappedVar = e;
1576
+ }
1577
+ };
1578
+ //#endregion
1579
+ //#region src/decomposition/column-generation.ts
1580
+ async function Je(e) {
1581
+ let t = e.master;
1582
+ if (!t) throw Error("A master Model must be provided for solveColumnGeneration.");
1583
+ let { pricing: n, maxIterations: r = 100, reducedCostTolerance: i = 1e-6, finalizeAsMIP: a = !0, solver: o, solverOptions: s, onIteration: c } = e, l = t.sense.toLowerCase() === "maximize", u = n;
1584
+ if (!u) throw Error("The 'pricing' callback must be provided in ColumnGenerationOptions.");
1585
+ let d = [], f = null, p = 0, m = t.status;
1586
+ for (let e = 1; e <= r; e++) {
1587
+ p = e;
1588
+ let n = await t.relax(o, s);
1589
+ if (m = n, n !== "Optimal" && n !== "Feasible" || !t.solution) break;
1590
+ f = t.objectiveValue;
1591
+ let r = t.solution, a = r.duals || {}, h = (e) => typeof e == "string" ? a[e] ?? 0 : e.dual ?? (e.name ? a[e.name] ?? 0 : 0), g = await u({
1592
+ iteration: e,
1593
+ duals: a,
1594
+ getDual: h,
1595
+ masterSolution: r,
1596
+ reducedCostTolerance: i,
1597
+ master: t
1598
+ }), _ = [];
1599
+ g && (Array.isArray(g) ? _.push(...g) : _.push(g));
1600
+ let v = [];
1601
+ for (let e of _) {
1602
+ let t = e.reducedCost;
1603
+ if (typeof t != "number" || !Number.isFinite(t)) {
1604
+ let n = 0, r = e.coefficients;
1605
+ if (Array.isArray(r)) for (let e of r) Array.isArray(e) ? n += e[1] * h(e[0]) : e && typeof e == "object" && (n += e.coeff * h(e.constraint));
1606
+ else if (r instanceof Map) for (let [e, t] of r.entries()) n += t * h(e);
1607
+ else if (r && typeof r == "object") for (let [e, t] of Object.entries(r)) n += t * h(e);
1608
+ t = e.cost - n;
1609
+ }
1610
+ (l ? t > i : t < -i) && v.push(e);
1611
+ }
1612
+ if (c && c({
1613
+ iteration: e,
1614
+ relaxationObjective: f,
1615
+ columnsAdded: d.length + v.length,
1616
+ proposedColumns: v
1617
+ }), v.length === 0) break;
1618
+ for (let e of v) {
1619
+ let n = t.addColumn({
1620
+ name: e.name,
1621
+ type: e.type || "Continuous",
1622
+ lb: e.lb,
1623
+ ub: e.ub,
1624
+ cost: e.cost,
1625
+ coefficients: e.coefficients
1626
+ });
1627
+ d.push({
1628
+ variable: n,
1629
+ proposal: e
1630
+ });
1631
+ }
1632
+ }
1633
+ let h = f;
1634
+ a && (m === "Optimal" || m === "Feasible") && (m = await t.solve(o, s), h = t.objectiveValue);
1635
+ let g = {};
1636
+ for (let e of t.variables) e.value !== null && (g[e.name] = e.value);
1637
+ let _ = {
1638
+ status: m,
1639
+ objectiveValue: h,
1640
+ relaxationObjectiveValue: f,
1641
+ iterations: p,
1642
+ columnsAdded: d.length,
1643
+ generatedColumns: d,
1644
+ master: t,
1645
+ values: g
1646
+ };
1647
+ return t.decomposition = _, _;
1648
+ }
1649
+ //#endregion
1650
+ //#region src/modeler/objective.ts
1651
+ function Ye(e, t) {
1652
+ let n = e;
1653
+ if (n instanceof c || typeof n == "object" && n && "sense" in n && "lhs" in n && "rhs" in n) throw Error(`Cannot use a Constraint as an objective in ${t}(). Use m.constraint(expr\`... <= ...\`) for constraints, or supply an unconstrained arithmetic expression to ${t}(), e.g. m.objective(${t}(expr\`30 * \${x}\`)).`);
1654
+ if (typeof n == "string" && /(<=|>=|==|=<|=>|=)/.test(n)) throw Error(`Cannot use a comparison constraint as an objective in ${t}(). Use m.constraint(expr\`... <= ...\`) for constraints, or supply an unconstrained arithmetic expression to ${t}(), e.g. m.objective(${t}(expr\`30 * \${x}\`)).`);
1655
+ if (typeof n == "number") {
1656
+ if (!Number.isFinite(n)) throw Error(`Invalid non-finite objective constant "${n}" passed to ${t}().`);
1657
+ return n;
1658
+ }
1659
+ if (typeof n == "string" || n instanceof j || n instanceof A || n instanceof b || typeof n == "object" && n && ("terms" in n && n.terms instanceof Map && typeof n.constant == "number" || "quadTerms" in n && n.quadTerms instanceof Map && "linearTerms" in n && n.linearTerms instanceof Map && typeof n.constant == "number" || "id" in n && "name" in n && "lb" in n && "ub" in n)) return n;
1660
+ throw Error(`Invalid expression passed to ${t}(): expected a finite number, Var, LinExpr, QuadExpr, or arithmetic expression string.`);
1661
+ }
1662
+ function Xe(e) {
1663
+ return {
1664
+ expr: Ye(e, "maximize"),
1665
+ sense: "Maximize"
1666
+ };
1667
+ }
1668
+ function Ze(e) {
1669
+ return {
1670
+ expr: Ye(e, "minimize"),
1671
+ sense: "Minimize"
1672
+ };
1673
+ }
1674
+ //#endregion
1675
+ //#region src/decomposition/benders.ts
1676
+ function Qe(e) {
1677
+ return !!(e && typeof e == "object" && "constraints" in e && "variables" in e && typeof e.solve == "function");
1678
+ }
1679
+ async function $e(e, t, n, r, i, a, o, s, l = 1) {
1680
+ let u = [];
1681
+ for (let r = 0; r < t.length; r++) {
1682
+ let a = t[r], o = a.lhs, s = a.sense, d = a.rhs - (o.constant || 0), f = [], p = [], m = 0;
1683
+ for (let [e, t] of o.terms.entries()) if (e.ownerModel === n || n.getVarByName(e.name) !== void 0) {
1684
+ p.push([e, t]);
1685
+ let n = i[e.name] ?? 0;
1686
+ m += t * n;
1687
+ } else f.push([e, t]);
1688
+ let h = d - m, g = new j();
1689
+ for (let [e, t] of f) g.addTerm(e, t);
1690
+ let _ = `__benders_link_${l}_${r}`, v = new c(g, s, h, _);
1691
+ e.constraint(v), u.push({
1692
+ origConstraint: a,
1693
+ subConstr: v,
1694
+ masterTerms: p,
1695
+ baseRhs: d
1696
+ });
1697
+ }
1698
+ let d = await e.solve(o, {
1699
+ ...s,
1700
+ relax: !0
1701
+ });
1702
+ if (d !== "Optimal" && d !== "Feasible") return null;
1703
+ let f = e.objectiveValue ?? 0, p = i[r.name] ?? 0, m = 1e-4;
1704
+ if (!(a ? p < f - m : p > f + m)) return null;
1705
+ let h = 0, g = /* @__PURE__ */ new Map(), _ = new Set(u.map((e) => e.subConstr.name));
1706
+ for (let t of e.constraints) {
1707
+ if (_.has(t.name)) continue;
1708
+ let n = e.solution?.duals[t.name] ?? t.dual ?? 0;
1709
+ if (Math.abs(n) > 1e-12) {
1710
+ let e = t.rhs - (t.lhs.constant || 0);
1711
+ h += n * e;
1712
+ }
1713
+ }
1714
+ for (let t of u) {
1715
+ let n = e.solution?.duals[t.subConstr.name] ?? t.subConstr.dual ?? 0;
1716
+ if (Math.abs(n) > 1e-12) {
1717
+ h += n * t.baseRhs;
1718
+ for (let [e, r] of t.masterTerms) {
1719
+ let t = g.get(e) ?? 0;
1720
+ g.set(e, t + n * r);
1721
+ }
1722
+ }
1723
+ }
1724
+ let v = new j();
1725
+ v.addTerm(r, 1);
1726
+ for (let [e, t] of g.entries()) Math.abs(t) > 1e-12 && v.addTerm(e, t);
1727
+ let y = new c(v, a ? ">=" : "<=", h, `__benders_opt_cut_${l}`), b = (n.objectiveValue ?? 0) - p + f;
1728
+ return {
1729
+ kind: "optimality",
1730
+ constraint: y,
1731
+ name: y.name,
1732
+ subproblemObjective: b
1733
+ };
1734
+ }
1735
+ async function et(e) {
1736
+ let t = e.master;
1737
+ if (!t) throw Error("A master Model must be provided for solveBenders.");
1738
+ let { subproblem: n, maxIterations: r = 100, gapTolerance: i = 1e-4, solver: a, solverOptions: o, onIteration: s } = e, c;
1739
+ e.theta && (c = typeof e.theta == "string" ? t.getVarByName(e.theta) : e.theta), c ||= t.variables.find((e) => e.name === "theta" || e.name === "__benders_theta");
1740
+ let l = 0, u = 0, d = t.status, f, p, m, h = {}, g = null;
1741
+ for (let e = 1; e <= r; e++) {
1742
+ u = e;
1743
+ let r = await t.solve(a, o);
1744
+ if (d = r, r !== "Optimal" && r !== "Feasible") break;
1745
+ let _ = t.objectiveValue, v = t.sense.toLowerCase() === "minimize";
1746
+ v ? f = _ === null ? f : _ : p = _ === null ? p : _;
1747
+ let y = {};
1748
+ for (let e of t.variables) e.value !== null && (y[e.name] = e.value);
1749
+ let b = await n({
1750
+ iteration: e,
1751
+ masterValues: y,
1752
+ getMasterValue: (e) => typeof e == "string" ? y[e] ?? 0 : e.value ?? (e.name ? y[e.name] ?? 0 : 0),
1753
+ masterObjective: _,
1754
+ lowerBound: f,
1755
+ upperBound: p,
1756
+ master: t
1757
+ }), x = [];
1758
+ if (b) {
1759
+ if (Qe(b)) {
1760
+ let n = b, r = n.linkingConstraints;
1761
+ c || (c = t.continuous("__benders_theta", { lb: 0 }), v ? t.objective(Ze(t.objectiveExpr.add(c))) : t.objective(Xe(t.objectiveExpr.sub(c))));
1762
+ let i = await $e(n, r, t, c, y, v, a, o, e);
1763
+ i && x.push(i);
1764
+ } else Array.isArray(b) ? x.push(...b) : x.push(b);
1765
+ }
1766
+ for (let e of x) if (typeof e.subproblemObjective == "number" && Number.isFinite(e.subproblemObjective)) {
1767
+ if (v) {
1768
+ let t = e.subproblemObjective;
1769
+ (p === void 0 || t < p) && (p = t, g = t, h = { ...y });
1770
+ } else {
1771
+ let t = e.subproblemObjective;
1772
+ (f === void 0 || t > f) && (f = t, g = t, h = { ...y });
1773
+ }
1774
+ }
1775
+ if (f !== void 0 && p !== void 0) {
1776
+ let e = Math.abs(p) + 1e-10;
1777
+ m = Math.abs(p - f) / e;
1778
+ }
1779
+ if (s && s({
1780
+ iteration: e,
1781
+ masterObjective: _,
1782
+ lowerBound: f,
1783
+ upperBound: p,
1784
+ cutsAdded: l + x.length,
1785
+ proposedCuts: x
1786
+ }), x.length === 0) {
1787
+ g = _, h = { ...y };
1788
+ break;
1789
+ }
1790
+ if (m !== void 0 && m <= i) break;
1791
+ for (let e of x) t.constraint(e.constraint, e.name), l++;
1792
+ }
1793
+ let _ = Object.keys(h).length > 0 ? h : (() => {
1794
+ let e = {};
1795
+ for (let n of t.variables) n.value !== null && (e[n.name] = n.value);
1796
+ return e;
1797
+ })(), v = g === null ? t.objectiveValue : g, y = {
1798
+ status: d,
1799
+ objectiveValue: v,
1800
+ lowerBound: f,
1801
+ upperBound: p,
1802
+ gap: m,
1803
+ iterations: u,
1804
+ cutsAdded: l,
1805
+ master: t,
1806
+ values: _
1807
+ };
1808
+ return t.decomposition = y, y;
1809
+ }
1810
+ //#endregion
1269
1811
  //#region src/modeler/model.ts
1270
1812
  function Z(e) {
1271
1813
  return Array.isArray(e) || typeof e == "object" && !!e && !(e instanceof String) && typeof e[Symbol.iterator] == "function";
@@ -1273,10 +1815,13 @@ function Z(e) {
1273
1815
  function Q(e) {
1274
1816
  return typeof e == "object" && !!e && !Array.isArray(e) && !(e instanceof String) && typeof e[Symbol.iterator] != "function";
1275
1817
  }
1818
+ function tt(e) {
1819
+ return e instanceof b || typeof e == "object" && !!e && !(e instanceof r) && !(e instanceof c) && "id" in e && "name" in e && "lb" in e && "ub" in e && !("terms" in e) && !("quadTerms" in e) && !("sense" in e);
1820
+ }
1276
1821
  function $(e, t) {
1277
1822
  if (!Number.isInteger(e) || e < 0) throw Error(`Invalid count (${e}) for ${t} variable creation: count must be a non-negative integer.`);
1278
1823
  }
1279
- var Re = class {
1824
+ var nt = class {
1280
1825
  name;
1281
1826
  _sense;
1282
1827
  _objectiveExpr;
@@ -1285,6 +1830,7 @@ var Re = class {
1285
1830
  boolVars = [];
1286
1831
  logicalConstraints = [];
1287
1832
  unsatCore = void 0;
1833
+ _conflicts = void 0;
1288
1834
  values = /* @__PURE__ */ new Map();
1289
1835
  varMapByName = /* @__PURE__ */ new Map();
1290
1836
  varPrefixCounters = /* @__PURE__ */ new Map();
@@ -1305,6 +1851,8 @@ var Re = class {
1305
1851
  runTime = 0;
1306
1852
  solution = null;
1307
1853
  solver = null;
1854
+ decomposition;
1855
+ _linkingConstraints;
1308
1856
  hasSolutionState = !1;
1309
1857
  modelRevision = 0;
1310
1858
  activeOperationId = 0;
@@ -1316,13 +1864,13 @@ var Re = class {
1316
1864
  n = typeof e == "string" ? {
1317
1865
  ...t,
1318
1866
  name: e
1319
- } : e, this.name = n.name || "OptimizationModel", this._sense = le(n.sense), this._objectiveExpr = new j(), n.solver && (this.solver = D(n.solver));
1867
+ } : e, this.name = n.name || "OptimizationModel", this._sense = _e(n.sense), this._objectiveExpr = new j(), n.solver && (this.solver = D(n.solver));
1320
1868
  }
1321
1869
  get sense() {
1322
1870
  return this._sense;
1323
1871
  }
1324
1872
  set sense(e) {
1325
- let t = le(e);
1873
+ let t = _e(e);
1326
1874
  this._sense !== t && (this._sense = t, this.recordModelMutation());
1327
1875
  }
1328
1876
  get objectiveExpr() {
@@ -1332,7 +1880,10 @@ var Re = class {
1332
1880
  this.applyObjective(e);
1333
1881
  }
1334
1882
  get conflicts() {
1335
- return this.unsatCore;
1883
+ return this._conflicts ?? this.unsatCore;
1884
+ }
1885
+ set conflicts(e) {
1886
+ this._conflicts = e;
1336
1887
  }
1337
1888
  get numVars() {
1338
1889
  return this.variables.length;
@@ -1342,7 +1893,7 @@ var Re = class {
1342
1893
  }
1343
1894
  clearSolutionFields() {
1344
1895
  if (this.hasSolutionState || this.status !== "NotSolved" || this.terminationStatus !== "NotSolved" || this.hasPrimalSolution || this.solution !== null || this.unsatCore !== void 0) {
1345
- this.hasSolutionState = !1, this.status = "NotSolved", this.terminationStatus = "NotSolved", this.hasPrimalSolution = !1, this.objectiveValue = null, this.objectiveBound = void 0, this.relGap = void 0, this.mipGap = void 0, this.absGap = void 0, this.solution = null, this.runTime = 0, this.unsatCore = void 0, this.values.clear();
1896
+ this.hasSolutionState = !1, this.status = "NotSolved", this.terminationStatus = "NotSolved", this.hasPrimalSolution = !1, this.objectiveValue = null, this.objectiveBound = void 0, this.relGap = void 0, this.mipGap = void 0, this.absGap = void 0, this.solution = null, this.runTime = 0, this.unsatCore = void 0, this._conflicts = void 0, this.values.clear();
1346
1897
  for (let e of this.variables) e.value = null, e.reducedCost = null;
1347
1898
  for (let e of this.boolVars) e.value = null;
1348
1899
  for (let e of this.constraints) e.dual = null, e.slack = null;
@@ -1467,6 +2018,37 @@ var Re = class {
1467
2018
  continuous(e, t, n) {
1468
2019
  return this.createDomainVars("Continuous", e, t, n);
1469
2020
  }
2021
+ addColumn(e) {
2022
+ let t = e.type || "Continuous", n = this.addVar({
2023
+ name: e.name,
2024
+ type: t,
2025
+ lb: e.lb,
2026
+ ub: e.ub
2027
+ });
2028
+ if (typeof e.cost == "number" && e.cost !== 0 && (this._objectiveExpr = this._objectiveExpr.add(n.mul(e.cost)), this.recordModelMutation()), e.coefficients) {
2029
+ if (Array.isArray(e.coefficients)) {
2030
+ for (let t of e.coefficients) if (Array.isArray(t)) {
2031
+ let [e, r] = t, i = typeof e == "string" ? this.getConstraintByName(e) : e;
2032
+ if (!i) throw Error(`Constraint '${String(e)}' not found in model when adding column`);
2033
+ i.addTerm(n, r);
2034
+ } else if (typeof t == "object" && t) {
2035
+ let e = typeof t.constraint == "string" ? this.getConstraintByName(t.constraint) : t.constraint;
2036
+ if (!e) throw Error(`Constraint '${String(t.constraint)}' not found in model when adding column`);
2037
+ e.addTerm(n, t.coeff);
2038
+ }
2039
+ } else if (e.coefficients instanceof Map) for (let [t, r] of e.coefficients.entries()) {
2040
+ let e = typeof t == "string" ? this.getConstraintByName(t) : t;
2041
+ if (!e) throw Error(`Constraint '${String(t)}' not found in model when adding column`);
2042
+ e.addTerm(n, r);
2043
+ }
2044
+ else if (typeof e.coefficients == "object") for (let [t, r] of Object.entries(e.coefficients)) {
2045
+ let e = this.getConstraintByName(t);
2046
+ if (!e) throw Error(`Constraint '${t}' not found in model when adding column`);
2047
+ e.addTerm(n, r);
2048
+ }
2049
+ }
2050
+ return n;
2051
+ }
1470
2052
  bool(e, t, n) {
1471
2053
  let r = typeof e == "number", i = typeof t == "number", a = Z(e), o = Z(t);
1472
2054
  if (i || o) {
@@ -1572,12 +2154,16 @@ var Re = class {
1572
2154
  return this.logicalConstrMapByName.get(e);
1573
2155
  }
1574
2156
  objective(e) {
1575
- return e ? (this.applyObjective(e.expr, e.sense), this) : this.objectiveExpr;
2157
+ if (arguments.length === 0) return this.objectiveExpr;
2158
+ let t = e;
2159
+ if (t instanceof c || typeof t == "object" && t && "sense" in t && "lhs" in t && "rhs" in t || typeof t == "string" && /(<=|>=|==|=<|=>|=)/.test(t)) throw Error("Cannot use a Constraint as an objective. Did you mean to use m.constraint(expr`... <= ...`)? To set an objective, wrap an unconstrained expression with maximize(...) or minimize(...), e.g. m.objective(maximize(expr`30 * ${x}`)).");
2160
+ if (typeof t != "object" || !t || !("expr" in t) || !("sense" in t)) throw Error("m.objective(...) expects an ObjectiveSpec created with maximize(...) or minimize(...), e.g. m.objective(maximize(expr`30 * ${x}`)).");
2161
+ return this.applyObjective(t.expr, t.sense), this;
1576
2162
  }
1577
2163
  applyObjective(e, t) {
1578
- if (e instanceof c || typeof e == "object" && e && "sense" in e && "lhs" in e && "rhs" in e || typeof e == "string" && /(<=|>=|==|=<|=>|=)/.test(e)) throw Error(typeof e == "string" ? "Cannot use a comparison constraint as an objective. Did you mean to use m.constraint(expr`... <= ...`)?" : "Cannot use a Constraint as an objective. Did you mean to use m.constraint(expr`... <= ...`)? For objectives, supply an unconstrained expression like expr`45 * ${x} + 80 * ${y}`.");
1579
- let n = t === void 0 ? this.sense : le(t), r;
1580
- if (typeof e == "string") r = pe(e, (e) => this.getVarByName(e));
2164
+ if (e instanceof c || typeof e == "object" && e && "sense" in e && "lhs" in e && "rhs" in e || typeof e == "string" && /(<=|>=|==|=<|=>|=)/.test(e)) throw Error(typeof e == "string" ? "Cannot use a comparison constraint as an objective. Did you mean to use m.constraint(expr`... <= ...`)? To set an objective, wrap an unconstrained expression with maximize(...) or minimize(...), e.g. m.objective(maximize(expr`30 * ${x}`))." : "Cannot use a Constraint as an objective. Did you mean to use m.constraint(expr`... <= ...`)? To set an objective, wrap an unconstrained expression with maximize(...) or minimize(...), e.g. m.objective(maximize(expr`30 * ${x}`)).");
2165
+ let n = t === void 0 ? this.sense : _e(t), r;
2166
+ if (typeof e == "string") r = Se(e, (e) => this.getVarByName(e));
1581
2167
  else if (typeof e == "number") r = new j(/* @__PURE__ */ new Map(), e);
1582
2168
  else if (e instanceof A) r = e.clone();
1583
2169
  else if (e instanceof j) r = e.clone();
@@ -1598,6 +2184,7 @@ var Re = class {
1598
2184
  });
1599
2185
  if (e instanceof A || typeof e == "object" && e && "quadTerms" in e) throw Error("Constraint must contain a comparison operator (<=, >=, ==): cannot add a quadratic expression as a constraint.");
1600
2186
  if (e instanceof j || typeof e == "object" && e && "terms" in e) throw Error("Constraint must contain a comparison operator (<=, >=, ==): cannot add a linear expression without a comparison operator. Use expr`... <= ...` or .le(), .ge(), .eq().");
2187
+ if (tt(e)) throw Error(`Cannot add numeric variable "${e.name}" directly as a constraint without a comparison operator (<=, >=, ==). Numeric variables require a comparison such as expr\`\${x} <= 10\` or x.le(10), whereas propositional BoolVar variables must be created with m.bool().`);
1601
2188
  return this.addConstraint(e, t), this;
1602
2189
  }
1603
2190
  getValues(e) {
@@ -1614,6 +2201,7 @@ var Re = class {
1614
2201
  addConstraint(e, t) {
1615
2202
  if (e instanceof A || typeof e == "object" && e && "quadTerms" in e) throw Error("Constraint must contain a comparison operator (<=, >=, ==): cannot add a quadratic expression as a constraint.");
1616
2203
  if (e instanceof j || typeof e == "object" && e && "terms" in e) throw Error("Constraint must contain a comparison operator (<=, >=, ==): cannot add a linear expression without a comparison operator. Use expr`... <= ...` or .le(), .ge(), .eq().");
2204
+ if (tt(e)) throw Error(`Cannot add numeric variable "${e.name}" directly as a constraint without a comparison operator (<=, >=, ==). Numeric variables require a comparison such as expr\`\${x} <= 10\` or x.le(10), whereas propositional BoolVar variables must be created with m.bool().`);
1617
2205
  if (e instanceof r) {
1618
2206
  let n = typeof t == "string" && t.trim().length > 0 ? t.trim() : void 0;
1619
2207
  if (n !== void 0) {
@@ -1633,7 +2221,8 @@ var Re = class {
1633
2221
  };
1634
2222
  return this.logicalConstraints.push(a), this.logicalConstrMapByName.set(i, a), this.recordModelMutation(), e;
1635
2223
  }
1636
- let n = typeof e == "string" ? he(e, (e) => this.getVarByName(e), t) : e;
2224
+ let n = typeof e == "string" ? we(e, (e) => this.getVarByName(e), t) : e;
2225
+ if (typeof n != "object" || !n || !("sense" in n) || !("lhs" in n) || !("rhs" in n)) throw Error("Invalid constraint passed to m.constraint(...): expected a linear Constraint (e.g. expr`${x} <= 10` or x.le(10)), a propositional BoolVar/BoolExpr (created with m.bool()), or an array of constraints.");
1637
2226
  n.ownerModel && n.ownerModel !== this && (h(n, this.name, (e) => this.varMapByName.get(e.name) === e, n.name), p(n, this));
1638
2227
  let i = typeof t == "string" && t.trim().length > 0 ? t.trim() : n.hasExplicitName ? n.name.trim() : void 0;
1639
2228
  if (i !== void 0) {
@@ -1652,40 +2241,41 @@ var Re = class {
1652
2241
  }), this.batchDepth === 0 && (this.batchUndoActions = []), n._assignModelName(o, !0), n.ownerModel = this, this.constraints.push(n), this.constrMapByName.set(n.name, n), this.recordModelMutation(), n;
1653
2242
  }
1654
2243
  indicator(e, t, n = {}) {
1655
- if (!(e instanceof b)) throw Error("Invalid binary variable passed to indicator(). Expected a binary Var instance.");
1656
- if (!(e.type === "Binary" || e.type === "Integer" && e.lb === 0 && e.ub === 1)) throw Error(`Invalid variable "${e.name}" passed to indicator(): variable has type "${e.type}" with bounds [${e.lb}, ${e.ub}]. Indicator activation variable must be a Binary variable (or Integer variable with bounds [0, 1]).`);
1657
- if (t instanceof A) throw Error("Quadratic expressions or constraints are not supported in indicator constraints (only linear constraints are allowed).");
1658
- if (!("sense" in t) || !("lhs" in t)) throw Error("Invalid constraint expression passed to indicator(). Expression must include a comparison operator (<=, >=, ==).");
1659
- let r = t, i = n.activeValue === void 0 ? 1 : n.activeValue;
1660
- if (i !== 0 && i !== 1) throw Error(`Invalid activeValue: ${i}. Indicator activeValue must be 0 or 1.`);
2244
+ if (e instanceof r) throw Error("Invalid binary variable passed to indicator(): received a propositional BoolVar/BoolExpr, but m.indicator() requires a 0-1 numeric binary Var created with m.binary(). For general boolean logic with m.bool(), use m.constraint(implies(flag, expr`${x} <= 10`)) with the Z3 solver.");
2245
+ if (!(e instanceof b)) throw Error("Invalid binary variable passed to indicator(). Expected a 0-1 binary Var instance created with m.binary() (or use implies(flag, ...) with m.bool() and the Z3 solver for general boolean logic).");
2246
+ if (!(e.type === "Binary" || e.type === "Integer" && e.lb === 0 && e.ub === 1)) throw Error(`Invalid variable "${e.name}" passed to indicator(): variable has type "${e.type}" with bounds [${e.lb}, ${e.ub}]. Indicator activation variable must be a Binary variable created with m.binary() (or Integer variable with bounds [0, 1]).`);
2247
+ if (t instanceof A || typeof t == "object" && t && "quadTerms" in t) throw Error("Quadratic expressions or constraints are not supported in indicator constraints (only linear Constraints with <=, >=, or == such as expr`${x} <= 10` are allowed).");
2248
+ if (typeof t != "object" || !t || !("sense" in t) || !("lhs" in t) || !("rhs" in t)) throw Error("Invalid constraint expression passed to indicator(). Expression must include a comparison operator (<=, >=, ==), e.g. m.indicator(b, expr`${x} <= 10`). For general boolean logic (such as BoolVar or implies/and/or/not), use m.constraint(implies(flag, ...)) with the Z3 solver.");
2249
+ let i = t, a = n.activeValue === void 0 ? 1 : n.activeValue;
2250
+ if (a !== 0 && a !== 1) throw Error(`Invalid activeValue: ${a}. Indicator activeValue must be 0 or 1.`);
1661
2251
  if (this.varMapByName.get(e.name) !== e) throw Error(`Variable "${e.name}" passed to indicator() does not belong to model "${this.name}". All variables must belong to the model by object identity.`);
1662
- let a = typeof n.name == "string" && n.name.trim().length > 0 ? n.name.trim() : void 0, o = this.constrPrefixCounters.get("c"), { lhs: s, sense: l, rhs: u } = r, d, f, p;
1663
- if (a !== void 0) d = a, f = l === "==" ? `${d}_le` : d, p = l === "==" ? `${d}_ge` : d;
1664
- else if (r.hasExplicitName) d = `ind_${e.name}_${r.name.trim()}`, f = l === "==" ? `${d}_le` : d, p = l === "==" ? `${d}_ge` : d;
2252
+ let o = typeof n.name == "string" && n.name.trim().length > 0 ? n.name.trim() : void 0, s = this.constrPrefixCounters.get("c"), { lhs: l, sense: u, rhs: d } = i, f, p, m;
2253
+ if (o !== void 0) f = o, p = u === "==" ? `${f}_le` : f, m = u === "==" ? `${f}_ge` : f;
2254
+ else if (i.hasExplicitName) f = `ind_${e.name}_${i.name.trim()}`, p = u === "==" ? `${f}_le` : f, m = u === "==" ? `${f}_ge` : f;
1665
2255
  else do {
1666
2256
  let t = this.getNextConstrName("c");
1667
- d = `ind_${e.name}_${t}`, f = l === "==" ? `${d}_le` : d, p = l === "==" ? `${d}_ge` : d;
1668
- } while ((l === "<=" || l === "==") && (this.hasConstraintName(f) || this.hasBoolVarName(f)) || (l === ">=" || l === "==") && (this.hasConstraintName(p) || this.hasBoolVarName(p)));
1669
- let m = [];
2257
+ f = `ind_${e.name}_${t}`, p = u === "==" ? `${f}_le` : f, m = u === "==" ? `${f}_ge` : f;
2258
+ } while ((u === "<=" || u === "==") && (this.hasConstraintName(p) || this.hasBoolVarName(p)) || (u === ">=" || u === "==") && (this.hasConstraintName(m) || this.hasBoolVarName(m)));
2259
+ let g = [];
1670
2260
  try {
1671
- if ((l === "<=" || l === "==") && (this.hasConstraintName(f) || this.hasBoolVarName(f))) throw Error(this.hasBoolVarName(f) ? `Constraint name '${f}' conflicts with an existing Boolean variable in model` : `Constraint with name '${f}' already exists in model`);
1672
- if ((l === ">=" || l === "==") && (this.hasConstraintName(p) || this.hasBoolVarName(p))) throw Error(this.hasBoolVarName(p) ? `Constraint name '${p}' conflicts with an existing Boolean variable in model` : `Constraint with name '${p}' already exists in model`);
1673
- n.M !== void 0 && Pe(n.M, d);
2261
+ if ((u === "<=" || u === "==") && (this.hasConstraintName(p) || this.hasBoolVarName(p))) throw Error(this.hasBoolVarName(p) ? `Constraint name '${p}' conflicts with an existing Boolean variable in model` : `Constraint with name '${p}' already exists in model`);
2262
+ if ((u === ">=" || u === "==") && (this.hasConstraintName(m) || this.hasBoolVarName(m))) throw Error(this.hasBoolVarName(m) ? `Constraint name '${m}' conflicts with an existing Boolean variable in model` : `Constraint with name '${m}' already exists in model`);
2263
+ n.M !== void 0 && We(n.M, f);
1674
2264
  let t = (e) => this.varMapByName.get(e.name) === e;
1675
- for (let [e] of s.terms) if (!t(e)) throw Error(`Variable "${e.name}" in constraint "${d}" does not belong to model "${this.name}". All variables must belong to the model by object identity.`);
1676
- if (l === "<=" || l === "==") {
1677
- let t = X(e, s, "<=", u, i, n.M === void 0 ? Ie(s, u, f) : n.M, f);
1678
- m.push([new c(t.lhs, "<=", t.rhs, f), f]);
2265
+ for (let [e] of l.terms) if (!t(e)) throw Error(`Variable "${e.name}" in constraint "${f}" does not belong to model "${this.name}". All variables must belong to the model by object identity.`);
2266
+ if (u === "<=" || u === "==") {
2267
+ let t = Y(e, l, "<=", d, a, n.M === void 0 ? q(l, d, p) : n.M, p);
2268
+ g.push([new c(t.lhs, "<=", t.rhs, p), p]);
1679
2269
  }
1680
- if (l === ">=" || l === "==") {
1681
- let t = X(e, s, ">=", u, i, n.M === void 0 ? Le(s, u, p) : n.M, p);
1682
- m.push([new c(t.lhs, ">=", t.rhs, p), p]);
2270
+ if (u === ">=" || u === "==") {
2271
+ let t = Y(e, l, ">=", d, a, n.M === void 0 ? J(l, d, m) : n.M, m);
2272
+ g.push([new c(t.lhs, ">=", t.rhs, m), m]);
1683
2273
  }
1684
- for (let [e, n] of m) h(e, this.name, t, n);
2274
+ for (let [e, n] of g) h(e, this.name, t, n);
1685
2275
  } catch (e) {
1686
- throw o === void 0 ? this.constrPrefixCounters.delete("c") : this.constrPrefixCounters.set("c", o), e;
2276
+ throw s === void 0 ? this.constrPrefixCounters.delete("c") : this.constrPrefixCounters.set("c", s), e;
1687
2277
  }
1688
- return this.runTransactionalBatch(() => m.map(([e, t]) => this.addConstraint(e, t)));
2278
+ return this.runTransactionalBatch(() => g.map(([e, t]) => this.addConstraint(e, t)));
1689
2279
  }
1690
2280
  toLpString() {
1691
2281
  this.validateIntegrity();
@@ -1750,14 +2340,31 @@ var Re = class {
1750
2340
  activeOptions: r
1751
2341
  };
1752
2342
  }
2343
+ async relax(e, t) {
2344
+ let n = typeof e == "object" && !!e && !("solve" in e), r = n ? {
2345
+ ...e,
2346
+ relax: !0
2347
+ } : {
2348
+ ...t || {},
2349
+ relax: !0
2350
+ }, i = n ? void 0 : e;
2351
+ return i ? this.solve(i, r) : this.solve(r);
2352
+ }
1753
2353
  async solve(e, t) {
1754
2354
  let n = ++this.activeOperationId, r = this.modelRevision;
1755
2355
  this.clearSolutionFields(), this.validateIntegrity();
1756
2356
  let { activeSolver: i, activeOptions: a } = this.resolveSolverAndOptions(e, t);
1757
2357
  if (this._objectiveExpr instanceof A && this._objectiveExpr.quadTerms.size > 0 && i.capabilities?.supportsQP === !1) throw Error(`Solver "${i.name}" does not support quadratic objectives (QP). Please use a QP-capable solver such as HiGHS or Clarabel.`);
1758
- if (this.logicalConstraints.length > 0 && i.capabilities?.supportsSMT !== !0) throw Error(`Solver "${i.name}" does not support SMT / logical constraints (or, implies, not, xor). Please use an SMT-capable solver such as Z3.`);
1759
- if (this.variables.some((e) => e.initialValue !== void 0) && i.capabilities?.supportsWarmStart !== !0) throw Error(`Solver "${i.name}" does not support primal initial values (initialValue). Please use a solver with warm-start support such as HiGHS.`);
1760
- let o = {
2358
+ let o, s = null;
2359
+ if (this.logicalConstraints.length > 0 && i.capabilities?.supportsSMT !== !0 ? (s = Ke(this.variables, this.boolVars, this.constraints, this.logicalConstraints), o = {
2360
+ name: this.name,
2361
+ sense: this.sense,
2362
+ objective: this._objectiveExpr,
2363
+ constraints: s.constraints,
2364
+ variables: s.variables,
2365
+ logicalConstraints: [],
2366
+ boolVars: []
2367
+ }) : o = {
1761
2368
  name: this.name,
1762
2369
  sense: this.sense,
1763
2370
  objective: this._objectiveExpr,
@@ -1765,53 +2372,64 @@ var Re = class {
1765
2372
  variables: this.variables,
1766
2373
  logicalConstraints: this.logicalConstraints,
1767
2374
  boolVars: this.boolVars
1768
- }, s = this.wrapSolveOptions(a, r, n), c;
2375
+ }, this.variables.some((e) => e.initialValue !== void 0) && i.capabilities?.supportsWarmStart !== !0) throw Error(`Solver "${i.name}" does not support primal initial values (initialValue). Please use a solver with warm-start support such as HiGHS.`);
2376
+ let c = this.wrapSolveOptions(a, r, n), l;
1769
2377
  try {
1770
- c = await i.solve(o, s);
2378
+ l = await i.solve(o, c);
1771
2379
  } catch (e) {
1772
2380
  throw this.activeOperationId === n && this.clearSolutionFields(), e;
1773
2381
  }
1774
- this.ensureExecutionValid(r, n, "solve"), this.runTime = c.runTime ?? 0, this.status = c.status, this.terminationStatus = c.terminationStatus ?? c.status;
1775
- let l = this.hasPrimalFromResult(c);
1776
- this.hasPrimalSolution = l, this.objectiveValue = l && typeof c.objectiveValue == "number" && Number.isFinite(c.objectiveValue) ? c.objectiveValue : null, this.objectiveBound = typeof c.objectiveBound == "number" && Number.isFinite(c.objectiveBound) ? c.objectiveBound : void 0;
1777
- let u = typeof c.relGap == "number" && Number.isFinite(c.relGap) ? c.relGap : typeof c.mipGap == "number" && Number.isFinite(c.mipGap) ? c.mipGap : void 0;
1778
- this.relGap = u, this.mipGap = u, this.absGap = typeof c.absGap == "number" && Number.isFinite(c.absGap) ? c.absGap : this.objectiveValue !== null && this.objectiveBound !== void 0 ? Math.abs(this.objectiveValue - this.objectiveBound) : void 0;
1779
- let d = (e, t, n) => {
2382
+ this.ensureExecutionValid(r, n, "solve"), this.runTime = l.runTime ?? 0, this.status = l.status, this.terminationStatus = l.terminationStatus ?? l.status;
2383
+ let u = this.hasPrimalFromResult(l);
2384
+ this.hasPrimalSolution = u, this.objectiveValue = u && typeof l.objectiveValue == "number" && Number.isFinite(l.objectiveValue) ? l.objectiveValue : null, this.objectiveBound = typeof l.objectiveBound == "number" && Number.isFinite(l.objectiveBound) ? l.objectiveBound : void 0;
2385
+ let d = typeof l.relGap == "number" && Number.isFinite(l.relGap) ? l.relGap : typeof l.mipGap == "number" && Number.isFinite(l.mipGap) ? l.mipGap : void 0;
2386
+ this.relGap = d, this.mipGap = d, this.absGap = typeof l.absGap == "number" && Number.isFinite(l.absGap) ? l.absGap : this.objectiveValue !== null && this.objectiveBound !== void 0 ? Math.abs(this.objectiveValue - this.objectiveBound) : void 0;
2387
+ let f = (e, t, n) => {
1780
2388
  Object.defineProperty(e, t, {
1781
2389
  value: n,
1782
2390
  enumerable: !0,
1783
2391
  writable: !0,
1784
2392
  configurable: !0
1785
2393
  });
1786
- }, f = {}, p = {}, m = {}, h = {};
1787
- if (this.values.clear(), l && c.values) {
1788
- for (let [e, t] of Object.entries(c.values)) if (typeof t == "number" && Number.isFinite(t)) {
2394
+ }, p = {}, m = {}, h = {}, g = {};
2395
+ if (this.values.clear(), u && l.values) {
2396
+ for (let [e, t] of Object.entries(l.values)) if (typeof t == "number" && Number.isFinite(t)) {
1789
2397
  let n = this.getVarByName(e), r = this.getBoolVarByName(e);
1790
- n && (n.value = t, d(f, n.name, t), this.values.set(n.name, t)), r && (r.value = !!t, this.values.set(r.name, t)), !n && !r && this.values.set(e, t);
2398
+ n && (n.value = t, f(p, n.name, t), this.values.set(n.name, t)), r && (r.value = !!t, this.values.set(r.name, t)), !n && !r && this.values.set(e, t);
1791
2399
  } else if (typeof t == "boolean") {
1792
2400
  let n = t, r = this.getBoolVarByName(e);
1793
- r ? (r.value = n, d(f, r.name, +!!n), this.values.set(r.name, n)) : this.values.set(e, n);
2401
+ r ? (r.value = n, f(p, r.name, +!!n), this.values.set(r.name, n)) : this.values.set(e, n);
2402
+ }
2403
+ if (s) for (let e of this.boolVars) {
2404
+ let t = s.boolVarToBinary.get(e);
2405
+ if (t && l.values) {
2406
+ let n = l.values[t.name];
2407
+ if (typeof n == "number" && Number.isFinite(n)) {
2408
+ let t = Math.round(n) === 1;
2409
+ e.value = t, f(p, e.name, +!!t), this.values.set(e.name, t);
2410
+ }
2411
+ }
1794
2412
  }
1795
2413
  }
1796
- if (l && c.boolValues) for (let [e, t] of Object.entries(c.boolValues)) {
2414
+ if (u && l.boolValues) for (let [e, t] of Object.entries(l.boolValues)) {
1797
2415
  if (typeof t != "boolean") continue;
1798
2416
  let n = this.getBoolVarByName(e);
1799
2417
  n ? (n.value = t, this.values.has(n.name) || this.values.set(n.name, t)) : this.values.has(e) || this.values.set(e, t);
1800
2418
  }
1801
- if (l && c.reducedCosts) for (let [e, t] of Object.entries(c.reducedCosts)) {
2419
+ if (u && l.reducedCosts) for (let [e, t] of Object.entries(l.reducedCosts)) {
1802
2420
  if (typeof t != "number" || !Number.isFinite(t)) continue;
1803
2421
  let n = this.getVarByName(e);
1804
- n && (n.reducedCost = t, d(m, n.name, t));
2422
+ n && (n.reducedCost = t, f(h, n.name, t));
1805
2423
  }
1806
- if (c.duals) for (let [e, t] of Object.entries(c.duals)) {
2424
+ if (l.duals) for (let [e, t] of Object.entries(l.duals)) {
1807
2425
  if (typeof t != "number" || !Number.isFinite(t)) continue;
1808
2426
  let n = this.getConstraintByName(e);
1809
- n && (n.dual = t, d(p, n.name, t));
2427
+ n && (n.dual = t, f(m, n.name, t));
1810
2428
  }
1811
- if (c.slacks) for (let [e, t] of Object.entries(c.slacks)) {
2429
+ if (l.slacks) for (let [e, t] of Object.entries(l.slacks)) {
1812
2430
  if (typeof t != "number" || !Number.isFinite(t)) continue;
1813
2431
  let n = this.getConstraintByName(e);
1814
- n && (n.slack = t, d(h, n.name, t));
2432
+ n && (n.slack = t, f(g, n.name, t));
1815
2433
  }
1816
2434
  return this.solution = {
1817
2435
  status: this.status,
@@ -1824,19 +2442,18 @@ var Re = class {
1824
2442
  mipGap: this.mipGap
1825
2443
  },
1826
2444
  ...this.absGap === void 0 ? {} : { absGap: this.absGap },
1827
- values: f,
1828
- duals: p,
1829
- reducedCosts: m,
1830
- slacks: h,
2445
+ values: p,
2446
+ duals: m,
2447
+ reducedCosts: h,
2448
+ slacks: g,
1831
2449
  runTime: this.runTime,
1832
- raw: c.raw
2450
+ raw: l.raw
1833
2451
  }, this.hasSolutionState = !0, this.status;
1834
2452
  }
1835
2453
  async check(e, t) {
1836
2454
  let n = ++this.activeOperationId, r = this.modelRevision;
1837
2455
  this.clearSolutionFields(), this.validateIntegrity();
1838
2456
  let { activeSolver: i, activeOptions: a } = this.resolveSolverAndOptions(e, t);
1839
- if (this.logicalConstraints.length > 0 && i.capabilities?.supportsSMT !== !0) throw Error(`Solver "${i.name}" does not support SMT / logical constraints (or, implies, not, xor). Please use an SMT-capable solver such as Z3.`);
1840
2457
  if (this.variables.some((e) => e.initialValue !== void 0) && i.capabilities?.supportsWarmStart !== !0) throw Error(`Solver "${i.name}" does not support primal initial values (initialValue). Please use a solver with warm-start support such as HiGHS.`);
1841
2458
  let o = this.wrapSolveOptions(a, r, n), s = (e, t, n) => {
1842
2459
  Object.defineProperty(e, t, {
@@ -1845,7 +2462,7 @@ var Re = class {
1845
2462
  writable: !0,
1846
2463
  configurable: !0
1847
2464
  });
1848
- }, c = {
2465
+ }, l = {
1849
2466
  name: this.name,
1850
2467
  variables: this.variables,
1851
2468
  boolVars: this.boolVars,
@@ -1855,11 +2472,11 @@ var Re = class {
1855
2472
  if (typeof i.check == "function") {
1856
2473
  let e;
1857
2474
  try {
1858
- e = await i.check(c, o);
2475
+ e = await i.check(l, o);
1859
2476
  } catch (e) {
1860
2477
  throw this.activeOperationId === n && this.clearSolutionFields(), e;
1861
2478
  }
1862
- this.ensureExecutionValid(r, n, "check"), this.status = e.status, this.terminationStatus = a.signal?.aborted ? "Interrupted" : e.status, this.hasPrimalSolution = e.status === "Sat", this.runTime = e.runTime ?? 0, this.unsatCore = e.unsatCore === void 0 ? void 0 : Object.freeze([...e.unsatCore]);
2479
+ this.ensureExecutionValid(r, n, "check"), this.status = e.status, this.terminationStatus = a.signal?.aborted ? "Interrupted" : e.status, this.hasPrimalSolution = e.status === "Sat", this.runTime = e.runTime ?? 0, this.unsatCore = e.unsatCore === void 0 ? void 0 : Object.freeze([...e.unsatCore]), this.conflicts = e.conflicts === void 0 ? this.unsatCore : Object.freeze([...e.conflicts]);
1863
2480
  let t = {};
1864
2481
  if (e.values && e.status === "Sat") {
1865
2482
  for (let [n, r] of Object.entries(e.values)) if (typeof r == "number") {
@@ -1875,133 +2492,184 @@ var Re = class {
1875
2492
  status: e.status,
1876
2493
  values: t,
1877
2494
  unsatCore: this.unsatCore,
1878
- conflicts: this.unsatCore,
2495
+ conflicts: this.conflicts,
1879
2496
  runTime: this.runTime
1880
2497
  };
1881
2498
  }
1882
- let l = {
1883
- name: this.name,
2499
+ let u = this.logicalConstraints.length > 0 || this.boolVars.length > 0 ? Ke(this.variables, this.boolVars, this.constraints, this.logicalConstraints) : {
2500
+ variables: [...this.variables],
2501
+ constraints: [...this.constraints],
2502
+ boolVarToBinary: /* @__PURE__ */ new Map(),
2503
+ constraintToOriginalName: new Map(this.constraints.map((e) => [e, e.name]))
2504
+ }, d = [], f = [], p = [], m = /* @__PURE__ */ new Map(), h = 0;
2505
+ for (let e of u.constraints) {
2506
+ let t = u.constraintToOriginalName.get(e) ?? e.name, { lhs: n, sense: r, rhs: i } = e;
2507
+ if (r === "<=") {
2508
+ let r = new b({
2509
+ name: `__slack_${++h}`,
2510
+ type: "Continuous",
2511
+ lb: 0,
2512
+ ub: Infinity
2513
+ });
2514
+ f.push(r), p.push([r, 1]), m.set(r, t);
2515
+ let a = n.clone().add(new j(/* @__PURE__ */ new Map([[r, -1]]), 0));
2516
+ d.push(new c(a, "<=", i, `${e.name}_slack`));
2517
+ } else if (r === ">=") {
2518
+ let r = new b({
2519
+ name: `__slack_${++h}`,
2520
+ type: "Continuous",
2521
+ lb: 0,
2522
+ ub: Infinity
2523
+ });
2524
+ f.push(r), p.push([r, 1]), m.set(r, t);
2525
+ let a = n.clone().add(new j(/* @__PURE__ */ new Map([[r, 1]]), 0));
2526
+ d.push(new c(a, ">=", i, `${e.name}_slack`));
2527
+ } else {
2528
+ let r = new b({
2529
+ name: `__slack_${++h}_p`,
2530
+ type: "Continuous",
2531
+ lb: 0,
2532
+ ub: Infinity
2533
+ }), a = new b({
2534
+ name: `__slack_${++h}_n`,
2535
+ type: "Continuous",
2536
+ lb: 0,
2537
+ ub: Infinity
2538
+ });
2539
+ f.push(r, a), p.push([r, 1], [a, 1]), m.set(r, t), m.set(a, t);
2540
+ let o = n.clone().add(new j(/* @__PURE__ */ new Map([[r, -1], [a, 1]]), 0));
2541
+ d.push(new c(o, "==", i, `${e.name}_slack`));
2542
+ }
2543
+ }
2544
+ let g = {
2545
+ name: `${this.name}_elastic_check`,
1884
2546
  sense: "Minimize",
1885
- objective: new j(),
1886
- constraints: this.constraints,
1887
- variables: this.variables,
1888
- logicalConstraints: this.logicalConstraints,
1889
- boolVars: this.boolVars
1890
- }, u;
2547
+ objective: new j(new Map(p), 0),
2548
+ constraints: d,
2549
+ variables: [...u.variables, ...f]
2550
+ }, _;
1891
2551
  try {
1892
- u = await i.solve(l, o);
2552
+ _ = await i.solve(g, o);
1893
2553
  } catch (e) {
1894
2554
  throw this.activeOperationId === n && this.clearSolutionFields(), e;
1895
2555
  }
1896
- this.ensureExecutionValid(r, n, "check"), this.runTime = u.runTime ?? 0;
1897
- let d = u.status, f = u.terminationStatus ?? d, p = this.hasPrimalFromResult(u) || d === "Optimal" || d === "Feasible", m = p ? "Sat" : d === "Infeasible" ? "Unsat" : "Unknown";
1898
- this.status = m, this.terminationStatus = a.signal?.aborted || f === "Interrupted" ? "Interrupted" : f === "Optimal" || f === "Feasible" || f === "Infeasible" ? m : f, this.hasPrimalSolution = p, this.objectiveValue = null, this.objectiveBound = void 0, this.relGap = void 0, this.mipGap = void 0, this.absGap = void 0, this.solution = null, this.values.clear();
1899
- let h = {};
1900
- if (p && u.values) {
1901
- for (let [e, t] of Object.entries(u.values)) if (typeof t == "number" && Number.isFinite(t)) {
1902
- let n = this.getVarByName(e), r = this.getBoolVarByName(e);
1903
- n && (n.value = t, this.values.set(n.name, t), s(h, n.name, t)), r && (r.value = !!t, this.values.set(r.name, r.value), s(h, r.name, r.value)), !n && !r && (this.values.set(e, t), s(h, e, t));
1904
- } else if (typeof t == "boolean") {
1905
- let n = t, r = this.getBoolVarByName(e);
1906
- r ? (r.value = n, this.values.set(r.name, n), s(h, r.name, n)) : (this.values.set(e, n), s(h, e, n));
2556
+ this.ensureExecutionValid(r, n, "check"), this.runTime = _.runTime ?? 0;
2557
+ let v = _.status, y = _.terminationStatus ?? v, x = this.hasPrimalFromResult(_), S = typeof _.objectiveValue == "number" && Number.isFinite(_.objectiveValue) ? _.objectiveValue : Infinity, C = (v === "Optimal" || v === "Feasible" || x) && S <= 1e-5, w = typeof _.objectiveBound == "number" && Number.isFinite(_.objectiveBound) && _.objectiveBound > 1e-5, T = !C && (v === "Infeasible" || v === "Optimal" && S > 1e-5 || w), E = C ? "Sat" : T ? "Unsat" : "Unknown";
2558
+ this.status = E, this.terminationStatus = a.signal?.aborted || y === "Interrupted" ? "Interrupted" : y === "Optimal" || y === "Feasible" || y === "Infeasible" ? E : y, this.hasPrimalSolution = C, this.objectiveValue = null, this.objectiveBound = void 0, this.relGap = void 0, this.mipGap = void 0, this.absGap = void 0, this.solution = null, this.values.clear();
2559
+ let D = {};
2560
+ if (C && _.values) {
2561
+ for (let e of this.variables) {
2562
+ let t = _.values[e.name];
2563
+ typeof t == "number" && Number.isFinite(t) && (e.value = t, this.values.set(e.name, t), s(D, e.name, t));
2564
+ }
2565
+ for (let e of this.boolVars) {
2566
+ let t = u.boolVarToBinary.get(e), n = t ? _.values[t.name] : _.values[e.name];
2567
+ if (typeof n == "number" && Number.isFinite(n)) {
2568
+ let t = Math.round(n) === 1;
2569
+ e.value = t, this.values.set(e.name, t), s(D, e.name, t);
2570
+ }
1907
2571
  }
1908
2572
  }
1909
- if (p && u.boolValues) for (let [e, t] of Object.entries(u.boolValues)) {
1910
- if (typeof t != "boolean") continue;
1911
- let n = this.getBoolVarByName(e);
1912
- n ? (n.value = t, this.values.set(n.name, t), s(h, n.name, t)) : (this.values.set(e, t), s(h, e, t));
1913
- }
1914
- if (u.slacks) for (let [e, t] of Object.entries(u.slacks)) {
1915
- if (typeof t != "number" || !Number.isFinite(t)) continue;
1916
- let n = this.getConstraintByName(e);
1917
- n && (n.slack = t);
2573
+ let O = /* @__PURE__ */ new Set();
2574
+ if (T && _.values) for (let [e, t] of m.entries()) {
2575
+ let n = _.values[e.name];
2576
+ typeof n == "number" && n > 1e-5 && O.add(t);
1918
2577
  }
1919
- return this.hasSolutionState = !0, {
1920
- status: m,
1921
- values: h,
2578
+ return this.conflicts = T ? Object.freeze(Array.from(O)) : void 0, this.unsatCore = void 0, this.hasSolutionState = !0, {
2579
+ status: E,
2580
+ values: D,
2581
+ conflicts: this.conflicts,
2582
+ unsatCore: this.unsatCore,
1922
2583
  runTime: this.runTime
1923
2584
  };
1924
2585
  }
1925
2586
  validateSolution(e = {}) {
1926
- return Ne(this, e);
2587
+ return Ue(this, e);
2588
+ }
2589
+ link(e) {
2590
+ if (e instanceof A || typeof e == "object" && e && "quadTerms" in e) throw Error("Linking constraint cannot be a quadratic expression.");
2591
+ if (!(e instanceof c) && (typeof e != "object" || !e || !("sense" in e) || !("lhs" in e) || !("rhs" in e))) throw Error("Linking constraint must contain a comparison operator (<=, >=, ==). Use expr`... <= ...` or .le(), .ge(), .eq().");
2592
+ this._linkingConstraints ||= [];
2593
+ let t = e;
2594
+ return this._linkingConstraints.push(t), t;
2595
+ }
2596
+ get linkingConstraints() {
2597
+ return this._linkingConstraints ?? [];
2598
+ }
2599
+ async solveBenders(e) {
2600
+ let t = await et({
2601
+ master: this,
2602
+ ...e
2603
+ });
2604
+ return this.decomposition = t, t;
1927
2605
  }
1928
- };
1929
- //#endregion
1930
- //#region src/modeler/objective.ts
1931
- function ze(e, t) {
1932
- let n = e;
1933
- if (n instanceof c || typeof n == "object" && n && "sense" in n && "lhs" in n && "rhs" in n) throw Error(`Cannot use a Constraint as an objective in ${t}(). Use model.constraint(expr\`... <= ...\`) for constraints, or supply an unconstrained arithmetic expression to ${t}().`);
1934
- if (typeof n == "string" && /(<=|>=|==|=<|=>|=)/.test(n)) throw Error(`Cannot use a comparison constraint as an objective in ${t}(). Use model.constraint(expr\`... <= ...\`) for constraints, or supply an unconstrained arithmetic expression to ${t}().`);
1935
- if (typeof n == "number") {
1936
- if (!Number.isFinite(n)) throw Error(`Invalid non-finite objective constant "${n}" passed to ${t}().`);
1937
- return n;
2606
+ async solveColumnGeneration(e) {
2607
+ let t = await Je({
2608
+ master: this,
2609
+ ...e
2610
+ });
2611
+ return this.decomposition = t, t;
1938
2612
  }
1939
- if (typeof n == "string" || n instanceof j || n instanceof A || n instanceof b || typeof n == "object" && n && ("terms" in n && n.terms instanceof Map && typeof n.constant == "number" || "quadTerms" in n && n.quadTerms instanceof Map && "linearTerms" in n && n.linearTerms instanceof Map && typeof n.constant == "number" || "id" in n && "name" in n && "lb" in n && "ub" in n)) return n;
1940
- throw Error(`Invalid expression passed to ${t}(): expected a finite number, Var, LinExpr, QuadExpr, or arithmetic expression string.`);
1941
- }
1942
- function Be(e) {
1943
- return {
1944
- expr: ze(e, "maximize"),
1945
- sense: "Maximize"
1946
- };
1947
- }
1948
- function Ve(e) {
1949
- return {
1950
- expr: ze(e, "minimize"),
1951
- sense: "Minimize"
1952
- };
1953
- }
1954
- z(/* @__PURE__ */ se({
2613
+ };
2614
+ R(/* @__PURE__ */ he({
1955
2615
  BoolExpr: () => r,
1956
2616
  BoolOp: () => n,
1957
2617
  BoolVar: () => o,
1958
2618
  Constraint: () => c,
1959
- HiGHS: () => J,
1960
- HighsSolver: () => q,
2619
+ HIGHS_CONSTANTS: () => ie,
2620
+ HIGHS_STATUS_NAMES: () => le,
2621
+ HiGHS: () => G,
2622
+ Highs: () => P,
2623
+ HighsError: () => te,
2624
+ HighsModel: () => se,
2625
+ HighsSolver: () => W,
2626
+ HighsUnsupportedOptionError: () => ae,
1961
2627
  LinExpr: () => j,
1962
- MockSolver: () => ke,
1963
- Model: () => Re,
1964
- OFFICIAL_HIGHS_CDN_WASM_URL: () => te,
2628
+ MockSolver: () => ze,
2629
+ Model: () => nt,
2630
+ OFFICIAL_HIGHS_CDN_WASM_URL: () => ce,
1965
2631
  QuadExpr: () => A,
1966
2632
  Var: () => b,
1967
2633
  and: () => y,
1968
- buildIndicatorLinearization: () => X,
2634
+ bindHighsFunctions: () => ne,
2635
+ buildIndicatorLinearization: () => Y,
1969
2636
  buildLpSymbolMaps: () => u,
1970
- deriveBigMForGe: () => Le,
1971
- deriveBigMForLe: () => Ie,
2637
+ deriveBigMForGe: () => J,
2638
+ deriveBigMForLe: () => q,
1972
2639
  dot: () => s,
1973
- expr: () => be,
2640
+ expr: () => ke,
1974
2641
  generateLpString: () => C,
1975
- getHighs: () => F,
1976
- getHighsWasmUrl: () => L,
2642
+ getHighs: () => oe,
2643
+ getHighsWasmUrl: () => I,
1977
2644
  getSolver: () => D,
1978
2645
  implies: () => e,
1979
2646
  isLpExportResult: () => E,
1980
- isValidWasmHeader: () => P,
2647
+ isValidWasmHeader: () => re,
2648
+ linearizeModelForMip: () => Ke,
1981
2649
  listAvailableSolvers: () => S,
1982
- mapHighsStatus: () => K,
1983
- mapHighsTerminationStatus: () => G,
1984
- maximize: () => Be,
1985
- minimize: () => Ve,
2650
+ mapHighsStatus: () => U,
2651
+ mapHighsTerminationStatus: () => H,
2652
+ maximize: () => Xe,
2653
+ minimize: () => Ze,
1986
2654
  not: () => v,
1987
2655
  or: () => i,
1988
- parseConstraint: () => he,
1989
- parseExpr: () => pe,
2656
+ parseConstraint: () => we,
2657
+ parseExpr: () => Se,
1990
2658
  probeWasmUrl: () => M,
1991
- registerHighsSolver: () => Y,
1992
- registerMockSolver: () => Ae,
2659
+ registerHighsSolver: () => K,
2660
+ registerMockSolver: () => Be,
1993
2661
  registerSolver: () => T,
1994
- resolveBrowserWasmUrl: () => I,
2662
+ resolveBrowserWasmUrl: () => F,
1995
2663
  sanitizeIdentifier: () => f,
1996
2664
  setDefaultSolver: () => _,
1997
- setHighsWasmUrl: () => R,
1998
- solveLp: () => W,
2665
+ setHighsWasmUrl: () => L,
2666
+ solveLp: () => V,
1999
2667
  solveLpWithHighs: () => N,
2000
2668
  sum: () => t,
2001
2669
  validateModelIntegrity: () => k,
2002
- validateModelSolution: () => Ne,
2003
- validateUserBigM: () => Pe,
2670
+ validateModelSolution: () => Ue,
2671
+ validateUserBigM: () => We,
2004
2672
  xor: () => a
2005
- }), je);
2673
+ }), Ve);
2006
2674
  //#endregion
2007
- export { r as BoolExpr, n as BoolOp, o as BoolVar, c as Constraint, J as HiGHS, q as HighsSolver, j as LinExpr, ke as MockSolver, Re as Model, A as QuadExpr, b as Var, y as and, X as buildIndicatorLinearization, u as buildLpSymbolMaps, Le as deriveBigMForGe, Ie as deriveBigMForLe, s as dot, be as expr, C as generateLpString, F as getHighs, L as getHighsWasmUrl, D as getSolver, e as implies, E as isLpExportResult, S as listAvailableSolvers, Be as maximize, Ve as minimize, le as normalizeSense, v as not, i as or, he as parseConstraint, pe as parseExpr, T as registerSolver, f as sanitizeIdentifier, _ as setDefaultSolver, R as setHighsWasmUrl, N as solveLpWithHighs, t as sum, k as validateModelIntegrity, Ne as validateModelSolution, Pe as validateUserBigM, a as xor };
2675
+ export { r as BoolExpr, n as BoolOp, o as BoolVar, c as Constraint, G as HiGHS, P as Highs, W as HighsSolver, j as LinExpr, ze as MockSolver, nt as Model, A as QuadExpr, b as Var, y as and, Y as buildIndicatorLinearization, u as buildLpSymbolMaps, J as deriveBigMForGe, q as deriveBigMForLe, s as dot, ke as expr, C as generateLpString, oe as getHighs, I as getHighsWasmUrl, D as getSolver, e as implies, E as isLpExportResult, Ke as linearizeModelForMip, S as listAvailableSolvers, Xe as maximize, Ze as minimize, _e as normalizeSense, v as not, i as or, we as parseConstraint, Se as parseExpr, T as registerSolver, f as sanitizeIdentifier, _ as setDefaultSolver, L as setHighsWasmUrl, et as solveBenders, Je as solveColumnGeneration, N as solveLpWithHighs, t as sum, k as validateModelIntegrity, Ue as validateModelSolution, We as validateUserBigM, a as xor };