@ohtaman/washi 0.6.0 → 0.7.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 (59) hide show
  1. package/README.ja.md +103 -421
  2. package/README.md +103 -421
  3. package/README.zh-CN.md +103 -421
  4. package/THIRD_PARTY_LICENSES.md +5 -3
  5. package/dist/browser/solvers/glpk.js +2 -2
  6. package/dist/browser/solvers/glpk.min.js +1 -1
  7. package/dist/browser/washi.js +777 -261
  8. package/dist/browser/washi.min.js +3 -3
  9. package/dist/lib/{registry-C20sxTwm.js → registry-D7TZ3Wh_.js} +88 -18
  10. package/dist/lib/solvers/glpk.js +3 -3
  11. package/dist/lib/solvers/z3.js +1 -1
  12. package/dist/lib/washi.js +864 -421
  13. package/dist/types/index.d.ts +1 -1
  14. package/dist/types/index.d.ts.map +1 -1
  15. package/dist/types/modeler/expression.d.ts +47 -26
  16. package/dist/types/modeler/expression.d.ts.map +1 -1
  17. package/dist/types/modeler/index.d.ts +2 -2
  18. package/dist/types/modeler/index.d.ts.map +1 -1
  19. package/dist/types/modeler/model.d.ts +12 -6
  20. package/dist/types/modeler/model.d.ts.map +1 -1
  21. package/dist/types/modeler/parser.d.ts +25 -5
  22. package/dist/types/modeler/parser.d.ts.map +1 -1
  23. package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
  24. package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
  25. package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
  26. package/dist/types/modeler/solvers/types.d.ts +2 -0
  27. package/dist/types/modeler/solvers/types.d.ts.map +1 -1
  28. package/docs/examples/diet-sensitivity.md +15 -14
  29. package/docs/examples/ecommerce-coupons.md +15 -22
  30. package/docs/examples/index.md +14 -12
  31. package/docs/examples/knapsack.md +8 -7
  32. package/docs/examples/portfolio-qp.md +11 -4
  33. package/docs/examples/production.md +4 -4
  34. package/docs/examples/shift-scheduling.md +20 -7
  35. package/docs/examples/smt-security.md +16 -4
  36. package/docs/examples/transportation.md +46 -19
  37. package/docs/examples/traveling-salesperson.md +28 -44
  38. package/docs/examples/unsat-core.md +15 -5
  39. package/docs/examples/vehicle-routing.md +10 -8
  40. package/docs/getting-started/ai-agents.md +25 -14
  41. package/docs/getting-started/cross-origin.md +56 -28
  42. package/docs/getting-started/index.md +40 -69
  43. package/docs/getting-started/runtimes.md +66 -61
  44. package/docs/guide/constraints.md +46 -40
  45. package/docs/guide/decomposition.md +127 -259
  46. package/docs/guide/expressions.md +90 -39
  47. package/docs/guide/formulation-tips.md +212 -0
  48. package/docs/guide/objectives.md +7 -4
  49. package/docs/guide/unsat-core.md +18 -6
  50. package/docs/guide/variables.md +33 -38
  51. package/docs/ja/getting-started/ai-agents.md +24 -14
  52. package/docs/solvers/highs.md +27 -6
  53. package/docs/solvers/index.md +1 -1
  54. package/docs/solvers/z3.md +3 -0
  55. package/docs/zh/getting-started/ai-agents.md +24 -14
  56. package/llms-full.txt +929 -687
  57. package/llms.txt +21 -19
  58. package/package.json +3 -3
  59. package/skills/washi/SKILL.md +14 -10
@@ -479,37 +479,107 @@ var m = class e {
479
479
  function g(e, t) {
480
480
  let n = /* @__PURE__ */ new Map(), r = 0;
481
481
  function i(e) {
482
+ return e instanceof d || e.kind === "constraint" || "sense" in e && (e.sense === "<=" || e.sense === ">=" || e.sense === "==") && "lhs" in e && "rhs" in e && typeof e.rhs == "number" && typeof e.lhs == "object" && e.lhs !== null && "terms" in e.lhs && e.lhs.terms instanceof Map;
483
+ }
484
+ function a(e) {
485
+ return e instanceof m || "quadTerms" in e && e.quadTerms instanceof Map && "linearTerms" in e && e.linearTerms instanceof Map && typeof e.constant == "number";
486
+ }
487
+ function o(e) {
488
+ return e instanceof h || "terms" in e && e.terms instanceof Map && typeof e.constant == "number";
489
+ }
490
+ function s(e) {
491
+ return e instanceof F || !i(e) && typeof e.id == "number" && typeof e.name == "string" && typeof e.lb == "number" && typeof e.ub == "number" && typeof e.type == "string" && typeof e.mul == "function";
492
+ }
493
+ function c(e) {
494
+ return i(e) || a(e) || o(e) || s(e);
495
+ }
496
+ function l(e) {
497
+ if (typeof e != "object" || !e || Array.isArray(e) || c(e)) return !1;
498
+ let t = Object.getPrototypeOf(e);
499
+ return t === Object.prototype || t === null;
500
+ }
501
+ function u(e) {
482
502
  if (e != null) {
483
- if (typeof e == "number") r += e;
484
- else if (e instanceof d || typeof e == "object" && "sense" in e && "lhs" in e && "rhs" in e) throw Error("Cannot sum a constraint comparison (<=, >=, ==) in sum(): expected a number, Var, or LinExpr.");
485
- else if (e instanceof m || typeof e == "object" && "quadTerms" in e && e.quadTerms instanceof Map) {
503
+ if (typeof e == "number") {
504
+ if (!Number.isFinite(e)) throw Error(`Invalid non-finite number "${e}" in sum().`);
505
+ let t = r + e;
506
+ if (!Number.isFinite(t)) throw Error("Constant accumulation overflows finite floating-point range in sum().");
507
+ r = t;
508
+ } else if (typeof e == "object" && i(e)) throw Error("Cannot sum a constraint comparison (<=, >=, ==) in sum(): expected a number, Var, or LinExpr.");
509
+ else if (typeof e == "object" && a(e)) {
486
510
  let t = e;
487
511
  if (t.quadTerms.size > 0) throw Error("Quadratic expressions are not supported in sum(): sum() produces a linear expression (LinExpr).");
512
+ if (!Number.isFinite(t.constant)) throw Error(`Invalid non-finite constant "${t.constant}" in sum().`);
488
513
  for (let [e, r] of t.linearTerms) {
489
- let t = n.get(e) ?? 0;
490
- n.set(e, t + r);
514
+ if (!Number.isFinite(r)) throw Error(`Invalid non-finite coefficient "${r}" in sum().`);
515
+ let t = (n.get(e) ?? 0) + r;
516
+ if (!Number.isFinite(t)) throw Error("Coefficient accumulation overflows finite floating-point range in sum().");
517
+ n.set(e, t);
491
518
  }
492
- r += t.constant;
493
- } else if (typeof e == "object" && "terms" in e) {
519
+ let i = r + t.constant;
520
+ if (!Number.isFinite(i)) throw Error("Constant accumulation overflows finite floating-point range in sum().");
521
+ r = i;
522
+ } else if (typeof e == "object" && o(e)) {
494
523
  let t = e;
524
+ if (!Number.isFinite(t.constant)) throw Error(`Invalid non-finite constant "${t.constant}" in sum().`);
495
525
  for (let [e, r] of t.terms) {
496
- let t = n.get(e) ?? 0;
497
- n.set(e, t + r);
526
+ if (!Number.isFinite(r)) throw Error(`Invalid non-finite coefficient "${r}" in sum().`);
527
+ let t = (n.get(e) ?? 0) + r;
528
+ if (!Number.isFinite(t)) throw Error("Coefficient accumulation overflows finite floating-point range in sum().");
529
+ n.set(e, t);
498
530
  }
499
- r += t.constant;
500
- } else if (typeof e == "object" && "id" in e && "name" in e && "lb" in e && "ub" in e) {
501
- let t = e, r = n.get(t) ?? 0;
502
- n.set(t, r + 1);
531
+ let i = r + t.constant;
532
+ if (!Number.isFinite(i)) throw Error("Constant accumulation overflows finite floating-point range in sum().");
533
+ r = i;
534
+ } else if (typeof e == "object" && s(e)) {
535
+ let t = e, r = (n.get(t) ?? 0) + 1;
536
+ if (!Number.isFinite(r)) throw Error("Coefficient accumulation overflows finite floating-point range in sum().");
537
+ n.set(t, r);
503
538
  } else throw Error("Unsupported item in sum(): expected a number, Var, or LinExpr.");
504
539
  }
505
540
  }
541
+ function f(e, t = 0) {
542
+ if (e != null) {
543
+ if (typeof e == "number") {
544
+ u(e);
545
+ return;
546
+ }
547
+ if (typeof e == "object") {
548
+ if (c(e)) {
549
+ u(e);
550
+ return;
551
+ }
552
+ if (!(e instanceof String) && !(e instanceof Map) && Symbol.iterator in e && typeof e[Symbol.iterator] == "function") {
553
+ if (t >= 2) throw Error("Nested containers deeper than 2D are not supported in sum().");
554
+ for (let n of e) f(n, t + 1);
555
+ return;
556
+ }
557
+ if (l(e)) {
558
+ if (t >= 2) throw Error("Nested containers deeper than 2D are not supported in sum().");
559
+ if (Object.getOwnPropertySymbols(e).length > 0) throw Error("Symbol keys are not supported in sum().");
560
+ for (let n of Object.keys(e)) f(e[n], t + 1);
561
+ return;
562
+ }
563
+ }
564
+ u(e);
565
+ }
566
+ }
506
567
  if (typeof e == "number") {
507
- let n = e, r = t;
508
- for (let e = 0; e < n; e++) i(r(e, e));
509
- } else {
568
+ if (typeof t != "function") throw Error("sum(count, mapFn) requires a mapping function as the second argument.");
569
+ if (!Number.isInteger(e) || e < 0) throw Error("sum(count, mapFn) requires a non-negative integer count.");
570
+ let n = e;
571
+ for (let e = 0; e < n; e++) f(t(e, e), 0);
572
+ } else if (typeof e == "object" && e && !(e instanceof String) && (!(e instanceof Map) || typeof t == "function") && Symbol.iterator in e && typeof e[Symbol.iterator] == "function") {
510
573
  let n = 0;
511
- for (let r of e) i(t ? t(r, n++) : r);
512
- }
574
+ for (let r of e) t ? f(t(r, n++), 0) : f(r, 1);
575
+ } else if (l(e)) {
576
+ if (Object.getOwnPropertySymbols(e).length > 0) throw Error("Symbol keys are not supported in sum().");
577
+ let n = 0;
578
+ for (let r of Object.keys(e)) {
579
+ let i = e[r];
580
+ t ? f(t(i, n++), 0) : f(i, 1);
581
+ }
582
+ } else throw Error("Unsupported item in sum(): expected an Iterable, Record, or (count, mapFn).");
513
583
  for (let [e, t] of n) t === 0 && n.delete(e);
514
584
  return new h(n, r);
515
585
  }
@@ -1,4 +1,4 @@
1
- import { a as e, r as t, s as n } from "../registry-C20sxTwm.js";
1
+ import { a as e, r as t, s as n } from "../registry-D7TZ3Wh_.js";
2
2
  //#region src/modeler/solvers/glpk/loader.ts
3
3
  var r = null, i = null;
4
4
  async function a() {
@@ -211,8 +211,8 @@ var l = class t {
211
211
  B = !1;
212
212
  break;
213
213
  }
214
- let n = f.get(e);
215
- c(z, n ? n.name : e, Math.abs(t) < 1e-9 ? 0 : t);
214
+ let n = f.get(e), r = n ? n.name : e, i = Math.abs(t) < 1e-9 ? 0 : t;
215
+ !l.relax && n && (n.type === "Integer" || n.type === "Binary") && Math.abs(i - Math.round(i)) <= 1e-5 && (i = Math.round(i) + 0), c(z, r, i);
216
216
  }
217
217
  if (B) for (let e of t.variables) {
218
218
  let t = p.get(e) || e.name;
@@ -1,4 +1,4 @@
1
- import { D as e, O as t, T as n, r, s as i } from "../registry-C20sxTwm.js";
1
+ import { D as e, O as t, T as n, r, s as i } from "../registry-D7TZ3Wh_.js";
2
2
  import { getBundledZ3AssetUrls as a } from "./z3-assets.js";
3
3
  //#region src/modeler/solvers/z3/loader.ts
4
4
  var o = null, s = null, c = null, l = null, u = /* @__PURE__ */ new WeakMap();