d3-dag
Version:
Layout algorithms for visualizing directed acylic graphs.
19 lines (16 loc) • 112 kB
JavaScript
// d3-dag Version 1.1.0. Copyright 2023 Erik Brinkman.
var d3 = Object.assign(d3 || {}, (() => {
"use strict";var d3=(()=>{var ri=Object.create;var je=Object.defineProperty,oi=Object.defineProperties,ii=Object.getOwnPropertyDescriptor,ai=Object.getOwnPropertyDescriptors,si=Object.getOwnPropertyNames,lt=Object.getOwnPropertySymbols,ui=Object.getPrototypeOf,Xt=Object.prototype.hasOwnProperty,Un=Object.prototype.propertyIsEnumerable;var Yt=(e,t)=>{if(t=Symbol[e])return t;throw Error("Symbol."+e+" is not defined")};var An=(e,t,n)=>t in e?je(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,T=(e,t)=>{for(var n in t||(t={}))Xt.call(t,n)&&An(e,n,t[n]);if(lt)for(var n of lt(t))Un.call(t,n)&&An(e,n,t[n]);return e},R=(e,t)=>oi(e,ai(t));var V=(e,t)=>{var n={};for(var r in e)Xt.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&<)for(var r of lt(e))t.indexOf(r)<0&&Un.call(e,r)&&(n[r]=e[r]);return n};var H=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),di=(e,t)=>{for(var n in t)je(e,n,{get:t[n],enumerable:!0})},En=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of si(t))!Xt.call(e,i)&&i!==n&&je(e,i,{get:()=>t[i],enumerable:!(r=ii(t,i))||r.enumerable});return e};var jn=(e,t,n)=>(n=e!=null?ri(ui(e)):{},En(t||!e||!e.__esModule?je(n,"default",{value:e,enumerable:!0}):n,e)),li=e=>En(je({},"__esModule",{value:!0}),e);var en=(e,t,n)=>{if(!t.has(e))throw TypeError("Cannot "+n)};var C=(e,t,n)=>(en(e,t,"read from private field"),n?n.call(e):t.get(e)),F=(e,t,n)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,n)},P=(e,t,n,r)=>(en(e,t,"write to private field"),r?r.call(e,n):t.set(e,n),n);var se=(e,t,n)=>(en(e,t,"access private method"),n);var fi=function(e,t){this[0]=e,this[1]=t};var Y=e=>{var t=e[Yt("asyncIterator")],n=!1,r,i={};return t==null?(t=e[Yt("iterator")](),r=o=>i[o]=a=>t[o](a)):(t=t.call(e),r=o=>i[o]=a=>{if(n){if(n=!1,o==="throw")throw a;return a}return n=!0,{done:!1,value:new fi(new Promise(s=>{var u=t[o](a);if(!(u instanceof Object))throw TypeError("Object expected");s(u)}),1)}}),i[Yt("iterator")]=()=>i,r("next"),"throw"in t?r("throw"):i.throw=o=>{throw o},"return"in t&&r("return"),i};var bn=H((au,mr)=>{"use strict";function hr(e,t,n,r){this.feasible=n,this.evaluation=t,this.bounded=r,this._tableau=e}mr.exports=hr;hr.prototype.generateSolutionSet=function(){for(var e={},t=this._tableau,n=t.varIndexByRow,r=t.variablesPerIndex,i=t.matrix,o=t.rhsColumn,a=t.height-1,s=Math.round(1/t.precision),u=1;u<=a;u+=1){var d=n[u],l=r[d];if(!(l===void 0||l.isSlack===!0)){var f=i[u][o];e[l.id]=Math.round((Number.EPSILON+f)*s)/s}}return e}});var Nr=H((su,yr)=>{"use strict";var gr=bn();function wt(e,t,n,r,i){gr.call(this,e,t,n,r),this.iter=i}yr.exports=wt;wt.prototype=Object.create(gr.prototype);wt.constructor=wt});var pe=H((uu,br)=>{"use strict";var Gi=bn(),Mi=Nr();function ge(e){this.model=null,this.matrix=null,this.width=0,this.height=0,this.costRowIndex=0,this.rhsColumn=0,this.variablesPerIndex=[],this.unrestrictedVars=null,this.feasible=!0,this.evaluation=0,this.simplexIters=0,this.varIndexByRow=null,this.varIndexByCol=null,this.rowByVarIndex=null,this.colByVarIndex=null,this.precision=e||1e-8,this.optionalObjectives=[],this.objectivesByPriority={},this.savedState=null,this.availableIndexes=[],this.lastElementIndex=0,this.variables=null,this.nVars=0,this.bounded=!0,this.unboundedVarIndex=null,this.branchAndCutIterations=0}br.exports=ge;ge.prototype.solve=function(){return this.model.getNumberOfIntegerVariables()>0?this.branchAndCut():this.simplex(),this.updateVariableValues(),this.getSolution()};function xn(e,t){this.priority=e,this.reducedCosts=new Array(t);for(var n=0;n<t;n+=1)this.reducedCosts[n]=0}xn.prototype.copy=function(){var e=new xn(this.priority,this.reducedCosts.length);return e.reducedCosts=this.reducedCosts.slice(),e};ge.prototype.setOptionalObjective=function(e,t,n){var r=this.objectivesByPriority[e];if(r===void 0){var i=Math.max(this.width,t+1);r=new xn(e,i),this.objectivesByPriority[e]=r,this.optionalObjectives.push(r),this.optionalObjectives.sort(function(o,a){return o.priority-a.priority})}r.reducedCosts[t]=n};ge.prototype.initialize=function(e,t,n,r){this.variables=n,this.unrestrictedVars=r,this.width=e,this.height=t;for(var i=new Array(e),o=0;o<e;o++)i[o]=0;this.matrix=new Array(t);for(var a=0;a<t;a++)this.matrix[a]=i.slice();this.varIndexByRow=new Array(this.height),this.varIndexByCol=new Array(this.width),this.varIndexByRow[0]=-1,this.varIndexByCol[0]=-1,this.nVars=e+t-2,this.rowByVarIndex=new Array(this.nVars),this.colByVarIndex=new Array(this.nVars),this.lastElementIndex=this.nVars};ge.prototype._resetMatrix=function(){var e=this.model.variables,t=this.model.constraints,n=e.length,r=t.length,i,o,a=this.matrix[0],s=this.model.isMinimization===!0?-1:1;for(i=0;i<n;i+=1){var u=e[i],d=u.priority,l=s*u.cost;d===0?a[i+1]=l:this.setOptionalObjective(d,i+1,l),o=e[i].index,this.rowByVarIndex[o]=-1,this.colByVarIndex[o]=i+1,this.varIndexByCol[i+1]=o}for(var f=1,p=0;p<r;p+=1){var m=t[p],g=m.index;this.rowByVarIndex[g]=f,this.colByVarIndex[g]=-1,this.varIndexByRow[f]=g;var c,b,y,h=m.terms,N=h.length,v=this.matrix[f++];if(m.isUpperBound){for(c=0;c<N;c+=1)b=h[c],y=this.colByVarIndex[b.variable.index],v[y]=b.coefficient;v[0]=m.rhs}else{for(c=0;c<N;c+=1)b=h[c],y=this.colByVarIndex[b.variable.index],v[y]=-b.coefficient;v[0]=-m.rhs}}};ge.prototype.setModel=function(e){this.model=e;var t=e.nVariables+1,n=e.nConstraints+1;return this.initialize(t,n,e.variables,e.unrestrictedVariables),this._resetMatrix(),this};ge.prototype.getNewElementIndex=function(){if(this.availableIndexes.length>0)return this.availableIndexes.pop();var e=this.lastElementIndex;return this.lastElementIndex+=1,e};ge.prototype.density=function(){for(var e=0,t=this.matrix,n=0;n<this.height;n++)for(var r=t[n],i=0;i<this.width;i++)r[i]!==0&&(e+=1);return e/(this.height*this.width)};ge.prototype.setEvaluation=function(){var e=Math.round(1/this.precision),t=this.matrix[this.costRowIndex][this.rhsColumn],n=Math.round((Number.EPSILON+t)*e)/e;this.evaluation=n,this.simplexIters===0&&(this.bestPossibleEval=n)};ge.prototype.getSolution=function(){var e=this.model.isMinimization===!0?this.evaluation:-this.evaluation;return this.model.getNumberOfIntegerVariables()>0?new Mi(this,e,this.feasible,this.bounded,this.branchAndCutIterations):new Gi(this,e,this.feasible,this.bounded)}});var xr=H(()=>{"use strict";var rt=pe();rt.prototype.simplex=function(){return this.bounded=!0,this.phase1(),this.feasible===!0&&this.phase2(),this};rt.prototype.phase1=function(){for(var e=this.model.checkForCycles,t=[],n=this.matrix,r=this.rhsColumn,i=this.width-1,o=this.height-1,a,s=0;;){for(var u=0,d=-this.precision,l=1;l<=o;l++){a=this.unrestrictedVars[this.varIndexByRow[l]]===!0;var f=n[l][r];f<d&&(d=f,u=l)}if(u===0)return this.feasible=!0,s;for(var p=0,m=-1/0,g=n[0],c=n[u],b=1;b<=i;b++){var y=c[b];if(a=this.unrestrictedVars[this.varIndexByCol[b]]===!0,a||y<-this.precision){var h=-g[b]/y;m<h&&(m=h,p=b)}}if(p===0)return this.feasible=!1,s;if(e){t.push([this.varIndexByRow[u],this.varIndexByCol[p]]);var N=this.checkForCycles(t);if(N.length>0)return this.model.messages.push("Cycle in phase 1"),this.model.messages.push("Start :"+N[0]),this.model.messages.push("Length :"+N[1]),this.feasible=!1,s}this.pivot(u,p),s+=1}};rt.prototype.phase2=function(){for(var e=this.model.checkForCycles,t=[],n=this.matrix,r=this.rhsColumn,i=this.width-1,o=this.height-1,a=this.precision,s=this.optionalObjectives.length,u=null,d=0,l,f;;){var p=n[this.costRowIndex];s>0&&(u=[]);for(var m=0,g=a,c=!1,b=1;b<=i;b++){if(l=p[b],f=this.unrestrictedVars[this.varIndexByCol[b]]===!0,s>0&&-a<l&&l<a){u.push(b);continue}if(f&&l<0){-l>g&&(g=-l,m=b,c=!0);continue}l>g&&(g=l,m=b,c=!1)}if(s>0)for(var y=0;m===0&&u.length>0&&y<s;){var h=[],N=this.optionalObjectives[y].reducedCosts;g=a;for(var v=0;v<u.length;v++){if(b=u[v],l=N[b],f=this.unrestrictedVars[this.varIndexByCol[b]]===!0,-a<l&&l<a){h.push(b);continue}if(f&&l<0){-l>g&&(g=-l,m=b,c=!0);continue}l>g&&(g=l,m=b,c=!1)}u=h,y+=1}if(m===0)return this.setEvaluation(),this.simplexIters+=1,d;for(var L=0,k=1/0,w=this.varIndexByRow,S=1;S<=o;S++){var O=n[S],I=O[r],z=O[m];if(!(-a<z&&z<a)){if(z>0&&a>I&&I>-a){k=0,L=S;break}var M=c?-I/z:I/z;M>a&&k>M&&(k=M,L=S)}}if(k===1/0)return this.evaluation=-1/0,this.bounded=!1,this.unboundedVarIndex=this.varIndexByCol[m],d;if(e){t.push([this.varIndexByRow[L],this.varIndexByCol[m]]);var $=this.checkForCycles(t);if($.length>0)return this.model.messages.push("Cycle in phase 2"),this.model.messages.push("Start :"+$[0]),this.model.messages.push("Length :"+$[1]),this.feasible=!1,d}this.pivot(L,m,!0),d+=1}};var kn=[];rt.prototype.pivot=function(e,t){var n=this.matrix,r=n[e][t],i=this.height-1,o=this.width-1,a=this.varIndexByRow[e],s=this.varIndexByCol[t];this.varIndexByRow[e]=s,this.varIndexByCol[t]=a,this.rowByVarIndex[s]=e,this.rowByVarIndex[a]=-1,this.colByVarIndex[s]=-1,this.colByVarIndex[a]=t;for(var u=n[e],d=0,l=0;l<=o;l++)u[l]>=-1e-16&&u[l]<=1e-16?u[l]=0:(u[l]/=r,kn[d]=l,d+=1);u[t]=1/r;for(var f,p,m,g=this.precision,c=0;c<=i;c++)if(c!==e&&!(n[c][t]>=-1e-16&&n[c][t]<=1e-16)){var b=n[c];if(f=b[t],f>=-1e-16&&f<=1e-16)f!==0&&(b[t]=0);else{for(p=0;p<d;p++)l=kn[p],m=u[l],m>=-1e-16&&m<=1e-16?m!==0&&(u[l]=0):b[l]=b[l]-f*m;b[t]=-f/r}}var y=this.optionalObjectives.length;if(y>0)for(var h=0;h<y;h+=1){var N=this.optionalObjectives[h].reducedCosts;if(f=N[t],f!==0){for(p=0;p<d;p++)l=kn[p],m=u[l],m!==0&&(N[l]=N[l]-f*m);N[t]=-f/r}}};rt.prototype.checkForCycles=function(e){for(var t=0;t<e.length-1;t++)for(var n=t+1;n<e.length;n++){var r=e[t],i=e[n];if(r[0]===i[0]&&r[1]===i[1]){if(n-t>e.length-n)break;for(var o=!0,a=1;a<n-t;a++){var s=e[t+a],u=e[n+a];if(s[0]!==u[0]||s[1]!==u[1]){o=!1;break}}if(o)return[t,n-t]}}return[]}});var Dt=H((fu,wr)=>{"use strict";function vn(e,t,n,r){this.id=e,this.cost=t,this.index=n,this.value=0,this.priority=r}function kr(e,t,n,r){vn.call(this,e,t,n,r)}kr.prototype.isInteger=!0;function Ln(e,t){vn.call(this,e,0,t,0)}Ln.prototype.isSlack=!0;function vr(e,t){this.variable=e,this.coefficient=t}function Lr(e,t,n){return n===0||n==="required"?null:(t=t||1,n=n||1,e.isMinimization===!1&&(t=-t),e.addVariable(t,"r"+e.relaxationIndex++,!1,!1,n))}function Te(e,t,n,r){this.slack=new Ln("s"+n,n),this.index=n,this.model=r,this.rhs=e,this.isUpperBound=t,this.terms=[],this.termsByVarIndex={},this.relaxation=null}Te.prototype.addTerm=function(e,t){var n=t.index,r=this.termsByVarIndex[n];if(r===void 0)r=new vr(t,e),this.termsByVarIndex[n]=r,this.terms.push(r),this.isUpperBound===!0&&(e=-e),this.model.updateConstraintCoefficient(this,t,e);else{var i=r.coefficient+e;this.setVariableCoefficient(i,t)}return this};Te.prototype.removeTerm=function(e){return this};Te.prototype.setRightHandSide=function(e){if(e!==this.rhs){var t=e-this.rhs;this.isUpperBound===!0&&(t=-t),this.rhs=e,this.model.updateRightHandSide(this,t)}return this};Te.prototype.setVariableCoefficient=function(e,t){var n=t.index;if(n===-1){console.warn("[Constraint.setVariableCoefficient] Trying to change coefficient of inexistant variable.");return}var r=this.termsByVarIndex[n];if(r===void 0)this.addTerm(e,t);else if(e!==r.coefficient){var i=e-r.coefficient;this.isUpperBound===!0&&(i=-i),r.coefficient=e,this.model.updateConstraintCoefficient(this,t,i)}return this};Te.prototype.relax=function(e,t){this.relaxation=Lr(this.model,e,t),this._relax(this.relaxation)};Te.prototype._relax=function(e){e!==null&&(this.isUpperBound?this.setVariableCoefficient(-1,e):this.setVariableCoefficient(1,e))};function Ue(e,t){this.upperBound=e,this.lowerBound=t,this.model=e.model,this.rhs=e.rhs,this.relaxation=null}Ue.prototype.isEquality=!0;Ue.prototype.addTerm=function(e,t){return this.upperBound.addTerm(e,t),this.lowerBound.addTerm(e,t),this};Ue.prototype.removeTerm=function(e){return this.upperBound.removeTerm(e),this.lowerBound.removeTerm(e),this};Ue.prototype.setRightHandSide=function(e){this.upperBound.setRightHandSide(e),this.lowerBound.setRightHandSide(e),this.rhs=e};Ue.prototype.relax=function(e,t){this.relaxation=Lr(this.model,e,t),this.upperBound.relaxation=this.relaxation,this.upperBound._relax(this.relaxation),this.lowerBound.relaxation=this.relaxation,this.lowerBound._relax(this.relaxation)};wr.exports={Constraint:Te,Variable:vn,IntegerVariable:kr,SlackVariable:Ln,Equality:Ue,Term:vr}});var Dr=H(()=>{"use strict";var St=pe(),wn=Dt().SlackVariable;St.prototype.addCutConstraints=function(e){for(var t=e.length,n=this.height,r=n+t,i=n;i<r;i+=1)this.matrix[i]===void 0&&(this.matrix[i]=this.matrix[i-1].slice());this.height=r,this.nVars=this.width+this.height-2;for(var o,a=this.width-1,s=0;s<t;s+=1){var u=e[s],d=n+s,l=u.type==="min"?-1:1,f=u.varIndex,p=this.rowByVarIndex[f],m=this.matrix[d];if(p===-1){for(m[this.rhsColumn]=l*u.value,o=1;o<=a;o+=1)m[o]=0;m[this.colByVarIndex[f]]=l}else{var g=this.matrix[p],c=g[this.rhsColumn];for(m[this.rhsColumn]=l*(u.value-c),o=1;o<=a;o+=1)m[o]=-l*g[o]}var b=this.getNewElementIndex();this.varIndexByRow[d]=b,this.rowByVarIndex[b]=d,this.colByVarIndex[b]=-1,this.variablesPerIndex[b]=new wn("s"+b,b),this.nVars+=1}};St.prototype._addLowerBoundMIRCut=function(e){if(e===this.costRowIndex)return!1;var t=this.model,n=this.matrix,r=this.variablesPerIndex[this.varIndexByRow[e]];if(!r.isInteger)return!1;var i=n[e][this.rhsColumn],o=i-Math.floor(i);if(o<this.precision||1-this.precision<o)return!1;var a=this.height;n[a]=n[a-1].slice(),this.height+=1,this.nVars+=1;var s=this.getNewElementIndex();this.varIndexByRow[a]=s,this.rowByVarIndex[s]=a,this.colByVarIndex[s]=-1,this.variablesPerIndex[s]=new wn("s"+s,s),n[a][this.rhsColumn]=Math.floor(i);for(var u=1;u<this.varIndexByCol.length;u+=1){var d=this.variablesPerIndex[this.varIndexByCol[u]];if(!d.isInteger)n[a][u]=Math.min(0,n[e][u]/(1-o));else{var l=n[e][u],f=Math.floor(l)+Math.max(0,l-Math.floor(l)-o)/(1-o);n[a][u]=f}}for(var p=0;p<this.width;p+=1)n[a][p]-=n[e][p];return!0};St.prototype._addUpperBoundMIRCut=function(e){if(e===this.costRowIndex)return!1;var t=this.model,n=this.matrix,r=this.variablesPerIndex[this.varIndexByRow[e]];if(!r.isInteger)return!1;var i=n[e][this.rhsColumn],o=i-Math.floor(i);if(o<this.precision||1-this.precision<o)return!1;var a=this.height;n[a]=n[a-1].slice(),this.height+=1,this.nVars+=1;var s=this.getNewElementIndex();this.varIndexByRow[a]=s,this.rowByVarIndex[s]=a,this.colByVarIndex[s]=-1,this.variablesPerIndex[s]=new wn("s"+s,s),n[a][this.rhsColumn]=-o;for(var u=1;u<this.varIndexByCol.length;u+=1){var d=this.variablesPerIndex[this.varIndexByCol[u]],l=n[e][u],f=l-Math.floor(l);d.isInteger?f<=o?n[a][u]=-f:n[a][u]=-(1-f)*o/f:l>=0?n[a][u]=-l:n[a][u]=l*o/(1-o)}return!0};St.prototype.applyMIRCuts=function(){}});var Sr=H(()=>{"use strict";var ye=pe();ye.prototype._putInBase=function(e){var t=this.rowByVarIndex[e];if(t===-1){for(var n=this.colByVarIndex[e],r=1;r<this.height;r+=1){var i=this.matrix[r][n];if(i<-this.precision||this.precision<i){t=r;break}}this.pivot(t,n)}return t};ye.prototype._takeOutOfBase=function(e){var t=this.colByVarIndex[e];if(t===-1){for(var n=this.rowByVarIndex[e],r=this.matrix[n],i=1;i<this.height;i+=1){var o=r[i];if(o<-this.precision||this.precision<o){t=i;break}}this.pivot(n,t)}return t};ye.prototype.updateVariableValues=function(){for(var e=this.variables.length,t=Math.round(1/this.precision),n=0;n<e;n+=1){var r=this.variables[n],i=r.index,o=this.rowByVarIndex[i];if(o===-1)r.value=0;else{var a=this.matrix[o][this.rhsColumn];r.value=Math.round((a+Number.EPSILON)*t)/t}}};ye.prototype.updateRightHandSide=function(e,t){var n=this.height-1,r=this.rowByVarIndex[e.index];if(r===-1){for(var i=this.colByVarIndex[e.index],o=0;o<=n;o+=1){var a=this.matrix[o];a[this.rhsColumn]-=t*a[i]}var s=this.optionalObjectives.length;if(s>0)for(var u=0;u<s;u+=1){var d=this.optionalObjectives[u].reducedCosts;d[this.rhsColumn]-=t*d[i]}}else this.matrix[r][this.rhsColumn]-=t};ye.prototype.updateConstraintCoefficient=function(e,t,n){if(e.index===t.index)throw new Error("[Tableau.updateConstraintCoefficient] constraint index should not be equal to variable index !");var r=this._putInBase(e.index),i=this.colByVarIndex[t.index];if(i===-1)for(var o=this.rowByVarIndex[t.index],a=0;a<this.width;a+=1)this.matrix[r][a]+=n*this.matrix[o][a];else this.matrix[r][i]-=n};ye.prototype.updateCost=function(e,t){var n=e.index,r=this.width-1,i=this.colByVarIndex[n];if(i===-1){var o=this.matrix[this.rowByVarIndex[n]],a;if(e.priority===0){var s=this.matrix[0];for(a=0;a<=r;a+=1)s[a]+=t*o[a]}else{var u=this.objectivesByPriority[e.priority].reducedCosts;for(a=0;a<=r;a+=1)u[a]+=t*o[a]}}else this.matrix[0][i]-=t};ye.prototype.addConstraint=function(e){var t=e.isUpperBound?1:-1,n=this.height,r=this.matrix[n];r===void 0&&(r=this.matrix[0].slice(),this.matrix[n]=r);for(var i=this.width-1,o=0;o<=i;o+=1)r[o]=0;r[this.rhsColumn]=t*e.rhs;for(var a=e.terms,s=a.length,u=0;u<s;u+=1){var d=a[u],l=d.coefficient,f=d.variable.index,p=this.rowByVarIndex[f];if(p===-1)r[this.colByVarIndex[f]]+=t*l;else{var m=this.matrix[p],g=m[this.rhsColumn];for(o=0;o<=i;o+=1)r[o]-=t*l*m[o]}}var c=e.index;this.varIndexByRow[n]=c,this.rowByVarIndex[c]=n,this.colByVarIndex[c]=-1,this.height+=1};ye.prototype.removeConstraint=function(e){var t=e.index,n=this.height-1,r=this._putInBase(t),i=this.matrix[n];this.matrix[n]=this.matrix[r],this.matrix[r]=i,this.varIndexByRow[r]=this.varIndexByRow[n],this.varIndexByRow[n]=-1,this.rowByVarIndex[t]=-1,this.availableIndexes[this.availableIndexes.length]=t,e.slack.index=-1,this.height-=1};ye.prototype.addVariable=function(e){var t=this.height-1,n=this.width,r=this.model.isMinimization===!0?-e.cost:e.cost,i=e.priority,o=this.optionalObjectives.length;if(o>0)for(var a=0;a<o;a+=1)this.optionalObjectives[a].reducedCosts[n]=0;i===0?this.matrix[0][n]=r:(this.setOptionalObjective(i,n,r),this.matrix[0][n]=0);for(var s=1;s<=t;s+=1)this.matrix[s][n]=0;var u=e.index;this.varIndexByCol[n]=u,this.rowByVarIndex[u]=-1,this.colByVarIndex[u]=n,this.width+=1};ye.prototype.removeVariable=function(e){var t=e.index,n=this._takeOutOfBase(t),r=this.width-1;if(n!==r){for(var i=this.height-1,o=0;o<=i;o+=1){var a=this.matrix[o];a[n]=a[r]}var s=this.optionalObjectives.length;if(s>0)for(var u=0;u<s;u+=1){var d=this.optionalObjectives[u].reducedCosts;d[n]=d[r]}var l=this.varIndexByCol[r];this.varIndexByCol[n]=l,this.colByVarIndex[l]=n}this.varIndexByCol[r]=-1,this.colByVarIndex[t]=-1,this.availableIndexes[this.availableIndexes.length]=t,e.index=-1,this.width-=1}});var Or=H(()=>{"use strict";var Ri=pe();Ri.prototype.log=function(e,t){console.log("****",e,"****"),console.log("Nb Variables",this.width-1),console.log("Nb Constraints",this.height-1),console.log("Basic Indexes",this.varIndexByRow),console.log("Non Basic Indexes",this.varIndexByCol),console.log("Rows",this.rowByVarIndex),console.log("Cols",this.colByVarIndex);var n=5,r="",i=[" "],o,a,s,u,d,l,f,p,m,g,c,b,y;for(a=1;a<this.width;a+=1)l=this.varIndexByCol[a],d=this.variablesPerIndex[l],d===void 0?f="c"+l:f=d.id,p=f.length,m=Math.abs(p-5),g=" ",c=" ",p>5?g+=" ":c+=" ",i[a]=g,r+=c+f;console.log(r);var h,N=this.matrix[this.costRowIndex],v=" ";for(o=1;o<this.width;o+=1)h=" ",v+=h,v+=i[o],v+=N[o].toFixed(n);for(h=" ",v+=h+i[0]+N[0].toFixed(n),console.log(v+" Z"),u=1;u<this.height;u+=1){for(b=this.matrix[u],y=" ",a=1;a<this.width;a+=1)h=" ",y+=h+i[a]+b[a].toFixed(n);h=" ",y+=h+i[0]+b[0].toFixed(n),l=this.varIndexByRow[u],d=this.variablesPerIndex[l],d===void 0?f="c"+l:f=d.id,console.log(y+" "+f)}console.log("");var L=this.optionalObjectives.length;if(L>0){console.log(" Optional objectives:");for(var k=0;k<L;k+=1){var w=this.optionalObjectives[k].reducedCosts,S="";for(o=1;o<this.width;o+=1)h=w[o]<0?"":" ",S+=h,S+=i[o],S+=w[o].toFixed(n);h=w[0]<0?"":" ",S+=h+i[0]+w[0].toFixed(n),console.log(S+" z"+k)}}return console.log("Feasible?",this.feasible),console.log("evaluation",this.evaluation),this}});var Ir=H(()=>{"use strict";var Ot=pe();Ot.prototype.copy=function(){var e=new Ot(this.precision);e.width=this.width,e.height=this.height,e.nVars=this.nVars,e.model=this.model,e.variables=this.variables,e.variablesPerIndex=this.variablesPerIndex,e.unrestrictedVars=this.unrestrictedVars,e.lastElementIndex=this.lastElementIndex,e.varIndexByRow=this.varIndexByRow.slice(),e.varIndexByCol=this.varIndexByCol.slice(),e.rowByVarIndex=this.rowByVarIndex.slice(),e.colByVarIndex=this.colByVarIndex.slice(),e.availableIndexes=this.availableIndexes.slice();for(var t=[],n=0;n<this.optionalObjectives.length;n++)t[n]=this.optionalObjectives[n].copy();e.optionalObjectives=t;for(var r=this.matrix,i=new Array(this.height),o=0;o<this.height;o++)i[o]=r[o].slice();return e.matrix=i,e};Ot.prototype.save=function(){this.savedState=this.copy()};Ot.prototype.restore=function(){if(this.savedState!==null){var e=this.savedState,t=e.matrix;this.nVars=e.nVars,this.model=e.model,this.variables=e.variables,this.variablesPerIndex=e.variablesPerIndex,this.unrestrictedVars=e.unrestrictedVars,this.lastElementIndex=e.lastElementIndex,this.width=e.width,this.height=e.height;var n,r;for(n=0;n<this.height;n+=1){var i=t[n],o=this.matrix[n];for(r=0;r<this.width;r+=1)o[r]=i[r]}var a=e.varIndexByRow;for(r=0;r<this.height;r+=1)this.varIndexByRow[r]=a[r];for(;this.varIndexByRow.length>this.height;)this.varIndexByRow.pop();var s=e.varIndexByCol;for(n=0;n<this.width;n+=1)this.varIndexByCol[n]=s[n];for(;this.varIndexByCol.length>this.width;)this.varIndexByCol.pop();for(var u=e.rowByVarIndex,d=e.colByVarIndex,l=0;l<this.nVars;l+=1)this.rowByVarIndex[l]=u[l],this.colByVarIndex[l]=d[l];if(e.optionalObjectives.length>0&&this.optionalObjectives.length>0){this.optionalObjectives=[],this.optionalObjectivePerPriority={};for(var f=0;f<e.optionalObjectives.length;f++){var p=e.optionalObjectives[f].copy();this.optionalObjectives[f]=p,this.optionalObjectivePerPriority[p.priority]=p}}}}});var Gr=H(()=>{"use strict";var Cr=pe();function Tr(e,t){this.index=e,this.value=t}Cr.prototype.getMostFractionalVar=function(){for(var e=0,t=null,n=null,r=.5,i=this.model.integerVariables,o=i.length,a=0;a<o;a++){var s=i[a].index,u=this.rowByVarIndex[s];if(u!==-1){var d=this.matrix[u][this.rhsColumn],l=Math.abs(d-Math.round(d));e<l&&(e=l,t=s,n=d)}}return new Tr(t,n)};Cr.prototype.getFractionalVarWithLowestCost=function(){for(var e=1/0,t=null,n=null,r=this.model.integerVariables,i=r.length,o=0;o<i;o++){var a=r[o],s=a.index,u=this.rowByVarIndex[s];if(u!==-1){var d=this.matrix[u][this.rhsColumn];if(Math.abs(d-Math.round(d))>this.precision){var l=a.cost;e>l&&(e=l,t=s,n=d)}}}return new Tr(t,n)}});var Mr=H(()=>{"use strict";var Dn=pe();Dn.prototype.countIntegerValues=function(){for(var e=0,t=1;t<this.height;t+=1)if(this.variablesPerIndex[this.varIndexByRow[t]].isInteger){var n=this.matrix[t][this.rhsColumn];n=n-Math.floor(n),n<this.precision&&-n<this.precision&&(e+=1)}return e};Dn.prototype.isIntegral=function(){for(var e=this.model.integerVariables,t=e.length,n=0;n<t;n++){var r=this.rowByVarIndex[e[n].index];if(r!==-1){var i=this.matrix[r][this.rhsColumn];if(Math.abs(i-Math.round(i))>this.precision)return!1}}return!0};Dn.prototype.computeFractionalVolume=function(e){for(var t=-1,n=1;n<this.height;n+=1)if(this.variablesPerIndex[this.varIndexByRow[n]].isInteger){var r=this.matrix[n][this.rhsColumn];r=Math.abs(r);var i=Math.min(r-Math.floor(r),Math.floor(r+1));if(i<this.precision){if(!e)return 0}else t===-1?t=r:t*=r}return t===-1?0:t}});var zr=H((wu,Rr)=>{"use strict";xr();Dr();Sr();Or();Ir();Gr();Mr();Rr.exports=pe()});var On=H(()=>{"use strict";var Vr=pe();function Br(e,t,n){this.type=e,this.varIndex=t,this.value=n}function Sn(e,t){this.relaxedEvaluation=e,this.cuts=t}function zi(e,t){return t.relaxedEvaluation-e.relaxedEvaluation}Vr.prototype.applyCuts=function(e){if(this.restore(),this.addCutConstraints(e),this.simplex(),this.model.useMIRCuts)for(var t=!0;t;){var n=this.computeFractionalVolume(!0);this.applyMIRCuts(),this.simplex();var r=this.computeFractionalVolume(!0);r>=.9*n&&(t=!1)}};Vr.prototype.branchAndCut=function(){var e=[],t=0,n=this.model.tolerance,r=!0,i=1e99;this.model.timeout&&(i=Date.now()+this.model.timeout);for(var o=1/0,a=null,s=[],u=0;u<this.optionalObjectives.length;u+=1)s.push(1/0);var d=new Sn(-1/0,[]),l;for(e.push(d);e.length>0&&r===!0&&Date.now()<i;)if(this.model.isMinimization?l=this.bestPossibleEval*(1+n):l=this.bestPossibleEval*(1-n),n>0&&o<l&&(r=!1),d=e.pop(),!(d.relaxedEvaluation>o)){var f=d.cuts;if(this.applyCuts(f),t++,this.feasible!==!1){var p=this.evaluation;if(!(p>o)){if(p===o){for(var m=!0,g=0;g<this.optionalObjectives.length&&!(this.optionalObjectives[g].reducedCosts[0]>s[g]);g+=1)if(this.optionalObjectives[g].reducedCosts[0]<s[g]){m=!1;break}if(m)continue}if(this.isIntegral()===!0){if(this.__isIntegral=!0,t===1){this.branchAndCutIterations=t;return}a=d,o=p;for(var c=0;c<this.optionalObjectives.length;c+=1)s[c]=this.optionalObjectives[c].reducedCosts[0]}else{t===1&&this.save();for(var b=this.getMostFractionalVar(),y=b.index,h=[],N=[],v=f.length,L=0;L<v;L+=1){var k=f[L];k.varIndex===y?k.type==="min"?N.push(k):h.push(k):(h.push(k),N.push(k))}var w=Math.ceil(b.value),S=Math.floor(b.value),O=new Br("min",y,w);h.push(O);var I=new Br("max",y,S);N.push(I),e.push(new Sn(p,h)),e.push(new Sn(p,N)),e.sort(zi)}}}}a!==null&&this.applyCuts(a.cuts),this.branchAndCutIterations=t}});var _r=H((Cu,Pr)=>{"use strict";var Bi=pe(),Ou=On(),ot=Dt(),It=ot.Constraint,$r=ot.Equality,Vi=ot.Variable,$i=ot.IntegerVariable,Iu=ot.Term;function J(e,t){this.tableau=new Bi(e),this.name=t,this.variables=[],this.integerVariables=[],this.unrestrictedVariables={},this.constraints=[],this.nConstraints=0,this.nVariables=0,this.isMinimization=!0,this.tableauInitialized=!1,this.relaxationIndex=1,this.useMIRCuts=!1,this.checkForCycles=!0,this.messages=[]}Pr.exports=J;J.prototype.minimize=function(){return this.isMinimization=!0,this};J.prototype.maximize=function(){return this.isMinimization=!1,this};J.prototype._getNewElementIndex=function(){if(this.availableIndexes.length>0)return this.availableIndexes.pop();var e=this.lastElementIndex;return this.lastElementIndex+=1,e};J.prototype._addConstraint=function(e){var t=e.slack;this.tableau.variablesPerIndex[t.index]=t,this.constraints.push(e),this.nConstraints+=1,this.tableauInitialized===!0&&this.tableau.addConstraint(e)};J.prototype.smallerThan=function(e){var t=new It(e,!0,this.tableau.getNewElementIndex(),this);return this._addConstraint(t),t};J.prototype.greaterThan=function(e){var t=new It(e,!1,this.tableau.getNewElementIndex(),this);return this._addConstraint(t),t};J.prototype.equal=function(e){var t=new It(e,!0,this.tableau.getNewElementIndex(),this);this._addConstraint(t);var n=new It(e,!1,this.tableau.getNewElementIndex(),this);return this._addConstraint(n),new $r(t,n)};J.prototype.addVariable=function(e,t,n,r,i){if(typeof i=="string")switch(i){case"required":i=0;break;case"strong":i=1;break;case"medium":i=2;break;case"weak":i=3;break;default:i=0;break}var o=this.tableau.getNewElementIndex();t==null&&(t="v"+o),e==null&&(e=0),i==null&&(i=0);var a;return n?(a=new $i(t,e,o,i),this.integerVariables.push(a)):a=new Vi(t,e,o,i),this.variables.push(a),this.tableau.variablesPerIndex[o]=a,r&&(this.unrestrictedVariables[o]=!0),this.nVariables+=1,this.tableauInitialized===!0&&this.tableau.addVariable(a),a};J.prototype._removeConstraint=function(e){var t=this.constraints.indexOf(e);if(t===-1){console.warn("[Model.removeConstraint] Constraint not present in model");return}this.constraints.splice(t,1),this.nConstraints-=1,this.tableauInitialized===!0&&this.tableau.removeConstraint(e),e.relaxation&&this.removeVariable(e.relaxation)};J.prototype.removeConstraint=function(e){return e.isEquality?(this._removeConstraint(e.upperBound),this._removeConstraint(e.lowerBound)):this._removeConstraint(e),this};J.prototype.removeVariable=function(e){var t=this.variables.indexOf(e);if(t===-1){console.warn("[Model.removeVariable] Variable not present in model");return}return this.variables.splice(t,1),this.tableauInitialized===!0&&this.tableau.removeVariable(e),this};J.prototype.updateRightHandSide=function(e,t){return this.tableauInitialized===!0&&this.tableau.updateRightHandSide(e,t),this};J.prototype.updateConstraintCoefficient=function(e,t,n){return this.tableauInitialized===!0&&this.tableau.updateConstraintCoefficient(e,t,n),this};J.prototype.setCost=function(e,t){var n=e-t.cost;return this.isMinimization===!1&&(n=-n),t.cost=e,this.tableau.updateCost(t,n),this};J.prototype.loadJson=function(e){this.isMinimization=e.opType!=="max";for(var t=e.variables,n=e.constraints,r={},i={},o=Object.keys(n),a=o.length,s=0;s<a;s+=1){var u=o[s],d=n[u],l=d.equal,f=d.weight,p=d.priority,m=f!==void 0||p!==void 0,g,c;if(l===void 0){var b=d.min;b!==void 0&&(g=this.greaterThan(b),r[u]=g,m&&g.relax(f,p));var y=d.max;y!==void 0&&(c=this.smallerThan(y),i[u]=c,m&&c.relax(f,p))}else{g=this.greaterThan(l),r[u]=g,c=this.smallerThan(l),i[u]=c;var h=new $r(g,c);m&&h.relax(f,p)}}var N=Object.keys(t),v=N.length;this.tolerance=e.tolerance||0,e.timeout&&(this.timeout=e.timeout),e.options&&(e.options.timeout&&(this.timeout=e.options.timeout),this.tolerance===0&&(this.tolerance=e.options.tolerance||0),e.options.useMIRCuts&&(this.useMIRCuts=e.options.useMIRCuts),typeof e.options.exitOnCycles=="undefined"?this.checkForCycles=!0:this.checkForCycles=e.options.exitOnCycles);for(var L=e.ints||{},k=e.binaries||{},w=e.unrestricted||{},S=e.optimize,O=0;O<v;O+=1){var I=N[O],z=t[I],M=z[S]||0,$=!!k[I],_=!!L[I]||$,W=!!w[I],B=this.addVariable(M,I,_,W);$&&this.smallerThan(1).addTerm(1,B);var Z=Object.keys(z);for(s=0;s<Z.length;s+=1){var E=Z[s];if(E!==S){var j=z[E],U=r[E];U!==void 0&&U.addTerm(j,B);var ne=i[E];ne!==void 0&&ne.addTerm(j,B)}}}return this};J.prototype.getNumberOfIntegerVariables=function(){return this.integerVariables.length};J.prototype.solve=function(){return this.tableauInitialized===!1&&(this.tableau.setModel(this),this.tableauInitialized=!0),this.tableau.solve()};J.prototype.isFeasible=function(){return this.tableau.feasible};J.prototype.save=function(){return this.tableau.save()};J.prototype.restore=function(){return this.tableau.restore()};J.prototype.activateMIRCuts=function(e){this.useMIRCuts=e};J.prototype.debug=function(e){this.checkForCycles=e};J.prototype.log=function(e){return this.tableau.log(e)}});var Ar=H(Wr=>{"use strict";Wr.CleanObjectiveAttributes=function(e){var t,n,r;if(typeof e.optimize=="string")if(e.constraints[e.optimize]){t=Math.random();for(n in e.variables)e.variables[n][e.optimize]&&(e.variables[n][t]=e.variables[n][e.optimize]);return e.constraints[t]=e.constraints[e.optimize],delete e.constraints[e.optimize],e}else return e;else{for(r in e.optimize)if(e.constraints[r])if(e.constraints[r]==="equal")delete e.optimize[r];else{t=Math.random();for(n in e.variables)e.variables[n][r]&&(e.variables[n][t]=e.variables[n][r]);e.constraints[t]=e.constraints[r],delete e.constraints[r]}return e}}});var Ct=H((Gu,Ur)=>{"use strict";function Pi(e){var t={is_blank:/^\W{0,}$/,is_objective:/(max|min)(imize){0,}\:/i,is_int:/^(?!\/\*)\W{0,}int/i,is_bin:/^(?!\/\*)\W{0,}bin/i,is_constraint:/(\>|\<){0,}\=/i,is_unrestricted:/^\S{0,}unrestricted/i,parse_lhs:/(\-|\+){0,1}\s{0,1}\d{0,}\.{0,}\d{0,}\s{0,}[A-Za-z]\S{0,}/gi,parse_rhs:/(\-|\+){0,1}\d{1,}\.{0,}\d{0,}\W{0,}\;{0,1}$/i,parse_dir:/(\>|\<){0,}\=/gi,parse_int:/[^\s|^\,]+/gi,parse_bin:/[^\s|^\,]+/gi,get_num:/(\-|\+){0,1}(\W|^)\d+\.{0,1}\d{0,}/g,get_word:/[A-Za-z].*/},n={opType:"",optimize:"_obj",constraints:{},variables:{}},r={">=":"min","<=":"max","=":"equal"},i="",o=0,a=null,s="",u="",d="",l=0;typeof e=="string"&&(e=e.split(`
`));for(var f=0;f<e.length;f++)if(d="__"+f,i=e[f],o=0,a=null,t.is_objective.test(i))n.opType=i.match(/(max|min)/gi)[0],a=i.match(t.parse_lhs).map(function(g){return g.replace(/\s+/,"")}).slice(1),a.forEach(function(g){s=g.match(t.get_num),s===null?g.substr(0,1)==="-"?s=-1:s=1:s=s[0],s=parseFloat(s),u=g.match(t.get_word)[0].replace(/\;$/,""),n.variables[u]=n.variables[u]||{},n.variables[u]._obj=s});else if(t.is_int.test(i))a=i.match(t.parse_int).slice(1),n.ints=n.ints||{},a.forEach(function(g){g=g.replace(";",""),n.ints[g]=1});else if(t.is_bin.test(i))a=i.match(t.parse_bin).slice(1),n.binaries=n.binaries||{},a.forEach(function(g){g=g.replace(";",""),n.binaries[g]=1});else if(t.is_constraint.test(i)){var p=i.indexOf(":"),m=p===-1?i:i.slice(p+1);a=m.match(t.parse_lhs).map(function(g){return g.replace(/\s+/,"")}),a.forEach(function(g){s=g.match(t.get_num),s===null?g.substr(0,1)==="-"?s=-1:s=1:s=s[0],s=parseFloat(s),u=g.match(t.get_word)[0],n.variables[u]=n.variables[u]||{},n.variables[u][d]=s}),l=parseFloat(i.match(t.parse_rhs)[0]),i=r[i.match(t.parse_dir)[0]],n.constraints[d]=n.constraints[d]||{},n.constraints[d][i]=l}else t.is_unrestricted.test(i)&&(a=i.match(t.parse_int).slice(1),n.unrestricted=n.unrestricted||{},a.forEach(function(g){g=g.replace(";",""),n.unrestricted[g]=1}));return n}function _i(e){if(!e)throw new Error("Solver requires a model to operate on");var t="",n=[],r=1,i={max:"<=",min:">=",equal:"="},o=new RegExp("[^A-Za-z0-9_[{}/.&#$%~'@^]","gi");if(e.opType){t+=e.opType+":";for(var a in e.variables)e.variables[a][a]=e.variables[a][a]?e.variables[a][a]:1,e.variables[a][e.optimize]&&(t+=" "+e.variables[a][e.optimize]+" "+a.replace(o,"_"))}else t+="max:";t+=`;
`;for(var s in e.constraints)for(var u in e.constraints[s])if(typeof i[u]!="undefined"){for(var d in e.variables)typeof e.variables[d][s]!="undefined"&&(t+=" "+e.variables[d][s]+" "+d.replace(o,"_"));t+=" "+i[u]+" "+e.constraints[s][u],t+=`;
`}if(e.ints){t+=`
`;for(var l in e.ints)t+="int "+l.replace(o,"_")+`;
`}if(e.unrestricted){t+=`
`;for(var f in e.unrestricted)t+="unrestricted "+f.replace(o,"_")+`;
`}return t}Ur.exports=function(e){return e.length?Pi(e):_i(e)}});var Er=H(()=>{"use strict"});var jr=H(()=>{"use strict"});var Hr=H(In=>{"use strict";In.reformat=Ct();function qr(e){return e=e.replace("\\r\\n",`\r
`),e=e.split(`\r
`),e=e.filter(function(t){var n;return n=new RegExp(" 0$","gi"),!(n.test(t)===!0||(n=new RegExp("\\d$","gi"),n.test(t)===!1))}).map(function(t){return t.split(/\:{0,1} +(?=\d)/)}).reduce(function(t,n,r){return t[n[0]]=n[1],t},{}),e}In.solve=function(e){return new Promise(function(t,n){typeof window!="undefined"&&n("Function Not Available in Browser");var r=Ct()(e);e.external||n("Data for this function must be contained in the 'external' attribute. Not seeing anything there."),e.external.binPath||n("No Executable | Binary path provided in arguments as 'binPath'"),e.external.args||n("No arguments array for cli | bash provided on 'args' attribute"),e.external.tempName||n("No 'tempName' given. This is necessary to produce a staging file for the solver to operate on");var i=Er();i.writeFile(e.external.tempName,r,function(o,a){if(o)n(o);else{var s=jr().execFile;e.external.args.push(e.external.tempName),s(e.external.binPath,e.external.args,function(u,d){if(u)if(u.code===1)t(qr(d));else{var l={"-2":"Out of Memory",1:"SUBOPTIMAL",2:"INFEASIBLE",3:"UNBOUNDED",4:"DEGENERATE",5:"NUMFAILURE",6:"USER-ABORT",7:"TIMEOUT",9:"PRESOLVED",25:"ACCURACY ERROR",255:"FILE-ERROR"},f={code:u.code,meaning:l[u.code],data:d};n(f)}else t(qr(d))})}})})}});var Zr=H(($u,Fr)=>{"use strict";Fr.exports={lpsolve:Hr()}});var Cn=H((Pu,Jr)=>{"use strict";Jr.exports=function(e,t){var n=t.optimize,r=JSON.parse(JSON.stringify(t.optimize)),i=Object.keys(t.optimize),o,a=0,s={},u="",d={},l=[],f,p,m,g,c;for(delete t.optimize,f=0;f<i.length;f++)r[i[f]]=0;for(f=0;f<i.length;f++){t.optimize=i[f],t.opType=n[i[f]],o=e.Solve(t,void 0,void 0,!0);for(g in i)if(!t.variables[i[g]]){o[i[g]]=o[i[g]]?o[i[g]]:0;for(m in t.variables)t.variables[m][i[g]]&&o[m]&&(o[i[g]]+=o[m]*t.variables[m][i[g]])}for(u="base",p=0;p<i.length;p++)o[i[p]]?u+="-"+(o[i[p]]*1e3|0)/1e3:u+="-0";if(!s[u]){for(s[u]=1,a++,p=0;p<i.length;p++)o[i[p]]&&(r[i[p]]+=o[i[p]]);delete o.feasible,delete o.result,l.push(o)}}for(f=0;f<i.length;f++)t.constraints[i[f]]={equal:r[i[f]]/a};t.optimize="cheater-"+Math.random(),t.opType="max";for(f in t.variables)t.variables[f].cheater=1;for(f in l)for(m in l[f])d[m]=d[m]||{min:1e99,max:-1e99};for(f in d)for(m in l)l[m][f]?(l[m][f]>d[f].max&&(d[f].max=l[m][f]),l[m][f]<d[f].min&&(d[f].min=l[m][f])):(l[m][f]=0,d[f].min=0);return o=e.Solve(t,void 0,void 0,!0),{midpoint:o,vertices:l,ranges:d}}});var Yr=H((_u,Kr)=>{"use strict";var Wi=zr(),Tn=_r(),Ai=On(),Mt=Dt(),Qr=Ar(),Ui=Mt.Constraint,Ei=Mt.Variable,ji=Mt.Numeral,qi=Mt.Term,Tt=Zr(),Gt=function(){"use strict";this.Model=Tn,this.branchAndCut=Ai,this.Constraint=Ui,this.Variable=Ei,this.Numeral=ji,this.Term=qi,this.Tableau=Wi,this.lastSolvedModel=null,this.External=Tt,this.Solve=function(e,t,n,r){if(r)for(var i in Qr)e=Qr[i](e);if(!e)throw new Error("Solver requires a model to operate on");if(typeof e.optimize=="object"&&Object.keys(e.optimize>1))return Cn()(this,e);if(e.external){var o=Object.keys(Tt);if(o=JSON.stringify(o),!e.external.solver)throw new Error("The model you provided has an 'external' object that doesn't have a solver attribute. Use one of the following:"+o);if(!Tt[e.external.solver])throw new Error("No support (yet) for "+e.external.solver+". Please use one of these instead:"+o);return Tt[e.external.solver].solve(e)}else{e instanceof Tn||(e=new Tn(t).loadJson(e));var a=e.solve();if(this.lastSolvedModel=e,a.solutionSet=a.generateSolutionSet(),n)return a;var s={};return s.feasible=a.feasible,s.result=a.evaluation,s.bounded=a.bounded,a._tableau.__isIntegral&&(s.isIntegral=!0),Object.keys(a.solutionSet).forEach(function(u){a.solutionSet[u]!==0&&(s[u]=a.solutionSet[u])}),s}},this.ReformatLP=Ct(),this.MultiObjective=function(e){return Cn()(this,e)}};typeof define=="function"?define([],function(){return new Gt}):typeof window=="object"?window.solver=new Gt:typeof self=="object"&&(self.solver=new Gt);Kr.exports=new Gt});var oo=H((td,ro)=>{"use strict";var at=1e-60,to,no;do at+=at,to=1+.1*at,no=1+.2*at;while(to<=1||no<=1);ro.exports=at});var ao=H((nd,io)=>{"use strict";function Fi(e,t,n){let r,i;for(let o=1;o<=n;o+=1){e[o][o]=1/e[o][o],i=-e[o][o];for(let a=1;a<o;a+=1)e[a][o]*=i;if(r=o+1,n<r)break;for(let a=r;a<=n;a+=1){i=e[o][a],e[o][a]=0;for(let s=1;s<=o;s+=1)e[s][a]+=i*e[s][o]}}}io.exports=Fi});var uo=H((rd,so)=>{"use strict";function Zi(e,t,n,r){let i,o;for(i=1;i<=n;i+=1){o=0;for(let a=1;a<i;a+=1)o+=e[a][i]*r[a];r[i]=(r[i]-o)/e[i][i]}for(let a=1;a<=n;a+=1){i=n+1-a,r[i]/=e[i][i],o=-r[i];for(let s=1;s<i;s+=1)r[s]+=o*e[s][i]}}so.exports=Zi});var fo=H((od,lo)=>{"use strict";function Ji(e,t,n,r){let i,o,a;for(let s=1;s<=n;s+=1){if(r[1]=s,a=0,i=s-1,i<1){if(a=e[s][s]-a,a<=0)break;e[s][s]=Math.sqrt(a)}else{for(let u=1;u<=i;u+=1){o=e[u][s];for(let d=1;d<u;d+=1)o-=e[d][s]*e[d][u];o/=e[u][u],e[u][s]=o,a+=o*o}if(a=e[s][s]-a,a<=0)break;e[s][s]=Math.sqrt(a)}r[1]=0}}lo.exports=Ji});var po=H((id,co)=>{"use strict";var Gn=oo(),Qi=ao(),Ki=uo(),Yi=fo();function Xi(e,t,n,r,i,o,a,s,u,d,l,f,p,m=0,g,c,b){let y,h,N,v,L,k,w,S,O,I,z,M,$,_,W=Math.min(r,l),B=2*r+W*(W+5)/2+2*l+1;for(let x=1;x<=r;x+=1)c[x]=t[x];for(let x=r+1;x<=B;x+=1)c[x]=0;for(let x=1;x<=l;x+=1)p[x]=0,o[x]=0;let Z=[];if(b[1]===0){if(Yi(e,n,r,Z),Z[1]!==0){b[1]=2;return}Ki(e,n,r,t),Qi(e,n,r)}else{for(let x=1;x<=r;x+=1){i[x]=0;for(let G=1;G<=x;G+=1)i[x]+=e[G][x]*t[G]}for(let x=1;x<=r;x+=1){t[x]=0;for(let G=x;G<=r;G+=1)t[x]+=e[x][G]*i[G]}}a[1]=0;for(let x=1;x<=r;x+=1){i[x]=t[x],a[1]+=c[x]*i[x],c[x]=0;for(let G=x+1;G<=r;G+=1)e[G][x]=0}a[1]=-a[1]/2,b[1]=0;let E=r,j=E+r,U=j+W,ne=U+W+1,ee=ne+W*(W+1)/2,ve=ee+l;for(let x=1;x<=l;x+=1){k=0;for(let G=1;G<=r;G+=1)k+=s[G][x]*s[G][x];c[ve+x]=Math.sqrt(k)}v=m,g[1]=0,g[2]=0;function Xo(){g[1]+=1,B=ee;for(let x=1;x<=l;x+=1){B+=1,k=-u[x];for(let G=1;G<=r;G+=1)k+=s[G][x]*i[G];if(Math.abs(k)<Gn&&(k=0),x>f)c[B]=k;else if(c[B]=-Math.abs(k),k>0){for(let G=1;G<=r;G+=1)s[G][x]=-s[G][x];u[x]=-u[x]}}for(let x=1;x<=v;x+=1)c[ee+p[x]]=0;N=0,L=0;for(let x=1;x<=l;x+=1)c[ee+x]<L*c[ve+x]&&(N=x,L=c[ee+x]/c[ve+x]);if(N===0){for(let x=1;x<=v;x+=1)o[p[x]]=c[U+x];return 999}return 0}function ei(){for(let x=1;x<=r;x+=1){k=0;for(let G=1;G<=r;G+=1)k+=e[G][x]*s[G][N];c[x]=k}y=E;for(let x=1;x<=r;x+=1)c[y+x]=0;for(let x=v+1;x<=r;x+=1)for(let G=1;G<=r;G+=1)c[y+G]=c[y+G]+e[G][x]*c[x];M=!0;for(let x=v;x>=1;x-=1){k=c[x],B=ne+x*(x+3)/2,y=B-x;for(let G=x+1;G<=v;G+=1)k-=c[B]*c[j+G],B+=G;k/=c[y],c[j+x]=k,!(p[x]<=f)&&(k<=0||(M=!1,h=x))}if(!M){w=c[U+h]/c[j+h];for(let x=1;x<=v;x+=1)p[x]<=f||c[j+x]<=0||(L=c[U+x]/c[j+x],L<w&&(w=L,h=x))}k=0;for(let x=E+1;x<=E+r;x+=1)k+=c[x]*c[x];if(Math.abs(k)<=Gn){if(M)return b[1]=1,999;for(let x=1;x<=v;x+=1)c[U+x]=c[U+x]-w*c[j+x];return c[U+v+1]=c[U+v+1]+w,700}k=0;for(let x=1;x<=r;x+=1)k+=c[E+x]*s[x][N];S=-c[ee+N]/k,$=!0,M||w<S&&(S=w,$=!1);for(let x=1;x<=r;x+=1)i[x]+=S*c[E+x],Math.abs(i[x])<Gn&&(i[x]=0);a[1]+=S*k*(S/2+c[U+v+1]);for(let x=1;x<=v;x+=1)c[U+x]=c[U+x]-S*c[j+x];if(c[U+v+1]=c[U+v+1]+S,$){v+=1,p[v]=N,B=ne+(v-1)*v/2+1;for(let x=1;x<=v-1;x+=1)c[B]=c[x],B+=1;if(v===r)c[B]=c[r];else{for(let x=r;x>=v+1;x-=1)if(c[x]!==0&&(O=Math.max(Math.abs(c[x-1]),Math.abs(c[x])),I=Math.min(Math.abs(c[x-1]),Math.abs(c[x])),c[x-1]>=0?L=Math.abs(O*Math.sqrt(1+I*I/(O*O))):L=-Math.abs(O*Math.sqrt(1+I*I/(O*O))),O=c[x-1]/L,I=c[x]/L,O!==1))if(O===0){c[x-1]=I*L;for(let G=1;G<=r;G+=1)L=e[G][x-1],e[G][x-1]=e[G][x],e[G][x]=L}else{c[x-1]=L,z=I/(1+O);for(let G=1;G<=r;G+=1)L=O*e[G][x-1]+I*e[G][x],e[G][x]=z*(e[G][x-1]+L)-e[G][x],e[G][x-1]=L}c[B]=c[v]}}else{k=-u[N];for(let x=1;x<=r;x+=1)k+=i[x]*s[x][N];if(N>f)c[ee+N]=k;else if(c[ee+N]=-Math.abs(k),k>0){for(let x=1;x<=r;x+=1)s[x][N]=-s[x][N];u[N]=-u[N]}return 700}return 0}function ti(){if(B=ne+h*(h+1)/2+1,y=B+h,c[y]===0||(O=Math.max(Math.abs(c[y-1]),Math.abs(c[y])),I=Math.min(Math.abs(c[y-1]),Math.abs(c[y])),c[y-1]>=0?L=Math.abs(O*Math.sqrt(1+I*I/(O*O))):L=-Math.abs(O*Math.sqrt(1+I*I/(O*O))),O=c[y-1]/L,I=c[y]/L,O===1))return 798;if(O===0){for(let x=h+1;x<=v;x+=1)L=c[y-1],c[y-1]=c[y],c[y]=L,y+=x;for(let x=1;x<=r;x+=1)L=e[x][h],e[x][h]=e[x][h+1],e[x][h+1]=L}else{z=I/(1+O);for(let x=h+1;x<=v;x+=1)L=O*c[y-1]+I*c[y],c[y]=z*(c[y-1]+L)-c[y],c[y-1]=L,y+=x;for(let x=1;x<=r;x+=1)L=O*e[x][h]+I*e[x][h+1],e[x][h+1]=z*(e[x][h]+L)-e[x][h+1],e[x][h]=L}return 0}function ni(){y=B-h;for(let x=1;x<=h;x+=1)c[y]=c[B],B+=1,y+=1;return c[U+h]=c[U+h+1],p[h]=p[h+1],h+=1,h<v?797:0}function Wn(){return c[U+v]=c[U+v+1],c[U+v+1]=0,p[v]=0,v-=1,g[2]+=1,0}for(_=0;;){if(_=Xo(),_===999)return;for(;_=ei(),_!==0;){if(_===999)return;if(_===700)if(h===v)Wn();else{for(;ti(),_=ni(),_===797;);Wn()}}}}co.exports=Xi});var mo=H(ho=>{"use strict";var ea=po();function ta(e,t,n,r=[],i=0,o=[0,0]){let a=[],s=[],u=[],d=[],l=[],f=[],p="",m=e.length-1,g=n[1].length-1;if(!r)for(let y=1;y<=g;y+=1)r[y]=0;if(m!==e[1].length-1&&(p="Dmat is not symmetric!"),m!==t.length-1&&(p="Dmat and dvec are incompatible!"),m!==n.length-1&&(p="Amat and dvec are incompatible!"),g!==r.length-1&&(p="Amat and bvec are incompatible!"),(i>g||i<0)&&(p="Value of meq is invalid!"),p!=="")return{message:p};for(let y=1;y<=g;y+=1)s[y]=0,d[y]=0;let c=0,b=Math.min(m,g);for(let y=1;y<=m;y+=1)u[y]=0;a[1]=0;for(let y=1;y<=2*m+b*(b+5)/2+2*g+1;y+=1)l[y]=0;for(let y=1;y<=2;y+=1)f[y]=0;return ea(e,t,m,m,u,d,a,n,r,m,g,i,s,c,f,l,o),o[1]===1&&(p="constraints are inconsistent, no solution!"),o[1]===2&&(p="matrix D in quadratic function is not positive definite!"),{solution:u,Lagrangian:d,value:a,unconstrained_solution:t,iterations:f,iact:s,message:p}}ho.solveQP=ta});var yo=H((sd,go)=>{"use strict";go.exports=mo()});var ya={};di(ya,{aggMean:()=>Bt,aggMedian:()=>No,aggWeightedMedian:()=>Mn,cachedNodeSize:()=>it,coordCenter:()=>Mo,coordGreedy:()=>Bo,coordQuad:()=>Vo,coordSimplex:()=>At,coordTopological:()=>Po,decrossDfs:()=>st,decrossOpt:()=>_o,decrossTwoLayer:()=>Ht,graph:()=>ie,graphConnect:()=>rr,graphHierarchy:()=>ar,graphJson:()=>Kn,graphStratify:()=>dr,grid:()=>pr,laneGreedy:()=>Lt,laneOpt:()=>eo,layerSeparation:()=>Ft,layeringLongestPath:()=>Wo,layeringSimplex:()=>Zt,layeringTopological:()=>Uo,shapeEllipse:()=>Zo,shapeRect:()=>_n,sizedSeparation:()=>Et,splitNodeSize:()=>zt,sugiNodeLength:()=>Kt,sugifyCompact:()=>Co,sugifyLayer:()=>Jt,sugiyama:()=>Go,tweakFlip:()=>Fo,tweakGrid:()=>Ho,tweakShape:()=>Jo,tweakSize:()=>qo,twolayerAgg:()=>Vt,twolayerGreedy:()=>Ut,twolayerOpt:()=>jo,unsugify:()=>Qt,zherebko:()=>Yo});function qn(e,t){if(t.size!==e.size)return!1;for(let n of e)if(!t.has(n))return!1;return!0}function Hn(e){for(let t of e)return t}function qe(e){for(let t of e)return e.delete(t),t}function Re(e,t,n){let r=e.get(t);r===void 0?e.set(t,[n]):r.push(n)}function ft(e,t,n){let r=e.get(t);r===void 0?e.set(t,new Set([n])):r.add(n)}function tn(e,t,n){let r=e.get(t);r!==void 0&&(r.delete(n),r.size||e.delete(t))}var{toString:ci}=Object.prototype;function nn(e){return ci.call(e)==="[object RegExp]"}function rn(e){let t=typeof e;return e!==null&&(t==="object"||t==="function")}var{propertyIsEnumerable:pi}=Object.prototype;function on(e){return[...Object.keys(e),...Object.getOwnPropertySymbols(e).filter(t=>pi.call(e,t))]}function an(e,t,n){let r=[];return function i(o,a={},s=""){let u=a.indent||" ",d;a.inlineCharacterLimit===void 0?d={newline:`
`,newlineOrSpace:`
`,pad:s,indent:s+u}:d={newline:"@@__STRINGIFY_OBJECT_NEW_LINE__@@",newlineOrSpace:"@@__STRINGIFY_OBJECT_NEW_LINE_OR_SPACE__@@",pad:"@@__STRINGIFY_OBJECT_PAD__@@",indent:"@@__STRINGIFY_OBJECT_INDENT__@@"};let l=f=>{if(a.inlineCharacterLimit===void 0)return f;let p=f.replace(new RegExp(d.newline,"g"),"").replace(new RegExp(d.newlineOrSpace,"g")," ").replace(new RegExp(d.pad+"|"+d.indent,"g"),"");return p.length<=a.inlineCharacterLimit?p:f.replace(new RegExp(d.newline+"|"+d.newlineOrSpace,"g"),`
`).replace(new RegExp(d.pad,"g"),s).replace(new RegExp(d.indent,"g"),s+u)};if(r.includes(o))return'"[Circular]"';if(o==null||typeof o=="number"||typeof o=="boolean"||typeof o=="function"||typeof o=="symbol"||nn(o))return String(o);if(o instanceof Date)return`new Date('${o.toISOString()}')`;if(Array.isArray(o)){if(o.length===0)return"[]";r.push(o);let f="["+d.newline+o.map((p,m)=>{let g=o.length-1===m?d.newline:","+d.newlineOrSpace,c=i(p,a,s+u);return a.transform&&(c=a.transform(o,m,c)),d.indent+c+g}).join("")+d.pad+"]";return r.pop(),l(f)}if(rn(o)){let f=on(o);if(a.filter&&(f=f.filter(m=>a.filter(o,m))),f.length===0)return"{}";r.push(o);let p="{"+d.newline+f.map((m,g)=>{let c=f.length-1===g?d.newline:","+d.newlineOrSpace,b=typeof m=="symbol",y=!b&&/^[a-z$_][$\w]*$/i.test(m),h=b||y?m:i(m,a),N=i(o[m],a,s+u);return a.transform&&(N=a.transform(o,m,N)),d.indent+String(h)+": "+N+c}).join("")+d.pad+"}";return r.pop(),l(p)}return o=o.replace(/\\/g,"\\\\"),o=String(o).replace(/[\r\n]/g,f=>f===`
`?"\\n":"\\r"),a.singleQuotes===!1?(o=o.replace(/"/g,'\\"'),`"${o}"`):(o=o.replace(/'/g,"\\'"),`'${o}'`)}(e,t,n)}function*Oe(e,...t){let n=new Set,r;for(;(r=t.pop())!==void 0;)n.has(r)||(yield r,n.add(r),t.push(...e(r)))}function sn(e,t){let n=[];for(let[r,i]of K(t))n.push(e[r]),n.push(i);return n.push(e[e.length-1]),n.join("")}function D(e,...t){let n=A(t,r=>an(r,{indent:" ",singleQuotes:!1,inlineCharacterLimit:60}));return new Error(sn(e,n))}function Fn(e){return`internal error: ${e}; if you encounter this please submit an issue at: https://github.com/erikbrinkman/d3-dag/issues`}function te(e,...t){let n=A(t,r=>r.toString());return new Error(Fn(sn(e,n)))}function oe(e,t,...n){let[r,...i]=e,o=A(n,u=>u.toString()),a=sn(i,o),s=t.name||"anonymous";return new Error("d3dagBuiltin"in t?Fn(`builtin ${r}'${s}'${a}`):`custom ${r}'${s}'${a}`)}function*K(e){let t=0;for(let n of e)yield[t++,n]}function*Ne(e,t){for(let[n,r]of K(e))yield*Y(t(r,n))}function Zn(e,t,n){let r=n;for(let[i,o]of K(e))r=t(r,o,i);return r}function*A(e,t){for(let[n,r]of K(e))yield t(r,n)}function*be(e,t){for(let[n,r]of K(e))t(r,n)&&(yield r)}function un(e,t){for(let[n,r]of K(e))if(t(r,n))return!0;return!1}function Jn(e,t){return!un(e,(n,r)=>!t(n,r))}function*hi(e,t,n,r){let i=Math.min(n,e.length);for(let o=t;o<i;o+=r)yield e[o]}function*mi(e,t,n,r){let i=Math.max(n,-1);for(let o=t;o>i;o+=r)yield e[o]}function q(e,t=0,n=e.length,r=1){if(r>0)return hi(e,t,n,r);if(r<0)return mi(e,t,n,r);throw D`can't slice with zero stride`}function*ue(...e){for(let t of e)yield*Y(t)}function*Q(e){let t=e[Symbol.iterator](),n=t.next();if(!n.done){let r=n.value,i;for(;!(i=t.next()).done;)yield[r,i.value],r=i.value}}function Qn(e){for(let t of e)return t}function ct(e){return typeof e=="object"&&e!==null&&Symbol.iterator in e&&typeof e[Symbol.iterator]=="function"}function gi(e){if(typeof e!="object"||e===null)return!1;let t="x"in e?e.x:void 0,n="y"in e?e.y:void 0,r="data"in e?e.data:void 0;if(typeof t!="number"&&t!==void 0||typeof n!="number"&&n!==void 0)return!1;let i={x:t,y:n,data:r};return!0}function yi(e){if(!Array.isArray(e)||e.length!==2)return!1;let t=e,[n,r]=t;return typeof n=="number"&&typeof r=="number"}function Ni(e){if(typeof e!="object"||e===null||!("source"in e)||!("target"in e)||!("points"in e))return!1;let{source:t,target:n,points:r}=e,i="data"in e?e.data:void 0;if(typeof t!="number"||typeof n!="number"||!Array.isArray(r)||!r.every(yi))return!1;let o={source:t,target:n,points:r,data:i};return!0}function ln(e){let t=[],n,r=new Map;for(let[a,s]of K(e.nodes()))r.set(s,a),t.push({x:s.ux,y:s.uy,data:s.data}),s===e&&(n=a);let i=[];for(let{source:a,target:s,data:u,points:d}of e.links())i.push({source:r.get(a),target:r.get(s),points:d,data:u});return{nodes:t,links:i,index:n,v:1}}function bi(e,t,n,r,i){let o=ie(),a=e.map(({x:s,y:u,data:d})=>{let l=o.node(r(d));return l.ux=s,l.uy=u,l});for(let{source:s,target:u,points:d,data:l}of t){let f=o.link(a[s],a[u],i(l));f.points=d.map(([p,m])=>[p,m])}return n===void 0?o:a[n]}function dn(e){function t(i){if(typeof i!="object"||i===null)throw D`parsedJson was null or wasn't an object: ${i}`;if(!("nodes"in i)||!("links"in i))throw D`parsedJson didn't have 'nodes' and 'links' properties: ${i}`;let{nodes:o,links:a}=i,s="index"in i?i.index:void 0;if(!Array.isArray(o)||!Array.isArray(a)