@ohtaman/washi 0.9.0-rc.1 → 0.9.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/dist/browser/washi.js +365 -316
- package/dist/browser/washi.min.js +1 -1
- package/dist/lib/washi.js +365 -316
- package/dist/types/modeler/model.d.ts +7 -0
- package/dist/types/modeler/model.d.ts.map +1 -1
- package/docs/getting-started/ai-agents.md +9 -8
- package/docs/getting-started/coding-agents.md +38 -5
- package/docs/getting-started/runtimes.md +23 -6
- package/llms-full.txt +32 -14
- package/llms.txt +9 -8
- package/package.json +2 -2
- package/skills/washi/SKILL.md +20 -23
- package/skills/{washi-single-html/SKILL.md → washi/references/single-html.md} +3 -8
|
@@ -3,4 +3,4 @@ var Washi=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module
|
|
|
3
3
|
`,nameToVar:s,nameToConstraint:l}}var Ye=Symbol.for(`washi.solverRegistry`),Xe=Symbol.for(`washi.defaultSolverFactory`),Ze=globalThis;Ze[Ye]||(Ze[Ye]=new Map);var Qe=Ze[Ye];function $e(e,t){Qe.set(e.toLowerCase(),t)}function et(e){if(typeof e==`string`){let t=Qe.get(e.toLowerCase());if(!t)throw Error(`Solver '${e}' is not registered.`);Ze[Xe]=t}else Ze[Xe]=typeof e==`function`?e:()=>e}function tt(e,t){if(!e){let e=Ze[Xe]||Qe.get(`highs`);if(!e)throw Error(`No default solver available. Available solvers: ${nt().join(`, `)}`);return e(t)}if(typeof e==`string`){let n=e.toLowerCase(),r=Qe.get(n);if(!r)throw Error(n===`glpk`?`Solver 'glpk' not found. Available solvers: ${nt().join(`, `)}. Please import '@ohtaman/washi/solvers/glpk' before selecting this solver.`:n===`z3`?`Solver 'z3' not found. Available solvers: ${nt().join(`, `)}. Please import '@ohtaman/washi/solvers/z3' before selecting this solver.`:`Solver '${e}' not found. Available solvers: ${nt().join(`, `)}`);return r(t)}return e}function nt(){return Array.from(Qe.keys())}var rt=class{name;capabilities;options;constructor(e={}){this.name=e.name||`MockSolver`,this.capabilities=e.capabilities||{supportsMIP:!0,supportsQP:!0,supportsWarmStart:!0},this.options=e}async solve(e,t={},n={}){let r=Ge(t)?n:t,i={...this.options,...r},a=!!(i.values&&Object.keys(i.values).length>0||i.boolValues&&Object.keys(i.boolValues).length>0);if(i.signal?.aborted)return{status:`Unknown`,terminationStatus:`Interrupted`,hasPrimalSolution:!1,objectiveValue:null,values:{},runTime:0,raw:{mock:!0}};if(i.delayMs&&i.delayMs>0&&(await new Promise(e=>{let t=setTimeout(()=>{i.signal?.removeEventListener(`abort`,n),e()},i.delayMs),n=()=>{clearTimeout(t),e()};i.signal?.addEventListener(`abort`,n,{once:!0})}),i.signal?.aborted)){let e=!!(i.hasPrimalSolution??a);return{status:e?`Feasible`:`Unknown`,terminationStatus:`Interrupted`,hasPrimalSolution:e,objectiveValue:e?i.objectiveValue??0:null,...i.objectiveBound===void 0?{}:{objectiveBound:i.objectiveBound},...i.relativeGap===void 0?{}:{relativeGap:i.relativeGap},...i.absoluteGap===void 0?{}:{absoluteGap:i.absoluteGap},values:e&&i.values||{},...e&&i.boolValues!==void 0?{boolValues:i.boolValues}:{},runTime:.001,raw:{mock:!0}}}if(i.onProgress&&Array.isArray(i.progressEvents))for(let e of i.progressEvents){if(i.signal?.aborted)break;i.onProgress(e)}let o=i.status||`Optimal`,s=i.terminationStatus??o,c=i.hasPrimalSolution===void 0?o===`Optimal`||o===`Feasible`||o===`Sat`||(o===`TimeLimit`||o===`IterationLimit`||s===`Interrupted`)&&a:i.hasPrimalSolution;if(i.onProgress&&!Array.isArray(i.progressEvents)&&!i.signal?.aborted){let e=c?i.objectiveValue??0:void 0;i.onProgress({elapsedTime:.001,elapsedSeconds:.001,...typeof e==`number`&&Number.isFinite(e)?{objectiveValue:e}:{},...i.objectiveBound===void 0?{}:{objectiveBound:i.objectiveBound},...i.relativeGap===void 0?{}:{relativeGap:i.relativeGap},...i.absoluteGap===void 0?{}:{absoluteGap:i.absoluteGap}})}return i.signal?.aborted&&(s=`Interrupted`,c=i.hasPrimalSolution===void 0?a:i.hasPrimalSolution,o=c?`Feasible`:`Unknown`),{status:o,terminationStatus:s,hasPrimalSolution:c,objectiveValue:c?i.objectiveValue??0:null,...i.objectiveBound===void 0?{}:{objectiveBound:i.objectiveBound},...i.relativeGap===void 0?{}:{relativeGap:i.relativeGap},...i.absoluteGap===void 0?{}:{absoluteGap:i.absoluteGap},values:c&&i.values||{},...c&&i.boolValues!==void 0?{boolValues:i.boolValues}:{},reducedCosts:i.reducedCosts,duals:i.duals,slacks:i.slacks,runTime:.001,raw:{mock:!0}}}};function it(){$e(`mock`,e=>new rt(e))}it();var at=`v1.16.0:d1c2cb62726e24a7:2bd77844c41e9c91`,ot=`0.5.0:fc7ddaf3ae17fcc8:ea94cc1b794de550`,st={highs:null,pumpkin:null};function ct(e){return e===`highs`?at:ot}function lt(e){return Symbol.for(`washi.embeddedWasm.${e}.${ct(e)}`)}function ut(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&Object.prototype.toString.call(e)===`[object Uint8Array]`}function dt(e,t,n){if(!ut(t))throw Error(`[WaSHI] Invalid ${e} ${n}: expected Uint8Array.`);let r=new Uint8Array(t.byteLength);if(r.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength)),r.byteLength<8||r[0]!==0||r[1]!==97||r[2]!==115||r[3]!==109)throw Error(`[WaSHI] Invalid ${e} ${n}: expected at least 8 bytes starting with \\0asm magic header.`);return r}function ft(e){let t=ct(e),n=lt(e),r=globalThis[n];if(r===void 0)return null;if(typeof r!=`object`||!r)throw Error(`[WaSHI] Invalid embedded WASM pack registered for ${e} (${t}).`);let i=r;if(i.solver!==e||i.compatId!==t||typeof i.getBytes!=`function`)throw Error(`[WaSHI] Invalid embedded WASM pack registered for ${e} (${t}).`);return dt(e,i.getBytes(),`embedded inline WASM binary`)}function pt(e){let t=st[e];if(t!==null)return t;let n=ft(e),r=n===null?{kind:`url`}:{kind:`embedded`,bytes:n};return st[e]=r,r}function mt(e){return st[e]}var ht=typeof document<`u`?document.currentScript?.src:null,gt=ht?new URL(`.`,ht).href:null;function _t(e){if(!gt)throw Error(`[WaSHI] Load the browser IIFE using an external script src, or use the browser ESM build.`);return new URL(e,gt).href}function vt(){return _t(`solvers/highs.wasm`)}function yt(){throw Error(`This distribution is for browsers. Use the npm entry in Node.js.`)}function bt(e,t,n){if(n<=0||!t)return new Float64Array;let r=e.wasmMemory?e.wasmMemory.buffer:e.HEAPF64?e.HEAPF64.buffer:e.HEAP8?.buffer;if(r)return new Float64Array(r,t,n).slice();let i=new Float64Array(n);for(let r=0;r<n;r++)i[r]=e.getValue(t+r*8,`double`);return i}function xt(e){return{create:e.cwrap(`Highs_create`,`number`,[]),destroy:e.cwrap(`Highs_destroy`,`void`,[`number`]),clearModel:e.cwrap(`Highs_clearModel`,`number`,[`number`]),version:e.cwrap(`Highs_version`,`string`,[]),readModel:e.cwrap(`Highs_readModel`,`number`,[`number`,`string`]),run:e.cwrap(`Highs_run`,`number`,[`number`]),getNumCol:e.cwrap(`Highs_getNumCol`,`number`,[`number`]),getNumRow:e.cwrap(`Highs_getNumRow`,`number`,[`number`]),getNumNz:e.cwrap(`Highs_getNumNz`,`number`,[`number`]),getObjectiveValue:e.cwrap(`Highs_getObjectiveValue`,`number`,[`number`]),getModelStatus:e.cwrap(`Highs_getModelStatus`,`number`,[`number`]),getSolution:e.cwrap(`Highs_getSolution`,`number`,[`number`,`number`,`number`,`number`,`number`]),getColName:e.cwrap(`Highs_getColName`,`number`,[`number`,`number`,`number`]),getRowName:e.cwrap(`Highs_getRowName`,`number`,[`number`,`number`,`number`]),getColIntegrality:e.cwrap(`Highs_getColIntegrality`,`number`,[`number`,`number`,`number`]),changeObjectiveOffset:e.cwrap(`Highs_changeObjectiveOffset`,`number`,[`number`,`number`]),getObjectiveOffset:e.cwrap(`Highs_getObjectiveOffset`,`number`,[`number`,`number`]),setBoolOptionValue:e.cwrap(`Highs_setBoolOptionValue`,`number`,[`number`,`string`,`number`]),setIntOptionValue:e.cwrap(`Highs_setIntOptionValue`,`number`,[`number`,`string`,`number`]),setDoubleOptionValue:e.cwrap(`Highs_setDoubleOptionValue`,`number`,[`number`,`string`,`number`]),setStringOptionValue:e.cwrap(`Highs_setStringOptionValue`,`number`,[`number`,`string`,`string`]),setSolution:e.cwrap(`Highs_setSolution`,`number`,[`number`,`number`,`number`,`number`,`number`]),setSparseSolution:e.cwrap(`Highs_setSparseSolution`,`number`,[`number`,`number`,`number`,`number`]),getIntInfoValue:e.cwrap(`Highs_getIntInfoValue`,`number`,[`number`,`string`,`number`]),getDoubleInfoValue:e.cwrap(`Highs_getDoubleInfoValue`,`number`,[`number`,`string`,`number`]),getInt64InfoValue:e.cwrap(`Highs_getInt64InfoValue`,`number`,[`number`,`string`,`number`]),setCallback:e.cwrap(`Highs_setCallback`,`number`,[`number`,`number`,`number`]),startCallback:e.cwrap(`Highs_startCallback`,`number`,[`number`,`number`]),stopCallback:e.cwrap(`Highs_stopCallback`,`number`,[`number`,`number`])}}var St,Ct,wt,Tt,Et,Dt,Ot,kt=n((()=>{St=class extends Error{constructor(e){super(e),this.name=`HighsError`}},Ct=class extends St{constructor(e){super(e),this.name=`HighsUnsupportedOptionError`}},wt={0:`Not Set`,1:`Load error`,2:`Model error`,3:`Presolve error`,4:`Solve error`,5:`Postsolve error`,6:`Empty`,7:`Optimal`,8:`Infeasible`,9:`Primal infeasible or unbounded`,10:`Unbounded`,11:`Bound on objective reached`,12:`Target for objective reached`,13:`Time limit reached`,14:`Iteration limit reached`,15:`Unknown`,16:`Solution limit reached`,17:`Interrupted`,18:`Memory limit reached`},Tt={callbackType:{logging:0,simplexInterrupt:1,ipmInterrupt:2,mipSolution:3,mipImprovingSolution:4,mipLogging:5,mipInterrupt:6,mipGetCutPool:7,mipDefineLazyConstraints:8,mipUserSolution:9},solutionStatus:{none:0,infeasible:1,feasible:2},modelStatus:{notSet:0,loadError:1,modelError:2,presolveError:3,solveError:4,postsolveError:5,modelEmpty:6,optimal:7,infeasible:8,unboundedOrInfeasible:9,unbounded:10,objectiveBound:11,objectiveTarget:12,timeLimit:13,iterationLimit:14,unknown:15,solutionLimit:16,interrupt:17}},Et=0,Dt=class{highs;module;bindings;stringBuf;isDestroyed=!1;constructor(e,t,n){this.module=e,this.bindings=t,this.highs=n??t.create(),this.stringBuf=e._malloc(512)}changeObjectiveOffset(e){let t=this.bindings.changeObjectiveOffset(this.highs,e);if(t!==0)throw new St(`Highs_changeObjectiveOffset failed with status ${t}`)}getObjectiveOffset(){let e=this.module._malloc(8);try{return this.bindings.getObjectiveOffset(this.highs,e),this.module.getValue(e,`double`)}finally{this.module._free(e)}}options={set:(e,t)=>{let n=-1;if(typeof t==`boolean`?n=this.bindings.setBoolOptionValue(this.highs,e,+!!t):typeof t==`number`?Number.isInteger(t)?(n=this.bindings.setIntOptionValue(this.highs,e,t),n!==0&&(n=this.bindings.setDoubleOptionValue(this.highs,e,t))):n=this.bindings.setDoubleOptionValue(this.highs,e,t):typeof t==`string`&&(n=this.bindings.setStringOptionValue(this.highs,e,t)),n!==0)throw new Ct(`Option "${e}" with value ${JSON.stringify(t)} is not supported or invalid in HiGHS`)}};getDimensions(){return{numCols:this.bindings.getNumCol(this.highs),numRows:this.bindings.getNumRow(this.highs)}}getColIntegrality(e){let t=this.module._malloc(4);try{return this.bindings.getColIntegrality(this.highs,e,t),this.module.getValue(t,`i32`)}finally{this.module._free(t)}}getColName(e){return this.bindings.getColName(this.highs,e,this.stringBuf),this.module.UTF8ToString(this.stringBuf)}getRowName(e){return this.bindings.getRowName(this.highs,e,this.stringBuf),this.module.UTF8ToString(this.stringBuf)}setSolution(e){if(e.colValue&&Array.isArray(e.colValue)){let t=e.colValue.length,n=this.module._malloc(t*8);try{for(let r=0;r<t;r++)this.module.setValue(n+r*8,e.colValue[r],`double`);let r=this.bindings.setSolution(this.highs,n,0,0,0);if(r!==0)throw new St(`Highs_setSolution failed with status ${r}`)}finally{this.module._free(n)}return}if(e.indices&&e.values&&e.indices.length===e.values.length){let t=e.indices.length,n=this.module._malloc(t*4),r=this.module._malloc(t*8);try{for(let i=0;i<t;i++)this.module.setValue(n+i*4,e.indices[i],`i32`),this.module.setValue(r+i*8,e.values[i],`double`);let i=this.bindings.setSparseSolution(this.highs,t,n,r);if(i!==0)throw new St(`Highs_setSparseSolution failed with status ${i}`)}finally{this.module._free(n),this.module._free(r)}return}throw new St(`Invalid argument to setSolution (expected { colValue } or { indices, values })`)}run(e){let t=0,n=[];if(e){if(typeof this.module.addFunction!=`function`)throw new St(`HiGHS WebAssembly runtime does not support module.addFunction; progress and interrupt callbacks are unavailable.`);t=this.module.addFunction((t,n,r,i)=>{let a=e[t];if(!a)return;let o={};if(r){let e=this.module.getValue(r+8,`double`),t=this.module.getValue(r+16,`i32`),n=this.module.getValue(r+20,`i32`),i=this.module.getValue(r+24,`i32`),a=this.module.getValue(r+32,`double`),s=Number(this.module.getValue(r+40,`i32`)),c=Number(this.module.getValue(r+48,`i32`)),l=this.module.getValue(r+56,`double`),u=this.module.getValue(r+64,`double`),d=this.module.getValue(r+72,`double`),f=this.module.getValue(r+80,`i32`),p=this.module.getValue(r+84,`i32`),m;f&&p>0&&(m=bt(this.module,f,p)),o={running_time:e,simplex_iteration_count:t,ipm_iteration_count:n,pdlp_iteration_count:i,objective_function_value:a,mip_node_count:s,mip_total_lp_iterations:c,mip_primal_bound:l,mip_dual_bound:u,mip_gap:d,...m?{mip_solution:m}:{}}}let s=n?this.module.UTF8ToString(n):``;a({data:o,message:s,interrupt:()=>{i&&this.module.setValue(i,1,`i32`)}})},`vipppp`),this.bindings.setCallback(this.highs,t,0);for(let t of Object.keys(e)){let e=Number(t);this.bindings.startCallback(this.highs,e),n.push(e)}}try{return this.bindings.run(this.highs)}finally{if(t){for(let e of n)try{this.bindings.stopCallback(this.highs,e)}catch{}try{this.module.removeFunction(t)}catch{}}}}getModelStatus(){return this.bindings.getModelStatus(this.highs)}info={get:e=>{let t=this.module._malloc(8);try{if(this.bindings.getDoubleInfoValue(this.highs,e,t)===0)return this.module.getValue(t,`double`)}finally{this.module._free(t)}let n=this.module._malloc(4);try{if(this.bindings.getIntInfoValue(this.highs,e,n)===0)return this.module.getValue(n,`i32`)}finally{this.module._free(n)}throw new St(`Info item "${e}" not available or unknown in HiGHS`)}};getSolution(){let e=this.getDimensions(),t=e.numCols>0?this.module._malloc(e.numCols*8):0,n=e.numCols>0?this.module._malloc(e.numCols*8):0,r=e.numRows>0?this.module._malloc(e.numRows*8):0,i=e.numRows>0?this.module._malloc(e.numRows*8):0;try{return this.bindings.getSolution(this.highs,t,n,r,i),{colValue:bt(this.module,t,e.numCols),colDual:bt(this.module,n,e.numCols),rowValue:bt(this.module,r,e.numRows),rowDual:bt(this.module,i,e.numRows)}}finally{t&&this.module._free(t),n&&this.module._free(n),r&&this.module._free(r),i&&this.module._free(i)}}getObjectiveValue(){return this.bindings.getObjectiveValue(this.highs)}destroy(){if(!this.isDestroyed){this.isDestroyed=!0;try{this.module._free(this.stringBuf)}catch{}try{this.bindings.destroy(this.highs)}catch{}}}[Symbol.dispose](){this.destroy()}},Ot=class{module;bindings;constants=Tt;errors={HighsError:St,HighsUnsupportedOptionError:Ct};constructor(e){this.module=e,this.bindings=xt(e)}withModel(e,t){let n=this.bindings.create(),r=new Dt(this.module,this.bindings,n),i=`/model_${++Et}.${e.format}`;if(!this.module.FS)throw new St(`Emscripten FS is not initialized on this HiGHS module instance`);let a=this.module.FS;try{a.writeFile(i,e.data);let o=this.bindings.readModel(n,i);if(o!==0)throw new St(`Failed to load ${e.format.toUpperCase()} model into HiGHS (status ${o})`);return t(r)}finally{try{a.unlink(i)}catch{}r.destroy()}}solve(e,t={}){return this.withModel({format:`lp`,data:e},e=>{for(let[n,r]of Object.entries(t))e.options.set(n,r);e.run();let n=e.getModelStatus(),r=e.getDimensions(),i=e.getSolution(),a={};for(let t=0;t<r.numCols;t++){let n=e.getColName(t);a[n]={Index:t,Name:n,Primal:i.colValue[t],Dual:i.colDual[t]}}return{Status:wt[n]??`Unknown`,StatusCode:n,ObjectiveValue:e.getObjectiveValue(),Columns:a}})}}})),At,jt=n((()=>{At=(()=>{var e={}.url;return(async function(t={}){var n=t,r,i;n.ready=new Promise((e,t)=>{r=e,i=t});var a=Object.assign({},n),o=`./this.program`,s=(e,t)=>{throw t},c=typeof window==`object`,l=typeof importScripts==`function`,u=``;function d(e){return n.locateFile?n.locateFile(e,u):u+e}var f,p,m;(c||l)&&(l?u=self.location.href:typeof document<`u`&&document.currentScript&&(u=document.currentScript.src),e&&(u=e),u=u.indexOf(`blob:`)===0?``:u.substr(0,u.replace(/[?#].*/,``).lastIndexOf(`/`)+1),f=e=>{var t=new XMLHttpRequest;return t.open(`GET`,e,!1),t.send(null),t.responseText},l&&(m=e=>{var t=new XMLHttpRequest;return t.open(`GET`,e,!1),t.responseType=`arraybuffer`,t.send(null),new Uint8Array(t.response)}),p=(e,t,n)=>{var r=new XMLHttpRequest;r.open(`GET`,e,!0),r.responseType=`arraybuffer`,r.onload=()=>{if(r.status==200||r.status==0&&r.response){t(r.response);return}n()},r.onerror=n,r.send(null)});var h=n.print||console.log.bind(console),g=n.printErr||console.error.bind(console);Object.assign(n,a),a=null,n.arguments&&n.arguments,n.thisProgram&&(o=n.thisProgram),n.quit&&(s=n.quit);var _;n.wasmBinary&&(_=n.wasmBinary),typeof WebAssembly!=`object`&&F(`no native wasm support detected`);var v,y=!1;function b(e,t){e||F(t)}var x,S,C,w,T,E,D;function ee(){var e=v.buffer;n.HEAP8=x=new Int8Array(e),n.HEAP16=C=new Int16Array(e),n.HEAPU8=S=new Uint8Array(e),n.HEAPU16=new Uint16Array(e),n.HEAP32=w=new Int32Array(e),n.HEAPU32=T=new Uint32Array(e),n.HEAPF32=E=new Float32Array(e),n.HEAPF64=D=new Float64Array(e)}var O=[],k=[],A=[],te=!1;function ne(){if(n.preRun)for(typeof n.preRun==`function`&&(n.preRun=[n.preRun]);n.preRun.length;)j(n.preRun.shift());_e(O)}function re(){te=!0,!n.noFSInit&&!K.init.initialized&&K.init(),K.ignorePermissions=!1,W.init(),_e(k)}function ie(){if(n.postRun)for(typeof n.postRun==`function`&&(n.postRun=[n.postRun]);n.postRun.length;)ae(n.postRun.shift());_e(A)}function j(e){O.unshift(e)}function M(e){k.unshift(e)}function ae(e){A.unshift(e)}var oe=0,se=null,N=null;function P(e){return e}function ce(e){oe++,n.monitorRunDependencies&&n.monitorRunDependencies(oe)}function le(e){if(oe--,n.monitorRunDependencies&&n.monitorRunDependencies(oe),oe==0&&(se!==null&&(clearInterval(se),se=null),N)){var t=N;N=null,t()}}function F(e){n.onAbort&&n.onAbort(e),e=`Aborted(`+e+`)`,g(e),y=!0,e+=`. Build with -sASSERTIONS for more info.`,te&&wn();var t=new WebAssembly.RuntimeError(e);throw i(t),t}var ue=`data:application/octet-stream;base64,`,I=e=>e.startsWith(ue),de=e=>e.startsWith(`file://`),L;n.locateFile?(L=`highs.wasm`,I(L)||(L=d(L))):L=new URL(`highs.wasm`,``+{}.url).href;function fe(e){if(e==L&&_)return new Uint8Array(_);if(m)return m(e);throw`both async and sync fetching of the wasm failed`}function pe(e){if(!_&&(c||l)){if(typeof fetch==`function`&&!de(e))return fetch(e,{credentials:`same-origin`}).then(t=>{if(!t.ok)throw`failed to load wasm binary file at '`+e+`'`;return t.arrayBuffer()}).catch(()=>fe(e));if(p)return new Promise((t,n)=>{p(e,e=>t(new Uint8Array(e)),n)})}return Promise.resolve().then(()=>fe(e))}function me(e,t,n){return pe(e).then(e=>WebAssembly.instantiate(e,t)).then(e=>e).then(n,e=>{g(`failed to asynchronously prepare wasm: ${e}`),F(e)})}function R(e,t,n,r){return!e&&typeof WebAssembly.instantiateStreaming==`function`&&!I(t)&&!de(t)&&typeof fetch==`function`?fetch(t,{credentials:`same-origin`}).then(e=>WebAssembly.instantiateStreaming(e,n).then(r,function(e){return g(`wasm streaming compile failed: ${e}`),g(`falling back to ArrayBuffer instantiation`),me(t,n,r)})):me(t,n,r)}function he(){var e={a:Gt};function t(e,t){return Y=e.exports,v=Y.s,n.wasmMemory=v,ee(),Mt=Y.ca,M(Y.t),le(`wasm-instantiate`),Y}ce(`wasm-instantiate`);function r(e){t(e.instance)}if(n.instantiateWasm)try{return n.instantiateWasm(e,t)}catch(e){g(`Module.instantiateWasm callback failed with error: ${e}`),i(e)}return R(_,L,e,r).catch(i),{}}var z,B;function ge(e){this.name=`ExitStatus`,this.message=`Program terminated with exit(${e})`,this.status=e}var _e=e=>{for(;e.length>0;)e.shift()(n)};function ve(e,t=`i8`){switch(t.endsWith(`*`)&&(t=`*`),t){case`i1`:return x[e>>0];case`i8`:return x[e>>0];case`i16`:return C[e>>1];case`i32`:return w[e>>2];case`i64`:F(`to do getValue(i64) use WASM_BIGINT`);case`float`:return E[e>>2];case`double`:return D[e>>3];case`*`:return T[e>>2];default:F(`invalid type for getValue: ${t}`)}}var ye=n.noExitRuntime||!0;function be(e,t,n=`i8`){switch(n.endsWith(`*`)&&(n=`*`),n){case`i1`:x[e>>0]=t;break;case`i8`:x[e>>0]=t;break;case`i16`:C[e>>1]=t;break;case`i32`:w[e>>2]=t;break;case`i64`:F(`to do setValue(i64) use WASM_BIGINT`);case`float`:E[e>>2]=t;break;case`double`:D[e>>3]=t;break;case`*`:T[e>>2]=t;break;default:F(`invalid type for setValue: ${n}`)}}var xe=e=>(w[xn()>>2]=e,e),V={isAbs:e=>e.charAt(0)===`/`,splitPath:e=>/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/.exec(e).slice(1),normalizeArray:(e,t)=>{for(var n=0,r=e.length-1;r>=0;r--){var i=e[r];i===`.`?e.splice(r,1):i===`..`?(e.splice(r,1),n++):n&&(e.splice(r,1),n--)}if(t)for(;n;n--)e.unshift(`..`);return e},normalize:e=>{var t=V.isAbs(e),n=e.substr(-1)===`/`;return e=V.normalizeArray(e.split(`/`).filter(e=>!!e),!t).join(`/`),!e&&!t&&(e=`.`),e&&n&&(e+=`/`),(t?`/`:``)+e},dirname:e=>{var t=V.splitPath(e),n=t[0],r=t[1];return!n&&!r?`.`:(r&&=r.substr(0,r.length-1),n+r)},basename:e=>{if(e===`/`)return`/`;e=V.normalize(e),e=e.replace(/\/$/,``);var t=e.lastIndexOf(`/`);return t===-1?e:e.substr(t+1)},join:function(){var e=Array.prototype.slice.call(arguments);return V.normalize(e.join(`/`))},join2:(e,t)=>V.normalize(e+`/`+t)},Se=()=>{if(typeof crypto==`object`&&typeof crypto.getRandomValues==`function`)return e=>crypto.getRandomValues(e);F(`initRandomDevice`)},Ce=e=>(Ce=Se())(e),H={resolve:function(){for(var e=``,t=!1,n=arguments.length-1;n>=-1&&!t;n--){var r=n>=0?arguments[n]:K.cwd();if(typeof r!=`string`)throw TypeError(`Arguments to path.resolve must be strings`);if(!r)return``;e=r+`/`+e,t=V.isAbs(r)}return e=V.normalizeArray(e.split(`/`).filter(e=>!!e),!t).join(`/`),(t?`/`:``)+e||`.`},relative:(e,t)=>{e=H.resolve(e).substr(1),t=H.resolve(t).substr(1);function n(e){for(var t=0;t<e.length&&e[t]===``;t++);for(var n=e.length-1;n>=0&&e[n]===``;n--);return t>n?[]:e.slice(t,n-t+1)}for(var r=n(e.split(`/`)),i=n(t.split(`/`)),a=Math.min(r.length,i.length),o=a,s=0;s<a;s++)if(r[s]!==i[s]){o=s;break}for(var c=[],s=o;s<r.length;s++)c.push(`..`);return c=c.concat(i.slice(o)),c.join(`/`)}},U=typeof TextDecoder<`u`?new TextDecoder(`utf8`):void 0,we=(e,t,n)=>{for(var r=t+n,i=t;e[i]&&!(i>=r);)++i;if(i-t>16&&e.buffer&&U)return U.decode(e.subarray(t,i));for(var a=``;t<i;){var o=e[t++];if(!(o&128)){a+=String.fromCharCode(o);continue}var s=e[t++]&63;if((o&224)==192){a+=String.fromCharCode((o&31)<<6|s);continue}var c=e[t++]&63;if(o=(o&240)==224?(o&15)<<12|s<<6|c:(o&7)<<18|s<<12|c<<6|e[t++]&63,o<65536)a+=String.fromCharCode(o);else{var l=o-65536;a+=String.fromCharCode(55296|l>>10,56320|l&1023)}}return a},Te=[],Ee=e=>{for(var t=0,n=0;n<e.length;++n){var r=e.charCodeAt(n);r<=127?t++:r<=2047?t+=2:r>=55296&&r<=57343?(t+=4,++n):t+=3}return t},De=(e,t,n,r)=>{if(!(r>0))return 0;for(var i=n,a=n+r-1,o=0;o<e.length;++o){var s=e.charCodeAt(o);if(s>=55296&&s<=57343){var c=e.charCodeAt(++o);s=65536+((s&1023)<<10)|c&1023}if(s<=127){if(n>=a)break;t[n++]=s}else if(s<=2047){if(n+1>=a)break;t[n++]=192|s>>6,t[n++]=128|s&63}else if(s<=65535){if(n+2>=a)break;t[n++]=224|s>>12,t[n++]=128|s>>6&63,t[n++]=128|s&63}else{if(n+3>=a)break;t[n++]=240|s>>18,t[n++]=128|s>>12&63,t[n++]=128|s>>6&63,t[n++]=128|s&63}}return t[n]=0,n-i};function Oe(e,t,n){var r=n>0?n:Ee(e)+1,i=Array(r),a=De(e,i,0,i.length);return t&&(i.length=a),i}var ke=()=>{if(!Te.length){var e=null;if(typeof window<`u`&&typeof window.prompt==`function`?(e=window.prompt(`Input: `),e!==null&&(e+=`
|
|
4
4
|
`)):typeof readline==`function`&&(e=readline(),e!==null&&(e+=`
|
|
5
5
|
`)),!e)return null;Te=Oe(e,!0)}return Te.shift()},W={ttys:[],init(){},shutdown(){},register(e,t){W.ttys[e]={input:[],output:[],ops:t},K.registerDevice(e,W.stream_ops)},stream_ops:{open(e){var t=W.ttys[e.node.rdev];if(!t)throw new K.ErrnoError(43);e.tty=t,e.seekable=!1},close(e){e.tty.ops.fsync(e.tty)},fsync(e){e.tty.ops.fsync(e.tty)},read(e,t,n,r,i){if(!e.tty||!e.tty.ops.get_char)throw new K.ErrnoError(60);for(var a=0,o=0;o<r;o++){var s;try{s=e.tty.ops.get_char(e.tty)}catch{throw new K.ErrnoError(29)}if(s===void 0&&a===0)throw new K.ErrnoError(6);if(s==null)break;a++,t[n+o]=s}return a&&(e.node.timestamp=Date.now()),a},write(e,t,n,r,i){if(!e.tty||!e.tty.ops.put_char)throw new K.ErrnoError(60);try{for(var a=0;a<r;a++)e.tty.ops.put_char(e.tty,t[n+a])}catch{throw new K.ErrnoError(29)}return r&&(e.node.timestamp=Date.now()),a}},default_tty_ops:{get_char(e){return ke()},put_char(e,t){t===null||t===10?(h(we(e.output,0)),e.output=[]):t!=0&&e.output.push(t)},fsync(e){e.output&&e.output.length>0&&(h(we(e.output,0)),e.output=[])},ioctl_tcgets(e){return{c_iflag:25856,c_oflag:5,c_cflag:191,c_lflag:35387,c_cc:[3,28,127,21,4,0,1,0,17,19,26,0,18,15,23,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},ioctl_tcsets(e,t,n){return 0},ioctl_tiocgwinsz(e){return[24,80]}},default_tty1_ops:{put_char(e,t){t===null||t===10?(g(we(e.output,0)),e.output=[]):t!=0&&e.output.push(t)},fsync(e){e.output&&e.output.length>0&&(g(we(e.output,0)),e.output=[])}}},Ae=e=>{F()},G={ops_table:null,mount(e){return G.createNode(null,`/`,16895,0)},createNode(e,t,n,r){if(K.isBlkdev(n)||K.isFIFO(n))throw new K.ErrnoError(63);G.ops_table||={dir:{node:{getattr:G.node_ops.getattr,setattr:G.node_ops.setattr,lookup:G.node_ops.lookup,mknod:G.node_ops.mknod,rename:G.node_ops.rename,unlink:G.node_ops.unlink,rmdir:G.node_ops.rmdir,readdir:G.node_ops.readdir,symlink:G.node_ops.symlink},stream:{llseek:G.stream_ops.llseek}},file:{node:{getattr:G.node_ops.getattr,setattr:G.node_ops.setattr},stream:{llseek:G.stream_ops.llseek,read:G.stream_ops.read,write:G.stream_ops.write,allocate:G.stream_ops.allocate,mmap:G.stream_ops.mmap,msync:G.stream_ops.msync}},link:{node:{getattr:G.node_ops.getattr,setattr:G.node_ops.setattr,readlink:G.node_ops.readlink},stream:{}},chrdev:{node:{getattr:G.node_ops.getattr,setattr:G.node_ops.setattr},stream:K.chrdev_stream_ops}};var i=K.createNode(e,t,n,r);return K.isDir(i.mode)?(i.node_ops=G.ops_table.dir.node,i.stream_ops=G.ops_table.dir.stream,i.contents={}):K.isFile(i.mode)?(i.node_ops=G.ops_table.file.node,i.stream_ops=G.ops_table.file.stream,i.usedBytes=0,i.contents=null):K.isLink(i.mode)?(i.node_ops=G.ops_table.link.node,i.stream_ops=G.ops_table.link.stream):K.isChrdev(i.mode)&&(i.node_ops=G.ops_table.chrdev.node,i.stream_ops=G.ops_table.chrdev.stream),i.timestamp=Date.now(),e&&(e.contents[t]=i,e.timestamp=i.timestamp),i},getFileDataAsTypedArray(e){return e.contents?e.contents.subarray?e.contents.subarray(0,e.usedBytes):new Uint8Array(e.contents):new Uint8Array},expandFileStorage(e,t){var n=e.contents?e.contents.length:0;if(!(n>=t)){t=Math.max(t,n*(n<1048576?2:1.125)>>>0),n!=0&&(t=Math.max(t,256));var r=e.contents;e.contents=new Uint8Array(t),e.usedBytes>0&&e.contents.set(r.subarray(0,e.usedBytes),0)}},resizeFileStorage(e,t){if(e.usedBytes!=t){if(t==0)e.contents=null,e.usedBytes=0;else{var n=e.contents;e.contents=new Uint8Array(t),n&&e.contents.set(n.subarray(0,Math.min(t,e.usedBytes))),e.usedBytes=t}}},node_ops:{getattr(e){var t={};return t.dev=K.isChrdev(e.mode)?e.id:1,t.ino=e.id,t.mode=e.mode,t.nlink=1,t.uid=0,t.gid=0,t.rdev=e.rdev,t.size=K.isDir(e.mode)?4096:K.isFile(e.mode)?e.usedBytes:K.isLink(e.mode)?e.link.length:0,t.atime=new Date(e.timestamp),t.mtime=new Date(e.timestamp),t.ctime=new Date(e.timestamp),t.blksize=4096,t.blocks=Math.ceil(t.size/t.blksize),t},setattr(e,t){t.mode!==void 0&&(e.mode=t.mode),t.timestamp!==void 0&&(e.timestamp=t.timestamp),t.size!==void 0&&G.resizeFileStorage(e,t.size)},lookup(e,t){throw K.genericErrors[44]},mknod(e,t,n,r){return G.createNode(e,t,n,r)},rename(e,t,n){if(K.isDir(e.mode)){var r;try{r=K.lookupNode(t,n)}catch{}if(r)for(var i in r.contents)throw new K.ErrnoError(55)}delete e.parent.contents[e.name],e.parent.timestamp=Date.now(),e.name=n,t.contents[n]=e,t.timestamp=e.parent.timestamp,e.parent=t},unlink(e,t){delete e.contents[t],e.timestamp=Date.now()},rmdir(e,t){for(var n in K.lookupNode(e,t).contents)throw new K.ErrnoError(55);delete e.contents[t],e.timestamp=Date.now()},readdir(e){var t=[`.`,`..`];for(var n in e.contents)e.contents.hasOwnProperty(n)&&t.push(n);return t},symlink(e,t,n){var r=G.createNode(e,t,41471,0);return r.link=n,r},readlink(e){if(!K.isLink(e.mode))throw new K.ErrnoError(28);return e.link}},stream_ops:{read(e,t,n,r,i){var a=e.node.contents;if(i>=e.node.usedBytes)return 0;var o=Math.min(e.node.usedBytes-i,r);if(o>8&&a.subarray)t.set(a.subarray(i,i+o),n);else for(var s=0;s<o;s++)t[n+s]=a[i+s];return o},write(e,t,n,r,i,a){if(t.buffer===x.buffer&&(a=!1),!r)return 0;var o=e.node;if(o.timestamp=Date.now(),t.subarray&&(!o.contents||o.contents.subarray)){if(a)return o.contents=t.subarray(n,n+r),o.usedBytes=r,r;if(o.usedBytes===0&&i===0)return o.contents=t.slice(n,n+r),o.usedBytes=r,r;if(i+r<=o.usedBytes)return o.contents.set(t.subarray(n,n+r),i),r}if(G.expandFileStorage(o,i+r),o.contents.subarray&&t.subarray)o.contents.set(t.subarray(n,n+r),i);else for(var s=0;s<r;s++)o.contents[i+s]=t[n+s];return o.usedBytes=Math.max(o.usedBytes,i+r),r},llseek(e,t,n){var r=t;if(n===1?r+=e.position:n===2&&K.isFile(e.node.mode)&&(r+=e.node.usedBytes),r<0)throw new K.ErrnoError(28);return r},allocate(e,t,n){G.expandFileStorage(e.node,t+n),e.node.usedBytes=Math.max(e.node.usedBytes,t+n)},mmap(e,t,n,r,i){if(!K.isFile(e.node.mode))throw new K.ErrnoError(43);var a,o,s=e.node.contents;if(!(i&2)&&s.buffer===x.buffer)o=!1,a=s.byteOffset;else{if((n>0||n+t<s.length)&&(s=s.subarray?s.subarray(n,n+t):Array.prototype.slice.call(s,n,n+t)),o=!0,a=Ae(t),!a)throw new K.ErrnoError(48);x.set(s,a)}return{ptr:a,allocated:o}},msync(e,t,n,r,i){return G.stream_ops.write(e,t,0,r,n,!1),0}}},je=(e,t,n,r)=>{var i=r?``:P(`al ${e}`);p(e,n=>{b(n,`Loading data file "${e}" failed (no arrayBuffer).`),t(new Uint8Array(n)),i&&le(i)},t=>{if(n)n();else throw`Loading data file "${e}" failed.`}),i&&ce(i)},Me=(e,t,n,r,i,a)=>{K.createDataFile(e,t,n,r,i,a)},Ne=n.preloadPlugins||[],Pe=(e,t,n,r)=>{typeof Browser<`u`&&Browser.init();var i=!1;return Ne.forEach(a=>{i||a.canHandle(t)&&(a.handle(e,t,n,r),i=!0)}),i},Fe=(e,t,n,r,i,a,o,s,c,l)=>{var u=t?H.resolve(V.join2(e,t)):e,d=P(`cp ${u}`);function f(n){function f(n){l&&l(),s||Me(e,t,n,r,i,c),a&&a(),le(d)}Pe(n,u,f,()=>{o&&o(),le(d)})||f(n)}ce(d),typeof n==`string`?je(n,e=>f(e),o):f(n)},Ie=e=>{var t={r:0,"r+":2,w:577,"w+":578,a:1089,"a+":1090}[e];if(t===void 0)throw Error(`Unknown file open mode: ${e}`);return t},Le=(e,t)=>{var n=0;return e&&(n|=365),t&&(n|=146),n},K={root:null,mounts:[],devices:{},streams:[],nextInode:1,nameTable:null,currentPath:`/`,initialized:!1,ignorePermissions:!0,ErrnoError:null,genericErrors:{},filesystems:null,syncFSRequests:0,lookupPath(e,t={}){if(e=H.resolve(e),!e)return{path:``,node:null};if(t=Object.assign({follow_mount:!0,recurse_count:0},t),t.recurse_count>8)throw new K.ErrnoError(32);for(var n=e.split(`/`).filter(e=>!!e),r=K.root,i=`/`,a=0;a<n.length;a++){var o=a===n.length-1;if(o&&t.parent)break;if(r=K.lookupNode(r,n[a]),i=V.join2(i,n[a]),K.isMountpoint(r)&&(!o||o&&t.follow_mount)&&(r=r.mounted.root),!o||t.follow)for(var s=0;K.isLink(r.mode);){var c=K.readlink(i);if(i=H.resolve(V.dirname(i),c),r=K.lookupPath(i,{recurse_count:t.recurse_count+1}).node,s++>40)throw new K.ErrnoError(32)}}return{path:i,node:r}},getPath(e){for(var t;;){if(K.isRoot(e)){var n=e.mount.mountpoint;return t?n[n.length-1]===`/`?n+t:`${n}/${t}`:n}t=t?`${e.name}/${t}`:e.name,e=e.parent}},hashName(e,t){for(var n=0,r=0;r<t.length;r++)n=(n<<5)-n+t.charCodeAt(r)|0;return(e+n>>>0)%K.nameTable.length},hashAddNode(e){var t=K.hashName(e.parent.id,e.name);e.name_next=K.nameTable[t],K.nameTable[t]=e},hashRemoveNode(e){var t=K.hashName(e.parent.id,e.name);if(K.nameTable[t]===e)K.nameTable[t]=e.name_next;else for(var n=K.nameTable[t];n;){if(n.name_next===e){n.name_next=e.name_next;break}n=n.name_next}},lookupNode(e,t){var n=K.mayLookup(e);if(n)throw new K.ErrnoError(n,e);for(var r=K.hashName(e.id,t),i=K.nameTable[r];i;i=i.name_next){var a=i.name;if(i.parent.id===e.id&&a===t)return i}return K.lookup(e,t)},createNode(e,t,n,r){var i=new K.FSNode(e,t,n,r);return K.hashAddNode(i),i},destroyNode(e){K.hashRemoveNode(e)},isRoot(e){return e===e.parent},isMountpoint(e){return!!e.mounted},isFile(e){return(e&61440)==32768},isDir(e){return(e&61440)==16384},isLink(e){return(e&61440)==40960},isChrdev(e){return(e&61440)==8192},isBlkdev(e){return(e&61440)==24576},isFIFO(e){return(e&61440)==4096},isSocket(e){return(e&49152)==49152},flagsToPermissionString(e){var t=[`r`,`w`,`rw`][e&3];return e&512&&(t+=`w`),t},nodePermissions(e,t){return K.ignorePermissions?0:t.includes(`r`)&&!(e.mode&292)||t.includes(`w`)&&!(e.mode&146)||t.includes(`x`)&&!(e.mode&73)?2:0},mayLookup(e){return K.nodePermissions(e,`x`)||(e.node_ops.lookup?0:2)},mayCreate(e,t){try{return K.lookupNode(e,t),20}catch{}return K.nodePermissions(e,`wx`)},mayDelete(e,t,n){var r;try{r=K.lookupNode(e,t)}catch(e){return e.errno}var i=K.nodePermissions(e,`wx`);if(i)return i;if(n){if(!K.isDir(r.mode))return 54;if(K.isRoot(r)||K.getPath(r)===K.cwd())return 10}else if(K.isDir(r.mode))return 31;return 0},mayOpen(e,t){return e?K.isLink(e.mode)?32:K.isDir(e.mode)&&(K.flagsToPermissionString(t)!==`r`||t&512)?31:K.nodePermissions(e,K.flagsToPermissionString(t)):44},MAX_OPEN_FDS:4096,nextfd(){for(var e=0;e<=K.MAX_OPEN_FDS;e++)if(!K.streams[e])return e;throw new K.ErrnoError(33)},getStreamChecked(e){var t=K.getStream(e);if(!t)throw new K.ErrnoError(8);return t},getStream:e=>K.streams[e],createStream(e,t=-1){return K.FSStream||(K.FSStream=function(){this.shared={}},K.FSStream.prototype={},Object.defineProperties(K.FSStream.prototype,{object:{get(){return this.node},set(e){this.node=e}},isRead:{get(){return(this.flags&2097155)!=1}},isWrite:{get(){return!!(this.flags&2097155)}},isAppend:{get(){return this.flags&1024}},flags:{get(){return this.shared.flags},set(e){this.shared.flags=e}},position:{get(){return this.shared.position},set(e){this.shared.position=e}}})),e=Object.assign(new K.FSStream,e),t==-1&&(t=K.nextfd()),e.fd=t,K.streams[t]=e,e},closeStream(e){K.streams[e]=null},chrdev_stream_ops:{open(e){e.stream_ops=K.getDevice(e.node.rdev).stream_ops,e.stream_ops.open&&e.stream_ops.open(e)},llseek(){throw new K.ErrnoError(70)}},major:e=>e>>8,minor:e=>e&255,makedev:(e,t)=>e<<8|t,registerDevice(e,t){K.devices[e]={stream_ops:t}},getDevice:e=>K.devices[e],getMounts(e){for(var t=[],n=[e];n.length;){var r=n.pop();t.push(r),n.push.apply(n,r.mounts)}return t},syncfs(e,t){typeof e==`function`&&(t=e,e=!1),K.syncFSRequests++,K.syncFSRequests>1&&g(`warning: ${K.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`);var n=K.getMounts(K.root.mount),r=0;function i(e){return K.syncFSRequests--,t(e)}function a(e){if(e)return a.errored?void 0:(a.errored=!0,i(e));++r>=n.length&&i(null)}n.forEach(t=>{if(!t.type.syncfs)return a(null);t.type.syncfs(t,e,a)})},mount(e,t,n){var r=n===`/`,i=!n,a;if(r&&K.root)throw new K.ErrnoError(10);if(!r&&!i){var o=K.lookupPath(n,{follow_mount:!1});if(n=o.path,a=o.node,K.isMountpoint(a))throw new K.ErrnoError(10);if(!K.isDir(a.mode))throw new K.ErrnoError(54)}var s={type:e,opts:t,mountpoint:n,mounts:[]},c=e.mount(s);return c.mount=s,s.root=c,r?K.root=c:a&&(a.mounted=s,a.mount&&a.mount.mounts.push(s)),c},unmount(e){var t=K.lookupPath(e,{follow_mount:!1});if(!K.isMountpoint(t.node))throw new K.ErrnoError(28);var n=t.node,r=n.mounted,i=K.getMounts(r);Object.keys(K.nameTable).forEach(e=>{for(var t=K.nameTable[e];t;){var n=t.name_next;i.includes(t.mount)&&K.destroyNode(t),t=n}}),n.mounted=null;var a=n.mount.mounts.indexOf(r);n.mount.mounts.splice(a,1)},lookup(e,t){return e.node_ops.lookup(e,t)},mknod(e,t,n){var r=K.lookupPath(e,{parent:!0}).node,i=V.basename(e);if(!i||i===`.`||i===`..`)throw new K.ErrnoError(28);var a=K.mayCreate(r,i);if(a)throw new K.ErrnoError(a);if(!r.node_ops.mknod)throw new K.ErrnoError(63);return r.node_ops.mknod(r,i,t,n)},create(e,t){return t=t===void 0?438:t,t&=4095,t|=32768,K.mknod(e,t,0)},mkdir(e,t){return t=t===void 0?511:t,t&=1023,t|=16384,K.mknod(e,t,0)},mkdirTree(e,t){for(var n=e.split(`/`),r=``,i=0;i<n.length;++i)if(n[i]){r+=`/`+n[i];try{K.mkdir(r,t)}catch(e){if(e.errno!=20)throw e}}},mkdev(e,t,n){return n===void 0&&(n=t,t=438),t|=8192,K.mknod(e,t,n)},symlink(e,t){if(!H.resolve(e))throw new K.ErrnoError(44);var n=K.lookupPath(t,{parent:!0}).node;if(!n)throw new K.ErrnoError(44);var r=V.basename(t),i=K.mayCreate(n,r);if(i)throw new K.ErrnoError(i);if(!n.node_ops.symlink)throw new K.ErrnoError(63);return n.node_ops.symlink(n,r,e)},rename(e,t){var n=V.dirname(e),r=V.dirname(t),i=V.basename(e),a=V.basename(t),o=K.lookupPath(e,{parent:!0}),s=o.node,c;if(o=K.lookupPath(t,{parent:!0}),c=o.node,!s||!c)throw new K.ErrnoError(44);if(s.mount!==c.mount)throw new K.ErrnoError(75);var l=K.lookupNode(s,i),u=H.relative(e,r);if(u.charAt(0)!==`.`)throw new K.ErrnoError(28);if(u=H.relative(t,n),u.charAt(0)!==`.`)throw new K.ErrnoError(55);var d;try{d=K.lookupNode(c,a)}catch{}if(l!==d){var f=K.isDir(l.mode),p=K.mayDelete(s,i,f);if(p||(p=d?K.mayDelete(c,a,f):K.mayCreate(c,a),p))throw new K.ErrnoError(p);if(!s.node_ops.rename)throw new K.ErrnoError(63);if(K.isMountpoint(l)||d&&K.isMountpoint(d))throw new K.ErrnoError(10);if(c!==s&&(p=K.nodePermissions(s,`w`),p))throw new K.ErrnoError(p);K.hashRemoveNode(l);try{s.node_ops.rename(l,c,a)}catch(e){throw e}finally{K.hashAddNode(l)}}},rmdir(e){var t=K.lookupPath(e,{parent:!0}).node,n=V.basename(e),r=K.lookupNode(t,n),i=K.mayDelete(t,n,!0);if(i)throw new K.ErrnoError(i);if(!t.node_ops.rmdir)throw new K.ErrnoError(63);if(K.isMountpoint(r))throw new K.ErrnoError(10);t.node_ops.rmdir(t,n),K.destroyNode(r)},readdir(e){var t=K.lookupPath(e,{follow:!0}).node;if(!t.node_ops.readdir)throw new K.ErrnoError(54);return t.node_ops.readdir(t)},unlink(e){var t=K.lookupPath(e,{parent:!0}).node;if(!t)throw new K.ErrnoError(44);var n=V.basename(e),r=K.lookupNode(t,n),i=K.mayDelete(t,n,!1);if(i)throw new K.ErrnoError(i);if(!t.node_ops.unlink)throw new K.ErrnoError(63);if(K.isMountpoint(r))throw new K.ErrnoError(10);t.node_ops.unlink(t,n),K.destroyNode(r)},readlink(e){var t=K.lookupPath(e).node;if(!t)throw new K.ErrnoError(44);if(!t.node_ops.readlink)throw new K.ErrnoError(28);return H.resolve(K.getPath(t.parent),t.node_ops.readlink(t))},stat(e,t){var n=K.lookupPath(e,{follow:!t}).node;if(!n)throw new K.ErrnoError(44);if(!n.node_ops.getattr)throw new K.ErrnoError(63);return n.node_ops.getattr(n)},lstat(e){return K.stat(e,!0)},chmod(e,t,n){var r=typeof e==`string`?K.lookupPath(e,{follow:!n}).node:e;if(!r.node_ops.setattr)throw new K.ErrnoError(63);r.node_ops.setattr(r,{mode:t&4095|r.mode&-4096,timestamp:Date.now()})},lchmod(e,t){K.chmod(e,t,!0)},fchmod(e,t){var n=K.getStreamChecked(e);K.chmod(n.node,t)},chown(e,t,n,r){var i=typeof e==`string`?K.lookupPath(e,{follow:!r}).node:e;if(!i.node_ops.setattr)throw new K.ErrnoError(63);i.node_ops.setattr(i,{timestamp:Date.now()})},lchown(e,t,n){K.chown(e,t,n,!0)},fchown(e,t,n){var r=K.getStreamChecked(e);K.chown(r.node,t,n)},truncate(e,t){if(t<0)throw new K.ErrnoError(28);var n=typeof e==`string`?K.lookupPath(e,{follow:!0}).node:e;if(!n.node_ops.setattr)throw new K.ErrnoError(63);if(K.isDir(n.mode))throw new K.ErrnoError(31);if(!K.isFile(n.mode))throw new K.ErrnoError(28);var r=K.nodePermissions(n,`w`);if(r)throw new K.ErrnoError(r);n.node_ops.setattr(n,{size:t,timestamp:Date.now()})},ftruncate(e,t){var n=K.getStreamChecked(e);if(!(n.flags&2097155))throw new K.ErrnoError(28);K.truncate(n.node,t)},utime(e,t,n){var r=K.lookupPath(e,{follow:!0}).node;r.node_ops.setattr(r,{timestamp:Math.max(t,n)})},open(e,t,r){if(e===``)throw new K.ErrnoError(44);t=typeof t==`string`?Ie(t):t,r=r===void 0?438:r,r=t&64?r&4095|32768:0;var i;if(typeof e==`object`)i=e;else{e=V.normalize(e);try{i=K.lookupPath(e,{follow:!(t&131072)}).node}catch{}}var a=!1;if(t&64){if(i){if(t&128)throw new K.ErrnoError(20)}else i=K.mknod(e,r,0),a=!0}if(!i)throw new K.ErrnoError(44);if(K.isChrdev(i.mode)&&(t&=-513),t&65536&&!K.isDir(i.mode))throw new K.ErrnoError(54);if(!a){var o=K.mayOpen(i,t);if(o)throw new K.ErrnoError(o)}t&512&&!a&&K.truncate(i,0),t&=-131713;var s=K.createStream({node:i,path:K.getPath(i),flags:t,seekable:!0,position:0,stream_ops:i.stream_ops,ungotten:[],error:!1});return s.stream_ops.open&&s.stream_ops.open(s),n.logReadFiles&&!(t&1)&&(K.readFiles||={},e in K.readFiles||(K.readFiles[e]=1)),s},close(e){if(K.isClosed(e))throw new K.ErrnoError(8);e.getdents&&=null;try{e.stream_ops.close&&e.stream_ops.close(e)}catch(e){throw e}finally{K.closeStream(e.fd)}e.fd=null},isClosed(e){return e.fd===null},llseek(e,t,n){if(K.isClosed(e))throw new K.ErrnoError(8);if(!e.seekable||!e.stream_ops.llseek)throw new K.ErrnoError(70);if(n!=0&&n!=1&&n!=2)throw new K.ErrnoError(28);return e.position=e.stream_ops.llseek(e,t,n),e.ungotten=[],e.position},read(e,t,n,r,i){if(r<0||i<0)throw new K.ErrnoError(28);if(K.isClosed(e)||(e.flags&2097155)==1)throw new K.ErrnoError(8);if(K.isDir(e.node.mode))throw new K.ErrnoError(31);if(!e.stream_ops.read)throw new K.ErrnoError(28);var a=i!==void 0;if(!a)i=e.position;else if(!e.seekable)throw new K.ErrnoError(70);var o=e.stream_ops.read(e,t,n,r,i);return a||(e.position+=o),o},write(e,t,n,r,i,a){if(r<0||i<0)throw new K.ErrnoError(28);if(K.isClosed(e)||!(e.flags&2097155))throw new K.ErrnoError(8);if(K.isDir(e.node.mode))throw new K.ErrnoError(31);if(!e.stream_ops.write)throw new K.ErrnoError(28);e.seekable&&e.flags&1024&&K.llseek(e,0,2);var o=i!==void 0;if(!o)i=e.position;else if(!e.seekable)throw new K.ErrnoError(70);var s=e.stream_ops.write(e,t,n,r,i,a);return o||(e.position+=s),s},allocate(e,t,n){if(K.isClosed(e))throw new K.ErrnoError(8);if(t<0||n<=0)throw new K.ErrnoError(28);if(!(e.flags&2097155))throw new K.ErrnoError(8);if(!K.isFile(e.node.mode)&&!K.isDir(e.node.mode))throw new K.ErrnoError(43);if(!e.stream_ops.allocate)throw new K.ErrnoError(138);e.stream_ops.allocate(e,t,n)},mmap(e,t,n,r,i){if(r&2&&!(i&2)&&(e.flags&2097155)!=2||(e.flags&2097155)==1)throw new K.ErrnoError(2);if(!e.stream_ops.mmap)throw new K.ErrnoError(43);return e.stream_ops.mmap(e,t,n,r,i)},msync(e,t,n,r,i){return e.stream_ops.msync?e.stream_ops.msync(e,t,n,r,i):0},munmap:e=>0,ioctl(e,t,n){if(!e.stream_ops.ioctl)throw new K.ErrnoError(59);return e.stream_ops.ioctl(e,t,n)},readFile(e,t={}){if(t.flags=t.flags||0,t.encoding=t.encoding||`binary`,t.encoding!==`utf8`&&t.encoding!==`binary`)throw Error(`Invalid encoding type "${t.encoding}"`);var n,r=K.open(e,t.flags),i=K.stat(e).size,a=new Uint8Array(i);return K.read(r,a,0,i,0),t.encoding===`utf8`?n=we(a,0):t.encoding===`binary`&&(n=a),K.close(r),n},writeFile(e,t,n={}){n.flags=n.flags||577;var r=K.open(e,n.flags,n.mode);if(typeof t==`string`){var i=new Uint8Array(Ee(t)+1),a=De(t,i,0,i.length);K.write(r,i,0,a,void 0,n.canOwn)}else if(ArrayBuffer.isView(t))K.write(r,t,0,t.byteLength,void 0,n.canOwn);else throw Error(`Unsupported data type`);K.close(r)},cwd:()=>K.currentPath,chdir(e){var t=K.lookupPath(e,{follow:!0});if(t.node===null)throw new K.ErrnoError(44);if(!K.isDir(t.node.mode))throw new K.ErrnoError(54);var n=K.nodePermissions(t.node,`x`);if(n)throw new K.ErrnoError(n);K.currentPath=t.path},createDefaultDirectories(){K.mkdir(`/tmp`),K.mkdir(`/home`),K.mkdir(`/home/web_user`)},createDefaultDevices(){K.mkdir(`/dev`),K.registerDevice(K.makedev(1,3),{read:()=>0,write:(e,t,n,r,i)=>r}),K.mkdev(`/dev/null`,K.makedev(1,3)),W.register(K.makedev(5,0),W.default_tty_ops),W.register(K.makedev(6,0),W.default_tty1_ops),K.mkdev(`/dev/tty`,K.makedev(5,0)),K.mkdev(`/dev/tty1`,K.makedev(6,0));var e=new Uint8Array(1024),t=0,n=()=>(t===0&&(t=Ce(e).byteLength),e[--t]);K.createDevice(`/dev`,`random`,n),K.createDevice(`/dev`,`urandom`,n),K.mkdir(`/dev/shm`),K.mkdir(`/dev/shm/tmp`)},createSpecialDirectories(){K.mkdir(`/proc`);var e=K.mkdir(`/proc/self`);K.mkdir(`/proc/self/fd`),K.mount({mount(){var t=K.createNode(e,`fd`,16895,73);return t.node_ops={lookup(e,t){var n=+t,r=K.getStreamChecked(n),i={parent:null,mount:{mountpoint:`fake`},node_ops:{readlink:()=>r.path}};return i.parent=i,i}},t}},{},`/proc/self/fd`)},createStandardStreams(){n.stdin?K.createDevice(`/dev`,`stdin`,n.stdin):K.symlink(`/dev/tty`,`/dev/stdin`),n.stdout?K.createDevice(`/dev`,`stdout`,null,n.stdout):K.symlink(`/dev/tty`,`/dev/stdout`),n.stderr?K.createDevice(`/dev`,`stderr`,null,n.stderr):K.symlink(`/dev/tty1`,`/dev/stderr`),K.open(`/dev/stdin`,0),K.open(`/dev/stdout`,1),K.open(`/dev/stderr`,1)},ensureErrnoError(){K.ErrnoError||(K.ErrnoError=function(e,t){this.name=`ErrnoError`,this.node=t,this.setErrno=function(e){this.errno=e},this.setErrno(e),this.message=`FS error`},K.ErrnoError.prototype=Error(),K.ErrnoError.prototype.constructor=K.ErrnoError,[44].forEach(e=>{K.genericErrors[e]=new K.ErrnoError(e),K.genericErrors[e].stack=`<generic error, no stack>`}))},staticInit(){K.ensureErrnoError(),K.nameTable=Array(4096),K.mount(G,{},`/`),K.createDefaultDirectories(),K.createDefaultDevices(),K.createSpecialDirectories(),K.filesystems={MEMFS:G}},init(e,t,r){K.init.initialized=!0,K.ensureErrnoError(),n.stdin=e||n.stdin,n.stdout=t||n.stdout,n.stderr=r||n.stderr,K.createStandardStreams()},quit(){K.init.initialized=!1;for(var e=0;e<K.streams.length;e++){var t=K.streams[e];t&&K.close(t)}},findObject(e,t){var n=K.analyzePath(e,t);return n.exists?n.object:null},analyzePath(e,t){try{var n=K.lookupPath(e,{follow:!t});e=n.path}catch{}var r={isRoot:!1,exists:!1,error:0,name:null,path:null,object:null,parentExists:!1,parentPath:null,parentObject:null};try{var n=K.lookupPath(e,{parent:!0});r.parentExists=!0,r.parentPath=n.path,r.parentObject=n.node,r.name=V.basename(e),n=K.lookupPath(e,{follow:!t}),r.exists=!0,r.path=n.path,r.object=n.node,r.name=n.node.name,r.isRoot=n.path===`/`}catch(e){r.error=e.errno}return r},createPath(e,t,n,r){e=typeof e==`string`?e:K.getPath(e);for(var i=t.split(`/`).reverse();i.length;){var a=i.pop();if(a){var o=V.join2(e,a);try{K.mkdir(o)}catch{}e=o}}return o},createFile(e,t,n,r,i){var a=V.join2(typeof e==`string`?e:K.getPath(e),t),o=Le(r,i);return K.create(a,o)},createDataFile(e,t,n,r,i,a){var o=t;e&&(e=typeof e==`string`?e:K.getPath(e),o=t?V.join2(e,t):e);var s=Le(r,i),c=K.create(o,s);if(n){if(typeof n==`string`){for(var l=Array(n.length),u=0,d=n.length;u<d;++u)l[u]=n.charCodeAt(u);n=l}K.chmod(c,s|146);var f=K.open(c,577);K.write(f,n,0,n.length,0,a),K.close(f),K.chmod(c,s)}},createDevice(e,t,n,r){var i=V.join2(typeof e==`string`?e:K.getPath(e),t),a=Le(!!n,!!r);K.createDevice.major||(K.createDevice.major=64);var o=K.makedev(K.createDevice.major++,0);return K.registerDevice(o,{open(e){e.seekable=!1},close(e){r&&r.buffer&&r.buffer.length&&r(10)},read(e,t,r,i,a){for(var o=0,s=0;s<i;s++){var c;try{c=n()}catch{throw new K.ErrnoError(29)}if(c===void 0&&o===0)throw new K.ErrnoError(6);if(c==null)break;o++,t[r+s]=c}return o&&(e.node.timestamp=Date.now()),o},write(e,t,n,i,a){for(var o=0;o<i;o++)try{r(t[n+o])}catch{throw new K.ErrnoError(29)}return i&&(e.node.timestamp=Date.now()),o}}),K.mkdev(i,a,o)},forceLoadFile(e){if(e.isDevice||e.isFolder||e.link||e.contents)return!0;if(typeof XMLHttpRequest<`u`)throw Error(`Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.`);if(f)try{e.contents=Oe(f(e.url),!0),e.usedBytes=e.contents.length}catch{throw new K.ErrnoError(29)}else throw Error(`Cannot load without read() or XMLHttpRequest.`)},createLazyFile(e,t,n,r,i){function a(){this.lengthKnown=!1,this.chunks=[]}if(a.prototype.get=function(e){if(!(e>this.length-1||e<0)){var t=e%this.chunkSize,n=e/this.chunkSize|0;return this.getter(n)[t]}},a.prototype.setDataGetter=function(e){this.getter=e},a.prototype.cacheLength=function(){var e=new XMLHttpRequest;if(e.open(`HEAD`,n,!1),e.send(null),!(e.status>=200&&e.status<300||e.status===304))throw Error(`Couldn't load `+n+`. Status: `+e.status);var t=Number(e.getResponseHeader(`Content-length`)),r,i=(r=e.getResponseHeader(`Accept-Ranges`))&&r===`bytes`,a=(r=e.getResponseHeader(`Content-Encoding`))&&r===`gzip`,o=1048576;i||(o=t);var s=(e,r)=>{if(e>r)throw Error(`invalid range (`+e+`, `+r+`) or no bytes requested!`);if(r>t-1)throw Error(`only `+t+` bytes available! programmer error!`);var i=new XMLHttpRequest;if(i.open(`GET`,n,!1),t!==o&&i.setRequestHeader(`Range`,`bytes=`+e+`-`+r),i.responseType=`arraybuffer`,i.overrideMimeType&&i.overrideMimeType(`text/plain; charset=x-user-defined`),i.send(null),!(i.status>=200&&i.status<300||i.status===304))throw Error(`Couldn't load `+n+`. Status: `+i.status);return i.response===void 0?Oe(i.responseText||``,!0):new Uint8Array(i.response||[])},c=this;c.setDataGetter(e=>{var n=e*o,r=(e+1)*o-1;if(r=Math.min(r,t-1),c.chunks[e]===void 0&&(c.chunks[e]=s(n,r)),c.chunks[e]===void 0)throw Error(`doXHR failed!`);return c.chunks[e]}),(a||!t)&&(o=t=1,t=this.getter(0).length,o=t,h(`LazyFiles on gzip forces download of the whole file when length is accessed`)),this._length=t,this._chunkSize=o,this.lengthKnown=!0},typeof XMLHttpRequest<`u`){if(!l)throw`Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc`;var o=new a;Object.defineProperties(o,{length:{get:function(){return this.lengthKnown||this.cacheLength(),this._length}},chunkSize:{get:function(){return this.lengthKnown||this.cacheLength(),this._chunkSize}}});var s={isDevice:!1,contents:o}}else var s={isDevice:!1,url:n};var c=K.createFile(e,t,s,r,i);s.contents?c.contents=s.contents:s.url&&(c.contents=null,c.url=s.url),Object.defineProperties(c,{usedBytes:{get:function(){return this.contents.length}}});var u={};Object.keys(c.stream_ops).forEach(e=>{var t=c.stream_ops[e];u[e]=function(){return K.forceLoadFile(c),t.apply(null,arguments)}});function d(e,t,n,r,i){var a=e.node.contents;if(i>=a.length)return 0;var o=Math.min(a.length-i,r);if(a.slice)for(var s=0;s<o;s++)t[n+s]=a[i+s];else for(var s=0;s<o;s++)t[n+s]=a.get(i+s);return o}return u.read=(e,t,n,r,i)=>(K.forceLoadFile(c),d(e,t,n,r,i)),u.mmap=(e,t,n,r,i)=>{K.forceLoadFile(c);var a=Ae(t);if(!a)throw new K.ErrnoError(48);return d(e,x,a,t,n),{ptr:a,allocated:!0}},c.stream_ops=u,c}},Re=(e,t)=>e?we(S,e,t):``,q={DEFAULT_POLLMASK:5,calculateAt(e,t,n){if(V.isAbs(t))return t;var r=e===-100?K.cwd():q.getStreamFromFD(e).path;if(t.length==0){if(!n)throw new K.ErrnoError(44);return r}return V.join2(r,t)},doStat(e,t,n){try{var r=e(t)}catch(e){if(e&&e.node&&V.normalize(t)!==V.normalize(K.getPath(e.node)))return-54;throw e}w[n>>2]=r.dev,w[n+4>>2]=r.mode,T[n+8>>2]=r.nlink,w[n+12>>2]=r.uid,w[n+16>>2]=r.gid,w[n+20>>2]=r.rdev,B=[r.size>>>0,(z=r.size,+Math.abs(z)>=1?z>0?Math.floor(z/4294967296)>>>0:~~+Math.ceil((z-+(~~z>>>0))/4294967296)>>>0:0)],w[n+24>>2]=B[0],w[n+28>>2]=B[1],w[n+32>>2]=4096,w[n+36>>2]=r.blocks;var i=r.atime.getTime(),a=r.mtime.getTime(),o=r.ctime.getTime();return B=[Math.floor(i/1e3)>>>0,(z=Math.floor(i/1e3),+Math.abs(z)>=1?z>0?Math.floor(z/4294967296)>>>0:~~+Math.ceil((z-+(~~z>>>0))/4294967296)>>>0:0)],w[n+40>>2]=B[0],w[n+44>>2]=B[1],T[n+48>>2]=i%1e3*1e3,B=[Math.floor(a/1e3)>>>0,(z=Math.floor(a/1e3),+Math.abs(z)>=1?z>0?Math.floor(z/4294967296)>>>0:~~+Math.ceil((z-+(~~z>>>0))/4294967296)>>>0:0)],w[n+56>>2]=B[0],w[n+60>>2]=B[1],T[n+64>>2]=a%1e3*1e3,B=[Math.floor(o/1e3)>>>0,(z=Math.floor(o/1e3),+Math.abs(z)>=1?z>0?Math.floor(z/4294967296)>>>0:~~+Math.ceil((z-+(~~z>>>0))/4294967296)>>>0:0)],w[n+72>>2]=B[0],w[n+76>>2]=B[1],T[n+80>>2]=o%1e3*1e3,B=[r.ino>>>0,(z=r.ino,+Math.abs(z)>=1?z>0?Math.floor(z/4294967296)>>>0:~~+Math.ceil((z-+(~~z>>>0))/4294967296)>>>0:0)],w[n+88>>2]=B[0],w[n+92>>2]=B[1],0},doMsync(e,t,n,r,i){if(!K.isFile(t.node.mode))throw new K.ErrnoError(43);if(r&2)return 0;var a=S.slice(e,e+n);K.msync(t,a,i,n,r)},varargs:void 0,get(){var e=w[q.varargs>>2];return q.varargs+=4,e},getp(){return q.get()},getStr(e){return Re(e)},getStreamFromFD(e){return K.getStreamChecked(e)}};function ze(e,t,n){q.varargs=n;try{var r=q.getStreamFromFD(e);switch(t){case 0:var i=q.get();if(i<0)return-28;for(;K.streams[i];)i++;return K.createStream(r,i).fd;case 1:case 2:return 0;case 3:return r.flags;case 4:var i=q.get();return r.flags|=i,0;case 5:var i=q.getp(),a=0;return C[i+a>>1]=2,0;case 6:case 7:return 0;case 16:case 8:return-28;case 9:return xe(28),-1;default:return-28}}catch(e){if(K===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Be(e,t,n){q.varargs=n;try{var r=q.getStreamFromFD(e);switch(t){case 21509:return r.tty?0:-59;case 21505:if(!r.tty)return-59;if(r.tty.ops.ioctl_tcgets){var i=r.tty.ops.ioctl_tcgets(r),a=q.getp();w[a>>2]=i.c_iflag||0,w[a+4>>2]=i.c_oflag||0,w[a+8>>2]=i.c_cflag||0,w[a+12>>2]=i.c_lflag||0;for(var o=0;o<32;o++)x[a+o+17>>0]=i.c_cc[o]||0;return 0}return 0;case 21510:case 21511:case 21512:return r.tty?0:-59;case 21506:case 21507:case 21508:if(!r.tty)return-59;if(r.tty.ops.ioctl_tcsets){for(var a=q.getp(),s=w[a>>2],c=w[a+4>>2],l=w[a+8>>2],u=w[a+12>>2],d=[],o=0;o<32;o++)d.push(x[a+o+17>>0]);return r.tty.ops.ioctl_tcsets(r.tty,t,{c_iflag:s,c_oflag:c,c_cflag:l,c_lflag:u,c_cc:d})}return 0;case 21519:if(!r.tty)return-59;var a=q.getp();return w[a>>2]=0,0;case 21520:return r.tty?-28:-59;case 21531:var a=q.getp();return K.ioctl(r,t,a);case 21523:if(!r.tty)return-59;if(r.tty.ops.ioctl_tiocgwinsz){var f=r.tty.ops.ioctl_tiocgwinsz(r.tty),a=q.getp();C[a>>1]=f[0],C[a+2>>1]=f[1]}return 0;case 21524:return r.tty?0:-59;case 21515:return r.tty?0:-59;default:return-28}}catch(e){if(K===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}function Ve(e,t,n,r){q.varargs=r;try{t=q.getStr(t),t=q.calculateAt(e,t);var i=r?q.get():0;return K.open(t,n,i).fd}catch(e){if(K===void 0||e.name!==`ErrnoError`)throw e;return-e.errno}}var J=1,He=()=>J,Ue=()=>{F(``)},We=()=>Date.now(),Ge=()=>2147483648,Ke=()=>Ge(),qe=()=>performance.now(),Je=(e,t,n)=>S.copyWithin(e,t,t+n),Ye=e=>{var t=(e-v.buffer.byteLength+65535)/65536;try{return v.grow(t),ee(),1}catch{}},Xe=e=>{var t=S.length;e>>>=0;var n=Ge();if(e>n)return!1;for(var r=(e,t)=>e+(t-e%t)%t,i=1;i<=4;i*=2){var a=t*(1+.2/i);if(a=Math.min(a,e+100663296),Ye(Math.min(n,r(Math.max(e,a),65536))))return!0}return!1},Ze={},Qe=()=>o||`./this.program`,$e=()=>{if(!$e.strings){var e={USER:`web_user`,LOGNAME:`web_user`,PATH:`/`,PWD:`/`,HOME:`/home/web_user`,LANG:(typeof navigator==`object`&&navigator.languages&&navigator.languages[0]||`C`).replace(`-`,`_`)+`.UTF-8`,_:Qe()};for(var t in Ze)Ze[t]===void 0?delete e[t]:e[t]=Ze[t];var n=[];for(var t in e)n.push(`${t}=${e[t]}`);$e.strings=n}return $e.strings},et=(e,t)=>{for(var n=0;n<e.length;++n)x[t++>>0]=e.charCodeAt(n);x[t>>0]=0},tt=(e,t)=>{var n=0;return $e().forEach((r,i)=>{var a=t+n;T[e+i*4>>2]=a,et(r,a),n+=r.length+1}),0},nt=(e,t)=>{var n=$e();T[e>>2]=n.length;var r=0;return n.forEach(e=>r+=e.length+1),T[t>>2]=r,0},rt=0,it=()=>ye||rt>0,at=e=>{it()||(n.onExit&&n.onExit(e),y=!0),s(e,new ge(e))},ot=(e,t)=>{at(e)};function st(e){try{var t=q.getStreamFromFD(e);return K.close(t),0}catch(e){if(K===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}var ct=(e,t,n,r)=>{for(var i=0,a=0;a<n;a++){var o=T[t>>2],s=T[t+4>>2];t+=8;var c=K.read(e,x,o,s,r);if(c<0)return-1;if(i+=c,c<s)break;r!==void 0&&(r+=c)}return i};function lt(e,t,n,r){try{var i=ct(q.getStreamFromFD(e),t,n);return T[r>>2]=i,0}catch(e){if(K===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}var ut=(e,t)=>t+2097152>>>0<4194305-!!e?(e>>>0)+t*4294967296:NaN;function dt(e,t,n,r,i){var a=ut(t,n);try{if(isNaN(a))return 61;var o=q.getStreamFromFD(e);return K.llseek(o,a,r),B=[o.position>>>0,(z=o.position,+Math.abs(z)>=1?z>0?Math.floor(z/4294967296)>>>0:~~+Math.ceil((z-+(~~z>>>0))/4294967296)>>>0:0)],w[i>>2]=B[0],w[i+4>>2]=B[1],o.getdents&&a===0&&r===0&&(o.getdents=null),0}catch(e){if(K===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}var ft=(e,t,n,r)=>{for(var i=0,a=0;a<n;a++){var o=T[t>>2],s=T[t+4>>2];t+=8;var c=K.write(e,x,o,s,r);if(c<0)return-1;i+=c,r!==void 0&&(r+=c)}return i};function pt(e,t,n,r){try{var i=ft(q.getStreamFromFD(e),t,n);return T[r>>2]=i,0}catch(e){if(K===void 0||e.name!==`ErrnoError`)throw e;return e.errno}}var mt=e=>e%4==0&&(e%100!=0||e%400==0),ht=(e,t)=>{for(var n=0,r=0;r<=t;n+=e[r++]);return n},gt=[31,29,31,30,31,30,31,31,30,31,30,31],_t=[31,28,31,30,31,30,31,31,30,31,30,31],vt=(e,t)=>{for(var n=new Date(e.getTime());t>0;){var r=mt(n.getFullYear()),i=n.getMonth(),a=(r?gt:_t)[i];if(t>a-n.getDate())t-=a-n.getDate()+1,n.setDate(1),i<11?n.setMonth(i+1):(n.setMonth(0),n.setFullYear(n.getFullYear()+1));else return n.setDate(n.getDate()+t),n}return n},yt=(e,t)=>{x.set(e,t)},bt=(e,t,n,r)=>{var i=T[r+40>>2],a={tm_sec:w[r>>2],tm_min:w[r+4>>2],tm_hour:w[r+8>>2],tm_mday:w[r+12>>2],tm_mon:w[r+16>>2],tm_year:w[r+20>>2],tm_wday:w[r+24>>2],tm_yday:w[r+28>>2],tm_isdst:w[r+32>>2],tm_gmtoff:w[r+36>>2],tm_zone:i?Re(i):``},o=Re(n),s={"%c":`%a %b %d %H:%M:%S %Y`,"%D":`%m/%d/%y`,"%F":`%Y-%m-%d`,"%h":`%b`,"%r":`%I:%M:%S %p`,"%R":`%H:%M`,"%T":`%H:%M:%S`,"%x":`%m/%d/%y`,"%X":`%H:%M:%S`,"%Ec":`%c`,"%EC":`%C`,"%Ex":`%m/%d/%y`,"%EX":`%H:%M:%S`,"%Ey":`%y`,"%EY":`%Y`,"%Od":`%d`,"%Oe":`%e`,"%OH":`%H`,"%OI":`%I`,"%Om":`%m`,"%OM":`%M`,"%OS":`%S`,"%Ou":`%u`,"%OU":`%U`,"%OV":`%V`,"%Ow":`%w`,"%OW":`%W`,"%Oy":`%y`};for(var c in s)o=o.replace(new RegExp(c,`g`),s[c]);var l=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],u=[`January`,`February`,`March`,`April`,`May`,`June`,`July`,`August`,`September`,`October`,`November`,`December`];function d(e,t,n){for(var r=typeof e==`number`?e.toString():e||``;r.length<t;)r=n[0]+r;return r}function f(e,t){return d(e,t,`0`)}function p(e,t){function n(e){return e<0?-1:+(e>0)}var r;return(r=n(e.getFullYear()-t.getFullYear()))===0&&(r=n(e.getMonth()-t.getMonth()))===0&&(r=n(e.getDate()-t.getDate())),r}function m(e){switch(e.getDay()){case 0:return new Date(e.getFullYear()-1,11,29);case 1:return e;case 2:return new Date(e.getFullYear(),0,3);case 3:return new Date(e.getFullYear(),0,2);case 4:return new Date(e.getFullYear(),0,1);case 5:return new Date(e.getFullYear()-1,11,31);case 6:return new Date(e.getFullYear()-1,11,30)}}function h(e){var t=vt(new Date(e.tm_year+1900,0,1),e.tm_yday),n=new Date(t.getFullYear(),0,4),r=new Date(t.getFullYear()+1,0,4),i=m(n),a=m(r);return p(i,t)<=0?p(a,t)<=0?t.getFullYear()+1:t.getFullYear():t.getFullYear()-1}var g={"%a":e=>l[e.tm_wday].substring(0,3),"%A":e=>l[e.tm_wday],"%b":e=>u[e.tm_mon].substring(0,3),"%B":e=>u[e.tm_mon],"%C":e=>f((e.tm_year+1900)/100|0,2),"%d":e=>f(e.tm_mday,2),"%e":e=>d(e.tm_mday,2,` `),"%g":e=>h(e).toString().substring(2),"%G":e=>h(e),"%H":e=>f(e.tm_hour,2),"%I":e=>{var t=e.tm_hour;return t==0?t=12:t>12&&(t-=12),f(t,2)},"%j":e=>f(e.tm_mday+ht(mt(e.tm_year+1900)?gt:_t,e.tm_mon-1),3),"%m":e=>f(e.tm_mon+1,2),"%M":e=>f(e.tm_min,2),"%n":()=>`
|
|
6
|
-
`,"%p":e=>e.tm_hour>=0&&e.tm_hour<12?`AM`:`PM`,"%S":e=>f(e.tm_sec,2),"%t":()=>` `,"%u":e=>e.tm_wday||7,"%U":e=>{var t=e.tm_yday+7-e.tm_wday;return f(Math.floor(t/7),2)},"%V":e=>{var t=Math.floor((e.tm_yday+7-(e.tm_wday+6)%7)/7);if((e.tm_wday+371-e.tm_yday-2)%7<=2&&t++,!t){t=52;var n=(e.tm_wday+7-e.tm_yday-1)%7;(n==4||n==5&&mt(e.tm_year%400-1))&&t++}else if(t==53){var r=(e.tm_wday+371-e.tm_yday)%7;r!=4&&(r!=3||!mt(e.tm_year))&&(t=1)}return f(t,2)},"%w":e=>e.tm_wday,"%W":e=>{var t=e.tm_yday+7-(e.tm_wday+6)%7;return f(Math.floor(t/7),2)},"%y":e=>(e.tm_year+1900).toString().substring(2),"%Y":e=>e.tm_year+1900,"%z":e=>{var t=e.tm_gmtoff,n=t>=0;return t=Math.abs(t)/60,t=t/60*100+t%60,(n?`+`:`-`)+String(`0000`+t).slice(-4)},"%Z":e=>e.tm_zone,"%%":()=>`%`};for(var c in o=o.replace(/%%/g,`\0\0`),g)o.includes(c)&&(o=o.replace(new RegExp(c,`g`),g[c](a)));o=o.replace(/\0\0/g,`%`);var _=Oe(o,!1);return _.length>t?0:(yt(_,e),_.length-1)},xt=(e,t,n,r,i)=>bt(e,t,n,r),St=e=>n[`_`+e],Ct=(e,t,n)=>De(e,S,t,n),wt=e=>{var t=Ee(e)+1,n=Dn(t);return Ct(e,n,t),n},Tt=(e,t,n,r,i)=>{var a={string:e=>{var t=0;return e!=null&&e!==0&&(t=wt(e)),t},array:e=>{var t=Dn(e.length);return yt(e,t),t}};function o(e){return t===`string`?Re(e):t===`boolean`?!!e:e}var s=St(e),c=[],l=0;if(r)for(var u=0;u<r.length;u++){var d=a[n[u]];d?(l===0&&(l=Tn()),c[u]=d(r[u])):c[u]=r[u]}var f=s.apply(null,c);function p(e){return l!==0&&En(l),o(e)}return f=p(f),f},Et=(e,t,n,r)=>{var i=!n||n.every(e=>e===`number`||e===`boolean`);return t!==`string`&&i&&!r?St(e):function(){return Tt(e,t,n,arguments,r)}},Dt=(e,t)=>{e<128?t.push(e):t.push(e%128|128,e>>7)},Ot=e=>{for(var t={i:`i32`,j:`i64`,f:`f32`,d:`f64`,e:`externref`,p:`i32`},n={parameters:[],results:e[0]==`v`?[]:[t[e[0]]]},r=1;r<e.length;++r)n.parameters.push(t[e[r]]);return n},kt=(e,t)=>{var n=e.slice(0,1),r=e.slice(1),i={i:127,p:127,j:126,f:125,d:124,e:111};t.push(96),Dt(r.length,t);for(var a=0;a<r.length;++a)t.push(i[r[a]]);n==`v`?t.push(0):t.push(1,i[n])},At=(e,t)=>{if(typeof WebAssembly.Function==`function`)return new WebAssembly.Function(Ot(t),e);var n=[1];kt(t,n);var r=[0,97,115,109,1,0,0,0,1];Dt(n.length,r),r.push.apply(r,n),r.push(2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0);var i=new WebAssembly.Module(new Uint8Array(r));return new WebAssembly.Instance(i,{e:{f:e}}).exports.f},jt=[],Mt,Nt=e=>{var t=jt[e];return t||(e>=jt.length&&(jt.length=e+1),jt[e]=t=Mt.get(e)),t},Pt=(e,t)=>{if(Ft)for(var n=e;n<e+t;n++){var r=Nt(n);r&&Ft.set(r,n)}},Ft,It=e=>(Ft||(Ft=new WeakMap,Pt(0,Mt.length)),Ft.get(e)||0),Lt=[],Rt=()=>{if(Lt.length)return Lt.pop();try{Mt.grow(1)}catch(e){throw e instanceof RangeError?`Unable to grow wasm table. Set ALLOW_TABLE_GROWTH.`:e}return Mt.length-1},zt=(e,t)=>{Mt.set(e,t),jt[e]=Mt.get(e)},Bt=(e,t)=>{var n=It(e);if(n)return n;var r=Rt();try{zt(r,e)}catch(n){if(!(n instanceof TypeError))throw n;zt(r,At(e,t))}return Ft.set(e,r),r},Vt=e=>{Ft.delete(Nt(e)),zt(e,null),Lt.push(e)},Ht=function(e,t,n,r){e||=this,this.parent=e,this.mount=e.mount,this.mounted=null,this.id=K.nextInode++,this.name=t,this.mode=n,this.node_ops={},this.stream_ops={},this.rdev=r},Ut=365,Wt=146;Object.defineProperties(Ht.prototype,{read:{get:function(){return(this.mode&Ut)===Ut},set:function(e){e?this.mode|=Ut:this.mode&=~Ut}},write:{get:function(){return(this.mode&Wt)===Wt},set:function(e){e?this.mode|=Wt:this.mode&=~Wt}},isFolder:{get:function(){return K.isDir(this.mode)}},isDevice:{get:function(){return K.isChrdev(this.mode)}}}),K.FSNode=Ht,K.createPreloadedFile=Fe,K.staticInit();var Gt={g:ze,p:Be,h:Ve,i:He,c:Ue,e:We,j:Ke,b:qe,q:Je,r:Xe,m:tt,n:nt,a:ot,f:st,o:lt,k:dt,d:pt,l:xt},Y=he(),Kt=n._Highs_create=()=>(Kt=n._Highs_create=Y.u)(),qt=n._Highs_destroy=e=>(qt=n._Highs_destroy=Y.v)(e),Jt=n._Highs_version=()=>(Jt=n._Highs_version=Y.w)(),X=n._Highs_run=e=>(X=n._Highs_run=Y.x)(e),Yt=n._Highs_readModel=(e,t)=>(Yt=n._Highs_readModel=Y.y)(e,t),Xt=n._Highs_getNumCol=e=>(Xt=n._Highs_getNumCol=Y.z)(e),Zt=n._Highs_clearModel=e=>(Zt=n._Highs_clearModel=Y.A)(e),Qt=n._Highs_setBoolOptionValue=(e,t,r)=>(Qt=n._Highs_setBoolOptionValue=Y.B)(e,t,r),$t=n._Highs_setIntOptionValue=(e,t,r)=>($t=n._Highs_setIntOptionValue=Y.C)(e,t,r),en=n._Highs_setDoubleOptionValue=(e,t,r)=>(en=n._Highs_setDoubleOptionValue=Y.D)(e,t,r),tn=n._Highs_setStringOptionValue=(e,t,r)=>(tn=n._Highs_setStringOptionValue=Y.E)(e,t,r),nn=n._Highs_getIntInfoValue=(e,t,r)=>(nn=n._Highs_getIntInfoValue=Y.F)(e,t,r),rn=n._Highs_getDoubleInfoValue=(e,t,r)=>(rn=n._Highs_getDoubleInfoValue=Y.G)(e,t,r),an=n._Highs_getInt64InfoValue=(e,t,r)=>(an=n._Highs_getInt64InfoValue=Y.H)(e,t,r),on=n._Highs_getSolution=(e,t,r,i,a)=>(on=n._Highs_getSolution=Y.I)(e,t,r,i,a),sn=n._Highs_getModelStatus=e=>(sn=n._Highs_getModelStatus=Y.J)(e),cn=n._Highs_getObjectiveValue=e=>(cn=n._Highs_getObjectiveValue=Y.K)(e),ln=n._Highs_getNumRow=e=>(ln=n._Highs_getNumRow=Y.L)(e),un=n._Highs_setSolution=(e,t,r,i,a)=>(un=n._Highs_setSolution=Y.M)(e,t,r,i,a),dn=n._Highs_setSparseSolution=(e,t,r,i)=>(dn=n._Highs_setSparseSolution=Y.N)(e,t,r,i),fn=n._Highs_setCallback=(e,t,r)=>(fn=n._Highs_setCallback=Y.O)(e,t,r),pn=n._Highs_startCallback=(e,t)=>(pn=n._Highs_startCallback=Y.P)(e,t),mn=n._Highs_stopCallback=(e,t)=>(mn=n._Highs_stopCallback=Y.Q)(e,t),hn=n._Highs_changeObjectiveOffset=(e,t)=>(hn=n._Highs_changeObjectiveOffset=Y.R)(e,t),gn=n._Highs_getObjectiveOffset=(e,t)=>(gn=n._Highs_getObjectiveOffset=Y.S)(e,t),_n=n._Highs_getRowName=(e,t,r)=>(_n=n._Highs_getRowName=Y.T)(e,t,r),vn=n._Highs_getColName=(e,t,r)=>(vn=n._Highs_getColName=Y.U)(e,t,r),yn=n._Highs_getColIntegrality=(e,t,r)=>(yn=n._Highs_getColIntegrality=Y.V)(e,t,r),bn=n._Highs_getNumNz=e=>(bn=n._Highs_getNumNz=Y.W)(e),xn=()=>(xn=Y.X)(),Sn=n._malloc=e=>(Sn=n._malloc=Y.Y)(e),Cn=n._free=e=>(Cn=n._free=Y.Z)(e),wn=()=>(wn=Y._)(),Tn=()=>(Tn=Y.$)(),En=e=>(En=Y.aa)(e),Dn=e=>(Dn=Y.ba)(e);n.wasmMemory=v,n.ccall=Tt,n.cwrap=Et,n.addFunction=Bt,n.removeFunction=Vt,n.setValue=be,n.getValue=ve,n.UTF8ToString=Re,n.stringToUTF8=Ct,n.FS=K;var On;N=function e(){On||kn(),On||(N=e)};function kn(){if(oe>0||(ne(),oe>0))return;function e(){On||(On=!0,n.calledRun=!0,!y&&(re(),r(n),n.onRuntimeInitialized&&n.onRuntimeInitialized(),ie()))}n.setStatus?(n.setStatus(`Running...`),setTimeout(function(){setTimeout(function(){n.setStatus(``)},1),e()},1)):e()}if(n.preInit)for(typeof n.preInit==`function`&&(n.preInit=[n.preInit]);n.preInit.length>0;)n.preInit.pop()();return kn(),t.ready})})()})),Mt=r({default:()=>Nt});async function Nt(e={}){let t=await At(e);return new Ot(t)}var Pt=n((()=>{jt(),kt()}));kt();var Ft=[`mip_max_nodes`,`mip_max_improving_sols`,`mip_max_leaves`,`simplex_iteration_limit`,`ipm_iteration_limit`],It=new Set([`timeLimit`,`outputFlag`,`presolve`,`solver`,`relativeGap`,`absoluteGap`,`wasmUrl`,`signal`,`onProgress`,`onIncumbent`,`relax`,`useWorker`,`objectiveOffset`,`initialValues`,...Ft]);function Lt(e={}){if(e.threads!==void 0)throw Error(`Solver "HiGHS" does not support option "threads" (HiGHS WebAssembly runs single-threaded).`);if(e.verbose!==void 0)throw Error(`Solver "HiGHS" does not support option "verbose"; use "outputFlag" instead.`);for(let[t,n]of Object.entries(e))if(n!==void 0&&!It.has(t))throw Error(`Solver "HiGHS" does not support option "${t}".`);if(e.useWorker!==void 0&&typeof e.useWorker!=`boolean`)throw Error(`Invalid HiGHS option "useWorker": expected boolean, got ${typeof e.useWorker}.`);if(e.outputFlag!==void 0&&typeof e.outputFlag!=`boolean`)throw Error(`Invalid HiGHS option "outputFlag": expected boolean, got ${typeof e.outputFlag}.`);if(e.relax!==void 0&&typeof e.relax!=`boolean`)throw Error(`Invalid HiGHS option "relax": expected boolean, got ${typeof e.relax}.`);if(e.presolve!==void 0&&e.presolve!==`on`&&e.presolve!==`off`&&e.presolve!==`choose`)throw Error(`Invalid HiGHS option "presolve" (${String(e.presolve)}): expected "on", "off", or "choose".`);if(e.timeLimit!==void 0&&(typeof e.timeLimit!=`number`||!Number.isFinite(e.timeLimit)||e.timeLimit<0))throw Error(`Invalid HiGHS option "timeLimit" (${String(e.timeLimit)}): expected a finite non-negative number of seconds.`);if(e.relativeGap!==void 0&&(typeof e.relativeGap!=`number`||!Number.isFinite(e.relativeGap)||e.relativeGap<0))throw Error(`Invalid HiGHS option "relativeGap" (${String(e.relativeGap)}): expected a finite non-negative number.`);if(e.absoluteGap!==void 0&&(typeof e.absoluteGap!=`number`||!Number.isFinite(e.absoluteGap)||e.absoluteGap<0))throw Error(`Invalid HiGHS option "absoluteGap" (${String(e.absoluteGap)}): expected a finite non-negative number.`);if(e.objectiveOffset!==void 0&&(typeof e.objectiveOffset!=`number`||!Number.isFinite(e.objectiveOffset)))throw Error(`Invalid HiGHS option "objectiveOffset" (${String(e.objectiveOffset)}): expected a finite number.`);if(e.wasmUrl!==void 0&&e.wasmUrl!==null&&(typeof e.wasmUrl!=`string`||e.wasmUrl===``))throw Error(`Invalid HiGHS option "wasmUrl": expected a non-empty string or null.`)}var Rt=null,zt=null,Bt=null;function Vt(){return Bt}async function Ht(e){return e||vt()}async function Ut(e,t){if(e.wasmUrl){let t=await Ht(e.wasmUrl);return{isNode:!1,wasmUrl:t,wasmBinary:null,key:t?`url:${t}`:`node`}}if(t===null)return null;if(t.kind===`embedded`)return{isNode:!1,wasmUrl:null,wasmBinary:t.bytes,key:`__embedded__`};let n=await Ht();return{isNode:!1,wasmUrl:n,wasmBinary:null,key:n?`url:${n}`:`node`}}async function Wt(e={}){let t=await Ut(e,pt(`highs`));if(!t)throw Error(`[WaSHI] Failed to resolve HiGHS WASM target.`);let{isNode:n,wasmUrl:r,wasmBinary:i,key:a}=t;if(Rt&&zt===a)return Rt;zt=a;let o=null;return o=(async()=>{let e=n?await yt():(await Promise.resolve().then(()=>(Pt(),Mt))).default;return i?await e({wasmBinary:i.slice(),locateFile:e=>e}):n?await e():await e({locateFile:e=>e.endsWith(`.wasm`)?r:e})})().then(e=>e).catch(e=>{Rt===o&&(Rt=null,zt=null);let t=e instanceof Error?e.message:String(e),n=i?` from embedded inline WASM`:r?` from "${r}"`:``;throw Error(`[WaSHI] Failed to initialize HiGHS${n}. Deploy the package's WASM asset or explicitly set wasmUrl; no CDN fallback is attempted. ${t}`,{cause:e})}),Rt=o,o}async function Gt(e,t={}){if(Lt(t),t.signal?.aborted)return{result:{Status:`Interrupted`,StatusCode:17,HasPrimalSolution:!1,ObjectiveValue:NaN,Columns:{},Rows:[]},runTime:0};let n=await Wt(t);if(t.signal?.aborted)return{result:{Status:`Interrupted`,StatusCode:17,HasPrimalSolution:!1,ObjectiveValue:NaN,Columns:{},Rows:[]},runTime:0};let r=performance.now(),i={output_flag:t.outputFlag??!1};t.timeLimit!==void 0&&(i.time_limit=t.timeLimit),t.presolve!==void 0&&(i.presolve=t.presolve),t.solver!==void 0&&(i.solver=t.solver),t.relativeGap!==void 0&&(i.mip_rel_gap=t.relativeGap),t.absoluteGap!==void 0&&(i.mip_abs_gap=t.absoluteGap);for(let e of Ft)t[e]!==void 0&&(i[e]=t[e]);let a=t.objectiveOffset??0,o=t.initialValues,s=!1;if(o){for(let[e,t]of Object.entries(o))if(t!==void 0){if(typeof t!=`number`||!Number.isFinite(t))throw Error(`Invalid initial value for column "${e}": ${String(t)} (must be a finite number).`);s=!0}}if(typeof n.withModel!=`function`)throw Error(`[WaSHI] HiGHS runtime is missing required withModel() API (legacy highs.solve fallback has been removed).`);return{result:n.withModel({format:`lp`,data:e},e=>{let c=!1;if(a!==0){if(typeof e.changeObjectiveOffset!=`function`)throw Error(`[WaSHI] HiGHS runtime does not support changeObjectiveOffset() for non-zero objectiveOffset.`);let t=typeof e.getObjectiveOffset==`function`?e.getObjectiveOffset():0;e.changeObjectiveOffset(t+a),c=!0}for(let[t,n]of Object.entries(i))e.options.set(t,n);let l=e.getDimensions(),u=[],d=!1;for(let t=0;t<l.numCols;t++){let n=e.getColIntegrality(t);n!==0&&(d=!0),u.push({name:e.getColName(t),type:n===1?`Integer`:`Continuous`})}if(s&&o){if(typeof e.setSolution!=`function`)throw Error(`HiGHS runtime does not support setting primal initial values (setSolution is unavailable).`);let t=new Map;for(let e=0;e<l.numCols;e++)t.set(u[e].name,e);for(let[e,n]of Object.entries(o))if(n!==void 0&&!t.has(e))throw Error(`Unknown column "${e}" in initialValues (column does not exist in the HiGHS LP model).`);let n=[],r=[];for(let e=0;e<l.numCols;e++){let t=u[e].name;if(Object.prototype.hasOwnProperty.call(o,t)){let i=o[t];i!==void 0&&(n.push(e),r.push(i))}}n.length>0&&(n.length===l.numCols?e.setSolution({colValue:r}):e.setSolution({indices:n,values:r}))}let f=null,p=null,m=0,h=e=>{let t=e?.data??{},n=typeof t.running_time==`number`&&Number.isFinite(t.running_time)?t.running_time:(performance.now()-r)/1e3,i=typeof t.mip_primal_bound==`number`&&Number.isFinite(t.mip_primal_bound)?t.mip_primal_bound:typeof t.objective_function_value==`number`&&Number.isFinite(t.objective_function_value)?t.objective_function_value:void 0,a=typeof t.mip_dual_bound==`number`&&Number.isFinite(t.mip_dual_bound)?t.mip_dual_bound:void 0,o=typeof t.mip_gap==`number`&&Number.isFinite(t.mip_gap)?t.mip_gap:void 0,s=i!==void 0&&a!==void 0?Math.abs(i-a):void 0,c=typeof t.mip_node_count==`bigint`?Number(t.mip_node_count):typeof t.mip_node_count==`number`&&Number.isFinite(t.mip_node_count)?t.mip_node_count:void 0,l=typeof t.mip_total_lp_iterations==`bigint`?Number(t.mip_total_lp_iterations):typeof t.simplex_iteration_count==`number`&&Number.isFinite(t.simplex_iteration_count)?t.simplex_iteration_count:typeof t.ipm_iteration_count==`number`&&Number.isFinite(t.ipm_iteration_count)?t.ipm_iteration_count:void 0,u=typeof e?.message==`string`&&e.message.trim().length>0?e.message.trim():void 0,d={elapsedTime:n,elapsedSeconds:n,...i===void 0?{}:{objectiveValue:i},...a===void 0?{}:{objectiveBound:a},...o===void 0?{}:{relativeGap:o},...s===void 0?{}:{absoluteGap:s},...c===void 0?{}:{nodes:c},...l===void 0?{}:{iterations:l},...u===void 0?{}:{message:u}};return p=d,d},g=e=>{let n=e?.data;if(!n||!(n.mip_solution instanceof Float64Array))return;let r=n.mip_solution,i={};for(let e=0;e<u.length&&e<r.length;e++)Object.defineProperty(i,u[e].name,{value:{Index:e,Type:u[e].type,Name:u[e].name,Primal:r[e]},enumerable:!0,writable:!0,configurable:!0});let a=typeof n.objective_function_value==`number`&&Number.isFinite(n.objective_function_value)?n.objective_function_value:typeof n.mip_primal_bound==`number`&&Number.isFinite(n.mip_primal_bound)?n.mip_primal_bound:NaN;Number.isFinite(a)&&(f={objectiveValue:a,...typeof n.mip_dual_bound==`number`&&Number.isFinite(n.mip_dual_bound)?{mipDualBound:n.mip_dual_bound}:{},...typeof n.mip_gap==`number`&&Number.isFinite(n.mip_gap)?{mipGap:n.mip_gap}:{},columns:i},t.onIncumbent?.(f))},_=!1;if(t.signal||t.onProgress||t.onIncumbent){let r=n.constants?.callbackType??{logging:0,simplexInterrupt:1,ipmInterrupt:2,mipSolution:3,mipImprovingSolution:4,mipLogging:5,mipInterrupt:6},i=e=>{if(t.signal?.aborted){_=!0,e.interrupt();return}t.onProgress&&(m++,t.onProgress(h(e)),t.signal?.aborted&&(_=!0,e.interrupt()))},a={[r.simplexInterrupt]:i,[r.ipmInterrupt]:i,[r.mipInterrupt]:i,[r.mipImprovingSolution]:e=>{g(e),t.onProgress&&!t.signal?.aborted&&(m++,t.onProgress(h(e)))},[r.mipLogging]:e=>{t.onProgress&&!t.signal?.aborted&&(m++,t.onProgress(h(e)))}};e.run(a)}else e.run();let v=e.getModelStatus();_&&(v=17);let y=wt[v]??`Unknown`,b=0,x=0;try{b=Number(e.info.get(`primal_solution_status`))}catch{}try{x=Number(e.info.get(`dual_solution_status`))}catch{}let S=n.constants?.solutionStatus?.feasible??2,C=b===S,w=x===S,T=C||w?e.getSolution():null,E=C,D={};if(!C&&f!==null)E=!0,D=f.columns;else for(let e=0;e<l.numCols;e++){let t=u[e],n={Index:e,Type:t.type,Name:t.name};C&&T&&(n.Primal=T.colValue[e]),!d&&w&&T&&(n.Dual=T.colDual[e]),Object.defineProperty(D,t.name,{value:n,enumerable:!0,writable:!0,configurable:!0})}let ee=[];for(let t=0;t<l.numRows;t++){let n=e.getRowName(t),r={Index:t,Name:n};C&&T&&(r.Primal=T.rowValue[t]),!d&&w&&T&&(r.Dual=T.rowDual[t]),ee.push(r)}let O=C?e.getObjectiveValue():f===null?NaN:f.objectiveValue,k,A;if(d){try{let t=Number(e.info.get(`mip_dual_bound`));Number.isFinite(t)&&(k=t)}catch{}k===void 0&&p&&p.objectiveBound!==void 0&&(k=p.objectiveBound);try{let t=Number(e.info.get(`mip_gap`));Number.isFinite(t)&&(A=t)}catch{}A===void 0&&p&&p.relativeGap!==void 0&&(A=p.relativeGap)}return{Status:wt[v]??y,StatusCode:v,PrimalSolutionStatus:b,DualSolutionStatus:x,HasPrimalSolution:E,IsMip:d,ObjectiveValue:O,ObjectiveOffsetApplied:c,MipDualBound:k,MipGap:A,Columns:D,Rows:ee}}),runTime:(performance.now()-r)/1e3}}function Y(){let e=_t(`solvers/highs-worker.js`),t=typeof window.origin==`string`?window.origin:window.location?.origin;if(new URL(e).origin===t)return new Worker(e,{type:`module`});let n=URL.createObjectURL(new Blob([`import `+JSON.stringify(e)+`;`],{type:`text/javascript`}));try{let e=new Worker(n,{type:`module`}),t=()=>URL.revokeObjectURL(n);return e.addEventListener(`message`,t,{once:!0}),e.addEventListener(`error`,t,{once:!0}),e}catch(e){throw URL.revokeObjectURL(n),e}}var Kt=null,qt=!1,Jt=0,X=new Map;function Yt(e,t){return e?{Status:`Interrupted`,StatusCode:17,HasPrimalSolution:!0,IsMip:!0,ObjectiveValue:e.objectiveValue,ObjectiveOffsetApplied:!0,...t?.objectiveBound===void 0?e.mipDualBound===void 0?{}:{MipDualBound:e.mipDualBound}:{MipDualBound:t.objectiveBound},...t?.relativeGap===void 0?e.mipGap===void 0?{}:{MipGap:e.mipGap}:{MipGap:t.relativeGap},Columns:e.columns,Rows:[]}:{Status:`Interrupted`,StatusCode:17,HasPrimalSolution:!1,ObjectiveValue:NaN,ObjectiveOffsetApplied:!0,...t?.objectiveBound===void 0?{}:{MipDualBound:t.objectiveBound},...t?.relativeGap===void 0?{}:{MipGap:t.relativeGap},Columns:{},Rows:[]}}function Xt(e){let t=X.values().next().value;if(!t||t.dispatched)return;t.dispatched=!0;let n={},r=!1;t.embeddedWasmBinary!==null&&!qt&&(n.embeddedWasmBinary=t.embeddedWasmBinary,r=!0);try{t.kind===`WARMUP`?e.postMessage({type:`WARMUP`,id:t.id,options:t.workerOptions,...n}):e.postMessage({type:`SOLVE`,id:t.id,lpString:t.lpString,options:t.workerOptions,...n,...t.reportProgress?{reportProgress:!0}:{}}),r&&(qt=!0)}catch(n){X.delete(t.id),t.cleanupAbort?.(),t.reject(n),Xt(e)}}function Zt(){let e=Kt;e&&(Kt=null,qt=!1,e.terminate());for(let e of X.values())e.dispatched=!1;if(X.size>0)try{let e=$t();if(e)Xt(e);else{let e=Error(`[WaSHI] Failed to recreate HiGHS Worker after interruption.`);for(let t of Array.from(X.values()))X.delete(t.id),t.cleanupAbort?.(),t.reject(e)}}catch(e){for(let t of Array.from(X.values()))X.delete(t.id),t.cleanupAbort?.(),t.reject(e)}}function Qt(){return typeof window<`u`&&typeof Worker<`u`&&typeof Worker?.prototype?.unref!=`function`}function $t(){if(!Qt())return null;if(!Kt){let e;try{e=Y(),e.onmessage=t=>{let{type:n,id:r,result:i,runTime:a,error:o,progress:s,incumbent:c}=t.data,l=X.get(r);if(l){if(n===`SOLVE_PROGRESS`){if(l.kind===`SOLVE`&&s){l.lastProgress=s;try{l.onProgress?.(s)}catch(e){let t=X.get(r);if(t){let n=X.keys().next().value;X.delete(r),t.cleanupAbort?.(),n===r&&Zt(),t.reject(e)}}}return}if(n===`SOLVE_INCUMBENT`){l.kind===`SOLVE`&&c&&(l.lastIncumbent=c);return}X.delete(r),l.cleanupAbort?.(),l.kind===`WARMUP`?n===`WARMUP_SUCCESS`?(Kt===e&&l.targetKey,l.resolve()):l.reject(Error(o||`Worker warmup failed`)):n===`SOLVE_SUCCESS`?(Kt===e&&l.targetKey,l.resolve({result:i,runTime:a})):l.reject(Error(o||`Worker solve failed`)),Kt===e&&Xt(e)}};let t=t=>{if(Kt===e){Kt=null,qt=!1,e.terminate();for(let e of X.values())e.cleanupAbort?.(),e.reject(t);X.clear()}};e.onerror=e=>t(Error(`[WaSHI] HiGHS Worker failed to load or execute. Check Worker assets, CORS and CSP. ${e?.message||``}`)),e.onmessageerror=()=>t(Error(`[WaSHI] Could not deserialize the HiGHS Worker response.`)),Kt=e}catch(e){throw Kt=null,e}}return Kt}function en(e){let t=typeof window<`u`?typeof window.origin==`string`?window.origin:window.location?.origin:void 0;return e.useWorker??(typeof window<`u`&&t!==`null`&&!t?.startsWith(`file:`))}function tn(e){if(e.useWorker===!0&&!Qt())throw Error(`[WaSHI] Web Worker execution was requested (useWorker: true), but browser Web Workers are unavailable in this environment.`);return en(e)?$t():null}async function nn(e,t){let n=t?pt(`highs`):mt(`highs`),r=n?.kind===`embedded`?n.bytes:null;if(e.wasmUrl){let t=await Ht(e.wasmUrl);return{wasmUrl:t,embeddedWasmBinary:r,targetKey:`url:${t}`}}if(Vt()){let e=await Ht();return{wasmUrl:e,embeddedWasmBinary:r,targetKey:`url:${e}`}}if(!n)return{wasmUrl:null,embeddedWasmBinary:null,targetKey:null};if(n.kind===`embedded`)return{wasmUrl:null,embeddedWasmBinary:r,targetKey:`__embedded__`};let i=await Ht();return{wasmUrl:i,embeddedWasmBinary:null,targetKey:`url:${i}`}}function rn(e,t){let{signal:n,onProgress:r,onIncumbent:i,...a}=e,o={};for(let[e,t]of Object.entries(a)){if(typeof t==`function`)throw Error(`[WaSHI] HiGHS Worker option "${e}" cannot be a function (functions cannot be cloned across Web Worker boundaries).`);o[e]=t}return t===null?delete o.wasmUrl:o.wasmUrl=t,o}function an(e,t,n){if(!e)return;let r=()=>{let e=X.get(t.id);if(!e)return;let r=X.keys().next().value;X.delete(t.id),e.cleanupAbort?.(),r===t.id&&Zt(),n()};e.addEventListener(`abort`,r,{once:!0}),t.cleanupAbort=()=>e.removeEventListener(`abort`,r)}async function on(e,t={}){if(Lt(t),t.signal?.aborted)return{result:Yt(),runTime:0};let n=await nn(t,!0);if(t.signal?.aborted)return{result:Yt(),runTime:0};let r=tn(t);if(!r)return Gt(e,t);let{signal:i,onProgress:a}=t,o=rn(t,n.wasmUrl),s=!!(a||i),c=`req_${++Jt}`,l=performance.now();return new Promise((t,u)=>{let d={kind:`SOLVE`,id:c,lpString:e,workerOptions:o,embeddedWasmBinary:n.embeddedWasmBinary,targetKey:n.targetKey,reportProgress:s,startTime:l,onProgress:a,resolve:t,reject:u};an(i,d,()=>{let e=(performance.now()-d.startTime)/1e3;d.resolve({result:Yt(d.lastIncumbent,d.lastProgress),runTime:e})}),X.set(c,d),Xt(r)})}function sn(e,t){if(typeof t==`number`)switch(t){case 0:return`NotSolved`;case 1:case 2:case 3:case 4:case 5:return`Error`;case 6:return`Unknown`;case 7:return`Optimal`;case 8:return`Infeasible`;case 9:return`InfeasibleOrUnbounded`;case 10:return`Unbounded`;case 11:return`ObjectiveBound`;case 12:return`ObjectiveTarget`;case 13:return`TimeLimit`;case 14:return`IterationLimit`;case 15:return`Unknown`;case 16:return`SolutionLimit`;case 17:return`Interrupted`;case 18:return`MemoryLimit`}if(typeof e!=`string`)return`Unknown`;let n=e.trim();if(!n)return`Unknown`;switch(n){case`Optimal`:return`Optimal`;case`Infeasible`:return`Infeasible`;case`Unbounded`:return`Unbounded`;case`Primal infeasible or unbounded`:case`InfeasibleOrUnbounded`:return`InfeasibleOrUnbounded`;case`Time limit reached`:case`TimeLimit`:return`TimeLimit`;case`Iteration limit reached`:case`IterationLimit`:return`IterationLimit`;case`Solution limit reached`:case`SolutionLimit`:return`SolutionLimit`;case`Memory limit reached`:case`MemoryLimit`:return`MemoryLimit`;case`Bound on objective reached`:case`ObjectiveBound`:return`ObjectiveBound`;case`Target for objective reached`:case`ObjectiveTarget`:return`ObjectiveTarget`;case`Interrupted`:case`User interrupt`:return`Interrupted`;case`Feasible`:return`Feasible`;case`Not Set`:return`NotSolved`;case`Load error`:case`Model error`:case`Presolve error`:case`Solve error`:case`Postsolve error`:case`Error`:return`Error`;case`Empty`:case`Unknown`:return`Unknown`}return`Unknown`}function cn(e,t,n){switch(sn(e,t)){case`Optimal`:return`Optimal`;case`Infeasible`:return`Infeasible`;case`Unbounded`:return`Unbounded`;case`TimeLimit`:return`TimeLimit`;case`IterationLimit`:return`IterationLimit`;case`Feasible`:return`Feasible`;case`ObjectiveBound`:case`ObjectiveTarget`:case`SolutionLimit`:return n===!1?`Unknown`:`Feasible`;case`MemoryLimit`:case`Interrupted`:return n?`Feasible`:`Unknown`;case`NotSolved`:return`NotSolved`;case`Error`:return`Error`;default:return`Unknown`}}var ln=class e{static capabilities={supportsMIP:!0,supportsQP:!0,supportsWarmStart:!0};name=`HiGHS`;version=`1.15.1`;capabilities=e.capabilities;options;constructor(e={}){this.options=e}async solve(e,t={},n={}){let r=Ge(t),i=r?n:t,a={...this.options,...i};Lt(a);let o=e.objective?.constant??0;if(typeof o!=`number`||!Number.isFinite(o))throw Error(`Solver "${this.name}" encountered non-finite objective constant: ${String(o)}.`);let s=o===0?0:o;for(let t of e.variables)M(t);let{lpString:c,nameToVar:l,nameToConstraint:u}=r?t:Je(e,{relax:a.relax}),d=Object.create(null),f=!1,p=new Set;for(let[e,t]of l.entries()){p.add(t);let n=ae(t);n!==void 0&&(d[e]=n,f=!0)}for(let t of e.variables)if(!p.has(t))throw Error(`LP export symbol map (nameToVar) is missing model variable "${t.name}".`);let m=a;(s!==0||f||m.initialValues!==void 0)&&(m={...m,...s===0?{}:{objectiveOffset:s},...f?{initialValues:d}:{}});let{result:h,runTime:g}=await on(c,m),_=h?.ObjectiveOffsetApplied?0:s,v=sn(h?.Status,h?.StatusCode),y=a.relax?!1:typeof h?.IsMip==`boolean`?h.IsMip:e.variables.some(e=>e.type===`Integer`||e.type===`Binary`),b=h?.HasPrimalSolution===!0,x=cn(h?.Status,h?.StatusCode,b),S=null;b&&typeof h?.ObjectiveValue==`number`&&Number.isFinite(h.ObjectiveValue)&&(S=h.ObjectiveValue+_);let C,w,T;if(typeof h?.MipDualBound==`number`&&Number.isFinite(h.MipDualBound)?C=h.MipDualBound+_:!y&&v===`Optimal`&&S!==null&&(C=S),S!==null&&C!==void 0&&Number.isFinite(C)&&(T=Math.abs(S-C)),_!==0&&y&&S!==null&&C!==void 0&&T!==void 0){if(T===0)w=0;else if(Math.abs(S)>0){let e=T/Math.abs(S);w=Number.isFinite(e)?e:void 0}else w=void 0}else typeof h?.MipGap==`number`&&Number.isFinite(h.MipGap)?w=h.MipGap:y&&v===`Optimal`&&b&&(T===void 0||T===0)&&(w=0);if(!b)return{status:x,terminationStatus:v,hasPrimalSolution:!1,objectiveValue:null,...C===void 0?{}:{objectiveBound:C},...w===void 0?{}:{relativeGap:w},...T===void 0?{}:{absoluteGap:T},values:{},reducedCosts:{},duals:{},slacks:{},runTime:g,raw:h};let E=(e,t,n)=>{Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})},D={},ee={},O={},k={};if(h.Columns)for(let[e,t]of Object.entries(h.Columns)){let n=l.get(e);if(n){if(typeof t.Primal==`number`&&Number.isFinite(t.Primal)){let e=Math.abs(t.Primal)<1e-9?0:t.Primal;!a.relax&&(n.type===`Integer`||n.type===`Binary`)&&Math.abs(e-Math.round(e))<=1e-5&&(e=Math.round(e)+0),E(D,n.name,e)}typeof t.Dual==`number`&&Number.isFinite(t.Dual)&&E(O,n.name,Math.abs(t.Dual)<1e-9?0:t.Dual)}}if(h.Rows){let e=Array.isArray(h.Rows)?h.Rows:Object.values(h.Rows);for(let t of e){let e=t.Name,n=e?u.get(e):void 0;if(n&&(typeof t.Dual==`number`&&Number.isFinite(t.Dual)&&E(ee,n.name,Math.abs(t.Dual)<1e-9?0:t.Dual),typeof t.Primal==`number`&&Number.isFinite(t.Primal))){let e=n.rhs-t.Primal;E(k,n.name,Math.abs(e)<1e-9?0:e)}}}return{status:x,terminationStatus:v,hasPrimalSolution:!0,objectiveValue:S,...C===void 0?{}:{objectiveBound:C},...w===void 0?{}:{relativeGap:w},...T===void 0?{}:{absoluteGap:T},values:D,reducedCosts:O,duals:ee,slacks:k,runTime:g,raw:h}}};function un(){$e(`highs`,e=>new ln(e)),et(e=>new ln(e))}un(),kt();var dn=typeof document<`u`?document.currentScript?.src:null,fn=dn?new URL(`.`,dn).href:null;function pn(e){if(!fn)throw Error(`[WaSHI] Load the browser IIFE using an external script src, or use the browser ESM build.`);return new URL(e,fn).href}function mn(){return pn(`solvers/pumpkin.wasm`)}function hn(){function e(e){let t,n;try{let r=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),i=g,a=_.check_json(r,i);return t=a[0],n=a[1],o(a[0],a[1])}finally{_.__wbindgen_free(t,n,1)}}function t(e,t){let n,r;try{let i=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),s=g,c=_.check_with_callback(i,s,u(t)?0:a(t));return n=c[0],r=c[1],o(c[0],c[1])}finally{_.__wbindgen_free(n,r,1)}}function n(e){let t,n;try{let r=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),i=g,a=_.solve_json(r,i);return t=a[0],n=a[1],o(a[0],a[1])}finally{_.__wbindgen_free(t,n,1)}}function r(e,t,n){let r,i;try{let s=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),c=g,l=_.solve_with_callback(s,c,u(t)?0:a(t),u(n)?0:a(n));return r=l[0],i=l[1],o(l[0],l[1])}finally{_.__wbindgen_free(r,i,1)}}function i(){return{__proto__:null,"./pumpkin_bg.js":{__proto__:null,__wbg___wbindgen_boolean_get_4f1baf9a00be3c74:function(e){let t=e,n=typeof t==`boolean`?t:void 0;return u(n)?16777215:+!!n},__wbg___wbindgen_is_undefined_be5b34249ff1fc15:function(e){return e===void 0},__wbg___wbindgen_throw_4c88d8bf264fd984:function(e,t){throw Error(o(e,t))},__wbg_call_40b008ba32f73991:function(){return l(function(e,t){return e.call(t)},arguments)},__wbg_call_a410eb4b59ed5965:function(){return l(function(e,t,n){return e.call(t,n)},arguments)},__wbg_now_e7c6795a7f81e10f:function(e){return e.now()},__wbg_performance_7e4e4494fdc9d07a:function(e){return e.performance},__wbg_static_accessor_GLOBAL_THIS_003ee833af9699fc:function(){let e=typeof globalThis>`u`?void 0:globalThis;return u(e)?0:a(e)},__wbg_static_accessor_GLOBAL_e4293fb22cbe77da:function(){let e=typeof globalThis>`u`?void 0:globalThis;return u(e)?0:a(e)},__wbg_static_accessor_SELF_53bb20457401453d:function(){let e=typeof self>`u`?void 0:self;return u(e)?0:a(e)},__wbg_static_accessor_WINDOW_b5e0810bfecb7feb:function(){let e=typeof window>`u`?void 0:window;return u(e)?0:a(e)},__wbindgen_generic_0000000000000001:function(e,t){return o(e,t)},__wbindgen_init_externref_table:function(){let e=_.__wbindgen_externrefs;e.set(0,void 0),e.set(1024,void 0),e.set(1025,null),e.set(1026,!0),e.set(1027,!1)}}}}function a(e){let t=_.__externref_table_alloc();return _.__wbindgen_externrefs.set(t,e),t}function o(e,t){return e>>>=0,m(c().subarray(e,e+t))}let s=null;function c(){return(s===null||s.byteLength===0)&&(s=new Uint8Array(_.memory.buffer)),s}function l(e,t){try{return e.apply(this,t)}catch(e){let t=a(e);_.__wbindgen_exn_store(t)}}function u(e){return e==null}function d(e,t,n){if(n===void 0){let n=h.encode(e),r=t(n.length,1)>>>0;return c().subarray(r,r+n.length).set(n),g=n.length,r}let r=e.length,i=t(r,1)>>>0,a=c(),o=0;for(;o<r;o++){let t=e.charCodeAt(o);if(t>127)break;a[i+o]=t}if(o!==r){o!==0&&(e=e.slice(o)),i=n(i,r,r=o+e.length*3,1)>>>0;let t=c().subarray(i+o,i+r),a=h.encodeInto(e,t);o+=a.written,i=n(i,r,o,1)>>>0}return g=o,i}let f=new TextDecoder(`utf-8`,{ignoreBOM:!0});f.decode();let p=0;function m(e){return p+=e.length,p>=2146435072&&(f=new TextDecoder(`utf-8`,{ignoreBOM:!0}),f.decode(),p=e.length),f.decode(e)}let h=new TextEncoder;`encodeInto`in h||(h.encodeInto=function(e,t){let n=h.encode(e);return t.set(n),{read:e.length,written:n.length}});let g=0,_;function v(e,t){if(_=e.exports,s=null,!_||!(_.memory instanceof WebAssembly.Memory)||typeof _.__wbindgen_start!=`function`||typeof _.__wbindgen_malloc!=`function`||typeof _.__wbindgen_free!=`function`||typeof _.check_json!=`function`||typeof _.check_with_callback!=`function`||typeof _.solve_json!=`function`||typeof _.solve_with_callback!=`function`)throw Error(`[WaSHI] Invalid Pumpkin WebAssembly module: missing expected solver exports.`);return _.__wbindgen_start(),_}async function y(e,t){if(typeof Response==`function`&&e instanceof Response){if(!e.ok)throw Error(`failed to fetch Wasm: ${e.status} ${e.statusText} fetching '${e.url}'`);if(typeof WebAssembly.instantiateStreaming==`function`)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if(n(e.type)&&e.headers.get(`Content-Type`)!==`application/wasm`)console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",t);else throw t}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}{let n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}function n(e){switch(e){case`basic`:case`cors`:case`default`:return!0}return!1}}let b;async function x(e){return _===void 0?(b===void 0&&(b=S(e),b.catch(()=>{b=void 0})),b):_}async function S(e){e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn(`using deprecated parameters for the initialization function; pass a single object instead`));let t=i();(typeof e==`string`||typeof Request==`function`&&e instanceof Request||typeof URL==`function`&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:r}=await y(await e,t);return v(n,r)}return{check_json:e,check_with_callback:t,solve_json:n,solve_with_callback:r,__wbg_init:x}}async function gn(e){let t=hn();return await t.__wbg_init({module_or_path:e}),{check_json:t.check_json,check_with_callback:t.check_with_callback,solve_json:t.solve_json,solve_with_callback:t.solve_with_callback}}var _n=r({readBundledPumpkinWasmBytes:()=>yn,readPumpkinWasmFileUrl:()=>vn});async function vn(){throw Error(`This distribution is for browsers. Use the npm entry in Node.js.`)}async function yn(){throw Error(`This distribution is for browsers. Use the npm entry in Node.js.`)}var bn=n((()=>{})),xn=4,Sn=null,Cn=new Map,wn=new Set,Tn=0;function En(){return!1}function Dn(e){return e.byteLength>=8&&e[0]===0&&e[1]===97&&e[2]===115&&e[3]===109}function On(){return Sn}function kn(e,t){if(e!==void 0){let n=Mn(e);return n===null?t?t.kind===`embedded`?{kind:`embedded`,binary:t.bytes,key:`__embedded__`}:{kind:`url`,url:null,key:`__bundled__`}:null:{kind:`url`,url:n,key:`url:${n}`}}return Sn===null?t?t.kind===`embedded`?{kind:`embedded`,binary:t.bytes,key:`__embedded__`}:{kind:`url`,url:null,key:`__bundled__`}:null:{kind:`url`,url:Sn,key:`url:${Sn}`}}function An(){if(typeof Worker>`u`||typeof window>`u`||typeof Worker.prototype.unref==`function`)return!1;let e=typeof window.origin==`string`?window.origin:(()=>{try{return window.location?.origin}catch{return}})();return!(!e||e===`null`||e.startsWith(`file:`))}async function jn(e){if(typeof fetch!=`function`)throw Error(`[WaSHI] Global fetch() is unavailable to load Pumpkin WebAssembly from "${e}"; no CDN fallback is attempted.`);let t;try{t=await fetch(e)}catch(t){throw Error(`[WaSHI] Failed to fetch pumpkin.wasm from "${e}" (no CDN fallback is attempted): ${t instanceof Error?t.message:String(t)}. Ensure pumpkin.wasm is hosted cleanly or call setPumpkinWasmUrl(url).`)}if(!t.ok)throw Error(`[WaSHI] Failed to fetch pumpkin.wasm from "${e}": HTTP ${t.status} ${t.statusText}; no CDN fallback is attempted.`);let n=t.headers?.get(`content-type`)?.toLowerCase()??``;if(n.includes(`text/html`))throw Error(`[WaSHI] Invalid response while loading pumpkin.wasm from "${e}": received HTML ("${n}") instead of a WebAssembly binary; no CDN fallback is attempted.`);let r=await t.arrayBuffer(),i=new Uint8Array(r);if(!Dn(i))throw Error(`[WaSHI] Invalid WebAssembly binary loaded from "${e}": expected \\0asm magic header; no CDN fallback is attempted.`);return i}function Mn(e){if(e===void 0)return Sn;if(e!==null&&typeof e!=`string`)throw Error(`Invalid pumpkin.wasm URL: expected string or null, got ${typeof e}.`);if(e===``)throw Error(`Invalid pumpkin.wasm URL: expected non-empty string or null (received empty string "").`);return e}async function Nn(e){if(e!==null){if(En()&&e.startsWith(`file://`)){let{readPumpkinWasmFileUrl:t}=await Promise.resolve().then(()=>(bn(),_n)),n=await t(new URL(e));if(!Dn(n))throw Error(`[WaSHI] Invalid WebAssembly binary at "${e}": expected \\0asm magic header.`);return n}return jn(e)}if(En()&&typeof window>`u`){let{readBundledPumpkinWasmBytes:e}=await Promise.resolve().then(()=>(bn(),_n)),t=await e();if(!Dn(t))throw Error(`[WaSHI] Bundled pumpkin.wasm on disk has an invalid WebAssembly magic header.`);return t}return jn(mn())}async function Pn(e){let t=kn(e,pt(`pumpkin`));if(!t)throw Error(`[WaSHI] Failed to resolve Pumpkin WASM target.`);let n=t.key,r=Cn.get(n);if(r)return Cn.delete(n),Cn.set(n,r),r;let i=Tn,a=null;for(a=(async()=>{try{let e=await gn(t.kind===`embedded`?t.binary.slice():await Nn(t.url));return Tn===i&&Cn.get(n)===a&&wn.add(n),e}catch(e){throw Tn===i&&(wn.delete(n),Cn.get(n)===a&&Cn.delete(n)),t.kind===`url`&&t.url!==null&&e instanceof Error&&e.message.includes(`Invalid Pumpkin WebAssembly module`)?Error(`[WaSHI] Invalid Pumpkin WebAssembly module loaded from "${t.url}" (${e.message}); no CDN fallback is attempted.`):e}})();Cn.size>=xn;){let e=Cn.keys().next().value;if(e===void 0)break;Cn.delete(e),wn.delete(e)}return Cn.set(n,a),a}function Fn(){let e=pn(`solvers/pumpkin-worker.js`),t=typeof window.origin==`string`?window.origin:window.location?.origin;if(new URL(e).origin===t)return new Worker(e,{type:`module`});let n=URL.createObjectURL(new Blob([`import `+JSON.stringify(e)+`;`],{type:`text/javascript`}));try{let e=new Worker(n,{type:`module`}),t=()=>URL.revokeObjectURL(n);return e.addEventListener(`message`,t,{once:!0}),e.addEventListener(`error`,t,{once:!0}),e}catch(e){throw URL.revokeObjectURL(n),e}}function In(e){if(e===``)throw Error(`Invalid pumpkin.wasm URL: expected non-empty string or null (received empty string "").`);if(e!=null&&typeof e!=`string`)throw Error(`Invalid pumpkin.wasm URL: expected string or null, got ${typeof e}.`)}function Ln(e){return{status:`Unknown`,values:[],boolValues:[],runTime:Math.max((performance.now()-e)/1e3,1e-6)}}function Rn(e,t){let n=Math.max((performance.now()-e)/1e3,1e-6);return t?{status:`Feasible`,terminationStatus:`Interrupted`,objectiveValue:t.objectiveValue,values:t.values,boolValues:t.boolValues,runTime:n}:{status:`Unknown`,terminationStatus:`Interrupted`,objectiveValue:null,values:[],boolValues:[],runTime:n}}function zn(e={}){let t=e.workerFactory??Fn,n=null,r=1,i=null,a=[],o=new Set,s=!1,c=!1;In(e.wasmUrl);let l=e=>{for(o.delete(e),o.add(e);o.size>4;){let e=o.keys().next().value;if(e===void 0)break;o.delete(e)}},u=()=>{o.clear(),s=!1,n&&=(n.onmessage=null,n.onerror=null,n.onmessageerror=null,n.terminate(),null)},d=e=>{i===e&&(i=null),e.cleanupAbort?.()},f=(e,t)=>{d(e),e.resolve(t),v()},p=(e,t)=>{d(e),e.resolve(t),v()},m=(e,t)=>{d(e),e.reject(t),v()},h=e=>{e.type===`check`?f(e,Ln(e.startTimeMs)):p(e,Rn(e.startTimeMs,e.lastIncumbent))},g=(e,t,n)=>{if(typeof e!=`string`)throw Error(`Pumpkin worker response is missing canonical responseJson string.`);let r=JSON.parse(e);if(!r)throw Error(`Pumpkin worker returned an empty success payload.`);if(r.error)throw Error(r.error);return{...r,runTime:typeof t==`number`?t:Math.max((performance.now()-n)/1e3,1e-6)}},_=()=>{if(n)return n;let e=t();return e.onmessage=t=>{let r=t.data,a=i;if(n===e&&r&&a&&r.id===a.id){if(r.type===`SOLVE_PROGRESS`){if(a.type!==`solve`)return;try{if(typeof r.payloadJson!=`string`)throw Error(`Pumpkin worker SOLVE_PROGRESS is missing canonical payloadJson string.`);let t=JSON.parse(r.payloadJson);if(!t)throw Error(`Pumpkin worker SOLVE_PROGRESS returned an empty incumbent payload.`);if(a.lastIncumbent=t,a.onProgress){let e=typeof r.elapsedTime==`number`?r.elapsedTime:Math.max((performance.now()-a.startTimeMs)/1e3,1e-6);a.onProgress({elapsedTime:e,elapsedSeconds:e,objectiveValue:t.objectiveValue})}if(n!==e||i!==a)return;a.signal?.aborted&&(u(),h(a))}catch(t){n===e&&i===a&&(u(),m(a,t))}return}if(r.type===`CHECK_SUCCESS`){if(a.type!==`check`){u(),m(a,Error(`Received "CHECK_SUCCESS" for a solve task.`));return}try{let e=g(r.responseJson,r.runTime,a.startTimeMs);l(a.cacheKey),f(a,e)}catch(t){n===e&&i===a&&(u(),m(a,t))}return}if(r.type===`SOLVE_SUCCESS`){if(a.type!==`solve`){u(),m(a,Error(`Received "SOLVE_SUCCESS" for a check task.`));return}try{let e=g(r.responseJson,r.runTime,a.startTimeMs);l(a.cacheKey),p(a,e)}catch(t){n===e&&i===a&&(u(),m(a,t))}return}if(r.type===`SOLVER_ERROR`){let e=typeof r.error==`string`?r.error:`Pumpkin worker execution failed.`;m(a,Error(e))}}},e.onerror=t=>{if(n!==e)return;let r=i;if(u(),r){let e=t?.message||`Pumpkin Web Worker encountered an unexpected error.`;m(r,Error(e))}},e.onmessageerror=()=>{if(n!==e)return;let t=i;u(),t&&m(t,Error(`Failed to deserialize message from Pumpkin Web Worker.`))},n=e,e},v=()=>{if(!(i||c))for(;a.length>0;){let e=a.shift();if(e.signal?.aborted){e.type===`check`?e.resolve(Ln(e.startTimeMs)):e.resolve(Rn(e.startTimeMs,e.lastIncumbent));continue}if(i=e,e.startTimeMs=performance.now(),e.signal){let t=()=>{i===e&&(u(),h(e))};e.signal.addEventListener(`abort`,t,{once:!0}),e.cleanupAbort=()=>e.signal?.removeEventListener(`abort`,t)}try{let t=_(),n={id:e.id,type:e.type,requestJson:e.requestJson};e.wasmUrl!==void 0&&(n.wasmUrl=e.wasmUrl);let r=!1;e.embeddedWasmBinary!==null&&!s&&(n.embeddedWasmBinary=e.embeddedWasmBinary,r=!0),t.postMessage(n),r&&(s=!0)}catch(t){i===e&&(u(),m(e,t))}return}},y=(t,n)=>{let r=n?pt(`pumpkin`):mt(`pumpkin`),i=r?.kind===`embedded`?r.bytes:null,a=r?r.kind===`embedded`?`__embedded__`:`__bundled__`:null;if(t!==void 0)return In(t),{wasmUrl:t,embeddedWasmBinary:i,cacheKey:t===null?a:`url:${t}`};if(e.wasmUrl!==void 0)return In(e.wasmUrl),{wasmUrl:e.wasmUrl,embeddedWasmBinary:i,cacheKey:e.wasmUrl===null?a:`url:${e.wasmUrl}`};let o=On();return In(o),{wasmUrl:o,embeddedWasmBinary:i,cacheKey:o===null?a:`url:${o}`}},b=e=>new Promise((t,n)=>{a.push(e(t,n)),v()});return{check(e,t){if(c)return Promise.reject(Error(`[WaSHI] Pumpkin worker client has been disposed.`));if(t?.signal?.aborted)return Promise.resolve(Ln(performance.now()));let n=y(e.wasmUrl,!0);return b((i,a)=>({id:r++,type:`check`,requestJson:e.requestJson,wasmUrl:n.wasmUrl,embeddedWasmBinary:n.embeddedWasmBinary,cacheKey:n.cacheKey,signal:t?.signal,startTimeMs:performance.now(),lastIncumbent:null,resolve:i,reject:a}))},solve(e,t){if(c)return Promise.reject(Error(`[WaSHI] Pumpkin worker client has been disposed.`));if(t?.signal?.aborted)return Promise.resolve(Rn(performance.now(),null));let n=y(e.wasmUrl,!0);return b((i,a)=>({id:r++,type:`solve`,requestJson:e.requestJson,wasmUrl:n.wasmUrl,embeddedWasmBinary:n.embeddedWasmBinary,cacheKey:n.cacheKey,signal:t?.signal,onProgress:t?.onProgress,startTimeMs:performance.now(),lastIncumbent:null,resolve:i,reject:a}))},isWarmed(e){if(c||n===null)return!1;let{cacheKey:t}=y(e,!1);return t!==null&&o.has(t)},dispose(){for(c=!0,u();a.length>0;){let e=a.shift();e.cleanupAbort?.(),e.reject(Error(`[WaSHI] Pumpkin worker client disposed.`))}if(i){let e=i;i=null,e.cleanupAbort?.(),e.reject(Error(`[WaSHI] Pumpkin worker client disposed.`))}}}}var Bn=null;function Vn(){return Bn||=zn(),Bn}var Hn=1073741823,Un=2147483646,Wn=1e-6;function Z(e){return Object.is(e,-0)||e===0?0:e}function Gn(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Q(e,t){if(typeof e!=`number`||Number.isNaN(e))throw Error(`PumpkinSolver encountered non-finite numeric value in ${t}.`);if(!Number.isFinite(e))throw Error(`PumpkinSolver only supports bounded finite integers (${t}: got ${e}).`);if(!Number.isInteger(e))throw Error(`PumpkinSolver only supports integer values (${t}: got ${e}).`);let n=Z(e);if(n<-1073741823||n>Hn)throw Error(`Value out of Pumpkin safe 32-bit integer range [-${Hn}, ${Hn}] (${t}: got ${n}).`);return n}function Kn(e){if(e===void 0||e===1/0)return null;if(typeof e!=`number`||Number.isNaN(e)||e<0||!Number.isFinite(e))throw Error(`Invalid timeLimit (${String(e)}): expected a finite non-negative number of seconds.`);if(e===0)return 0;let t=Math.round(e*1e3);if(t>2**53-1)throw Error(`timeLimit (${e}s) exceeds safe millisecond range.`);return Math.max(1,t)}function qn(e){return e instanceof w||typeof e==`object`&&!!e&&`quadTerms`in e}function Jn(e,t,n){if(e.initialValue===void 0)return;if(typeof e.initialValue!=`number`||!Number.isFinite(e.initialValue))throw Error(`Variable "${e.name}" has invalid initialValue: ${String(e.initialValue)} (initialValue must be a finite number).`);if(e.initialValue<t-Wn||e.initialValue>n+Wn)throw Error(`Variable "${e.name}" has initialValue (${e.initialValue}) outside its bounds [${t}, ${n}] (tolerance ${Wn}).`);let r=Z(Math.round(e.initialValue));if(Math.abs(e.initialValue-r)>Wn||r<t||r>n)throw Error(`Variable "${e.name}" of type "${e.type}" has non-integral or out-of-domain initialValue: ${e.initialValue} (must be within ${Wn} of an integer in [${t}, ${n}]).`);return Q(r,`initialValue of variable "${e.name}"`)}function Yn(e){let t=[],n=new Map,r=!1;for(let i=0;i<e.length;i++){let a=e[i],o=String(a.type).toLowerCase();if(o===`continuous`||o===`cont`)throw Error(`PumpkinSolver does not support Continuous variable "${a.name}". Use an Integer or Binary variable, or select a MIP/SMT solver.`);if(n.set(a,i),o===`binary`||o===`bin`){if(typeof a.lb!=`number`||Number.isNaN(a.lb)||typeof a.ub!=`number`||Number.isNaN(a.ub))throw Error(`PumpkinSolver encountered non-finite numeric value in bounds of variable "${a.name}".`);if(a.lb===1/0||a.ub===-1/0||a.lb>a.ub)throw Error(`Variable "${a.name}" has invalid bounds lb (${a.lb}) > ub (${a.ub}).`);if(Number.isFinite(a.lb)&&!Number.isInteger(a.lb)||Number.isFinite(a.ub)&&!Number.isInteger(a.ub))throw Error(`PumpkinSolver only supports integer values (bounds of binary variable "${a.name}").`);let e=a.lb===-1/0?0:Math.max(0,Z(a.lb)),n=a.ub===1/0?1:Math.min(1,Z(a.ub)),i=Jn(a,e,n);e>n?(r=!0,t.push({name:a.name,lb:0,ub:1})):t.push(i===void 0?{name:a.name,lb:e,ub:n}:{name:a.name,lb:e,ub:n,initialValue:i});continue}let s=Q(a.lb,`lower bound of variable "${a.name}"`),c=Q(a.ub,`upper bound of variable "${a.name}"`);if(s>c)throw Error(`Variable "${a.name}" has invalid bounds lb (${s}) > ub (${c}).`);let l=Jn(a,s,c);t.push(l===void 0?{name:a.name,lb:s,ub:c}:{name:a.name,lb:s,ub:c,initialValue:l})}return{vars:t,varIndexMap:n,hasEmptyDomain:r}}function Xn(e,t,n){let r=0;function i(e,n,i){let a=Q(e,`internal ${i} lb`),o=Q(n,`internal ${i} ub`),s=t.length;return t.push({name:`__pumpkin_${i}_${++r}`,lb:a,ub:o,internal:!0}),s}function a(n,r,i){let a=new Map;for(let[t,r]of n.entries()){let n=e.get(t);if(n===void 0)throw Error(`Variable "${t.name}" in ${i} is not registered in the model.`);if(typeof r!=`number`||!Number.isFinite(r))throw Error(`Invalid non-finite coefficient for "${t.name}" in ${i}.`);if(!Number.isInteger(r))throw Error(`PumpkinSolver only supports integer coefficients (variable "${t.name}" in ${i} has ${r}).`);let o=(a.get(n)??0)+Z(r);if(!Number.isSafeInteger(o))throw Error(`Coefficient sum overflow for "${t.name}" in ${i}.`);a.set(n,o)}for(let e of r){let t=(a.get(e.varIndex)??0)+Z(e.coeff);if(!Number.isSafeInteger(t))throw Error(`Coefficient sum overflow in ${i}.`);a.set(e.varIndex,t)}let o=[],s=0;for(let[e,n]of a.entries()){let r=Z(n);if(r===0)continue;let a=t[e];Q(r,`coefficient of "${a.name}" in ${i}`);let c=r*a.lb,l=r*a.ub;if(Q(c,`scaled lower bound of "${a.name}" in ${i}`),Q(l,`scaled upper bound of "${a.name}" in ${i}`),s+=Math.max(Math.abs(c),Math.abs(l)),s>Un)throw Error(`Linear expression magnitude in ${i} exceeds Pumpkin safe 32-bit propagator overflow limit.`);o.push({varIndex:e,coeff:r})}return{terms:o,sumMaxAbs:s}}function o(e,n,r){let i=n,a=n;for(let n of e){let e=t[n.varIndex],r=n.coeff*e.lb,o=n.coeff*e.ub;i+=Math.min(r,o),a+=Math.max(r,o)}return{lb:Q(Z(i),`lower bound of ${r}`),ub:Q(Z(a),`upper bound of ${r}`)}}function s(e,r,a){switch(e.kind){case`abs`:{let o=l(e.arg,r,`${a} abs()`),s=t[o],c=i(s.lb<=0&&s.ub>=0?0:Math.min(Math.abs(s.lb),Math.abs(s.ub)),Math.max(Math.abs(s.lb),Math.abs(s.ub)),`abs`);return n.push({kind:`abs`,argVar:o,outVar:c,owner:r}),c}case`max`:{let o=e.args.map((e,t)=>l(e,r,`${a} max()[${t}]`)),s=i(Math.max(...o.map(e=>t[e].lb)),Math.max(...o.map(e=>t[e].ub)),`max`);return n.push({kind:`max`,argVars:o,outVar:s,owner:r}),s}case`min`:{let o=e.args.map((e,t)=>l(e,r,`${a} min()[${t}]`)),s=i(Math.min(...o.map(e=>t[e].lb)),Math.min(...o.map(e=>t[e].ub)),`min`);return n.push({kind:`min`,argVars:o,outVar:s,owner:r}),s}case`at`:{let o=l(e.index,r,`${a} at() index`),s=e.array.map((e,t)=>l(e,r,`${a} at()[${t}]`)),c=i(Math.min(...s.map(e=>t[e].lb)),Math.max(...s.map(e=>t[e].ub)),`elem`);return n.push({kind:`element`,indexVar:o,arrayVars:s,outVar:c,owner:r}),c}}}function c(e,t,n,r=!1){if(typeof e.constant!=`number`||!Number.isFinite(e.constant))throw Error(`Invalid non-finite constant in ${n}.`);let i;if(r)i=Z(e.constant);else{if(!Number.isInteger(e.constant))throw Error(`PumpkinSolver only supports integer constants (${n}: got ${e.constant}).`);i=Q(Z(e.constant),`constant of ${n}`)}let o=[];if(Array.isArray(e.nonlinearTerms))for(let r of e.nonlinearTerms){if(r.coeff===0)continue;if(typeof r.coeff!=`number`||!Number.isFinite(r.coeff)||!Number.isInteger(r.coeff))throw Error(`PumpkinSolver only supports safe integer coefficients in ${n} (got ${r.coeff}).`);let e=Q(Z(r.coeff),`nonlinear coefficient in ${n}`),i=s(r.atom,t,n);o.push({varIndex:i,coeff:e})}let{terms:c,sumMaxAbs:l}=a(e.terms,o,n);return{terms:c,constant:i,sumMaxAbs:l}}function l(e,r,a){let{terms:s,constant:l}=c(e,r,a);if(s.length===1&&s[0].coeff===1&&l===0)return s[0].varIndex;let{lb:u,ub:d}=o(s,l,a),f=i(u,d,`expr`);if(s.length>0){let e=[...s,{varIndex:f,coeff:-1}],i=Q(Z(-l),`linearEq RHS in ${a}`),o=e.reduce((e,n)=>{let r=t[n.varIndex];return e+Math.max(Math.abs(n.coeff*r.lb),Math.abs(n.coeff*r.ub))},0);if(Math.abs(i)+o>Un)throw Error(`Linear expression magnitude in ${a} exceeds Pumpkin safe 32-bit propagator overflow limit.`);n.push({kind:`linearEq`,terms:e,rhs:i,owner:r})}return f}function u(e,t,n,r){if(typeof t!=`number`||!Number.isFinite(t))throw Error(`Invalid non-finite RHS in ${r}.`);if(!Number.isInteger(t))throw Error(`PumpkinSolver only supports integer RHS (${r}: got ${t}).`);let{terms:i,constant:a,sumMaxAbs:o}=c(e,n,r),s=Q(Z(t-a),`RHS of ${r}`);if(Math.abs(s)+o>Un)throw Error(`Linear expression magnitude in ${r} exceeds Pumpkin safe 32-bit propagator overflow limit.`);return{terms:i,rhs:s}}return{lowerLinExpr:c,materializeExprToVarIndex:l,serializeConstraintSide:u}}function Zn(e,t,n,r,i){if(r.has(e)||e instanceof c||typeof e==`object`&&e&&`name`in e&&`id`in e&&!(`op`in e)&&!(`lhs`in e)&&!(`spec`in e)){let t=e,n=r.get(t);if(n===void 0)throw Error(`Boolean variable "${t.name}" in ${i} is not registered in the model.`);return{kind:`boolVar`,index:n}}if(e instanceof I||`lhs`in e&&`sense`in e&&`rhs`in e){let r=e;if(qn(r.lhs))throw Error(`PumpkinSolver does not support quadratic constraints inside ${i}.`);let{terms:a,rhs:o}=t.serializeConstraintSide(r.lhs,r.rhs,n,i);return{kind:`linear`,terms:a,sense:r.sense,rhs:o}}if(e instanceof h||typeof e==`object`&&e&&`spec`in e&&typeof e.spec==`object`){let r=e.spec;switch(r.kind){case`distinct`:return{kind:`allDifferent`,vars:r.args.map((e,r)=>t.materializeExprToVarIndex(e,n,`${i} distinct()[${r}]`))};case`disjoint`:return{kind:`disjunctive`,tasks:r.tasks.map((e,r)=>({startVar:t.materializeExprToVarIndex(e.start,n,`${i} disjoint()[${r}]`),duration:Q(e.duration,`duration of ${i} disjoint()[${r}]`)}))};case`cumulative`:return{kind:`cumulative`,tasks:r.tasks.map((e,r)=>({startVar:t.materializeExprToVarIndex(e.start,n,`${i} cumulative()[${r}]`),duration:Q(e.duration,`duration of ${i} cumulative()[${r}]`),demand:Q(e.demand,`demand of ${i} cumulative()[${r}]`)})),capacity:Q(r.capacity,`capacity of ${i} cumulative()`)};case`allowed`:return{kind:`table`,vars:r.vars.map((e,r)=>t.materializeExprToVarIndex(e,n,`${i} allowed() vars[${r}]`)),tuples:r.tuples.map((e,t)=>e.map((e,n)=>Q(e,`tuple[${t}][${n}] in ${i}`)))}}}if(e instanceof l||`op`in e&&`children`in e){let a=e;switch(a.op){case`and`:return{kind:`and`,children:a.children.map(e=>Zn(e,t,n,r,i))};case`or`:return{kind:`or`,children:a.children.map(e=>Zn(e,t,n,r,i))};case`not`:if(a.children.length!==1)throw Error(`Invalid 'not' operator arity in ${i}.`);return{kind:`not`,child:Zn(a.children[0],t,n,r,i)};case`implies`:if(a.children.length!==2)throw Error(`Invalid 'implies' operator arity in ${i}.`);return{kind:`implies`,left:Zn(a.children[0],t,n,r,i),right:Zn(a.children[1],t,n,r,i)};case`xor`:return{kind:`xor`,children:a.children.map(e=>Zn(e,t,n,r,i))};default:throw Error(`Unsupported logical operator "${String(a.op)}" in ${i}.`)}}throw Error(`Unsupported logical constraint node in ${i}.`)}function Qn(e){let{vars:t,varIndexMap:n,hasEmptyDomain:r}=Yn(e.variables),i=[],a=Xn(n,t,i),o=e.boolVars??[],s=new Map,c=[];for(let e=0;e<o.length;e++)s.set(o[e],e),c.push(o[e].name);let l=[];for(let t=0;t<e.constraints.length;t++){let r=e.constraints[t],i=`constraint "${r.name}"`,o={kind:`constraint`,index:t};if(r._indicatorMeta){let e=r._indicatorMeta,t=n.get(e.binVar);if(t===void 0)throw Error(`Indicator binary variable "${e.binVar.name}" in ${i} is not registered in the model.`);let{terms:s,rhs:c}=a.serializeConstraintSide(e.targetLhs,e.targetRhs,o,i);l.push({name:r.name,terms:s,sense:e.targetSense,rhs:c,indicator:{binVarIndex:t,activeValue:e.activeValue}});continue}if(qn(r.lhs))throw Error(`PumpkinSolver does not support quadratic constraints (${i}).`);let{terms:s,rhs:c}=a.serializeConstraintSide(r.lhs,r.rhs,o,i);l.push({name:r.name,terms:s,sense:r.sense,rhs:c})}let u=[],d=e.logicalConstraints??[];for(let e=0;e<d.length;e++){let t=d[e],n=`logical constraint "${t.name}"`,r={kind:`logic`,index:e},i=Zn(t.expr,a,r,s,n);u.push({name:t.name,expr:i})}return{vars:t,boolVars:c,constraints:l,logicalConstraints:u,auxPropagators:i,varIndexMap:n,lowerer:a,hasEmptyDomain:r}}function $n(e,t,n){let r={};if(e)for(let[t,n]of e)Gn(r,t,Z(n));let i;if(t&&t.length>0){i={};for(let[e,a]of t)Gn(i,e,a),n&&Gn(r,e,+!!a)}return{values:r,...i===void 0?{}:{boolValues:i}}}function er(e,t){let n={};if(e)for(let[t,r]of e)Gn(n,t,Z(r));if(t)for(let[e,r]of t)Gn(n,e,r);return n}var tr=new Set([`presolve`,`relativeGap`,`absoluteGap`,`threads`,`verbose`,`outputFlag`]),nr=new Set([`timeLimit`,`wasmUrl`,`useWorker`,`signal`,`onProgress`,`relax`]);function rr(e={}){if(e.relax!==void 0){if(typeof e.relax!=`boolean`)throw Error(`Invalid Pumpkin option "relax": expected boolean, got ${typeof e.relax}.`);if(e.relax===!0)throw Error(`PumpkinSolver does not support LP relaxation (relax: true). Use a simplex/IPM solver such as HiGHS or GLPK.`)}for(let t of tr)if(e[t]!==void 0)throw Error(`PumpkinSolver does not support option "${t}".`);for(let[t,n]of Object.entries(e))if(n!==void 0&&!nr.has(t))throw Error(`PumpkinSolver does not support option "${t}".`);if(e.useWorker!==void 0&&typeof e.useWorker!=`boolean`)throw Error(`Invalid Pumpkin option "useWorker": expected boolean, got ${typeof e.useWorker}.`);if(e.onProgress!==void 0&&typeof e.onProgress!=`function`)throw Error(`Invalid Pumpkin option "onProgress": expected function, got ${typeof e.onProgress}.`)}function ir(e){if(e.wasmUrl!==void 0&&e.wasmUrl!==null&&typeof e.wasmUrl!=`string`)throw Error(`Invalid pumpkin.wasm URL: expected string or null, got ${typeof e.wasmUrl}.`);if(e.wasmUrl===``)throw Error(`Invalid pumpkin.wasm URL: expected non-empty string or null (received empty string "").`);return e.wasmUrl}var ar=class e{static capabilities={supportsMIP:!0,supportsQP:!1,supportsQCQP:!1,supportsSMT:!1,supportsLogicalConstraints:!0,supportsUnsatCore:!0,supportsWarmStart:!0};name=`pumpkin`;options;capabilities=e.capabilities;constructor(e={}){this.options=e}async check(e,t={}){let n={...this.options,...t};rr(n);let r=ir(n),i=Kn(n.timeLimit),a=Qn(e);if(n.signal?.aborted)return{status:`Unknown`,values:{},runTime:0};if(a.hasEmptyDomain)return{status:`Unsat`,values:{},unsatCore:[],conflicts:[],runTime:1e-6};let o=JSON.stringify({vars:a.vars,boolVars:a.boolVars,constraints:a.constraints,logicalConstraints:a.logicalConstraints,auxPropagators:a.auxPropagators,timeLimitMs:i}),s=n.useWorker??An(),c;if(s)c=await Vn().check({requestJson:o,wasmUrl:r},{signal:n.signal});else{let e=await Pn(r);if(n.signal?.aborted)return{status:`Unknown`,values:{},runTime:0};let t=performance.now(),i=e.check_with_callback(o,()=>!!n.signal?.aborted),a=Math.max((performance.now()-t)/1e3,1e-6);if(c=JSON.parse(i),c.runTime=a,c.error)throw Error(c.error)}let l=c.runTime??0;if(c.status===`Sat`)return{status:`Sat`,values:er(c.values,c.boolValues),runTime:l};if(c.status===`Unsat`){let e=c.unsatCore?[...c.unsatCore]:[];return{status:`Unsat`,values:{},unsatCore:e,conflicts:e,runTime:l}}return{status:`Unknown`,values:{},runTime:l}}async solve(e,t={}){let n={...this.options,...t};rr(n);let r=ir(n),a=Kn(n.timeLimit),o=i(e.sense),s=Qn(e);if(qn(e.objective))throw Error(`PumpkinSolver does not support quadratic objective expressions (QuadExpr). Use a QP solver such as HiGHS.`);let c=e.objective;if(typeof c.constant!=`number`||!Number.isFinite(c.constant))throw Error(`Invalid non-finite objective constant.`);let l=Z(c.constant),{terms:u,sumMaxAbs:d}=s.lowerer.lowerLinExpr(c,{kind:`objective`},`objective expression`,!0);if(d>Hn)throw Error(`Objective expression magnitude (${d}) exceeds Pumpkin safe 32-bit integer range [-${Hn}, ${Hn}].`);if(n.signal?.aborted)return{status:`Unknown`,terminationStatus:`Interrupted`,hasPrimalSolution:!1,objectiveValue:null,values:{},runTime:0};if(s.hasEmptyDomain)return{status:`Infeasible`,terminationStatus:`Infeasible`,hasPrimalSolution:!1,objectiveValue:null,values:{},runTime:1e-6};let f=JSON.stringify({vars:s.vars,boolVars:s.boolVars,constraints:s.constraints,logicalConstraints:s.logicalConstraints,auxPropagators:s.auxPropagators,sense:o,objectiveTerms:u,objectiveConstant:l,timeLimitMs:a}),p=n.useWorker??An(),m=n.onProgress,h=0,g=m?e=>{h++,m(e)}:void 0,_;if(p)_=await Vn().solve({requestJson:f,wasmUrl:r},{signal:n.signal,onProgress:g});else{let e=await Pn(r);if(n.signal?.aborted)return{status:`Unknown`,terminationStatus:`Interrupted`,hasPrimalSolution:!1,objectiveValue:null,values:{},runTime:0};let t=performance.now(),i=null,a=n.signal,o=g?e=>{try{let n=JSON.parse(e),r=Math.max((performance.now()-t)/1e3,1e-6);return g({elapsedTime:r,elapsedSeconds:r,objectiveValue:n.objectiveValue}),!!a?.aborted}catch(e){return i=e,!0}}:null,s=a?()=>!!a.aborted:null,c=e.solve_with_callback(f,o,s);if(i!==null)throw i;let l=Math.max((performance.now()-t)/1e3,1e-6);if(_=JSON.parse(c),_.runTime=l,_.error)throw Error(_.error)}let v=_.status===`Optimal`||_.status===`Feasible`,y=typeof _.objectiveValue==`number`?Z(_.objectiveValue):null,b=_.runTime??0;v&&h===0&&g&&g({elapsedTime:b,elapsedSeconds:b,...y===null?{}:{objectiveValue:y}});let x=v?$n(_.values,_.boolValues,!0):{values:{}};return{status:_.status,terminationStatus:_.terminationStatus,hasPrimalSolution:v,objectiveValue:y,values:x.values,...x.boolValues===void 0?{}:{boolValues:x.boolValues},runTime:b}}};function or(e){$e(`pumpkin`,t=>new ar(t??e))}or();function sr(e,t){if(e===void 0)return 1e-6;if(typeof e!=`number`||!Number.isFinite(e)||e<0)throw Error(`Invalid ${t}: expected a finite non-negative number, received ${String(e)}.`);return e}function cr(e,t={}){let n=sr(t.feasibilityTolerance,`feasibilityTolerance`),r=sr(t.integralityTolerance,`integralityTolerance`),i=t.evaluateLogicalConstraints===void 0||!!t.evaluateLogicalConstraints,a=t.values!==void 0&&t.values!==null;if(t.values!==void 0&&(typeof t.values!=`object`||t.values===null||Array.isArray(t.values)))throw Error(`Invalid values option: expected a plain object mapping variable names to values.`);let o=t.values,s=[],u=Object.create(null),d=[],f=[],p=0,m=e=>{typeof e==`number`&&!Number.isNaN(e)&&e>p&&(p=e)},g=e=>{s.push(e),Object.prototype.hasOwnProperty.call(u,e.name)||(u[e.name]=[]),u[e.name].push(e),e.type!==`missing_value`&&e.type!==`unchecked_constraint`&&m(e.violation)},_=[],v=[];for(let t of e.variables.values())t.type===`Boolean`?v.push(t):_.push(t);let y=[],b=[];for(let t of e.constraints.values())t instanceof I?y.push(t):b.push(t);let x=new Map,S=new Map,C=0,T=0,E=0,D=0;for(let e of _){let t=a?Object.prototype.hasOwnProperty.call(o,e.name)?o[e.name]:void 0:e.value;if(t==null){f.push(e.name),g({type:`missing_value`,target:`variable`,name:e.name,actual:t??null,violation:1/0,message:`Variable "${e.name}" has no assigned solution value.`});continue}if(typeof t!=`number`||!Number.isFinite(t)){g({type:`non_finite_value`,target:`variable`,name:e.name,actual:t,violation:1/0,message:`Variable "${e.name}" has non-finite or non-numeric value: ${String(t)}.`});continue}x.set(e,t),C++;let i=e.type===`Binary`||e.type===`BINARY`,s=i||e.type===`Integer`||e.type===`INTEGER`,c=i?Math.max(0,e.lb):e.lb,l=i?Math.min(1,e.ub):e.ub,u=typeof e.lb==`number`&&!Number.isNaN(e.lb)&&e.lb!==1/0,d=typeof e.ub==`number`&&!Number.isNaN(e.ub)&&e.ub!==-1/0;if(!u)g({type:`lower_bound`,target:`variable`,name:e.name,actual:t,limit:e.lb,violation:1/0,message:`Variable "${e.name}" has invalid lower bound (${String(e.lb)}).`});else if(c!==-1/0){let r=t-c,i=Math.max(0,c-t);m(i),i>n&&g({type:`lower_bound`,target:`variable`,name:e.name,actual:t,limit:c,violation:i,signedViolation:r,message:`Variable "${e.name}" value (${t}) violates lower bound (${c}) by ${i}.`})}if(!d)g({type:`upper_bound`,target:`variable`,name:e.name,actual:t,limit:e.ub,violation:1/0,message:`Variable "${e.name}" has invalid upper bound (${String(e.ub)}).`});else if(l!==1/0){let r=t-l,i=Math.max(0,t-l);m(i),i>n&&g({type:`upper_bound`,target:`variable`,name:e.name,actual:t,limit:l,violation:i,signedViolation:r,message:`Variable "${e.name}" value (${t}) violates upper bound (${l}) by ${i}.`})}if(u&&d&&c>l&&c-t<=n&&t-l<=n){let n=c-l;g({type:`lower_bound`,target:`variable`,name:e.name,actual:t,limit:c,violation:n,signedViolation:t-c,message:`Variable "${e.name}" has inverted bounds [${c}, ${l}].`})}if(s){let n=Math.round(t),a=t-n,o=Math.abs(a);m(o),o>r&&g({type:`integrality`,target:`variable`,name:e.name,varType:i?`Binary`:`Integer`,actual:t,nearestInteger:n,violation:o,signedViolation:a,message:`${i?`Binary`:`Integer`} variable "${e.name}" value (${t}) violates integrality by ${o} (nearest integer: ${n}).`})}}for(let e of v){let t=a?Object.prototype.hasOwnProperty.call(o,e.name)?o[e.name]:void 0:e.value;if(t==null){f.push(e.name),g({type:`missing_value`,target:`bool_variable`,name:e.name,actual:t??null,violation:1/0,message:`Boolean variable "${e.name}" has no assigned solution value.`});continue}if(typeof t!=`boolean`){g({type:`invalid_boolean_value`,target:`bool_variable`,name:e.name,actual:t,violation:1/0,message:`Boolean variable "${e.name}" has non-boolean value: ${String(t)}.`});continue}S.set(e,t),T++}let ee=e=>{switch(e.kind){case`abs`:{let t=O(e.arg);return t.ok?{ok:!0,value:Math.abs(t.value),...t.atDomainError?{atDomainError:t.atDomainError}:{}}:t}case`max`:{let t=-1/0,n;for(let r of e.args){let e=O(r);if(!e.ok)return e;!n&&e.atDomainError&&(n=e.atDomainError),e.value>t&&(t=e.value)}return{ok:!0,value:t,...n?{atDomainError:n}:{}}}case`min`:{let t=1/0,n;for(let r of e.args){let e=O(r);if(!e.ok)return e;!n&&e.atDomainError&&(n=e.atDomainError),e.value<t&&(t=e.value)}return{ok:!0,value:t,...n?{atDomainError:n}:{}}}case`at`:{let t=O(e.index);if(!t.ok)return t;let i=t.value,a=e.array.length-1,o=Math.max(0,-i),s=Math.max(0,i-a),c=Math.max(o,s),l=Math.abs(i-Math.round(i));if(c>n||l>r)return{ok:!0,value:0,atDomainError:{violation:Math.max(c,l),message:`at() index (${i}) violates valid integer range [0, ${a}].`}};let u=O(e.array[Math.round(i)]);return u.ok?{ok:!0,value:u.value,...t.atDomainError??u.atDomainError?{atDomainError:t.atDomainError??u.atDomainError}:{}}:u}}},O=e=>{let t=e.constant===void 0?0:e.constant;if(typeof t!=`number`||!Number.isFinite(t))return{ok:!1,reason:`non-finite constant (${String(t)})`};let n=t;for(let[t,r]of e.terms){if(typeof r!=`number`||!Number.isFinite(r))return{ok:!1,reason:`non-finite coefficient (${String(r)}) for variable "${t.name}"`};if(r!==0){if(!x.has(t))return{ok:!1,reason:`missing or invalid value for variable "${t.name}"`};if(n+=r*x.get(t),!Number.isFinite(n))return{ok:!1,reason:`linear expression evaluation overflowed finite range`}}}let r;for(let t of e.nonlinearTerms??[]){if(typeof t.coeff!=`number`||!Number.isFinite(t.coeff))return{ok:!1,reason:`non-finite nonlinear coefficient (${String(t.coeff)})`};let e=ee(t.atom);if(!e.ok)return e;if(!r&&e.atDomainError&&(r=e.atDomainError),t.coeff!==0&&(n+=t.coeff*e.value,!Number.isFinite(n)))return{ok:!1,reason:`expression evaluation overflowed finite range`}}return{ok:!0,value:n,...r?{atDomainError:r}:{}}},k=e=>{switch(e.kind){case`abs`:return A(e.arg);case`max`:case`min`:{let t=[];for(let n of e.args){let e=A(n);if(!e.ok)return e;t.push(...e.errors)}return{ok:!0,errors:t}}case`at`:{let t=[],i=A(e.index);if(!i.ok)return i;t.push(...i.errors);for(let n of e.array){let e=A(n);if(!e.ok)return e;t.push(...e.errors)}let a=O(e.index);if(!a.ok)return a;if(i.errors.length===0){let i=a.value,o=e.array.length-1,s=Math.max(0,-i),c=Math.max(0,i-o),l=Math.max(s,c),u=Math.abs(i-Math.round(i));if(l>n||u>r){let e=Math.max(l,u);t.push({violation:e,message:`at() index (${i}) violates valid integer range [0, ${o}].`})}}return{ok:!0,errors:t}}}},A=e=>{let t=[];for(let n of e.nonlinearTerms??[]){let e=k(n.atom);if(!e.ok)return e;t.push(...e.errors)}return{ok:!0,errors:t}},te=e=>{if(e instanceof c)return{ok:!0};if(e instanceof I){let t=A(e.lhs);return t.ok?{ok:!0,...t.errors.length>0?{firstError:t.errors[0]}:{}}:t}if(e instanceof h){let t=e.spec,n=t.kind===`distinct`?t.args:t.kind===`disjoint`||t.kind===`cumulative`?t.tasks.map(e=>e.start):t.vars;for(let e of n){let t=A(e);if(!t.ok)return t;if(t.errors.length>0)return{ok:!0,firstError:t.errors[0]}}return{ok:!0}}if(e instanceof l){let t;for(let n of e.children){let e=te(n);if(!e.ok)return e;!t&&e.firstError&&(t=e.firstError)}return{ok:!0,...t?{firstError:t}:{}}}return{ok:!0}},ne=(e,t=n)=>{if(typeof e.rhs!=`number`||!Number.isFinite(e.rhs))return{status:`unchecked`,reason:`non-finite right-hand side (${String(e.rhs)})`};let r=A(e.lhs);if(!r.ok)return{status:`unchecked`,reason:r.reason};let i=O(e.lhs);if(!i.ok)return{status:`unchecked`,reason:i.reason};if(r.errors.length>0||i.atDomainError){let t=r.errors[0]??i.atDomainError;return{status:`violated`,lhsVal:i.value,signed:i.value-e.rhs,violation:t.violation,message:`Constraint "${e.name}" invalid element lookup: ${t.message}`}}let a=i.value,o=a-e.rhs;if(!Number.isFinite(o))return{status:`unchecked`,reason:`constraint residual overflowed finite range`};let s=e.sense===`<=`?Math.max(0,o):e.sense===`>=`?Math.max(0,-o):e.sense===`!=`?Math.max(0,1-Math.abs(o)):Math.abs(o);return s>t?{status:`violated`,lhsVal:a,signed:o,violation:s,message:`Constraint "${e.name}" (${a} ${e.sense} ${e.rhs}) violated by ${s}.`}:{status:`satisfied`,lhsVal:a,signed:o,violation:s}},re=e.objective();if((re instanceof w||re instanceof z)&&re.nonlinearTerms.length>0){let e=A(new z(new Map,0,re.nonlinearTerms));if(e.ok)for(let t of e.errors)g({type:`linear_constraint`,target:`constraint`,name:`objective_at`,violation:t.violation,message:`Objective at() lookup failed: ${t.message}`})}for(let e of y){let t=ne(e);t.status===`unchecked`?(d.push(e.name),g({type:`unchecked_constraint`,target:`constraint`,name:e.name,sense:e.sense,limit:e.rhs,rhs:e.rhs,violation:1/0,message:`Constraint "${e.name}" could not be evaluated: ${t.reason}.`})):t.status===`violated`?(E++,g({type:`linear_constraint`,target:`constraint`,name:e.name,sense:e.sense,actual:t.lhsVal,limit:e.rhs,rhs:e.rhs,violation:t.violation,signedViolation:t.signed,message:t.message})):(E++,m(t.violation))}let ie=e=>{if(e instanceof c)return S.has(e)?{ok:!0,value:S.get(e),violation:0}:{ok:!1,reason:`missing or invalid value for Boolean variable "${e.name}"`};if(e instanceof I){if(e.sense===`!=`){let t=O(e.lhs);if(!t.ok)return{ok:!1,reason:t.reason};if(t.atDomainError)return{ok:!1,reason:t.atDomainError.message};let r=Math.abs(t.value-e.rhs);return r<=n?{ok:!0,value:!1,violation:0}:r>=1-n?{ok:!0,value:!0,violation:0}:{ok:!1,reason:`discrete comparison "${e.name}" lies between 0 and 1 (${t.value} != ${e.rhs})`}}let t=ne(e,0);if(t.status===`unchecked`)return{ok:!1,reason:t.reason};if(n>0){let r=Math.abs(t.lhsVal-e.rhs);if(r>0&&r<=n)return{ok:!1,reason:`numeric comparison "${e.name}" lies within feasibilityTolerance (${n}) of boundary (${t.lhsVal} vs ${e.rhs})`}}return{ok:!0,value:t.status===`satisfied`,violation:0}}if(e instanceof h){let t=e.spec;if(t.kind===`distinct`){let e=[];for(let n of t.args){let t=O(n);if(!t.ok)return t;if(t.atDomainError)return{ok:!1,reason:t.atDomainError.message};e.push(t.value)}for(let t=0;t<e.length;t++)for(let r=t+1;r<e.length;r++){let i=Math.abs(e[t]-e[r]);if(i<=n)return{ok:!0,value:!1,violation:0};if(i<1-n)return{ok:!1,reason:`distinct() operands at indices (${t}, ${r}) have fractional gap (${i})`}}return{ok:!0,value:!0,violation:0}}if(t.kind===`disjoint`){let e=[];for(let n of t.tasks){let t=O(n.start);if(!t.ok)return t;if(t.atDomainError)return{ok:!1,reason:t.atDomainError.message};e.push(t.value)}for(let r=0;r<t.tasks.length;r++)for(let i=r+1;i<t.tasks.length;i++){let a=e[r],o=t.tasks[r].duration,s=e[i],c=t.tasks[i].duration;if(!(a+o<=s+n||s+c<=a+n))return{ok:!0,value:!1,violation:0}}return{ok:!0,value:!0,violation:0}}if(t.kind===`cumulative`){let e=[];for(let n of t.tasks){let t=O(n.start);if(!t.ok)return t;if(t.atDomainError)return{ok:!1,reason:t.atDomainError.message};e.push(t.value)}let r=[];for(let n=0;n<t.tasks.length;n++){let i=t.tasks[n];if(i.duration>0&&i.demand>0){if(i.demand>t.capacity)return{ok:!0,value:!1,violation:0};r.push({start:e[n],duration:i.duration,demand:i.demand})}}for(let e=0;e<r.length;e++){let i=r[e].start,a=0;for(let e=0;e<r.length;e++){let t=r[e];t.start-n<=i&&i<t.start+t.duration-n&&(a+=t.demand)}if(a>t.capacity+n)return{ok:!0,value:!1,violation:0}}return{ok:!0,value:!0,violation:0}}if(t.kind===`allowed`){let e=[];for(let n of t.vars){let t=O(n);if(!t.ok)return t;if(t.atDomainError)return{ok:!1,reason:t.atDomainError.message};e.push(t.value)}return{ok:!0,value:t.tuples.some(t=>t.every((t,r)=>Math.abs(e[r]-t)<=n)),violation:0}}}if(e instanceof l)switch(e.op){case`not`:{let t=ie(e.children[0]);return t.ok?{ok:!0,value:!t.value,violation:0}:t}case`and`:{let t=0;for(let n of e.children){let e=ie(n);if(!e.ok)return e;if(!e.value)return{ok:!0,value:!1,violation:0};e.violation>t&&(t=e.violation)}return{ok:!0,value:!0,violation:t}}case`or`:{let t=!1,n=1/0;for(let r of e.children){let e=ie(r);if(!e.ok)return e;e.value&&(t=!0,e.violation<n&&(n=e.violation))}return{ok:!0,value:t,violation:t?n:0}}case`implies`:{let t=ie(e.children[0]);if(!t.ok)return t;if(!t.value)return{ok:!0,value:!0,violation:0};let n=ie(e.children[1]);return n.ok?{ok:!0,value:n.value,violation:n.value?n.violation:0}:n}case`xor`:{let t=!1,n=0;for(let r of e.children){let e=ie(r);if(!e.ok)return e;e.value&&(t=!t,e.violation>n&&(n=e.violation))}return{ok:!0,value:t,violation:t?n:0}}default:return{ok:!1,reason:`unsupported logical operator "${String(e.op)}"`}}return{ok:!1,reason:`unsupported logical expression node`}};for(let e=0;e<b.length;e++){let t=b[e],n=t.name||`lc_${e+1}`;if(!i){d.push(n),g({type:`unchecked_constraint`,target:`logical_constraint`,name:n,violation:1/0,message:`Logical constraint "${n}" was not evaluated because evaluateLogicalConstraints is false.`});continue}let r=te(t.expr);if(!r.ok){d.push(n),g({type:`unchecked_constraint`,target:`logical_constraint`,name:n,violation:1/0,message:`Logical constraint "${n}" could not be evaluated: ${r.reason}.`});continue}if(r.firstError){D++,g({type:`logical_constraint`,target:`logical_constraint`,name:n,actual:!1,limit:!0,violation:r.firstError.violation,signedViolation:-1,message:`Logical constraint "${n}" invalid element lookup: ${r.firstError.message}`});continue}let a=ie(t.expr);if(!a.ok){d.push(n),g({type:`unchecked_constraint`,target:`logical_constraint`,name:n,violation:1/0,message:`Logical constraint "${n}" could not be evaluated: ${a.reason}.`});continue}D++,a.value?m(a.violation):g({type:`logical_constraint`,target:`logical_constraint`,name:n,actual:!1,limit:!0,violation:1,signedViolation:-1,message:`Logical constraint "${n}" evaluated to false.`})}let j=C===_.length&&T===v.length&&E===y.length&&D===b.length&&d.length===0&&f.length===0;return{valid:j&&s.length===0,complete:j,violations:s,violationsByName:u,uncheckedConstraints:d,missingVariables:f,maxViolation:p,summary:{checkedVariables:C,totalVariables:_.length,checkedBoolVariables:T,totalBoolVariables:v.length,checkedLinearConstraints:E,totalLinearConstraints:y.length,checkedLogicalConstraints:D,totalLogicalConstraints:b.length}}}function lr(e,t){if(typeof e!=`number`||!Number.isFinite(e)||e<=0)throw Error(`Invalid Big-M value for indicator constraint "${t}": expected a finite positive number, received ${e}.`)}function ur(e,t,n){let r=e.constant===void 0?0:e.constant;if(!Number.isFinite(t)||!Number.isFinite(r))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": constraint contains non-finite constant (${r}) or right-hand side (${t}).`);let i=t-r;if(!Number.isFinite(i))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": effective right-hand side (${t} - ${r}) overflows finite floating-point range. Please rescale coefficients/constants.`);for(let[t,r]of e.terms){if(!Number.isFinite(r))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" has non-finite coefficient (${r}).`);if(Number.isNaN(t.lb)||Number.isNaN(t.ub)||t.lb===1/0||t.ub===-1/0||t.lb>t.ub)throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" has invalid bounds [${t.lb}, ${t.ub}].`)}return i}function dr(e,t,n){let r=ur(e,t,n),i=0;for(let[t,r]of e.terms){if(r===0)continue;let e;if(r>0){if(!Number.isFinite(t.ub))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" lacks a finite upper bound (required because coefficient ${r} is positive in <= constraint). Please set an explicit finite upper bound on the variable or specify { M } explicitly in indicator options.`);e=t.ub}else{if(!Number.isFinite(t.lb))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" lacks a finite lower bound (required because coefficient ${r} is negative in <= constraint). Please set an explicit finite lower bound on the variable or specify { M } explicitly in indicator options.`);e=t.lb}let a=r*e;if(i+=a,!Number.isFinite(a)||!Number.isFinite(i))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": numeric overflow while bounding contribution of variable "${t.name}". Please rescale coefficients/bounds or specify a finite { M } explicitly.`)}let a=i-r;if(!Number.isFinite(a))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": numeric overflow while computing Big-M (${i} - ${r}). Please rescale coefficients/bounds or specify a finite { M } explicitly.`);let o=Math.max(0,a);if(!Number.isFinite(o)||!Number.isFinite(r+o))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": derived Big-M (${o}) or shifted right-hand side overflows finite floating-point range. Please rescale coefficients/bounds or specify a finite { M } explicitly.`);return o}function fr(e,t,n){let r=ur(e,t,n),i=0;for(let[t,r]of e.terms){if(r===0)continue;let e;if(r>0){if(!Number.isFinite(t.lb))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" lacks a finite lower bound (required because coefficient ${r} is positive in >= constraint). Please set an explicit finite lower bound on the variable or specify { M } explicitly in indicator options.`);e=t.lb}else{if(!Number.isFinite(t.ub))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" lacks a finite upper bound (required because coefficient ${r} is negative in >= constraint). Please set an explicit finite upper bound on the variable or specify { M } explicitly in indicator options.`);e=t.ub}let a=r*e;if(i+=a,!Number.isFinite(a)||!Number.isFinite(i))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": numeric overflow while bounding contribution of variable "${t.name}". Please rescale coefficients/bounds or specify a finite { M } explicitly.`)}let a=r-i;if(!Number.isFinite(a))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": numeric overflow while computing Big-M (${r} - ${i}). Please rescale coefficients/bounds or specify a finite { M } explicitly.`);let o=Math.max(0,a);if(!Number.isFinite(o)||!Number.isFinite(r-o))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": derived Big-M (${o}) or shifted right-hand side overflows finite floating-point range. Please rescale coefficients/bounds or specify a finite { M } explicitly.`);return o}function pr(e,t,n,r,i,a,o){if(!(e instanceof H&&(e.type===`Binary`||e.type===`Integer`&&e.lb===0&&e.ub===1)))throw Error(`Indicator variable "${e?.name??String(e)}" must be a Binary variable (or Integer variable with bounds [0, 1]), received "${e?.type??typeof e}" with bounds [${e?.lb}, ${e?.ub}].`);if(!Number.isFinite(e.lb)||!Number.isFinite(e.ub)||e.lb<0||e.ub>1||e.lb>e.ub)throw Error(`Binary indicator variable "${e.name}" has invalid bounds [${e.lb}, ${e.ub}]. Binary variables must stay within [0, 1] with lb <= ub.`);let s=ur(t,r,o);if(i!==0&&i!==1)throw Error(`Invalid activeValue: ${i}. Indicator activation value must be 0 or 1.`);if(n!==`<=`&&n!==`>=`)throw Error(`Invalid indicator sense for "${o}": expected "<=" or ">=", received "${String(n)}".`);if(!Number.isFinite(a)||a<0)throw Error(`Invalid Big-M value for indicator constraint "${o}": expected a finite non-negative number, received ${a}.`);let c=t.terms.get(e);if(c!==void 0&&c!==0)throw Error(`Indicator constraint "${o}" cannot include its own binary activation variable "${e.name}" in the linear expression.`);let l,u;if(i===1?n===`<=`?(l=a,u=s+a):(l=-a,u=s-a):n===`<=`?(l=-a,u=s):(l=a,u=s),!Number.isFinite(u))throw Error(`Cannot construct finite indicator constraint "${o}": shifted right-hand side overflows finite floating-point range. Please rescale coefficients/bounds or specify a smaller finite { M }.`);let d=new Map;for(let[e,n]of t.terms)n!==0&&d.set(e,n);return l!==0&&d.set(e,l),{lhs:new z(d,0),rhs:u}}function $(e,t=0){let n=new Map;for(let[t,r]of e){if(r===0)continue;let e=(n.get(t)??0)+r;e===0?n.delete(t):n.set(t,e)}return new z(n,t)}function mr(e,t,n=1){if(n!==0){e.constant+=t.constant*n;for(let[r,i]of t.terms.entries())i!==0&&e.addTerm(r,i*n)}}var hr=5e3,gr=25e3;function _r(e,t,n,r,a){let o=[...e],s=[],u=new Map,d=new Map,f=new Set,p=[];for(let e of n)if(e.sense===`!=`||e.lhs.hasNonlinearTerms())p.push(e);else{let t=e;if(f.has(t.name)){let n=1;for(;f.has(`${e.name}_${n}`);)n++;t=new I(e.lhs,e.sense,e.rhs,`${e.name}_${n}`)}f.add(t.name),s.push(t),d.set(t,e.name)}let m=new Set(e.map(e=>e.name)),g=0;function _(e){let t;do t=`__washi_${e}_${++g}`;while(m.has(t));return m.add(t),t}function v(e,t){let n=e.name||`c`,r=n;if(f.has(r)){let t=1;for(;f.has(`${n}_${t}`);)t++;r=`${n}_${t}`,e=new I(e.lhs,e.sense,e.rhs,r)}f.add(r),s.push(e),d.set(e,t)}for(let e of t){let t=e.name;m.has(t)?t=_(`bool_${e.name}`):m.add(t);let n=new H({name:t,type:`Binary`,lb:0,ub:1});u.set(e,n),o.push(n)}function y(e,t){if(!Number.isFinite(e.constant))throw Error(`Cannot linearize piecewise expression in "${t}": non-finite constant (${e.constant}).`);let n=e.constant,r=e.constant,i=Number.isSafeInteger(e.constant);for(let[a,o]of e.terms.entries()){if(!Number.isFinite(o))throw Error(`Cannot linearize piecewise expression in "${t}": variable "${a.name}" has non-finite coefficient (${o}).`);if(o===0)continue;if(typeof a.lb!=`number`||typeof a.ub!=`number`||Number.isNaN(a.lb)||Number.isNaN(a.ub)||a.lb===-1/0||a.ub===1/0||a.lb>a.ub)throw Error(`Cannot linearize non-convex piecewise expression in "${t}": variable "${a.name}" has unbounded or invalid domain [${a.lb}, ${a.ub}]. Finite bounds are required.`);let e=a.lb,s=a.ub;if(a.type===`Binary`){let t=Math.max(0,Math.ceil(a.lb)),n=Math.min(1,Math.floor(a.ub));t<=n&&(e=t,s=n)}else if(a.type===`Integer`){let t=Math.ceil(a.lb),n=Math.floor(a.ub);t<=n&&(e=t,s=n)}let c=o*e,l=o*s;if(n+=Math.min(c,l),r+=Math.max(c,l),!Number.isFinite(n)||!Number.isFinite(r))throw Error(`Cannot linearize non-convex piecewise expression in "${t}": bound calculation overflowed.`);i&&=(a.type===`Integer`||a.type===`Binary`)&&Number.isSafeInteger(o)&&Number.isSafeInteger(e)&&Number.isSafeInteger(s)}return{lb:Object.is(n,-0)?0:n,ub:Object.is(r,-0)?0:r,isDiscrete:i}}function b(e,t){if(!e.hasNonlinearTerms())return e.clone();let n=new z(e.terms,e.constant);for(let r of e.nonlinearTerms)r.coeff!==0&&mr(n,x(r.atom,t),r.coeff);return n}function x(e,t){switch(e.kind){case`abs`:{let n=b(e.arg,t),{lb:r,ub:i,isDiscrete:a}=y(n,t);if(r>=0)return n;if(i<=0)return n.mul(-1);let s=Math.max(-r,i),c=new H({name:_(`abs_t`),type:a?`Integer`:`Continuous`,lb:0,ub:s}),l=new H({name:_(`abs_z`),type:`Binary`,lb:0,ub:1});o.push(c,l);let u=$([[c,1]],0);return P(new I(n.sub(u),`<=`,0,`${t}_abs_pos`),t),P(new I(n.mul(-1).sub(u),`<=`,0,`${t}_abs_neg`),t),P(new I(u.sub(n).add($([[l,2*-r]],0)),`<=`,2*-r,`${t}_abs_hi_pos`),t),P(new I(u.add(n).sub($([[l,2*i]],0)),`<=`,0,`${t}_abs_hi_neg`),t),u}case`max`:{let n=e.args.map(e=>b(e,t));if(n.length===1)return n[0];let r=n.map(e=>y(e,t)),i=Math.max(...r.map(e=>e.lb)),a=Math.max(...r.map(e=>e.ub)),s=r.every(e=>e.isDiscrete),c=new H({name:_(`max_t`),type:s?`Integer`:`Continuous`,lb:i,ub:a});o.push(c);let l=$([[c,1]],0),u=[];for(let e=0;e<n.length;e++){let i=new H({name:_(`max_z_${e}`),type:`Binary`,lb:0,ub:1});o.push(i),u.push(i),P(new I(n[e].sub(l),`<=`,0,`${t}_max_lb_${e}`),t);let s=a-r[e].lb;P(new I(l.sub(n[e]).add($([[i,s]],0)),`<=`,s,`${t}_max_ub_${e}`),t)}return v(new I($(u.map(e=>[e,1]),0),`==`,1,`${t}_max_sos`),t),l}case`min`:{let n=e.args.map(e=>b(e,t));if(n.length===1)return n[0];let r=n.map(e=>y(e,t)),i=Math.min(...r.map(e=>e.lb)),a=Math.min(...r.map(e=>e.ub)),s=r.every(e=>e.isDiscrete),c=new H({name:_(`min_t`),type:s?`Integer`:`Continuous`,lb:i,ub:a});o.push(c);let l=$([[c,1]],0),u=[];for(let e=0;e<n.length;e++){let a=new H({name:_(`min_z_${e}`),type:`Binary`,lb:0,ub:1});o.push(a),u.push(a),P(new I(n[e].sub(l),`>=`,0,`${t}_min_ub_${e}`),t);let s=r[e].ub-i;P(new I(n[e].sub(l).add($([[a,s]],0)),`<=`,s,`${t}_min_lb_${e}`),t)}return v(new I($(u.map(e=>[e,1]),0),`==`,1,`${t}_min_sos`),t),l}case`at`:{let n=e.array.length,r=b(e.index,t),i=e.array.map(e=>b(e,t)),a=[];for(let e=0;e<n;e++){let t=new H({name:_(`at_lam_${e}`),type:`Binary`,lb:0,ub:1});o.push(t),a.push(t)}v(new I($(a.map(e=>[e,1]),0),`==`,1,`${t}_at_sos`),t);let s=r.clone();for(let e=1;e<n;e++)s.addTerm(a[e],-e);P(new I(s,`==`,0,`${t}_at_idx`),t);let c=new z(new Map,0);for(let e=0;e<n;e++){let n=i[e];if(n.terms.size===0)n.constant!==0&&c.addTerm(a[e],n.constant);else{let{lb:r,ub:i,isDiscrete:s}=y(n,t),l=new H({name:_(`at_w_${e}`),type:s?`Integer`:`Continuous`,lb:Math.min(0,r),ub:Math.max(0,i)});o.push(l);let u=$([[l,1]],0);P(new I($([[l,1],[a[e],-r]],0),`>=`,0,`${t}_at_mc1_${e}`),t),P(new I($([[l,1],[a[e],-i]],0),`<=`,0,`${t}_at_mc2_${e}`),t),P(new I(u.sub(n).add($([[a[e],-i]],0)),`>=`,-i,`${t}_at_mc3_${e}`),t),P(new I(u.sub(n).add($([[a[e],-r]],0)),`<=`,-r,`${t}_at_mc4_${e}`),t),c.addTerm(l,1)}}return c}}}function S(e,t,n){if(t===`upper`&&e.kind===`max`){let t=new H({name:_(`epi_max`),type:`Continuous`,lb:-1/0,ub:1/0});o.push(t);let r=$([[t,1]],0);for(let t=0;t<e.args.length;t++)T(e.args[t].sub(r),`<=`,0,`${n}_epi_max_${t}`,n);return r}if(t===`upper`&&e.kind===`abs`){let t=e.arg.hasNonlinearTerms()?b(e.arg,n):e.arg,r=new H({name:_(`epi_abs`),type:`Continuous`,lb:0,ub:1/0});o.push(r);let i=$([[r,1]],0);return P(new I(t.sub(i),`<=`,0,`${n}_epi_abs_pos`),n),P(new I(t.mul(-1).sub(i),`<=`,0,`${n}_epi_abs_neg`),n),i}if(t===`lower`&&e.kind===`min`){let t=new H({name:_(`epi_min`),type:`Continuous`,lb:-1/0,ub:1/0});o.push(t);let r=$([[t,1]],0);for(let t=0;t<e.args.length;t++)T(e.args[t].sub(r),`>=`,0,`${n}_epi_min_${t}`,n);return r}return x(e,n)}function C(e,t,n){if(!e.hasNonlinearTerms())return e;if(t===`==`||t===`!=`)return b(e,n);let r=new z(e.terms,e.constant);for(let i of e.nonlinearTerms){if(i.coeff===0)continue;let e=t===`<=`?i.coeff>0?`upper`:`lower`:i.coeff>0?`lower`:`upper`;mr(r,S(i.atom,e,n),i.coeff)}return r}function T(e,t,n,r,i){let a=C(e,t,i);if(t===`!=`){ce(new I(a,`==`,n,r),i);return}P(new I(a,t,n,r),i)}function E(e,t){return e.lhs.hasNonlinearTerms()?new I(b(e.lhs,t),e.sense,e.rhs,e.name):e}function D(e,t){if(e instanceof c){let n=u.get(e);if(!n)throw Error(`Unregistered BoolVar "${e.name}" in logical constraint "${t}".`);return n}let n=new H({name:_(`expr`),type:`Binary`,lb:0,ub:1});return o.push(n),O(n,e,t),n}function ee(e,t,n,r){v(new I($([[e,1],[t,-1],[n,-1]],0),`<=`,0,`${r}_xor_1`),r),v(new I($([[e,1],[t,-1],[n,1]],0),`>=`,0,`${r}_xor_2`),r),v(new I($([[e,1],[n,-1],[t,1]],0),`>=`,0,`${r}_xor_3`),r),v(new I($([[e,1],[t,1],[n,1]],0),`<=`,2,`${r}_xor_4`),r)}function O(e,t,n){if(t instanceof c){let r=u.get(t);v(new I($([[e,1],[r,-1]],0),`==`,0,`${n}_equiv`),n);return}if(t instanceof I){let r=E(t,n);le(e,r,0,`${n}_c_neg`,n),se(e,r,1,`${n}_c_pos`,n);return}if(t instanceof h){ne(e,t,n);return}if(t instanceof l){if(t.op===`not`){let r=D(t.children[0],n);v(new I($([[e,1],[r,1]],0),`==`,1,`${n}_not`),n);return}if(t.op===`and`){let r=t.children.map(e=>D(e,n));for(let t=0;t<r.length;t++)v(new I($([[e,1],[r[t],-1]],0),`<=`,0,`${n}_and_ub_${t}`),n);v(new I($([[e,1],...r.map(e=>[e,-1])],0),`>=`,1-r.length,`${n}_and_lb`),n);return}if(t.op===`or`){let r=t.children.map(e=>D(e,n));for(let t=0;t<r.length;t++)v(new I($([[e,1],[r[t],-1]],0),`>=`,0,`${n}_or_lb_${t}`),n);v(new I($([[e,1],...r.map(e=>[e,-1])],0),`<=`,0,`${n}_or_ub`),n);return}if(t.op===`implies`){let r=D(t.children[0],n),i=D(t.children[1],n);v(new I($([[e,1],[r,1]],0),`>=`,1,`${n}_imp_1`),n),v(new I($([[e,1],[i,-1]],0),`>=`,0,`${n}_imp_2`),n),v(new I($([[e,1],[r,1],[i,-1]],0),`<=`,1,`${n}_imp_3`),n);return}if(t.op===`xor`){if(t.children.length===0){v(new I($([[e,1]],0),`==`,0,`${n}_xor_empty`),n);return}if(t.children.length===1){let r=D(t.children[0],n);v(new I($([[e,1],[r,-1]],0),`==`,0,`${n}_xor_single`),n);return}let r=t.children.map(e=>D(e,n)),i=r[0];for(let e=1;e<r.length-1;e++){let t=new H({name:_(`xor_fold_${e}`),type:`Binary`,lb:0,ub:1});o.push(t),ee(t,i,r[e],`${n}_xor_fold_${e}`),i=t}ee(e,i,r[r.length-1],n);return}}throw Error(`Unsupported logical element in equivalence linearization: ${t}`)}function k(e,t){let n=e.map(e=>b(e.start,t)),r=[];for(let t=0;t<e.length;t++)for(let i=t+1;i<e.length;i++)(e[t].duration>0||e[i].duration>0)&&r.push({i:t,j:i,sI:n[t],dI:e[t].duration,sJ:n[i],dJ:e[i].duration});return r}function A(e,t,n){let r=e.map(e=>({start:b(e.start,n),duration:e.duration,demand:e.demand})).filter(e=>e.duration>0&&e.demand>0);if(r.length===0)return{kind:`constant`,value:!0};let i=[];for(let e of r){let t=e.start.constant??0;if(!Number.isSafeInteger(t))throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: task start offset (${t}) must be a safe integer.`);let r=t,a=t;for(let[t,i]of e.start.terms.entries()){if(i===0)continue;if(typeof t.lb!=`number`||typeof t.ub!=`number`||Number.isNaN(t.lb)||Number.isNaN(t.ub)||t.lb===-1/0||t.ub===1/0||t.lb>t.ub)throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: variable "${t.name}" has unbounded or invalid domain [${t.lb}, ${t.ub}]. Finite bounds are required.`);if(!Number.isSafeInteger(i))throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: variable "${t.name}" coefficient (${i}) exceeds safe integer precision.`);let e=t.type===`Binary`?Math.max(0,Math.ceil(t.lb)):Math.ceil(t.lb),o=t.type===`Binary`?Math.min(1,Math.floor(t.ub)):Math.floor(t.ub);if(e>o)return{kind:`empty_domain`};if(!Number.isSafeInteger(e)||!Number.isSafeInteger(o))throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: variable "${t.name}" integer bounds [${e}, ${o}] exceed JavaScript safe integer precision.`);let s=i*e,c=i*o;if(r+=Math.min(s,c),a+=Math.max(s,c),!Number.isSafeInteger(s)||!Number.isSafeInteger(c)||!Number.isSafeInteger(r)||!Number.isSafeInteger(a))throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: task start time bounds exceed JavaScript safe integer precision.`)}let o=r+e.duration,s=a+e.duration;if(!Number.isSafeInteger(o)||!Number.isSafeInteger(s))throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: task end time bounds [${r}, ${s}) exceed JavaScript safe integer precision.`);i.push({...e,est:Object.is(r,-0)?0:r,lst:Object.is(a,-0)?0:a})}return i.some(e=>e.demand>t)?{kind:`constant`,value:!1}:{kind:`tasks`,active:i}}function te(e,t,n){let r=e.spec;switch(r.kind){case`distinct`:{let e=r.args.map(e=>b(e,n));if(e.length<=1){t||N(n);return}if(t)for(let t=0;t<e.length;t++)for(let r=t+1;r<e.length;r++)T(e[t].sub(e[r]),`!=`,0,`${n}_neq_${t}_${r}`,n);else{let t=[];for(let r=0;r<e.length;r++)for(let i=r+1;i<e.length;i++)t.push(new I(e[r].sub(e[i]),`==`,0,`${n}_eq_${r}_${i}`));M(new l(`or`,t),n)}return}case`disjoint`:{let e=k(r.tasks,n);if(e.length===0){t||N(n);return}if(t)for(let{i:t,j:r,sI:i,dI:a,sJ:s,dJ:c}of e){let e=new H({name:_(`disj_${t}_${r}`),type:`Binary`,lb:0,ub:1});o.push(e),ae(e,i.sub(s),`<=`,-a,1,`${n}_p_${t}_${r}`,n),ae(e,s.sub(i),`<=`,-c,0,`${n}_q_${t}_${r}`,n)}else M(new l(`or`,e.map(({i:e,j:t,sI:r,dI:i,sJ:a,dJ:o})=>new l(`and`,[new I(r.sub(a),`>=`,1-i,`${n}_ov1_${e}_${t}`),new I(a.sub(r),`>=`,1-o,`${n}_ov2_${e}_${t}`)]))),n);return}case`cumulative`:{let e=A(r.tasks,r.capacity,n);if(e.kind===`empty_domain`){N(n);return}if(e.kind===`constant`){e.value!==t&&N(n);return}let{active:i}=e;if(t){let e=1/0,t=-1/0,a=0;for(let n of i)n.est<e&&(e=n.est),n.lst+n.duration>t&&(t=n.lst+n.duration),a+=Math.max(0,n.lst-n.est+1);let s=t-e;if(!Number.isSafeInteger(s)||s>hr||a>gr)throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: time horizon [${e}, ${t}) (span ${s}, ${a} time-indexed variables) exceeds MIP limit. Tighten start bounds or use { solver: "pumpkin" }.`);let c=[];for(let e=0;e<i.length;e++){let t=i[e],r=new Map,a=[],s=t.start.clone();for(let n=t.est;n<=t.lst;n++){let t=new H({name:_(`cum_u_${e}_${n}`),type:`Binary`,lb:0,ub:1});o.push(t),r.set(n,t),a.push([t,1]),n!==0&&s.addTerm(t,-n)}if(a.length===0){N(n);return}v(new I($(a,0),`==`,1,`${n}_cum_sos_${e}`),n),P(new I(s,`==`,0,`${n}_cum_start_${e}`),n),c.push(r)}for(let a=e;a<t;a++){let e=[],t=0;for(let n=0;n<i.length;n++){let r=i[n],o=a<=r.est+r.duration-1?r.est:a-r.duration+1,s=Math.min(r.lst,a);if(o<=s){t+=r.demand;let i=c[n];for(let t=o;t<=s;t++){let n=i.get(t);n&&e.push([n,r.demand])}}}t>r.capacity&&e.length>0&&v(new I($(e,0),`<=`,r.capacity,`${n}_cum_t_${a}`),n)}return}let a=[];for(let e=0;e<i.length;e++){let t=i[e],s=[];for(let r=0;r<i.length;r++){if(r===e)continue;let a=i[r],c=new H({name:_(`cum_act_${r}_${e}`),type:`Binary`,lb:0,ub:1});o.push(c),O(c,new l(`and`,[new I(a.start.sub(t.start),`<=`,0,`${n}_act_le_${r}_${e}`),new I(t.start.sub(a.start),`<=`,a.duration-1,`${n}_act_ge_${r}_${e}`)]),n),s.push([c,a.demand])}let c=new I($(s,0),`>=`,r.capacity-t.demand+1,`${n}_overload_${e}`);a.push(new l(`and`,[c]))}M(new l(`or`,a),n);return}case`allowed`:{let e=r.vars.map(e=>b(e,n));if(r.tuples.length===0){t&&N(n);return}if(t){let t=[];for(let e=0;e<r.tuples.length;e++){let n=new H({name:_(`tbl_r_${e}`),type:`Binary`,lb:0,ub:1});o.push(n),t.push(n)}v(new I($(t.map(e=>[e,1]),0),`==`,1,`${n}_tbl_sos`),n);for(let i=0;i<e.length;i++){let a=e[i].clone();for(let e=0;e<r.tuples.length;e++){let n=r.tuples[e][i];n!==0&&a.addTerm(t[e],-n)}P(new I(a,`==`,0,`${n}_tbl_col_${i}`),n)}return}let i=e.map(e=>{let t=Array.from(e.terms.entries()).filter(([,e])=>e!==0);if(t.length!==1)return null;let[n,r]=t[0];if(Math.abs(r)!==1||!Number.isSafeInteger(n.lb)||!Number.isSafeInteger(n.ub)||n.ub-n.lb!==1)return null;let i=e.constant;if(!Number.isSafeInteger(i))return null;let a=r*n.lb+i,o=r*n.ub+i;return{expr:e,lo:Math.min(a,o),hi:Math.max(a,o)}});for(let t=0;t<r.tuples.length;t++){let a=r.tuples[t],o=!0,s=!1;for(let e=0;e<a.length;e++){let t=i[e];if(!t){o=!1;break}if(a[e]!==t.lo&&a[e]!==t.hi){s=!0;break}}if(!s){if(o){let e=new z(new Map,0);for(let t=0;t<a.length;t++){let n=i[t];a[t]===n.lo?mr(e,n.expr.sub(n.lo),1):mr(e,$([],n.hi).sub(n.expr),1)}P(new I(e,`>=`,1,`${n}_nogood_${t}`),n)}else M(new l(`or`,a.map((r,i)=>new I(e[i],`!=`,r,`${n}_ntbl_${t}_${i}`))),n,`${n}_ntbl_${t}`)}}return}}}function ne(e,t,n){let r=t.spec;switch(r.kind){case`distinct`:{let t=r.args.map(e=>b(e,n));if(t.length<=1){v(new I($([[e,1]],0),`==`,1,`${n}_distinct_triv`),n);return}let i=[];for(let e=0;e<t.length;e++)for(let r=e+1;r<t.length;r++)i.push(new I(t[e].sub(t[r]),`!=`,0,`${n}_d_${e}_${r}`));O(e,new l(`and`,i),n);return}case`disjoint`:{let t=k(r.tasks,n);if(t.length===0){v(new I($([[e,1]],0),`==`,1,`${n}_disjoint_triv`),n);return}O(e,new l(`and`,t.map(({i:e,j:t,sI:r,dI:i,sJ:a,dJ:o})=>new l(`or`,[new I(r.sub(a),`<=`,-i,`${n}_dj1_${e}_${t}`),new I(a.sub(r),`<=`,-o,`${n}_dj2_${e}_${t}`)]))),n);return}case`cumulative`:{let t=A(r.tasks,r.capacity,n);if(t.kind===`empty_domain`){N(n);return}if(t.kind===`constant`){v(new I($([[e,1]],0),`==`,+!!t.value,`${n}_cum_triv`),n);return}let{active:i}=t,a=[];for(let e=0;e<i.length;e++){let t=i[e],s=[];for(let r=0;r<i.length;r++){if(r===e)continue;let a=i[r],c=new H({name:_(`cum_eq_act_${r}_${e}`),type:`Binary`,lb:0,ub:1});o.push(c),O(c,new l(`and`,[new I(a.start.sub(t.start),`<=`,0,`${n}_eq_le_${r}_${e}`),new I(t.start.sub(a.start),`<=`,a.duration-1,`${n}_eq_ge_${r}_${e}`)]),n),s.push([c,a.demand])}a.push(new I($(s,0),`<=`,r.capacity-t.demand,`${n}_ev_${e}`))}O(e,new l(`and`,a),n);return}case`allowed`:{let t=r.vars.map(e=>b(e,n));if(r.tuples.length===0){v(new I($([[e,1]],0),`==`,0,`${n}_allowed_empty`),n);return}O(e,new l(`or`,r.tuples.map((e,r)=>new l(`and`,e.map((e,i)=>new I(t[i],`==`,e,`${n}_eq_tbl_${r}_${i}`))))),n);return}}}function re(e){return e instanceof I||e instanceof l&&e.children.some(e=>re(e))}function ie(e,t){if(e instanceof I){if((e.lhs.terms.get(t)??0)!==0)return!0;for(let n of e.lhs.nonlinearTerms){if(n.coeff===0)continue;let e=n.atom;if(e.kind===`abs`&&(e.arg.terms.get(t)??0)!==0||(e.kind===`max`||e.kind===`min`)&&e.args.some(e=>(e.terms.get(t)??0)!==0)||e.kind===`at`&&((e.index.terms.get(t)??0)!==0||e.array.some(e=>(e.terms.get(t)??0)!==0)))return!0}return!1}return e instanceof l&&e.children.some(e=>ie(e,t))}function j(e,t,n,r){if(t instanceof I){se(e,E(t,n),1,r,n);return}if(t instanceof c||t instanceof h){v(new I($([[D(t,n),1],[e,-1]],0),`>=`,0,r),n);return}if(t instanceof l){if(t.op===`and`){for(let i=0;i<t.children.length;i++)j(e,t.children[i],n,`${r}_and_${i}`);return}if(t.op===`not`){let i=t.children[0];if(i instanceof I){le(e,E(i,n),1,r,n);return}if(i instanceof l){if(i.op===`not`){j(e,i.children[0],n,r);return}if(i.op===`or`){for(let t=0;t<i.children.length;t++)j(e,new l(`not`,[i.children[t]]),n,`${r}_not_or_${t}`);return}if(i.op===`and`){j(e,new l(`or`,i.children.map(e=>new l(`not`,[e]))),n,r);return}if(i.op===`implies`){j(e,i.children[0],n,`${r}_not_imp_0`),j(e,new l(`not`,[i.children[1]]),n,`${r}_not_imp_1`);return}}let a=D(i,n);v(new I($([[e,1],[a,1]],0),`<=`,1,r),n);return}if(t.op===`or`){if(t.children.length===0){v(new I($([[e,1]],0),`<=`,0,r),n);return}if(t.children.length===1){j(e,t.children[0],n,r);return}if(!t.children.some(e=>re(e))){let i=t.children.map(e=>D(e,n));v(new I($([[e,-1],...i.map(e=>[e,1])],0),`>=`,0,r),n);return}let i=[];for(let e=0;e<t.children.length;e++){let a=t.children[e];if(a instanceof c)i.push(D(a,n));else{let t=new H({name:_(`imp_or_${e}`),type:`Binary`,lb:0,ub:1});o.push(t),i.push(t),j(t,a,n,`${r}_or_${e}`)}}v(new I($([[e,-1],...i.map(e=>[e,1])],0),`>=`,0,r),n);return}if(t.op===`implies`){let[i,a]=t.children,s;if(i instanceof I){let e=E(i,n);s=new H({name:_(`ante`),type:`Binary`,lb:0,ub:1}),o.push(s),le(s,e,0,`${r}_ante_neg`,n)}else s=D(i,n);if(a instanceof c){v(new I($([[D(a,n),1],[e,-1],[s,-1]],0),`>=`,-1,r),n);return}let l=new H({name:_(`imp_joint`),type:`Binary`,lb:0,ub:1});o.push(l),v(new I($([[l,1],[e,-1],[s,-1]],0),`>=`,-1,`${r}_joint`),n),j(l,a,n,r);return}v(new I($([[D(t,n),1],[e,-1]],0),`>=`,0,r),n);return}throw Error(`Unsupported logical element in implication consequent "${n}": ${t}`)}function M(e,t,n=t){if(e instanceof I){T(e.lhs,e.sense,e.rhs,n,t);return}if(e instanceof h){te(e,!0,t);return}if(e instanceof c){v(new I($([[D(e,t),1]],0),`>=`,1,n),t);return}if(e instanceof l){if(e.op===`not`){let r=e.children[0];if(r instanceof c){v(new I($([[D(r,t),1]],0),`<=`,0,n),t);return}if(r instanceof h){te(r,!1,t);return}if(r instanceof I){ce(E(r,t),t);return}if(r instanceof l){if(r.op===`not`){M(r.children[0],t,n);return}if(r.op===`or`){for(let e=0;e<r.children.length;e++)M(new l(`not`,[r.children[e]]),t,`${n}_not_or_${e}`);return}if(r.op===`and`){M(new l(`or`,r.children.map(e=>new l(`not`,[e]))),t,n);return}if(r.op===`implies`){M(r.children[0],t,`${n}_not_imp_0`),M(new l(`not`,[r.children[1]]),t,`${n}_not_imp_1`);return}}v(new I($([[D(r,t),1]],0),`<=`,0,n),t);return}if(e.op===`and`){for(let r=0;r<e.children.length;r++)M(e.children[r],t,`${n}_and_${r}`);return}if(e.op===`or`){if(e.children.length===0){N(t);return}if(e.children.length===1){M(e.children[0],t,n);return}if(!e.children.some(e=>re(e))){v(new I($(e.children.map(e=>D(e,t)).map(e=>[e,1]),0),`>=`,1,n),t);return}let r=[];for(let i=0;i<e.children.length;i++){let a=e.children[i];if(a instanceof c)r.push(D(a,t));else{let e=new H({name:_(`or_branch_${i}`),type:`Binary`,lb:0,ub:1});o.push(e),r.push(e),j(e,a,t,`${n}_or_${i}`)}}v(new I($(r.map(e=>[e,1]),0),`>=`,1,n),t);return}if(e.op===`xor`){if(e.children.length===0){N(t);return}if(e.children.length===1){M(e.children[0],t,n);return}let r=e.children.map(e=>D(e,t));if(r.length===2){v(new I($([[r[0],1],[r[1],1]],0),`==`,1,n),t);return}let i=r[0];for(let e=1;e<r.length-1;e++){let t=new H({name:_(`xor_fold_${e}`),type:`Binary`,lb:0,ub:1});o.push(t),ee(t,i,r[e],`${n}_xor_fold_${e}`),i=t}let a=r[r.length-1];v(new I($([[i,1],[a,1]],0),`==`,1,n),t);return}if(e.op===`implies`){let[r,i]=e.children,a=r instanceof I?vr(r):null;if(a!==null){if(i instanceof I){let e=E(i,t);if((e.lhs.terms.get(a.binVar)??0)===0){se(a.binVar,e,a.activeVal,n,t);return}}if(i instanceof c){let e=D(i,t);v(a.activeVal===1?new I($([[e,1],[a.binVar,-1]],0),`>=`,0,n):new I($([[e,1],[a.binVar,1]],0),`>=`,1,n),t);return}if(i instanceof l&&i.op===`not`){let e=i.children[0];if(e instanceof c){let r=D(e,t);v(a.activeVal===1?new I($([[r,1],[a.binVar,1]],0),`<=`,1,n):new I($([[r,1],[a.binVar,-1]],0),`<=`,0,n),t);return}if(e instanceof I){let r=E(e,t);if((r.lhs.terms.get(a.binVar)??0)===0){le(a.binVar,r,a.activeVal,n,t);return}}}if(a.activeVal===1&&!ie(i,a.binVar)){j(a.binVar,i,t,n);return}}let s;if(r instanceof I){let e=E(r,t);s=new H({name:_(`ante`),type:`Binary`,lb:0,ub:1}),o.push(s),le(s,e,0,`${n}_ante_neg`,t)}else s=D(r,t);j(s,i,t,n);return}}throw Error(`Unsupported top-level logical constraint "${t}": ${e}`)}function ae(e,t,n,r,i,a,o){let s=pr(e,t,n,r,i,n===`<=`?dr(t,r,a):fr(t,r,a),a);s.lhs.terms.size>0&&v(new I(s.lhs,n,s.rhs,a),o)}function oe(e){return new I(e.lhs,`==`,e.rhs,e.name)}function se(e,t,n,r,i){let a=E(t,i);if(a.sense===`!=`){le(e,oe(a),n,r,i);return}let{lhs:o,sense:s,rhs:c}=a;s===`==`?(ae(e,o,`<=`,c,n,`${r}_le`,i),ae(e,o,`>=`,c,n,`${r}_ge`,i)):ae(e,o,s,c,n,r,i)}function N(e){let t=new H({name:_(`unsat`),type:`Binary`,lb:0,ub:1});o.push(t),v(new I($([[t,1]],0),`>=`,2,e),e)}function P(e,t){let n=E(e,t),{lhs:r,sense:i,rhs:a}=n;if(i===`!=`){ce(oe(n),t);return}let o=r.constant??0,s=a-o;if(!Number.isFinite(o)||!Number.isFinite(a)||!Number.isFinite(s))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: constraint "${e.name}" contains non-finite constant or right-hand side.`);let c=[];for(let[n,i]of r.terms){if(!Number.isFinite(i))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: variable "${n.name}" in constraint "${e.name}" has non-finite coefficient (${i}).`);i!==0&&c.push([n,i])}if(c.length===0){(i===`<=`?0<=s:i===`>=`?0>=s:s===0)||N(t);return}v(new I($(c,0),i,s,e.name||t),t)}function ce(e,t){let n=E(e,t);if(n.sense===`!=`){P(oe(n),t);return}let r=yr(n,t);if(r.kind===`always_true`)return;if(r.kind===`always_false`){N(t);return}if(r.kind===`single`){v(new I(r.lhs,r.sense,r.rhs,n.name||t),t);return}let i=new H({name:_(`neq_dir`),type:`Binary`,lb:0,ub:1});o.push(i);let a=n.name||t;ae(i,r.lhs,`<=`,r.ltRhs,1,`${a}_lt`,t),ae(i,r.lhs,`>=`,r.gtRhs,0,`${a}_gt`,t)}function le(e,t,n,r,i){let a=E(t,i);if(a.sense===`!=`){se(e,oe(a),n,r,i);return}let s=yr(a,i);if(s.kind===`always_true`)return;if(s.kind===`always_false`){v(new I($([[e,1]],0),n===0?`>=`:`<=`,+(n===0),r),i);return}if(s.kind===`single`){ae(e,s.lhs,s.sense,s.rhs,n,r,i);return}let c=new H({name:_(`neq_lt`),type:`Binary`,lb:0,ub:1}),l=new H({name:_(`neq_gt`),type:`Binary`,lb:0,ub:1});o.push(c,l),ae(c,s.lhs,`<=`,s.ltRhs,1,`${r}_lt`,i),ae(l,s.lhs,`>=`,s.gtRhs,1,`${r}_gt`,i),v(new I($([[c,1],[l,1],[e,n===0?1:-1]],0),`>=`,+(n===0),`${r}_disj`),i)}for(let e of p)T(e.lhs,e.sense,e.rhs,e.name,e.name);let F;if(a&&a.expr.hasNonlinearTerms()){let e=i(a.sense)===`Minimize`,t=a.expr,n=new Map(t instanceof w?t.linearTerms:t.terms),r=t.constant;for(let i of t.nonlinearTerms){if(i.coeff===0)continue;let t=(e?i.coeff>0:i.coeff<0)?`upper`:`lower`,a=S(i.atom,t,`__objective`);r+=i.coeff*a.constant;for(let[e,t]of a.terms.entries()){let r=(n.get(e)??0)+i.coeff*t;r===0?n.delete(e):n.set(e,r)}}F=t instanceof w?new w(n,t.quadTerms,r,[]):new z(n,r,[])}else a&&(F=a.expr);for(let e of r){let t=e.name,n=e.expr;M(n,t)}return{variables:o,constraints:s,boolVarToBinary:u,constraintToOriginalName:d,...F===void 0?{}:{objective:F}}}function vr(e){if(e.lhs.hasNonlinearTerms()||e.lhs.terms.size!==1||(e.lhs.constant??0)!==0)return null;let[[t,n]]=Array.from(e.lhs.terms.entries());return t.type!==`Binary`&&t.type!==`Integer`||t.lb!==0||t.ub!==1||n!==1?null:e.sense===`==`&&e.rhs===1||e.sense===`>=`&&e.rhs===1||e.sense===`!=`&&e.rhs===0?{binVar:t,activeVal:1}:e.sense===`==`&&e.rhs===0||e.sense===`<=`&&e.rhs===0||e.sense===`!=`&&e.rhs===1?{binVar:t,activeVal:0}:null}function yr(e,t){let{lhs:n,sense:r,rhs:i}=e;if(n.hasNonlinearTerms())throw Error(`Cannot negate unlowered nonlinear constraint "${e.name}" in "${t}".`);let a=n.constant??0,o=i-a;if(!Number.isFinite(a)||!Number.isFinite(i)||!Number.isFinite(o))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: constraint "${e.name}" contains non-finite constant or right-hand side.`);if(r!==`<=`&&r!==`>=`&&r!==`==`)throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: unsupported comparison sense "${String(r)}" in constraint "${e.name}".`);let s=[];for(let[r,i]of n.terms){if(!Number.isFinite(i))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: variable "${r.name}" in constraint "${e.name}" has non-finite coefficient (${i}).`);if(i!==0){if(r.type!==`Integer`&&r.type!==`Binary`)throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: negating constraint "${e.name}" involves Continuous variable "${r.name}", whose strict-inequality negation creates an open half-space not representable in MIP. Use { solver: "z3" }, rewrite explicitly with a closed tolerance such as or(expr\`... >= ... + eps\`, ...), or model the proposition with m.bool().`);if(!Number.isSafeInteger(i))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: negating constraint "${e.name}" requires safe integer coefficients, but variable "${r.name}" has coefficient ${i}. Scale to integer coefficients, use { solver: "z3" }, or rewrite explicitly with or(expr\`... >= ... + eps\`, ...) / m.bool().`);s.push([r,i])}}if(s.length===0)return(r===`<=`?0<=o:r===`>=`?0>=o:o===0)?{kind:`always_false`}:{kind:`always_true`};if(!Number.isInteger(o))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: negating constraint "${e.name}" requires an integer right-hand side and constant, received effective right-hand side ${o}. Scale or round the threshold to an integer, use { solver: "z3" }, or rewrite explicitly with or(expr\`... >= ... + eps\`, ...) / m.bool().`);if(Math.abs(o)>=2**53-1)throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: effective right-hand side (${o}) of constraint "${e.name}" exceeds safe integer precision for exact +/-1 negation. Please rescale coefficients/constants or solve with { solver: "z3" }.`);let c=$(s,0);if(r===`<=`)return{kind:`single`,lhs:c,sense:`>=`,rhs:o+1};if(r===`>=`)return{kind:`single`,lhs:c,sense:`<=`,rhs:o-1};let l=o-1,u=o+1,d=0,f=0,p=!0,m=!0;for(let[e,t]of s){if(!(e.lb<=e.ub)){p=!1,m=!1;break}let n=t>0?e.lb:e.ub,r=t>0?e.ub:e.lb,i=t*n,a=t*r;d+=i,f+=a,p&&=Number.isSafeInteger(n)&&Number.isSafeInteger(i)&&Number.isSafeInteger(d),m&&=Number.isSafeInteger(r)&&Number.isSafeInteger(a)&&Number.isSafeInteger(f)}let h=!(p&&d>l),g=!(m&&f<u);return!h&&!g?{kind:`always_false`}:g?h?{kind:`disjunction`,lhs:c,ltRhs:l,gtRhs:u}:{kind:`single`,lhs:c,sense:`>=`,rhs:u}:{kind:`single`,lhs:c,sense:`<=`,rhs:l}}async function br(e){let t=e.master;if(!t)throw Error(`A master Model must be provided for solveColumnGeneration.`);let{pricing:n,maxIterations:r=100,reducedCostTolerance:i=1e-6,finalizeAsMIP:a=!0,solver:o,solverOptions:s,onIteration:c}=e,l=t.sense.toLowerCase()===`maximize`,u=n;if(!u)throw Error(`The 'pricing' callback must be provided in ColumnGenerationOptions.`);let d=[],f=null,p=0,m=t.status;for(let e=1;e<=r;e++){p=e;let n=await t.relax(o,s);if(m=n,n!==`Optimal`&&n!==`Feasible`||!t.solution)break;f=t.objectiveValue;let r=t.solution,a=r.duals||{},h=e=>typeof e==`string`?a[e]??0:e.dual??(e.name?a[e.name]??0:0),g=await u({iteration:e,duals:a,getDual:h,masterSolution:r,reducedCostTolerance:i,master:t}),_=[];g&&(Array.isArray(g)?_.push(...g):_.push(g));let v=[];for(let e of _){let t=e.reducedCost;if(typeof t!=`number`||!Number.isFinite(t)){let n=0,r=e.coefficients;if(Array.isArray(r))for(let e of r)Array.isArray(e)?n+=e[1]*h(e[0]):e&&typeof e==`object`&&(n+=e.coeff*h(e.constraint));else if(r instanceof Map)for(let[e,t]of r.entries())n+=t*h(e);else if(r&&typeof r==`object`)for(let[e,t]of Object.entries(r))n+=t*h(e);t=e.cost-n}(l?t>i:t<-i)&&v.push(e)}if(c&&c({iteration:e,relaxationObjective:f,columnsAdded:d.length+v.length,proposedColumns:v}),v.length===0)break;for(let e of v){let n=t.column({name:e.name,type:e.type||`Continuous`,lb:e.lb,ub:e.ub,cost:e.cost,coefficients:e.coefficients});d.push({variable:n,proposal:e})}}let h=f;a&&(m===`Optimal`||m===`Feasible`)&&(m=await t.solve(o,s),h=t.objectiveValue);let g={};for(let e of t.variables.values())e instanceof H&&e.value!==null&&(g[e.name]=e.value);let _={status:m,objectiveValue:h,relaxationObjectiveValue:f,iterations:p,columnsAdded:d.length,generatedColumns:d,master:t,values:g};return t.decomposition=_,_}function xr(e,t){let n=e;if(n instanceof I||typeof n==`object`&&n&&`sense`in n&&`lhs`in n&&`rhs`in n)throw Error(`Cannot use a Constraint as an objective in ${t}(). Use m.constraint(expr\`... <= ...\`) for constraints, or supply an unconstrained arithmetic expression to ${t}(), e.g. m.objective(${t}(expr\`30 * \${x}\`)).`);if(typeof n==`string`&&/(<=|>=|==|!=|=<|=>|<|>|=)/.test(n))throw Error(`Cannot use a comparison constraint as an objective in ${t}(). Use m.constraint(expr\`... <= ...\`) for constraints, or supply an unconstrained arithmetic expression to ${t}(), e.g. m.objective(${t}(expr\`30 * \${x}\`)).`);if(typeof n==`number`){if(!Number.isFinite(n))throw Error(`Invalid non-finite objective constant "${n}" passed to ${t}().`);return n}if(typeof n==`string`||n instanceof z||n instanceof w||n instanceof H||typeof n==`object`&&n&&(`terms`in n&&n.terms instanceof Map&&typeof n.constant==`number`||`quadTerms`in n&&n.quadTerms instanceof Map&&`linearTerms`in n&&n.linearTerms instanceof Map&&typeof n.constant==`number`||`id`in n&&`name`in n&&`lb`in n&&`ub`in n))return n;throw Error(`Invalid expression passed to ${t}(): expected a finite number, Var, LinExpr, QuadExpr, or arithmetic expression string.`)}function Sr(e){return{expr:xr(e,`maximize`),sense:`Maximize`}}function Cr(e){return{expr:xr(e,`minimize`),sense:`Minimize`}}var wr=new WeakSet;function Tr(e){return!!(e&&typeof e==`object`&&`constraints`in e&&`variables`in e&&typeof e.solve==`function`)}async function Er(e,t,n,r,i,a,o,s,c=1){let l=[];for(let r=0;r<t.length;r++){let a=t[r],o=a.lhs,s=a.sense,u=a.rhs-(o.constant||0),d=[],f=[],p=0;for(let[e,t]of o.terms.entries()){let r=n.variables.get(e.name);if(e.ownerModel===n||r instanceof H){f.push([e,t]);let n=i[e.name]??0;p+=t*n}else d.push([e,t])}let m=u-p,h=new z;for(let[e,t]of d)h.addTerm(e,t);let g=new I(h,s,m,`__benders_link_${c}_${r}`);e.constraint(g),l.push({origConstraint:a,subConstr:g,masterTerms:f,baseRhs:u})}let u=await e.solve(o,{...s,relax:!0});if(u!==`Optimal`&&u!==`Feasible`)throw Error(`Benders subproblem failed at iteration ${c} with status "${u}". Auto-cut generation requires an Optimal or Feasible subproblem (expected Optimal or Feasible).`);let d=e.objectiveValue;if(typeof d!=`number`||!Number.isFinite(d))throw Error(`Benders subproblem returned invalid objectiveValue (${String(d)}) at iteration ${c}.`);if(wr.has(r)&&d<r.lb-1e-6)throw Error(`Benders auto-created "__benders_theta" (lb: ${r.lb}) cannot represent negative subproblem cost (${d}) at iteration ${c}. Define an explicit theta variable with a negative lower bound and pass options.theta.`);let f=i[r.name]??0,p=1e-4;if(!(a?f<d-p:f>d+p))return null;let m=0,h=new Map,g=new Set(l.map(e=>e.subConstr.name));for(let t of e.constraints.values()){if(!(t instanceof I)||g.has(t.name))continue;let n=e.solution?.duals[t.name]??t.dual??0;if(Math.abs(n)>1e-12){let e=t.rhs-(t.lhs.constant||0);m+=n*e}}for(let t of l){let n=e.solution?.duals[t.subConstr.name]??t.subConstr.dual??0;if(Math.abs(n)>1e-12){m+=n*t.baseRhs;for(let[e,r]of t.masterTerms){let t=h.get(e)??0;h.set(e,t+n*r)}}}let _=new z;_.addTerm(r,1);for(let[e,t]of h.entries())Math.abs(t)>1e-12&&_.addTerm(e,t);let v=new I(_,a?`>=`:`<=`,m,`__benders_opt_cut_${c}`),y=(n.objectiveValue??0)-f+d;return{kind:`optimality`,constraint:v,name:v.name,subproblemObjective:y}}async function Dr(e){let t=e.master;if(!t)throw Error(`A master Model must be provided for solveBenders.`);let{subproblem:n,maxIterations:r=100,gapTolerance:i=1e-4,solver:a,solverOptions:o,onIteration:s}=e,c;if(e.theta!==void 0){if(typeof e.theta==`string`){let n=t.variables.get(e.theta);if(!(n instanceof H))throw Error(`Benders option "theta" references variable "${e.theta}", which was not found on the master model.`);c=n}else c=e.theta}if(!c){for(let e of t.variables.values())if(e instanceof H&&(e.name===`theta`||e.name===`__benders_theta`)){c=e;break}}let l=0,u=0,d=t.status,f,p,m,h={},g=null;for(let e=1;e<=r;e++){u=e;let r=await t.solve(a,o);if(d=r,r!==`Optimal`&&r!==`Feasible`)break;let _=t.objectiveValue,v=t.sense.toLowerCase()===`minimize`;v?f=_===null?f:_:p=_===null?p:_;let y={};for(let e of t.variables.values())e instanceof H&&e.value!==null&&(y[e.name]=e.value);let b=await n({iteration:e,masterValues:y,getMasterValue:e=>typeof e==`string`?y[e]??0:e.value??(e.name?y[e.name]??0:0),masterObjective:_,lowerBound:f,upperBound:p,master:t}),x=[];if(b){if(Tr(b)){let n=b,r=n.linkingConstraints;if(!c){if(!v)throw Error(`Benders auto-cut generation requires an explicit options.theta variable for Maximize master models.`);c=t.continuous(`__benders_theta`,{lb:0}),t.objective(Cr(t.objective().add(c))),wr.add(c)}let i=await Er(n,r,t,c,y,v,a,o,e);i&&x.push(i)}else Array.isArray(b)?x.push(...b):x.push(b)}for(let e of x)if(typeof e.subproblemObjective==`number`&&Number.isFinite(e.subproblemObjective)){if(v){let t=e.subproblemObjective;(p===void 0||t<p)&&(p=t,g=t,h={...y})}else{let t=e.subproblemObjective;(f===void 0||t>f)&&(f=t,g=t,h={...y})}}if(f!==void 0&&p!==void 0){let e=Math.abs(p)+1e-10;m=Math.abs(p-f)/e}if(s&&s({iteration:e,masterObjective:_,lowerBound:f,upperBound:p,cutsAdded:l+x.length,proposedCuts:x}),x.length===0){g=_,h={...y};break}if(m!==void 0&&m<=i)break;for(let e of x)t.constraint(e.constraint,e.name),l++}let _=d===`Optimal`||d===`Feasible`,v=Object.keys(h).length>0?h:_?(()=>{let e={};for(let n of t.variables.values())n instanceof H&&n.value!==null&&(e[n.name]=n.value);return e})():{},y=g===null?_?t.objectiveValue:null:g,b={status:d,objectiveValue:y,lowerBound:f,upperBound:p,gap:m,iterations:u,cutsAdded:l,master:t,values:v};return t.decomposition=b,b}function Or(e,t){return e.hasNonlinearTerms()?!0:kr(t)}function kr(e){for(let t of e)if(t.sense===`!=`||t.lhs.hasNonlinearTerms())return!0;return!1}function Ar(e){let t=Object.freeze({get size(){return e.size},get(t){return e.get(t)},has(t){return e.has(t)},forEach(n,r){e.forEach((e,i)=>{n.call(r,e,i,t)})},entries(){return e.entries()},keys(){return e.keys()},values(){return e.values()},[Symbol.iterator](){return e[Symbol.iterator]()}});return t}function jr(e){return Array.isArray(e)||typeof e==`object`&&!!e&&!(e instanceof String)&&typeof e[Symbol.iterator]==`function`}function Mr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!(e instanceof String)&&typeof e[Symbol.iterator]!=`function`}function Nr(e){return e instanceof H||typeof e==`object`&&!!e&&!(e instanceof s)&&!(e instanceof I)&&`id`in e&&`name`in e&&`lb`in e&&`ub`in e&&!(`terms`in e)&&!(`quadTerms`in e)&&!(`sense`in e)}function Pr(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 Fr=class{name;_sense;_objectiveExpr;_variables=[];_constraints=[];_boolVars=[];_logicalConstraints=[];unsatCore=void 0;_conflicts=void 0;_values=new Map;varMapByName=new Map;varPrefixCounters=new Map;boolVarMapByName=new Map;boolVarPrefixCounters=new Map;constrMapByName=new Map;constrPrefixCounters=new Map;logicalConstrMapByName=new Map;logicalConstrCounter=0;allVarsMap=new Map;allConstrsMap=new Map;variables;constraints;values;status=`NotSolved`;terminationStatus=`NotSolved`;hasPrimalSolution=!1;objectiveValue=null;objectiveBound=void 0;relativeGap=void 0;absoluteGap=void 0;runTime=0;solution=null;solver=null;decomposition;_linkingConstraints;hasSolutionState=!1;modelRevision=0;activeOperationId=0;batchDepth=0;batchMutated=!1;batchUndoActions=[];constructor(e={},t){let n;n=typeof e==`string`?{...t,name:e}:e,this.name=n.name||`OptimizationModel`,this._sense=i(n.sense),this._objectiveExpr=new z,this.variables=Ar(this.allVarsMap),this.constraints=Ar(this.allConstrsMap),this.values=Ar(this._values),O(this,()=>this.recordModelMutation()),n.solver&&(this.solver=tt(n.solver))}get sense(){return this._sense}set sense(e){let t=i(e);this._sense!==t&&(this._sense=t,this.recordModelMutation())}get conflicts(){return this._conflicts??this.unsatCore}set conflicts(e){this._conflicts=e}clearSolutionFields(){if(this.hasSolutionState||this.status!==`NotSolved`||this.terminationStatus!==`NotSolved`||this.hasPrimalSolution||this.solution!==null||this.unsatCore!==void 0){this.hasSolutionState=!1,this.status=`NotSolved`,this.terminationStatus=`NotSolved`,this.hasPrimalSolution=!1,this.objectiveValue=null,this.objectiveBound=void 0,this.relativeGap=void 0,this.absoluteGap=void 0,this.solution=null,this.runTime=0,this.unsatCore=void 0,this._conflicts=void 0,this._values.clear();for(let e of this._variables)e.value=null,e.reducedCost=null;for(let e of this._boolVars)e.value=null;for(let e of this._constraints)e.dual=null,e.slack=null}}recordModelMutation(){if(this.batchDepth>0){this.batchMutated=!0;return}this.modelRevision++,this.clearSolutionFields()}runTransactionalBatch(e){if(this.batchDepth>0)return e();let t=this._variables.length,n=this._boolVars.length,r=this._constraints.length,i=this._logicalConstraints.length,a=new Map(this.varPrefixCounters),o=new Map(this.boolVarPrefixCounters),s=new Map(this.constrPrefixCounters),c=this.logicalConstrCounter;this.batchDepth=1,this.batchMutated=!1,this.batchUndoActions=[];try{let t=e();this.batchDepth=0;let n=this.batchMutated;return this.batchMutated=!1,this.batchUndoActions=[],n&&this.recordModelMutation(),t}catch(e){this.batchDepth=0,this.batchMutated=!1;for(let e=t;e<this._variables.length;e++){let t=this._variables[e];this.varMapByName.delete(t.name),this.allVarsMap.delete(t.name),t.ownerModel=null,re(t,this)}this._variables.length=t;for(let e=n;e<this._boolVars.length;e++){let t=this._boolVars[e];this.boolVarMapByName.delete(t.name),this.allVarsMap.delete(t.name)}this._boolVars.length=n;for(let e=r;e<this._constraints.length;e++){let t=this._constraints[e];this.constrMapByName.delete(t.name),this.allConstrsMap.delete(t.name)}this._constraints.length=r;for(let e=i;e<this._logicalConstraints.length;e++){let t=this._logicalConstraints[e];this.logicalConstrMapByName.delete(t.name),this.allConstrsMap.delete(t.name)}this._logicalConstraints.length=i;for(let e=this.batchUndoActions.length-1;e>=0;e--)this.batchUndoActions[e]();throw this.batchUndoActions=[],this.varPrefixCounters=a,this.boolVarPrefixCounters=o,this.constrPrefixCounters=s,this.logicalConstrCounter=c,e}}createDomainVars(e,t,n,r){let i=e.toLowerCase(),a=typeof t==`number`,o=typeof n==`number`,s=jr(t),c=jr(n);if(o||c){if(a&&Pr(t,i),o&&Pr(n,i),!a&&!s||r!==void 0&&!Mr(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&&!Mr(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(Mr(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&&!Mr(n))throw Error(`Invalid arguments provided for ${i} variable creation`);let l=n||{},u=l.prefix||l.name;if(typeof t==`number`)return Pr(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(jr(t))return this.runTransactionalBatch(()=>{let n={};for(let r of t){let t=u?`${u}_${r}`:`${r}`;n[r]=this.addVar({...l,type:e,name:t})}return n});throw Error(`Invalid arguments provided for ${i} variable creation`)}binary(e,t,n){return this.createDomainVars(`Binary`,e,t,n)}integer(e,t,n){return this.createDomainVars(`Integer`,e,t,n)}continuous(e,t,n){return this.createDomainVars(`Continuous`,e,t,n)}column(e){let t=e.type||`Continuous`,n=this.addVar({name:e.name,type:t,lb:e.lb,ub:e.ub});if(typeof e.cost==`number`&&e.cost!==0&&(this._objectiveExpr=this._objectiveExpr.add(n.mul(e.cost)),this.recordModelMutation()),e.coefficients){if(Array.isArray(e.coefficients)){for(let t of e.coefficients)if(Array.isArray(t)){let[e,r]=t,i=typeof e==`string`?this.constrMapByName.get(e):e;if(!i)throw Error(`Constraint '${String(e)}' not found in model when adding column`);i.addTerm(n,r)}else if(typeof t==`object`&&t){let e=typeof t.constraint==`string`?this.constrMapByName.get(t.constraint):t.constraint;if(!e)throw Error(`Constraint '${String(t.constraint)}' not found in model when adding column`);e.addTerm(n,t.coeff)}}else if(e.coefficients instanceof Map)for(let[t,r]of e.coefficients.entries()){let e=typeof t==`string`?this.constrMapByName.get(t):t;if(!e)throw Error(`Constraint '${String(t)}' not found in model when adding column`);e.addTerm(n,r)}else if(typeof e.coefficients==`object`)for(let[t,r]of Object.entries(e.coefficients)){let e=this.constrMapByName.get(t);if(!e)throw Error(`Constraint '${t}' not found in model when adding column`);e.addTerm(n,r)}}return n}bool(e,t,n){let r=typeof e==`number`,i=typeof t==`number`,a=jr(e),o=jr(t);if(i||o){if(r&&Pr(e,`boolean`),i&&Pr(t,`boolean`),!r&&!a||n!==void 0&&!Mr(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&&!Mr(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(Mr(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&&!Mr(t))throw Error(`Invalid arguments provided for boolean variable creation`);let s=t||{},c=s.prefix||s.name;if(typeof e==`number`)return Pr(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(jr(e))return this.runTransactionalBatch(()=>{let t={};for(let n of e){let e=c?`${c}_${n}`:`${n}`;t[n]=this.createBoolVar(e)}return t});throw Error(`Invalid arguments provided for boolean variable creation`)}hasVarName(e){return this.varMapByName.has(e)||this.boolVarMapByName.has(e)}getNextVarName(e){let t=this.varPrefixCounters.get(e)??0,n=`${e}_${t}`;for(;this.hasVarName(n);)t++,n=`${e}_${t}`;return this.varPrefixCounters.set(e,t+1),n}getNextBoolVarName(e){let t=this.boolVarPrefixCounters.get(e)??0,n=`${e}_${t}`;for(;this.hasVarName(n)||this.hasConstraintName(n);)t++,n=`${e}_${t}`;return this.boolVarPrefixCounters.set(e,t+1),n}hasConstraintName(e){return this.constrMapByName.has(e)||this.logicalConstrMapByName.has(e)}hasBoolVarName(e){return this.boolVarMapByName.has(e)}getNextConstrName(e=`c`){let t=this.constrPrefixCounters.get(e)??1,n=`${e}_${t}`;for(;this.hasConstraintName(n)||this.hasBoolVarName(n);)t++,n=`${e}_${t}`;return this.constrPrefixCounters.set(e,t+1),n}getNextLogicalConstrName(){let e=this.logicalConstrCounter+1,t=`lc_${e}`;for(;this.hasConstraintName(t)||this.hasBoolVarName(t);)e++,t=`lc_${e}`;return this.logicalConstrCounter=e,t}createBoolVar(e,t){let n=typeof e==`string`?e.trim():void 0,r=typeof t==`string`?t.trim():``,i=r.length>0?r:`p`,a=n&&n.length>0?n:this.getNextBoolVarName(i);if(this.hasVarName(a))throw Error(`Variable with name '${a}' already exists in model`);if(this.hasConstraintName(a))throw Error(`Boolean variable name '${a}' conflicts with an existing constraint in model`);let o=new c(a);return this._boolVars.push(o),this.boolVarMapByName.set(o.name,o),this.allVarsMap.set(o.name,o),this.recordModelMutation(),o}addVar(e){let t=e||{},n=typeof t.name==`string`?t.name.trim():void 0,r=n&&n.length>0?n:void 0,i=typeof t.prefix==`string`?t.prefix.trim():``,a=i.length>0?i:`x`,o=this.varPrefixCounters.get(a),s=r??this.getNextVarName(a);try{if(this.hasVarName(s))throw Error(`Variable with name '${s}' already exists in model`);let e=new H({...t,name:s,prefix:a});return e.hasExplicitName=r!==void 0,M(e),te(e,this),e.ownerModel=this,this._variables.push(e),this.varMapByName.set(e.name,e),this.allVarsMap.set(e.name,e),this.recordModelMutation(),e}catch(e){throw r===void 0&&(o===void 0?this.varPrefixCounters.delete(a):this.varPrefixCounters.set(a,o)),e}}objective(e){if(arguments.length===0)return this._objectiveExpr.clone();let t=e;if(t instanceof I||typeof t==`object`&&t&&`sense`in t&&`lhs`in t&&`rhs`in t||typeof t==`string`&&/(<=|>=|==|!=|=<|=>|<|>|=)/.test(t))throw Error("Cannot use a Constraint as an objective. Did you mean to use m.constraint(expr`... <= ...`)? To set an objective, wrap an unconstrained expression with maximize(...) or minimize(...), e.g. m.objective(maximize(expr`30 * ${x}`)).");if(typeof t!=`object`||!t||!(`expr`in t)||!(`sense`in t))throw Error("m.objective(...) expects an ObjectiveSpec created with maximize(...) or minimize(...), e.g. m.objective(maximize(expr`30 * ${x}`)).");return this.applyObjective(t.expr,t.sense),this}applyObjective(e,t){if(e instanceof I||typeof e==`object`&&e&&`sense`in e&&`lhs`in e&&`rhs`in e||typeof e==`string`&&/(<=|>=|==|!=|=<|=>|<|>|=)/.test(e))throw Error(typeof e==`string`?"Cannot use a comparison constraint as an objective. Did you mean to use m.constraint(expr`... <= ...`)? To set an objective, wrap an unconstrained expression with maximize(...) or minimize(...), e.g. m.objective(maximize(expr`30 * ${x}`)).":"Cannot use a Constraint as an objective. Did you mean to use m.constraint(expr`... <= ...`)? To set an objective, wrap an unconstrained expression with maximize(...) or minimize(...), e.g. m.objective(maximize(expr`30 * ${x}`)).");let n=t===void 0?this.sense:i(t),r;if(typeof e==`string`)r=Re(e,e=>this.varMapByName.get(e));else if(typeof e==`number`)r=new z(new Map,e);else if(e instanceof w)r=e.clone();else if(e instanceof z)r=e.clone();else if(typeof e==`object`&&e&&`quadTerms`in e&&e.quadTerms instanceof Map&&`linearTerms`in e&&e.linearTerms instanceof Map&&typeof e.constant==`number`){let t=e;r=new w(t.linearTerms,t.quadTerms,t.constant,t.nonlinearTerms)}else if(typeof e==`object`&&e&&`terms`in e&&e.terms instanceof Map&&typeof e.constant==`number`){let t=e;r=new z(t.terms,t.constant,t.nonlinearTerms)}else if(e instanceof H||typeof e==`object`&&e&&`id`in e&&`name`in e&&`lb`in e&&`ub`in e)r=new z(new Map([[e,1]]),0);else throw Error(`Invalid objective expression: expected a finite number, Var, LinExpr, QuadExpr, or arithmetic expression string.`);P(r,this.name,e=>this.varMapByName.get(e.name)===e),this._sense=n,this._objectiveExpr=r,this.recordModelMutation()}constraint(e,t){if(Array.isArray(e))return this.runTransactionalBatch(()=>{let t=[];for(let n of e)t.push(this.constraint(n));return t});if(e instanceof w||typeof e==`object`&&e&&`quadTerms`in e)throw Error(`Constraint must contain a comparison operator (<=, >=, ==): cannot add a quadratic expression as a constraint.`);if(e instanceof z||typeof e==`object`&&e&&`terms`in e)throw Error("Constraint must contain a comparison operator (<=, >=, ==): cannot add a linear expression without a comparison operator. Use expr`... <= ...` or .le(), .ge(), .eq().");if(Nr(e))throw Error(`Cannot add numeric variable "${e.name}" directly as a constraint without a comparison operator (<=, >=, ==). Numeric variables require a comparison such as expr\`\${x} <= 10\` or x.le(10), whereas propositional BoolVar variables must be created with m.bool().`);return this.addConstraint(e,t)}addConstraint(e,t){if(e instanceof w||typeof e==`object`&&e&&`quadTerms`in e)throw Error(`Constraint must contain a comparison operator (<=, >=, ==): cannot add a quadratic expression as a constraint.`);if(e instanceof z||typeof e==`object`&&e&&`terms`in e)throw Error("Constraint must contain a comparison operator (<=, >=, ==): cannot add a linear expression without a comparison operator. Use expr`... <= ...` or .le(), .ge(), .eq().");if(Nr(e))throw Error(`Cannot add numeric variable "${e.name}" directly as a constraint without a comparison operator (<=, >=, ==). Numeric variables require a comparison such as expr\`\${x} <= 10\` or x.le(10), whereas propositional BoolVar variables must be created with m.bool().`);if(e instanceof s){let n=typeof t==`string`&&t.trim().length>0?t.trim():void 0;if(n!==void 0){if(this.hasConstraintName(n))throw Error(`Constraint with name '${n}' already exists in model`);if(this.hasBoolVarName(n))throw Error(`Constraint name '${n}' conflicts with an existing Boolean variable in model`)}let r=this.logicalConstrCounter,i=n??this.getNextLogicalConstrName();try{le(e,i,this.name,e=>this.varMapByName.get(e.name)===e,e=>this.boolVarMapByName.get(e.name)===e,this)}catch(e){throw n===void 0&&(this.logicalConstrCounter=r),e}A(e,this,this.batchDepth>0?this.batchUndoActions:void 0);let a=Object.freeze({kind:`logical`,name:i,expr:e,dual:null,slack:null});return this._logicalConstraints.push(a),this.logicalConstrMapByName.set(i,a),this.allConstrsMap.set(i,a),this.recordModelMutation(),e}let n=typeof e==`string`?Be(e,e=>this.varMapByName.get(e),t):e;if(typeof n!=`object`||!n||!(`sense`in n)||!(`lhs`in n)||!(`rhs`in n))throw Error("Invalid constraint passed to m.constraint(...): expected a linear Constraint (e.g. expr`${x} <= 10` or x.le(10)), a propositional BoolVar/BoolExpr (created with m.bool()), or an array of constraints.");n.ownerModel&&n.ownerModel!==this&&(ce(n,this.name,e=>this.varMapByName.get(e.name)===e,n.name),ne(n,this));let r=typeof t==`string`&&t.trim().length>0?t.trim():n.hasExplicitName?n.name.trim():void 0;if(r!==void 0){if(this.hasConstraintName(r))throw Error(`Constraint with name '${r}' already exists in model`);if(this.hasBoolVarName(r))throw Error(`Constraint name '${r}' conflicts with an existing Boolean variable in model`)}let i=this.constrPrefixCounters.get(`c`),a=r??this.getNextConstrName(`c`),o;try{ce(n,this.name,e=>this.varMapByName.get(e.name)===e,a),o=ne(n,this)}catch(e){throw r===void 0&&(i===void 0?this.constrPrefixCounters.delete(`c`):this.constrPrefixCounters.set(`c`,i)),e}let c=n.name,l=n.hasExplicitName,u=n.ownerModel,d=o;return this.batchUndoActions.push(()=>{n.ownerModel=u,n._assignModelName(c,l),ie(n,this,d)}),this.batchDepth===0&&(this.batchUndoActions=[]),n._assignModelName(a,!0),n.ownerModel=this,this._constraints.push(n),this.constrMapByName.set(n.name,n),this.allConstrsMap.set(n.name,n),this.recordModelMutation(),n}indicator(e,t,n={}){if(e instanceof s)throw Error("Invalid binary variable passed to indicator(): received a propositional BoolVar/BoolExpr, but m.indicator() requires a 0-1 numeric binary Var created with m.binary(). For general boolean logic with m.bool(), use m.constraint(implies(flag, expr`${x} <= 10`)) with the Z3 solver.");if(!(e instanceof H))throw Error(`Invalid binary variable passed to indicator(). Expected a 0-1 binary Var instance created with m.binary() (or use implies(flag, ...) with m.bool() and the Z3 solver for general boolean logic).`);if(!(e.type===`Binary`||e.type===`Integer`&&e.lb===0&&e.ub===1))throw Error(`Invalid variable "${e.name}" passed to indicator(): variable has type "${e.type}" with bounds [${e.lb}, ${e.ub}]. Indicator activation variable must be a Binary variable created with m.binary() (or Integer variable with bounds [0, 1]).`);if(t instanceof w||typeof t==`object`&&t&&`quadTerms`in t)throw Error("Quadratic expressions or constraints are not supported in indicator constraints (only linear Constraints with <=, >=, or == such as expr`${x} <= 10` are allowed).");if(typeof t!=`object`||!t||!(`sense`in t)||!(`lhs`in t)||!(`rhs`in t))throw Error("Invalid constraint expression passed to indicator(). Expression must include a comparison operator (<=, >=, ==), e.g. m.indicator(b, expr`${x} <= 10`). For general boolean logic (such as BoolVar or implies/and/or/not), use m.constraint(implies(flag, ...)) with the Z3 solver.");let r=t;if(r.sense===`!=`)throw Error(`Constraint "${r.name}" uses discrete "!=", which is not supported in m.indicator(). Use m.constraint(implies(${e.name}.eq(1), ...)) instead.`);if(r.lhs.hasNonlinearTerms())throw Error(`Constraint "${r.name}" contains nonlinear terms (max/min/abs/at), which are not supported in m.indicator().`);let i=n.activeValue===void 0?1:n.activeValue;if(i!==0&&i!==1)throw Error(`Invalid activeValue: ${i}. Indicator activeValue must be 0 or 1.`);if(this.varMapByName.get(e.name)!==e)throw Error(`Variable "${e.name}" passed to indicator() does not belong to model "${this.name}". All variables must belong to the model by object identity.`);let a=typeof n.name==`string`&&n.name.trim().length>0?n.name.trim():void 0,o=this.constrPrefixCounters.get(`c`),{lhs:c,sense:l,rhs:u}=r,d,f,p;if(a!==void 0)d=a,f=l===`==`?`${d}_le`:d,p=l===`==`?`${d}_ge`:d;else if(r.hasExplicitName)d=`ind_${e.name}_${r.name.trim()}`,f=l===`==`?`${d}_le`:d,p=l===`==`?`${d}_ge`:d;else do{let t=this.getNextConstrName(`c`);d=`ind_${e.name}_${t}`,f=l===`==`?`${d}_le`:d,p=l===`==`?`${d}_ge`:d}while((l===`<=`||l===`==`)&&(this.hasConstraintName(f)||this.hasBoolVarName(f))||(l===`>=`||l===`==`)&&(this.hasConstraintName(p)||this.hasBoolVarName(p)));let m=[];try{if((l===`<=`||l===`==`)&&(this.hasConstraintName(f)||this.hasBoolVarName(f)))throw Error(this.hasBoolVarName(f)?`Constraint name '${f}' conflicts with an existing Boolean variable in model`:`Constraint with name '${f}' already exists in model`);if((l===`>=`||l===`==`)&&(this.hasConstraintName(p)||this.hasBoolVarName(p)))throw Error(this.hasBoolVarName(p)?`Constraint name '${p}' conflicts with an existing Boolean variable in model`:`Constraint with name '${p}' already exists in model`);n.M!==void 0&&lr(n.M,d);let t=e=>this.varMapByName.get(e.name)===e;for(let[e]of c.terms)if(!t(e))throw Error(`Variable "${e.name}" in constraint "${d}" does not belong to model "${this.name}". All variables must belong to the model by object identity.`);if(l===`<=`||l===`==`){let t=n.M===void 0?dr(c,u,f):n.M,r=pr(e,c,`<=`,u,i,t,f),a=new I(r.lhs,`<=`,r.rhs,f);n.M===void 0&&a._setIndicatorOrigin({binVar:e,activeValue:i,targetLhs:c.clone(),targetSense:`<=`,targetRhs:u,derivedM:t}),m.push([a,f])}if(l===`>=`||l===`==`){let t=n.M===void 0?fr(c,u,p):n.M,r=pr(e,c,`>=`,u,i,t,p),a=new I(r.lhs,`>=`,r.rhs,p);n.M===void 0&&a._setIndicatorOrigin({binVar:e,activeValue:i,targetLhs:c.clone(),targetSense:`>=`,targetRhs:u,derivedM:t}),m.push([a,p])}for(let[e,n]of m)ce(e,this.name,t,n)}catch(e){throw o===void 0?this.constrPrefixCounters.delete(`c`):this.constrPrefixCounters.set(`c`,o),e}return this.runTransactionalBatch(()=>m.map(([e,t])=>this.addConstraint(e,t)))}toLpString(){if(this.validateIntegrityInternal(),Or(this._objectiveExpr,this._constraints)){let e=_r(this._variables,[],this._constraints,[],{expr:this._objectiveExpr,sense:this.sense}),{lpString:t}=Je({name:this.name,sense:this.sense,objective:e.objective??this._objectiveExpr,constraints:e.constraints,variables:e.variables});return t}let{lpString:e}=Je({name:this.name,sense:this.sense,objective:this._objectiveExpr.clone(),constraints:this._constraints,variables:this._variables});return e}validateIntegrityInternal(){F({model:this,name:this.name,variables:this._variables,boolVars:this._boolVars,constraints:this._constraints,logicalConstraints:this._logicalConstraints,objectiveExpr:this._objectiveExpr,getVarByName:e=>this.varMapByName.get(e),getBoolVarByName:e=>this.boolVarMapByName.get(e),getConstraintByName:e=>this.constrMapByName.get(e),getLogicalConstraintByName:e=>this.logicalConstrMapByName.get(e)})}ensureExecutionValid(e,t,n){if(this.modelRevision!==e)throw this.activeOperationId===t&&this.clearSolutionFields(),Error(`Model "${this.name}" was modified while ${n}() was in progress; stale solver result was discarded.`);if(this.activeOperationId!==t)throw Error(`Stale ${n}() result discarded because a newer solve or check operation was started on model "${this.name}".`)}wrapSolveOptions(e,t,n){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`))}normalizePrimalValue(e,t,n,r){return(r.relax??n.options?.relax)!==!0&&(e.type===`Integer`||e.type===`Binary`)&&Math.abs(t-Math.round(t))<=1e-5?Math.round(t)+0:t}resolveSolverAndOptions(e,t){if(e&&typeof e==`object`&&`solve`in e&&typeof e.solve==`function`){let{solver:n,...r}=t||{};return{activeSolver:e,activeOptions:r}}if(typeof e==`function`){let{solver:n,...r}=t||{};return{activeSolver:new e(r),activeOptions:r}}if(typeof e==`string`){let{solver:n,...r}=t||{};return{activeSolver:tt(e,r),activeOptions:r}}let{solver:n,...r}=e||{};return n?{activeSolver:tt(n,r),activeOptions:r}:{activeSolver:this.solver||tt(),activeOptions:r}}async relax(e,t){let n=typeof e==`object`&&!!e&&!(`solve`in e),r=n?{...e,relax:!0}:{...t||{},relax:!0},i=n?void 0:e;return i?this.solve(i,r):this.solve(r)}async solve(e,t){let n=++this.activeOperationId,r=this.modelRevision;this.clearSolutionFields(),this.validateIntegrityInternal();let{activeSolver:i,activeOptions:a}=this.resolveSolverAndOptions(e,t);if(this._objectiveExpr instanceof w&&this._objectiveExpr.quadTerms.size>0&&i.capabilities?.supportsQP===!1)throw Error(`Solver "${i.name}" does not support quadratic objectives (QP). Please use a QP-capable solver such as HiGHS or Clarabel.`);let o,s=null;if(i.capabilities?.supportsLogicalConstraints!==!0&&i.capabilities?.supportsSMT!==!0&&(this._logicalConstraints.length>0||this._boolVars.length>0||Or(this._objectiveExpr,this._constraints))?(s=_r(this._variables,this._boolVars,this._constraints,this._logicalConstraints,{expr:this._objectiveExpr,sense:this.sense}),o={name:this.name,sense:this.sense,objective:s.objective??this._objectiveExpr,constraints:s.constraints,variables:s.variables,logicalConstraints:[],boolVars:[]}):o={name:this.name,sense:this.sense,objective:this._objectiveExpr,constraints:this._constraints,variables:this._variables,logicalConstraints:this._logicalConstraints,boolVars:this._boolVars},this._variables.some(e=>e.initialValue!==void 0)&&i.capabilities?.supportsWarmStart!==!0)throw Error(`Solver "${i.name}" does not support primal initial values (initialValue). Please use a solver with warm-start support such as HiGHS or Pumpkin.`);let c=this.wrapSolveOptions(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.relativeGap==`number`&&Number.isFinite(l.relativeGap)?l.relativeGap:void 0;this.relativeGap=d,this.absoluteGap=typeof l.absoluteGap==`number`&&Number.isFinite(l.absoluteGap)?l.absoluteGap:this.objectiveValue!==null&&this.objectiveBound!==void 0?Math.abs(this.objectiveValue-this.objectiveBound):void 0;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.varMapByName.get(e),r=this.boolVarMapByName.get(e);if(n){let e=this.normalizePrimalValue(n,t,i,a);n.value=e,f(p,n.name,e),this._values.set(n.name,e)}r&&(r.value=!!t,this._values.set(r.name,t)),!n&&!r&&!s&&this._values.set(e,t)}else if(typeof t==`boolean`){let n=t,r=this.boolVarMapByName.get(e);r?(r.value=n,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.boolVarMapByName.get(e);n?(n.value=t,this._values.has(n.name)||this._values.set(n.name,t)):this._values.has(e)||this._values.set(e,t)}if(u&&l.reducedCosts)for(let[e,t]of Object.entries(l.reducedCosts)){if(typeof t!=`number`||!Number.isFinite(t))continue;let n=this.varMapByName.get(e);n&&(n.reducedCost=t,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.constrMapByName.get(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.constrMapByName.get(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.relativeGap===void 0?{}:{relativeGap:this.relativeGap},...this.absoluteGap===void 0?{}:{absoluteGap:this.absoluteGap},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.validateIntegrityInternal();let{activeSolver:i,activeOptions:a}=this.resolveSolverAndOptions(e,t);if(this._variables.some(e=>e.initialValue!==void 0)&&i.capabilities?.supportsWarmStart!==!0)throw Error(`Solver "${i.name}" does not support primal initial values (initialValue). Please use a solver with warm-start support such as HiGHS or Pumpkin.`);let o=this.wrapSolveOptions(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.varMapByName.get(n),o=this.boolVarMapByName.get(n);if(e){let n=this.normalizePrimalValue(e,r,i,a);e.value=n,this._values.set(e.name,n),s(t,e.name,n)}o&&(o.value=!!r,this._values.set(o.name,o.value),s(t,o.name,o.value)),!e&&!o&&(this._values.set(n,r),s(t,n,r))}else if(typeof r==`boolean`){let e=this.boolVarMapByName.get(n);e?(e.value=r,this._values.set(e.name,r),s(t,e.name,r)):(this._values.set(n,r),s(t,n,r))}}return this.hasSolutionState=!0,{status:e.status,values:t,unsatCore:this.unsatCore,conflicts:this.conflicts,runTime:this.runTime}}let l=this._logicalConstraints.length>0||this._boolVars.length>0||kr(this._constraints)?_r(this._variables,this._boolVars,this._constraints,this._logicalConstraints):{variables:[...this._variables],constraints:[...this._constraints],boolVarToBinary:new Map,constraintToOriginalName:new Map(this._constraints.map(e=>[e,e.name]))},u=[],d=[],f=[],p=new Map,m=0;for(let e of l.constraints){let t=l.constraintToOriginalName.get(e)??e.name,{lhs:n,sense:r,rhs:i}=e;if(r===`<=`){let r=new H({name:`__slack_${++m}`,type:`Continuous`,lb:0,ub:1/0});d.push(r),f.push([r,1]),p.set(r,t);let a=n.clone().add(new z(new Map([[r,-1]]),0));u.push(new I(a,`<=`,i,`${e.name}_slack`))}else if(r===`>=`){let r=new H({name:`__slack_${++m}`,type:`Continuous`,lb:0,ub:1/0});d.push(r),f.push([r,1]),p.set(r,t);let a=n.clone().add(new z(new Map([[r,1]]),0));u.push(new I(a,`>=`,i,`${e.name}_slack`))}else{let r=new H({name:`__slack_${++m}_p`,type:`Continuous`,lb:0,ub:1/0}),a=new H({name:`__slack_${++m}_n`,type:`Continuous`,lb:0,ub:1/0});d.push(r,a),f.push([r,1],[a,1]),p.set(r,t),p.set(a,t);let o=n.clone().add(new z(new Map([[r,-1],[a,1]]),0));u.push(new I(o,`==`,i,`${e.name}_slack`))}}let h={name:`${this.name}_elastic_check`,sense:`Minimize`,objective:new z(new Map(f),0),constraints:u,variables:[...l.variables,...d]},g;try{g=await i.solve(h,o)}catch(e){throw this.activeOperationId===n&&this.clearSolutionFields(),e}this.ensureExecutionValid(r,n,`check`),this.runTime=g.runTime??0;let _=g.status,v=g.terminationStatus??_,y=this.hasPrimalFromResult(g),b=typeof g.objectiveValue==`number`&&Number.isFinite(g.objectiveValue)?g.objectiveValue:1/0,x=(_===`Optimal`||_===`Feasible`||y)&&b<=1e-5,S=typeof g.objectiveBound==`number`&&Number.isFinite(g.objectiveBound)&&g.objectiveBound>1e-5,C=!x&&(_===`Infeasible`||_===`Optimal`&&b>1e-5||S),w=x?`Sat`:C?`Unsat`:`Unknown`;this.status=w,this.terminationStatus=a.signal?.aborted||v===`Interrupted`?`Interrupted`:v===`Optimal`||v===`Feasible`||v===`Infeasible`?w:v,this.hasPrimalSolution=x,this.objectiveValue=null,this.objectiveBound=void 0,this.relativeGap=void 0,this.absoluteGap=void 0,this.solution=null,this._values.clear();let T={};if(x&&g.values){for(let e of this._variables){let t=g.values[e.name];if(typeof t==`number`&&Number.isFinite(t)){let n=this.normalizePrimalValue(e,t,i,a);e.value=n,this._values.set(e.name,n),s(T,e.name,n)}}for(let e of this._boolVars){let t=l.boolVarToBinary.get(e),n=t?g.values[t.name]:g.values[e.name];if(typeof n==`number`&&Number.isFinite(n)){let t=Math.round(n)===1;e.value=t,this._values.set(e.name,t),s(T,e.name,t)}}}let E=new Set;if(C&&g.values)for(let[e,t]of p.entries()){let n=g.values[e.name];typeof n==`number`&&n>1e-5&&E.add(t)}return this.conflicts=C?Object.freeze(Array.from(E)):void 0,this.unsatCore=void 0,this.hasSolutionState=!0,{status:w,values:T,conflicts:this.conflicts,unsatCore:this.unsatCore,runTime:this.runTime}}verify(e={}){return cr(this,e)}link(e){if(e instanceof w||typeof e==`object`&&e&&`quadTerms`in e)throw Error(`Linking constraint cannot be a quadratic expression.`);if(!(e instanceof I)&&(typeof e!=`object`||!e||!(`sense`in e)||!(`lhs`in e)||!(`rhs`in e)))throw Error("Linking constraint must contain a comparison operator (<=, >=, ==). Use expr`... <= ...` or .le(), .ge(), .eq().");this._linkingConstraints||=[];let t=e;return this._linkingConstraints.push(t),t}get linkingConstraints(){return this._linkingConstraints??[]}async solveBenders(e){let t=await Dr({master:this,...e});return this.decomposition=t,t}async solveColumnGeneration(e){let t=await br({master:this,...e});return this.decomposition=t,t}};return e.BoolExpr=s,e.BoolOp=l,e.BoolVar=c,e.Constraint=I,e.GlobalConstraint=h,e.LinExpr=z,e.MockSolver=rt,e.Model=Fr,e.QuadExpr=w,e.Var=H,e.abs=_e,e.allowed=S,e.and=u,e.at=V,e.buildIndicatorLinearization=pr,e.buildLpSymbolMaps=qe,e.cumulative=x,e.deriveBigMForGe=fr,e.deriveBigMForLe=dr,e.disjoint=b,e.distinct=v,e.dot=ge,e.expr=We,e.generateLpString=Je,e.getSolver=tt,e.implies=p,e.isLpExportResult=Ge,e.linearizeModelForMip=_r,e.listAvailableSolvers=nt,e.max=be,e.maximize=Sr,e.min=xe,e.minimize=Cr,e.normalizeSense=i,e.not=f,e.or=d,e.parseConstraint=Be,e.parseExpr=Re,e.registerSolver=$e,e.sanitizeIdentifier=Ke,e.setDefaultSolver=et,e.solveBenders=Dr,e.solveColumnGeneration=br,e.sum=B,e.validateUserBigM=lr,e.xor=m,e})({});
|
|
6
|
+
`,"%p":e=>e.tm_hour>=0&&e.tm_hour<12?`AM`:`PM`,"%S":e=>f(e.tm_sec,2),"%t":()=>` `,"%u":e=>e.tm_wday||7,"%U":e=>{var t=e.tm_yday+7-e.tm_wday;return f(Math.floor(t/7),2)},"%V":e=>{var t=Math.floor((e.tm_yday+7-(e.tm_wday+6)%7)/7);if((e.tm_wday+371-e.tm_yday-2)%7<=2&&t++,!t){t=52;var n=(e.tm_wday+7-e.tm_yday-1)%7;(n==4||n==5&&mt(e.tm_year%400-1))&&t++}else if(t==53){var r=(e.tm_wday+371-e.tm_yday)%7;r!=4&&(r!=3||!mt(e.tm_year))&&(t=1)}return f(t,2)},"%w":e=>e.tm_wday,"%W":e=>{var t=e.tm_yday+7-(e.tm_wday+6)%7;return f(Math.floor(t/7),2)},"%y":e=>(e.tm_year+1900).toString().substring(2),"%Y":e=>e.tm_year+1900,"%z":e=>{var t=e.tm_gmtoff,n=t>=0;return t=Math.abs(t)/60,t=t/60*100+t%60,(n?`+`:`-`)+String(`0000`+t).slice(-4)},"%Z":e=>e.tm_zone,"%%":()=>`%`};for(var c in o=o.replace(/%%/g,`\0\0`),g)o.includes(c)&&(o=o.replace(new RegExp(c,`g`),g[c](a)));o=o.replace(/\0\0/g,`%`);var _=Oe(o,!1);return _.length>t?0:(yt(_,e),_.length-1)},xt=(e,t,n,r,i)=>bt(e,t,n,r),St=e=>n[`_`+e],Ct=(e,t,n)=>De(e,S,t,n),wt=e=>{var t=Ee(e)+1,n=Dn(t);return Ct(e,n,t),n},Tt=(e,t,n,r,i)=>{var a={string:e=>{var t=0;return e!=null&&e!==0&&(t=wt(e)),t},array:e=>{var t=Dn(e.length);return yt(e,t),t}};function o(e){return t===`string`?Re(e):t===`boolean`?!!e:e}var s=St(e),c=[],l=0;if(r)for(var u=0;u<r.length;u++){var d=a[n[u]];d?(l===0&&(l=Tn()),c[u]=d(r[u])):c[u]=r[u]}var f=s.apply(null,c);function p(e){return l!==0&&En(l),o(e)}return f=p(f),f},Et=(e,t,n,r)=>{var i=!n||n.every(e=>e===`number`||e===`boolean`);return t!==`string`&&i&&!r?St(e):function(){return Tt(e,t,n,arguments,r)}},Dt=(e,t)=>{e<128?t.push(e):t.push(e%128|128,e>>7)},Ot=e=>{for(var t={i:`i32`,j:`i64`,f:`f32`,d:`f64`,e:`externref`,p:`i32`},n={parameters:[],results:e[0]==`v`?[]:[t[e[0]]]},r=1;r<e.length;++r)n.parameters.push(t[e[r]]);return n},kt=(e,t)=>{var n=e.slice(0,1),r=e.slice(1),i={i:127,p:127,j:126,f:125,d:124,e:111};t.push(96),Dt(r.length,t);for(var a=0;a<r.length;++a)t.push(i[r[a]]);n==`v`?t.push(0):t.push(1,i[n])},At=(e,t)=>{if(typeof WebAssembly.Function==`function`)return new WebAssembly.Function(Ot(t),e);var n=[1];kt(t,n);var r=[0,97,115,109,1,0,0,0,1];Dt(n.length,r),r.push.apply(r,n),r.push(2,7,1,1,101,1,102,0,0,7,5,1,1,102,0,0);var i=new WebAssembly.Module(new Uint8Array(r));return new WebAssembly.Instance(i,{e:{f:e}}).exports.f},jt=[],Mt,Nt=e=>{var t=jt[e];return t||(e>=jt.length&&(jt.length=e+1),jt[e]=t=Mt.get(e)),t},Pt=(e,t)=>{if(Ft)for(var n=e;n<e+t;n++){var r=Nt(n);r&&Ft.set(r,n)}},Ft,It=e=>(Ft||(Ft=new WeakMap,Pt(0,Mt.length)),Ft.get(e)||0),Lt=[],Rt=()=>{if(Lt.length)return Lt.pop();try{Mt.grow(1)}catch(e){throw e instanceof RangeError?`Unable to grow wasm table. Set ALLOW_TABLE_GROWTH.`:e}return Mt.length-1},zt=(e,t)=>{Mt.set(e,t),jt[e]=Mt.get(e)},Bt=(e,t)=>{var n=It(e);if(n)return n;var r=Rt();try{zt(r,e)}catch(n){if(!(n instanceof TypeError))throw n;zt(r,At(e,t))}return Ft.set(e,r),r},Vt=e=>{Ft.delete(Nt(e)),zt(e,null),Lt.push(e)},Ht=function(e,t,n,r){e||=this,this.parent=e,this.mount=e.mount,this.mounted=null,this.id=K.nextInode++,this.name=t,this.mode=n,this.node_ops={},this.stream_ops={},this.rdev=r},Ut=365,Wt=146;Object.defineProperties(Ht.prototype,{read:{get:function(){return(this.mode&Ut)===Ut},set:function(e){e?this.mode|=Ut:this.mode&=~Ut}},write:{get:function(){return(this.mode&Wt)===Wt},set:function(e){e?this.mode|=Wt:this.mode&=~Wt}},isFolder:{get:function(){return K.isDir(this.mode)}},isDevice:{get:function(){return K.isChrdev(this.mode)}}}),K.FSNode=Ht,K.createPreloadedFile=Fe,K.staticInit();var Gt={g:ze,p:Be,h:Ve,i:He,c:Ue,e:We,j:Ke,b:qe,q:Je,r:Xe,m:tt,n:nt,a:ot,f:st,o:lt,k:dt,d:pt,l:xt},Y=he(),Kt=n._Highs_create=()=>(Kt=n._Highs_create=Y.u)(),qt=n._Highs_destroy=e=>(qt=n._Highs_destroy=Y.v)(e),Jt=n._Highs_version=()=>(Jt=n._Highs_version=Y.w)(),X=n._Highs_run=e=>(X=n._Highs_run=Y.x)(e),Yt=n._Highs_readModel=(e,t)=>(Yt=n._Highs_readModel=Y.y)(e,t),Xt=n._Highs_getNumCol=e=>(Xt=n._Highs_getNumCol=Y.z)(e),Zt=n._Highs_clearModel=e=>(Zt=n._Highs_clearModel=Y.A)(e),Qt=n._Highs_setBoolOptionValue=(e,t,r)=>(Qt=n._Highs_setBoolOptionValue=Y.B)(e,t,r),$t=n._Highs_setIntOptionValue=(e,t,r)=>($t=n._Highs_setIntOptionValue=Y.C)(e,t,r),en=n._Highs_setDoubleOptionValue=(e,t,r)=>(en=n._Highs_setDoubleOptionValue=Y.D)(e,t,r),tn=n._Highs_setStringOptionValue=(e,t,r)=>(tn=n._Highs_setStringOptionValue=Y.E)(e,t,r),nn=n._Highs_getIntInfoValue=(e,t,r)=>(nn=n._Highs_getIntInfoValue=Y.F)(e,t,r),rn=n._Highs_getDoubleInfoValue=(e,t,r)=>(rn=n._Highs_getDoubleInfoValue=Y.G)(e,t,r),an=n._Highs_getInt64InfoValue=(e,t,r)=>(an=n._Highs_getInt64InfoValue=Y.H)(e,t,r),on=n._Highs_getSolution=(e,t,r,i,a)=>(on=n._Highs_getSolution=Y.I)(e,t,r,i,a),sn=n._Highs_getModelStatus=e=>(sn=n._Highs_getModelStatus=Y.J)(e),cn=n._Highs_getObjectiveValue=e=>(cn=n._Highs_getObjectiveValue=Y.K)(e),ln=n._Highs_getNumRow=e=>(ln=n._Highs_getNumRow=Y.L)(e),un=n._Highs_setSolution=(e,t,r,i,a)=>(un=n._Highs_setSolution=Y.M)(e,t,r,i,a),dn=n._Highs_setSparseSolution=(e,t,r,i)=>(dn=n._Highs_setSparseSolution=Y.N)(e,t,r,i),fn=n._Highs_setCallback=(e,t,r)=>(fn=n._Highs_setCallback=Y.O)(e,t,r),pn=n._Highs_startCallback=(e,t)=>(pn=n._Highs_startCallback=Y.P)(e,t),mn=n._Highs_stopCallback=(e,t)=>(mn=n._Highs_stopCallback=Y.Q)(e,t),hn=n._Highs_changeObjectiveOffset=(e,t)=>(hn=n._Highs_changeObjectiveOffset=Y.R)(e,t),gn=n._Highs_getObjectiveOffset=(e,t)=>(gn=n._Highs_getObjectiveOffset=Y.S)(e,t),_n=n._Highs_getRowName=(e,t,r)=>(_n=n._Highs_getRowName=Y.T)(e,t,r),vn=n._Highs_getColName=(e,t,r)=>(vn=n._Highs_getColName=Y.U)(e,t,r),yn=n._Highs_getColIntegrality=(e,t,r)=>(yn=n._Highs_getColIntegrality=Y.V)(e,t,r),bn=n._Highs_getNumNz=e=>(bn=n._Highs_getNumNz=Y.W)(e),xn=()=>(xn=Y.X)(),Sn=n._malloc=e=>(Sn=n._malloc=Y.Y)(e),Cn=n._free=e=>(Cn=n._free=Y.Z)(e),wn=()=>(wn=Y._)(),Tn=()=>(Tn=Y.$)(),En=e=>(En=Y.aa)(e),Dn=e=>(Dn=Y.ba)(e);n.wasmMemory=v,n.ccall=Tt,n.cwrap=Et,n.addFunction=Bt,n.removeFunction=Vt,n.setValue=be,n.getValue=ve,n.UTF8ToString=Re,n.stringToUTF8=Ct,n.FS=K;var On;N=function e(){On||kn(),On||(N=e)};function kn(){if(oe>0||(ne(),oe>0))return;function e(){On||(On=!0,n.calledRun=!0,!y&&(re(),r(n),n.onRuntimeInitialized&&n.onRuntimeInitialized(),ie()))}n.setStatus?(n.setStatus(`Running...`),setTimeout(function(){setTimeout(function(){n.setStatus(``)},1),e()},1)):e()}if(n.preInit)for(typeof n.preInit==`function`&&(n.preInit=[n.preInit]);n.preInit.length>0;)n.preInit.pop()();return kn(),t.ready})})()})),Mt=r({default:()=>Nt});async function Nt(e={}){let t=await At(e);return new Ot(t)}var Pt=n((()=>{jt(),kt()}));kt();var Ft=[`mip_max_nodes`,`mip_max_improving_sols`,`mip_max_leaves`,`simplex_iteration_limit`,`ipm_iteration_limit`],It=new Set([`timeLimit`,`outputFlag`,`presolve`,`solver`,`relativeGap`,`absoluteGap`,`wasmUrl`,`signal`,`onProgress`,`onIncumbent`,`relax`,`useWorker`,`objectiveOffset`,`initialValues`,...Ft]);function Lt(e={}){if(e.threads!==void 0)throw Error(`Solver "HiGHS" does not support option "threads" (HiGHS WebAssembly runs single-threaded).`);if(e.verbose!==void 0)throw Error(`Solver "HiGHS" does not support option "verbose"; use "outputFlag" instead.`);for(let[t,n]of Object.entries(e))if(n!==void 0&&!It.has(t))throw Error(`Solver "HiGHS" does not support option "${t}".`);if(e.useWorker!==void 0&&typeof e.useWorker!=`boolean`)throw Error(`Invalid HiGHS option "useWorker": expected boolean, got ${typeof e.useWorker}.`);if(e.outputFlag!==void 0&&typeof e.outputFlag!=`boolean`)throw Error(`Invalid HiGHS option "outputFlag": expected boolean, got ${typeof e.outputFlag}.`);if(e.relax!==void 0&&typeof e.relax!=`boolean`)throw Error(`Invalid HiGHS option "relax": expected boolean, got ${typeof e.relax}.`);if(e.presolve!==void 0&&e.presolve!==`on`&&e.presolve!==`off`&&e.presolve!==`choose`)throw Error(`Invalid HiGHS option "presolve" (${String(e.presolve)}): expected "on", "off", or "choose".`);if(e.timeLimit!==void 0&&(typeof e.timeLimit!=`number`||!Number.isFinite(e.timeLimit)||e.timeLimit<0))throw Error(`Invalid HiGHS option "timeLimit" (${String(e.timeLimit)}): expected a finite non-negative number of seconds.`);if(e.relativeGap!==void 0&&(typeof e.relativeGap!=`number`||!Number.isFinite(e.relativeGap)||e.relativeGap<0))throw Error(`Invalid HiGHS option "relativeGap" (${String(e.relativeGap)}): expected a finite non-negative number.`);if(e.absoluteGap!==void 0&&(typeof e.absoluteGap!=`number`||!Number.isFinite(e.absoluteGap)||e.absoluteGap<0))throw Error(`Invalid HiGHS option "absoluteGap" (${String(e.absoluteGap)}): expected a finite non-negative number.`);if(e.objectiveOffset!==void 0&&(typeof e.objectiveOffset!=`number`||!Number.isFinite(e.objectiveOffset)))throw Error(`Invalid HiGHS option "objectiveOffset" (${String(e.objectiveOffset)}): expected a finite number.`);if(e.wasmUrl!==void 0&&e.wasmUrl!==null&&(typeof e.wasmUrl!=`string`||e.wasmUrl===``))throw Error(`Invalid HiGHS option "wasmUrl": expected a non-empty string or null.`)}var Rt=null,zt=null,Bt=null;function Vt(){return Bt}async function Ht(e){return e||vt()}async function Ut(e,t){if(e.wasmUrl){let t=await Ht(e.wasmUrl);return{isNode:!1,wasmUrl:t,wasmBinary:null,key:t?`url:${t}`:`node`}}if(t===null)return null;if(t.kind===`embedded`)return{isNode:!1,wasmUrl:null,wasmBinary:t.bytes,key:`__embedded__`};let n=await Ht();return{isNode:!1,wasmUrl:n,wasmBinary:null,key:n?`url:${n}`:`node`}}async function Wt(e={}){let t=await Ut(e,pt(`highs`));if(!t)throw Error(`[WaSHI] Failed to resolve HiGHS WASM target.`);let{isNode:n,wasmUrl:r,wasmBinary:i,key:a}=t;if(Rt&&zt===a)return Rt;zt=a;let o=null;return o=(async()=>{let e=n?await yt():(await Promise.resolve().then(()=>(Pt(),Mt))).default;return i?await e({wasmBinary:i.slice(),locateFile:e=>e}):n?await e():await e({locateFile:e=>e.endsWith(`.wasm`)?r:e})})().then(e=>e).catch(e=>{Rt===o&&(Rt=null,zt=null);let t=e instanceof Error?e.message:String(e),n=i?` from embedded inline WASM`:r?` from "${r}"`:``;throw Error(`[WaSHI] Failed to initialize HiGHS${n}. Deploy the package's WASM asset or explicitly set wasmUrl; no CDN fallback is attempted. ${t}`,{cause:e})}),Rt=o,o}async function Gt(e,t={}){if(Lt(t),t.signal?.aborted)return{result:{Status:`Interrupted`,StatusCode:17,HasPrimalSolution:!1,ObjectiveValue:NaN,Columns:{},Rows:[]},runTime:0};let n=await Wt(t);if(t.signal?.aborted)return{result:{Status:`Interrupted`,StatusCode:17,HasPrimalSolution:!1,ObjectiveValue:NaN,Columns:{},Rows:[]},runTime:0};let r=performance.now(),i={output_flag:t.outputFlag??!1};t.timeLimit!==void 0&&(i.time_limit=t.timeLimit),t.presolve!==void 0&&(i.presolve=t.presolve),t.solver!==void 0&&(i.solver=t.solver),t.relativeGap!==void 0&&(i.mip_rel_gap=t.relativeGap),t.absoluteGap!==void 0&&(i.mip_abs_gap=t.absoluteGap);for(let e of Ft)t[e]!==void 0&&(i[e]=t[e]);let a=t.objectiveOffset??0,o=t.initialValues,s=!1;if(o){for(let[e,t]of Object.entries(o))if(t!==void 0){if(typeof t!=`number`||!Number.isFinite(t))throw Error(`Invalid initial value for column "${e}": ${String(t)} (must be a finite number).`);s=!0}}if(typeof n.withModel!=`function`)throw Error(`[WaSHI] HiGHS runtime is missing required withModel() API (legacy highs.solve fallback has been removed).`);return{result:n.withModel({format:`lp`,data:e},e=>{let c=!1;if(a!==0){if(typeof e.changeObjectiveOffset!=`function`)throw Error(`[WaSHI] HiGHS runtime does not support changeObjectiveOffset() for non-zero objectiveOffset.`);let t=typeof e.getObjectiveOffset==`function`?e.getObjectiveOffset():0;e.changeObjectiveOffset(t+a),c=!0}for(let[t,n]of Object.entries(i))e.options.set(t,n);let l=e.getDimensions(),u=[],d=!1;for(let t=0;t<l.numCols;t++){let n=e.getColIntegrality(t);n!==0&&(d=!0),u.push({name:e.getColName(t),type:n===1?`Integer`:`Continuous`})}if(s&&o){if(typeof e.setSolution!=`function`)throw Error(`HiGHS runtime does not support setting primal initial values (setSolution is unavailable).`);let t=new Map;for(let e=0;e<l.numCols;e++)t.set(u[e].name,e);for(let[e,n]of Object.entries(o))if(n!==void 0&&!t.has(e))throw Error(`Unknown column "${e}" in initialValues (column does not exist in the HiGHS LP model).`);let n=[],r=[];for(let e=0;e<l.numCols;e++){let t=u[e].name;if(Object.prototype.hasOwnProperty.call(o,t)){let i=o[t];i!==void 0&&(n.push(e),r.push(i))}}n.length>0&&(n.length===l.numCols?e.setSolution({colValue:r}):e.setSolution({indices:n,values:r}))}let f=null,p=null,m=0,h=e=>{let t=e?.data??{},n=typeof t.running_time==`number`&&Number.isFinite(t.running_time)?t.running_time:(performance.now()-r)/1e3,i=typeof t.mip_primal_bound==`number`&&Number.isFinite(t.mip_primal_bound)?t.mip_primal_bound:typeof t.objective_function_value==`number`&&Number.isFinite(t.objective_function_value)?t.objective_function_value:void 0,a=typeof t.mip_dual_bound==`number`&&Number.isFinite(t.mip_dual_bound)?t.mip_dual_bound:void 0,o=typeof t.mip_gap==`number`&&Number.isFinite(t.mip_gap)?t.mip_gap:void 0,s=i!==void 0&&a!==void 0?Math.abs(i-a):void 0,c=typeof t.mip_node_count==`bigint`?Number(t.mip_node_count):typeof t.mip_node_count==`number`&&Number.isFinite(t.mip_node_count)?t.mip_node_count:void 0,l=typeof t.mip_total_lp_iterations==`bigint`?Number(t.mip_total_lp_iterations):typeof t.simplex_iteration_count==`number`&&Number.isFinite(t.simplex_iteration_count)?t.simplex_iteration_count:typeof t.ipm_iteration_count==`number`&&Number.isFinite(t.ipm_iteration_count)?t.ipm_iteration_count:void 0,u=typeof e?.message==`string`&&e.message.trim().length>0?e.message.trim():void 0,d={elapsedTime:n,elapsedSeconds:n,...i===void 0?{}:{objectiveValue:i},...a===void 0?{}:{objectiveBound:a},...o===void 0?{}:{relativeGap:o},...s===void 0?{}:{absoluteGap:s},...c===void 0?{}:{nodes:c},...l===void 0?{}:{iterations:l},...u===void 0?{}:{message:u}};return p=d,d},g=e=>{let n=e?.data;if(!n||!(n.mip_solution instanceof Float64Array))return;let r=n.mip_solution,i={};for(let e=0;e<u.length&&e<r.length;e++)Object.defineProperty(i,u[e].name,{value:{Index:e,Type:u[e].type,Name:u[e].name,Primal:r[e]},enumerable:!0,writable:!0,configurable:!0});let a=typeof n.objective_function_value==`number`&&Number.isFinite(n.objective_function_value)?n.objective_function_value:typeof n.mip_primal_bound==`number`&&Number.isFinite(n.mip_primal_bound)?n.mip_primal_bound:NaN;Number.isFinite(a)&&(f={objectiveValue:a,...typeof n.mip_dual_bound==`number`&&Number.isFinite(n.mip_dual_bound)?{mipDualBound:n.mip_dual_bound}:{},...typeof n.mip_gap==`number`&&Number.isFinite(n.mip_gap)?{mipGap:n.mip_gap}:{},columns:i},t.onIncumbent?.(f))},_=!1;if(t.signal||t.onProgress||t.onIncumbent){let r=n.constants?.callbackType??{logging:0,simplexInterrupt:1,ipmInterrupt:2,mipSolution:3,mipImprovingSolution:4,mipLogging:5,mipInterrupt:6},i=e=>{if(t.signal?.aborted){_=!0,e.interrupt();return}t.onProgress&&(m++,t.onProgress(h(e)),t.signal?.aborted&&(_=!0,e.interrupt()))},a={[r.simplexInterrupt]:i,[r.ipmInterrupt]:i,[r.mipInterrupt]:i,[r.mipImprovingSolution]:e=>{g(e),t.onProgress&&!t.signal?.aborted&&(m++,t.onProgress(h(e)))},[r.mipLogging]:e=>{t.onProgress&&!t.signal?.aborted&&(m++,t.onProgress(h(e)))}};e.run(a)}else e.run();let v=e.getModelStatus();_&&(v=17);let y=wt[v]??`Unknown`,b=0,x=0;try{b=Number(e.info.get(`primal_solution_status`))}catch{}try{x=Number(e.info.get(`dual_solution_status`))}catch{}let S=n.constants?.solutionStatus?.feasible??2,C=b===S,w=x===S,T=C||w?e.getSolution():null,E=C,D={};if(!C&&f!==null)E=!0,D=f.columns;else for(let e=0;e<l.numCols;e++){let t=u[e],n={Index:e,Type:t.type,Name:t.name};C&&T&&(n.Primal=T.colValue[e]),!d&&w&&T&&(n.Dual=T.colDual[e]),Object.defineProperty(D,t.name,{value:n,enumerable:!0,writable:!0,configurable:!0})}let ee=[];for(let t=0;t<l.numRows;t++){let n=e.getRowName(t),r={Index:t,Name:n};C&&T&&(r.Primal=T.rowValue[t]),!d&&w&&T&&(r.Dual=T.rowDual[t]),ee.push(r)}let O=C?e.getObjectiveValue():f===null?NaN:f.objectiveValue,k,A;if(d){try{let t=Number(e.info.get(`mip_dual_bound`));Number.isFinite(t)&&(k=t)}catch{}k===void 0&&p&&p.objectiveBound!==void 0&&(k=p.objectiveBound);try{let t=Number(e.info.get(`mip_gap`));Number.isFinite(t)&&(A=t)}catch{}A===void 0&&p&&p.relativeGap!==void 0&&(A=p.relativeGap)}return{Status:wt[v]??y,StatusCode:v,PrimalSolutionStatus:b,DualSolutionStatus:x,HasPrimalSolution:E,IsMip:d,ObjectiveValue:O,ObjectiveOffsetApplied:c,MipDualBound:k,MipGap:A,Columns:D,Rows:ee}}),runTime:(performance.now()-r)/1e3}}function Y(){let e=_t(`solvers/highs-worker.js`),t=typeof window.origin==`string`?window.origin:window.location?.origin;if(new URL(e).origin===t)return new Worker(e,{type:`module`});let n=URL.createObjectURL(new Blob([`import `+JSON.stringify(e)+`;`],{type:`text/javascript`}));try{let e=new Worker(n,{type:`module`}),t=()=>URL.revokeObjectURL(n);return e.addEventListener(`message`,t,{once:!0}),e.addEventListener(`error`,t,{once:!0}),e}catch(e){throw URL.revokeObjectURL(n),e}}var Kt=null,qt=!1,Jt=0,X=new Map;function Yt(e,t){return e?{Status:`Interrupted`,StatusCode:17,HasPrimalSolution:!0,IsMip:!0,ObjectiveValue:e.objectiveValue,ObjectiveOffsetApplied:!0,...t?.objectiveBound===void 0?e.mipDualBound===void 0?{}:{MipDualBound:e.mipDualBound}:{MipDualBound:t.objectiveBound},...t?.relativeGap===void 0?e.mipGap===void 0?{}:{MipGap:e.mipGap}:{MipGap:t.relativeGap},Columns:e.columns,Rows:[]}:{Status:`Interrupted`,StatusCode:17,HasPrimalSolution:!1,ObjectiveValue:NaN,ObjectiveOffsetApplied:!0,...t?.objectiveBound===void 0?{}:{MipDualBound:t.objectiveBound},...t?.relativeGap===void 0?{}:{MipGap:t.relativeGap},Columns:{},Rows:[]}}function Xt(e){let t=X.values().next().value;if(!t||t.dispatched)return;t.dispatched=!0;let n={},r=!1;t.embeddedWasmBinary!==null&&!qt&&(n.embeddedWasmBinary=t.embeddedWasmBinary,r=!0);try{t.kind===`WARMUP`?e.postMessage({type:`WARMUP`,id:t.id,options:t.workerOptions,...n}):e.postMessage({type:`SOLVE`,id:t.id,lpString:t.lpString,options:t.workerOptions,...n,...t.reportProgress?{reportProgress:!0}:{}}),r&&(qt=!0)}catch(n){X.delete(t.id),t.cleanupAbort?.(),t.reject(n),Xt(e)}}function Zt(){let e=Kt;e&&(Kt=null,qt=!1,e.terminate());for(let e of X.values())e.dispatched=!1;if(X.size>0)try{let e=$t();if(e)Xt(e);else{let e=Error(`[WaSHI] Failed to recreate HiGHS Worker after interruption.`);for(let t of Array.from(X.values()))X.delete(t.id),t.cleanupAbort?.(),t.reject(e)}}catch(e){for(let t of Array.from(X.values()))X.delete(t.id),t.cleanupAbort?.(),t.reject(e)}}function Qt(){return typeof window<`u`&&typeof Worker<`u`&&typeof Worker?.prototype?.unref!=`function`}function $t(){if(!Qt())return null;if(!Kt){let e;try{e=Y(),e.onmessage=t=>{let{type:n,id:r,result:i,runTime:a,error:o,progress:s,incumbent:c}=t.data,l=X.get(r);if(l){if(n===`SOLVE_PROGRESS`){if(l.kind===`SOLVE`&&s){l.lastProgress=s;try{l.onProgress?.(s)}catch(e){let t=X.get(r);if(t){let n=X.keys().next().value;X.delete(r),t.cleanupAbort?.(),n===r&&Zt(),t.reject(e)}}}return}if(n===`SOLVE_INCUMBENT`){l.kind===`SOLVE`&&c&&(l.lastIncumbent=c);return}X.delete(r),l.cleanupAbort?.(),l.kind===`WARMUP`?n===`WARMUP_SUCCESS`?(Kt===e&&l.targetKey,l.resolve()):l.reject(Error(o||`Worker warmup failed`)):n===`SOLVE_SUCCESS`?(Kt===e&&l.targetKey,l.resolve({result:i,runTime:a})):l.reject(Error(o||`Worker solve failed`)),Kt===e&&Xt(e)}};let t=t=>{if(Kt===e){Kt=null,qt=!1,e.terminate();for(let e of X.values())e.cleanupAbort?.(),e.reject(t);X.clear()}};e.onerror=e=>t(Error(`[WaSHI] HiGHS Worker failed to load or execute. Check Worker assets, CORS and CSP. ${e?.message||``}`)),e.onmessageerror=()=>t(Error(`[WaSHI] Could not deserialize the HiGHS Worker response.`)),Kt=e}catch(e){throw Kt=null,e}}return Kt}function en(e){let t=typeof window<`u`?typeof window.origin==`string`?window.origin:window.location?.origin:void 0;return e.useWorker??(typeof window<`u`&&t!==`null`&&!t?.startsWith(`file:`))}function tn(e){if(e.useWorker===!0&&!Qt())throw Error(`[WaSHI] Web Worker execution was requested (useWorker: true), but browser Web Workers are unavailable in this environment.`);return en(e)?$t():null}async function nn(e,t){let n=t?pt(`highs`):mt(`highs`),r=n?.kind===`embedded`?n.bytes:null;if(e.wasmUrl){let t=await Ht(e.wasmUrl);return{wasmUrl:t,embeddedWasmBinary:r,targetKey:`url:${t}`}}if(Vt()){let e=await Ht();return{wasmUrl:e,embeddedWasmBinary:r,targetKey:`url:${e}`}}if(!n)return{wasmUrl:null,embeddedWasmBinary:null,targetKey:null};if(n.kind===`embedded`)return{wasmUrl:null,embeddedWasmBinary:r,targetKey:`__embedded__`};let i=await Ht();return{wasmUrl:i,embeddedWasmBinary:null,targetKey:`url:${i}`}}function rn(e,t){let{signal:n,onProgress:r,onIncumbent:i,...a}=e,o={};for(let[e,t]of Object.entries(a)){if(typeof t==`function`)throw Error(`[WaSHI] HiGHS Worker option "${e}" cannot be a function (functions cannot be cloned across Web Worker boundaries).`);o[e]=t}return t===null?delete o.wasmUrl:o.wasmUrl=t,o}function an(e,t,n){if(!e)return;let r=()=>{let e=X.get(t.id);if(!e)return;let r=X.keys().next().value;X.delete(t.id),e.cleanupAbort?.(),r===t.id&&Zt(),n()};e.addEventListener(`abort`,r,{once:!0}),t.cleanupAbort=()=>e.removeEventListener(`abort`,r)}async function on(e,t={}){if(Lt(t),t.signal?.aborted)return{result:Yt(),runTime:0};let n=await nn(t,!0);if(t.signal?.aborted)return{result:Yt(),runTime:0};let r=tn(t);if(!r)return Gt(e,t);let{signal:i,onProgress:a}=t,o=rn(t,n.wasmUrl),s=!!(a||i),c=`req_${++Jt}`,l=performance.now();return new Promise((t,u)=>{let d={kind:`SOLVE`,id:c,lpString:e,workerOptions:o,embeddedWasmBinary:n.embeddedWasmBinary,targetKey:n.targetKey,reportProgress:s,startTime:l,onProgress:a,resolve:t,reject:u};an(i,d,()=>{let e=(performance.now()-d.startTime)/1e3;d.resolve({result:Yt(d.lastIncumbent,d.lastProgress),runTime:e})}),X.set(c,d),Xt(r)})}function sn(e,t){if(typeof t==`number`)switch(t){case 0:return`NotSolved`;case 1:case 2:case 3:case 4:case 5:return`Error`;case 6:return`Unknown`;case 7:return`Optimal`;case 8:return`Infeasible`;case 9:return`InfeasibleOrUnbounded`;case 10:return`Unbounded`;case 11:return`ObjectiveBound`;case 12:return`ObjectiveTarget`;case 13:return`TimeLimit`;case 14:return`IterationLimit`;case 15:return`Unknown`;case 16:return`SolutionLimit`;case 17:return`Interrupted`;case 18:return`MemoryLimit`}if(typeof e!=`string`)return`Unknown`;let n=e.trim();if(!n)return`Unknown`;switch(n){case`Optimal`:return`Optimal`;case`Infeasible`:return`Infeasible`;case`Unbounded`:return`Unbounded`;case`Primal infeasible or unbounded`:case`InfeasibleOrUnbounded`:return`InfeasibleOrUnbounded`;case`Time limit reached`:case`TimeLimit`:return`TimeLimit`;case`Iteration limit reached`:case`IterationLimit`:return`IterationLimit`;case`Solution limit reached`:case`SolutionLimit`:return`SolutionLimit`;case`Memory limit reached`:case`MemoryLimit`:return`MemoryLimit`;case`Bound on objective reached`:case`ObjectiveBound`:return`ObjectiveBound`;case`Target for objective reached`:case`ObjectiveTarget`:return`ObjectiveTarget`;case`Interrupted`:case`User interrupt`:return`Interrupted`;case`Feasible`:return`Feasible`;case`Not Set`:return`NotSolved`;case`Load error`:case`Model error`:case`Presolve error`:case`Solve error`:case`Postsolve error`:case`Error`:return`Error`;case`Empty`:case`Unknown`:return`Unknown`}return`Unknown`}function cn(e,t,n){switch(sn(e,t)){case`Optimal`:return`Optimal`;case`Infeasible`:return`Infeasible`;case`Unbounded`:return`Unbounded`;case`TimeLimit`:return`TimeLimit`;case`IterationLimit`:return`IterationLimit`;case`Feasible`:return`Feasible`;case`ObjectiveBound`:case`ObjectiveTarget`:case`SolutionLimit`:return n===!1?`Unknown`:`Feasible`;case`MemoryLimit`:case`Interrupted`:return n?`Feasible`:`Unknown`;case`NotSolved`:return`NotSolved`;case`Error`:return`Error`;default:return`Unknown`}}var ln=class e{static capabilities={supportsMIP:!0,supportsQP:!0,supportsWarmStart:!0};name=`HiGHS`;version=`1.15.1`;capabilities=e.capabilities;options;constructor(e={}){this.options=e}async solve(e,t={},n={}){let r=Ge(t),i=r?n:t,a={...this.options,...i};Lt(a);let o=e.objective?.constant??0;if(typeof o!=`number`||!Number.isFinite(o))throw Error(`Solver "${this.name}" encountered non-finite objective constant: ${String(o)}.`);let s=o===0?0:o;for(let t of e.variables)M(t);let{lpString:c,nameToVar:l,nameToConstraint:u}=r?t:Je(e,{relax:a.relax}),d=Object.create(null),f=!1,p=new Set;for(let[e,t]of l.entries()){p.add(t);let n=ae(t);n!==void 0&&(d[e]=n,f=!0)}for(let t of e.variables)if(!p.has(t))throw Error(`LP export symbol map (nameToVar) is missing model variable "${t.name}".`);let m=a;(s!==0||f||m.initialValues!==void 0)&&(m={...m,...s===0?{}:{objectiveOffset:s},...f?{initialValues:d}:{}});let{result:h,runTime:g}=await on(c,m),_=h?.ObjectiveOffsetApplied?0:s,v=sn(h?.Status,h?.StatusCode),y=a.relax?!1:typeof h?.IsMip==`boolean`?h.IsMip:e.variables.some(e=>e.type===`Integer`||e.type===`Binary`),b=h?.HasPrimalSolution===!0,x=cn(h?.Status,h?.StatusCode,b),S=null;b&&typeof h?.ObjectiveValue==`number`&&Number.isFinite(h.ObjectiveValue)&&(S=h.ObjectiveValue+_);let C,w,T;if(typeof h?.MipDualBound==`number`&&Number.isFinite(h.MipDualBound)?C=h.MipDualBound+_:!y&&v===`Optimal`&&S!==null&&(C=S),S!==null&&C!==void 0&&Number.isFinite(C)&&(T=Math.abs(S-C)),_!==0&&y&&S!==null&&C!==void 0&&T!==void 0){if(T===0)w=0;else if(Math.abs(S)>0){let e=T/Math.abs(S);w=Number.isFinite(e)?e:void 0}else w=void 0}else typeof h?.MipGap==`number`&&Number.isFinite(h.MipGap)?w=h.MipGap:y&&v===`Optimal`&&b&&(T===void 0||T===0)&&(w=0);if(!b)return{status:x,terminationStatus:v,hasPrimalSolution:!1,objectiveValue:null,...C===void 0?{}:{objectiveBound:C},...w===void 0?{}:{relativeGap:w},...T===void 0?{}:{absoluteGap:T},values:{},reducedCosts:{},duals:{},slacks:{},runTime:g,raw:h};let E=(e,t,n)=>{Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})},D={},ee={},O={},k={};if(h.Columns)for(let[e,t]of Object.entries(h.Columns)){let n=l.get(e);if(n){if(typeof t.Primal==`number`&&Number.isFinite(t.Primal)){let e=Math.abs(t.Primal)<1e-9?0:t.Primal;!a.relax&&(n.type===`Integer`||n.type===`Binary`)&&Math.abs(e-Math.round(e))<=1e-5&&(e=Math.round(e)+0),E(D,n.name,e)}typeof t.Dual==`number`&&Number.isFinite(t.Dual)&&E(O,n.name,Math.abs(t.Dual)<1e-9?0:t.Dual)}}if(h.Rows){let e=Array.isArray(h.Rows)?h.Rows:Object.values(h.Rows);for(let t of e){let e=t.Name,n=e?u.get(e):void 0;if(n&&(typeof t.Dual==`number`&&Number.isFinite(t.Dual)&&E(ee,n.name,Math.abs(t.Dual)<1e-9?0:t.Dual),typeof t.Primal==`number`&&Number.isFinite(t.Primal))){let e=n.rhs-t.Primal;E(k,n.name,Math.abs(e)<1e-9?0:e)}}}return{status:x,terminationStatus:v,hasPrimalSolution:!0,objectiveValue:S,...C===void 0?{}:{objectiveBound:C},...w===void 0?{}:{relativeGap:w},...T===void 0?{}:{absoluteGap:T},values:D,reducedCosts:O,duals:ee,slacks:k,runTime:g,raw:h}}};function un(){$e(`highs`,e=>new ln(e)),et(e=>new ln(e))}un(),kt();var dn=typeof document<`u`?document.currentScript?.src:null,fn=dn?new URL(`.`,dn).href:null;function pn(e){if(!fn)throw Error(`[WaSHI] Load the browser IIFE using an external script src, or use the browser ESM build.`);return new URL(e,fn).href}function mn(){return pn(`solvers/pumpkin.wasm`)}function hn(){function e(e){let t,n;try{let r=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),i=g,a=_.check_json(r,i);return t=a[0],n=a[1],o(a[0],a[1])}finally{_.__wbindgen_free(t,n,1)}}function t(e,t){let n,r;try{let i=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),s=g,c=_.check_with_callback(i,s,u(t)?0:a(t));return n=c[0],r=c[1],o(c[0],c[1])}finally{_.__wbindgen_free(n,r,1)}}function n(e){let t,n;try{let r=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),i=g,a=_.solve_json(r,i);return t=a[0],n=a[1],o(a[0],a[1])}finally{_.__wbindgen_free(t,n,1)}}function r(e,t,n){let r,i;try{let s=d(e,_.__wbindgen_malloc,_.__wbindgen_realloc),c=g,l=_.solve_with_callback(s,c,u(t)?0:a(t),u(n)?0:a(n));return r=l[0],i=l[1],o(l[0],l[1])}finally{_.__wbindgen_free(r,i,1)}}function i(){return{__proto__:null,"./pumpkin_bg.js":{__proto__:null,__wbg___wbindgen_boolean_get_4f1baf9a00be3c74:function(e){let t=e,n=typeof t==`boolean`?t:void 0;return u(n)?16777215:+!!n},__wbg___wbindgen_is_undefined_be5b34249ff1fc15:function(e){return e===void 0},__wbg___wbindgen_throw_4c88d8bf264fd984:function(e,t){throw Error(o(e,t))},__wbg_call_40b008ba32f73991:function(){return l(function(e,t){return e.call(t)},arguments)},__wbg_call_a410eb4b59ed5965:function(){return l(function(e,t,n){return e.call(t,n)},arguments)},__wbg_now_e7c6795a7f81e10f:function(e){return e.now()},__wbg_performance_7e4e4494fdc9d07a:function(e){return e.performance},__wbg_static_accessor_GLOBAL_THIS_003ee833af9699fc:function(){let e=typeof globalThis>`u`?void 0:globalThis;return u(e)?0:a(e)},__wbg_static_accessor_GLOBAL_e4293fb22cbe77da:function(){let e=typeof globalThis>`u`?void 0:globalThis;return u(e)?0:a(e)},__wbg_static_accessor_SELF_53bb20457401453d:function(){let e=typeof self>`u`?void 0:self;return u(e)?0:a(e)},__wbg_static_accessor_WINDOW_b5e0810bfecb7feb:function(){let e=typeof window>`u`?void 0:window;return u(e)?0:a(e)},__wbindgen_generic_0000000000000001:function(e,t){return o(e,t)},__wbindgen_init_externref_table:function(){let e=_.__wbindgen_externrefs;e.set(0,void 0),e.set(1024,void 0),e.set(1025,null),e.set(1026,!0),e.set(1027,!1)}}}}function a(e){let t=_.__externref_table_alloc();return _.__wbindgen_externrefs.set(t,e),t}function o(e,t){return e>>>=0,m(c().subarray(e,e+t))}let s=null;function c(){return(s===null||s.byteLength===0)&&(s=new Uint8Array(_.memory.buffer)),s}function l(e,t){try{return e.apply(this,t)}catch(e){let t=a(e);_.__wbindgen_exn_store(t)}}function u(e){return e==null}function d(e,t,n){if(n===void 0){let n=h.encode(e),r=t(n.length,1)>>>0;return c().subarray(r,r+n.length).set(n),g=n.length,r}let r=e.length,i=t(r,1)>>>0,a=c(),o=0;for(;o<r;o++){let t=e.charCodeAt(o);if(t>127)break;a[i+o]=t}if(o!==r){o!==0&&(e=e.slice(o)),i=n(i,r,r=o+e.length*3,1)>>>0;let t=c().subarray(i+o,i+r),a=h.encodeInto(e,t);o+=a.written,i=n(i,r,o,1)>>>0}return g=o,i}let f=new TextDecoder(`utf-8`,{ignoreBOM:!0});f.decode();let p=0;function m(e){return p+=e.length,p>=2146435072&&(f=new TextDecoder(`utf-8`,{ignoreBOM:!0}),f.decode(),p=e.length),f.decode(e)}let h=new TextEncoder;`encodeInto`in h||(h.encodeInto=function(e,t){let n=h.encode(e);return t.set(n),{read:e.length,written:n.length}});let g=0,_;function v(e,t){if(_=e.exports,s=null,!_||!(_.memory instanceof WebAssembly.Memory)||typeof _.__wbindgen_start!=`function`||typeof _.__wbindgen_malloc!=`function`||typeof _.__wbindgen_free!=`function`||typeof _.check_json!=`function`||typeof _.check_with_callback!=`function`||typeof _.solve_json!=`function`||typeof _.solve_with_callback!=`function`)throw Error(`[WaSHI] Invalid Pumpkin WebAssembly module: missing expected solver exports.`);return _.__wbindgen_start(),_}async function y(e,t){if(typeof Response==`function`&&e instanceof Response){if(!e.ok)throw Error(`failed to fetch Wasm: ${e.status} ${e.statusText} fetching '${e.url}'`);if(typeof WebAssembly.instantiateStreaming==`function`)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if(n(e.type)&&e.headers.get(`Content-Type`)!==`application/wasm`)console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",t);else throw t}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}{let n=await WebAssembly.instantiate(e,t);return n instanceof WebAssembly.Instance?{instance:n,module:e}:n}function n(e){switch(e){case`basic`:case`cors`:case`default`:return!0}return!1}}let b;async function x(e){return _===void 0?(b===void 0&&(b=S(e),b.catch(()=>{b=void 0})),b):_}async function S(e){e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn(`using deprecated parameters for the initialization function; pass a single object instead`));let t=i();(typeof e==`string`||typeof Request==`function`&&e instanceof Request||typeof URL==`function`&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:r}=await y(await e,t);return v(n,r)}return{check_json:e,check_with_callback:t,solve_json:n,solve_with_callback:r,__wbg_init:x}}async function gn(e){let t=hn();return await t.__wbg_init({module_or_path:e}),{check_json:t.check_json,check_with_callback:t.check_with_callback,solve_json:t.solve_json,solve_with_callback:t.solve_with_callback}}var _n=r({readBundledPumpkinWasmBytes:()=>yn,readPumpkinWasmFileUrl:()=>vn});async function vn(){throw Error(`This distribution is for browsers. Use the npm entry in Node.js.`)}async function yn(){throw Error(`This distribution is for browsers. Use the npm entry in Node.js.`)}var bn=n((()=>{})),xn=4,Sn=null,Cn=new Map,wn=new Set,Tn=0;function En(){return!1}function Dn(e){return e.byteLength>=8&&e[0]===0&&e[1]===97&&e[2]===115&&e[3]===109}function On(){return Sn}function kn(e,t){if(e!==void 0){let n=Mn(e);return n===null?t?t.kind===`embedded`?{kind:`embedded`,binary:t.bytes,key:`__embedded__`}:{kind:`url`,url:null,key:`__bundled__`}:null:{kind:`url`,url:n,key:`url:${n}`}}return Sn===null?t?t.kind===`embedded`?{kind:`embedded`,binary:t.bytes,key:`__embedded__`}:{kind:`url`,url:null,key:`__bundled__`}:null:{kind:`url`,url:Sn,key:`url:${Sn}`}}function An(){if(typeof Worker>`u`||typeof window>`u`||typeof Worker.prototype.unref==`function`)return!1;let e=typeof window.origin==`string`?window.origin:(()=>{try{return window.location?.origin}catch{return}})();return!(!e||e===`null`||e.startsWith(`file:`))}async function jn(e){if(typeof fetch!=`function`)throw Error(`[WaSHI] Global fetch() is unavailable to load Pumpkin WebAssembly from "${e}"; no CDN fallback is attempted.`);let t;try{t=await fetch(e)}catch(t){throw Error(`[WaSHI] Failed to fetch pumpkin.wasm from "${e}" (no CDN fallback is attempted): ${t instanceof Error?t.message:String(t)}. Ensure pumpkin.wasm is hosted cleanly or call setPumpkinWasmUrl(url).`)}if(!t.ok)throw Error(`[WaSHI] Failed to fetch pumpkin.wasm from "${e}": HTTP ${t.status} ${t.statusText}; no CDN fallback is attempted.`);let n=t.headers?.get(`content-type`)?.toLowerCase()??``;if(n.includes(`text/html`))throw Error(`[WaSHI] Invalid response while loading pumpkin.wasm from "${e}": received HTML ("${n}") instead of a WebAssembly binary; no CDN fallback is attempted.`);let r=await t.arrayBuffer(),i=new Uint8Array(r);if(!Dn(i))throw Error(`[WaSHI] Invalid WebAssembly binary loaded from "${e}": expected \\0asm magic header; no CDN fallback is attempted.`);return i}function Mn(e){if(e===void 0)return Sn;if(e!==null&&typeof e!=`string`)throw Error(`Invalid pumpkin.wasm URL: expected string or null, got ${typeof e}.`);if(e===``)throw Error(`Invalid pumpkin.wasm URL: expected non-empty string or null (received empty string "").`);return e}async function Nn(e){if(e!==null){if(En()&&e.startsWith(`file://`)){let{readPumpkinWasmFileUrl:t}=await Promise.resolve().then(()=>(bn(),_n)),n=await t(new URL(e));if(!Dn(n))throw Error(`[WaSHI] Invalid WebAssembly binary at "${e}": expected \\0asm magic header.`);return n}return jn(e)}if(En()&&typeof window>`u`){let{readBundledPumpkinWasmBytes:e}=await Promise.resolve().then(()=>(bn(),_n)),t=await e();if(!Dn(t))throw Error(`[WaSHI] Bundled pumpkin.wasm on disk has an invalid WebAssembly magic header.`);return t}return jn(mn())}async function Pn(e){let t=kn(e,pt(`pumpkin`));if(!t)throw Error(`[WaSHI] Failed to resolve Pumpkin WASM target.`);let n=t.key,r=Cn.get(n);if(r)return Cn.delete(n),Cn.set(n,r),r;let i=Tn,a=null;for(a=(async()=>{try{let e=await gn(t.kind===`embedded`?t.binary.slice():await Nn(t.url));return Tn===i&&Cn.get(n)===a&&wn.add(n),e}catch(e){throw Tn===i&&(wn.delete(n),Cn.get(n)===a&&Cn.delete(n)),t.kind===`url`&&t.url!==null&&e instanceof Error&&e.message.includes(`Invalid Pumpkin WebAssembly module`)?Error(`[WaSHI] Invalid Pumpkin WebAssembly module loaded from "${t.url}" (${e.message}); no CDN fallback is attempted.`):e}})();Cn.size>=xn;){let e=Cn.keys().next().value;if(e===void 0)break;Cn.delete(e),wn.delete(e)}return Cn.set(n,a),a}function Fn(){let e=pn(`solvers/pumpkin-worker.js`),t=typeof window.origin==`string`?window.origin:window.location?.origin;if(new URL(e).origin===t)return new Worker(e,{type:`module`});let n=URL.createObjectURL(new Blob([`import `+JSON.stringify(e)+`;`],{type:`text/javascript`}));try{let e=new Worker(n,{type:`module`}),t=()=>URL.revokeObjectURL(n);return e.addEventListener(`message`,t,{once:!0}),e.addEventListener(`error`,t,{once:!0}),e}catch(e){throw URL.revokeObjectURL(n),e}}function In(e){if(e===``)throw Error(`Invalid pumpkin.wasm URL: expected non-empty string or null (received empty string "").`);if(e!=null&&typeof e!=`string`)throw Error(`Invalid pumpkin.wasm URL: expected string or null, got ${typeof e}.`)}function Ln(e){return{status:`Unknown`,values:[],boolValues:[],runTime:Math.max((performance.now()-e)/1e3,1e-6)}}function Rn(e,t){let n=Math.max((performance.now()-e)/1e3,1e-6);return t?{status:`Feasible`,terminationStatus:`Interrupted`,objectiveValue:t.objectiveValue,values:t.values,boolValues:t.boolValues,runTime:n}:{status:`Unknown`,terminationStatus:`Interrupted`,objectiveValue:null,values:[],boolValues:[],runTime:n}}function zn(e={}){let t=e.workerFactory??Fn,n=null,r=1,i=null,a=[],o=new Set,s=!1,c=!1;In(e.wasmUrl);let l=e=>{for(o.delete(e),o.add(e);o.size>4;){let e=o.keys().next().value;if(e===void 0)break;o.delete(e)}},u=()=>{o.clear(),s=!1,n&&=(n.onmessage=null,n.onerror=null,n.onmessageerror=null,n.terminate(),null)},d=e=>{i===e&&(i=null),e.cleanupAbort?.()},f=(e,t)=>{d(e),e.resolve(t),v()},p=(e,t)=>{d(e),e.resolve(t),v()},m=(e,t)=>{d(e),e.reject(t),v()},h=e=>{e.type===`check`?f(e,Ln(e.startTimeMs)):p(e,Rn(e.startTimeMs,e.lastIncumbent))},g=(e,t,n)=>{if(typeof e!=`string`)throw Error(`Pumpkin worker response is missing canonical responseJson string.`);let r=JSON.parse(e);if(!r)throw Error(`Pumpkin worker returned an empty success payload.`);if(r.error)throw Error(r.error);return{...r,runTime:typeof t==`number`?t:Math.max((performance.now()-n)/1e3,1e-6)}},_=()=>{if(n)return n;let e=t();return e.onmessage=t=>{let r=t.data,a=i;if(n===e&&r&&a&&r.id===a.id){if(r.type===`SOLVE_PROGRESS`){if(a.type!==`solve`)return;try{if(typeof r.payloadJson!=`string`)throw Error(`Pumpkin worker SOLVE_PROGRESS is missing canonical payloadJson string.`);let t=JSON.parse(r.payloadJson);if(!t)throw Error(`Pumpkin worker SOLVE_PROGRESS returned an empty incumbent payload.`);if(a.lastIncumbent=t,a.onProgress){let e=typeof r.elapsedTime==`number`?r.elapsedTime:Math.max((performance.now()-a.startTimeMs)/1e3,1e-6);a.onProgress({elapsedTime:e,elapsedSeconds:e,objectiveValue:t.objectiveValue})}if(n!==e||i!==a)return;a.signal?.aborted&&(u(),h(a))}catch(t){n===e&&i===a&&(u(),m(a,t))}return}if(r.type===`CHECK_SUCCESS`){if(a.type!==`check`){u(),m(a,Error(`Received "CHECK_SUCCESS" for a solve task.`));return}try{let e=g(r.responseJson,r.runTime,a.startTimeMs);l(a.cacheKey),f(a,e)}catch(t){n===e&&i===a&&(u(),m(a,t))}return}if(r.type===`SOLVE_SUCCESS`){if(a.type!==`solve`){u(),m(a,Error(`Received "SOLVE_SUCCESS" for a check task.`));return}try{let e=g(r.responseJson,r.runTime,a.startTimeMs);l(a.cacheKey),p(a,e)}catch(t){n===e&&i===a&&(u(),m(a,t))}return}if(r.type===`SOLVER_ERROR`){let e=typeof r.error==`string`?r.error:`Pumpkin worker execution failed.`;m(a,Error(e))}}},e.onerror=t=>{if(n!==e)return;let r=i;if(u(),r){let e=t?.message||`Pumpkin Web Worker encountered an unexpected error.`;m(r,Error(e))}},e.onmessageerror=()=>{if(n!==e)return;let t=i;u(),t&&m(t,Error(`Failed to deserialize message from Pumpkin Web Worker.`))},n=e,e},v=()=>{if(!(i||c))for(;a.length>0;){let e=a.shift();if(e.signal?.aborted){e.type===`check`?e.resolve(Ln(e.startTimeMs)):e.resolve(Rn(e.startTimeMs,e.lastIncumbent));continue}if(i=e,e.startTimeMs=performance.now(),e.signal){let t=()=>{i===e&&(u(),h(e))};e.signal.addEventListener(`abort`,t,{once:!0}),e.cleanupAbort=()=>e.signal?.removeEventListener(`abort`,t)}try{let t=_(),n={id:e.id,type:e.type,requestJson:e.requestJson};e.wasmUrl!==void 0&&(n.wasmUrl=e.wasmUrl);let r=!1;e.embeddedWasmBinary!==null&&!s&&(n.embeddedWasmBinary=e.embeddedWasmBinary,r=!0),t.postMessage(n),r&&(s=!0)}catch(t){i===e&&(u(),m(e,t))}return}},y=(t,n)=>{let r=n?pt(`pumpkin`):mt(`pumpkin`),i=r?.kind===`embedded`?r.bytes:null,a=r?r.kind===`embedded`?`__embedded__`:`__bundled__`:null;if(t!==void 0)return In(t),{wasmUrl:t,embeddedWasmBinary:i,cacheKey:t===null?a:`url:${t}`};if(e.wasmUrl!==void 0)return In(e.wasmUrl),{wasmUrl:e.wasmUrl,embeddedWasmBinary:i,cacheKey:e.wasmUrl===null?a:`url:${e.wasmUrl}`};let o=On();return In(o),{wasmUrl:o,embeddedWasmBinary:i,cacheKey:o===null?a:`url:${o}`}},b=e=>new Promise((t,n)=>{a.push(e(t,n)),v()});return{check(e,t){if(c)return Promise.reject(Error(`[WaSHI] Pumpkin worker client has been disposed.`));if(t?.signal?.aborted)return Promise.resolve(Ln(performance.now()));let n=y(e.wasmUrl,!0);return b((i,a)=>({id:r++,type:`check`,requestJson:e.requestJson,wasmUrl:n.wasmUrl,embeddedWasmBinary:n.embeddedWasmBinary,cacheKey:n.cacheKey,signal:t?.signal,startTimeMs:performance.now(),lastIncumbent:null,resolve:i,reject:a}))},solve(e,t){if(c)return Promise.reject(Error(`[WaSHI] Pumpkin worker client has been disposed.`));if(t?.signal?.aborted)return Promise.resolve(Rn(performance.now(),null));let n=y(e.wasmUrl,!0);return b((i,a)=>({id:r++,type:`solve`,requestJson:e.requestJson,wasmUrl:n.wasmUrl,embeddedWasmBinary:n.embeddedWasmBinary,cacheKey:n.cacheKey,signal:t?.signal,onProgress:t?.onProgress,startTimeMs:performance.now(),lastIncumbent:null,resolve:i,reject:a}))},isWarmed(e){if(c||n===null)return!1;let{cacheKey:t}=y(e,!1);return t!==null&&o.has(t)},dispose(){for(c=!0,u();a.length>0;){let e=a.shift();e.cleanupAbort?.(),e.reject(Error(`[WaSHI] Pumpkin worker client disposed.`))}if(i){let e=i;i=null,e.cleanupAbort?.(),e.reject(Error(`[WaSHI] Pumpkin worker client disposed.`))}}}}var Bn=null;function Vn(){return Bn||=zn(),Bn}var Hn=1073741823,Un=2147483646,Wn=1e-6;function Z(e){return Object.is(e,-0)||e===0?0:e}function Gn(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Q(e,t){if(typeof e!=`number`||Number.isNaN(e))throw Error(`PumpkinSolver encountered non-finite numeric value in ${t}.`);if(!Number.isFinite(e))throw Error(`PumpkinSolver only supports bounded finite integers (${t}: got ${e}).`);if(!Number.isInteger(e))throw Error(`PumpkinSolver only supports integer values (${t}: got ${e}).`);let n=Z(e);if(n<-1073741823||n>Hn)throw Error(`Value out of Pumpkin safe 32-bit integer range [-${Hn}, ${Hn}] (${t}: got ${n}).`);return n}function Kn(e){if(e===void 0||e===1/0)return null;if(typeof e!=`number`||Number.isNaN(e)||e<0||!Number.isFinite(e))throw Error(`Invalid timeLimit (${String(e)}): expected a finite non-negative number of seconds.`);if(e===0)return 0;let t=Math.round(e*1e3);if(t>2**53-1)throw Error(`timeLimit (${e}s) exceeds safe millisecond range.`);return Math.max(1,t)}function qn(e){return e instanceof w||typeof e==`object`&&!!e&&`quadTerms`in e}function Jn(e,t,n){if(e.initialValue===void 0)return;if(typeof e.initialValue!=`number`||!Number.isFinite(e.initialValue))throw Error(`Variable "${e.name}" has invalid initialValue: ${String(e.initialValue)} (initialValue must be a finite number).`);if(e.initialValue<t-Wn||e.initialValue>n+Wn)throw Error(`Variable "${e.name}" has initialValue (${e.initialValue}) outside its bounds [${t}, ${n}] (tolerance ${Wn}).`);let r=Z(Math.round(e.initialValue));if(Math.abs(e.initialValue-r)>Wn||r<t||r>n)throw Error(`Variable "${e.name}" of type "${e.type}" has non-integral or out-of-domain initialValue: ${e.initialValue} (must be within ${Wn} of an integer in [${t}, ${n}]).`);return Q(r,`initialValue of variable "${e.name}"`)}function Yn(e){let t=[],n=new Map,r=!1;for(let i=0;i<e.length;i++){let a=e[i],o=String(a.type).toLowerCase();if(o===`continuous`||o===`cont`)throw Error(`PumpkinSolver does not support Continuous variable "${a.name}". Use an Integer or Binary variable, or select a MIP/SMT solver.`);if(n.set(a,i),o===`binary`||o===`bin`){if(typeof a.lb!=`number`||Number.isNaN(a.lb)||typeof a.ub!=`number`||Number.isNaN(a.ub))throw Error(`PumpkinSolver encountered non-finite numeric value in bounds of variable "${a.name}".`);if(a.lb===1/0||a.ub===-1/0||a.lb>a.ub)throw Error(`Variable "${a.name}" has invalid bounds lb (${a.lb}) > ub (${a.ub}).`);if(Number.isFinite(a.lb)&&!Number.isInteger(a.lb)||Number.isFinite(a.ub)&&!Number.isInteger(a.ub))throw Error(`PumpkinSolver only supports integer values (bounds of binary variable "${a.name}").`);let e=a.lb===-1/0?0:Math.max(0,Z(a.lb)),n=a.ub===1/0?1:Math.min(1,Z(a.ub)),i=Jn(a,e,n);e>n?(r=!0,t.push({name:a.name,lb:0,ub:1})):t.push(i===void 0?{name:a.name,lb:e,ub:n}:{name:a.name,lb:e,ub:n,initialValue:i});continue}let s=Q(a.lb,`lower bound of variable "${a.name}"`),c=Q(a.ub,`upper bound of variable "${a.name}"`);if(s>c)throw Error(`Variable "${a.name}" has invalid bounds lb (${s}) > ub (${c}).`);let l=Jn(a,s,c);t.push(l===void 0?{name:a.name,lb:s,ub:c}:{name:a.name,lb:s,ub:c,initialValue:l})}return{vars:t,varIndexMap:n,hasEmptyDomain:r}}function Xn(e,t,n){let r=0;function i(e,n,i){let a=Q(e,`internal ${i} lb`),o=Q(n,`internal ${i} ub`),s=t.length;return t.push({name:`__pumpkin_${i}_${++r}`,lb:a,ub:o,internal:!0}),s}function a(n,r,i){let a=new Map;for(let[t,r]of n.entries()){let n=e.get(t);if(n===void 0)throw Error(`Variable "${t.name}" in ${i} is not registered in the model.`);if(typeof r!=`number`||!Number.isFinite(r))throw Error(`Invalid non-finite coefficient for "${t.name}" in ${i}.`);if(!Number.isInteger(r))throw Error(`PumpkinSolver only supports integer coefficients (variable "${t.name}" in ${i} has ${r}).`);let o=(a.get(n)??0)+Z(r);if(!Number.isSafeInteger(o))throw Error(`Coefficient sum overflow for "${t.name}" in ${i}.`);a.set(n,o)}for(let e of r){let t=(a.get(e.varIndex)??0)+Z(e.coeff);if(!Number.isSafeInteger(t))throw Error(`Coefficient sum overflow in ${i}.`);a.set(e.varIndex,t)}let o=[],s=0;for(let[e,n]of a.entries()){let r=Z(n);if(r===0)continue;let a=t[e];Q(r,`coefficient of "${a.name}" in ${i}`);let c=r*a.lb,l=r*a.ub;if(Q(c,`scaled lower bound of "${a.name}" in ${i}`),Q(l,`scaled upper bound of "${a.name}" in ${i}`),s+=Math.max(Math.abs(c),Math.abs(l)),s>Un)throw Error(`Linear expression magnitude in ${i} exceeds Pumpkin safe 32-bit propagator overflow limit.`);o.push({varIndex:e,coeff:r})}return{terms:o,sumMaxAbs:s}}function o(e,n,r){let i=n,a=n;for(let n of e){let e=t[n.varIndex],r=n.coeff*e.lb,o=n.coeff*e.ub;i+=Math.min(r,o),a+=Math.max(r,o)}return{lb:Q(Z(i),`lower bound of ${r}`),ub:Q(Z(a),`upper bound of ${r}`)}}function s(e,r,a){switch(e.kind){case`abs`:{let o=l(e.arg,r,`${a} abs()`),s=t[o],c=i(s.lb<=0&&s.ub>=0?0:Math.min(Math.abs(s.lb),Math.abs(s.ub)),Math.max(Math.abs(s.lb),Math.abs(s.ub)),`abs`);return n.push({kind:`abs`,argVar:o,outVar:c,owner:r}),c}case`max`:{let o=e.args.map((e,t)=>l(e,r,`${a} max()[${t}]`)),s=i(Math.max(...o.map(e=>t[e].lb)),Math.max(...o.map(e=>t[e].ub)),`max`);return n.push({kind:`max`,argVars:o,outVar:s,owner:r}),s}case`min`:{let o=e.args.map((e,t)=>l(e,r,`${a} min()[${t}]`)),s=i(Math.min(...o.map(e=>t[e].lb)),Math.min(...o.map(e=>t[e].ub)),`min`);return n.push({kind:`min`,argVars:o,outVar:s,owner:r}),s}case`at`:{let o=l(e.index,r,`${a} at() index`),s=e.array.map((e,t)=>l(e,r,`${a} at()[${t}]`)),c=i(Math.min(...s.map(e=>t[e].lb)),Math.max(...s.map(e=>t[e].ub)),`elem`);return n.push({kind:`element`,indexVar:o,arrayVars:s,outVar:c,owner:r}),c}}}function c(e,t,n,r=!1){if(typeof e.constant!=`number`||!Number.isFinite(e.constant))throw Error(`Invalid non-finite constant in ${n}.`);let i;if(r)i=Z(e.constant);else{if(!Number.isInteger(e.constant))throw Error(`PumpkinSolver only supports integer constants (${n}: got ${e.constant}).`);i=Q(Z(e.constant),`constant of ${n}`)}let o=[];if(Array.isArray(e.nonlinearTerms))for(let r of e.nonlinearTerms){if(r.coeff===0)continue;if(typeof r.coeff!=`number`||!Number.isFinite(r.coeff)||!Number.isInteger(r.coeff))throw Error(`PumpkinSolver only supports safe integer coefficients in ${n} (got ${r.coeff}).`);let e=Q(Z(r.coeff),`nonlinear coefficient in ${n}`),i=s(r.atom,t,n);o.push({varIndex:i,coeff:e})}let{terms:c,sumMaxAbs:l}=a(e.terms,o,n);return{terms:c,constant:i,sumMaxAbs:l}}function l(e,r,a){let{terms:s,constant:l}=c(e,r,a);if(s.length===1&&s[0].coeff===1&&l===0)return s[0].varIndex;let{lb:u,ub:d}=o(s,l,a),f=i(u,d,`expr`);if(s.length>0){let e=[...s,{varIndex:f,coeff:-1}],i=Q(Z(-l),`linearEq RHS in ${a}`),o=e.reduce((e,n)=>{let r=t[n.varIndex];return e+Math.max(Math.abs(n.coeff*r.lb),Math.abs(n.coeff*r.ub))},0);if(Math.abs(i)+o>Un)throw Error(`Linear expression magnitude in ${a} exceeds Pumpkin safe 32-bit propagator overflow limit.`);n.push({kind:`linearEq`,terms:e,rhs:i,owner:r})}return f}function u(e,t,n,r){if(typeof t!=`number`||!Number.isFinite(t))throw Error(`Invalid non-finite RHS in ${r}.`);if(!Number.isInteger(t))throw Error(`PumpkinSolver only supports integer RHS (${r}: got ${t}).`);let{terms:i,constant:a,sumMaxAbs:o}=c(e,n,r),s=Q(Z(t-a),`RHS of ${r}`);if(Math.abs(s)+o>Un)throw Error(`Linear expression magnitude in ${r} exceeds Pumpkin safe 32-bit propagator overflow limit.`);return{terms:i,rhs:s}}return{lowerLinExpr:c,materializeExprToVarIndex:l,serializeConstraintSide:u}}function Zn(e,t,n,r,i){if(r.has(e)||e instanceof c||typeof e==`object`&&e&&`name`in e&&`id`in e&&!(`op`in e)&&!(`lhs`in e)&&!(`spec`in e)){let t=e,n=r.get(t);if(n===void 0)throw Error(`Boolean variable "${t.name}" in ${i} is not registered in the model.`);return{kind:`boolVar`,index:n}}if(e instanceof I||`lhs`in e&&`sense`in e&&`rhs`in e){let r=e;if(qn(r.lhs))throw Error(`PumpkinSolver does not support quadratic constraints inside ${i}.`);let{terms:a,rhs:o}=t.serializeConstraintSide(r.lhs,r.rhs,n,i);return{kind:`linear`,terms:a,sense:r.sense,rhs:o}}if(e instanceof h||typeof e==`object`&&e&&`spec`in e&&typeof e.spec==`object`){let r=e.spec;switch(r.kind){case`distinct`:return{kind:`allDifferent`,vars:r.args.map((e,r)=>t.materializeExprToVarIndex(e,n,`${i} distinct()[${r}]`))};case`disjoint`:return{kind:`disjunctive`,tasks:r.tasks.map((e,r)=>({startVar:t.materializeExprToVarIndex(e.start,n,`${i} disjoint()[${r}]`),duration:Q(e.duration,`duration of ${i} disjoint()[${r}]`)}))};case`cumulative`:return{kind:`cumulative`,tasks:r.tasks.map((e,r)=>({startVar:t.materializeExprToVarIndex(e.start,n,`${i} cumulative()[${r}]`),duration:Q(e.duration,`duration of ${i} cumulative()[${r}]`),demand:Q(e.demand,`demand of ${i} cumulative()[${r}]`)})),capacity:Q(r.capacity,`capacity of ${i} cumulative()`)};case`allowed`:return{kind:`table`,vars:r.vars.map((e,r)=>t.materializeExprToVarIndex(e,n,`${i} allowed() vars[${r}]`)),tuples:r.tuples.map((e,t)=>e.map((e,n)=>Q(e,`tuple[${t}][${n}] in ${i}`)))}}}if(e instanceof l||`op`in e&&`children`in e){let a=e;switch(a.op){case`and`:return{kind:`and`,children:a.children.map(e=>Zn(e,t,n,r,i))};case`or`:return{kind:`or`,children:a.children.map(e=>Zn(e,t,n,r,i))};case`not`:if(a.children.length!==1)throw Error(`Invalid 'not' operator arity in ${i}.`);return{kind:`not`,child:Zn(a.children[0],t,n,r,i)};case`implies`:if(a.children.length!==2)throw Error(`Invalid 'implies' operator arity in ${i}.`);return{kind:`implies`,left:Zn(a.children[0],t,n,r,i),right:Zn(a.children[1],t,n,r,i)};case`xor`:return{kind:`xor`,children:a.children.map(e=>Zn(e,t,n,r,i))};default:throw Error(`Unsupported logical operator "${String(a.op)}" in ${i}.`)}}throw Error(`Unsupported logical constraint node in ${i}.`)}function Qn(e){let{vars:t,varIndexMap:n,hasEmptyDomain:r}=Yn(e.variables),i=[],a=Xn(n,t,i),o=e.boolVars??[],s=new Map,c=[];for(let e=0;e<o.length;e++)s.set(o[e],e),c.push(o[e].name);let l=[];for(let t=0;t<e.constraints.length;t++){let r=e.constraints[t],i=`constraint "${r.name}"`,o={kind:`constraint`,index:t};if(r._indicatorMeta){let e=r._indicatorMeta,t=n.get(e.binVar);if(t===void 0)throw Error(`Indicator binary variable "${e.binVar.name}" in ${i} is not registered in the model.`);let{terms:s,rhs:c}=a.serializeConstraintSide(e.targetLhs,e.targetRhs,o,i);l.push({name:r.name,terms:s,sense:e.targetSense,rhs:c,indicator:{binVarIndex:t,activeValue:e.activeValue}});continue}if(qn(r.lhs))throw Error(`PumpkinSolver does not support quadratic constraints (${i}).`);let{terms:s,rhs:c}=a.serializeConstraintSide(r.lhs,r.rhs,o,i);l.push({name:r.name,terms:s,sense:r.sense,rhs:c})}let u=[],d=e.logicalConstraints??[];for(let e=0;e<d.length;e++){let t=d[e],n=`logical constraint "${t.name}"`,r={kind:`logic`,index:e},i=Zn(t.expr,a,r,s,n);u.push({name:t.name,expr:i})}return{vars:t,boolVars:c,constraints:l,logicalConstraints:u,auxPropagators:i,varIndexMap:n,lowerer:a,hasEmptyDomain:r}}function $n(e,t,n){let r={};if(e)for(let[t,n]of e)Gn(r,t,Z(n));let i;if(t&&t.length>0){i={};for(let[e,a]of t)Gn(i,e,a),n&&Gn(r,e,+!!a)}return{values:r,...i===void 0?{}:{boolValues:i}}}function er(e,t){let n={};if(e)for(let[t,r]of e)Gn(n,t,Z(r));if(t)for(let[e,r]of t)Gn(n,e,r);return n}var tr=new Set([`presolve`,`relativeGap`,`absoluteGap`,`threads`,`verbose`,`outputFlag`]),nr=new Set([`timeLimit`,`wasmUrl`,`useWorker`,`signal`,`onProgress`,`relax`]);function rr(e={}){if(e.relax!==void 0){if(typeof e.relax!=`boolean`)throw Error(`Invalid Pumpkin option "relax": expected boolean, got ${typeof e.relax}.`);if(e.relax===!0)throw Error(`PumpkinSolver does not support LP relaxation (relax: true). Use a simplex/IPM solver such as HiGHS or GLPK.`)}for(let t of tr)if(e[t]!==void 0)throw Error(`PumpkinSolver does not support option "${t}".`);for(let[t,n]of Object.entries(e))if(n!==void 0&&!nr.has(t))throw Error(`PumpkinSolver does not support option "${t}".`);if(e.useWorker!==void 0&&typeof e.useWorker!=`boolean`)throw Error(`Invalid Pumpkin option "useWorker": expected boolean, got ${typeof e.useWorker}.`);if(e.onProgress!==void 0&&typeof e.onProgress!=`function`)throw Error(`Invalid Pumpkin option "onProgress": expected function, got ${typeof e.onProgress}.`)}function ir(e){if(e.wasmUrl!==void 0&&e.wasmUrl!==null&&typeof e.wasmUrl!=`string`)throw Error(`Invalid pumpkin.wasm URL: expected string or null, got ${typeof e.wasmUrl}.`);if(e.wasmUrl===``)throw Error(`Invalid pumpkin.wasm URL: expected non-empty string or null (received empty string "").`);return e.wasmUrl}var ar=class e{static capabilities={supportsMIP:!0,supportsQP:!1,supportsQCQP:!1,supportsSMT:!1,supportsLogicalConstraints:!0,supportsUnsatCore:!0,supportsWarmStart:!0};name=`pumpkin`;options;capabilities=e.capabilities;constructor(e={}){this.options=e}async check(e,t={}){let n={...this.options,...t};rr(n);let r=ir(n),i=Kn(n.timeLimit),a=Qn(e);if(n.signal?.aborted)return{status:`Unknown`,values:{},runTime:0};if(a.hasEmptyDomain)return{status:`Unsat`,values:{},unsatCore:[],conflicts:[],runTime:1e-6};let o=JSON.stringify({vars:a.vars,boolVars:a.boolVars,constraints:a.constraints,logicalConstraints:a.logicalConstraints,auxPropagators:a.auxPropagators,timeLimitMs:i}),s=n.useWorker??An(),c;if(s)c=await Vn().check({requestJson:o,wasmUrl:r},{signal:n.signal});else{let e=await Pn(r);if(n.signal?.aborted)return{status:`Unknown`,values:{},runTime:0};let t=performance.now(),i=e.check_with_callback(o,()=>!!n.signal?.aborted),a=Math.max((performance.now()-t)/1e3,1e-6);if(c=JSON.parse(i),c.runTime=a,c.error)throw Error(c.error)}let l=c.runTime??0;if(c.status===`Sat`)return{status:`Sat`,values:er(c.values,c.boolValues),runTime:l};if(c.status===`Unsat`){let e=c.unsatCore?[...c.unsatCore]:[];return{status:`Unsat`,values:{},unsatCore:e,conflicts:e,runTime:l}}return{status:`Unknown`,values:{},runTime:l}}async solve(e,t={}){let n={...this.options,...t};rr(n);let r=ir(n),a=Kn(n.timeLimit),o=i(e.sense),s=Qn(e);if(qn(e.objective))throw Error(`PumpkinSolver does not support quadratic objective expressions (QuadExpr). Use a QP solver such as HiGHS.`);let c=e.objective;if(typeof c.constant!=`number`||!Number.isFinite(c.constant))throw Error(`Invalid non-finite objective constant.`);let l=Z(c.constant),{terms:u,sumMaxAbs:d}=s.lowerer.lowerLinExpr(c,{kind:`objective`},`objective expression`,!0);if(d>Hn)throw Error(`Objective expression magnitude (${d}) exceeds Pumpkin safe 32-bit integer range [-${Hn}, ${Hn}].`);if(n.signal?.aborted)return{status:`Unknown`,terminationStatus:`Interrupted`,hasPrimalSolution:!1,objectiveValue:null,values:{},runTime:0};if(s.hasEmptyDomain)return{status:`Infeasible`,terminationStatus:`Infeasible`,hasPrimalSolution:!1,objectiveValue:null,values:{},runTime:1e-6};let f=JSON.stringify({vars:s.vars,boolVars:s.boolVars,constraints:s.constraints,logicalConstraints:s.logicalConstraints,auxPropagators:s.auxPropagators,sense:o,objectiveTerms:u,objectiveConstant:l,timeLimitMs:a}),p=n.useWorker??An(),m=n.onProgress,h=0,g=m?e=>{h++,m(e)}:void 0,_;if(p)_=await Vn().solve({requestJson:f,wasmUrl:r},{signal:n.signal,onProgress:g});else{let e=await Pn(r);if(n.signal?.aborted)return{status:`Unknown`,terminationStatus:`Interrupted`,hasPrimalSolution:!1,objectiveValue:null,values:{},runTime:0};let t=performance.now(),i=null,a=n.signal,o=g?e=>{try{let n=JSON.parse(e),r=Math.max((performance.now()-t)/1e3,1e-6);return g({elapsedTime:r,elapsedSeconds:r,objectiveValue:n.objectiveValue}),!!a?.aborted}catch(e){return i=e,!0}}:null,s=a?()=>!!a.aborted:null,c=e.solve_with_callback(f,o,s);if(i!==null)throw i;let l=Math.max((performance.now()-t)/1e3,1e-6);if(_=JSON.parse(c),_.runTime=l,_.error)throw Error(_.error)}let v=_.status===`Optimal`||_.status===`Feasible`,y=typeof _.objectiveValue==`number`?Z(_.objectiveValue):null,b=_.runTime??0;v&&h===0&&g&&g({elapsedTime:b,elapsedSeconds:b,...y===null?{}:{objectiveValue:y}});let x=v?$n(_.values,_.boolValues,!0):{values:{}};return{status:_.status,terminationStatus:_.terminationStatus,hasPrimalSolution:v,objectiveValue:y,values:x.values,...x.boolValues===void 0?{}:{boolValues:x.boolValues},runTime:b}}};function or(e){$e(`pumpkin`,t=>new ar(t??e))}or();function sr(e,t){if(e===void 0)return 1e-6;if(typeof e!=`number`||!Number.isFinite(e)||e<0)throw Error(`Invalid ${t}: expected a finite non-negative number, received ${String(e)}.`);return e}function cr(e,t={}){let n=sr(t.feasibilityTolerance,`feasibilityTolerance`),r=sr(t.integralityTolerance,`integralityTolerance`),i=t.evaluateLogicalConstraints===void 0||!!t.evaluateLogicalConstraints,a=t.values!==void 0&&t.values!==null;if(t.values!==void 0&&(typeof t.values!=`object`||t.values===null||Array.isArray(t.values)))throw Error(`Invalid values option: expected a plain object mapping variable names to values.`);let o=t.values,s=[],u=Object.create(null),d=[],f=[],p=0,m=e=>{typeof e==`number`&&!Number.isNaN(e)&&e>p&&(p=e)},g=e=>{s.push(e),Object.prototype.hasOwnProperty.call(u,e.name)||(u[e.name]=[]),u[e.name].push(e),e.type!==`missing_value`&&e.type!==`unchecked_constraint`&&m(e.violation)},_=[],v=[];for(let t of e.variables.values())t.type===`Boolean`?v.push(t):_.push(t);let y=[],b=[];for(let t of e.constraints.values())t instanceof I?y.push(t):b.push(t);let x=new Map,S=new Map,C=0,T=0,E=0,D=0;for(let e of _){let t=a?Object.prototype.hasOwnProperty.call(o,e.name)?o[e.name]:void 0:e.value;if(t==null){f.push(e.name),g({type:`missing_value`,target:`variable`,name:e.name,actual:t??null,violation:1/0,message:`Variable "${e.name}" has no assigned solution value.`});continue}if(typeof t!=`number`||!Number.isFinite(t)){g({type:`non_finite_value`,target:`variable`,name:e.name,actual:t,violation:1/0,message:`Variable "${e.name}" has non-finite or non-numeric value: ${String(t)}.`});continue}x.set(e,t),C++;let i=e.type===`Binary`||e.type===`BINARY`,s=i||e.type===`Integer`||e.type===`INTEGER`,c=i?Math.max(0,e.lb):e.lb,l=i?Math.min(1,e.ub):e.ub,u=typeof e.lb==`number`&&!Number.isNaN(e.lb)&&e.lb!==1/0,d=typeof e.ub==`number`&&!Number.isNaN(e.ub)&&e.ub!==-1/0;if(!u)g({type:`lower_bound`,target:`variable`,name:e.name,actual:t,limit:e.lb,violation:1/0,message:`Variable "${e.name}" has invalid lower bound (${String(e.lb)}).`});else if(c!==-1/0){let r=t-c,i=Math.max(0,c-t);m(i),i>n&&g({type:`lower_bound`,target:`variable`,name:e.name,actual:t,limit:c,violation:i,signedViolation:r,message:`Variable "${e.name}" value (${t}) violates lower bound (${c}) by ${i}.`})}if(!d)g({type:`upper_bound`,target:`variable`,name:e.name,actual:t,limit:e.ub,violation:1/0,message:`Variable "${e.name}" has invalid upper bound (${String(e.ub)}).`});else if(l!==1/0){let r=t-l,i=Math.max(0,t-l);m(i),i>n&&g({type:`upper_bound`,target:`variable`,name:e.name,actual:t,limit:l,violation:i,signedViolation:r,message:`Variable "${e.name}" value (${t}) violates upper bound (${l}) by ${i}.`})}if(u&&d&&c>l&&c-t<=n&&t-l<=n){let n=c-l;g({type:`lower_bound`,target:`variable`,name:e.name,actual:t,limit:c,violation:n,signedViolation:t-c,message:`Variable "${e.name}" has inverted bounds [${c}, ${l}].`})}if(s){let n=Math.round(t),a=t-n,o=Math.abs(a);m(o),o>r&&g({type:`integrality`,target:`variable`,name:e.name,varType:i?`Binary`:`Integer`,actual:t,nearestInteger:n,violation:o,signedViolation:a,message:`${i?`Binary`:`Integer`} variable "${e.name}" value (${t}) violates integrality by ${o} (nearest integer: ${n}).`})}}for(let e of v){let t=a?Object.prototype.hasOwnProperty.call(o,e.name)?o[e.name]:void 0:e.value;if(t==null){f.push(e.name),g({type:`missing_value`,target:`bool_variable`,name:e.name,actual:t??null,violation:1/0,message:`Boolean variable "${e.name}" has no assigned solution value.`});continue}if(typeof t!=`boolean`){g({type:`invalid_boolean_value`,target:`bool_variable`,name:e.name,actual:t,violation:1/0,message:`Boolean variable "${e.name}" has non-boolean value: ${String(t)}.`});continue}S.set(e,t),T++}let ee=e=>{switch(e.kind){case`abs`:{let t=O(e.arg);return t.ok?{ok:!0,value:Math.abs(t.value),...t.atDomainError?{atDomainError:t.atDomainError}:{}}:t}case`max`:{let t=-1/0,n;for(let r of e.args){let e=O(r);if(!e.ok)return e;!n&&e.atDomainError&&(n=e.atDomainError),e.value>t&&(t=e.value)}return{ok:!0,value:t,...n?{atDomainError:n}:{}}}case`min`:{let t=1/0,n;for(let r of e.args){let e=O(r);if(!e.ok)return e;!n&&e.atDomainError&&(n=e.atDomainError),e.value<t&&(t=e.value)}return{ok:!0,value:t,...n?{atDomainError:n}:{}}}case`at`:{let t=O(e.index);if(!t.ok)return t;let i=t.value,a=e.array.length-1,o=Math.max(0,-i),s=Math.max(0,i-a),c=Math.max(o,s),l=Math.abs(i-Math.round(i));if(c>n||l>r)return{ok:!0,value:0,atDomainError:{violation:Math.max(c,l),message:`at() index (${i}) violates valid integer range [0, ${a}].`}};let u=O(e.array[Math.round(i)]);return u.ok?{ok:!0,value:u.value,...t.atDomainError??u.atDomainError?{atDomainError:t.atDomainError??u.atDomainError}:{}}:u}}},O=e=>{let t=e.constant===void 0?0:e.constant;if(typeof t!=`number`||!Number.isFinite(t))return{ok:!1,reason:`non-finite constant (${String(t)})`};let n=t;for(let[t,r]of e.terms){if(typeof r!=`number`||!Number.isFinite(r))return{ok:!1,reason:`non-finite coefficient (${String(r)}) for variable "${t.name}"`};if(r!==0){if(!x.has(t))return{ok:!1,reason:`missing or invalid value for variable "${t.name}"`};if(n+=r*x.get(t),!Number.isFinite(n))return{ok:!1,reason:`linear expression evaluation overflowed finite range`}}}let r;for(let t of e.nonlinearTerms??[]){if(typeof t.coeff!=`number`||!Number.isFinite(t.coeff))return{ok:!1,reason:`non-finite nonlinear coefficient (${String(t.coeff)})`};let e=ee(t.atom);if(!e.ok)return e;if(!r&&e.atDomainError&&(r=e.atDomainError),t.coeff!==0&&(n+=t.coeff*e.value,!Number.isFinite(n)))return{ok:!1,reason:`expression evaluation overflowed finite range`}}return{ok:!0,value:n,...r?{atDomainError:r}:{}}},k=e=>{switch(e.kind){case`abs`:return A(e.arg);case`max`:case`min`:{let t=[];for(let n of e.args){let e=A(n);if(!e.ok)return e;t.push(...e.errors)}return{ok:!0,errors:t}}case`at`:{let t=[],i=A(e.index);if(!i.ok)return i;t.push(...i.errors);for(let n of e.array){let e=A(n);if(!e.ok)return e;t.push(...e.errors)}let a=O(e.index);if(!a.ok)return a;if(i.errors.length===0){let i=a.value,o=e.array.length-1,s=Math.max(0,-i),c=Math.max(0,i-o),l=Math.max(s,c),u=Math.abs(i-Math.round(i));if(l>n||u>r){let e=Math.max(l,u);t.push({violation:e,message:`at() index (${i}) violates valid integer range [0, ${o}].`})}}return{ok:!0,errors:t}}}},A=e=>{let t=[];for(let n of e.nonlinearTerms??[]){let e=k(n.atom);if(!e.ok)return e;t.push(...e.errors)}return{ok:!0,errors:t}},te=e=>{if(e instanceof c)return{ok:!0};if(e instanceof I){let t=A(e.lhs);return t.ok?{ok:!0,...t.errors.length>0?{firstError:t.errors[0]}:{}}:t}if(e instanceof h){let t=e.spec,n=t.kind===`distinct`?t.args:t.kind===`disjoint`||t.kind===`cumulative`?t.tasks.map(e=>e.start):t.vars;for(let e of n){let t=A(e);if(!t.ok)return t;if(t.errors.length>0)return{ok:!0,firstError:t.errors[0]}}return{ok:!0}}if(e instanceof l){let t;for(let n of e.children){let e=te(n);if(!e.ok)return e;!t&&e.firstError&&(t=e.firstError)}return{ok:!0,...t?{firstError:t}:{}}}return{ok:!0}},ne=(e,t=n)=>{if(typeof e.rhs!=`number`||!Number.isFinite(e.rhs))return{status:`unchecked`,reason:`non-finite right-hand side (${String(e.rhs)})`};let r=A(e.lhs);if(!r.ok)return{status:`unchecked`,reason:r.reason};let i=O(e.lhs);if(!i.ok)return{status:`unchecked`,reason:i.reason};if(r.errors.length>0||i.atDomainError){let t=r.errors[0]??i.atDomainError;return{status:`violated`,lhsVal:i.value,signed:i.value-e.rhs,violation:t.violation,message:`Constraint "${e.name}" invalid element lookup: ${t.message}`}}let a=i.value,o=a-e.rhs;if(!Number.isFinite(o))return{status:`unchecked`,reason:`constraint residual overflowed finite range`};let s=e.sense===`<=`?Math.max(0,o):e.sense===`>=`?Math.max(0,-o):e.sense===`!=`?Math.max(0,1-Math.abs(o)):Math.abs(o);return s>t?{status:`violated`,lhsVal:a,signed:o,violation:s,message:`Constraint "${e.name}" (${a} ${e.sense} ${e.rhs}) violated by ${s}.`}:{status:`satisfied`,lhsVal:a,signed:o,violation:s}},re=e.objective();if((re instanceof w||re instanceof z)&&re.nonlinearTerms.length>0){let e=A(new z(new Map,0,re.nonlinearTerms));if(e.ok)for(let t of e.errors)g({type:`linear_constraint`,target:`constraint`,name:`objective_at`,violation:t.violation,message:`Objective at() lookup failed: ${t.message}`})}for(let e of y){let t=ne(e);t.status===`unchecked`?(d.push(e.name),g({type:`unchecked_constraint`,target:`constraint`,name:e.name,sense:e.sense,limit:e.rhs,rhs:e.rhs,violation:1/0,message:`Constraint "${e.name}" could not be evaluated: ${t.reason}.`})):t.status===`violated`?(E++,g({type:`linear_constraint`,target:`constraint`,name:e.name,sense:e.sense,actual:t.lhsVal,limit:e.rhs,rhs:e.rhs,violation:t.violation,signedViolation:t.signed,message:t.message})):(E++,m(t.violation))}let ie=e=>{if(e instanceof c)return S.has(e)?{ok:!0,value:S.get(e),violation:0}:{ok:!1,reason:`missing or invalid value for Boolean variable "${e.name}"`};if(e instanceof I){if(e.sense===`!=`){let t=O(e.lhs);if(!t.ok)return{ok:!1,reason:t.reason};if(t.atDomainError)return{ok:!1,reason:t.atDomainError.message};let r=Math.abs(t.value-e.rhs);return r<=n?{ok:!0,value:!1,violation:0}:r>=1-n?{ok:!0,value:!0,violation:0}:{ok:!1,reason:`discrete comparison "${e.name}" lies between 0 and 1 (${t.value} != ${e.rhs})`}}let t=ne(e,0);if(t.status===`unchecked`)return{ok:!1,reason:t.reason};if(n>0){let r=Math.abs(t.lhsVal-e.rhs);if(r>0&&r<=n)return{ok:!1,reason:`numeric comparison "${e.name}" lies within feasibilityTolerance (${n}) of boundary (${t.lhsVal} vs ${e.rhs})`}}return{ok:!0,value:t.status===`satisfied`,violation:0}}if(e instanceof h){let t=e.spec;if(t.kind===`distinct`){let e=[];for(let n of t.args){let t=O(n);if(!t.ok)return t;if(t.atDomainError)return{ok:!1,reason:t.atDomainError.message};e.push(t.value)}for(let t=0;t<e.length;t++)for(let r=t+1;r<e.length;r++){let i=Math.abs(e[t]-e[r]);if(i<=n)return{ok:!0,value:!1,violation:0};if(i<1-n)return{ok:!1,reason:`distinct() operands at indices (${t}, ${r}) have fractional gap (${i})`}}return{ok:!0,value:!0,violation:0}}if(t.kind===`disjoint`){let e=[];for(let n of t.tasks){let t=O(n.start);if(!t.ok)return t;if(t.atDomainError)return{ok:!1,reason:t.atDomainError.message};e.push(t.value)}for(let r=0;r<t.tasks.length;r++)for(let i=r+1;i<t.tasks.length;i++){let a=e[r],o=t.tasks[r].duration,s=e[i],c=t.tasks[i].duration;if(!(a+o<=s+n||s+c<=a+n))return{ok:!0,value:!1,violation:0}}return{ok:!0,value:!0,violation:0}}if(t.kind===`cumulative`){let e=[];for(let n of t.tasks){let t=O(n.start);if(!t.ok)return t;if(t.atDomainError)return{ok:!1,reason:t.atDomainError.message};e.push(t.value)}let r=[];for(let n=0;n<t.tasks.length;n++){let i=t.tasks[n];if(i.duration>0&&i.demand>0){if(i.demand>t.capacity)return{ok:!0,value:!1,violation:0};r.push({start:e[n],duration:i.duration,demand:i.demand})}}for(let e=0;e<r.length;e++){let i=r[e].start,a=0;for(let e=0;e<r.length;e++){let t=r[e];t.start-n<=i&&i<t.start+t.duration-n&&(a+=t.demand)}if(a>t.capacity+n)return{ok:!0,value:!1,violation:0}}return{ok:!0,value:!0,violation:0}}if(t.kind===`allowed`){let e=[];for(let n of t.vars){let t=O(n);if(!t.ok)return t;if(t.atDomainError)return{ok:!1,reason:t.atDomainError.message};e.push(t.value)}return{ok:!0,value:t.tuples.some(t=>t.every((t,r)=>Math.abs(e[r]-t)<=n)),violation:0}}}if(e instanceof l)switch(e.op){case`not`:{let t=ie(e.children[0]);return t.ok?{ok:!0,value:!t.value,violation:0}:t}case`and`:{let t=0;for(let n of e.children){let e=ie(n);if(!e.ok)return e;if(!e.value)return{ok:!0,value:!1,violation:0};e.violation>t&&(t=e.violation)}return{ok:!0,value:!0,violation:t}}case`or`:{let t=!1,n=1/0;for(let r of e.children){let e=ie(r);if(!e.ok)return e;e.value&&(t=!0,e.violation<n&&(n=e.violation))}return{ok:!0,value:t,violation:t?n:0}}case`implies`:{let t=ie(e.children[0]);if(!t.ok)return t;if(!t.value)return{ok:!0,value:!0,violation:0};let n=ie(e.children[1]);return n.ok?{ok:!0,value:n.value,violation:n.value?n.violation:0}:n}case`xor`:{let t=!1,n=0;for(let r of e.children){let e=ie(r);if(!e.ok)return e;e.value&&(t=!t,e.violation>n&&(n=e.violation))}return{ok:!0,value:t,violation:t?n:0}}default:return{ok:!1,reason:`unsupported logical operator "${String(e.op)}"`}}return{ok:!1,reason:`unsupported logical expression node`}};for(let e=0;e<b.length;e++){let t=b[e],n=t.name||`lc_${e+1}`;if(!i){d.push(n),g({type:`unchecked_constraint`,target:`logical_constraint`,name:n,violation:1/0,message:`Logical constraint "${n}" was not evaluated because evaluateLogicalConstraints is false.`});continue}let r=te(t.expr);if(!r.ok){d.push(n),g({type:`unchecked_constraint`,target:`logical_constraint`,name:n,violation:1/0,message:`Logical constraint "${n}" could not be evaluated: ${r.reason}.`});continue}if(r.firstError){D++,g({type:`logical_constraint`,target:`logical_constraint`,name:n,actual:!1,limit:!0,violation:r.firstError.violation,signedViolation:-1,message:`Logical constraint "${n}" invalid element lookup: ${r.firstError.message}`});continue}let a=ie(t.expr);if(!a.ok){d.push(n),g({type:`unchecked_constraint`,target:`logical_constraint`,name:n,violation:1/0,message:`Logical constraint "${n}" could not be evaluated: ${a.reason}.`});continue}D++,a.value?m(a.violation):g({type:`logical_constraint`,target:`logical_constraint`,name:n,actual:!1,limit:!0,violation:1,signedViolation:-1,message:`Logical constraint "${n}" evaluated to false.`})}let j=C===_.length&&T===v.length&&E===y.length&&D===b.length&&d.length===0&&f.length===0;return{valid:j&&s.length===0,complete:j,violations:s,violationsByName:u,uncheckedConstraints:d,missingVariables:f,maxViolation:p,summary:{checkedVariables:C,totalVariables:_.length,checkedBoolVariables:T,totalBoolVariables:v.length,checkedLinearConstraints:E,totalLinearConstraints:y.length,checkedLogicalConstraints:D,totalLogicalConstraints:b.length}}}function lr(e,t){if(typeof e!=`number`||!Number.isFinite(e)||e<=0)throw Error(`Invalid Big-M value for indicator constraint "${t}": expected a finite positive number, received ${e}.`)}function ur(e,t,n){let r=e.constant===void 0?0:e.constant;if(!Number.isFinite(t)||!Number.isFinite(r))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": constraint contains non-finite constant (${r}) or right-hand side (${t}).`);let i=t-r;if(!Number.isFinite(i))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": effective right-hand side (${t} - ${r}) overflows finite floating-point range. Please rescale coefficients/constants.`);for(let[t,r]of e.terms){if(!Number.isFinite(r))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" has non-finite coefficient (${r}).`);if(Number.isNaN(t.lb)||Number.isNaN(t.ub)||t.lb===1/0||t.ub===-1/0||t.lb>t.ub)throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" has invalid bounds [${t.lb}, ${t.ub}].`)}return i}function dr(e,t,n){let r=ur(e,t,n),i=0;for(let[t,r]of e.terms){if(r===0)continue;let e;if(r>0){if(!Number.isFinite(t.ub))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" lacks a finite upper bound (required because coefficient ${r} is positive in <= constraint). Please set an explicit finite upper bound on the variable or specify { M } explicitly in indicator options.`);e=t.ub}else{if(!Number.isFinite(t.lb))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" lacks a finite lower bound (required because coefficient ${r} is negative in <= constraint). Please set an explicit finite lower bound on the variable or specify { M } explicitly in indicator options.`);e=t.lb}let a=r*e;if(i+=a,!Number.isFinite(a)||!Number.isFinite(i))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": numeric overflow while bounding contribution of variable "${t.name}". Please rescale coefficients/bounds or specify a finite { M } explicitly.`)}let a=i-r;if(!Number.isFinite(a))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": numeric overflow while computing Big-M (${i} - ${r}). Please rescale coefficients/bounds or specify a finite { M } explicitly.`);let o=Math.max(0,a);if(!Number.isFinite(o)||!Number.isFinite(r+o))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": derived Big-M (${o}) or shifted right-hand side overflows finite floating-point range. Please rescale coefficients/bounds or specify a finite { M } explicitly.`);return o}function fr(e,t,n){let r=ur(e,t,n),i=0;for(let[t,r]of e.terms){if(r===0)continue;let e;if(r>0){if(!Number.isFinite(t.lb))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" lacks a finite lower bound (required because coefficient ${r} is positive in >= constraint). Please set an explicit finite lower bound on the variable or specify { M } explicitly in indicator options.`);e=t.lb}else{if(!Number.isFinite(t.ub))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": variable "${t.name}" lacks a finite upper bound (required because coefficient ${r} is negative in >= constraint). Please set an explicit finite upper bound on the variable or specify { M } explicitly in indicator options.`);e=t.ub}let a=r*e;if(i+=a,!Number.isFinite(a)||!Number.isFinite(i))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": numeric overflow while bounding contribution of variable "${t.name}". Please rescale coefficients/bounds or specify a finite { M } explicitly.`)}let a=r-i;if(!Number.isFinite(a))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": numeric overflow while computing Big-M (${r} - ${i}). Please rescale coefficients/bounds or specify a finite { M } explicitly.`);let o=Math.max(0,a);if(!Number.isFinite(o)||!Number.isFinite(r-o))throw Error(`Cannot derive safe Big-M for indicator constraint "${n}": derived Big-M (${o}) or shifted right-hand side overflows finite floating-point range. Please rescale coefficients/bounds or specify a finite { M } explicitly.`);return o}function pr(e,t,n,r,i,a,o){if(!(e instanceof H&&(e.type===`Binary`||e.type===`Integer`&&e.lb===0&&e.ub===1)))throw Error(`Indicator variable "${e?.name??String(e)}" must be a Binary variable (or Integer variable with bounds [0, 1]), received "${e?.type??typeof e}" with bounds [${e?.lb}, ${e?.ub}].`);if(!Number.isFinite(e.lb)||!Number.isFinite(e.ub)||e.lb<0||e.ub>1||e.lb>e.ub)throw Error(`Binary indicator variable "${e.name}" has invalid bounds [${e.lb}, ${e.ub}]. Binary variables must stay within [0, 1] with lb <= ub.`);let s=ur(t,r,o);if(i!==0&&i!==1)throw Error(`Invalid activeValue: ${i}. Indicator activation value must be 0 or 1.`);if(n!==`<=`&&n!==`>=`)throw Error(`Invalid indicator sense for "${o}": expected "<=" or ">=", received "${String(n)}".`);if(!Number.isFinite(a)||a<0)throw Error(`Invalid Big-M value for indicator constraint "${o}": expected a finite non-negative number, received ${a}.`);let c=t.terms.get(e);if(c!==void 0&&c!==0)throw Error(`Indicator constraint "${o}" cannot include its own binary activation variable "${e.name}" in the linear expression.`);let l,u;if(i===1?n===`<=`?(l=a,u=s+a):(l=-a,u=s-a):n===`<=`?(l=-a,u=s):(l=a,u=s),!Number.isFinite(u))throw Error(`Cannot construct finite indicator constraint "${o}": shifted right-hand side overflows finite floating-point range. Please rescale coefficients/bounds or specify a smaller finite { M }.`);let d=new Map;for(let[e,n]of t.terms)n!==0&&d.set(e,n);return l!==0&&d.set(e,l),{lhs:new z(d,0),rhs:u}}function $(e,t=0){let n=new Map;for(let[t,r]of e){if(r===0)continue;let e=(n.get(t)??0)+r;e===0?n.delete(t):n.set(t,e)}return new z(n,t)}function mr(e,t,n=1){if(n!==0){e.constant+=t.constant*n;for(let[r,i]of t.terms.entries())i!==0&&e.addTerm(r,i*n)}}var hr=5e3,gr=25e3;function _r(e,t,n,r,a){let o=[...e],s=[],u=new Map,d=new Map,f=new Set,p=[];for(let e of n)if(e.sense===`!=`||e.lhs.hasNonlinearTerms())p.push(e);else{let t=e;if(f.has(t.name)){let n=1;for(;f.has(`${e.name}_${n}`);)n++;t=new I(e.lhs,e.sense,e.rhs,`${e.name}_${n}`)}f.add(t.name),s.push(t),d.set(t,e.name)}let m=new Set(e.map(e=>e.name)),g=0;function _(e){let t;do t=`__washi_${e}_${++g}`;while(m.has(t));return m.add(t),t}function v(e,t){let n=e.name||`c`,r=n;if(f.has(r)){let t=1;for(;f.has(`${n}_${t}`);)t++;r=`${n}_${t}`,e=new I(e.lhs,e.sense,e.rhs,r)}f.add(r),s.push(e),d.set(e,t)}for(let e of t){let t=e.name;m.has(t)?t=_(`bool_${e.name}`):m.add(t);let n=new H({name:t,type:`Binary`,lb:0,ub:1});u.set(e,n),o.push(n)}function y(e,t){if(!Number.isFinite(e.constant))throw Error(`Cannot linearize piecewise expression in "${t}": non-finite constant (${e.constant}).`);let n=e.constant,r=e.constant,i=Number.isSafeInteger(e.constant);for(let[a,o]of e.terms.entries()){if(!Number.isFinite(o))throw Error(`Cannot linearize piecewise expression in "${t}": variable "${a.name}" has non-finite coefficient (${o}).`);if(o===0)continue;if(typeof a.lb!=`number`||typeof a.ub!=`number`||Number.isNaN(a.lb)||Number.isNaN(a.ub)||a.lb===-1/0||a.ub===1/0||a.lb>a.ub)throw Error(`Cannot linearize non-convex piecewise expression in "${t}": variable "${a.name}" has unbounded or invalid domain [${a.lb}, ${a.ub}]. Finite bounds are required.`);let e=a.lb,s=a.ub;if(a.type===`Binary`){let t=Math.max(0,Math.ceil(a.lb)),n=Math.min(1,Math.floor(a.ub));t<=n&&(e=t,s=n)}else if(a.type===`Integer`){let t=Math.ceil(a.lb),n=Math.floor(a.ub);t<=n&&(e=t,s=n)}let c=o*e,l=o*s;if(n+=Math.min(c,l),r+=Math.max(c,l),!Number.isFinite(n)||!Number.isFinite(r))throw Error(`Cannot linearize non-convex piecewise expression in "${t}": bound calculation overflowed.`);i&&=(a.type===`Integer`||a.type===`Binary`)&&Number.isSafeInteger(o)&&Number.isSafeInteger(e)&&Number.isSafeInteger(s)}return{lb:Object.is(n,-0)?0:n,ub:Object.is(r,-0)?0:r,isDiscrete:i}}function b(e,t){if(!e.hasNonlinearTerms())return e.clone();let n=new z(e.terms,e.constant);for(let r of e.nonlinearTerms)r.coeff!==0&&mr(n,x(r.atom,t),r.coeff);return n}function x(e,t){switch(e.kind){case`abs`:{let n=b(e.arg,t),{lb:r,ub:i,isDiscrete:a}=y(n,t);if(r>=0)return n;if(i<=0)return n.mul(-1);let s=Math.max(-r,i),c=new H({name:_(`abs_t`),type:a?`Integer`:`Continuous`,lb:0,ub:s}),l=new H({name:_(`abs_z`),type:`Binary`,lb:0,ub:1});o.push(c,l);let u=$([[c,1]],0);return P(new I(n.sub(u),`<=`,0,`${t}_abs_pos`),t),P(new I(n.mul(-1).sub(u),`<=`,0,`${t}_abs_neg`),t),P(new I(u.sub(n).add($([[l,2*-r]],0)),`<=`,2*-r,`${t}_abs_hi_pos`),t),P(new I(u.add(n).sub($([[l,2*i]],0)),`<=`,0,`${t}_abs_hi_neg`),t),u}case`max`:{let n=e.args.map(e=>b(e,t));if(n.length===1)return n[0];let r=n.map(e=>y(e,t)),i=Math.max(...r.map(e=>e.lb)),a=Math.max(...r.map(e=>e.ub)),s=r.every(e=>e.isDiscrete),c=new H({name:_(`max_t`),type:s?`Integer`:`Continuous`,lb:i,ub:a});o.push(c);let l=$([[c,1]],0),u=[];for(let e=0;e<n.length;e++){let i=new H({name:_(`max_z_${e}`),type:`Binary`,lb:0,ub:1});o.push(i),u.push(i),P(new I(n[e].sub(l),`<=`,0,`${t}_max_lb_${e}`),t);let s=a-r[e].lb;P(new I(l.sub(n[e]).add($([[i,s]],0)),`<=`,s,`${t}_max_ub_${e}`),t)}return v(new I($(u.map(e=>[e,1]),0),`==`,1,`${t}_max_sos`),t),l}case`min`:{let n=e.args.map(e=>b(e,t));if(n.length===1)return n[0];let r=n.map(e=>y(e,t)),i=Math.min(...r.map(e=>e.lb)),a=Math.min(...r.map(e=>e.ub)),s=r.every(e=>e.isDiscrete),c=new H({name:_(`min_t`),type:s?`Integer`:`Continuous`,lb:i,ub:a});o.push(c);let l=$([[c,1]],0),u=[];for(let e=0;e<n.length;e++){let a=new H({name:_(`min_z_${e}`),type:`Binary`,lb:0,ub:1});o.push(a),u.push(a),P(new I(n[e].sub(l),`>=`,0,`${t}_min_ub_${e}`),t);let s=r[e].ub-i;P(new I(n[e].sub(l).add($([[a,s]],0)),`<=`,s,`${t}_min_lb_${e}`),t)}return v(new I($(u.map(e=>[e,1]),0),`==`,1,`${t}_min_sos`),t),l}case`at`:{let n=e.array.length,r=b(e.index,t),i=e.array.map(e=>b(e,t)),a=[];for(let e=0;e<n;e++){let t=new H({name:_(`at_lam_${e}`),type:`Binary`,lb:0,ub:1});o.push(t),a.push(t)}v(new I($(a.map(e=>[e,1]),0),`==`,1,`${t}_at_sos`),t);let s=r.clone();for(let e=1;e<n;e++)s.addTerm(a[e],-e);P(new I(s,`==`,0,`${t}_at_idx`),t);let c=new z(new Map,0);for(let e=0;e<n;e++){let n=i[e];if(n.terms.size===0)n.constant!==0&&c.addTerm(a[e],n.constant);else{let{lb:r,ub:i,isDiscrete:s}=y(n,t),l=new H({name:_(`at_w_${e}`),type:s?`Integer`:`Continuous`,lb:Math.min(0,r),ub:Math.max(0,i)});o.push(l);let u=$([[l,1]],0);P(new I($([[l,1],[a[e],-r]],0),`>=`,0,`${t}_at_mc1_${e}`),t),P(new I($([[l,1],[a[e],-i]],0),`<=`,0,`${t}_at_mc2_${e}`),t),P(new I(u.sub(n).add($([[a[e],-i]],0)),`>=`,-i,`${t}_at_mc3_${e}`),t),P(new I(u.sub(n).add($([[a[e],-r]],0)),`<=`,-r,`${t}_at_mc4_${e}`),t),c.addTerm(l,1)}}return c}}}function S(e,t,n){if(t===`upper`&&e.kind===`max`){let t=new H({name:_(`epi_max`),type:`Continuous`,lb:-1/0,ub:1/0});o.push(t);let r=$([[t,1]],0);for(let t=0;t<e.args.length;t++)T(e.args[t].sub(r),`<=`,0,`${n}_epi_max_${t}`,n);return r}if(t===`upper`&&e.kind===`abs`){let t=e.arg.hasNonlinearTerms()?b(e.arg,n):e.arg,r=new H({name:_(`epi_abs`),type:`Continuous`,lb:0,ub:1/0});o.push(r);let i=$([[r,1]],0);return P(new I(t.sub(i),`<=`,0,`${n}_epi_abs_pos`),n),P(new I(t.mul(-1).sub(i),`<=`,0,`${n}_epi_abs_neg`),n),i}if(t===`lower`&&e.kind===`min`){let t=new H({name:_(`epi_min`),type:`Continuous`,lb:-1/0,ub:1/0});o.push(t);let r=$([[t,1]],0);for(let t=0;t<e.args.length;t++)T(e.args[t].sub(r),`>=`,0,`${n}_epi_min_${t}`,n);return r}return x(e,n)}function C(e,t,n){if(!e.hasNonlinearTerms())return e;if(t===`==`||t===`!=`)return b(e,n);let r=new z(e.terms,e.constant);for(let i of e.nonlinearTerms){if(i.coeff===0)continue;let e=t===`<=`?i.coeff>0?`upper`:`lower`:i.coeff>0?`lower`:`upper`;mr(r,S(i.atom,e,n),i.coeff)}return r}function T(e,t,n,r,i){let a=C(e,t,i);if(t===`!=`){ce(new I(a,`==`,n,r),i);return}P(new I(a,t,n,r),i)}function E(e,t){return e.lhs.hasNonlinearTerms()?new I(b(e.lhs,t),e.sense,e.rhs,e.name):e}function D(e,t){if(e instanceof c){let n=u.get(e);if(!n)throw Error(`Unregistered BoolVar "${e.name}" in logical constraint "${t}".`);return n}let n=new H({name:_(`expr`),type:`Binary`,lb:0,ub:1});return o.push(n),O(n,e,t),n}function ee(e,t,n,r){v(new I($([[e,1],[t,-1],[n,-1]],0),`<=`,0,`${r}_xor_1`),r),v(new I($([[e,1],[t,-1],[n,1]],0),`>=`,0,`${r}_xor_2`),r),v(new I($([[e,1],[n,-1],[t,1]],0),`>=`,0,`${r}_xor_3`),r),v(new I($([[e,1],[t,1],[n,1]],0),`<=`,2,`${r}_xor_4`),r)}function O(e,t,n){if(t instanceof c){let r=u.get(t);v(new I($([[e,1],[r,-1]],0),`==`,0,`${n}_equiv`),n);return}if(t instanceof I){let r=E(t,n);le(e,r,0,`${n}_c_neg`,n),se(e,r,1,`${n}_c_pos`,n);return}if(t instanceof h){ne(e,t,n);return}if(t instanceof l){if(t.op===`not`){let r=D(t.children[0],n);v(new I($([[e,1],[r,1]],0),`==`,1,`${n}_not`),n);return}if(t.op===`and`){let r=t.children.map(e=>D(e,n));for(let t=0;t<r.length;t++)v(new I($([[e,1],[r[t],-1]],0),`<=`,0,`${n}_and_ub_${t}`),n);v(new I($([[e,1],...r.map(e=>[e,-1])],0),`>=`,1-r.length,`${n}_and_lb`),n);return}if(t.op===`or`){let r=t.children.map(e=>D(e,n));for(let t=0;t<r.length;t++)v(new I($([[e,1],[r[t],-1]],0),`>=`,0,`${n}_or_lb_${t}`),n);v(new I($([[e,1],...r.map(e=>[e,-1])],0),`<=`,0,`${n}_or_ub`),n);return}if(t.op===`implies`){let r=D(t.children[0],n),i=D(t.children[1],n);v(new I($([[e,1],[r,1]],0),`>=`,1,`${n}_imp_1`),n),v(new I($([[e,1],[i,-1]],0),`>=`,0,`${n}_imp_2`),n),v(new I($([[e,1],[r,1],[i,-1]],0),`<=`,1,`${n}_imp_3`),n);return}if(t.op===`xor`){if(t.children.length===0){v(new I($([[e,1]],0),`==`,0,`${n}_xor_empty`),n);return}if(t.children.length===1){let r=D(t.children[0],n);v(new I($([[e,1],[r,-1]],0),`==`,0,`${n}_xor_single`),n);return}let r=t.children.map(e=>D(e,n)),i=r[0];for(let e=1;e<r.length-1;e++){let t=new H({name:_(`xor_fold_${e}`),type:`Binary`,lb:0,ub:1});o.push(t),ee(t,i,r[e],`${n}_xor_fold_${e}`),i=t}ee(e,i,r[r.length-1],n);return}}throw Error(`Unsupported logical element in equivalence linearization: ${t}`)}function k(e,t){let n=e.map(e=>b(e.start,t)),r=[];for(let t=0;t<e.length;t++)for(let i=t+1;i<e.length;i++)(e[t].duration>0||e[i].duration>0)&&r.push({i:t,j:i,sI:n[t],dI:e[t].duration,sJ:n[i],dJ:e[i].duration});return r}function A(e,t,n){let r=e.map(e=>({start:b(e.start,n),duration:e.duration,demand:e.demand})).filter(e=>e.duration>0&&e.demand>0);if(r.length===0)return{kind:`constant`,value:!0};let i=[];for(let e of r){let t=e.start.constant??0;if(!Number.isSafeInteger(t))throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: task start offset (${t}) must be a safe integer.`);let r=t,a=t;for(let[t,i]of e.start.terms.entries()){if(i===0)continue;if(typeof t.lb!=`number`||typeof t.ub!=`number`||Number.isNaN(t.lb)||Number.isNaN(t.ub)||t.lb===-1/0||t.ub===1/0||t.lb>t.ub)throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: variable "${t.name}" has unbounded or invalid domain [${t.lb}, ${t.ub}]. Finite bounds are required.`);if(!Number.isSafeInteger(i))throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: variable "${t.name}" coefficient (${i}) exceeds safe integer precision.`);let e=t.type===`Binary`?Math.max(0,Math.ceil(t.lb)):Math.ceil(t.lb),o=t.type===`Binary`?Math.min(1,Math.floor(t.ub)):Math.floor(t.ub);if(e>o)return{kind:`empty_domain`};if(!Number.isSafeInteger(e)||!Number.isSafeInteger(o))throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: variable "${t.name}" integer bounds [${e}, ${o}] exceed JavaScript safe integer precision.`);let s=i*e,c=i*o;if(r+=Math.min(s,c),a+=Math.max(s,c),!Number.isSafeInteger(s)||!Number.isSafeInteger(c)||!Number.isSafeInteger(r)||!Number.isSafeInteger(a))throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: task start time bounds exceed JavaScript safe integer precision.`)}let o=r+e.duration,s=a+e.duration;if(!Number.isSafeInteger(o)||!Number.isSafeInteger(s))throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: task end time bounds [${r}, ${s}) exceed JavaScript safe integer precision.`);i.push({...e,est:Object.is(r,-0)?0:r,lst:Object.is(a,-0)?0:a})}return i.some(e=>e.demand>t)?{kind:`constant`,value:!1}:{kind:`tasks`,active:i}}function te(e,t,n){let r=e.spec;switch(r.kind){case`distinct`:{let e=r.args.map(e=>b(e,n));if(e.length<=1){t||N(n);return}if(t)for(let t=0;t<e.length;t++)for(let r=t+1;r<e.length;r++)T(e[t].sub(e[r]),`!=`,0,`${n}_neq_${t}_${r}`,n);else{let t=[];for(let r=0;r<e.length;r++)for(let i=r+1;i<e.length;i++)t.push(new I(e[r].sub(e[i]),`==`,0,`${n}_eq_${r}_${i}`));M(new l(`or`,t),n)}return}case`disjoint`:{let e=k(r.tasks,n);if(e.length===0){t||N(n);return}if(t)for(let{i:t,j:r,sI:i,dI:a,sJ:s,dJ:c}of e){let e=new H({name:_(`disj_${t}_${r}`),type:`Binary`,lb:0,ub:1});o.push(e),ae(e,i.sub(s),`<=`,-a,1,`${n}_p_${t}_${r}`,n),ae(e,s.sub(i),`<=`,-c,0,`${n}_q_${t}_${r}`,n)}else M(new l(`or`,e.map(({i:e,j:t,sI:r,dI:i,sJ:a,dJ:o})=>new l(`and`,[new I(r.sub(a),`>=`,1-i,`${n}_ov1_${e}_${t}`),new I(a.sub(r),`>=`,1-o,`${n}_ov2_${e}_${t}`)]))),n);return}case`cumulative`:{let e=A(r.tasks,r.capacity,n);if(e.kind===`empty_domain`){N(n);return}if(e.kind===`constant`){e.value!==t&&N(n);return}let{active:i}=e;if(t){let e=1/0,t=-1/0,a=0;for(let n of i)n.est<e&&(e=n.est),n.lst+n.duration>t&&(t=n.lst+n.duration),a+=Math.max(0,n.lst-n.est+1);let s=t-e;if(!Number.isSafeInteger(s)||s>hr||a>gr)throw Error(`Cannot linearize cumulative() constraint "${n}" for MIP solver: time horizon [${e}, ${t}) (span ${s}, ${a} time-indexed variables) exceeds MIP limit. Tighten start bounds or use { solver: "pumpkin" }.`);let c=[];for(let e=0;e<i.length;e++){let t=i[e],r=new Map,a=[],s=t.start.clone();for(let n=t.est;n<=t.lst;n++){let t=new H({name:_(`cum_u_${e}_${n}`),type:`Binary`,lb:0,ub:1});o.push(t),r.set(n,t),a.push([t,1]),n!==0&&s.addTerm(t,-n)}if(a.length===0){N(n);return}v(new I($(a,0),`==`,1,`${n}_cum_sos_${e}`),n),P(new I(s,`==`,0,`${n}_cum_start_${e}`),n),c.push(r)}for(let a=e;a<t;a++){let e=[],t=0;for(let n=0;n<i.length;n++){let r=i[n],o=a<=r.est+r.duration-1?r.est:a-r.duration+1,s=Math.min(r.lst,a);if(o<=s){t+=r.demand;let i=c[n];for(let t=o;t<=s;t++){let n=i.get(t);n&&e.push([n,r.demand])}}}t>r.capacity&&e.length>0&&v(new I($(e,0),`<=`,r.capacity,`${n}_cum_t_${a}`),n)}return}let a=[];for(let e=0;e<i.length;e++){let t=i[e],s=[];for(let r=0;r<i.length;r++){if(r===e)continue;let a=i[r],c=new H({name:_(`cum_act_${r}_${e}`),type:`Binary`,lb:0,ub:1});o.push(c),O(c,new l(`and`,[new I(a.start.sub(t.start),`<=`,0,`${n}_act_le_${r}_${e}`),new I(t.start.sub(a.start),`<=`,a.duration-1,`${n}_act_ge_${r}_${e}`)]),n),s.push([c,a.demand])}let c=new I($(s,0),`>=`,r.capacity-t.demand+1,`${n}_overload_${e}`);a.push(new l(`and`,[c]))}M(new l(`or`,a),n);return}case`allowed`:{let e=r.vars.map(e=>b(e,n));if(r.tuples.length===0){t&&N(n);return}if(t){let t=[];for(let e=0;e<r.tuples.length;e++){let n=new H({name:_(`tbl_r_${e}`),type:`Binary`,lb:0,ub:1});o.push(n),t.push(n)}v(new I($(t.map(e=>[e,1]),0),`==`,1,`${n}_tbl_sos`),n);for(let i=0;i<e.length;i++){let a=e[i].clone();for(let e=0;e<r.tuples.length;e++){let n=r.tuples[e][i];n!==0&&a.addTerm(t[e],-n)}P(new I(a,`==`,0,`${n}_tbl_col_${i}`),n)}return}let i=e.map(e=>{let t=Array.from(e.terms.entries()).filter(([,e])=>e!==0);if(t.length!==1)return null;let[n,r]=t[0];if(Math.abs(r)!==1||!Number.isSafeInteger(n.lb)||!Number.isSafeInteger(n.ub)||n.ub-n.lb!==1)return null;let i=e.constant;if(!Number.isSafeInteger(i))return null;let a=r*n.lb+i,o=r*n.ub+i;return{expr:e,lo:Math.min(a,o),hi:Math.max(a,o)}});for(let t=0;t<r.tuples.length;t++){let a=r.tuples[t],o=!0,s=!1;for(let e=0;e<a.length;e++){let t=i[e];if(!t){o=!1;break}if(a[e]!==t.lo&&a[e]!==t.hi){s=!0;break}}if(!s){if(o){let e=new z(new Map,0);for(let t=0;t<a.length;t++){let n=i[t];a[t]===n.lo?mr(e,n.expr.sub(n.lo),1):mr(e,$([],n.hi).sub(n.expr),1)}P(new I(e,`>=`,1,`${n}_nogood_${t}`),n)}else M(new l(`or`,a.map((r,i)=>new I(e[i],`!=`,r,`${n}_ntbl_${t}_${i}`))),n,`${n}_ntbl_${t}`)}}return}}}function ne(e,t,n){let r=t.spec;switch(r.kind){case`distinct`:{let t=r.args.map(e=>b(e,n));if(t.length<=1){v(new I($([[e,1]],0),`==`,1,`${n}_distinct_triv`),n);return}let i=[];for(let e=0;e<t.length;e++)for(let r=e+1;r<t.length;r++)i.push(new I(t[e].sub(t[r]),`!=`,0,`${n}_d_${e}_${r}`));O(e,new l(`and`,i),n);return}case`disjoint`:{let t=k(r.tasks,n);if(t.length===0){v(new I($([[e,1]],0),`==`,1,`${n}_disjoint_triv`),n);return}O(e,new l(`and`,t.map(({i:e,j:t,sI:r,dI:i,sJ:a,dJ:o})=>new l(`or`,[new I(r.sub(a),`<=`,-i,`${n}_dj1_${e}_${t}`),new I(a.sub(r),`<=`,-o,`${n}_dj2_${e}_${t}`)]))),n);return}case`cumulative`:{let t=A(r.tasks,r.capacity,n);if(t.kind===`empty_domain`){N(n);return}if(t.kind===`constant`){v(new I($([[e,1]],0),`==`,+!!t.value,`${n}_cum_triv`),n);return}let{active:i}=t,a=[];for(let e=0;e<i.length;e++){let t=i[e],s=[];for(let r=0;r<i.length;r++){if(r===e)continue;let a=i[r],c=new H({name:_(`cum_eq_act_${r}_${e}`),type:`Binary`,lb:0,ub:1});o.push(c),O(c,new l(`and`,[new I(a.start.sub(t.start),`<=`,0,`${n}_eq_le_${r}_${e}`),new I(t.start.sub(a.start),`<=`,a.duration-1,`${n}_eq_ge_${r}_${e}`)]),n),s.push([c,a.demand])}a.push(new I($(s,0),`<=`,r.capacity-t.demand,`${n}_ev_${e}`))}O(e,new l(`and`,a),n);return}case`allowed`:{let t=r.vars.map(e=>b(e,n));if(r.tuples.length===0){v(new I($([[e,1]],0),`==`,0,`${n}_allowed_empty`),n);return}O(e,new l(`or`,r.tuples.map((e,r)=>new l(`and`,e.map((e,i)=>new I(t[i],`==`,e,`${n}_eq_tbl_${r}_${i}`))))),n);return}}}function re(e){return e instanceof I||e instanceof l&&e.children.some(e=>re(e))}function ie(e,t){if(e instanceof I){if((e.lhs.terms.get(t)??0)!==0)return!0;for(let n of e.lhs.nonlinearTerms){if(n.coeff===0)continue;let e=n.atom;if(e.kind===`abs`&&(e.arg.terms.get(t)??0)!==0||(e.kind===`max`||e.kind===`min`)&&e.args.some(e=>(e.terms.get(t)??0)!==0)||e.kind===`at`&&((e.index.terms.get(t)??0)!==0||e.array.some(e=>(e.terms.get(t)??0)!==0)))return!0}return!1}return e instanceof l&&e.children.some(e=>ie(e,t))}function j(e,t,n,r){if(t instanceof I){se(e,E(t,n),1,r,n);return}if(t instanceof c||t instanceof h){v(new I($([[D(t,n),1],[e,-1]],0),`>=`,0,r),n);return}if(t instanceof l){if(t.op===`and`){for(let i=0;i<t.children.length;i++)j(e,t.children[i],n,`${r}_and_${i}`);return}if(t.op===`not`){let i=t.children[0];if(i instanceof I){le(e,E(i,n),1,r,n);return}if(i instanceof l){if(i.op===`not`){j(e,i.children[0],n,r);return}if(i.op===`or`){for(let t=0;t<i.children.length;t++)j(e,new l(`not`,[i.children[t]]),n,`${r}_not_or_${t}`);return}if(i.op===`and`){j(e,new l(`or`,i.children.map(e=>new l(`not`,[e]))),n,r);return}if(i.op===`implies`){j(e,i.children[0],n,`${r}_not_imp_0`),j(e,new l(`not`,[i.children[1]]),n,`${r}_not_imp_1`);return}}let a=D(i,n);v(new I($([[e,1],[a,1]],0),`<=`,1,r),n);return}if(t.op===`or`){if(t.children.length===0){v(new I($([[e,1]],0),`<=`,0,r),n);return}if(t.children.length===1){j(e,t.children[0],n,r);return}if(!t.children.some(e=>re(e))){let i=t.children.map(e=>D(e,n));v(new I($([[e,-1],...i.map(e=>[e,1])],0),`>=`,0,r),n);return}let i=[];for(let e=0;e<t.children.length;e++){let a=t.children[e];if(a instanceof c)i.push(D(a,n));else{let t=new H({name:_(`imp_or_${e}`),type:`Binary`,lb:0,ub:1});o.push(t),i.push(t),j(t,a,n,`${r}_or_${e}`)}}v(new I($([[e,-1],...i.map(e=>[e,1])],0),`>=`,0,r),n);return}if(t.op===`implies`){let[i,a]=t.children,s;if(i instanceof I){let e=E(i,n);s=new H({name:_(`ante`),type:`Binary`,lb:0,ub:1}),o.push(s),le(s,e,0,`${r}_ante_neg`,n)}else s=D(i,n);if(a instanceof c){v(new I($([[D(a,n),1],[e,-1],[s,-1]],0),`>=`,-1,r),n);return}let l=new H({name:_(`imp_joint`),type:`Binary`,lb:0,ub:1});o.push(l),v(new I($([[l,1],[e,-1],[s,-1]],0),`>=`,-1,`${r}_joint`),n),j(l,a,n,r);return}v(new I($([[D(t,n),1],[e,-1]],0),`>=`,0,r),n);return}throw Error(`Unsupported logical element in implication consequent "${n}": ${t}`)}function M(e,t,n=t){if(e instanceof I){T(e.lhs,e.sense,e.rhs,n,t);return}if(e instanceof h){te(e,!0,t);return}if(e instanceof c){v(new I($([[D(e,t),1]],0),`>=`,1,n),t);return}if(e instanceof l){if(e.op===`not`){let r=e.children[0];if(r instanceof c){v(new I($([[D(r,t),1]],0),`<=`,0,n),t);return}if(r instanceof h){te(r,!1,t);return}if(r instanceof I){ce(E(r,t),t);return}if(r instanceof l){if(r.op===`not`){M(r.children[0],t,n);return}if(r.op===`or`){for(let e=0;e<r.children.length;e++)M(new l(`not`,[r.children[e]]),t,`${n}_not_or_${e}`);return}if(r.op===`and`){M(new l(`or`,r.children.map(e=>new l(`not`,[e]))),t,n);return}if(r.op===`implies`){M(r.children[0],t,`${n}_not_imp_0`),M(new l(`not`,[r.children[1]]),t,`${n}_not_imp_1`);return}}v(new I($([[D(r,t),1]],0),`<=`,0,n),t);return}if(e.op===`and`){for(let r=0;r<e.children.length;r++)M(e.children[r],t,`${n}_and_${r}`);return}if(e.op===`or`){if(e.children.length===0){N(t);return}if(e.children.length===1){M(e.children[0],t,n);return}if(!e.children.some(e=>re(e))){v(new I($(e.children.map(e=>D(e,t)).map(e=>[e,1]),0),`>=`,1,n),t);return}let r=[];for(let i=0;i<e.children.length;i++){let a=e.children[i];if(a instanceof c)r.push(D(a,t));else{let e=new H({name:_(`or_branch_${i}`),type:`Binary`,lb:0,ub:1});o.push(e),r.push(e),j(e,a,t,`${n}_or_${i}`)}}v(new I($(r.map(e=>[e,1]),0),`>=`,1,n),t);return}if(e.op===`xor`){if(e.children.length===0){N(t);return}if(e.children.length===1){M(e.children[0],t,n);return}let r=e.children.map(e=>D(e,t));if(r.length===2){v(new I($([[r[0],1],[r[1],1]],0),`==`,1,n),t);return}let i=r[0];for(let e=1;e<r.length-1;e++){let t=new H({name:_(`xor_fold_${e}`),type:`Binary`,lb:0,ub:1});o.push(t),ee(t,i,r[e],`${n}_xor_fold_${e}`),i=t}let a=r[r.length-1];v(new I($([[i,1],[a,1]],0),`==`,1,n),t);return}if(e.op===`implies`){let[r,i]=e.children,a=r instanceof I?vr(r):null;if(a!==null){if(i instanceof I){let e=E(i,t);if((e.lhs.terms.get(a.binVar)??0)===0){se(a.binVar,e,a.activeVal,n,t);return}}if(i instanceof c){let e=D(i,t);v(a.activeVal===1?new I($([[e,1],[a.binVar,-1]],0),`>=`,0,n):new I($([[e,1],[a.binVar,1]],0),`>=`,1,n),t);return}if(i instanceof l&&i.op===`not`){let e=i.children[0];if(e instanceof c){let r=D(e,t);v(a.activeVal===1?new I($([[r,1],[a.binVar,1]],0),`<=`,1,n):new I($([[r,1],[a.binVar,-1]],0),`<=`,0,n),t);return}if(e instanceof I){let r=E(e,t);if((r.lhs.terms.get(a.binVar)??0)===0){le(a.binVar,r,a.activeVal,n,t);return}}}if(a.activeVal===1&&!ie(i,a.binVar)){j(a.binVar,i,t,n);return}}let s;if(r instanceof I){let e=E(r,t);s=new H({name:_(`ante`),type:`Binary`,lb:0,ub:1}),o.push(s),le(s,e,0,`${n}_ante_neg`,t)}else s=D(r,t);j(s,i,t,n);return}}throw Error(`Unsupported top-level logical constraint "${t}": ${e}`)}function ae(e,t,n,r,i,a,o){let s=pr(e,t,n,r,i,n===`<=`?dr(t,r,a):fr(t,r,a),a);s.lhs.terms.size>0&&v(new I(s.lhs,n,s.rhs,a),o)}function oe(e){return new I(e.lhs,`==`,e.rhs,e.name)}function se(e,t,n,r,i){let a=E(t,i);if(a.sense===`!=`){le(e,oe(a),n,r,i);return}let{lhs:o,sense:s,rhs:c}=a;s===`==`?(ae(e,o,`<=`,c,n,`${r}_le`,i),ae(e,o,`>=`,c,n,`${r}_ge`,i)):ae(e,o,s,c,n,r,i)}function N(e){let t=new H({name:_(`unsat`),type:`Binary`,lb:0,ub:1});o.push(t),v(new I($([[t,1]],0),`>=`,2,e),e)}function P(e,t){let n=E(e,t),{lhs:r,sense:i,rhs:a}=n;if(i===`!=`){ce(oe(n),t);return}let o=r.constant??0,s=a-o;if(!Number.isFinite(o)||!Number.isFinite(a)||!Number.isFinite(s))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: constraint "${e.name}" contains non-finite constant or right-hand side.`);let c=[];for(let[n,i]of r.terms){if(!Number.isFinite(i))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: variable "${n.name}" in constraint "${e.name}" has non-finite coefficient (${i}).`);i!==0&&c.push([n,i])}if(c.length===0){(i===`<=`?0<=s:i===`>=`?0>=s:s===0)||N(t);return}v(new I($(c,0),i,s,e.name||t),t)}function ce(e,t){let n=E(e,t);if(n.sense===`!=`){P(oe(n),t);return}let r=yr(n,t);if(r.kind===`always_true`)return;if(r.kind===`always_false`){N(t);return}if(r.kind===`single`){v(new I(r.lhs,r.sense,r.rhs,n.name||t),t);return}let i=new H({name:_(`neq_dir`),type:`Binary`,lb:0,ub:1});o.push(i);let a=n.name||t;ae(i,r.lhs,`<=`,r.ltRhs,1,`${a}_lt`,t),ae(i,r.lhs,`>=`,r.gtRhs,0,`${a}_gt`,t)}function le(e,t,n,r,i){let a=E(t,i);if(a.sense===`!=`){se(e,oe(a),n,r,i);return}let s=yr(a,i);if(s.kind===`always_true`)return;if(s.kind===`always_false`){v(new I($([[e,1]],0),n===0?`>=`:`<=`,+(n===0),r),i);return}if(s.kind===`single`){ae(e,s.lhs,s.sense,s.rhs,n,r,i);return}let c=new H({name:_(`neq_lt`),type:`Binary`,lb:0,ub:1}),l=new H({name:_(`neq_gt`),type:`Binary`,lb:0,ub:1});o.push(c,l),ae(c,s.lhs,`<=`,s.ltRhs,1,`${r}_lt`,i),ae(l,s.lhs,`>=`,s.gtRhs,1,`${r}_gt`,i),v(new I($([[c,1],[l,1],[e,n===0?1:-1]],0),`>=`,+(n===0),`${r}_disj`),i)}for(let e of p)T(e.lhs,e.sense,e.rhs,e.name,e.name);let F;if(a&&a.expr.hasNonlinearTerms()){let e=i(a.sense)===`Minimize`,t=a.expr,n=new Map(t instanceof w?t.linearTerms:t.terms),r=t.constant;for(let i of t.nonlinearTerms){if(i.coeff===0)continue;let t=(e?i.coeff>0:i.coeff<0)?`upper`:`lower`,a=S(i.atom,t,`__objective`);r+=i.coeff*a.constant;for(let[e,t]of a.terms.entries()){let r=(n.get(e)??0)+i.coeff*t;r===0?n.delete(e):n.set(e,r)}}F=t instanceof w?new w(n,t.quadTerms,r,[]):new z(n,r,[])}else a&&(F=a.expr);for(let e of r){let t=e.name,n=e.expr;M(n,t)}return{variables:o,constraints:s,boolVarToBinary:u,constraintToOriginalName:d,...F===void 0?{}:{objective:F}}}function vr(e){if(e.lhs.hasNonlinearTerms()||e.lhs.terms.size!==1||(e.lhs.constant??0)!==0)return null;let[[t,n]]=Array.from(e.lhs.terms.entries());return t.type!==`Binary`&&t.type!==`Integer`||t.lb!==0||t.ub!==1||n!==1?null:e.sense===`==`&&e.rhs===1||e.sense===`>=`&&e.rhs===1||e.sense===`!=`&&e.rhs===0?{binVar:t,activeVal:1}:e.sense===`==`&&e.rhs===0||e.sense===`<=`&&e.rhs===0||e.sense===`!=`&&e.rhs===1?{binVar:t,activeVal:0}:null}function yr(e,t){let{lhs:n,sense:r,rhs:i}=e;if(n.hasNonlinearTerms())throw Error(`Cannot negate unlowered nonlinear constraint "${e.name}" in "${t}".`);let a=n.constant??0,o=i-a;if(!Number.isFinite(a)||!Number.isFinite(i)||!Number.isFinite(o))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: constraint "${e.name}" contains non-finite constant or right-hand side.`);if(r!==`<=`&&r!==`>=`&&r!==`==`)throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: unsupported comparison sense "${String(r)}" in constraint "${e.name}".`);let s=[];for(let[r,i]of n.terms){if(!Number.isFinite(i))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: variable "${r.name}" in constraint "${e.name}" has non-finite coefficient (${i}).`);if(i!==0){if(r.type!==`Integer`&&r.type!==`Binary`)throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: negating constraint "${e.name}" involves Continuous variable "${r.name}", whose strict-inequality negation creates an open half-space not representable in MIP. Use { solver: "z3" }, rewrite explicitly with a closed tolerance such as or(expr\`... >= ... + eps\`, ...), or model the proposition with m.bool().`);if(!Number.isSafeInteger(i))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: negating constraint "${e.name}" requires safe integer coefficients, but variable "${r.name}" has coefficient ${i}. Scale to integer coefficients, use { solver: "z3" }, or rewrite explicitly with or(expr\`... >= ... + eps\`, ...) / m.bool().`);s.push([r,i])}}if(s.length===0)return(r===`<=`?0<=o:r===`>=`?0>=o:o===0)?{kind:`always_false`}:{kind:`always_true`};if(!Number.isInteger(o))throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: negating constraint "${e.name}" requires an integer right-hand side and constant, received effective right-hand side ${o}. Scale or round the threshold to an integer, use { solver: "z3" }, or rewrite explicitly with or(expr\`... >= ... + eps\`, ...) / m.bool().`);if(Math.abs(o)>=2**53-1)throw Error(`Cannot linearize logical constraint "${t}" for MIP solver: effective right-hand side (${o}) of constraint "${e.name}" exceeds safe integer precision for exact +/-1 negation. Please rescale coefficients/constants or solve with { solver: "z3" }.`);let c=$(s,0);if(r===`<=`)return{kind:`single`,lhs:c,sense:`>=`,rhs:o+1};if(r===`>=`)return{kind:`single`,lhs:c,sense:`<=`,rhs:o-1};let l=o-1,u=o+1,d=0,f=0,p=!0,m=!0;for(let[e,t]of s){if(!(e.lb<=e.ub)){p=!1,m=!1;break}let n=t>0?e.lb:e.ub,r=t>0?e.ub:e.lb,i=t*n,a=t*r;d+=i,f+=a,p&&=Number.isSafeInteger(n)&&Number.isSafeInteger(i)&&Number.isSafeInteger(d),m&&=Number.isSafeInteger(r)&&Number.isSafeInteger(a)&&Number.isSafeInteger(f)}let h=!(p&&d>l),g=!(m&&f<u);return!h&&!g?{kind:`always_false`}:g?h?{kind:`disjunction`,lhs:c,ltRhs:l,gtRhs:u}:{kind:`single`,lhs:c,sense:`>=`,rhs:u}:{kind:`single`,lhs:c,sense:`<=`,rhs:l}}async function br(e){let t=e.master;if(!t)throw Error(`A master Model must be provided for solveColumnGeneration.`);let{pricing:n,maxIterations:r=100,reducedCostTolerance:i=1e-6,finalizeAsMIP:a=!0,solver:o,solverOptions:s,onIteration:c}=e,l=t.sense.toLowerCase()===`maximize`,u=n;if(!u)throw Error(`The 'pricing' callback must be provided in ColumnGenerationOptions.`);let d=[],f=null,p=0,m=t.status;for(let e=1;e<=r;e++){p=e;let n=await t.relax(o,s);if(m=n,n!==`Optimal`&&n!==`Feasible`||!t.solution)break;f=t.objectiveValue;let r=t.solution,a=r.duals||{},h=e=>typeof e==`string`?a[e]??0:e.dual??(e.name?a[e.name]??0:0),g=await u({iteration:e,duals:a,getDual:h,masterSolution:r,reducedCostTolerance:i,master:t}),_=[];g&&(Array.isArray(g)?_.push(...g):_.push(g));let v=[];for(let e of _){let t=e.reducedCost;if(typeof t!=`number`||!Number.isFinite(t)){let n=0,r=e.coefficients;if(Array.isArray(r))for(let e of r)Array.isArray(e)?n+=e[1]*h(e[0]):e&&typeof e==`object`&&(n+=e.coeff*h(e.constraint));else if(r instanceof Map)for(let[e,t]of r.entries())n+=t*h(e);else if(r&&typeof r==`object`)for(let[e,t]of Object.entries(r))n+=t*h(e);t=e.cost-n}(l?t>i:t<-i)&&v.push(e)}if(c&&c({iteration:e,relaxationObjective:f,columnsAdded:d.length+v.length,proposedColumns:v}),v.length===0)break;for(let e of v){let n=t.column({name:e.name,type:e.type||`Continuous`,lb:e.lb,ub:e.ub,cost:e.cost,coefficients:e.coefficients});d.push({variable:n,proposal:e})}}let h=f;a&&(m===`Optimal`||m===`Feasible`)&&(m=await t.solve(o,s),h=t.objectiveValue);let g={};for(let e of t.variables.values())e instanceof H&&e.value!==null&&(g[e.name]=e.value);let _={status:m,objectiveValue:h,relaxationObjectiveValue:f,iterations:p,columnsAdded:d.length,generatedColumns:d,master:t,values:g};return t.decomposition=_,_}function xr(e,t){let n=e;if(n instanceof I||typeof n==`object`&&n&&`sense`in n&&`lhs`in n&&`rhs`in n)throw Error(`Cannot use a Constraint as an objective in ${t}(). Use m.constraint(expr\`... <= ...\`) for constraints, or supply an unconstrained arithmetic expression to ${t}(), e.g. m.objective(${t}(expr\`30 * \${x}\`)).`);if(typeof n==`string`&&/(<=|>=|==|!=|=<|=>|<|>|=)/.test(n))throw Error(`Cannot use a comparison constraint as an objective in ${t}(). Use m.constraint(expr\`... <= ...\`) for constraints, or supply an unconstrained arithmetic expression to ${t}(), e.g. m.objective(${t}(expr\`30 * \${x}\`)).`);if(typeof n==`number`){if(!Number.isFinite(n))throw Error(`Invalid non-finite objective constant "${n}" passed to ${t}().`);return n}if(typeof n==`string`||n instanceof z||n instanceof w||n instanceof H||typeof n==`object`&&n&&(`terms`in n&&n.terms instanceof Map&&typeof n.constant==`number`||`quadTerms`in n&&n.quadTerms instanceof Map&&`linearTerms`in n&&n.linearTerms instanceof Map&&typeof n.constant==`number`||`id`in n&&`name`in n&&`lb`in n&&`ub`in n))return n;throw Error(`Invalid expression passed to ${t}(): expected a finite number, Var, LinExpr, QuadExpr, or arithmetic expression string.`)}function Sr(e){return{expr:xr(e,`maximize`),sense:`Maximize`}}function Cr(e){return{expr:xr(e,`minimize`),sense:`Minimize`}}var wr=new WeakSet;function Tr(e){return!!(e&&typeof e==`object`&&`constraints`in e&&`variables`in e&&typeof e.solve==`function`)}async function Er(e,t,n,r,i,a,o,s,c=1){let l=[];for(let r=0;r<t.length;r++){let a=t[r],o=a.lhs,s=a.sense,u=a.rhs-(o.constant||0),d=[],f=[],p=0;for(let[e,t]of o.terms.entries()){let r=n.variables.get(e.name);if(e.ownerModel===n||r instanceof H){f.push([e,t]);let n=i[e.name]??0;p+=t*n}else d.push([e,t])}let m=u-p,h=new z;for(let[e,t]of d)h.addTerm(e,t);let g=new I(h,s,m,`__benders_link_${c}_${r}`);e.constraint(g),l.push({origConstraint:a,subConstr:g,masterTerms:f,baseRhs:u})}let u=await e.solve(o,{...s,relax:!0});if(u!==`Optimal`&&u!==`Feasible`)throw Error(`Benders subproblem failed at iteration ${c} with status "${u}". Auto-cut generation requires an Optimal or Feasible subproblem (expected Optimal or Feasible).`);let d=e.objectiveValue;if(typeof d!=`number`||!Number.isFinite(d))throw Error(`Benders subproblem returned invalid objectiveValue (${String(d)}) at iteration ${c}.`);if(wr.has(r)&&d<r.lb-1e-6)throw Error(`Benders auto-created "__benders_theta" (lb: ${r.lb}) cannot represent negative subproblem cost (${d}) at iteration ${c}. Define an explicit theta variable with a negative lower bound and pass options.theta.`);let f=i[r.name]??0,p=1e-4;if(!(a?f<d-p:f>d+p))return null;let m=0,h=new Map,g=new Set(l.map(e=>e.subConstr.name));for(let t of e.constraints.values()){if(!(t instanceof I)||g.has(t.name))continue;let n=e.solution?.duals[t.name]??t.dual??0;if(Math.abs(n)>1e-12){let e=t.rhs-(t.lhs.constant||0);m+=n*e}}for(let t of l){let n=e.solution?.duals[t.subConstr.name]??t.subConstr.dual??0;if(Math.abs(n)>1e-12){m+=n*t.baseRhs;for(let[e,r]of t.masterTerms){let t=h.get(e)??0;h.set(e,t+n*r)}}}let _=new z;_.addTerm(r,1);for(let[e,t]of h.entries())Math.abs(t)>1e-12&&_.addTerm(e,t);let v=new I(_,a?`>=`:`<=`,m,`__benders_opt_cut_${c}`),y=(n.objectiveValue??0)-f+d;return{kind:`optimality`,constraint:v,name:v.name,subproblemObjective:y}}async function Dr(e){let t=e.master;if(!t)throw Error(`A master Model must be provided for solveBenders.`);let{subproblem:n,maxIterations:r=100,gapTolerance:i=1e-4,solver:a,solverOptions:o,onIteration:s}=e,c;if(e.theta!==void 0){if(typeof e.theta==`string`){let n=t.variables.get(e.theta);if(!(n instanceof H))throw Error(`Benders option "theta" references variable "${e.theta}", which was not found on the master model.`);c=n}else c=e.theta}if(!c){for(let e of t.variables.values())if(e instanceof H&&(e.name===`theta`||e.name===`__benders_theta`)){c=e;break}}let l=0,u=0,d=t.status,f,p,m,h={},g=null;for(let e=1;e<=r;e++){u=e;let r=await t.solve(a,o);if(d=r,r!==`Optimal`&&r!==`Feasible`)break;let _=t.objectiveValue,v=t.sense.toLowerCase()===`minimize`;v?f=_===null?f:_:p=_===null?p:_;let y={};for(let e of t.variables.values())e instanceof H&&e.value!==null&&(y[e.name]=e.value);let b=await n({iteration:e,masterValues:y,getMasterValue:e=>typeof e==`string`?y[e]??0:e.value??(e.name?y[e.name]??0:0),masterObjective:_,lowerBound:f,upperBound:p,master:t}),x=[];if(b){if(Tr(b)){let n=b,r=n.linkingConstraints;if(!c){if(!v)throw Error(`Benders auto-cut generation requires an explicit options.theta variable for Maximize master models.`);c=t.continuous(`__benders_theta`,{lb:0}),t.objective(Cr(t.objective().add(c))),wr.add(c)}let i=await Er(n,r,t,c,y,v,a,o,e);i&&x.push(i)}else Array.isArray(b)?x.push(...b):x.push(b)}for(let e of x)if(typeof e.subproblemObjective==`number`&&Number.isFinite(e.subproblemObjective)){if(v){let t=e.subproblemObjective;(p===void 0||t<p)&&(p=t,g=t,h={...y})}else{let t=e.subproblemObjective;(f===void 0||t>f)&&(f=t,g=t,h={...y})}}if(f!==void 0&&p!==void 0){let e=Math.abs(p)+1e-10;m=Math.abs(p-f)/e}if(s&&s({iteration:e,masterObjective:_,lowerBound:f,upperBound:p,cutsAdded:l+x.length,proposedCuts:x}),x.length===0){g=_,h={...y};break}if(m!==void 0&&m<=i)break;for(let e of x)t.constraint(e.constraint,e.name),l++}let _=d===`Optimal`||d===`Feasible`,v=Object.keys(h).length>0?h:_?(()=>{let e={};for(let n of t.variables.values())n instanceof H&&n.value!==null&&(e[n.name]=n.value);return e})():{},y=g===null?_?t.objectiveValue:null:g,b={status:d,objectiveValue:y,lowerBound:f,upperBound:p,gap:m,iterations:u,cutsAdded:l,master:t,values:v};return t.decomposition=b,b}function Or(e,t){return e.hasNonlinearTerms()?!0:kr(t)}function kr(e){for(let t of e)if(t.sense===`!=`||t.lhs.hasNonlinearTerms())return!0;return!1}function Ar(e){return e.type===`Integer`||e.type===`Binary`}function jr(e){switch(e.kind){case`abs`:return Nr(e.arg);case`max`:case`min`:return e.args.length>0&&e.args.every(Nr);case`at`:return e.array.length>0&&e.array.every(Nr)}}function Mr(e){for(let t of e)if(t.coeff!==0&&(!Number.isInteger(t.coeff)||!jr(t.atom)))return!1;return!0}function Nr(e){if(!Number.isInteger(e.constant))return!1;if(e instanceof w){for(let[t,n]of e.linearTerms)if(n!==0&&(!Ar(t)||!Number.isInteger(n)))return!1;for(let t of e.quadTerms.values())if(t.coeff!==0&&(!Ar(t.var1)||!Ar(t.var2)||!Number.isInteger(t.coeff)))return!1;return Mr(e.nonlinearTerms)}for(let[t,n]of e.terms)if(n!==0&&(!Ar(t)||!Number.isInteger(n)))return!1;return Mr(e.nonlinearTerms)}function Pr(e){let t=Object.freeze({get size(){return e.size},get(t){return e.get(t)},has(t){return e.has(t)},forEach(n,r){e.forEach((e,i)=>{n.call(r,e,i,t)})},entries(){return e.entries()},keys(){return e.keys()},values(){return e.values()},[Symbol.iterator](){return e[Symbol.iterator]()}});return t}function Fr(e){return Array.isArray(e)||typeof e==`object`&&!!e&&!(e instanceof String)&&typeof e[Symbol.iterator]==`function`}function Ir(e){return typeof e==`object`&&!!e&&!Array.isArray(e)&&!(e instanceof String)&&typeof e[Symbol.iterator]!=`function`}function Lr(e){return e instanceof H||typeof e==`object`&&!!e&&!(e instanceof s)&&!(e instanceof I)&&`id`in e&&`name`in e&&`lb`in e&&`ub`in e&&!(`terms`in e)&&!(`quadTerms`in e)&&!(`sense`in e)}function Rr(e,t){if(!Number.isInteger(e)||e<0)throw Error(`Invalid count (${e}) for ${t} variable creation: count must be a non-negative integer.`)}var zr=class{name;_sense;_objectiveExpr;_variables=[];_constraints=[];_boolVars=[];_logicalConstraints=[];unsatCore=void 0;_conflicts=void 0;_values=new Map;varMapByName=new Map;varPrefixCounters=new Map;boolVarMapByName=new Map;boolVarPrefixCounters=new Map;constrMapByName=new Map;constrPrefixCounters=new Map;logicalConstrMapByName=new Map;logicalConstrCounter=0;allVarsMap=new Map;allConstrsMap=new Map;variables;constraints;values;status=`NotSolved`;terminationStatus=`NotSolved`;hasPrimalSolution=!1;objectiveValue=null;objectiveBound=void 0;relativeGap=void 0;absoluteGap=void 0;runTime=0;solution=null;solver=null;decomposition;_linkingConstraints;hasSolutionState=!1;modelRevision=0;activeOperationId=0;batchDepth=0;batchMutated=!1;batchUndoActions=[];constructor(e={},t){let n;n=typeof e==`string`?{...t,name:e}:e,this.name=n.name||`OptimizationModel`,this._sense=i(n.sense),this._objectiveExpr=new z,this.variables=Pr(this.allVarsMap),this.constraints=Pr(this.allConstrsMap),this.values=Pr(this._values),O(this,()=>this.recordModelMutation()),n.solver&&(this.solver=tt(n.solver))}get sense(){return this._sense}set sense(e){let t=i(e);this._sense!==t&&(this._sense=t,this.recordModelMutation())}get conflicts(){return this._conflicts??this.unsatCore}set conflicts(e){this._conflicts=e}clearSolutionFields(){if(this.hasSolutionState||this.status!==`NotSolved`||this.terminationStatus!==`NotSolved`||this.hasPrimalSolution||this.solution!==null||this.unsatCore!==void 0){this.hasSolutionState=!1,this.status=`NotSolved`,this.terminationStatus=`NotSolved`,this.hasPrimalSolution=!1,this.objectiveValue=null,this.objectiveBound=void 0,this.relativeGap=void 0,this.absoluteGap=void 0,this.solution=null,this.runTime=0,this.unsatCore=void 0,this._conflicts=void 0,this._values.clear();for(let e of this._variables)e.value=null,e.reducedCost=null;for(let e of this._boolVars)e.value=null;for(let e of this._constraints)e.dual=null,e.slack=null}}recordModelMutation(){if(this.batchDepth>0){this.batchMutated=!0;return}this.modelRevision++,this.clearSolutionFields()}runTransactionalBatch(e){if(this.batchDepth>0)return e();let t=this._variables.length,n=this._boolVars.length,r=this._constraints.length,i=this._logicalConstraints.length,a=new Map(this.varPrefixCounters),o=new Map(this.boolVarPrefixCounters),s=new Map(this.constrPrefixCounters),c=this.logicalConstrCounter;this.batchDepth=1,this.batchMutated=!1,this.batchUndoActions=[];try{let t=e();this.batchDepth=0;let n=this.batchMutated;return this.batchMutated=!1,this.batchUndoActions=[],n&&this.recordModelMutation(),t}catch(e){this.batchDepth=0,this.batchMutated=!1;for(let e=t;e<this._variables.length;e++){let t=this._variables[e];this.varMapByName.delete(t.name),this.allVarsMap.delete(t.name),t.ownerModel=null,re(t,this)}this._variables.length=t;for(let e=n;e<this._boolVars.length;e++){let t=this._boolVars[e];this.boolVarMapByName.delete(t.name),this.allVarsMap.delete(t.name)}this._boolVars.length=n;for(let e=r;e<this._constraints.length;e++){let t=this._constraints[e];this.constrMapByName.delete(t.name),this.allConstrsMap.delete(t.name)}this._constraints.length=r;for(let e=i;e<this._logicalConstraints.length;e++){let t=this._logicalConstraints[e];this.logicalConstrMapByName.delete(t.name),this.allConstrsMap.delete(t.name)}this._logicalConstraints.length=i;for(let e=this.batchUndoActions.length-1;e>=0;e--)this.batchUndoActions[e]();throw this.batchUndoActions=[],this.varPrefixCounters=a,this.boolVarPrefixCounters=o,this.constrPrefixCounters=s,this.logicalConstrCounter=c,e}}createDomainVars(e,t,n,r){let i=e.toLowerCase(),a=typeof t==`number`,o=typeof n==`number`,s=Fr(t),c=Fr(n);if(o||c){if(a&&Rr(t,i),o&&Rr(n,i),!a&&!s||r!==void 0&&!Ir(r))throw Error(`Invalid arguments provided for ${i} variable creation`);let c=a?Array.from({length:t},(e,t)=>t):Array.from(t),l=o?Array.from({length:n},(e,t)=>t):n===t?c:Array.from(n),u=r||{},d=u.prefix||u.name||`x`;return this.runTransactionalBatch(()=>{let t=a?[]:{};for(let n of c){let r=o?[]:{};for(let t of l)r[t]=this.addVar({...u,type:e,name:`${d}_${n}_${t}`});t[n]=r}return t})}if(typeof t==`string`||t===void 0){if(n!==void 0&&!Ir(n))throw Error(`Invalid arguments provided for ${i} variable creation`);let r=n||{},a=typeof t==`string`?t:r.name;return this.addVar({...r,type:e,name:a})}if(Ir(t)){if(n!==void 0)throw Error(`Invalid arguments provided for ${i} variable creation`);let r=t;return this.addVar({...r,type:e})}if(n!==void 0&&!Ir(n))throw Error(`Invalid arguments provided for ${i} variable creation`);let l=n||{},u=l.prefix||l.name;if(typeof t==`number`)return Rr(t,i),this.runTransactionalBatch(()=>{let n=[],r=u||`x`;for(let i=0;i<t;i++)n.push(this.addVar({...l,type:e,name:void 0,prefix:r}));return n});if(Fr(t))return this.runTransactionalBatch(()=>{let n={};for(let r of t){let t=u?`${u}_${r}`:`${r}`;n[r]=this.addVar({...l,type:e,name:t})}return n});throw Error(`Invalid arguments provided for ${i} variable creation`)}binary(e,t,n){return this.createDomainVars(`Binary`,e,t,n)}integer(e,t,n){return this.createDomainVars(`Integer`,e,t,n)}continuous(e,t,n){return this.createDomainVars(`Continuous`,e,t,n)}column(e){let t=e.type||`Continuous`,n=this.addVar({name:e.name,type:t,lb:e.lb,ub:e.ub});if(typeof e.cost==`number`&&e.cost!==0&&(this._objectiveExpr=this._objectiveExpr.add(n.mul(e.cost)),this.recordModelMutation()),e.coefficients){if(Array.isArray(e.coefficients)){for(let t of e.coefficients)if(Array.isArray(t)){let[e,r]=t,i=typeof e==`string`?this.constrMapByName.get(e):e;if(!i)throw Error(`Constraint '${String(e)}' not found in model when adding column`);i.addTerm(n,r)}else if(typeof t==`object`&&t){let e=typeof t.constraint==`string`?this.constrMapByName.get(t.constraint):t.constraint;if(!e)throw Error(`Constraint '${String(t.constraint)}' not found in model when adding column`);e.addTerm(n,t.coeff)}}else if(e.coefficients instanceof Map)for(let[t,r]of e.coefficients.entries()){let e=typeof t==`string`?this.constrMapByName.get(t):t;if(!e)throw Error(`Constraint '${String(t)}' not found in model when adding column`);e.addTerm(n,r)}else if(typeof e.coefficients==`object`)for(let[t,r]of Object.entries(e.coefficients)){let e=this.constrMapByName.get(t);if(!e)throw Error(`Constraint '${t}' not found in model when adding column`);e.addTerm(n,r)}}return n}bool(e,t,n){let r=typeof e==`number`,i=typeof t==`number`,a=Fr(e),o=Fr(t);if(i||o){if(r&&Rr(e,`boolean`),i&&Rr(t,`boolean`),!r&&!a||n!==void 0&&!Ir(n))throw Error(`Invalid arguments provided for boolean variable creation`);let o=r?Array.from({length:e},(e,t)=>t):Array.from(e),s=i?Array.from({length:t},(e,t)=>t):t===e?o:Array.from(t),c=n||{},l=c.prefix||c.name||`p`;return this.runTransactionalBatch(()=>{let e=r?[]:{};for(let t of o){let n=i?[]:{};for(let e of s)n[e]=this.createBoolVar(`${l}_${t}_${e}`);e[t]=n}return e})}if(typeof e==`string`||e===void 0){if(t!==void 0&&!Ir(t))throw Error(`Invalid arguments provided for boolean variable creation`);let n=t||{},r=typeof e==`string`?e:n.name;return this.createBoolVar(r,n.prefix)}if(Ir(e)){if(t!==void 0)throw Error(`Invalid arguments provided for boolean variable creation`);let n=e;return this.createBoolVar(n.name,n.prefix)}if(t!==void 0&&!Ir(t))throw Error(`Invalid arguments provided for boolean variable creation`);let s=t||{},c=s.prefix||s.name;if(typeof e==`number`)return Rr(e,`boolean`),this.runTransactionalBatch(()=>{let t=[],n=c||`p`;for(let r=0;r<e;r++)t.push(this.createBoolVar(void 0,n));return t});if(Fr(e))return this.runTransactionalBatch(()=>{let t={};for(let n of e){let e=c?`${c}_${n}`:`${n}`;t[n]=this.createBoolVar(e)}return t});throw Error(`Invalid arguments provided for boolean variable creation`)}hasVarName(e){return this.varMapByName.has(e)||this.boolVarMapByName.has(e)}getNextVarName(e){let t=this.varPrefixCounters.get(e)??0,n=`${e}_${t}`;for(;this.hasVarName(n);)t++,n=`${e}_${t}`;return this.varPrefixCounters.set(e,t+1),n}getNextBoolVarName(e){let t=this.boolVarPrefixCounters.get(e)??0,n=`${e}_${t}`;for(;this.hasVarName(n)||this.hasConstraintName(n);)t++,n=`${e}_${t}`;return this.boolVarPrefixCounters.set(e,t+1),n}hasConstraintName(e){return this.constrMapByName.has(e)||this.logicalConstrMapByName.has(e)}hasBoolVarName(e){return this.boolVarMapByName.has(e)}getNextConstrName(e=`c`){let t=this.constrPrefixCounters.get(e)??1,n=`${e}_${t}`;for(;this.hasConstraintName(n)||this.hasBoolVarName(n);)t++,n=`${e}_${t}`;return this.constrPrefixCounters.set(e,t+1),n}getNextLogicalConstrName(){let e=this.logicalConstrCounter+1,t=`lc_${e}`;for(;this.hasConstraintName(t)||this.hasBoolVarName(t);)e++,t=`lc_${e}`;return this.logicalConstrCounter=e,t}createBoolVar(e,t){let n=typeof e==`string`?e.trim():void 0,r=typeof t==`string`?t.trim():``,i=r.length>0?r:`p`,a=n&&n.length>0?n:this.getNextBoolVarName(i);if(this.hasVarName(a))throw Error(`Variable with name '${a}' already exists in model`);if(this.hasConstraintName(a))throw Error(`Boolean variable name '${a}' conflicts with an existing constraint in model`);let o=new c(a);return this._boolVars.push(o),this.boolVarMapByName.set(o.name,o),this.allVarsMap.set(o.name,o),this.recordModelMutation(),o}addVar(e){let t=e||{},n=typeof t.name==`string`?t.name.trim():void 0,r=n&&n.length>0?n:void 0,i=typeof t.prefix==`string`?t.prefix.trim():``,a=i.length>0?i:`x`,o=this.varPrefixCounters.get(a),s=r??this.getNextVarName(a);try{if(this.hasVarName(s))throw Error(`Variable with name '${s}' already exists in model`);let e=new H({...t,name:s,prefix:a});return e.hasExplicitName=r!==void 0,M(e),te(e,this),e.ownerModel=this,this._variables.push(e),this.varMapByName.set(e.name,e),this.allVarsMap.set(e.name,e),this.recordModelMutation(),e}catch(e){throw r===void 0&&(o===void 0?this.varPrefixCounters.delete(a):this.varPrefixCounters.set(a,o)),e}}objective(e){if(arguments.length===0)return this._objectiveExpr.clone();let t=e;if(t instanceof I||typeof t==`object`&&t&&`sense`in t&&`lhs`in t&&`rhs`in t||typeof t==`string`&&/(<=|>=|==|!=|=<|=>|<|>|=)/.test(t))throw Error("Cannot use a Constraint as an objective. Did you mean to use m.constraint(expr`... <= ...`)? To set an objective, wrap an unconstrained expression with maximize(...) or minimize(...), e.g. m.objective(maximize(expr`30 * ${x}`)).");if(typeof t!=`object`||!t||!(`expr`in t)||!(`sense`in t))throw Error("m.objective(...) expects an ObjectiveSpec created with maximize(...) or minimize(...), e.g. m.objective(maximize(expr`30 * ${x}`)).");return this.applyObjective(t.expr,t.sense),this}applyObjective(e,t){if(e instanceof I||typeof e==`object`&&e&&`sense`in e&&`lhs`in e&&`rhs`in e||typeof e==`string`&&/(<=|>=|==|!=|=<|=>|<|>|=)/.test(e))throw Error(typeof e==`string`?"Cannot use a comparison constraint as an objective. Did you mean to use m.constraint(expr`... <= ...`)? To set an objective, wrap an unconstrained expression with maximize(...) or minimize(...), e.g. m.objective(maximize(expr`30 * ${x}`)).":"Cannot use a Constraint as an objective. Did you mean to use m.constraint(expr`... <= ...`)? To set an objective, wrap an unconstrained expression with maximize(...) or minimize(...), e.g. m.objective(maximize(expr`30 * ${x}`)).");let n=t===void 0?this.sense:i(t),r;if(typeof e==`string`)r=Re(e,e=>this.varMapByName.get(e));else if(typeof e==`number`)r=new z(new Map,e);else if(e instanceof w)r=e.clone();else if(e instanceof z)r=e.clone();else if(typeof e==`object`&&e&&`quadTerms`in e&&e.quadTerms instanceof Map&&`linearTerms`in e&&e.linearTerms instanceof Map&&typeof e.constant==`number`){let t=e;r=new w(t.linearTerms,t.quadTerms,t.constant,t.nonlinearTerms)}else if(typeof e==`object`&&e&&`terms`in e&&e.terms instanceof Map&&typeof e.constant==`number`){let t=e;r=new z(t.terms,t.constant,t.nonlinearTerms)}else if(e instanceof H||typeof e==`object`&&e&&`id`in e&&`name`in e&&`lb`in e&&`ub`in e)r=new z(new Map([[e,1]]),0);else throw Error(`Invalid objective expression: expected a finite number, Var, LinExpr, QuadExpr, or arithmetic expression string.`);P(r,this.name,e=>this.varMapByName.get(e.name)===e),this._sense=n,this._objectiveExpr=r,this.recordModelMutation()}constraint(e,t){if(Array.isArray(e))return this.runTransactionalBatch(()=>{let t=[];for(let n of e)t.push(this.constraint(n));return t});if(e instanceof w||typeof e==`object`&&e&&`quadTerms`in e)throw Error(`Constraint must contain a comparison operator (<=, >=, ==): cannot add a quadratic expression as a constraint.`);if(e instanceof z||typeof e==`object`&&e&&`terms`in e)throw Error("Constraint must contain a comparison operator (<=, >=, ==): cannot add a linear expression without a comparison operator. Use expr`... <= ...` or .le(), .ge(), .eq().");if(Lr(e))throw Error(`Cannot add numeric variable "${e.name}" directly as a constraint without a comparison operator (<=, >=, ==). Numeric variables require a comparison such as expr\`\${x} <= 10\` or x.le(10), whereas propositional BoolVar variables must be created with m.bool().`);return this.addConstraint(e,t)}addConstraint(e,t){if(e instanceof w||typeof e==`object`&&e&&`quadTerms`in e)throw Error(`Constraint must contain a comparison operator (<=, >=, ==): cannot add a quadratic expression as a constraint.`);if(e instanceof z||typeof e==`object`&&e&&`terms`in e)throw Error("Constraint must contain a comparison operator (<=, >=, ==): cannot add a linear expression without a comparison operator. Use expr`... <= ...` or .le(), .ge(), .eq().");if(Lr(e))throw Error(`Cannot add numeric variable "${e.name}" directly as a constraint without a comparison operator (<=, >=, ==). Numeric variables require a comparison such as expr\`\${x} <= 10\` or x.le(10), whereas propositional BoolVar variables must be created with m.bool().`);if(e instanceof s){let n=typeof t==`string`&&t.trim().length>0?t.trim():void 0;if(n!==void 0){if(this.hasConstraintName(n))throw Error(`Constraint with name '${n}' already exists in model`);if(this.hasBoolVarName(n))throw Error(`Constraint name '${n}' conflicts with an existing Boolean variable in model`)}let r=this.logicalConstrCounter,i=n??this.getNextLogicalConstrName();try{le(e,i,this.name,e=>this.varMapByName.get(e.name)===e,e=>this.boolVarMapByName.get(e.name)===e,this)}catch(e){throw n===void 0&&(this.logicalConstrCounter=r),e}A(e,this,this.batchDepth>0?this.batchUndoActions:void 0);let a=Object.freeze({kind:`logical`,name:i,expr:e,dual:null,slack:null});return this._logicalConstraints.push(a),this.logicalConstrMapByName.set(i,a),this.allConstrsMap.set(i,a),this.recordModelMutation(),e}let n=typeof e==`string`?Be(e,e=>this.varMapByName.get(e),t):e;if(typeof n!=`object`||!n||!(`sense`in n)||!(`lhs`in n)||!(`rhs`in n))throw Error("Invalid constraint passed to m.constraint(...): expected a linear Constraint (e.g. expr`${x} <= 10` or x.le(10)), a propositional BoolVar/BoolExpr (created with m.bool()), or an array of constraints.");n.ownerModel&&n.ownerModel!==this&&(ce(n,this.name,e=>this.varMapByName.get(e.name)===e,n.name),ne(n,this));let r=typeof t==`string`&&t.trim().length>0?t.trim():n.hasExplicitName?n.name.trim():void 0;if(r!==void 0){if(this.hasConstraintName(r))throw Error(`Constraint with name '${r}' already exists in model`);if(this.hasBoolVarName(r))throw Error(`Constraint name '${r}' conflicts with an existing Boolean variable in model`)}let i=this.constrPrefixCounters.get(`c`),a=r??this.getNextConstrName(`c`),o;try{ce(n,this.name,e=>this.varMapByName.get(e.name)===e,a),o=ne(n,this)}catch(e){throw r===void 0&&(i===void 0?this.constrPrefixCounters.delete(`c`):this.constrPrefixCounters.set(`c`,i)),e}let c=n.name,l=n.hasExplicitName,u=n.ownerModel,d=o;return this.batchUndoActions.push(()=>{n.ownerModel=u,n._assignModelName(c,l),ie(n,this,d)}),this.batchDepth===0&&(this.batchUndoActions=[]),n._assignModelName(a,!0),n.ownerModel=this,this._constraints.push(n),this.constrMapByName.set(n.name,n),this.allConstrsMap.set(n.name,n),this.recordModelMutation(),n}indicator(e,t,n={}){if(e instanceof s)throw Error("Invalid binary variable passed to indicator(): received a propositional BoolVar/BoolExpr, but m.indicator() requires a 0-1 numeric binary Var created with m.binary(). For general boolean logic with m.bool(), use m.constraint(implies(flag, expr`${x} <= 10`)) with the Z3 solver.");if(!(e instanceof H))throw Error(`Invalid binary variable passed to indicator(). Expected a 0-1 binary Var instance created with m.binary() (or use implies(flag, ...) with m.bool() and the Z3 solver for general boolean logic).`);if(!(e.type===`Binary`||e.type===`Integer`&&e.lb===0&&e.ub===1))throw Error(`Invalid variable "${e.name}" passed to indicator(): variable has type "${e.type}" with bounds [${e.lb}, ${e.ub}]. Indicator activation variable must be a Binary variable created with m.binary() (or Integer variable with bounds [0, 1]).`);if(t instanceof w||typeof t==`object`&&t&&`quadTerms`in t)throw Error("Quadratic expressions or constraints are not supported in indicator constraints (only linear Constraints with <=, >=, or == such as expr`${x} <= 10` are allowed).");if(typeof t!=`object`||!t||!(`sense`in t)||!(`lhs`in t)||!(`rhs`in t))throw Error("Invalid constraint expression passed to indicator(). Expression must include a comparison operator (<=, >=, ==), e.g. m.indicator(b, expr`${x} <= 10`). For general boolean logic (such as BoolVar or implies/and/or/not), use m.constraint(implies(flag, ...)) with the Z3 solver.");let r=t;if(r.sense===`!=`)throw Error(`Constraint "${r.name}" uses discrete "!=", which is not supported in m.indicator(). Use m.constraint(implies(${e.name}.eq(1), ...)) instead.`);if(r.lhs.hasNonlinearTerms())throw Error(`Constraint "${r.name}" contains nonlinear terms (max/min/abs/at), which are not supported in m.indicator().`);let i=n.activeValue===void 0?1:n.activeValue;if(i!==0&&i!==1)throw Error(`Invalid activeValue: ${i}. Indicator activeValue must be 0 or 1.`);if(this.varMapByName.get(e.name)!==e)throw Error(`Variable "${e.name}" passed to indicator() does not belong to model "${this.name}". All variables must belong to the model by object identity.`);let a=typeof n.name==`string`&&n.name.trim().length>0?n.name.trim():void 0,o=this.constrPrefixCounters.get(`c`),{lhs:c,sense:l,rhs:u}=r,d,f,p;if(a!==void 0)d=a,f=l===`==`?`${d}_le`:d,p=l===`==`?`${d}_ge`:d;else if(r.hasExplicitName)d=`ind_${e.name}_${r.name.trim()}`,f=l===`==`?`${d}_le`:d,p=l===`==`?`${d}_ge`:d;else do{let t=this.getNextConstrName(`c`);d=`ind_${e.name}_${t}`,f=l===`==`?`${d}_le`:d,p=l===`==`?`${d}_ge`:d}while((l===`<=`||l===`==`)&&(this.hasConstraintName(f)||this.hasBoolVarName(f))||(l===`>=`||l===`==`)&&(this.hasConstraintName(p)||this.hasBoolVarName(p)));let m=[];try{if((l===`<=`||l===`==`)&&(this.hasConstraintName(f)||this.hasBoolVarName(f)))throw Error(this.hasBoolVarName(f)?`Constraint name '${f}' conflicts with an existing Boolean variable in model`:`Constraint with name '${f}' already exists in model`);if((l===`>=`||l===`==`)&&(this.hasConstraintName(p)||this.hasBoolVarName(p)))throw Error(this.hasBoolVarName(p)?`Constraint name '${p}' conflicts with an existing Boolean variable in model`:`Constraint with name '${p}' already exists in model`);n.M!==void 0&&lr(n.M,d);let t=e=>this.varMapByName.get(e.name)===e;for(let[e]of c.terms)if(!t(e))throw Error(`Variable "${e.name}" in constraint "${d}" does not belong to model "${this.name}". All variables must belong to the model by object identity.`);if(l===`<=`||l===`==`){let t=n.M===void 0?dr(c,u,f):n.M,r=pr(e,c,`<=`,u,i,t,f),a=new I(r.lhs,`<=`,r.rhs,f);n.M===void 0&&a._setIndicatorOrigin({binVar:e,activeValue:i,targetLhs:c.clone(),targetSense:`<=`,targetRhs:u,derivedM:t}),m.push([a,f])}if(l===`>=`||l===`==`){let t=n.M===void 0?fr(c,u,p):n.M,r=pr(e,c,`>=`,u,i,t,p),a=new I(r.lhs,`>=`,r.rhs,p);n.M===void 0&&a._setIndicatorOrigin({binVar:e,activeValue:i,targetLhs:c.clone(),targetSense:`>=`,targetRhs:u,derivedM:t}),m.push([a,p])}for(let[e,n]of m)ce(e,this.name,t,n)}catch(e){throw o===void 0?this.constrPrefixCounters.delete(`c`):this.constrPrefixCounters.set(`c`,o),e}return this.runTransactionalBatch(()=>m.map(([e,t])=>this.addConstraint(e,t)))}toLpString(){if(this.validateIntegrityInternal(),Or(this._objectiveExpr,this._constraints)){let e=_r(this._variables,[],this._constraints,[],{expr:this._objectiveExpr,sense:this.sense}),{lpString:t}=Je({name:this.name,sense:this.sense,objective:e.objective??this._objectiveExpr,constraints:e.constraints,variables:e.variables});return t}let{lpString:e}=Je({name:this.name,sense:this.sense,objective:this._objectiveExpr.clone(),constraints:this._constraints,variables:this._variables});return e}validateIntegrityInternal(){F({model:this,name:this.name,variables:this._variables,boolVars:this._boolVars,constraints:this._constraints,logicalConstraints:this._logicalConstraints,objectiveExpr:this._objectiveExpr,getVarByName:e=>this.varMapByName.get(e),getBoolVarByName:e=>this.boolVarMapByName.get(e),getConstraintByName:e=>this.constrMapByName.get(e),getLogicalConstraintByName:e=>this.logicalConstrMapByName.get(e)})}ensureExecutionValid(e,t,n){if(this.modelRevision!==e)throw this.activeOperationId===t&&this.clearSolutionFields(),Error(`Model "${this.name}" was modified while ${n}() was in progress; stale solver result was discarded.`);if(this.activeOperationId!==t)throw Error(`Stale ${n}() result discarded because a newer solve or check operation was started on model "${this.name}".`)}wrapSolveOptions(e,t,n,r,i){let a=t.onProgress;return a?{...t,onProgress:o=>{if(this.activeOperationId===r&&this.modelRevision===n){if(i&&typeof o.objectiveValue==`number`&&Number.isFinite(o.objectiveValue)){let n=this.normalizeObjectiveValue(o.objectiveValue,e,t);if(!Object.is(n,o.objectiveValue)){let e=typeof o.objectiveBound==`number`&&Number.isFinite(o.objectiveBound),t=e?Math.abs(n-o.objectiveBound)+0:void 0,r={...o,objectiveValue:n};e&&`absoluteGap`in o&&o.absoluteGap!==void 0&&(r.absoluteGap=t),e&&`relativeGap`in o&&o.relativeGap!==void 0&&(t===0?r.relativeGap=0:Math.abs(n)>0&&t!==void 0?r.relativeGap=t/Math.abs(n):delete r.relativeGap),a(r);return}}a(o)}}}:t}hasPrimalFromResult(e){if(typeof e.hasPrimalSolution==`boolean`)return e.hasPrimalSolution;let t=e.status,n=e.terminationStatus??t,r=e.values||{},i=e.boolValues||{};return t!==`Infeasible`&&t!==`Unsat`&&t!==`Unbounded`&&t!==`Error`&&t!==`NotSolved`&&n!==`Infeasible`&&n!==`Unsat`&&n!==`Unbounded`&&n!==`InfeasibleOrUnbounded`&&n!==`Error`&&n!==`NotSolved`&&(t===`Optimal`||t===`Feasible`||t===`Sat`||n===`Optimal`||n===`Feasible`||n===`Sat`||typeof e.objectiveValue==`number`&&Number.isFinite(e.objectiveValue)||Object.values(r).some(e=>typeof e==`number`&&Number.isFinite(e)||typeof e==`boolean`)||Object.values(i).some(e=>typeof e==`boolean`))}normalizePrimalValue(e,t,n,r){return(r.relax??n.options?.relax)!==!0&&Ar(e)&&Math.abs(t-Math.round(t))<=1e-5?Math.round(t)+0:t}normalizeObjectiveValue(e,t,n){if((n.relax??t.options?.relax)!==!0&&Nr(this._objectiveExpr)){let t=Math.round(e);if(Number.isSafeInteger(t)&&Math.abs(e-t)<=1e-5)return t+0}return e}resolveSolverAndOptions(e,t){if(e&&typeof e==`object`&&`solve`in e&&typeof e.solve==`function`){let{solver:n,...r}=t||{};return{activeSolver:e,activeOptions:r}}if(typeof e==`function`){let{solver:n,...r}=t||{};return{activeSolver:new e(r),activeOptions:r}}if(typeof e==`string`){let{solver:n,...r}=t||{};return{activeSolver:tt(e,r),activeOptions:r}}let{solver:n,...r}=e||{};return n?{activeSolver:tt(n,r),activeOptions:r}:{activeSolver:this.solver||tt(),activeOptions:r}}async relax(e,t){let n=typeof e==`object`&&!!e&&!(`solve`in e),r=n?{...e,relax:!0}:{...t||{},relax:!0},i=n?void 0:e;return i?this.solve(i,r):this.solve(r)}async solve(e,t){let n=++this.activeOperationId,r=this.modelRevision;this.clearSolutionFields(),this.validateIntegrityInternal();let{activeSolver:i,activeOptions:a}=this.resolveSolverAndOptions(e,t);if(this._objectiveExpr instanceof w&&this._objectiveExpr.quadTerms.size>0&&i.capabilities?.supportsQP===!1)throw Error(`Solver "${i.name}" does not support quadratic objectives (QP). Please use a QP-capable solver such as HiGHS or Clarabel.`);let o,s=null;if(i.capabilities?.supportsLogicalConstraints!==!0&&i.capabilities?.supportsSMT!==!0&&(this._logicalConstraints.length>0||this._boolVars.length>0||Or(this._objectiveExpr,this._constraints))?(s=_r(this._variables,this._boolVars,this._constraints,this._logicalConstraints,{expr:this._objectiveExpr,sense:this.sense}),o={name:this.name,sense:this.sense,objective:s.objective??this._objectiveExpr,constraints:s.constraints,variables:s.variables,logicalConstraints:[],boolVars:[]}):o={name:this.name,sense:this.sense,objective:this._objectiveExpr,constraints:this._constraints,variables:this._variables,logicalConstraints:this._logicalConstraints,boolVars:this._boolVars},this._variables.some(e=>e.initialValue!==void 0)&&i.capabilities?.supportsWarmStart!==!0)throw Error(`Solver "${i.name}" does not support primal initial values (initialValue). Please use a solver with warm-start support such as HiGHS or Pumpkin.`);let c=this.wrapSolveOptions(i,a,r,n,!0),l;try{l=await i.solve(o,c)}catch(e){throw this.activeOperationId===n&&this.clearSolutionFields(),e}this.ensureExecutionValid(r,n,`solve`),this.runTime=l.runTime??0,this.status=l.status,this.terminationStatus=l.terminationStatus??l.status;let u=this.hasPrimalFromResult(l);this.hasPrimalSolution=u;let d=(a.relax??i.options?.relax)!==!0&&Nr(this._objectiveExpr),f=u&&typeof l.objectiveValue==`number`&&Number.isFinite(l.objectiveValue)?l.objectiveValue:null;this.objectiveValue=f===null?null:this.normalizeObjectiveValue(f,i,a);let p=typeof l.objectiveBound==`number`&&Number.isFinite(l.objectiveBound)?l.objectiveBound:void 0;this.objectiveBound=d&&this.status===`Optimal`&&this.objectiveValue!==null&&p!==void 0&&Math.abs(p-this.objectiveValue)<=1e-5?this.objectiveValue:p;let m=typeof l.relativeGap==`number`&&Number.isFinite(l.relativeGap)?l.relativeGap:void 0,h=f!==null&&this.objectiveValue!==null&&!Object.is(f,this.objectiveValue),g=p!==void 0&&this.objectiveBound!==void 0&&!Object.is(p,this.objectiveBound);this.absoluteGap=(h||g)&&this.objectiveValue!==null&&this.objectiveBound!==void 0?Math.abs(this.objectiveValue-this.objectiveBound)+0:typeof l.absoluteGap==`number`&&Number.isFinite(l.absoluteGap)?l.absoluteGap:this.objectiveValue!==null&&this.objectiveBound!==void 0?Math.abs(this.objectiveValue-this.objectiveBound):void 0,this.relativeGap=(h||g)&&m!==void 0&&this.objectiveValue!==null&&this.absoluteGap!==void 0?this.absoluteGap===0?0:Math.abs(this.objectiveValue)>0?this.absoluteGap/Math.abs(this.objectiveValue):void 0:m;let _=(e,t,n)=>{Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})},v={},y={},b={},x={};if(this._values.clear(),u&&l.values){for(let[e,t]of Object.entries(l.values))if(typeof t==`number`&&Number.isFinite(t)){let n=this.varMapByName.get(e),r=this.boolVarMapByName.get(e);if(n){let e=this.normalizePrimalValue(n,t,i,a);n.value=e,_(v,n.name,e),this._values.set(n.name,e)}r&&(r.value=!!t,this._values.set(r.name,t)),!n&&!r&&!s&&this._values.set(e,t)}else if(typeof t==`boolean`){let n=t,r=this.boolVarMapByName.get(e);r?(r.value=n,_(v,r.name,+!!n),this._values.set(r.name,n)):this._values.set(e,n)}if(s)for(let e of this._boolVars){let t=s.boolVarToBinary.get(e);if(t&&l.values){let n=l.values[t.name];if(typeof n==`number`&&Number.isFinite(n)){let t=Math.round(n)===1;e.value=t,_(v,e.name,+!!t),this._values.set(e.name,t)}}}}if(u&&l.boolValues)for(let[e,t]of Object.entries(l.boolValues)){if(typeof t!=`boolean`)continue;let n=this.boolVarMapByName.get(e);n?(n.value=t,this._values.has(n.name)||this._values.set(n.name,t)):this._values.has(e)||this._values.set(e,t)}if(u&&l.reducedCosts)for(let[e,t]of Object.entries(l.reducedCosts)){if(typeof t!=`number`||!Number.isFinite(t))continue;let n=this.varMapByName.get(e);n&&(n.reducedCost=t,_(b,n.name,t))}if(l.duals)for(let[e,t]of Object.entries(l.duals)){if(typeof t!=`number`||!Number.isFinite(t))continue;let n=this.constrMapByName.get(e);n&&(n.dual=t,_(y,n.name,t))}if(l.slacks)for(let[e,t]of Object.entries(l.slacks)){if(typeof t!=`number`||!Number.isFinite(t))continue;let n=this.constrMapByName.get(e);n&&(n.slack=t,_(x,n.name,t))}return this.solution={status:this.status,terminationStatus:this.terminationStatus,hasPrimalSolution:this.hasPrimalSolution,objectiveValue:this.objectiveValue,...this.objectiveBound===void 0?{}:{objectiveBound:this.objectiveBound},...this.relativeGap===void 0?{}:{relativeGap:this.relativeGap},...this.absoluteGap===void 0?{}:{absoluteGap:this.absoluteGap},values:v,duals:y,reducedCosts:b,slacks:x,runTime:this.runTime,raw:l.raw},this.hasSolutionState=!0,this.status}async check(e,t){let n=++this.activeOperationId,r=this.modelRevision;this.clearSolutionFields(),this.validateIntegrityInternal();let{activeSolver:i,activeOptions:a}=this.resolveSolverAndOptions(e,t);if(this._variables.some(e=>e.initialValue!==void 0)&&i.capabilities?.supportsWarmStart!==!0)throw Error(`Solver "${i.name}" does not support primal initial values (initialValue). Please use a solver with warm-start support such as HiGHS or Pumpkin.`);let o=this.wrapSolveOptions(i,a,r,n,!1),s=(e,t,n)=>{Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0,configurable:!0})},c={name:this.name,variables:this._variables,boolVars:this._boolVars,constraints:this._constraints,logicalConstraints:this._logicalConstraints};if(typeof i.check==`function`){let e;try{e=await i.check(c,o)}catch(e){throw this.activeOperationId===n&&this.clearSolutionFields(),e}this.ensureExecutionValid(r,n,`check`),this.status=e.status,this.terminationStatus=a.signal?.aborted?`Interrupted`:e.status,this.hasPrimalSolution=e.status===`Sat`,this.runTime=e.runTime??0,this.unsatCore=e.unsatCore===void 0?void 0:Object.freeze([...e.unsatCore]),this.conflicts=e.conflicts===void 0?this.unsatCore:Object.freeze([...e.conflicts]);let t={};if(e.values&&e.status===`Sat`){for(let[n,r]of Object.entries(e.values))if(typeof r==`number`){if(!Number.isFinite(r))continue;let e=this.varMapByName.get(n),o=this.boolVarMapByName.get(n);if(e){let n=this.normalizePrimalValue(e,r,i,a);e.value=n,this._values.set(e.name,n),s(t,e.name,n)}o&&(o.value=!!r,this._values.set(o.name,o.value),s(t,o.name,o.value)),!e&&!o&&(this._values.set(n,r),s(t,n,r))}else if(typeof r==`boolean`){let e=this.boolVarMapByName.get(n);e?(e.value=r,this._values.set(e.name,r),s(t,e.name,r)):(this._values.set(n,r),s(t,n,r))}}return this.hasSolutionState=!0,{status:e.status,values:t,unsatCore:this.unsatCore,conflicts:this.conflicts,runTime:this.runTime}}let l=this._logicalConstraints.length>0||this._boolVars.length>0||kr(this._constraints)?_r(this._variables,this._boolVars,this._constraints,this._logicalConstraints):{variables:[...this._variables],constraints:[...this._constraints],boolVarToBinary:new Map,constraintToOriginalName:new Map(this._constraints.map(e=>[e,e.name]))},u=[],d=[],f=[],p=new Map,m=0;for(let e of l.constraints){let t=l.constraintToOriginalName.get(e)??e.name,{lhs:n,sense:r,rhs:i}=e;if(r===`<=`){let r=new H({name:`__slack_${++m}`,type:`Continuous`,lb:0,ub:1/0});d.push(r),f.push([r,1]),p.set(r,t);let a=n.clone().add(new z(new Map([[r,-1]]),0));u.push(new I(a,`<=`,i,`${e.name}_slack`))}else if(r===`>=`){let r=new H({name:`__slack_${++m}`,type:`Continuous`,lb:0,ub:1/0});d.push(r),f.push([r,1]),p.set(r,t);let a=n.clone().add(new z(new Map([[r,1]]),0));u.push(new I(a,`>=`,i,`${e.name}_slack`))}else{let r=new H({name:`__slack_${++m}_p`,type:`Continuous`,lb:0,ub:1/0}),a=new H({name:`__slack_${++m}_n`,type:`Continuous`,lb:0,ub:1/0});d.push(r,a),f.push([r,1],[a,1]),p.set(r,t),p.set(a,t);let o=n.clone().add(new z(new Map([[r,-1],[a,1]]),0));u.push(new I(o,`==`,i,`${e.name}_slack`))}}let h={name:`${this.name}_elastic_check`,sense:`Minimize`,objective:new z(new Map(f),0),constraints:u,variables:[...l.variables,...d]},g;try{g=await i.solve(h,o)}catch(e){throw this.activeOperationId===n&&this.clearSolutionFields(),e}this.ensureExecutionValid(r,n,`check`),this.runTime=g.runTime??0;let _=g.status,v=g.terminationStatus??_,y=this.hasPrimalFromResult(g),b=typeof g.objectiveValue==`number`&&Number.isFinite(g.objectiveValue)?g.objectiveValue:1/0,x=(_===`Optimal`||_===`Feasible`||y)&&b<=1e-5,S=typeof g.objectiveBound==`number`&&Number.isFinite(g.objectiveBound)&&g.objectiveBound>1e-5,C=!x&&(_===`Infeasible`||_===`Optimal`&&b>1e-5||S),w=x?`Sat`:C?`Unsat`:`Unknown`;this.status=w,this.terminationStatus=a.signal?.aborted||v===`Interrupted`?`Interrupted`:v===`Optimal`||v===`Feasible`||v===`Infeasible`?w:v,this.hasPrimalSolution=x,this.objectiveValue=null,this.objectiveBound=void 0,this.relativeGap=void 0,this.absoluteGap=void 0,this.solution=null,this._values.clear();let T={};if(x&&g.values){for(let e of this._variables){let t=g.values[e.name];if(typeof t==`number`&&Number.isFinite(t)){let n=this.normalizePrimalValue(e,t,i,a);e.value=n,this._values.set(e.name,n),s(T,e.name,n)}}for(let e of this._boolVars){let t=l.boolVarToBinary.get(e),n=t?g.values[t.name]:g.values[e.name];if(typeof n==`number`&&Number.isFinite(n)){let t=Math.round(n)===1;e.value=t,this._values.set(e.name,t),s(T,e.name,t)}}}let E=new Set;if(C&&g.values)for(let[e,t]of p.entries()){let n=g.values[e.name];typeof n==`number`&&n>1e-5&&E.add(t)}return this.conflicts=C?Object.freeze(Array.from(E)):void 0,this.unsatCore=void 0,this.hasSolutionState=!0,{status:w,values:T,conflicts:this.conflicts,unsatCore:this.unsatCore,runTime:this.runTime}}verify(e={}){return cr(this,e)}link(e){if(e instanceof w||typeof e==`object`&&e&&`quadTerms`in e)throw Error(`Linking constraint cannot be a quadratic expression.`);if(!(e instanceof I)&&(typeof e!=`object`||!e||!(`sense`in e)||!(`lhs`in e)||!(`rhs`in e)))throw Error("Linking constraint must contain a comparison operator (<=, >=, ==). Use expr`... <= ...` or .le(), .ge(), .eq().");this._linkingConstraints||=[];let t=e;return this._linkingConstraints.push(t),t}get linkingConstraints(){return this._linkingConstraints??[]}async solveBenders(e){let t=await Dr({master:this,...e});return this.decomposition=t,t}async solveColumnGeneration(e){let t=await br({master:this,...e});return this.decomposition=t,t}};return e.BoolExpr=s,e.BoolOp=l,e.BoolVar=c,e.Constraint=I,e.GlobalConstraint=h,e.LinExpr=z,e.MockSolver=rt,e.Model=zr,e.QuadExpr=w,e.Var=H,e.abs=_e,e.allowed=S,e.and=u,e.at=V,e.buildIndicatorLinearization=pr,e.buildLpSymbolMaps=qe,e.cumulative=x,e.deriveBigMForGe=fr,e.deriveBigMForLe=dr,e.disjoint=b,e.distinct=v,e.dot=ge,e.expr=We,e.generateLpString=Je,e.getSolver=tt,e.implies=p,e.isLpExportResult=Ge,e.linearizeModelForMip=_r,e.listAvailableSolvers=nt,e.max=be,e.maximize=Sr,e.min=xe,e.minimize=Cr,e.normalizeSense=i,e.not=f,e.or=d,e.parseConstraint=Be,e.parseExpr=Re,e.registerSolver=$e,e.sanitizeIdentifier=Ke,e.setDefaultSolver=et,e.solveBenders=Dr,e.solveColumnGeneration=br,e.sum=B,e.validateUserBigM=lr,e.xor=m,e})({});
|