@ohtaman/washi 0.9.0 → 0.10.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 (117) hide show
  1. package/README.md +9 -10
  2. package/THIRD_PARTY_LICENSES.md +4 -4
  3. package/dist/{browser/washi.js → core-b430-tAc.js} +656 -661
  4. package/dist/solvers/browser-_washi-browser-node-runtime-BOEcR5J2.js +28 -0
  5. package/dist/solvers/browser-browser-worker-CT6498Is.js +13 -0
  6. package/dist/{lib/solvers/loader-b5PNpCmX.js → solvers/browser-loader-D21chr4P.js} +12 -23
  7. package/dist/{lib/solvers/loader-DCtyxsfF.js → solvers/browser-loader-DWFhT0yY.js} +13 -13
  8. package/dist/solvers/browser-lp-writer-DH_1sdsF.js +115 -0
  9. package/dist/solvers/glpk.js +310 -0
  10. package/dist/{lib/solvers/glpk.js → solvers/glpk.node.js} +5 -9
  11. package/dist/{lib/solvers/__vite-browser-external-oLchLuMx.js → solvers/highs-browser-__vite-browser-external-Cu-Zq4Hm.js} +1 -1
  12. package/dist/solvers/highs-browser-runtime.js +2410 -0
  13. package/dist/{lib/solvers → solvers}/highs-node-runtime.js +1 -1
  14. package/dist/{lib/solvers → solvers}/highs-worker.js +2 -2
  15. package/dist/{lib/solvers → solvers}/highs.js +64 -70
  16. package/dist/{browser/solvers/highs-loader-Csn3-0tq.js → solvers/highs.node.js} +520 -138
  17. package/dist/solvers/node-browser-worker-CN93BPoO.js +54 -0
  18. package/dist/{lib/solvers/lp-writer-CLScMFbS.js → solvers/node-lp-writer-CqMLgMIk.js} +1 -1
  19. package/dist/solvers/node-node-runtime-BUlNfXvx.js +10 -0
  20. package/dist/solvers/node-registry-CrYRRk9q.js +907 -0
  21. package/dist/solvers/node-types-BGqPkxwu.js +12 -0
  22. package/dist/{lib/solvers → solvers}/pumpkin-node-runtime.js +1 -1
  23. package/dist/{browser/solvers → solvers}/pumpkin-worker.js +2 -1
  24. package/dist/{lib/solvers → solvers}/pumpkin.js +174 -164
  25. package/dist/solvers/pumpkin.node.js +1228 -0
  26. package/dist/{lib/solvers → solvers}/z3.js +123 -120
  27. package/dist/types/core.d.ts +11 -0
  28. package/dist/types/core.d.ts.map +1 -0
  29. package/dist/types/index.d.ts +3 -4
  30. package/dist/types/index.d.ts.map +1 -1
  31. package/dist/types/modeler/core.d.ts +14 -0
  32. package/dist/types/modeler/core.d.ts.map +1 -0
  33. package/dist/types/modeler/index.d.ts +1 -13
  34. package/dist/types/modeler/index.d.ts.map +1 -1
  35. package/dist/types/modeler/model.d.ts +1 -1
  36. package/dist/types/modeler/model.d.ts.map +1 -1
  37. package/dist/types/modeler/solvers/browser-worker.d.ts +17 -0
  38. package/dist/types/modeler/solvers/browser-worker.d.ts.map +1 -0
  39. package/dist/types/modeler/solvers/glpk/loader.d.ts +2 -2
  40. package/dist/types/modeler/solvers/glpk/node-runtime.d.ts +5 -0
  41. package/dist/types/modeler/solvers/glpk/node-runtime.d.ts.map +1 -0
  42. package/dist/types/modeler/solvers/highs/worker-client.d.ts +5 -5
  43. package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
  44. package/dist/types/modeler/solvers/pumpkin/loader.d.ts +0 -4
  45. package/dist/types/modeler/solvers/pumpkin/loader.d.ts.map +1 -1
  46. package/dist/types/modeler/solvers/pumpkin/solver.d.ts.map +1 -1
  47. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts +4 -3
  48. package/dist/types/modeler/solvers/pumpkin/worker-client.d.ts.map +1 -1
  49. package/dist/types/modeler/solvers/types.d.ts +5 -1
  50. package/dist/types/modeler/solvers/types.d.ts.map +1 -1
  51. package/dist/types/modeler/solvers/z3/loader.d.ts +3 -8
  52. package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
  53. package/dist/types/modeler/solvers/z3/solver.d.ts +3 -2
  54. package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -1
  55. package/dist/types/modeler/types.d.ts +18 -3
  56. package/dist/types/modeler/types.d.ts.map +1 -1
  57. package/dist/washi.js +4 -0
  58. package/dist/washi.min.js +6 -0
  59. package/dist/washi.node.js +4 -0
  60. package/docs/getting-started/ai-agents.md +23 -22
  61. package/docs/getting-started/coding-agents.md +26 -17
  62. package/docs/getting-started/cross-origin.md +2 -1
  63. package/docs/getting-started/index.md +3 -1
  64. package/docs/getting-started/runtimes.md +53 -63
  65. package/docs/guide/objectives.md +3 -3
  66. package/docs/solvers/custom-solver.md +4 -9
  67. package/docs/solvers/glpk.md +2 -0
  68. package/docs/solvers/highs.md +8 -10
  69. package/docs/solvers/index.md +1 -1
  70. package/docs/solvers/pumpkin.md +7 -7
  71. package/docs/solvers/z3.md +18 -1
  72. package/llms-full.txt +124 -118
  73. package/llms.txt +23 -22
  74. package/package.json +31 -64
  75. package/skills/washi/SKILL.md +18 -18
  76. package/skills/washi/references/single-html.md +7 -12
  77. package/dist/browser/solvers/glpk.js +0 -1263
  78. package/dist/browser/solvers/glpk.min.js +0 -1
  79. package/dist/browser/solvers/highs-__vite-browser-external-xcxOpLMD.js +0 -7
  80. package/dist/browser/solvers/highs-browser-runtime-ccRmE4qj.js +0 -2021
  81. package/dist/browser/solvers/highs-worker.js +0 -55
  82. package/dist/browser/solvers/highs.js +0 -1454
  83. package/dist/browser/solvers/pumpkin-_washi-pumpkin-node-runtime-CEKUDK6d.js +0 -9
  84. package/dist/browser/solvers/pumpkin-loader-BI3n3dWO.js +0 -401
  85. package/dist/browser/solvers/pumpkin.js +0 -1796
  86. package/dist/browser/solvers/z3-built.js +0 -8245
  87. package/dist/browser/solvers/z3-built.wasm +0 -4
  88. package/dist/browser/solvers/z3.js +0 -7842
  89. package/dist/browser/solvers/z3.min.js +0 -5
  90. package/dist/browser/washi.min.js +0 -6
  91. package/dist/lib/solvers/highs-browser-runtime.js +0 -2413
  92. package/dist/lib/solvers/highs.wasm +0 -0
  93. package/dist/lib/solvers/highs.wasm.LICENSE +0 -21
  94. package/dist/lib/solvers/pumpkin-worker.js +0 -47
  95. package/dist/lib/solvers/pumpkin.wasm +0 -0
  96. package/dist/lib/solvers/pumpkin.wasm.LICENSE +0 -21
  97. package/dist/lib/solvers/z3-assets.js +0 -1
  98. package/dist/lib/solvers/z3-built.js +0 -8245
  99. package/dist/lib/solvers/z3-built.wasm +0 -4
  100. package/dist/lib/washi.js +0 -5662
  101. package/dist/types/modeler/solvers/z3/assets.d.ts +0 -11
  102. package/dist/types/modeler/solvers/z3/assets.d.ts.map +0 -1
  103. /package/dist/{lib/solvers/embedded-wasm-CSFlLV5N.js → solvers/browser-embedded-wasm-CSFlLV5N.js} +0 -0
  104. /package/dist/{lib/solvers/registry-CrYRRk9q.js → solvers/browser-registry-CrYRRk9q.js} +0 -0
  105. /package/dist/{lib/solvers/types-BGqPkxwu.js → solvers/browser-types-BGqPkxwu.js} +0 -0
  106. /package/dist/{lib/solvers → solvers}/highs-assets.js +0 -0
  107. /package/dist/{lib/solvers/rolldown-runtime-DtPi1Y-2.js → solvers/highs-browser-rolldown-runtime-DtPi1Y-2.js} +0 -0
  108. /package/dist/{browser/solvers → solvers}/highs-inline.js +0 -0
  109. /package/dist/{lib/solvers → solvers}/highs-runtime.js +0 -0
  110. /package/dist/{lib/solvers → solvers}/highs-worker-factory.js +0 -0
  111. /package/dist/{browser/solvers → solvers}/highs.wasm +0 -0
  112. /package/dist/{browser/solvers → solvers}/highs.wasm.LICENSE +0 -0
  113. /package/dist/{lib/solvers → solvers}/pumpkin-assets.js +0 -0
  114. /package/dist/{browser/solvers → solvers}/pumpkin-inline.js +0 -0
  115. /package/dist/{lib/solvers → solvers}/pumpkin-worker-factory.js +0 -0
  116. /package/dist/{browser/solvers → solvers}/pumpkin.wasm +0 -0
  117. /package/dist/{browser/solvers → solvers}/pumpkin.wasm.LICENSE +0 -0
@@ -1,6 +0,0 @@
1
- var Washi=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.defineProperty,n=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},r=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r};function i(e){if(e===void 0)return`Minimize`;if(typeof e==`string`){let t=e.toLowerCase();if(t===`maximize`)return`Maximize`;if(t===`minimize`)return`Minimize`}throw Error(`Invalid optimization sense "${String(e)}": expected "Maximize", "Minimize", "maximize", or "minimize".`)}var a=0;function o(e,t){if(e instanceof s||e instanceof I)return e;throw typeof e==`object`&&e&&(`terms`in e||`quadTerms`in e)?Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical operator "${t}". Use a comparison constraint such as expr\`\${x} <= 10\` or a BoolVar/BoolExpr.`):typeof e==`object`&&e&&`id`in e&&`name`in e&&`lb`in e&&`ub`in e&&!(`sense`in e)?Error(`Invalid operand passed to logical operator "${t}": expected a BoolVar, BoolExpr, or Constraint, but received numeric variable "${e.name}". Use m.bool() for propositional variables, add a comparison such as expr\`\${x} == 1\`, or use m.indicator(binVar, constraint) for 0-1 Big-M indicator constraints.`):Error(`Invalid operand passed to logical operator "${t}": expected a BoolVar, BoolExpr, or Constraint.`)}var s=class{and(e){return new l(`and`,[this,o(e,`and`)])}or(e){return new l(`or`,[this,o(e,`or`)])}implies(e){return new l(`implies`,[this,o(e,`implies`)])}xor(e){return new l(`xor`,[this,o(e,`xor`)])}not(){return new l(`not`,[this])}},c=class extends s{id;type=`Boolean`;name;value=null;constructor(e){super(),this.id=++a,this.name=e||`p_${this.id}`}toString(){return this.name}},l=class extends s{op;children;constructor(e,t){super(),this.op=e,this.children=t.map(t=>o(t,e))}toString(){return this.op===`not`?`not(${this.children[0].toString()})`:`(${this.children.map(e=>e.toString()).join(` ${this.op} `)})`}};function u(...e){if(e.length===0)throw Error(`and() requires at least one expression`);return new l(`and`,e)}function d(...e){if(e.length===0)throw Error(`or() requires at least one expression`);return new l(`or`,e)}function f(e){return new l(`not`,[e])}function p(e,t){return new l(`implies`,[e,t])}function m(...e){if(e.length===0)throw Error(`xor() requires at least one expression`);return new l(`xor`,e)}var h=class extends s{spec;discreteVars;constructor(e,t){super(),this.spec=e,this.discreteVars=t}toString(){switch(this.spec.kind){case`distinct`:return`distinct(${this.spec.args.map(e=>e.toString()).join(`, `)})`;case`disjoint`:return`disjoint([${this.spec.tasks.map(e=>`{ start: ${e.start.toString()}, duration: ${e.duration} }`).join(`, `)}])`;case`cumulative`:return`cumulative([${this.spec.tasks.map(e=>`{ start: ${e.start.toString()}, duration: ${e.duration}, demand: ${e.demand} }`).join(`, `)}], ${this.spec.capacity})`;case`allowed`:return`allowed([${this.spec.vars.map(e=>e.toString()).join(`, `)}], [${this.spec.tuples.map(e=>`[${e.join(`, `)}]`).join(`, `)}])`}}};function g(e){if(typeof e!=`object`||!e||Array.isArray(e)||e instanceof I||e instanceof s||e instanceof z)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function _(e){return typeof e==`number`||e instanceof I||e instanceof z||typeof e==`object`&&!!e&&(`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&&!(`sense`in e))}function v(...e){if(e.length===0)throw Error(`distinct() requires at least one expression or container.`);let t=[],n=new Set,r=(e,i)=>{if(e==null)throw Error(`Unsupported nullish item in distinct(): expected an integer-valued expression.`);if(_(e)){let r=he(e,`distinct()`);R(r,`distinct()`,n),t.push(r);return}if(Array.isArray(e)){if(i>=2)throw Error(`Nested containers deeper than 2D are not supported in distinct().`);for(let t=0;t<e.length;t++){if(!(t in e))throw Error(`Unsupported item in distinct(): sparse array hole at index ${t}.`);r(e[t],i+1)}return}if(typeof e==`object`&&!(e instanceof String)&&!(e instanceof Map)&&Symbol.iterator in e&&typeof e[Symbol.iterator]==`function`){if(i>=2)throw Error(`Nested containers deeper than 2D are not supported in distinct().`);for(let t of e)r(t,i+1);return}if(g(e)){if(i>=2)throw Error(`Nested containers deeper than 2D are not supported in distinct().`);if(Object.getOwnPropertySymbols(e).length>0)throw Error(`Symbol keys are not supported in distinct().`);for(let t of Object.keys(e))r(e[t],i+1);return}throw Error(`Unsupported item in distinct(): expected an integer-valued expression or container.`)};for(let t of e)r(t,0);return new h({kind:`distinct`,args:t},n)}function y(e,t){if(e==null)throw Error(`${t}(tasks) requires an Array, Iterable, or Record of task objects.`);if(Array.isArray(e)){let n=[];for(let r=0;r<e.length;r++){if(!(r in e))throw Error(`${t}(tasks) encountered sparse array hole at index ${r}.`);n.push(e[r])}return n}if(typeof e==`object`&&!(e instanceof String)&&!(e instanceof Map)&&Symbol.iterator in e&&typeof e[Symbol.iterator]==`function`)return Array.from(e);if(g(e)){if(`start`in e&&`duration`in e)throw Error(`${t}(tasks) expects an Array, Iterable, or Record of task objects, not a single task object.`);if(Object.getOwnPropertySymbols(e).length>0)throw Error(`Symbol keys are not supported in ${t}().`);return Object.keys(e).map(t=>e[t])}throw Error(`${t}(tasks) requires an Array, Iterable, or Record of task objects.`)}function b(e){let t=y(e,`disjoint`),n=new Set,r=[];for(let e=0;e<t.length;e++){let i=t[e];if(typeof i!=`object`||!i||!(`start`in i)||!(`duration`in i))throw Error(`disjoint() task at index ${e} must be an object with { start, duration }.`);let a=i,o=he(a.start,`disjoint() task[${e}].start`);if(R(o,`disjoint() task[${e}].start`,n),typeof a.duration!=`number`||!Number.isSafeInteger(a.duration)||a.duration<0)throw Error(`disjoint() task[${e}].duration must be a finite non-negative integer, received ${String(a.duration)}.`);r.push({start:o,duration:Object.is(a.duration,-0)?0:a.duration})}return new h({kind:`disjoint`,tasks:r},n)}function x(e,t){if(typeof t!=`number`||!Number.isSafeInteger(t)||t<0)throw Error(`cumulative() capacity must be a finite non-negative integer, received ${String(t)}.`);let n=y(e,`cumulative`),r=new Set,i=[];for(let e=0;e<n.length;e++){let t=n[e];if(typeof t!=`object`||!t||!(`start`in t)||!(`duration`in t)||!(`demand`in t))throw Error(`cumulative() task at index ${e} must be an object with { start, duration, demand }.`);let a=t,o=he(a.start,`cumulative() task[${e}].start`);if(R(o,`cumulative() task[${e}].start`,r),typeof a.duration!=`number`||!Number.isSafeInteger(a.duration)||a.duration<0)throw Error(`cumulative() task[${e}].duration must be a finite non-negative integer, received ${String(a.duration)}.`);if(typeof a.demand!=`number`||!Number.isSafeInteger(a.demand)||a.demand<0)throw Error(`cumulative() task[${e}].demand must be a finite non-negative integer, received ${String(a.demand)}.`);i.push({start:o,duration:Object.is(a.duration,-0)?0:a.duration,demand:Object.is(a.demand,-0)?0:a.demand})}return new h({kind:`cumulative`,tasks:i,capacity:Object.is(t,-0)?0:t},r)}function S(e,t){if(!Array.isArray(e)||e.length===0)throw Error(`allowed(vars, tuples) requires a non-empty Array of expressions as its first argument.`);let n=new Set,r=Array(e.length);for(let t=0;t<e.length;t++){if(!(t in e))throw Error(`allowed() vars encountered sparse array hole at index ${t}.`);let i=he(e[t],`allowed() vars[${t}]`);R(i,`allowed() vars[${t}]`,n),r[t]=i}if(typeof t!=`object`||!t||t instanceof String||!(Symbol.iterator in t)||typeof t[Symbol.iterator]!=`function`)throw Error(`allowed(vars, tuples) requires an Iterable of integer tuples as its second argument.`);let i=[],a=0;for(let n of t){if(!Array.isArray(n)||n.length!==e.length)throw Error(`allowed() tuple at index ${a} must be an Array of length ${e.length}.`);let t=Array(e.length);for(let r=0;r<e.length;r++){if(!(r in n))throw Error(`allowed() tuple[${a}] encountered sparse array hole at index ${r}.`);let e=n[r];if(typeof e!=`number`||!Number.isSafeInteger(e))throw Error(`allowed() tuple[${a}][${r}] must be a safe integer, received ${String(e)}.`);t[r]=Object.is(e,-0)?0:e}i.push(t),a++}return new h({kind:`allowed`,vars:r,tuples:i},n)}function C(e,t){let n=e.id,r=t.id;return n<=r?`${n}:${r}`:`${r}:${n}`}var w=class e{kind=`quadratic`;linearTerms;quadTerms;constant;nonlinearTerms;constructor(e=new Map,t=new Map,n=0,r=[]){this.linearTerms=new Map(e),this.quadTerms=new Map;for(let[e,n]of t)this.quadTerms.set(e,{...n});this.constant=n,this.nonlinearTerms=r.filter(e=>e.coeff!==0).map(e=>({atom:L(e.atom),coeff:e.coeff}))}hasNonlinearTerms(){return this.nonlinearTerms.length>0}clone(){return new e(this.linearTerms,this.quadTerms,this.constant,this.nonlinearTerms)}getQuadCoeff(e,t){let n=C(e,t),r=this.quadTerms.get(n);return r?r.coeff:0}add(t){if(de(t))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);let n=this.clone();if(typeof t==`number`)return n.constant+=t,n;if(t instanceof e){for(let[e,r]of t.quadTerms){let t=n.quadTerms.get(e),i=(t?t.coeff:0)+r.coeff;i===0?n.quadTerms.delete(e):n.quadTerms.set(e,{var1:r.var1,var2:r.var2,coeff:i})}for(let[e,r]of t.linearTerms){let t=(n.linearTerms.get(e)??0)+r;t===0?n.linearTerms.delete(e):n.linearTerms.set(e,t)}if(n.constant+=t.constant,Array.isArray(t.nonlinearTerms))for(let e of t.nonlinearTerms)e.coeff!==0&&n.nonlinearTerms.push({atom:L(e.atom),coeff:e.coeff});return n}if(`terms`in t&&t.terms instanceof Map){for(let[e,r]of t.terms){let t=(n.linearTerms.get(e)??0)+r;t===0?n.linearTerms.delete(e):n.linearTerms.set(e,t)}if(n.constant+=t.constant,Array.isArray(t.nonlinearTerms))for(let e of t.nonlinearTerms)e.coeff!==0&&n.nonlinearTerms.push({atom:L(e.atom),coeff:e.coeff});return n}let r=t,i=(n.linearTerms.get(r)??0)+1;return i===0?n.linearTerms.delete(r):n.linearTerms.set(r,i),n}sub(e){if(de(e))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);return typeof e==`number`?this.add(-e):this.add(e.mul(-1))}mul(t){if(de(t))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);if(typeof t==`number`){let n=this.linearTerms.size>0||this.quadTerms.size>0||this.nonlinearTerms.length>0,r=this.constant===0&&n?0:this.constant*t;if(this.constant!==0&&t!==0&&r===0)throw Error(`Constant multiplication underflows to zero.`);let i=new e(new Map,new Map,r);for(let[e,n]of this.linearTerms){let r=n*t;if(n!==0&&t!==0&&r===0)throw Error(`Coefficient multiplication underflows to zero.`);r!==0&&i.linearTerms.set(e,r)}for(let[e,n]of this.quadTerms){let r=n.coeff*t;if(n.coeff!==0&&t!==0&&r===0)throw Error(`Coefficient multiplication underflows to zero.`);r!==0&&i.quadTerms.set(e,{var1:n.var1,var2:n.var2,coeff:r})}if(t!==0)for(let e of this.nonlinearTerms){let n=e.coeff*t;if(e.coeff!==0&&n===0)throw Error(`Coefficient multiplication underflows to zero.`);n!==0&&i.nonlinearTerms.push({atom:L(e.atom),coeff:n})}return i}let n=`id`in t&&`name`in t&&!(`terms`in t)&&!(`quadTerms`in t),r=`quadTerms`in t?t.quadTerms.size:0,i=!n&&`nonlinearTerms`in t&&Array.isArray(t.nonlinearTerms)?t.nonlinearTerms.length:0,a=n?new Map([[t,1]]):`quadTerms`in t?t.linearTerms:t.terms,o=n?0:t.constant;if(this.nonlinearTerms.length>0){if(!n&&r===0&&a.size===0&&i===0)return this.mul(o);throw Error(`Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.`)}if(i>0){if(this.quadTerms.size===0&&this.linearTerms.size===0){let n=t.mul(this.constant);return`quadTerms`in n?n:new e(n.terms,new Map,n.constant,n.nonlinearTerms)}throw Error(`Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.`)}if(this.quadTerms.size>0&&(r>0||a.size>0)||r>0&&this.linearTerms.size>0)throw Error(`Multiplication creates a non-linear term of degree > 2 (not allowed in MILP/LP/QP)`);if(r===0&&a.size===0)return this.mul(o);if(this.quadTerms.size===0&&this.linearTerms.size===0&&!n){let n=t.mul(this.constant);return`quadTerms`in n?n:new e(n.terms,new Map,n.constant,n.nonlinearTerms)}return e.multiplyLinearTerms(this.constant,this.linearTerms,o,a)}div(t){let n=e.extractScalarDivisor(t,`QuadExpr.div()`);return this.mul(1/n)}neg(){return this.mul(-1)}get value(){let e=this.constant;for(let[t,n]of this.linearTerms){if(t.value===null)return null;e+=n*t.value}for(let t of this.quadTerms.values()){if(t.var1.value===null||t.var2.value===null)return null;e+=t.coeff*t.var1.value*t.var2.value}for(let t of this.nonlinearTerms){let n=pe(t.atom);if(n===null)return null;e+=t.coeff*n}return e}le(e,t){return this.toConstraint(`<=`,e,t)}ge(e,t){return this.toConstraint(`>=`,e,t)}eq(e,t){return this.toConstraint(`==`,e,t)}lt(e,t){return this.toDiscreteComparison(`<`,e,t)}gt(e,t){return this.toDiscreteComparison(`>`,e,t)}ne(e,t){return this.toDiscreteComparison(`!=`,e,t)}toDiscreteComparison(e,t,n){if(this.quadTerms.size>0)throw Error(`Quadratic expressions are not supported in discrete comparisons (${e}): quadratic terms are only allowed in objectives.`);let r=new z(this.linearTerms,this.constant,this.nonlinearTerms);return e===`<`?r.lt(t,n):e===`>`?r.gt(t,n):r.ne(t,n)}toConstraint(e,t,n){if(this.quadTerms.size>0)throw Error(`Quadratic expressions are not supported in linear constraints (${e}): quadratic terms are only allowed in objectives.`);let r=new z(this.linearTerms,this.constant,this.nonlinearTerms);return e===`<=`?r.le(t,n):e===`>=`?r.ge(t,n):r.eq(t,n)}and(e){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical 'and': expected a BoolVar, Constraint, or BoolOp.`)}or(e){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical 'or': expected a BoolVar, Constraint, or BoolOp.`)}implies(e){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical 'implies': expected a BoolVar, Constraint, or BoolOp.`)}xor(e){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical 'xor': expected a BoolVar, Constraint, or BoolOp.`)}not(){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==) in logical 'not': expected a BoolVar, Constraint, or BoolOp.`)}toString(){let e=[],t=!0;for(let n of this.quadTerms.values()){let r=n.coeff,i=r>=0?t?``:`+ `:`- `,a=Math.abs(r),o=a===1?``:`${a} `;n.var1===n.var2?e.push(`${i}${o}${n.var1.name}^2`):e.push(`${i}${o}${n.var1.name} * ${n.var2.name}`),t=!1}for(let[n,r]of this.linearTerms){let i=r>=0?t?``:`+ `:`- `,a=Math.abs(r),o=a===1?``:`${a} `;e.push(`${i}${o}${n.name}`),t=!1}if(this.nonlinearTerms.length>0){let n=new z(new Map,0,this.nonlinearTerms).toString();n!==`0`&&(e.push(t?n:n.startsWith(`-`)?`- ${n.slice(2)}`:`+ ${n}`),t=!1)}if(this.constant!==0||e.length===0){let n=this.constant>=0?t?``:`+ `:`- `;e.push(`${n}${Math.abs(this.constant)}`)}return e.join(` `)||`0`}static fromProduct(t,n,r=1){let i=new e;if(r===0)return i;let a=C(t,n);return i.quadTerms.set(a,{var1:t.id<=n.id?t:n,var2:t.id<=n.id?n:t,coeff:r}),i}static multiplyLinearTerms(t,n,r,i){let a=n.size>0||i.size>0,o=(t===0||r===0)&&a?0:t*r;if(t!==0&&r!==0&&o===0)throw Error(`Constant multiplication underflows to zero.`);let s=new e(new Map,new Map,o===0?0:o);if(r!==0)for(let[e,t]of n){let n=t*r;if(t!==0&&n===0)throw Error(`Coefficient multiplication underflows to zero.`);n!==0&&s.linearTerms.set(e,n)}if(t!==0)for(let[e,n]of i){let r=s.linearTerms.get(e)??0,i=n*t;if(n!==0&&i===0)throw Error(`Coefficient multiplication underflows to zero.`);let a=r+i;a===0?s.linearTerms.delete(e):s.linearTerms.set(e,a)}for(let[t,r]of n)for(let[n,a]of i){let i=r*a;if(r!==0&&a!==0&&i===0)throw Error(`Coefficient multiplication underflows to zero.`);s=s.add(e.fromProduct(t,n,i))}return s}static extractScalarDivisor(e,t){if(de(e))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);if(typeof e==`number`){if(e===0)throw Error(`Division by zero in ${t}`);return e}let n=`quadTerms`in e?e.linearTerms.size:e.terms.size,r=`quadTerms`in e?e.quadTerms.size:0,i=`nonlinearTerms`in e&&Array.isArray(e.nonlinearTerms)?e.nonlinearTerms.length:0;if(n>0||r>0||i>0)throw Error(`Cannot divide by variable in expression`);if(e.constant===0)throw Error(`Division by zero in ${t}`);return e.constant}},T=new WeakMap,E=new WeakMap,D=new WeakMap,ee=new WeakMap;function O(e,t){ee.set(e,t)}function k(e){e&&ee.get(e)?.()}function A(e,t,n){if(e instanceof l)for(let r of e.children)A(r,t,n);else if(e instanceof I){let r=e.ownerModel,i=E.get(e);(r!==t||i!==t)&&(n&&n.push(()=>{e.ownerModel=r,i?E.set(e,i):E.delete(e)}),e.ownerModel=t,E.set(e,t))}}function te(e,t){let n=T.get(e);if(n&&n!==t)throw Error(`Variable "${e.name}" already belongs to model "${n.name}" and cannot be added to model "${t.name}".`);T.set(e,t)}function ne(e,t){let n=D.get(e);if(n)throw Error(n===t?`Constraint "${e.name}" is already registered in model "${t.name}".`:`Constraint "${e.name}" already belongs to model "${n.name}" and cannot be added to model "${t.name}".`);let r=E.get(e);if(r&&r!==t)throw Error(`Constraint "${e.name}" already belongs to model "${r.name}" and cannot be added to model "${t.name}".`);return D.set(e,t),E.set(e,t),r}function re(e,t){T.get(e)===t&&T.delete(e)}function ie(e,t,n){D.get(e)===t&&D.delete(e),E.get(e)===t&&(n?E.set(e,n):E.delete(e))}var j=1e-6;function M(e){if(typeof e.lb!=`number`||Number.isNaN(e.lb))throw Error(`Variable "${e.name}" has invalid lower bound: ${e.lb} (NaN or non-numeric bound is not allowed).`);if(e.lb===1/0)throw Error(`Variable "${e.name}" has invalid lower bound: +Infinity is not allowed as a lower bound.`);if(typeof e.ub!=`number`||Number.isNaN(e.ub))throw Error(`Variable "${e.name}" has invalid upper bound: ${e.ub} (NaN or non-numeric bound is not allowed).`);if(e.ub===-1/0)throw Error(`Variable "${e.name}" has invalid upper bound: -Infinity is not allowed as an upper bound.`);if(e.lb>e.ub)throw Error(`Variable "${e.name}" has invalid bounds: lower bound (${e.lb}) is strictly greater than upper bound (${e.ub}).`);if(e.initialValue!==void 0){if(typeof e.initialValue!=`number`||!Number.isFinite(e.initialValue))throw Error(`Variable "${e.name}" has invalid initialValue: ${String(e.initialValue)} (initialValue must be a finite number).`);let t=e.type===`Binary`?Math.max(0,e.lb):e.lb,n=e.type===`Binary`?Math.min(1,e.ub):e.ub;if(e.initialValue<t-1e-6||e.initialValue>n+1e-6)throw Error(`Variable "${e.name}" has initialValue (${e.initialValue}) outside its bounds [${t}, ${n}] (tolerance ${j}).`);if(e.type===`Integer`||e.type===`Binary`){let r=Math.round(e.initialValue);if(Math.abs(e.initialValue-r)>1e-6||r<t||r>n)throw Error(`Variable "${e.name}" of type "${e.type}" has non-integral or out-of-domain initialValue: ${e.initialValue} (must be within ${j} of an integer in [${t}, ${n}]).`)}}}function ae(e){if(e.initialValue===void 0)return;if(M(e),e.type===`Integer`||e.type===`Binary`){let t=Math.round(e.initialValue);return Object.is(t,-0)?0:t}let t=Math.min(e.ub,Math.max(e.lb,e.initialValue));return Object.is(t,-0)?0:t}function oe(e,t){if(e){for(let n of e)if(n.type!==`Integer`&&n.type!==`Binary`)throw Error(`${t} requires Integer or Binary variables, but variable "${n.name}" has type "${n.type}".`)}}function se(e,t,n,r){if(e&&e.length!==0)for(let i of e){if(!Number.isFinite(i.coeff))throw Error(`Nonlinear expression in ${t} has invalid coefficient: ${i.coeff}. Coefficients must be finite numbers.`);let e=i.atom;if(e.kind===`abs`)N(e.arg,t,n,r);else if(e.kind===`max`||e.kind===`min`)for(let i of e.args)N(i,t,n,r);else if(e.kind===`at`){oe(e.discreteVars,`at() index in ${t}`),N(e.index,t,n,r);for(let i of e.array)N(i,t,n,r)}}}function N(e,t,n,r,i){if(e.constant!==void 0&&!Number.isFinite(e.constant)){let n=i?.constantPrefix??t,r=i?.constantKind??`constant`;throw Error(`${n} has invalid ${r}: ${e.constant}. Constant must be a finite number.`)}let a=i?.varLocationPhrase??`in ${t}`;for(let[i,o]of e.terms){if(!r(i))throw Error(`Variable "${i.name}" ${a} does not belong to model "${n}". All variables must belong to the model by object identity.`);if(!Number.isFinite(o))throw Error(`Variable "${i.name}" in ${t} has invalid coefficient: ${o}. Coefficients must be finite numbers.`)}se(e.nonlinearTerms,t,n,r)}function P(e,t,n){if(e instanceof w){if(!Number.isFinite(e.constant))throw Error(`Objective function has invalid constant: ${e.constant}. Constant must be a finite number.`);for(let[r,i]of e.linearTerms){if(!n(r))throw Error(`Variable "${r.name}" in objective function does not belong to model "${t}". All variables must belong to the model by object identity.`);if(!Number.isFinite(i))throw Error(`Variable "${r.name}" in objective function has invalid coefficient: ${i}. Coefficients must be finite numbers.`)}for(let[,r]of e.quadTerms){if(!n(r.var1))throw Error(`Variable "${r.var1.name}" in quadratic objective function does not belong to model "${t}". All variables must belong to the model by object identity.`);if(!n(r.var2))throw Error(`Variable "${r.var2.name}" in quadratic objective function does not belong to model "${t}". All variables must belong to the model by object identity.`);if(!Number.isFinite(r.coeff)||!Number.isFinite(r.coeff*2))throw Error(`Quadratic term (${r.var1.name} * ${r.var2.name}) in objective function has invalid coefficient: ${r.coeff}.`)}se(e.nonlinearTerms,`objective function`,t,n)}else`terms`in e&&N(e,`objective function`,t,n,{constantPrefix:`Objective function`})}function ce(e,t,n,r=e.name){if(!Number.isFinite(e.rhs))throw Error(`Constraint "${r}" has invalid right-hand side (RHS): ${e.rhs}. RHS must be a finite number.`);if(oe(e._requiredDiscreteVars,`Discrete constraint "${r}"`),N(e.lhs,`constraint "${r}"`,t,n),e.sense===`!=`){if(!Number.isSafeInteger(e.rhs))throw Error(`Discrete "!=" in constraint "${r}" requires a safe integer RHS, received ${e.rhs}.`);R(e.lhs,`Discrete "!=" in constraint "${r}"`)}if(e._indicatorMeta){let i=e._indicatorMeta.binVar;if(!n(i))throw Error(`Indicator binary variable "${i.name}" in constraint "${r}" does not belong to model "${t}".`);if(!(i.type===`Binary`||i.type===`Integer`&&i.lb===0&&i.ub===1))throw Error(`Indicator variable "${i.name}" in constraint "${r}" has invalid type "${i.type}" or bounds [${i.lb}, ${i.ub}]: expected Binary or Integer [0, 1].`)}}function le(e,t,n,r,i,a){if(e instanceof c){if(!i(e))throw Error(`Boolean variable "${e.name}" in logical constraint "${t}" does not belong to model "${n}".`)}else if(e instanceof l)for(let o of e.children)le(o,t,n,r,i,a);else if(e instanceof h){oe(e.discreteVars,`Global constraint "${t}"`);let i=`logical constraint "${t}"`;switch(e.spec.kind){case`distinct`:for(let t of e.spec.args)N(t,i,n,r);break;case`disjoint`:for(let t of e.spec.tasks)N(t.start,i,n,r);break;case`cumulative`:for(let t of e.spec.tasks)N(t.start,i,n,r);break;case`allowed`:for(let t of e.spec.vars)N(t,i,n,r)}}else if(e instanceof I){if(a){let r=E.get(e)??e.ownerModel??void 0;if(r&&r!==a)throw Error(`Constraint "${e.name}" embedded in logical constraint "${t}" already belongs to model "${r.name??`another model`}" and cannot be added to model "${n}".`)}if(!Number.isFinite(e.rhs))throw Error(`Constraint "${e.name}" embedded in logical constraint "${t}" has invalid RHS: ${e.rhs}.`);if(oe(e._requiredDiscreteVars,`Discrete constraint "${e.name}" embedded in logical constraint "${t}"`),N(e.lhs,`constraint "${e.name}" embedded in logical constraint "${t}"`,n,r,{constantPrefix:`Constraint "${e.name}" embedded in logical constraint "${t}"`,constantKind:`LHS constant`,varLocationPhrase:`embedded in logical constraint "${t}"`}),e.sense===`!=`){if(!Number.isSafeInteger(e.rhs))throw Error(`Discrete "!=" in constraint "${e.name}" embedded in logical constraint "${t}" requires a safe integer RHS, received ${e.rhs}.`);R(e.lhs,`Discrete "!=" in constraint "${e.name}" embedded in logical constraint "${t}"`)}}}function F(e){let{model:t}=e,n=new Set,r=new Set;for(let i of e.variables){M(i);let a=T.get(i);if(a&&a!==t||n.has(i.name)||e.getVarByName(i.name)!==i)throw Error(`Variable "${i.name}" is duplicated or not canonically registered in model "${e.name}".`);n.add(i.name),r.add(i)}let i=new Set,a=new Set;for(let t of e.boolVars){if(i.has(t.name)||e.getBoolVarByName(t.name)!==t)throw Error(`Boolean variable "${t.name}" is duplicated or not canonically registered in model "${e.name}".`);i.add(t.name),a.add(t)}let o=new Set;for(let t of e.constraints){if(i.has(t.name))throw Error(`Constraint name "${t.name}" conflicts with Boolean variable "${t.name}" in model "${e.name}".`);if(o.has(t.name))throw Error(`Duplicate constraint name "${t.name}" in model "${e.name}".`);o.add(t.name)}for(let t of e.logicalConstraints){if(i.has(t.name))throw Error(`Logical constraint name "${t.name}" conflicts with Boolean variable "${t.name}" in model "${e.name}".`);if(o.has(t.name))throw Error(`Conflicting constraint name "${t.name}" across arithmetic and logical constraints in model "${e.name}".`);o.add(t.name)}for(let n of e.constraints){let r=E.get(n);if(r&&r!==t||e.getConstraintByName(n.name)!==n)throw Error(`Constraint "${n.name}" is duplicated or not canonically registered in model "${e.name}".`)}for(let t of e.logicalConstraints)if(e.getLogicalConstraintByName(t.name)!==t)throw Error(`Logical constraint "${t.name}" is duplicated or not canonically registered in model "${e.name}".`);e.objectiveExpr&&P(e.objectiveExpr,e.name,e=>r.has(e));for(let t of e.constraints)ce(t,e.name,e=>r.has(e));for(let n of e.logicalConstraints)le(n.expr,n.name,e.name,e=>r.has(e),e=>a.has(e),t)}var ue=0,I=class e{kind=`constraint`;id;_lhs;_sense;_rhs;_name;hasExplicitName;ownerModel=null;_indicatorOrigin;_indicatorSnapshot;_discreteVars;slack=null;dual=null;addTerm(e,t){return t===0?this:(this._indicatorOrigin=void 0,this._indicatorSnapshot=void 0,this._lhs.addTerm(e,t),k(this.ownerModel),this)}setTerm(e,t){return this._indicatorOrigin=void 0,this._indicatorSnapshot=void 0,this._lhs.setTerm(e,t),k(this.ownerModel),this}constructor(e,t,n,r){this.id=++ue,this._lhs=e,this._sense=t,this._rhs=n;let i=typeof r==`string`?r.trim():void 0;i&&i.length>0?(this._name=i,this.hasExplicitName=!0):(this._name=`c_${this.id}`,this.hasExplicitName=!1)}get lhs(){return this._lhs}set lhs(e){this._lhs!==e&&(this._indicatorOrigin=void 0,this._indicatorSnapshot=void 0,this._lhs=e,k(this.ownerModel))}get sense(){return this._sense}set sense(e){if(e===`!=`&&!Number.isSafeInteger(this._rhs))throw Error(`Discrete "!=" in constraint "${this._name}" requires a safe integer RHS, received ${this._rhs}.`);this._sense!==e&&(this._indicatorOrigin=void 0,this._indicatorSnapshot=void 0,this._sense=e,k(this.ownerModel))}get rhs(){return this._rhs}set rhs(e){if(this._sense===`!=`&&!Number.isSafeInteger(e))throw Error(`Discrete "!=" in constraint "${this._name}" requires a safe integer RHS, received ${e}.`);Object.is(this._rhs,e)||(this._indicatorOrigin=void 0,this._indicatorSnapshot=void 0,this._rhs=e,k(this.ownerModel))}get name(){return this._name}set name(e){this._name!==e&&(this._name=e,k(this.ownerModel)),this.hasExplicitName=!0}get _indicatorMeta(){let e=this._indicatorOrigin,t=this._indicatorSnapshot;if(!e||!t)return;if(this._lhs!==t.lhsRef||this._sense!==t.sense||!Object.is(this._rhs,t.rhs)||!Object.is(this._lhs.constant,t.constant)||this._lhs.nonlinearTerms.length>0||this._lhs.terms.size!==t.terms.size){this._indicatorOrigin=void 0,this._indicatorSnapshot=void 0;return}for(let[e,n]of t.terms)if(!this._lhs.terms.has(e)||!Object.is(this._lhs.terms.get(e),n)){this._indicatorOrigin=void 0,this._indicatorSnapshot=void 0;return}let n=e.targetRhs-(e.targetLhs.constant??0),r=0;for(let[t,n]of e.targetLhs.terms){if(n===0)continue;let i=e.targetSense===`<=`?n>0?t.ub:t.lb:n>0?t.lb:t.ub;if(!Number.isFinite(i)||(r+=n*i,!Number.isFinite(r)))return}if(!((e.targetSense===`<=`?r-n:n-r)>e.derivedM+1e-9))return e}_setIndicatorOrigin(e){if(!e){this._indicatorOrigin=void 0,this._indicatorSnapshot=void 0;return}this._indicatorOrigin=e,this._indicatorSnapshot={lhsRef:this._lhs,terms:new Map(this._lhs.terms),constant:this._lhs.constant,sense:this._sense,rhs:this._rhs}}get _requiredDiscreteVars(){return this._discreteVars}_setDiscreteVars(e){this._discreteVars=e}_assignModelName(e,t){this._name=e,this.hasExplicitName=t}and(e){return new l(`and`,[this,e])}or(e){return new l(`or`,[this,e])}implies(e){return new l(`implies`,[this,e])}xor(e){return new l(`xor`,[this,e])}not(){return new l(`not`,[this])}add(e){throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`)}sub(e){throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`)}mul(e){throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`)}div(e){throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`)}neg(){throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`)}le(e,t){throw Error(`Cannot compare a Constraint in (<=): expected a number, Var, or LinExpr.`)}ge(e,t){throw Error(`Cannot compare a Constraint in (>=): expected a number, Var, or LinExpr.`)}eq(e,t){throw Error(`Cannot compare a Constraint in (==): expected a number, Var, or LinExpr.`)}lt(e,t){throw Error(`Cannot compare a Constraint in (<): expected a number, Var, or LinExpr.`)}gt(e,t){throw Error(`Cannot compare a Constraint in (>): expected a number, Var, or LinExpr.`)}ne(e,t){throw Error(`Cannot compare a Constraint in (!=): expected a number, Var, or LinExpr.`)}get value(){throw Error(`Cannot read numeric value of a Constraint: expected a Var, LinExpr, or QuadExpr.`)}get constant(){throw Error(`Cannot read numeric constant of a Constraint: expected a LinExpr or QuadExpr.`)}clone(){let t=new e(this._lhs.clone(),this._sense,this._rhs,this.hasExplicitName?this._name:void 0);return this._discreteVars&&t._setDiscreteVars(new Set(this._discreteVars)),t}toString(){let e=this.sense===`==`?`=`:this.sense;return`${this.name}: ${this.lhs.toString()} ${e} ${this.rhs}`}};function de(e){return e instanceof I||typeof e==`object`&&!!e&&`sense`in e&&`lhs`in e&&`rhs`in e}function L(e){switch(e.kind){case`abs`:return{kind:`abs`,arg:e.arg.clone()};case`max`:return{kind:`max`,args:e.args.map(e=>e.clone())};case`min`:return{kind:`min`,args:e.args.map(e=>e.clone())};case`at`:return{kind:`at`,array:e.array.map(e=>e.clone()),index:e.index.clone(),discreteVars:new Set(e.discreteVars)}}}function fe(e){switch(e.kind){case`abs`:return`abs(${e.arg.toString()})`;case`max`:return`max(${e.args.map(e=>e.toString()).join(`, `)})`;case`min`:return`min(${e.args.map(e=>e.toString()).join(`, `)})`;case`at`:return`at([${e.array.map(e=>e.toString()).join(`, `)}], ${e.index.toString()})`}}function pe(e){switch(e.kind){case`abs`:{let t=e.arg.value;return t===null?null:Math.abs(t)}case`max`:{let t=-1/0;for(let n of e.args){let e=n.value;if(e===null)return null;e>t&&(t=e)}return t}case`min`:{let t=1/0;for(let n of e.args){let e=n.value;if(e===null)return null;e<t&&(t=e)}return t}case`at`:{let t=e.index.value;if(t===null||!Number.isFinite(t))return null;let n=Math.round(t);return Math.abs(t-n)>1e-6||n<0||n>=e.array.length?null:e.array[n].value}}}function me(e){return e instanceof H||typeof e==`object`&&!!e&&!de(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`}function R(e,t,n=new Set){if(typeof e==`number`){if(!Number.isSafeInteger(e))throw Error(`${t} requires Integer or Binary variables and integer constants/coefficients, but received constant ${e}.`);return n}if(de(e))throw Error(`${t} cannot accept a Constraint comparison.`);if(e instanceof w||`quadTerms`in e&&e.quadTerms instanceof Map&&`linearTerms`in e&&e.linearTerms instanceof Map&&typeof e.constant==`number`){let r=e;if(r.quadTerms.size>0)throw Error(`${t} does not support quadratic expressions.`);return R(new z(r.linearTerms,r.constant,r.nonlinearTerms??[]),t,n)}if(me(e)){if(e.type!==`Integer`&&e.type!==`Binary`)throw Error(`${t} requires Integer or Binary variables, but involves Continuous variable "${e.name}".`);return n.add(e),n}if(`terms`in e&&e.terms instanceof Map){let r=e,i=r.constant??0;if(!Number.isSafeInteger(i))throw Error(`${t} requires Integer or Binary variables and integer constants/coefficients, but received constant ${i}.`);for(let[e,i]of r.terms)if(i!==0){if(e.type!==`Integer`&&e.type!==`Binary`)throw Error(`${t} requires Integer or Binary variables, but involves Continuous variable "${e.name}".`);if(!Number.isSafeInteger(i))throw Error(`${t} requires integer coefficients, but variable "${e.name}" has coefficient ${i}.`);n.add(e)}for(let e of r.nonlinearTerms??[]){if(e.coeff===0)continue;if(!Number.isSafeInteger(e.coeff))throw Error(`${t} requires integer coefficients on nonlinear expressions, received ${e.coeff}.`);let r=e.atom;if(r.kind===`abs`)R(r.arg,t,n);else if(r.kind===`max`||r.kind===`min`)for(let e of r.args)R(e,t,n);else if(r.kind===`at`){R(r.index,t,n);for(let e of r.array)R(e,t,n)}}return n}throw Error(`${t} expected an integer-valued scalar expression.`)}function he(e,t){if(typeof e==`number`){if(!Number.isFinite(e))throw Error(`Invalid non-finite number "${e}" in ${t}.`);return new z(new Map,Object.is(e,-0)?0:e)}if(de(e))throw t.startsWith(`sum`)?Error(`Cannot sum a constraint comparison (<=, >=, ==, !=, <, >): expected arithmetic expressions in ${t}.`):Error(`Cannot use a constraint comparison (<=, >=, ==, !=, <, >) in ${t}: expected a finite number, Var, or LinExpr.`);if(e instanceof w||typeof e==`object`&&e&&`quadTerms`in e&&e.quadTerms instanceof Map&&`linearTerms`in e&&e.linearTerms instanceof Map){let n=e;if(n.quadTerms.size>0)throw Error(`Quadratic expressions are not supported in ${t}.`);if(!Number.isFinite(n.constant))throw Error(`Invalid non-finite constant "${n.constant}" in ${t}.`);for(let[,e]of n.linearTerms)if(!Number.isFinite(e))throw Error(`Invalid non-finite coefficient "${e}" in ${t}.`);return new z(n.linearTerms,n.constant,n.nonlinearTerms??[])}if(e instanceof z||typeof e==`object`&&e&&`terms`in e&&e.terms instanceof Map&&typeof e.constant==`number`){let n=e;if(!Number.isFinite(n.constant))throw Error(`Invalid non-finite constant "${n.constant}" in ${t}.`);for(let[,e]of n.terms)if(!Number.isFinite(e))throw Error(`Invalid non-finite coefficient "${e}" in ${t}.`);return n.clone()}if(me(e))return new z(new Map([[e,1]]),0);throw Error(`Unsupported item in ${t}: expected a finite number, Var, or LinExpr.`)}var z=class e{kind=`linear`;terms;constant;nonlinearTerms;constructor(e=new Map,t=0,n=[]){this.terms=new Map(e),this.constant=t,this.nonlinearTerms=n.filter(e=>e.coeff!==0).map(e=>({atom:L(e.atom),coeff:e.coeff}))}hasNonlinearTerms(){return this.nonlinearTerms.length>0}setTerm(e,t){return t===0?this.terms.delete(e):this.terms.set(e,t),this}addTerm(e,t){let n=(this.terms.get(e)??0)+t;return n===0?this.terms.delete(e):this.terms.set(e,n),this}clone(){return new e(this.terms,this.constant,this.nonlinearTerms)}add(e){if(de(e))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);if(e instanceof w)return e.add(this);let t=this.clone();if(typeof e==`number`)t.constant+=e;else if(`terms`in e){for(let[n,r]of e.terms){let e=(t.terms.get(n)??0)+r;e===0?t.terms.delete(n):t.terms.set(n,e)}if(t.constant+=e.constant,Array.isArray(e.nonlinearTerms))for(let n of e.nonlinearTerms)n.coeff!==0&&t.nonlinearTerms.push({atom:L(n.atom),coeff:n.coeff})}else{let n=(t.terms.get(e)??0)+1;n===0?t.terms.delete(e):t.terms.set(e,n)}return t}sub(e){if(de(e))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);return e instanceof w?e.neg().add(this):typeof e==`number`?this.add(-e):this.add(e.mul(-1))}mul(t){if(de(t))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);if(typeof t==`number`){let n=this.terms.size>0||this.nonlinearTerms.length>0,r=this.constant===0&&n?0:this.constant*t;if(this.constant!==0&&t!==0&&r===0)throw Error(`Constant multiplication underflows to zero.`);let i=new e(new Map,r);for(let[e,n]of this.terms){let r=n*t;if(n!==0&&t!==0&&r===0)throw Error(`Coefficient multiplication underflows to zero.`);r!==0&&i.terms.set(e,r)}if(t!==0)for(let e of this.nonlinearTerms){let n=e.coeff*t;if(e.coeff!==0&&n===0)throw Error(`Coefficient multiplication underflows to zero.`);n!==0&&i.nonlinearTerms.push({atom:L(e.atom),coeff:n})}return i}if(t instanceof H||typeof t==`object`&&t&&`id`in t&&!(`terms`in t)&&!(`quadTerms`in t)){if(this.hasNonlinearTerms())throw Error(`Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.`);return w.multiplyLinearTerms(this.constant,this.terms,0,new Map([[t,1]]))}if(t instanceof w){let e=t.linearTerms.size>0||t.quadTerms.size>0||t.hasNonlinearTerms();if(this.hasNonlinearTerms()){if(!e)return this.mul(t.constant);throw Error(`Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.`)}if(t.hasNonlinearTerms()){if(this.terms.size===0)return t.mul(this.constant);throw Error(`Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.`)}return this.terms.size===0?t.mul(this.constant):new w(this.terms,new Map,this.constant).mul(t)}let n=Array.isArray(t.nonlinearTerms)&&t.nonlinearTerms.length>0;if(this.hasNonlinearTerms()){if(t.terms.size===0&&!n)return this.mul(t.constant);throw Error(`Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.`)}if(n){if(this.terms.size===0)return t.mul(this.constant);throw Error(`Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.`)}return this.terms.size===0?t.mul(this.constant):t.terms.size===0?this.mul(t.constant):w.multiplyLinearTerms(this.constant,this.terms,t.constant,t.terms)}div(e){let t=w.extractScalarDivisor(e,`LinExpr.div()`);return this.mul(1/t)}neg(){return this.mul(-1)}get value(){let e=this.constant;for(let[t,n]of this.terms){if(t.value===null)return null;e+=n*t.value}for(let t of this.nonlinearTerms){let n=pe(t.atom);if(n===null)return null;e+=t.coeff*n}return e}le(e,t){return this.toConstraint(`<=`,e,t)}ge(e,t){return this.toConstraint(`>=`,e,t)}eq(e,t){return this.toConstraint(`==`,e,t)}lt(e,t){return this.toDiscreteComparison(`<`,e,t)}gt(e,t){return this.toDiscreteComparison(`>`,e,t)}ne(e,t){return this.toDiscreteComparison(`!=`,e,t)}toDiscreteComparison(e,t,n){if(t instanceof I||typeof t==`object`&&t&&`sense`in t&&`lhs`in t)throw Error(`Cannot compare against a Constraint in (${e}): expected a finite integer, discrete Var, or discrete LinExpr.`);let r=`discrete ${e}`,i=new Set;R(this,r,i),R(t,r,i);let a=this.toConstraint(e===`<`?`<=`:e===`>`?`>=`:`!=`,t,n);if(e===`<`){let e=a.rhs-1;if(!Number.isSafeInteger(e))throw Error(`Discrete comparison (<) adjusted right-hand side (${e}) exceeds safe integer range.`);a.rhs=e}else if(e===`>`){let e=a.rhs+1;if(!Number.isSafeInteger(e))throw Error(`Discrete comparison (>) adjusted right-hand side (${e}) exceeds safe integer range.`);a.rhs=e}else if(!Number.isSafeInteger(a.rhs))throw Error(`Discrete comparison (!=) adjusted right-hand side (${a.rhs}) exceeds safe integer range.`);return a._setDiscreteVars(i),a}toConstraint(t,n,r){let i=this.clone(),a=0;if(typeof n==`number`)a=n;else if(n instanceof I||typeof n==`object`&&n&&`sense`in n&&`lhs`in n)throw Error(`Cannot compare against a Constraint in (${t}): expected a number, Var, or LinExpr.`);else if(n instanceof w||typeof n==`object`&&n&&`quadTerms`in n){let r=n;if(r.quadTerms.size>0)throw Error(`Quadratic expressions are not supported in linear constraints (${t}): quadratic terms are only allowed in objectives.`);i=i.sub(new e(r.linearTerms,0,r.nonlinearTerms??[])),a=r.constant}else`terms`in n?(i=i.sub(new e(n.terms,0,n.nonlinearTerms??[])),a=n.constant):i=i.sub(n);let o=a-i.constant;return i.constant=0,new I(i,t,o,r)}and(e){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==, !=, <, >) in logical 'and': expected a BoolVar, Constraint, or BoolOp.`)}or(e){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==, !=, <, >) in logical 'or': expected a BoolVar, Constraint, or BoolOp.`)}implies(e){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==, !=, <, >) in logical 'implies': expected a BoolVar, Constraint, or BoolOp.`)}xor(e){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==, !=, <, >) in logical 'xor': expected a BoolVar, Constraint, or BoolOp.`)}not(){throw Error(`Cannot use an arithmetic expression without a comparison operator (<=, >=, ==, !=, <, >) in logical 'not': expected a BoolVar, Constraint, or BoolOp.`)}toString(){let e=[],t=!0;for(let[n,r]of this.terms){let i=r>=0?t?``:`+ `:`- `,a=Math.abs(r),o=a===1?``:`${a} `;e.push(`${i}${o}${n.name}`),t=!1}for(let n of this.nonlinearTerms){let r=n.coeff,i=r>=0?t?``:`+ `:`- `,a=Math.abs(r),o=a===1?``:`${a} `;e.push(`${i}${o}${fe(n.atom)}`),t=!1}if(this.constant!==0||e.length===0){let n=this.constant>=0?t?``:`+ `:`- `;e.push(`${n}${Math.abs(this.constant)}`)}return e.join(` `)||`0`}};function B(e,t){let n=new Map,r=[],i=0;function a(e){return e instanceof I||e.kind===`constraint`||`sense`in e&&(e.sense===`<=`||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}function o(e){return e instanceof w||`quadTerms`in e&&e.quadTerms instanceof Map&&`linearTerms`in e&&e.linearTerms instanceof Map&&typeof e.constant==`number`}function s(e){return e instanceof z||`terms`in e&&e.terms instanceof Map&&typeof e.constant==`number`}function c(e){return e instanceof H||!a(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`}function l(e){return a(e)||o(e)||s(e)||c(e)}function u(e){if(typeof e!=`object`||!e||Array.isArray(e)||l(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function d(e){if(e!=null){if(typeof e==`number`){if(!Number.isFinite(e))throw Error(`Invalid non-finite number "${e}" in sum().`);let t=i+e;if(!Number.isFinite(t))throw Error(`Constant accumulation overflows finite floating-point range in sum().`);i=t}else if(typeof e==`object`&&a(e))throw Error(`Cannot sum a constraint comparison (<=, >=, ==) in sum(): expected a number, Var, or LinExpr.`);else if(typeof e==`object`&&o(e)){let t=e;if(t.quadTerms.size>0)throw Error(`Quadratic expressions are not supported in sum(): sum() produces a linear expression (LinExpr).`);if(!Number.isFinite(t.constant))throw Error(`Invalid non-finite constant "${t.constant}" in sum().`);for(let[e,r]of t.linearTerms){if(!Number.isFinite(r))throw Error(`Invalid non-finite coefficient "${r}" in sum().`);let t=(n.get(e)??0)+r;if(!Number.isFinite(t))throw Error(`Coefficient accumulation overflows finite floating-point range in sum().`);n.set(e,t)}let a=i+t.constant;if(!Number.isFinite(a))throw Error(`Constant accumulation overflows finite floating-point range in sum().`);if(i=a,Array.isArray(t.nonlinearTerms))for(let e of t.nonlinearTerms){if(!Number.isFinite(e.coeff))throw Error(`Invalid non-finite coefficient "${e.coeff}" in sum().`);e.coeff!==0&&r.push({atom:L(e.atom),coeff:e.coeff})}}else if(typeof e==`object`&&s(e)){let t=e;if(!Number.isFinite(t.constant))throw Error(`Invalid non-finite constant "${t.constant}" in sum().`);for(let[e,r]of t.terms){if(!Number.isFinite(r))throw Error(`Invalid non-finite coefficient "${r}" in sum().`);let t=(n.get(e)??0)+r;if(!Number.isFinite(t))throw Error(`Coefficient accumulation overflows finite floating-point range in sum().`);n.set(e,t)}let a=i+t.constant;if(!Number.isFinite(a))throw Error(`Constant accumulation overflows finite floating-point range in sum().`);if(i=a,Array.isArray(t.nonlinearTerms))for(let e of t.nonlinearTerms){if(!Number.isFinite(e.coeff))throw Error(`Invalid non-finite coefficient "${e.coeff}" in sum().`);e.coeff!==0&&r.push({atom:L(e.atom),coeff:e.coeff})}}else if(typeof e==`object`&&c(e)){let t=e,r=(n.get(t)??0)+1;if(!Number.isFinite(r))throw Error(`Coefficient accumulation overflows finite floating-point range in sum().`);n.set(t,r)}else throw Error(`Unsupported item in sum(): expected a number, Var, or LinExpr.`)}}function f(e,t=0){if(e!=null){if(typeof e==`number`){d(e);return}if(typeof e==`object`){if(l(e)){d(e);return}if(!(e instanceof String)&&!(e instanceof Map)&&Symbol.iterator in e&&typeof e[Symbol.iterator]==`function`){if(t>=2)throw Error(`Nested containers deeper than 2D are not supported in sum().`);for(let n of e)f(n,t+1);return}if(u(e)){if(t>=2)throw Error(`Nested containers deeper than 2D are not supported in sum().`);if(Object.getOwnPropertySymbols(e).length>0)throw Error(`Symbol keys are not supported in sum().`);for(let n of Object.keys(e))f(e[n],t+1);return}}d(e)}}if(typeof e==`number`){if(typeof t!=`function`)throw Error(`sum(count, mapFn) requires a mapping function as the second argument.`);if(!Number.isInteger(e)||e<0)throw Error(`sum(count, mapFn) requires a non-negative integer count.`);let n=e;for(let e=0;e<n;e++)f(t(e,e),0)}else if(typeof e==`object`&&e&&!(e instanceof String)&&(!(e instanceof Map)||typeof t==`function`)&&Symbol.iterator in e&&typeof e[Symbol.iterator]==`function`){let n=0;for(let r of e)t?f(t(r,n++),0):f(r,1)}else if(u(e)){if(Object.getOwnPropertySymbols(e).length>0)throw Error(`Symbol keys are not supported in sum().`);let n=0;for(let r of Object.keys(e)){let i=e[r];t?f(t(i,n++),0):f(i,1)}}else throw Error(`Unsupported item in sum(): expected an Iterable, Record, or (count, mapFn).`);for(let[e,t]of n)t===0&&n.delete(e);return new z(n,i,r)}function ge(e,t){let n=new Map,r=[],i=0;function a(e){return typeof e==`object`&&!!e&&!(e instanceof I)&&typeof e.id==`number`&&typeof e.name==`string`&&typeof e.lb==`number`&&typeof e.ub==`number`&&typeof e.type==`string`&&typeof e.mul==`function`&&typeof e.le==`function`}function o(e){return a(e)||e instanceof z||e instanceof w}function s(e,t,o){if(!Number.isFinite(e))throw Error(`Invalid non-finite coefficient "${e}" in dot() at '${o||`root`}'.`);if(t instanceof w)throw Error(`Quadratic expressions are not supported in dot() at '${o||`root`}': dot() produces a linear expression (LinExpr).`);if(t instanceof z){if(!Number.isFinite(t.constant))throw Error(`Invalid non-finite constant "${t.constant}" in dot() at '${o||`root`}'.`);let a=e===0||t.constant===0?0:e*t.constant;if(e!==0&&t.constant!==0&&a===0)throw Error(`Constant multiplication underflows to zero.`);if(!Number.isFinite(a))throw Error(`Coefficient multiplication overflows finite floating-point range in dot() at '${o||`root`}'.`);let s=i+a;if(!Number.isFinite(s))throw Error(`Constant accumulation overflows finite floating-point range in dot() at '${o||`root`}'.`);i=s;for(let[r,i]of t.terms){if(!Number.isFinite(i))throw Error(`Invalid non-finite coefficient "${i}" in dot() at '${o||`root`}'.`);let t=e*i;if(e!==0&&i!==0&&t===0)throw Error(`Coefficient multiplication underflows to zero.`);if(!Number.isFinite(t))throw Error(`Coefficient multiplication overflows finite floating-point range in dot() at '${o||`root`}'.`);let a=(n.get(r)??0)+t;if(!Number.isFinite(a))throw Error(`Coefficient accumulation overflows finite floating-point range in dot() at '${o||`root`}'.`);n.set(r,a)}if(Array.isArray(t.nonlinearTerms)&&e!==0)for(let n of t.nonlinearTerms){if(!Number.isFinite(n.coeff))throw Error(`Invalid non-finite coefficient "${n.coeff}" in dot() at '${o||`root`}'.`);let t=e*n.coeff;if(n.coeff!==0&&t===0)throw Error(`Coefficient multiplication underflows to zero.`);if(!Number.isFinite(t))throw Error(`Coefficient multiplication overflows finite floating-point range in dot() at '${o||`root`}'.`);t!==0&&r.push({atom:L(n.atom),coeff:t})}}else if(a(t)){let r=t,i=(n.get(r)??0)+e;if(!Number.isFinite(i))throw Error(`Coefficient accumulation overflows finite floating-point range in dot() at '${o||`root`}'.`);n.set(r,i)}else throw Error(`Cannot multiply number by non-variable/expression operand in dot() at '${o||`root`}'.`)}function c(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!o(e)&&!(e instanceof I)&&e.kind!==`constraint`}function l(e,t,n=``){if(e===void 0||t===void 0||e===null||t===null)throw Error(`Nullish or undefined operand encountered in dot() at '${n||`root`}'.`);if(typeof e==`number`&&typeof t==`number`)throw Error(`Cannot multiply two numbers in dot() at '${n||`root`}': expected one numeric coefficient and one Var or LinExpr.`);if(typeof e==`number`){s(e,t,n);return}if(typeof t==`number`){s(t,e,n);return}if(Array.isArray(e)||Array.isArray(t)){if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)throw Error(`Array length mismatch in dot() at '${n||`root`}': received lengths ${e.length} and ${t.length}.`);for(let r=0;r<e.length;r++)l(e[r],t[r],n?`${n}[${r}]`:`[${r}]`);return}let r=Array.isArray(e)?e:t,i=Array.isArray(e)?t:e;if(c(i)){if(Object.getOwnPropertySymbols(i).length>0)throw Error(`Symbol keys are not supported in dot() at '${n||`root`}'.`);let a=Object.keys(i);if(a.length===r.length&&a.every(e=>/^(?:0|[1-9]\d*)$/.test(e))){let a=[];for(let e=0;e<r.length;e++)Object.prototype.hasOwnProperty.call(i,e)||a.push(e);if(a.length>0)throw Error(`Key mismatch in dot() at '${n||`root`}': missing indices [${a.join(`, `)}] in numeric record.`);for(let i=0;i<r.length;i++)l(e[i],t[i],n?`${n}[${i}]`:`[${i}]`);return}throw a.length>0&&a.every(e=>/^(?:0|[1-9]\d*)$/.test(e))?Error(`Array length mismatch in dot() at '${n||`root`}': array has length ${r.length}, but object has ${a.length} indices.`):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(`, `)}].`)}throw Error(`Type mismatch in dot() at '${n||`root`}': one operand is an Array while the other is not.`)}if(c(e)&&c(t)){if(Object.getOwnPropertySymbols(e).length>0||Object.getOwnPropertySymbols(t).length>0)throw Error(`Symbol keys are not supported in dot() at '${n||`root`}'.`);let r=Object.keys(e),i=Object.keys(t),a=r.filter(e=>!Object.prototype.hasOwnProperty.call(t,e)),o=i.filter(t=>!Object.prototype.hasOwnProperty.call(e,t));if(a.length>0||o.length>0){let e=[];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(`; `)}.`)}for(let i of r)l(e[i],t[i],n?`${n}.${i}`:i);return}throw Error(`Unsupported operand types in dot() at '${n||`root`}'.`)}l(e,t);for(let[e,t]of n)t===0&&n.delete(e);return new z(n,i,r)}function _e(e){let t=he(e,`abs()`);return t.terms.size===0&&t.nonlinearTerms.length===0?new z(new Map,Math.abs(t.constant)+0):new z(new Map,0,[{atom:{kind:`abs`,arg:t},coeff:1}])}function ve(e,t){if(t.length===0)throw Error(`${e}() requires at least one expression.`);let n=[],r=e=>typeof e==`number`||de(e)||me(e)||e instanceof z||e instanceof w||typeof e==`object`&&!!e&&(`terms`in e&&e.terms instanceof Map||`quadTerms`in e&&e.quadTerms instanceof Map),i=e=>{if(typeof e!=`object`||!e||Array.isArray(e)||r(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},a=t=>{n.push(he(t,`${e}()`))},o=(t,n)=>{if(t==null)throw Error(`Unsupported nullish item in ${e}(): expected a finite number, Var, or LinExpr.`);if(typeof t==`number`||r(t)){a(t);return}if(Array.isArray(t)){if(n>=2)throw Error(`Nested containers deeper than 2D are not supported in ${e}().`);for(let r=0;r<t.length;r++){if(!(r in t))throw Error(`Unsupported item in ${e}(): sparse array hole at index ${r}.`);o(t[r],n+1)}return}if(typeof t==`object`&&!(t instanceof String)&&!(t instanceof Map)&&Symbol.iterator in t&&typeof t[Symbol.iterator]==`function`){if(n>=2)throw Error(`Nested containers deeper than 2D are not supported in ${e}().`);for(let e of t)o(e,n+1);return}if(i(t)){if(n>=2)throw Error(`Nested containers deeper than 2D are not supported in ${e}().`);if(Object.getOwnPropertySymbols(t).length>0)throw Error(`Symbol keys are not supported in ${e}().`);for(let e of Object.keys(t))o(t[e],n+1);return}throw Error(`Unsupported item in ${e}(): expected a finite number, Var, or LinExpr.`)};if(t.length===2&&typeof t[1]==`function`){let n=t[0],r=t[1];if(typeof n==`number`){if(!Number.isInteger(n)||n<0)throw Error(`${e}(count, mapFn) requires a non-negative integer count.`);for(let e=0;e<n;e++)o(r(e,e),0)}else if(Array.isArray(n))for(let t=0;t<n.length;t++){if(!(t in n))throw Error(`Unsupported item in ${e}(): sparse array hole at index ${t}.`);o(r(n[t],t),0)}else if(typeof n==`object`&&n&&!(n instanceof String)&&Symbol.iterator in n&&typeof n[Symbol.iterator]==`function`){let e=0;for(let t of n)o(r(t,e++),0)}else if(i(n)){if(Object.getOwnPropertySymbols(n).length>0)throw Error(`Symbol keys are not supported in ${e}().`);let t=0;for(let e of Object.keys(n))o(r(n[e],t++),0)}else throw Error(`Invalid first argument in ${e}(itemsOrCount, mapFn): expected an Iterable, Record, or non-negative integer count.`)}else for(let n of t){if(typeof n==`function`)throw Error(`Function interpolation in ${e}() is only supported as ${e}(itemsOrCount, mapFn).`);o(n,0)}if(n.length===0)throw Error(`${e}() requires at least one expression.`);return n}function ye(e,t){if(t.length===1)return t[0].clone();if(t.every(e=>e.terms.size===0&&e.nonlinearTerms.length===0)){let n=t.map(e=>e.constant),r=e===`max`?Math.max(...n):Math.min(...n);return new z(new Map,Object.is(r,-0)?0:r)}return new z(new Map,0,[{atom:{kind:e,args:t},coeff:1}])}function be(...e){return ye(`max`,ve(`max`,e))}function xe(...e){return ye(`min`,ve(`min`,e))}function V(e,t){if(!Array.isArray(e))throw Error(`at(array, index) requires an Array as its first argument.`);if(e.length===0)throw Error(`at(array, index) requires an array with at least 1 element.`);let n=Array(e.length);for(let t=0;t<e.length;t++){if(!(t in e))throw Error(`at(array, index) encountered sparse array hole at index ${t}.`);n[t]=he(e[t],`at() array[${t}]`)}let r=he(t,`at() index`),i=R(r,`at() index`);return new z(new Map,0,[{atom:{kind:`at`,array:n,index:r,discreteVars:i},coeff:1}])}var Se=0;function Ce(e){if(e===void 0)return`Continuous`;if(typeof e==`string`){let t=e.toLowerCase();if(t===`binary`||t===`bin`)return`Binary`;if(t===`integer`||t===`int`)return`Integer`;if(t===`continuous`||t===`cont`)return`Continuous`}throw Error(`Invalid variable type "${String(e)}": expected "Continuous", "Integer", or "Binary".`)}var H=class{id;_name;prefix;hasExplicitName;ownerModel=null;_type;_lb;_ub;_initialValue;value=null;reducedCost=null;constructor(e={}){this.id=++Se;let t=typeof e.name==`string`?e.name.trim():``,n=typeof e.prefix==`string`?e.prefix.trim():``;this.prefix=n.length>0?n:`x`,this.hasExplicitName=t.length>0,this._name=this.hasExplicitName?t:`${this.prefix}_${this.id}`,this._type=Ce(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?1/0:e.ub),this._initialValue=e.initialValue===void 0?void 0:Object.is(e.initialValue,-0)?0:e.initialValue,this._initialValue!==void 0&&M(this)}get name(){return this._name}get type(){return this._type}set type(e){let t=Ce(e);this._type!==t&&(this._type=t,k(this.ownerModel))}get lb(){return this._lb}set lb(e){Object.is(this._lb,e)||(this._lb=e,k(this.ownerModel))}get ub(){return this._ub}set ub(e){Object.is(this._ub,e)||(this._ub=e,k(this.ownerModel))}get initialValue(){return this._initialValue}set initialValue(e){let t=e!==void 0&&Object.is(e,-0)?0:e;Object.is(this._initialValue,t)||(this._initialValue=t,k(this.ownerModel))}_assignModelName(e){this._name=e}mul(e){return typeof e==`number`?new z(new Map([[this,1]]),0).mul(e):new w(new Map([[this,1]]),new Map,0).mul(e)}add(e){return e instanceof w?e.add(this):new z(new Map([[this,1]]),0).add(e)}sub(e){return e instanceof w?e.neg().add(this):new z(new Map([[this,1]]),0).sub(e)}neg(){return this.mul(-1)}le(e,t){return new z(new Map([[this,1]]),0).le(e,t)}ge(e,t){return new z(new Map([[this,1]]),0).ge(e,t)}eq(e,t){return new z(new Map([[this,1]]),0).eq(e,t)}lt(e,t){return new z(new Map([[this,1]]),0).lt(e,t)}gt(e,t){return new z(new Map([[this,1]]),0).gt(e,t)}ne(e,t){return new z(new Map([[this,1]]),0).ne(e,t)}toString(){return this.name}};function U(e){return typeof e==`object`&&!!e&&e.kind===`container`}var we=/^(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?$/;function Te(e,t){let n=[],r=0,i=e.length;for(;r<i;){let a=e[r];if(/\s/.test(a)){r++;continue}if(a===`+`)n.push({type:`PLUS`,value:`+`}),r++;else if(a===`-`)n.push({type:`MINUS`,value:`-`}),r++;else if(a===`*`)r+1<i&&e[r+1]===`*`?(n.push({type:`CARET`,value:`**`}),r+=2):(n.push({type:`STAR`,value:`*`}),r++);else if(a===`^`)n.push({type:`CARET`,value:`^`}),r++;else if(a===`/`)n.push({type:`SLASH`,value:`/`}),r++;else if(a===`(`)n.push({type:`LPAREN`,value:`(`}),r++;else if(a===`)`)n.push({type:`RPAREN`,value:`)`}),r++;else if(a===`,`)n.push({type:`COMMA`,value:`,`}),r++;else if(a===`<`||a===`>`||a===`=`||a===`!`){let t=a;if(r+1<i&&(e[r+1]===`=`||a!==`!`&&(e[r+1]===`<`||e[r+1]===`>`))?(t+=e[r+1],r+=2):r++,t===`!`)throw Error(`Unexpected character '!' at position ${r-1} in: "${e}"`);n.push({type:`COMP`,value:t})}else if(/[0-9.]/.test(a)){let t=r,a=``;for(;r<i&&/[0-9]/.test(e[r]);)a+=e[r++];if(r<i&&e[r]===`.`)for(a+=e[r++];r<i&&/[0-9]/.test(e[r]);)a+=e[r++];if(r<i&&(e[r]===`e`||e[r]===`E`)){let t=r+1<i?e[r+1]:``;if(!/[a-zA-Z_]/.test(t)){for(a+=e[r++],r<i&&(e[r]===`+`||e[r]===`-`)&&(a+=e[r++]);r<i&&/[0-9]/.test(e[r]);)a+=e[r++];for(;r<i&&(e[r]===`.`||e[r]===`e`||e[r]===`E`||/[0-9]/.test(e[r]));)a+=e[r++]}}else for(;r<i&&(e[r]===`.`||/[0-9]/.test(e[r]));)a+=e[r++];if(!we.test(a))throw Error(`Invalid numeric literal '${a}' at position ${t} in: "${e}"`);let o=Number(a);if(!Number.isFinite(o))throw Error(`Numeric literal '${a}' overflows finite floating-point range in: "${e}"`);if(o===0&&!/^[0.]+(?:[eE][+-]?\d+)?$/.test(a))throw Error(`Numeric literal '${a}' underflows to zero at position ${t} in: "${e}"`);n.push({type:`NUMBER`,value:a,numericValue:o})}else if(/[a-zA-Z_]/.test(a)){let a=``;for(;r<i&&/[a-zA-Z0-9_]/.test(e[r]);)a+=e[r],r++;if(t&&t.has(a)){let e=t.get(a);n.push({type:`NUMBER`,value:String(e),numericValue:e})}else n.push({type:`IDENT`,value:a})}else throw Error(`Unexpected character '${a}' at position ${r} in: "${e}"`)}return n}function Ee(e){return e instanceof w&&e.quadTerms.size===0?new z(e.linearTerms,e.constant,e.nonlinearTerms):e}function De(e){return typeof e==`number`||e instanceof H||e instanceof z||e instanceof w||Ve(e)}function Oe(e){return typeof e==`number`?new z(new Map,e):e instanceof H||`id`in e&&!(`terms`in e)&&!(`quadTerms`in e)?new z(new Map([[e,1]]),0):e.clone()}function ke(e,t,n){if(typeof e==`number`&&typeof t==`number`){if(n===`+`){let n=e+t;if(!Number.isFinite(n))throw Error(`Invalid non-finite constant "${n}" in expression.`);return n}if(n===`-`){let n=e-t;if(!Number.isFinite(n))throw Error(`Invalid non-finite constant "${n}" in expression.`);return n}if(n===`*`){let n=e*t;if(e!==0&&t!==0&&n===0)throw Error(`Constant multiplication underflows to zero.`);if(!Number.isFinite(n))throw Error(`Invalid non-finite constant "${n}" in expression.`);return n}if(t===0)throw Error(`Division by zero`);let r=1/t*e;if(e!==0&&r===0)throw Error(`Constant multiplication underflows to zero.`);if(!Number.isFinite(r))throw Error(`Invalid non-finite constant "${r}" in expression.`);return r}let r=Oe(e),i=Oe(t),a;a=n===`+`?r.add(i):n===`-`?r.sub(i):n===`*`?r.mul(i):r.div(i);let o=Ee(a);return J(o),o}function W(e,t){if(Array.isArray(e)){let n=Array(e.length);for(let r=0;r<e.length;r++){let i=e[r];n[r]=De(i)?t(i):W(i,t)}return n}let n=Object.create(null);for(let r of Object.keys(e)){let i=e[r];n[r]=De(i)?t(i):W(i,t)}return n}function Ae(e,t,n,r=``){let i=De(e),a=De(t);if(i&&a)return ke(e,t,n);if(i||a)throw Error(`Dimension mismatch in template expression at '${r||`root`}': cannot combine scalar element with sub-container.`);if(Array.isArray(e)||Array.isArray(t)){if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)throw Error(`Array length mismatch in template expression at '${r||`root`}': received lengths ${e.length} and ${t.length}.`);let i=Array(e.length);for(let a=0;a<e.length;a++)i[a]=Ae(e[a],t[a],n,r?`${r}[${a}]`:`[${a}]`);return i}let i=Array.isArray(e)?e:t,a=Array.isArray(e)?t:e,o=Object.keys(a);if(o.length===i.length&&o.every(e=>/^(?:0|[1-9]\d*)$/.test(e))){let o=[];for(let e=0;e<i.length;e++)Object.prototype.hasOwnProperty.call(a,e)||o.push(e);if(o.length>0)throw Error(`Key mismatch in template expression at '${r||`root`}': missing indices [${o.join(`, `)}] in numeric record.`);let s=Array(i.length);for(let a=0;a<i.length;a++){let i=e[a],o=t[a];s[a]=Ae(i,o,n,r?`${r}[${a}]`:`[${a}]`)}return s}throw o.length>0&&o.every(e=>/^(?:0|[1-9]\d*)$/.test(e))?Error(`Array length mismatch in template expression at '${r||`root`}': array has length ${i.length}, but object has ${o.length} indices.`):Error(`Type mismatch in template expression at '${r||`root`}': one operand is an Array while the other is an Object with keys [${o.slice(0,5).join(`, `)}].`)}let o=e,s=t,c=Object.keys(o),l=Object.keys(s),u=c.filter(e=>!Object.prototype.hasOwnProperty.call(s,e)),d=l.filter(e=>!Object.prototype.hasOwnProperty.call(o,e));if(u.length>0||d.length>0){let e=[];throw u.length>0&&e.push(`missing in second operand: [${u.join(`, `)}]`),d.length>0&&e.push(`missing in first operand: [${d.join(`, `)}]`),Error(`Key mismatch in template expression at '${r||`root`}': ${e.join(`; `)}.`)}let f=Object.create(null);for(let e of c)f[e]=Ae(o[e],s[e],n,r?`${r}.${e}`:e);return f}function G(e,t,n){let r=U(e),i=U(t);if(!r&&!i)return ke(e,t,n);if(r&&!i)return{kind:`container`,data:W(e.data,e=>ke(e,t,n)),fromNonArrayIterable:e.fromNonArrayIterable};if(!r&&i)return{kind:`container`,data:W(t.data,t=>ke(e,t,n)),fromNonArrayIterable:t.fromNonArrayIterable};let a=e,o=t;return{kind:`container`,data:Ae(a.data,o.data,n),fromNonArrayIterable:a.fromNonArrayIterable||o.fromNonArrayIterable}}function je(e){return typeof e==`number`?-e:U(e)?{kind:`container`,data:W(e.data,e=>typeof e==`number`?-e:Oe(e).neg()),fromNonArrayIterable:e.fromNonArrayIterable}:e.neg()}function Me(e,t){let n=e instanceof w,r=n?e.quadTerms.size:0,i=n?e.linearTerms.size:e.terms.size,a=Array.isArray(e.nonlinearTerms)?e.nonlinearTerms.length:0;if(r===0&&i===0&&a===0){let n=e.constant**+t;if(e.constant!==0&&t>0&&n===0)throw Error(`Constant exponentiation underflows to zero.`);return new z(new Map,n)}if(t===0)return new z(new Map,1);if(t===1)return e;if(a>0)throw Error(`Cannot multiply nonlinear expression (max, min, abs, or at) by a variable expression: only scalar multiplication is supported.`);if(t===2)return e.mul(e);throw Error(`Exponent ${t} creates a non-linear term of degree > 2 (not allowed in MILP/LP/QP)`)}function Ne(e){if(typeof e!=`object`||!e||Array.isArray(e)||Ve(e)||He(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function Pe(e){if(typeof e==`number`){if(!Number.isFinite(e))throw Error(`Invalid numeric value "${e}" in template expression: interpolated numbers must be finite.`);return e}if(He(e))throw Error(`Cannot interpolate a constraint comparison (<=, >=, ==) inside a template expression: expected a finite number, Var, LinExpr, or QuadExpr.`);if(Ve(e))return J(e),e instanceof H||`id`in e&&!(`terms`in e)&&!(`quadTerms`in e)?e:e.clone();throw Error(`Unsupported interpolation value in template expression: expected a finite number, Var, LinExpr, or QuadExpr.`)}function Fe(e){return typeof e==`object`&&!!e&&!(e instanceof String)&&!(e instanceof Map)&&!Ve(e)&&!He(e)&&Symbol.iterator in e&&typeof e[Symbol.iterator]==`function`}function Ie(e,t=0){if(Array.isArray(e)){let n=!1,r=Array(e.length);for(let i=0;i<e.length;i++){if(!(i in e))throw Error(`Unsupported interpolation value in template expression: sparse array hole at index ${i}.`);let a=e[i];if(Array.isArray(a)||Ne(a)||Fe(a)){if(t>=1)throw Error(`Nested containers deeper than 2D are not supported in template expressions.`);let e=Ie(a,t+1);e.fromNonArrayIterable&&(n=!0),r[i]=e.data}else r[i]=Pe(a)}return{kind:`container`,data:r,fromNonArrayIterable:n}}if(Fe(e))return{kind:`container`,data:Array.from(e).map(e=>{if(Array.isArray(e)||Ne(e)||Fe(e)){if(t>=1)throw Error(`Nested containers deeper than 2D are not supported in template expressions.`);return Ie(e,t+1).data}return Pe(e)}),fromNonArrayIterable:!0};if(Ne(e)){if(Object.getOwnPropertySymbols(e).length>0)throw Error(`Symbol keys are not supported in template expression at 'root'.`);let n=!1,r=Object.create(null);for(let i of Object.keys(e)){let a=e[i];if(Array.isArray(a)||Ne(a)||Fe(a)){if(t>=1)throw Error(`Nested containers deeper than 2D are not supported in template expressions.`);let e=Ie(a,t+1);e.fromNonArrayIterable&&(n=!0),r[i]=e.data}else r[i]=Pe(a)}return{kind:`container`,data:r,fromNonArrayIterable:n}}throw Error(`Unsupported interpolation value in template expression: expected a finite number, Var, LinExpr, or QuadExpr.`)}var Le=class{tokens;pos=0;resolver;templateCtx;constructor(e,t,n){this.tokens=e,this.resolver=t,this.templateCtx=n}peek(){return this.tokens[this.pos]}consume(e){let t=this.tokens[this.pos++];if(!t)throw Error(`Unexpected end of input`);if(e&&t.value!==e&&t.type!==e)throw Error(`Expected '${e}', but found '${t.value}'`);return t}parseExpression(){let e=this.parseExpressionNode();if(U(e))throw Error(`Container expression (Array or Record) cannot be used directly as a scalar expression or constraint; wrap it in sum(...) or use dot(a, b).`);return typeof e==`number`?new z(new Map,e):Ee(e)}parseExpressionNode(){let e=this.parseTermNode();for(;this.pos<this.tokens.length;){let t=this.peek();if(!t)break;if(t.type===`PLUS`)this.consume(),e=G(e,this.parseTermNode(),`+`);else if(t.type===`MINUS`)this.consume(),e=G(e,this.parseTermNode(),`-`);else break}return U(e)||typeof e==`number`?e:Ee(e)}parseTermNode(){let e=this.parseFactorNode();for(;this.pos<this.tokens.length;){let t=this.peek();if(!t)break;if(t.type===`STAR`)this.consume(),e=G(e,this.parseFactorNode(),`*`);else if(t.type===`SLASH`)this.consume(),e=G(e,this.parseFactorNode(),`/`);else break}return e}parseFactorNode(){let e=this.peek();if(!e)throw Error(`Unexpected end of expression`);if(e.type===`PLUS`)return this.consume(),this.parseFactorNode();if(e.type===`MINUS`)return this.consume(),je(this.parseFactorNode());let t;if(e.type===`NUMBER`){this.consume();let n=e.numericValue??Number(e.value);if(this.peek()?.type===`IDENT`||this.peek()?.type===`LPAREN`){let e=this.parsePrimaryNode();return G(this.applyPowerNode(e),n,`*`)}t=n}else if(e.type===`IDENT`||e.type===`LPAREN`)t=this.parsePrimaryNode();else throw Error(`Unexpected token '${e.value}' in expression`);return this.applyPowerNode(t)}parsePrimaryNode(){if(this.peek()?.type===`IDENT`){let e=this.consume();return(e.value===`sum`||e.value===`dot`||e.value===`abs`||e.value===`max`||e.value===`min`||e.value===`at`)&&this.peek()?.type===`LPAREN`?this.parseFunctionCall(e.value):this.resolveNode(e.value)}this.consume(`LPAREN`);let e=this.parseExpressionNode();return this.consume(`RPAREN`),e}parseFunctionCall(e){this.consume(`LPAREN`);let t=1;for(let n=this.pos;n<this.tokens.length&&t>0;n++){let r=this.tokens[n];if(r.type===`LPAREN`)t++;else if(r.type===`RPAREN`)t--;else if(r.type===`COMP`)throw Error(e===`sum`?`Cannot sum a constraint comparison (<=, >=, ==, !=, <, >) in sum(): expected arithmetic expressions.`:e===`dot`?`Cannot use a constraint comparison (<=, >=, ==, !=, <, >) in dot(): expected 1D or 2D Array or Record containers.`:`Cannot use a constraint comparison (<=, >=, ==, !=, <, >) in ${e}(): expected arithmetic expressions.`)}if(this.peek()?.type===`RPAREN`)throw this.consume(`RPAREN`),Error(e===`dot`?`dot() in template expression requires exactly 2 arguments: dot(a, b).`:e===`at`?`at() in template expression requires exactly 2 arguments: at(array, index).`:e===`abs`?`abs() in template expression requires 1 argument.`:`${e}() in template expression requires at least 1 argument.`);if(e===`abs`){let e=this.parseExpressionNode();if(this.peek()?.type===`COMMA`)throw Error(`abs() in template expression accepts exactly 1 argument.`);return this.consume(`RPAREN`),U(e)?{kind:`container`,data:W(e.data,e=>_e(e)),fromNonArrayIterable:e.fromNonArrayIterable}:_e(e)}if(e===`at`){let e=this.parseExpressionNode();if(this.peek()?.type!==`COMMA`)throw Error(`at() in template expression requires exactly 2 arguments: at(array, index).`);this.consume(`COMMA`);let t=this.parseExpressionNode();if(this.peek()?.type===`COMMA`)throw Error(`at() in template expression requires exactly 2 arguments: at(array, index).`);if(this.consume(`RPAREN`),!U(e)||e.fromNonArrayIterable||!Array.isArray(e.data))throw Error(`at(array, index) requires a 1D Array as its first argument.`);if(U(t))throw Error(`at(array, index) requires a discrete scalar expression as its index.`);let n=V(e.data,t);return J(n),n}if(e===`max`||e===`min`){let t=this.pos,n=0;for(;this.tokens[t]?.type===`LPAREN`;)n++,t++;if(this.tokens[t]?.type===`IDENT`&&this.templateCtx?.rawContainerMap.has(this.tokens[t].value)){let r=this.tokens[t].value,i=t+1,a=0;for(;a<n&&this.tokens[i]?.type===`RPAREN`;)a++,i++;if(a===n&&this.tokens[i]?.type===`COMMA`){let t=this.tokens[i+1];if(t?.type===`IDENT`&&this.templateCtx.functionMap.has(t.value)&&this.tokens[i+2]?.type===`RPAREN`){this.pos=i+2,this.consume(`RPAREN`);let n=this.templateCtx.functionMap.get(t.value);return this.evalExtremumWithMapper(e,this.templateCtx.rawContainerMap.get(r),n)}}}if(this.tokens[this.pos]?.type===`IDENT`&&this.templateCtx?.rawContainerMap.has(this.tokens[this.pos].value)&&this.tokens[this.pos+1]?.type===`RPAREN`){let t=this.consume();this.consume(`RPAREN`);let n=this.templateCtx.rawContainerMap.get(t.value),r=e===`max`?be(n):xe(n);return J(r),r}let r=this.parseExpressionNode();if(this.peek()?.type===`COMMA`){let t=this.tokens[this.pos+1];if(t&&t.type===`IDENT`&&this.templateCtx?.functionMap.has(t.value)){this.consume(`COMMA`);let t=this.consume();if(this.peek()?.type===`COMMA`)throw Error(`${e}(itemsOrCount, mapFn) accepts at most 2 arguments when using a mapper.`);this.consume(`RPAREN`);let n=this.templateCtx.functionMap.get(t.value);if(typeof r==`number`)return this.evalExtremumWithMapper(e,r,n);if(!U(r)&&r instanceof z&&r.terms.size===0&&r.nonlinearTerms.length===0)return this.evalExtremumWithMapper(e,r.constant,n);if(U(r))return this.evalExtremumWithMapper(e,r.data,n);throw Error(`Invalid first argument in ${e}(itemsOrCount, mapFn): expected an Iterable, Record, or non-negative integer count.`)}let n=[U(r)?r.data:r];for(;this.peek()?.type===`COMMA`;){this.consume(`COMMA`);let e=this.parseExpressionNode();n.push(U(e)?e.data:e)}this.consume(`RPAREN`);let i=e===`max`?be(...n):xe(...n);return J(i),i}this.consume(`RPAREN`);let i=U(r)?r.data:r,a=e===`max`?be(i):xe(i);return J(a),a}if(e===`sum`){if(this.tokens[this.pos]?.type===`IDENT`&&this.templateCtx?.rawContainerMap.has(this.tokens[this.pos].value)&&this.tokens[this.pos+1]?.type===`RPAREN`){let e=this.consume();this.consume(`RPAREN`);let t=this.templateCtx.rawContainerMap.get(e.value);return this.accumulateSumItems(e=>{e(t,0)})}let e=this.pos,t=0;for(;this.tokens[e]?.type===`LPAREN`;)t++,e++;if(this.tokens[e]?.type===`IDENT`&&this.templateCtx?.rawContainerMap.has(this.tokens[e].value)){let n=this.tokens[e].value,r=e+1,i=0;for(;i<t&&this.tokens[r]?.type===`RPAREN`;)i++,r++;if(i===t&&this.tokens[r]?.type===`COMMA`){this.pos=r+1;let e=this.peek();if(!e||e.type!==`IDENT`||!this.templateCtx.functionMap.has(e.value))throw Error(`Second argument to sum() must be a mapping function: sum(itemsOrCount, mapFn).`);if(this.consume(),this.peek()?.type===`COMMA`)throw Error(`sum() in template expression accepts at most 2 arguments: sum(container) or sum(itemsOrCount, mapFn).`);return this.consume(`RPAREN`),this.evalSumWithMapper(this.templateCtx.rawContainerMap.get(n),this.templateCtx.functionMap.get(e.value))}}let n=this.parseExpressionNode();if(this.peek()?.type===`COMMA`){this.consume(`COMMA`);let e=this.peek();if(!e||e.type!==`IDENT`||!this.templateCtx?.functionMap.has(e.value))throw Error(`Second argument to sum() must be a mapping function: sum(itemsOrCount, mapFn).`);if(this.consume(),this.peek()?.type===`COMMA`)throw Error(`sum() in template expression accepts at most 2 arguments: sum(container) or sum(itemsOrCount, mapFn).`);this.consume(`RPAREN`);let t=this.templateCtx.functionMap.get(e.value);if(typeof n==`number`)return this.evalSumWithMapper(n,t);if(!U(n)&&n instanceof z&&n.terms.size===0)return this.evalSumWithMapper(n.constant,t);if(U(n))return this.evalSumWithMapper(n.data,t);throw Error(`Invalid first argument in sum(itemsOrCount, mapFn): expected an Iterable, Record, or non-negative integer count.`)}return this.consume(`RPAREN`),this.evalSumSingle(n)}let n=this.parseExpressionNode();if(this.peek()?.type!==`COMMA`)throw Error(`dot() in template expression requires exactly 2 arguments: dot(a, b).`);this.consume(`COMMA`);let r=this.parseExpressionNode();if(this.peek()?.type===`COMMA`)throw Error(`dot() in template expression requires exactly 2 arguments: dot(a, b).`);return this.consume(`RPAREN`),this.evalDot(n,r)}accumulateSumItems(e){let t=new Map,n=new Map,r=[],i=0,a=(e,o=0)=>{if(e!=null){if(typeof e==`number`){if(!Number.isFinite(e))throw Error(`Invalid non-finite number "${e}" in sum().`);let t=i+e;if(!Number.isFinite(t))throw Error(`Constant accumulation overflows finite floating-point range in sum().`);i=t;return}if(He(e))throw Error(`Cannot sum a constraint comparison (<=, >=, ==) in sum(): expected a number, Var, LinExpr, or QuadExpr.`);if(e instanceof w||typeof e==`object`&&e&&`quadTerms`in e&&e.quadTerms instanceof Map&&`linearTerms`in e&&e.linearTerms instanceof Map){let a=e;J(a);let o=i+a.constant;if(!Number.isFinite(o))throw Error(`Constant accumulation overflows finite floating-point range in sum().`);i=o;for(let[e,n]of a.linearTerms){let r=(t.get(e)??0)+n;if(!Number.isFinite(r))throw Error(`Coefficient accumulation overflows finite floating-point range in sum().`);t.set(e,r)}for(let[e,t]of a.quadTerms){let r=n.get(e);if(r){let i=r.coeff+t.coeff;if(!Number.isFinite(i))throw Error(`Quadratic coefficient accumulation overflows finite floating-point range in sum().`);n.set(e,{var1:t.var1,var2:t.var2,coeff:i})}else n.set(e,{var1:t.var1,var2:t.var2,coeff:t.coeff})}if(Array.isArray(a.nonlinearTerms))for(let e of a.nonlinearTerms)e.coeff!==0&&r.push({atom:L(e.atom),coeff:e.coeff});return}if(e instanceof z||typeof e==`object`&&e&&`terms`in e&&e.terms instanceof Map&&typeof e.constant==`number`){let n=e;J(n);let a=i+n.constant;if(!Number.isFinite(a))throw Error(`Constant accumulation overflows finite floating-point range in sum().`);i=a;for(let[e,r]of n.terms){let n=(t.get(e)??0)+r;if(!Number.isFinite(n))throw Error(`Coefficient accumulation overflows finite floating-point range in sum().`);t.set(e,n)}if(Array.isArray(n.nonlinearTerms))for(let e of n.nonlinearTerms)e.coeff!==0&&r.push({atom:L(e.atom),coeff:e.coeff});return}if(Ve(e)){let n=e,r=(t.get(n)??0)+1;if(!Number.isFinite(r))throw Error(`Coefficient accumulation overflows finite floating-point range in sum().`);t.set(n,r);return}if(Array.isArray(e)){if(o>=2)throw Error(`Nested containers deeper than 2D are not supported in sum().`);for(let t=0;t<e.length;t++){if(!(t in e))throw Error(`Unsupported item in sum(): sparse array hole at index ${t}.`);a(e[t],o+1)}return}if(Fe(e)){if(o>=2)throw Error(`Nested containers deeper than 2D are not supported in sum().`);for(let t of e)a(t,o+1);return}if(Ne(e)){if(o>=2)throw Error(`Nested containers deeper than 2D are not supported in sum().`);if(Object.getOwnPropertySymbols(e).length>0)throw Error(`Symbol keys are not supported in sum().`);for(let t of Object.keys(e))a(e[t],o+1);return}throw Error(`Unsupported item in sum(): expected a number, Var, LinExpr, or QuadExpr.`)}};e(a);for(let[e,n]of t)n===0&&t.delete(e);for(let[e,t]of n)t.coeff===0&&n.delete(e);return n.size>0?new w(t,n,i,r):new z(t,i,r)}evalExtremumWithMapper(e,t,n){let r=e===`max`?be(t,n):xe(t,n);return J(r),r}evalSumSingle(e){if(!U(e))throw Error(`sum() requires a container (Array, Iterable, or Record) or (itemsOrCount, mapFn).`);return this.accumulateSumItems(t=>{t(e.data,0)})}evalSumWithMapper(e,t){return this.accumulateSumItems(n=>{if(typeof e==`number`){if(!Number.isInteger(e)||e<0)throw Error(`sum(count, mapFn) requires a non-negative integer count.`);for(let r=0;r<e;r++)n(t(r,r));return}if(Array.isArray(e)){for(let r=0;r<e.length;r++){if(!(r in e))throw Error(`Unsupported item in sum(): sparse array hole at index ${r}.`);n(t(e[r],r))}return}if(typeof e==`object`&&e&&!(e instanceof String)&&Symbol.iterator in e&&typeof e[Symbol.iterator]==`function`){let r=0;for(let i of e)n(t(i,r++));return}if(Ne(e)){if(Object.getOwnPropertySymbols(e).length>0)throw Error(`Symbol keys are not supported in sum().`);let r=0;for(let i of Object.keys(e))n(t(e[i],r++));return}throw Error(`Invalid first argument in sum(itemsOrCount, mapFn): expected an Iterable, Record, or non-negative integer count.`)})}evalDot(e,t){if(!U(e)||!U(t))throw Error(`dot() in template expression requires 1D or 2D Array or Record containers as arguments.`);if(e.fromNonArrayIterable||t.fromNonArrayIterable)throw Error(`Unsupported operand types in dot() at 'root': dot() requires Array or Record containers (use sum() for general Iterables).`);let n=ge(e.data,t.data);return J(n),n}applyPowerNode(e){if(this.peek()?.type!==`CARET`)return e;let t=[];for(;this.peek()?.type===`CARET`;){this.consume();let e=this.tokens[this.pos]?.type===`LPAREN`&&this.tokens[this.pos+1]?.type===`NUMBER`&&this.tokens[this.pos+2]?.type===`RPAREN`;e&&this.consume(`LPAREN`);let n=this.peek();if(!n||n.type!==`NUMBER`)throw Error(`Exponent must be a non-negative integer number`);this.consume(),e&&this.consume(`RPAREN`);let r=n.numericValue??Number(n.value);if(!Number.isInteger(r)||r<0)throw Error(`Exponent must be a non-negative integer`);t.push(r)}let n=t[t.length-1];for(let e=t.length-2;e>=0;e--)n=t[e]**+n;if(!Number.isFinite(n)||n<0)throw Error(`Exponent creates an invalid or out-of-range power`);if(typeof e==`number`){let t=e**+n;if(e!==0&&n>0&&t===0)throw Error(`Constant exponentiation underflows to zero.`);if(!Number.isFinite(t))throw Error(`Invalid non-finite constant "${t}" in expression.`);return t}return U(e)?{kind:`container`,data:W(e.data,e=>{if(typeof e==`number`){let t=e**+n;if(e!==0&&n>0&&t===0)throw Error(`Constant exponentiation underflows to zero.`);if(!Number.isFinite(t))throw Error(`Constant exponentiation overflows finite floating-point range.`);return t}let t=Ee(Me(Oe(e),n));return J(t),t}),fromNonArrayIterable:e.fromNonArrayIterable}:Me(e,n)}getRemainingToken(){return this.peek()}resolveNode(e){if(this.templateCtx?.functionMap.has(e))throw Error(`Function interpolation is only supported as the second argument of sum(itemsOrCount, mapFn) in template expressions.`);if(this.templateCtx?.rawContainerMap.has(e))return Ie(this.templateCtx.rawContainerMap.get(e));let t=this.resolver(e);if(!t)throw Error(`Unknown variable '${e}' in expression`);return t instanceof H||`id`in t&&!(`terms`in t)&&!(`quadTerms`in t)?new z(new Map([[t,1]]),0):t.clone()}};function K(e,t,n,r){let i=new Le(Te(e,n),t,r),a=i.parseExpression(),o=i.getRemainingToken();if(o)throw Error(`Unexpected token '${o.value}' after expression in "${e}"`);return J(a),a}function Re(e,t){return K(e,t)}function q(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];if(r===`(`)t++;else if(r===`)`)t>0&&t--;else if(t===0){let t=e.slice(n,n+2);if(t===`<=`||t===`>=`||t===`==`||t===`!=`||t===`=<`||t===`=>`)return{rawOp:t,index:n};if(r===`=`||r===`<`||r===`>`)return{rawOp:r,index:n}}}return null}function ze(e,t,n,r,i){let a=q(e);if(!a)throw Error(`Constraint must contain a comparison operator (<=, >=, ==, !=, <, >): "${e}"`);let o=a.rawOp,s=a.index,c=e.substring(0,s).trim(),l=e.substring(s+o.length).trim(),u;if(o===`<=`||o===`=<`)u=`<=`;else if(o===`>=`||o===`=>`)u=`>=`;else if(o===`==`||o===`=`)u=`==`;else if(o===`!=`)u=`!=`;else if(o===`<`)u=`<`;else if(o===`>`)u=`>`;else throw Error(`Unsupported operator "${o}"`);let d=K(c,t,r,i),f=K(l,t,r,i);if(d instanceof w&&d.quadTerms.size>0||f instanceof w&&f.quadTerms.size>0)throw Error(`Quadratic constraints are not supported (only linear constraints are allowed in MILP/LP/QP)`);let p=d instanceof w?new z(d.linearTerms,d.constant,d.nonlinearTerms):d,m=f instanceof w?new z(f.linearTerms,f.constant,f.nonlinearTerms):f,h;if(h=u===`<=`?p.le(m,n):u===`>=`?p.ge(m,n):u===`==`?p.eq(m,n):u===`!=`?p.ne(m,n):u===`<`?p.lt(m,n):p.gt(m,n),J(h.lhs),!Number.isFinite(h.rhs))throw Error(`Invalid non-finite right-hand side "${h.rhs}" in constraint.`);return h}function Be(e,t,n){return ze(e,t,n)}function Ve(e){return e instanceof H||e instanceof z||e instanceof w?!0:typeof e!=`object`||!e||He(e)?!1:`terms`in e&&e.terms instanceof Map&&typeof e.constant==`number`||`quadTerms`in e&&e.quadTerms instanceof Map&&`linearTerms`in e&&e.linearTerms instanceof Map&&typeof e.constant==`number`||typeof e.id==`number`&&typeof e.name==`string`&&typeof e.lb==`number`&&typeof e.ub==`number`&&typeof e.type==`string`&&typeof e.mul==`function`}function J(e){if(`constant`in e&&!Number.isFinite(e.constant))throw Error(`Invalid non-finite constant "${e.constant}" in expression.`);if(`terms`in e&&e.terms instanceof Map){for(let[,t]of e.terms)if(!Number.isFinite(t))throw Error(`Invalid non-finite coefficient "${t}" in expression.`)}if(`linearTerms`in e&&e.linearTerms instanceof Map){for(let[,t]of e.linearTerms)if(!Number.isFinite(t))throw Error(`Invalid non-finite coefficient "${t}" in expression.`)}if(`quadTerms`in e&&e.quadTerms instanceof Map){for(let[,t]of e.quadTerms)if(!Number.isFinite(t.coeff))throw Error(`Invalid non-finite quadratic coefficient "${t.coeff}" in expression.`)}if(`nonlinearTerms`in e&&Array.isArray(e.nonlinearTerms))for(let t of e.nonlinearTerms){if(!Number.isFinite(t.coeff))throw Error(`Invalid non-finite coefficient "${t.coeff}" in expression.`);if(t.atom.kind===`abs`)J(t.atom.arg);else if(t.atom.kind===`max`||t.atom.kind===`min`)for(let e of t.atom.args)J(e);else if(t.atom.kind===`at`){J(t.atom.index);for(let e of t.atom.array)J(e)}}}function He(e){return e instanceof I?!0:typeof e!=`object`||!e?!1:e.kind===`constraint`||`sense`in e&&(e.sense===`<=`||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}function Ue(e,t){let n=new Map,r=new Map,i=new Map,a=new Map,o=e.join(``),s=`__washi_`;for(;o.includes(s);)s+=`_`;let c=``;for(let o=0;o<e.length;o++)if(c+=e[o],o<t.length){let e=t[o];if(typeof e==`number`){if(!Number.isFinite(e))throw Error(`Invalid numeric value "${e}" in template expression: interpolated numbers must be finite.`);let t=`${s}num_${o}__`;r.set(t,e),c+=`(${t})`}else if(He(e))throw Error(`Cannot interpolate a constraint comparison (<=, >=, ==) inside a template expression: expected a finite number, Var, LinExpr, or QuadExpr.`);else if(Ve(e)){J(e);let t=`${s}ph_${o}__`;n.set(t,e),c+=` ${t} `}else if(typeof e==`function`){let t=`${s}fn_${o}__`;a.set(t,e),c+=` ${t} `}else if(Array.isArray(e)||Fe(e)||e instanceof Map||Ne(e)){let t=`${s}ph_${o}__`;i.set(t,e),c+=` ${t} `}else throw Error(`Unsupported interpolation value in template expression: expected a finite number, Var, LinExpr, or QuadExpr.`)}return{fullText:c,resolver:e=>n.get(e),numberMap:r,templateCtx:{rawContainerMap:i,functionMap:a}}}function We(e,...t){let{fullText:n,resolver:r,numberMap:i,templateCtx:a}=Ue(e,t);return q(n)?ze(n,r,void 0,i,a):K(n,r,i,a)}function Ge(e){return typeof e==`object`&&!!e&&typeof e.lpString==`string`&&e.nameToVar instanceof Map&&e.nameToConstraint instanceof Map}function Ke(e,t=`x`,n=0){let r=e.replace(/[^a-zA-Z0-9_]/g,`_`);return/^[0-9]/.test(r)&&(r=`${t}_${r}`),(!r||r.length===0)&&(r=`${t}_${n}`),r}function qe(e){let t=e.variables||[],n=e.constraints||[],r=new Map,i=new Map,a=new Map,o=new Map,s=new Map,c=new Set;for(let e=0;e<t.length;e++){let n=t[e];s.set(n,e);let a=Ke(n.name,`x`,e),o=a,l=1;for(;c.has(o);)o=`${a}_${l++}`;c.add(o),i.set(n,o),r.set(o,n)}let l=new Set;for(let e=0;e<n.length;e++){let t=n[e],r=Ke(t.name,`c`,e+1),i=r,s=1;for(;l.has(i);)i=`${r}_${s++}`;l.add(i),o.set(t,i),a.set(i,t)}return{nameToVar:r,varToName:i,nameToConstraint:a,constraintToName:o,constrToName:o,varOrder:s}}function Je(e,t){let{sense:n,objective:r,constraints:i,variables:a}=e;if(typeof r.hasNonlinearTerms==`function`&&r.hasNonlinearTerms())throw Error(`generateLpString() received an unlowered nonlinear objective (max/min/abs/at). Lower via Model.toLpString() or linearizeModelForMip() first.`);let o=t?.relax===!0,{nameToVar:s,varToName:c,nameToConstraint:l,constrToName:u,varOrder:d}=qe(e),f=[];f.push(n&&n.toLowerCase()===`maximize`?`Maximize`:`Minimize`);let p=[],m=!0,h=r instanceof w?r.linearTerms:r.terms;if(h)for(let[e,t]of h){if(t===0)continue;let n=c.get(e),r=t>=0?m?``:`+ `:`- `,i=Math.abs(t),a=i===1?``:`${i} `;p.push(`${r}${a}${n}`),m=!1}if(r instanceof w&&r.quadTerms.size>0){let e=[],t=!0,n=Array.from(r.quadTerms.values()).filter(e=>e.coeff!==0).map(e=>{let t=d.get(e.var1)??e.var1.id,n=d.get(e.var2)??e.var2.id,[r,i,a,o]=t<=n?[e.var1,e.var2,t,n]:[e.var2,e.var1,n,t];return{firstVar:r,secondVar:i,firstIdx:a,secondIdx:o,coeff:e.coeff}}).sort((e,t)=>e.firstIdx-t.firstIdx||e.secondIdx-t.secondIdx);for(let r of n){let n=2*r.coeff,i=n>=0?t?``:`+ `:`- `,a=Math.abs(n),o=a===1?``:`${a} `,s=c.get(r.firstVar),l=c.get(r.secondVar);r.firstVar===r.secondVar?e.push(`${i}${o}${s} ^ 2`):e.push(`${i}${o}${s} * ${l}`),t=!1}if(e.length>0){let t=`[ ${e.join(` `)} ] / 2`;p.length>0?p.push(`+`,t):p.push(t)}}let g=p.length>0?p.join(` `):`0`;f.push(` obj: ${g}`),f.push(`Subject To`);for(let e of i){if(e.sense===`!=`||e.lhs.hasNonlinearTerms())throw Error(`generateLpString() received unlowered constraint "${e.name}" (${e.sense===`!=`?`discrete !=`:`nonlinear max/min/abs/at`}). Lower via Model.toLpString() or linearizeModelForMip() first.`);let t=u.get(e),n=[],r=!0;for(let[t,i]of e.lhs.terms){if(i===0)continue;let e=c.get(t),a=i>=0?r?``:`+ `:`- `,o=Math.abs(i),s=o===1?``:`${o} `;n.push(`${a}${s}${e}`),r=!1}let i=n.length>0?n.join(` `):`0`,a=e.sense===`==`?`=`:e.sense;f.push(` ${t}: ${i} ${a} ${e.rhs}`)}f.push(`Bounds`);let _=[],v=[];for(let e of a){let t=c.get(e);if(!o&&e.type===`Binary`){v.push(t);continue}!o&&e.type===`Integer`&&_.push(t);let n=e.lb===-1/0,r=e.ub===1/0;n&&r?f.push(` ${t} free`):n&&!r?f.push(` -infinity <= ${t} <= ${e.ub}`):!n&&r?(e.lb!==0||e.initialValue!==void 0)&&f.push(` ${t} >= ${e.lb}`):f.push(` ${e.lb} <= ${t} <= ${e.ub}`)}if(_.length>0){f.push(`Generals`);for(let e=0;e<_.length;e+=10)f.push(` `+_.slice(e,e+10).join(` `))}if(v.length>0){f.push(`Binary`);for(let e=0;e<v.length;e+=10)f.push(` `+v.slice(e,e+10).join(` `))}return f.push(`End`),{lpString:f.join(`
2
- `)+`
3
- `,nameToVar:s,nameToConstraint:l}}var Ye=Symbol.for(`washi.solverRegistry`),Xe=Symbol.for(`washi.defaultSolverFactory`),Ze=globalThis;Ze[Ye]||(Ze[Ye]=new Map);var Qe=Ze[Ye];function $e(e,t){Qe.set(e.toLowerCase(),t)}function et(e){if(typeof e==`string`){let t=Qe.get(e.toLowerCase());if(!t)throw Error(`Solver '${e}' is not registered.`);Ze[Xe]=t}else Ze[Xe]=typeof e==`function`?e:()=>e}function tt(e,t){if(!e){let e=Ze[Xe]||Qe.get(`highs`);if(!e)throw Error(`No default solver available. Available solvers: ${nt().join(`, `)}`);return e(t)}if(typeof e==`string`){let n=e.toLowerCase(),r=Qe.get(n);if(!r)throw Error(n===`glpk`?`Solver 'glpk' not found. Available solvers: ${nt().join(`, `)}. Please import '@ohtaman/washi/solvers/glpk' before selecting this solver.`:n===`z3`?`Solver 'z3' not found. Available solvers: ${nt().join(`, `)}. Please import '@ohtaman/washi/solvers/z3' before selecting this solver.`:`Solver '${e}' not found. Available solvers: ${nt().join(`, `)}`);return r(t)}return e}function nt(){return Array.from(Qe.keys())}var rt=class{name;capabilities;options;constructor(e={}){this.name=e.name||`MockSolver`,this.capabilities=e.capabilities||{supportsMIP:!0,supportsQP:!0,supportsWarmStart:!0},this.options=e}async solve(e,t={},n={}){let r=Ge(t)?n:t,i={...this.options,...r},a=!!(i.values&&Object.keys(i.values).length>0||i.boolValues&&Object.keys(i.boolValues).length>0);if(i.signal?.aborted)return{status:`Unknown`,terminationStatus:`Interrupted`,hasPrimalSolution:!1,objectiveValue:null,values:{},runTime:0,raw:{mock:!0}};if(i.delayMs&&i.delayMs>0&&(await new Promise(e=>{let t=setTimeout(()=>{i.signal?.removeEventListener(`abort`,n),e()},i.delayMs),n=()=>{clearTimeout(t),e()};i.signal?.addEventListener(`abort`,n,{once:!0})}),i.signal?.aborted)){let e=!!(i.hasPrimalSolution??a);return{status:e?`Feasible`:`Unknown`,terminationStatus:`Interrupted`,hasPrimalSolution:e,objectiveValue:e?i.objectiveValue??0:null,...i.objectiveBound===void 0?{}:{objectiveBound:i.objectiveBound},...i.relativeGap===void 0?{}:{relativeGap:i.relativeGap},...i.absoluteGap===void 0?{}:{absoluteGap:i.absoluteGap},values:e&&i.values||{},...e&&i.boolValues!==void 0?{boolValues:i.boolValues}:{},runTime:.001,raw:{mock:!0}}}if(i.onProgress&&Array.isArray(i.progressEvents))for(let e of i.progressEvents){if(i.signal?.aborted)break;i.onProgress(e)}let o=i.status||`Optimal`,s=i.terminationStatus??o,c=i.hasPrimalSolution===void 0?o===`Optimal`||o===`Feasible`||o===`Sat`||(o===`TimeLimit`||o===`IterationLimit`||s===`Interrupted`)&&a:i.hasPrimalSolution;if(i.onProgress&&!Array.isArray(i.progressEvents)&&!i.signal?.aborted){let e=c?i.objectiveValue??0:void 0;i.onProgress({elapsedTime:.001,elapsedSeconds:.001,...typeof e==`number`&&Number.isFinite(e)?{objectiveValue:e}:{},...i.objectiveBound===void 0?{}:{objectiveBound:i.objectiveBound},...i.relativeGap===void 0?{}:{relativeGap:i.relativeGap},...i.absoluteGap===void 0?{}:{absoluteGap:i.absoluteGap}})}return i.signal?.aborted&&(s=`Interrupted`,c=i.hasPrimalSolution===void 0?a:i.hasPrimalSolution,o=c?`Feasible`:`Unknown`),{status:o,terminationStatus:s,hasPrimalSolution:c,objectiveValue:c?i.objectiveValue??0:null,...i.objectiveBound===void 0?{}:{objectiveBound:i.objectiveBound},...i.relativeGap===void 0?{}:{relativeGap:i.relativeGap},...i.absoluteGap===void 0?{}:{absoluteGap:i.absoluteGap},values:c&&i.values||{},...c&&i.boolValues!==void 0?{boolValues:i.boolValues}:{},reducedCosts:i.reducedCosts,duals:i.duals,slacks:i.slacks,runTime:.001,raw:{mock:!0}}}};function it(){$e(`mock`,e=>new rt(e))}it();var at=`v1.16.0:d1c2cb62726e24a7:2bd77844c41e9c91`,ot=`0.5.0:fc7ddaf3ae17fcc8:ea94cc1b794de550`,st={highs:null,pumpkin:null};function ct(e){return e===`highs`?at:ot}function lt(e){return Symbol.for(`washi.embeddedWasm.${e}.${ct(e)}`)}function ut(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&Object.prototype.toString.call(e)===`[object Uint8Array]`}function dt(e,t,n){if(!ut(t))throw Error(`[WaSHI] Invalid ${e} ${n}: expected Uint8Array.`);let r=new Uint8Array(t.byteLength);if(r.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength)),r.byteLength<8||r[0]!==0||r[1]!==97||r[2]!==115||r[3]!==109)throw Error(`[WaSHI] Invalid ${e} ${n}: expected at least 8 bytes starting with \\0asm magic header.`);return r}function ft(e){let t=ct(e),n=lt(e),r=globalThis[n];if(r===void 0)return null;if(typeof r!=`object`||!r)throw Error(`[WaSHI] Invalid embedded WASM pack registered for ${e} (${t}).`);let i=r;if(i.solver!==e||i.compatId!==t||typeof i.getBytes!=`function`)throw Error(`[WaSHI] Invalid embedded WASM pack registered for ${e} (${t}).`);return dt(e,i.getBytes(),`embedded inline WASM binary`)}function pt(e){let t=st[e];if(t!==null)return t;let n=ft(e),r=n===null?{kind:`url`}:{kind:`embedded`,bytes:n};return st[e]=r,r}function mt(e){return st[e]}var ht=typeof document<`u`?document.currentScript?.src:null,gt=ht?new URL(`.`,ht).href:null;function _t(e){if(!gt)throw Error(`[WaSHI] Load the browser IIFE using an external script src, or use the browser ESM build.`);return new URL(e,gt).href}function vt(){return _t(`solvers/highs.wasm`)}function yt(){throw Error(`This distribution is for browsers. Use the npm entry in Node.js.`)}function bt(e,t,n){if(n<=0||!t)return new Float64Array;let r=e.wasmMemory?e.wasmMemory.buffer:e.HEAPF64?e.HEAPF64.buffer:e.HEAP8?.buffer;if(r)return new Float64Array(r,t,n).slice();let i=new Float64Array(n);for(let r=0;r<n;r++)i[r]=e.getValue(t+r*8,`double`);return i}function xt(e){return{create:e.cwrap(`Highs_create`,`number`,[]),destroy:e.cwrap(`Highs_destroy`,`void`,[`number`]),clearModel:e.cwrap(`Highs_clearModel`,`number`,[`number`]),version:e.cwrap(`Highs_version`,`string`,[]),readModel:e.cwrap(`Highs_readModel`,`number`,[`number`,`string`]),run:e.cwrap(`Highs_run`,`number`,[`number`]),getNumCol:e.cwrap(`Highs_getNumCol`,`number`,[`number`]),getNumRow:e.cwrap(`Highs_getNumRow`,`number`,[`number`]),getNumNz:e.cwrap(`Highs_getNumNz`,`number`,[`number`]),getObjectiveValue:e.cwrap(`Highs_getObjectiveValue`,`number`,[`number`]),getModelStatus:e.cwrap(`Highs_getModelStatus`,`number`,[`number`]),getSolution:e.cwrap(`Highs_getSolution`,`number`,[`number`,`number`,`number`,`number`,`number`]),getColName:e.cwrap(`Highs_getColName`,`number`,[`number`,`number`,`number`]),getRowName:e.cwrap(`Highs_getRowName`,`number`,[`number`,`number`,`number`]),getColIntegrality:e.cwrap(`Highs_getColIntegrality`,`number`,[`number`,`number`,`number`]),changeObjectiveOffset:e.cwrap(`Highs_changeObjectiveOffset`,`number`,[`number`,`number`]),getObjectiveOffset:e.cwrap(`Highs_getObjectiveOffset`,`number`,[`number`,`number`]),setBoolOptionValue:e.cwrap(`Highs_setBoolOptionValue`,`number`,[`number`,`string`,`number`]),setIntOptionValue:e.cwrap(`Highs_setIntOptionValue`,`number`,[`number`,`string`,`number`]),setDoubleOptionValue:e.cwrap(`Highs_setDoubleOptionValue`,`number`,[`number`,`string`,`number`]),setStringOptionValue:e.cwrap(`Highs_setStringOptionValue`,`number`,[`number`,`string`,`string`]),setSolution:e.cwrap(`Highs_setSolution`,`number`,[`number`,`number`,`number`,`number`,`number`]),setSparseSolution:e.cwrap(`Highs_setSparseSolution`,`number`,[`number`,`number`,`number`,`number`]),getIntInfoValue:e.cwrap(`Highs_getIntInfoValue`,`number`,[`number`,`string`,`number`]),getDoubleInfoValue:e.cwrap(`Highs_getDoubleInfoValue`,`number`,[`number`,`string`,`number`]),getInt64InfoValue:e.cwrap(`Highs_getInt64InfoValue`,`number`,[`number`,`string`,`number`]),setCallback:e.cwrap(`Highs_setCallback`,`number`,[`number`,`number`,`number`]),startCallback:e.cwrap(`Highs_startCallback`,`number`,[`number`,`number`]),stopCallback:e.cwrap(`Highs_stopCallback`,`number`,[`number`,`number`])}}var St,Ct,wt,Tt,Et,Dt,Ot,kt=n((()=>{St=class extends Error{constructor(e){super(e),this.name=`HighsError`}},Ct=class extends St{constructor(e){super(e),this.name=`HighsUnsupportedOptionError`}},wt={0:`Not Set`,1:`Load error`,2:`Model error`,3:`Presolve error`,4:`Solve error`,5:`Postsolve error`,6:`Empty`,7:`Optimal`,8:`Infeasible`,9:`Primal infeasible or unbounded`,10:`Unbounded`,11:`Bound on objective reached`,12:`Target for objective reached`,13:`Time limit reached`,14:`Iteration limit reached`,15:`Unknown`,16:`Solution limit reached`,17:`Interrupted`,18:`Memory limit reached`},Tt={callbackType:{logging:0,simplexInterrupt:1,ipmInterrupt:2,mipSolution:3,mipImprovingSolution:4,mipLogging:5,mipInterrupt:6,mipGetCutPool:7,mipDefineLazyConstraints:8,mipUserSolution:9},solutionStatus:{none:0,infeasible:1,feasible:2},modelStatus:{notSet:0,loadError:1,modelError:2,presolveError:3,solveError:4,postsolveError:5,modelEmpty:6,optimal:7,infeasible:8,unboundedOrInfeasible:9,unbounded:10,objectiveBound:11,objectiveTarget:12,timeLimit:13,iterationLimit:14,unknown:15,solutionLimit:16,interrupt:17}},Et=0,Dt=class{highs;module;bindings;stringBuf;isDestroyed=!1;constructor(e,t,n){this.module=e,this.bindings=t,this.highs=n??t.create(),this.stringBuf=e._malloc(512)}changeObjectiveOffset(e){let t=this.bindings.changeObjectiveOffset(this.highs,e);if(t!==0)throw new St(`Highs_changeObjectiveOffset failed with status ${t}`)}getObjectiveOffset(){let e=this.module._malloc(8);try{return this.bindings.getObjectiveOffset(this.highs,e),this.module.getValue(e,`double`)}finally{this.module._free(e)}}options={set:(e,t)=>{let n=-1;if(typeof t==`boolean`?n=this.bindings.setBoolOptionValue(this.highs,e,+!!t):typeof t==`number`?Number.isInteger(t)?(n=this.bindings.setIntOptionValue(this.highs,e,t),n!==0&&(n=this.bindings.setDoubleOptionValue(this.highs,e,t))):n=this.bindings.setDoubleOptionValue(this.highs,e,t):typeof t==`string`&&(n=this.bindings.setStringOptionValue(this.highs,e,t)),n!==0)throw new Ct(`Option "${e}" with value ${JSON.stringify(t)} is not supported or invalid in HiGHS`)}};getDimensions(){return{numCols:this.bindings.getNumCol(this.highs),numRows:this.bindings.getNumRow(this.highs)}}getColIntegrality(e){let t=this.module._malloc(4);try{return this.bindings.getColIntegrality(this.highs,e,t),this.module.getValue(t,`i32`)}finally{this.module._free(t)}}getColName(e){return this.bindings.getColName(this.highs,e,this.stringBuf),this.module.UTF8ToString(this.stringBuf)}getRowName(e){return this.bindings.getRowName(this.highs,e,this.stringBuf),this.module.UTF8ToString(this.stringBuf)}setSolution(e){if(e.colValue&&Array.isArray(e.colValue)){let t=e.colValue.length,n=this.module._malloc(t*8);try{for(let r=0;r<t;r++)this.module.setValue(n+r*8,e.colValue[r],`double`);let r=this.bindings.setSolution(this.highs,n,0,0,0);if(r!==0)throw new St(`Highs_setSolution failed with status ${r}`)}finally{this.module._free(n)}return}if(e.indices&&e.values&&e.indices.length===e.values.length){let t=e.indices.length,n=this.module._malloc(t*4),r=this.module._malloc(t*8);try{for(let i=0;i<t;i++)this.module.setValue(n+i*4,e.indices[i],`i32`),this.module.setValue(r+i*8,e.values[i],`double`);let i=this.bindings.setSparseSolution(this.highs,t,n,r);if(i!==0)throw new St(`Highs_setSparseSolution failed with status ${i}`)}finally{this.module._free(n),this.module._free(r)}return}throw new St(`Invalid argument to setSolution (expected { colValue } or { indices, values })`)}run(e){let t=0,n=[];if(e){if(typeof this.module.addFunction!=`function`)throw new St(`HiGHS WebAssembly runtime does not support module.addFunction; progress and interrupt callbacks are unavailable.`);t=this.module.addFunction((t,n,r,i)=>{let a=e[t];if(!a)return;let o={};if(r){let e=this.module.getValue(r+8,`double`),t=this.module.getValue(r+16,`i32`),n=this.module.getValue(r+20,`i32`),i=this.module.getValue(r+24,`i32`),a=this.module.getValue(r+32,`double`),s=Number(this.module.getValue(r+40,`i32`)),c=Number(this.module.getValue(r+48,`i32`)),l=this.module.getValue(r+56,`double`),u=this.module.getValue(r+64,`double`),d=this.module.getValue(r+72,`double`),f=this.module.getValue(r+80,`i32`),p=this.module.getValue(r+84,`i32`),m;f&&p>0&&(m=bt(this.module,f,p)),o={running_time:e,simplex_iteration_count:t,ipm_iteration_count:n,pdlp_iteration_count:i,objective_function_value:a,mip_node_count:s,mip_total_lp_iterations:c,mip_primal_bound:l,mip_dual_bound:u,mip_gap:d,...m?{mip_solution:m}:{}}}let s=n?this.module.UTF8ToString(n):``;a({data:o,message:s,interrupt:()=>{i&&this.module.setValue(i,1,`i32`)}})},`vipppp`),this.bindings.setCallback(this.highs,t,0);for(let t of Object.keys(e)){let e=Number(t);this.bindings.startCallback(this.highs,e),n.push(e)}}try{return this.bindings.run(this.highs)}finally{if(t){for(let e of n)try{this.bindings.stopCallback(this.highs,e)}catch{}try{this.module.removeFunction(t)}catch{}}}}getModelStatus(){return this.bindings.getModelStatus(this.highs)}info={get:e=>{let t=this.module._malloc(8);try{if(this.bindings.getDoubleInfoValue(this.highs,e,t)===0)return this.module.getValue(t,`double`)}finally{this.module._free(t)}let n=this.module._malloc(4);try{if(this.bindings.getIntInfoValue(this.highs,e,n)===0)return this.module.getValue(n,`i32`)}finally{this.module._free(n)}throw new St(`Info item "${e}" not available or unknown in HiGHS`)}};getSolution(){let e=this.getDimensions(),t=e.numCols>0?this.module._malloc(e.numCols*8):0,n=e.numCols>0?this.module._malloc(e.numCols*8):0,r=e.numRows>0?this.module._malloc(e.numRows*8):0,i=e.numRows>0?this.module._malloc(e.numRows*8):0;try{return this.bindings.getSolution(this.highs,t,n,r,i),{colValue:bt(this.module,t,e.numCols),colDual:bt(this.module,n,e.numCols),rowValue:bt(this.module,r,e.numRows),rowDual:bt(this.module,i,e.numRows)}}finally{t&&this.module._free(t),n&&this.module._free(n),r&&this.module._free(r),i&&this.module._free(i)}}getObjectiveValue(){return this.bindings.getObjectiveValue(this.highs)}destroy(){if(!this.isDestroyed){this.isDestroyed=!0;try{this.module._free(this.stringBuf)}catch{}try{this.bindings.destroy(this.highs)}catch{}}}[Symbol.dispose](){this.destroy()}},Ot=class{module;bindings;constants=Tt;errors={HighsError:St,HighsUnsupportedOptionError:Ct};constructor(e){this.module=e,this.bindings=xt(e)}withModel(e,t){let n=this.bindings.create(),r=new Dt(this.module,this.bindings,n),i=`/model_${++Et}.${e.format}`;if(!this.module.FS)throw new St(`Emscripten FS is not initialized on this HiGHS module instance`);let a=this.module.FS;try{a.writeFile(i,e.data);let o=this.bindings.readModel(n,i);if(o!==0)throw new St(`Failed to load ${e.format.toUpperCase()} model into HiGHS (status ${o})`);return t(r)}finally{try{a.unlink(i)}catch{}r.destroy()}}solve(e,t={}){return this.withModel({format:`lp`,data:e},e=>{for(let[n,r]of Object.entries(t))e.options.set(n,r);e.run();let n=e.getModelStatus(),r=e.getDimensions(),i=e.getSolution(),a={};for(let t=0;t<r.numCols;t++){let n=e.getColName(t);a[n]={Index:t,Name:n,Primal:i.colValue[t],Dual:i.colDual[t]}}return{Status:wt[n]??`Unknown`,StatusCode:n,ObjectiveValue:e.getObjectiveValue(),Columns:a}})}}})),At,jt=n((()=>{At=(()=>{var e={}.url;return(async function(t={}){var n=t,r,i;n.ready=new Promise((e,t)=>{r=e,i=t});var a=Object.assign({},n),o=`./this.program`,s=(e,t)=>{throw t},c=typeof window==`object`,l=typeof importScripts==`function`,u=``;function d(e){return n.locateFile?n.locateFile(e,u):u+e}var f,p,m;(c||l)&&(l?u=self.location.href:typeof document<`u`&&document.currentScript&&(u=document.currentScript.src),e&&(u=e),u=u.indexOf(`blob:`)===0?``:u.substr(0,u.replace(/[?#].*/,``).lastIndexOf(`/`)+1),f=e=>{var t=new XMLHttpRequest;return t.open(`GET`,e,!1),t.send(null),t.responseText},l&&(m=e=>{var t=new XMLHttpRequest;return t.open(`GET`,e,!1),t.responseType=`arraybuffer`,t.send(null),new Uint8Array(t.response)}),p=(e,t,n)=>{var r=new XMLHttpRequest;r.open(`GET`,e,!0),r.responseType=`arraybuffer`,r.onload=()=>{if(r.status==200||r.status==0&&r.response){t(r.response);return}n()},r.onerror=n,r.send(null)});var h=n.print||console.log.bind(console),g=n.printErr||console.error.bind(console);Object.assign(n,a),a=null,n.arguments&&n.arguments,n.thisProgram&&(o=n.thisProgram),n.quit&&(s=n.quit);var _;n.wasmBinary&&(_=n.wasmBinary),typeof WebAssembly!=`object`&&F(`no native wasm support detected`);var v,y=!1;function b(e,t){e||F(t)}var x,S,C,w,T,E,D;function ee(){var e=v.buffer;n.HEAP8=x=new Int8Array(e),n.HEAP16=C=new Int16Array(e),n.HEAPU8=S=new Uint8Array(e),n.HEAPU16=new Uint16Array(e),n.HEAP32=w=new Int32Array(e),n.HEAPU32=T=new Uint32Array(e),n.HEAPF32=E=new Float32Array(e),n.HEAPF64=D=new Float64Array(e)}var O=[],k=[],A=[],te=!1;function ne(){if(n.preRun)for(typeof n.preRun==`function`&&(n.preRun=[n.preRun]);n.preRun.length;)j(n.preRun.shift());_e(O)}function re(){te=!0,!n.noFSInit&&!K.init.initialized&&K.init(),K.ignorePermissions=!1,W.init(),_e(k)}function ie(){if(n.postRun)for(typeof n.postRun==`function`&&(n.postRun=[n.postRun]);n.postRun.length;)ae(n.postRun.shift());_e(A)}function j(e){O.unshift(e)}function M(e){k.unshift(e)}function ae(e){A.unshift(e)}var oe=0,se=null,N=null;function P(e){return e}function ce(e){oe++,n.monitorRunDependencies&&n.monitorRunDependencies(oe)}function le(e){if(oe--,n.monitorRunDependencies&&n.monitorRunDependencies(oe),oe==0&&(se!==null&&(clearInterval(se),se=null),N)){var t=N;N=null,t()}}function F(e){n.onAbort&&n.onAbort(e),e=`Aborted(`+e+`)`,g(e),y=!0,e+=`. Build with -sASSERTIONS for more info.`,te&&wn();var t=new WebAssembly.RuntimeError(e);throw i(t),t}var ue=`data:application/octet-stream;base64,`,I=e=>e.startsWith(ue),de=e=>e.startsWith(`file://`),L;n.locateFile?(L=`highs.wasm`,I(L)||(L=d(L))):L=new URL(`highs.wasm`,``+{}.url).href;function fe(e){if(e==L&&_)return new Uint8Array(_);if(m)return m(e);throw`both async and sync fetching of the wasm failed`}function pe(e){if(!_&&(c||l)){if(typeof fetch==`function`&&!de(e))return fetch(e,{credentials:`same-origin`}).then(t=>{if(!t.ok)throw`failed to load wasm binary file at '`+e+`'`;return t.arrayBuffer()}).catch(()=>fe(e));if(p)return new Promise((t,n)=>{p(e,e=>t(new Uint8Array(e)),n)})}return Promise.resolve().then(()=>fe(e))}function me(e,t,n){return pe(e).then(e=>WebAssembly.instantiate(e,t)).then(e=>e).then(n,e=>{g(`failed to asynchronously prepare wasm: ${e}`),F(e)})}function R(e,t,n,r){return!e&&typeof WebAssembly.instantiateStreaming==`function`&&!I(t)&&!de(t)&&typeof fetch==`function`?fetch(t,{credentials:`same-origin`}).then(e=>WebAssembly.instantiateStreaming(e,n).then(r,function(e){return g(`wasm streaming compile failed: ${e}`),g(`falling back to ArrayBuffer instantiation`),me(t,n,r)})):me(t,n,r)}function he(){var e={a:Gt};function t(e,t){return Y=e.exports,v=Y.s,n.wasmMemory=v,ee(),Mt=Y.ca,M(Y.t),le(`wasm-instantiate`),Y}ce(`wasm-instantiate`);function r(e){t(e.instance)}if(n.instantiateWasm)try{return n.instantiateWasm(e,t)}catch(e){g(`Module.instantiateWasm callback failed with error: ${e}`),i(e)}return R(_,L,e,r).catch(i),{}}var z,B;function ge(e){this.name=`ExitStatus`,this.message=`Program terminated with exit(${e})`,this.status=e}var _e=e=>{for(;e.length>0;)e.shift()(n)};function ve(e,t=`i8`){switch(t.endsWith(`*`)&&(t=`*`),t){case`i1`:return x[e>>0];case`i8`:return x[e>>0];case`i16`:return C[e>>1];case`i32`:return w[e>>2];case`i64`:F(`to do getValue(i64) use WASM_BIGINT`);case`float`:return E[e>>2];case`double`:return D[e>>3];case`*`:return T[e>>2];default:F(`invalid type for getValue: ${t}`)}}var ye=n.noExitRuntime||!0;function be(e,t,n=`i8`){switch(n.endsWith(`*`)&&(n=`*`),n){case`i1`:x[e>>0]=t;break;case`i8`:x[e>>0]=t;break;case`i16`:C[e>>1]=t;break;case`i32`:w[e>>2]=t;break;case`i64`:F(`to do setValue(i64) use WASM_BIGINT`);case`float`:E[e>>2]=t;break;case`double`:D[e>>3]=t;break;case`*`:T[e>>2]=t;break;default:F(`invalid type for setValue: ${n}`)}}var xe=e=>(w[xn()>>2]=e,e),V={isAbs:e=>e.charAt(0)===`/`,splitPath:e=>/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(e).slice(1),normalizeArray:(e,t)=>{for(var n=0,r=e.length-1;r>=0;r--){var i=e[r];i===`.`?e.splice(r,1):i===`..`?(e.splice(r,1),n++):n&&(e.splice(r,1),n--)}if(t)for(;n;n--)e.unshift(`..`);return e},normalize:e=>{var t=V.isAbs(e),n=e.substr(-1)===`/`;return e=V.normalizeArray(e.split(`/`).filter(e=>!!e),!t).join(`/`),!e&&!t&&(e=`.`),e&&n&&(e+=`/`),(t?`/`:``)+e},dirname:e=>{var t=V.splitPath(e),n=t[0],r=t[1];return!n&&!r?`.`:(r&&=r.substr(0,r.length-1),n+r)},basename:e=>{if(e===`/`)return`/`;e=V.normalize(e),e=e.replace(/\/$/,``);var t=e.lastIndexOf(`/`);return t===-1?e:e.substr(t+1)},join:function(){var e=Array.prototype.slice.call(arguments);return V.normalize(e.join(`/`))},join2:(e,t)=>V.normalize(e+`/`+t)},Se=()=>{if(typeof crypto==`object`&&typeof crypto.getRandomValues==`function`)return e=>crypto.getRandomValues(e);F(`initRandomDevice`)},Ce=e=>(Ce=Se())(e),H={resolve:function(){for(var e=``,t=!1,n=arguments.length-1;n>=-1&&!t;n--){var r=n>=0?arguments[n]:K.cwd();if(typeof r!=`string`)throw TypeError(`Arguments to path.resolve must be strings`);if(!r)return``;e=r+`/`+e,t=V.isAbs(r)}return e=V.normalizeArray(e.split(`/`).filter(e=>!!e),!t).join(`/`),(t?`/`:``)+e||`.`},relative:(e,t)=>{e=H.resolve(e).substr(1),t=H.resolve(t).substr(1);function n(e){for(var t=0;t<e.length&&e[t]===``;t++);for(var n=e.length-1;n>=0&&e[n]===``;n--);return t>n?[]:e.slice(t,n-t+1)}for(var r=n(e.split(`/`)),i=n(t.split(`/`)),a=Math.min(r.length,i.length),o=a,s=0;s<a;s++)if(r[s]!==i[s]){o=s;break}for(var c=[],s=o;s<r.length;s++)c.push(`..`);return c=c.concat(i.slice(o)),c.join(`/`)}},U=typeof TextDecoder<`u`?new TextDecoder(`utf8`):void 0,we=(e,t,n)=>{for(var r=t+n,i=t;e[i]&&!(i>=r);)++i;if(i-t>16&&e.buffer&&U)return U.decode(e.subarray(t,i));for(var a=``;t<i;){var o=e[t++];if(!(o&128)){a+=String.fromCharCode(o);continue}var s=e[t++]&63;if((o&224)==192){a+=String.fromCharCode((o&31)<<6|s);continue}var c=e[t++]&63;if(o=(o&240)==224?(o&15)<<12|s<<6|c:(o&7)<<18|s<<12|c<<6|e[t++]&63,o<65536)a+=String.fromCharCode(o);else{var l=o-65536;a+=String.fromCharCode(55296|l>>10,56320|l&1023)}}return a},Te=[],Ee=e=>{for(var t=0,n=0;n<e.length;++n){var r=e.charCodeAt(n);r<=127?t++:r<=2047?t+=2:r>=55296&&r<=57343?(t+=4,++n):t+=3}return t},De=(e,t,n,r)=>{if(!(r>0))return 0;for(var i=n,a=n+r-1,o=0;o<e.length;++o){var s=e.charCodeAt(o);if(s>=55296&&s<=57343){var c=e.charCodeAt(++o);s=65536+((s&1023)<<10)|c&1023}if(s<=127){if(n>=a)break;t[n++]=s}else if(s<=2047){if(n+1>=a)break;t[n++]=192|s>>6,t[n++]=128|s&63}else if(s<=65535){if(n+2>=a)break;t[n++]=224|s>>12,t[n++]=128|s>>6&63,t[n++]=128|s&63}else{if(n+3>=a)break;t[n++]=240|s>>18,t[n++]=128|s>>12&63,t[n++]=128|s>>6&63,t[n++]=128|s&63}}return t[n]=0,n-i};function Oe(e,t,n){var r=n>0?n:Ee(e)+1,i=Array(r),a=De(e,i,0,i.length);return t&&(i.length=a),i}var ke=()=>{if(!Te.length){var e=null;if(typeof window<`u`&&typeof window.prompt==`function`?(e=window.prompt(`Input: `),e!==null&&(e+=`
4
- `)):typeof readline==`function`&&(e=readline(),e!==null&&(e+=`
5
- `)),!e)return null;Te=Oe(e,!0)}return Te.shift()},W={ttys:[],init(){},shutdown(){},register(e,t){W.ttys[e]={input:[],output:[],ops:t},K.registerDevice(e,W.stream_ops)},stream_ops:{open(e){var t=W.ttys[e.node.rdev];if(!t)throw new K.ErrnoError(43);e.tty=t,e.seekable=!1},close(e){e.tty.ops.fsync(e.tty)},fsync(e){e.tty.ops.fsync(e.tty)},read(e,t,n,r,i){if(!e.tty||!e.tty.ops.get_char)throw new K.ErrnoError(60);for(var a=0,o=0;o<r;o++){var s;try{s=e.tty.ops.get_char(e.tty)}catch{throw new K.ErrnoError(29)}if(s===void 0&&a===0)throw new K.ErrnoError(6);if(s==null)break;a++,t[n+o]=s}return a&&(e.node.timestamp=Date.now()),a},write(e,t,n,r,i){if(!e.tty||!e.tty.ops.put_char)throw new K.ErrnoError(60);try{for(var a=0;a<r;a++)e.tty.ops.put_char(e.tty,t[n+a])}catch{throw new K.ErrnoError(29)}return r&&(e.node.timestamp=Date.now()),a}},default_tty_ops:{get_char(e){return ke()},put_char(e,t){t===null||t===10?(h(we(e.output,0)),e.output=[]):t!=0&&e.output.push(t)},fsync(e){e.output&&e.output.length>0&&(h(we(e.output,0)),e.output=[])},ioctl_tcgets(e){return{c_iflag:25856,c_oflag:5,c_cflag:191,c_lflag:35387,c_cc:[3,28,127,21,4,0,1,0,17,19,26,0,18,15,23,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},ioctl_tcsets(e,t,n){return 0},ioctl_tiocgwinsz(e){return[24,80]}},default_tty1_ops:{put_char(e,t){t===null||t===10?(g(we(e.output,0)),e.output=[]):t!=0&&e.output.push(t)},fsync(e){e.output&&e.output.length>0&&(g(we(e.output,0)),e.output=[])}}},Ae=e=>{F()},G={ops_table:null,mount(e){return G.createNode(null,`/`,16895,0)},createNode(e,t,n,r){if(K.isBlkdev(n)||K.isFIFO(n))throw new K.ErrnoError(63);G.ops_table||={dir:{node:{getattr:G.node_ops.getattr,setattr:G.node_ops.setattr,lookup:G.node_ops.lookup,mknod:G.node_ops.mknod,rename:G.node_ops.rename,unlink:G.node_ops.unlink,rmdir:G.node_ops.rmdir,readdir:G.node_ops.readdir,symlink:G.node_ops.symlink},stream:{llseek:G.stream_ops.llseek}},file:{node:{getattr:G.node_ops.getattr,setattr:G.node_ops.setattr},stream:{llseek:G.stream_ops.llseek,read:G.stream_ops.read,write:G.stream_ops.write,allocate:G.stream_ops.allocate,mmap:G.stream_ops.mmap,msync:G.stream_ops.msync}},link:{node:{getattr:G.node_ops.getattr,setattr:G.node_ops.setattr,readlink:G.node_ops.readlink},stream:{}},chrdev:{node:{getattr:G.node_ops.getattr,setattr:G.node_ops.setattr},stream:K.chrdev_stream_ops}};var i=K.createNode(e,t,n,r);return K.isDir(i.mode)?(i.node_ops=G.ops_table.dir.node,i.stream_ops=G.ops_table.dir.stream,i.contents={}):K.isFile(i.mode)?(i.node_ops=G.ops_table.file.node,i.stream_ops=G.ops_table.file.stream,i.usedBytes=0,i.contents=null):K.isLink(i.mode)?(i.node_ops=G.ops_table.link.node,i.stream_ops=G.ops_table.link.stream):K.isChrdev(i.mode)&&(i.node_ops=G.ops_table.chrdev.node,i.stream_ops=G.ops_table.chrdev.stream),i.timestamp=Date.now(),e&&(e.contents[t]=i,e.timestamp=i.timestamp),i},getFileDataAsTypedArray(e){return e.contents?e.contents.subarray?e.contents.subarray(0,e.usedBytes):new Uint8Array(e.contents):new Uint8Array},expandFileStorage(e,t){var n=e.contents?e.contents.length:0;if(!(n>=t)){t=Math.max(t,n*(n<1048576?2:1.125)>>>0),n!=0&&(t=Math.max(t,256));var r=e.contents;e.contents=new Uint8Array(t),e.usedBytes>0&&e.contents.set(r.subarray(0,e.usedBytes),0)}},resizeFileStorage(e,t){if(e.usedBytes!=t){if(t==0)e.contents=null,e.usedBytes=0;else{var n=e.contents;e.contents=new Uint8Array(t),n&&e.contents.set(n.subarray(0,Math.min(t,e.usedBytes))),e.usedBytes=t}}},node_ops:{getattr(e){var t={};return t.dev=K.isChrdev(e.mode)?e.id:1,t.ino=e.id,t.mode=e.mode,t.nlink=1,t.uid=0,t.gid=0,t.rdev=e.rdev,t.size=K.isDir(e.mode)?4096:K.isFile(e.mode)?e.usedBytes:K.isLink(e.mode)?e.link.length:0,t.atime=new Date(e.timestamp),t.mtime=new Date(e.timestamp),t.ctime=new Date(e.timestamp),t.blksize=4096,t.blocks=Math.ceil(t.size/t.blksize),t},setattr(e,t){t.mode!==void 0&&(e.mode=t.mode),t.timestamp!==void 0&&(e.timestamp=t.timestamp),t.size!==void 0&&G.resizeFileStorage(e,t.size)},lookup(e,t){throw K.genericErrors[44]},mknod(e,t,n,r){return G.createNode(e,t,n,r)},rename(e,t,n){if(K.isDir(e.mode)){var r;try{r=K.lookupNode(t,n)}catch{}if(r)for(var i in r.contents)throw new K.ErrnoError(55)}delete e.parent.contents[e.name],e.parent.timestamp=Date.now(),e.name=n,t.contents[n]=e,t.timestamp=e.parent.timestamp,e.parent=t},unlink(e,t){delete e.contents[t],e.timestamp=Date.now()},rmdir(e,t){for(var n in K.lookupNode(e,t).contents)throw new K.ErrnoError(55);delete e.contents[t],e.timestamp=Date.now()},readdir(e){var t=[`.`,`..`];for(var n in e.contents)e.contents.hasOwnProperty(n)&&t.push(n);return t},symlink(e,t,n){var r=G.createNode(e,t,41471,0);return r.link=n,r},readlink(e){if(!K.isLink(e.mode))throw new K.ErrnoError(28);return e.link}},stream_ops:{read(e,t,n,r,i){var a=e.node.contents;if(i>=e.node.usedBytes)return 0;var o=Math.min(e.node.usedBytes-i,r);if(o>8&&a.subarray)t.set(a.subarray(i,i+o),n);else for(var s=0;s<o;s++)t[n+s]=a[i+s];return o},write(e,t,n,r,i,a){if(t.buffer===x.buffer&&(a=!1),!r)return 0;var o=e.node;if(o.timestamp=Date.now(),t.subarray&&(!o.contents||o.contents.subarray)){if(a)return o.contents=t.subarray(n,n+r),o.usedBytes=r,r;if(o.usedBytes===0&&i===0)return o.contents=t.slice(n,n+r),o.usedBytes=r,r;if(i+r<=o.usedBytes)return o.contents.set(t.subarray(n,n+r),i),r}if(G.expandFileStorage(o,i+r),o.contents.subarray&&t.subarray)o.contents.set(t.subarray(n,n+r),i);else for(var s=0;s<r;s++)o.contents[i+s]=t[n+s];return o.usedBytes=Math.max(o.usedBytes,i+r),r},llseek(e,t,n){var r=t;if(n===1?r+=e.position:n===2&&K.isFile(e.node.mode)&&(r+=e.node.usedBytes),r<0)throw new K.ErrnoError(28);return r},allocate(e,t,n){G.expandFileStorage(e.node,t+n),e.node.usedBytes=Math.max(e.node.usedBytes,t+n)},mmap(e,t,n,r,i){if(!K.isFile(e.node.mode))throw new K.ErrnoError(43);var a,o,s=e.node.contents;if(!(i&2)&&s.buffer===x.buffer)o=!1,a=s.byteOffset;else{if((n>0||n+t<s.length)&&(s=s.subarray?s.subarray(n,n+t):Array.prototype.slice.call(s,n,n+t)),o=!0,a=Ae(t),!a)throw new K.ErrnoError(48);x.set(s,a)}return{ptr:a,allocated:o}},msync(e,t,n,r,i){return G.stream_ops.write(e,t,0,r,n,!1),0}}},je=(e,t,n,r)=>{var i=r?``:P(`al ${e}`);p(e,n=>{b(n,`Loading data file "${e}" failed (no arrayBuffer).`),t(new Uint8Array(n)),i&&le(i)},t=>{if(n)n();else throw`Loading data file "${e}" failed.`}),i&&ce(i)},Me=(e,t,n,r,i,a)=>{K.createDataFile(e,t,n,r,i,a)},Ne=n.preloadPlugins||[],Pe=(e,t,n,r)=>{typeof Browser<`u`&&Browser.init();var i=!1;return Ne.forEach(a=>{i||a.canHandle(t)&&(a.handle(e,t,n,r),i=!0)}),i},Fe=(e,t,n,r,i,a,o,s,c,l)=>{var u=t?H.resolve(V.join2(e,t)):e,d=P(`cp ${u}`);function f(n){function f(n){l&&l(),s||Me(e,t,n,r,i,c),a&&a(),le(d)}Pe(n,u,f,()=>{o&&o(),le(d)})||f(n)}ce(d),typeof n==`string`?je(n,e=>f(e),o):f(n)},Ie=e=>{var t={r:0,"r+":2,w:577,"w+":578,a:1089,"a+":1090}[e];if(t===void 0)throw Error(`Unknown file open mode: ${e}`);return t},Le=(e,t)=>{var n=0;return e&&(n|=365),t&&(n|=146),n},K={root:null,mounts:[],devices:{},streams:[],nextInode:1,nameTable:null,currentPath:`/`,initialized:!1,ignorePermissions:!0,ErrnoError:null,genericErrors:{},filesystems:null,syncFSRequests:0,lookupPath(e,t={}){if(e=H.resolve(e),!e)return{path:``,node:null};if(t=Object.assign({follow_mount:!0,recurse_count:0},t),t.recurse_count>8)throw new K.ErrnoError(32);for(var n=e.split(`/`).filter(e=>!!e),r=K.root,i=`/`,a=0;a<n.length;a++){var o=a===n.length-1;if(o&&t.parent)break;if(r=K.lookupNode(r,n[a]),i=V.join2(i,n[a]),K.isMountpoint(r)&&(!o||o&&t.follow_mount)&&(r=r.mounted.root),!o||t.follow)for(var s=0;K.isLink(r.mode);){var c=K.readlink(i);if(i=H.resolve(V.dirname(i),c),r=K.lookupPath(i,{recurse_count:t.recurse_count+1}).node,s++>40)throw new K.ErrnoError(32)}}return{path:i,node:r}},getPath(e){for(var t;;){if(K.isRoot(e)){var n=e.mount.mountpoint;return t?n[n.length-1]===`/`?n+t:`${n}/${t}`:n}t=t?`${e.name}/${t}`:e.name,e=e.parent}},hashName(e,t){for(var n=0,r=0;r<t.length;r++)n=(n<<5)-n+t.charCodeAt(r)|0;return(e+n>>>0)%K.nameTable.length},hashAddNode(e){var t=K.hashName(e.parent.id,e.name);e.name_next=K.nameTable[t],K.nameTable[t]=e},hashRemoveNode(e){var t=K.hashName(e.parent.id,e.name);if(K.nameTable[t]===e)K.nameTable[t]=e.name_next;else for(var n=K.nameTable[t];n;){if(n.name_next===e){n.name_next=e.name_next;break}n=n.name_next}},lookupNode(e,t){var n=K.mayLookup(e);if(n)throw new K.ErrnoError(n,e);for(var r=K.hashName(e.id,t),i=K.nameTable[r];i;i=i.name_next){var a=i.name;if(i.parent.id===e.id&&a===t)return i}return K.lookup(e,t)},createNode(e,t,n,r){var i=new K.FSNode(e,t,n,r);return K.hashAddNode(i),i},destroyNode(e){K.hashRemoveNode(e)},isRoot(e){return e===e.parent},isMountpoint(e){return!!e.mounted},isFile(e){return(e&61440)==32768},isDir(e){return(e&61440)==16384},isLink(e){return(e&61440)==40960},isChrdev(e){return(e&61440)==8192},isBlkdev(e){return(e&61440)==24576},isFIFO(e){return(e&61440)==4096},isSocket(e){return(e&49152)==49152},flagsToPermissionString(e){var t=[`r`,`w`,`rw`][e&3];return e&512&&(t+=`w`),t},nodePermissions(e,t){return K.ignorePermissions?0:t.includes(`r`)&&!(e.mode&292)||t.includes(`w`)&&!(e.mode&146)||t.includes(`x`)&&!(e.mode&73)?2:0},mayLookup(e){return K.nodePermissions(e,`x`)||(e.node_ops.lookup?0:2)},mayCreate(e,t){try{return K.lookupNode(e,t),20}catch{}return K.nodePermissions(e,`wx`)},mayDelete(e,t,n){var r;try{r=K.lookupNode(e,t)}catch(e){return e.errno}var i=K.nodePermissions(e,`wx`);if(i)return i;if(n){if(!K.isDir(r.mode))return 54;if(K.isRoot(r)||K.getPath(r)===K.cwd())return 10}else if(K.isDir(r.mode))return 31;return 0},mayOpen(e,t){return e?K.isLink(e.mode)?32:K.isDir(e.mode)&&(K.flagsToPermissionString(t)!==`r`||t&512)?31:K.nodePermissions(e,K.flagsToPermissionString(t)):44},MAX_OPEN_FDS:4096,nextfd(){for(var e=0;e<=K.MAX_OPEN_FDS;e++)if(!K.streams[e])return e;throw new K.ErrnoError(33)},getStreamChecked(e){var t=K.getStream(e);if(!t)throw new K.ErrnoError(8);return t},getStream:e=>K.streams[e],createStream(e,t=-1){return K.FSStream||(K.FSStream=function(){this.shared={}},K.FSStream.prototype={},Object.defineProperties(K.FSStream.prototype,{object:{get(){return this.node},set(e){this.node=e}},isRead:{get(){return(this.flags&2097155)!=1}},isWrite:{get(){return!!(this.flags&2097155)}},isAppend:{get(){return this.flags&1024}},flags:{get(){return this.shared.flags},set(e){this.shared.flags=e}},position:{get(){return this.shared.position},set(e){this.shared.position=e}}})),e=Object.assign(new K.FSStream,e),t==-1&&(t=K.nextfd()),e.fd=t,K.streams[t]=e,e},closeStream(e){K.streams[e]=null},chrdev_stream_ops:{open(e){e.stream_ops=K.getDevice(e.node.rdev).stream_ops,e.stream_ops.open&&e.stream_ops.open(e)},llseek(){throw new K.ErrnoError(70)}},major:e=>e>>8,minor:e=>e&255,makedev:(e,t)=>e<<8|t,registerDevice(e,t){K.devices[e]={stream_ops:t}},getDevice:e=>K.devices[e],getMounts(e){for(var t=[],n=[e];n.length;){var r=n.pop();t.push(r),n.push.apply(n,r.mounts)}return t},syncfs(e,t){typeof e==`function`&&(t=e,e=!1),K.syncFSRequests++,K.syncFSRequests>1&&g(`warning: ${K.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`);var n=K.getMounts(K.root.mount),r=0;function i(e){return K.syncFSRequests--,t(e)}function a(e){if(e)return a.errored?void 0:(a.errored=!0,i(e));++r>=n.length&&i(null)}n.forEach(t=>{if(!t.type.syncfs)return a(null);t.type.syncfs(t,e,a)})},mount(e,t,n){var r=n===`/`,i=!n,a;if(r&&K.root)throw new K.ErrnoError(10);if(!r&&!i){var o=K.lookupPath(n,{follow_mount:!1});if(n=o.path,a=o.node,K.isMountpoint(a))throw new K.ErrnoError(10);if(!K.isDir(a.mode))throw new K.ErrnoError(54)}var s={type:e,opts:t,mountpoint:n,mounts:[]},c=e.mount(s);return c.mount=s,s.root=c,r?K.root=c:a&&(a.mounted=s,a.mount&&a.mount.mounts.push(s)),c},unmount(e){var t=K.lookupPath(e,{follow_mount:!1});if(!K.isMountpoint(t.node))throw new K.ErrnoError(28);var n=t.node,r=n.mounted,i=K.getMounts(r);Object.keys(K.nameTable).forEach(e=>{for(var t=K.nameTable[e];t;){var n=t.name_next;i.includes(t.mount)&&K.destroyNode(t),t=n}}),n.mounted=null;var a=n.mount.mounts.indexOf(r);n.mount.mounts.splice(a,1)},lookup(e,t){return e.node_ops.lookup(e,t)},mknod(e,t,n){var r=K.lookupPath(e,{parent:!0}).node,i=V.basename(e);if(!i||i===`.`||i===`..`)throw new K.ErrnoError(28);var a=K.mayCreate(r,i);if(a)throw new K.ErrnoError(a);if(!r.node_ops.mknod)throw new K.ErrnoError(63);return r.node_ops.mknod(r,i,t,n)},create(e,t){return t=t===void 0?438:t,t&=4095,t|=32768,K.mknod(e,t,0)},mkdir(e,t){return t=t===void 0?511:t,t&=1023,t|=16384,K.mknod(e,t,0)},mkdirTree(e,t){for(var n=e.split(`/`),r=``,i=0;i<n.length;++i)if(n[i]){r+=`/`+n[i];try{K.mkdir(r,t)}catch(e){if(e.errno!=20)throw e}}},mkdev(e,t,n){return n===void 0&&(n=t,t=438),t|=8192,K.mknod(e,t,n)},symlink(e,t){if(!H.resolve(e))throw new K.ErrnoError(44);var n=K.lookupPath(t,{parent:!0}).node;if(!n)throw new K.ErrnoError(44);var r=V.basename(t),i=K.mayCreate(n,r);if(i)throw new K.ErrnoError(i);if(!n.node_ops.symlink)throw new K.ErrnoError(63);return n.node_ops.symlink(n,r,e)},rename(e,t){var n=V.dirname(e),r=V.dirname(t),i=V.basename(e),a=V.basename(t),o=K.lookupPath(e,{parent:!0}),s=o.node,c;if(o=K.lookupPath(t,{parent:!0}),c=o.node,!s||!c)throw new K.ErrnoError(44);if(s.mount!==c.mount)throw new K.ErrnoError(75);var l=K.lookupNode(s,i),u=H.relative(e,r);if(u.charAt(0)!==`.`)throw new K.ErrnoError(28);if(u=H.relative(t,n),u.charAt(0)!==`.`)throw new K.ErrnoError(55);var d;try{d=K.lookupNode(c,a)}catch{}if(l!==d){var f=K.isDir(l.mode),p=K.mayDelete(s,i,f);if(p||(p=d?K.mayDelete(c,a,f):K.mayCreate(c,a),p))throw new K.ErrnoError(p);if(!s.node_ops.rename)throw new K.ErrnoError(63);if(K.isMountpoint(l)||d&&K.isMountpoint(d))throw new K.ErrnoError(10);if(c!==s&&(p=K.nodePermissions(s,`w`),p))throw new K.ErrnoError(p);K.hashRemoveNode(l);try{s.node_ops.rename(l,c,a)}catch(e){throw e}finally{K.hashAddNode(l)}}},rmdir(e){var t=K.lookupPath(e,{parent:!0}).node,n=V.basename(e),r=K.lookupNode(t,n),i=K.mayDelete(t,n,!0);if(i)throw new K.ErrnoError(i);if(!t.node_ops.rmdir)throw new K.ErrnoError(63);if(K.isMountpoint(r))throw new K.ErrnoError(10);t.node_ops.rmdir(t,n),K.destroyNode(r)},readdir(e){var t=K.lookupPath(e,{follow:!0}).node;if(!t.node_ops.readdir)throw new K.ErrnoError(54);return t.node_ops.readdir(t)},unlink(e){var t=K.lookupPath(e,{parent:!0}).node;if(!t)throw new K.ErrnoError(44);var n=V.basename(e),r=K.lookupNode(t,n),i=K.mayDelete(t,n,!1);if(i)throw new K.ErrnoError(i);if(!t.node_ops.unlink)throw new K.ErrnoError(63);if(K.isMountpoint(r))throw new K.ErrnoError(10);t.node_ops.unlink(t,n),K.destroyNode(r)},readlink(e){var t=K.lookupPath(e).node;if(!t)throw new K.ErrnoError(44);if(!t.node_ops.readlink)throw new K.ErrnoError(28);return H.resolve(K.getPath(t.parent),t.node_ops.readlink(t))},stat(e,t){var n=K.lookupPath(e,{follow:!t}).node;if(!n)throw new K.ErrnoError(44);if(!n.node_ops.getattr)throw new K.ErrnoError(63);return n.node_ops.getattr(n)},lstat(e){return K.stat(e,!0)},chmod(e,t,n){var r=typeof e==`string`?K.lookupPath(e,{follow:!n}).node:e;if(!r.node_ops.setattr)throw new K.ErrnoError(63);r.node_ops.setattr(r,{mode:t&4095|r.mode&-4096,timestamp:Date.now()})},lchmod(e,t){K.chmod(e,t,!0)},fchmod(e,t){var n=K.getStreamChecked(e);K.chmod(n.node,t)},chown(e,t,n,r){var i=typeof e==`string`?K.lookupPath(e,{follow:!r}).node:e;if(!i.node_ops.setattr)throw new K.ErrnoError(63);i.node_ops.setattr(i,{timestamp:Date.now()})},lchown(e,t,n){K.chown(e,t,n,!0)},fchown(e,t,n){var r=K.getStreamChecked(e);K.chown(r.node,t,n)},truncate(e,t){if(t<0)throw new K.ErrnoError(28);var n=typeof e==`string`?K.lookupPath(e,{follow:!0}).node:e;if(!n.node_ops.setattr)throw new K.ErrnoError(63);if(K.isDir(n.mode))throw new K.ErrnoError(31);if(!K.isFile(n.mode))throw new K.ErrnoError(28);var r=K.nodePermissions(n,`w`);if(r)throw new K.ErrnoError(r);n.node_ops.setattr(n,{size:t,timestamp:Date.now()})},ftruncate(e,t){var n=K.getStreamChecked(e);if(!(n.flags&2097155))throw new K.ErrnoError(28);K.truncate(n.node,t)},utime(e,t,n){var r=K.lookupPath(e,{follow:!0}).node;r.node_ops.setattr(r,{timestamp:Math.max(t,n)})},open(e,t,r){if(e===``)throw new K.ErrnoError(44);t=typeof t==`string`?Ie(t):t,r=r===void 0?438:r,r=t&64?r&4095|32768:0;var i;if(typeof e==`object`)i=e;else{e=V.normalize(e);try{i=K.lookupPath(e,{follow:!(t&131072)}).node}catch{}}var a=!1;if(t&64){if(i){if(t&128)throw new K.ErrnoError(20)}else i=K.mknod(e,r,0),a=!0}if(!i)throw new K.ErrnoError(44);if(K.isChrdev(i.mode)&&(t&=-513),t&65536&&!K.isDir(i.mode))throw new K.ErrnoError(54);if(!a){var o=K.mayOpen(i,t);if(o)throw new K.ErrnoError(o)}t&512&&!a&&K.truncate(i,0),t&=-131713;var s=K.createStream({node:i,path:K.getPath(i),flags:t,seekable:!0,position:0,stream_ops:i.stream_ops,ungotten:[],error:!1});return s.stream_ops.open&&s.stream_ops.open(s),n.logReadFiles&&!(t&1)&&(K.readFiles||={},e in K.readFiles||(K.readFiles[e]=1)),s},close(e){if(K.isClosed(e))throw new K.ErrnoError(8);e.getdents&&=null;try{e.stream_ops.close&&e.stream_ops.close(e)}catch(e){throw e}finally{K.closeStream(e.fd)}e.fd=null},isClosed(e){return e.fd===null},llseek(e,t,n){if(K.isClosed(e))throw new K.ErrnoError(8);if(!e.seekable||!e.stream_ops.llseek)throw new K.ErrnoError(70);if(n!=0&&n!=1&&n!=2)throw new K.ErrnoError(28);return e.position=e.stream_ops.llseek(e,t,n),e.ungotten=[],e.position},read(e,t,n,r,i){if(r<0||i<0)throw new K.ErrnoError(28);if(K.isClosed(e)||(e.flags&2097155)==1)throw new K.ErrnoError(8);if(K.isDir(e.node.mode))throw new K.ErrnoError(31);if(!e.stream_ops.read)throw new K.ErrnoError(28);var a=i!==void 0;if(!a)i=e.position;else if(!e.seekable)throw new K.ErrnoError(70);var o=e.stream_ops.read(e,t,n,r,i);return a||(e.position+=o),o},write(e,t,n,r,i,a){if(r<0||i<0)throw new K.ErrnoError(28);if(K.isClosed(e)||!(e.flags&2097155))throw new K.ErrnoError(8);if(K.isDir(e.node.mode))throw new K.ErrnoError(31);if(!e.stream_ops.write)throw new K.ErrnoError(28);e.seekable&&e.flags&1024&&K.llseek(e,0,2);var o=i!==void 0;if(!o)i=e.position;else if(!e.seekable)throw new K.ErrnoError(70);var s=e.stream_ops.write(e,t,n,r,i,a);return o||(e.position+=s),s},allocate(e,t,n){if(K.isClosed(e))throw new K.ErrnoError(8);if(t<0||n<=0)throw new K.ErrnoError(28);if(!(e.flags&2097155))throw new K.ErrnoError(8);if(!K.isFile(e.node.mode)&&!K.isDir(e.node.mode))throw new K.ErrnoError(43);if(!e.stream_ops.allocate)throw new K.ErrnoError(138);e.stream_ops.allocate(e,t,n)},mmap(e,t,n,r,i){if(r&2&&!(i&2)&&(e.flags&2097155)!=2||(e.flags&2097155)==1)throw new K.ErrnoError(2);if(!e.stream_ops.mmap)throw new K.ErrnoError(43);return e.stream_ops.mmap(e,t,n,r,i)},msync(e,t,n,r,i){return e.stream_ops.msync?e.stream_ops.msync(e,t,n,r,i):0},munmap:e=>0,ioctl(e,t,n){if(!e.stream_ops.ioctl)throw new K.ErrnoError(59);return e.stream_ops.ioctl(e,t,n)},readFile(e,t={}){if(t.flags=t.flags||0,t.encoding=t.encoding||`binary`,t.encoding!==`utf8`&&t.encoding!==`binary`)throw Error(`Invalid encoding type "${t.encoding}"`);var n,r=K.open(e,t.flags),i=K.stat(e).size,a=new Uint8Array(i);return K.read(r,a,0,i,0),t.encoding===`utf8`?n=we(a,0):t.encoding===`binary`&&(n=a),K.close(r),n},writeFile(e,t,n={}){n.flags=n.flags||577;var r=K.open(e,n.flags,n.mode);if(typeof t==`string`){var i=new Uint8Array(Ee(t)+1),a=De(t,i,0,i.length);K.write(r,i,0,a,void 0,n.canOwn)}else if(ArrayBuffer.isView(t))K.write(r,t,0,t.byteLength,void 0,n.canOwn);else throw Error(`Unsupported data type`);K.close(r)},cwd:()=>K.currentPath,chdir(e){var t=K.lookupPath(e,{follow:!0});if(t.node===null)throw new K.ErrnoError(44);if(!K.isDir(t.node.mode))throw new K.ErrnoError(54);var n=K.nodePermissions(t.node,`x`);if(n)throw new K.ErrnoError(n);K.currentPath=t.path},createDefaultDirectories(){K.mkdir(`/tmp`),K.mkdir(`/home`),K.mkdir(`/home/web_user`)},createDefaultDevices(){K.mkdir(`/dev`),K.registerDevice(K.makedev(1,3),{read:()=>0,write:(e,t,n,r,i)=>r}),K.mkdev(`/dev/null`,K.makedev(1,3)),W.register(K.makedev(5,0),W.default_tty_ops),W.register(K.makedev(6,0),W.default_tty1_ops),K.mkdev(`/dev/tty`,K.makedev(5,0)),K.mkdev(`/dev/tty1`,K.makedev(6,0));var e=new Uint8Array(1024),t=0,n=()=>(t===0&&(t=Ce(e).byteLength),e[--t]);K.createDevice(`/dev`,`random`,n),K.createDevice(`/dev`,`urandom`,n),K.mkdir(`/dev/shm`),K.mkdir(`/dev/shm/tmp`)},createSpecialDirectories(){K.mkdir(`/proc`);var e=K.mkdir(`/proc/self`);K.mkdir(`/proc/self/fd`),K.mount({mount(){var t=K.createNode(e,`fd`,16895,73);return t.node_ops={lookup(e,t){var n=+t,r=K.getStreamChecked(n),i={parent:null,mount:{mountpoint:`fake`},node_ops:{readlink:()=>r.path}};return i.parent=i,i}},t}},{},`/proc/self/fd`)},createStandardStreams(){n.stdin?K.createDevice(`/dev`,`stdin`,n.stdin):K.symlink(`/dev/tty`,`/dev/stdin`),n.stdout?K.createDevice(`/dev`,`stdout`,null,n.stdout):K.symlink(`/dev/tty`,`/dev/stdout`),n.stderr?K.createDevice(`/dev`,`stderr`,null,n.stderr):K.symlink(`/dev/tty1`,`/dev/stderr`),K.open(`/dev/stdin`,0),K.open(`/dev/stdout`,1),K.open(`/dev/stderr`,1)},ensureErrnoError(){K.ErrnoError||(K.ErrnoError=function(e,t){this.name=`ErrnoError`,this.node=t,this.setErrno=function(e){this.errno=e},this.setErrno(e),this.message=`FS error`},K.ErrnoError.prototype=Error(),K.ErrnoError.prototype.constructor=K.ErrnoError,[44].forEach(e=>{K.genericErrors[e]=new K.ErrnoError(e),K.genericErrors[e].stack=`<generic error, no stack>`}))},staticInit(){K.ensureErrnoError(),K.nameTable=Array(4096),K.mount(G,{},`/`),K.createDefaultDirectories(),K.createDefaultDevices(),K.createSpecialDirectories(),K.filesystems={MEMFS:G}},init(e,t,r){K.init.initialized=!0,K.ensureErrnoError(),n.stdin=e||n.stdin,n.stdout=t||n.stdout,n.stderr=r||n.stderr,K.createStandardStreams()},quit(){K.init.initialized=!1;for(var e=0;e<K.streams.length;e++){var t=K.streams[e];t&&K.close(t)}},findObject(e,t){var n=K.analyzePath(e,t);return n.exists?n.object:null},analyzePath(e,t){try{var n=K.lookupPath(e,{follow:!t});e=n.path}catch{}var r={isRoot:!1,exists:!1,error:0,name:null,path:null,object:null,parentExists:!1,parentPath:null,parentObject:null};try{var n=K.lookupPath(e,{parent:!0});r.parentExists=!0,r.parentPath=n.path,r.parentObject=n.node,r.name=V.basename(e),n=K.lookupPath(e,{follow:!t}),r.exists=!0,r.path=n.path,r.object=n.node,r.name=n.node.name,r.isRoot=n.path===`/`}catch(e){r.error=e.errno}return r},createPath(e,t,n,r){e=typeof e==`string`?e:K.getPath(e);for(var i=t.split(`/`).reverse();i.length;){var a=i.pop();if(a){var o=V.join2(e,a);try{K.mkdir(o)}catch{}e=o}}return o},createFile(e,t,n,r,i){var a=V.join2(typeof e==`string`?e:K.getPath(e),t),o=Le(r,i);return K.create(a,o)},createDataFile(e,t,n,r,i,a){var o=t;e&&(e=typeof e==`string`?e:K.getPath(e),o=t?V.join2(e,t):e);var s=Le(r,i),c=K.create(o,s);if(n){if(typeof n==`string`){for(var l=Array(n.length),u=0,d=n.length;u<d;++u)l[u]=n.charCodeAt(u);n=l}K.chmod(c,s|146);var f=K.open(c,577);K.write(f,n,0,n.length,0,a),K.close(f),K.chmod(c,s)}},createDevice(e,t,n,r){var i=V.join2(typeof e==`string`?e:K.getPath(e),t),a=Le(!!n,!!r);K.createDevice.major||(K.createDevice.major=64);var o=K.makedev(K.createDevice.major++,0);return K.registerDevice(o,{open(e){e.seekable=!1},close(e){r&&r.buffer&&r.buffer.length&&r(10)},read(e,t,r,i,a){for(var o=0,s=0;s<i;s++){var c;try{c=n()}catch{throw new K.ErrnoError(29)}if(c===void 0&&o===0)throw new K.ErrnoError(6);if(c==null)break;o++,t[r+s]=c}return o&&(e.node.timestamp=Date.now()),o},write(e,t,n,i,a){for(var o=0;o<i;o++)try{r(t[n+o])}catch{throw new K.ErrnoError(29)}return i&&(e.node.timestamp=Date.now()),o}}),K.mkdev(i,a,o)},forceLoadFile(e){if(e.isDevice||e.isFolder||e.link||e.contents)return!0;if(typeof XMLHttpRequest<`u`)throw Error(`Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.`);if(f)try{e.contents=Oe(f(e.url),!0),e.usedBytes=e.contents.length}catch{throw new K.ErrnoError(29)}else throw Error(`Cannot load without read() or XMLHttpRequest.`)},createLazyFile(e,t,n,r,i){function a(){this.lengthKnown=!1,this.chunks=[]}if(a.prototype.get=function(e){if(!(e>this.length-1||e<0)){var t=e%this.chunkSize,n=e/this.chunkSize|0;return this.getter(n)[t]}},a.prototype.setDataGetter=function(e){this.getter=e},a.prototype.cacheLength=function(){var e=new XMLHttpRequest;if(e.open(`HEAD`,n,!1),e.send(null),!(e.status>=200&&e.status<300||e.status===304))throw Error(`Couldn't load `+n+`. Status: `+e.status);var t=Number(e.getResponseHeader(`Content-length`)),r,i=(r=e.getResponseHeader(`Accept-Ranges`))&&r===`bytes`,a=(r=e.getResponseHeader(`Content-Encoding`))&&r===`gzip`,o=1048576;i||(o=t);var s=(e,r)=>{if(e>r)throw Error(`invalid range (`+e+`, `+r+`) or no bytes requested!`);if(r>t-1)throw Error(`only `+t+` bytes available! programmer error!`);var i=new XMLHttpRequest;if(i.open(`GET`,n,!1),t!==o&&i.setRequestHeader(`Range`,`bytes=`+e+`-`+r),i.responseType=`arraybuffer`,i.overrideMimeType&&i.overrideMimeType(`text/plain; charset=x-user-defined`),i.send(null),!(i.status>=200&&i.status<300||i.status===304))throw Error(`Couldn't load `+n+`. Status: `+i.status);return i.response===void 0?Oe(i.responseText||``,!0):new Uint8Array(i.response||[])},c=this;c.setDataGetter(e=>{var n=e*o,r=(e+1)*o-1;if(r=Math.min(r,t-1),c.chunks[e]===void 0&&(c.chunks[e]=s(n,r)),c.chunks[e]===void 0)throw Error(`doXHR failed!`);return c.chunks[e]}),(a||!t)&&(o=t=1,t=this.getter(0).length,o=t,h(`LazyFiles on gzip forces download of the whole file when length is accessed`)),this._length=t,this._chunkSize=o,this.lengthKnown=!0},typeof XMLHttpRequest<`u`){if(!l)throw`Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc`;var o=new a;Object.defineProperties(o,{length:{get:function(){return this.lengthKnown||this.cacheLength(),this._length}},chunkSize:{get:function(){return this.lengthKnown||this.cacheLength(),this._chunkSize}}});var s={isDevice:!1,contents:o}}else var s={isDevice:!1,url:n};var c=K.createFile(e,t,s,r,i);s.contents?c.contents=s.contents:s.url&&(c.contents=null,c.url=s.url),Object.defineProperties(c,{usedBytes:{get:function(){return this.contents.length}}});var u={};Object.keys(c.stream_ops).forEach(e=>{var t=c.stream_ops[e];u[e]=function(){return K.forceLoadFile(c),t.apply(null,arguments)}});function d(e,t,n,r,i){var a=e.node.contents;if(i>=a.length)return 0;var o=Math.min(a.length-i,r);if(a.slice)for(var s=0;s<o;s++)t[n+s]=a[i+s];else for(var s=0;s<o;s++)t[n+s]=a.get(i+s);return o}return u.read=(e,t,n,r,i)=>(K.forceLoadFile(c),d(e,t,n,r,i)),u.mmap=(e,t,n,r,i)=>{K.forceLoadFile(c);var a=Ae(t);if(!a)throw new K.ErrnoError(48);return d(e,x,a,t,n),{ptr:a,allocated:!0}},c.stream_ops=u,c}},Re=(e,t)=>e?we(S,e,t):``,q={DEFAULT_POLLMASK:5,calculateAt(e,t,n){if(V.isAbs(t))return t;var r=e===-100?K.cwd():q.getStreamFromFD(e).path;if(t.length==0){if(!n)throw new K.ErrnoError(44);return r}return V.join2(r,t)},doStat(e,t,n){try{var r=e(t)}catch(e){if(e&&e.node&&V.normalize(t)!==V.normalize(K.getPath(e.node)))return-54;throw e}w[n>>2]=r.dev,w[n+4>>2]=r.mode,T[n+8>>2]=r.nlink,w[n+12>>2]=r.uid,w[n+16>>2]=r.gid,w[n+20>>2]=r.rdev,B=[r.size>>>0,(z=r.size,+Math.abs(z)>=1?z>0?Math.floor(z/4294967296)>>>0:~~+Math.ceil((z-+(~~z>>>0))/4294967296)>>>0:0)],w[n+24>>2]=B[0],w[n+28>>2]=B[1],w[n+32>>2]=4096,w[n+36>>2]=r.blocks;var i=r.atime.getTime(),a=r.mtime.getTime(),o=r.ctime.getTime();return B=[Math.floor(i/1e3)>>>0,(z=Math.floor(i/1e3),+Math.abs(z)>=1?z>0?Math.floor(z/4294967296)>>>0:~~+Math.ceil((z-+(~~z>>>0))/4294967296)>>>0:0)],w[n+40>>2]=B[0],w[n+44>>2]=B[1],T[n+48>>2]=i%1e3*1e3,B=[Math.floor(a/1e3)>>>0,(z=Math.floor(a/1e3),+Math.abs(z)>=1?z>0?Math.floor(z/4294967296)>>>0:~~+Math.ceil((z-+(~~z>>>0))/4294967296)>>>0:0)],w[n+56>>2]=B[0],w[n+60>>2]=B[1],T[n+64>>2]=a%1e3*1e3,B=[Math.floor(o/1e3)>>>0,(z=Math.floor(o/1e3),+Math.abs(z)>=1?z>0?Math.floor(z/4294967296)>>>0:~~+Math.ceil((z-+(~~z>>>0))/4294967296)>>>0:0)],w[n+72>>2]=B[0],w[n+76>>2]=B[1],T[n+80>>2]=o%1e3*1e3,B=[r.ino>>>0,(z=r.ino,+Math.abs(z)>=1?z>0?Math.floor(z/4294967296)>>>0:~~+Math.ceil((z-+(~~z>>>0))/4294967296)>>>0:0)],w[n+88>>2]=B[0],w[n+92>>2]=B[1],0},doMsync(e,t,n,r,i){if(!K.isFile(t.node.mode))throw new K.ErrnoError(43);if(r&2)return 0;var a=S.slice(e,e+n);K.msync(t,a,i,n,r)},varargs:void 0,get(){var e=w[q.varargs>>2];return q.varargs+=4,e},getp(){return q.get()},getStr(e){return Re(e)},getStreamFromFD(e){return K.getStreamChecked(e)}};function ze(e,t,n){q.varargs=n;try{var r=q.getStreamFromFD(e);switch(t){case 0:var i=q.get();if(i<0)return-28;for(;K.streams[i];)i++;return K.createStream(r,i).fd;case 1:case 2:return 0;case 3:return r.flags;case 4:var i=q.get();return r.flags|=i,0;case 5:var i=q.getp(),a=0;return C[i+a>>1]=2,0;case 6:case 7:return 0;case 16:case 8:return-28;case 9:return xe(28),-1;default:return-28}}catch(e){if(K===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Be(e,t,n){q.varargs=n;try{var r=q.getStreamFromFD(e);switch(t){case 21509:return r.tty?0:-59;case 21505:if(!r.tty)return-59;if(r.tty.ops.ioctl_tcgets){var i=r.tty.ops.ioctl_tcgets(r),a=q.getp();w[a>>2]=i.c_iflag||0,w[a+4>>2]=i.c_oflag||0,w[a+8>>2]=i.c_cflag||0,w[a+12>>2]=i.c_lflag||0;for(var o=0;o<32;o++)x[a+o+17>>0]=i.c_cc[o]||0;return 0}return 0;case 21510:case 21511:case 21512:return r.tty?0:-59;case 21506:case 21507:case 21508:if(!r.tty)return-59;if(r.tty.ops.ioctl_tcsets){for(var a=q.getp(),s=w[a>>2],c=w[a+4>>2],l=w[a+8>>2],u=w[a+12>>2],d=[],o=0;o<32;o++)d.push(x[a+o+17>>0]);return r.tty.ops.ioctl_tcsets(r.tty,t,{c_iflag:s,c_oflag:c,c_cflag:l,c_lflag:u,c_cc:d})}return 0;case 21519:if(!r.tty)return-59;var a=q.getp();return w[a>>2]=0,0;case 21520:return r.tty?-28:-59;case 21531:var a=q.getp();return K.ioctl(r,t,a);case 21523:if(!r.tty)return-59;if(r.tty.ops.ioctl_tiocgwinsz){var f=r.tty.ops.ioctl_tiocgwinsz(r.tty),a=q.getp();C[a>>1]=f[0],C[a+2>>1]=f[1]}return 0;case 21524:return r.tty?0:-59;case 21515:return r.tty?0:-59;default:return-28}}catch(e){if(K===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Ve(e,t,n,r){q.varargs=r;try{t=q.getStr(t),t=q.calculateAt(e,t);var i=r?q.get():0;return K.open(t,n,i).fd}catch(e){if(K===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}var J=1,He=()=>J,Ue=()=>{F(``)},We=()=>Date.now(),Ge=()=>2147483648,Ke=()=>Ge(),qe=()=>performance.now(),Je=(e,t,n)=>S.copyWithin(e,t,t+n),Ye=e=>{var t=(e-v.buffer.byteLength+65535)/65536;try{return v.grow(t),ee(),1}catch{}},Xe=e=>{var t=S.length;e>>>=0;var n=Ge();if(e>n)return!1;for(var r=(e,t)=>e+(t-e%t)%t,i=1;i<=4;i*=2){var a=t*(1+.2/i);if(a=Math.min(a,e+100663296),Ye(Math.min(n,r(Math.max(e,a),65536))))return!0}return!1},Ze={},Qe=()=>o||`./this.program`,$e=()=>{if(!$e.strings){var e={USER:`web_user`,LOGNAME:`web_user`,PATH:`/`,PWD:`/`,HOME:`/home/web_user`,LANG:(typeof navigator==`object`&&navigator.languages&&navigator.languages[0]||`C`).replace(`-`,`_`)+`.UTF-8`,_:Qe()};for(var t in Ze)Ze[t]===void 0?delete e[t]:e[t]=Ze[t];var n=[];for(var t in e)n.push(`${t}=${e[t]}`);$e.strings=n}return $e.strings},et=(e,t)=>{for(var n=0;n<e.length;++n)x[t++>>0]=e.charCodeAt(n);x[t>>0]=0},tt=(e,t)=>{var n=0;return $e().forEach((r,i)=>{var a=t+n;T[e+i*4>>2]=a,et(r,a),n+=r.length+1}),0},nt=(e,t)=>{var n=$e();T[e>>2]=n.length;var r=0;return n.forEach(e=>r+=e.length+1),T[t>>2]=r,0},rt=0,it=()=>ye||rt>0,at=e=>{it()||(n.onExit&&n.onExit(e),y=!0),s(e,new ge(e))},ot=(e,t)=>{at(e)};function st(e){try{var t=q.getStreamFromFD(e);return K.close(t),0}catch(e){if(K===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}var ct=(e,t,n,r)=>{for(var i=0,a=0;a<n;a++){var o=T[t>>2],s=T[t+4>>2];t+=8;var c=K.read(e,x,o,s,r);if(c<0)return-1;if(i+=c,c<s)break;r!==void 0&&(r+=c)}return i};function lt(e,t,n,r){try{var i=ct(q.getStreamFromFD(e),t,n);return T[r>>2]=i,0}catch(e){if(K===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}var ut=(e,t)=>t+2097152>>>0<4194305-!!e?(e>>>0)+t*4294967296:NaN;function dt(e,t,n,r,i){var a=ut(t,n);try{if(isNaN(a))return 61;var o=q.getStreamFromFD(e);return K.llseek(o,a,r),B=[o.position>>>0,(z=o.position,+Math.abs(z)>=1?z>0?Math.floor(z/4294967296)>>>0:~~+Math.ceil((z-+(~~z>>>0))/4294967296)>>>0:0)],w[i>>2]=B[0],w[i+4>>2]=B[1],o.getdents&&a===0&&r===0&&(o.getdents=null),0}catch(e){if(K===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}var ft=(e,t,n,r)=>{for(var i=0,a=0;a<n;a++){var o=T[t>>2],s=T[t+4>>2];t+=8;var c=K.write(e,x,o,s,r);if(c<0)return-1;i+=c,r!==void 0&&(r+=c)}return i};function pt(e,t,n,r){try{var i=ft(q.getStreamFromFD(e),t,n);return T[r>>2]=i,0}catch(e){if(K===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}var mt=e=>e%4==0&&(e%100!=0||e%400==0),ht=(e,t)=>{for(var n=0,r=0;r<=t;n+=e[r++]);return n},gt=[31,29,31,30,31,30,31,31,30,31,30,31],_t=[31,28,31,30,31,30,31,31,30,31,30,31],vt=(e,t)=>{for(var n=new Date(e.getTime());t>0;){var r=mt(n.getFullYear()),i=n.getMonth(),a=(r?gt:_t)[i];if(t>a-n.getDate())t-=a-n.getDate()+1,n.setDate(1),i<11?n.setMonth(i+1):(n.setMonth(0),n.setFullYear(n.getFullYear()+1));else return n.setDate(n.getDate()+t),n}return n},yt=(e,t)=>{x.set(e,t)},bt=(e,t,n,r)=>{var i=T[r+40>>2],a={tm_sec:w[r>>2],tm_min:w[r+4>>2],tm_hour:w[r+8>>2],tm_mday:w[r+12>>2],tm_mon:w[r+16>>2],tm_year:w[r+20>>2],tm_wday:w[r+24>>2],tm_yday:w[r+28>>2],tm_isdst:w[r+32>>2],tm_gmtoff:w[r+36>>2],tm_zone:i?Re(i):``},o=Re(n),s={"%c":`%a %b %d %H:%M:%S %Y`,"%D":`%m/%d/%y`,"%F":`%Y-%m-%d`,"%h":`%b`,"%r":`%I:%M:%S %p`,"%R":`%H:%M`,"%T":`%H:%M:%S`,"%x":`%m/%d/%y`,"%X":`%H:%M:%S`,"%Ec":`%c`,"%EC":`%C`,"%Ex":`%m/%d/%y`,"%EX":`%H:%M:%S`,"%Ey":`%y`,"%EY":`%Y`,"%Od":`%d`,"%Oe":`%e`,"%OH":`%H`,"%OI":`%I`,"%Om":`%m`,"%OM":`%M`,"%OS":`%S`,"%Ou":`%u`,"%OU":`%U`,"%OV":`%V`,"%Ow":`%w`,"%OW":`%W`,"%Oy":`%y`};for(var c in s)o=o.replace(new RegExp(c,`g`),s[c]);var l=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],u=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`];function d(e,t,n){for(var r=typeof e==`number`?e.toString():e||``;r.length<t;)r=n[0]+r;return r}function f(e,t){return d(e,t,`0`)}function p(e,t){function n(e){return e<0?-1:+(e>0)}var r;return(r=n(e.getFullYear()-t.getFullYear()))===0&&(r=n(e.getMonth()-t.getMonth()))===0&&(r=n(e.getDate()-t.getDate())),r}function m(e){switch(e.getDay()){case 0:return new Date(e.getFullYear()-1,11,29);case 1:return e;case 2:return new Date(e.getFullYear(),0,3);case 3:return new Date(e.getFullYear(),0,2);case 4:return new Date(e.getFullYear(),0,1);case 5:return new Date(e.getFullYear()-1,11,31);case 6:return new Date(e.getFullYear()-1,11,30)}}function h(e){var t=vt(new Date(e.tm_year+1900,0,1),e.tm_yday),n=new Date(t.getFullYear(),0,4),r=new Date(t.getFullYear()+1,0,4),i=m(n),a=m(r);return p(i,t)<=0?p(a,t)<=0?t.getFullYear()+1:t.getFullYear():t.getFullYear()-1}var g={"%a":e=>l[e.tm_wday].substring(0,3),"%A":e=>l[e.tm_wday],"%b":e=>u[e.tm_mon].substring(0,3),"%B":e=>u[e.tm_mon],"%C":e=>f((e.tm_year+1900)/100|0,2),"%d":e=>f(e.tm_mday,2),"%e":e=>d(e.tm_mday,2,` `),"%g":e=>h(e).toString().substring(2),"%G":e=>h(e),"%H":e=>f(e.tm_hour,2),"%I":e=>{var t=e.tm_hour;return t==0?t=12:t>12&&(t-=12),f(t,2)},"%j":e=>f(e.tm_mday+ht(mt(e.tm_year+1900)?gt:_t,e.tm_mon-1),3),"%m":e=>f(e.tm_mon+1,2),"%M":e=>f(e.tm_min,2),"%n":()=>`
6
- `,"%p":e=>e.tm_hour>=0&&e.tm_hour<12?`AM`:`PM`,"%S":e=>f(e.tm_sec,2),"%t":()=>` `,"%u":e=>e.tm_wday||7,"%U":e=>{var t=e.tm_yday+7-e.tm_wday;return f(Math.floor(t/7),2)},"%V":e=>{var t=Math.floor((e.tm_yday+7-(e.tm_wday+6)%7)/7);if((e.tm_wday+371-e.tm_yday-2)%7<=2&&t++,!t){t=52;var n=(e.tm_wday+7-e.tm_yday-1)%7;(n==4||n==5&&mt(e.tm_year%400-1))&&t++}else if(t==53){var r=(e.tm_wday+371-e.tm_yday)%7;r!=4&&(r!=3||!mt(e.tm_year))&&(t=1)}return f(t,2)},"%w":e=>e.tm_wday,"%W":e=>{var t=e.tm_yday+7-(e.tm_wday+6)%7;return f(Math.floor(t/7),2)},"%y":e=>(e.tm_year+1900).toString().substring(2),"%Y":e=>e.tm_year+1900,"%z":e=>{var t=e.tm_gmtoff,n=t>=0;return t=Math.abs(t)/60,t=t/60*100+t%60,(n?`+`:`-`)+String(`0000`+t).slice(-4)},"%Z":e=>e.tm_zone,"%%":()=>`%`};for(var c in o=o.replace(/%%/g,`\0\0`),g)o.includes(c)&&(o=o.replace(new RegExp(c,`g`),g[c](a)));o=o.replace(/\0\0/g,`%`);var _=Oe(o,!1);return _.length>t?0:(yt(_,e),_.length-1)},xt=(e,t,n,r,i)=>bt(e,t,n,r),St=e=>n[`_`+e],Ct=(e,t,n)=>De(e,S,t,n),wt=e=>{var t=Ee(e)+1,n=Dn(t);return Ct(e,n,t),n},Tt=(e,t,n,r,i)=>{var a={string:e=>{var t=0;return e!=null&&e!==0&&(t=wt(e)),t},array:e=>{var t=Dn(e.length);return yt(e,t),t}};function o(e){return t===`string`?Re(e):t===`boolean`?!!e:e}var s=St(e),c=[],l=0;if(r)for(var u=0;u<r.length;u++){var d=a[n[u]];d?(l===0&&(l=Tn()),c[u]=d(r[u])):c[u]=r[u]}var f=s.apply(null,c);function p(e){return l!==0&&En(l),o(e)}return f=p(f),f},Et=(e,t,n,r)=>{var i=!n||n.every(e=>e===`number`||e===`boolean`);return t!==`string`&&i&&!r?St(e):function(){return Tt(e,t,n,arguments,r)}},Dt=(e,t)=>{e<128?t.push(e):t.push(e%128|128,e>>7)},Ot=e=>{for(var t={i:`i32`,j:`i64`,f:`f32`,d:`f64`,e:`externref`,p:`i32`},n={parameters:[],results:e[0]==`v`?[]:[t[e[0]]]},r=1;r<e.length;++r)n.parameters.push(t[e[r]]);return n},kt=(e,t)=>{var n=e.slice(0,1),r=e.slice(1),i={i:127,p:127,j:126,f:125,d:124,e:111};t.push(96),Dt(r.length,t);for(var a=0;a<r.length;++a)t.push(i[r[a]]);n==`v`?t.push(0):t.push(1,i[n])},At=(e,t)=>{if(typeof WebAssembly.Function==`function`)return new WebAssembly.Function(Ot(t),e);var n=[1];kt(t,n);var r=[0,97,115,109,1,0,0,0,1];Dt(n.length,r),r.push.apply(r,n),r.push(2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0);var i=new WebAssembly.Module(new Uint8Array(r));return new WebAssembly.Instance(i,{e:{f:e}}).exports.f},jt=[],Mt,Nt=e=>{var t=jt[e];return t||(e>=jt.length&&(jt.length=e+1),jt[e]=t=Mt.get(e)),t},Pt=(e,t)=>{if(Ft)for(var n=e;n<e+t;n++){var r=Nt(n);r&&Ft.set(r,n)}},Ft,It=e=>(Ft||(Ft=new WeakMap,Pt(0,Mt.length)),Ft.get(e)||0),Lt=[],Rt=()=>{if(Lt.length)return Lt.pop();try{Mt.grow(1)}catch(e){throw e instanceof RangeError?`Unable to grow wasm table. Set ALLOW_TABLE_GROWTH.`:e}return Mt.length-1},zt=(e,t)=>{Mt.set(e,t),jt[e]=Mt.get(e)},Bt=(e,t)=>{var n=It(e);if(n)return n;var r=Rt();try{zt(r,e)}catch(n){if(!(n instanceof TypeError))throw n;zt(r,At(e,t))}return Ft.set(e,r),r},Vt=e=>{Ft.delete(Nt(e)),zt(e,null),Lt.push(e)},Ht=function(e,t,n,r){e||=this,this.parent=e,this.mount=e.mount,this.mounted=null,this.id=K.nextInode++,this.name=t,this.mode=n,this.node_ops={},this.stream_ops={},this.rdev=r},Ut=365,Wt=146;Object.defineProperties(Ht.prototype,{read:{get:function(){return(this.mode&Ut)===Ut},set:function(e){e?this.mode|=Ut:this.mode&=~Ut}},write:{get:function(){return(this.mode&Wt)===Wt},set:function(e){e?this.mode|=Wt:this.mode&=~Wt}},isFolder:{get:function(){return K.isDir(this.mode)}},isDevice:{get:function(){return K.isChrdev(this.mode)}}}),K.FSNode=Ht,K.createPreloadedFile=Fe,K.staticInit();var Gt={g:ze,p:Be,h:Ve,i:He,c:Ue,e:We,j:Ke,b:qe,q:Je,r:Xe,m:tt,n:nt,a:ot,f:st,o:lt,k:dt,d:pt,l:xt},Y=he(),Kt=n._Highs_create=()=>(Kt=n._Highs_create=Y.u)(),qt=n._Highs_destroy=e=>(qt=n._Highs_destroy=Y.v)(e),Jt=n._Highs_version=()=>(Jt=n._Highs_version=Y.w)(),X=n._Highs_run=e=>(X=n._Highs_run=Y.x)(e),Yt=n._Highs_readModel=(e,t)=>(Yt=n._Highs_readModel=Y.y)(e,t),Xt=n._Highs_getNumCol=e=>(Xt=n._Highs_getNumCol=Y.z)(e),Zt=n._Highs_clearModel=e=>(Zt=n._Highs_clearModel=Y.A)(e),Qt=n._Highs_setBoolOptionValue=(e,t,r)=>(Qt=n._Highs_setBoolOptionValue=Y.B)(e,t,r),$t=n._Highs_setIntOptionValue=(e,t,r)=>($t=n._Highs_setIntOptionValue=Y.C)(e,t,r),en=n._Highs_setDoubleOptionValue=(e,t,r)=>(en=n._Highs_setDoubleOptionValue=Y.D)(e,t,r),tn=n._Highs_setStringOptionValue=(e,t,r)=>(tn=n._Highs_setStringOptionValue=Y.E)(e,t,r),nn=n._Highs_getIntInfoValue=(e,t,r)=>(nn=n._Highs_getIntInfoValue=Y.F)(e,t,r),rn=n._Highs_getDoubleInfoValue=(e,t,r)=>(rn=n._Highs_getDoubleInfoValue=Y.G)(e,t,r),an=n._Highs_getInt64InfoValue=(e,t,r)=>(an=n._Highs_getInt64InfoValue=Y.H)(e,t,r),on=n._Highs_getSolution=(e,t,r,i,a)=>(on=n._Highs_getSolution=Y.I)(e,t,r,i,a),sn=n._Highs_getModelStatus=e=>(sn=n._Highs_getModelStatus=Y.J)(e),cn=n._Highs_getObjectiveValue=e=>(cn=n._Highs_getObjectiveValue=Y.K)(e),ln=n._Highs_getNumRow=e=>(ln=n._Highs_getNumRow=Y.L)(e),un=n._Highs_setSolution=(e,t,r,i,a)=>(un=n._Highs_setSolution=Y.M)(e,t,r,i,a),dn=n._Highs_setSparseSolution=(e,t,r,i)=>(dn=n._Highs_setSparseSolution=Y.N)(e,t,r,i),fn=n._Highs_setCallback=(e,t,r)=>(fn=n._Highs_setCallback=Y.O)(e,t,r),pn=n._Highs_startCallback=(e,t)=>(pn=n._Highs_startCallback=Y.P)(e,t),mn=n._Highs_stopCallback=(e,t)=>(mn=n._Highs_stopCallback=Y.Q)(e,t),hn=n._Highs_changeObjectiveOffset=(e,t)=>(hn=n._Highs_changeObjectiveOffset=Y.R)(e,t),gn=n._Highs_getObjectiveOffset=(e,t)=>(gn=n._Highs_getObjectiveOffset=Y.S)(e,t),_n=n._Highs_getRowName=(e,t,r)=>(_n=n._Highs_getRowName=Y.T)(e,t,r),vn=n._Highs_getColName=(e,t,r)=>(vn=n._Highs_getColName=Y.U)(e,t,r),yn=n._Highs_getColIntegrality=(e,t,r)=>(yn=n._Highs_getColIntegrality=Y.V)(e,t,r),bn=n._Highs_getNumNz=e=>(bn=n._Highs_getNumNz=Y.W)(e),xn=()=>(xn=Y.X)(),Sn=n._malloc=e=>(Sn=n._malloc=Y.Y)(e),Cn=n._free=e=>(Cn=n._free=Y.Z)(e),wn=()=>(wn=Y._)(),Tn=()=>(Tn=Y.$)(),En=e=>(En=Y.aa)(e),Dn=e=>(Dn=Y.ba)(e);n.wasmMemory=v,n.ccall=Tt,n.cwrap=Et,n.addFunction=Bt,n.removeFunction=Vt,n.setValue=be,n.getValue=ve,n.UTF8ToString=Re,n.stringToUTF8=Ct,n.FS=K;var On;N=function e(){On||kn(),On||(N=e)};function kn(){if(oe>0||(ne(),oe>0))return;function e(){On||(On=!0,n.calledRun=!0,!y&&(re(),r(n),n.onRuntimeInitialized&&n.onRuntimeInitialized(),ie()))}n.setStatus?(n.setStatus(`Running...`),setTimeout(function(){setTimeout(function(){n.setStatus(``)},1),e()},1)):e()}if(n.preInit)for(typeof n.preInit==`function`&&(n.preInit=[n.preInit]);n.preInit.length>0;)n.preInit.pop()();return kn(),t.ready})})()})),Mt=r({default:()=>Nt});async function Nt(e={}){let t=await At(e);return new Ot(t)}var Pt=n((()=>{jt(),kt()}));kt();var Ft=[`mip_max_nodes`,`mip_max_improving_sols`,`mip_max_leaves`,`simplex_iteration_limit`,`ipm_iteration_limit`],It=new Set([`timeLimit`,`outputFlag`,`presolve`,`solver`,`relativeGap`,`absoluteGap`,`wasmUrl`,`signal`,`onProgress`,`onIncumbent`,`relax`,`useWorker`,`objectiveOffset`,`initialValues`,...Ft]);function Lt(e={}){if(e.threads!==void 0)throw Error(`Solver "HiGHS" does not support option "threads" (HiGHS WebAssembly runs single-threaded).`);if(e.verbose!==void 0)throw Error(`Solver "HiGHS" does not support option "verbose"; use "outputFlag" instead.`);for(let[t,n]of Object.entries(e))if(n!==void 0&&!It.has(t))throw Error(`Solver "HiGHS" does not support option "${t}".`);if(e.useWorker!==void 0&&typeof e.useWorker!=`boolean`)throw Error(`Invalid HiGHS option "useWorker": expected boolean, got ${typeof e.useWorker}.`);if(e.outputFlag!==void 0&&typeof e.outputFlag!=`boolean`)throw Error(`Invalid HiGHS option "outputFlag": expected boolean, got ${typeof e.outputFlag}.`);if(e.relax!==void 0&&typeof e.relax!=`boolean`)throw Error(`Invalid HiGHS option "relax": expected boolean, got ${typeof e.relax}.`);if(e.presolve!==void 0&&e.presolve!==`on`&&e.presolve!==`off`&&e.presolve!==`choose`)throw Error(`Invalid HiGHS option "presolve" (${String(e.presolve)}): expected "on", "off", or "choose".`);if(e.timeLimit!==void 0&&(typeof e.timeLimit!=`number`||!Number.isFinite(e.timeLimit)||e.timeLimit<0))throw Error(`Invalid HiGHS option "timeLimit" (${String(e.timeLimit)}): expected a finite non-negative number of seconds.`);if(e.relativeGap!==void 0&&(typeof e.relativeGap!=`number`||!Number.isFinite(e.relativeGap)||e.relativeGap<0))throw Error(`Invalid HiGHS option "relativeGap" (${String(e.relativeGap)}): expected a finite non-negative number.`);if(e.absoluteGap!==void 0&&(typeof e.absoluteGap!=`number`||!Number.isFinite(e.absoluteGap)||e.absoluteGap<0))throw Error(`Invalid HiGHS option "absoluteGap" (${String(e.absoluteGap)}): expected a finite non-negative number.`);if(e.objectiveOffset!==void 0&&(typeof e.objectiveOffset!=`number`||!Number.isFinite(e.objectiveOffset)))throw Error(`Invalid HiGHS option "objectiveOffset" (${String(e.objectiveOffset)}): expected a finite number.`);if(e.wasmUrl!==void 0&&e.wasmUrl!==null&&(typeof e.wasmUrl!=`string`||e.wasmUrl===``))throw Error(`Invalid HiGHS option "wasmUrl": expected a non-empty string or null.`)}var Rt=null,zt=null,Bt=null;function Vt(){return Bt}async function Ht(e){return e||vt()}async function Ut(e,t){if(e.wasmUrl){let t=await Ht(e.wasmUrl);return{isNode:!1,wasmUrl:t,wasmBinary:null,key:t?`url:${t}`:`node`}}if(t===null)return null;if(t.kind===`embedded`)return{isNode:!1,wasmUrl:null,wasmBinary:t.bytes,key:`__embedded__`};let n=await Ht();return{isNode:!1,wasmUrl:n,wasmBinary:null,key:n?`url:${n}`:`node`}}async function Wt(e={}){let t=await Ut(e,pt(`highs`));if(!t)throw Error(`[WaSHI] Failed to resolve HiGHS WASM target.`);let{isNode:n,wasmUrl:r,wasmBinary:i,key:a}=t;if(Rt&&zt===a)return Rt;zt=a;let o=null;return o=(async()=>{let e=n?await yt():(await Promise.resolve().then(()=>(Pt(),Mt))).default;return i?await e({wasmBinary:i.slice(),locateFile:e=>e}):n?await e():await e({locateFile:e=>e.endsWith(`.wasm`)?r:e})})().then(e=>e).catch(e=>{Rt===o&&(Rt=null,zt=null);let t=e instanceof Error?e.message:String(e),n=i?` from embedded inline WASM`:r?` from "${r}"`:``;throw Error(`[WaSHI] Failed to initialize HiGHS${n}. Deploy the package's WASM asset or explicitly set wasmUrl; no CDN fallback is attempted. ${t}`,{cause:e})}),Rt=o,o}async function Gt(e,t={}){if(Lt(t),t.signal?.aborted)return{result:{Status:`Interrupted`,StatusCode:17,HasPrimalSolution:!1,ObjectiveValue:NaN,Columns:{},Rows:[]},runTime:0};let n=await Wt(t);if(t.signal?.aborted)return{result:{Status:`Interrupted`,StatusCode:17,HasPrimalSolution:!1,ObjectiveValue:NaN,Columns:{},Rows:[]},runTime:0};let r=performance.now(),i={output_flag:t.outputFlag??!1};t.timeLimit!==void 0&&(i.time_limit=t.timeLimit),t.presolve!==void 0&&(i.presolve=t.presolve),t.solver!==void 0&&(i.solver=t.solver),t.relativeGap!==void 0&&(i.mip_rel_gap=t.relativeGap),t.absoluteGap!==void 0&&(i.mip_abs_gap=t.absoluteGap);for(let e of Ft)t[e]!==void 0&&(i[e]=t[e]);let a=t.objectiveOffset??0,o=t.initialValues,s=!1;if(o){for(let[e,t]of Object.entries(o))if(t!==void 0){if(typeof t!=`number`||!Number.isFinite(t))throw Error(`Invalid initial value for column "${e}": ${String(t)} (must be a finite number).`);s=!0}}if(typeof n.withModel!=`function`)throw Error(`[WaSHI] HiGHS runtime is missing required withModel() API (legacy highs.solve fallback has been removed).`);return{result:n.withModel({format:`lp`,data:e},e=>{let c=!1;if(a!==0){if(typeof e.changeObjectiveOffset!=`function`)throw Error(`[WaSHI] HiGHS runtime does not support changeObjectiveOffset() for non-zero objectiveOffset.`);let t=typeof e.getObjectiveOffset==`function`?e.getObjectiveOffset():0;e.changeObjectiveOffset(t+a),c=!0}for(let[t,n]of Object.entries(i))e.options.set(t,n);let l=e.getDimensions(),u=[],d=!1;for(let t=0;t<l.numCols;t++){let n=e.getColIntegrality(t);n!==0&&(d=!0),u.push({name:e.getColName(t),type:n===1?`Integer`:`Continuous`})}if(s&&o){if(typeof e.setSolution!=`function`)throw Error(`HiGHS runtime does not support setting primal initial values (setSolution is unavailable).`);let t=new Map;for(let e=0;e<l.numCols;e++)t.set(u[e].name,e);for(let[e,n]of Object.entries(o))if(n!==void 0&&!t.has(e))throw Error(`Unknown column "${e}" in initialValues (column does not exist in the HiGHS LP model).`);let n=[],r=[];for(let e=0;e<l.numCols;e++){let t=u[e].name;if(Object.prototype.hasOwnProperty.call(o,t)){let i=o[t];i!==void 0&&(n.push(e),r.push(i))}}n.length>0&&(n.length===l.numCols?e.setSolution({colValue:r}):e.setSolution({indices:n,values:r}))}let f=null,p=null,m=0,h=e=>{let t=e?.data??{},n=typeof t.running_time==`number`&&Number.isFinite(t.running_time)?t.running_time:(performance.now()-r)/1e3,i=typeof t.mip_primal_bound==`number`&&Number.isFinite(t.mip_primal_bound)?t.mip_primal_bound:typeof t.objective_function_value==`number`&&Number.isFinite(t.objective_function_value)?t.objective_function_value:void 0,a=typeof t.mip_dual_bound==`number`&&Number.isFinite(t.mip_dual_bound)?t.mip_dual_bound:void 0,o=typeof t.mip_gap==`number`&&Number.isFinite(t.mip_gap)?t.mip_gap:void 0,s=i!==void 0&&a!==void 0?Math.abs(i-a):void 0,c=typeof t.mip_node_count==`bigint`?Number(t.mip_node_count):typeof t.mip_node_count==`number`&&Number.isFinite(t.mip_node_count)?t.mip_node_count:void 0,l=typeof t.mip_total_lp_iterations==`bigint`?Number(t.mip_total_lp_iterations):typeof t.simplex_iteration_count==`number`&&Number.isFinite(t.simplex_iteration_count)?t.simplex_iteration_count:typeof t.ipm_iteration_count==`number`&&Number.isFinite(t.ipm_iteration_count)?t.ipm_iteration_count:void 0,u=typeof e?.message==`string`&&e.message.trim().length>0?e.message.trim():void 0,d={elapsedTime:n,elapsedSeconds:n,...i===void 0?{}:{objectiveValue:i},...a===void 0?{}:{objectiveBound:a},...o===void 0?{}:{relativeGap:o},...s===void 0?{}:{absoluteGap:s},...c===void 0?{}:{nodes:c},...l===void 0?{}:{iterations:l},...u===void 0?{}:{message:u}};return p=d,d},g=e=>{let n=e?.data;if(!n||!(n.mip_solution instanceof Float64Array))return;let r=n.mip_solution,i={};for(let e=0;e<u.length&&e<r.length;e++)Object.defineProperty(i,u[e].name,{value:{Index:e,Type:u[e].type,Name:u[e].name,Primal:r[e]},enumerable:!0,writable:!0,configurable:!0});let a=typeof n.objective_function_value==`number`&&Number.isFinite(n.objective_function_value)?n.objective_function_value:typeof n.mip_primal_bound==`number`&&Number.isFinite(n.mip_primal_bound)?n.mip_primal_bound:NaN;Number.isFinite(a)&&(f={objectiveValue:a,...typeof n.mip_dual_bound==`number`&&Number.isFinite(n.mip_dual_bound)?{mipDualBound:n.mip_dual_bound}:{},...typeof n.mip_gap==`number`&&Number.isFinite(n.mip_gap)?{mipGap:n.mip_gap}:{},columns:i},t.onIncumbent?.(f))},_=!1;if(t.signal||t.onProgress||t.onIncumbent){let r=n.constants?.callbackType??{logging:0,simplexInterrupt:1,ipmInterrupt:2,mipSolution:3,mipImprovingSolution:4,mipLogging:5,mipInterrupt:6},i=e=>{if(t.signal?.aborted){_=!0,e.interrupt();return}t.onProgress&&(m++,t.onProgress(h(e)),t.signal?.aborted&&(_=!0,e.interrupt()))},a={[r.simplexInterrupt]:i,[r.ipmInterrupt]:i,[r.mipInterrupt]:i,[r.mipImprovingSolution]:e=>{g(e),t.onProgress&&!t.signal?.aborted&&(m++,t.onProgress(h(e)))},[r.mipLogging]:e=>{t.onProgress&&!t.signal?.aborted&&(m++,t.onProgress(h(e)))}};e.run(a)}else e.run();let v=e.getModelStatus();_&&(v=17);let y=wt[v]??`Unknown`,b=0,x=0;try{b=Number(e.info.get(`primal_solution_status`))}catch{}try{x=Number(e.info.get(`dual_solution_status`))}catch{}let S=n.constants?.solutionStatus?.feasible??2,C=b===S,w=x===S,T=C||w?e.getSolution():null,E=C,D={};if(!C&&f!==null)E=!0,D=f.columns;else for(let e=0;e<l.numCols;e++){let t=u[e],n={Index:e,Type:t.type,Name:t.name};C&&T&&(n.Primal=T.colValue[e]),!d&&w&&T&&(n.Dual=T.colDual[e]),Object.defineProperty(D,t.name,{value:n,enumerable:!0,writable:!0,configurable:!0})}let ee=[];for(let t=0;t<l.numRows;t++){let n=e.getRowName(t),r={Index:t,Name:n};C&&T&&(r.Primal=T.rowValue[t]),!d&&w&&T&&(r.Dual=T.rowDual[t]),ee.push(r)}let O=C?e.getObjectiveValue():f===null?NaN:f.objectiveValue,k,A;if(d){try{let t=Number(e.info.get(`mip_dual_bound`));Number.isFinite(t)&&(k=t)}catch{}k===void 0&&p&&p.objectiveBound!==void 0&&(k=p.objectiveBound);try{let t=Number(e.info.get(`mip_gap`));Number.isFinite(t)&&(A=t)}catch{}A===void 0&&p&&p.relativeGap!==void 0&&(A=p.relativeGap)}return{Status:wt[v]??y,StatusCode:v,PrimalSolutionStatus:b,DualSolutionStatus:x,HasPrimalSolution:E,IsMip:d,ObjectiveValue:O,ObjectiveOffsetApplied:c,MipDualBound:k,MipGap:A,Columns:D,Rows:ee}}),runTime:(performance.now()-r)/1e3}}function Y(){let e=_t(`solvers/highs-worker.js`),t=typeof window.origin==`string`?window.origin:window.location?.origin;if(new URL(e).origin===t)return new Worker(e,{type:`module`});let n=URL.createObjectURL(new Blob([`import `+JSON.stringify(e)+`;`],{type:`text/javascript`}));try{let e=new Worker(n,{type:`module`}),t=()=>URL.revokeObjectURL(n);return e.addEventListener(`message`,t,{once:!0}),e.addEventListener(`error`,t,{once:!0}),e}catch(e){throw URL.revokeObjectURL(n),e}}var Kt=null,qt=!1,Jt=0,X=new Map;function Yt(e,t){return e?{Status:`Interrupted`,StatusCode:17,HasPrimalSolution:!0,IsMip:!0,ObjectiveValue:e.objectiveValue,ObjectiveOffsetApplied:!0,...t?.objectiveBound===void 0?e.mipDualBound===void 0?{}:{MipDualBound:e.mipDualBound}:{MipDualBound:t.objectiveBound},...t?.relativeGap===void 0?e.mipGap===void 0?{}:{MipGap:e.mipGap}:{MipGap:t.relativeGap},Columns:e.columns,Rows:[]}:{Status:`Interrupted`,StatusCode:17,HasPrimalSolution:!1,ObjectiveValue:NaN,ObjectiveOffsetApplied:!0,...t?.objectiveBound===void 0?{}:{MipDualBound:t.objectiveBound},...t?.relativeGap===void 0?{}:{MipGap:t.relativeGap},Columns:{},Rows:[]}}function Xt(e){let t=X.values().next().value;if(!t||t.dispatched)return;t.dispatched=!0;let n={},r=!1;t.embeddedWasmBinary!==null&&!qt&&(n.embeddedWasmBinary=t.embeddedWasmBinary,r=!0);try{t.kind===`WARMUP`?e.postMessage({type:`WARMUP`,id:t.id,options:t.workerOptions,...n}):e.postMessage({type:`SOLVE`,id:t.id,lpString:t.lpString,options:t.workerOptions,...n,...t.reportProgress?{reportProgress:!0}:{}}),r&&(qt=!0)}catch(n){X.delete(t.id),t.cleanupAbort?.(),t.reject(n),Xt(e)}}function Zt(){let e=Kt;e&&(Kt=null,qt=!1,e.terminate());for(let e of X.values())e.dispatched=!1;if(X.size>0)try{let e=$t();if(e)Xt(e);else{let e=Error(`[WaSHI] Failed to recreate HiGHS Worker after interruption.`);for(let t of Array.from(X.values()))X.delete(t.id),t.cleanupAbort?.(),t.reject(e)}}catch(e){for(let t of Array.from(X.values()))X.delete(t.id),t.cleanupAbort?.(),t.reject(e)}}function Qt(){return typeof window<`u`&&typeof Worker<`u`&&typeof Worker?.prototype?.unref!=`function`}function $t(){if(!Qt())return null;if(!Kt){let e;try{e=Y(),e.onmessage=t=>{let{type:n,id:r,result:i,runTime:a,error:o,progress:s,incumbent:c}=t.data,l=X.get(r);if(l){if(n===`SOLVE_PROGRESS`){if(l.kind===`SOLVE`&&s){l.lastProgress=s;try{l.onProgress?.(s)}catch(e){let t=X.get(r);if(t){let n=X.keys().next().value;X.delete(r),t.cleanupAbort?.(),n===r&&Zt(),t.reject(e)}}}return}if(n===`SOLVE_INCUMBENT`){l.kind===`SOLVE`&&c&&(l.lastIncumbent=c);return}X.delete(r),l.cleanupAbort?.(),l.kind===`WARMUP`?n===`WARMUP_SUCCESS`?(Kt===e&&l.targetKey,l.resolve()):l.reject(Error(o||`Worker warmup failed`)):n===`SOLVE_SUCCESS`?(Kt===e&&l.targetKey,l.resolve({result:i,runTime:a})):l.reject(Error(o||`Worker solve failed`)),Kt===e&&Xt(e)}};let t=t=>{if(Kt===e){Kt=null,qt=!1,e.terminate();for(let e of X.values())e.cleanupAbort?.(),e.reject(t);X.clear()}};e.onerror=e=>t(Error(`[WaSHI] HiGHS Worker failed to load or execute. Check Worker assets, CORS and CSP. ${e?.message||``}`)),e.onmessageerror=()=>t(Error(`[WaSHI] Could not deserialize the HiGHS Worker response.`)),Kt=e}catch(e){throw Kt=null,e}}return Kt}function en(e){let t=typeof window<`u`?typeof window.origin==`string`?window.origin:window.location?.origin:void 0;return e.useWorker??(typeof window<`u`&&t!==`null`&&!t?.startsWith(`file:`))}function tn(e){if(e.useWorker===!0&&!Qt())throw Error(`[WaSHI] Web Worker execution was requested (useWorker: true), but browser Web Workers are unavailable in this environment.`);return en(e)?$t():null}async function nn(e,t){let n=t?pt(`highs`):mt(`highs`),r=n?.kind===`embedded`?n.bytes:null;if(e.wasmUrl){let t=await Ht(e.wasmUrl);return{wasmUrl:t,embeddedWasmBinary:r,targetKey:`url:${t}`}}if(Vt()){let e=await Ht();return{wasmUrl:e,embeddedWasmBinary:r,targetKey:`url:${e}`}}if(!n)return{wasmUrl:null,embeddedWasmBinary:null,targetKey:null};if(n.kind===`embedded`)return{wasmUrl:null,embeddedWasmBinary:r,targetKey:`__embedded__`};let i=await Ht();return{wasmUrl:i,embeddedWasmBinary:null,targetKey:`url:${i}`}}function rn(e,t){let{signal:n,onProgress:r,onIncumbent:i,...a}=e,o={};for(let[e,t]of Object.entries(a)){if(typeof t==`function`)throw Error(`[WaSHI] HiGHS Worker option "${e}" cannot be a function (functions cannot be cloned across Web Worker boundaries).`);o[e]=t}return t===null?delete o.wasmUrl:o.wasmUrl=t,o}function an(e,t,n){if(!e)return;let r=()=>{let e=X.get(t.id);if(!e)return;let r=X.keys().next().value;X.delete(t.id),e.cleanupAbort?.(),r===t.id&&Zt(),n()};e.addEventListener(`abort`,r,{once:!0}),t.cleanupAbort=()=>e.removeEventListener(`abort`,r)}async function on(e,t={}){if(Lt(t),t.signal?.aborted)return{result:Yt(),runTime:0};let n=await nn(t,!0);if(t.signal?.aborted)return{result:Yt(),runTime:0};let r=tn(t);if(!r)return Gt(e,t);let{signal:i,onProgress:a}=t,o=rn(t,n.wasmUrl),s=!!(a||i),c=`req_${++Jt}`,l=performance.now();return new Promise((t,u)=>{let d={kind:`SOLVE`,id:c,lpString:e,workerOptions:o,embeddedWasmBinary:n.embeddedWasmBinary,targetKey:n.targetKey,reportProgress:s,startTime:l,onProgress:a,resolve:t,reject:u};an(i,d,()=>{let e=(performance.now()-d.startTime)/1e3;d.resolve({result:Yt(d.lastIncumbent,d.lastProgress),runTime:e})}),X.set(c,d),Xt(r)})}function sn(e,t){if(typeof t==`number`)switch(t){case 0:return`NotSolved`;case 1:case 2:case 3:case 4:case 5:return`Error`;case 6:return`Unknown`;case 7:return`Optimal`;case 8:return`Infeasible`;case 9:return`InfeasibleOrUnbounded`;case 10:return`Unbounded`;case 11:return`ObjectiveBound`;case 12:return`ObjectiveTarget`;case 13:return`TimeLimit`;case 14:return`IterationLimit`;case 15:return`Unknown`;case 16:return`SolutionLimit`;case 17:return`Interrupted`;case 18:return`MemoryLimit`}if(typeof e!=`string`)return`Unknown`;let n=e.trim();if(!n)return`Unknown`;switch(n){case`Optimal`:return`Optimal`;case`Infeasible`:return`Infeasible`;case`Unbounded`:return`Unbounded`;case`Primal infeasible or unbounded`:case`InfeasibleOrUnbounded`:return`InfeasibleOrUnbounded`;case`Time limit reached`:case`TimeLimit`:return`TimeLimit`;case`Iteration limit reached`:case`IterationLimit`:return`IterationLimit`;case`Solution limit reached`:case`SolutionLimit`:return`SolutionLimit`;case`Memory limit reached`:case`MemoryLimit`:return`MemoryLimit`;case`Bound on objective reached`:case`ObjectiveBound`:return`ObjectiveBound`;case`Target for objective reached`:case`ObjectiveTarget`:return`ObjectiveTarget`;case`Interrupted`:case`User interrupt`:return`Interrupted`;case`Feasible`:return`Feasible`;case`Not Set`:return`NotSolved`;case`Load error`:case`Model error`:case`Presolve error`:case`Solve error`:case`Postsolve error`:case`Error`:return`Error`;case`Empty`:case`Unknown`:return`Unknown`}return`Unknown`}function cn(e,t,n){switch(sn(e,t)){case`Optimal`:return`Optimal`;case`Infeasible`:return`Infeasible`;case`Unbounded`:return`Unbounded`;case`TimeLimit`:return`TimeLimit`;case`IterationLimit`:return`IterationLimit`;case`Feasible`:return`Feasible`;case`ObjectiveBound`:case`ObjectiveTarget`:case`SolutionLimit`:return n===!1?`Unknown`:`Feasible`;case`MemoryLimit`:case`Interrupted`:return n?`Feasible`:`Unknown`;case`NotSolved`:return`NotSolved`;case`Error`:return`Error`;default:return`Unknown`}}var ln=class e{static capabilities={supportsMIP:!0,supportsQP:!0,supportsWarmStart:!0};name=`HiGHS`;version=`1.15.1`;capabilities=e.capabilities;options;constructor(e={}){this.options=e}async solve(e,t={},n={}){let r=Ge(t),i=r?n:t,a={...this.options,...i};Lt(a);let o=e.objective?.constant??0;if(typeof o!=`number`||!Number.isFinite(o))throw Error(`Solver "${this.name}" encountered non-finite objective constant: ${String(o)}.`);let s=o===0?0:o;for(let t of e.variables)M(t);let{lpString:c,nameToVar:l,nameToConstraint:u}=r?t:Je(e,{relax:a.relax}),d=Object.create(null),f=!1,p=new Set;for(let[e,t]of l.entries()){p.add(t);let n=ae(t);n!==void 0&&(d[e]=n,f=!0)}for(let t of e.variables)if(!p.has(t))throw Error(`LP export symbol map (nameToVar) is missing model variable "${t.name}".`);let m=a;(s!==0||f||m.initialValues!==void 0)&&(m={...m,...s===0?{}:{objectiveOffset:s},...f?{initialValues:d}:{}});let{result:h,runTime:g}=await on(c,m),_=h?.ObjectiveOffsetApplied?0:s,v=sn(h?.Status,h?.StatusCode),y=a.relax?!1:typeof h?.IsMip==`boolean`?h.IsMip:e.variables.some(e=>e.type===`Integer`||e.type===`Binary`),b=h?.HasPrimalSolution===!0,x=cn(h?.Status,h?.StatusCode,b),S=null;b&&typeof h?.ObjectiveValue==`number`&&Number.isFinite(h.ObjectiveValue)&&(S=h.ObjectiveValue+_);let C,w,T;if(typeof h?.MipDualBound==`number`&&Number.isFinite(h.MipDualBound)?C=h.MipDualBound+_:!y&&v===`Optimal`&&S!==null&&(C=S),S!==null&&C!==void 0&&Number.isFinite(C)&&(T=Math.abs(S-C)),_!==0&&y&&S!==null&&C!==void 0&&T!==void 0){if(T===0)w=0;else if(Math.abs(S)>0){let e=T/Math.abs(S);w=Number.isFinite(e)?e:void 0}else w=void 0}else typeof h?.MipGap==`number`&&Number.isFinite(h.MipGap)?w=h.MipGap:y&&v===`Optimal`&&b&&(T===void 0||T===0)&&(w=0);if(!b)return{status:x,terminationStatus:v,hasPrimalSolution:!1,objectiveValue:null,...C===void 0?{}:{objectiveBound:C},...w===void 0?{}:{relativeGap:w},...T===void 0?{}:{absoluteGap:T},values:{},reducedCosts:{},duals:{},slacks:{},runTime:g,raw:h};let E=(e,t,n)=>{Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})},D={},ee={},O={},k={};if(h.Columns)for(let[e,t]of Object.entries(h.Columns)){let n=l.get(e);if(n){if(typeof t.Primal==`number`&&Number.isFinite(t.Primal)){let e=Math.abs(t.Primal)<1e-9?0:t.Primal;!a.relax&&(n.type===`Integer`||n.type===`Binary`)&&Math.abs(e-Math.round(e))<=1e-5&&(e=Math.round(e)+0),E(D,n.name,e)}typeof t.Dual==`number`&&Number.isFinite(t.Dual)&&E(O,n.name,Math.abs(t.Dual)<1e-9?0:t.Dual)}}if(h.Rows){let e=Array.isArray(h.Rows)?h.Rows:Object.values(h.Rows);for(let t of e){let e=t.Name,n=e?u.get(e):void 0;if(n&&(typeof t.Dual==`number`&&Number.isFinite(t.Dual)&&E(ee,n.name,Math.abs(t.Dual)<1e-9?0:t.Dual),typeof t.Primal==`number`&&Number.isFinite(t.Primal))){let e=n.rhs-t.Primal;E(k,n.name,Math.abs(e)<1e-9?0:e)}}}return{status:x,terminationStatus:v,hasPrimalSolution:!0,objectiveValue:S,...C===void 0?{}:{objectiveBound:C},...w===void 0?{}:{relativeGap:w},...T===void 0?{}:{absoluteGap:T},values:D,reducedCosts:O,duals:ee,slacks:k,runTime:g,raw:h}}};function un(){$e(`highs`,e=>new ln(e)),et(e=>new ln(e))}un(),kt();var dn=typeof document<`u`?document.currentScript?.src:null,fn=dn?new URL(`.`,dn).href:null;function pn(e){if(!fn)throw Error(`[WaSHI] Load the browser IIFE using an external script src, or use the browser ESM build.`);return new URL(e,fn).href}function mn(){return pn(`solvers/pumpkin.wasm`)}function hn(){function e(e){let t,n;try{let r=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),i=g,a=_.check_json(r,i);return t=a[0],n=a[1],o(a[0],a[1])}finally{_.__wbindgen_free(t,n,1)}}function t(e,t){let n,r;try{let i=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),s=g,c=_.check_with_callback(i,s,u(t)?0:a(t));return n=c[0],r=c[1],o(c[0],c[1])}finally{_.__wbindgen_free(n,r,1)}}function n(e){let t,n;try{let r=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),i=g,a=_.solve_json(r,i);return t=a[0],n=a[1],o(a[0],a[1])}finally{_.__wbindgen_free(t,n,1)}}function r(e,t,n){let r,i;try{let s=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),c=g,l=_.solve_with_callback(s,c,u(t)?0:a(t),u(n)?0:a(n));return r=l[0],i=l[1],o(l[0],l[1])}finally{_.__wbindgen_free(r,i,1)}}function i(){return{__proto__:null,"./pumpkin_bg.js":{__proto__:null,__wbg___wbindgen_boolean_get_4f1baf9a00be3c74:function(e){let t=e,n=typeof t==`boolean`?t:void 0;return u(n)?16777215:+!!n},__wbg___wbindgen_is_undefined_be5b34249ff1fc15:function(e){return e===void 0},__wbg___wbindgen_throw_4c88d8bf264fd984:function(e,t){throw Error(o(e,t))},__wbg_call_40b008ba32f73991:function(){return l(function(e,t){return e.call(t)},arguments)},__wbg_call_a410eb4b59ed5965:function(){return l(function(e,t,n){return e.call(t,n)},arguments)},__wbg_now_e7c6795a7f81e10f:function(e){return e.now()},__wbg_performance_7e4e4494fdc9d07a:function(e){return e.performance},__wbg_static_accessor_GLOBAL_THIS_003ee833af9699fc:function(){let e=typeof globalThis>`u`?void 0:globalThis;return u(e)?0:a(e)},__wbg_static_accessor_GLOBAL_e4293fb22cbe77da:function(){let e=typeof globalThis>`u`?void 0:globalThis;return u(e)?0:a(e)},__wbg_static_accessor_SELF_53bb20457401453d:function(){let e=typeof self>`u`?void 0:self;return u(e)?0:a(e)},__wbg_static_accessor_WINDOW_b5e0810bfecb7feb:function(){let e=typeof window>`u`?void 0:window;return u(e)?0:a(e)},__wbindgen_generic_0000000000000001:function(e,t){return o(e,t)},__wbindgen_init_externref_table:function(){let e=_.__wbindgen_externrefs;e.set(0,void 0),e.set(1024,void 0),e.set(1025,null),e.set(1026,!0),e.set(1027,!1)}}}}function a(e){let t=_.__externref_table_alloc();return _.__wbindgen_externrefs.set(t,e),t}function o(e,t){return e>>>=0,m(c().subarray(e,e+t))}let s=null;function c(){return(s===null||s.byteLength===0)&&(s=new Uint8Array(_.memory.buffer)),s}function l(e,t){try{return e.apply(this,t)}catch(e){let t=a(e);_.__wbindgen_exn_store(t)}}function u(e){return e==null}function d(e,t,n){if(n===void 0){let n=h.encode(e),r=t(n.length,1)>>>0;return c().subarray(r,r+n.length).set(n),g=n.length,r}let r=e.length,i=t(r,1)>>>0,a=c(),o=0;for(;o<r;o++){let t=e.charCodeAt(o);if(t>127)break;a[i+o]=t}if(o!==r){o!==0&&(e=e.slice(o)),i=n(i,r,r=o+e.length*3,1)>>>0;let t=c().subarray(i+o,i+r),a=h.encodeInto(e,t);o+=a.written,i=n(i,r,o,1)>>>0}return g=o,i}let f=new TextDecoder(`utf-8`,{ignoreBOM:!0});f.decode();let p=0;function m(e){return p+=e.length,p>=2146435072&&(f=new TextDecoder(`utf-8`,{ignoreBOM:!0}),f.decode(),p=e.length),f.decode(e)}let h=new TextEncoder;`encodeInto`in h||(h.encodeInto=function(e,t){let n=h.encode(e);return t.set(n),{read:e.length,written:n.length}});let g=0,_;function v(e,t){if(_=e.exports,s=null,!_||!(_.memory instanceof WebAssembly.Memory)||typeof _.__wbindgen_start!=`function`||typeof _.__wbindgen_malloc!=`function`||typeof _.__wbindgen_free!=`function`||typeof _.check_json!=`function`||typeof _.check_with_callback!=`function`||typeof _.solve_json!=`function`||typeof _.solve_with_callback!=`function`)throw Error(`[WaSHI] Invalid Pumpkin WebAssembly module: missing expected solver exports.`);return _.__wbindgen_start(),_}async function y(e,t){if(typeof Response==`function`&&e instanceof Response){if(!e.ok)throw Error(`failed to fetch Wasm: ${e.status} ${e.statusText} fetching '${e.url}'`);if(typeof WebAssembly.instantiateStreaming==`function`)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if(n(e.type)&&e.headers.get(`Content-Type`)!==`application/wasm`)console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",t);else throw t}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}{let n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}function n(e){switch(e){case`basic`:case`cors`:case`default`:return!0}return!1}}let b;async function x(e){return _===void 0?(b===void 0&&(b=S(e),b.catch(()=>{b=void 0})),b):_}async function S(e){e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn(`using deprecated parameters for the initialization function; pass a single object instead`));let t=i();(typeof e==`string`||typeof Request==`function`&&e instanceof Request||typeof URL==`function`&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:r}=await y(await e,t);return v(n,r)}return{check_json:e,check_with_callback:t,solve_json:n,solve_with_callback:r,__wbg_init:x}}async function gn(e){let t=hn();return await t.__wbg_init({module_or_path:e}),{check_json:t.check_json,check_with_callback:t.check_with_callback,solve_json:t.solve_json,solve_with_callback:t.solve_with_callback}}var _n=r({readBundledPumpkinWasmBytes:()=>yn,readPumpkinWasmFileUrl:()=>vn});async function vn(){throw Error(`This distribution is for browsers. Use the npm entry in Node.js.`)}async function yn(){throw Error(`This distribution is for browsers. Use the npm entry in Node.js.`)}var bn=n((()=>{})),xn=4,Sn=null,Cn=new Map,wn=new Set,Tn=0;function En(){return!1}function Dn(e){return e.byteLength>=8&&e[0]===0&&e[1]===97&&e[2]===115&&e[3]===109}function On(){return Sn}function kn(e,t){if(e!==void 0){let n=Mn(e);return n===null?t?t.kind===`embedded`?{kind:`embedded`,binary:t.bytes,key:`__embedded__`}:{kind:`url`,url:null,key:`__bundled__`}:null:{kind:`url`,url:n,key:`url:${n}`}}return Sn===null?t?t.kind===`embedded`?{kind:`embedded`,binary:t.bytes,key:`__embedded__`}:{kind:`url`,url:null,key:`__bundled__`}:null:{kind:`url`,url:Sn,key:`url:${Sn}`}}function An(){if(typeof Worker>`u`||typeof window>`u`||typeof Worker.prototype.unref==`function`)return!1;let e=typeof window.origin==`string`?window.origin:(()=>{try{return window.location?.origin}catch{return}})();return!(!e||e===`null`||e.startsWith(`file:`))}async function jn(e){if(typeof fetch!=`function`)throw Error(`[WaSHI] Global fetch() is unavailable to load Pumpkin WebAssembly from "${e}"; no CDN fallback is attempted.`);let t;try{t=await fetch(e)}catch(t){throw Error(`[WaSHI] Failed to fetch pumpkin.wasm from "${e}" (no CDN fallback is attempted): ${t instanceof Error?t.message:String(t)}. Ensure pumpkin.wasm is hosted cleanly or call setPumpkinWasmUrl(url).`)}if(!t.ok)throw Error(`[WaSHI] Failed to fetch pumpkin.wasm from "${e}": HTTP ${t.status} ${t.statusText}; no CDN fallback is attempted.`);let n=t.headers?.get(`content-type`)?.toLowerCase()??``;if(n.includes(`text/html`))throw Error(`[WaSHI] Invalid response while loading pumpkin.wasm from "${e}": received HTML ("${n}") instead of a WebAssembly binary; no CDN fallback is attempted.`);let r=await t.arrayBuffer(),i=new Uint8Array(r);if(!Dn(i))throw Error(`[WaSHI] Invalid WebAssembly binary loaded from "${e}": expected \\0asm magic header; no CDN fallback is attempted.`);return i}function Mn(e){if(e===void 0)return Sn;if(e!==null&&typeof e!=`string`)throw Error(`Invalid pumpkin.wasm URL: expected string or null, got ${typeof e}.`);if(e===``)throw Error(`Invalid pumpkin.wasm URL: expected non-empty string or null (received empty string "").`);return e}async function Nn(e){if(e!==null){if(En()&&e.startsWith(`file://`)){let{readPumpkinWasmFileUrl:t}=await Promise.resolve().then(()=>(bn(),_n)),n=await t(new URL(e));if(!Dn(n))throw Error(`[WaSHI] Invalid WebAssembly binary at "${e}": expected \\0asm magic header.`);return n}return jn(e)}if(En()&&typeof window>`u`){let{readBundledPumpkinWasmBytes:e}=await Promise.resolve().then(()=>(bn(),_n)),t=await e();if(!Dn(t))throw Error(`[WaSHI] Bundled pumpkin.wasm on disk has an invalid WebAssembly magic header.`);return t}return jn(mn())}async function Pn(e){let t=kn(e,pt(`pumpkin`));if(!t)throw Error(`[WaSHI] Failed to resolve Pumpkin WASM target.`);let n=t.key,r=Cn.get(n);if(r)return Cn.delete(n),Cn.set(n,r),r;let i=Tn,a=null;for(a=(async()=>{try{let e=await gn(t.kind===`embedded`?t.binary.slice():await Nn(t.url));return Tn===i&&Cn.get(n)===a&&wn.add(n),e}catch(e){throw Tn===i&&(wn.delete(n),Cn.get(n)===a&&Cn.delete(n)),t.kind===`url`&&t.url!==null&&e instanceof Error&&e.message.includes(`Invalid Pumpkin WebAssembly module`)?Error(`[WaSHI] Invalid Pumpkin WebAssembly module loaded from "${t.url}" (${e.message}); no CDN fallback is attempted.`):e}})();Cn.size>=xn;){let e=Cn.keys().next().value;if(e===void 0)break;Cn.delete(e),wn.delete(e)}return Cn.set(n,a),a}function Fn(){let e=pn(`solvers/pumpkin-worker.js`),t=typeof window.origin==`string`?window.origin:window.location?.origin;if(new URL(e).origin===t)return new Worker(e,{type:`module`});let n=URL.createObjectURL(new Blob([`import `+JSON.stringify(e)+`;`],{type:`text/javascript`}));try{let e=new Worker(n,{type:`module`}),t=()=>URL.revokeObjectURL(n);return e.addEventListener(`message`,t,{once:!0}),e.addEventListener(`error`,t,{once:!0}),e}catch(e){throw URL.revokeObjectURL(n),e}}function In(e){if(e===``)throw Error(`Invalid pumpkin.wasm URL: expected non-empty string or null (received empty string "").`);if(e!=null&&typeof e!=`string`)throw Error(`Invalid pumpkin.wasm URL: expected string or null, got ${typeof e}.`)}function Ln(e){return{status:`Unknown`,values:[],boolValues:[],runTime:Math.max((performance.now()-e)/1e3,1e-6)}}function Rn(e,t){let n=Math.max((performance.now()-e)/1e3,1e-6);return t?{status:`Feasible`,terminationStatus:`Interrupted`,objectiveValue:t.objectiveValue,values:t.values,boolValues:t.boolValues,runTime:n}:{status:`Unknown`,terminationStatus:`Interrupted`,objectiveValue:null,values:[],boolValues:[],runTime:n}}function zn(e={}){let t=e.workerFactory??Fn,n=null,r=1,i=null,a=[],o=new Set,s=!1,c=!1;In(e.wasmUrl);let l=e=>{for(o.delete(e),o.add(e);o.size>4;){let e=o.keys().next().value;if(e===void 0)break;o.delete(e)}},u=()=>{o.clear(),s=!1,n&&=(n.onmessage=null,n.onerror=null,n.onmessageerror=null,n.terminate(),null)},d=e=>{i===e&&(i=null),e.cleanupAbort?.()},f=(e,t)=>{d(e),e.resolve(t),v()},p=(e,t)=>{d(e),e.resolve(t),v()},m=(e,t)=>{d(e),e.reject(t),v()},h=e=>{e.type===`check`?f(e,Ln(e.startTimeMs)):p(e,Rn(e.startTimeMs,e.lastIncumbent))},g=(e,t,n)=>{if(typeof e!=`string`)throw Error(`Pumpkin worker response is missing canonical responseJson string.`);let r=JSON.parse(e);if(!r)throw Error(`Pumpkin worker returned an empty success payload.`);if(r.error)throw Error(r.error);return{...r,runTime:typeof t==`number`?t:Math.max((performance.now()-n)/1e3,1e-6)}},_=()=>{if(n)return n;let e=t();return e.onmessage=t=>{let r=t.data,a=i;if(n===e&&r&&a&&r.id===a.id){if(r.type===`SOLVE_PROGRESS`){if(a.type!==`solve`)return;try{if(typeof r.payloadJson!=`string`)throw Error(`Pumpkin worker SOLVE_PROGRESS is missing canonical payloadJson string.`);let t=JSON.parse(r.payloadJson);if(!t)throw Error(`Pumpkin worker SOLVE_PROGRESS returned an empty incumbent payload.`);if(a.lastIncumbent=t,a.onProgress){let e=typeof r.elapsedTime==`number`?r.elapsedTime:Math.max((performance.now()-a.startTimeMs)/1e3,1e-6);a.onProgress({elapsedTime:e,elapsedSeconds:e,objectiveValue:t.objectiveValue})}if(n!==e||i!==a)return;a.signal?.aborted&&(u(),h(a))}catch(t){n===e&&i===a&&(u(),m(a,t))}return}if(r.type===`CHECK_SUCCESS`){if(a.type!==`check`){u(),m(a,Error(`Received "CHECK_SUCCESS" for a solve task.`));return}try{let e=g(r.responseJson,r.runTime,a.startTimeMs);l(a.cacheKey),f(a,e)}catch(t){n===e&&i===a&&(u(),m(a,t))}return}if(r.type===`SOLVE_SUCCESS`){if(a.type!==`solve`){u(),m(a,Error(`Received "SOLVE_SUCCESS" for a check task.`));return}try{let e=g(r.responseJson,r.runTime,a.startTimeMs);l(a.cacheKey),p(a,e)}catch(t){n===e&&i===a&&(u(),m(a,t))}return}if(r.type===`SOLVER_ERROR`){let e=typeof r.error==`string`?r.error:`Pumpkin worker execution failed.`;m(a,Error(e))}}},e.onerror=t=>{if(n!==e)return;let r=i;if(u(),r){let e=t?.message||`Pumpkin Web Worker encountered an unexpected error.`;m(r,Error(e))}},e.onmessageerror=()=>{if(n!==e)return;let t=i;u(),t&&m(t,Error(`Failed to deserialize message from Pumpkin Web Worker.`))},n=e,e},v=()=>{if(!(i||c))for(;a.length>0;){let e=a.shift();if(e.signal?.aborted){e.type===`check`?e.resolve(Ln(e.startTimeMs)):e.resolve(Rn(e.startTimeMs,e.lastIncumbent));continue}if(i=e,e.startTimeMs=performance.now(),e.signal){let t=()=>{i===e&&(u(),h(e))};e.signal.addEventListener(`abort`,t,{once:!0}),e.cleanupAbort=()=>e.signal?.removeEventListener(`abort`,t)}try{let t=_(),n={id:e.id,type:e.type,requestJson:e.requestJson};e.wasmUrl!==void 0&&(n.wasmUrl=e.wasmUrl);let r=!1;e.embeddedWasmBinary!==null&&!s&&(n.embeddedWasmBinary=e.embeddedWasmBinary,r=!0),t.postMessage(n),r&&(s=!0)}catch(t){i===e&&(u(),m(e,t))}return}},y=(t,n)=>{let r=n?pt(`pumpkin`):mt(`pumpkin`),i=r?.kind===`embedded`?r.bytes:null,a=r?r.kind===`embedded`?`__embedded__`:`__bundled__`:null;if(t!==void 0)return In(t),{wasmUrl:t,embeddedWasmBinary:i,cacheKey:t===null?a:`url:${t}`};if(e.wasmUrl!==void 0)return In(e.wasmUrl),{wasmUrl:e.wasmUrl,embeddedWasmBinary:i,cacheKey:e.wasmUrl===null?a:`url:${e.wasmUrl}`};let o=On();return In(o),{wasmUrl:o,embeddedWasmBinary:i,cacheKey:o===null?a:`url:${o}`}},b=e=>new Promise((t,n)=>{a.push(e(t,n)),v()});return{check(e,t){if(c)return Promise.reject(Error(`[WaSHI] Pumpkin worker client has been disposed.`));if(t?.signal?.aborted)return Promise.resolve(Ln(performance.now()));let n=y(e.wasmUrl,!0);return b((i,a)=>({id:r++,type:`check`,requestJson:e.requestJson,wasmUrl:n.wasmUrl,embeddedWasmBinary:n.embeddedWasmBinary,cacheKey:n.cacheKey,signal:t?.signal,startTimeMs:performance.now(),lastIncumbent:null,resolve:i,reject:a}))},solve(e,t){if(c)return Promise.reject(Error(`[WaSHI] Pumpkin worker client has been disposed.`));if(t?.signal?.aborted)return Promise.resolve(Rn(performance.now(),null));let n=y(e.wasmUrl,!0);return b((i,a)=>({id:r++,type:`solve`,requestJson:e.requestJson,wasmUrl:n.wasmUrl,embeddedWasmBinary:n.embeddedWasmBinary,cacheKey:n.cacheKey,signal:t?.signal,onProgress:t?.onProgress,startTimeMs:performance.now(),lastIncumbent:null,resolve:i,reject:a}))},isWarmed(e){if(c||n===null)return!1;let{cacheKey:t}=y(e,!1);return t!==null&&o.has(t)},dispose(){for(c=!0,u();a.length>0;){let e=a.shift();e.cleanupAbort?.(),e.reject(Error(`[WaSHI] Pumpkin worker client disposed.`))}if(i){let e=i;i=null,e.cleanupAbort?.(),e.reject(Error(`[WaSHI] Pumpkin worker client disposed.`))}}}}var Bn=null;function Vn(){return Bn||=zn(),Bn}var Hn=1073741823,Un=2147483646,Wn=1e-6;function Z(e){return Object.is(e,-0)||e===0?0:e}function Gn(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Q(e,t){if(typeof e!=`number`||Number.isNaN(e))throw Error(`PumpkinSolver encountered non-finite numeric value in ${t}.`);if(!Number.isFinite(e))throw Error(`PumpkinSolver only supports bounded finite integers (${t}: got ${e}).`);if(!Number.isInteger(e))throw Error(`PumpkinSolver only supports integer values (${t}: got ${e}).`);let n=Z(e);if(n<-1073741823||n>Hn)throw Error(`Value out of Pumpkin safe 32-bit integer range [-${Hn}, ${Hn}] (${t}: got ${n}).`);return n}function Kn(e){if(e===void 0||e===1/0)return null;if(typeof e!=`number`||Number.isNaN(e)||e<0||!Number.isFinite(e))throw Error(`Invalid timeLimit (${String(e)}): expected a finite non-negative number of seconds.`);if(e===0)return 0;let t=Math.round(e*1e3);if(t>2**53-1)throw Error(`timeLimit (${e}s) exceeds safe millisecond range.`);return Math.max(1,t)}function qn(e){return e instanceof w||typeof e==`object`&&!!e&&`quadTerms`in e}function Jn(e,t,n){if(e.initialValue===void 0)return;if(typeof e.initialValue!=`number`||!Number.isFinite(e.initialValue))throw Error(`Variable "${e.name}" has invalid initialValue: ${String(e.initialValue)} (initialValue must be a finite number).`);if(e.initialValue<t-Wn||e.initialValue>n+Wn)throw Error(`Variable "${e.name}" has initialValue (${e.initialValue}) outside its bounds [${t}, ${n}] (tolerance ${Wn}).`);let r=Z(Math.round(e.initialValue));if(Math.abs(e.initialValue-r)>Wn||r<t||r>n)throw Error(`Variable "${e.name}" of type "${e.type}" has non-integral or out-of-domain initialValue: ${e.initialValue} (must be within ${Wn} of an integer in [${t}, ${n}]).`);return Q(r,`initialValue of variable "${e.name}"`)}function Yn(e){let t=[],n=new Map,r=!1;for(let i=0;i<e.length;i++){let a=e[i],o=String(a.type).toLowerCase();if(o===`continuous`||o===`cont`)throw Error(`PumpkinSolver does not support Continuous variable "${a.name}". Use an Integer or Binary variable, or select a MIP/SMT solver.`);if(n.set(a,i),o===`binary`||o===`bin`){if(typeof a.lb!=`number`||Number.isNaN(a.lb)||typeof a.ub!=`number`||Number.isNaN(a.ub))throw Error(`PumpkinSolver encountered non-finite numeric value in bounds of variable "${a.name}".`);if(a.lb===1/0||a.ub===-1/0||a.lb>a.ub)throw Error(`Variable "${a.name}" has invalid bounds lb (${a.lb}) > ub (${a.ub}).`);if(Number.isFinite(a.lb)&&!Number.isInteger(a.lb)||Number.isFinite(a.ub)&&!Number.isInteger(a.ub))throw Error(`PumpkinSolver only supports integer values (bounds of binary variable "${a.name}").`);let e=a.lb===-1/0?0:Math.max(0,Z(a.lb)),n=a.ub===1/0?1:Math.min(1,Z(a.ub)),i=Jn(a,e,n);e>n?(r=!0,t.push({name:a.name,lb:0,ub:1})):t.push(i===void 0?{name:a.name,lb:e,ub:n}:{name:a.name,lb:e,ub:n,initialValue:i});continue}let s=Q(a.lb,`lower bound of variable "${a.name}"`),c=Q(a.ub,`upper bound of variable "${a.name}"`);if(s>c)throw Error(`Variable "${a.name}" has invalid bounds lb (${s}) > ub (${c}).`);let l=Jn(a,s,c);t.push(l===void 0?{name:a.name,lb:s,ub:c}:{name:a.name,lb:s,ub:c,initialValue:l})}return{vars:t,varIndexMap:n,hasEmptyDomain:r}}function Xn(e,t,n){let r=0;function i(e,n,i){let a=Q(e,`internal ${i} lb`),o=Q(n,`internal ${i} ub`),s=t.length;return t.push({name:`__pumpkin_${i}_${++r}`,lb:a,ub:o,internal:!0}),s}function a(n,r,i){let a=new Map;for(let[t,r]of n.entries()){let n=e.get(t);if(n===void 0)throw Error(`Variable "${t.name}" in ${i} is not registered in the model.`);if(typeof r!=`number`||!Number.isFinite(r))throw Error(`Invalid non-finite coefficient for "${t.name}" in ${i}.`);if(!Number.isInteger(r))throw Error(`PumpkinSolver only supports integer coefficients (variable "${t.name}" in ${i} has ${r}).`);let o=(a.get(n)??0)+Z(r);if(!Number.isSafeInteger(o))throw Error(`Coefficient sum overflow for "${t.name}" in ${i}.`);a.set(n,o)}for(let e of r){let t=(a.get(e.varIndex)??0)+Z(e.coeff);if(!Number.isSafeInteger(t))throw Error(`Coefficient sum overflow in ${i}.`);a.set(e.varIndex,t)}let o=[],s=0;for(let[e,n]of a.entries()){let r=Z(n);if(r===0)continue;let a=t[e];Q(r,`coefficient of "${a.name}" in ${i}`);let c=r*a.lb,l=r*a.ub;if(Q(c,`scaled lower bound of "${a.name}" in ${i}`),Q(l,`scaled upper bound of "${a.name}" in ${i}`),s+=Math.max(Math.abs(c),Math.abs(l)),s>Un)throw Error(`Linear expression magnitude in ${i} exceeds Pumpkin safe 32-bit propagator overflow limit.`);o.push({varIndex:e,coeff:r})}return{terms:o,sumMaxAbs:s}}function o(e,n,r){let i=n,a=n;for(let n of e){let e=t[n.varIndex],r=n.coeff*e.lb,o=n.coeff*e.ub;i+=Math.min(r,o),a+=Math.max(r,o)}return{lb:Q(Z(i),`lower bound of ${r}`),ub:Q(Z(a),`upper bound of ${r}`)}}function s(e,r,a){switch(e.kind){case`abs`:{let o=l(e.arg,r,`${a} abs()`),s=t[o],c=i(s.lb<=0&&s.ub>=0?0:Math.min(Math.abs(s.lb),Math.abs(s.ub)),Math.max(Math.abs(s.lb),Math.abs(s.ub)),`abs`);return n.push({kind:`abs`,argVar:o,outVar:c,owner:r}),c}case`max`:{let o=e.args.map((e,t)=>l(e,r,`${a} max()[${t}]`)),s=i(Math.max(...o.map(e=>t[e].lb)),Math.max(...o.map(e=>t[e].ub)),`max`);return n.push({kind:`max`,argVars:o,outVar:s,owner:r}),s}case`min`:{let o=e.args.map((e,t)=>l(e,r,`${a} min()[${t}]`)),s=i(Math.min(...o.map(e=>t[e].lb)),Math.min(...o.map(e=>t[e].ub)),`min`);return n.push({kind:`min`,argVars:o,outVar:s,owner:r}),s}case`at`:{let o=l(e.index,r,`${a} at() index`),s=e.array.map((e,t)=>l(e,r,`${a} at()[${t}]`)),c=i(Math.min(...s.map(e=>t[e].lb)),Math.max(...s.map(e=>t[e].ub)),`elem`);return n.push({kind:`element`,indexVar:o,arrayVars:s,outVar:c,owner:r}),c}}}function c(e,t,n,r=!1){if(typeof e.constant!=`number`||!Number.isFinite(e.constant))throw Error(`Invalid non-finite constant in ${n}.`);let i;if(r)i=Z(e.constant);else{if(!Number.isInteger(e.constant))throw Error(`PumpkinSolver only supports integer constants (${n}: got ${e.constant}).`);i=Q(Z(e.constant),`constant of ${n}`)}let o=[];if(Array.isArray(e.nonlinearTerms))for(let r of e.nonlinearTerms){if(r.coeff===0)continue;if(typeof r.coeff!=`number`||!Number.isFinite(r.coeff)||!Number.isInteger(r.coeff))throw Error(`PumpkinSolver only supports safe integer coefficients in ${n} (got ${r.coeff}).`);let e=Q(Z(r.coeff),`nonlinear coefficient in ${n}`),i=s(r.atom,t,n);o.push({varIndex:i,coeff:e})}let{terms:c,sumMaxAbs:l}=a(e.terms,o,n);return{terms:c,constant:i,sumMaxAbs:l}}function l(e,r,a){let{terms:s,constant:l}=c(e,r,a);if(s.length===1&&s[0].coeff===1&&l===0)return s[0].varIndex;let{lb:u,ub:d}=o(s,l,a),f=i(u,d,`expr`);if(s.length>0){let e=[...s,{varIndex:f,coeff:-1}],i=Q(Z(-l),`linearEq RHS in ${a}`),o=e.reduce((e,n)=>{let r=t[n.varIndex];return e+Math.max(Math.abs(n.coeff*r.lb),Math.abs(n.coeff*r.ub))},0);if(Math.abs(i)+o>Un)throw Error(`Linear expression magnitude in ${a} exceeds Pumpkin safe 32-bit propagator overflow limit.`);n.push({kind:`linearEq`,terms:e,rhs:i,owner:r})}return f}function u(e,t,n,r){if(typeof t!=`number`||!Number.isFinite(t))throw Error(`Invalid non-finite RHS in ${r}.`);if(!Number.isInteger(t))throw Error(`PumpkinSolver only supports integer RHS (${r}: got ${t}).`);let{terms:i,constant:a,sumMaxAbs:o}=c(e,n,r),s=Q(Z(t-a),`RHS of ${r}`);if(Math.abs(s)+o>Un)throw Error(`Linear expression magnitude in ${r} exceeds Pumpkin safe 32-bit propagator overflow limit.`);return{terms:i,rhs:s}}return{lowerLinExpr:c,materializeExprToVarIndex:l,serializeConstraintSide:u}}function Zn(e,t,n,r,i){if(r.has(e)||e instanceof c||typeof e==`object`&&e&&`name`in e&&`id`in e&&!(`op`in e)&&!(`lhs`in e)&&!(`spec`in e)){let t=e,n=r.get(t);if(n===void 0)throw Error(`Boolean variable "${t.name}" in ${i} is not registered in the model.`);return{kind:`boolVar`,index:n}}if(e instanceof I||`lhs`in e&&`sense`in e&&`rhs`in e){let r=e;if(qn(r.lhs))throw Error(`PumpkinSolver does not support quadratic constraints inside ${i}.`);let{terms:a,rhs:o}=t.serializeConstraintSide(r.lhs,r.rhs,n,i);return{kind:`linear`,terms:a,sense:r.sense,rhs:o}}if(e instanceof h||typeof e==`object`&&e&&`spec`in e&&typeof e.spec==`object`){let r=e.spec;switch(r.kind){case`distinct`:return{kind:`allDifferent`,vars:r.args.map((e,r)=>t.materializeExprToVarIndex(e,n,`${i} distinct()[${r}]`))};case`disjoint`:return{kind:`disjunctive`,tasks:r.tasks.map((e,r)=>({startVar:t.materializeExprToVarIndex(e.start,n,`${i} disjoint()[${r}]`),duration:Q(e.duration,`duration of ${i} disjoint()[${r}]`)}))};case`cumulative`:return{kind:`cumulative`,tasks:r.tasks.map((e,r)=>({startVar:t.materializeExprToVarIndex(e.start,n,`${i} cumulative()[${r}]`),duration:Q(e.duration,`duration of ${i} cumulative()[${r}]`),demand:Q(e.demand,`demand of ${i} cumulative()[${r}]`)})),capacity:Q(r.capacity,`capacity of ${i} cumulative()`)};case`allowed`:return{kind:`table`,vars:r.vars.map((e,r)=>t.materializeExprToVarIndex(e,n,`${i} allowed() vars[${r}]`)),tuples:r.tuples.map((e,t)=>e.map((e,n)=>Q(e,`tuple[${t}][${n}] in ${i}`)))}}}if(e instanceof l||`op`in e&&`children`in e){let a=e;switch(a.op){case`and`:return{kind:`and`,children:a.children.map(e=>Zn(e,t,n,r,i))};case`or`:return{kind:`or`,children:a.children.map(e=>Zn(e,t,n,r,i))};case`not`:if(a.children.length!==1)throw Error(`Invalid 'not' operator arity in ${i}.`);return{kind:`not`,child:Zn(a.children[0],t,n,r,i)};case`implies`:if(a.children.length!==2)throw Error(`Invalid 'implies' operator arity in ${i}.`);return{kind:`implies`,left:Zn(a.children[0],t,n,r,i),right:Zn(a.children[1],t,n,r,i)};case`xor`:return{kind:`xor`,children:a.children.map(e=>Zn(e,t,n,r,i))};default:throw Error(`Unsupported logical operator "${String(a.op)}" in ${i}.`)}}throw Error(`Unsupported logical constraint node in ${i}.`)}function Qn(e){let{vars:t,varIndexMap:n,hasEmptyDomain:r}=Yn(e.variables),i=[],a=Xn(n,t,i),o=e.boolVars??[],s=new Map,c=[];for(let e=0;e<o.length;e++)s.set(o[e],e),c.push(o[e].name);let l=[];for(let t=0;t<e.constraints.length;t++){let r=e.constraints[t],i=`constraint "${r.name}"`,o={kind:`constraint`,index:t};if(r._indicatorMeta){let e=r._indicatorMeta,t=n.get(e.binVar);if(t===void 0)throw Error(`Indicator binary variable "${e.binVar.name}" in ${i} is not registered in the model.`);let{terms:s,rhs:c}=a.serializeConstraintSide(e.targetLhs,e.targetRhs,o,i);l.push({name:r.name,terms:s,sense:e.targetSense,rhs:c,indicator:{binVarIndex:t,activeValue:e.activeValue}});continue}if(qn(r.lhs))throw Error(`PumpkinSolver does not support quadratic constraints (${i}).`);let{terms:s,rhs:c}=a.serializeConstraintSide(r.lhs,r.rhs,o,i);l.push({name:r.name,terms:s,sense:r.sense,rhs:c})}let u=[],d=e.logicalConstraints??[];for(let e=0;e<d.length;e++){let t=d[e],n=`logical constraint "${t.name}"`,r={kind:`logic`,index:e},i=Zn(t.expr,a,r,s,n);u.push({name:t.name,expr:i})}return{vars:t,boolVars:c,constraints:l,logicalConstraints:u,auxPropagators:i,varIndexMap:n,lowerer:a,hasEmptyDomain:r}}function $n(e,t,n){let r={};if(e)for(let[t,n]of e)Gn(r,t,Z(n));let i;if(t&&t.length>0){i={};for(let[e,a]of t)Gn(i,e,a),n&&Gn(r,e,+!!a)}return{values:r,...i===void 0?{}:{boolValues:i}}}function er(e,t){let n={};if(e)for(let[t,r]of e)Gn(n,t,Z(r));if(t)for(let[e,r]of t)Gn(n,e,r);return n}var tr=new Set([`presolve`,`relativeGap`,`absoluteGap`,`threads`,`verbose`,`outputFlag`]),nr=new Set([`timeLimit`,`wasmUrl`,`useWorker`,`signal`,`onProgress`,`relax`]);function rr(e={}){if(e.relax!==void 0){if(typeof e.relax!=`boolean`)throw Error(`Invalid Pumpkin option "relax": expected boolean, got ${typeof e.relax}.`);if(e.relax===!0)throw Error(`PumpkinSolver does not support LP relaxation (relax: true). Use a simplex/IPM solver such as HiGHS or GLPK.`)}for(let t of tr)if(e[t]!==void 0)throw Error(`PumpkinSolver does not support option "${t}".`);for(let[t,n]of Object.entries(e))if(n!==void 0&&!nr.has(t))throw Error(`PumpkinSolver does not support option "${t}".`);if(e.useWorker!==void 0&&typeof e.useWorker!=`boolean`)throw Error(`Invalid Pumpkin option "useWorker": expected boolean, got ${typeof e.useWorker}.`);if(e.onProgress!==void 0&&typeof e.onProgress!=`function`)throw Error(`Invalid Pumpkin option "onProgress": expected function, got ${typeof e.onProgress}.`)}function ir(e){if(e.wasmUrl!==void 0&&e.wasmUrl!==null&&typeof e.wasmUrl!=`string`)throw Error(`Invalid pumpkin.wasm URL: expected string or null, got ${typeof e.wasmUrl}.`);if(e.wasmUrl===``)throw Error(`Invalid pumpkin.wasm URL: expected non-empty string or null (received empty string "").`);return e.wasmUrl}var ar=class e{static capabilities={supportsMIP:!0,supportsQP:!1,supportsQCQP:!1,supportsSMT:!1,supportsLogicalConstraints:!0,supportsUnsatCore:!0,supportsWarmStart:!0};name=`pumpkin`;options;capabilities=e.capabilities;constructor(e={}){this.options=e}async check(e,t={}){let n={...this.options,...t};rr(n);let r=ir(n),i=Kn(n.timeLimit),a=Qn(e);if(n.signal?.aborted)return{status:`Unknown`,values:{},runTime:0};if(a.hasEmptyDomain)return{status:`Unsat`,values:{},unsatCore:[],conflicts:[],runTime:1e-6};let o=JSON.stringify({vars:a.vars,boolVars:a.boolVars,constraints:a.constraints,logicalConstraints:a.logicalConstraints,auxPropagators:a.auxPropagators,timeLimitMs:i}),s=n.useWorker??An(),c;if(s)c=await Vn().check({requestJson:o,wasmUrl:r},{signal:n.signal});else{let e=await Pn(r);if(n.signal?.aborted)return{status:`Unknown`,values:{},runTime:0};let t=performance.now(),i=e.check_with_callback(o,()=>!!n.signal?.aborted),a=Math.max((performance.now()-t)/1e3,1e-6);if(c=JSON.parse(i),c.runTime=a,c.error)throw Error(c.error)}let l=c.runTime??0;if(c.status===`Sat`)return{status:`Sat`,values:er(c.values,c.boolValues),runTime:l};if(c.status===`Unsat`){let e=c.unsatCore?[...c.unsatCore]:[];return{status:`Unsat`,values:{},unsatCore:e,conflicts:e,runTime:l}}return{status:`Unknown`,values:{},runTime:l}}async solve(e,t={}){let n={...this.options,...t};rr(n);let r=ir(n),a=Kn(n.timeLimit),o=i(e.sense),s=Qn(e);if(qn(e.objective))throw Error(`PumpkinSolver does not support quadratic objective expressions (QuadExpr). Use a QP solver such as HiGHS.`);let c=e.objective;if(typeof c.constant!=`number`||!Number.isFinite(c.constant))throw Error(`Invalid non-finite objective constant.`);let l=Z(c.constant),{terms:u,sumMaxAbs:d}=s.lowerer.lowerLinExpr(c,{kind:`objective`},`objective expression`,!0);if(d>Hn)throw Error(`Objective expression magnitude (${d}) exceeds Pumpkin safe 32-bit integer range [-${Hn}, ${Hn}].`);if(n.signal?.aborted)return{status:`Unknown`,terminationStatus:`Interrupted`,hasPrimalSolution:!1,objectiveValue:null,values:{},runTime:0};if(s.hasEmptyDomain)return{status:`Infeasible`,terminationStatus:`Infeasible`,hasPrimalSolution:!1,objectiveValue:null,values:{},runTime:1e-6};let f=JSON.stringify({vars:s.vars,boolVars:s.boolVars,constraints:s.constraints,logicalConstraints:s.logicalConstraints,auxPropagators:s.auxPropagators,sense:o,objectiveTerms:u,objectiveConstant:l,timeLimitMs:a}),p=n.useWorker??An(),m=n.onProgress,h=0,g=m?e=>{h++,m(e)}:void 0,_;if(p)_=await Vn().solve({requestJson:f,wasmUrl:r},{signal:n.signal,onProgress:g});else{let e=await Pn(r);if(n.signal?.aborted)return{status:`Unknown`,terminationStatus:`Interrupted`,hasPrimalSolution:!1,objectiveValue:null,values:{},runTime:0};let t=performance.now(),i=null,a=n.signal,o=g?e=>{try{let n=JSON.parse(e),r=Math.max((performance.now()-t)/1e3,1e-6);return g({elapsedTime:r,elapsedSeconds:r,objectiveValue:n.objectiveValue}),!!a?.aborted}catch(e){return i=e,!0}}:null,s=a?()=>!!a.aborted:null,c=e.solve_with_callback(f,o,s);if(i!==null)throw i;let l=Math.max((performance.now()-t)/1e3,1e-6);if(_=JSON.parse(c),_.runTime=l,_.error)throw Error(_.error)}let v=_.status===`Optimal`||_.status===`Feasible`,y=typeof _.objectiveValue==`number`?Z(_.objectiveValue):null,b=_.runTime??0;v&&h===0&&g&&g({elapsedTime:b,elapsedSeconds:b,...y===null?{}:{objectiveValue:y}});let x=v?$n(_.values,_.boolValues,!0):{values:{}};return{status:_.status,terminationStatus:_.terminationStatus,hasPrimalSolution:v,objectiveValue:y,values:x.values,...x.boolValues===void 0?{}:{boolValues:x.boolValues},runTime:b}}};function or(e){$e(`pumpkin`,t=>new ar(t??e))}or();function sr(e,t){if(e===void 0)return 1e-6;if(typeof e!=`number`||!Number.isFinite(e)||e<0)throw Error(`Invalid ${t}: expected a finite non-negative number, received ${String(e)}.`);return e}function cr(e,t={}){let n=sr(t.feasibilityTolerance,`feasibilityTolerance`),r=sr(t.integralityTolerance,`integralityTolerance`),i=t.evaluateLogicalConstraints===void 0||!!t.evaluateLogicalConstraints,a=t.values!==void 0&&t.values!==null;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.`);let o=t.values,s=[],u=Object.create(null),d=[],f=[],p=0,m=e=>{typeof e==`number`&&!Number.isNaN(e)&&e>p&&(p=e)},g=e=>{s.push(e),Object.prototype.hasOwnProperty.call(u,e.name)||(u[e.name]=[]),u[e.name].push(e),e.type!==`missing_value`&&e.type!==`unchecked_constraint`&&m(e.violation)},_=[],v=[];for(let t of e.variables.values())t.type===`Boolean`?v.push(t):_.push(t);let y=[],b=[];for(let t of e.constraints.values())t instanceof I?y.push(t):b.push(t);let x=new Map,S=new Map,C=0,T=0,E=0,D=0;for(let e of _){let t=a?Object.prototype.hasOwnProperty.call(o,e.name)?o[e.name]:void 0:e.value;if(t==null){f.push(e.name),g({type:`missing_value`,target:`variable`,name:e.name,actual:t??null,violation:1/0,message:`Variable "${e.name}" has no assigned solution value.`});continue}if(typeof t!=`number`||!Number.isFinite(t)){g({type:`non_finite_value`,target:`variable`,name:e.name,actual:t,violation:1/0,message:`Variable "${e.name}" has non-finite or non-numeric value: ${String(t)}.`});continue}x.set(e,t),C++;let i=e.type===`Binary`||e.type===`BINARY`,s=i||e.type===`Integer`||e.type===`INTEGER`,c=i?Math.max(0,e.lb):e.lb,l=i?Math.min(1,e.ub):e.ub,u=typeof e.lb==`number`&&!Number.isNaN(e.lb)&&e.lb!==1/0,d=typeof e.ub==`number`&&!Number.isNaN(e.ub)&&e.ub!==-1/0;if(!u)g({type:`lower_bound`,target:`variable`,name:e.name,actual:t,limit:e.lb,violation:1/0,message:`Variable "${e.name}" has invalid lower bound (${String(e.lb)}).`});else if(c!==-1/0){let r=t-c,i=Math.max(0,c-t);m(i),i>n&&g({type:`lower_bound`,target:`variable`,name:e.name,actual:t,limit:c,violation:i,signedViolation:r,message:`Variable "${e.name}" value (${t}) violates lower bound (${c}) by ${i}.`})}if(!d)g({type:`upper_bound`,target:`variable`,name:e.name,actual:t,limit:e.ub,violation:1/0,message:`Variable "${e.name}" has invalid upper bound (${String(e.ub)}).`});else if(l!==1/0){let r=t-l,i=Math.max(0,t-l);m(i),i>n&&g({type:`upper_bound`,target:`variable`,name:e.name,actual:t,limit:l,violation:i,signedViolation:r,message:`Variable "${e.name}" value (${t}) violates upper bound (${l}) by ${i}.`})}if(u&&d&&c>l&&c-t<=n&&t-l<=n){let n=c-l;g({type:`lower_bound`,target:`variable`,name:e.name,actual:t,limit:c,violation:n,signedViolation:t-c,message:`Variable "${e.name}" has inverted bounds [${c}, ${l}].`})}if(s){let n=Math.round(t),a=t-n,o=Math.abs(a);m(o),o>r&&g({type:`integrality`,target:`variable`,name:e.name,varType:i?`Binary`:`Integer`,actual:t,nearestInteger:n,violation:o,signedViolation:a,message:`${i?`Binary`:`Integer`} variable "${e.name}" value (${t}) violates integrality by ${o} (nearest integer: ${n}).`})}}for(let e of v){let t=a?Object.prototype.hasOwnProperty.call(o,e.name)?o[e.name]:void 0:e.value;if(t==null){f.push(e.name),g({type:`missing_value`,target:`bool_variable`,name:e.name,actual:t??null,violation:1/0,message:`Boolean variable "${e.name}" has no assigned solution value.`});continue}if(typeof t!=`boolean`){g({type:`invalid_boolean_value`,target:`bool_variable`,name:e.name,actual:t,violation:1/0,message:`Boolean variable "${e.name}" has non-boolean value: ${String(t)}.`});continue}S.set(e,t),T++}let ee=e=>{switch(e.kind){case`abs`:{let t=O(e.arg);return t.ok?{ok:!0,value:Math.abs(t.value),...t.atDomainError?{atDomainError:t.atDomainError}:{}}:t}case`max`:{let t=-1/0,n;for(let r of e.args){let e=O(r);if(!e.ok)return e;!n&&e.atDomainError&&(n=e.atDomainError),e.value>t&&(t=e.value)}return{ok:!0,value:t,...n?{atDomainError:n}:{}}}case`min`:{let t=1/0,n;for(let r of e.args){let e=O(r);if(!e.ok)return e;!n&&e.atDomainError&&(n=e.atDomainError),e.value<t&&(t=e.value)}return{ok:!0,value:t,...n?{atDomainError:n}:{}}}case`at`:{let t=O(e.index);if(!t.ok)return t;let i=t.value,a=e.array.length-1,o=Math.max(0,-i),s=Math.max(0,i-a),c=Math.max(o,s),l=Math.abs(i-Math.round(i));if(c>n||l>r)return{ok:!0,value:0,atDomainError:{violation:Math.max(c,l),message:`at() index (${i}) violates valid integer range [0, ${a}].`}};let u=O(e.array[Math.round(i)]);return u.ok?{ok:!0,value:u.value,...t.atDomainError??u.atDomainError?{atDomainError:t.atDomainError??u.atDomainError}:{}}:u}}},O=e=>{let t=e.constant===void 0?0:e.constant;if(typeof t!=`number`||!Number.isFinite(t))return{ok:!1,reason:`non-finite constant (${String(t)})`};let n=t;for(let[t,r]of e.terms){if(typeof r!=`number`||!Number.isFinite(r))return{ok:!1,reason:`non-finite coefficient (${String(r)}) for variable "${t.name}"`};if(r!==0){if(!x.has(t))return{ok:!1,reason:`missing or invalid value for variable "${t.name}"`};if(n+=r*x.get(t),!Number.isFinite(n))return{ok:!1,reason:`linear expression evaluation overflowed finite range`}}}let r;for(let t of e.nonlinearTerms??[]){if(typeof t.coeff!=`number`||!Number.isFinite(t.coeff))return{ok:!1,reason:`non-finite nonlinear coefficient (${String(t.coeff)})`};let e=ee(t.atom);if(!e.ok)return e;if(!r&&e.atDomainError&&(r=e.atDomainError),t.coeff!==0&&(n+=t.coeff*e.value,!Number.isFinite(n)))return{ok:!1,reason:`expression evaluation overflowed finite range`}}return{ok:!0,value:n,...r?{atDomainError:r}:{}}},k=e=>{switch(e.kind){case`abs`:return A(e.arg);case`max`:case`min`:{let t=[];for(let n of e.args){let e=A(n);if(!e.ok)return e;t.push(...e.errors)}return{ok:!0,errors:t}}case`at`:{let t=[],i=A(e.index);if(!i.ok)return i;t.push(...i.errors);for(let n of e.array){let e=A(n);if(!e.ok)return e;t.push(...e.errors)}let a=O(e.index);if(!a.ok)return a;if(i.errors.length===0){let i=a.value,o=e.array.length-1,s=Math.max(0,-i),c=Math.max(0,i-o),l=Math.max(s,c),u=Math.abs(i-Math.round(i));if(l>n||u>r){let e=Math.max(l,u);t.push({violation:e,message:`at() index (${i}) violates valid integer range [0, ${o}].`})}}return{ok:!0,errors:t}}}},A=e=>{let t=[];for(let n of e.nonlinearTerms??[]){let e=k(n.atom);if(!e.ok)return e;t.push(...e.errors)}return{ok:!0,errors:t}},te=e=>{if(e instanceof c)return{ok:!0};if(e instanceof I){let t=A(e.lhs);return t.ok?{ok:!0,...t.errors.length>0?{firstError:t.errors[0]}:{}}:t}if(e instanceof h){let t=e.spec,n=t.kind===`distinct`?t.args:t.kind===`disjoint`||t.kind===`cumulative`?t.tasks.map(e=>e.start):t.vars;for(let e of n){let t=A(e);if(!t.ok)return t;if(t.errors.length>0)return{ok:!0,firstError:t.errors[0]}}return{ok:!0}}if(e instanceof l){let t;for(let n of e.children){let e=te(n);if(!e.ok)return e;!t&&e.firstError&&(t=e.firstError)}return{ok:!0,...t?{firstError:t}:{}}}return{ok:!0}},ne=(e,t=n)=>{if(typeof e.rhs!=`number`||!Number.isFinite(e.rhs))return{status:`unchecked`,reason:`non-finite right-hand side (${String(e.rhs)})`};let r=A(e.lhs);if(!r.ok)return{status:`unchecked`,reason:r.reason};let i=O(e.lhs);if(!i.ok)return{status:`unchecked`,reason:i.reason};if(r.errors.length>0||i.atDomainError){let t=r.errors[0]??i.atDomainError;return{status:`violated`,lhsVal:i.value,signed:i.value-e.rhs,violation:t.violation,message:`Constraint "${e.name}" invalid element lookup: ${t.message}`}}let a=i.value,o=a-e.rhs;if(!Number.isFinite(o))return{status:`unchecked`,reason:`constraint residual overflowed finite range`};let s=e.sense===`<=`?Math.max(0,o):e.sense===`>=`?Math.max(0,-o):e.sense===`!=`?Math.max(0,1-Math.abs(o)):Math.abs(o);return s>t?{status:`violated`,lhsVal:a,signed:o,violation:s,message:`Constraint "${e.name}" (${a} ${e.sense} ${e.rhs}) violated by ${s}.`}:{status:`satisfied`,lhsVal:a,signed:o,violation:s}},re=e.objective();if((re instanceof w||re instanceof z)&&re.nonlinearTerms.length>0){let e=A(new z(new Map,0,re.nonlinearTerms));if(e.ok)for(let t of e.errors)g({type:`linear_constraint`,target:`constraint`,name:`objective_at`,violation:t.violation,message:`Objective at() lookup failed: ${t.message}`})}for(let e of y){let t=ne(e);t.status===`unchecked`?(d.push(e.name),g({type:`unchecked_constraint`,target:`constraint`,name:e.name,sense:e.sense,limit:e.rhs,rhs:e.rhs,violation:1/0,message:`Constraint "${e.name}" could not be evaluated: ${t.reason}.`})):t.status===`violated`?(E++,g({type:`linear_constraint`,target:`constraint`,name:e.name,sense:e.sense,actual:t.lhsVal,limit:e.rhs,rhs:e.rhs,violation:t.violation,signedViolation:t.signed,message:t.message})):(E++,m(t.violation))}let ie=e=>{if(e instanceof c)return S.has(e)?{ok:!0,value:S.get(e),violation:0}:{ok:!1,reason:`missing or invalid value for Boolean variable "${e.name}"`};if(e instanceof I){if(e.sense===`!=`){let t=O(e.lhs);if(!t.ok)return{ok:!1,reason:t.reason};if(t.atDomainError)return{ok:!1,reason:t.atDomainError.message};let r=Math.abs(t.value-e.rhs);return r<=n?{ok:!0,value:!1,violation:0}:r>=1-n?{ok:!0,value:!0,violation:0}:{ok:!1,reason:`discrete comparison "${e.name}" lies between 0 and 1 (${t.value} != ${e.rhs})`}}let t=ne(e,0);if(t.status===`unchecked`)return{ok:!1,reason:t.reason};if(n>0){let r=Math.abs(t.lhsVal-e.rhs);if(r>0&&r<=n)return{ok:!1,reason:`numeric comparison "${e.name}" lies within feasibilityTolerance (${n}) of boundary (${t.lhsVal} vs ${e.rhs})`}}return{ok:!0,value:t.status===`satisfied`,violation:0}}if(e instanceof h){let t=e.spec;if(t.kind===`distinct`){let e=[];for(let n of t.args){let t=O(n);if(!t.ok)return t;if(t.atDomainError)return{ok:!1,reason:t.atDomainError.message};e.push(t.value)}for(let t=0;t<e.length;t++)for(let r=t+1;r<e.length;r++){let i=Math.abs(e[t]-e[r]);if(i<=n)return{ok:!0,value:!1,violation:0};if(i<1-n)return{ok:!1,reason:`distinct() operands at indices (${t}, ${r}) have fractional gap (${i})`}}return{ok:!0,value:!0,violation:0}}if(t.kind===`disjoint`){let e=[];for(let n of t.tasks){let t=O(n.start);if(!t.ok)return t;if(t.atDomainError)return{ok:!1,reason:t.atDomainError.message};e.push(t.value)}for(let r=0;r<t.tasks.length;r++)for(let i=r+1;i<t.tasks.length;i++){let a=e[r],o=t.tasks[r].duration,s=e[i],c=t.tasks[i].duration;if(!(a+o<=s+n||s+c<=a+n))return{ok:!0,value:!1,violation:0}}return{ok:!0,value:!0,violation:0}}if(t.kind===`cumulative`){let e=[];for(let n of t.tasks){let t=O(n.start);if(!t.ok)return t;if(t.atDomainError)return{ok:!1,reason:t.atDomainError.message};e.push(t.value)}let r=[];for(let n=0;n<t.tasks.length;n++){let i=t.tasks[n];if(i.duration>0&&i.demand>0){if(i.demand>t.capacity)return{ok:!0,value:!1,violation:0};r.push({start:e[n],duration:i.duration,demand:i.demand})}}for(let e=0;e<r.length;e++){let i=r[e].start,a=0;for(let e=0;e<r.length;e++){let t=r[e];t.start-n<=i&&i<t.start+t.duration-n&&(a+=t.demand)}if(a>t.capacity+n)return{ok:!0,value:!1,violation:0}}return{ok:!0,value:!0,violation:0}}if(t.kind===`allowed`){let e=[];for(let n of t.vars){let t=O(n);if(!t.ok)return t;if(t.atDomainError)return{ok:!1,reason:t.atDomainError.message};e.push(t.value)}return{ok:!0,value:t.tuples.some(t=>t.every((t,r)=>Math.abs(e[r]-t)<=n)),violation:0}}}if(e instanceof l)switch(e.op){case`not`:{let t=ie(e.children[0]);return t.ok?{ok:!0,value:!t.value,violation:0}:t}case`and`:{let t=0;for(let n of e.children){let e=ie(n);if(!e.ok)return e;if(!e.value)return{ok:!0,value:!1,violation:0};e.violation>t&&(t=e.violation)}return{ok:!0,value:!0,violation:t}}case`or`:{let t=!1,n=1/0;for(let r of e.children){let e=ie(r);if(!e.ok)return e;e.value&&(t=!0,e.violation<n&&(n=e.violation))}return{ok:!0,value:t,violation:t?n:0}}case`implies`:{let t=ie(e.children[0]);if(!t.ok)return t;if(!t.value)return{ok:!0,value:!0,violation:0};let n=ie(e.children[1]);return n.ok?{ok:!0,value:n.value,violation:n.value?n.violation:0}:n}case`xor`:{let t=!1,n=0;for(let r of e.children){let e=ie(r);if(!e.ok)return e;e.value&&(t=!t,e.violation>n&&(n=e.violation))}return{ok:!0,value:t,violation:t?n:0}}default:return{ok:!1,reason:`unsupported logical operator "${String(e.op)}"`}}return{ok:!1,reason:`unsupported logical expression node`}};for(let e=0;e<b.length;e++){let t=b[e],n=t.name||`lc_${e+1}`;if(!i){d.push(n),g({type:`unchecked_constraint`,target:`logical_constraint`,name:n,violation:1/0,message:`Logical constraint "${n}" was not evaluated because evaluateLogicalConstraints is false.`});continue}let r=te(t.expr);if(!r.ok){d.push(n),g({type:`unchecked_constraint`,target:`logical_constraint`,name:n,violation:1/0,message:`Logical constraint "${n}" could not be evaluated: ${r.reason}.`});continue}if(r.firstError){D++,g({type:`logical_constraint`,target:`logical_constraint`,name:n,actual:!1,limit:!0,violation:r.firstError.violation,signedViolation:-1,message:`Logical constraint "${n}" invalid element lookup: ${r.firstError.message}`});continue}let a=ie(t.expr);if(!a.ok){d.push(n),g({type:`unchecked_constraint`,target:`logical_constraint`,name:n,violation:1/0,message:`Logical constraint "${n}" could not be evaluated: ${a.reason}.`});continue}D++,a.value?m(a.violation):g({type:`logical_constraint`,target:`logical_constraint`,name:n,actual:!1,limit:!0,violation:1,signedViolation:-1,message:`Logical constraint "${n}" evaluated to false.`})}let j=C===_.length&&T===v.length&&E===y.length&&D===b.length&&d.length===0&&f.length===0;return{valid:j&&s.length===0,complete:j,violations:s,violationsByName:u,uncheckedConstraints:d,missingVariables:f,maxViolation:p,summary:{checkedVariables:C,totalVariables:_.length,checkedBoolVariables:T,totalBoolVariables:v.length,checkedLinearConstraints:E,totalLinearConstraints:y.length,checkedLogicalConstraints:D,totalLogicalConstraints:b.length}}}function lr(e,t){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}.`)}function ur(e,t,n){let r=e.constant===void 0?0:e.constant;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}).`);let i=t-r;if(!Number.isFinite(i))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": effective right-hand side (${t} - ${r}) overflows finite floating-point range. Please rescale coefficients/constants.`);for(let[t,r]of e.terms){if(!Number.isFinite(r))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" has non-finite coefficient (${r}).`);if(Number.isNaN(t.lb)||Number.isNaN(t.ub)||t.lb===1/0||t.ub===-1/0||t.lb>t.ub)throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" has invalid bounds [${t.lb}, ${t.ub}].`)}return i}function dr(e,t,n){let r=ur(e,t,n),i=0;for(let[t,r]of e.terms){if(r===0)continue;let e;if(r>0){if(!Number.isFinite(t.ub))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" lacks a finite upper bound (required because coefficient ${r} is positive in <= constraint). Please set an explicit finite upper bound on the variable or specify { M } explicitly in indicator options.`);e=t.ub}else{if(!Number.isFinite(t.lb))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" lacks a finite lower bound (required because coefficient ${r} is negative in <= constraint). Please set an explicit finite lower bound on the variable or specify { M } explicitly in indicator options.`);e=t.lb}let a=r*e;if(i+=a,!Number.isFinite(a)||!Number.isFinite(i))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": numeric overflow while bounding contribution of variable "${t.name}". Please rescale coefficients/bounds or specify a finite { M } explicitly.`)}let a=i-r;if(!Number.isFinite(a))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": numeric overflow while computing Big-M (${i} - ${r}). Please rescale coefficients/bounds or specify a finite { M } explicitly.`);let o=Math.max(0,a);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.`);return o}function fr(e,t,n){let r=ur(e,t,n),i=0;for(let[t,r]of e.terms){if(r===0)continue;let e;if(r>0){if(!Number.isFinite(t.lb))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" lacks a finite lower bound (required because coefficient ${r} is positive in >= constraint). Please set an explicit finite lower bound on the variable or specify { M } explicitly in indicator options.`);e=t.lb}else{if(!Number.isFinite(t.ub))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" lacks a finite upper bound (required because coefficient ${r} is negative in >= constraint). Please set an explicit finite upper bound on the variable or specify { M } explicitly in indicator options.`);e=t.ub}let a=r*e;if(i+=a,!Number.isFinite(a)||!Number.isFinite(i))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": numeric overflow while bounding contribution of variable "${t.name}". Please rescale coefficients/bounds or specify a finite { M } explicitly.`)}let a=r-i;if(!Number.isFinite(a))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": numeric overflow while computing Big-M (${r} - ${i}). Please rescale coefficients/bounds or specify a finite { M } explicitly.`);let o=Math.max(0,a);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.`);return o}function pr(e,t,n,r,i,a,o){if(!(e instanceof H&&(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}].`);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.`);let s=ur(t,r,o);if(i!==0&&i!==1)throw Error(`Invalid activeValue: ${i}. Indicator activation value must be 0 or 1.`);if(n!==`<=`&&n!==`>=`)throw Error(`Invalid indicator sense for "${o}": expected "<=" or ">=", received "${String(n)}".`);if(!Number.isFinite(a)||a<0)throw Error(`Invalid Big-M value for indicator constraint "${o}": expected a finite non-negative number, received ${a}.`);let c=t.terms.get(e);if(c!==void 0&&c!==0)throw Error(`Indicator constraint "${o}" cannot include its own binary activation variable "${e.name}" in the linear expression.`);let l,u;if(i===1?n===`<=`?(l=a,u=s+a):(l=-a,u=s-a):n===`<=`?(l=-a,u=s):(l=a,u=s),!Number.isFinite(u))throw Error(`Cannot construct finite indicator constraint "${o}": shifted right-hand side overflows finite floating-point range. Please rescale coefficients/bounds or specify a smaller finite { M }.`);let d=new Map;for(let[e,n]of t.terms)n!==0&&d.set(e,n);return l!==0&&d.set(e,l),{lhs:new z(d,0),rhs:u}}function $(e,t=0){let n=new Map;for(let[t,r]of e){if(r===0)continue;let e=(n.get(t)??0)+r;e===0?n.delete(t):n.set(t,e)}return new z(n,t)}function mr(e,t,n=1){if(n!==0){e.constant+=t.constant*n;for(let[r,i]of t.terms.entries())i!==0&&e.addTerm(r,i*n)}}var hr=5e3,gr=25e3;function _r(e,t,n,r,a){let o=[...e],s=[],u=new Map,d=new Map,f=new Set,p=[];for(let e of n)if(e.sense===`!=`||e.lhs.hasNonlinearTerms())p.push(e);else{let t=e;if(f.has(t.name)){let n=1;for(;f.has(`${e.name}_${n}`);)n++;t=new I(e.lhs,e.sense,e.rhs,`${e.name}_${n}`)}f.add(t.name),s.push(t),d.set(t,e.name)}let m=new Set(e.map(e=>e.name)),g=0;function _(e){let t;do t=`__washi_${e}_${++g}`;while(m.has(t));return m.add(t),t}function v(e,t){let n=e.name||`c`,r=n;if(f.has(r)){let t=1;for(;f.has(`${n}_${t}`);)t++;r=`${n}_${t}`,e=new I(e.lhs,e.sense,e.rhs,r)}f.add(r),s.push(e),d.set(e,t)}for(let e of t){let t=e.name;m.has(t)?t=_(`bool_${e.name}`):m.add(t);let n=new H({name:t,type:`Binary`,lb:0,ub:1});u.set(e,n),o.push(n)}function y(e,t){if(!Number.isFinite(e.constant))throw Error(`Cannot linearize piecewise expression in "${t}": non-finite constant (${e.constant}).`);let n=e.constant,r=e.constant,i=Number.isSafeInteger(e.constant);for(let[a,o]of e.terms.entries()){if(!Number.isFinite(o))throw Error(`Cannot linearize piecewise expression in "${t}": variable "${a.name}" has non-finite coefficient (${o}).`);if(o===0)continue;if(typeof a.lb!=`number`||typeof a.ub!=`number`||Number.isNaN(a.lb)||Number.isNaN(a.ub)||a.lb===-1/0||a.ub===1/0||a.lb>a.ub)throw Error(`Cannot linearize non-convex piecewise expression in "${t}": variable "${a.name}" has unbounded or invalid domain [${a.lb}, ${a.ub}]. Finite bounds are required.`);let e=a.lb,s=a.ub;if(a.type===`Binary`){let t=Math.max(0,Math.ceil(a.lb)),n=Math.min(1,Math.floor(a.ub));t<=n&&(e=t,s=n)}else if(a.type===`Integer`){let t=Math.ceil(a.lb),n=Math.floor(a.ub);t<=n&&(e=t,s=n)}let c=o*e,l=o*s;if(n+=Math.min(c,l),r+=Math.max(c,l),!Number.isFinite(n)||!Number.isFinite(r))throw Error(`Cannot linearize non-convex piecewise expression in "${t}": bound calculation overflowed.`);i&&=(a.type===`Integer`||a.type===`Binary`)&&Number.isSafeInteger(o)&&Number.isSafeInteger(e)&&Number.isSafeInteger(s)}return{lb:Object.is(n,-0)?0:n,ub:Object.is(r,-0)?0:r,isDiscrete:i}}function b(e,t){if(!e.hasNonlinearTerms())return e.clone();let n=new z(e.terms,e.constant);for(let r of e.nonlinearTerms)r.coeff!==0&&mr(n,x(r.atom,t),r.coeff);return n}function x(e,t){switch(e.kind){case`abs`:{let n=b(e.arg,t),{lb:r,ub:i,isDiscrete:a}=y(n,t);if(r>=0)return n;if(i<=0)return n.mul(-1);let s=Math.max(-r,i),c=new H({name:_(`abs_t`),type:a?`Integer`:`Continuous`,lb:0,ub:s}),l=new H({name:_(`abs_z`),type:`Binary`,lb:0,ub:1});o.push(c,l);let u=$([[c,1]],0);return P(new I(n.sub(u),`<=`,0,`${t}_abs_pos`),t),P(new I(n.mul(-1).sub(u),`<=`,0,`${t}_abs_neg`),t),P(new I(u.sub(n).add($([[l,2*-r]],0)),`<=`,2*-r,`${t}_abs_hi_pos`),t),P(new I(u.add(n).sub($([[l,2*i]],0)),`<=`,0,`${t}_abs_hi_neg`),t),u}case`max`:{let n=e.args.map(e=>b(e,t));if(n.length===1)return n[0];let r=n.map(e=>y(e,t)),i=Math.max(...r.map(e=>e.lb)),a=Math.max(...r.map(e=>e.ub)),s=r.every(e=>e.isDiscrete),c=new H({name:_(`max_t`),type:s?`Integer`:`Continuous`,lb:i,ub:a});o.push(c);let l=$([[c,1]],0),u=[];for(let e=0;e<n.length;e++){let i=new H({name:_(`max_z_${e}`),type:`Binary`,lb:0,ub:1});o.push(i),u.push(i),P(new I(n[e].sub(l),`<=`,0,`${t}_max_lb_${e}`),t);let s=a-r[e].lb;P(new I(l.sub(n[e]).add($([[i,s]],0)),`<=`,s,`${t}_max_ub_${e}`),t)}return v(new I($(u.map(e=>[e,1]),0),`==`,1,`${t}_max_sos`),t),l}case`min`:{let n=e.args.map(e=>b(e,t));if(n.length===1)return n[0];let r=n.map(e=>y(e,t)),i=Math.min(...r.map(e=>e.lb)),a=Math.min(...r.map(e=>e.ub)),s=r.every(e=>e.isDiscrete),c=new H({name:_(`min_t`),type:s?`Integer`:`Continuous`,lb:i,ub:a});o.push(c);let l=$([[c,1]],0),u=[];for(let e=0;e<n.length;e++){let a=new H({name:_(`min_z_${e}`),type:`Binary`,lb:0,ub:1});o.push(a),u.push(a),P(new I(n[e].sub(l),`>=`,0,`${t}_min_ub_${e}`),t);let s=r[e].ub-i;P(new I(n[e].sub(l).add($([[a,s]],0)),`<=`,s,`${t}_min_lb_${e}`),t)}return v(new I($(u.map(e=>[e,1]),0),`==`,1,`${t}_min_sos`),t),l}case`at`:{let n=e.array.length,r=b(e.index,t),i=e.array.map(e=>b(e,t)),a=[];for(let e=0;e<n;e++){let t=new H({name:_(`at_lam_${e}`),type:`Binary`,lb:0,ub:1});o.push(t),a.push(t)}v(new I($(a.map(e=>[e,1]),0),`==`,1,`${t}_at_sos`),t);let s=r.clone();for(let e=1;e<n;e++)s.addTerm(a[e],-e);P(new I(s,`==`,0,`${t}_at_idx`),t);let c=new z(new Map,0);for(let e=0;e<n;e++){let n=i[e];if(n.terms.size===0)n.constant!==0&&c.addTerm(a[e],n.constant);else{let{lb:r,ub:i,isDiscrete:s}=y(n,t),l=new H({name:_(`at_w_${e}`),type:s?`Integer`:`Continuous`,lb:Math.min(0,r),ub:Math.max(0,i)});o.push(l);let u=$([[l,1]],0);P(new I($([[l,1],[a[e],-r]],0),`>=`,0,`${t}_at_mc1_${e}`),t),P(new I($([[l,1],[a[e],-i]],0),`<=`,0,`${t}_at_mc2_${e}`),t),P(new I(u.sub(n).add($([[a[e],-i]],0)),`>=`,-i,`${t}_at_mc3_${e}`),t),P(new I(u.sub(n).add($([[a[e],-r]],0)),`<=`,-r,`${t}_at_mc4_${e}`),t),c.addTerm(l,1)}}return c}}}function S(e,t,n){if(t===`upper`&&e.kind===`max`){let t=new H({name:_(`epi_max`),type:`Continuous`,lb:-1/0,ub:1/0});o.push(t);let r=$([[t,1]],0);for(let t=0;t<e.args.length;t++)T(e.args[t].sub(r),`<=`,0,`${n}_epi_max_${t}`,n);return r}if(t===`upper`&&e.kind===`abs`){let t=e.arg.hasNonlinearTerms()?b(e.arg,n):e.arg,r=new H({name:_(`epi_abs`),type:`Continuous`,lb:0,ub:1/0});o.push(r);let i=$([[r,1]],0);return P(new I(t.sub(i),`<=`,0,`${n}_epi_abs_pos`),n),P(new I(t.mul(-1).sub(i),`<=`,0,`${n}_epi_abs_neg`),n),i}if(t===`lower`&&e.kind===`min`){let t=new H({name:_(`epi_min`),type:`Continuous`,lb:-1/0,ub:1/0});o.push(t);let r=$([[t,1]],0);for(let t=0;t<e.args.length;t++)T(e.args[t].sub(r),`>=`,0,`${n}_epi_min_${t}`,n);return r}return x(e,n)}function C(e,t,n){if(!e.hasNonlinearTerms())return e;if(t===`==`||t===`!=`)return b(e,n);let r=new z(e.terms,e.constant);for(let i of e.nonlinearTerms){if(i.coeff===0)continue;let e=t===`<=`?i.coeff>0?`upper`:`lower`:i.coeff>0?`lower`:`upper`;mr(r,S(i.atom,e,n),i.coeff)}return r}function T(e,t,n,r,i){let a=C(e,t,i);if(t===`!=`){ce(new I(a,`==`,n,r),i);return}P(new I(a,t,n,r),i)}function E(e,t){return e.lhs.hasNonlinearTerms()?new I(b(e.lhs,t),e.sense,e.rhs,e.name):e}function D(e,t){if(e instanceof c){let n=u.get(e);if(!n)throw Error(`Unregistered BoolVar "${e.name}" in logical constraint "${t}".`);return n}let n=new H({name:_(`expr`),type:`Binary`,lb:0,ub:1});return o.push(n),O(n,e,t),n}function ee(e,t,n,r){v(new I($([[e,1],[t,-1],[n,-1]],0),`<=`,0,`${r}_xor_1`),r),v(new I($([[e,1],[t,-1],[n,1]],0),`>=`,0,`${r}_xor_2`),r),v(new I($([[e,1],[n,-1],[t,1]],0),`>=`,0,`${r}_xor_3`),r),v(new I($([[e,1],[t,1],[n,1]],0),`<=`,2,`${r}_xor_4`),r)}function O(e,t,n){if(t instanceof c){let r=u.get(t);v(new I($([[e,1],[r,-1]],0),`==`,0,`${n}_equiv`),n);return}if(t instanceof I){let r=E(t,n);le(e,r,0,`${n}_c_neg`,n),se(e,r,1,`${n}_c_pos`,n);return}if(t instanceof h){ne(e,t,n);return}if(t instanceof l){if(t.op===`not`){let r=D(t.children[0],n);v(new I($([[e,1],[r,1]],0),`==`,1,`${n}_not`),n);return}if(t.op===`and`){let r=t.children.map(e=>D(e,n));for(let t=0;t<r.length;t++)v(new I($([[e,1],[r[t],-1]],0),`<=`,0,`${n}_and_ub_${t}`),n);v(new I($([[e,1],...r.map(e=>[e,-1])],0),`>=`,1-r.length,`${n}_and_lb`),n);return}if(t.op===`or`){let r=t.children.map(e=>D(e,n));for(let t=0;t<r.length;t++)v(new I($([[e,1],[r[t],-1]],0),`>=`,0,`${n}_or_lb_${t}`),n);v(new I($([[e,1],...r.map(e=>[e,-1])],0),`<=`,0,`${n}_or_ub`),n);return}if(t.op===`implies`){let r=D(t.children[0],n),i=D(t.children[1],n);v(new I($([[e,1],[r,1]],0),`>=`,1,`${n}_imp_1`),n),v(new I($([[e,1],[i,-1]],0),`>=`,0,`${n}_imp_2`),n),v(new I($([[e,1],[r,1],[i,-1]],0),`<=`,1,`${n}_imp_3`),n);return}if(t.op===`xor`){if(t.children.length===0){v(new I($([[e,1]],0),`==`,0,`${n}_xor_empty`),n);return}if(t.children.length===1){let r=D(t.children[0],n);v(new I($([[e,1],[r,-1]],0),`==`,0,`${n}_xor_single`),n);return}let r=t.children.map(e=>D(e,n)),i=r[0];for(let e=1;e<r.length-1;e++){let t=new H({name:_(`xor_fold_${e}`),type:`Binary`,lb:0,ub:1});o.push(t),ee(t,i,r[e],`${n}_xor_fold_${e}`),i=t}ee(e,i,r[r.length-1],n);return}}throw Error(`Unsupported logical element in equivalence linearization: ${t}`)}function k(e,t){let n=e.map(e=>b(e.start,t)),r=[];for(let t=0;t<e.length;t++)for(let i=t+1;i<e.length;i++)(e[t].duration>0||e[i].duration>0)&&r.push({i:t,j:i,sI:n[t],dI:e[t].duration,sJ:n[i],dJ:e[i].duration});return r}function A(e,t,n){let r=e.map(e=>({start:b(e.start,n),duration:e.duration,demand:e.demand})).filter(e=>e.duration>0&&e.demand>0);if(r.length===0)return{kind:`constant`,value:!0};let i=[];for(let e of r){let t=e.start.constant??0;if(!Number.isSafeInteger(t))throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: task start offset (${t}) must be a safe integer.`);let r=t,a=t;for(let[t,i]of e.start.terms.entries()){if(i===0)continue;if(typeof t.lb!=`number`||typeof t.ub!=`number`||Number.isNaN(t.lb)||Number.isNaN(t.ub)||t.lb===-1/0||t.ub===1/0||t.lb>t.ub)throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: variable "${t.name}" has unbounded or invalid domain [${t.lb}, ${t.ub}]. Finite bounds are required.`);if(!Number.isSafeInteger(i))throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: variable "${t.name}" coefficient (${i}) exceeds safe integer precision.`);let e=t.type===`Binary`?Math.max(0,Math.ceil(t.lb)):Math.ceil(t.lb),o=t.type===`Binary`?Math.min(1,Math.floor(t.ub)):Math.floor(t.ub);if(e>o)return{kind:`empty_domain`};if(!Number.isSafeInteger(e)||!Number.isSafeInteger(o))throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: variable "${t.name}" integer bounds [${e}, ${o}] exceed JavaScript safe integer precision.`);let s=i*e,c=i*o;if(r+=Math.min(s,c),a+=Math.max(s,c),!Number.isSafeInteger(s)||!Number.isSafeInteger(c)||!Number.isSafeInteger(r)||!Number.isSafeInteger(a))throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: task start time bounds exceed JavaScript safe integer precision.`)}let o=r+e.duration,s=a+e.duration;if(!Number.isSafeInteger(o)||!Number.isSafeInteger(s))throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: task end time bounds [${r}, ${s}) exceed JavaScript safe integer precision.`);i.push({...e,est:Object.is(r,-0)?0:r,lst:Object.is(a,-0)?0:a})}return i.some(e=>e.demand>t)?{kind:`constant`,value:!1}:{kind:`tasks`,active:i}}function te(e,t,n){let r=e.spec;switch(r.kind){case`distinct`:{let e=r.args.map(e=>b(e,n));if(e.length<=1){t||N(n);return}if(t)for(let t=0;t<e.length;t++)for(let r=t+1;r<e.length;r++)T(e[t].sub(e[r]),`!=`,0,`${n}_neq_${t}_${r}`,n);else{let t=[];for(let r=0;r<e.length;r++)for(let i=r+1;i<e.length;i++)t.push(new I(e[r].sub(e[i]),`==`,0,`${n}_eq_${r}_${i}`));M(new l(`or`,t),n)}return}case`disjoint`:{let e=k(r.tasks,n);if(e.length===0){t||N(n);return}if(t)for(let{i:t,j:r,sI:i,dI:a,sJ:s,dJ:c}of e){let e=new H({name:_(`disj_${t}_${r}`),type:`Binary`,lb:0,ub:1});o.push(e),ae(e,i.sub(s),`<=`,-a,1,`${n}_p_${t}_${r}`,n),ae(e,s.sub(i),`<=`,-c,0,`${n}_q_${t}_${r}`,n)}else M(new l(`or`,e.map(({i:e,j:t,sI:r,dI:i,sJ:a,dJ:o})=>new l(`and`,[new I(r.sub(a),`>=`,1-i,`${n}_ov1_${e}_${t}`),new I(a.sub(r),`>=`,1-o,`${n}_ov2_${e}_${t}`)]))),n);return}case`cumulative`:{let e=A(r.tasks,r.capacity,n);if(e.kind===`empty_domain`){N(n);return}if(e.kind===`constant`){e.value!==t&&N(n);return}let{active:i}=e;if(t){let e=1/0,t=-1/0,a=0;for(let n of i)n.est<e&&(e=n.est),n.lst+n.duration>t&&(t=n.lst+n.duration),a+=Math.max(0,n.lst-n.est+1);let s=t-e;if(!Number.isSafeInteger(s)||s>hr||a>gr)throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: time horizon [${e}, ${t}) (span ${s}, ${a} time-indexed variables) exceeds MIP limit. Tighten start bounds or use { solver: "pumpkin" }.`);let c=[];for(let e=0;e<i.length;e++){let t=i[e],r=new Map,a=[],s=t.start.clone();for(let n=t.est;n<=t.lst;n++){let t=new H({name:_(`cum_u_${e}_${n}`),type:`Binary`,lb:0,ub:1});o.push(t),r.set(n,t),a.push([t,1]),n!==0&&s.addTerm(t,-n)}if(a.length===0){N(n);return}v(new I($(a,0),`==`,1,`${n}_cum_sos_${e}`),n),P(new I(s,`==`,0,`${n}_cum_start_${e}`),n),c.push(r)}for(let a=e;a<t;a++){let e=[],t=0;for(let n=0;n<i.length;n++){let r=i[n],o=a<=r.est+r.duration-1?r.est:a-r.duration+1,s=Math.min(r.lst,a);if(o<=s){t+=r.demand;let i=c[n];for(let t=o;t<=s;t++){let n=i.get(t);n&&e.push([n,r.demand])}}}t>r.capacity&&e.length>0&&v(new I($(e,0),`<=`,r.capacity,`${n}_cum_t_${a}`),n)}return}let a=[];for(let e=0;e<i.length;e++){let t=i[e],s=[];for(let r=0;r<i.length;r++){if(r===e)continue;let a=i[r],c=new H({name:_(`cum_act_${r}_${e}`),type:`Binary`,lb:0,ub:1});o.push(c),O(c,new l(`and`,[new I(a.start.sub(t.start),`<=`,0,`${n}_act_le_${r}_${e}`),new I(t.start.sub(a.start),`<=`,a.duration-1,`${n}_act_ge_${r}_${e}`)]),n),s.push([c,a.demand])}let c=new I($(s,0),`>=`,r.capacity-t.demand+1,`${n}_overload_${e}`);a.push(new l(`and`,[c]))}M(new l(`or`,a),n);return}case`allowed`:{let e=r.vars.map(e=>b(e,n));if(r.tuples.length===0){t&&N(n);return}if(t){let t=[];for(let e=0;e<r.tuples.length;e++){let n=new H({name:_(`tbl_r_${e}`),type:`Binary`,lb:0,ub:1});o.push(n),t.push(n)}v(new I($(t.map(e=>[e,1]),0),`==`,1,`${n}_tbl_sos`),n);for(let i=0;i<e.length;i++){let a=e[i].clone();for(let e=0;e<r.tuples.length;e++){let n=r.tuples[e][i];n!==0&&a.addTerm(t[e],-n)}P(new I(a,`==`,0,`${n}_tbl_col_${i}`),n)}return}let i=e.map(e=>{let t=Array.from(e.terms.entries()).filter(([,e])=>e!==0);if(t.length!==1)return null;let[n,r]=t[0];if(Math.abs(r)!==1||!Number.isSafeInteger(n.lb)||!Number.isSafeInteger(n.ub)||n.ub-n.lb!==1)return null;let i=e.constant;if(!Number.isSafeInteger(i))return null;let a=r*n.lb+i,o=r*n.ub+i;return{expr:e,lo:Math.min(a,o),hi:Math.max(a,o)}});for(let t=0;t<r.tuples.length;t++){let a=r.tuples[t],o=!0,s=!1;for(let e=0;e<a.length;e++){let t=i[e];if(!t){o=!1;break}if(a[e]!==t.lo&&a[e]!==t.hi){s=!0;break}}if(!s){if(o){let e=new z(new Map,0);for(let t=0;t<a.length;t++){let n=i[t];a[t]===n.lo?mr(e,n.expr.sub(n.lo),1):mr(e,$([],n.hi).sub(n.expr),1)}P(new I(e,`>=`,1,`${n}_nogood_${t}`),n)}else M(new l(`or`,a.map((r,i)=>new I(e[i],`!=`,r,`${n}_ntbl_${t}_${i}`))),n,`${n}_ntbl_${t}`)}}return}}}function ne(e,t,n){let r=t.spec;switch(r.kind){case`distinct`:{let t=r.args.map(e=>b(e,n));if(t.length<=1){v(new I($([[e,1]],0),`==`,1,`${n}_distinct_triv`),n);return}let i=[];for(let e=0;e<t.length;e++)for(let r=e+1;r<t.length;r++)i.push(new I(t[e].sub(t[r]),`!=`,0,`${n}_d_${e}_${r}`));O(e,new l(`and`,i),n);return}case`disjoint`:{let t=k(r.tasks,n);if(t.length===0){v(new I($([[e,1]],0),`==`,1,`${n}_disjoint_triv`),n);return}O(e,new l(`and`,t.map(({i:e,j:t,sI:r,dI:i,sJ:a,dJ:o})=>new l(`or`,[new I(r.sub(a),`<=`,-i,`${n}_dj1_${e}_${t}`),new I(a.sub(r),`<=`,-o,`${n}_dj2_${e}_${t}`)]))),n);return}case`cumulative`:{let t=A(r.tasks,r.capacity,n);if(t.kind===`empty_domain`){N(n);return}if(t.kind===`constant`){v(new I($([[e,1]],0),`==`,+!!t.value,`${n}_cum_triv`),n);return}let{active:i}=t,a=[];for(let e=0;e<i.length;e++){let t=i[e],s=[];for(let r=0;r<i.length;r++){if(r===e)continue;let a=i[r],c=new H({name:_(`cum_eq_act_${r}_${e}`),type:`Binary`,lb:0,ub:1});o.push(c),O(c,new l(`and`,[new I(a.start.sub(t.start),`<=`,0,`${n}_eq_le_${r}_${e}`),new I(t.start.sub(a.start),`<=`,a.duration-1,`${n}_eq_ge_${r}_${e}`)]),n),s.push([c,a.demand])}a.push(new I($(s,0),`<=`,r.capacity-t.demand,`${n}_ev_${e}`))}O(e,new l(`and`,a),n);return}case`allowed`:{let t=r.vars.map(e=>b(e,n));if(r.tuples.length===0){v(new I($([[e,1]],0),`==`,0,`${n}_allowed_empty`),n);return}O(e,new l(`or`,r.tuples.map((e,r)=>new l(`and`,e.map((e,i)=>new I(t[i],`==`,e,`${n}_eq_tbl_${r}_${i}`))))),n);return}}}function re(e){return e instanceof I||e instanceof l&&e.children.some(e=>re(e))}function ie(e,t){if(e instanceof I){if((e.lhs.terms.get(t)??0)!==0)return!0;for(let n of e.lhs.nonlinearTerms){if(n.coeff===0)continue;let e=n.atom;if(e.kind===`abs`&&(e.arg.terms.get(t)??0)!==0||(e.kind===`max`||e.kind===`min`)&&e.args.some(e=>(e.terms.get(t)??0)!==0)||e.kind===`at`&&((e.index.terms.get(t)??0)!==0||e.array.some(e=>(e.terms.get(t)??0)!==0)))return!0}return!1}return e instanceof l&&e.children.some(e=>ie(e,t))}function j(e,t,n,r){if(t instanceof I){se(e,E(t,n),1,r,n);return}if(t instanceof c||t instanceof h){v(new I($([[D(t,n),1],[e,-1]],0),`>=`,0,r),n);return}if(t instanceof l){if(t.op===`and`){for(let i=0;i<t.children.length;i++)j(e,t.children[i],n,`${r}_and_${i}`);return}if(t.op===`not`){let i=t.children[0];if(i instanceof I){le(e,E(i,n),1,r,n);return}if(i instanceof l){if(i.op===`not`){j(e,i.children[0],n,r);return}if(i.op===`or`){for(let t=0;t<i.children.length;t++)j(e,new l(`not`,[i.children[t]]),n,`${r}_not_or_${t}`);return}if(i.op===`and`){j(e,new l(`or`,i.children.map(e=>new l(`not`,[e]))),n,r);return}if(i.op===`implies`){j(e,i.children[0],n,`${r}_not_imp_0`),j(e,new l(`not`,[i.children[1]]),n,`${r}_not_imp_1`);return}}let a=D(i,n);v(new I($([[e,1],[a,1]],0),`<=`,1,r),n);return}if(t.op===`or`){if(t.children.length===0){v(new I($([[e,1]],0),`<=`,0,r),n);return}if(t.children.length===1){j(e,t.children[0],n,r);return}if(!t.children.some(e=>re(e))){let i=t.children.map(e=>D(e,n));v(new I($([[e,-1],...i.map(e=>[e,1])],0),`>=`,0,r),n);return}let i=[];for(let e=0;e<t.children.length;e++){let a=t.children[e];if(a instanceof c)i.push(D(a,n));else{let t=new H({name:_(`imp_or_${e}`),type:`Binary`,lb:0,ub:1});o.push(t),i.push(t),j(t,a,n,`${r}_or_${e}`)}}v(new I($([[e,-1],...i.map(e=>[e,1])],0),`>=`,0,r),n);return}if(t.op===`implies`){let[i,a]=t.children,s;if(i instanceof I){let e=E(i,n);s=new H({name:_(`ante`),type:`Binary`,lb:0,ub:1}),o.push(s),le(s,e,0,`${r}_ante_neg`,n)}else s=D(i,n);if(a instanceof c){v(new I($([[D(a,n),1],[e,-1],[s,-1]],0),`>=`,-1,r),n);return}let l=new H({name:_(`imp_joint`),type:`Binary`,lb:0,ub:1});o.push(l),v(new I($([[l,1],[e,-1],[s,-1]],0),`>=`,-1,`${r}_joint`),n),j(l,a,n,r);return}v(new I($([[D(t,n),1],[e,-1]],0),`>=`,0,r),n);return}throw Error(`Unsupported logical element in implication consequent "${n}": ${t}`)}function M(e,t,n=t){if(e instanceof I){T(e.lhs,e.sense,e.rhs,n,t);return}if(e instanceof h){te(e,!0,t);return}if(e instanceof c){v(new I($([[D(e,t),1]],0),`>=`,1,n),t);return}if(e instanceof l){if(e.op===`not`){let r=e.children[0];if(r instanceof c){v(new I($([[D(r,t),1]],0),`<=`,0,n),t);return}if(r instanceof h){te(r,!1,t);return}if(r instanceof I){ce(E(r,t),t);return}if(r instanceof l){if(r.op===`not`){M(r.children[0],t,n);return}if(r.op===`or`){for(let e=0;e<r.children.length;e++)M(new l(`not`,[r.children[e]]),t,`${n}_not_or_${e}`);return}if(r.op===`and`){M(new l(`or`,r.children.map(e=>new l(`not`,[e]))),t,n);return}if(r.op===`implies`){M(r.children[0],t,`${n}_not_imp_0`),M(new l(`not`,[r.children[1]]),t,`${n}_not_imp_1`);return}}v(new I($([[D(r,t),1]],0),`<=`,0,n),t);return}if(e.op===`and`){for(let r=0;r<e.children.length;r++)M(e.children[r],t,`${n}_and_${r}`);return}if(e.op===`or`){if(e.children.length===0){N(t);return}if(e.children.length===1){M(e.children[0],t,n);return}if(!e.children.some(e=>re(e))){v(new I($(e.children.map(e=>D(e,t)).map(e=>[e,1]),0),`>=`,1,n),t);return}let r=[];for(let i=0;i<e.children.length;i++){let a=e.children[i];if(a instanceof c)r.push(D(a,t));else{let e=new H({name:_(`or_branch_${i}`),type:`Binary`,lb:0,ub:1});o.push(e),r.push(e),j(e,a,t,`${n}_or_${i}`)}}v(new I($(r.map(e=>[e,1]),0),`>=`,1,n),t);return}if(e.op===`xor`){if(e.children.length===0){N(t);return}if(e.children.length===1){M(e.children[0],t,n);return}let r=e.children.map(e=>D(e,t));if(r.length===2){v(new I($([[r[0],1],[r[1],1]],0),`==`,1,n),t);return}let i=r[0];for(let e=1;e<r.length-1;e++){let t=new H({name:_(`xor_fold_${e}`),type:`Binary`,lb:0,ub:1});o.push(t),ee(t,i,r[e],`${n}_xor_fold_${e}`),i=t}let a=r[r.length-1];v(new I($([[i,1],[a,1]],0),`==`,1,n),t);return}if(e.op===`implies`){let[r,i]=e.children,a=r instanceof I?vr(r):null;if(a!==null){if(i instanceof I){let e=E(i,t);if((e.lhs.terms.get(a.binVar)??0)===0){se(a.binVar,e,a.activeVal,n,t);return}}if(i instanceof c){let e=D(i,t);v(a.activeVal===1?new I($([[e,1],[a.binVar,-1]],0),`>=`,0,n):new I($([[e,1],[a.binVar,1]],0),`>=`,1,n),t);return}if(i instanceof l&&i.op===`not`){let e=i.children[0];if(e instanceof c){let r=D(e,t);v(a.activeVal===1?new I($([[r,1],[a.binVar,1]],0),`<=`,1,n):new I($([[r,1],[a.binVar,-1]],0),`<=`,0,n),t);return}if(e instanceof I){let r=E(e,t);if((r.lhs.terms.get(a.binVar)??0)===0){le(a.binVar,r,a.activeVal,n,t);return}}}if(a.activeVal===1&&!ie(i,a.binVar)){j(a.binVar,i,t,n);return}}let s;if(r instanceof I){let e=E(r,t);s=new H({name:_(`ante`),type:`Binary`,lb:0,ub:1}),o.push(s),le(s,e,0,`${n}_ante_neg`,t)}else s=D(r,t);j(s,i,t,n);return}}throw Error(`Unsupported top-level logical constraint "${t}": ${e}`)}function ae(e,t,n,r,i,a,o){let s=pr(e,t,n,r,i,n===`<=`?dr(t,r,a):fr(t,r,a),a);s.lhs.terms.size>0&&v(new I(s.lhs,n,s.rhs,a),o)}function oe(e){return new I(e.lhs,`==`,e.rhs,e.name)}function se(e,t,n,r,i){let a=E(t,i);if(a.sense===`!=`){le(e,oe(a),n,r,i);return}let{lhs:o,sense:s,rhs:c}=a;s===`==`?(ae(e,o,`<=`,c,n,`${r}_le`,i),ae(e,o,`>=`,c,n,`${r}_ge`,i)):ae(e,o,s,c,n,r,i)}function N(e){let t=new H({name:_(`unsat`),type:`Binary`,lb:0,ub:1});o.push(t),v(new I($([[t,1]],0),`>=`,2,e),e)}function P(e,t){let n=E(e,t),{lhs:r,sense:i,rhs:a}=n;if(i===`!=`){ce(oe(n),t);return}let o=r.constant??0,s=a-o;if(!Number.isFinite(o)||!Number.isFinite(a)||!Number.isFinite(s))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: constraint "${e.name}" contains non-finite constant or right-hand side.`);let c=[];for(let[n,i]of r.terms){if(!Number.isFinite(i))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: variable "${n.name}" in constraint "${e.name}" has non-finite coefficient (${i}).`);i!==0&&c.push([n,i])}if(c.length===0){(i===`<=`?0<=s:i===`>=`?0>=s:s===0)||N(t);return}v(new I($(c,0),i,s,e.name||t),t)}function ce(e,t){let n=E(e,t);if(n.sense===`!=`){P(oe(n),t);return}let r=yr(n,t);if(r.kind===`always_true`)return;if(r.kind===`always_false`){N(t);return}if(r.kind===`single`){v(new I(r.lhs,r.sense,r.rhs,n.name||t),t);return}let i=new H({name:_(`neq_dir`),type:`Binary`,lb:0,ub:1});o.push(i);let a=n.name||t;ae(i,r.lhs,`<=`,r.ltRhs,1,`${a}_lt`,t),ae(i,r.lhs,`>=`,r.gtRhs,0,`${a}_gt`,t)}function le(e,t,n,r,i){let a=E(t,i);if(a.sense===`!=`){se(e,oe(a),n,r,i);return}let s=yr(a,i);if(s.kind===`always_true`)return;if(s.kind===`always_false`){v(new I($([[e,1]],0),n===0?`>=`:`<=`,+(n===0),r),i);return}if(s.kind===`single`){ae(e,s.lhs,s.sense,s.rhs,n,r,i);return}let c=new H({name:_(`neq_lt`),type:`Binary`,lb:0,ub:1}),l=new H({name:_(`neq_gt`),type:`Binary`,lb:0,ub:1});o.push(c,l),ae(c,s.lhs,`<=`,s.ltRhs,1,`${r}_lt`,i),ae(l,s.lhs,`>=`,s.gtRhs,1,`${r}_gt`,i),v(new I($([[c,1],[l,1],[e,n===0?1:-1]],0),`>=`,+(n===0),`${r}_disj`),i)}for(let e of p)T(e.lhs,e.sense,e.rhs,e.name,e.name);let F;if(a&&a.expr.hasNonlinearTerms()){let e=i(a.sense)===`Minimize`,t=a.expr,n=new Map(t instanceof w?t.linearTerms:t.terms),r=t.constant;for(let i of t.nonlinearTerms){if(i.coeff===0)continue;let t=(e?i.coeff>0:i.coeff<0)?`upper`:`lower`,a=S(i.atom,t,`__objective`);r+=i.coeff*a.constant;for(let[e,t]of a.terms.entries()){let r=(n.get(e)??0)+i.coeff*t;r===0?n.delete(e):n.set(e,r)}}F=t instanceof w?new w(n,t.quadTerms,r,[]):new z(n,r,[])}else a&&(F=a.expr);for(let e of r){let t=e.name,n=e.expr;M(n,t)}return{variables:o,constraints:s,boolVarToBinary:u,constraintToOriginalName:d,...F===void 0?{}:{objective:F}}}function vr(e){if(e.lhs.hasNonlinearTerms()||e.lhs.terms.size!==1||(e.lhs.constant??0)!==0)return null;let[[t,n]]=Array.from(e.lhs.terms.entries());return t.type!==`Binary`&&t.type!==`Integer`||t.lb!==0||t.ub!==1||n!==1?null:e.sense===`==`&&e.rhs===1||e.sense===`>=`&&e.rhs===1||e.sense===`!=`&&e.rhs===0?{binVar:t,activeVal:1}:e.sense===`==`&&e.rhs===0||e.sense===`<=`&&e.rhs===0||e.sense===`!=`&&e.rhs===1?{binVar:t,activeVal:0}:null}function yr(e,t){let{lhs:n,sense:r,rhs:i}=e;if(n.hasNonlinearTerms())throw Error(`Cannot negate unlowered nonlinear constraint "${e.name}" in "${t}".`);let a=n.constant??0,o=i-a;if(!Number.isFinite(a)||!Number.isFinite(i)||!Number.isFinite(o))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: constraint "${e.name}" contains non-finite constant or right-hand side.`);if(r!==`<=`&&r!==`>=`&&r!==`==`)throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: unsupported comparison sense "${String(r)}" in constraint "${e.name}".`);let s=[];for(let[r,i]of n.terms){if(!Number.isFinite(i))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: variable "${r.name}" in constraint "${e.name}" has non-finite coefficient (${i}).`);if(i!==0){if(r.type!==`Integer`&&r.type!==`Binary`)throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: negating constraint "${e.name}" involves Continuous variable "${r.name}", whose strict-inequality negation creates an open half-space not representable in MIP. Use { solver: "z3" }, rewrite explicitly with a closed tolerance such as or(expr\`... >= ... + eps\`, ...), or model the proposition with m.bool().`);if(!Number.isSafeInteger(i))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: negating constraint "${e.name}" requires safe integer coefficients, but variable "${r.name}" has coefficient ${i}. Scale to integer coefficients, use { solver: "z3" }, or rewrite explicitly with or(expr\`... >= ... + eps\`, ...) / m.bool().`);s.push([r,i])}}if(s.length===0)return(r===`<=`?0<=o:r===`>=`?0>=o:o===0)?{kind:`always_false`}:{kind:`always_true`};if(!Number.isInteger(o))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: negating constraint "${e.name}" requires an integer right-hand side and constant, received effective right-hand side ${o}. Scale or round the threshold to an integer, use { solver: "z3" }, or rewrite explicitly with or(expr\`... >= ... + eps\`, ...) / m.bool().`);if(Math.abs(o)>=2**53-1)throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: effective right-hand side (${o}) of constraint "${e.name}" exceeds safe integer precision for exact +/-1 negation. Please rescale coefficients/constants or solve with { solver: "z3" }.`);let c=$(s,0);if(r===`<=`)return{kind:`single`,lhs:c,sense:`>=`,rhs:o+1};if(r===`>=`)return{kind:`single`,lhs:c,sense:`<=`,rhs:o-1};let l=o-1,u=o+1,d=0,f=0,p=!0,m=!0;for(let[e,t]of s){if(!(e.lb<=e.ub)){p=!1,m=!1;break}let n=t>0?e.lb:e.ub,r=t>0?e.ub:e.lb,i=t*n,a=t*r;d+=i,f+=a,p&&=Number.isSafeInteger(n)&&Number.isSafeInteger(i)&&Number.isSafeInteger(d),m&&=Number.isSafeInteger(r)&&Number.isSafeInteger(a)&&Number.isSafeInteger(f)}let h=!(p&&d>l),g=!(m&&f<u);return!h&&!g?{kind:`always_false`}:g?h?{kind:`disjunction`,lhs:c,ltRhs:l,gtRhs:u}:{kind:`single`,lhs:c,sense:`>=`,rhs:u}:{kind:`single`,lhs:c,sense:`<=`,rhs:l}}async function br(e){let t=e.master;if(!t)throw Error(`A master Model must be provided for solveColumnGeneration.`);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;if(!u)throw Error(`The 'pricing' callback must be provided in ColumnGenerationOptions.`);let d=[],f=null,p=0,m=t.status;for(let e=1;e<=r;e++){p=e;let n=await t.relax(o,s);if(m=n,n!==`Optimal`&&n!==`Feasible`||!t.solution)break;f=t.objectiveValue;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({iteration:e,duals:a,getDual:h,masterSolution:r,reducedCostTolerance:i,master:t}),_=[];g&&(Array.isArray(g)?_.push(...g):_.push(g));let v=[];for(let e of _){let t=e.reducedCost;if(typeof t!=`number`||!Number.isFinite(t)){let n=0,r=e.coefficients;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));else if(r instanceof Map)for(let[e,t]of r.entries())n+=t*h(e);else if(r&&typeof r==`object`)for(let[e,t]of Object.entries(r))n+=t*h(e);t=e.cost-n}(l?t>i:t<-i)&&v.push(e)}if(c&&c({iteration:e,relaxationObjective:f,columnsAdded:d.length+v.length,proposedColumns:v}),v.length===0)break;for(let e of v){let n=t.column({name:e.name,type:e.type||`Continuous`,lb:e.lb,ub:e.ub,cost:e.cost,coefficients:e.coefficients});d.push({variable:n,proposal:e})}}let h=f;a&&(m===`Optimal`||m===`Feasible`)&&(m=await t.solve(o,s),h=t.objectiveValue);let g={};for(let e of t.variables.values())e instanceof H&&e.value!==null&&(g[e.name]=e.value);let _={status:m,objectiveValue:h,relaxationObjectiveValue:f,iterations:p,columnsAdded:d.length,generatedColumns:d,master:t,values:g};return t.decomposition=_,_}function xr(e,t){let n=e;if(n instanceof I||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}\`)).`);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}\`)).`);if(typeof n==`number`){if(!Number.isFinite(n))throw Error(`Invalid non-finite objective constant "${n}" passed to ${t}().`);return n}if(typeof n==`string`||n instanceof z||n instanceof w||n instanceof H||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;throw Error(`Invalid expression passed to ${t}(): expected a finite number, Var, LinExpr, QuadExpr, or arithmetic expression string.`)}function Sr(e){return{expr:xr(e,`maximize`),sense:`Maximize`}}function Cr(e){return{expr:xr(e,`minimize`),sense:`Minimize`}}var wr=new WeakSet;function Tr(e){return!!(e&&typeof e==`object`&&`constraints`in e&&`variables`in e&&typeof e.solve==`function`)}async function Er(e,t,n,r,i,a,o,s,c=1){let l=[];for(let r=0;r<t.length;r++){let a=t[r],o=a.lhs,s=a.sense,u=a.rhs-(o.constant||0),d=[],f=[],p=0;for(let[e,t]of o.terms.entries()){let r=n.variables.get(e.name);if(e.ownerModel===n||r instanceof H){f.push([e,t]);let n=i[e.name]??0;p+=t*n}else d.push([e,t])}let m=u-p,h=new z;for(let[e,t]of d)h.addTerm(e,t);let g=new I(h,s,m,`__benders_link_${c}_${r}`);e.constraint(g),l.push({origConstraint:a,subConstr:g,masterTerms:f,baseRhs:u})}let u=await e.solve(o,{...s,relax:!0});if(u!==`Optimal`&&u!==`Feasible`)throw Error(`Benders subproblem failed at iteration ${c} with status "${u}". Auto-cut generation requires an Optimal or Feasible subproblem (expected Optimal or Feasible).`);let d=e.objectiveValue;if(typeof d!=`number`||!Number.isFinite(d))throw Error(`Benders subproblem returned invalid objectiveValue (${String(d)}) at iteration ${c}.`);if(wr.has(r)&&d<r.lb-1e-6)throw Error(`Benders auto-created "__benders_theta" (lb: ${r.lb}) cannot represent negative subproblem cost (${d}) at iteration ${c}. Define an explicit theta variable with a negative lower bound and pass options.theta.`);let f=i[r.name]??0,p=1e-4;if(!(a?f<d-p:f>d+p))return null;let m=0,h=new Map,g=new Set(l.map(e=>e.subConstr.name));for(let t of e.constraints.values()){if(!(t instanceof I)||g.has(t.name))continue;let n=e.solution?.duals[t.name]??t.dual??0;if(Math.abs(n)>1e-12){let e=t.rhs-(t.lhs.constant||0);m+=n*e}}for(let t of l){let n=e.solution?.duals[t.subConstr.name]??t.subConstr.dual??0;if(Math.abs(n)>1e-12){m+=n*t.baseRhs;for(let[e,r]of t.masterTerms){let t=h.get(e)??0;h.set(e,t+n*r)}}}let _=new z;_.addTerm(r,1);for(let[e,t]of h.entries())Math.abs(t)>1e-12&&_.addTerm(e,t);let v=new I(_,a?`>=`:`<=`,m,`__benders_opt_cut_${c}`),y=(n.objectiveValue??0)-f+d;return{kind:`optimality`,constraint:v,name:v.name,subproblemObjective:y}}async function Dr(e){let t=e.master;if(!t)throw Error(`A master Model must be provided for solveBenders.`);let{subproblem:n,maxIterations:r=100,gapTolerance:i=1e-4,solver:a,solverOptions:o,onIteration:s}=e,c;if(e.theta!==void 0){if(typeof e.theta==`string`){let n=t.variables.get(e.theta);if(!(n instanceof H))throw Error(`Benders option "theta" references variable "${e.theta}", which was not found on the master model.`);c=n}else c=e.theta}if(!c){for(let e of t.variables.values())if(e instanceof H&&(e.name===`theta`||e.name===`__benders_theta`)){c=e;break}}let l=0,u=0,d=t.status,f,p,m,h={},g=null;for(let e=1;e<=r;e++){u=e;let r=await t.solve(a,o);if(d=r,r!==`Optimal`&&r!==`Feasible`)break;let _=t.objectiveValue,v=t.sense.toLowerCase()===`minimize`;v?f=_===null?f:_:p=_===null?p:_;let y={};for(let e of t.variables.values())e instanceof H&&e.value!==null&&(y[e.name]=e.value);let b=await n({iteration:e,masterValues:y,getMasterValue:e=>typeof e==`string`?y[e]??0:e.value??(e.name?y[e.name]??0:0),masterObjective:_,lowerBound:f,upperBound:p,master:t}),x=[];if(b){if(Tr(b)){let n=b,r=n.linkingConstraints;if(!c){if(!v)throw Error(`Benders auto-cut generation requires an explicit options.theta variable for Maximize master models.`);c=t.continuous(`__benders_theta`,{lb:0}),t.objective(Cr(t.objective().add(c))),wr.add(c)}let i=await Er(n,r,t,c,y,v,a,o,e);i&&x.push(i)}else Array.isArray(b)?x.push(...b):x.push(b)}for(let e of x)if(typeof e.subproblemObjective==`number`&&Number.isFinite(e.subproblemObjective)){if(v){let t=e.subproblemObjective;(p===void 0||t<p)&&(p=t,g=t,h={...y})}else{let t=e.subproblemObjective;(f===void 0||t>f)&&(f=t,g=t,h={...y})}}if(f!==void 0&&p!==void 0){let e=Math.abs(p)+1e-10;m=Math.abs(p-f)/e}if(s&&s({iteration:e,masterObjective:_,lowerBound:f,upperBound:p,cutsAdded:l+x.length,proposedCuts:x}),x.length===0){g=_,h={...y};break}if(m!==void 0&&m<=i)break;for(let e of x)t.constraint(e.constraint,e.name),l++}let _=d===`Optimal`||d===`Feasible`,v=Object.keys(h).length>0?h:_?(()=>{let e={};for(let n of t.variables.values())n instanceof H&&n.value!==null&&(e[n.name]=n.value);return e})():{},y=g===null?_?t.objectiveValue:null:g,b={status:d,objectiveValue:y,lowerBound:f,upperBound:p,gap:m,iterations:u,cutsAdded:l,master:t,values:v};return t.decomposition=b,b}function Or(e,t){return e.hasNonlinearTerms()?!0:kr(t)}function kr(e){for(let t of e)if(t.sense===`!=`||t.lhs.hasNonlinearTerms())return!0;return!1}function Ar(e){return e.type===`Integer`||e.type===`Binary`}function jr(e){switch(e.kind){case`abs`:return Nr(e.arg);case`max`:case`min`:return e.args.length>0&&e.args.every(Nr);case`at`:return e.array.length>0&&e.array.every(Nr)}}function Mr(e){for(let t of e)if(t.coeff!==0&&(!Number.isInteger(t.coeff)||!jr(t.atom)))return!1;return!0}function Nr(e){if(!Number.isInteger(e.constant))return!1;if(e instanceof w){for(let[t,n]of e.linearTerms)if(n!==0&&(!Ar(t)||!Number.isInteger(n)))return!1;for(let t of e.quadTerms.values())if(t.coeff!==0&&(!Ar(t.var1)||!Ar(t.var2)||!Number.isInteger(t.coeff)))return!1;return Mr(e.nonlinearTerms)}for(let[t,n]of e.terms)if(n!==0&&(!Ar(t)||!Number.isInteger(n)))return!1;return Mr(e.nonlinearTerms)}function Pr(e){let t=Object.freeze({get size(){return e.size},get(t){return e.get(t)},has(t){return e.has(t)},forEach(n,r){e.forEach((e,i)=>{n.call(r,e,i,t)})},entries(){return e.entries()},keys(){return e.keys()},values(){return e.values()},[Symbol.iterator](){return e[Symbol.iterator]()}});return t}function Fr(e){return Array.isArray(e)||typeof e==`object`&&!!e&&!(e instanceof String)&&typeof e[Symbol.iterator]==`function`}function Ir(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!(e instanceof String)&&typeof e[Symbol.iterator]!=`function`}function Lr(e){return e instanceof H||typeof e==`object`&&!!e&&!(e instanceof s)&&!(e instanceof I)&&`id`in e&&`name`in e&&`lb`in e&&`ub`in e&&!(`terms`in e)&&!(`quadTerms`in e)&&!(`sense`in e)}function Rr(e,t){if(!Number.isInteger(e)||e<0)throw Error(`Invalid count (${e}) for ${t} variable creation: count must be a non-negative integer.`)}var zr=class{name;_sense;_objectiveExpr;_variables=[];_constraints=[];_boolVars=[];_logicalConstraints=[];unsatCore=void 0;_conflicts=void 0;_values=new Map;varMapByName=new Map;varPrefixCounters=new Map;boolVarMapByName=new Map;boolVarPrefixCounters=new Map;constrMapByName=new Map;constrPrefixCounters=new Map;logicalConstrMapByName=new Map;logicalConstrCounter=0;allVarsMap=new Map;allConstrsMap=new Map;variables;constraints;values;status=`NotSolved`;terminationStatus=`NotSolved`;hasPrimalSolution=!1;objectiveValue=null;objectiveBound=void 0;relativeGap=void 0;absoluteGap=void 0;runTime=0;solution=null;solver=null;decomposition;_linkingConstraints;hasSolutionState=!1;modelRevision=0;activeOperationId=0;batchDepth=0;batchMutated=!1;batchUndoActions=[];constructor(e={},t){let n;n=typeof e==`string`?{...t,name:e}:e,this.name=n.name||`OptimizationModel`,this._sense=i(n.sense),this._objectiveExpr=new z,this.variables=Pr(this.allVarsMap),this.constraints=Pr(this.allConstrsMap),this.values=Pr(this._values),O(this,()=>this.recordModelMutation()),n.solver&&(this.solver=tt(n.solver))}get sense(){return this._sense}set sense(e){let t=i(e);this._sense!==t&&(this._sense=t,this.recordModelMutation())}get conflicts(){return this._conflicts??this.unsatCore}set conflicts(e){this._conflicts=e}clearSolutionFields(){if(this.hasSolutionState||this.status!==`NotSolved`||this.terminationStatus!==`NotSolved`||this.hasPrimalSolution||this.solution!==null||this.unsatCore!==void 0){this.hasSolutionState=!1,this.status=`NotSolved`,this.terminationStatus=`NotSolved`,this.hasPrimalSolution=!1,this.objectiveValue=null,this.objectiveBound=void 0,this.relativeGap=void 0,this.absoluteGap=void 0,this.solution=null,this.runTime=0,this.unsatCore=void 0,this._conflicts=void 0,this._values.clear();for(let e of this._variables)e.value=null,e.reducedCost=null;for(let e of this._boolVars)e.value=null;for(let e of this._constraints)e.dual=null,e.slack=null}}recordModelMutation(){if(this.batchDepth>0){this.batchMutated=!0;return}this.modelRevision++,this.clearSolutionFields()}runTransactionalBatch(e){if(this.batchDepth>0)return e();let t=this._variables.length,n=this._boolVars.length,r=this._constraints.length,i=this._logicalConstraints.length,a=new Map(this.varPrefixCounters),o=new Map(this.boolVarPrefixCounters),s=new Map(this.constrPrefixCounters),c=this.logicalConstrCounter;this.batchDepth=1,this.batchMutated=!1,this.batchUndoActions=[];try{let t=e();this.batchDepth=0;let n=this.batchMutated;return this.batchMutated=!1,this.batchUndoActions=[],n&&this.recordModelMutation(),t}catch(e){this.batchDepth=0,this.batchMutated=!1;for(let e=t;e<this._variables.length;e++){let t=this._variables[e];this.varMapByName.delete(t.name),this.allVarsMap.delete(t.name),t.ownerModel=null,re(t,this)}this._variables.length=t;for(let e=n;e<this._boolVars.length;e++){let t=this._boolVars[e];this.boolVarMapByName.delete(t.name),this.allVarsMap.delete(t.name)}this._boolVars.length=n;for(let e=r;e<this._constraints.length;e++){let t=this._constraints[e];this.constrMapByName.delete(t.name),this.allConstrsMap.delete(t.name)}this._constraints.length=r;for(let e=i;e<this._logicalConstraints.length;e++){let t=this._logicalConstraints[e];this.logicalConstrMapByName.delete(t.name),this.allConstrsMap.delete(t.name)}this._logicalConstraints.length=i;for(let e=this.batchUndoActions.length-1;e>=0;e--)this.batchUndoActions[e]();throw this.batchUndoActions=[],this.varPrefixCounters=a,this.boolVarPrefixCounters=o,this.constrPrefixCounters=s,this.logicalConstrCounter=c,e}}createDomainVars(e,t,n,r){let i=e.toLowerCase(),a=typeof t==`number`,o=typeof n==`number`,s=Fr(t),c=Fr(n);if(o||c){if(a&&Rr(t,i),o&&Rr(n,i),!a&&!s||r!==void 0&&!Ir(r))throw Error(`Invalid arguments provided for ${i} variable creation`);let c=a?Array.from({length:t},(e,t)=>t):Array.from(t),l=o?Array.from({length:n},(e,t)=>t):n===t?c:Array.from(n),u=r||{},d=u.prefix||u.name||`x`;return this.runTransactionalBatch(()=>{let t=a?[]:{};for(let n of c){let r=o?[]:{};for(let t of l)r[t]=this.addVar({...u,type:e,name:`${d}_${n}_${t}`});t[n]=r}return t})}if(typeof t==`string`||t===void 0){if(n!==void 0&&!Ir(n))throw Error(`Invalid arguments provided for ${i} variable creation`);let r=n||{},a=typeof t==`string`?t:r.name;return this.addVar({...r,type:e,name:a})}if(Ir(t)){if(n!==void 0)throw Error(`Invalid arguments provided for ${i} variable creation`);let r=t;return this.addVar({...r,type:e})}if(n!==void 0&&!Ir(n))throw Error(`Invalid arguments provided for ${i} variable creation`);let l=n||{},u=l.prefix||l.name;if(typeof t==`number`)return Rr(t,i),this.runTransactionalBatch(()=>{let n=[],r=u||`x`;for(let i=0;i<t;i++)n.push(this.addVar({...l,type:e,name:void 0,prefix:r}));return n});if(Fr(t))return this.runTransactionalBatch(()=>{let n={};for(let r of t){let t=u?`${u}_${r}`:`${r}`;n[r]=this.addVar({...l,type:e,name:t})}return n});throw Error(`Invalid arguments provided for ${i} variable creation`)}binary(e,t,n){return this.createDomainVars(`Binary`,e,t,n)}integer(e,t,n){return this.createDomainVars(`Integer`,e,t,n)}continuous(e,t,n){return this.createDomainVars(`Continuous`,e,t,n)}column(e){let t=e.type||`Continuous`,n=this.addVar({name:e.name,type:t,lb:e.lb,ub:e.ub});if(typeof e.cost==`number`&&e.cost!==0&&(this._objectiveExpr=this._objectiveExpr.add(n.mul(e.cost)),this.recordModelMutation()),e.coefficients){if(Array.isArray(e.coefficients)){for(let t of e.coefficients)if(Array.isArray(t)){let[e,r]=t,i=typeof e==`string`?this.constrMapByName.get(e):e;if(!i)throw Error(`Constraint '${String(e)}' not found in model when adding column`);i.addTerm(n,r)}else if(typeof t==`object`&&t){let e=typeof t.constraint==`string`?this.constrMapByName.get(t.constraint):t.constraint;if(!e)throw Error(`Constraint '${String(t.constraint)}' not found in model when adding column`);e.addTerm(n,t.coeff)}}else if(e.coefficients instanceof Map)for(let[t,r]of e.coefficients.entries()){let e=typeof t==`string`?this.constrMapByName.get(t):t;if(!e)throw Error(`Constraint '${String(t)}' not found in model when adding column`);e.addTerm(n,r)}else if(typeof e.coefficients==`object`)for(let[t,r]of Object.entries(e.coefficients)){let e=this.constrMapByName.get(t);if(!e)throw Error(`Constraint '${t}' not found in model when adding column`);e.addTerm(n,r)}}return n}bool(e,t,n){let r=typeof e==`number`,i=typeof t==`number`,a=Fr(e),o=Fr(t);if(i||o){if(r&&Rr(e,`boolean`),i&&Rr(t,`boolean`),!r&&!a||n!==void 0&&!Ir(n))throw Error(`Invalid arguments provided for boolean variable creation`);let o=r?Array.from({length:e},(e,t)=>t):Array.from(e),s=i?Array.from({length:t},(e,t)=>t):t===e?o:Array.from(t),c=n||{},l=c.prefix||c.name||`p`;return this.runTransactionalBatch(()=>{let e=r?[]:{};for(let t of o){let n=i?[]:{};for(let e of s)n[e]=this.createBoolVar(`${l}_${t}_${e}`);e[t]=n}return e})}if(typeof e==`string`||e===void 0){if(t!==void 0&&!Ir(t))throw Error(`Invalid arguments provided for boolean variable creation`);let n=t||{},r=typeof e==`string`?e:n.name;return this.createBoolVar(r,n.prefix)}if(Ir(e)){if(t!==void 0)throw Error(`Invalid arguments provided for boolean variable creation`);let n=e;return this.createBoolVar(n.name,n.prefix)}if(t!==void 0&&!Ir(t))throw Error(`Invalid arguments provided for boolean variable creation`);let s=t||{},c=s.prefix||s.name;if(typeof e==`number`)return Rr(e,`boolean`),this.runTransactionalBatch(()=>{let t=[],n=c||`p`;for(let r=0;r<e;r++)t.push(this.createBoolVar(void 0,n));return t});if(Fr(e))return this.runTransactionalBatch(()=>{let t={};for(let n of e){let e=c?`${c}_${n}`:`${n}`;t[n]=this.createBoolVar(e)}return t});throw Error(`Invalid arguments provided for boolean variable creation`)}hasVarName(e){return this.varMapByName.has(e)||this.boolVarMapByName.has(e)}getNextVarName(e){let t=this.varPrefixCounters.get(e)??0,n=`${e}_${t}`;for(;this.hasVarName(n);)t++,n=`${e}_${t}`;return this.varPrefixCounters.set(e,t+1),n}getNextBoolVarName(e){let t=this.boolVarPrefixCounters.get(e)??0,n=`${e}_${t}`;for(;this.hasVarName(n)||this.hasConstraintName(n);)t++,n=`${e}_${t}`;return this.boolVarPrefixCounters.set(e,t+1),n}hasConstraintName(e){return this.constrMapByName.has(e)||this.logicalConstrMapByName.has(e)}hasBoolVarName(e){return this.boolVarMapByName.has(e)}getNextConstrName(e=`c`){let t=this.constrPrefixCounters.get(e)??1,n=`${e}_${t}`;for(;this.hasConstraintName(n)||this.hasBoolVarName(n);)t++,n=`${e}_${t}`;return this.constrPrefixCounters.set(e,t+1),n}getNextLogicalConstrName(){let e=this.logicalConstrCounter+1,t=`lc_${e}`;for(;this.hasConstraintName(t)||this.hasBoolVarName(t);)e++,t=`lc_${e}`;return this.logicalConstrCounter=e,t}createBoolVar(e,t){let n=typeof e==`string`?e.trim():void 0,r=typeof t==`string`?t.trim():``,i=r.length>0?r:`p`,a=n&&n.length>0?n:this.getNextBoolVarName(i);if(this.hasVarName(a))throw Error(`Variable with name '${a}' already exists in model`);if(this.hasConstraintName(a))throw Error(`Boolean variable name '${a}' conflicts with an existing constraint in model`);let o=new c(a);return this._boolVars.push(o),this.boolVarMapByName.set(o.name,o),this.allVarsMap.set(o.name,o),this.recordModelMutation(),o}addVar(e){let t=e||{},n=typeof t.name==`string`?t.name.trim():void 0,r=n&&n.length>0?n:void 0,i=typeof t.prefix==`string`?t.prefix.trim():``,a=i.length>0?i:`x`,o=this.varPrefixCounters.get(a),s=r??this.getNextVarName(a);try{if(this.hasVarName(s))throw Error(`Variable with name '${s}' already exists in model`);let e=new H({...t,name:s,prefix:a});return e.hasExplicitName=r!==void 0,M(e),te(e,this),e.ownerModel=this,this._variables.push(e),this.varMapByName.set(e.name,e),this.allVarsMap.set(e.name,e),this.recordModelMutation(),e}catch(e){throw r===void 0&&(o===void 0?this.varPrefixCounters.delete(a):this.varPrefixCounters.set(a,o)),e}}objective(e){if(arguments.length===0)return this._objectiveExpr.clone();let t=e;if(t instanceof I||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}`)).");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}`)).");return this.applyObjective(t.expr,t.sense),this}applyObjective(e,t){if(e instanceof I||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}`)).");let n=t===void 0?this.sense:i(t),r;if(typeof e==`string`)r=Re(e,e=>this.varMapByName.get(e));else if(typeof e==`number`)r=new z(new Map,e);else if(e instanceof w)r=e.clone();else if(e instanceof z)r=e.clone();else if(typeof e==`object`&&e&&`quadTerms`in e&&e.quadTerms instanceof Map&&`linearTerms`in e&&e.linearTerms instanceof Map&&typeof e.constant==`number`){let t=e;r=new w(t.linearTerms,t.quadTerms,t.constant,t.nonlinearTerms)}else if(typeof e==`object`&&e&&`terms`in e&&e.terms instanceof Map&&typeof e.constant==`number`){let t=e;r=new z(t.terms,t.constant,t.nonlinearTerms)}else if(e instanceof H||typeof e==`object`&&e&&`id`in e&&`name`in e&&`lb`in e&&`ub`in e)r=new z(new Map([[e,1]]),0);else throw Error(`Invalid objective expression: expected a finite number, Var, LinExpr, QuadExpr, or arithmetic expression string.`);P(r,this.name,e=>this.varMapByName.get(e.name)===e),this._sense=n,this._objectiveExpr=r,this.recordModelMutation()}constraint(e,t){if(Array.isArray(e))return this.runTransactionalBatch(()=>{let t=[];for(let n of e)t.push(this.constraint(n));return t});if(e instanceof w||typeof e==`object`&&e&&`quadTerms`in e)throw Error(`Constraint must contain a comparison operator (<=, >=, ==): cannot add a quadratic expression as a constraint.`);if(e instanceof z||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().");if(Lr(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().`);return this.addConstraint(e,t)}addConstraint(e,t){if(e instanceof w||typeof e==`object`&&e&&`quadTerms`in e)throw Error(`Constraint must contain a comparison operator (<=, >=, ==): cannot add a quadratic expression as a constraint.`);if(e instanceof z||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().");if(Lr(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().`);if(e instanceof s){let n=typeof t==`string`&&t.trim().length>0?t.trim():void 0;if(n!==void 0){if(this.hasConstraintName(n))throw Error(`Constraint with name '${n}' already exists in model`);if(this.hasBoolVarName(n))throw Error(`Constraint name '${n}' conflicts with an existing Boolean variable in model`)}let r=this.logicalConstrCounter,i=n??this.getNextLogicalConstrName();try{le(e,i,this.name,e=>this.varMapByName.get(e.name)===e,e=>this.boolVarMapByName.get(e.name)===e,this)}catch(e){throw n===void 0&&(this.logicalConstrCounter=r),e}A(e,this,this.batchDepth>0?this.batchUndoActions:void 0);let a=Object.freeze({kind:`logical`,name:i,expr:e,dual:null,slack:null});return this._logicalConstraints.push(a),this.logicalConstrMapByName.set(i,a),this.allConstrsMap.set(i,a),this.recordModelMutation(),e}let n=typeof e==`string`?Be(e,e=>this.varMapByName.get(e),t):e;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.");n.ownerModel&&n.ownerModel!==this&&(ce(n,this.name,e=>this.varMapByName.get(e.name)===e,n.name),ne(n,this));let r=typeof t==`string`&&t.trim().length>0?t.trim():n.hasExplicitName?n.name.trim():void 0;if(r!==void 0){if(this.hasConstraintName(r))throw Error(`Constraint with name '${r}' already exists in model`);if(this.hasBoolVarName(r))throw Error(`Constraint name '${r}' conflicts with an existing Boolean variable in model`)}let i=this.constrPrefixCounters.get(`c`),a=r??this.getNextConstrName(`c`),o;try{ce(n,this.name,e=>this.varMapByName.get(e.name)===e,a),o=ne(n,this)}catch(e){throw r===void 0&&(i===void 0?this.constrPrefixCounters.delete(`c`):this.constrPrefixCounters.set(`c`,i)),e}let c=n.name,l=n.hasExplicitName,u=n.ownerModel,d=o;return this.batchUndoActions.push(()=>{n.ownerModel=u,n._assignModelName(c,l),ie(n,this,d)}),this.batchDepth===0&&(this.batchUndoActions=[]),n._assignModelName(a,!0),n.ownerModel=this,this._constraints.push(n),this.constrMapByName.set(n.name,n),this.allConstrsMap.set(n.name,n),this.recordModelMutation(),n}indicator(e,t,n={}){if(e instanceof s)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.");if(!(e instanceof H))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).`);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]).`);if(t instanceof w||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).");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.");let r=t;if(r.sense===`!=`)throw Error(`Constraint "${r.name}" uses discrete "!=", which is not supported in m.indicator(). Use m.constraint(implies(${e.name}.eq(1), ...)) instead.`);if(r.lhs.hasNonlinearTerms())throw Error(`Constraint "${r.name}" contains nonlinear terms (max/min/abs/at), which are not supported in m.indicator().`);let i=n.activeValue===void 0?1:n.activeValue;if(i!==0&&i!==1)throw Error(`Invalid activeValue: ${i}. Indicator activeValue must be 0 or 1.`);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.`);let a=typeof n.name==`string`&&n.name.trim().length>0?n.name.trim():void 0,o=this.constrPrefixCounters.get(`c`),{lhs:c,sense:l,rhs:u}=r,d,f,p;if(a!==void 0)d=a,f=l===`==`?`${d}_le`:d,p=l===`==`?`${d}_ge`:d;else if(r.hasExplicitName)d=`ind_${e.name}_${r.name.trim()}`,f=l===`==`?`${d}_le`:d,p=l===`==`?`${d}_ge`:d;else do{let t=this.getNextConstrName(`c`);d=`ind_${e.name}_${t}`,f=l===`==`?`${d}_le`:d,p=l===`==`?`${d}_ge`:d}while((l===`<=`||l===`==`)&&(this.hasConstraintName(f)||this.hasBoolVarName(f))||(l===`>=`||l===`==`)&&(this.hasConstraintName(p)||this.hasBoolVarName(p)));let m=[];try{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`);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`);n.M!==void 0&&lr(n.M,d);let t=e=>this.varMapByName.get(e.name)===e;for(let[e]of c.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.`);if(l===`<=`||l===`==`){let t=n.M===void 0?dr(c,u,f):n.M,r=pr(e,c,`<=`,u,i,t,f),a=new I(r.lhs,`<=`,r.rhs,f);n.M===void 0&&a._setIndicatorOrigin({binVar:e,activeValue:i,targetLhs:c.clone(),targetSense:`<=`,targetRhs:u,derivedM:t}),m.push([a,f])}if(l===`>=`||l===`==`){let t=n.M===void 0?fr(c,u,p):n.M,r=pr(e,c,`>=`,u,i,t,p),a=new I(r.lhs,`>=`,r.rhs,p);n.M===void 0&&a._setIndicatorOrigin({binVar:e,activeValue:i,targetLhs:c.clone(),targetSense:`>=`,targetRhs:u,derivedM:t}),m.push([a,p])}for(let[e,n]of m)ce(e,this.name,t,n)}catch(e){throw o===void 0?this.constrPrefixCounters.delete(`c`):this.constrPrefixCounters.set(`c`,o),e}return this.runTransactionalBatch(()=>m.map(([e,t])=>this.addConstraint(e,t)))}toLpString(){if(this.validateIntegrityInternal(),Or(this._objectiveExpr,this._constraints)){let e=_r(this._variables,[],this._constraints,[],{expr:this._objectiveExpr,sense:this.sense}),{lpString:t}=Je({name:this.name,sense:this.sense,objective:e.objective??this._objectiveExpr,constraints:e.constraints,variables:e.variables});return t}let{lpString:e}=Je({name:this.name,sense:this.sense,objective:this._objectiveExpr.clone(),constraints:this._constraints,variables:this._variables});return e}validateIntegrityInternal(){F({model:this,name:this.name,variables:this._variables,boolVars:this._boolVars,constraints:this._constraints,logicalConstraints:this._logicalConstraints,objectiveExpr:this._objectiveExpr,getVarByName:e=>this.varMapByName.get(e),getBoolVarByName:e=>this.boolVarMapByName.get(e),getConstraintByName:e=>this.constrMapByName.get(e),getLogicalConstraintByName:e=>this.logicalConstrMapByName.get(e)})}ensureExecutionValid(e,t,n){if(this.modelRevision!==e)throw this.activeOperationId===t&&this.clearSolutionFields(),Error(`Model "${this.name}" was modified while ${n}() was in progress; stale solver result was discarded.`);if(this.activeOperationId!==t)throw Error(`Stale ${n}() result discarded because a newer solve or check operation was started on model "${this.name}".`)}wrapSolveOptions(e,t,n,r,i){let a=t.onProgress;return a?{...t,onProgress:o=>{if(this.activeOperationId===r&&this.modelRevision===n){if(i&&typeof o.objectiveValue==`number`&&Number.isFinite(o.objectiveValue)){let n=this.normalizeObjectiveValue(o.objectiveValue,e,t);if(!Object.is(n,o.objectiveValue)){let e=typeof o.objectiveBound==`number`&&Number.isFinite(o.objectiveBound),t=e?Math.abs(n-o.objectiveBound)+0:void 0,r={...o,objectiveValue:n};e&&`absoluteGap`in o&&o.absoluteGap!==void 0&&(r.absoluteGap=t),e&&`relativeGap`in o&&o.relativeGap!==void 0&&(t===0?r.relativeGap=0:Math.abs(n)>0&&t!==void 0?r.relativeGap=t/Math.abs(n):delete r.relativeGap),a(r);return}}a(o)}}}:t}hasPrimalFromResult(e){if(typeof e.hasPrimalSolution==`boolean`)return e.hasPrimalSolution;let t=e.status,n=e.terminationStatus??t,r=e.values||{},i=e.boolValues||{};return t!==`Infeasible`&&t!==`Unsat`&&t!==`Unbounded`&&t!==`Error`&&t!==`NotSolved`&&n!==`Infeasible`&&n!==`Unsat`&&n!==`Unbounded`&&n!==`InfeasibleOrUnbounded`&&n!==`Error`&&n!==`NotSolved`&&(t===`Optimal`||t===`Feasible`||t===`Sat`||n===`Optimal`||n===`Feasible`||n===`Sat`||typeof e.objectiveValue==`number`&&Number.isFinite(e.objectiveValue)||Object.values(r).some(e=>typeof e==`number`&&Number.isFinite(e)||typeof e==`boolean`)||Object.values(i).some(e=>typeof e==`boolean`))}normalizePrimalValue(e,t,n,r){return(r.relax??n.options?.relax)!==!0&&Ar(e)&&Math.abs(t-Math.round(t))<=1e-5?Math.round(t)+0:t}normalizeObjectiveValue(e,t,n){if((n.relax??t.options?.relax)!==!0&&Nr(this._objectiveExpr)){let t=Math.round(e);if(Number.isSafeInteger(t)&&Math.abs(e-t)<=1e-5)return t+0}return e}resolveSolverAndOptions(e,t){if(e&&typeof e==`object`&&`solve`in e&&typeof e.solve==`function`){let{solver:n,...r}=t||{};return{activeSolver:e,activeOptions:r}}if(typeof e==`function`){let{solver:n,...r}=t||{};return{activeSolver:new e(r),activeOptions:r}}if(typeof e==`string`){let{solver:n,...r}=t||{};return{activeSolver:tt(e,r),activeOptions:r}}let{solver:n,...r}=e||{};return n?{activeSolver:tt(n,r),activeOptions:r}:{activeSolver:this.solver||tt(),activeOptions:r}}async relax(e,t){let n=typeof e==`object`&&!!e&&!(`solve`in e),r=n?{...e,relax:!0}:{...t||{},relax:!0},i=n?void 0:e;return i?this.solve(i,r):this.solve(r)}async solve(e,t){let n=++this.activeOperationId,r=this.modelRevision;this.clearSolutionFields(),this.validateIntegrityInternal();let{activeSolver:i,activeOptions:a}=this.resolveSolverAndOptions(e,t);if(this._objectiveExpr instanceof w&&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.`);let o,s=null;if(i.capabilities?.supportsLogicalConstraints!==!0&&i.capabilities?.supportsSMT!==!0&&(this._logicalConstraints.length>0||this._boolVars.length>0||Or(this._objectiveExpr,this._constraints))?(s=_r(this._variables,this._boolVars,this._constraints,this._logicalConstraints,{expr:this._objectiveExpr,sense:this.sense}),o={name:this.name,sense:this.sense,objective:s.objective??this._objectiveExpr,constraints:s.constraints,variables:s.variables,logicalConstraints:[],boolVars:[]}):o={name:this.name,sense:this.sense,objective:this._objectiveExpr,constraints:this._constraints,variables:this._variables,logicalConstraints:this._logicalConstraints,boolVars:this._boolVars},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 or Pumpkin.`);let c=this.wrapSolveOptions(i,a,r,n,!0),l;try{l=await i.solve(o,c)}catch(e){throw this.activeOperationId===n&&this.clearSolutionFields(),e}this.ensureExecutionValid(r,n,`solve`),this.runTime=l.runTime??0,this.status=l.status,this.terminationStatus=l.terminationStatus??l.status;let u=this.hasPrimalFromResult(l);this.hasPrimalSolution=u;let d=(a.relax??i.options?.relax)!==!0&&Nr(this._objectiveExpr),f=u&&typeof l.objectiveValue==`number`&&Number.isFinite(l.objectiveValue)?l.objectiveValue:null;this.objectiveValue=f===null?null:this.normalizeObjectiveValue(f,i,a);let p=typeof l.objectiveBound==`number`&&Number.isFinite(l.objectiveBound)?l.objectiveBound:void 0;this.objectiveBound=d&&this.status===`Optimal`&&this.objectiveValue!==null&&p!==void 0&&Math.abs(p-this.objectiveValue)<=1e-5?this.objectiveValue:p;let m=typeof l.relativeGap==`number`&&Number.isFinite(l.relativeGap)?l.relativeGap:void 0,h=f!==null&&this.objectiveValue!==null&&!Object.is(f,this.objectiveValue),g=p!==void 0&&this.objectiveBound!==void 0&&!Object.is(p,this.objectiveBound);this.absoluteGap=(h||g)&&this.objectiveValue!==null&&this.objectiveBound!==void 0?Math.abs(this.objectiveValue-this.objectiveBound)+0:typeof l.absoluteGap==`number`&&Number.isFinite(l.absoluteGap)?l.absoluteGap:this.objectiveValue!==null&&this.objectiveBound!==void 0?Math.abs(this.objectiveValue-this.objectiveBound):void 0,this.relativeGap=(h||g)&&m!==void 0&&this.objectiveValue!==null&&this.absoluteGap!==void 0?this.absoluteGap===0?0:Math.abs(this.objectiveValue)>0?this.absoluteGap/Math.abs(this.objectiveValue):void 0:m;let _=(e,t,n)=>{Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})},v={},y={},b={},x={};if(this._values.clear(),u&&l.values){for(let[e,t]of Object.entries(l.values))if(typeof t==`number`&&Number.isFinite(t)){let n=this.varMapByName.get(e),r=this.boolVarMapByName.get(e);if(n){let e=this.normalizePrimalValue(n,t,i,a);n.value=e,_(v,n.name,e),this._values.set(n.name,e)}r&&(r.value=!!t,this._values.set(r.name,t)),!n&&!r&&!s&&this._values.set(e,t)}else if(typeof t==`boolean`){let n=t,r=this.boolVarMapByName.get(e);r?(r.value=n,_(v,r.name,+!!n),this._values.set(r.name,n)):this._values.set(e,n)}if(s)for(let e of this._boolVars){let t=s.boolVarToBinary.get(e);if(t&&l.values){let n=l.values[t.name];if(typeof n==`number`&&Number.isFinite(n)){let t=Math.round(n)===1;e.value=t,_(v,e.name,+!!t),this._values.set(e.name,t)}}}}if(u&&l.boolValues)for(let[e,t]of Object.entries(l.boolValues)){if(typeof t!=`boolean`)continue;let n=this.boolVarMapByName.get(e);n?(n.value=t,this._values.has(n.name)||this._values.set(n.name,t)):this._values.has(e)||this._values.set(e,t)}if(u&&l.reducedCosts)for(let[e,t]of Object.entries(l.reducedCosts)){if(typeof t!=`number`||!Number.isFinite(t))continue;let n=this.varMapByName.get(e);n&&(n.reducedCost=t,_(b,n.name,t))}if(l.duals)for(let[e,t]of Object.entries(l.duals)){if(typeof t!=`number`||!Number.isFinite(t))continue;let n=this.constrMapByName.get(e);n&&(n.dual=t,_(y,n.name,t))}if(l.slacks)for(let[e,t]of Object.entries(l.slacks)){if(typeof t!=`number`||!Number.isFinite(t))continue;let n=this.constrMapByName.get(e);n&&(n.slack=t,_(x,n.name,t))}return this.solution={status:this.status,terminationStatus:this.terminationStatus,hasPrimalSolution:this.hasPrimalSolution,objectiveValue:this.objectiveValue,...this.objectiveBound===void 0?{}:{objectiveBound:this.objectiveBound},...this.relativeGap===void 0?{}:{relativeGap:this.relativeGap},...this.absoluteGap===void 0?{}:{absoluteGap:this.absoluteGap},values:v,duals:y,reducedCosts:b,slacks:x,runTime:this.runTime,raw:l.raw},this.hasSolutionState=!0,this.status}async check(e,t){let n=++this.activeOperationId,r=this.modelRevision;this.clearSolutionFields(),this.validateIntegrityInternal();let{activeSolver:i,activeOptions:a}=this.resolveSolverAndOptions(e,t);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 or Pumpkin.`);let o=this.wrapSolveOptions(i,a,r,n,!1),s=(e,t,n)=>{Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})},c={name:this.name,variables:this._variables,boolVars:this._boolVars,constraints:this._constraints,logicalConstraints:this._logicalConstraints};if(typeof i.check==`function`){let e;try{e=await i.check(c,o)}catch(e){throw this.activeOperationId===n&&this.clearSolutionFields(),e}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]);let t={};if(e.values&&e.status===`Sat`){for(let[n,r]of Object.entries(e.values))if(typeof r==`number`){if(!Number.isFinite(r))continue;let e=this.varMapByName.get(n),o=this.boolVarMapByName.get(n);if(e){let n=this.normalizePrimalValue(e,r,i,a);e.value=n,this._values.set(e.name,n),s(t,e.name,n)}o&&(o.value=!!r,this._values.set(o.name,o.value),s(t,o.name,o.value)),!e&&!o&&(this._values.set(n,r),s(t,n,r))}else if(typeof r==`boolean`){let e=this.boolVarMapByName.get(n);e?(e.value=r,this._values.set(e.name,r),s(t,e.name,r)):(this._values.set(n,r),s(t,n,r))}}return this.hasSolutionState=!0,{status:e.status,values:t,unsatCore:this.unsatCore,conflicts:this.conflicts,runTime:this.runTime}}let l=this._logicalConstraints.length>0||this._boolVars.length>0||kr(this._constraints)?_r(this._variables,this._boolVars,this._constraints,this._logicalConstraints):{variables:[...this._variables],constraints:[...this._constraints],boolVarToBinary:new Map,constraintToOriginalName:new Map(this._constraints.map(e=>[e,e.name]))},u=[],d=[],f=[],p=new Map,m=0;for(let e of l.constraints){let t=l.constraintToOriginalName.get(e)??e.name,{lhs:n,sense:r,rhs:i}=e;if(r===`<=`){let r=new H({name:`__slack_${++m}`,type:`Continuous`,lb:0,ub:1/0});d.push(r),f.push([r,1]),p.set(r,t);let a=n.clone().add(new z(new Map([[r,-1]]),0));u.push(new I(a,`<=`,i,`${e.name}_slack`))}else if(r===`>=`){let r=new H({name:`__slack_${++m}`,type:`Continuous`,lb:0,ub:1/0});d.push(r),f.push([r,1]),p.set(r,t);let a=n.clone().add(new z(new Map([[r,1]]),0));u.push(new I(a,`>=`,i,`${e.name}_slack`))}else{let r=new H({name:`__slack_${++m}_p`,type:`Continuous`,lb:0,ub:1/0}),a=new H({name:`__slack_${++m}_n`,type:`Continuous`,lb:0,ub:1/0});d.push(r,a),f.push([r,1],[a,1]),p.set(r,t),p.set(a,t);let o=n.clone().add(new z(new Map([[r,-1],[a,1]]),0));u.push(new I(o,`==`,i,`${e.name}_slack`))}}let h={name:`${this.name}_elastic_check`,sense:`Minimize`,objective:new z(new Map(f),0),constraints:u,variables:[...l.variables,...d]},g;try{g=await i.solve(h,o)}catch(e){throw this.activeOperationId===n&&this.clearSolutionFields(),e}this.ensureExecutionValid(r,n,`check`),this.runTime=g.runTime??0;let _=g.status,v=g.terminationStatus??_,y=this.hasPrimalFromResult(g),b=typeof g.objectiveValue==`number`&&Number.isFinite(g.objectiveValue)?g.objectiveValue:1/0,x=(_===`Optimal`||_===`Feasible`||y)&&b<=1e-5,S=typeof g.objectiveBound==`number`&&Number.isFinite(g.objectiveBound)&&g.objectiveBound>1e-5,C=!x&&(_===`Infeasible`||_===`Optimal`&&b>1e-5||S),w=x?`Sat`:C?`Unsat`:`Unknown`;this.status=w,this.terminationStatus=a.signal?.aborted||v===`Interrupted`?`Interrupted`:v===`Optimal`||v===`Feasible`||v===`Infeasible`?w:v,this.hasPrimalSolution=x,this.objectiveValue=null,this.objectiveBound=void 0,this.relativeGap=void 0,this.absoluteGap=void 0,this.solution=null,this._values.clear();let T={};if(x&&g.values){for(let e of this._variables){let t=g.values[e.name];if(typeof t==`number`&&Number.isFinite(t)){let n=this.normalizePrimalValue(e,t,i,a);e.value=n,this._values.set(e.name,n),s(T,e.name,n)}}for(let e of this._boolVars){let t=l.boolVarToBinary.get(e),n=t?g.values[t.name]:g.values[e.name];if(typeof n==`number`&&Number.isFinite(n)){let t=Math.round(n)===1;e.value=t,this._values.set(e.name,t),s(T,e.name,t)}}}let E=new Set;if(C&&g.values)for(let[e,t]of p.entries()){let n=g.values[e.name];typeof n==`number`&&n>1e-5&&E.add(t)}return this.conflicts=C?Object.freeze(Array.from(E)):void 0,this.unsatCore=void 0,this.hasSolutionState=!0,{status:w,values:T,conflicts:this.conflicts,unsatCore:this.unsatCore,runTime:this.runTime}}verify(e={}){return cr(this,e)}link(e){if(e instanceof w||typeof e==`object`&&e&&`quadTerms`in e)throw Error(`Linking constraint cannot be a quadratic expression.`);if(!(e instanceof I)&&(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().");this._linkingConstraints||=[];let t=e;return this._linkingConstraints.push(t),t}get linkingConstraints(){return this._linkingConstraints??[]}async solveBenders(e){let t=await Dr({master:this,...e});return this.decomposition=t,t}async solveColumnGeneration(e){let t=await br({master:this,...e});return this.decomposition=t,t}};return e.BoolExpr=s,e.BoolOp=l,e.BoolVar=c,e.Constraint=I,e.GlobalConstraint=h,e.LinExpr=z,e.MockSolver=rt,e.Model=zr,e.QuadExpr=w,e.Var=H,e.abs=_e,e.allowed=S,e.and=u,e.at=V,e.buildIndicatorLinearization=pr,e.buildLpSymbolMaps=qe,e.cumulative=x,e.deriveBigMForGe=fr,e.deriveBigMForLe=dr,e.disjoint=b,e.distinct=v,e.dot=ge,e.expr=We,e.generateLpString=Je,e.getSolver=tt,e.implies=p,e.isLpExportResult=Ge,e.linearizeModelForMip=_r,e.listAvailableSolvers=nt,e.max=be,e.maximize=Sr,e.min=xe,e.minimize=Cr,e.normalizeSense=i,e.not=f,e.or=d,e.parseConstraint=Be,e.parseExpr=Re,e.registerSolver=$e,e.sanitizeIdentifier=Ke,e.setDefaultSolver=et,e.solveBenders=Dr,e.solveColumnGeneration=br,e.sum=B,e.validateUserBigM=lr,e.xor=m,e})({});