@ohtaman/washi 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.ja.md +149 -121
- package/README.md +149 -121
- package/README.zh-CN.md +150 -122
- package/THIRD_PARTY_LICENSES.md +3 -4
- package/dist/browser/_washi-node-only-BvRk9kiK.js +0 -0
- package/dist/browser/browser-runtime-TLCY0hkc.js +1793 -0
- package/dist/browser/highs-worker.js +21 -3
- package/dist/browser/highs.wasm +0 -0
- package/dist/browser/highs.wasm.LICENSE +1 -2
- package/dist/browser/loader-DewlSho8.js +643 -0
- package/dist/browser/solvers/glpk.js +433 -286
- package/dist/browser/solvers/glpk.min.js +1 -1
- package/dist/browser/solvers/z3.js +1008 -981
- package/dist/browser/solvers/z3.min.js +2 -2
- package/dist/browser/washi.js +2778 -673
- package/dist/browser/washi.min.js +3 -4
- package/dist/lib/_washi-node-only-BvRk9kiK.js +0 -0
- package/dist/lib/highs-browser-runtime.js +2120 -4124
- package/dist/lib/highs-node-runtime.js +24 -1
- package/dist/lib/highs-runtime.js +2 -0
- package/dist/lib/highs-worker.js +21 -3
- package/dist/lib/highs.wasm +0 -0
- package/dist/lib/highs.wasm.LICENSE +1 -2
- package/dist/lib/loader-BZUQNvh4.js +649 -0
- package/dist/lib/registry-C20sxTwm.js +964 -0
- package/dist/lib/solvers/glpk.js +201 -90
- package/dist/lib/solvers/z3.js +399 -259
- package/dist/lib/washi.js +2363 -1056
- package/dist/types/decomposition/benders.d.ts +32 -0
- package/dist/types/decomposition/benders.d.ts.map +1 -0
- package/dist/types/decomposition/column-generation.d.ts +34 -0
- package/dist/types/decomposition/column-generation.d.ts.map +1 -0
- package/dist/types/decomposition/index.d.ts +4 -0
- package/dist/types/decomposition/index.d.ts.map +1 -0
- package/dist/types/decomposition/types.d.ts +230 -0
- package/dist/types/decomposition/types.d.ts.map +1 -0
- package/dist/types/index.d.ts +5 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/modeler/big-m.d.ts +75 -0
- package/dist/types/modeler/big-m.d.ts.map +1 -0
- package/dist/types/modeler/boolean-expr.d.ts +103 -14
- package/dist/types/modeler/boolean-expr.d.ts.map +1 -1
- package/dist/types/modeler/constraint.d.ts +47 -9
- package/dist/types/modeler/constraint.d.ts.map +1 -1
- package/dist/types/modeler/expression.d.ts +123 -28
- package/dist/types/modeler/expression.d.ts.map +1 -1
- package/dist/types/modeler/index.d.ts +11 -6
- package/dist/types/modeler/index.d.ts.map +1 -1
- package/dist/types/modeler/linearizer.d.ts +15 -0
- package/dist/types/modeler/linearizer.d.ts.map +1 -0
- package/dist/types/modeler/lp-writer.d.ts +30 -3
- package/dist/types/modeler/lp-writer.d.ts.map +1 -1
- package/dist/types/modeler/model.d.ts +623 -131
- package/dist/types/modeler/model.d.ts.map +1 -1
- package/dist/types/modeler/objective.d.ts +59 -0
- package/dist/types/modeler/objective.d.ts.map +1 -0
- package/dist/types/modeler/parser.d.ts +34 -10
- package/dist/types/modeler/parser.d.ts.map +1 -1
- package/dist/types/modeler/quad-expr.d.ts +26 -7
- package/dist/types/modeler/quad-expr.d.ts.map +1 -1
- package/dist/types/modeler/solution-validator.d.ts +93 -0
- package/dist/types/modeler/solution-validator.d.ts.map +1 -0
- package/dist/types/modeler/solvers/glpk/solver.d.ts +26 -2
- package/dist/types/modeler/solvers/glpk/solver.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/browser-runtime.d.ts +2 -1
- package/dist/types/modeler/solvers/highs/browser-runtime.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/driver.d.ts +232 -0
- package/dist/types/modeler/solvers/highs/driver.d.ts.map +1 -0
- package/dist/types/modeler/solvers/highs/index.d.ts +1 -0
- package/dist/types/modeler/solvers/highs/index.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/loader.d.ts +38 -13
- package/dist/types/modeler/solvers/highs/loader.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/node-runtime.d.ts +2 -1
- package/dist/types/modeler/solvers/highs/node-runtime.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/solver.d.ts +12 -5
- package/dist/types/modeler/solvers/highs/solver.d.ts.map +1 -1
- package/dist/types/modeler/solvers/highs/worker-client.d.ts.map +1 -1
- package/dist/types/modeler/solvers/mock.d.ts +14 -5
- package/dist/types/modeler/solvers/mock.d.ts.map +1 -1
- package/dist/types/modeler/solvers/types.d.ts +73 -11
- package/dist/types/modeler/solvers/types.d.ts.map +1 -1
- package/dist/types/modeler/solvers/z3/loader.d.ts +2 -3
- package/dist/types/modeler/solvers/z3/loader.d.ts.map +1 -1
- package/dist/types/modeler/solvers/z3/solver.d.ts +15 -5
- package/dist/types/modeler/solvers/z3/solver.d.ts.map +1 -1
- package/dist/types/modeler/types.d.ts +86 -1
- package/dist/types/modeler/types.d.ts.map +1 -1
- package/dist/types/modeler/validation.d.ts +56 -0
- package/dist/types/modeler/validation.d.ts.map +1 -0
- package/dist/types/modeler/variable.d.ts +48 -14
- package/dist/types/modeler/variable.d.ts.map +1 -1
- package/docs/examples/diet-sensitivity.md +90 -0
- package/docs/examples/ecommerce-coupons.md +106 -0
- package/docs/examples/index.md +57 -0
- package/docs/examples/knapsack.md +60 -0
- package/docs/examples/portfolio-qp.md +83 -0
- package/docs/examples/production.md +51 -0
- package/docs/examples/shift-scheduling.md +175 -0
- package/docs/examples/smt-security.md +74 -0
- package/docs/examples/transportation.md +90 -0
- package/docs/examples/traveling-salesperson.md +173 -0
- package/docs/examples/unsat-core.md +64 -0
- package/docs/examples/vehicle-routing.md +206 -0
- package/docs/getting-started/ai-agents.md +271 -0
- package/docs/getting-started/cross-origin.md +87 -0
- package/docs/getting-started/index.md +116 -0
- package/docs/getting-started/runtimes.md +227 -0
- package/docs/guide/constraints.md +177 -0
- package/docs/guide/decomposition.md +399 -0
- package/docs/guide/expressions.md +204 -0
- package/docs/guide/objectives.md +170 -0
- package/docs/guide/unsat-core.md +154 -0
- package/docs/guide/variables.md +188 -0
- package/docs/ja/getting-started/ai-agents.md +270 -0
- package/docs/solvers/custom-solver.md +525 -0
- package/docs/solvers/glpk.md +66 -0
- package/docs/solvers/highs.md +115 -0
- package/docs/solvers/index.md +42 -0
- package/docs/solvers/z3.md +78 -0
- package/docs/zh/getting-started/ai-agents.md +270 -0
- package/llms-full.txt +4065 -0
- package/llms.txt +201 -0
- package/package.json +32 -16
- package/skills/washi/SKILL.md +197 -0
- package/dist/browser/browser-runtime-D13gHOT5.js +0 -4189
- package/dist/browser/loader-CVt4CloI.js +0 -58
- package/dist/lib/async-mutex-Duo4jwzn.js +0 -195
- package/dist/lib/constraint-BRuB3ooC.js +0 -90
- package/dist/lib/loader-Dti0v9yC.js +0 -50
- package/dist/lib/registry-DksqCSjI.js +0 -32
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
var Washi=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,s=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},c=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),l=(e,t)=>{let r={};for(var i in e)n(r,i,{get:e[i],enumerable:!0});return t||n(r,Symbol.toStringTag,{value:`Module`}),r},u=(e,t,a,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=i(t),l=0,u=c.length,d;l<u;l++)d=c[l],!o.call(e,d)&&d!==a&&n(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(s=r(t,d))||s.enumerable});return e},d=(e,r,i)=>(i=e==null?{}:t(a(e)),u(r||!e||!e.__esModule||!o.call(e,`default`)?n(i,`default`,{value:e,enumerable:!0}):i,e));function f(e){return e&&e.toLowerCase()===`maximize`?`Maximize`:`Minimize`}var p=0,m=class{and(e){return new g(`and`,[this,e])}or(e){return new g(`or`,[this,e])}implies(e){return new g(`implies`,[this,e])}xor(e){return new g(`xor`,[this,e])}not(){return new g(`not`,[this])}},h=class extends m{id;name;value=null;constructor(e){super(),this.id=++p,this.name=e||`p_${this.id}`}toString(){return this.name}},g=class extends m{op;children;constructor(e,t){super(),this.op=e,this.children=t}toString(){return this.op===`not`?`not(${this.children[0].toString()})`:`(${this.children.map(e=>e.toString()).join(` ${this.op} `)})`}};function _(...e){if(e.length===0)throw Error(`and() requires at least one expression`);return new g(`and`,e)}function v(...e){if(e.length===0)throw Error(`or() requires at least one expression`);return new g(`or`,e)}function y(e){return new g(`not`,[e])}function b(e,t){return new g(`implies`,[e,t])}function x(...e){if(e.length===0)throw Error(`xor() requires at least one expression`);return new g(`xor`,e)}var S=0,C=class{id;lhs;sense;rhs;name;slack=null;dual=null;constructor(e,t,n,r){this.id=++S,this.lhs=e,this.sense=t,this.rhs=n,this.name=r||`c_${this.id}`}and(e){return new g(`and`,[this,e])}or(e){return new g(`or`,[this,e])}implies(e){return new g(`implies`,[this,e])}xor(e){return new g(`xor`,[this,e])}not(){return new g(`not`,[this])}toString(){let e=this.sense===`==`?`=`:this.sense;return`${this.name}: ${this.lhs.toString()} ${e} ${this.rhs}`}};function w(e,t){let n=e.id,r=t.id;return n<=r?`${n}:${r}`:`${r}:${n}`}var T=class e{linearTerms;quadTerms;constant;constructor(e=new Map,t=new Map,n=0){this.linearTerms=new Map(e),this.quadTerms=new Map;for(let[e,n]of t)this.quadTerms.set(e,{...n});this.constant=n}clone(){return new e(this.linearTerms,this.quadTerms,this.constant)}getQuadCoeff(e,t){let n=w(e,t),r=this.quadTerms.get(n);return r?r.coeff:0}add(t){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;Math.abs(i)<1e-12?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;Math.abs(t)<1e-12?n.linearTerms.delete(e):n.linearTerms.set(e,t)}return n.constant+=t.constant,n}if(`terms`in t&&t.terms instanceof Map){for(let[e,r]of t.terms){let t=(n.linearTerms.get(e)||0)+r;Math.abs(t)<1e-12?n.linearTerms.delete(e):n.linearTerms.set(e,t)}return n.constant+=t.constant,n}let r=t,i=(n.linearTerms.get(r)||0)+1;return Math.abs(i)<1e-12?n.linearTerms.delete(r):n.linearTerms.set(r,i),n}sub(t){return typeof t==`number`?this.add(-t):t instanceof e?this.add(t.neg()):(`terms`in t&&t.terms instanceof Map,this.add(t.mul(-1)))}mul(t){if(typeof t==`number`){let n=new e(new Map,new Map,this.constant*t);for(let[e,r]of this.linearTerms){let i=r*t;Math.abs(i)>=1e-12&&n.linearTerms.set(e,i)}for(let[e,r]of this.quadTerms){let i=r.coeff*t;Math.abs(i)>=1e-12&&n.quadTerms.set(e,{var1:r.var1,var2:r.var2,coeff:i})}return n}if(`id`in t&&`name`in t&&!(`terms`in t)&&!(`quadTerms`in t)){if(this.quadTerms.size>0)throw Error(`Multiplication creates a non-linear term of degree > 2 (not allowed in MILP/LP/QP)`);let n=new e;Math.abs(this.constant)>=1e-12&&n.linearTerms.set(t,this.constant);for(let[r,i]of this.linearTerms)n=n.add(e.fromProduct(r,t,i));return n}let n=t,r=`quadTerms`in n?n.quadTerms.size:0,i=`quadTerms`in n?n.linearTerms:n.terms;if(this.quadTerms.size>0&&(r>0||i.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&&i.size===0)return this.mul(n.constant);if(this.quadTerms.size===0&&this.linearTerms.size===0){let t=n.mul(this.constant);if(t instanceof e)return t;let r=new e;r.constant=t.constant;for(let[e,n]of t.terms)r.linearTerms.set(e,n);return r}let a=new e;if(a.constant=this.constant*n.constant,Math.abs(n.constant)>=1e-12)for(let[e,t]of this.linearTerms)a.linearTerms.set(e,(a.linearTerms.get(e)||0)+t*n.constant);if(Math.abs(this.constant)>=1e-12)for(let[e,t]of i)a.linearTerms.set(e,(a.linearTerms.get(e)||0)+t*this.constant);for(let[t,n]of this.linearTerms)for(let[r,o]of i)a=a.add(e.fromProduct(t,r,n*o));return a}div(e){if(Math.abs(e)<1e-12)throw Error(`Division by zero in QuadExpr.div()`);return this.mul(1/e)}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}return e}getValue(){return this.value}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.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,a=w(t,n);return i.quadTerms.set(a,{var1:t.id<=n.id?t:n,var2:t.id<=n.id?n:t,coeff:r}),i}},E=class e{terms;constant;constructor(e=new Map,t=0){this.terms=new Map(e),this.constant=t}clone(){return new e(this.terms,this.constant)}add(e){if(e instanceof T)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;Math.abs(e)<1e-12?t.terms.delete(n):t.terms.set(n,e)}t.constant+=e.constant}else{let n=(t.terms.get(e)||0)+1;Math.abs(n)<1e-12?t.terms.delete(e):t.terms.set(e,n)}return t}sub(e){return e instanceof T?e.neg().add(this):typeof e==`number`?this.add(-e):(`terms`in e,this.add(e.mul(-1)))}mul(t){if(typeof t==`number`){let n=new e(new Map,this.constant*t);for(let[e,r]of this.terms){let i=r*t;Math.abs(i)>=1e-12&&n.terms.set(e,i)}return n}if(t instanceof k||typeof t==`object`&&t&&`id`in t&&!(`terms`in t)&&!(`quadTerms`in t)){let e=t,n=new T;Math.abs(this.constant)>=1e-12&&n.linearTerms.set(e,this.constant);for(let[t,r]of this.terms)n=n.add(T.fromProduct(t,e,r));return n}if(t instanceof T){if(t.quadTerms.size>0&&this.terms.size>0)throw Error(`Multiplication creates a non-linear term of degree > 2 (not allowed in MILP/LP/QP)`);if(this.terms.size===0)return t.mul(this.constant);let e=new T;if(e.constant=this.constant*t.constant,Math.abs(t.constant)>=1e-12)for(let[n,r]of this.terms)e.linearTerms.set(n,(e.linearTerms.get(n)||0)+r*t.constant);if(Math.abs(this.constant)>=1e-12)for(let[n,r]of t.linearTerms)e.linearTerms.set(n,(e.linearTerms.get(n)||0)+r*this.constant);for(let[n,r]of this.terms)for(let[i,a]of t.linearTerms)e=e.add(T.fromProduct(n,i,r*a));return e}if(this.terms.size===0)return t.mul(this.constant);if(t.terms.size===0)return this.mul(t.constant);let n=new T;if(n.constant=this.constant*t.constant,Math.abs(t.constant)>=1e-12)for(let[e,r]of this.terms)n.linearTerms.set(e,(n.linearTerms.get(e)||0)+r*t.constant);if(Math.abs(this.constant)>=1e-12)for(let[e,r]of t.terms)n.linearTerms.set(e,(n.linearTerms.get(e)||0)+r*this.constant);for(let[e,r]of this.terms)for(let[i,a]of t.terms)n=n.add(T.fromProduct(e,i,r*a));return n}div(e){if(Math.abs(e)<1e-12)throw Error(`Division by zero in LinExpr.div()`);return this.mul(1/e)}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}return e}getValue(){return this.value}le(e,t){return this.toConstraint(`<=`,e,t)}lessThanOrEqual(e,t){return this.le(e,t)}ge(e,t){return this.toConstraint(`>=`,e,t)}greaterThanOrEqual(e,t){return this.ge(e,t)}eq(e,t){return this.toConstraint(`==`,e,t)}equalTo(e,t){return this.eq(e,t)}toConstraint(t,n,r){let i=this.clone(),a=0;typeof n==`number`?a=n:`terms`in n?(i=i.sub(new e(n.terms,0)),a=n.constant):i=i.sub(n);let o=a-i.constant;return i.constant=0,new C(i,t,o,r)}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}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 ee(e,t){let n=new Map,r=0;function i(e){if(e!=null){if(typeof e==`number`)r+=e;else if(typeof e==`object`&&`terms`in e){let t=e;for(let[e,r]of t.terms){let t=n.get(e)||0;n.set(e,t+r)}r+=t.constant}else{let t=e,r=n.get(t)||0;n.set(t,r+1)}}}if(typeof e==`number`){let n=e,r=t;for(let e=0;e<n;e++)i(r(e,e))}else{let n=0;for(let r of e)i(t?t(r,n++):r)}for(let[e,t]of n)Math.abs(t)<1e-12&&n.delete(e);return new E(n,r)}function D(e,t){let n=new Map,r=0;function i(e){return typeof e==`object`&&!!e&&typeof e.id==`number`&&typeof e.name==`string`&&typeof e.mul==`function`&&typeof e.le==`function`}function a(e){return i(e)||e instanceof E||e instanceof T}function o(e,t){if(typeof t==`number`)r+=e*t;else if(t instanceof E){for(let[r,i]of t.terms){let t=n.get(r)||0;n.set(r,t+e*i)}r+=e*t.constant}else if(i(t)){let r=t,i=n.get(r)||0;n.set(r,i+e)}else throw Error(`Cannot multiply number by non-variable/expression operand in dot().`)}function s(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!a(e)}function c(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`){o(e,t);return}if(typeof t==`number`){o(t,e);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++)c(e[r],t[r],n?`${n}[${r}]`:`[${r}]`);return}let r=Array.isArray(e)?e:t,i=Array.isArray(e)?t:e;if(s(i)){let a=Object.keys(i);if(a.length>0&&a.every(e=>/^\d+$/.test(e))){if(a.length!==r.length)throw Error(`Array length mismatch in dot() at '${n||`root`}': array has length ${r.length}, but object has ${a.length} indices.`);let o=[];for(let e=0;e<r.length;e++)!(e in i)&&!(String(e)in i)&&o.push(e);if(o.length>0)throw Error(`Key mismatch in dot() at '${n||`root`}': missing indices [${o.join(`, `)}] in numeric record.`);for(let i=0;i<r.length;i++)c(e[i],t[i],n?`${n}[${i}]`:`[${i}]`);return}throw Error(`Type mismatch in dot() at '${n||`root`}': one operand is an Array while the other is an Object with keys [${a.slice(0,5).join(`, `)}].`)}throw Error(`Type mismatch in dot() at '${n||`root`}': one operand is an Array while the other is not.`)}if(s(e)&&s(t)){let r=Object.keys(e),i=Object.keys(t),a=r.filter(e=>!(e in t)),o=i.filter(t=>!(t in e));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)c(e[i],t[i],n?`${n}.${i}`:i);return}throw Error(`Unsupported operand types in dot() at '${n||`root`}'.`)}c(e,t);for(let[e,t]of n)Math.abs(t)<1e-12&&n.delete(e);return new E(n,r)}var O=0;function te(e){if(!e)return`Continuous`;let t=e.toLowerCase();return t===`binary`||t===`bin`?`Binary`:t===`integer`||t===`int`?`Integer`:`Continuous`}var k=class e{id;name;type;lb;ub;value=null;reducedCost=null;constructor(e={}){this.id=++O,this.name=e.name||`x_${this.id}`,this.type=te(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)}mul(t){if(typeof t==`number`)return new E(new Map([[this,t]]),0);if(t instanceof e)return T.fromProduct(this,t,1);if(t instanceof T){if(t.quadTerms.size>0)throw Error(`Multiplication creates a non-linear term of degree > 2 (not allowed in MILP/LP/QP)`);let e=new T;Math.abs(t.constant)>=1e-12&&e.linearTerms.set(this,t.constant);for(let[n,r]of t.linearTerms)e=e.add(T.fromProduct(this,n,r));return e}let n=new T;Math.abs(t.constant)>=1e-12&&n.linearTerms.set(this,t.constant);for(let[e,r]of t.terms){let t=T.fromProduct(this,e,r);n=n.add(t)}return n}add(e){return e instanceof T?e.add(this):new E(new Map([[this,1]]),0).add(e)}sub(e){return e instanceof T?e.neg().add(this):new E(new Map([[this,1]]),0).sub(e)}neg(){return this.mul(-1)}le(e,t){return new E(new Map([[this,1]]),0).le(e,t)}lessThanOrEqual(e,t){return this.le(e,t)}ge(e,t){return new E(new Map([[this,1]]),0).ge(e,t)}greaterThanOrEqual(e,t){return this.ge(e,t)}eq(e,t){return new E(new Map([[this,1]]),0).eq(e,t)}equalTo(e,t){return this.eq(e,t)}toString(){return this.name}};function A(e){let t=[],n=0,r=e.length;for(;n<r;){let i=e[n];if(/\s/.test(i)){n++;continue}if(i===`+`)t.push({type:`PLUS`,value:`+`}),n++;else if(i===`-`)t.push({type:`MINUS`,value:`-`}),n++;else if(i===`*`)n+1<r&&e[n+1]===`*`?(t.push({type:`CARET`,value:`**`}),n+=2):(t.push({type:`STAR`,value:`*`}),n++);else if(i===`^`)t.push({type:`CARET`,value:`^`}),n++;else if(i===`/`)t.push({type:`SLASH`,value:`/`}),n++;else if(i===`(`)t.push({type:`LPAREN`,value:`(`}),n++;else if(i===`)`)t.push({type:`RPAREN`,value:`)`}),n++;else if(i===`<`||i===`>`||i===`=`){let a=i;n+1<r&&(e[n+1]===`=`||e[n+1]===`<`||e[n+1]===`>`)?(a+=e[n+1],n+=2):n++,t.push({type:`COMP`,value:a})}else if(/[0-9.]/.test(i)){let i=``;for(;n<r&&/[0-9.]/.test(e[n]);)i+=e[n],n++;t.push({type:`NUMBER`,value:i})}else if(/[a-zA-Z_]/.test(i)){let i=``;for(;n<r&&/[a-zA-Z0-9_]/.test(e[n]);)i+=e[n],n++;t.push({type:`IDENT`,value:i})}else throw Error(`Unexpected character '${i}' at position ${n} in: "${e}"`)}return t}function j(e,t){return e instanceof T?e.add(t):t instanceof T?t.add(e):e.add(t)}function M(e,t){return e instanceof T?e.sub(t):t instanceof T?t.neg().add(e):e.sub(t)}function N(e,t){let n=e instanceof T?e.quadTerms:new Map,r=t instanceof T?t.quadTerms:new Map,i=e instanceof T?e.linearTerms:e.terms,a=t instanceof T?t.linearTerms:t.terms;if(n.size>0&&(r.size>0||a.size>0)||r.size>0&&(n.size>0||i.size>0))throw Error(`Multiplication creates a non-linear term of degree > 2 (not allowed in MILP/LP/QP)`);if(n.size===0&&i.size===0)return t.mul(e.constant);if(r.size===0&&a.size===0)return e.mul(t.constant);let o=new T;if(o.constant=e.constant*t.constant,Math.abs(t.constant)>=1e-12)for(let[e,n]of i)o.linearTerms.set(e,(o.linearTerms.get(e)||0)+n*t.constant);if(Math.abs(e.constant)>=1e-12)for(let[t,n]of a)o.linearTerms.set(t,(o.linearTerms.get(t)||0)+n*e.constant);for(let[e,t]of i)for(let[n,r]of a)o=o.add(T.fromProduct(e,n,t*r));return o}var P=class{tokens;pos=0;resolver;constructor(e,t){this.tokens=e,this.resolver=t}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.parseTerm();for(;this.pos<this.tokens.length;){let t=this.peek();if(!t)break;if(t.type===`PLUS`)this.consume(),e=j(e,this.parseTerm());else if(t.type===`MINUS`)this.consume(),e=M(e,this.parseTerm());else break}return e instanceof T&&e.quadTerms.size===0?new E(e.linearTerms,e.constant):e}parseTerm(){let e=this.parseFactor();for(;this.pos<this.tokens.length;){let t=this.peek();if(!t)break;if(t.type===`STAR`){this.consume();let t=this.parseFactor();e=N(e,t)}else if(t.type===`SLASH`){this.consume();let t=this.parseFactor(),n=t instanceof T?t.linearTerms:t.terms,r=t instanceof T?t.quadTerms.size:0;if(n.size>0||r>0)throw Error(`Cannot divide by variable in expression`);if(Math.abs(t.constant)<1e-12)throw Error(`Division by zero in expression`);e=e.div(t.constant)}else break}return e}parseFactor(){let e=this.peek();if(!e)throw Error(`Unexpected end of expression`);if(e.type===`PLUS`)return this.consume(),this.parseFactor();if(e.type===`MINUS`)return this.consume(),this.parseFactor().neg();let t;if(e.type===`NUMBER`){this.consume();let n=parseFloat(e.value);if(this.peek()?.type===`IDENT`||this.peek()?.type===`LPAREN`){let e;if(this.peek()?.type===`IDENT`){let t=this.consume(),n=this.resolve(t.value);e=n instanceof k||`id`in n&&!(`terms`in n)&&!(`quadTerms`in n)?new E(new Map([[n,1]]),0):n.clone()}else this.consume(`LPAREN`),e=this.parseExpression(),this.consume(`RPAREN`);return this.applyPower(e).mul(n)}t=new E(new Map,n)}else if(e.type===`IDENT`){this.consume();let n=this.resolve(e.value);t=n instanceof k||`id`in n&&!(`terms`in n)&&!(`quadTerms`in n)?new E(new Map([[n,1]]),0):n.clone()}else if(e.type===`LPAREN`)this.consume(`LPAREN`),t=this.parseExpression(),this.consume(`RPAREN`);else throw Error(`Unexpected token '${e.value}' in expression`);return this.applyPower(t)}applyPower(e){if(this.peek()?.type!==`CARET`)return e;let t=[];for(;this.peek()?.type===`CARET`;){this.consume();let e=this.peek();if(!e||e.type!==`NUMBER`)throw Error(`Exponent must be a non-negative integer number`);this.consume();let n=parseFloat(e.value);if(!Number.isInteger(n)||n<0)throw Error(`Exponent must be a non-negative integer`);t.push(n)}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`);let r=e instanceof T,i=r?e.quadTerms.size:0,a=r?e.linearTerms.size:e.terms.size;if(i===0&&a===0){let t=e.constant**+n;return new E(new Map,t)}if(n===0)return new E(new Map,1);if(n===1)return e;if(n===2)return N(e,e);throw Error(`Exponent ${n} creates a non-linear term of degree > 2 (not allowed in MILP/LP/QP)`)}getRemainingToken(){return this.peek()}resolve(e){let t=this.resolver(e);if(!t)throw Error(`Unknown variable '${e}' in expression`);return t}};function F(e,t){let n=new P(A(e),t),r=n.parseExpression(),i=n.getRemainingToken();if(i)throw Error(`Unexpected token '${i.value}' after expression in "${e}"`);return r}function I(e,t,n){let r=e.match(/(<=|>=|==|=<|=>|=)/);if(!r)throw Error(`Constraint must contain a comparison operator (<=, >=, ==, =): "${e}"`);let i=r[0],a=r.index,o=e.substring(0,a).trim(),s=e.substring(a+i.length).trim(),c;if(i===`<=`||i===`=<`)c=`<=`;else if(i===`>=`||i===`=>`)c=`>=`;else if(i===`==`||i===`=`)c=`==`;else throw Error(`Unsupported operator "${i}"`);let l=F(o,t),u=F(s,t);if(l instanceof T&&l.quadTerms.size>0||u instanceof T&&u.quadTerms.size>0)throw Error(`Quadratic constraints are not supported (only linear constraints are allowed in MILP/LP/QP)`);let d=l instanceof T?new E(l.linearTerms,l.constant):l,f=u instanceof T?new E(u.linearTerms,u.constant):u;return c===`<=`?d.le(f,n):c===`>=`?d.ge(f,n):d.eq(f,n)}function L(e,t){let n=new Map,r=``;for(let i=0;i<e.length;i++)if(r+=e[i],i<t.length){let e=t[i];if(typeof e==`number`)r+=`(${e})`;else if(e instanceof k||e instanceof E||e instanceof T||typeof e==`object`&&e&&(`id`in e||`terms`in e||`quadTerms`in e)){let t=`__ph_${i}__`;n.set(t,e),r+=t}}return{fullText:r,resolver:e=>n.get(e)}}function ne(e,...t){let{fullText:n,resolver:r}=L(e,t);return I(n,r)}function R(e,...t){let{fullText:n,resolver:r}=L(e,t);return/(<=|>=|==|=<|=>|=)/.test(n)?I(n,r):F(n,r)}function re(e,t,n){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 ie(e){let{sense:t,objective:n,constraints:r,variables:i}=e,a=new Map,o=new Map,s=new Map,c=new Set;for(let e of i){let t=re(e.name,`x`,e.id),n=t,r=1;for(;c.has(n);)n=`${t}_${r++}`;c.add(n),o.set(e,n),a.set(n,e)}let l=new Set,u=new Map;for(let e of r){let t=re(e.name,`c`,e.id),n=t,r=1;for(;l.has(n);)n=`${t}_${r++}`;l.add(n),u.set(e,n),s.set(n,e)}let d=[];d.push(t&&t.toLowerCase()===`maximize`?`Maximize`:`Minimize`);let f=[],p=!0,m=n instanceof T?n.linearTerms:n.terms;if(m)for(let[e,t]of m){if(Math.abs(t)<1e-12)continue;let n=o.get(e),r=t>=0?p?``:`+ `:`- `,i=Math.abs(t),a=i===1?``:`${i} `;f.push(`${r}${a}${n}`),p=!1}if(n instanceof T&&n.quadTerms.size>0){let e=[],t=!0;for(let r of n.quadTerms.values()){if(Math.abs(r.coeff)<1e-12)continue;let n=2*r.coeff,i=n>=0?t?``:`+ `:`- `,a=Math.abs(n),s=a===1?``:`${a} `,c=o.get(r.var1),l=o.get(r.var2);r.var1===r.var2?e.push(`${i}${s}${c} ^ 2`):e.push(`${i}${s}${c} * ${l}`),t=!1}if(e.length>0){let t=`[ ${e.join(` `)} ] / 2`;f.length>0?f.push(`+`,t):f.push(t)}}let h=f.length>0?f.join(` `):`0`;d.push(` obj: ${h}`),d.push(`Subject To`);for(let e of r){let t=u.get(e),n=[],r=!0;for(let[t,i]of e.lhs.terms){if(Math.abs(i)<1e-12)continue;let e=o.get(t),a=i>=0?r?``:`+ `:`- `,s=Math.abs(i),c=s===1?``:`${s} `;n.push(`${a}${c}${e}`),r=!1}let i=n.length>0?n.join(` `):`0`,a=e.sense===`==`?`=`:e.sense;d.push(` ${t}: ${i} ${a} ${e.rhs}`)}d.push(`Bounds`);let g=[],_=[];for(let e of i){let t=o.get(e);if(e.type===`Binary`){_.push(t);continue}e.type===`Integer`&&g.push(t);let n=e.lb===-1/0,r=e.ub===1/0;n&&r?d.push(` ${t} free`):n&&!r?d.push(` -infinity <= ${t} <= ${e.ub}`):!n&&r?e.lb!==0&&d.push(` ${t} >= ${e.lb}`):d.push(` ${e.lb} <= ${t} <= ${e.ub}`)}if(g.length>0){d.push(`Generals`);for(let e=0;e<g.length;e+=10)d.push(` `+g.slice(e,e+10).join(` `))}if(_.length>0){d.push(`Binary`);for(let e=0;e<_.length;e+=10)d.push(` `+_.slice(e,e+10).join(` `))}return d.push(`End`),{lpString:d.join(`
|
|
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 g)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;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=0,g=class e{kind=`constraint`;id;_lhs;_sense;_rhs;_name;hasExplicitName;ownerModel=null;slack=null;dual=null;addTerm(e,t){return t===0?this:(this._lhs.addTerm(e,t),this.ownerModel?.notifyMutation?.(),this)}setTerm(e,t){return this._lhs.setTerm(e,t),this.ownerModel?.notifyMutation?.(),this}constructor(e,t,n,r){this.id=++h,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._lhs=e,this.ownerModel?.notifyMutation?.())}get sense(){return this._sense}set sense(e){this._sense!==e&&(this._sense=e,this.ownerModel?.notifyMutation?.())}get rhs(){return this._rhs}set rhs(e){Object.is(this._rhs,e)||(this._rhs=e,this.ownerModel?.notifyMutation?.())}get name(){return this._name}set name(e){this._name!==e&&(this._name=e,this.ownerModel?.notifyMutation?.()),this.hasExplicitName=!0}_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.`)}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(){return new e(this._lhs.clone(),this._sense,this._rhs,this.hasExplicitName?this._name:void 0)}toString(){let e=this.sense===`==`?`=`:this.sense;return`${this.name}: ${this.lhs.toString()} ${e} ${this.rhs}`}};function _(e){return e instanceof g||typeof e==`object`&&!!e&&`sense`in e&&`lhs`in e&&`rhs`in e}function v(e,t){let n=e.id,r=t.id;return n<=r?`${n}:${r}`:`${r}:${n}`}var y=class e{kind=`quadratic`;linearTerms;quadTerms;constant;constructor(e=new Map,t=new Map,n=0){this.linearTerms=new Map(e),this.quadTerms=new Map;for(let[e,n]of t)this.quadTerms.set(e,{...n});this.constant=n}clone(){return new e(this.linearTerms,this.quadTerms,this.constant)}getQuadCoeff(e,t){let n=v(e,t),r=this.quadTerms.get(n);return r?r.coeff:0}add(t){if(_(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)}return n.constant+=t.constant,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)}return n.constant+=t.constant,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(_(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(_(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,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})}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?new Map([[t,1]]):`quadTerms`in t?t.linearTerms:t.terms,a=n?0:t.constant;if(this.quadTerms.size>0&&(r>0||i.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&&i.size===0)return this.mul(a);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)}return e.multiplyLinearTerms(this.constant,this.linearTerms,a,i)}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}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)}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 b(this.linearTerms,this.constant);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.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=v(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(_(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;if(n>0||r>0)throw Error(`Cannot divide by variable in expression`);if(e.constant===0)throw Error(`Division by zero in ${t}`);return e.constant}},b=class e{kind=`linear`;terms;constant;constructor(e=new Map,t=0){this.terms=new Map(e),this.constant=t}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)}add(e){if(_(e))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);if(e instanceof y)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)}t.constant+=e.constant}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(_(e))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);return e instanceof y?e.neg().add(this):typeof e==`number`?this.add(-e):this.add(e.mul(-1))}mul(t){if(_(t))throw Error(`Cannot perform arithmetic on a Constraint: expected a number, Var, LinExpr, or QuadExpr.`);if(typeof t==`number`){let n=this.constant===0&&this.terms.size>0?0:this.constant*t;if(this.constant!==0&&t!==0&&n===0)throw Error(`Constant multiplication underflows to zero.`);let r=new e(new Map,n);for(let[e,n]of this.terms){let i=n*t;if(n!==0&&t!==0&&i===0)throw Error(`Coefficient multiplication underflows to zero.`);i!==0&&r.terms.set(e,i)}return r}return t instanceof P||typeof t==`object`&&t&&`id`in t&&!(`terms`in t)&&!(`quadTerms`in t)?y.multiplyLinearTerms(this.constant,this.terms,0,new Map([[t,1]])):t instanceof y?this.terms.size===0?t.mul(this.constant):new y(this.terms,new Map,this.constant).mul(t):this.terms.size===0?t.mul(this.constant):t.terms.size===0?this.mul(t.constant):y.multiplyLinearTerms(this.constant,this.terms,t.constant,t.terms)}div(e){let t=y.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}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)}toConstraint(t,n,r){let i=this.clone(),a=0;if(typeof n==`number`)a=n;else if(n instanceof g||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 y||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)),a=r.constant}else`terms`in n?(i=i.sub(new e(n.terms,0)),a=n.constant):i=i.sub(n);let o=a-i.constant;return i.constant=0,new g(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}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 x(e,t){let n=new Map,r=0;function i(e){if(e!=null){if(typeof e==`number`)r+=e;else if(e instanceof g||typeof e==`object`&&`sense`in e&&`lhs`in e&&`rhs`in e)throw Error(`Cannot sum a constraint comparison (<=, >=, ==) in sum(): expected a number, Var, or LinExpr.`);else if(e instanceof y||typeof e==`object`&&`quadTerms`in e&&e.quadTerms instanceof Map){let t=e;if(t.quadTerms.size>0)throw Error(`Quadratic expressions are not supported in sum(): sum() produces a linear expression (LinExpr).`);for(let[e,r]of t.linearTerms){let t=n.get(e)??0;n.set(e,t+r)}r+=t.constant}else if(typeof e==`object`&&`terms`in e){let t=e;for(let[e,r]of t.terms){let t=n.get(e)??0;n.set(e,t+r)}r+=t.constant}else if(typeof e==`object`&&`id`in e&&`name`in e&&`lb`in e&&`ub`in e){let t=e,r=n.get(t)??0;n.set(t,r+1)}else throw Error(`Unsupported item in sum(): expected a number, Var, or LinExpr.`)}}if(typeof e==`number`){let n=e,r=t;for(let e=0;e<n;e++)i(r(e,e))}else{let n=0;for(let r of e)i(t?t(r,n++):r)}for(let[e,t]of n)t===0&&n.delete(e);return new b(n,r)}function S(e,t){let n=new Map,r=0;function i(e){return typeof e==`object`&&!!e&&!(e instanceof g)&&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 a(e){return i(e)||e instanceof b||e instanceof y}function o(e,t,a){if(!Number.isFinite(e))throw Error(`Invalid non-finite coefficient "${e}" in dot() at '${a||`root`}'.`);if(t instanceof y)throw Error(`Quadratic expressions are not supported in dot() at '${a||`root`}': dot() produces a linear expression (LinExpr).`);if(t instanceof b){if(!Number.isFinite(t.constant))throw Error(`Invalid non-finite constant "${t.constant}" in dot() at '${a||`root`}'.`);let i=e===0||t.constant===0?0:e*t.constant;if(e!==0&&t.constant!==0&&i===0)throw Error(`Constant multiplication underflows to zero.`);if(!Number.isFinite(i))throw Error(`Coefficient multiplication overflows finite floating-point range in dot() at '${a||`root`}'.`);let o=r+i;if(!Number.isFinite(o))throw Error(`Constant accumulation overflows finite floating-point range in dot() at '${a||`root`}'.`);r=o;for(let[r,i]of t.terms){if(!Number.isFinite(i))throw Error(`Invalid non-finite coefficient "${i}" in dot() at '${a||`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 '${a||`root`}'.`);let o=(n.get(r)??0)+t;if(!Number.isFinite(o))throw Error(`Coefficient accumulation overflows finite floating-point range in dot() at '${a||`root`}'.`);n.set(r,o)}}else if(i(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 '${a||`root`}'.`);n.set(r,i)}else throw Error(`Cannot multiply number by non-variable/expression operand in dot() at '${a||`root`}'.`)}function s(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!a(e)&&!(e instanceof g)&&e.kind!==`constraint`}function c(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`){o(e,t,n);return}if(typeof t==`number`){o(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++)c(e[r],t[r],n?`${n}[${r}]`:`[${r}]`);return}let r=Array.isArray(e)?e:t,i=Array.isArray(e)?t:e;if(s(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++)c(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(s(e)&&s(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)c(e[i],t[i],n?`${n}.${i}`:i);return}throw Error(`Unsupported operand types in dot() at '${n||`root`}'.`)}c(e,t);for(let[e,t]of n)t===0&&n.delete(e);return new b(n,r)}var C=new WeakMap,w=new WeakMap,T=new WeakMap;function E(e,t,n){if(e instanceof l)for(let r of e.children)E(r,t,n);else if(e instanceof g){let r=e.ownerModel,i=w.get(e);(r!==t||i!==t)&&(n&&n.push(()=>{e.ownerModel=r,i?w.set(e,i):w.delete(e)}),e.ownerModel=t,w.set(e,t))}}function D(e,t){let n=C.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}".`);C.set(e,t)}function O(e,t){let n=T.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=w.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 T.set(e,t),w.set(e,t),r}function k(e,t){C.get(e)===t&&C.delete(e)}function A(e,t,n){T.get(e)===t&&T.delete(e),w.get(e)===t&&(n?w.set(e,n):w.delete(e))}var ee=1e-6;function te(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 ${ee}).`);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 ${ee} of an integer in [${t}, ${n}]).`)}}}function ne(e){if(e.initialValue===void 0)return;if(te(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 re(e,t,n){if(e instanceof y){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}.`)}}else if(`terms`in e){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.terms){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.`)}}}function j(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(e.lhs.constant!==void 0&&!Number.isFinite(e.lhs.constant))throw Error(`Constraint "${r}" has invalid LHS constant: ${e.lhs.constant}. Constant must be a finite number.`);for(let[i,a]of e.lhs.terms){if(!n(i))throw Error(`Variable "${i.name}" in constraint "${r}" does not belong to model "${t}". All variables must belong to the model by object identity.`);if(!Number.isFinite(a))throw Error(`Variable "${i.name}" in constraint "${r}" has invalid coefficient: ${a}. Coefficients must be finite numbers.`)}}function ie(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)ie(o,t,n,r,i,a);else if(e instanceof g){if(a){let r=w.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(e.lhs.constant!==void 0&&!Number.isFinite(e.lhs.constant))throw Error(`Constraint "${e.name}" embedded in logical constraint "${t}" has invalid LHS constant: ${e.lhs.constant}.`);for(let[i,a]of e.lhs.terms){if(!r(i))throw Error(`Variable "${i.name}" embedded in logical constraint "${t}" does not belong to model "${n}".`);if(!Number.isFinite(a))throw Error(`Variable "${i.name}" embedded in logical constraint "${t}" has invalid coefficient: ${a}.`)}}}function M(e){let t=new Set,n=new Set;for(let r of e.variables){te(r);let i=C.get(r);if(i&&i!==e||t.has(r.name)||e.getVarByName(r.name)!==r)throw Error(`Variable "${r.name}" is duplicated or not canonically registered in model "${e.name}".`);t.add(r.name),n.add(r)}let r=new Set,i=new Set;for(let t of e.boolVars){if(r.has(t.name)||e.getBoolVarByName(t.name)!==t)throw Error(`Boolean variable "${t.name}" is duplicated or not canonically registered in model "${e.name}".`);r.add(t.name),i.add(t)}let a=new Set;for(let t of e.constraints){if(r.has(t.name))throw Error(`Constraint name "${t.name}" conflicts with Boolean variable "${t.name}" in model "${e.name}".`);if(a.has(t.name))throw Error(`Duplicate constraint name "${t.name}" in model "${e.name}".`);a.add(t.name)}for(let t of e.logicalConstraints){if(r.has(t.name))throw Error(`Logical constraint name "${t.name}" conflicts with Boolean variable "${t.name}" in model "${e.name}".`);if(a.has(t.name))throw Error(`Conflicting constraint name "${t.name}" across arithmetic and logical constraints in model "${e.name}".`);a.add(t.name)}for(let t of e.constraints){let n=w.get(t);if(n&&n!==e||e.getConstraintByName(t.name)!==t)throw Error(`Constraint "${t.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&&re(e.objectiveExpr,e.name,e=>n.has(e));for(let t of e.constraints)j(t,e.name,e=>n.has(e));for(let t of e.logicalConstraints)ie(t.expr,t.name,e.name,e=>n.has(e),e=>i.has(e),e)}var N=0;function ae(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 P=class{id;_name;prefix;hasExplicitName;ownerModel=null;_type;_lb;_ub;_initialValue;value=null;reducedCost=null;constructor(e={}){this.id=++N;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=ae(e.type),this._type===`Binary`?(this._lb=0,this._ub=1):(this._lb=e.lb===void 0?0:e.lb,this._ub=e.ub===void 0?1/0:e.ub),this._initialValue=e.initialValue===void 0?void 0:Object.is(e.initialValue,-0)?0:e.initialValue,this._initialValue!==void 0&&te(this)}get name(){return this._name}get type(){return this._type}set type(e){let t=ae(e);this._type!==t&&(this._type=t,this.ownerModel?.notifyMutation?.())}get lb(){return this._lb}set lb(e){Object.is(this._lb,e)||(this._lb=e,this.ownerModel?.notifyMutation?.())}get ub(){return this._ub}set ub(e){Object.is(this._ub,e)||(this._ub=e,this.ownerModel?.notifyMutation?.())}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,this.ownerModel?.notifyMutation?.())}_assignModelName(e){this._name=e}mul(e){return typeof e==`number`?new b(new Map([[this,1]]),0).mul(e):new y(new Map([[this,1]]),new Map,0).mul(e)}add(e){return e instanceof y?e.add(this):new b(new Map([[this,1]]),0).add(e)}sub(e){return e instanceof y?e.neg().add(this):new b(new Map([[this,1]]),0).sub(e)}neg(){return this.mul(-1)}le(e,t){return new b(new Map([[this,1]]),0).le(e,t)}ge(e,t){return new b(new Map([[this,1]]),0).ge(e,t)}eq(e,t){return new b(new Map([[this,1]]),0).eq(e,t)}toString(){return this.name}},oe=/^(?:[0-9]+(?:\.[0-9]+)?|\.[0-9]+)(?:[eE][+-]?[0-9]+)?$/;function se(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===`<`||a===`>`||a===`=`){let t=a;r+1<i&&(e[r+1]===`=`||e[r+1]===`<`||e[r+1]===`>`)?(t+=e[r+1],r+=2):r++,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(!oe.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}var ce=class{tokens;pos=0;resolver;constructor(e,t){this.tokens=e,this.resolver=t}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.parseTerm();for(;this.pos<this.tokens.length;){let t=this.peek();if(!t)break;if(t.type===`PLUS`)this.consume(),e=e.add(this.parseTerm());else if(t.type===`MINUS`)this.consume(),e=e.sub(this.parseTerm());else break}return e instanceof y&&e.quadTerms.size===0?new b(e.linearTerms,e.constant):e}parseTerm(){let e=this.parseFactor();for(;this.pos<this.tokens.length;){let t=this.peek();if(!t)break;if(t.type===`STAR`)this.consume(),e=e.mul(this.parseFactor());else if(t.type===`SLASH`)this.consume(),e=e.div(this.parseFactor());else break}return e}parseFactor(){let e=this.peek();if(!e)throw Error(`Unexpected end of expression`);if(e.type===`PLUS`)return this.consume(),this.parseFactor();if(e.type===`MINUS`)return this.consume(),this.parseFactor().neg();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;if(this.peek()?.type===`IDENT`){let t=this.consume(),n=this.resolve(t.value);e=n instanceof P||`id`in n&&!(`terms`in n)&&!(`quadTerms`in n)?new b(new Map([[n,1]]),0):n.clone()}else this.consume(`LPAREN`),e=this.parseExpression(),this.consume(`RPAREN`);return this.applyPower(e).mul(n)}t=new b(new Map,n)}else if(e.type===`IDENT`){this.consume();let n=this.resolve(e.value);t=n instanceof P||`id`in n&&!(`terms`in n)&&!(`quadTerms`in n)?new b(new Map([[n,1]]),0):n.clone()}else if(e.type===`LPAREN`)this.consume(`LPAREN`),t=this.parseExpression(),this.consume(`RPAREN`);else throw Error(`Unexpected token '${e.value}' in expression`);return this.applyPower(t)}applyPower(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`);let r=e instanceof y,i=r?e.quadTerms.size:0,a=r?e.linearTerms.size:e.terms.size;if(i===0&&a===0){let t=e.constant**+n;if(e.constant!==0&&n>0&&t===0)throw Error(`Constant exponentiation underflows to zero.`);return new b(new Map,t)}if(n===0)return new b(new Map,1);if(n===1)return e;if(n===2)return e.mul(e);throw Error(`Exponent ${n} creates a non-linear term of degree > 2 (not allowed in MILP/LP/QP)`)}getRemainingToken(){return this.peek()}resolve(e){let t=this.resolver(e);if(!t)throw Error(`Unknown variable '${e}' in expression`);return t}};function F(e,t,n){let r=new ce(se(e,n),t),i=r.parseExpression(),a=r.getRemainingToken();if(a)throw Error(`Unexpected token '${a.value}' after expression in "${e}"`);return pe(i),i}function le(e,t){return F(e,t)}function ue(e,t,n,r){let i=e.match(/(<=|>=|==|=<|=>|=)/);if(!i)throw Error(`Constraint must contain a comparison operator (<=, >=, ==, =): "${e}"`);let a=i[0],o=i.index,s=e.substring(0,o).trim(),c=e.substring(o+a.length).trim(),l;if(a===`<=`||a===`=<`)l=`<=`;else if(a===`>=`||a===`=>`)l=`>=`;else if(a===`==`||a===`=`)l=`==`;else throw Error(`Unsupported operator "${a}"`);let u=F(s,t,r),d=F(c,t,r);if(u instanceof y&&u.quadTerms.size>0||d instanceof y&&d.quadTerms.size>0)throw Error(`Quadratic constraints are not supported (only linear constraints are allowed in MILP/LP/QP)`);let f=u instanceof y?new b(u.linearTerms,u.constant):u,p=d instanceof y?new b(d.linearTerms,d.constant):d,m;if(m=l===`<=`?f.le(p,n):l===`>=`?f.ge(p,n):f.eq(p,n),pe(m.lhs),!Number.isFinite(m.rhs))throw Error(`Invalid non-finite right-hand side "${m.rhs}" in constraint.`);return m}function de(e,t,n){return ue(e,t,n)}function fe(e){return e instanceof P||e instanceof b||e instanceof y?!0:typeof e!=`object`||!e?!1:`terms`in e&&e.terms instanceof Map||`quadTerms`in e&&e.quadTerms instanceof Map||`id`in e&&`name`in e&&`lb`in e&&`ub`in e&&`type`in e&&typeof e.mul==`function`}function pe(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.`)}}function I(e){return e instanceof g||typeof e==`object`&&!!e&&`sense`in e&&`lhs`in e&&`rhs`in e}function me(e,t){let n=new Map,r=new Map,i=e.join(``),a=`__washi_`;for(;i.includes(a);)a+=`_`;let o=``;for(let i=0;i<e.length;i++)if(o+=e[i],i<t.length){let e=t[i];if(typeof e==`number`){if(!Number.isFinite(e))throw Error(`Invalid numeric value "${e}" in template expression: interpolated numbers must be finite.`);let t=`${a}num_${i}__`;r.set(t,e),o+=`(${t})`}else if(I(e))throw Error(`Cannot interpolate a constraint comparison (<=, >=, ==) inside a template expression: expected a finite number, Var, LinExpr, or QuadExpr.`);else if(fe(e)){pe(e);let t=`${a}ph_${i}__`;n.set(t,e),o+=` ${t} `}else throw Error(`Unsupported interpolation value in template expression: expected a finite number, Var, LinExpr, or QuadExpr.`)}return{fullText:o,resolver:e=>n.get(e),numberMap:r}}function L(e,...t){let{fullText:n,resolver:r,numberMap:i}=me(e,t);return/(<=|>=|==|=<|=>|=)/.test(n)?ue(n,r,void 0,i):F(n,r,i)}function he(e){return typeof e==`object`&&!!e&&typeof e.lpString==`string`&&e.nameToVar instanceof Map&&e.nameToConstraint instanceof Map}function ge(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 _e(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=ge(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=ge(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 ve(e,t){let{sense:n,objective:r,constraints:i,variables:a}=e,o=t?.relax===!0,{nameToVar:s,varToName:c,nameToConstraint:l,constrToName:u,varOrder:d}=_e(e),f=[];f.push(n&&n.toLowerCase()===`maximize`?`Maximize`:`Minimize`);let p=[],m=!0,h=r instanceof y?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 y&&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){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
2
|
`)+`
|
|
3
|
-
`,nameToVar:a,nameToConstraint:s}}var ae=Symbol.for(`washi.solverRegistry`),oe=Symbol.for(`washi.defaultSolverFactory`),z=globalThis;z[ae]||(z[ae]=new Map);var B=z[ae];function V(e,t){B.set(e.toLowerCase(),t)}function se(e){if(typeof e==`string`){let t=B.get(e.toLowerCase());if(!t)throw Error(`Solver '${e}' is not registered.`);z[oe]=t}else z[oe]=typeof e==`function`?e:()=>e}function H(e,t){if(!e){let e=z[oe]||B.get(`highs`);if(!e)throw Error(`No default solver available. Available solvers: ${ce().join(`, `)}`);return e(t)}if(typeof e==`string`){let n=e.toLowerCase(),r=B.get(n);if(!r)throw Error(n===`glpk`?`Solver 'glpk' not found. Available solvers: ${ce().join(`, `)}. Please import '@ohtaman/washi/solvers/glpk' before selecting this solver.`:n===`z3`?`Solver 'z3' not found. Available solvers: ${ce().join(`, `)}. Please import '@ohtaman/washi/solvers/z3' before selecting this solver.`:`Solver '${e}' not found. Available solvers: ${ce().join(`, `)}`);return r(t)}return e}function ce(){return Array.from(B.keys())}var le=typeof document<`u`?document.currentScript?.src:null,ue=le?new URL(`.`,le).href:null;function U(e){if(!ue)throw Error(`[WaSHI] Load the browser IIFE using an external script src, or use the browser ESM build.`);return new URL(e,ue).href}function W(){return U(`highs.wasm`)}var de=c(((e,t)=>{var n=(()=>{var e=globalThis.document?.currentScript?.src;return async function(t={}){var n=t,r=!!globalThis.window,i=!!globalThis.WorkerGlobalScope;let a=n.print,o=n.printErr;n.print=e=>{a&&a(e)},n.printErr=e=>{o&&o(e)};var s=`./this.program`,c=(e,t)=>{throw t};i&&(e=self.location.href);var l=``;function u(e){return n.locateFile?n.locateFile(e,l):l+e}var d,f;if(r||i){try{l=new URL(`.`,e).href}catch{}i&&(f=e=>{var t=new XMLHttpRequest;return t.open(`GET`,e,!1),t.responseType=`arraybuffer`,t.send(null),new Uint8Array(t.response)}),d=async e=>{if(v(e))return new Promise((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.status)},r.onerror=n,r.send(null)});var t=await fetch(e,{credentials:`same-origin`});if(t.ok)return t.arrayBuffer();throw Error(t.status+` : `+t.url)}}var p=console.log.bind(console),m=console.error.bind(console),h,g=!1,_,v=e=>e.startsWith(`file://`);function y(){return Zt.buffer}function b(){if(!F?.buffer?.resizable){var e=y();F=new Int8Array(e),M=new Int16Array(e),ie=new Uint8Array(e),ne=new Uint16Array(e),N=new Int32Array(e),R=new Uint32Array(e),I=new Float32Array(e),L=new Float64Array(e),P=new BigInt64Array(e),re=new BigUint64Array(e)}}function x(){var e=n.preRun;e&&(typeof e==`function`&&(e=[e]),z.push(...e)),ae(z)}function S(){!n.noFSInit&&!Q.initialized&&Q.init(),J.init(),nn.v(),Q.ignorePermissions=!1}function C(){var e=n.postRun;e&&(typeof e==`function`&&(e=[e]),oe.push(...e)),ae(oe)}function w(e){throw n.onAbort?.(e),e=`Aborted(${e})`,m(e),g=!0,e+=`. Build with -sASSERTIONS for more info.`,new WebAssembly.RuntimeError(e)}var T;function E(){return u(`highs.wasm`)}function ee(e){if(f)return f(e);throw`both async and sync fetching of the wasm failed`}async function D(e){if(!h)try{var t=await d(e);return new Uint8Array(t)}catch{}return ee(e)}async function O(e,t){try{var n=await D(e);return await WebAssembly.instantiate(n,t)}catch(e){m(`failed to asynchronously prepare wasm: ${e}`),w(e)}}async function te(e,t,n){if(!e&&!v(t))try{var r=fetch(t,{credentials:`same-origin`});return await WebAssembly.instantiateStreaming(r,n)}catch(e){m(`wasm streaming compile failed: ${e}`),m(`falling back to ArrayBuffer instantiation`)}return O(t,n)}function k(){return{a:en}}async function A(){function e(e){return nn=e.exports,$t(nn),b(),nn}function t(t){return e(t.instance)}var r=k(),i=n.instantiateWasm;return i?new Promise(t=>{i(r,n=>t(e(n)))}):(T??=E(),t(await te(h,T,r)))}class j{name=`ExitStatus`;constructor(e){this.message=`Program terminated with exit(${e})`,this.status=e}}var M,N,P,F,I,L,ne,R,re,ie,ae=e=>{for(;e.length>0;)e.shift()(n)},oe=[],z=[],B=!0,V=e=>Jt(e),se=()=>Xt();class H{constructor(e){this.excPtr=e,this.ptr=e-24}set_type(e){R[this.ptr+4>>2]=e}get_type(){return R[this.ptr+4>>2]}set_destructor(e){R[this.ptr+8>>2]=e}get_destructor(){return R[this.ptr+8>>2]}set_caught(e){e=+!!e,F[this.ptr+12]=e}get_caught(){return F[this.ptr+12]!=0}set_rethrown(e){e=+!!e,F[this.ptr+13]=e}get_rethrown(){return F[this.ptr+13]!=0}init(e,t){this.set_adjusted_ptr(0),this.set_type(e),this.set_destructor(t)}set_adjusted_ptr(e){R[this.ptr+16>>2]=e}get_adjusted_ptr(){return R[this.ptr+16>>2]}}var ce=0,le=(e,t,n)=>{new H(e).init(t,n),ce++,w()},ue=()=>{var e=N[$.varargs>>2];return $.varargs+=4,e},U=ue,W={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=W.isAbs(e),n=e.slice(-1)===`/`;return e=W.normalizeArray(e.split(`/`).filter(e=>!!e),!t).join(`/`),!e&&!t&&(e=`.`),e&&n&&(e+=`/`),(t?`/`:``)+e},dirname:e=>{var t=W.splitPath(e),n=t[0],r=t[1];return!n&&!r?`.`:(r&&=r.slice(0,-1),n+r)},basename:e=>e&&e.match(/([^\/]+|\/)\/*$/)[1],join:(...e)=>W.normalize(e.join(`/`)),join2:(e,t)=>W.normalize(e+`/`+t)},de=()=>e=>(crypto.getRandomValues(e),0),fe=e=>(fe=de())(e),G={resolve:(...e)=>{for(var t=``,n=!1,r=e.length-1;r>=-1&&!n;r--){var i=r>=0?e[r]:Q.cwd();if(typeof i!=`string`)throw TypeError(`Arguments to path.resolve must be strings`);if(!i)return``;t=i+`/`+t,n=W.isAbs(i)}return t=W.normalizeArray(t.split(`/`).filter(e=>!!e),!n).join(`/`),(n?`/`:``)+t||`.`},relative:(e,t)=>{e=G.resolve(e).slice(1),t=G.resolve(t).slice(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(`/`)}},K=globalThis.TextDecoder&&new TextDecoder,pe=(e,t,n,r)=>{var i=t+n;if(r)return i;for(;e[t]&&!(t>=i);)++t;return t},q=(e,t=0,n,r)=>{var i=pe(e,t,n,r);if(i-t>16&&e.buffer&&K)return K.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},me=[],he=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},ge=(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.codePointAt(o);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,o++}}return t[n]=0,n-i},_e=(e,t,n)=>{var r=n>0?n:he(e)+1,i=Array(r),a=ge(e,i,0,i.length);return t&&(i.length=a),i},ve=()=>{if(!me.length){var e=null;if(globalThis.window?.prompt&&(e=window.prompt(`Input: `),e!==null&&(e+=`
|
|
4
|
-
`)),!e)return null;me=_e(e,!0)}return me.shift()},J={ttys:[],init(){},shutdown(){},register(e,t){J.ttys[e]={input:[],output:[],ops:t},Q.registerDevice(e,J.stream_ops)},stream_ops:{open(e){var t=J.ttys[e.node.rdev];if(!t)throw new Q.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 Q.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 Q.ErrnoError(29)}if(s===void 0&&a===0)throw new Q.ErrnoError(6);if(s==null)break;a++,t[n+o]=s}return a&&(e.node.atime=Date.now()),a},write(e,t,n,r,i){if(!e.tty||!e.tty.ops.put_char)throw new Q.ErrnoError(60);try{for(var a=0;a<r;a++)e.tty.ops.put_char(e.tty,t[n+a])}catch{throw new Q.ErrnoError(29)}return r&&(e.node.mtime=e.node.ctime=Date.now()),a}},default_tty_ops:{get_char(e){return ve()},put_char(e,t){t===null||t===10?(p(q(e.output)),e.output=[]):t!=0&&e.output.push(t)},fsync(e){e.output?.length>0&&(p(q(e.output)),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?(m(q(e.output)),e.output=[]):t!=0&&e.output.push(t)},fsync(e){e.output?.length>0&&(m(q(e.output)),e.output=[])}}},ye=e=>{w()},Y={ops_table:null,mount(e){return Y.createNode(null,`/`,16895,0)},createNode(e,t,n,r){if(Q.isBlkdev(n)||Q.isFIFO(n))throw new Q.ErrnoError(63);Y.ops_table||={dir:{node:{getattr:Y.node_ops.getattr,setattr:Y.node_ops.setattr,lookup:Y.node_ops.lookup,mknod:Y.node_ops.mknod,rename:Y.node_ops.rename,unlink:Y.node_ops.unlink,rmdir:Y.node_ops.rmdir,readdir:Y.node_ops.readdir,symlink:Y.node_ops.symlink},stream:{llseek:Y.stream_ops.llseek}},file:{node:{getattr:Y.node_ops.getattr,setattr:Y.node_ops.setattr},stream:{llseek:Y.stream_ops.llseek,read:Y.stream_ops.read,write:Y.stream_ops.write,mmap:Y.stream_ops.mmap,msync:Y.stream_ops.msync}},link:{node:{getattr:Y.node_ops.getattr,setattr:Y.node_ops.setattr,readlink:Y.node_ops.readlink},stream:{}},chrdev:{node:{getattr:Y.node_ops.getattr,setattr:Y.node_ops.setattr},stream:Q.chrdev_stream_ops}};var i=Q.createNode(e,t,n,r);return Q.isDir(i.mode)?(i.node_ops=Y.ops_table.dir.node,i.stream_ops=Y.ops_table.dir.stream,i.contents={}):Q.isFile(i.mode)?(i.node_ops=Y.ops_table.file.node,i.stream_ops=Y.ops_table.file.stream,i.usedBytes=0,i.contents=Y.emptyFileContents??=new Uint8Array):Q.isLink(i.mode)?(i.node_ops=Y.ops_table.link.node,i.stream_ops=Y.ops_table.link.stream):Q.isChrdev(i.mode)&&(i.node_ops=Y.ops_table.chrdev.node,i.stream_ops=Y.ops_table.chrdev.stream),i.atime=i.mtime=i.ctime=Date.now(),e&&(e.contents[t]=i,e.atime=e.mtime=e.ctime=i.atime),i},getFileDataAsTypedArray(e){return e.contents.subarray(0,e.usedBytes)},expandFileStorage(e,t){var n=e.contents.length;if(!(n>=t)){t=Math.max(t,n*(n<1048576?2:1.125)>>>0),n&&(t=Math.max(t,256));var r=Y.getFileDataAsTypedArray(e);e.contents=new Uint8Array(t),e.contents.set(r)}},resizeFileStorage(e,t){if(e.usedBytes!=t){var n=e.contents;e.contents=new Uint8Array(t),e.contents.set(n.subarray(0,Math.min(t,e.usedBytes))),e.usedBytes=t}},node_ops:{getattr(e){var t={};return t.dev=Q.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=Q.isDir(e.mode)?4096:Q.isFile(e.mode)?e.usedBytes:Q.isLink(e.mode)?e.link.length:0,t.atime=new Date(e.atime),t.mtime=new Date(e.mtime),t.ctime=new Date(e.ctime),t.blksize=4096,t.blocks=Math.ceil(t.size/t.blksize),t},setattr(e,t){for(let n of[`mode`,`atime`,`mtime`,`ctime`])t[n]!=null&&(e[n]=t[n]);t.size!==void 0&&Y.resizeFileStorage(e,t.size)},lookup(e,t){throw Y.doesNotExistError||(Y.doesNotExistError=new Q.ErrnoError(44),Y.doesNotExistError.stack=`<generic error, no stack>`),Y.doesNotExistError},mknod(e,t,n,r){return Y.createNode(e,t,n,r)},rename(e,t,n){var r;try{r=Q.lookupNode(t,n)}catch{}if(r){if(Q.isDir(e.mode))for(var i in r.contents)throw new Q.ErrnoError(55);Q.hashRemoveNode(r)}delete e.parent.contents[e.name],t.contents[n]=e,e.name=n,t.ctime=t.mtime=e.parent.ctime=e.parent.mtime=Date.now()},unlink(e,t){delete e.contents[t],e.ctime=e.mtime=Date.now()},rmdir(e,t){for(var n in Q.lookupNode(e,t).contents)throw new Q.ErrnoError(55);delete e.contents[t],e.ctime=e.mtime=Date.now()},readdir(e){return[`.`,`..`,...Object.keys(e.contents)]},symlink(e,t,n){var r=Y.createNode(e,t,41471,0);return r.link=n,r},readlink(e){if(!Q.isLink(e.mode))throw new Q.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);return t.set(a.subarray(i,i+o),n),o},write(e,t,n,r,i,a){if(t.buffer===F.buffer&&(a=!1),!r)return 0;var o=e.node;return o.mtime=o.ctime=Date.now(),a?(o.contents=t.subarray(n,n+r),o.usedBytes=r):o.usedBytes===0&&i===0?(o.contents=t.slice(n,n+r),o.usedBytes=r):(Y.expandFileStorage(o,i+r),o.contents.set(t.subarray(n,n+r),i),o.usedBytes=Math.max(o.usedBytes,i+r)),r},llseek(e,t,n){var r=t;if(n===1?r+=e.position:n===2&&Q.isFile(e.node.mode)&&(r+=e.node.usedBytes),r<0)throw new Q.ErrnoError(28);return r},mmap(e,t,n,r,i){if(!Q.isFile(e.node.mode))throw new Q.ErrnoError(43);var a,o,s=e.node.contents;if(!(i&2)&&s.buffer===F.buffer)o=!1,a=s.byteOffset;else{if(o=!0,a=ye(t),!a)throw new Q.ErrnoError(48);s&&((n>0||n+t<s.length)&&(s=s.subarray?s.subarray(n,n+t):Array.prototype.slice.call(s,n,n+t)),F.set(s,a))}return{ptr:a,allocated:o}},msync(e,t,n,r,i){return Y.stream_ops.write(e,t,0,r,n,!1),0}}},be=e=>{if(typeof e!=`string`)return 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},xe=e=>(typeof e==`string`&&(e=_e(e,!0)),e.subarray||(e=new Uint8Array(e)),e),X=(e,t)=>{var n=0;return e&&(n|=365),t&&(n|=146),n},Se=async e=>{var t=await d(e);return new Uint8Array(t)},Ce=(...e)=>Q.createDataFile(...e),we=e=>e,Te=null,Ee=async()=>Te,Z=0,De=null,Oe=e=>{Z--,n.monitorRunDependencies?.(Z),Z||De()},ke=e=>{Z||(Te=new Promise(e=>De=e)),Z++,n.monitorRunDependencies?.(Z)},Ae=[],je=async(e,t)=>{typeof Browser<`u`&&Browser.init();for(var n of Ae)if(n.canHandle(t))return n.handle(e,t);return e},Me=async(e,t,n,r,i,a,o,s)=>{var c=t?G.resolve(W.join2(e,t)):e,l=we(`cp ${c}`);ke(l);try{var u=n;typeof n==`string`&&(u=await Se(n)),u=await je(u,c),s?.(),a||Ce(e,t,u,r,i,o)}finally{Oe(l)}},Ne=(e,t,n,r,i,a,o,s,c,l)=>{Me(e,t,n,r,i,s,c,l).then(a).catch(o)},Q={root:null,mounts:[],devices:{},streams:[],nextInode:1,nameTable:null,currentPath:`/`,initialized:!1,ignorePermissions:!0,filesystems:null,syncFSRequests:0,ErrnoError:class{name=`ErrnoError`;constructor(e){this.errno=e}},FSStream:class{shared={};get object(){return this.node}set object(e){this.node=e}get isRead(){return(this.flags&2097155)!=1}get isWrite(){return!!(this.flags&2097155)}get isAppend(){return this.flags&1024}get flags(){return this.shared.flags}set flags(e){this.shared.flags=e}get position(){return this.shared.position}set position(e){this.shared.position=e}},FSNode:class{node_ops={};stream_ops={};readMode=365;writeMode=146;mounted=null;constructor(e,t,n,r){e||=this,this.parent=e,this.mount=e.mount,this.id=Q.nextInode++,this.name=t,this.mode=n,this.rdev=r,this.atime=this.mtime=this.ctime=Date.now()}get read(){return(this.mode&this.readMode)===this.readMode}set read(e){e?this.mode|=this.readMode:this.mode&=~this.readMode}get write(){return(this.mode&this.writeMode)===this.writeMode}set write(e){e?this.mode|=this.writeMode:this.mode&=~this.writeMode}get isFolder(){return Q.isDir(this.mode)}get isDevice(){return Q.isChrdev(this.mode)}addListener(e,t=!1){var n={cb:e,exclusive:t},r=this.listeners??=new Set;return r.add(n),{listeners:r,entry:n}}notifyListeners(e){if(this.listeners){var t;for(var n of this.listeners)n.exclusive?(t||=[]).push(n):n.cb(e);if(t){var r=(this.exclTurn||0)%t.length;this.exclTurn=r+1,t[r].cb(e)}}}},lookupPath(e,t={}){if(!e)throw new Q.ErrnoError(44);t.follow_mount??=!0,W.isAbs(e)||(e=Q.cwd()+`/`+e);linkloop:for(var n=0;n<40;n++){for(var r=e.split(`/`).filter(e=>!!e),i=Q.root,a=`/`,o=0;o<r.length;o++){var s=o===r.length-1;if(s&&t.parent)break;if(r[o]!==`.`){if(r[o]===`..`){if(a=W.dirname(a),Q.isRoot(i)){e=a+`/`+r.slice(o+1).join(`/`),n--;continue linkloop}i=i.parent;continue}a=W.join2(a,r[o]);try{i=Q.lookupNode(i,r[o])}catch(e){if(e?.errno===44&&s&&t.noent_okay)return{path:a};throw e}if(Q.isMountpoint(i)&&(!s||t.follow_mount)&&(i=i.mounted.root),Q.isLink(i.mode)&&(!s||t.follow)){if(!i.node_ops.readlink)throw new Q.ErrnoError(52);var c=i.node_ops.readlink(i);W.isAbs(c)||(c=W.dirname(a)+`/`+c),e=c+`/`+r.slice(o+1).join(`/`);continue linkloop}}}return{path:a,node:i}}throw new Q.ErrnoError(32)},getPath(e){for(var t;;){if(Q.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)%Q.nameTable.length},hashAddNode(e){var t=Q.hashName(e.parent.id,e.name);e.name_next=Q.nameTable[t],Q.nameTable[t]=e},hashRemoveNode(e){var t=Q.hashName(e.parent.id,e.name);if(Q.nameTable[t]===e)Q.nameTable[t]=e.name_next;else for(var n=Q.nameTable[t];n;){if(n.name_next===e){n.name_next=e.name_next;break}n=n.name_next}},lookupNode(e,t){var n=Q.mayLookup(e);if(n)throw new Q.ErrnoError(n);for(var r=Q.hashName(e.id,t),i=Q.nameTable[r];i;i=i.name_next){var a=i.name;if(i.parent.id===e.id&&a===t)return i}return Q.lookup(e,t)},createNode(e,t,n,r){var i=new Q.FSNode(e,t,n,r);return Q.hashAddNode(i),i},destroyNode(e){Q.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 Q.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 Q.isDir(e.mode)?Q.nodePermissions(e,`x`)||(e.node_ops.lookup?0:2):54},mayCreate(e,t){if(!Q.isDir(e.mode))return 54;try{return Q.lookupNode(e,t),20}catch{}return Q.nodePermissions(e,`wx`)},mayDelete(e,t,n){var r;try{r=Q.lookupNode(e,t)}catch(e){return e.errno}var i=Q.nodePermissions(e,`wx`);if(i)return i;if(n){if(!Q.isDir(r.mode))return 54;if(Q.isRoot(r)||Q.getPath(r)===Q.cwd())return 10}else if(Q.isDir(r.mode))return 31;return 0},mayOpen(e,t){if(!e)return 44;if(Q.isLink(e.mode))return 32;var n=Q.flagsToPermissionString(t);return Q.isDir(e.mode)&&(n!==`r`||t&576)?31:Q.nodePermissions(e,n)},checkOpExists(e,t){if(!e)throw new Q.ErrnoError(t);return e},MAX_OPEN_FDS:4096,nextfd(){for(var e=0;e<=Q.MAX_OPEN_FDS;e++)if(!Q.streams[e])return e;throw new Q.ErrnoError(33)},getStreamChecked(e){var t=Q.getStream(e);if(!t)throw new Q.ErrnoError(8);return t},getStream:e=>Q.streams[e],createStream(e,t=-1){return e=Object.assign(new Q.FSStream,e),t==-1&&(t=Q.nextfd()),e.fd=t,Q.streams[t]=e,e},closeStream(e){Q.streams[e]=null},dupStream(e,t=-1){var n=Q.createStream(e,t);return n.stream_ops?.dup?.(n),n},doSetAttr(e,t,n){var r=e?.stream_ops.setattr,i=r?e:t;r??=t.node_ops.setattr,Q.checkOpExists(r,63);try{r(i,n)}catch(e){throw e instanceof RangeError?new Q.ErrnoError(22):e}},chrdev_stream_ops:{open(e){e.stream_ops=Q.getDevice(e.node.rdev).stream_ops,e.stream_ops.open?.(e)},llseek(){throw new Q.ErrnoError(70)}},major:e=>e>>8,minor:e=>e&255,makedev:(e,t)=>e<<8|t,registerDevice(e,t){Q.devices[e]={stream_ops:t}},getDevice:e=>Q.devices[e],getMounts(e){for(var t=[],n=[e];n.length;){var r=n.pop();t.push(r),n.push(...r.mounts)}return t},syncfs(e,t){typeof e==`function`&&(t=e,e=!1),Q.syncFSRequests++,Q.syncFSRequests>1&&m(`warning: ${Q.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`);var n=Q.getMounts(Q.root.mount),r=0;function i(e){return Q.syncFSRequests--,t(e)}function a(e){if(e)return a.errored?void 0:(a.errored=!0,i(e));++r>=n.length&&i(null)}for(var o of n)o.type.syncfs?o.type.syncfs(o,e,a):a(null)},mount(e,t,n){var r=n===`/`,i=!n,a;if(r&&Q.root)throw new Q.ErrnoError(10);if(!r&&!i){var o=Q.lookupPath(n,{follow_mount:!1});if(n=o.path,a=o.node,Q.isMountpoint(a))throw new Q.ErrnoError(10);if(!Q.isDir(a.mode))throw new Q.ErrnoError(54)}var s={type:e,opts:t,mountpoint:n,mounts:[]},c=e.mount(s);return c.mount=s,s.root=c,r?Q.root=c:a&&(a.mounted=s,a.mount&&a.mount.mounts.push(s)),c},unmount(e){var t=Q.lookupPath(e,{follow_mount:!1});if(!Q.isMountpoint(t.node))throw new Q.ErrnoError(28);var n=t.node,r=n.mounted,i=Q.getMounts(r);for(var[a,o]of Object.entries(Q.nameTable))for(;o;){var s=o.name_next;i.includes(o.mount)&&Q.destroyNode(o),o=s}n.mounted=null;var c=n.mount.mounts.indexOf(r);n.mount.mounts.splice(c,1)},lookup(e,t){return e.node_ops.lookup(e,t)},mknod(e,t,n){var r=Q.lookupPath(e,{parent:!0}).node,i=W.basename(e);if(!i)throw new Q.ErrnoError(28);if(i===`.`||i===`..`)throw new Q.ErrnoError(20);var a=Q.mayCreate(r,i);if(a)throw new Q.ErrnoError(a);if(!r.node_ops.mknod)throw new Q.ErrnoError(63);return r.node_ops.mknod(r,i,t,n)},statfs(e){return Q.statfsNode(Q.lookupPath(e,{follow:!0}).node)},statfsStream(e){return Q.statfsNode(e.node)},statfsNode(e){var t={bsize:4096,frsize:4096,blocks:1e6,bfree:5e5,bavail:5e5,files:Q.nextInode,ffree:Q.nextInode-1,fsid:42,flags:2,namelen:255};return e.node_ops.statfs&&Object.assign(t,e.node_ops.statfs(e.mount.opts.root)),t},create(e,t=438){return t&=4095,t|=32768,Q.mknod(e,t,0)},mkdir(e,t=511){return t&=1023,t|=16384,Q.mknod(e,t,0)},mkdirTree(e,t){var n=e.split(`/`),r=``;for(var i of n)if(i){(r||W.isAbs(e))&&(r+=`/`),r+=i;try{Q.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,Q.mknod(e,t,n)},symlink(e,t){if(!G.resolve(e))throw new Q.ErrnoError(44);var n=Q.lookupPath(t,{parent:!0}).node;if(!n)throw new Q.ErrnoError(44);var r=W.basename(t),i=Q.mayCreate(n,r);if(i)throw new Q.ErrnoError(i);if(!n.node_ops.symlink)throw new Q.ErrnoError(63);return n.node_ops.symlink(n,r,e)},link(e,t,n){var r=Q.lookupPath(t,{parent:!0}).node;if(!r)throw new Q.ErrnoError(44);var i=W.basename(t),a=Q.mayCreate(r,i);if(a)throw new Q.ErrnoError(a);if(!r.node_ops.link)throw new Q.ErrnoError(34);return r.node_ops.link(r,i,e,n)},rename(e,t){var n=W.dirname(e),r=W.dirname(t),i=W.basename(e),a=W.basename(t),o=Q.lookupPath(e,{parent:!0}),s=o.node,c;if(o=Q.lookupPath(t,{parent:!0}),c=o.node,!s||!c)throw new Q.ErrnoError(44);if(s.mount!==c.mount)throw new Q.ErrnoError(75);var l=Q.lookupNode(s,i),u=G.relative(e,r);if(u.charAt(0)!==`.`)throw new Q.ErrnoError(28);if(u=G.relative(t,n),u.charAt(0)!==`.`)throw new Q.ErrnoError(55);var d;try{d=Q.lookupNode(c,a)}catch{}if(l!==d){var f=Q.isDir(l.mode),p=Q.mayDelete(s,i,f);if(p||(p=d?Q.mayDelete(c,a,f):Q.mayCreate(c,a),p))throw new Q.ErrnoError(p);if(!s.node_ops.rename)throw new Q.ErrnoError(63);if(Q.isMountpoint(l)||d&&Q.isMountpoint(d))throw new Q.ErrnoError(10);if(c!==s&&(p=Q.nodePermissions(s,`w`),p))throw new Q.ErrnoError(p);Q.hashRemoveNode(l);try{s.node_ops.rename(l,c,a),l.parent=c}catch(e){throw e}finally{Q.hashAddNode(l)}}},rmdir(e){var t=Q.lookupPath(e,{parent:!0}).node,n=W.basename(e),r=Q.lookupNode(t,n),i=Q.mayDelete(t,n,!0);if(i)throw new Q.ErrnoError(i);if(!t.node_ops.rmdir)throw new Q.ErrnoError(63);if(Q.isMountpoint(r))throw new Q.ErrnoError(10);t.node_ops.rmdir(t,n),Q.destroyNode(r)},readdir(e){var t=Q.lookupPath(e,{follow:!0}).node;return Q.checkOpExists(t.node_ops.readdir,54)(t)},unlink(e){var t=Q.lookupPath(e,{parent:!0}).node;if(!t)throw new Q.ErrnoError(44);var n=W.basename(e),r=Q.lookupNode(t,n),i=Q.mayDelete(t,n,!1);if(i)throw new Q.ErrnoError(i);if(!t.node_ops.unlink)throw new Q.ErrnoError(63);if(Q.isMountpoint(r))throw new Q.ErrnoError(10);t.node_ops.unlink(t,n),Q.destroyNode(r)},readlink(e){var t=Q.lookupPath(e).node;if(!t)throw new Q.ErrnoError(44);if(!t.node_ops.readlink)throw new Q.ErrnoError(28);return t.node_ops.readlink(t)},stat(e,t){var n=Q.lookupPath(e,{follow:!t}).node;return Q.checkOpExists(n.node_ops.getattr,63)(n)},fstat(e){var t=Q.getStreamChecked(e),n=t.node,r=t.stream_ops.getattr,i=r?t:n;return r??=n.node_ops.getattr,Q.checkOpExists(r,63),r(i)},lstat(e){return Q.stat(e,!0)},doChmod(e,t,n,r){Q.doSetAttr(e,t,{mode:n&4095|t.mode&-4096,ctime:Date.now(),dontFollow:r})},chmod(e,t,n){var r=typeof e==`string`?Q.lookupPath(e,{follow:!n}).node:e;Q.doChmod(null,r,t,n)},lchmod(e,t){Q.chmod(e,t,!0)},fchmod(e,t){var n=Q.getStreamChecked(e);Q.doChmod(n,n.node,t,!1)},doChown(e,t,n){Q.doSetAttr(e,t,{timestamp:Date.now(),dontFollow:n})},chown(e,t,n,r){var i=typeof e==`string`?Q.lookupPath(e,{follow:!r}).node:e;Q.doChown(null,i,r)},lchown(e,t,n){Q.chown(e,t,n,!0)},fchown(e,t,n){var r=Q.getStreamChecked(e);Q.doChown(r,r.node,!1)},doTruncate(e,t,n){if(Q.isDir(t.mode))throw new Q.ErrnoError(31);if(!Q.isFile(t.mode))throw new Q.ErrnoError(28);var r=Q.nodePermissions(t,`w`);if(r)throw new Q.ErrnoError(r);Q.doSetAttr(e,t,{size:n,timestamp:Date.now()})},truncate(e,t){if(t<0)throw new Q.ErrnoError(28);var n=typeof e==`string`?Q.lookupPath(e,{follow:!0}).node:e;Q.doTruncate(null,n,t)},ftruncate(e,t){var n=Q.getStreamChecked(e);if(t<0||!(n.flags&2097155))throw new Q.ErrnoError(28);Q.doTruncate(n,n.node,t)},utime(e,t,n,r){var i=Q.lookupPath(e,{follow:!r});Q.doSetAttr(null,i.node,{atime:t,mtime:n,dontFollow:r})},open(e,t,n=438){if(e===``)throw new Q.ErrnoError(44);t=be(t),n=t&64?n&4095|32768:0;var r,i;if(typeof e==`object`)r=e;else{i=e.endsWith(`/`);var a=Q.lookupPath(e,{follow:!(t&131072),noent_okay:!0});r=a.node,e=a.path}var o=!1;if(t&64){if(r){if(t&128)throw new Q.ErrnoError(20)}else if(i)throw new Q.ErrnoError(31);else r=Q.mknod(e,n|511,0),o=!0}if(!r)throw new Q.ErrnoError(44);if(Q.isChrdev(r.mode)&&(t&=-513),t&65536&&!Q.isDir(r.mode))throw new Q.ErrnoError(54);if(!o){var s=Q.mayOpen(r,t);if(s)throw new Q.ErrnoError(s)}t&512&&!o&&Q.truncate(r,0),t&=-131713;var c=Q.createStream({node:r,path:Q.getPath(r),flags:t,seekable:!0,position:0,stream_ops:r.stream_ops,ungotten:[],error:!1});return c.stream_ops.open&&c.stream_ops.open(c),o&&Q.chmod(r,n&511),c},close(e){if(Q.isClosed(e))throw new Q.ErrnoError(8);e.getdents&&=null,e.node?.notifyListeners(32);try{e.stream_ops.close&&e.stream_ops.close(e)}catch(e){throw e}finally{Q.closeStream(e.fd)}e.fd=null},isClosed(e){return e.fd===null},llseek(e,t,n){if(Q.isClosed(e))throw new Q.ErrnoError(8);if(!e.seekable||!e.stream_ops.llseek)throw new Q.ErrnoError(70);if(n!=0&&n!=1&&n!=2)throw new Q.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 Q.ErrnoError(28);if(Q.isClosed(e)||(e.flags&2097155)==1)throw new Q.ErrnoError(8);if(Q.isDir(e.node.mode))throw new Q.ErrnoError(31);if(!e.stream_ops.read)throw new Q.ErrnoError(28);var a=i!==void 0;if(!a)i=e.position;else if(!e.seekable)throw new Q.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 Q.ErrnoError(28);if(Q.isClosed(e)||!(e.flags&2097155))throw new Q.ErrnoError(8);if(Q.isDir(e.node.mode))throw new Q.ErrnoError(31);if(!e.stream_ops.write)throw new Q.ErrnoError(28);e.seekable&&e.flags&1024&&Q.llseek(e,0,2);var o=i!==void 0;if(!o)i=e.position;else if(!e.seekable)throw new Q.ErrnoError(70);var s=e.stream_ops.write(e,t,n,r,i,a);return o||(e.position+=s),s},mmap(e,t,n,r,i){if(r&2&&!(i&2)&&(e.flags&2097155)!=2||(e.flags&2097155)==1)throw new Q.ErrnoError(2);if(!e.stream_ops.mmap)throw new Q.ErrnoError(43);if(!t)throw new Q.ErrnoError(28);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},ioctl(e,t,n){if(!e.stream_ops.ioctl)throw new Q.ErrnoError(59);return e.stream_ops.ioctl(e,t,n)},readFile(e,t={}){t.flags=t.flags??0,t.encoding=t.encoding??`binary`,t.encoding!==`utf8`&&t.encoding!==`binary`&&w(`Invalid encoding type "${t.encoding}"`);var n=Q.open(e,t.flags),r=Q.stat(e).size,i=new Uint8Array(r);return Q.read(n,i,0,r,0),t.encoding===`utf8`&&(i=q(i)),Q.close(n),i},writeFile(e,t,n={}){n.flags=n.flags??577;var r=Q.open(e,n.flags,n.mode);t=xe(t),Q.write(r,t,0,t.byteLength,void 0,n.canOwn),Q.close(r)},cwd:()=>Q.currentPath,chdir(e){var t=Q.lookupPath(e,{follow:!0});if(t.node===null)throw new Q.ErrnoError(44);if(!Q.isDir(t.node.mode))throw new Q.ErrnoError(54);var n=Q.nodePermissions(t.node,`x`);if(n)throw new Q.ErrnoError(n);Q.currentPath=t.path},createDefaultDirectories(){Q.mkdir(`/tmp`),Q.mkdir(`/home`),Q.mkdir(`/home/web_user`)},createDefaultDevices(){Q.mkdir(`/dev`),Q.registerDevice(Q.makedev(1,3),{read:()=>0,write:(e,t,n,r,i)=>r,llseek:()=>0}),Q.mkdev(`/dev/null`,Q.makedev(1,3)),J.register(Q.makedev(5,0),J.default_tty_ops),J.register(Q.makedev(6,0),J.default_tty1_ops),Q.mkdev(`/dev/tty`,Q.makedev(5,0)),Q.mkdev(`/dev/tty1`,Q.makedev(6,0));var e=new Uint8Array(1024),t=0,n=()=>(t===0&&(fe(e),t=e.byteLength),e[--t]);Q.createDevice(`/dev`,`random`,n),Q.createDevice(`/dev`,`urandom`,n),Q.mkdir(`/dev/shm`),Q.mkdir(`/dev/shm/tmp`)},createSpecialDirectories(){Q.mkdir(`/proc`);var e=Q.mkdir(`/proc/self`);Q.mkdir(`/proc/self/fd`),Q.mount({mount(){var t=Q.createNode(e,`fd`,16895,73);return t.stream_ops={llseek:Y.stream_ops.llseek},t.node_ops={lookup(e,t){var n=+t,r=Q.getStreamChecked(n),i={parent:null,mount:{mountpoint:`fake`},node_ops:{readlink:()=>r.path},id:n+1};return i.parent=i,i},readdir(){return Array.from(Q.streams.entries()).filter(([e,t])=>t).map(([e,t])=>e.toString())}},t}},{},`/proc/self/fd`)},createStandardStreams(e,t,n){e?Q.createDevice(`/dev`,`stdin`,e):Q.symlink(`/dev/tty`,`/dev/stdin`),t?Q.createDevice(`/dev`,`stdout`,null,t):Q.symlink(`/dev/tty`,`/dev/stdout`),n?Q.createDevice(`/dev`,`stderr`,null,n):Q.symlink(`/dev/tty1`,`/dev/stderr`),Q.open(`/dev/stdin`,0),Q.open(`/dev/stdout`,1),Q.open(`/dev/stderr`,1)},staticInit(){Q.nameTable=Array(4096),Q.mount(Y,{},`/`),Q.createDefaultDirectories(),Q.createDefaultDevices(),Q.createSpecialDirectories(),Q.filesystems={MEMFS:Y}},init(e,t,r){Q.initialized=!0,e??=n.stdin,t??=n.stdout,r??=n.stderr,Q.createStandardStreams(e,t,r)},quit(){Q.initialized=!1;for(var e of Q.streams)e&&Q.close(e)},findObject(e,t){var n=Q.analyzePath(e,t);return n.exists?n.object:null},analyzePath(e,t){try{var n=Q.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=Q.lookupPath(e,{parent:!0});r.parentExists=!0,r.parentPath=n.path,r.parentObject=n.node,r.name=W.basename(e),n=Q.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:Q.getPath(e);for(var i=t.split(`/`).reverse();i.length;){var a=i.pop();if(a){var o=W.join2(e,a);try{Q.mkdir(o)}catch(e){if(e.errno!=20)throw e}e=o}}return o},createFile(e,t,n,r,i){var a=W.join2(typeof e==`string`?e:Q.getPath(e),t),o=X(r,i);return Q.create(a,o)},createDataFile(e,t,n,r,i,a){var o=t;e&&(e=typeof e==`string`?e:Q.getPath(e),o=t?W.join2(e,t):e);var s=X(r,i),c=Q.create(o,s);if(n){n=xe(n),Q.chmod(c,s|146);var l=Q.open(c,577);Q.write(l,n,0,n.length,0,a),Q.close(l),Q.chmod(c,s)}},createDevice(e,t,n,r){var i=W.join2(typeof e==`string`?e:Q.getPath(e),t),a=X(!!n,!!r);Q.createDevice.major??=64;var o=Q.makedev(Q.createDevice.major++,0);return Q.registerDevice(o,{open(e){e.seekable=!1},close(e){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 Q.ErrnoError(29)}if(c===void 0&&o===0)throw new Q.ErrnoError(6);if(c==null)break;o++,t[r+s]=c}return o&&(e.node.atime=Date.now()),o},write(e,t,n,i,a){for(var o=0;o<i;o++)try{r(t[n+o])}catch{throw new Q.ErrnoError(29)}return i&&(e.node.mtime=e.node.ctime=Date.now()),o}}),Q.mkdev(i,a,o)},forceLoadFile(e){if(e.isDevice||e.isFolder||e.link||e.contents)return!0;if(globalThis.XMLHttpRequest)w(`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.`);else try{e.contents=f(e.url)}catch{throw new Q.ErrnoError(29)}},createLazyFile(e,t,n,r,a){class o{lengthKnown=!1;chunks=[];get(e){if(!(e>this.length-1||e<0)){var t=e%this.chunkSize,n=e/this.chunkSize|0;return this.getter(n)[t]}}setDataGetter(e){this.getter=e}cacheLength(){var e=new XMLHttpRequest;e.open(`HEAD`,n,!1),e.send(null),e.status>=200&&e.status<300||e.status===304||w(`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)=>{e>r&&w(`invalid range (${e}, ${r}) or no bytes requested!`),r>t-1&&w(`only ${t} bytes available! programmer error!`);var i=new XMLHttpRequest;return 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||w(`Couldn't load `+n+`. Status: `+i.status),i.response===void 0?_e(i.responseText??``,!0):new Uint8Array(i.response||[])},c=this;c.setDataGetter(e=>{var n=e*o,r=(e+1)*o-1;return r=Math.min(r,t-1),c.chunks[e]===void 0&&(c.chunks[e]=s(n,r)),c.chunks[e]===void 0&&w(`doXHR failed!`),c.chunks[e]}),(a||!t)&&(o=t=1,t=this.getter(0).length,o=t,p(`LazyFiles on gzip forces download of the whole file when length is accessed`)),this._length=t,this._chunkSize=o,this.lengthKnown=!0}get length(){return this.lengthKnown||this.cacheLength(),this._length}get chunkSize(){return this.lengthKnown||this.cacheLength(),this._chunkSize}}if(globalThis.XMLHttpRequest){i||w(`Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc`);var s={isDevice:!1,contents:new o}}else var s={isDevice:!1,url:n};var c=Q.createFile(e,t,s,r,a);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 l={};for(let[e,t]of Object.entries(c.stream_ops))l[e]=(...e)=>(Q.forceLoadFile(c),t(...e));function u(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 l.read=(e,t,n,r,i)=>(Q.forceLoadFile(c),u(e,t,n,r,i)),l.mmap=(e,t,n,r,i)=>{Q.forceLoadFile(c);var a=ye(t);if(!a)throw new Q.ErrnoError(48);return u(e,F,a,t,n),{ptr:a,allocated:!0}},c.stream_ops=l,c}},Pe=(e,t,n)=>e?q(ie,e,t,n):``,$={currentUmask:18,calculateAt(e,t,n){if(W.isAbs(t))return t;var r=e===-100?Q.cwd():$.getStreamFromFD(e).path;if(t.length==0){if(!n)throw new Q.ErrnoError(44);return r}return r+`/`+t},writeStat(e,t){R[e>>2]=t.dev,R[e+4>>2]=t.mode,R[e+8>>2]=t.nlink,R[e+12>>2]=t.uid,R[e+16>>2]=t.gid,R[e+20>>2]=t.rdev,P[e+24>>3]=BigInt(t.size),N[e+32>>2]=4096,N[e+36>>2]=t.blocks;var n=t.atime.getTime(),r=t.mtime.getTime(),i=t.ctime.getTime();return P[e+40>>3]=BigInt(Math.floor(n/1e3)),R[e+48>>2]=n%1e3*1e3*1e3,P[e+56>>3]=BigInt(Math.floor(r/1e3)),R[e+64>>2]=r%1e3*1e3*1e3,P[e+72>>3]=BigInt(Math.floor(i/1e3)),R[e+80>>2]=i%1e3*1e3*1e3,P[e+88>>3]=BigInt(t.ino),0},writeStatFs(e,t){R[e+4>>2]=t.bsize,R[e+60>>2]=t.bsize,P[e+8>>3]=BigInt(t.blocks),P[e+16>>3]=BigInt(t.bfree),P[e+24>>3]=BigInt(t.bavail),P[e+32>>3]=BigInt(t.files),P[e+40>>3]=BigInt(t.ffree),R[e+48>>2]=t.fsid,R[e+64>>2]=t.flags,R[e+56>>2]=t.namelen},doMsync(e,t,n,r,i){if(!Q.isFile(t.node.mode))throw new Q.ErrnoError(43);if(r&2)return 0;var a=ie.subarray(e,e+n);Q.msync(t,a,i,n,r)},getStreamFromFD(e){return Q.getStreamChecked(e)},varargs:void 0,getStr(e){return Pe(e)}};function Fe(e,t,n){$.varargs=n;try{var r=$.getStreamFromFD(e);switch(t){case 0:var i=ue();if(i<0)return-28;for(;Q.streams[i];)i++;return Q.dupStream(r,i).fd;case 1:case 2:return 0;case 3:return r.flags;case 4:var i=ue(),a=289792;return r.flags=r.flags&~a|i&a,0;case 12:var i=U(),o=0;return M[i+o>>1]=2,0;case 13:case 14:return 0}return-28}catch(e){if(Q===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Ie(e,t,n){$.varargs=n;try{var r=$.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=U();N[a>>2]=i.c_iflag||0,N[a+4>>2]=i.c_oflag||0,N[a+8>>2]=i.c_cflag||0,N[a+12>>2]=i.c_lflag||0;for(var o=0;o<32;o++)F[a+o+17]=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=U(),s=N[a>>2],c=N[a+4>>2],l=N[a+8>>2],u=N[a+12>>2],d=[],o=0;o<32;o++)d.push(F[a+o+17]);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=U();return N[a>>2]=0,0;case 21520:return r.tty?-28:-59;case 21537:case 21531:var a=U();return Q.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=U();M[a>>1]=f[0],M[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(Q===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Le(e,t,n,r){$.varargs=r;try{t=$.getStr(t),t=$.calculateAt(e,t);var i=r?ue():0;return n&64&&(i&=~$.currentUmask),Q.open(t,n,i).fd}catch(e){if(Q===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}var Re=()=>w(``),ze=0,Be=()=>{B=!1,ze=0},Ve={},He=e=>{if(e instanceof j||e==`unwind`)return _;c(1,e)},Ue=()=>B||ze>0,We=e=>{_=e,Ue()||(n.onExit?.(e),g=!0),c(e,new j(e))},Ge=(e,t)=>{_=e,We(e)},Ke=()=>{if(!Ue())try{Ge(_)}catch(e){He(e)}},qe=e=>{if(!g)try{return e()}catch(e){He(e)}finally{Ke()}},Je=()=>performance.now(),Ye=(e,t)=>(Ve[e]&&(clearTimeout(Ve[e].id),delete Ve[e]),t&&(Ve[e]={id:setTimeout(()=>{delete Ve[e],qe(()=>qt(e,Je()))},t),timeout_ms:t}),0),Xe=(e,t,n)=>ge(e,ie,t,n),Ze=(e,t,n,r)=>{var i=new Date().getFullYear(),a=new Date(i,0,1),o=new Date(i,6,1),s=a.getTimezoneOffset(),c=o.getTimezoneOffset(),l=Math.max(s,c);R[e>>2]=l*60,N[t>>2]=Number(s!=c);var u=e=>{var t=e>=0?`-`:`+`,n=Math.abs(e);return`UTC${t}${String(Math.floor(n/60)).padStart(2,`0`)}${String(n%60).padStart(2,`0`)}`},d=u(s),f=u(c);c<s?(Xe(d,n,17),Xe(f,r,17)):(Xe(d,r,17),Xe(f,n,17))},Qe=()=>Date.now(),$e=1,et=e=>e>=0&&e<=3,tt=9007199254740992,nt=-9007199254740992,rt=e=>e<nt||e>tt?NaN:Number(e);function it(e,t,n){if(t=rt(t),!et(e))return 28;var r;if(e===0)r=Qe();else if($e)r=Je();else return 52;var i=Math.round(r*1e3*1e3);return P[n>>3]=BigInt(i),0}var at=()=>2147483648,ot=(e,t)=>Math.ceil(e/t)*t,st=e=>{var t=(e-Zt.buffer.byteLength+65535)/65536|0;try{return Zt.grow(t),b(),1}catch{}},ct=e=>{var t=ie.length;e>>>=0;var n=at();if(e>n)return!1;for(var r=1;r<=4;r*=2){var i=t*(1+.2/r);if(i=Math.min(i,e+100663296),st(Math.min(n,ot(Math.max(e,i),65536))))return!0}return!1},lt={},ut=()=>s,dt=()=>{if(!dt.strings){var e={USER:`web_user`,LOGNAME:`web_user`,PATH:`/`,PWD:`/`,HOME:`/home/web_user`,LANG:(globalThis.navigator?.language??`C`).replace(`-`,`_`)+`.UTF-8`,_:ut()};for(var t in lt)lt[t]===void 0?delete e[t]:e[t]=lt[t];var n=[];for(var t in e)n.push(`${t}=${e[t]}`);dt.strings=n}return dt.strings},ft=(e,t)=>{var n=0,r=0;for(var i of dt()){var a=t+n;R[e+r>>2]=a,n+=Xe(i,a,1/0)+1,r+=4}return 0},pt=(e,t)=>{var n=dt();R[e>>2]=n.length;var r=0;for(var i of n)r+=he(i)+1;return R[t>>2]=r,0};function mt(e){try{var t=$.getStreamFromFD(e);return Q.close(t),0}catch(e){if(Q===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}var ht=(e,t,n,r)=>{for(var i=0,a=0;a<n;a++){var o=R[t>>2],s=R[t+4>>2];t+=8;try{var c=Q.read(e,F,o,s,r)}catch(e){if(i>0&&e instanceof Q.ErrnoError&&(e.errno==6||e.errno==6))break;throw e}if(c<0)return-1;if(i+=c,c<s)break;r!==void 0&&(r+=c)}return i};function gt(e,t,n,r){try{var i=ht($.getStreamFromFD(e),t,n);return R[r>>2]=i,0}catch(e){if(Q===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}function _t(e,t,n,r){t=rt(t);try{if(isNaN(t))return 22;var i=$.getStreamFromFD(e);return Q.llseek(i,t,n),P[r>>3]=BigInt(i.position),i.getdents&&t===0&&n===0&&(i.getdents=null),0}catch(e){if(Q===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}var vt=(e,t,n,r)=>{if(n==1)return Q.write(e,F,R[t>>2],R[t+4>>2],r);for(var i=0,a=0,o=t;a<n;a++,o+=8)i+=R[o+4>>2];for(var s=new Uint8Array(i),c=0,a=0;a<n;a++,t+=8){var l=R[t>>2],u=R[t+4>>2];s.set(ie.subarray(l,l+u),c),c+=u}return Q.write(e,s,0,i,r)};function yt(e,t,n,r){try{var i=vt($.getStreamFromFD(e),t,n);return R[r>>2]=i,0}catch(e){if(Q===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}var bt=e=>n[`_`+e],xt=(e,t)=>{F.set(e,t)},St=e=>Yt(e),Ct=e=>{var t=he(e)+1,n=St(t);return Xe(e,n,t),n},wt=(e,t,n,r,i)=>{var a={string:e=>{var t=0;return e!=null&&e!==0&&(t=Ct(e)),t},array:e=>{var t=St(e.length);return xt(e,t),t}};function o(e){return t===`string`?Pe(e):t===`boolean`?!!e:e}var s=bt(e),c=[],l=0;if(r)for(var u=0;u<r.length;u++){var d=a[n[u]];d?(l===0&&(l=se()),c[u]=d(r[u])):c[u]=r[u]}var f=s(...c);function p(e){return l!==0&&V(l),o(e)}return f=p(f),f},Tt=(e,t,n,r)=>{var i=!n||n.every(e=>e===`number`||e===`boolean`);return t!==`string`&&i&&!r?bt(e):(...i)=>wt(e,t,n,i,r)},Et=[],Dt=e=>{var t=Et[e];return t||(Et[e]=t=Qt.get(e)),t},Ot=(e,t)=>{if(kt)for(var n=e;n<e+t;n++){var r=Dt(n);r&&kt.set(r,n)}},kt,At=e=>(kt||(kt=new WeakMap,Ot(0,Qt.length)),kt.get(e)||0),jt=[],Mt=()=>jt.length?jt.pop():Qt.grow(1),Nt=(e,t)=>{Qt.set(e,t),Et[e]=Qt.get(e)},Pt=e=>{let t=e.length;return[t%128|128,t>>7,...e]},Ft={i:127,p:127,j:126,f:125,d:124,e:111},It=e=>Pt(Array.from(e,e=>Ft[e])),Lt=(e,t)=>{var n=Uint8Array.of(0,97,115,109,1,0,0,0,1,...Pt([1,96,...It(t.slice(1)),...It(t[0]===`v`?``:t[0])]),2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0),r=new WebAssembly.Module(n);return new WebAssembly.Instance(r,{e:{f:e}}).exports.f},Rt=(e,t)=>{var n=At(e);if(n)return n;var r=Mt();try{Nt(r,e)}catch(n){if(!(n instanceof TypeError))throw n;Nt(r,Lt(e,t))}return kt.set(e,r),r},zt=e=>{kt.delete(Dt(e)),Nt(e,null),jt.push(e)};Q.createPreloadedFile=Ne,Q.preloadFile=Me,Q.staticInit(),n.noExitRuntime&&(B=n.noExitRuntime),n.print&&(p=n.print),n.printErr&&(m=n.printErr),n.arguments&&n.arguments,n.thisProgram&&(s=n.thisProgram);var Bt=n.preInit;if(Bt)for(typeof Bt==`function`&&(n.preInit=Bt=[Bt]);Bt.length>0;)Bt.shift()();n.cwrap=Tt,n.addFunction=Rt,n.removeFunction=zt,n.UTF8ToString=Pe;var Vt,Ht,Ut,Wt,Gt,Kt,qt,Jt,Yt,Xt,Zt,Qt;function $t(e){n._Highs_js_getColName=e.w,n._Highs_js_getRowName=e.x,n._Highs_js_getPresolvedColName=e.y,n._Highs_js_getPresolvedRowName=e.z,n._Highs_js_setCallback=e.A,n._Highs_js_getCallbackMipSolutionSize=e.B,n._Highs_lpCall=e.C,n._Highs_mipCall=e.D,n._Highs_qpCall=e.E,Vt=n._Highs_create=e.F,Ht=n._Highs_destroy=e.G,n._Highs_version=e.H,n._Highs_versionMajor=e.I,n._Highs_versionMinor=e.J,n._Highs_versionPatch=e.K,n._Highs_githash=e.L,n._Highs_presolve=e.M,Ut=n._Highs_run=e.N,n._Highs_postsolve=e.O,n._Highs_readModel=e.P,n._Highs_writeModel=e.Q,n._Highs_writePresolvedModel=e.R,n._Highs_writeSolution=e.S,n._Highs_writeSolutionPretty=e.T,n._Highs_passLp=e.U,n._Highs_passMip=e.V,n._Highs_passModel=e.W,n._Highs_passHessian=e.X,n._Highs_passLinearObjectives=e.Y,n._Highs_clearLinearObjectives=e.Z,n._Highs_getNumCol=e._,n._Highs_addLinearObjective=e.$,n._Highs_passRowName=e.aa,n._Highs_passColName=e.ba,n._Highs_passModelName=e.ca,n._Highs_readOptions=e.da,n._Highs_clear=e.ea,n._Highs_clearModel=e.fa,n._Highs_clearSolver=e.ga,n._Highs_releaseMemory=e.ha,n._Highs_setBoolOptionValue=e.ia,n._Highs_setIntOptionValue=e.ja,n._Highs_setDoubleOptionValue=e.ka,n._Highs_setStringOptionValue=e.la,n._Highs_getNumOptions=e.ma,n._Highs_getOptionName=e.na,n._Highs_getBoolOptionValue=e.oa,n._Highs_getBoolOptionValues=e.pa,n._Highs_getIntOptionValue=e.qa,n._Highs_getIntOptionValues=e.ra,n._Highs_getDoubleOptionValue=e.sa,n._Highs_getDoubleOptionValues=e.ta,n._Highs_getStringOptionValue=e.ua,n._Highs_getStringOptionValues=e.va,n._Highs_getOptionType=e.wa,n._Highs_resetOptions=e.xa,n._Highs_writeOptions=e.ya,n._Highs_writeOptionsDeviations=e.za,n._Highs_getIntInfoValue=e.Aa,n._Highs_getDoubleInfoValue=e.Ba,n._Highs_getInt64InfoValue=e.Ca,n._Highs_getInfoType=e.Da,n._Highs_getSolution=e.Ea,n._Highs_getBasis=e.Fa,Wt=n._Highs_getModelStatus=e.Ga,n._Highs_getDualRay=e.Ha,n._Highs_getDualUnboundednessDirection=e.Ia,n._Highs_getPrimalRay=e.Ja,n._Highs_getObjectiveValue=e.Ka,n._Highs_getBasicVariables=e.La,n._Highs_getBasisInverseRow=e.Ma,n._Highs_getBasisInverseCol=e.Na,n._Highs_getBasisSolve=e.Oa,n._Highs_getBasisTransposeSolve=e.Pa,n._Highs_getReducedRow=e.Qa,n._Highs_getReducedColumn=e.Ra,n._Highs_setBasis=e.Sa,n._Highs_getNumRow=e.Ta,n._Highs_setLogicalBasis=e.Ua,n._Highs_setSolution=e.Va,n._Highs_setSparseSolution=e.Wa,n._Highs_setCallback=e.Xa,n._Highs_startCallback=e.Ya,n._Highs_stopCallback=e.Za,n._Highs_getRunTime=e._a,n._Highs_zeroAllClocks=e.$a,n._Highs_addCol=e.ab,n._Highs_addCols=e.bb,n._Highs_addVar=e.cb,n._Highs_addVars=e.db,n._Highs_addRow=e.eb,n._Highs_addRows=e.fb,n._Highs_ensureColwise=e.gb,n._Highs_ensureRowwise=e.hb,n._Highs_changeObjectiveSense=e.ib,n._Highs_changeObjectiveOffset=e.jb,n._Highs_changeColIntegrality=e.kb,n._Highs_changeColsIntegralityByRange=e.lb,n._Highs_changeColsIntegralityBySet=e.mb,n._Highs_changeColsIntegralityByMask=e.nb,n._Highs_clearIntegrality=e.ob,n._Highs_changeColCost=e.pb,n._Highs_changeColsCostByRange=e.qb,n._Highs_changeColsCostBySet=e.rb,n._Highs_changeColsCostByMask=e.sb,n._Highs_changeColBounds=e.tb,n._Highs_changeColsBoundsByRange=e.ub,n._Highs_changeColsBoundsBySet=e.vb,n._Highs_changeColsBoundsByMask=e.wb,n._Highs_changeRowBounds=e.xb,n._Highs_changeRowsBoundsByRange=e.yb,n._Highs_changeRowsBoundsBySet=e.zb,n._Highs_changeRowsBoundsByMask=e.Ab,n._Highs_changeCoeff=e.Bb,n._Highs_getObjectiveSense=e.Cb,n._Highs_getObjectiveOffset=e.Db,n._Highs_getColsByRange=e.Eb,n._Highs_getColsBySet=e.Fb,n._Highs_getColsByMask=e.Gb,n._Highs_getRowsByRange=e.Hb,n._Highs_getRowsBySet=e.Ib,n._Highs_getRowsByMask=e.Jb,n._Highs_getRowName=e.Kb,n._Highs_getRowByName=e.Lb,n._Highs_getColName=e.Mb,n._Highs_getColByName=e.Nb,n._Highs_getColIntegrality=e.Ob,n._Highs_deleteColsByRange=e.Pb,n._Highs_deleteColsBySet=e.Qb,n._Highs_deleteColsByMask=e.Rb,n._Highs_deleteRowsByRange=e.Sb,n._Highs_deleteRowsBySet=e.Tb,n._Highs_deleteRowsByMask=e.Ub,n._Highs_scaleCol=e.Vb,n._Highs_scaleRow=e.Wb,n._Highs_getInfinity=e.Xb,n._Highs_getSizeofHighsInt=e.Yb,n._Highs_getNumNz=e.Zb,n._Highs_getHessianNumNz=e._b,n._Highs_getPresolvedNumCol=e.$b,n._Highs_getPresolvedNumRow=e.ac,n._Highs_getPresolvedNumNz=e.bc,n._Highs_getModel=e.cc,n._Highs_getLp=e.dc,n._Highs_getFixedLp=e.ec,n._Highs_getPresolvedLp=e.fc,n._Highs_getPresolvedColName=e.gc,n._Highs_getPresolvedRowName=e.hc,n._Highs_getIis=e.ic,n._Highs_getIisLp=e.jc,n._Highs_crossover=e.kc,n._Highs_getRanging=e.lc,n._Highs_feasibilityRelaxation=e.mc,n._Highs_getCallbackDataOutItem=e.nc,n._Highs_setCallbackSolution=e.oc,n._Highs_setCallbackSparseSolution=e.pc,n._Highs_repairCallbackSolution=e.qc,n._Highs_call=e.rc,Gt=n._free=e.tc,Kt=n._malloc=e.uc,qt=e.vc,Jt=e.wc,Yt=e.xc,Xt=e.yc,Zt=e.u,Qt=e.sc}var en={a:le,e:Fe,h:Ie,i:Le,k:Re,s:Be,l:Ye,m:Ze,p:it,j:Qe,c:Je,q:ct,n:ft,o:pt,b:Ge,d:mt,g:gt,t:_t,f:yt,r:We};async function tn(){x(),Z&&await Ee();var e=n.setStatus;e&&(e(`Running...`),await new Promise(e=>setTimeout(e,1)),setTimeout(e,1,``)),!g&&(S(),n.onRuntimeInitialized?.(),C())}var nn=await A();await tn();let rn=0;n.Highs_readModel=n.cwrap(`Highs_readModel`,`number`,[`number`,`string`]);let an=n.cwrap(`Highs_setIntOptionValue`,`number`,[`number`,`string`,`number`]),on=n.cwrap(`Highs_setDoubleOptionValue`,`number`,[`number`,`string`,`number`]),sn=n.cwrap(`Highs_setStringOptionValue`,`number`,[`number`,`string`,`string`]),cn=n.cwrap(`Highs_setBoolOptionValue`,`number`,[`number`,`string`,`number`]),ln=n.cwrap(`Highs_getOptionType`,`number`,[`number`,`string`,`number`]),un=n.cwrap(`Highs_getNumCol`,`number`,[`number`]),dn=n.cwrap(`Highs_getNumRow`,`number`,[`number`]),fn=n.cwrap(`Highs_getObjectiveValue`,`number`,[`number`]),pn=n.cwrap(`Highs_getInfinity`,`number`,[]),mn=n.cwrap(`Highs_getSolution`,`number`,[`number`,`number`,`number`,`number`,`number`]),hn=n.cwrap(`Highs_getBasis`,`number`,[`number`,`number`,`number`]),gn=n.cwrap(`Highs_getColsByRange`,`number`,[`number`,`number`,`number`,`number`,`number`,`number`,`number`,`number`,`number`,`number`,`number`]),_n=n.cwrap(`Highs_getRowsByRange`,`number`,[`number`,`number`,`number`,`number`,`number`,`number`,`number`,`number`,`number`,`number`]),vn=n.cwrap(`Highs_getColIntegrality`,`number`,[`number`,`number`,`number`]),yn=n.cwrap(`Highs_js_getColName`,`number`,[`number`,`number`,`number`,`number`,`number`]),bn=n.cwrap(`Highs_js_getRowName`,`number`,[`number`,`number`,`number`,`number`,`number`]),xn={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`};var Vt,Ut,Ht,Wt,Q;let Sn={0:`LB`,1:`BS`,2:`UB`,3:`FX`};function Cn(e,t,n){return e===3||e===2&&t===n?`FX`:Sn[e]||``}let wn=new Set([`Not Set`,`Load error`,`Model error`,`Presolve error`,`Solve error`,`Postsolve error`,`Empty`,`Infeasible`,`Unknown`]);n.solve=function(e,t){let r=`highs-model-${++rn}.lp`,i,a=[];function o(e){let t=Kt(e);if(!t)throw Error(`malloc failed`);return a.push(t),t}function s(e,t){let n=o(Int32Array.BYTES_PER_ELEMENT),r=yn(e,t,0,0,n);if(r!==0&&r!==1)return``;let i=N[n>>2];if(i<=0)return``;let s=Kt(i);return a.push(s),r=yn(e,t,s,i,n),r!==0&&r!==1?``:Pe(s)}function c(e,t){let n=o(Int32Array.BYTES_PER_ELEMENT),r=bn(e,t,0,0,n);if(r!==0&&r!==1)return``;let i=N[n>>2];if(i<=0)return``;let s=Kt(i);return a.push(s),r=bn(e,t,s,i,n),r!==0&&r!==1?``:Pe(s)}try{if(Q.writeFile(r,e),i=Vt(),!i)throw Error(`Unable to create the HiGHS solver`);En(()=>n.Highs_readModel(i,r),`read LP model (see http://web.mit.edu/lpsolve/doc/CPLEX-format.htm)`);let a=t||{};for(let e in a){let t=a[e],n=typeof t,r;if(n===`number`)r=Tn;else if(n===`boolean`)r=cn;else if(n===`string`)r=sn;else throw Error(`Unsupported option value type ${t} for '${e}'`);En(()=>r(i,e,t),`set option '${e}'`)}En(()=>Ut(i),`solve the problem`);let l=Wt(i),u=xn[l]||`Unknown`;if(u===`Empty`)return{Columns:{},Rows:[],ObjectiveValue:0,Status:`Empty`};let d=un(i),f=dn(i),p=pn(),m=fn(i);Math.abs(m)>=p*.5&&(m=m>0?1/0:-1/0);let h=d>0?o(d*Float64Array.BYTES_PER_ELEMENT):0,g=d>0?o(d*Float64Array.BYTES_PER_ELEMENT):0,_=f>0?o(f*Float64Array.BYTES_PER_ELEMENT):0,v=f>0?o(f*Float64Array.BYTES_PER_ELEMENT):0;En(()=>mn(i,h,g,_,v),`get solution`);let y=d>0?o(d*Int32Array.BYTES_PER_ELEMENT):0,b=f>0?o(f*Int32Array.BYTES_PER_ELEMENT):0,x=!1,S=hn(i,y,b);(S===0||S===1)&&(x=!0);let C=o(Int32Array.BYTES_PER_ELEMENT),w=d>0?o(d*Float64Array.BYTES_PER_ELEMENT):0,T=d>0?o(d*Float64Array.BYTES_PER_ELEMENT):0,E=d>0?o(d*Float64Array.BYTES_PER_ELEMENT):0;gn(i,0,d-1,C,w,T,E,0,0,0,0);let ee=o(Int32Array.BYTES_PER_ELEMENT),D=f>0?o(f*Float64Array.BYTES_PER_ELEMENT):0,O=f>0?o(f*Float64Array.BYTES_PER_ELEMENT):0;_n(i,0,f-1,ee,D,O,0,0,0,0);let te=o(Int32Array.BYTES_PER_ELEMENT),k=!wn.has(u),A=!1;for(let e=0;e<d&&!A;e++)vn(i,e,te),N[te>>2]!==0&&(A=!0);let j={};for(let e=0;e<d;e++){let t={Index:e,Lower:L[(T>>3)+e],Upper:L[(E>>3)+e]};if(vn(i,e,te),t.Type=N[te>>2]===1?`Integer`:`Continuous`,k&&(t.Primal=L[(h>>3)+e]),x&&k&&!A){let n=N[(y>>2)+e];t.Status=Cn(n,t.Lower,t.Upper),t.Dual=L[(g>>3)+e]}t.Name=s(i,e),j[t.Name]=t}let M=[];for(let e=0;e<f;e++){let t={Index:e,Name:c(i,e),Lower:L[(D>>3)+e],Upper:L[(O>>3)+e]};if(k&&(t.Primal=L[(_>>3)+e]),x&&k&&!A){let n=N[(b>>2)+e];t.Status=Cn(n,t.Lower,t.Upper),t.Dual=L[(v>>3)+e]}M.push(t)}return{Status:u,ObjectiveValue:m,Columns:j,Rows:M}}finally{i&&Ht(i);try{Q.unlink(r)}catch{}for(let e=a.length-1;e>=0;e--)try{Gt(a[e])}catch{}}};function Tn(e,t,n){let r=Kt(Int32Array.BYTES_PER_ELEMENT);if(!r)return-1;try{let i=ln(e,t,r);if(i!==0&&i!==1)return i;let a=N[r>>2];return a===1?!Number.isSafeInteger(n)||n<-2147483648||n>2147483647?-1:an(e,t,n):a===2?on(e,t,n):-1}finally{Gt(r)}}function En(e,t){let n;try{n=e()}catch(e){n=e}if(n!==0&&n!==1)throw Error(`Unable to `+t+`. HiGHS error `+n)}var Dn=this&&this.__classPrivateFieldSet||function(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n},On=this&&this.__classPrivateFieldGet||function(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)};return(function(e){"use strict";var t,n;let r={csc:1,csr:2},i={triangular:1,square:2},a=new Map,o=new Map,s=new Map,c=1,l=1,u=0;class d extends Error{constructor(e,t){super(e),this.status=-1,this.name=`HighsError`,this.operation=t}}class f extends d{constructor(){super(`Cannot use this HiGHS model after disposal; create a new model or keep the work inside highs.withModel()`,`dispose`),this.name=`HighsDisposedError`}}class p extends d{constructor(e){super(e,`validate`),this.name=`HighsValidationError`}}class m extends d{constructor(){super(`Only callback control methods may be called while HiGHS is executing a callback`,`callback`),this.name=`HighsReentrancyError`}}class h extends d{constructor(e){super(`Option '`+e+`' is not supported by the single-threaded data-only API`,`setOptionValue`),this.name=`HighsUnsupportedOptionError`,this.option=e}}function g(t,n,r){let i=t+`:`+n+`:`+r.join(`,`),a=s.get(i);if(!a){let c=e.cwrap(t,n,r);a=function(...e){let t=c.apply(null,e),n=o.get(e[0]);return n&&n._throwCallbackError(),t},s.set(i,a)}return a}function _(e,t,n=`number`){return g(e,n,Array(t).fill(`number`))}function v(e,t,n,r=`number`){return g(e,r,Array(t||0).fill(`number`).concat([`string`],Array(n||0).fill(`number`)))}function y(){return ie}function b(){return N}function x(){return L}function S(e){return e?Pe(e):``}function C(e){return new p(e)}function w(){return new f}function T(e){return new d(e+` failed with HiGHS status -1`,e)}function E(e){return new h(e)}function ee(){return new m}function D(e){return{status:e}}function O(e,t){return e===-1?{status:e}:{status:e,value:t}}function te(e,t){if(e===-1)throw T(t);return{status:e,warnings:e===1?[t+` completed with a HiGHS warning`]:[]}}function k(e,t,n=0){if(!Number.isSafeInteger(e)||e<(n||0)||e>2147483647)throw C(t+` must be a 32-bit non-negative integer`);return e}function A(e,t){if(!Number.isSafeInteger(e)||e<-2147483648||e>2147483647)throw C(t+` must be a signed 32-bit integer`);return e}function j(e,t){if(e==null||typeof e.length!=`number`)throw C(t+` must be an array or typed array`);return e}function M(e,t,n){if(j(e,n),e.length!==t)throw C(n+` must contain `+t+` values; got `+e.length);return e}function P(e,t){if(typeof e!=`number`||Number.isNaN(e))throw C(t+` must be a number`);return e}function F(e,t,n){M(e,t,n);for(let t=0;t<e.length;t++)P(e[t],n+`[`+t+`]`);return e}function I(e,t,n,r){t==null?j(e,n):M(e,t,n);for(let t=0;t<e.length;t++){let i=e[t];if(k(i,n+`[`+t+`]`,0),r!=null&&i>=r)throw C(n+`[`+t+`] is outside the model`)}return e}function ne(e,t,n,r){if(!e||e.format!==`csc`&&e.format!==`csr`)throw C(r+`.format must be 'csc' or 'csr'`);if(e.numRows!==t||e.numCols!==n)throw C(r+` dimensions do not match the model`);let i=e.format===`csc`?n:t;if(I(e.starts,i+1,r+`.starts`),e.starts[0]!==0)throw C(r+`.starts must begin with zero`);for(let t=1;t<e.starts.length;t++)if(e.starts[t]<e.starts[t-1])throw C(r+`.starts must be monotonic`);let a=e.starts[i];return I(e.indices,a,r+`.indices`,e.format===`csc`?t:n),F(e.values,a,r+`.values`),a}function R(e,t,n){if(!e||!(e.format in i))throw C(n+`.format must be 'triangular' or 'square'`);if(e.dimension!==t)throw C(n+`.dimension must equal numCols`);if(I(e.starts,t+1,n+`.starts`),e.starts[0]!==0)throw C(n+`.starts must begin with zero`);for(let t=1;t<e.starts.length;t++)if(e.starts[t]<e.starts[t-1])throw C(n+`.starts must be monotonic`);let r=e.starts[t];return I(e.indices,r,n+`.indices`,t),F(e.values,r,n+`.values`),r}function re(e){if(!e||typeof e!=`object`)throw C(`model must be an object`);let t=k(e.numCols,`numCols`,0),n=k(e.numRows,`numRows`,0);F(e.colCost,t,`colCost`),F(e.colLower,t,`colLower`),F(e.colUpper,t,`colUpper`),F(e.rowLower,n,`rowLower`),F(e.rowUpper,n,`rowUpper`);let r=ne(e.matrix,n,t,`matrix`);if(e.integrality!=null){I(e.integrality,t,`integrality`);for(let n=0;n<t;n++)if(e.integrality[n]>4)throw C(`integrality values must be between 0 and 4`)}let i=e.hessian?R(e.hessian,t,`hessian`):0,a=e.sense==null?1:e.sense;if(a!==1&&a!==-1)throw C(`sense must be 1 (minimize) or -1 (maximize)`);if(P(e.offset==null?0:e.offset,`offset`),e.modelName!=null&&typeof e.modelName!=`string`)throw C(`modelName must be a string`);for(let[r,i,a]of[[e.colNames,t,`colNames`],[e.rowNames,n,`rowNames`]])if(r!=null){M(r,i,a);for(let e=0;e<r.length;e++)if(typeof r[e]!=`string`)throw C(a+`[`+e+`] must be a string`)}return{numCols:t,numRows:n,numNonzeros:r,hessianNonzeros:i,sense:a}}function ae(e,t,n){if(!e||typeof e!=`object`)throw C(n+` must be an object`);P(e.weight,n+`.weight`),P(e.offset,n+`.offset`),F(e.coefficients,t,n+`.coefficients`),P(e.absoluteTolerance,n+`.absoluteTolerance`),P(e.relativeTolerance,n+`.relativeTolerance`),A(e.priority,n+`.priority`)}class oe{constructor(){this.pointers=[]}bytes(e){k(e,`allocation size`,0);let t=Kt(Math.max(1,e));if(!t)throw RangeError(`Unable to allocate WebAssembly memory`);return this.pointers.push(t),t}ints(e){let t=this.bytes(e.length*4);return b().set(e,t>>2),t}doubles(e){let t=this.bytes(e.length*8);return x().set(e,t>>3),t}pack(e){let t=[],n=0;for(let r of e){let e=r.type===`f64`?8:4;n=Math.ceil(n/e)*e,t.push(n),n+=r.values.length*e}let r=this.bytes(n);return e.forEach((e,n)=>{let i=r+t[n];e.type===`f64`?x().set(e.values,i>>3):b().set(e.values,i>>2)}),t.map(e=>r+e)}outInts(e){let t=this.bytes(e*4);return b().fill(0,t>>2,(t>>2)+e),t}outDoubles(e){let t=this.bytes(e*8);return x().fill(0,t>>3,(t>>3)+e),t}free(){for(let e=this.pointers.length-1;e>=0;e--)Gt(this.pointers[e]);this.pointers.length=0}}function z(e){let t=new oe;try{return e(t)}finally{t.free()}}function B(e,t){return b().slice(e>>2,(e>>2)+t)}function V(e,t){return x().slice(e>>3,(e>>3)+t)}function se(e){return new BigInt64Array(y().buffer,e,1)[0]}function H(e){return`/tmp/highs-js-`+l+++`.`+e}function ce(e,t){if(!e||e.format!==`lp`&&e.format!==`mps`)throw C(`format must be 'lp' or 'mps'`);if(!(typeof e.data==`string`||ArrayBuffer.isView(e.data)))throw C(`model data must be a string or Uint8Array`);let n=H(e.format);try{return Q.writeFile(n,e.data),t(n)}finally{try{Q.unlink(n)}catch{}}}function le(e,t,n){if(typeof e!=`string`)throw C(`data must be a string`);let r=H(t);try{return Q.writeFile(r,e),n(r)}finally{try{Q.unlink(r)}catch{}}}function ue(e,t,n){let r=H(e);try{let e=n(r);return e===-1?O(e):O(e,Q.readFile(r,t===`utf8`?{encoding:`utf8`}:void 0))}finally{try{Q.unlink(r)}catch{}}}function U(e){return/thread|parallel|concurr/i.test(e)||/(^|_)(log_file|read_.*_file|write_.*_file|solution_file|.*_file)$/.test(e)||/^write_.*_to_file$/.test(e)}function W(e){if(typeof e!=`string`||!e)throw C(`option name is required`);if(U(e))throw E(e)}function de(e){if(typeof e!=`string`||!e)throw C(`option name is required`);return!U(e)}function fe(e){if(typeof e!=`string`)throw C(`option data must be a string`);for(let t of e.split(/\r?\n/)){let e=/^\s*([A-Za-z][A-Za-z0-9_]*)\b/.exec(t);e&&!t.trimStart().startsWith(`#`)&&W(e[1])}}function G(e,t,n,r){if(!e||typeof e!=`object`)throw C(r+` selection must be tagged`);if(e.kind===`range`){let n=k(e.from,r+`.from`,0),i=k(e.to,r+`.to`,0);if(i<n||i>=t)throw C(r+` range is outside the model`);return{suffix:`ByRange`,prefix:[n,i],count:i-n+1}}if(e.kind===`set`){I(e.indices,null,r+`.indices`,t);for(let t=1;t<e.indices.length;t++)if(e.indices[t]<=e.indices[t-1])throw C(r+` set indices must increase strictly`);return{suffix:`BySet`,prefix:[e.indices.length,n.ints(e.indices)],count:e.indices.length}}if(e.kind===`mask`){M(e.mask,t,r+`.mask`);let i=new Int32Array(t),a=0;for(let n=0;n<t;n++){if(e.mask[n]!==!1&&e.mask[n]!==!0&&e.mask[n]!==0&&e.mask[n]!==1)throw C(r+`.mask values must be boolean, 0, or 1`);i[n]=+!!e.mask[n],a+=i[n]}return{suffix:`ByMask`,prefix:[n.ints(i)],count:a}}throw C(r+`.kind must be 'range', 'set', or 'mask'`)}function K(e){return{numCols:_(`Highs_getNumCol`,1)(e),numRows:_(`Highs_getNumRow`,1)(e),numNonzeros:_(`Highs_getNumNz`,1)(e),hessianNonzeros:_(`Highs_getHessianNumNz`,1)(e)}}function pe(e){return{numCols:_(`Highs_getPresolvedNumCol`,1)(e),numRows:_(`Highs_getPresolvedNumRow`,1)(e),numNonzeros:_(`Highs_getPresolvedNumNz`,1)(e)}}class q{constructor(e){t.set(this,void 0),n.set(this,void 0),this._callbackNumCols=0,Dn(this,t,e,`f`),Dn(this,n,!1,`f`),this._callbackDepth=0,this._callbackId=0,this._callbackError=void 0,this._callbackErrorPending=!1,o.set(e,this)}get disposed(){return On(this,n,`f`)}_require(e=!1){if(On(this,n,`f`))throw w();if(this._callbackDepth&&!e)throw ee();return On(this,t,`f`)}_rememberCallbackError(e){this._callbackErrorPending||=(this._callbackError=e,!0)}_throwCallbackError(){if(!this._callbackErrorPending)return;let e=this._callbackError;throw this._callbackError=void 0,this._callbackErrorPending=!1,e}clear(){return this._simple(`Highs_clear`)}clearSolver(){return this._simple(`Highs_clearSolver`)}presolve(){return this._simple(`Highs_presolve`)}getRunTime(){return _(`Highs_getRunTime`,1)(this._require(!1))}readModel(e){let t=this._require(!1);return D(ce(e,function(e){return v(`Highs_readModel`,1,0)(t,e)}))}exportPresolvedModel(e){let t=this._require(!1);if(e!==`lp`&&e!==`mps`)throw C(`format must be 'lp' or 'mps'`);return ue(e,e===`lp`?`utf8`:void 0,function(e){return v(`Highs_writePresolvedModel`,1,0)(t,e)})}passModel(e){let t=this._require(!1),n=z(function(n){let r=he(e,n);return _(`Highs_passModel`,21).apply(null,[t].concat(r.values))}),r=n===-1?n:ge(t,e);return D(n===-1||r===-1?-1:Math.max(n,r))}passMip(e){let t=this._require(!1),n=z(function(n){let i=re(e),a=e.matrix;if(!e.integrality)throw C(`passMip requires an integrality vector`);let o=me(e,n,!0);return _(`Highs_passMip`,16)(t,i.numCols,i.numRows,i.numNonzeros,r[a.format],i.sense,e.offset==null?0:e.offset,...o)}),i=n===-1?n:ge(t,e);return D(n===-1||i===-1?-1:Math.max(n,i))}passHessian(e){let t=this._require(!1),n=K(t).numCols;return D(z(function(r){let a=R(e,n,`hessian`);return _(`Highs_passHessian`,7)(t,n,a,i[e.format],r.ints(Array.prototype.slice.call(e.starts,0,-1)),r.ints(e.indices),r.doubles(e.values))}))}addLinearObjective(e){let t=this._require(!1),n=K(t).numCols;return ae(e,n,`objective`),D(z(function(n){return _(`Highs_addLinearObjective`,7)(t,e.weight,e.offset,n.doubles(e.coefficients),e.absoluteTolerance,e.relativeTolerance,A(e.priority,`priority`))}))}passRowName(e,t){let n=this._require(!1);if(k(e,`row`,0),typeof t!=`string`)throw C(`name must be a string`);return D(v(`Highs_passRowName`,2,0)(n,e,t))}passModelName(e){if(typeof e!=`string`)throw C(`name must be a string`);return D(v(`Highs_passModelName`,1,0)(this._require(!1),e))}getOptionType(e){let t=this._require(!1);return de(e)?z(function(n){let r=n.outInts(1);return O(v(`Highs_getOptionType`,1,1)(t,e,r),[`boolean`,`integer`,`double`,`string`][b()[r>>2]])}):O(-1)}resetOptions(){return this._simple(`Highs_resetOptions`)}exportOptions(e){let t=this._require(!1),n=ue(`options`,`utf8`,function(n){return v(e?`Highs_writeOptionsDeviations`:`Highs_writeOptions`,1,0)(t,n)});return n.status!==-1&&(n.value=n.value.split(/\r?\n/).filter(function(e){let t=/^\s*([A-Za-z][A-Za-z0-9_]*)\b/.exec(e);return!t||!U(t[1])}).join(`
|
|
5
|
-
`)),n}getOptionName(e){let t=this._require(!1);return k(e,`option index`,0),z(function(n){let r=n.outInts(1),i=_(`Highs_getOptionName`,3)(t,e,r),a=b()[r>>2]>>>0;if(!a)return O(i,``);try{return O(i,S(a))}finally{Gt(a)}})}getInfoType(e){let t=this._require(!1);if(typeof e!=`string`||!e)throw C(`info name is required`);return z(function(n){let r=n.outInts(1),i=v(`Highs_getInfoType`,1,1)(t,e,r),a=b()[r>>2];return O(i,a===-1?`int64`:a===1?`integer`:a===2?`double`:void 0)})}getDimensions(){return K(this._require(!1))}getInfinity(){return _(`Highs_getInfinity`,1)(this._require(!1))}getModelStatus(){return _(`Highs_getModelStatus`,1)(this._require(!1))}getSolution(){let e=this._require(!1),t=this.getModelStatus();if(t===0||t===6)throw new d(`The model has not been solved`,`getSolution`);let n=K(e);return z(function(t){let r=t.outDoubles(n.numCols),i=t.outDoubles(n.numCols),a=t.outDoubles(n.numRows),o=t.outDoubles(n.numRows);return O(_(`Highs_getSolution`,5)(e,r,i,a,o),{colValue:V(r,n.numCols),rowValue:V(a,n.numRows),colDual:V(i,n.numCols),rowDual:V(o,n.numRows)})})}setSolution(e){let t=this._require(!1),n=K(t);return D(z(function(r){function i(e,t,n){return e==null?0:(F(e,t,n),r.doubles(e))}return _(`Highs_setSolution`,5)(t,i(e.colValue,n.numCols,`colValue`),i(e.rowValue,n.numRows,`rowValue`),i(e.colDual,n.numCols,`colDual`),i(e.rowDual,n.numRows,`rowDual`))}))}setBasis(e){let t=this._require(!1),n=K(t);if(!e)throw C(`basis is required`);return I(e.colStatus,n.numCols,`colStatus`),I(e.rowStatus,n.numRows,`rowStatus`),D(z(function(n){return _(`Highs_setBasis`,3)(t,n.ints(e.colStatus),n.ints(e.rowStatus))}))}postsolve(e){let t=this._require(!1),n=pe(t);if(!e||e.colValue==null)throw C(`postsolve requires colValue`);return F(e.colValue,n.numCols,`colValue`),e.colDual!=null&&F(e.colDual,n.numCols,`colDual`),e.rowDual!=null&&F(e.rowDual,n.numRows,`rowDual`),D(z(function(n){return _(`Highs_postsolve`,4)(t,n.doubles(e.colValue),e.colDual?n.doubles(e.colDual):0,e.rowDual?n.doubles(e.rowDual):0)}))}getObjectiveOffset(){let e=this._require(!1);return z(function(t){let n=t.outDoubles(1);return O(_(`Highs_getObjectiveOffset`,2)(e,n),x()[n>>3])})}getModel(e){return _e(this,`Highs_getModel`,e,!0)}getPresolvedLp(e){return _e(this,`Highs_getPresolvedLp`,e,!1)}getFixedLp(e){let t=_e(this,`Highs_getFixedLp`,e,!1);return t.status!==-1&&t.value&&t.value.integrality.fill(0),t}ensureRowwise(){return this._simple(`Highs_ensureRowwise`)}addVars(e,t){let n=this._require(!1);return j(e,`lower`),F(t,e.length,`upper`),F(e,e.length,`lower`),D(z(function(r){return _(`Highs_addVars`,4)(n,e.length,r.doubles(e),r.doubles(t))}))}addCol(e,t,n,r){let i=this._require(!1);return P(e,`cost`),P(t,`lower`),P(n,`upper`),ve(r,K(i).numRows),D(z(function(a){return _(`Highs_addCol`,7)(i,e,t,n,r.indices.length,a.ints(r.indices),a.doubles(r.values))}))}addCols(e){let t=this._require(!1),n=K(t).numRows;if(!e||!e.matrix)throw C(`column data and matrix are required`);let r=e.cost.length;if(F(e.cost,r,`cost`),F(e.lower,r,`lower`),F(e.upper,r,`upper`),e.matrix.format!==`csc`)throw C(`addCols requires a csc matrix`);let i=ne(e.matrix,n,r,`matrix`);return D(z(function(n){return _(`Highs_addCols`,9)(t,r,n.doubles(e.cost),n.doubles(e.lower),n.doubles(e.upper),i,n.ints(Array.prototype.slice.call(e.matrix.starts,0,-1)),n.ints(e.matrix.indices),n.doubles(e.matrix.values))}))}changeObjectiveSense(e){if(e!==1&&e!==-1)throw C(`sense must be 1 or -1`);return D(_(`Highs_changeObjectiveSense`,2)(this._require(!1),e))}changeColIntegrality(e,t){if(k(e,`column`,0),k(t,`integrality`,0),t>4)throw C(`integrality must be between 0 and 4`);return D(_(`Highs_changeColIntegrality`,3)(this._require(!1),e,t))}changeColCost(e,t){return k(e,`column`,0),P(t,`cost`),D(_(`Highs_changeColCost`,3)(this._require(!1),e,t))}changeRowBounds(e,t,n){return k(e,`row`,0),P(t,`lower`),P(n,`upper`),D(_(`Highs_changeRowBounds`,4)(this._require(!1),e,t,n))}changeColsIntegrality(e,t){let n=K(this._require(!1)).numCols;return J(this,`changeColsIntegrality`,e,[],[t],n,`columns`)}changeColsBounds(e,t,n){let r=K(this._require(!1)).numCols;return J(this,`changeColsBounds`,e,[t,n],[],r,`columns`)}deleteCols(e){return ye(this,`Cols`,e,K(this._require(!1)).numCols)}scaleCol(e,t){return k(e,`column`,0),P(t,`factor`),D(_(`Highs_scaleCol`,3)(this._require(!1),e,t))}getCols(e){return Y(this,`Cols`,e)}getColName(e){return be(this,`Highs_js_getColName`,e)}getPresolvedColName(e){return be(this,`Highs_js_getPresolvedColName`,e)}getColByName(e){return xe(this,`Col`,e)}getColIntegrality(e){let t=this._require(!1);return k(e,`column`,0),z(function(n){let r=n.outInts(1);return O(_(`Highs_getColIntegrality`,3)(t,e,r),b()[r>>2])})}getPrimalRay(){return X(this,`Highs_getPrimalRay`,K(this._require(!1)).numCols)}getDualUnboundednessDirection(){return X(this,`Highs_getDualUnboundednessDirection`,K(this._require(!1)).numCols)}getBasisInverseRow(e,t){return Se(this,`Highs_getBasisInverseRow`,e,K(this._require(!1)).numRows,t)}getBasisSolve(e,t){return Ce(this,`Highs_getBasisSolve`,e,t)}getReducedRow(e,t){let n=this._require(!1),r=K(n);return k(e,`row`,0),z(function(i){let a=i.outDoubles(r.numCols),o=i.outInts(1),s=i.outInts(r.numCols),c=_(`Highs_getReducedRow`,5)(n,e,a,o,s),l={values:V(a,r.numCols)};return t&&(l.nonzeroIndices=B(s,b()[o>>2])),O(c,l)})}crossover(e){let t=this._require(!1),n=K(t);if(!e||e.colValue==null)throw C(`crossover requires colValue`);if(F(e.colValue,n.numCols,`colValue`),e.colDual==null!=(e.rowDual==null))throw C(`colDual and rowDual must be supplied together`);return e.colDual&&F(e.colDual,n.numCols,`colDual`),e.rowDual&&F(e.rowDual,n.numRows,`rowDual`),D(z(function(r){return _(`Highs_crossover`,6)(t,n.numCols,n.numRows,r.doubles(e.colValue),e.colDual?r.doubles(e.colDual):0,e.rowDual?r.doubles(e.rowDual):0)}))}getRanging(){let e=this._require(!1),t=K(e);return z(function(n){let r=we(n,t.numCols),i=we(n,t.numCols),a=we(n,t.numCols),o=we(n,t.numCols),s=we(n,t.numRows),c=we(n,t.numRows),l=[r,i,a,o,s,c],u=[e];return l.forEach(function(e){u.push(e.valuePointer,e.objectivePointer,e.inPointer,e.outPointer)}),O(_(`Highs_getRanging`,u.length).apply(null,u),{colCostUp:r.detach(),colCostDown:i.detach(),colBoundUp:a.detach(),colBoundDown:o.detach(),rowBoundUp:s.detach(),rowBoundDown:c.detach()})})}setCallback(e){let t=this._require(!1);if(e!=null&&typeof e!=`function`)throw C(`callback must be a function or undefined`);let n=this._callbackId;if(!e){let e=_(`Highs_js_setCallback`,3)(t,0,0);return e!==-1&&(n&&a.delete(n),this._callbackId=0),D(e)}let r=c++;a.set(r,{raw:this,callback:e});let i=_(`Highs_js_setCallback`,3)(t,Oe(),r);return i===-1?a.delete(r):(n&&a.delete(n),this._callbackId=r),D(i)}startCallback(e){return ke(e),D(_(`Highs_startCallback`,2)(this._require(!1),e))}dispose(){if(On(this,n,`f`))return;let e=this._require(!1);this._callbackId&&a.delete(this._callbackId),o.delete(e),_(`Highs_destroy`,1,null)(e),Dn(this,t,0,`f`),Dn(this,n,!0,`f`)}_simple(e){return D(_(e,1)(this._require(!1)))}clearModel(){return this._simple(`Highs_clearModel`)}releaseMemory(){return this._simple(`Highs_releaseMemory`)}zeroAllClocks(){return this._simple(`Highs_zeroAllClocks`)}run(){let e=this._require(!1);return this._callbackNumCols=K(e).numCols,D(_(`Highs_run`,1)(e))}exportModel(e){let t=this._require(!1);if(e!==`lp`&&e!==`mps`)throw C(`format must be 'lp' or 'mps'`);return ue(e,e===`lp`?`utf8`:void 0,function(e){return v(`Highs_writeModel`,1,0)(t,e)})}exportSolution(e){let t=this._require(!1);return ue(`sol`,`utf8`,function(n){return v(e?`Highs_writeSolutionPretty`:`Highs_writeSolution`,1,0)(t,n)})}passLp(e){let t=this._require(!1),n=z(function(n){let i=re(e),a=e.matrix,o=me(e,n,!1);return _(`Highs_passLp`,15)(t,i.numCols,i.numRows,i.numNonzeros,r[a.format],i.sense,e.offset==null?0:e.offset,...o)}),i=n===-1?n:ge(t,e);return D(n===-1||i===-1?-1:Math.max(n,i))}passLinearObjectives(e){let t=this._require(!1),n=K(t).numCols;return j(e,`objectives`),D(z(function(r){let i=e.length,a=new Float64Array(i),o=new Float64Array(i),s=new Float64Array(i*n),c=new Float64Array(i),l=new Float64Array(i),u=new Int32Array(i);for(let t=0;t<i;t++){let r=e[t];ae(r,n,`objectives[`+t+`]`),a[t]=r.weight,o[t]=r.offset,s.set(r.coefficients,t*n),c[t]=r.absoluteTolerance,l[t]=r.relativeTolerance,u[t]=A(r.priority,`objectives[`+t+`].priority`)}return _(`Highs_passLinearObjectives`,8)(t,i,r.doubles(a),r.doubles(o),r.doubles(s),r.doubles(c),r.doubles(l),r.ints(u))}))}clearLinearObjectives(){return this._simple(`Highs_clearLinearObjectives`)}passColName(e,t){let n=this._require(!1);if(k(e,`column`,0),typeof t!=`string`)throw C(`name must be a string`);return D(v(`Highs_passColName`,2,0)(n,e,t))}setOptionValue(e,t){let n=this._require(!1);if(!de(e))return D(-1);let r=typeof t,i;if(r===`boolean`)i=v(`Highs_setBoolOptionValue`,1,1)(n,e,+!!t);else if(r===`string`)i=g(`Highs_setStringOptionValue`,`number`,[`number`,`string`,`string`])(n,e,t);else if(r===`number`){if(!Number.isFinite(t))throw C(`numeric option values must be finite`);Number.isSafeInteger(t)&&t>=-2147483648&&t<=2147483647?(i=v(`Highs_setIntOptionValue`,1,1)(n,e,t),i===-1&&(i=v(`Highs_setDoubleOptionValue`,1,1)(n,e,t))):i=v(`Highs_setDoubleOptionValue`,1,1)(n,e,t)}else throw C(`option values must be boolean, number, or string`);return D(i)}getOptionValue(e){let t=this._require(!1);if(!de(e))return O(-1);let n=this.getOptionType(e);return n.status===-1?O(-1):z(function(r){if(n.value===`string`){let n=r.bytes(512);return O(v(`Highs_getStringOptionValue`,1,1)(t,e,n),S(n))}if(n.value===`double`){let n=r.outDoubles(1);return O(v(`Highs_getDoubleOptionValue`,1,1)(t,e,n),x()[n>>3])}let i=r.outInts(1),a=v(n.value===`boolean`?`Highs_getBoolOptionValue`:`Highs_getIntOptionValue`,1,1)(t,e,i),o=b()[i>>2];return O(a,n.value===`boolean`?!!o:o)})}readOptions(e){let t=this._require(!1);if(typeof e!=`string`)throw C(`option data must be a string`);for(let t of e.split(/\r?\n/)){let e=/^\s*([A-Za-z][A-Za-z0-9_]*)\b/.exec(t);if(e&&!t.trimStart().startsWith(`#`)&&!de(e[1]))return D(-1)}return D(le(e,`options`,function(e){return v(`Highs_readOptions`,1,0)(t,e)}))}getNumOptions(){return _(`Highs_getNumOptions`,1)(this._require(!1))}getOptionValues(e){let t=this._require(!1);if(!de(e))return O(-1);let n=this.getOptionType(e);return n.status===-1?O(-1):z(function(r){let i=n.value;if(i===`boolean`){let n=r.outInts(1),a=r.outInts(1);return O(v(`Highs_getBoolOptionValues`,1,2)(t,e,n,a),{name:e,type:i,current:!!b()[n>>2],default:!!b()[a>>2]})}if(i===`integer`){let n=r.outInts(1),a=r.outInts(1),o=r.outInts(1),s=r.outInts(1);return O(v(`Highs_getIntOptionValues`,1,4)(t,e,n,a,o,s),{name:e,type:i,current:b()[n>>2],default:b()[s>>2],minimum:b()[a>>2],maximum:b()[o>>2]})}if(i===`double`){let n=r.outDoubles(1),a=r.outDoubles(1),o=r.outDoubles(1),s=r.outDoubles(1);return O(v(`Highs_getDoubleOptionValues`,1,4)(t,e,n,a,o,s),{name:e,type:i,current:x()[n>>3],default:x()[s>>3],minimum:x()[a>>3],maximum:x()[o>>3]})}let a=r.bytes(512),o=r.bytes(512);return O(v(`Highs_getStringOptionValues`,1,2)(t,e,a,o),{name:e,type:i,current:S(a),default:S(o)})})}getInfoValue(e){let t=this._require(!1),n=this.getInfoType(e);return n.status===-1?O(-1):z(function(r){if(n.value===`double`){let n=r.outDoubles(1);return O(v(`Highs_getDoubleInfoValue`,1,1)(t,e,n),x()[n>>3])}if(n.value===`int64`){let n=r.bytes(8);return O(v(`Highs_getInt64InfoValue`,1,1)(t,e,n),se(n))}let i=r.outInts(1);return O(v(`Highs_getIntInfoValue`,1,1)(t,e,i),b()[i>>2])})}getPresolvedDimensions(){return pe(this._require(!1))}getSizeofHighsInt(){return _(`Highs_getSizeofHighsInt`,1)(this._require(!1))}getObjectiveValue(){return _(`Highs_getObjectiveValue`,1)(this._require(!1))}getBasis(){let e=this._require(!1),t=this.getModelStatus();if(t===0||t===6)throw new d(`The model has not been solved`,`getBasis`);let n=K(e);return z(function(t){let r=t.outInts(n.numCols),i=t.outInts(n.numRows);return O(_(`Highs_getBasis`,3)(e,r,i),{colStatus:B(r,n.numCols),rowStatus:B(i,n.numRows)})})}setSparseSolution(e){let t=this._require(!1);if(!e)throw C(`solution is required`);let n=e.indices.length;return I(e.indices,null,`indices`,K(t).numCols),F(e.values,n,`values`),D(z(function(r){return _(`Highs_setSparseSolution`,4)(t,n,r.ints(e.indices),r.doubles(e.values))}))}setLogicalBasis(){return this._simple(`Highs_setLogicalBasis`)}getObjectiveSense(){let e=this._require(!1);return z(function(t){let n=t.outInts(1);return O(_(`Highs_getObjectiveSense`,2)(e,n),b()[n>>2])})}getLp(e){return _e(this,`Highs_getLp`,e,!1)}getIisLp(e){return _e(this,`Highs_getIisLp`,e,!1)}ensureColwise(){return this._simple(`Highs_ensureColwise`)}addVar(e,t){return P(e,`lower`),P(t,`upper`),D(_(`Highs_addVar`,3)(this._require(!1),e,t))}addRow(e,t,n){let r=this._require(!1);return P(e,`lower`),P(t,`upper`),ve(n,K(r).numCols),D(z(function(i){return _(`Highs_addRow`,6)(r,e,t,n.indices.length,i.ints(n.indices),i.doubles(n.values))}))}addRows(e){let t=this._require(!1),n=K(t).numCols;if(!e||!e.matrix)throw C(`row data and matrix are required`);let r=e.lower.length;if(F(e.lower,r,`lower`),F(e.upper,r,`upper`),e.matrix.format!==`csr`)throw C(`addRows requires a csr matrix`);let i=ne(e.matrix,r,n,`matrix`);return D(z(function(n){return _(`Highs_addRows`,8)(t,r,n.doubles(e.lower),n.doubles(e.upper),i,n.ints(Array.prototype.slice.call(e.matrix.starts,0,-1)),n.ints(e.matrix.indices),n.doubles(e.matrix.values))}))}changeObjectiveOffset(e){return P(e,`offset`),D(_(`Highs_changeObjectiveOffset`,2)(this._require(!1),e))}clearIntegrality(){return this._simple(`Highs_clearIntegrality`)}changeColBounds(e,t,n){return k(e,`column`,0),P(t,`lower`),P(n,`upper`),D(_(`Highs_changeColBounds`,4)(this._require(!1),e,t,n))}changeCoeff(e,t,n){return k(e,`row`,0),k(t,`column`,0),P(n,`value`),D(_(`Highs_changeCoeff`,4)(this._require(!1),e,t,n))}changeColsCost(e,t){let n=K(this._require(!1)).numCols;return J(this,`changeColsCost`,e,[t],[],n,`columns`)}changeRowsBounds(e,t,n){let r=K(this._require(!1)).numRows;return J(this,`changeRowsBounds`,e,[t,n],[],r,`rows`)}deleteRows(e){return ye(this,`Rows`,e,K(this._require(!1)).numRows)}scaleRow(e,t){return k(e,`row`,0),P(t,`factor`),D(_(`Highs_scaleRow`,3)(this._require(!1),e,t))}getRows(e){return Y(this,`Rows`,e)}getRowName(e){return be(this,`Highs_js_getRowName`,e)}getPresolvedRowName(e){return be(this,`Highs_js_getPresolvedRowName`,e)}getRowByName(e){return xe(this,`Row`,e)}getDualRay(){return X(this,`Highs_getDualRay`,K(this._require(!1)).numRows)}getBasicVariables(){let e=this._require(!1),t=K(e).numRows;return z(function(n){let r=n.outInts(t);return O(_(`Highs_getBasicVariables`,2)(e,r),B(r,t))})}getBasisInverseCol(e,t){return Se(this,`Highs_getBasisInverseCol`,e,K(this._require(!1)).numRows,t)}getBasisTransposeSolve(e,t){return Ce(this,`Highs_getBasisTransposeSolve`,e,t)}getReducedColumn(e,t){return Se(this,`Highs_getReducedColumn`,e,K(this._require(!1)).numRows,t)}feasibilityRelaxation(e){let t=this._require(!1),n=K(t);if(!e)throw C(`relaxation input is required`);return P(e.globalLowerPenalty,`globalLowerPenalty`),P(e.globalUpperPenalty,`globalUpperPenalty`),P(e.globalRowPenalty,`globalRowPenalty`),D(z(function(r){function i(e,t,n){return e==null?0:(F(e,t,n),r.doubles(e))}return _(`Highs_feasibilityRelaxation`,7)(t,e.globalLowerPenalty,e.globalUpperPenalty,e.globalRowPenalty,i(e.localLowerPenalty,n.numCols,`localLowerPenalty`),i(e.localUpperPenalty,n.numCols,`localUpperPenalty`),i(e.localRowPenalty,n.numRows,`localRowPenalty`))}))}getIis(){let e=this._require(!1),t=K(e);return z(function(n){let r=n.outInts(1),i=n.outInts(1),a=n.outInts(t.numCols),o=n.outInts(t.numRows),s=n.outInts(t.numCols),c=n.outInts(t.numRows),l=n.outInts(t.numCols),u=n.outInts(t.numRows),d=_(`Highs_getIis`,9)(e,r,i,a,o,s,c,l,u);if(d===-1)return O(d);let f=b()[r>>2],p=b()[i>>2];if(f<0||f>t.numCols||p<0||p>t.numRows)throw RangeError(`HiGHS returned invalid IIS dimensions`);return O(d,{colIndex:B(a,f),rowIndex:B(o,p),colBound:B(s,f),rowBound:B(c,p),colStatus:B(l,t.numCols),rowStatus:B(u,t.numRows)})})}stopCallback(e){return ke(e),D(_(`Highs_stopCallback`,2)(this._require(!1),e))}}t=new WeakMap,n=new WeakMap;function me(e,t,n){let r=e.matrix;return t.pack([{type:`f64`,values:e.colCost},{type:`f64`,values:e.colLower},{type:`f64`,values:e.colUpper},{type:`f64`,values:e.rowLower},{type:`f64`,values:e.rowUpper},{type:`i32`,values:Array.prototype.slice.call(r.starts,0,-1)},{type:`i32`,values:r.indices},{type:`f64`,values:r.values},...n?[{type:`i32`,values:e.integrality}]:[]])}function he(e,t){let n=re(e),a=e.matrix,o=e.hessian,s=t.pack([{type:`f64`,values:e.colCost},{type:`f64`,values:e.colLower},{type:`f64`,values:e.colUpper},{type:`f64`,values:e.rowLower},{type:`f64`,values:e.rowUpper},{type:`i32`,values:Array.prototype.slice.call(a.starts,0,-1)},{type:`i32`,values:a.indices},{type:`f64`,values:a.values},...o?[{type:`i32`,values:Array.prototype.slice.call(o.starts,0,-1)},{type:`i32`,values:o.indices},{type:`f64`,values:o.values}]:[],...e.integrality?[{type:`i32`,values:e.integrality}]:[]]),c=0,l=s[c++],u=s[c++],d=s[c++],f=s[c++],p=s[c++],m=s[c++],h=s[c++],g=s[c++],_=o?s[c++]:0,v=o?s[c++]:0,y=o?s[c++]:0,b=e.integrality?s[c]:0;return{shape:n,values:[n.numCols,n.numRows,n.numNonzeros,n.hessianNonzeros,r[a.format],o?i[o.format]:1,n.sense,e.offset==null?0:e.offset,l,u,d,f,p,m,h,g,_,v,y,b]}}function ge(e,t){let n=0;if(t.modelName!=null&&(n=Math.max(n,v(`Highs_passModelName`,1,0)(e,String(t.modelName)))),t.colNames!=null){M(t.colNames,t.numCols,`colNames`);for(let r=0;r<t.colNames.length;r++){let i=v(`Highs_passColName`,2,0)(e,r,String(t.colNames[r]));if(i===-1)return i;n=Math.max(n,i)}}if(t.rowNames!=null){M(t.rowNames,t.numRows,`rowNames`);for(let r=0;r<t.rowNames.length;r++){let i=v(`Highs_passRowName`,2,0)(e,r,String(t.rowNames[r]));if(i===-1)return i;n=Math.max(n,i)}}return n}function _e(e,t,n,i){let a=e._require(!1),o=t!==`Highs_getFixedLp`,s=n??`csc`;if(!(s in r))throw C(`format must be 'csc' or 'csr'`);let c=t===`Highs_getModel`||t===`Highs_getLp`?K(a):t===`Highs_getPresolvedLp`?pe(a):t===`Highs_getFixedLp`?K(a):void 0;return z(function(e){let n=e.outInts(1),l=e.outInts(1),u=e.outInts(1),d=i?e.outInts(1):0,f=e.outInts(1),p=e.outDoubles(1),m=i?21:o?16:15,h=0,g=c?.numCols??0,v=c?.numRows??0,y=c?.numNonzeros??0,S=i?c?.hessianNonzeros??0:0;if(!c){let e=i?[a,r[s],1,n,l,u,d,f,p]:[a,r[s],n,l,u,f,p],c=i?Array(12).fill(0):Array(o?9:8).fill(0);if(h=_(t,m).apply(null,e.concat(c)),h===-1)return O(h);g=b()[n>>2],v=b()[l>>2],y=b()[u>>2],S=i?b()[d>>2]:0}let C=s===`csc`?g:v,w=e.outDoubles(g),T=e.outDoubles(g),E=e.outDoubles(g),ee=e.outDoubles(v),D=e.outDoubles(v),te=e.outInts(C),k=e.outInts(y),A=e.outDoubles(y),j=o?e.outInts(g):0,M=i?e.outInts(g):0,N=i?e.outInts(S):0,P=i?e.outDoubles(S):0,F=i?[a,r[s],1,n,l,u,d,f,p,w,T,E,ee,D,te,k,A,M,N,P,j]:[a,r[s],n,l,u,f,p,w,T,E,ee,D,te,k,A].concat(o?[j]:[]);if(h=_(t,m).apply(null,F),h===-1)return O(h);let I=new Int32Array(C+1);I.set(B(te,C)),I[C]=y;let L={numCols:g,numRows:v,sense:b()[f>>2],offset:x()[p>>3],colCost:V(w,g),colLower:V(T,g),colUpper:V(E,g),rowLower:V(ee,v),rowUpper:V(D,v),matrix:{format:s,numRows:v,numCols:g,starts:I,indices:B(k,y),values:V(A,y)},integrality:o?B(j,g):new Int32Array(g)};if(i&&S){let e=new Int32Array(g+1);e.set(B(M,g)),e[g]=S,L.hessian={format:`triangular`,dimension:g,starts:e,indices:B(N,S),values:V(P,S)}}return O(h,L)})}function ve(e,t){if(!e)throw C(`entries are required`);I(e.indices,null,`entries.indices`,t),F(e.values,e.indices.length,`entries.values`)}function J(e,t,n,r,i,a,o){let s=e._require(!1);return D(z(function(e){let c=G(n,a,e,o),l=c.suffix===`ByMask`?a:c.count,u=r.map(function(t,n){return F(t,l,o+` values `+n),e.doubles(t)}),d=i.map(function(t,n){return I(t,l,o+` integer values `+n),e.ints(t)}),f=[s].concat(c.prefix,u,d);return _(`Highs_`+t+c.suffix,f.length).apply(null,f)}))}function ye(e,t,n,r){let i=e._require(!1);return D(z(function(e){let a=G(n,r,e,t.toLowerCase()),o=[i].concat(a.prefix);return _(`Highs_delete`+t+a.suffix,o.length).apply(null,o)}))}function Y(e,t,n){let r=e._require(!1),i=K(r),a=t===`Cols`,o=a?i.numCols:i.numRows;return z(function(e){let s=G(n,o,e,t.toLowerCase()),c=e.outInts(1),l=e.outInts(1),u=a?3:2,d=[r].concat(s.prefix,[c],Array(u).fill(0),[l,0,0,0]),f=`Highs_get`+t+s.suffix,p=_(f,d.length).apply(null,d);if(p===-1)return O(p);let m=b()[c>>2],h=b()[l>>2],g=a?e.outDoubles(m):0,v=e.outDoubles(m),y=e.outDoubles(m),x=e.outInts(m),S=e.outInts(h),C=e.outDoubles(h),w=[r].concat(s.prefix,[c],a?[g,v,y]:[v,y],[l,x,S,C]);if(p=_(f,w.length).apply(null,w),p===-1)return O(p);let T=new Int32Array(m+1);T.set(B(x,m)),T[m]=h;let E={format:a?`csc`:`csr`,numRows:a?i.numRows:m,numCols:a?m:i.numCols,starts:T,indices:B(S,h),values:V(C,h)};return O(p,a?{count:m,cost:V(g,m),lower:V(v,m),upper:V(y,m),matrix:E}:{count:m,lower:V(v,m),upper:V(y,m),matrix:E})})}function be(e,t,n){let r=e._require(!1);return k(n,`index`,0),z(function(e){let i=e.outInts(1),a=_(t,5)(r,n,0,0,i);if(a===-1)return O(a);let o=b()[i>>2];if(o<=0)return O(a,``);let s=e.bytes(o);return a=_(t,5)(r,n,s,o,i),O(a,S(s))})}function xe(e,t,n){let r=e._require(!1);if(typeof n!=`string`)throw C(`name must be a string`);return z(function(e){let i=e.outInts(1);return O(v(`Highs_get`+t+`ByName`,1,1)(r,n,i),b()[i>>2])})}function X(e,t,n){let r=e._require(!1);return z(function(e){let i=e.outInts(1),a=e.outDoubles(n);return O(_(t,3)(r,i,a),b()[i>>2]?{values:V(a,n)}:void 0)})}function Se(e,t,n,r,i){let a=e._require(!1);return z(function(e){let o=e.outDoubles(r),s=e.outInts(1),c=e.outInts(r);if(n==null)throw C(`an index is required`);k(n,`index`,0);let l=[a,n,o,s,c],u=_(t,l.length).apply(null,l),d={values:V(o,r)};return i&&(d.nonzeroIndices=B(c,b()[s>>2])),O(u,d)})}function Ce(e,t,n,r){let i=e._require(!1),a=K(i).numRows;return F(n,a,`rhs`),z(function(e){let o=e.outDoubles(a),s=e.outInts(1),c=e.outInts(a),l=_(t,5)(i,e.doubles(n),o,s,c),u={values:V(o,a)};return r&&(u.nonzeroIndices=B(c,b()[s>>2])),O(l,u)})}function we(e,t){return{valuePointer:e.outDoubles(t),objectivePointer:e.outDoubles(t),inPointer:e.outInts(t),outPointer:e.outInts(t),detach:function(){return{value:V(this.valuePointer,t),objective:V(this.objectivePointer,t),inVariable:B(this.inPointer,t),outVariable:B(this.outPointer,t)}}}}function Te(e,t){return v(`Highs_getCallbackDataOutItem`,1,0)(e,t)}function Ee(e,t,n){let r=Te(e,t);if(r)return n===`double`?x()[r>>3]:n===`int64`?se(r):b()[r>>2]}let Z=[[`running_time`,`double`],[`objective_function_value`,`double`],[`mip_node_count`,`int64`],[`mip_total_lp_iterations`,`int64`],[`mip_primal_bound`,`double`],[`mip_dual_bound`,`double`],[`mip_gap`,`double`]];function De(e,t,n,r,i){let o=a.get(i);if(!o)return;let s=o.raw,c=o.callback,l=!0;function u(){if(!l)throw C(`callback controls expire when the callback returns`)}s._callbackDepth+=1;try{let i={numCols:s._callbackNumCols},a={};if((e===0?[[`log_type`,`int`]]:e===1?[[`simplex_iteration_count`,`int`]]:e===2?[[`ipm_iteration_count`,`int`]]:e>=3&&e<=9?Z:[]).forEach(function(e){let t=Ee(n,e[0],e[1]);t!==void 0&&(a[e[0]]=t)}),e===3||e===4){let e=Te(n,`mip_solution`),t=_(`Highs_js_getCallbackMipSolutionSize`,1)(n);if(t<0)throw RangeError(`HiGHS returned an invalid MIP solution size`);if(e)a.mip_solution=V(e,t);else if(t)throw RangeError(`HiGHS returned a null MIP solution`)}if(e===7){let e=Ee(n,`cutpool_num_cut`,`int`),t=Ee(n,`cutpool_num_nz`,`int`),r=Ee(n,`cutpool_num_col`,`int`);if(typeof e==`number`&&typeof t==`number`&&typeof r==`number`&&e>=0&&t>=0){let i=Te(n,`cutpool_start`),o=Te(n,`cutpool_index`),s=Te(n,`cutpool_value`),c=Te(n,`cutpool_lower`),l=Te(n,`cutpool_upper`);i&&o&&s&&c&&l&&(a.cut_pool={numCols:r,numCuts:e,starts:B(i,e+1),indices:B(o,t),values:V(s,t),lower:V(c,e),upper:V(l,e)})}}let o={type:e,message:S(t),data:a};e===9?(o.setSolution=function(e){u();try{return e&&e.indices?(I(e.indices,null,`indices`,i.numCols),F(e.values,e.indices.length,`values`),D(z(function(t){return _(`Highs_setCallbackSparseSolution`,4)(r,e.indices.length,t.ints(e.indices),t.doubles(e.values))}))):(F(e,i.numCols,`solution`),D(z(function(t){return _(`Highs_setCallbackSolution`,3)(r,i.numCols,t.doubles(e))})))}catch(e){return s._rememberCallbackError(e),D(-1)}},o.repairSolution=function(){return u(),D(_(`Highs_repairCallbackSolution`,1)(r))}):(e===1||e===2||e===6)&&(o.interrupt=function(){u(),b()[r>>2]=1});let l=c(o);if(l&&(typeof l==`object`||typeof l==`function`)&&typeof l.then==`function`)throw Promise.resolve(l).catch(function(){}),C(`callbacks must be synchronous and return undefined`)}catch(t){s._rememberCallbackError(t),(e===1||e===2||e===6)&&r&&(b()[r>>2]=1)}finally{l=!1,--s._callbackDepth}}function Oe(){return u||=Rt(De,`viiiii`),u}function ke(e){if(k(e,`callback type`,0),e===8||e>9)throw C(`callback type must be one of 0..7 or 9`)}function Ae(e,t,n=void 0){if(e.status===-1)throw T(t);return n&&n._setLast(e.status,t),e.value}class je{constructor(e){this.raw=e,this.lastCall={status:0,warnings:[]},this.options=new Me(this),this.info=new Ne(this)}get disposed(){return this.raw.disposed}_setLast(e,t){return this.lastCall=te(e,t),this.lastCall}_value(e,t=[]){return Ae(this.raw[e].apply(this.raw,t||[]),e,this)}exportModel(e){return this._value(`exportModel`,[e])}exportSolution(e){return this._value(`exportSolution`,[e])}getPresolvedDimensions(){return this.raw.getPresolvedDimensions()}getModelStatus(){return this.raw.getModelStatus()}setSolution(e){if(e==null)throw C(`solution is required`);return this._status(e.indices?`setSparseSolution`:`setSolution`,[e])}setLogicalBasis(){return this._status(`setLogicalBasis`)}dispose(){this.raw.dispose()}_status(e,t=[]){let n=this.raw[e].apply(this.raw,t||[]);return this._setLast(n.status,e)}exportPresolvedModel(e){return this._value(`exportPresolvedModel`,[e])}getDimensions(){return this.raw.getDimensions()}getRunTime(){return this.raw.getRunTime()}getObjectiveValue(){return this.raw.getObjectiveValue()}getObjectiveSense(){return this._value(`getObjectiveSense`)}getObjectiveOffset(){return this._value(`getObjectiveOffset`)}setBasis(e){return e==null?this._status(`setLogicalBasis`):this._status(`setBasis`,[e])}run(e){let t=this.raw,n=[],r=!1;try{if(e&&Object.keys(e).length){if(t._callbackId)throw C(`run callbacks cannot replace a callback registered through model.raw`);if(t.setCallback(function(t){let n=e[t.type];if(n)return n(t)}).status===-1)throw T(`setCallback`);r=!0,Object.keys(e).forEach(function(e){let r=Number(e);if(ke(r),t.startCallback(r).status===-1)throw T(`startCallback`);n.push(r)})}let i=t.run(),a=this._setLast(i.status,`run`);return{status:a.status,warnings:a.warnings,modelStatus:t.getModelStatus()}}finally{try{for(let e=0;e<n.length;e++)t.stopCallback(n[e])}finally{r&&t.setCallback(void 0)}}}clear(...e){return this._status(`clear`,e)}clearModel(...e){return this._status(`clearModel`,e)}clearSolver(...e){return this._status(`clearSolver`,e)}releaseMemory(...e){return this._status(`releaseMemory`,e)}readModel(...e){return this._status(`readModel`,e)}passModel(...e){return this._status(`passModel`,e)}passHessian(...e){return this._status(`passHessian`,e)}passLinearObjectives(...e){return this._status(`passLinearObjectives`,e)}addLinearObjective(...e){return this._status(`addLinearObjective`,e)}clearLinearObjectives(...e){return this._status(`clearLinearObjectives`,e)}presolve(...e){return this._status(`presolve`,e)}postsolve(...e){return this._status(`postsolve`,e)}zeroAllClocks(...e){return this._status(`zeroAllClocks`,e)}addVar(...e){return this._status(`addVar`,e)}addVars(...e){return this._status(`addVars`,e)}addCol(...e){return this._status(`addCol`,e)}addCols(...e){return this._status(`addCols`,e)}addRow(...e){return this._status(`addRow`,e)}addRows(...e){return this._status(`addRows`,e)}ensureColwise(...e){return this._status(`ensureColwise`,e)}ensureRowwise(...e){return this._status(`ensureRowwise`,e)}changeObjectiveSense(...e){return this._status(`changeObjectiveSense`,e)}changeObjectiveOffset(...e){return this._status(`changeObjectiveOffset`,e)}changeColIntegrality(...e){return this._status(`changeColIntegrality`,e)}changeColsIntegrality(...e){return this._status(`changeColsIntegrality`,e)}clearIntegrality(...e){return this._status(`clearIntegrality`,e)}changeColCost(...e){return this._status(`changeColCost`,e)}changeColsCost(...e){return this._status(`changeColsCost`,e)}changeColBounds(...e){return this._status(`changeColBounds`,e)}changeColsBounds(...e){return this._status(`changeColsBounds`,e)}changeRowBounds(...e){return this._status(`changeRowBounds`,e)}changeRowsBounds(...e){return this._status(`changeRowsBounds`,e)}deleteCols(...e){return this._status(`deleteCols`,e)}deleteRows(...e){return this._status(`deleteRows`,e)}scaleCol(...e){return this._status(`scaleCol`,e)}scaleRow(...e){return this._status(`scaleRow`,e)}passColName(...e){return this._status(`passColName`,e)}passRowName(...e){return this._status(`passRowName`,e)}passModelName(...e){return this._status(`passModelName`,e)}crossover(...e){return this._status(`crossover`,e)}feasibilityRelaxation(...e){return this._status(`feasibilityRelaxation`,e)}changeCoefficient(...e){return this._status(`changeCoeff`,e)}getSolution(...e){return this._value(`getSolution`,e)}getBasis(...e){return this._value(`getBasis`,e)}getPrimalRay(...e){return this._value(`getPrimalRay`,e)}getDualRay(...e){return this._value(`getDualRay`,e)}getDualUnboundednessDirection(...e){return this._value(`getDualUnboundednessDirection`,e)}getModel(...e){return this._value(`getModel`,e)}getLp(...e){return this._value(`getLp`,e)}getPresolvedLp(...e){return this._value(`getPresolvedLp`,e)}getIisLp(...e){return this._value(`getIisLp`,e)}getFixedLp(...e){return this._value(`getFixedLp`,e)}getCols(...e){return this._value(`getCols`,e)}getRows(...e){return this._value(`getRows`,e)}getColName(...e){return this._value(`getColName`,e)}getRowName(...e){return this._value(`getRowName`,e)}getPresolvedColName(...e){return this._value(`getPresolvedColName`,e)}getPresolvedRowName(...e){return this._value(`getPresolvedRowName`,e)}getColByName(...e){return this._value(`getColByName`,e)}getRowByName(...e){return this._value(`getRowByName`,e)}getColIntegrality(...e){return this._value(`getColIntegrality`,e)}getBasicVariables(...e){return this._value(`getBasicVariables`,e)}getBasisInverseRow(...e){return this._value(`getBasisInverseRow`,e)}getBasisInverseCol(...e){return this._value(`getBasisInverseCol`,e)}getBasisSolve(...e){return this._value(`getBasisSolve`,e)}getBasisTransposeSolve(...e){return this._value(`getBasisTransposeSolve`,e)}getReducedRow(...e){return this._value(`getReducedRow`,e)}getReducedColumn(...e){return this._value(`getReducedColumn`,e)}getRanging(...e){return this._value(`getRanging`,e)}getIis(...e){return this._value(`getIis`,e)}}class Me{constructor(e){this._model=e}set(e,t){if(typeof e==`object`&&e){Object.keys(e).forEach(W);let t=0;return Object.keys(e).forEach(function(n){let r=this._model.raw.setOptionValue(n,e[n]);if(r.status===-1)throw T(`setOptionValue`);t=Math.max(t,r.status)}.bind(this)),this._model._setLast(t,`setOptionValue`)}return W(e),this._model._status(`setOptionValue`,[e,t])}describe(e){return W(e),this._model._value(`getOptionValues`,[e])}reset(){return this._model._status(`resetOptions`)}export(e){return this._model._value(`exportOptions`,[e])}get(e){return W(e),this._model._value(`getOptionValue`,[e])}names(){let e=this._model.raw.getNumOptions(),t=[];for(let n=0;n<e;n++){let e=this._model.raw.getOptionName(n);if(e.status===-1)throw T(`getOptionName`);U(e.value)||t.push(e.value)}return t}read(e){return fe(e),this._model._status(`readOptions`,[e])}}class Ne{constructor(e){this._model=e}get(e){return this._model._value(`getInfoValue`,[e])}type(e){return this._model._value(`getInfoType`,[e])}}function $(){let e=_(`Highs_create`,0)();if(!e)throw Error(`Highs_create failed`);let t=Ie(new q(e));return v(`Highs_setIntOptionValue`,1,1)(e,`threads`,1),g(`Highs_setStringOptionValue`,`number`,[`number`,`string`,`string`])(e,`parallel`,`off`),t}function Fe(e){let t=Ie(new je($()));try{return e&&(e.format===`lp`||e.format===`mps`?t.readModel(e):t.passModel(e)),t}catch(e){throw t.dispose(),e}}function Ie(e){let t=Symbol.dispose;return t!==void 0&&Object.defineProperty(e,t,{configurable:!0,writable:!0,value:e.dispose}),e}function Le(e){return e!==null&&(typeof e==`object`||typeof e==`function`)&&typeof e.then==`function`}function Re(e,t=void 0){let n=typeof e!=`function`,r=n?e:void 0,i=n?t:e;if(typeof i!=`function`)throw C(`withModel requires a callback`);let a=Fe(r);try{let e=i(a);return Le(e)?Promise.resolve(e).finally(function(){a.dispose()}):(a.dispose(),e)}catch(e){throw a.dispose(),e}}function ze(e,t){let n=re(t);return z(function(a){let o=t.matrix,s=e===`Highs_mipCall`,c=a.outDoubles(n.numCols),l=s?0:a.outDoubles(n.numCols),u=a.outDoubles(n.numRows),d=s?0:a.outDoubles(n.numRows),f=s?0:a.outInts(n.numCols),p=s?0:a.outInts(n.numRows),m=a.outInts(1),h=me(t,a,s),g=[n.numCols,n.numRows,n.numNonzeros,r[o.format],n.sense,t.offset==null?0:t.offset,...h.slice(0,8)],v;if(e===`Highs_mipCall`){if(!t.integrality)throw C(`mipCall requires integrality`);v=g.concat([h[8],c,u,m])}else if(e===`Highs_qpCall`){if(!t.hessian)throw C(`qpCall requires hessian`);let e=t.hessian;v=g.slice(0,3).concat([n.hessianNonzeros,r[o.format],i[e.format],n.sense,t.offset==null?0:t.offset,...h.slice(0,8),a.ints(Array.prototype.slice.call(e.starts,0,-1)),a.ints(e.indices),a.doubles(e.values),c,l,u,d,f,p,m])}else v=g.concat([c,l,u,d,f,p,m]);let y=_(e,v.length).apply(null,v);return s?O(y,{modelStatus:b()[m>>2],solution:{colValue:V(c,n.numCols),rowValue:V(u,n.numRows)}}):O(y,{modelStatus:b()[m>>2],solution:{colValue:V(c,n.numCols),rowValue:V(u,n.numRows),colDual:V(l,n.numCols),rowDual:V(d,n.numRows)},basis:{colStatus:B(f,n.numCols),rowStatus:B(p,n.numRows)}})})}let Be=Object.freeze({major:_(`Highs_versionMajor`,0)(),minor:_(`Highs_versionMinor`,0)(),patch:_(`Highs_versionPatch`,0)(),string:g(`Highs_version`,`string`,[])(),gitHash:g(`Highs_githash`,`string`,[])()}),Ve=Object.freeze({status:Object.freeze({error:-1,ok:0,warning:1}),variableType:Object.freeze({continuous:0,integer:1,semiContinuous:2,semiInteger:3,implicitInteger:4}),objectiveSense:Object.freeze({minimize:1,maximize:-1}),matrixFormat:Object.freeze({columnWise:1,rowWise:2}),hessianFormat:Object.freeze({triangular:1,square:2}),optionType:Object.freeze({boolean:0,integer:1,double:2,string:3}),infoType:Object.freeze({int64:-1,integer:1,double:2}),solutionStatus:Object.freeze({none:0,infeasible:1,feasible:2}),basisValidity:Object.freeze({invalid:0,valid:1}),basisStatus:Object.freeze({lower:0,basic:1,upper:2,zero:3,nonbasic:4}),callbackType:Object.freeze({logging:0,simplexInterrupt:1,ipmInterrupt:2,mipSolution:3,mipImprovingSolution:4,mipLogging:5,mipInterrupt:6,mipCutPool:7,mipUserSolution:9}),presolveStatus:Object.freeze({notPresolved:-1,notReduced:0,infeasible:1,unboundedOrInfeasible:2,reduced:3,reducedToEmpty:4,timeout:5,nullError:6,optionsError:7,outOfMemory:8}),modelStatus:Object.freeze({notSet:0,loadError:1,modelError:2,presolveError:3,solveError:4,postsolveError:5,empty:6,optimal:7,infeasible:8,unboundedOrInfeasible:9,unbounded:10,objectiveBound:11,objectiveTarget:12,timeLimit:13,iterationLimit:14,unknown:15,solutionLimit:16,interrupted:17}),iis:Object.freeze({strategyLight:0,strategyRowPriority:6,strategyColPriority:14,boundFree:1,boundLower:2,boundUpper:3,boundBoxed:4,notInConflict:-1,maybeInConflict:0,inConflict:1})}),He=$(),Ue=He.getInfinity(),We=He.getSizeofHighsInt();if(He.dispose(),We!==4)throw Error(`This highs-js runtime requires a 32-bit HighsInt build; received `+We*8+` bits`);e.version=Be,e.infinity=Ue,e.intBytes=We,e.intBits=We*8,Object.defineProperty(e,"memoryBytes",{enumerable:!0,get:function(){return y().buffer.byteLength}}),e.constants=Ve,e.errors=Object.freeze({HighsError:d,HighsDisposedError:f,HighsValidationError:p,HighsReentrancyError:m,HighsUnsupportedOptionError:h}),e.createModel=Fe,e.withModel=Re,e.raw=Object.freeze({version:function(){return Be},lpCall:function(e){return ze(`Highs_lpCall`,e)},mipCall:function(e){return ze(`Highs_mipCall`,e)},qpCall:function(e){return ze(`Highs_qpCall`,e)},createModel:$})})(n),n}})();typeof e==`object`&&typeof t==`object`?(t.exports=n,t.exports.default=n):typeof define==`function`&&define.amd&&define([],()=>n)})),fe=l({default:()=>G.default}),G,K=s((()=>{G=d(de(),1)})),pe=`https://cdn.jsdelivr.net/npm/highs@1.15.3/build/highs.wasm`,q=null,me=null,he=null;function ge(e){he=e,q=null,me=null}function _e(){return he}function ve(e){return e.length>=4&&e[0]===0&&e[1]===97&&e[2]===115&&e[3]===109}async function J(e){try{let t=await fetch(e,{headers:{Range:`bytes=0-3`}});if(!t.ok||(t.headers.get(`content-type`)||``).includes(`text/html`))return!1;if(!t.body)return!0;let n=t.body.getReader(),{value:r,done:i}=await n.read();return await n.cancel(),i||!r||r.length<4?!1:ve(r)}catch{return!1}}async function ye(e){return e||he||W()}async function Y(e={}){let t=await ye(e.wasmUrl),n=t??`node`;if(q&&me===n)return q;me=n;let r=(async()=>{let e=(await Promise.resolve().then(()=>(K(),fe))).default;return await e({locateFile:e=>e.endsWith(`.wasm`)?t:e})})().catch(e=>{q===r&&(q=null,me=null);let n=e instanceof Error?e.message:String(e);throw Error(`[WaSHI] Failed to initialize HiGHS${t?` from "${t}"`:``}. Deploy the package's WASM asset or explicitly set wasmUrl; no CDN fallback is attempted. ${n}`,{cause:e})});return q=r,r}async function be(e,t={}){let n=await Y(t),r=performance.now(),i={output_flag:t.outputFlag??!1};return t.timeLimit!==void 0&&(i.time_limit=t.timeLimit),t.presolve!==void 0&&(i.presolve=t.presolve),t.solver!==void 0&&(i.solver=t.solver),t.relGap!==void 0&&(i.mip_rel_gap=t.relGap),t.absGap!==void 0&&(i.mip_abs_gap=t.absGap),{result:n.solve(e,i),runTime:(performance.now()-r)/1e3}}function xe(){let e=U(`highs-worker.js`);if(new URL(e).origin===window.location.origin)return new Worker(e,{type:`module`});let t=URL.createObjectURL(new Blob([`import `+JSON.stringify(e)+`;`],{type:`text/javascript`}));try{let e=new Worker(t,{type:`module`}),n=()=>URL.revokeObjectURL(t);return e.addEventListener(`message`,n,{once:!0}),e.addEventListener(`error`,n,{once:!0}),e}catch(e){throw URL.revokeObjectURL(t),e}}var X=null,Se=0,Ce=new Map;function we(){if(typeof window>`u`||typeof Worker>`u`)return null;if(!X)try{X=xe();let e=X;X.onmessage=e=>{let{type:t,id:n,result:r,runTime:i,error:a}=e.data,o=Ce.get(n);o&&(Ce.delete(n),t===`SOLVE_SUCCESS`?o.resolve({result:r,runTime:i}):o.reject(Error(a||`Worker solve failed`)))};let t=t=>{if(X===e){X=null,e.terminate();for(let e of Ce.values())e.reject(t);Ce.clear()}};X.onerror=e=>t(Error(`[WaSHI] HiGHS Worker failed to load or execute. Check Worker assets, CORS and CSP. ${e?.message||``}`)),X.onmessageerror=()=>t(Error(`[WaSHI] Could not deserialize the HiGHS Worker response.`))}catch{X=null}return X}async function Te(e,t={}){let n=await ye(t.wasmUrl),r=t.useWorker??typeof window<`u`?we():null;if(!r)return be(e,t);let i={...t,wasmUrl:n},a=`req_${++Se}`;return new Promise((t,n)=>{Ce.set(a,{resolve:t,reject:n});try{r.postMessage({type:`SOLVE`,id:a,lpString:e,options:i})}catch(e){Ce.delete(a),n(e)}})}function Ee(e){if(typeof e!=`string`)return`Unknown`;let t=e.trim();if(!t)return`Unknown`;switch(t){case`Optimal`:return`Optimal`;case`Infeasible`:return`Infeasible`;case`Unbounded`:return`Unbounded`;case`Primal infeasible or unbounded`:return`Unknown`;case`Time limit reached`:case`TimeLimit`:return`TimeLimit`;case`Iteration limit reached`:case`IterationLimit`:return`IterationLimit`;case`Bound on objective reached`:case`Target for objective reached`: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`}let n=t.toLowerCase();return n.includes(`infeasible`)&&n.includes(`unbounded`)?`Unknown`:n.includes(`infeasible`)?`Infeasible`:n.includes(`unbounded`)?`Unbounded`:n.includes(`time limit`)||n.includes(`timelimit`)?`TimeLimit`:n.includes(`iteration limit`)||n.includes(`iterationlimit`)?`IterationLimit`:n.includes(`error`)?`Error`:n===`optimal`?`Optimal`:`Unknown`}var Z=class e{static capabilities={supportsMIP:!0,supportsQP:!0};name=`HiGHS`;version=`1.15.3`;capabilities=e.capabilities;options;constructor(e={}){this.options=e}async solve(e,t,n={}){let r={...this.options,...n},{lpString:i,nameToVar:a,nameToConstraint:o}=t,{result:s,runTime:c}=await Te(i,r),l=Ee(s?.Status);if(l===`Infeasible`||l===`Unbounded`)return{status:l,objectiveValue:null,values:{},reducedCosts:{},duals:{},slacks:{},runTime:c,raw:s};let u=s.ObjectiveValue,d=typeof u==`number`?u+e.objective.constant:null,f={},p={},m={},h={};if(s.Columns)for(let[e,t]of Object.entries(s.Columns)){let n=a.get(e);if(n){let e=Math.abs(t.Primal)<1e-9?0:t.Primal;f[n.name]=e,t.Dual!==void 0&&(m[n.name]=Math.abs(t.Dual)<1e-9?0:t.Dual)}}if(s.Rows){let e=Array.isArray(s.Rows)?s.Rows:Object.values(s.Rows);for(let t of e){let e=t.Name,n=o.get(e);if(n&&(t.Dual!==void 0&&(p[n.name]=Math.abs(t.Dual)<1e-9?0:t.Dual),t.Primal!==void 0)){let e=n.rhs-t.Primal;h[n.name]=Math.abs(e)<1e-9?0:e}}}return{status:l,objectiveValue:d,values:f,reducedCosts:m,duals:p,slacks:h,runTime:c,raw:s}}},De=Z;function Oe(){V(`highs`,e=>new Z(e)),se(e=>new Z(e))}Oe();var ke=class{name;capabilities;options;constructor(e={}){this.name=e.name||`MockSolver`,this.capabilities=e.capabilities||{supportsMIP:!0,supportsQP:!0},this.options=e}async solve(e,t,n={}){let r={...this.options,...n};return r.delayMs&&r.delayMs>0&&await new Promise(e=>setTimeout(e,r.delayMs)),{status:r.status||`Optimal`,objectiveValue:r.objectiveValue??0,values:r.values||{},reducedCosts:r.reducedCosts,duals:r.duals,slacks:r.slacks,runTime:.001,raw:{mock:!0}}}};function Ae(){V(`mock`,e=>new ke(e))}Ae();var je=class{name;sense;objective;variables=[];constraints=[];boolVars=[];logicalConstraints=[];unsatCore=[];values=new Map;varMapByName=new Map;boolVarMapByName=new Map;boolVarPrefixCounters=new Map;constrMapByName=new Map;status=`NotSolved`;objectiveValue=null;runTime=0;solution=null;solver=null;constructor(e={},t){let n;n=typeof e==`string`?{...t,name:e}:e,this.name=n.name||`OptimizationModel`,this.sense=f(n.sense),this.objective=new E,n.solver&&(this.solver=H(n.solver))}get vars(){return this.variables}get constrs(){return this.constraints}get numVars(){return this.variables.length}get numConstrs(){return this.constraints.length}createDomainVars(e,t,n,r){if(typeof n==`number`||Array.isArray(n)){let i=typeof t==`number`?Array.from({length:t},(e,t)=>t):t,a=typeof n==`number`?Array.from({length:n},(e,t)=>t):n,o=r||{},s=o.prefix||o.name||`x`,c={};for(let t of i){c[t]={};for(let n of a)c[t][n]=this.addVar({...o,type:e,name:`${s}_${t}_${n}`})}return c}if(typeof t==`string`){let r=n||{};return this.addVar({...r,type:e,name:t})}let i=n||{},a=i.prefix||i.name;if(typeof t==`number`){let n=[],r=a||`x`;for(let a=0;a<t;a++)n.push(this.addVar({...i,type:e,name:`${r}_${a}`}));return n}if(Array.isArray(t)||t&&typeof t[Symbol.iterator]==`function`){let n={};for(let r of t){let t=a?`${a}_${r}`:`${r}`;n[r]=this.addVar({...i,type:e,name:t})}return n}throw Error(`Invalid arguments provided for ${e.toLowerCase()} 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)}bool(e,t,n){if(typeof t==`number`||Array.isArray(t)){let r=typeof e==`number`?Array.from({length:e},(e,t)=>t):e,i=typeof t==`number`?Array.from({length:t},(e,t)=>t):t,a=n||{},o=a.prefix||a.name||`p`,s={};for(let e of r){s[e]={};for(let t of i)s[e][t]=this.createBoolVar(`${o}_${e}_${t}`)}return s}if(typeof e==`string`||e===void 0)return this.createBoolVar(e);let r=t||{},i=r.prefix||r.name;if(typeof e==`number`){let t=[],n=i||`p`;for(let r=0;r<e;r++)t.push(this.createBoolVar(this.getNextBoolVarName(n)));return t}if(Array.isArray(e)||e&&typeof e[Symbol.iterator]==`function`){let t={};for(let n of e){let e=i?`${i}_${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)}getNextBoolVarName(e){let t=this.boolVarPrefixCounters.get(e)??0,n=`${e}_${t}`;for(;this.hasVarName(n);)t++,n=`${e}_${t}`;return this.boolVarPrefixCounters.set(e,t+1),n}createBoolVar(e){let t=typeof e==`string`?e.trim():void 0,n=t&&t.length>0?t:this.getNextBoolVarName(`p`);if(this.hasVarName(n))throw Error(`Variable with name '${n}' already exists in model`);let r=new h(n);return this.boolVars.push(r),this.boolVarMapByName.set(r.name,r),r}addVar(e){let t=e||{},n=typeof t.name==`string`?t.name.trim():void 0,r=n&&n.length>0?n:void 0,i=new k({...t,name:r});if(this.hasVarName(i.name))throw Error(`Variable with name '${i.name}' already exists in model`);return this.variables.push(i),this.varMapByName.set(i.name,i),i}getVarByName(e){return this.varMapByName.get(e)}getBoolVarByName(e){return this.boolVarMapByName.get(e)}getConstraintByName(e){return this.constrMapByName.get(e)}setObjective(e,t){if(e instanceof C)throw Error("Cannot set objective to a constraint comparison (<=, >=, ==). Did you mean to use m.constrain(expr`... <= ...`)? For objectives, supply an unconstrained expression like expr`45 * ${x} + 80 * ${y}`.");t&&(this.sense=f(t)),this.objective=typeof e==`string`?F(e,e=>this.getVarByName(e)):typeof e==`number`?new E(new Map,e):e instanceof T||`terms`in e?e.clone():new E(new Map([[e,1]]),0)}maximize(e){this.setObjective(e,`Maximize`)}minimize(e){this.setObjective(e,`Minimize`)}constrain(e,t){if(Array.isArray(e)){for(let t of e)this.constrain(t);return this}if(e instanceof T)throw Error(`Cannot add a quadratic expression without a comparison operator (<=, >=, ==) as a constraint. Quadratic constraints are not supported (only linear constraints are allowed in MILP/LP/QP).`);if(e instanceof E)throw Error("Cannot add a linear expression without a comparison operator (<=, >=, ==) as a constraint. Use expr`... <= ...` or .le(), .ge(), .eq().");return this.addConstraint(e,t),this}getValues(e){if(e==null)return null;if(e instanceof k||e instanceof h)return e.value;if(Array.isArray(e))return e.map(e=>this.getValues(e));if(typeof e==`object`){let t={};for(let[n,r]of Object.entries(e))t[n]=this.getValues(r);return t}return null}addConstraint(e,t){if(e instanceof T)throw Error(`Cannot add a quadratic expression without a comparison operator (<=, >=, ==) as a constraint. Quadratic constraints are not supported (only linear constraints are allowed in MILP/LP/QP).`);if(e instanceof E)throw Error("Cannot add a linear expression without a comparison operator (<=, >=, ==) as a constraint. Use expr`... <= ...` or .le(), .ge(), .eq().");if(e instanceof m){let n=t||`lc_${this.logicalConstraints.length+1}`;return this.logicalConstraints.push({name:n,expr:e}),e}let n;if(typeof e==`string`?n=I(e,e=>this.getVarByName(e),t):(n=e,t&&(n.name=t)),this.constrMapByName.has(n.name))throw Error(`Constraint with name '${n.name}' already exists in model`);return this.constraints.push(n),this.constrMapByName.set(n.name,n),n}add(e,t){if(Array.isArray(e)){for(let t of e)this.add(t);return this}return e instanceof k?(this.varMapByName.has(e.name)||(this.variables.push(e),this.varMapByName.set(e.name,e)),this):(this.addConstraint(e,t),this)}indicator(e,t,n={}){if(t instanceof T)throw Error(`Quadratic expressions or constraints are not supported in indicator constraints (only linear constraints are allowed).`);if(!(`sense`in t)||!(`lhs`in t))throw Error(`Invalid constraint expression passed to indicator(). Expression must include a comparison operator (<=, >=, ==).`);let r=t,i=n.activeValue===void 0?1:n.activeValue,a=n.M===void 0?1e5:n.M,o=n.name||`ind_${e.name}_${r.name}`,s=[],{lhs:c,sense:l,rhs:u}=r;if(i===1){if(l===`<=`||l===`==`){let t=this.addConstraint(c.add(e.mul(a)).le(u+a),l===`==`?`${o}_le`:o);s.push(t)}if(l===`>=`||l===`==`){let t=this.addConstraint(c.sub(e.mul(a)).ge(u-a),l===`==`?`${o}_ge`:o);s.push(t)}}else{if(l===`<=`||l===`==`){let t=this.addConstraint(c.sub(e.mul(a)).le(u),l===`==`?`${o}_le`:o);s.push(t)}if(l===`>=`||l===`==`){let t=this.addConstraint(c.add(e.mul(a)).ge(u),l===`==`?`${o}_ge`:o);s.push(t)}}return s}toLpString(){let{lpString:e}=ie({name:this.name,sense:this.sense,objective:this.objective,constraints:this.constraints,variables:this.variables});return e}async optimize(e,t){let n,r;if(e&&typeof e==`object`&&`solve`in e&&typeof e.solve==`function`?(n=e,r=t||{}):typeof e==`function`?(n=new e(t),r=t||{}):typeof e==`string`?(n=H(e,t),r=t||{}):(r={...e},r.solver?(n=H(r.solver,r),delete r.solver):n=this.solver||H()),this.objective instanceof T&&this.objective.quadTerms.size>0&&n.capabilities?.supportsQP===!1)throw Error(`Solver "${n.name}" does not support quadratic objectives (QP). Please use a QP-capable solver such as HiGHS or Clarabel.`);if(this.logicalConstraints.length>0&&n.capabilities?.supportsSMT!==!0)throw Error(`Solver "${n.name}" does not support SMT / logical constraints (or, implies, not, xor). Please use an SMT-capable solver such as Z3.`);let i={name:this.name,sense:this.sense,objective:this.objective,constraints:this.constraints,variables:this.variables,logicalConstraints:this.logicalConstraints,boolVars:this.boolVars},a=ie(i),o=await n.solve(i,a,r);this.runTime=o.runTime??0,this.status=o.status,this.objectiveValue=o.objectiveValue??null;let s={},c={},l={},u={};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;if(a?.nameToVar)for(let e of a.nameToVar.values())e.value=null,e.reducedCost=null;if(a?.nameToConstraint)for(let e of a.nameToConstraint.values())e.dual=null,e.slack=null;if(o.values&&o.status!==`Infeasible`&&o.status!==`Unbounded`){for(let[e,t]of Object.entries(o.values))if(typeof t==`number`&&!Number.isNaN(t)){this.values.set(e,t);let n=this.getVarByName(e)||a.nameToVar.get(e);n&&(n.value=t,s[n.name]=t);let r=this.boolVars.find(t=>t.name===e);r&&(r.value=!!t)}}if(o.reducedCosts)for(let[e,t]of Object.entries(o.reducedCosts)){let n=this.getVarByName(e)||a.nameToVar.get(e);n&&(n.reducedCost=t,l[n.name]=t)}if(o.duals)for(let[e,t]of Object.entries(o.duals)){let n=this.getConstraintByName(e)||a.nameToConstraint.get(e);n&&(n.dual=t,c[n.name]=t)}if(o.slacks)for(let[e,t]of Object.entries(o.slacks)){let n=this.getConstraintByName(e)||a.nameToConstraint.get(e);n&&(n.slack=t,u[n.name]=t)}return this.solution={status:this.status,objectiveValue:this.objectiveValue,values:s,duals:c,reducedCosts:l,slacks:u,runTime:this.runTime,raw:o.raw},this.status}async solve(e,t){return this.optimize(e,t)}async check(e,t){let n,r;if(e&&typeof e==`object`&&`solve`in e&&typeof e.solve==`function`?(n=e,r=t||{}):typeof e==`function`?(n=new e(t),r=t||{}):typeof e==`string`?(n=H(e,t),r=t||{}):(r={...e},r.solver?(n=H(r.solver,r),delete r.solver):n=this.solver||H()),this.logicalConstraints.length>0&&n.capabilities?.supportsSMT!==!0)throw Error(`Solver "${n.name}" does not support SMT / logical constraints (or, implies, not, xor). Please use an SMT-capable solver such as Z3.`);if(typeof n.check==`function`){let e=await n.check({name:this.name,variables:this.variables,boolVars:this.boolVars,constraints:this.constraints,logicalConstraints:this.logicalConstraints},r);this.status=e.status,this.runTime=e.runTime??0,this.unsatCore=e.unsatCore||[],this.values.clear();for(let e of this.variables)e.value=null;for(let e of this.boolVars)e.value=null;if(e.values&&e.status===`Sat`)for(let[t,n]of Object.entries(e.values)){this.values.set(t,n);let e=this.getVarByName(t);e&&typeof n==`number`&&(e.value=n);let r=this.boolVars.find(e=>e.name===t);r&&(r.value=!!n)}return e}let i=this.objective,a=this.sense;try{this.objective=new E,this.sense=`Minimize`;let e=await this.optimize(n,r),t=e===`Optimal`||e===`Feasible`,i=e===`Infeasible`,a={};if(t){for(let e of this.variables)e.value!==null&&(a[e.name]=e.value);for(let e of this.boolVars)e.value!==null&&(a[e.name]=e.value)}return{status:t?`Sat`:i?`Unsat`:`Unknown`,values:a,runTime:this.runTime}}finally{this.objective=i,this.sense=a}}};return e.BoolExpr=m,e.BoolOp=g,e.BoolVar=h,e.Constraint=C,e.HiGHS=De,e.HighsSolver=Z,e.LinExpr=E,e.MockSolver=ke,e.Model=je,e.OFFICIAL_HIGHS_CDN_WASM_URL=pe,e.QuadExpr=T,e.Var=k,e.and=_,e.c=ne,e.dot=D,e.expr=R,e.generateLpString=ie,e.getHighs=Y,e.getHighsWasmUrl=_e,e.getSolver=H,e.implies=b,e.isValidWasmHeader=ve,e.listAvailableSolvers=ce,e.normalizeSense=f,e.not=y,e.or=v,e.parseConstraint=I,e.parseExpr=F,e.probeWasmUrl=J,e.registerSolver=V,e.resolveBrowserWasmUrl=ye,e.setDefaultSolver=se,e.setHighsWasmUrl=ge,e.solveLpWithHighs=be,e.sum=ee,e.xor=x,e})({});
|
|
3
|
+
`,nameToVar:s,nameToConstraint:l}}var ye=Symbol.for(`washi.solverRegistry`),be=Symbol.for(`washi.defaultSolverFactory`),xe=globalThis;xe[ye]||(xe[ye]=new Map);var R=xe[ye];function Se(e,t){R.set(e.toLowerCase(),t)}function Ce(e){if(typeof e==`string`){let t=R.get(e.toLowerCase());if(!t)throw Error(`Solver '${e}' is not registered.`);xe[be]=t}else xe[be]=typeof e==`function`?e:()=>e}function we(e,t){if(!e){let e=xe[be]||R.get(`highs`);if(!e)throw Error(`No default solver available. Available solvers: ${Te().join(`, `)}`);return e(t)}if(typeof e==`string`){let n=e.toLowerCase(),r=R.get(n);if(!r)throw Error(n===`glpk`?`Solver 'glpk' not found. Available solvers: ${Te().join(`, `)}. Please import '@ohtaman/washi/solvers/glpk' before selecting this solver.`:n===`z3`?`Solver 'z3' not found. Available solvers: ${Te().join(`, `)}. Please import '@ohtaman/washi/solvers/z3' before selecting this solver.`:`Solver '${e}' not found. Available solvers: ${Te().join(`, `)}`);return r(t)}return e}function Te(){return Array.from(R.keys())}var Ee=typeof document<`u`?document.currentScript?.src:null,De=Ee?new URL(`.`,Ee).href:null;function z(e){if(!De)throw Error(`[WaSHI] Load the browser IIFE using an external script src, or use the browser ESM build.`);return new URL(e,De).href}function Oe(){return z(`highs.wasm`)}function B(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 V(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 H,U,W,G,ke,Ae,je,Me=n((()=>{H=class extends Error{constructor(e){super(e),this.name=`HighsError`}},U=class extends H{constructor(e){super(e),this.name=`HighsUnsupportedOptionError`}},W={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`},G={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}},ke=0,Ae=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 H(`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 U(`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 H(`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 H(`Highs_setSparseSolution failed with status ${i}`)}finally{this.module._free(n),this.module._free(r)}return}throw new H(`Invalid argument to setSolution (expected { colValue } or { indices, values })`)}run(e){let t=0,n=[];if(e&&typeof this.module.addFunction==`function`){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=B(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 H(`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:B(this.module,t,e.numCols),colDual:B(this.module,n,e.numCols),rowValue:B(this.module,r,e.numRows),rowDual:B(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()}},je=class{module;bindings;constants=G;errors={HighsError:H,HighsUnsupportedOptionError:U};constructor(e){this.module=e,this.bindings=V(e)}withModel(e,t){let n=this.bindings.create(),r=new Ae(this.module,this.bindings,n),i=`/model_${++ke}.${e.format}`;if(!this.module.FS)throw new H(`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 H(`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))try{e.options.set(n,r)}catch{}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:W[n]??`Unknown`,StatusCode:n,ObjectiveValue:e.getObjectiveValue(),Columns:a}})}}}));async function Ne(e={}){var t=e,n=!!globalThis.window,r=!!globalThis.WorkerGlobalScope,i=`./this.program`,a=(e,t)=>{throw t},o={}.url,s=``;function c(e){return t.locateFile?t.locateFile(e,s):s+e}var l,u;if(n||r){try{s=new URL(`.`,o).href}catch{}r&&(u=e=>{var t=new XMLHttpRequest;return t.open(`GET`,e,!1),t.responseType=`arraybuffer`,t.send(null),new Uint8Array(t.response)}),l=async e=>{if(m(e))return new Promise((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.status)},r.onerror=n,r.send(null)});var t=await fetch(e,{credentials:`same-origin`});if(t.ok)return t.arrayBuffer();throw Error(t.status+` : `+t.url)}}var d=console.log.bind(console),f=console.error.bind(console),p=!1,m=e=>e.startsWith(`file://`),h=!1;function g(){return lt.buffer}function _(){if(!A?.buffer?.resizable){var e=g();t.HEAP8=A=new Int8Array(e),W=new Int16Array(e),t.HEAPU8=Oe=new Uint8Array(e),t.HEAP32=j=new Int32Array(e),t.HEAPU32=V=new Uint32Array(e),Je=new Float32Array(e),t.HEAPF64=Ye=new Float64Array(e),H=new BigInt64Array(e)}}function v(){var e=t.preRun;e&&(typeof e==`function`&&(e=[e]),ne.push(...e)),ee(ne)}function y(){h=!0,!t.noFSInit&&!z.initialized&&z.init(),I.init(),ft.s(),z.ignorePermissions=!1}function b(){var e=t.postRun;e&&(typeof e==`function`&&(e=[e]),te.push(...e)),ee(te)}function x(e){throw t.onAbort?.(e),e=`Aborted(${e})`,f(e),p=!0,e+=`. Build with -sASSERTIONS for more info.`,h&&st(),new WebAssembly.RuntimeError(e)}var S;function C(){return t.locateFile?c(`highs.wasm`):new URL(`highs.wasm`,``+{}.url).href}function w(e){if(u)return u(e);throw`both async and sync fetching of the wasm failed`}async function T(e){try{var t=await l(e);return new Uint8Array(t)}catch{}return w(e)}async function E(e,t){try{var n=await T(e);return await WebAssembly.instantiate(n,t)}catch(e){f(`failed to asynchronously prepare wasm: ${e}`),x(e)}}async function D(e,t,n){if(!e&&!m(t))try{var r=fetch(t,{credentials:`same-origin`});return await WebAssembly.instantiateStreaming(r,n)}catch(e){f(`wasm streaming compile failed: ${e}`),f(`falling back to ArrayBuffer instantiation`)}return E(t,n)}function O(){return{a:dt}}class k{name=`ExitStatus`;constructor(e){this.message=`Program terminated with exit(${e})`,this.status=e}}var A,ee=e=>{for(;e.length>0;)e.shift()(t)},te=[],ne=[],re=!0,j,ie=()=>{var e=j[U.varargs>>2];return U.varargs+=4,e},M=ie,N={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=N.isAbs(e),n=e.slice(-1)===`/`;return e=N.normalizeArray(e.split(`/`).filter(e=>!!e),!t).join(`/`),!e&&!t&&(e=`.`),e&&n&&(e+=`/`),(t?`/`:``)+e},dirname:e=>{var t=N.splitPath(e),n=t[0],r=t[1];return!n&&!r?`.`:(r&&=r.slice(0,-1),n+r)},basename:e=>e&&e.match(/([^\/]+|\/)\/*$/)[1],join:(...e)=>N.normalize(e.join(`/`)),join2:(e,t)=>N.normalize(e+`/`+t)},ae=()=>e=>(crypto.getRandomValues(e),0),P=e=>(P=ae())(e),oe={resolve:(...e)=>{for(var t=``,n=!1,r=e.length-1;r>=-1&&!n;r--){var i=r>=0?e[r]:z.cwd();if(typeof i!=`string`)throw TypeError(`Arguments to path.resolve must be strings`);if(!i)return``;t=i+`/`+t,n=N.isAbs(i)}return t=N.normalizeArray(t.split(`/`).filter(e=>!!e),!n).join(`/`),(n?`/`:``)+t||`.`},relative:(e,t)=>{e=oe.resolve(e).slice(1),t=oe.resolve(t).slice(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}var c=[];for(s=o;s<r.length;s++)c.push(`..`);return c=c.concat(i.slice(o)),c.join(`/`)}},se=globalThis.TextDecoder&&new TextDecoder,ce=(e,t,n,r)=>{var i=t+n;if(r)return i;for(;e[t]&&!(t>=i);)++t;return t},F=(e,t=0,n,r)=>{var i=ce(e,t,n,r);if(i-t>16&&e.buffer&&se)return se.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},le=[],ue=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.codePointAt(o);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,o++}}return t[n]=0,n-i},fe=(e,t,n)=>{var r=n>0?n:ue(e)+1,i=Array(r),a=de(e,i,0,i.length);return t&&(i.length=a),i},pe=()=>{if(!le.length){var e=null;if(globalThis.window?.prompt&&(e=window.prompt(`Input: `),e!==null&&(e+=`
|
|
4
|
+
`)),!e)return null;le=fe(e,!0)}return le.shift()},I={ttys:[],init(){},shutdown(){},register(e,t){I.ttys[e]={input:[],output:[],ops:t},z.registerDevice(e,I.stream_ops)},stream_ops:{open(e){var t=I.ttys[e.node.rdev];if(!t)throw new z.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 z.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 z.ErrnoError(29)}if(s===void 0&&!a)throw new z.ErrnoError(6);if(s==null||(a++,t[n+o]=s,s===10))break}return a&&(e.node.atime=Date.now()),a},write(e,t,n,r,i){if(!e.tty||!e.tty.ops.put_char)throw new z.ErrnoError(60);try{for(var a=0;a<r;a++)e.tty.ops.put_char(e.tty,t[n+a])}catch{throw new z.ErrnoError(29)}return r&&(e.node.mtime=e.node.ctime=Date.now()),a}},default_tty_ops:{get_char(e){return pe()},put_char(e,t){t===null||t===10?(d(F(e.output)),e.output=[]):t!=0&&e.output.push(t)},fsync(e){e.output?.length>0&&(d(F(e.output)),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?(f(F(e.output)),e.output=[]):t!=0&&e.output.push(t)},fsync(e){e.output?.length>0&&(f(F(e.output)),e.output=[])}}},me=()=>{x()},L={ops_table:null,mount(e){return L.createNode(null,`/`,16895,0)},createNode(e,t,n,r){if(z.isBlkdev(n)||z.isFIFO(n))throw new z.ErrnoError(63);L.ops_table||={dir:{node:{getattr:L.node_ops.getattr,setattr:L.node_ops.setattr,lookup:L.node_ops.lookup,mknod:L.node_ops.mknod,rename:L.node_ops.rename,unlink:L.node_ops.unlink,rmdir:L.node_ops.rmdir,readdir:L.node_ops.readdir,symlink:L.node_ops.symlink},stream:{llseek:L.stream_ops.llseek}},file:{node:{getattr:L.node_ops.getattr,setattr:L.node_ops.setattr},stream:{llseek:L.stream_ops.llseek,read:L.stream_ops.read,write:L.stream_ops.write,mmap:L.stream_ops.mmap,msync:L.stream_ops.msync}},link:{node:{getattr:L.node_ops.getattr,setattr:L.node_ops.setattr,readlink:L.node_ops.readlink},stream:{}},chrdev:{node:{getattr:L.node_ops.getattr,setattr:L.node_ops.setattr},stream:z.chrdev_stream_ops}};var i=z.createNode(e,t,n,r);return z.isDir(i.mode)?(i.node_ops=L.ops_table.dir.node,i.stream_ops=L.ops_table.dir.stream,i.contents={}):z.isFile(i.mode)?(i.node_ops=L.ops_table.file.node,i.stream_ops=L.ops_table.file.stream,i.usedBytes=0,i.contents=L.emptyFileContents??=new Uint8Array):z.isLink(i.mode)?(i.node_ops=L.ops_table.link.node,i.stream_ops=L.ops_table.link.stream):z.isChrdev(i.mode)&&(i.node_ops=L.ops_table.chrdev.node,i.stream_ops=L.ops_table.chrdev.stream),i.atime=i.mtime=i.ctime=Date.now(),e&&(e.contents[t]=i,e.atime=e.mtime=e.ctime=i.atime),i},getFileDataAsTypedArray(e){return e.contents.subarray(0,e.usedBytes)},expandFileStorage(e,t){var n=e.contents.length;if(!(n>=t)){t=Math.max(t,n*(n<1048576?2:1.125)>>>0),n&&(t=Math.max(t,256));var r=L.getFileDataAsTypedArray(e);e.contents=new Uint8Array(t),e.contents.set(r)}},resizeFileStorage(e,t){if(e.usedBytes!=t){var n=e.contents;e.contents=new Uint8Array(t),e.contents.set(n.subarray(0,Math.min(t,e.usedBytes))),e.usedBytes=t}},node_ops:{getattr(e){var t={};return t.dev=z.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=z.isDir(e.mode)?4096:z.isFile(e.mode)?e.usedBytes:z.isLink(e.mode)?e.link.length:0,t.atime=new Date(e.atime),t.mtime=new Date(e.mtime),t.ctime=new Date(e.ctime),t.blksize=4096,t.blocks=Math.ceil(t.size/t.blksize),t},setattr(e,t){for(let n of[`mode`,`atime`,`mtime`,`ctime`])t[n]!=null&&(e[n]=t[n]);t.size!==void 0&&L.resizeFileStorage(e,t.size)},lookup(e,t){throw L.doesNotExistError||(L.doesNotExistError=new z.ErrnoError(44),L.doesNotExistError.stack=`<generic error, no stack>`),L.doesNotExistError},mknod(e,t,n,r){return L.createNode(e,t,n,r)},rename(e,t,n){var r;try{r=z.lookupNode(t,n)}catch{}if(r&&z.isDir(e.mode))for(var i in r.contents)throw new z.ErrnoError(55);delete e.parent.contents[e.name],t.contents[n]=e,e.name=n,t.ctime=t.mtime=e.parent.ctime=e.parent.mtime=Date.now()},unlink(e,t){delete e.contents[t],e.ctime=e.mtime=Date.now()},rmdir(e,t){for(var n in z.lookupNode(e,t).contents)throw new z.ErrnoError(55);delete e.contents[t],e.ctime=e.mtime=Date.now()},readdir(e){return[`.`,`..`,...Object.keys(e.contents)]},symlink(e,t,n){var r=L.createNode(e,t,41471,0);return r.link=n,r},readlink(e){if(!z.isLink(e.mode))throw new z.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);return t.set(a.subarray(i,i+o),n),o},write(e,t,n,r,i,a){if(t.buffer===A.buffer&&(a=!1),!r)return 0;var o=e.node;return o.mtime=o.ctime=Date.now(),a?(o.contents=t.subarray(n,n+r),o.usedBytes=r):!o.usedBytes&&!i?(o.contents=t.slice(n,n+r),o.usedBytes=r):(L.expandFileStorage(o,i+r),o.contents.set(t.subarray(n,n+r),i),o.usedBytes=Math.max(o.usedBytes,i+r)),r},llseek(e,t,n){var r=t;if(n===1?r+=e.position:n===2&&z.isFile(e.node.mode)&&(r+=e.node.usedBytes),r<0)throw new z.ErrnoError(28);return r},mmap(e,t,n,r,i){if(!z.isFile(e.node.mode))throw new z.ErrnoError(43);var a,o,s=e.node.contents;if(!(i&2)&&s.buffer===A.buffer)o=!1,a=s.byteOffset;else{if(o=!0,a=me(),!a)throw new z.ErrnoError(48);s&&((n>0||n+t<s.length)&&(s=s.subarray?s.subarray(n,n+t):Array.prototype.slice.call(s,n,n+t)),A.set(s,a))}return{ptr:a,allocated:o}},msync(e,t,n,r,i){return L.stream_ops.write(e,t,0,r,n,!1),0}}},he=e=>{if(typeof e!=`string`)return 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},ge=e=>(typeof e==`string`&&(e=fe(e,!0)),e.subarray||(e=new Uint8Array(e)),e),_e=(e,t)=>{var n=0;return e&&(n|=365),t&&(n|=146),n},ve=async e=>{var t=await l(e);return new Uint8Array(t)},ye=(...e)=>z.createDataFile(...e),be=null,xe=async()=>be,R=0,Se=null,Ce=()=>{R--,t.monitorRunDependencies?.(R),R||Se()},we=()=>{R||(be=new Promise(e=>Se=e)),R++,t.monitorRunDependencies?.(R)},Te=[],Ee=async(e,t)=>{typeof Browser<`u`&&Browser.init();for(var n of Te)if(n.canHandle(t))return n.handle(e,t);return e},De=async(e,t,n,r,i,a,o,s)=>{var c=t?oe.resolve(N.join2(e,t)):e;`${c}`,we();try{var l=n;typeof n==`string`&&(l=await ve(n)),l=await Ee(l,c),s?.(),a||ye(e,t,l,r,i,o)}finally{Ce()}},z={root:null,mounts:[],devices:{},streams:[],nextInode:1,nameTable:[],currentPath:`/`,initialized:!1,ignorePermissions:!0,syncFSRequests:0,ErrnoError:class{name=`ErrnoError`;constructor(e){this.errno=e}},FSStream:class{shared={};get object(){return this.node}set object(e){this.node=e}get isRead(){return(this.flags&2097155)!=1}get isWrite(){return!!(this.flags&2097155)}get isAppend(){return this.flags&1024}get flags(){return this.shared.flags}set flags(e){this.shared.flags=e}get position(){return this.shared.position}set position(e){this.shared.position=e}},FSNode:class{node_ops={};stream_ops={};readMode=365;writeMode=146;mounted=null;constructor(e,t,n,r){e||=this,this.parent=e,this.mount=e.mount,this.id=z.nextInode++,this.name=t,this.mode=n,this.rdev=r,this.atime=this.mtime=this.ctime=Date.now()}get read(){return(this.mode&this.readMode)===this.readMode}set read(e){e?this.mode|=this.readMode:this.mode&=~this.readMode}get write(){return(this.mode&this.writeMode)===this.writeMode}set write(e){e?this.mode|=this.writeMode:this.mode&=~this.writeMode}get isFolder(){return z.isDir(this.mode)}get isDevice(){return z.isChrdev(this.mode)}addListener(e,t=!1){var n={cb:e,exclusive:t},r=this.listeners??=new Set;return r.add(n),{listeners:r,entry:n}}notifyListeners(e){if(this.listeners){var t;for(var n of this.listeners)n.exclusive?(t||=[]).push(n):n.cb(e);if(t){var r=(this.exclTurn||0)%t.length;this.exclTurn=r+1,t[r].cb(e)}}}},lookupPath(e,t={}){if(!e)throw new z.ErrnoError(44);t.follow_mount??=!0,N.isAbs(e)||(e=z.cwd()+`/`+e);linkloop:for(var n=0;n<40;n++){for(var r=e.split(`/`).filter(e=>!!e),i=z.root,a=`/`,o=0;o<r.length;o++){var s=o===r.length-1;if(s&&t.parent)break;if(r[o]!==`.`){if(r[o]===`..`){if(a=N.dirname(a),z.isRoot(i)){e=a+`/`+r.slice(o+1).join(`/`),n--;continue linkloop}i=i.parent;continue}a=N.join2(a,r[o]);try{i=z.lookupNode(i,r[o])}catch(e){if(e?.errno===44&&s&&t.noent_okay)return{path:a};throw e}if(z.isMountpoint(i)&&(!s||t.follow_mount)&&(i=i.mounted.root),z.isLink(i.mode)&&(!s||t.follow)){if(!i.node_ops.readlink)throw new z.ErrnoError(52);var c=i.node_ops.readlink(i);N.isAbs(c)||(c=N.dirname(a)+`/`+c),e=c+`/`+r.slice(o+1).join(`/`);continue linkloop}}}return{path:a,node:i}}throw new z.ErrnoError(32)},getPath(e){for(var t;;){if(z.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)%z.nameTable.length},hashAddNode(e){var t=z.hashName(e.parent.id,e.name);e.name_next=z.nameTable[t],z.nameTable[t]=e},hashRemoveNode(e){var t=z.hashName(e.parent.id,e.name);if(z.nameTable[t]===e)z.nameTable[t]=e.name_next;else for(var n=z.nameTable[t];n;){if(n.name_next===e){n.name_next=e.name_next;break}n=n.name_next}},lookupNode(e,t){var n=z.mayLookup(e);if(n)throw new z.ErrnoError(n);for(var r=z.hashName(e.id,t),i=z.nameTable[r];i;i=i.name_next){var a=i.name;if(i.parent.id===e.id&&a===t)return i}return z.lookup(e,t)},createNode(e,t,n,r){var i=new z.FSNode(e,t,n,r);return z.hashAddNode(i),i},destroyNode(e){z.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 z.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 z.isDir(e.mode)?z.nodePermissions(e,`x`)||(e.node_ops.lookup?0:2):54},mayCreate(e,t){if(!z.isDir(e.mode))return 54;try{return z.lookupNode(e,t),20}catch{}return z.nodePermissions(e,`wx`)},mayDelete(e,t,n){var r;try{r=z.lookupNode(e,t)}catch(e){return e.errno}var i=z.nodePermissions(e,`wx`);if(i)return i;if(n){if(!z.isDir(r.mode))return 54;if(z.isRoot(r)||z.getPath(r)===z.cwd())return 10}else if(z.isDir(r.mode))return 31;return 0},mayOpen(e,t){if(!e)return 44;if(z.isLink(e.mode))return 32;var n=z.flagsToPermissionString(t);return z.isDir(e.mode)&&(n!==`r`||t&576)?31:z.nodePermissions(e,n)},checkOpExists(e,t){if(!e)throw new z.ErrnoError(t);return e},MAX_OPEN_FDS:4096,nextfd(){for(var e=0;e<=z.MAX_OPEN_FDS;e++)if(!z.streams[e])return e;throw new z.ErrnoError(33)},getStreamChecked(e){var t=z.getStream(e);if(!t)throw new z.ErrnoError(8);return t},getStream:e=>z.streams[e],createStream(e,t=-1){return e=Object.assign(new z.FSStream,e),t==-1&&(t=z.nextfd()),e.fd=t,z.streams[t]=e,e},closeStream(e){z.streams[e]=null},dupStream(e,t=-1){var n=z.createStream(e,t);return n.stream_ops?.dup?.(n),n},doSetAttr(e,t,n){var r=e?.stream_ops.setattr,i=r?e:t;r??=t.node_ops.setattr,z.checkOpExists(r,63);try{r(i,n)}catch(e){throw e instanceof RangeError?new z.ErrnoError(22):e}},chrdev_stream_ops:{open(e){e.stream_ops=z.getDevice(e.node.rdev).stream_ops,e.stream_ops.open?.(e)},llseek(){throw new z.ErrnoError(70)}},major:e=>e>>8,minor:e=>e&255,makedev:(e,t)=>e<<8|t,registerDevice(e,t){z.devices[e]={stream_ops:t}},getDevice:e=>z.devices[e],getMounts(e){for(var t=[],n=[e];n.length;){var r=n.pop();t.push(r),n.push(...r.mounts)}return t},syncfs(e,t){typeof e==`function`&&(t=e,e=!1),z.syncFSRequests++,z.syncFSRequests>1&&f(`warning: ${z.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`);var n=z.getMounts(z.root.mount),r=0;function i(e){return z.syncFSRequests--,t(e)}function a(e){if(e)return a.errored?void 0:(a.errored=!0,i(e));++r>=n.length&&i(null)}for(var o of n)o.type.syncfs?o.type.syncfs(o,e,a):a(null)},mount(e,t,n){var r=n===`/`,i=!n,a;if(r&&z.root)throw new z.ErrnoError(10);if(!r&&!i){var o=z.lookupPath(n,{follow_mount:!1});if(n=o.path,a=o.node,z.isMountpoint(a))throw new z.ErrnoError(10);if(!z.isDir(a.mode))throw new z.ErrnoError(54)}var s={type:e,opts:t,mountpoint:n,mounts:[]},c=e.mount(s);return c.mount=s,s.root=c,r?z.root=c:a&&(a.mounted=s,a.mount&&a.mount.mounts.push(s)),c},unmount(e){var t=z.lookupPath(e,{follow_mount:!1});if(!z.isMountpoint(t.node))throw new z.ErrnoError(28);var n=t.node,r=n.mounted,i=z.getMounts(r);for(var[a,o]of Object.entries(z.nameTable))for(;o;){var s=o.name_next;i.includes(o.mount)&&z.destroyNode(o),o=s}n.mounted=null;var c=n.mount.mounts.indexOf(r);n.mount.mounts.splice(c,1)},lookup(e,t){return e.node_ops.lookup(e,t)},mknod(e,t,n){var r=z.lookupPath(e,{parent:!0}).node,i=N.basename(e);if(!i)throw new z.ErrnoError(28);if(i===`.`||i===`..`)throw new z.ErrnoError(20);var a=z.mayCreate(r,i);if(a)throw new z.ErrnoError(a);if(!r.node_ops.mknod)throw new z.ErrnoError(63);return r.node_ops.mknod(r,i,t,n)},statfs(e){return z.statfsNode(z.lookupPath(e,{follow:!0}).node)},statfsStream(e){return z.statfsNode(e.node)},statfsNode(e){var t={bsize:4096,frsize:4096,blocks:1e6,bfree:5e5,bavail:5e5,files:z.nextInode,ffree:z.nextInode-1,fsid:42,flags:2,namelen:255};return e.node_ops.statfs&&Object.assign(t,e.node_ops.statfs(e.mount.opts.root)),t},create(e,t=438){return t&=4095,t|=32768,z.mknod(e,t,0)},mkdir(e,t=511){return t&=1023,t|=16384,z.mknod(e,t,0)},mkdirTree(e,t=511){var n=e.split(`/`),r=``;for(var i of n)if(i){(r||N.isAbs(e))&&(r+=`/`),r+=i;try{z.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,z.mknod(e,t,n)},symlink(e,t){if(!oe.resolve(e))throw new z.ErrnoError(44);var n=z.lookupPath(t,{parent:!0}).node;if(!n)throw new z.ErrnoError(44);var r=N.basename(t),i=z.mayCreate(n,r);if(i)throw new z.ErrnoError(i);if(!n.node_ops.symlink)throw new z.ErrnoError(63);return n.node_ops.symlink(n,r,e)},link(e,t,n){var r=z.lookupPath(t,{parent:!0}).node;if(!r)throw new z.ErrnoError(44);var i=N.basename(t),a=z.mayCreate(r,i);if(a)throw new z.ErrnoError(a);if(!r.node_ops.link)throw new z.ErrnoError(34);return r.node_ops.link(r,i,e,n)},rename(e,t){var n=N.dirname(e),r=N.dirname(t),i=N.basename(e),a=N.basename(t),o=z.lookupPath(e,{parent:!0}),s=o.node,c;if(o=z.lookupPath(t,{parent:!0}),c=o.node,!s||!c)throw new z.ErrnoError(44);if(s.mount!==c.mount)throw new z.ErrnoError(75);var l=z.lookupNode(s,i),u=oe.relative(e,r);if(u.charAt(0)!==`.`)throw new z.ErrnoError(28);if(u=oe.relative(t,n),u.charAt(0)!==`.`)throw new z.ErrnoError(55);var d;try{d=z.lookupNode(c,a)}catch{}if(l!==d){var f=z.isDir(l.mode),p=z.mayDelete(s,i,f);if(p||(p=d?z.mayDelete(c,a,f):z.mayCreate(c,a),p))throw new z.ErrnoError(p);if(!s.node_ops.rename)throw new z.ErrnoError(63);if(z.isMountpoint(l)||d&&z.isMountpoint(d))throw new z.ErrnoError(10);if(c!==s&&(p=z.nodePermissions(s,`w`),p))throw new z.ErrnoError(p);z.hashRemoveNode(l);try{s.node_ops.rename(l,c,a),d&&z.hashRemoveNode(d),l.parent=c}catch(e){throw e}finally{z.hashAddNode(l)}}},rmdir(e){var t=z.lookupPath(e,{parent:!0}).node,n=N.basename(e),r=z.lookupNode(t,n),i=z.mayDelete(t,n,!0);if(i)throw new z.ErrnoError(i);if(!t.node_ops.rmdir)throw new z.ErrnoError(63);if(z.isMountpoint(r))throw new z.ErrnoError(10);t.node_ops.rmdir(t,n),z.destroyNode(r)},readdir(e){var t=z.lookupPath(e,{follow:!0}).node;return z.checkOpExists(t.node_ops.readdir,54)(t)},unlink(e){var t=z.lookupPath(e,{parent:!0}).node;if(!t)throw new z.ErrnoError(44);var n=N.basename(e),r=z.lookupNode(t,n),i=z.mayDelete(t,n,!1);if(i)throw new z.ErrnoError(i);if(!t.node_ops.unlink)throw new z.ErrnoError(63);if(z.isMountpoint(r))throw new z.ErrnoError(10);t.node_ops.unlink(t,n),z.destroyNode(r)},readlink(e){var t=z.lookupPath(e).node;if(!t)throw new z.ErrnoError(44);if(!t.node_ops.readlink)throw new z.ErrnoError(28);return t.node_ops.readlink(t)},stat(e,t=!1){var n=z.lookupPath(e,{follow:!t}).node;return z.checkOpExists(n.node_ops.getattr,63)(n)},fstat(e){var t=z.getStreamChecked(e),n=t.node,r=t.stream_ops.getattr,i=r?t:n;return r??=n.node_ops.getattr,z.checkOpExists(r,63),r(i)},lstat(e){return z.stat(e,!0)},doChmod(e,t,n,r=!1){z.doSetAttr(e,t,{mode:n&4095|t.mode&-4096,ctime:Date.now(),dontFollow:r})},chmod(e,t,n=!1){var r=typeof e==`string`?z.lookupPath(e,{follow:!n}).node:e;z.doChmod(null,r,t,n)},lchmod(e,t){z.chmod(e,t,!0)},fchmod(e,t){var n=z.getStreamChecked(e);z.doChmod(n,n.node,t,!1)},doChown(e,t,n=!1){z.doSetAttr(e,t,{timestamp:Date.now(),dontFollow:n})},chown(e,t,n,r=!1){var i=typeof e==`string`?z.lookupPath(e,{follow:!r}).node:e;z.doChown(null,i,r)},lchown(e,t,n){z.chown(e,t,n,!0)},fchown(e,t,n){var r=z.getStreamChecked(e);z.doChown(r,r.node,!1)},doTruncate(e,t,n){if(z.isDir(t.mode))throw new z.ErrnoError(31);if(!z.isFile(t.mode))throw new z.ErrnoError(28);var r=z.nodePermissions(t,`w`);if(r)throw new z.ErrnoError(r);z.doSetAttr(e,t,{size:n,timestamp:Date.now()})},truncate(e,t){if(t<0)throw new z.ErrnoError(28);var n=typeof e==`string`?z.lookupPath(e,{follow:!0}).node:e;z.doTruncate(null,n,t)},ftruncate(e,t){var n=z.getStreamChecked(e);if(t<0||!(n.flags&2097155))throw new z.ErrnoError(28);z.doTruncate(n,n.node,t)},utime(e,t,n,r=!1){var i=z.lookupPath(e,{follow:!r});z.doSetAttr(null,i.node,{atime:t,mtime:n,dontFollow:r})},open(e,t,n=438){if(e===``)throw new z.ErrnoError(44);t=he(t),n=t&64?n&4095|32768:0;var r,i;if(typeof e==`object`)r=e;else{i=e.endsWith(`/`);var a=z.lookupPath(e,{follow:!(t&131072),noent_okay:!0});r=a.node,e=a.path}var o=!1;if(t&64){if(r){if(t&128)throw new z.ErrnoError(20)}else if(i)throw new z.ErrnoError(31);else r=z.mknod(e,n|511,0),o=!0}if(!r)throw new z.ErrnoError(44);if(z.isChrdev(r.mode)&&(t&=-513),t&65536&&!z.isDir(r.mode))throw new z.ErrnoError(54);if(!o){var s=z.mayOpen(r,t);if(s)throw new z.ErrnoError(s)}t&512&&!o&&z.truncate(r,0),t&=-131713;var c=z.createStream({node:r,path:z.getPath(r),flags:t,seekable:!0,position:0,stream_ops:r.stream_ops,ungotten:[],error:!1});return c.stream_ops.open&&c.stream_ops.open(c),o&&z.chmod(r,n&511),c},close(e){if(z.isClosed(e))throw new z.ErrnoError(8);e.getdents&&=null,e.node?.notifyListeners(32);try{e.stream_ops.close&&e.stream_ops.close(e)}catch(e){throw e}finally{z.closeStream(e.fd)}e.fd=null},isClosed(e){return e.fd===null},llseek(e,t,n){if(z.isClosed(e))throw new z.ErrnoError(8);if(!e.seekable||!e.stream_ops.llseek)throw new z.ErrnoError(70);if(n!=0&&n!=1&&n!=2)throw new z.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 z.ErrnoError(28);if(z.isClosed(e)||(e.flags&2097155)==1)throw new z.ErrnoError(8);if(z.isDir(e.node.mode))throw new z.ErrnoError(31);if(!e.stream_ops.read)throw new z.ErrnoError(28);var a=i!==void 0;if(!a)i=e.position;else if(!e.seekable)throw new z.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 z.ErrnoError(28);if(z.isClosed(e)||!(e.flags&2097155))throw new z.ErrnoError(8);if(z.isDir(e.node.mode))throw new z.ErrnoError(31);if(!e.stream_ops.write)throw new z.ErrnoError(28);e.seekable&&e.flags&1024&&z.llseek(e,0,2);var o=i!==void 0;if(!o)i=e.position;else if(!e.seekable)throw new z.ErrnoError(70);var s=e.stream_ops.write(e,t,n,r,i,a);return o||(e.position+=s),s},mmap(e,t,n,r,i){if(r&2&&!(i&2)&&(e.flags&2097155)!=2||(e.flags&2097155)==1)throw new z.ErrnoError(2);if(!e.stream_ops.mmap)throw new z.ErrnoError(43);if(!t)throw new z.ErrnoError(28);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},ioctl(e,t,n){if(!e.stream_ops.ioctl)throw new z.ErrnoError(59);return e.stream_ops.ioctl(e,t,n)},readFile(e,t={}){t.flags??=0,t.encoding??=`binary`,t.encoding!==`utf8`&&t.encoding!==`binary`&&x(`Invalid encoding type "${t.encoding}"`);var n=z.open(e,t.flags),r=z.stat(e).size,i=new Uint8Array(r);return z.read(n,i,0,r,0),t.encoding===`utf8`&&(i=F(i)),z.close(n),i},writeFile(e,t,n={}){n.flags??=577;var r=z.open(e,n.flags,n.mode);t=ge(t),z.write(r,t,0,t.byteLength,void 0,n.canOwn),z.close(r)},cwd:()=>z.currentPath,chdir(e){var t=z.lookupPath(e,{follow:!0});if(t.node===null)throw new z.ErrnoError(44);if(!z.isDir(t.node.mode))throw new z.ErrnoError(54);var n=z.nodePermissions(t.node,`x`);if(n)throw new z.ErrnoError(n);z.currentPath=t.path},createDefaultDirectories(){z.mkdir(`/tmp`),z.mkdir(`/home`),z.mkdir(`/home/web_user`)},createDefaultDevices(){z.mkdir(`/dev`),z.registerDevice(z.makedev(1,3),{read:()=>0,write:(e,t,n,r)=>r,llseek:()=>0}),z.mkdev(`/dev/null`,z.makedev(1,3)),I.register(z.makedev(5,0),I.default_tty_ops),I.register(z.makedev(6,0),I.default_tty1_ops),z.mkdev(`/dev/tty`,z.makedev(5,0)),z.mkdev(`/dev/tty1`,z.makedev(6,0));var e=new Uint8Array(1024),t=0,n=()=>(t||=(P(e),e.byteLength),e[--t]);z.createDevice(`/dev`,`random`,n),z.createDevice(`/dev`,`urandom`,n),z.mkdir(`/dev/shm`),z.mkdir(`/dev/shm/tmp`)},createSpecialDirectories(){z.mkdir(`/proc`);var e=z.mkdir(`/proc/self`);z.mkdir(`/proc/self/fd`),z.mount({mount(){var t=z.createNode(e,`fd`,16895,73);return t.stream_ops={llseek:L.stream_ops.llseek},t.node_ops={lookup(e,t){var n=+t,r=z.getStreamChecked(n),i={parent:null,mount:{mountpoint:`fake`},node_ops:{readlink:()=>r.path},id:n+1};return i.parent=i,i},readdir(){return Array.from(z.streams.entries()).filter(([e,t])=>t).map(([e,t])=>e.toString())}},t}},{},`/proc/self/fd`)},createStandardStreams(e,t,n){e?z.createDevice(`/dev`,`stdin`,e):z.symlink(`/dev/tty`,`/dev/stdin`),t?z.createDevice(`/dev`,`stdout`,null,t):z.symlink(`/dev/tty`,`/dev/stdout`),n?z.createDevice(`/dev`,`stderr`,null,n):z.symlink(`/dev/tty1`,`/dev/stderr`),z.open(`/dev/stdin`,0),z.open(`/dev/stdout`,1),z.open(`/dev/stderr`,1)},staticInit(){z.nameTable.length=4096,z.mount(L,{},`/`),z.createDefaultDirectories(),z.createDefaultDevices(),z.createSpecialDirectories()},init(e,n,r){z.initialized=!0,e??=t.stdin,n??=t.stdout,r??=t.stderr,z.createStandardStreams(e,n,r)},quit(){z.initialized=!1;for(var e of z.streams)e&&z.close(e)},analyzePath(e,t=!1){try{var n=z.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{n=z.lookupPath(e,{parent:!0}),r.parentExists=!0,r.parentPath=n.path,r.parentObject=n.node,r.name=N.basename(e),n=z.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:z.getPath(e);for(var i=t.split(`/`).reverse();i.length;){var a=i.pop();if(a){var o=N.join2(e,a);try{z.mkdir(o)}catch(e){if(e.errno!=20)throw e}e=o}}return o},createFile(e,t,n,r,i){var a=N.join2(typeof e==`string`?e:z.getPath(e),t),o=_e(r,i);return z.create(a,o)},createDataFile(e,t,n,r,i,a){var o=t;e&&(e=typeof e==`string`?e:z.getPath(e),o=t?N.join2(e,t):e);var s=_e(r,i),c=z.create(o,s);if(n){n=ge(n),z.chmod(c,s|146);var l=z.open(c,577);z.write(l,n,0,n.length,0,a),z.close(l),z.chmod(c,s)}},createDevice(e,t,n,r){var i=N.join2(typeof e==`string`?e:z.getPath(e),t),a=_e(!!n,!!r);z.createDevice.major??=64;var o=z.makedev(z.createDevice.major++,0);return z.registerDevice(o,{open(e){e.seekable=!1},close(e){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 z.ErrnoError(29)}if(c===void 0&&!o)throw new z.ErrnoError(6);if(c==null)break;o++,t[r+s]=c}return o&&(e.node.atime=Date.now()),o},write(e,t,n,i,a){for(var o=0;o<i;o++)try{r(t[n+o])}catch{throw new z.ErrnoError(29)}return i&&(e.node.mtime=e.node.ctime=Date.now()),o}}),z.mkdev(i,a,o)},forceLoadFile(e){if(e.isDevice||e.isFolder||e.link||e.contents)return!0;if(globalThis.XMLHttpRequest)x(`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.`);else try{e.contents=u(e.url)}catch{throw new z.ErrnoError(29)}},createLazyFile(e,t,n,i,a){class o{lengthKnown=!1;chunks=[];get(e){if(!(e>this.length-1||e<0)){var t=e%this.chunkSize,n=e/this.chunkSize|0;return this.getter(n)[t]}}setDataGetter(e){this.getter=e}cacheLength(){var e=new XMLHttpRequest;e.open(`HEAD`,n,!1),e.send(null),e.status>=200&&e.status<300||e.status===304||x(`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)=>{e>r&&x(`invalid range (${e}, ${r}) or no bytes requested!`),r>t-1&&x(`only ${t} bytes available! programmer error!`);var i=new XMLHttpRequest;return 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||x(`Couldn't load ${n}. Status: ${i.status}`),i.response===void 0?fe(i.responseText??``,!0):new Uint8Array(i.response||[])},c=this;c.setDataGetter(e=>{var n=e*o,r=(e+1)*o-1;return r=Math.min(r,t-1),c.chunks[e]===void 0&&(c.chunks[e]=s(n,r)),c.chunks[e]===void 0&&x(`doXHR failed!`),c.chunks[e]}),(a||!t)&&(o=t=1,t=this.getter(0).length,o=t,d(`LazyFiles on gzip forces download of the whole file when length is accessed`)),this._length=t,this._chunkSize=o,this.lengthKnown=!0}get length(){return this.lengthKnown||this.cacheLength(),this._length}get chunkSize(){return this.lengthKnown||this.cacheLength(),this._chunkSize}}if(globalThis.XMLHttpRequest){r||x(`Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc`);var s={isDevice:!1,contents:new o}}else s={isDevice:!1,url:n};var c=z.createFile(e,t,s,i,a);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 l={};for(let[e,t]of Object.entries(c.stream_ops))l[e]=(...e)=>(z.forceLoadFile(c),t(...e));function u(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(s=0;s<o;s++)t[n+s]=a.get(i+s);return o}return l.read=(e,t,n,r,i)=>(z.forceLoadFile(c),u(e,t,n,r,i)),l.mmap=(e,t,n)=>{z.forceLoadFile(c);var r=me();if(!r)throw new z.ErrnoError(48);return u(e,A,r,t,n),{ptr:r,allocated:!0}},c.stream_ops=l,c}},Oe,B=(e,t,n)=>e?F(Oe,e,t,n):``,V,H,U={currentUmask:18,calculateAt(e,t,n=!1){if(N.isAbs(t))return t;var r=e===-100?z.cwd():U.getStreamFromFD(e).path;if(t.length==0){if(!n)throw new z.ErrnoError(44);return r}return r+`/`+t},writeStat(e,t){V[e>>2]=t.dev,V[e+4>>2]=t.mode,V[e+8>>2]=t.nlink,V[e+12>>2]=t.uid,V[e+16>>2]=t.gid,V[e+20>>2]=t.rdev,H[e+24>>3]=BigInt(t.size),j[e+32>>2]=4096,j[e+36>>2]=t.blocks;var n=t.atime.getTime(),r=t.mtime.getTime(),i=t.ctime.getTime();return H[e+40>>3]=BigInt(Math.floor(n/1e3)),V[e+48>>2]=n%1e3*1e3*1e3,H[e+56>>3]=BigInt(Math.floor(r/1e3)),V[e+64>>2]=r%1e3*1e3*1e3,H[e+72>>3]=BigInt(Math.floor(i/1e3)),V[e+80>>2]=i%1e3*1e3*1e3,H[e+88>>3]=BigInt(t.ino),0},writeStatFs(e,t){V[e+4>>2]=t.bsize,V[e+60>>2]=t.bsize,H[e+8>>3]=BigInt(t.blocks),H[e+16>>3]=BigInt(t.bfree),H[e+24>>3]=BigInt(t.bavail),H[e+32>>3]=BigInt(t.files),H[e+40>>3]=BigInt(t.ffree),V[e+48>>2]=t.fsid,V[e+64>>2]=t.flags,V[e+56>>2]=t.namelen},doMsync(e,t,n,r,i){if(!z.isFile(t.node.mode))throw new z.ErrnoError(43);if(r&2)return 0;var a=Oe.subarray(e,e+n);z.msync(t,a,i,n,r)},getStreamFromFD(e){return z.getStreamChecked(e)},varargs:void 0,getStr(e){return B(e)}},W,G=(e,t,n)=>de(e,Oe,t,n),ke=()=>performance.now(),Ae=()=>Date.now(),je=e=>e>=0&&e<=3,Me=e=>e<-9007199254740992||e>9007199254740992?NaN:Number(e),Ne=()=>2147483648,Pe=(e,t)=>Math.ceil(e/t)*t,Fe=e=>{var t=(e-lt.buffer.byteLength+65535)/65536|0;try{return lt.grow(t),_(),1}catch{}},Ie={},Le=()=>i,K=()=>{if(!K.strings){var e={USER:`web_user`,LOGNAME:`web_user`,PATH:`/`,PWD:`/`,HOME:`/home/web_user`,LANG:(globalThis.navigator?.language??`C`).replace(`-`,`_`)+`.UTF-8`,_:Le()};for(var t in Ie)Ie[t]===void 0?delete e[t]:e[t]=Ie[t];var n=[];for(var t in e)n.push(`${t}=${e[t]}`);K.strings=n}return K.strings},Re=()=>re||!1,ze=e=>{Re()||(t.onExit?.(e),p=!0),a(e,new k(e))},Be=e=>{ze(e)},Ve=(e,t,n,r)=>{for(var i=0,a=0;a<n;a++){var o=V[t>>2],s=V[t+4>>2];t+=8;try{var c=z.read(e,A,o,s,r)}catch(e){if(i>0&&e instanceof z.ErrnoError&&(e.errno==6||e.errno==6))break;throw e}if(c<0)return-1;if(i+=c,c<s)break;r!==void 0&&(r+=c)}return i},He=(e,t,n,r)=>{if(n==1)return z.write(e,A,V[t>>2],V[t+4>>2],r);for(var i=0,a=0,o=t;a<n;a++,o+=8)i+=V[o+4>>2];var s=new Uint8Array(i),c=0;for(a=0;a<n;a++,t+=8){var l=V[t>>2],u=V[t+4>>2];s.set(Oe.subarray(l,l+u),c),c+=u}return z.write(e,s,0,i,r)},Ue=e=>t[`_`+e],We=(e,t)=>{A.set(e,t)},Ge=e=>Z(e),q=e=>{var t=ue(e)+1,n=Ge(t);return G(e,n,t),n},Ke=()=>Q(),J=e=>ct(e),qe=(e,t,n,r)=>{var i={string:e=>{var t=0;return e!=null&&e!==0&&(t=q(e)),t},array:e=>{var t=Ge(e.length);return We(e,t),t}};function a(e){return t===`string`?B(e):t===`boolean`?!!e:e}var o=Ue(e),s=[],c=0;if(r)for(var l=0;l<r.length;l++){var u=i[n[l]];u?(c||=Ke(),s[l]=u(r[l])):s[l]=r[l]}var d=o(...s);return d=function(e){return c&&J(c),a(e)}(d),d},Je,Ye,Xe=[],Ze=e=>{var t=Xe[e];return t||(Xe[e]=t=$.get(e)),t},Qe=(e,t)=>{if(Y)for(var n=e;n<e+t;n++){var r=Ze(n);r&&Y.set(r,n)}},Y,$e=e=>(Y||(Y=new WeakMap,Qe(0,$.length)),Y.get(e)||0),et=[],tt=()=>et.length?et.pop():$.grow(1),nt=(e,t)=>{$.set(e,t),Xe[e]=$.get(e)},rt=e=>{let t=e.length;return[t%128|128,t>>7,...e]},it={i:127,p:127,j:126,f:125,d:124,e:111},at=e=>rt(Array.from(e,e=>it[e])),ot=(e,t)=>{var n=Uint8Array.of(0,97,115,109,1,0,0,0,1,...rt([1,96,...at(t.slice(1)),...at(t[0]===`v`?``:t[0])]),2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0),r=new WebAssembly.Module(n);return new WebAssembly.Instance(r,{e:{f:e}}).exports.f};z.createPreloadedFile=(e,t,n,r,i,a,o,s,c,l)=>{De(e,t,n,r,i,s,c,l).then(a).catch(o)},z.preloadFile=De,z.staticInit(),t.noExitRuntime&&(re=t.noExitRuntime),t.print&&(d=t.print),t.printErr&&(f=t.printErr),t.arguments&&t.arguments,t.thisProgram&&(i=t.thisProgram);var X=t.preInit;if(X)for(typeof X==`function`&&(t.preInit=X=[X]);X.length>0;)X.shift()();t.ccall=qe,t.cwrap=(e,t,n,r)=>{var i=!n||n.every(e=>e===`number`||e===`boolean`);return t!==`string`&&i&&!r?Ue(e):(...r)=>qe(e,t,n,r)},t.addFunction=(e,t)=>{var n=$e(e);if(n)return n;var r=tt();try{nt(r,e)}catch(n){if(!(n instanceof TypeError))throw n;nt(r,ot(e,t))}return Y.set(e,r),r},t.removeFunction=e=>{Y.delete(Ze(e)),nt(e,null),et.push(e)},t.setValue=function(e,t,n=`i8`){switch(n.endsWith(`*`)&&(n=`*`),n){case`i1`:A[e]=t;break;case`i8`:A[e]=t;break;case`i16`:W[e>>1]=t;break;case`i32`:j[e>>2]=t;break;case`i64`:H[e>>3]=BigInt(t);break;case`float`:Je[e>>2]=t;break;case`double`:Ye[e>>3]=t;break;case`*`:V[e>>2]=t;break;default:x(`invalid type for setValue: ${n}`)}},t.getValue=function(e,t=`i8`){switch(t.endsWith(`*`)&&(t=`*`),t){case`i1`:return A[e];case`i8`:return A[e];case`i16`:return W[e>>1];case`i32`:return j[e>>2];case`i64`:return H[e>>3];case`float`:return Je[e>>2];case`double`:return Ye[e>>3];case`*`:return V[e>>2];default:x(`invalid type for getValue: ${t}`)}},t.UTF8ToString=B,t.stringToUTF8=G,t.FS=z;var st,ct,Z,Q,lt,$;function ut(e){t._Highs_create=e.t,t._Highs_destroy=e.u,t._Highs_version=e.v,t._Highs_run=e.w,t._Highs_readModel=e.x,t._Highs_getNumCol=e.y,t._Highs_clearModel=e.z,t._Highs_setBoolOptionValue=e.A,t._Highs_setIntOptionValue=e.B,t._Highs_setDoubleOptionValue=e.C,t._Highs_setStringOptionValue=e.D,t._Highs_getIntInfoValue=e.E,t._Highs_getDoubleInfoValue=e.F,t._Highs_getInt64InfoValue=e.G,t._Highs_getSolution=e.H,t._Highs_getModelStatus=e.I,t._Highs_getObjectiveValue=e.J,t._Highs_getNumRow=e.K,t._Highs_setSolution=e.L,t._Highs_setSparseSolution=e.M,t._Highs_setCallback=e.N,t._Highs_startCallback=e.O,t._Highs_stopCallback=e.P,t._Highs_changeObjectiveOffset=e.Q,t._Highs_getObjectiveOffset=e.R,t._Highs_getRowName=e.S,t._Highs_getColName=e.T,t._Highs_getColIntegrality=e.U,t._Highs_getNumNz=e.V,t._malloc=e.W,t._free=e.X,st=e.Y,ct=e.Z,Z=e._,Q=e.$,lt=t.wasmMemory=e.r,$=e.aa}var dt={c:function(e,t,n){U.varargs=n;try{var r=U.getStreamFromFD(e);switch(t){case 0:var i=ie();if(i<0)return-28;for(;z.streams[i];)i++;return z.dupStream(r,i).fd;case 1:case 2:return 0;case 3:return r.flags;case 4:return i=ie(),r.flags=r.flags&-289793|i&289792,0;case 12:return i=M(),W[i+0>>1]=2,0;case 13:case 14:return 0}return-28}catch(e){if(z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}},g:function(e,t,n){U.varargs=n;try{var r=U.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=M();j[a>>2]=i.c_iflag||0,j[a+4>>2]=i.c_oflag||0,j[a+8>>2]=i.c_cflag||0,j[a+12>>2]=i.c_lflag||0;for(var o=0;o<32;o++)A[a+o+17]=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){a=M();var s=j[a>>2],c=j[a+4>>2],l=j[a+8>>2],u=j[a+12>>2],d=[];for(o=0;o<32;o++)d.push(A[a+o+17]);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:return r.tty?(a=M(),j[a>>2]=0,0):-59;case 21520:return r.tty?-28:-59;case 21537:case 21531:return a=M(),z.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=M(),W[a>>1]=f[0],W[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(z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}},h:function(e,t,n,r){U.varargs=r;try{t=U.getStr(t),t=U.calculateAt(e,t);var i=r?ie():0;return n&64&&(i&=~U.currentUmask),z.open(t,n,i).fd}catch(e){if(z===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}},p:()=>x(``),m:(e,t,n,r)=>{var i=new Date().getFullYear(),a=new Date(i,0,1),o=new Date(i,6,1),s=a.getTimezoneOffset(),c=o.getTimezoneOffset(),l=Math.max(s,c);V[e>>2]=l*60,j[t>>2]=Number(s!=c);var u=e=>{var t=e>=0?`-`:`+`,n=Math.abs(e);return`UTC${t}${String(Math.floor(n/60)).padStart(2,`0`)}${String(n%60).padStart(2,`0`)}`},d=u(s),f=u(c);c<s?(G(d,n,17),G(f,r,17)):(G(d,r,17),G(f,n,17))},n:function(e,t,n){if(t=Me(t),!je(e))return 28;var r=e===0?Ae():ke(),i=Math.round(r*1e6);return H[n>>3]=BigInt(i),0},j:Ae,i:()=>Ne(),b:ke,q:e=>{var t=Oe.length;e>>>=0;var n=Ne();if(e>n)return!1;for(var r=1;r<=4;r*=2){var i=t*(1+.2/r);if(i=Math.min(i,e+100663296),Fe(Math.min(n,Pe(Math.max(e,i),65536))))return!0}return!1},k:(e,t)=>{var n=0,r=0;for(var i of K()){var a=t+n;V[e+r>>2]=a,n+=G(i,a,1/0)+1,r+=4}return 0},l:(e,t)=>{var n=K();V[e>>2]=n.length;var r=0;for(var i of n)r+=ue(i)+1;return V[t>>2]=r,0},a:Be,e:function(e){try{var t=U.getStreamFromFD(e);return z.close(t),0}catch(e){if(z===void 0||e.name!==`ErrnoError`)throw e;return e.errno}},o:function(e,t,n,r){try{var i=Ve(U.getStreamFromFD(e),t,n);return V[r>>2]=i,0}catch(e){if(z===void 0||e.name!==`ErrnoError`)throw e;return e.errno}},f:function(e,t,n,r){t=Me(t);try{if(isNaN(t))return 22;var i=U.getStreamFromFD(e);return z.llseek(i,t,n),H[r>>3]=BigInt(i.position),i.getdents&&!t&&n===0&&(i.getdents=null),0}catch(e){if(z===void 0||e.name!==`ErrnoError`)throw e;return e.errno}},d:function(e,t,n,r){try{var i=He(U.getStreamFromFD(e),t,n);return V[r>>2]=i,0}catch(e){if(z===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}},ft=await async function(){function e(e){return ft=e.exports,ut(ft),_(),ft}var n=O(),r=t.instantiateWasm;return r?new Promise(t=>{r(n,n=>t(e(n)))}):(S??=C(),function(t){return e(t.instance)}(await D(void 0,S,n)))}();return await async function(){v(),R&&await xe();var e=t.setStatus;e&&(e(`Running...`),await new Promise(e=>setTimeout(e,1)),setTimeout(e,1,``)),!p&&(y(),t.onRuntimeInitialized?.(),b())}(),t}var Pe=n((()=>{})),Fe=r({default:()=>Ie});async function Ie(e={}){let t=await Ne(e);return new je(t)}var Le=n((()=>{Pe(),Me()}));Me();var K=null,Re=null,ze=null;function Be(e){ze=e,K=null,Re=null}function Ve(){return ze}async function He(e){return e||ze||Oe()}async function Ue(e={}){let t=await He(e.wasmUrl),n=t??`node`;if(K&&Re===n)return K;Re=n;let r=(async()=>{let e=(await Promise.resolve().then(()=>(Le(),Fe))).default;return await e({locateFile:e=>e.endsWith(`.wasm`)?t:e})})().catch(e=>{K===r&&(K=null,Re=null);let n=e instanceof Error?e.message:String(e);throw Error(`[WaSHI] Failed to initialize HiGHS${t?` from "${t}"`:``}. Deploy the package's WASM asset or explicitly set wasmUrl; no CDN fallback is attempted. ${n}`,{cause:e})});return K=r,r}async function We(e,t={}){if(t.signal?.aborted)return{result:{Status:`Interrupted`,StatusCode:17,HasPrimalSolution:!1,ObjectiveValue:NaN,Columns:{},Rows:[]},runTime:0};let n=await Ue(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.relGap===void 0?t.mipGap!==void 0&&(i.mip_rel_gap=t.mipGap):i.mip_rel_gap=t.relGap,t.absGap!==void 0&&(i.mip_abs_gap=t.absGap);for(let e of[`mip_max_nodes`,`mip_max_improving_sols`,`mip_max_leaves`,`simplex_iteration_limit`,`ipm_iteration_limit`])t[e]!==void 0&&(i[e]=t[e]);let a=typeof t.objectiveOffset==`number`&&Number.isFinite(t.objectiveOffset)?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`)return{result:n.withModel({format:`lp`,data:e},e=>{if(a!==0&&typeof e.changeObjectiveOffset==`function`){let t=typeof e.getObjectiveOffset==`function`?e.getObjectiveOffset():0;e.changeObjectiveOffset(t+a)}for(let[t,r]of Object.entries(i))try{e.options.set(t,r)}catch(e){if(e?.name!==`HighsUnsupportedOptionError`&&!(n.errors?.HighsUnsupportedOptionError&&e instanceof n.errors.HighsUnsupportedOptionError))throw e}let c=e.getDimensions(),l=[],u=!1;for(let t=0;t<c.numCols;t++){let n=e.getColIntegrality(t);n!==0&&(u=!0),l.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<c.numCols;e++)t.set(l[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<c.numCols;e++){let t=l[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===c.numCols?e.setSolution({colValue:r}):e.setSolution({indices:n,values:r}))}let d=null,f=null,p=0,m=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?{}:{relGap:o,mipGap:o},...s===void 0?{}:{absGap:s},...c===void 0?{}:{nodes:c},...l===void 0?{}:{iterations:l},...u===void 0?{}:{message:u}};return f=d,d},h=e=>{let n=e?.data;if(!n||!(n.mip_solution instanceof Float64Array))return;let r=n.mip_solution,i={};for(let e=0;e<l.length&&e<r.length;e++)Object.defineProperty(i,l[e].name,{value:{Index:e,Type:l[e].type,Name:l[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)&&(d={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?.(d))},g=!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){g=!0,e.interrupt();return}t.onProgress&&(p++,t.onProgress(m(e)),t.signal?.aborted&&(g=!0,e.interrupt()))},a={[r.simplexInterrupt]:i,[r.ipmInterrupt]:i,[r.mipInterrupt]:i,[r.mipImprovingSolution]:e=>{h(e),t.onProgress&&!t.signal?.aborted&&(p++,t.onProgress(m(e)))},[r.mipLogging]:e=>{t.onProgress&&!t.signal?.aborted&&(p++,t.onProgress(m(e)))}};e.run(a)}else e.run();let _=e.getModelStatus();g&&(_=17);let v=W[_]??`Unknown`,y=0,b=0;try{y=Number(e.info.get(`primal_solution_status`))}catch{}try{b=Number(e.info.get(`dual_solution_status`))}catch{}let x=n.constants?.solutionStatus?.feasible??2,S=y===x,C=b===x,w=S||C?e.getSolution():null,T=S,E={};if(!S&&d!==null)T=!0,E=d.columns;else for(let e=0;e<c.numCols;e++){let t=l[e],n={Index:e,Type:t.type,Name:t.name};S&&w&&(n.Primal=w.colValue[e]),!u&&C&&w&&(n.Dual=w.colDual[e]),Object.defineProperty(E,t.name,{value:n,enumerable:!0,writable:!0,configurable:!0})}let D=[];for(let t=0;t<c.numRows;t++){let n=e.getRowName(t),r={Index:t,Name:n};S&&w&&(r.Primal=w.rowValue[t]),!u&&C&&w&&(r.Dual=w.rowDual[t]),D.push(r)}let O=S?e.getObjectiveValue():d===null?NaN:d.objectiveValue,k,A;if(u){try{let t=Number(e.info.get(`mip_dual_bound`));Number.isFinite(t)&&(k=t)}catch{}k===void 0&&f&&f.objectiveBound!==void 0&&(k=f.objectiveBound);try{let t=Number(e.info.get(`mip_gap`));Number.isFinite(t)&&(A=t)}catch{}A===void 0&&f&&f.relGap!==void 0&&(A=f.relGap)}return{Status:W[_]??v,StatusCode:_,PrimalSolutionStatus:y,DualSolutionStatus:b,HasPrimalSolution:T,IsMip:u,ObjectiveValue:O,ObjectiveOffsetApplied:a!==0,MipDualBound:k,MipGap:A,Columns:E,Rows:D}}),runTime:(performance.now()-r)/1e3};if(s)throw Error(`HiGHS runtime does not support setting primal initial values (withModel/setSolution is unavailable).`);return{result:n.solve(e,i),runTime:(performance.now()-r)/1e3}}function Ge(){let e=z(`highs-worker.js`);if(new URL(e).origin===window.location.origin)return new Worker(e,{type:`module`});let t=URL.createObjectURL(new Blob([`import `+JSON.stringify(e)+`;`],{type:`text/javascript`}));try{let e=new Worker(t,{type:`module`}),n=()=>URL.revokeObjectURL(t);return e.addEventListener(`message`,n,{once:!0}),e.addEventListener(`error`,n,{once:!0}),e}catch(e){throw URL.revokeObjectURL(t),e}}var q=null,Ke=0,J=new Map;function qe(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?.relGap===void 0?e.mipGap===void 0?{}:{MipGap:e.mipGap}:{MipGap:t.relGap},Columns:e.columns,Rows:[]}:{Status:`Interrupted`,StatusCode:17,HasPrimalSolution:!1,ObjectiveValue:NaN,ObjectiveOffsetApplied:!0,...t?.objectiveBound===void 0?{}:{MipDualBound:t.objectiveBound},...t?.relGap===void 0?{}:{MipGap:t.relGap},Columns:{},Rows:[]}}function Je(e){let t=J.values().next().value;if(t&&!t.dispatched){t.dispatched=!0;try{e.postMessage({type:`SOLVE`,id:t.id,lpString:t.lpString,options:t.workerOptions,...t.reportProgress?{reportProgress:!0}:{}})}catch(n){J.delete(t.id),t.cleanupAbort?.(),t.reject(n),Je(e)}}}function Ye(){let e=q;e&&(q=null,e.terminate());for(let e of J.values())e.dispatched=!1;if(J.size>0){let e=Xe();if(e)Je(e);else{let e=Error(`[WaSHI] Failed to recreate HiGHS Worker after interruption.`);for(let t of Array.from(J.values()))J.delete(t.id),t.cleanupAbort?.(),t.reject(e)}}}function Xe(){if(typeof window>`u`||typeof Worker>`u`)return null;if(!q)try{q=Ge();let e=q;q.onmessage=t=>{let{type:n,id:r,result:i,runTime:a,error:o,progress:s,incumbent:c}=t.data,l=J.get(r);if(l){if(n===`SOLVE_PROGRESS`){if(s){l.lastProgress=s;try{l.onProgress?.(s)}catch(e){let t=J.get(r);if(t){let n=J.keys().next().value;J.delete(r),t.cleanupAbort?.(),n===r&&Ye(),t.reject(e)}}}return}if(n===`SOLVE_INCUMBENT`){c&&(l.lastIncumbent=c);return}J.delete(r),l.cleanupAbort?.(),n===`SOLVE_SUCCESS`?l.resolve({result:i,runTime:a}):l.reject(Error(o||`Worker solve failed`)),q===e&&Je(e)}};let t=t=>{if(q===e){q=null,e.terminate();for(let e of J.values())e.cleanupAbort?.(),e.reject(t);J.clear()}};q.onerror=e=>t(Error(`[WaSHI] HiGHS Worker failed to load or execute. Check Worker assets, CORS and CSP. ${e?.message||``}`)),q.onmessageerror=()=>t(Error(`[WaSHI] Could not deserialize the HiGHS Worker response.`))}catch{q=null}return q}async function Ze(e,t={}){if(t.signal?.aborted)return{result:qe(),runTime:0};let n=await He(t.wasmUrl);if(t.signal?.aborted)return{result:qe(),runTime:0};let r=t.useWorker??typeof window<`u`?Xe():null;if(!r)return We(e,t);let{signal:i,onProgress:a,...o}=t,s={};for(let[e,t]of Object.entries(o))typeof t!=`function`&&(s[e]=t);s.wasmUrl=n;let c=!!(a||i),l=`req_${++Ke}`,u=performance.now();return new Promise((t,n)=>{let o={id:l,lpString:e,workerOptions:s,reportProgress:c,startTime:u,onProgress:a,resolve:t,reject:n};if(i){let e=()=>{let e=J.get(l);if(!e)return;let t=J.keys().next().value;J.delete(l),e.cleanupAbort?.(),t===l&&Ye();let n=(performance.now()-e.startTime)/1e3;e.resolve({result:qe(e.lastIncumbent,e.lastProgress),runTime:n})};i.addEventListener(`abort`,e,{once:!0}),o.cleanupAbort=()=>i.removeEventListener(`abort`,e)}J.set(l,o),Je(r)})}function Qe(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`}let r=n.toLowerCase();return r.includes(`infeasible`)&&r.includes(`unbounded`)?`InfeasibleOrUnbounded`:r.includes(`infeasible`)?`Infeasible`:r.includes(`unbounded`)?`Unbounded`:r.includes(`time limit`)||r.includes(`timelimit`)?`TimeLimit`:r.includes(`iteration limit`)||r.includes(`iterationlimit`)?`IterationLimit`:r.includes(`solution limit`)||r.includes(`solutionlimit`)?`SolutionLimit`:r.includes(`memory limit`)||r.includes(`memorylimit`)?`MemoryLimit`:r.includes(`bound on objective`)?`ObjectiveBound`:r.includes(`target for objective`)?`ObjectiveTarget`:r.includes(`interrupt`)?`Interrupted`:r.includes(`error`)?`Error`:r===`optimal`?`Optimal`:`Unknown`}function Y(e,t,n){switch(Qe(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 $e=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=he(t),i=r?n:t,a={...this.options,...i},o=e.objective.constant||0;for(let t of e.variables)te(t);let{lpString:s,nameToVar:c,nameToConstraint:l}=r?t:ve(e,{relax:a.relax}),u=Object.create(null),d=!1,f=new Set;for(let[e,t]of c.entries()){f.add(t);let n=ne(t);n!==void 0&&(u[e]=n,d=!0)}for(let t=0;t<e.variables.length;t++){let n=e.variables[t];if(!f.has(n)){let e=ne(n);if(e!==void 0){let r=ge(n.name,`x`,t);Object.prototype.hasOwnProperty.call(u,r)||(u[r]=e,d=!0)}}}let p=a;(o!==0||d||p.initialValues!==void 0)&&(p={...p,...o===0?{}:{objectiveOffset:o},initialValues:d?u:void 0});let{result:m,runTime:h}=await Ze(s,p),g=m?.ObjectiveOffsetApplied?0:o,_=Qe(m?.Status,m?.StatusCode),v=a.relax?!1:typeof m?.IsMip==`boolean`?m.IsMip:e.variables.some(e=>e.type===`Integer`||e.type===`Binary`),y;if(typeof m?.HasPrimalSolution==`boolean`)y=m.HasPrimalSolution;else{let e=m?.Columns?Object.values(m.Columns):[],t=e.length>0&&e.some(e=>typeof e?.Primal==`number`&&Number.isFinite(e.Primal)),n=typeof m?.ObjectiveValue==`number`&&Number.isFinite(m.ObjectiveValue);y=_===`Infeasible`||_===`Unbounded`||_===`InfeasibleOrUnbounded`||_===`Error`||_===`NotSolved`?!1:_===`Optimal`||_===`Feasible`?n||t:n&&(e.length===0||t)}let b=Y(m?.Status,m?.StatusCode,y),x=null;y&&typeof m?.ObjectiveValue==`number`&&Number.isFinite(m.ObjectiveValue)&&(x=m.ObjectiveValue+g);let S,C,w;if(typeof m?.MipDualBound==`number`&&Number.isFinite(m.MipDualBound)?S=m.MipDualBound+g:!v&&_===`Optimal`&&x!==null&&(S=x),x!==null&&S!==void 0&&Number.isFinite(S)&&(w=Math.abs(x-S)),g!==0&&v&&x!==null&&S!==void 0&&w!==void 0){if(w===0)C=0;else if(Math.abs(x)>0){let e=w/Math.abs(x);C=Number.isFinite(e)?e:void 0}else C=void 0}else typeof m?.MipGap==`number`&&Number.isFinite(m.MipGap)?C=m.MipGap:v&&_===`Optimal`&&y&&(w===void 0||w===0)&&(C=0);if(!y)return{status:b,terminationStatus:_,hasPrimalSolution:!1,objectiveValue:null,...S===void 0?{}:{objectiveBound:S},...C===void 0?{}:{relGap:C,mipGap:C},...w===void 0?{}:{absGap:w},values:{},reducedCosts:{},duals:{},slacks:{},runTime:h,raw:m};let T=(e,t,n)=>{Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})},E={},D={},O={},k={};if(m.Columns)for(let[e,t]of Object.entries(m.Columns)){let n=c.get(e);if(n){if(typeof t.Primal==`number`&&Number.isFinite(t.Primal)){let e=Math.abs(t.Primal)<1e-9?0:t.Primal;T(E,n.name,e)}typeof t.Dual==`number`&&Number.isFinite(t.Dual)&&T(O,n.name,Math.abs(t.Dual)<1e-9?0:t.Dual)}}if(m.Rows){let e=Array.isArray(m.Rows)?m.Rows:Object.values(m.Rows);for(let t of e){let e=t.Name,n=e?l.get(e):void 0;if(n&&(typeof t.Dual==`number`&&Number.isFinite(t.Dual)&&T(D,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;T(k,n.name,Math.abs(e)<1e-9?0:e)}}}return{status:b,terminationStatus:_,hasPrimalSolution:!0,objectiveValue:x,...S===void 0?{}:{objectiveBound:S},...C===void 0?{}:{relGap:C,mipGap:C},...w===void 0?{}:{absGap:w},values:E,reducedCosts:O,duals:D,slacks:k,runTime:h,raw:m}}},et=$e;function tt(){Se(`highs`,e=>new $e(e)),Ce(e=>new $e(e))}tt(),Me();var nt=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=he(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.relGap===void 0?i.mipGap===void 0?{}:{relGap:i.mipGap,mipGap:i.mipGap}:{relGap:i.relGap,mipGap:i.relGap},...i.absGap===void 0?{}:{absGap:i.absGap},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.relGap===void 0?i.mipGap===void 0?{}:{relGap:i.mipGap,mipGap:i.mipGap}:{relGap:i.relGap,mipGap:i.relGap},...i.absGap===void 0?{}:{absGap:i.absGap}})}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.relGap===void 0?i.mipGap===void 0?{}:{relGap:i.mipGap,mipGap:i.mipGap}:{relGap:i.relGap,mipGap:i.relGap},...i.absGap===void 0?{}:{absGap:i.absGap},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 rt(){Se(`mock`,e=>new nt(e))}rt();function it(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 at(e,t={}){let n=it(t.feasibilityTolerance,`feasibilityTolerance`),r=it(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)},h=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)},_=new Map,v=new Map,y=0,b=0,x=0,S=0;for(let t of e.variables){let e=a?Object.prototype.hasOwnProperty.call(o,t.name)?o[t.name]:void 0:t.value;if(e==null){f.push(t.name),h({type:`missing_value`,target:`variable`,name:t.name,actual:e??null,violation:1/0,message:`Variable "${t.name}" has no assigned solution value.`});continue}if(typeof e!=`number`||!Number.isFinite(e)){h({type:`non_finite_value`,target:`variable`,name:t.name,actual:e,violation:1/0,message:`Variable "${t.name}" has non-finite or non-numeric value: ${String(e)}.`});continue}_.set(t,e),y++;let i=t.type===`Binary`||t.type===`BINARY`,s=i||t.type===`Integer`||t.type===`INTEGER`,c=i?Math.max(0,t.lb):t.lb,l=i?Math.min(1,t.ub):t.ub,u=typeof t.lb==`number`&&!Number.isNaN(t.lb)&&t.lb!==1/0,d=typeof t.ub==`number`&&!Number.isNaN(t.ub)&&t.ub!==-1/0;if(!u)h({type:`lower_bound`,target:`variable`,name:t.name,actual:e,limit:t.lb,violation:1/0,message:`Variable "${t.name}" has invalid lower bound (${String(t.lb)}).`});else if(c!==-1/0){let r=e-c,i=Math.max(0,c-e);m(i),i>n&&h({type:`lower_bound`,target:`variable`,name:t.name,actual:e,limit:c,violation:i,signedViolation:r,message:`Variable "${t.name}" value (${e}) violates lower bound (${c}) by ${i}.`})}if(!d)h({type:`upper_bound`,target:`variable`,name:t.name,actual:e,limit:t.ub,violation:1/0,message:`Variable "${t.name}" has invalid upper bound (${String(t.ub)}).`});else if(l!==1/0){let r=e-l,i=Math.max(0,e-l);m(i),i>n&&h({type:`upper_bound`,target:`variable`,name:t.name,actual:e,limit:l,violation:i,signedViolation:r,message:`Variable "${t.name}" value (${e}) violates upper bound (${l}) by ${i}.`})}if(u&&d&&c>l&&c-e<=n&&e-l<=n){let n=c-l;h({type:`lower_bound`,target:`variable`,name:t.name,actual:e,limit:c,violation:n,signedViolation:e-c,message:`Variable "${t.name}" has inverted bounds [${c}, ${l}].`})}if(s){let n=Math.round(e),a=e-n,o=Math.abs(a);m(o),o>r&&h({type:`integrality`,target:`variable`,name:t.name,varType:i?`Binary`:`Integer`,actual:e,nearestInteger:n,violation:o,signedViolation:a,message:`${i?`Binary`:`Integer`} variable "${t.name}" value (${e}) violates integrality by ${o} (nearest integer: ${n}).`})}}for(let t of e.boolVars){let e=a?Object.prototype.hasOwnProperty.call(o,t.name)?o[t.name]:void 0:t.value;if(e==null){f.push(t.name),h({type:`missing_value`,target:`bool_variable`,name:t.name,actual:e??null,violation:1/0,message:`Boolean variable "${t.name}" has no assigned solution value.`});continue}if(typeof e!=`boolean`){h({type:`invalid_boolean_value`,target:`bool_variable`,name:t.name,actual:e,violation:1/0,message:`Boolean variable "${t.name}" has non-boolean value: ${String(e)}.`});continue}v.set(t,e),b++}let C=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(!_.has(t))return{ok:!1,reason:`missing or invalid value for variable "${t.name}"`};if(n+=r*_.get(t),!Number.isFinite(n))return{ok:!1,reason:`linear expression evaluation overflowed finite range`}}}return{ok:!0,value:n}},w=(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=C(e.lhs);if(!r.ok)return{status:`unchecked`,reason:r.reason};let i=r.value,a=i-e.rhs;if(!Number.isFinite(a))return{status:`unchecked`,reason:`constraint residual overflowed finite range`};let o=e.sense===`<=`?Math.max(0,a):e.sense===`>=`?Math.max(0,-a):Math.abs(a);return o>t?{status:`violated`,lhsVal:i,signed:a,violation:o,message:`Constraint "${e.name}" (${i} ${e.sense} ${e.rhs}) violated by ${o}.`}:{status:`satisfied`,lhsVal:i,signed:a,violation:o}};for(let t of e.constraints){let e=w(t);e.status===`unchecked`?(d.push(t.name),h({type:`unchecked_constraint`,target:`constraint`,name:t.name,sense:t.sense,limit:t.rhs,rhs:t.rhs,violation:1/0,message:`Constraint "${t.name}" could not be evaluated: ${e.reason}.`})):e.status===`violated`?(x++,h({type:`linear_constraint`,target:`constraint`,name:t.name,sense:t.sense,actual:e.lhsVal,limit:t.rhs,rhs:t.rhs,violation:e.violation,signedViolation:e.signed,message:e.message})):(x++,m(e.violation))}let T=e=>{if(e instanceof c)return v.has(e)?{ok:!0,value:v.get(e),violation:0}:{ok:!1,reason:`missing or invalid value for Boolean variable "${e.name}"`};if(e instanceof g){let t=w(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 l)switch(e.op){case`not`:{let t=T(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=T(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=T(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=T(e.children[0]);if(!t.ok)return t;if(!t.value)return{ok:!0,value:!0,violation:0};let n=T(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=T(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 t=0;t<e.logicalConstraints.length;t++){let n=e.logicalConstraints[t],r=n.name||`lc_${t+1}`;if(!i){d.push(r),h({type:`unchecked_constraint`,target:`logical_constraint`,name:r,violation:1/0,message:`Logical constraint "${r}" was not evaluated because evaluateLogicalConstraints is false.`});continue}let a=T(n.expr);if(!a.ok){d.push(r),h({type:`unchecked_constraint`,target:`logical_constraint`,name:r,violation:1/0,message:`Logical constraint "${r}" could not be evaluated: ${a.reason}.`});continue}S++,a.value?m(a.violation):h({type:`logical_constraint`,target:`logical_constraint`,name:r,actual:!1,limit:!0,violation:1,signedViolation:-1,message:`Logical constraint "${r}" evaluated to false.`})}let E=y===e.variables.length&&b===e.boolVars.length&&x===e.constraints.length&&S===e.logicalConstraints.length&&d.length===0&&f.length===0;return{valid:E&&s.length===0,complete:E,violations:s,violationsByName:u,uncheckedConstraints:d,missingVariables:f,maxViolation:p,summary:{checkedVariables:y,totalVariables:e.variables.length,checkedBoolVariables:b,totalBoolVariables:e.boolVars.length,checkedLinearConstraints:x,totalLinearConstraints:e.constraints.length,checkedLogicalConstraints:S,totalLogicalConstraints:e.logicalConstraints.length}}}function ot(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 X(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 st(e,t,n){let r=X(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 ct(e,t,n){let r=X(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 Z(e,t,n,r,i,a,o){if(!(e instanceof P&&(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=X(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 b(d,0),rhs:u}}function Q(e,t=0){return new b(new Map(e),t)}function lt(e,t,n,r){let i=[...e],a=[...n],o=new Map,s=new Map;for(let e of n)s.set(e,e.name);let u=new Set(e.map(e=>e.name)),d=0;function f(e){let t;do t=`__washi_${e}_${++d}`;while(u.has(t));return u.add(t),t}for(let e of t){let t=e.name;u.has(t)?t=f(`bool_${e.name}`):u.add(t);let n=new P({name:t,type:`Binary`,lb:0,ub:1});o.set(e,n),i.push(n)}function p(e,t){if(e instanceof $)return e.wrappedVar;if(e instanceof c){let n=o.get(e);if(!n)throw Error(`Unregistered BoolVar "${e.name}" in logical constraint "${t}".`);return n}let n=new P({name:f(`expr`),type:`Binary`,lb:0,ub:1});return i.push(n),h(n,e,t),n}function m(e,t,n,r){let i=new g(Q([[e,1],[t,-1],[n,-1]],0),`<=`,0,`${r}_xor_1`),o=new g(Q([[e,1],[t,-1],[n,1]],0),`>=`,0,`${r}_xor_2`),c=new g(Q([[e,1],[n,-1],[t,1]],0),`>=`,0,`${r}_xor_3`),l=new g(Q([[e,1],[t,1],[n,1]],0),`<=`,2,`${r}_xor_4`);a.push(i,o,c,l),s.set(i,r),s.set(o,r),s.set(c,r),s.set(l,r)}function h(e,t,n){if(t instanceof c){let r=o.get(t),i=new g(Q([[e,1],[r,-1]],0),`==`,0,`${n}_equiv`);a.push(i),s.set(i,n);return}if(t instanceof l){if(t.op===`not`){let r=p(t.children[0],n),i=new g(Q([[e,1],[r,1]],0),`==`,1,`${n}_not`);a.push(i),s.set(i,n);return}if(t.op===`and`){let r=t.children.map(e=>p(e,n));for(let t=0;t<r.length;t++){let i=new g(Q([[e,1],[r[t],-1]],0),`<=`,0,`${n}_and_ub_${t}`);a.push(i),s.set(i,n)}let i=new g(Q([[e,1],...r.map(e=>[e,-1])],0),`>=`,1-r.length,`${n}_and_lb`);a.push(i),s.set(i,n);return}if(t.op===`or`){let r=t.children.map(e=>p(e,n));for(let t=0;t<r.length;t++){let i=new g(Q([[e,1],[r[t],-1]],0),`>=`,0,`${n}_or_lb_${t}`);a.push(i),s.set(i,n)}let i=new g(Q([[e,1],...r.map(e=>[e,-1])],0),`<=`,0,`${n}_or_ub`);a.push(i),s.set(i,n);return}if(t.op===`implies`){let r=p(t.children[0],n),i=p(t.children[1],n),o=new g(Q([[e,1],[i,-1],[r,1]],0),`>=`,0,`${n}_imp_1`),c=new g(Q([[e,1],[r,1],[i,-1]],0),`<=`,1,`${n}_imp_2`);a.push(o,c),s.set(o,n),s.set(c,n);return}if(t.op===`xor`){if(t.children.length===0){let t=new g(Q([[e,1]],0),`==`,0,`${n}_xor_empty`);a.push(t),s.set(t,n);return}if(t.children.length===1){let r=p(t.children[0],n),i=new g(Q([[e,1],[r,-1]],0),`==`,0,`${n}_xor_single`);a.push(i),s.set(i,n);return}let r=t.children.map(e=>p(e,n)),o=r[0];for(let e=1;e<r.length-1;e++){let t=new P({name:f(`xor_fold_${e}`),type:`Binary`,lb:0,ub:1});i.push(t),m(t,o,r[e],`${n}_xor_fold_${e}`),o=t}m(e,o,r[r.length-1],n);return}}throw Error(`Unsupported logical element in equivalence linearization: ${t}`)}for(let e of r){let t=e.name,n=e.expr;_(n,t)}function _(e,t){if(e instanceof c){let n=new g(Q([[o.get(e),1]],0),`>=`,1,t);a.push(n),s.set(n,t);return}if(e instanceof l){if(e.op===`not`){let n=e.children[0];if(n instanceof c){let e=new g(Q([[o.get(n),1]],0),`<=`,0,t);a.push(e),s.set(e,t);return}let r=new g(Q([[p(n,t),1]],0),`<=`,0,t);a.push(r),s.set(r,t);return}if(e.op===`and`){for(let n=0;n<e.children.length;n++)_(e.children[n],`${t}_and_${n}`);return}if(e.op===`or`){if(e.children.every(e=>e instanceof c||e instanceof l)){let n=new g(Q(e.children.map(e=>p(e,t)).map(e=>[e,1]),0),`>=`,1,t);a.push(n),s.set(n,t);return}let n=[];for(let r=0;r<e.children.length;r++){let o=e.children[r],c=new P({name:f(`or_branch_${r}`),type:`Binary`,lb:0,ub:1});if(i.push(c),n.push(c),o instanceof g)v(c,o,1,`${t}_or_branch_${r}`,t);else{let e=p(o,t),n=new g(Q([[c,1],[e,-1]],0),`<=`,0,`${t}_or_bool_${r}`);a.push(n),s.set(n,t)}}let r=new g(Q(n.map(e=>[e,1]),0),`>=`,1,t);a.push(r),s.set(r,t);return}if(e.op===`xor`){if(e.children.length===0){let e=new P({name:f(`unsat`),type:`Binary`,lb:0,ub:0});i.push(e);let n=new g(Q([[e,1]],0),`>=`,1,t);a.push(n),s.set(n,t);return}if(e.children.length===1){_(e.children[0],t);return}let n=e.children.map(e=>p(e,t));if(n.length===2){let e=new g(Q([[n[0],1],[n[1],1]],0),`==`,1,t);a.push(e),s.set(e,t);return}let r=n[0];for(let e=1;e<n.length-1;e++){let a=new P({name:f(`xor_fold_${e}`),type:`Binary`,lb:0,ub:1});i.push(a),m(a,r,n[e],`${t}_xor_fold_${e}`),r=a}let o=n[n.length-1],c=new g(Q([[r,1],[o,1]],0),`==`,1,t);a.push(c),s.set(c,t);return}if(e.op===`implies`){let[n,r]=e.children;if(n instanceof g&&n.lhs.terms.size===1&&n.lhs.constant===0){let[[e,i]]=Array.from(n.lhs.terms.entries());if((e.type===`Binary`||e.type===`Integer`&&e.lb===0&&e.ub===1)&&i===1){let i=null;if(n.sense===`==`&&n.rhs===1?i=1:n.sense===`==`&&n.rhs===0||n.sense===`<=`&&n.rhs===0?i=0:n.sense===`>=`&&n.rhs===1&&(i=1),i!==null&&r instanceof g){v(e,r,i,t,t);return}}}let u;if(n instanceof g?(u=new P({name:f(`ante`),type:`Binary`,lb:0,ub:1}),i.push(u),v(u,n,1,`${t}_ante_active`,t)):u=p(n,t),r instanceof g){v(u,r,1,t,t);return}if(r instanceof c){let e=new g(Q([[o.get(r),1],[u,-1]],0),`>=`,0,t);a.push(e),s.set(e,t);return}if(r instanceof l){if(r.op===`and`){for(let e=0;e<r.children.length;e++)_(new l(`implies`,[u instanceof P?new $(u):n,r.children[e]]),`${t}_and_${e}`);return}if(r.op===`not`){let e=r.children[0],n=p(e,t),i=new g(Q([[u,1],[n,1]],0),`<=`,1,t);a.push(i),s.set(i,t);return}let e=new g(Q([[p(r,t),1],[u,-1]],0),`>=`,0,t);a.push(e),s.set(e,t);return}}}throw Error(`Unsupported top-level logical constraint "${t}": ${e}`)}function v(e,t,n,r,i){let{lhs:o,sense:c,rhs:l}=t;if(c===`<=`||c===`>=`){let t=Z(e,o,c,l,n,c===`<=`?st(o,l,r):ct(o,l,r),r),u=new g(t.lhs,c,t.rhs,r);a.push(u),s.set(u,i)}else{let t=st(o,l,`${r}_le`),c=ct(o,l,`${r}_ge`),u=Z(e,o,`<=`,l,n,t,`${r}_le`),d=Z(e,o,`>=`,l,n,c,`${r}_ge`),f=new g(u.lhs,`<=`,u.rhs,`${r}_le`),p=new g(d.lhs,`>=`,d.rhs,`${r}_ge`);a.push(f,p),s.set(f,i),s.set(p,i)}}return{variables:i,constraints:a,boolVarToBinary:o,constraintToOriginalName:s}}var $=class extends c{wrappedVar;constructor(e){super(e.name),this.wrappedVar=e}};async function ut(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.addColumn({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)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 dt(e,t){let n=e;if(n instanceof g||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 b||n instanceof y||n instanceof P||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 ft(e){return{expr:dt(e,`maximize`),sense:`Maximize`}}function pt(e){return{expr:dt(e,`minimize`),sense:`Minimize`}}function mt(e){return!!(e&&typeof e==`object`&&`constraints`in e&&`variables`in e&&typeof e.solve==`function`)}async function ht(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())if(e.ownerModel===n||n.getVarByName(e.name)!==void 0){f.push([e,t]);let n=i[e.name]??0;p+=t*n}else d.push([e,t]);let m=u-p,h=new b;for(let[e,t]of d)h.addTerm(e,t);let _=new g(h,s,m,`__benders_link_${c}_${r}`);e.constraint(_),l.push({origConstraint:a,subConstr:_,masterTerms:f,baseRhs:u})}let u=await e.solve(o,{...s,relax:!0});if(u!==`Optimal`&&u!==`Feasible`)return null;let d=e.objectiveValue??0,f=i[r.name]??0,p=1e-4;if(!(a?f<d-p:f>d+p))return null;let m=0,h=new Map,_=new Set(l.map(e=>e.subConstr.name));for(let t of e.constraints){if(_.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 v=new b;v.addTerm(r,1);for(let[e,t]of h.entries())Math.abs(t)>1e-12&&v.addTerm(e,t);let y=new g(v,a?`>=`:`<=`,m,`__benders_opt_cut_${c}`),x=(n.objectiveValue??0)-f+d;return{kind:`optimality`,constraint:y,name:y.name,subproblemObjective:x}}async function gt(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;e.theta&&(c=typeof e.theta==`string`?t.getVarByName(e.theta):e.theta),c||=t.variables.find(e=>e.name===`theta`||e.name===`__benders_theta`);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)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(mt(b)){let n=b,r=n.linkingConstraints;c||(c=t.continuous(`__benders_theta`,{lb:0}),v?t.objective(pt(t.objectiveExpr.add(c))):t.objective(ft(t.objectiveExpr.sub(c))));let i=await ht(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 _=Object.keys(h).length>0?h:(()=>{let e={};for(let n of t.variables)n.value!==null&&(e[n.name]=n.value);return e})(),v=g===null?t.objectiveValue:g,y={status:d,objectiveValue:v,lowerBound:f,upperBound:p,gap:m,iterations:u,cutsAdded:l,master:t,values:_};return t.decomposition=y,y}function _t(e){return Array.isArray(e)||typeof e==`object`&&!!e&&!(e instanceof String)&&typeof e[Symbol.iterator]==`function`}function vt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!(e instanceof String)&&typeof e[Symbol.iterator]!=`function`}function yt(e){return e instanceof P||typeof e==`object`&&!!e&&!(e instanceof s)&&!(e instanceof g)&&`id`in e&&`name`in e&&`lb`in e&&`ub`in e&&!(`terms`in e)&&!(`quadTerms`in e)&&!(`sense`in e)}function bt(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 xt=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;status=`NotSolved`;terminationStatus=`NotSolved`;hasPrimalSolution=!1;objectiveValue=null;objectiveBound=void 0;relGap=void 0;mipGap=void 0;absGap=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 b,n.solver&&(this.solver=we(n.solver))}get sense(){return this._sense}set sense(e){let t=i(e);this._sense!==t&&(this._sense=t,this.recordModelMutation())}get objectiveExpr(){return this._objectiveExpr.clone()}set objectiveExpr(e){this.applyObjective(e)}get conflicts(){return this._conflicts??this.unsatCore}set conflicts(e){this._conflicts=e}get numVars(){return this.variables.length}get numConstrs(){return this.constraints.length}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.relGap=void 0,this.mipGap=void 0,this.absGap=void 0,this.solution=null,this.runTime=0,this.unsatCore=void 0,this._conflicts=void 0,this.values.clear();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()}notifyMutation(){this.recordModelMutation()}resetSolutionState(){this.recordModelMutation()}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),t.ownerModel=null,k(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.boolVars.length=n;for(let e=r;e<this.constraints.length;e++){let t=this.constraints[e];this.constrMapByName.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.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=_t(t),c=_t(n);if(o||c){if(a&&bt(t,i),o&&bt(n,i),!a&&!s||r!==void 0&&!vt(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&&!vt(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(vt(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&&!vt(n))throw Error(`Invalid arguments provided for ${i} variable creation`);let l=n||{},u=l.prefix||l.name;if(typeof t==`number`)return bt(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(_t(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)}addColumn(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.getConstraintByName(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.getConstraintByName(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.getConstraintByName(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.getConstraintByName(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=_t(e),o=_t(t);if(i||o){if(r&&bt(e,`boolean`),i&&bt(t,`boolean`),!r&&!a||n!==void 0&&!vt(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&&!vt(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(vt(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&&!vt(t))throw Error(`Invalid arguments provided for boolean variable creation`);let s=t||{},c=s.prefix||s.name;if(typeof e==`number`)return bt(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(_t(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.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 P({...t,name:s,prefix:a});return e.hasExplicitName=r!==void 0,te(e),D(e,this),e.ownerModel=this,this.variables.push(e),this.varMapByName.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}}getVarByName(e){return this.varMapByName.get(e)}getBoolVarByName(e){return this.boolVarMapByName.get(e)}getConstraintByName(e){return this.constrMapByName.get(e)}getLogicalConstraintByName(e){return this.logicalConstrMapByName.get(e)}objective(e){if(arguments.length===0)return this.objectiveExpr;let t=e;if(t instanceof g||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 g||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=le(e,e=>this.getVarByName(e));else if(typeof e==`number`)r=new b(new Map,e);else if(e instanceof y)r=e.clone();else if(e instanceof b)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 y(t.linearTerms,t.quadTerms,t.constant)}else if(typeof e==`object`&&e&&`terms`in e&&e.terms instanceof Map&&typeof e.constant==`number`){let t=e;r=new b(t.terms,t.constant)}else if(e instanceof P||typeof e==`object`&&e&&`id`in e&&`name`in e&&`lb`in e&&`ub`in e)r=new b(new Map([[e,1]]),0);else throw Error(`Invalid objective expression: expected a finite number, Var, LinExpr, QuadExpr, or arithmetic expression string.`);re(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(()=>{for(let t of e)this.constraint(t);return this});if(e instanceof y||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 b||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(yt(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),this}getValues(e){if(e==null)return null;if(e instanceof P||e instanceof c)return e.value;if(Array.isArray(e))return e.map(e=>this.getValues(e));if(typeof e==`object`){let t={};for(let[n,r]of Object.entries(e))t[n]=this.getValues(r);return t}return null}addConstraint(e,t){if(e instanceof y||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 b||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(yt(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{ie(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}E(e,this,this.batchDepth>0?this.batchUndoActions:void 0);let a={name:i,expr:e};return this.logicalConstraints.push(a),this.logicalConstrMapByName.set(i,a),this.recordModelMutation(),e}let n=typeof e==`string`?de(e,e=>this.getVarByName(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&&(j(n,this.name,e=>this.varMapByName.get(e.name)===e,n.name),O(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{j(n,this.name,e=>this.varMapByName.get(e.name)===e,a),o=O(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),A(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.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 P))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 y||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,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&&ot(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=Z(e,c,`<=`,u,i,n.M===void 0?st(c,u,f):n.M,f);m.push([new g(t.lhs,`<=`,t.rhs,f),f])}if(l===`>=`||l===`==`){let t=Z(e,c,`>=`,u,i,n.M===void 0?ct(c,u,p):n.M,p);m.push([new g(t.lhs,`>=`,t.rhs,p),p])}for(let[e,n]of m)j(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(){this.validateIntegrity();let{lpString:e}=ve({name:this.name,sense:this.sense,objective:this.objectiveExpr,constraints:this.constraints,variables:this.variables});return e}validateIntegrity(){M(this)}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){let r=e.onProgress;return r?{...e,onProgress:e=>{this.activeOperationId===n&&this.modelRevision===t&&r(e)}}:e}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`))}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:we(e,r),activeOptions:r}}let{solver:n,...r}=e||{};return n?{activeSolver:we(n,r),activeOptions:r}:{activeSolver:this.solver||we(),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.validateIntegrity();let{activeSolver:i,activeOptions:a}=this.resolveSolverAndOptions(e,t);if(this._objectiveExpr instanceof y&&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(this.logicalConstraints.length>0&&i.capabilities?.supportsSMT!==!0?(s=lt(this.variables,this.boolVars,this.constraints,this.logicalConstraints),o={name:this.name,sense:this.sense,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.`);let c=this.wrapSolveOptions(a,r,n),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,this.objectiveValue=u&&typeof l.objectiveValue==`number`&&Number.isFinite(l.objectiveValue)?l.objectiveValue:null,this.objectiveBound=typeof l.objectiveBound==`number`&&Number.isFinite(l.objectiveBound)?l.objectiveBound:void 0;let d=typeof l.relGap==`number`&&Number.isFinite(l.relGap)?l.relGap:typeof l.mipGap==`number`&&Number.isFinite(l.mipGap)?l.mipGap:void 0;this.relGap=d,this.mipGap=d,this.absGap=typeof l.absGap==`number`&&Number.isFinite(l.absGap)?l.absGap:this.objectiveValue!==null&&this.objectiveBound!==void 0?Math.abs(this.objectiveValue-this.objectiveBound):void 0;let f=(e,t,n)=>{Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})},p={},m={},h={},g={};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.getVarByName(e),r=this.getBoolVarByName(e);n&&(n.value=t,f(p,n.name,t),this.values.set(n.name,t)),r&&(r.value=!!t,this.values.set(r.name,t)),!n&&!r&&this.values.set(e,t)}else if(typeof t==`boolean`){let n=t,r=this.getBoolVarByName(e);r?(r.value=n,f(p,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,f(p,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.getBoolVarByName(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.getVarByName(e);n&&(n.reducedCost=t,f(h,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.getConstraintByName(e);n&&(n.dual=t,f(m,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.getConstraintByName(e);n&&(n.slack=t,f(g,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.relGap===void 0?{}:{relGap:this.relGap,mipGap:this.mipGap},...this.absGap===void 0?{}:{absGap:this.absGap},values:p,duals:m,reducedCosts:h,slacks:g,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.validateIntegrity();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.`);let o=this.wrapSolveOptions(a,r,n),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.getVarByName(n),i=this.getBoolVarByName(n);e&&(e.value=r,this.values.set(e.name,r),s(t,e.name,r)),i&&(i.value=!!r,this.values.set(i.name,i.value),s(t,i.name,i.value)),!e&&!i&&(this.values.set(n,r),s(t,n,r))}else if(typeof r==`boolean`){let e=this.getBoolVarByName(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?lt(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 P({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 b(new Map([[r,-1]]),0));u.push(new g(a,`<=`,i,`${e.name}_slack`))}else if(r===`>=`){let r=new P({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 b(new Map([[r,1]]),0));u.push(new g(a,`>=`,i,`${e.name}_slack`))}else{let r=new P({name:`__slack_${++m}_p`,type:`Continuous`,lb:0,ub:1/0}),a=new P({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 b(new Map([[r,-1],[a,1]]),0));u.push(new g(o,`==`,i,`${e.name}_slack`))}}let h={name:`${this.name}_elastic_check`,sense:`Minimize`,objective:new b(new Map(f),0),constraints:u,variables:[...l.variables,...d]},_;try{_=await i.solve(h,o)}catch(e){throw this.activeOperationId===n&&this.clearSolutionFields(),e}this.ensureExecutionValid(r,n,`check`),this.runTime=_.runTime??0;let v=_.status,y=_.terminationStatus??v,x=this.hasPrimalFromResult(_),S=typeof _.objectiveValue==`number`&&Number.isFinite(_.objectiveValue)?_.objectiveValue:1/0,C=(v===`Optimal`||v===`Feasible`||x)&&S<=1e-5,w=typeof _.objectiveBound==`number`&&Number.isFinite(_.objectiveBound)&&_.objectiveBound>1e-5,T=!C&&(v===`Infeasible`||v===`Optimal`&&S>1e-5||w),E=C?`Sat`:T?`Unsat`:`Unknown`;this.status=E,this.terminationStatus=a.signal?.aborted||y===`Interrupted`?`Interrupted`:y===`Optimal`||y===`Feasible`||y===`Infeasible`?E:y,this.hasPrimalSolution=C,this.objectiveValue=null,this.objectiveBound=void 0,this.relGap=void 0,this.mipGap=void 0,this.absGap=void 0,this.solution=null,this.values.clear();let D={};if(C&&_.values){for(let e of this.variables){let t=_.values[e.name];typeof t==`number`&&Number.isFinite(t)&&(e.value=t,this.values.set(e.name,t),s(D,e.name,t))}for(let e of this.boolVars){let t=l.boolVarToBinary.get(e),n=t?_.values[t.name]:_.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(D,e.name,t)}}}let O=new Set;if(T&&_.values)for(let[e,t]of p.entries()){let n=_.values[e.name];typeof n==`number`&&n>1e-5&&O.add(t)}return this.conflicts=T?Object.freeze(Array.from(O)):void 0,this.unsatCore=void 0,this.hasSolutionState=!0,{status:E,values:D,conflicts:this.conflicts,unsatCore:this.unsatCore,runTime:this.runTime}}validateSolution(e={}){return at(this,e)}link(e){if(e instanceof y||typeof e==`object`&&e&&`quadTerms`in e)throw Error(`Linking constraint cannot be a quadratic expression.`);if(!(e instanceof g)&&(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 gt({master:this,...e});return this.decomposition=t,t}async solveColumnGeneration(e){let t=await ut({master:this,...e});return this.decomposition=t,t}};return Me(),e.BoolExpr=s,e.BoolOp=l,e.BoolVar=c,e.Constraint=g,e.HiGHS=et,e.Highs=je,e.HighsSolver=$e,e.LinExpr=b,e.MockSolver=nt,e.Model=xt,e.QuadExpr=y,e.Var=P,e.and=u,e.buildIndicatorLinearization=Z,e.buildLpSymbolMaps=_e,e.deriveBigMForGe=ct,e.deriveBigMForLe=st,e.dot=S,e.expr=L,e.generateLpString=ve,e.getHighs=Ue,e.getHighsWasmUrl=Ve,e.getSolver=we,e.implies=p,e.isLpExportResult=he,e.linearizeModelForMip=lt,e.listAvailableSolvers=Te,e.maximize=ft,e.minimize=pt,e.normalizeSense=i,e.not=f,e.or=d,e.parseConstraint=de,e.parseExpr=le,e.registerSolver=Se,e.sanitizeIdentifier=ge,e.setDefaultSolver=Ce,e.setHighsWasmUrl=Be,e.solveBenders=gt,e.solveColumnGeneration=ut,e.solveLpWithHighs=We,e.sum=x,e.validateModelIntegrity=M,e.validateModelSolution=at,e.validateUserBigM=ot,e.xor=m,e})({});
|