@ohtaman/washi 0.2.0 → 0.3.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 (38) hide show
  1. package/README.ja.md +131 -115
  2. package/README.md +131 -115
  3. package/README.zh-CN.md +133 -117
  4. package/dist/browser/solvers/glpk.js +10 -2
  5. package/dist/browser/solvers/glpk.min.js +1 -1
  6. package/dist/browser/solvers/z3.js +34 -12
  7. package/dist/browser/solvers/z3.min.js +2 -2
  8. package/dist/browser/washi.js +368 -306
  9. package/dist/browser/washi.min.js +4 -4
  10. package/dist/lib/{constraint-XWdn0ID9.js → constraint-BRuB3ooC.js} +0 -3
  11. package/dist/lib/solvers/glpk.js +10 -2
  12. package/dist/lib/solvers/z3.js +35 -10
  13. package/dist/lib/washi.js +368 -321
  14. package/dist/types/index.d.ts +5 -7
  15. package/dist/types/index.d.ts.map +1 -1
  16. package/dist/types/modeler/constraint.d.ts +0 -3
  17. package/dist/types/modeler/constraint.d.ts.map +1 -1
  18. package/dist/types/modeler/expression.d.ts +16 -10
  19. package/dist/types/modeler/expression.d.ts.map +1 -1
  20. package/dist/types/modeler/index.d.ts +2 -4
  21. package/dist/types/modeler/index.d.ts.map +1 -1
  22. package/dist/types/modeler/model.d.ts +90 -11
  23. package/dist/types/modeler/model.d.ts.map +1 -1
  24. package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
  25. package/dist/types/modeler/solvers/highs/solver.d.ts +1 -1
  26. package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
  27. package/dist/types/modeler/solvers/types.d.ts +1 -1
  28. package/dist/types/modeler/solvers/z3/loader.d.ts +12 -0
  29. package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
  30. package/dist/types/modeler/types.d.ts +8 -3
  31. package/dist/types/modeler/types.d.ts.map +1 -1
  32. package/dist/types/modeler/variable.d.ts +1 -6
  33. package/dist/types/modeler/variable.d.ts.map +1 -1
  34. package/package.json +10 -2
  35. package/dist/types/modeler/mip-compat.d.ts +0 -43
  36. package/dist/types/modeler/mip-compat.d.ts.map +0 -1
  37. package/dist/types/modeler/pulp-compat.d.ts +0 -67
  38. package/dist/types/modeler/pulp-compat.d.ts.map +0 -1
package/dist/lib/washi.js CHANGED
@@ -1,4 +1,4 @@
1
- import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c } from "./constraint-XWdn0ID9.js";
1
+ import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c } from "./constraint-BRuB3ooC.js";
2
2
  import { i as l, n as u, r as d, t as f } from "./registry-DksqCSjI.js";
3
3
  import { a as p, c as m, i as h, n as g, o as _, r as v, s as y, t as b } from "./loader-Dti0v9yC.js";
4
4
  import { createHighsWorker as ee } from "./highs-worker-factory.js";
@@ -18,12 +18,17 @@ var x = Object.defineProperty, te = Object.getOwnPropertyDescriptor, ne = Object
18
18
  return e;
19
19
  }, w = (e, t, n) => (C(e, t, "default"), n && C(n, t, "default"));
20
20
  //#endregion
21
+ //#region src/modeler/types.ts
22
+ function T(e) {
23
+ return e && e.toLowerCase() === "maximize" ? "Maximize" : "Minimize";
24
+ }
25
+ //#endregion
21
26
  //#region src/modeler/quad-expr.ts
22
- function T(e, t) {
27
+ function E(e, t) {
23
28
  let n = e.id, r = t.id;
24
29
  return n <= r ? `${n}:${r}` : `${r}:${n}`;
25
30
  }
26
- var E = class e {
31
+ var D = class e {
27
32
  linearTerms;
28
33
  quadTerms;
29
34
  constant;
@@ -36,7 +41,7 @@ var E = class e {
36
41
  return new e(this.linearTerms, this.quadTerms, this.constant);
37
42
  }
38
43
  getQuadCoeff(e, t) {
39
- let n = T(e, t), r = this.quadTerms.get(n);
44
+ let n = E(e, t), r = this.quadTerms.get(n);
40
45
  return r ? r.coeff : 0;
41
46
  }
42
47
  add(t) {
@@ -109,14 +114,14 @@ var E = class e {
109
114
  return this.value;
110
115
  }
111
116
  static fromProduct(t, n, r = 1) {
112
- let i = new e(), a = T(t, n);
117
+ let i = new e(), a = E(t, n);
113
118
  return i.quadTerms.set(a, {
114
119
  var1: t.id <= n.id ? t : n,
115
120
  var2: t.id <= n.id ? n : t,
116
121
  coeff: r
117
122
  }), i;
118
123
  }
119
- }, D = class e {
124
+ }, O = class e {
120
125
  terms;
121
126
  constant;
122
127
  constructor(e = /* @__PURE__ */ new Map(), t = 0) {
@@ -126,7 +131,7 @@ var E = class e {
126
131
  return new e(this.terms, this.constant);
127
132
  }
128
133
  add(e) {
129
- if (e instanceof E) return e.add(this);
134
+ if (e instanceof D) return e.add(this);
130
135
  let t = this.clone();
131
136
  if (typeof e == "number") t.constant += e;
132
137
  else if ("terms" in e) {
@@ -142,7 +147,7 @@ var E = class e {
142
147
  return t;
143
148
  }
144
149
  sub(e) {
145
- return e instanceof E ? e.neg().add(this) : typeof e == "number" ? this.add(-e) : ("terms" in e, this.add(e.mul(-1)));
150
+ return e instanceof D ? e.neg().add(this) : typeof e == "number" ? this.add(-e) : ("terms" in e, this.add(e.mul(-1)));
146
151
  }
147
152
  mul(t) {
148
153
  if (typeof t == "number") {
@@ -153,9 +158,9 @@ var E = class e {
153
158
  }
154
159
  return n;
155
160
  }
156
- let n = new E();
161
+ let n = new D();
157
162
  Math.abs(this.constant) >= 1e-12 && n.linearTerms.set(t, this.constant);
158
- for (let [e, r] of this.terms) n = n.add(E.fromProduct(e, t, r));
163
+ for (let [e, r] of this.terms) n = n.add(D.fromProduct(e, t, r));
159
164
  return n;
160
165
  }
161
166
  div(e) {
@@ -213,27 +218,113 @@ var E = class e {
213
218
  return e.join(" ") || "0";
214
219
  }
215
220
  };
216
- function O(e, t) {
217
- let n = /* @__PURE__ */ new Map(), r = 0, i = 0;
218
- for (let a of e) {
219
- let e = t ? t(a, i++) : a;
220
- if (typeof e == "number") r += e;
221
- else if (e && typeof e == "object" && "terms" in e) {
222
- let t = e;
223
- for (let [e, r] of t.terms) {
224
- let t = n.get(e) || 0;
225
- n.set(e, t + r);
221
+ function k(e, t) {
222
+ let n = /* @__PURE__ */ new Map(), r = 0;
223
+ function i(e) {
224
+ if (e != null) {
225
+ if (typeof e == "number") r += e;
226
+ else if (typeof e == "object" && "terms" in e) {
227
+ let t = e;
228
+ for (let [e, r] of t.terms) {
229
+ let t = n.get(e) || 0;
230
+ n.set(e, t + r);
231
+ }
232
+ r += t.constant;
233
+ } else {
234
+ let t = e, r = n.get(t) || 0;
235
+ n.set(t, r + 1);
236
+ }
237
+ }
238
+ }
239
+ if (typeof e == "number") {
240
+ let n = e, r = t;
241
+ for (let e = 0; e < n; e++) i(r(e, e));
242
+ } else {
243
+ let n = 0;
244
+ for (let r of e) i(t ? t(r, n++) : r);
245
+ }
246
+ for (let [e, t] of n) Math.abs(t) < 1e-12 && n.delete(e);
247
+ return new O(n, r);
248
+ }
249
+ function A(e, t) {
250
+ let n = /* @__PURE__ */ new Map(), r = 0;
251
+ function i(e) {
252
+ return typeof e == "object" && !!e && typeof e.id == "number" && typeof e.name == "string" && typeof e.mul == "function" && typeof e.le == "function";
253
+ }
254
+ function a(e) {
255
+ return i(e) || e instanceof O || e instanceof D;
256
+ }
257
+ function o(e, t) {
258
+ if (typeof t == "number") r += e * t;
259
+ else if (t instanceof O) {
260
+ for (let [r, i] of t.terms) {
261
+ let t = n.get(r) || 0;
262
+ n.set(r, t + e * i);
263
+ }
264
+ r += e * t.constant;
265
+ } else if (i(t)) {
266
+ let r = t, i = n.get(r) || 0;
267
+ n.set(r, i + e);
268
+ } else throw Error("Cannot multiply number by non-variable/expression operand in dot().");
269
+ }
270
+ function s(e) {
271
+ return typeof e == "object" && !!e && !Array.isArray(e) && !a(e);
272
+ }
273
+ function c(e, t, n = "") {
274
+ if (e === void 0 || t === void 0 || e === null || t === null) throw Error(`Nullish or undefined operand encountered in dot() at '${n || "root"}'.`);
275
+ if (typeof e == "number") {
276
+ o(e, t);
277
+ return;
278
+ }
279
+ if (typeof t == "number") {
280
+ o(t, e);
281
+ return;
282
+ }
283
+ if (Array.isArray(e) || Array.isArray(t)) {
284
+ if (Array.isArray(e) && Array.isArray(t)) {
285
+ if (e.length !== t.length) throw Error(`Array length mismatch in dot() at '${n || "root"}': received lengths ${e.length} and ${t.length}.`);
286
+ for (let r = 0; r < e.length; r++) c(e[r], t[r], n ? `${n}[${r}]` : `[${r}]`);
287
+ return;
288
+ }
289
+ let r = Array.isArray(e) ? e : t, i = Array.isArray(e) ? t : e;
290
+ if (s(i)) {
291
+ let a = Object.keys(i);
292
+ if (a.length > 0 && a.every((e) => /^\d+$/.test(e))) {
293
+ if (a.length !== r.length) throw Error(`Array length mismatch in dot() at '${n || "root"}': array has length ${r.length}, but object has ${a.length} indices.`);
294
+ let o = [];
295
+ for (let e = 0; e < r.length; e++) !(e in i) && !(String(e) in i) && o.push(e);
296
+ if (o.length > 0) throw Error(`Key mismatch in dot() at '${n || "root"}': missing indices [${o.join(", ")}] in numeric record.`);
297
+ for (let i = 0; i < r.length; i++) c(e[i], t[i], n ? `${n}[${i}]` : `[${i}]`);
298
+ return;
299
+ }
300
+ throw Error(`Type mismatch in dot() at '${n || "root"}': one operand is an Array while the other is an Object with keys [${a.slice(0, 5).join(", ")}].`);
301
+ }
302
+ throw Error(`Type mismatch in dot() at '${n || "root"}': one operand is an Array while the other is not.`);
303
+ }
304
+ if (s(e) && s(t)) {
305
+ let r = Object.keys(e), i = Object.keys(t), a = r.filter((e) => !(e in t)), o = i.filter((t) => !(t in e));
306
+ if (a.length > 0 || o.length > 0) {
307
+ let e = [];
308
+ throw a.length > 0 && e.push(`missing in second operand: [${a.join(", ")}]`), o.length > 0 && e.push(`missing in first operand: [${o.join(", ")}]`), Error(`Key mismatch in dot() at '${n || "root"}': ${e.join("; ")}.`);
226
309
  }
227
- r += t.constant;
228
- } else if (e) {
229
- let t = e, r = n.get(t) || 0;
230
- n.set(t, r + 1);
310
+ for (let i of r) c(e[i], t[i], n ? `${n}.${i}` : i);
311
+ return;
231
312
  }
313
+ throw Error(`Unsupported operand types in dot() at '${n || "root"}'.`);
232
314
  }
315
+ c(e, t);
233
316
  for (let [e, t] of n) Math.abs(t) < 1e-12 && n.delete(e);
234
- return new D(n, r);
317
+ return new O(n, r);
235
318
  }
236
- var k = O, A = O, ie = 0, j = class e {
319
+ //#endregion
320
+ //#region src/modeler/variable.ts
321
+ var ie = 0;
322
+ function ae(e) {
323
+ if (!e) return "Continuous";
324
+ let t = e.toLowerCase();
325
+ return t === "binary" || t === "bin" ? "Binary" : t === "integer" || t === "int" ? "Integer" : "Continuous";
326
+ }
327
+ var j = class e {
237
328
  id;
238
329
  name;
239
330
  type;
@@ -242,48 +333,42 @@ var k = O, A = O, ie = 0, j = class e {
242
333
  value = null;
243
334
  reducedCost = null;
244
335
  constructor(e = {}) {
245
- this.id = ++ie, this.name = e.name || `x_${this.id}`, this.type = e.type || "Continuous", this.type === "Binary" ? (this.lb = 0, this.ub = 1) : (this.lb = e.lb === void 0 ? 0 : e.lb, this.ub = e.ub === void 0 ? Infinity : e.ub);
246
- }
247
- get x() {
248
- return this.value;
249
- }
250
- get varValue() {
251
- return this.value;
336
+ this.id = ++ie, this.name = e.name || `x_${this.id}`, this.type = ae(e.type), this.type === "Binary" ? (this.lb = 0, this.ub = 1) : (this.lb = e.lb === void 0 ? 0 : e.lb, this.ub = e.ub === void 0 ? Infinity : e.ub);
252
337
  }
253
338
  mul(t) {
254
- if (typeof t == "number") return new D(/* @__PURE__ */ new Map([[this, t]]), 0);
255
- if (t instanceof e) return E.fromProduct(this, t, 1);
256
- let n = new E();
339
+ if (typeof t == "number") return new O(/* @__PURE__ */ new Map([[this, t]]), 0);
340
+ if (t instanceof e) return D.fromProduct(this, t, 1);
341
+ let n = new D();
257
342
  Math.abs(t.constant) >= 1e-12 && n.linearTerms.set(this, t.constant);
258
343
  for (let [e, r] of t.terms) {
259
- let t = E.fromProduct(this, e, r);
344
+ let t = D.fromProduct(this, e, r);
260
345
  n = n.add(t);
261
346
  }
262
347
  return n;
263
348
  }
264
349
  add(e) {
265
- return e instanceof E ? e.add(this) : new D(/* @__PURE__ */ new Map([[this, 1]]), 0).add(e);
350
+ return e instanceof D ? e.add(this) : new O(/* @__PURE__ */ new Map([[this, 1]]), 0).add(e);
266
351
  }
267
352
  sub(e) {
268
- return e instanceof E ? e.neg().add(this) : new D(/* @__PURE__ */ new Map([[this, 1]]), 0).sub(e);
353
+ return e instanceof D ? e.neg().add(this) : new O(/* @__PURE__ */ new Map([[this, 1]]), 0).sub(e);
269
354
  }
270
355
  neg() {
271
356
  return this.mul(-1);
272
357
  }
273
358
  le(e, t) {
274
- return new D(/* @__PURE__ */ new Map([[this, 1]]), 0).le(e, t);
359
+ return new O(/* @__PURE__ */ new Map([[this, 1]]), 0).le(e, t);
275
360
  }
276
361
  lessThanOrEqual(e, t) {
277
362
  return this.le(e, t);
278
363
  }
279
364
  ge(e, t) {
280
- return new D(/* @__PURE__ */ new Map([[this, 1]]), 0).ge(e, t);
365
+ return new O(/* @__PURE__ */ new Map([[this, 1]]), 0).ge(e, t);
281
366
  }
282
367
  greaterThanOrEqual(e, t) {
283
368
  return this.ge(e, t);
284
369
  }
285
370
  eq(e, t) {
286
- return new D(/* @__PURE__ */ new Map([[this, 1]]), 0).eq(e, t);
371
+ return new O(/* @__PURE__ */ new Map([[this, 1]]), 0).eq(e, t);
287
372
  }
288
373
  equalTo(e, t) {
289
374
  return this.eq(e, t);
@@ -294,7 +379,7 @@ var k = O, A = O, ie = 0, j = class e {
294
379
  };
295
380
  //#endregion
296
381
  //#region src/modeler/parser.ts
297
- function ae(e) {
382
+ function M(e) {
298
383
  let t = [], n = 0, r = e.length;
299
384
  for (; n < r;) {
300
385
  let i = e[n];
@@ -350,7 +435,7 @@ function ae(e) {
350
435
  }
351
436
  return t;
352
437
  }
353
- var oe = class {
438
+ var N = class {
354
439
  tokens;
355
440
  pos = 0;
356
441
  resolver;
@@ -412,12 +497,12 @@ var oe = class {
412
497
  let e = this.consume();
413
498
  return this.resolveVariable(e.value).mul(t);
414
499
  }
415
- return new D(/* @__PURE__ */ new Map(), t);
500
+ return new O(/* @__PURE__ */ new Map(), t);
416
501
  }
417
502
  if (e.type === "IDENT") {
418
503
  this.consume();
419
504
  let t = this.resolveVariable(e.value);
420
- return new D(/* @__PURE__ */ new Map([[t, 1]]), 0);
505
+ return new O(/* @__PURE__ */ new Map([[t, 1]]), 0);
421
506
  }
422
507
  if (e.type === "LPAREN") {
423
508
  this.consume("LPAREN");
@@ -432,10 +517,10 @@ var oe = class {
432
517
  return t;
433
518
  }
434
519
  };
435
- function M(e, t) {
436
- return new oe(ae(e), t).parseExpression();
520
+ function P(e, t) {
521
+ return new N(M(e), t).parseExpression();
437
522
  }
438
- function N(e, t, n) {
523
+ function F(e, t, n) {
439
524
  let r = e.match(/(<=|>=|==|=<|=>|=)/);
440
525
  if (!r) throw Error(`Constraint must contain a comparison operator (<=, >=, ==, =): "${e}"`);
441
526
  let i = r[0], a = r.index, o = e.substring(0, a).trim(), s = e.substring(a + i.length).trim(), c;
@@ -443,10 +528,10 @@ function N(e, t, n) {
443
528
  else if (i === ">=" || i === "=>") c = ">=";
444
529
  else if (i === "==" || i === "=") c = "==";
445
530
  else throw Error(`Unsupported operator "${i}"`);
446
- let l = M(o, t), u = M(s, t);
531
+ let l = P(o, t), u = P(s, t);
447
532
  return c === "<=" ? l.le(u, n) : c === ">=" ? l.ge(u, n) : l.eq(u, n);
448
533
  }
449
- function P(e, t) {
534
+ function I(e, t) {
450
535
  let n = /* @__PURE__ */ new Map(), r = "";
451
536
  for (let i = 0; i < e.length; i++) if (r += e[i], i < t.length) {
452
537
  let e = t[i];
@@ -454,7 +539,7 @@ function P(e, t) {
454
539
  else if (e instanceof j) {
455
540
  let t = `__v_${i}__`;
456
541
  n.set(t, e), r += t;
457
- } else if (e instanceof D) {
542
+ } else if (e instanceof O) {
458
543
  `${i}`, r += `(${e.toString()})`;
459
544
  for (let [t] of e.terms) n.set(t.name, t);
460
545
  }
@@ -464,42 +549,42 @@ function P(e, t) {
464
549
  resolver: (e) => n.get(e)
465
550
  };
466
551
  }
467
- function se(e, ...t) {
468
- let { fullText: n, resolver: r } = P(e, t);
469
- return N(n, r);
552
+ function L(e, ...t) {
553
+ let { fullText: n, resolver: r } = I(e, t);
554
+ return F(n, r);
470
555
  }
471
- function ce(e, ...t) {
472
- let { fullText: n, resolver: r } = P(e, t);
473
- return /(<=|>=|==|=<|=>|=)/.test(n) ? N(n, r) : M(n, r);
556
+ function R(e, ...t) {
557
+ let { fullText: n, resolver: r } = I(e, t);
558
+ return /(<=|>=|==|=<|=>|=)/.test(n) ? F(n, r) : P(n, r);
474
559
  }
475
560
  //#endregion
476
561
  //#region src/modeler/lp-writer.ts
477
- function le(e, t, n) {
562
+ function z(e, t, n) {
478
563
  let r = e.replace(/[^a-zA-Z0-9_]/g, "_");
479
564
  return /^[0-9]/.test(r) && (r = `${t}_${r}`), (!r || r.length === 0) && (r = `${t}_${n}`), r;
480
565
  }
481
- function F(e) {
566
+ function B(e) {
482
567
  let { sense: t, objective: n, constraints: r, variables: i } = e, a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map(), c = /* @__PURE__ */ new Set();
483
568
  for (let e of i) {
484
- let t = le(e.name, "x", e.id), n = t, r = 1;
569
+ let t = z(e.name, "x", e.id), n = t, r = 1;
485
570
  for (; c.has(n);) n = `${t}_${r++}`;
486
571
  c.add(n), o.set(e, n), a.set(n, e);
487
572
  }
488
573
  let l = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Map();
489
574
  for (let e of r) {
490
- let t = le(e.name, "c", e.id), n = t, r = 1;
575
+ let t = z(e.name, "c", e.id), n = t, r = 1;
491
576
  for (; l.has(n);) n = `${t}_${r++}`;
492
577
  l.add(n), u.set(e, n), s.set(n, e);
493
578
  }
494
579
  let d = [];
495
- d.push(t === "Maximize" ? "Maximize" : "Minimize");
496
- let f = [], p = !0, m = n instanceof E ? n.linearTerms : n.terms;
580
+ d.push(t && t.toLowerCase() === "maximize" ? "Maximize" : "Minimize");
581
+ let f = [], p = !0, m = n instanceof D ? n.linearTerms : n.terms;
497
582
  if (m) for (let [e, t] of m) {
498
583
  if (Math.abs(t) < 1e-12) continue;
499
584
  let n = o.get(e), r = t >= 0 ? p ? "" : "+ " : "- ", i = Math.abs(t), a = i === 1 ? "" : `${i} `;
500
585
  f.push(`${r}${a}${n}`), p = !1;
501
586
  }
502
- if (n instanceof E && n.quadTerms.size > 0) {
587
+ if (n instanceof D && n.quadTerms.size > 0) {
503
588
  let e = [], t = !0;
504
589
  for (let r of n.quadTerms.values()) {
505
590
  if (Math.abs(r.coeff) < 1e-12) continue;
@@ -551,41 +636,41 @@ function F(e) {
551
636
  }
552
637
  //#endregion
553
638
  //#region src/modeler/solvers/highs/worker-client.ts
554
- var I = null, ue = 0, L = /* @__PURE__ */ new Map();
555
- function de() {
639
+ var V = null, oe = 0, H = /* @__PURE__ */ new Map();
640
+ function se() {
556
641
  if (typeof window > "u" || typeof Worker > "u") return null;
557
- if (!I) try {
558
- I = ee();
559
- let e = I;
560
- I.onmessage = (e) => {
561
- let { type: t, id: n, result: r, runTime: i, error: a } = e.data, o = L.get(n);
562
- o && (L.delete(n), t === "SOLVE_SUCCESS" ? o.resolve({
642
+ if (!V) try {
643
+ V = ee();
644
+ let e = V;
645
+ V.onmessage = (e) => {
646
+ let { type: t, id: n, result: r, runTime: i, error: a } = e.data, o = H.get(n);
647
+ o && (H.delete(n), t === "SOLVE_SUCCESS" ? o.resolve({
563
648
  result: r,
564
649
  runTime: i
565
650
  }) : o.reject(Error(a || "Worker solve failed")));
566
651
  };
567
652
  let t = (t) => {
568
- if (I === e) {
569
- I = null, e.terminate();
570
- for (let e of L.values()) e.reject(t);
571
- L.clear();
653
+ if (V === e) {
654
+ V = null, e.terminate();
655
+ for (let e of H.values()) e.reject(t);
656
+ H.clear();
572
657
  }
573
658
  };
574
- I.onerror = (e) => t(/* @__PURE__ */ Error(`[WaSHI] HiGHS Worker failed to load or execute. Check Worker assets, CORS and CSP. ${e?.message || ""}`)), I.onmessageerror = () => t(/* @__PURE__ */ Error("[WaSHI] Could not deserialize the HiGHS Worker response."));
659
+ 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."));
575
660
  } catch {
576
- I = null;
661
+ V = null;
577
662
  }
578
- return I;
663
+ return V;
579
664
  }
580
- async function R(e, t = {}) {
581
- let n = await _(t.wasmUrl), r = t.useWorker ?? typeof window < "u" ? de() : null;
665
+ async function U(e, t = {}) {
666
+ let n = await _(t.wasmUrl), r = t.useWorker ?? typeof window < "u" ? se() : null;
582
667
  if (!r) return m(e, t);
583
668
  let i = {
584
669
  ...t,
585
670
  wasmUrl: n
586
- }, a = `req_${++ue}`;
671
+ }, a = `req_${++oe}`;
587
672
  return new Promise((t, n) => {
588
- L.set(a, {
673
+ H.set(a, {
589
674
  resolve: t,
590
675
  reject: n
591
676
  });
@@ -597,13 +682,13 @@ async function R(e, t = {}) {
597
682
  options: i
598
683
  });
599
684
  } catch (e) {
600
- L.delete(a), n(e);
685
+ H.delete(a), n(e);
601
686
  }
602
687
  });
603
688
  }
604
689
  //#endregion
605
690
  //#region src/modeler/solvers/highs/solver.ts
606
- function z(e) {
691
+ function W(e) {
607
692
  if (typeof e != "string") return "Unknown";
608
693
  let t = e.trim();
609
694
  if (!t) return "Unknown";
@@ -632,7 +717,7 @@ function z(e) {
632
717
  let n = t.toLowerCase();
633
718
  return n.includes("infeasible") && n.includes("unbounded") ? "Unknown" : n.includes("infeasible") ? "Infeasible" : n.includes("unbounded") ? "Unbounded" : n.includes("time limit") || n.includes("timelimit") ? "TimeLimit" : n.includes("iteration limit") || n.includes("iterationlimit") ? "IterationLimit" : n.includes("error") ? "Error" : n === "optimal" ? "Optimal" : "Unknown";
634
719
  }
635
- var B = class e {
720
+ var G = class e {
636
721
  static capabilities = {
637
722
  supportsMIP: !0,
638
723
  supportsQP: !0
@@ -648,7 +733,18 @@ var B = class e {
648
733
  let r = {
649
734
  ...this.options,
650
735
  ...n
651
- }, { lpString: i, nameToVar: a, nameToConstraint: o } = t, { result: s, runTime: c } = await R(i, r), l = z(s?.Status), u = s.ObjectiveValue, d = typeof u == "number" ? u + e.objective.constant : null, f = {}, p = {}, m = {}, h = {};
736
+ }, { lpString: i, nameToVar: a, nameToConstraint: o } = t, { result: s, runTime: c } = await U(i, r), l = W(s?.Status);
737
+ if (l === "Infeasible" || l === "Unbounded") return {
738
+ status: l,
739
+ objectiveValue: null,
740
+ values: {},
741
+ reducedCosts: {},
742
+ duals: {},
743
+ slacks: {},
744
+ runTime: c,
745
+ raw: s
746
+ };
747
+ let u = s.ObjectiveValue, d = typeof u == "number" ? u + e.objective.constant : null, f = {}, p = {}, m = {}, h = {};
652
748
  if (s.Columns) for (let [e, t] of Object.entries(s.Columns)) {
653
749
  let n = a.get(e);
654
750
  if (n) {
@@ -677,53 +773,53 @@ var B = class e {
677
773
  raw: s
678
774
  };
679
775
  }
680
- }, V = B;
681
- function H() {
682
- d("highs", (e) => new B(e)), l((e) => new B(e));
776
+ }, K = G;
777
+ function q() {
778
+ d("highs", (e) => new G(e)), l((e) => new G(e));
683
779
  }
684
- H();
780
+ q();
685
781
  //#endregion
686
782
  //#region src/modeler/solvers/highs/index.ts
687
- var U = /* @__PURE__ */ S({
688
- HiGHS: () => V,
689
- HighsSolver: () => B,
783
+ var J = /* @__PURE__ */ S({
784
+ HiGHS: () => K,
785
+ HighsSolver: () => G,
690
786
  OFFICIAL_HIGHS_CDN_WASM_URL: () => b,
691
787
  getHighs: () => g,
692
788
  getHighsWasmUrl: () => v,
693
789
  isValidWasmHeader: () => h,
694
- mapHighsStatus: () => z,
790
+ mapHighsStatus: () => W,
695
791
  probeWasmUrl: () => p,
696
- registerHighsSolver: () => H,
792
+ registerHighsSolver: () => q,
697
793
  resolveBrowserWasmUrl: () => _,
698
794
  setHighsWasmUrl: () => y,
699
- solveLp: () => R,
795
+ solveLp: () => U,
700
796
  solveLpWithHighs: () => m
701
797
  });
702
- import * as fe from "./highs-worker-factory.js";
703
- w(U, fe);
704
- import * as pe from "./highs-assets.js";
705
- w(U, pe);
798
+ import * as ce from "./highs-worker-factory.js";
799
+ w(J, ce);
800
+ import * as le from "./highs-assets.js";
801
+ w(J, le);
706
802
  //#endregion
707
803
  //#region src/modeler/solvers/highs.ts
708
- var W = /* @__PURE__ */ S({
709
- HiGHS: () => V,
710
- HighsSolver: () => B,
804
+ var Y = /* @__PURE__ */ S({
805
+ HiGHS: () => K,
806
+ HighsSolver: () => G,
711
807
  OFFICIAL_HIGHS_CDN_WASM_URL: () => b,
712
808
  getHighs: () => g,
713
809
  getHighsWasmUrl: () => v,
714
810
  isValidWasmHeader: () => h,
715
- mapHighsStatus: () => z,
811
+ mapHighsStatus: () => W,
716
812
  probeWasmUrl: () => p,
717
- registerHighsSolver: () => H,
813
+ registerHighsSolver: () => q,
718
814
  resolveBrowserWasmUrl: () => _,
719
815
  setHighsWasmUrl: () => y,
720
- solveLp: () => R,
816
+ solveLp: () => U,
721
817
  solveLpWithHighs: () => m
722
818
  });
723
- w(W, U);
819
+ w(Y, J);
724
820
  //#endregion
725
821
  //#region src/modeler/solvers/mock.ts
726
- var G = class {
822
+ var X = class {
727
823
  name;
728
824
  capabilities;
729
825
  options;
@@ -750,37 +846,37 @@ var G = class {
750
846
  };
751
847
  }
752
848
  };
753
- function K() {
754
- d("mock", (e) => new G(e));
849
+ function Z() {
850
+ d("mock", (e) => new X(e));
755
851
  }
756
- K();
852
+ Z();
757
853
  //#endregion
758
854
  //#region src/modeler/solvers/index.ts
759
- var q = /* @__PURE__ */ S({
760
- HiGHS: () => V,
761
- HighsSolver: () => B,
762
- MockSolver: () => G,
855
+ var Q = /* @__PURE__ */ S({
856
+ HiGHS: () => K,
857
+ HighsSolver: () => G,
858
+ MockSolver: () => X,
763
859
  OFFICIAL_HIGHS_CDN_WASM_URL: () => b,
764
860
  getHighs: () => g,
765
861
  getHighsWasmUrl: () => v,
766
862
  getSolver: () => f,
767
863
  isValidWasmHeader: () => h,
768
864
  listAvailableSolvers: () => u,
769
- mapHighsStatus: () => z,
865
+ mapHighsStatus: () => W,
770
866
  probeWasmUrl: () => p,
771
- registerHighsSolver: () => H,
772
- registerMockSolver: () => K,
867
+ registerHighsSolver: () => q,
868
+ registerMockSolver: () => Z,
773
869
  registerSolver: () => d,
774
870
  resolveBrowserWasmUrl: () => _,
775
871
  setDefaultSolver: () => l,
776
872
  setHighsWasmUrl: () => y,
777
- solveLp: () => R,
873
+ solveLp: () => U,
778
874
  solveLpWithHighs: () => m
779
875
  });
780
- w(q, W);
876
+ w(Q, Y);
781
877
  //#endregion
782
878
  //#region src/modeler/model.ts
783
- var J = class {
879
+ var $ = class {
784
880
  name;
785
881
  sense;
786
882
  objective;
@@ -802,7 +898,7 @@ var J = class {
802
898
  n = typeof e == "string" ? {
803
899
  ...t,
804
900
  name: e
805
- } : e, this.name = n.name || "OptimizationModel", this.sense = n.sense || "Minimize", this.objective = new D(), n.solver && (this.solver = f(n.solver));
901
+ } : e, this.name = n.name || "OptimizationModel", this.sense = T(n.sense), this.objective = new O(), n.solver && (this.solver = f(n.solver));
806
902
  }
807
903
  get vars() {
808
904
  return this.variables;
@@ -816,6 +912,60 @@ var J = class {
816
912
  get numConstrs() {
817
913
  return this.constraints.length;
818
914
  }
915
+ createDomainVars(e, t, n, r) {
916
+ if (typeof n == "number" || Array.isArray(n)) {
917
+ let i = typeof t == "number" ? Array.from({ length: t }, (e, t) => t) : t, a = typeof n == "number" ? Array.from({ length: n }, (e, t) => t) : n, o = r || {}, s = o.prefix || o.name || "x", c = {};
918
+ for (let t of i) {
919
+ c[t] = {};
920
+ for (let n of a) c[t][n] = this.addVar({
921
+ ...o,
922
+ type: e,
923
+ name: `${s}_${t}_${n}`
924
+ });
925
+ }
926
+ return c;
927
+ }
928
+ if (typeof t == "string") {
929
+ let r = n || {};
930
+ return this.addVar({
931
+ ...r,
932
+ type: e,
933
+ name: t
934
+ });
935
+ }
936
+ let i = n || {}, a = i.prefix || i.name;
937
+ if (typeof t == "number") {
938
+ let n = [], r = a || "x";
939
+ for (let a = 0; a < t; a++) n.push(this.addVar({
940
+ ...i,
941
+ type: e,
942
+ name: `${r}_${a}`
943
+ }));
944
+ return n;
945
+ }
946
+ if (Array.isArray(t) || t && typeof t[Symbol.iterator] == "function") {
947
+ let n = {};
948
+ for (let r of t) {
949
+ let t = a ? `${a}_${r}` : `${r}`;
950
+ n[r] = this.addVar({
951
+ ...i,
952
+ type: e,
953
+ name: t
954
+ });
955
+ }
956
+ return n;
957
+ }
958
+ throw Error(`Invalid arguments provided for ${e.toLowerCase()} variable creation`);
959
+ }
960
+ binary(e, t, n) {
961
+ return this.createDomainVars("Binary", e, t, n);
962
+ }
963
+ integer(e, t, n) {
964
+ return this.createDomainVars("Integer", e, t, n);
965
+ }
966
+ continuous(e, t, n) {
967
+ return this.createDomainVars("Continuous", e, t, n);
968
+ }
819
969
  addVar(e, t, n, r) {
820
970
  let i;
821
971
  i = typeof e == "string" ? {
@@ -879,7 +1029,8 @@ var J = class {
879
1029
  return this.constrMapByName.get(e);
880
1030
  }
881
1031
  setObjective(e, t) {
882
- t && (this.sense = t), this.objective = typeof e == "string" ? M(e, (e) => this.getVarByName(e)) : typeof e == "number" ? new D(/* @__PURE__ */ new Map(), e) : e instanceof E || "terms" in e ? e.clone() : new D(/* @__PURE__ */ new Map([[e, 1]]), 0);
1032
+ if (e instanceof c) throw Error("Cannot set objective to a constraint comparison (<=, >=, ==). Did you mean to use m.constrain(expr`... <= ...`)? For objectives, supply an unconstrained expression like expr`45 * ${x} + 80 * ${y}`.");
1033
+ t && (this.sense = T(t)), this.objective = typeof e == "string" ? P(e, (e) => this.getVarByName(e)) : typeof e == "number" ? new O(/* @__PURE__ */ new Map(), e) : e instanceof D || "terms" in e ? e.clone() : new O(/* @__PURE__ */ new Map([[e, 1]]), 0);
883
1034
  }
884
1035
  maximize(e) {
885
1036
  this.setObjective(e, "Maximize");
@@ -887,11 +1038,31 @@ var J = class {
887
1038
  minimize(e) {
888
1039
  this.setObjective(e, "Minimize");
889
1040
  }
1041
+ constrain(e, t) {
1042
+ if (Array.isArray(e)) {
1043
+ for (let t of e) this.constrain(t);
1044
+ return this;
1045
+ }
1046
+ if (e instanceof O) throw Error("Cannot add a linear expression without a comparison operator (<=, >=, ==) as a constraint. Use expr`... <= ...` or .le(), .ge(), .eq().");
1047
+ return this.addConstraint(e, t), this;
1048
+ }
1049
+ getValues(e) {
1050
+ if (e == null) return null;
1051
+ if (e instanceof j) return e.value;
1052
+ if (Array.isArray(e)) return e.map((e) => this.getValues(e));
1053
+ if (typeof e == "object") {
1054
+ let t = {};
1055
+ for (let [n, r] of Object.entries(e)) t[n] = this.getValues(r);
1056
+ return t;
1057
+ }
1058
+ return null;
1059
+ }
890
1060
  addBoolVar(e) {
891
1061
  let t = new n(e);
892
1062
  return this.boolVars.push(t), t;
893
1063
  }
894
1064
  addConstraint(e, t) {
1065
+ if (e instanceof O) throw Error("Cannot add a linear expression without a comparison operator (<=, >=, ==) as a constraint. Use expr`... <= ...` or .le(), .ge(), .eq().");
895
1066
  if (e instanceof i) {
896
1067
  let n = t || `lc_${this.logicalConstraints.length + 1}`;
897
1068
  return this.logicalConstraints.push({
@@ -900,7 +1071,7 @@ var J = class {
900
1071
  }), e;
901
1072
  }
902
1073
  let n;
903
- if (typeof e == "string" ? n = N(e, (e) => this.getVarByName(e), t) : (n = e, t && (n.name = t)), this.constrMapByName.has(n.name)) throw Error(`Constraint with name '${n.name}' already exists in model`);
1074
+ if (typeof e == "string" ? n = F(e, (e) => this.getVarByName(e), t) : (n = e, t && (n.name = t)), this.constrMapByName.has(n.name)) throw Error(`Constraint with name '${n.name}' already exists in model`);
904
1075
  return this.constraints.push(n), this.constrMapByName.set(n.name, n), n;
905
1076
  }
906
1077
  addConstr(e, t) {
@@ -916,31 +1087,35 @@ var J = class {
916
1087
  }
917
1088
  return e instanceof j ? (this.varMapByName.has(e.name) || (this.variables.push(e), this.varMapByName.set(e.name, e)), this) : (this.addConstraint(e, t), this);
918
1089
  }
919
- addIndicator(e, t, n = {}) {
920
- let r = n.activeValue === void 0 ? 1 : n.activeValue, i = n.M === void 0 ? 1e5 : n.M, a = n.name || `ind_${e.name}_${t.name}`, o = [], { lhs: s, sense: c, rhs: l } = t;
921
- if (r === 1) {
922
- if (c === "<=" || c === "==") {
923
- let t = this.addConstraint(s.add(e.mul(i)).le(l + i), c === "==" ? `${a}_le` : a);
924
- o.push(t);
1090
+ indicator(e, t, n = {}) {
1091
+ if (!("sense" in t) || !("lhs" in t)) throw Error("Invalid constraint expression passed to indicator(). Expression must include a comparison operator (<=, >=, ==).");
1092
+ let r = t, i = n.activeValue === void 0 ? 1 : n.activeValue, a = n.M === void 0 ? 1e5 : n.M, o = n.name || `ind_${e.name}_${r.name}`, s = [], { lhs: c, sense: l, rhs: u } = r;
1093
+ if (i === 1) {
1094
+ if (l === "<=" || l === "==") {
1095
+ let t = this.addConstraint(c.add(e.mul(a)).le(u + a), l === "==" ? `${o}_le` : o);
1096
+ s.push(t);
925
1097
  }
926
- if (c === ">=" || c === "==") {
927
- let t = this.addConstraint(s.sub(e.mul(i)).ge(l - i), c === "==" ? `${a}_ge` : a);
928
- o.push(t);
1098
+ if (l === ">=" || l === "==") {
1099
+ let t = this.addConstraint(c.sub(e.mul(a)).ge(u - a), l === "==" ? `${o}_ge` : o);
1100
+ s.push(t);
929
1101
  }
930
1102
  } else {
931
- if (c === "<=" || c === "==") {
932
- let t = this.addConstraint(s.sub(e.mul(i)).le(l), c === "==" ? `${a}_le` : a);
933
- o.push(t);
1103
+ if (l === "<=" || l === "==") {
1104
+ let t = this.addConstraint(c.sub(e.mul(a)).le(u), l === "==" ? `${o}_le` : o);
1105
+ s.push(t);
934
1106
  }
935
- if (c === ">=" || c === "==") {
936
- let t = this.addConstraint(s.add(e.mul(i)).ge(l), c === "==" ? `${a}_ge` : a);
937
- o.push(t);
1107
+ if (l === ">=" || l === "==") {
1108
+ let t = this.addConstraint(c.add(e.mul(a)).ge(u), l === "==" ? `${o}_ge` : o);
1109
+ s.push(t);
938
1110
  }
939
1111
  }
940
- return o;
1112
+ return s;
1113
+ }
1114
+ addIndicator(e, t, n = {}) {
1115
+ return this.indicator(e, t, n);
941
1116
  }
942
1117
  toLpString() {
943
- let { lpString: e } = F({
1118
+ let { lpString: e } = B({
944
1119
  name: this.name,
945
1120
  sense: this.sense,
946
1121
  objective: this.objective,
@@ -951,7 +1126,7 @@ var J = class {
951
1126
  }
952
1127
  async optimize(e, t) {
953
1128
  let n, r;
954
- if (e && typeof e == "object" && "solve" in e && typeof e.solve == "function" ? (n = e, r = t || {}) : typeof e == "function" ? (n = new e(t), r = t || {}) : typeof e == "string" ? (n = f(e, t), r = t || {}) : (r = { ...e }, r.solver ? (n = f(r.solver, r), delete r.solver) : n = this.solver || f()), this.objective instanceof E && this.objective.quadTerms.size > 0 && n.capabilities?.supportsQP === !1) throw Error(`Solver "${n.name}" does not support quadratic objectives (QP). Please use a QP-capable solver such as HiGHS or Clarabel.`);
1129
+ if (e && typeof e == "object" && "solve" in e && typeof e.solve == "function" ? (n = e, r = t || {}) : typeof e == "function" ? (n = new e(t), r = t || {}) : typeof e == "string" ? (n = f(e, t), r = t || {}) : (r = { ...e }, r.solver ? (n = f(r.solver, r), delete r.solver) : n = this.solver || f()), this.objective instanceof D && this.objective.quadTerms.size > 0 && n.capabilities?.supportsQP === !1) throw Error(`Solver "${n.name}" does not support quadratic objectives (QP). Please use a QP-capable solver such as HiGHS or Clarabel.`);
955
1130
  let i = {
956
1131
  name: this.name,
957
1132
  sense: this.sense,
@@ -960,13 +1135,23 @@ var J = class {
960
1135
  variables: this.variables,
961
1136
  logicalConstraints: this.logicalConstraints,
962
1137
  boolVars: this.boolVars
963
- }, a = F(i), o = await n.solve(i, a, r);
1138
+ }, a = B(i), o = await n.solve(i, a, r);
964
1139
  this.runTime = o.runTime ?? 0, this.status = o.status, this.objectiveValue = o.objectiveValue ?? null;
965
1140
  let s = {}, c = {}, l = {}, u = {};
966
- if (this.values.clear(), o.values) for (let [e, t] of Object.entries(o.values)) {
967
- this.values.set(e, t);
968
- let n = this.getVarByName(e) || a.nameToVar.get(e);
969
- n && (n.value = t, s[n.name] = t);
1141
+ this.values.clear();
1142
+ for (let e of this.variables) e.value = null, e.reducedCost = null;
1143
+ for (let e of this.boolVars) e.value = null;
1144
+ for (let e of this.constraints) e.dual = null, e.slack = null;
1145
+ if (a?.nameToVar) for (let e of a.nameToVar.values()) e.value = null, e.reducedCost = null;
1146
+ if (a?.nameToConstraint) for (let e of a.nameToConstraint.values()) e.dual = null, e.slack = null;
1147
+ if (o.values && o.status !== "Infeasible" && o.status !== "Unbounded") {
1148
+ for (let [e, t] of Object.entries(o.values)) if (typeof t == "number" && !Number.isNaN(t)) {
1149
+ this.values.set(e, t);
1150
+ let n = this.getVarByName(e) || a.nameToVar.get(e);
1151
+ n && (n.value = t, s[n.name] = t);
1152
+ let r = this.boolVars.find((t) => t.name === e);
1153
+ r && (r.value = !!t);
1154
+ }
970
1155
  }
971
1156
  if (o.reducedCosts) for (let [e, t] of Object.entries(o.reducedCosts)) {
972
1157
  let n = this.getVarByName(e) || a.nameToVar.get(e);
@@ -1005,21 +1190,26 @@ var J = class {
1005
1190
  constraints: this.constraints,
1006
1191
  logicalConstraints: this.logicalConstraints
1007
1192
  }, r);
1008
- if (this.status = e.status, this.runTime = e.runTime ?? 0, this.unsatCore = e.unsatCore || [], e.values) {
1009
- this.values.clear();
1010
- for (let [t, n] of Object.entries(e.values)) {
1011
- this.values.set(t, n);
1012
- let e = this.getVarByName(t);
1013
- e && typeof n == "number" && (e.value = n);
1014
- }
1193
+ this.status = e.status, this.runTime = e.runTime ?? 0, this.unsatCore = e.unsatCore || [], this.values.clear();
1194
+ for (let e of this.variables) e.value = null;
1195
+ for (let e of this.boolVars) e.value = null;
1196
+ if (e.values && e.status === "Sat") for (let [t, n] of Object.entries(e.values)) {
1197
+ this.values.set(t, n);
1198
+ let e = this.getVarByName(t);
1199
+ e && typeof n == "number" && (e.value = n);
1200
+ let r = this.boolVars.find((e) => e.name === t);
1201
+ r && (r.value = !!n);
1015
1202
  }
1016
1203
  return e;
1017
1204
  }
1018
1205
  let i = this.objective, a = this.sense;
1019
1206
  try {
1020
- this.objective = new D(), this.sense = "Minimize";
1207
+ this.objective = new O(), this.sense = "Minimize";
1021
1208
  let e = await this.optimize(n, r), t = e === "Optimal" || e === "Feasible", i = e === "Infeasible", a = {};
1022
- for (let e of this.variables) a[e.name] = e.value ?? 0;
1209
+ if (t) {
1210
+ for (let e of this.variables) e.value !== null && (a[e.name] = e.value);
1211
+ for (let e of this.boolVars) e.value !== null && (a[e.name] = e.value);
1212
+ }
1023
1213
  return {
1024
1214
  status: t ? "Sat" : i ? "Unsat" : "Unknown",
1025
1215
  values: a,
@@ -1029,190 +1219,47 @@ var J = class {
1029
1219
  this.objective = i, this.sense = a;
1030
1220
  }
1031
1221
  }
1032
- }, Y = "Minimize", me = "Maximize", he = "Continuous", ge = "Integer", _e = "Binary", ve = {
1033
- Optimal: "Optimal",
1034
- Feasible: "Feasible",
1035
- Infeasible: "Infeasible",
1036
- Unbounded: "Unbounded",
1037
- TimeLimit: "Not Solved (Time Limit)",
1038
- IterationLimit: "Not Solved (Iteration Limit)",
1039
- Error: "Error",
1040
- NotSolved: "Not Solved",
1041
- Sat: "Sat",
1042
- Unsat: "Unsat",
1043
- Unknown: "Unknown"
1044
- }, ye = class e extends j {
1045
- constructor(e, t, n, r = "Continuous") {
1046
- super({
1047
- name: e,
1048
- lb: t === void 0 ? 0 : t,
1049
- ub: n === void 0 ? Infinity : n,
1050
- type: r
1051
- });
1052
- }
1053
- static dicts(t, n, r, i, a = "Continuous") {
1054
- let o = {};
1055
- for (let s of n) {
1056
- let n = `${t}_${s}`;
1057
- o[s] = new e(n, r, i, a);
1058
- }
1059
- return o;
1060
- }
1061
- };
1062
- function be(e) {
1063
- return e == null ? null : typeof e == "number" ? e : e.value;
1064
- }
1065
- var xe = class {
1066
- model;
1067
- constructor(e = "NoName", t = Y) {
1068
- this.model = new J({
1069
- name: e,
1070
- sense: t
1071
- });
1072
- }
1073
- get name() {
1074
- return this.model.name;
1075
- }
1076
- get sense() {
1077
- return this.model.sense;
1078
- }
1079
- set sense(e) {
1080
- this.model.sense = e;
1081
- }
1082
- get objective() {
1083
- return this.model.objective;
1084
- }
1085
- get variables() {
1086
- return this.model.variables;
1087
- }
1088
- get constraints() {
1089
- return this.model.constraints;
1090
- }
1091
- get status() {
1092
- return this.model.status;
1093
- }
1094
- get objectiveValue() {
1095
- return this.model.objectiveValue;
1096
- }
1097
- addVariable(e) {
1098
- return this.model.getVarByName(e.name) || (this.model.variables.push(e), this.model.varMapByName.set(e.name, e)), e;
1099
- }
1100
- setObjective(e) {
1101
- if (typeof e == "object" && e) {
1102
- if ("terms" in e) for (let [t] of e.terms) this.addVariable(t);
1103
- else e instanceof j && this.addVariable(e);
1104
- }
1105
- this.model.setObjective(e);
1106
- }
1107
- addConstraint(e, t) {
1108
- if (typeof e == "object" && e && "lhs" in e) for (let [t] of e.lhs.terms) this.addVariable(t);
1109
- return this.model.addConstraint(e, t);
1110
- }
1111
- add(e, t) {
1112
- typeof e == "string" ? /(<=|>=|==|=<|=>|=)/.test(e) ? this.addConstraint(e, t) : this.setObjective(e) : e instanceof c ? this.addConstraint(e, t) : this.setObjective(e);
1113
- }
1114
- async solve(e, t) {
1115
- return this.model.optimize(e, t);
1116
- }
1117
- toLpString() {
1118
- return this.model.toLpString();
1119
- }
1120
- }, X = "Minimize", Z = "Maximize", Q = "Binary", Se = "Integer", Ce = "Continuous";
1121
- function we(e) {
1122
- return {
1123
- expr: e,
1124
- sense: Z
1125
- };
1126
- }
1127
- function Te(e) {
1128
- return {
1129
- expr: e,
1130
- sense: X
1131
- };
1132
- }
1133
- var $ = class extends J {
1134
- constructor(e = "MipModel", t = X) {
1135
- super({
1136
- name: e,
1137
- sense: t
1138
- });
1139
- }
1140
- add_var(e = {}) {
1141
- return this.addVar({
1142
- name: e.name,
1143
- type: e.var_type,
1144
- lb: e.lb,
1145
- ub: e.ub
1146
- });
1147
- }
1148
- set objective_spec(e) {
1149
- this.setObjective(e.expr, e.sense);
1150
- }
1151
- get objective_value() {
1152
- return this.objectiveValue;
1153
- }
1154
- add_constr(e, t) {
1155
- return this.addConstraint(e, t);
1156
- }
1157
1222
  };
1158
1223
  w(/* @__PURE__ */ S({
1159
- BINARY: () => Q,
1160
1224
  BoolExpr: () => i,
1161
1225
  BoolOp: () => o,
1162
1226
  BoolVar: () => n,
1163
- CONTINUOUS: () => Ce,
1164
1227
  Constraint: () => c,
1165
- HiGHS: () => V,
1166
- HighsSolver: () => B,
1167
- INTEGER: () => Se,
1168
- LinExpr: () => D,
1169
- LpBinary: () => _e,
1170
- LpContinuous: () => he,
1171
- LpInteger: () => ge,
1172
- LpMaximize: () => me,
1173
- LpMinimize: () => Y,
1174
- LpProblem: () => xe,
1175
- LpStatus: () => ve,
1176
- LpVariable: () => ye,
1177
- MAXIMIZE: () => Z,
1178
- MINIMIZE: () => X,
1179
- MipModel: () => $,
1180
- MockSolver: () => G,
1181
- Model: () => J,
1228
+ HiGHS: () => K,
1229
+ HighsSolver: () => G,
1230
+ LinExpr: () => O,
1231
+ MockSolver: () => X,
1232
+ Model: () => $,
1182
1233
  OFFICIAL_HIGHS_CDN_WASM_URL: () => b,
1183
- QuadExpr: () => E,
1234
+ QuadExpr: () => D,
1184
1235
  Var: () => j,
1185
1236
  and: () => e,
1186
- c: () => se,
1187
- expr: () => ce,
1188
- generateLpString: () => F,
1237
+ c: () => L,
1238
+ dot: () => A,
1239
+ expr: () => R,
1240
+ generateLpString: () => B,
1189
1241
  getHighs: () => g,
1190
1242
  getHighsWasmUrl: () => v,
1191
1243
  getSolver: () => f,
1192
1244
  implies: () => a,
1193
1245
  isValidWasmHeader: () => h,
1194
1246
  listAvailableSolvers: () => u,
1195
- lpSum: () => A,
1196
- mapHighsStatus: () => z,
1197
- maximize: () => we,
1198
- minimize: () => Te,
1247
+ mapHighsStatus: () => W,
1199
1248
  not: () => s,
1200
1249
  or: () => t,
1201
- parseConstraint: () => N,
1202
- parseExpr: () => M,
1250
+ parseConstraint: () => F,
1251
+ parseExpr: () => P,
1203
1252
  probeWasmUrl: () => p,
1204
- registerHighsSolver: () => H,
1205
- registerMockSolver: () => K,
1253
+ registerHighsSolver: () => q,
1254
+ registerMockSolver: () => Z,
1206
1255
  registerSolver: () => d,
1207
1256
  resolveBrowserWasmUrl: () => _,
1208
1257
  setDefaultSolver: () => l,
1209
1258
  setHighsWasmUrl: () => y,
1210
- solveLp: () => R,
1259
+ solveLp: () => U,
1211
1260
  solveLpWithHighs: () => m,
1212
- sum: () => O,
1213
- value: () => be,
1214
- xor: () => r,
1215
- xsum: () => k
1216
- }), q);
1261
+ sum: () => k,
1262
+ xor: () => r
1263
+ }), Q);
1217
1264
  //#endregion
1218
- export { Q as BINARY, i as BoolExpr, o as BoolOp, n as BoolVar, Ce as CONTINUOUS, c as Constraint, V as HiGHS, B as HighsSolver, Se as INTEGER, D as LinExpr, _e as LpBinary, he as LpContinuous, ge as LpInteger, me as LpMaximize, Y as LpMinimize, xe as LpProblem, ve as LpStatus, ye as LpVariable, Z as MAXIMIZE, X as MINIMIZE, $ as MipModel, G as MockSolver, J as Model, b as OFFICIAL_HIGHS_CDN_WASM_URL, E as QuadExpr, j as Var, e as and, se as c, ce as expr, F as generateLpString, g as getHighs, v as getHighsWasmUrl, f as getSolver, a as implies, h as isValidWasmHeader, u as listAvailableSolvers, A as lpSum, we as maximize, Te as minimize, s as not, t as or, N as parseConstraint, M as parseExpr, p as probeWasmUrl, d as registerSolver, _ as resolveBrowserWasmUrl, l as setDefaultSolver, y as setHighsWasmUrl, m as solveLpWithHighs, O as sum, be as value, r as xor, k as xsum };
1265
+ export { i as BoolExpr, o as BoolOp, n as BoolVar, c as Constraint, K as HiGHS, G as HighsSolver, O as LinExpr, X as MockSolver, $ as Model, b as OFFICIAL_HIGHS_CDN_WASM_URL, D as QuadExpr, j as Var, e as and, L as c, A as dot, R as expr, B as generateLpString, g as getHighs, v as getHighsWasmUrl, f as getSolver, a as implies, h as isValidWasmHeader, u as listAvailableSolvers, T as normalizeSense, s as not, t as or, F as parseConstraint, P as parseExpr, p as probeWasmUrl, d as registerSolver, _ as resolveBrowserWasmUrl, l as setDefaultSolver, y as setHighsWasmUrl, m as solveLpWithHighs, k as sum, r as xor };