// d3-dag Version 0.9.1. Copyright 2022 Erik Brinkman.
var d3 = Object.assign(d3 || {}, (() => {
var d3=(()=>{var Fn=Object.create;var ve=Object.defineProperty,Zn=Object.defineProperties,Qn=Object.getOwnPropertyDescriptor,Jn=Object.getOwnPropertyDescriptors,Kn=Object.getOwnPropertyNames,Ie=Object.getOwnPropertySymbols,Yn=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty,Wt=Object.prototype.propertyIsEnumerable;var Rt=(e,t,r)=>t in e?ve(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,A=(e,t)=>{for(var r in t||(t={}))st.call(t,r)&&Rt(e,r,t[r]);if(Ie)for(var r of Ie(t))Wt.call(t,r)&&Rt(e,r,t[r]);return e},T=(e,t)=>Zn(e,Jn(t)),$t=e=>ve(e,"__esModule",{value:!0});var B=(e,t)=>{var r={};for(var n in e)st.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&Ie)for(var n of Ie(e))t.indexOf(n)<0&&Wt.call(e,n)&&(r[n]=e[n]);return r};var _=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Xn=(e,t)=>{for(var r in t)ve(e,r,{get:t[r],enumerable:!0})},Gt=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Kn(t))!st.call(e,o)&&(r||o!=="default")&&ve(e,o,{get:()=>t[o],enumerable:!(n=Qn(t,o))||n.enumerable});return e},ut=(e,t)=>Gt($t(ve(e!=null?Fn(Yn(e)):{},"default",!t&&e&&e.__esModule?{get:()=>e.default,enumerable:!0}:{value:e,enumerable:!0})),e),eo=(e=>(t,r)=>e&&e.get(t)||(r=Gt($t({}),t,1),e&&e.set(t,r),r))(typeof WeakMap!="undefined"?new WeakMap:0);var mt=_((Ui,sr)=>{function ar(e,t,r,n){this.feasible=r,this.evaluation=t,this.bounded=n,this._tableau=e}sr.exports=ar;ar.prototype.generateSolutionSet=function(){for(var e={},t=this._tableau,r=t.varIndexByRow,n=t.variablesPerIndex,o=t.matrix,a=t.rhsColumn,i=t.height-1,s=Math.round(1/t.precision),u=1;u<=i;u+=1){var c=r[u],d=n[c];if(!(d===void 0||d.isSlack===!0)){var l=o[u][a];e[d.id]=Math.round((Number.EPSILON+l)*s)/s}}return e}});var lr=_((ji,dr)=>{var ur=mt();function We(e,t,r,n,o){ur.call(this,e,t,r,n),this.iter=o}dr.exports=We;We.prototype=Object.create(ur.prototype);We.constructor=We});var K=_((Hi,cr)=>{var xo=mt(),yo=lr();function X(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}cr.exports=X;X.prototype.solve=function(){return this.model.getNumberOfIntegerVariables()>0?this.branchAndCut():this.simplex(),this.updateVariableValues(),this.getSolution()};function gt(e,t){this.priority=e,this.reducedCosts=new Array(t);for(var r=0;r<t;r+=1)this.reducedCosts[r]=0}gt.prototype.copy=function(){var e=new gt(this.priority,this.reducedCosts.length);return e.reducedCosts=this.reducedCosts.slice(),e};X.prototype.setOptionalObjective=function(e,t,r){var n=this.objectivesByPriority[e];if(n===void 0){var o=Math.max(this.width,t+1);n=new gt(e,o),this.objectivesByPriority[e]=n,this.optionalObjectives.push(n),this.optionalObjectives.sort(function(a,i){return a.priority-i.priority})}n.reducedCosts[t]=r};X.prototype.initialize=function(e,t,r,n){this.variables=r,this.unrestrictedVars=n,this.width=e,this.height=t;for(var o=new Array(e),a=0;a<e;a++)o[a]=0;this.matrix=new Array(t);for(var i=0;i<t;i++)this.matrix[i]=o.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};X.prototype._resetMatrix=function(){var e=this.model.variables,t=this.model.constraints,r=e.length,n=t.length,o,a,i=this.matrix[0],s=this.model.isMinimization===!0?-1:1;for(o=0;o<r;o+=1){var u=e[o],c=u.priority,d=s*u.cost;c===0?i[o+1]=d:this.setOptionalObjective(c,o+1,d),a=e[o].index,this.rowByVarIndex[a]=-1,this.colByVarIndex[a]=o+1,this.varIndexByCol[o+1]=a}for(var l=1,p=0;p<n;p+=1){var m=t[p],g=m.index;this.rowByVarIndex[g]=l,this.colByVarIndex[g]=-1,this.varIndexByRow[l]=g;var f,N,h,b=m.terms,O=b.length,x=this.matrix[l++];if(m.isUpperBound){for(f=0;f<O;f+=1)N=b[f],h=this.colByVarIndex[N.variable.index],x[h]=N.coefficient;x[0]=m.rhs}else{for(f=0;f<O;f+=1)N=b[f],h=this.colByVarIndex[N.variable.index],x[h]=-N.coefficient;x[0]=-m.rhs}}};X.prototype.setModel=function(e){this.model=e;var t=e.nVariables+1,r=e.nConstraints+1;return this.initialize(t,r,e.variables,e.unrestrictedVariables),this._resetMatrix(),this};X.prototype.getNewElementIndex=function(){if(this.availableIndexes.length>0)return this.availableIndexes.pop();var e=this.lastElementIndex;return this.lastElementIndex+=1,e};X.prototype.density=function(){for(var e=0,t=this.matrix,r=0;r<this.height;r++)for(var n=t[r],o=0;o<this.width;o++)n[o]!==0&&(e+=1);return e/(this.height*this.width)};X.prototype.setEvaluation=function(){var e=Math.round(1/this.precision),t=this.matrix[this.costRowIndex][this.rhsColumn],r=Math.round((Number.EPSILON+t)*e)/e;this.evaluation=r,this.simplexIters===0&&(this.bestPossibleEval=r)};X.prototype.getSolution=function(){var e=this.model.isMinimization===!0?this.evaluation:-this.evaluation;return this.model.getNumberOfIntegerVariables()>0?new yo(this,e,this.feasible,this.bounded,this.branchAndCutIterations):new xo(this,e,this.feasible,this.bounded)}});var fr=_(()=>{var Le=K();Le.prototype.simplex=function(){return this.bounded=!0,this.phase1(),this.feasible===!0&&this.phase2(),this};Le.prototype.phase1=function(){for(var e=this.model.checkForCycles,t=[],r=this.matrix,n=this.rhsColumn,o=this.width-1,a=this.height-1,i,s=0;;){for(var u=0,c=-this.precision,d=1;d<=a;d++){i=this.unrestrictedVars[this.varIndexByRow[d]]===!0;var l=r[d][n];l<c&&(c=l,u=d)}if(u===0)return this.feasible=!0,s;for(var p=0,m=-1/0,g=r[0],f=r[u],N=1;N<=o;N++){var h=f[N];if(i=this.unrestrictedVars[this.varIndexByCol[N]]===!0,i||h<-this.precision){var b=-g[N]/h;m<b&&(m=b,p=N)}}if(p===0)return this.feasible=!1,s;if(e){t.push([this.varIndexByRow[u],this.varIndexByCol[p]]);var O=this.checkForCycles(t);if(O.length>0)return this.model.messages.push("Cycle in phase 1"),this.model.messages.push("Start :"+O[0]),this.model.messages.push("Length :"+O[1]),this.feasible=!1,s}this.pivot(u,p),s+=1}};Le.prototype.phase2=function(){for(var e=this.model.checkForCycles,t=[],r=this.matrix,n=this.rhsColumn,o=this.width-1,a=this.height-1,i=this.precision,s=this.optionalObjectives.length,u=null,c=0,d,l;;){var p=r[this.costRowIndex];s>0&&(u=[]);for(var m=0,g=i,f=!1,N=1;N<=o;N++){if(d=p[N],l=this.unrestrictedVars[this.varIndexByCol[N]]===!0,s>0&&-i<d&&d<i){u.push(N);continue}if(l&&d<0){-d>g&&(g=-d,m=N,f=!0);continue}d>g&&(g=d,m=N,f=!1)}if(s>0)for(var h=0;m===0&&u.length>0&&h<s;){var b=[],O=this.optionalObjectives[h].reducedCosts;g=i;for(var x=0;x<u.length;x++){if(N=u[x],d=O[N],l=this.unrestrictedVars[this.varIndexByCol[N]]===!0,-i<d&&d<i){b.push(N);continue}if(l&&d<0){-d>g&&(g=-d,m=N,f=!0);continue}d>g&&(g=d,m=N,f=!1)}u=b,h+=1}if(m===0)return this.setEvaluation(),this.simplexIters+=1,c;for(var w=0,y=1/0,L=this.varIndexByRow,D=1;D<=a;D++){var C=r[D],S=C[n],z=C[m];if(!(-i<z&&z<i)){if(z>0&&i>S&&S>-i){y=0,w=D;break}var k=f?-S/z:S/z;k>i&&y>k&&(y=k,w=D)}}if(y===1/0)return this.evaluation=-1/0,this.bounded=!1,this.unboundedVarIndex=this.varIndexByCol[m],c;if(e){t.push([this.varIndexByRow[w],this.varIndexByCol[m]]);var E=this.checkForCycles(t);if(E.length>0)return this.model.messages.push("Cycle in phase 2"),this.model.messages.push("Start :"+E[0]),this.model.messages.push("Length :"+E[1]),this.feasible=!1,c}this.pivot(w,m,!0),c+=1}};var vt=[];Le.prototype.pivot=function(e,t){var r=this.matrix,n=r[e][t],o=this.height-1,a=this.width-1,i=this.varIndexByRow[e],s=this.varIndexByCol[t];this.varIndexByRow[e]=s,this.varIndexByCol[t]=i,this.rowByVarIndex[s]=e,this.rowByVarIndex[i]=-1,this.colByVarIndex[s]=-1,this.colByVarIndex[i]=t;for(var u=r[e],c=0,d=0;d<=a;d++)u[d]>=-1e-16&&u[d]<=1e-16?u[d]=0:(u[d]/=n,vt[c]=d,c+=1);u[t]=1/n;for(var l,p,m,g=this.precision,f=0;f<=o;f++)if(f!==e&&!(r[f][t]>=-1e-16&&r[f][t]<=1e-16)){var N=r[f];if(l=N[t],l>=-1e-16&&l<=1e-16)l!==0&&(N[t]=0);else{for(p=0;p<c;p++)d=vt[p],m=u[d],m>=-1e-16&&m<=1e-16?m!==0&&(u[d]=0):N[d]=N[d]-l*m;N[t]=-l/n}}var h=this.optionalObjectives.length;if(h>0)for(var b=0;b<h;b+=1){var O=this.optionalObjectives[b].reducedCosts;if(l=O[t],l!==0){for(p=0;p<c;p++)d=vt[p],m=u[d],m!==0&&(O[d]=O[d]-l*m);O[t]=-l/n}}};Le.prototype.checkForCycles=function(e){for(var t=0;t<e.length-1;t++)for(var r=t+1;r<e.length;r++){var n=e[t],o=e[r];if(n[0]===o[0]&&n[1]===o[1]){if(r-t>e.length-r)break;for(var a=!0,i=1;i<r-t;i++){var s=e[t+i],u=e[r+i];if(s[0]!==u[0]||s[1]!==u[1]){a=!1;break}}if(a)return[t,r-t]}}return[]}});var Re=_((Qi,gr)=>{function Nt(e,t,r,n){this.id=e,this.cost=t,this.index=r,this.value=0,this.priority=n}function pr(e,t,r,n){Nt.call(this,e,t,r,n)}pr.prototype.isInteger=!0;function bt(e,t){Nt.call(this,e,0,t,0)}bt.prototype.isSlack=!0;function hr(e,t){this.variable=e,this.coefficient=t}function mr(e,t,r){return r===0||r==="required"?null:(t=t||1,r=r||1,e.isMinimization===!1&&(t=-t),e.addVariable(t,"r"+e.relaxationIndex++,!1,!1,r))}function de(e,t,r,n){this.slack=new bt("s"+r,r),this.index=r,this.model=n,this.rhs=e,this.isUpperBound=t,this.terms=[],this.termsByVarIndex={},this.relaxation=null}de.prototype.addTerm=function(e,t){var r=t.index,n=this.termsByVarIndex[r];if(n===void 0)n=new hr(t,e),this.termsByVarIndex[r]=n,this.terms.push(n),this.isUpperBound===!0&&(e=-e),this.model.updateConstraintCoefficient(this,t,e);else{var o=n.coefficient+e;this.setVariableCoefficient(o,t)}return this};de.prototype.removeTerm=function(e){return this};de.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};de.prototype.setVariableCoefficient=function(e,t){var r=t.index;if(r===-1){console.warn("[Constraint.setVariableCoefficient] Trying to change coefficient of inexistant variable.");return}var n=this.termsByVarIndex[r];if(n===void 0)this.addTerm(e,t);else if(e!==n.coefficient){var o=e-n.coefficient;this.isUpperBound===!0&&(o=-o),n.coefficient=e,this.model.updateConstraintCoefficient(this,t,o)}return this};de.prototype.relax=function(e,t){this.relaxation=mr(this.model,e,t),this._relax(this.relaxation)};de.prototype._relax=function(e){e!==null&&(this.isUpperBound?this.setVariableCoefficient(-1,e):this.setVariableCoefficient(1,e))};function me(e,t){this.upperBound=e,this.lowerBound=t,this.model=e.model,this.rhs=e.rhs,this.relaxation=null}me.prototype.isEquality=!0;me.prototype.addTerm=function(e,t){return this.upperBound.addTerm(e,t),this.lowerBound.addTerm(e,t),this};me.prototype.removeTerm=function(e){return this.upperBound.removeTerm(e),this.lowerBound.removeTerm(e),this};me.prototype.setRightHandSide=function(e){this.upperBound.setRightHandSide(e),this.lowerBound.setRightHandSide(e),this.rhs=e};me.prototype.relax=function(e,t){this.relaxation=mr(this.model,e,t),this.upperBound.relaxation=this.relaxation,this.upperBound._relax(this.relaxation),this.lowerBound.relaxation=this.relaxation,this.lowerBound._relax(this.relaxation)};gr.exports={Constraint:de,Variable:Nt,IntegerVariable:pr,SlackVariable:bt,Equality:me,Term:hr}});var vr=_(()=>{var $e=K(),xt=Re().SlackVariable;$e.prototype.addCutConstraints=function(e){for(var t=e.length,r=this.height,n=r+t,o=r;o<n;o+=1)this.matrix[o]===void 0&&(this.matrix[o]=this.matrix[o-1].slice());this.height=n,this.nVars=this.width+this.height-2;for(var a,i=this.width-1,s=0;s<t;s+=1){var u=e[s],c=r+s,d=u.type==="min"?-1:1,l=u.varIndex,p=this.rowByVarIndex[l],m=this.matrix[c];if(p===-1){for(m[this.rhsColumn]=d*u.value,a=1;a<=i;a+=1)m[a]=0;m[this.colByVarIndex[l]]=d}else{var g=this.matrix[p],f=g[this.rhsColumn];for(m[this.rhsColumn]=d*(u.value-f),a=1;a<=i;a+=1)m[a]=-d*g[a]}var N=this.getNewElementIndex();this.varIndexByRow[c]=N,this.rowByVarIndex[N]=c,this.colByVarIndex[N]=-1,this.variablesPerIndex[N]=new xt("s"+N,N),this.nVars+=1}};$e.prototype._addLowerBoundMIRCut=function(e){if(e===this.costRowIndex)return!1;var t=this.model,r=this.matrix,n=this.variablesPerIndex[this.varIndexByRow[e]];if(!n.isInteger)return!1;var o=r[e][this.rhsColumn],a=o-Math.floor(o);if(a<this.precision||1-this.precision<a)return!1;var i=this.height;r[i]=r[i-1].slice(),this.height+=1,this.nVars+=1;var s=this.getNewElementIndex();this.varIndexByRow[i]=s,this.rowByVarIndex[s]=i,this.colByVarIndex[s]=-1,this.variablesPerIndex[s]=new xt("s"+s,s),r[i][this.rhsColumn]=Math.floor(o);for(var u=1;u<this.varIndexByCol.length;u+=1){var c=this.variablesPerIndex[this.varIndexByCol[u]];if(!c.isInteger)r[i][u]=Math.min(0,r[e][u]/(1-a));else{var d=r[e][u],l=Math.floor(d)+Math.max(0,d-Math.floor(d)-a)/(1-a);r[i][u]=l}}for(var p=0;p<this.width;p+=1)r[i][p]-=r[e][p];return!0};$e.prototype._addUpperBoundMIRCut=function(e){if(e===this.costRowIndex)return!1;var t=this.model,r=this.matrix,n=this.variablesPerIndex[this.varIndexByRow[e]];if(!n.isInteger)return!1;var o=r[e][this.rhsColumn],a=o-Math.floor(o);if(a<this.precision||1-this.precision<a)return!1;var i=this.height;r[i]=r[i-1].slice(),this.height+=1,this.nVars+=1;var s=this.getNewElementIndex();this.varIndexByRow[i]=s,this.rowByVarIndex[s]=i,this.colByVarIndex[s]=-1,this.variablesPerIndex[s]=new xt("s"+s,s),r[i][this.rhsColumn]=-a;for(var u=1;u<this.varIndexByCol.length;u+=1){var c=this.variablesPerIndex[this.varIndexByCol[u]],d=r[e][u],l=d-Math.floor(d);c.isInteger?l<=a?r[i][u]=-l:r[i][u]=-(1-l)*a/l:d>=0?r[i][u]=-d:r[i][u]=d*a/(1-a)}return!0};$e.prototype.applyMIRCuts=function(){}});var Nr=_(()=>{var ee=K();ee.prototype._putInBase=function(e){var t=this.rowByVarIndex[e];if(t===-1){for(var r=this.colByVarIndex[e],n=1;n<this.height;n+=1){var o=this.matrix[n][r];if(o<-this.precision||this.precision<o){t=n;break}}this.pivot(t,r)}return t};ee.prototype._takeOutOfBase=function(e){var t=this.colByVarIndex[e];if(t===-1){for(var r=this.rowByVarIndex[e],n=this.matrix[r],o=1;o<this.height;o+=1){var a=n[o];if(a<-this.precision||this.precision<a){t=o;break}}this.pivot(r,t)}return t};ee.prototype.updateVariableValues=function(){for(var e=this.variables.length,t=Math.round(1/this.precision),r=0;r<e;r+=1){var n=this.variables[r],o=n.index,a=this.rowByVarIndex[o];if(a===-1)n.value=0;else{var i=this.matrix[a][this.rhsColumn];n.value=Math.round((i+Number.EPSILON)*t)/t}}};ee.prototype.updateRightHandSide=function(e,t){var r=this.height-1,n=this.rowByVarIndex[e.index];if(n===-1){for(var o=this.colByVarIndex[e.index],a=0;a<=r;a+=1){var i=this.matrix[a];i[this.rhsColumn]-=t*i[o]}var s=this.optionalObjectives.length;if(s>0)for(var u=0;u<s;u+=1){var c=this.optionalObjectives[u].reducedCosts;c[this.rhsColumn]-=t*c[o]}}else this.matrix[n][this.rhsColumn]-=t};ee.prototype.updateConstraintCoefficient=function(e,t,r){if(e.index===t.index)throw new Error("[Tableau.updateConstraintCoefficient] constraint index should not be equal to variable index !");var n=this._putInBase(e.index),o=this.colByVarIndex[t.index];if(o===-1)for(var a=this.rowByVarIndex[t.index],i=0;i<this.width;i+=1)this.matrix[n][i]+=r*this.matrix[a][i];else this.matrix[n][o]-=r};ee.prototype.updateCost=function(e,t){var r=e.index,n=this.width-1,o=this.colByVarIndex[r];if(o===-1){var a=this.matrix[this.rowByVarIndex[r]],i;if(e.priority===0){var s=this.matrix[0];for(i=0;i<=n;i+=1)s[i]+=t*a[i]}else{var u=this.objectivesByPriority[e.priority].reducedCosts;for(i=0;i<=n;i+=1)u[i]+=t*a[i]}}else this.matrix[0][o]-=t};ee.prototype.addConstraint=function(e){var t=e.isUpperBound?1:-1,r=this.height,n=this.matrix[r];n===void 0&&(n=this.matrix[0].slice(),this.matrix[r]=n);for(var o=this.width-1,a=0;a<=o;a+=1)n[a]=0;n[this.rhsColumn]=t*e.rhs;for(var i=e.terms,s=i.length,u=0;u<s;u+=1){var c=i[u],d=c.coefficient,l=c.variable.index,p=this.rowByVarIndex[l];if(p===-1)n[this.colByVarIndex[l]]+=t*d;else{var m=this.matrix[p],g=m[this.rhsColumn];for(a=0;a<=o;a+=1)n[a]-=t*d*m[a]}}var f=e.index;this.varIndexByRow[r]=f,this.rowByVarIndex[f]=r,this.colByVarIndex[f]=-1,this.height+=1};ee.prototype.removeConstraint=function(e){var t=e.index,r=this.height-1,n=this._putInBase(t),o=this.matrix[r];this.matrix[r]=this.matrix[n],this.matrix[n]=o,this.varIndexByRow[n]=this.varIndexByRow[r],this.varIndexByRow[r]=-1,this.rowByVarIndex[t]=-1,this.availableIndexes[this.availableIndexes.length]=t,e.slack.index=-1,this.height-=1};ee.prototype.addVariable=function(e){var t=this.height-1,r=this.width,n=this.model.isMinimization===!0?-e.cost:e.cost,o=e.priority,a=this.optionalObjectives.length;if(a>0)for(var i=0;i<a;i+=1)this.optionalObjectives[i].reducedCosts[r]=0;o===0?this.matrix[0][r]=n:(this.setOptionalObjective(o,r,n),this.matrix[0][r]=0);for(var s=1;s<=t;s+=1)this.matrix[s][r]=0;var u=e.index;this.varIndexByCol[r]=u,this.rowByVarIndex[u]=-1,this.colByVarIndex[u]=r,this.width+=1};ee.prototype.removeVariable=function(e){var t=e.index,r=this._takeOutOfBase(t),n=this.width-1;if(r!==n){for(var o=this.height-1,a=0;a<=o;a+=1){var i=this.matrix[a];i[r]=i[n]}var s=this.optionalObjectives.length;if(s>0)for(var u=0;u<s;u+=1){var c=this.optionalObjectives[u].reducedCosts;c[r]=c[n]}var d=this.varIndexByCol[n];this.varIndexByCol[r]=d,this.colByVarIndex[d]=r}this.varIndexByCol[n]=-1,this.colByVarIndex[t]=-1,this.availableIndexes[this.availableIndexes.length]=t,e.index=-1,this.width-=1}});var br=_(()=>{var Oo=K();Oo.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 r=5,n="",o=[" "],a,i,s,u,c,d,l,p,m,g,f,N,h;for(i=1;i<this.width;i+=1)d=this.varIndexByCol[i],c=this.variablesPerIndex[d],c===void 0?l="c"+d:l=c.id,p=l.length,m=Math.abs(p-5),g=" ",f=" ",p>5?g+=" ":f+=" ",o[i]=g,n+=f+l;console.log(n);var b,O=this.matrix[this.costRowIndex],x=" ";for(a=1;a<this.width;a+=1)b=" ",x+=b,x+=o[a],x+=O[a].toFixed(r);for(b=" ",x+=b+o[0]+O[0].toFixed(r),console.log(x+" Z"),u=1;u<this.height;u+=1){for(N=this.matrix[u],h=" ",i=1;i<this.width;i+=1)b=" ",h+=b+o[i]+N[i].toFixed(r);b=" ",h+=b+o[0]+N[0].toFixed(r),d=this.varIndexByRow[u],c=this.variablesPerIndex[d],c===void 0?l="c"+d:l=c.id,console.log(h+" "+l)}console.log("");var w=this.optionalObjectives.length;if(w>0){console.log(" Optional objectives:");for(var y=0;y<w;y+=1){var L=this.optionalObjectives[y].reducedCosts,D="";for(a=1;a<this.width;a+=1)b=L[a]<0?"":" ",D+=b,D+=o[a],D+=L[a].toFixed(r);b=L[0]<0?"":" ",D+=b+o[0]+L[0].toFixed(r),console.log(D+" z"+y)}}return console.log("Feasible?",this.feasible),console.log("evaluation",this.evaluation),this}});var xr=_(()=>{var Ge=K();Ge.prototype.copy=function(){var e=new Ge(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=[],r=0;r<this.optionalObjectives.length;r++)t[r]=this.optionalObjectives[r].copy();e.optionalObjectives=t;for(var n=this.matrix,o=new Array(this.height),a=0;a<this.height;a++)o[a]=n[a].slice();return e.matrix=o,e};Ge.prototype.save=function(){this.savedState=this.copy()};Ge.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 r,n;for(r=0;r<this.height;r+=1){var o=t[r],a=this.matrix[r];for(n=0;n<this.width;n+=1)a[n]=o[n]}var i=e.varIndexByRow;for(n=0;n<this.height;n+=1)this.varIndexByRow[n]=i[n];for(;this.varIndexByRow.length>this.height;)this.varIndexByRow.pop();var s=e.varIndexByCol;for(r=0;r<this.width;r+=1)this.varIndexByCol[r]=s[r];for(;this.varIndexByCol.length>this.width;)this.varIndexByCol.pop();for(var u=e.rowByVarIndex,c=e.colByVarIndex,d=0;d<this.nVars;d+=1)this.rowByVarIndex[d]=u[d],this.colByVarIndex[d]=c[d];if(e.optionalObjectives.length>0&&this.optionalObjectives.length>0){this.optionalObjectives=[],this.optionalObjectivePerPriority={};for(var l=0;l<e.optionalObjectives.length;l++){var p=e.optionalObjectives[l].copy();this.optionalObjectives[l]=p,this.optionalObjectivePerPriority[p.priority]=p}}}}});var wr=_(()=>{var yr=K();function Or(e,t){this.index=e,this.value=t}yr.prototype.getMostFractionalVar=function(){for(var e=0,t=null,r=null,n=.5,o=this.model.integerVariables,a=o.length,i=0;i<a;i++){var s=o[i].index,u=this.rowByVarIndex[s];if(u!==-1){var c=this.matrix[u][this.rhsColumn],d=Math.abs(c-Math.round(c));e<d&&(e=d,t=s,r=c)}}return new Or(t,r)};yr.prototype.getFractionalVarWithLowestCost=function(){for(var e=1/0,t=null,r=null,n=this.model.integerVariables,o=n.length,a=0;a<o;a++){var i=n[a],s=i.index,u=this.rowByVarIndex[s];if(u!==-1){var c=this.matrix[u][this.rhsColumn];if(Math.abs(c-Math.round(c))>this.precision){var d=i.cost;e>d&&(e=d,t=s,r=c)}}}return new Or(t,r)}});var Dr=_(()=>{var yt=K();yt.prototype.countIntegerValues=function(){for(var e=0,t=1;t<this.height;t+=1)if(this.variablesPerIndex[this.varIndexByRow[t]].isInteger){var r=this.matrix[t][this.rhsColumn];r=r-Math.floor(r),r<this.precision&&-r<this.precision&&(e+=1)}return e};yt.prototype.isIntegral=function(){for(var e=this.model.integerVariables,t=e.length,r=0;r<t;r++){var n=this.rowByVarIndex[e[r].index];if(n!==-1){var o=this.matrix[n][this.rhsColumn];if(Math.abs(o-Math.round(o))>this.precision)return!1}}return!0};yt.prototype.computeFractionalVolume=function(e){for(var t=-1,r=1;r<this.height;r+=1)if(this.variablesPerIndex[this.varIndexByRow[r]].isInteger){var n=this.matrix[r][this.rhsColumn];n=Math.abs(n);var o=Math.min(n-Math.floor(n),Math.floor(n+1));if(o<this.precision){if(!e)return 0}else t===-1?t=n:t*=n}return t===-1?0:t}});var Sr=_((ua,Lr)=>{fr();vr();Nr();br();xr();wr();Dr();Lr.exports=K()});var wt=_(()=>{var Cr=K();function Ir(e,t,r){this.type=e,this.varIndex=t,this.value=r}function Ot(e,t){this.relaxedEvaluation=e,this.cuts=t}function wo(e,t){return t.relaxedEvaluation-e.relaxedEvaluation}Cr.prototype.applyCuts=function(e){if(this.restore(),this.addCutConstraints(e),this.simplex(),this.model.useMIRCuts)for(var t=!0;t;){var r=this.computeFractionalVolume(!0);this.applyMIRCuts(),this.simplex();var n=this.computeFractionalVolume(!0);n>=.9*r&&(t=!1)}};Cr.prototype.branchAndCut=function(){var e=[],t=0,r=this.model.tolerance,n=!0,o=1e99;this.model.timeout&&(o=Date.now()+this.model.timeout);for(var a=1/0,i=null,s=[],u=0;u<this.optionalObjectives.length;u+=1)s.push(1/0);var c=new Ot(-1/0,[]),d;for(e.push(c);e.length>0&&n===!0&&Date.now()<o;)if(this.model.isMinimization?d=this.bestPossibleEval*(1+r):d=this.bestPossibleEval*(1-r),r>0&&a<d&&(n=!1),c=e.pop(),!(c.relaxedEvaluation>a)){var l=c.cuts;if(this.applyCuts(l),t++,this.feasible!==!1){var p=this.evaluation;if(!(p>a)){if(p===a){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}i=c,a=p;for(var f=0;f<this.optionalObjectives.length;f+=1)s[f]=this.optionalObjectives[f].reducedCosts[0]}else{t===1&&this.save();for(var N=this.getMostFractionalVar(),h=N.index,b=[],O=[],x=l.length,w=0;w<x;w+=1){var y=l[w];y.varIndex===h?y.type==="min"?O.push(y):b.push(y):(b.push(y),O.push(y))}var L=Math.ceil(N.value),D=Math.floor(N.value),C=new Ir("min",h,L);b.push(C);var S=new Ir("max",h,D);O.push(S),e.push(new Ot(p,b)),e.push(new Ot(p,O)),e.sort(wo)}}}}i!==null&&this.applyCuts(i.cuts),this.branchAndCutIterations=t}});var Mr=_((pa,zr)=>{var Do=K(),ca=wt(),Se=Re(),qe=Se.Constraint,kr=Se.Equality,Lo=Se.Variable,So=Se.IntegerVariable,fa=Se.Term;function G(e,t){this.tableau=new Do(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=[]}zr.exports=G;G.prototype.minimize=function(){return this.isMinimization=!0,this};G.prototype.maximize=function(){return this.isMinimization=!1,this};G.prototype._getNewElementIndex=function(){if(this.availableIndexes.length>0)return this.availableIndexes.pop();var e=this.lastElementIndex;return this.lastElementIndex+=1,e};G.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)};G.prototype.smallerThan=function(e){var t=new qe(e,!0,this.tableau.getNewElementIndex(),this);return this._addConstraint(t),t};G.prototype.greaterThan=function(e){var t=new qe(e,!1,this.tableau.getNewElementIndex(),this);return this._addConstraint(t),t};G.prototype.equal=function(e){var t=new qe(e,!0,this.tableau.getNewElementIndex(),this);this._addConstraint(t);var r=new qe(e,!1,this.tableau.getNewElementIndex(),this);return this._addConstraint(r),new kr(t,r)};G.prototype.addVariable=function(e,t,r,n,o){if(typeof o=="string")switch(o){case"required":o=0;break;case"strong":o=1;break;case"medium":o=2;break;case"weak":o=3;break;default:o=0;break}var a=this.tableau.getNewElementIndex();t==null&&(t="v"+a),e==null&&(e=0),o==null&&(o=0);var i;return r?(i=new So(t,e,a,o),this.integerVariables.push(i)):i=new Lo(t,e,a,o),this.variables.push(i),this.tableau.variablesPerIndex[a]=i,n&&(this.unrestrictedVariables[a]=!0),this.nVariables+=1,this.tableauInitialized===!0&&this.tableau.addVariable(i),i};G.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)};G.prototype.removeConstraint=function(e){return e.isEquality?(this._removeConstraint(e.upperBound),this._removeConstraint(e.lowerBound)):this._removeConstraint(e),this};G.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};G.prototype.updateRightHandSide=function(e,t){return this.tableauInitialized===!0&&this.tableau.updateRightHandSide(e,t),this};G.prototype.updateConstraintCoefficient=function(e,t,r){return this.tableauInitialized===!0&&this.tableau.updateConstraintCoefficient(e,t,r),this};G.prototype.setCost=function(e,t){var r=e-t.cost;return this.isMinimization===!1&&(r=-r),t.cost=e,this.tableau.updateCost(t,r),this};G.prototype.loadJson=function(e){this.isMinimization=e.opType!=="max";for(var t=e.variables,r=e.constraints,n={},o={},a=Object.keys(r),i=a.length,s=0;s<i;s+=1){var u=a[s],c=r[u],d=c.equal,l=c.weight,p=c.priority,m=l!==void 0||p!==void 0,g,f;if(d===void 0){var N=c.min;N!==void 0&&(g=this.greaterThan(N),n[u]=g,m&&g.relax(l,p));var h=c.max;h!==void 0&&(f=this.smallerThan(h),o[u]=f,m&&f.relax(l,p))}else{g=this.greaterThan(d),n[u]=g,f=this.smallerThan(d),o[u]=f;var b=new kr(g,f);m&&b.relax(l,p)}}var O=Object.keys(t),x=O.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 w=e.ints||{},y=e.binaries||{},L=e.unrestricted||{},D=e.optimize,C=0;C<x;C+=1){var S=O[C],z=t[S],k=z[D]||0,E=!!y[S],V=!!w[S]||E,P=!!L[S],M=this.addVariable(k,S,V,P);E&&this.smallerThan(1).addTerm(1,M);var $=Object.keys(z);for(s=0;s<$.length;s+=1){var j=$[s];if(j!==D){var U=z[j],R=n[j];R!==void 0&&R.addTerm(U,M);var re=o[j];re!==void 0&&re.addTerm(U,M)}}}return this};G.prototype.getNumberOfIntegerVariables=function(){return this.integerVariables.length};G.prototype.solve=function(){return this.tableauInitialized===!1&&(this.tableau.setModel(this),this.tableauInitialized=!0),this.tableau.solve()};G.prototype.isFeasible=function(){return this.tableau.feasible};G.prototype.save=function(){return this.tableau.save()};G.prototype.restore=function(){return this.tableau.restore()};G.prototype.activateMIRCuts=function(e){this.useMIRCuts=e};G.prototype.debug=function(e){this.checkForCycles=e};G.prototype.log=function(e){return this.tableau.log(e)}});var Tr=_(Ar=>{Ar.CleanObjectiveAttributes=function(e){var t,r,n;if(typeof e.optimize=="string")if(e.constraints[e.optimize]){t=Math.random();for(r in e.variables)e.variables[r][e.optimize]&&(e.variables[r][t]=e.variables[r][e.optimize]);return e.constraints[t]=e.constraints[e.optimize],delete e.constraints[e.optimize],e}else return e;else{for(n in e.optimize)if(e.constraints[n])if(e.constraints[n]==="equal")delete e.optimize[n];else{t=Math.random();for(r in e.variables)e.variables[r][n]&&(e.variables[r][t]=e.variables[r][n]);e.constraints[t]=e.constraints[n],delete e.constraints[n]}return e}}});var Ue=_((ma,Vr)=>{function Co(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].*/},r={opType:"",optimize:"_obj",constraints:{},variables:{}},n={">=":"min","<=":"max","=":"equal"},o="",a=0,i=null,s="",u="",c="",d=0;typeof e=="string"&&(e=e.split(`
`));for(var l=0;l<e.length;l++)if(c="__"+l,o=e[l],a=0,i=null,t.is_objective.test(o))r.opType=o.match(/(max|min)/gi)[0],i=o.match(t.parse_lhs).map(function(g){return g.replace(/\s+/,"")}).slice(1),i.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(/\;$/,""),r.variables[u]=r.variables[u]||{},r.variables[u]._obj=s});else if(t.is_int.test(o))i=o.match(t.parse_int).slice(1),r.ints=r.ints||{},i.forEach(function(g){g=g.replace(";",""),r.ints[g]=1});else if(t.is_bin.test(o))i=o.match(t.parse_bin).slice(1),r.binaries=r.binaries||{},i.forEach(function(g){g=g.replace(";",""),r.binaries[g]=1});else if(t.is_constraint.test(o)){var p=o.indexOf(":"),m=p===-1?o:o.slice(p+1);i=m.match(t.parse_lhs).map(function(g){return g.replace(/\s+/,"")}),i.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],r.variables[u]=r.variables[u]||{},r.variables[u][c]=s}),d=parseFloat(o.match(t.parse_rhs)[0]),o=n[o.match(t.parse_dir)[0]],r.constraints[c]=r.constraints[c]||{},r.constraints[c][o]=d}else t.is_unrestricted.test(o)&&(i=o.match(t.parse_int).slice(1),r.unrestricted=r.unrestricted||{},i.forEach(function(g){g=g.replace(";",""),r.unrestricted[g]=1}));return r}function Io(e){if(!e)throw new Error("Solver requires a model to operate on");var t="",r=[],n=1,o={max:"<=",min:">=",equal:"="},a=new RegExp("[^A-Za-z0-9_[{}/.&#$%~'@^]","gi");if(e.opType){t+=e.opType+":";for(var i in e.variables)e.variables[i][i]=e.variables[i][i]?e.variables[i][i]:1,e.variables[i][e.optimize]&&(t+=" "+e.variables[i][e.optimize]+" "+i.replace(a,"_"))}else t+="max:";t+=`;
`;for(var s in e.constraints)for(var u in e.constraints[s])if(typeof o[u]!="undefined"){for(var c in e.variables)typeof e.variables[c][s]!="undefined"&&(t+=" "+e.variables[c][s]+" "+c.replace(a,"_"));t+=" "+o[u]+" "+e.constraints[s][u],t+=`;
`}if(e.ints){t+=`
`;for(var d in e.ints)t+="int "+d.replace(a,"_")+`;
`}if(e.unrestricted){t+=`
`;for(var l in e.unrestricted)t+="unrestricted "+l.replace(a,"_")+`;
`}return t}Vr.exports=function(e){return e.length?Co(e):Io(e)}});var Er=_(()=>{});var Pr=_(()=>{});var _r=_(Dt=>{Dt.reformat=Ue();function Br(e){return e=e.replace("\\r\\n",`\r
`),e=e.split(`\r
`),e=e.filter(function(t){var r;return r=new RegExp(" 0$","gi"),!(r.test(t)===!0||(r=new RegExp("\\d$","gi"),r.test(t)===!1))}).map(function(t){return t.split(/\:{0,1} +(?=\d)/)}).reduce(function(t,r,n){return t[r[0]]=r[1],t},{}),e}Dt.solve=function(e){return new Promise(function(t,r){typeof window!="undefined"&&r("Function Not Available in Browser");var n=Ue()(e);e.external||r("Data for this function must be contained in the 'external' attribute. Not seeing anything there."),e.external.binPath||r("No Executable | Binary path provided in arguments as 'binPath'"),e.external.args||r("No arguments array for cli | bash provided on 'args' attribute"),e.external.tempName||r("No 'tempName' given. This is necessary to produce a staging file for the solver to operate on");var o=Er();o.writeFile(e.external.tempName,n,function(a,i){if(a)r(a);else{var s=Pr().execFile;e.external.args.push(e.external.tempName),s(e.external.binPath,e.external.args,function(u,c){if(u)if(u.code===1)t(Br(c));else{var d={"-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"},l={code:u.code,meaning:d[u.code],data:c};r(l)}else t(Br(c))})}})})}});var Rr=_((ya,Wr)=>{Wr.exports={lpsolve:_r()}});var Lt=_((Oa,$r)=>{$r.exports=function(e,t){var r=t.optimize,n=JSON.parse(JSON.stringify(t.optimize)),o=Object.keys(t.optimize),a,i=0,s={},u="",c={},d=[],l,p,m,g,f;for(delete t.optimize,l=0;l<o.length;l++)n[o[l]]=0;for(l=0;l<o.length;l++){t.optimize=o[l],t.opType=r[o[l]],a=e.Solve(t,void 0,void 0,!0);for(g in o)if(!t.variables[o[g]]){a[o[g]]=a[o[g]]?a[o[g]]:0;for(m in t.variables)t.variables[m][o[g]]&&a[m]&&(a[o[g]]+=a[m]*t.variables[m][o[g]])}for(u="base",p=0;p<o.length;p++)a[o[p]]?u+="-"+(a[o[p]]*1e3|0)/1e3:u+="-0";if(!s[u]){for(s[u]=1,i++,p=0;p<o.length;p++)a[o[p]]&&(n[o[p]]+=a[o[p]]);delete a.feasible,delete a.result,d.push(a)}}for(l=0;l<o.length;l++)t.constraints[o[l]]={equal:n[o[l]]/i};t.optimize="cheater-"+Math.random(),t.opType="max";for(l in t.variables)t.variables[l].cheater=1;for(l in d)for(m in d[l])c[m]=c[m]||{min:1e99,max:-1e99};for(l in c)for(m in d)d[m][l]?(d[m][l]>c[l].max&&(c[l].max=d[m][l]),d[m][l]<c[l].min&&(c[l].min=d[m][l])):(d[m][l]=0,c[l].min=0);return a=e.Solve(t,void 0,void 0,!0),{midpoint:a,vertices:d,ranges:c}}});var Ur=_((wa,qr)=>{var ko=Sr(),St=Mr(),zo=wt(),je=Re(),Gr=Tr(),Mo=je.Constraint,Ao=je.Variable,To=je.Numeral,Vo=je.Term,He=Rr(),Fe=function(){"use strict";this.Model=St,this.branchAndCut=zo,this.Constraint=Mo,this.Variable=Ao,this.Numeral=To,this.Term=Vo,this.Tableau=ko,this.lastSolvedModel=null,this.External=He,this.Solve=function(e,t,r,n){if(n)for(var o in Gr)e=Gr[o](e);if(!e)throw new Error("Solver requires a model to operate on");if(typeof e.optimize=="object"&&Object.keys(e.optimize>1))return Lt()(this,e);if(e.external){var a=Object.keys(He);if(a=JSON.stringify(a),!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:"+a);if(!He[e.external.solver])throw new Error("No support (yet) for "+e.external.solver+". Please use one of these instead:"+a);return He[e.external.solver].solve(e)}else{e instanceof St||(e=new St(t).loadJson(e));var i=e.solve();if(this.lastSolvedModel=e,i.solutionSet=i.generateSolutionSet(),r)return i;var s={};return s.feasible=i.feasible,s.result=i.evaluation,s.bounded=i.bounded,i._tableau.__isIntegral&&(s.isIntegral=!0),Object.keys(i.solutionSet).forEach(function(u){i.solutionSet[u]!==0&&(s[u]=i.solutionSet[u])}),s}},this.ReformatLP=Ue(),this.MultiObjective=function(e){return Lt()(this,e)}};typeof define=="function"?define([],function(){return new Fe}):typeof window=="object"?window.solver=new Fe:typeof self=="object"&&(self.solver=new Fe);qr.exports=new Fe});var Jr=_((Aa,Qr)=>{"use strict";var Ce=1e-60,Fr,Zr;do Ce+=Ce,Fr=1+.1*Ce,Zr=1+.2*Ce;while(Fr<=1||Zr<=1);Qr.exports=Ce});var Yr=_((Ta,Kr)=>{"use strict";function Po(e,t,r){let n,o;for(let a=1;a<=r;a+=1){e[a][a]=1/e[a][a],o=-e[a][a];for(let i=1;i<a;i+=1)e[i][a]*=o;if(n=a+1,r<n)break;for(let i=n;i<=r;i+=1){o=e[a][i],e[a][i]=0;for(let s=1;s<=a;s+=1)e[s][i]+=o*e[s][a]}}}Kr.exports=Po});var en=_((Va,Xr)=>{"use strict";function Bo(e,t,r,n){let o,a;for(o=1;o<=r;o+=1){a=0;for(let i=1;i<o;i+=1)a+=e[i][o]*n[i];n[o]=(n[o]-a)/e[o][o]}for(let i=1;i<=r;i+=1){o=r+1-i,n[o]/=e[o][o],a=-n[o];for(let s=1;s<o;s+=1)n[s]+=a*e[s][o]}}Xr.exports=Bo});var rn=_((Ea,tn)=>{"use strict";function _o(e,t,r,n){let o,a,i;for(let s=1;s<=r;s+=1){if(n[1]=s,i=0,o=s-1,o<1){if(i=e[s][s]-i,i<=0)break;e[s][s]=Math.sqrt(i)}else{for(let u=1;u<=o;u+=1){a=e[u][s];for(let c=1;c<u;c+=1)a-=e[c][s]*e[c][u];a/=e[u][u],e[u][s]=a,i+=a*a}if(i=e[s][s]-i,i<=0)break;e[s][s]=Math.sqrt(i)}n[1]=0}}tn.exports=_o});var on=_((Pa,nn)=>{"use strict";var It=Jr(),Wo=Yr(),Ro=en(),$o=rn();function Go(e,t,r,n,o,a,i,s,u,c,d,l,p,m=0,g,f,N){let h,b,O,x,w,y,L,D,C,S,z,k,E,V,P=Math.min(n,d),M=2*n+P*(P+5)/2+2*d+1;for(let v=1;v<=n;v+=1)f[v]=t[v];for(let v=n+1;v<=M;v+=1)f[v]=0;for(let v=1;v<=d;v+=1)p[v]=0,a[v]=0;let $=[];if(N[1]===0){if($o(e,r,n,$),$[1]!==0){N[1]=2;return}Ro(e,r,n,t),Wo(e,r,n)}else{for(let v=1;v<=n;v+=1){o[v]=0;for(let I=1;I<=v;I+=1)o[v]+=e[I][v]*t[I]}for(let v=1;v<=n;v+=1){t[v]=0;for(let I=v;I<=n;I+=1)t[v]+=e[v][I]*o[I]}}i[1]=0;for(let v=1;v<=n;v+=1){o[v]=t[v],i[1]+=f[v]*o[v],f[v]=0;for(let I=v+1;I<=n;I+=1)e[I][v]=0}i[1]=-i[1]/2,N[1]=0;let j=n,U=j+n,R=U+P,re=R+P+1,Y=re+P*(P+1)/2,at=Y+d;for(let v=1;v<=d;v+=1){y=0;for(let I=1;I<=n;I+=1)y+=s[I][v]*s[I][v];f[at+v]=Math.sqrt(y)}x=m,g[1]=0,g[2]=0;function qn(){g[1]+=1,M=Y;for(let v=1;v<=d;v+=1){M+=1,y=-u[v];for(let I=1;I<=n;I+=1)y+=s[I][v]*o[I];if(Math.abs(y)<It&&(y=0),v>l)f[M]=y;else if(f[M]=-Math.abs(y),y>0){for(let I=1;I<=n;I+=1)s[I][v]=-s[I][v];u[v]=-u[v]}}for(let v=1;v<=x;v+=1)f[Y+p[v]]=0;O=0,w=0;for(let v=1;v<=d;v+=1)f[Y+v]<w*f[at+v]&&(O=v,w=f[Y+v]/f[at+v]);if(O===0){for(let v=1;v<=x;v+=1)a[p[v]]=f[R+v];return 999}return 0}function Un(){for(let v=1;v<=n;v+=1){y=0;for(let I=1;I<=n;I+=1)y+=e[I][v]*s[I][O];f[v]=y}h=j;for(let v=1;v<=n;v+=1)f[h+v]=0;for(let v=x+1;v<=n;v+=1)for(let I=1;I<=n;I+=1)f[h+I]=f[h+I]+e[I][v]*f[v];k=!0;for(let v=x;v>=1;v-=1){y=f[v],M=re+v*(v+3)/2,h=M-v;for(let I=v+1;I<=x;I+=1)y-=f[M]*f[U+I],M+=I;y/=f[h],f[U+v]=y,!(p[v]<=l)&&(y<=0||(k=!1,b=v))}if(!k){L=f[R+b]/f[U+b];for(let v=1;v<=x;v+=1)p[v]<=l||f[U+v]<=0||(w=f[R+v]/f[U+v],w<L&&(L=w,b=v))}y=0;for(let v=j+1;v<=j+n;v+=1)y+=f[v]*f[v];if(Math.abs(y)<=It){if(k)return N[1]=1,999;for(let v=1;v<=x;v+=1)f[R+v]=f[R+v]-L*f[U+v];return f[R+x+1]=f[R+x+1]+L,700}y=0;for(let v=1;v<=n;v+=1)y+=f[j+v]*s[v][O];D=-f[Y+O]/y,E=!0,k||L<D&&(D=L,E=!1);for(let v=1;v<=n;v+=1)o[v]+=D*f[j+v],Math.abs(o[v])<It&&(o[v]=0);i[1]+=D*y*(D/2+f[R+x+1]);for(let v=1;v<=x;v+=1)f[R+v]=f[R+v]-D*f[U+v];if(f[R+x+1]=f[R+x+1]+D,E){x+=1,p[x]=O,M=re+(x-1)*x/2+1;for(let v=1;v<=x-1;v+=1)f[M]=f[v],M+=1;if(x===n)f[M]=f[n];else{for(let v=n;v>=x+1;v-=1)if(f[v]!==0&&(C=Math.max(Math.abs(f[v-1]),Math.abs(f[v])),S=Math.min(Math.abs(f[v-1]),Math.abs(f[v])),f[v-1]>=0?w=Math.abs(C*Math.sqrt(1+S*S/(C*C))):w=-Math.abs(C*Math.sqrt(1+S*S/(C*C))),C=f[v-1]/w,S=f[v]/w,C!==1))if(C===0){f[v-1]=S*w;for(let I=1;I<=n;I+=1)w=e[I][v-1],e[I][v-1]=e[I][v],e[I][v]=w}else{f[v-1]=w,z=S/(1+C);for(let I=1;I<=n;I+=1)w=C*e[I][v-1]+S*e[I][v],e[I][v]=z*(e[I][v-1]+w)-e[I][v],e[I][v-1]=w}f[M]=f[x]}}else{y=-u[O];for(let v=1;v<=n;v+=1)y+=o[v]*s[v][O];if(O>l)f[Y+O]=y;else if(f[Y+O]=-Math.abs(y),y>0){for(let v=1;v<=n;v+=1)s[v][O]=-s[v][O];u[O]=-u[O]}return 700}return 0}function jn(){if(M=re+b*(b+1)/2+1,h=M+b,f[h]===0||(C=Math.max(Math.abs(f[h-1]),Math.abs(f[h])),S=Math.min(Math.abs(f[h-1]),Math.abs(f[h])),f[h-1]>=0?w=Math.abs(C*Math.sqrt(1+S*S/(C*C))):w=-Math.abs(C*Math.sqrt(1+S*S/(C*C))),C=f[h-1]/w,S=f[h]/w,C===1))return 798;if(C===0){for(let v=b+1;v<=x;v+=1)w=f[h-1],f[h-1]=f[h],f[h]=w,h+=v;for(let v=1;v<=n;v+=1)w=e[v][b],e[v][b]=e[v][b+1],e[v][b+1]=w}else{z=S/(1+C);for(let v=b+1;v<=x;v+=1)w=C*f[h-1]+S*f[h],f[h]=z*(f[h-1]+w)-f[h],f[h-1]=w,h+=v;for(let v=1;v<=n;v+=1)w=C*e[v][b]+S*e[v][b+1],e[v][b+1]=z*(e[v][b]+w)-e[v][b+1],e[v][b]=w}return 0}function Hn(){h=M-b;for(let v=1;v<=b;v+=1)f[h]=f[M],M+=1,h+=1;return f[R+b]=f[R+b+1],p[b]=p[b+1],b+=1,b<x?797:0}function _t(){return f[R+x]=f[R+x+1],f[R+x+1]=0,p[x]=0,x-=1,g[2]+=1,0}for(V=0;;){if(V=qn(),V===999)return;for(;V=Un(),V!==0;){if(V===999)return;if(V===700)if(b===x)_t();else{for(;jn(),V=Hn(),V===797;);_t()}}}}nn.exports=Go});var sn=_(an=>{"use strict";var qo=on();function Uo(e,t,r,n=[],o=0,a=[0,0]){let i=[],s=[],u=[],c=[],d=[],l=[],p="",m=e.length-1,g=r[1].length-1;if(!n)for(let h=1;h<=g;h+=1)n[h]=0;if(m!==e[1].length-1&&(p="Dmat is not symmetric!"),m!==t.length-1&&(p="Dmat and dvec are incompatible!"),m!==r.length-1&&(p="Amat and dvec are incompatible!"),g!==n.length-1&&(p="Amat and bvec are incompatible!"),(o>g||o<0)&&(p="Value of meq is invalid!"),p!=="")return{message:p};for(let h=1;h<=g;h+=1)s[h]=0,c[h]=0;let f=0,N=Math.min(m,g);for(let h=1;h<=m;h+=1)u[h]=0;i[1]=0;for(let h=1;h<=2*m+N*(N+5)/2+2*g+1;h+=1)d[h]=0;for(let h=1;h<=2;h+=1)l[h]=0;return qo(e,t,m,m,u,c,i,r,n,m,g,o,s,f,l,d,a),a[1]===1&&(p="constraints are inconsistent, no solution!"),a[1]===2&&(p="matrix D in quadratic function is not positive definite!"),{solution:u,Lagrangian:c,value:i,unconstrained_solution:t,iterations:l,iact:s,message:p}}an.solveQP=Uo});var dn=_((_a,un)=>{"use strict";un.exports=sn()});var An=_((Fs,Mn)=>{"use strict";var ni=function(e,t){return e<t};function q(e){if(!(this instanceof q))return new q(e);this.array=[],this.size=0,this.compare=e||ni}q.prototype.clone=function(){var e=new q(this.compare);return e.size=this.size,e.array=this.array.slice(0,this.size),e};q.prototype.add=function(e){var t=this.size;this.array[this.size]=e,this.size+=1;for(var r,n;t>0&&(r=t-1>>1,n=this.array[r],!!this.compare(e,n));)this.array[t]=n,t=r;this.array[t]=e};q.prototype.heapify=function(e){this.array=e,this.size=e.length;var t;for(t=this.size>>1;t>=0;t--)this._percolateDown(t)};q.prototype._percolateUp=function(e,t){for(var r=this.array[e],n,o;e>0&&(n=e-1>>1,o=this.array[n],!(!t&&!this.compare(r,o)));)this.array[e]=o,e=n;this.array[e]=r};q.prototype._percolateDown=function(e){for(var t=this.size,r=this.size>>>1,n=this.array[e],o,a,i;e<r&&(o=(e<<1)+1,a=o+1,i=this.array[o],a<t&&this.compare(this.array[a],i)&&(o=a,i=this.array[a]),!!this.compare(i,n));)this.array[e]=i,e=o;this.array[e]=n};q.prototype._removeAt=function(e){if(!(e>this.size-1||e<0))return this._percolateUp(e,!0),this.poll()};q.prototype.remove=function(e){for(var t=0;t<this.size;t++)if(!this.compare(this.array[t],e)&&!this.compare(e,this.array[t]))return this._removeAt(t),!0;return!1};q.prototype.removeOne=function(e){if(typeof e=="function"){for(var t=0;t<this.size;t++)if(e(this.array[t]))return this._removeAt(t)}};q.prototype.removeMany=function(e,t){if(typeof e!="function"||this.size<1)return[];t=t?Math.min(t,this.size):this.size;for(var r=0,n=new Array(t),o=0,a=new Array(this.size);r<t&&!this.isEmpty();){var i=this.poll();e(i)?n[r++]=i:a[o++]=i}n.length=r;for(var s=0;s<o;)this.add(a[s++]);return n};q.prototype.peek=function(){if(this.size!=0)return this.array[0]};q.prototype.poll=function(){if(this.size!=0){var e=this.array[0];return this.size>1?(this.array[0]=this.array[--this.size],this._percolateDown(0)):this.size-=1,e}};q.prototype.replaceTop=function(e){if(this.size!=0){var t=this.array[0];return this.array[0]=e,this._percolateDown(0),t}};q.prototype.trim=function(){this.array=this.array.slice(0,this.size)};q.prototype.isEmpty=function(){return this.size===0};q.prototype.forEach=function(e){if(!(this.isEmpty()||typeof e!="function"))for(var t=0,r=this.clone();!r.isEmpty();)e(r.poll(),t++)};q.prototype.kSmallest=function(e){if(this.size==0)return[];e=Math.min(this.size,e);var t=new q(this.compare);let r=Math.min((e>0?Math.pow(2,e-1):0)+1,this.size);t.size=r,t.array=this.array.slice(0,r);for(var n=new Array(e),o=0;o<e;o++)n[o]=t.poll();return n};Mn.exports=q});var oi={};Xn(oi,{aggMeanFactory:()=>hn,aggMedianFactory:()=>zt,coordCenter:()=>Ln,coordGreedy:()=>Sn,coordQuad:()=>In,coordSimplex:()=>et,coordTopological:()=>kn,dagConnect:()=>Qt,dagHierarchy:()=>Ae,dagStratify:()=>er,decrossOpt:()=>zn,decrossTwoLayer:()=>tt,grid:()=>ir,laneGreedy:()=>Be,laneOpt:()=>Hr,layeringCoffmanGraham:()=>En,layeringLongestPath:()=>Bn,layeringSimplex:()=>rt,layeringTopological:()=>_n,sugiCoordVertical:()=>Vt,sugify:()=>ot,sugiyama:()=>Dn,twolayerAgg:()=>ge,twolayerGreedy:()=>nt,twolayerOpt:()=>Wn,unsugify:()=>it,zherebko:()=>Gn});function*Q(e){let t=0;for(let r of e)yield[t++,r]}function*Z(e,t){for(let[r,n]of Q(e))yield*t(n,r)}function dt(e,t,r){let n=t,o=r;for(let[a,i]of Q(e))o=n(o,i,a);return o}function*W(e,t){for(let[r,n]of Q(e))yield t(n,r)}function*qt(e,t){for(let[r,n]of Q(e))t(n,r)&&(yield n)}function fe(e,t){for(let[r,n]of Q(e))if(t(n,r))return!0;return!1}function Ut(e,t){return!fe(e,(r,n)=>!t(r,n))}function*jt(e){for(let t=e.length;t!=0;)yield e[--t]}function Ne(e){if(!e)throw new Error("internal error: failed assert")}function Ht(e,t){if(t.size!==e.size)return!1;for(let r of e)if(!t.has(r))return!1;return!0}function Ft(e,t){t.size<e.size&&([t,e]=[e,t]);for(let r of e)if(t.has(r))return!0;return!1}function ke(e){let{done:t,value:r}=e.values().next();if(!t)return e.delete(r),r}function se(e,t,r){let n=e.get(t);n===void 0?e.set(t,[r]):n.push(r)}function ze(e,t,r){let n=e.get(t);n===void 0?e.set(t,new Set([r])):n.add(r)}function to(){let e=new WeakSet;return(t,r)=>{if(typeof r=="object"&&r!==null){if(e.has(r))return"[circular]";e.add(r)}return r}}function H(e,...t){let[r,...n]=e;return[r].concat(...n.map((o,a)=>[JSON.stringify(t[a],to()),o])).join("")}function*F(e){let[t,...r]=e;for(let n of r)yield[t,n],t=n}function*ue(e,...t){let r=new Set,n;for(;(n=t.pop())!==void 0;)r.has(n)||(yield n,r.add(n),t.push(...e(n)))}function J(e){let t=new Map;for(let r of e)for(let n of r.ichildren())se(t,n,r);return t}function Me(e){let t=new Map;for(let r of e)for(let[n,o]of r.ichildrenCounts())se(t,n,[r,o]);return t}var be=class{constructor(t,r,n=[],o=!1){this.child=t;this.data=r;this.points=n;this.reversed=o}},Zt=class{constructor(t,r,n,o,a){this.source=t;this.target=r;this.data=n;this.points=o;this.reversed=a}},ne=class{constructor(t){t&&(this.proots=t)}[Symbol.iterator](){return this.idescendants()[Symbol.iterator]()}iroots(){return{[Symbol.iterator]:()=>this.proots[Symbol.iterator]()}}roots(){return[...this.iroots()]}*idepth(){yield*ue(r=>r.ichildren(),...this.iroots())}*ibreadth(){let t=new Set,r=this.roots(),n=[];do{n=r.reverse(),r=[];let o;for(;o=n.pop();)t.has(o)||(t.add(o),yield o,r.push(...o.ichildren()))}while(r.length)}*ibefore(){let t=new Map;for(let o of this)for(let a of o.ichildren())t.set(a,(t.get(a)||0)+1);let r=this.roots(),n;for(;n=r.pop();){yield n;for(let o of n.ichildren()){let a=t.get(o);a>1?t.set(o,a-1):r.push(o)}}}*iafter(){let t=this.roots(),r=new Set,n;for(;n=t.pop();)r.has(n)||(Ut(n.ichildren(),o=>r.has(o))?(r.add(n),yield n):t.push(n,...n.ichildren()))}idescendants(t="depth"){if(t==="depth")return this.idepth();if(t==="breadth")return this.ibreadth();if(t==="before")return this.ibefore();if(t==="after")return this.iafter();throw new Error(`unknown iteration style: ${t}`)}descendants(t="depth"){return[...this.idescendants(t)]}ilinks(){return Z(this,t=>t.ichildLinks())}links(){return[...this.ilinks()]}size(){return dt(this,t=>t+1,0)}sum(t){let r=new Map;for(let[n,o]of Q(this.idescendants("after"))){let a=t(o,n),i=new Map;i.set(o,a);for(let s of o.ichildren()){let u=r.get(s);for(let[c,d]of u.entries())i.set(c,d)}o.value=dt(i.values(),(s,u)=>s+u,0),r.set(o,i)}return this}count(){let t=new Map;for(let r of this.idescendants("after"))if(r.ichildren()[Symbol.iterator]().next().done)t.set(r,new Set([r])),r.value=1;else{let n=new Set;for(let o of r.ichildren()){let a=t.get(o);for(let i of a)n.add(i)}t.set(r,n),r.value=n.size}return this}height(){for(let t of this.idescendants("after"))t.value=Math.max(0,...W(t.ichildren(),r=>r.value+1));return this}depth(){var r;let t=J(this);for(let n of this.idescendants("before"))n.value=Math.max(0,...W((r=t.get(n))!=null?r:[],o=>o.value+1));return this}*isplit(){let t=J(this);function*r(o){var a;yield*o.ichildren(),yield*(a=t.get(o))!=null?a:[]}let n=new Set(this.iroots());for(let o of this.iroots()){if(!n.delete(o))continue;let a=[o];for(let i of ue(r,o))n.delete(i)&&a.push(i);yield a.length>1?new ne(a):a[0]}}split(){return[...this.isplit()]}connected(){let t=this.isplit()[Symbol.iterator]();t.next();let{done:r}=t.next();return!!r}multidag(){return this.pmultidag===void 0?this.pmultidag=fe(this.iroots(),t=>t.multidag()):this.pmultidag}},xe=class extends ne{constructor(t){super();this.data=t;this.dataChildren=[]}childrenCountsMap(){var t;if(this.cachedChildrenCounts===void 0){let r=new Map;for(let{child:n}of this.dataChildren)r.set(n,((t=r.get(n))!=null?t:0)+1);return this.cachedChildrenCounts=r.size===this.dataChildren.length?null:r}else return this.cachedChildrenCounts}iroots(){let t=[this];return{[Symbol.iterator]:()=>t[Symbol.iterator]()}}nchildren(){var t,r;return(r=(t=this.childrenCountsMap())==null?void 0:t.size)!=null?r:this.dataChildren.length}nchildLinks(){return this.dataChildren.length}nchildLinksTo(t){var r,n;return(n=(r=this.childrenCountsMap())==null?void 0:r.get(t))!=null?n:1}*ichildren(){let t=this.childrenCountsMap();if(t===null)for(let{child:r}of this.dataChildren)yield r;else yield*t.keys()}children(){return[...this.ichildren()]}*ichildrenCounts(){let t=this.childrenCountsMap();if(t===null)for(let{child:r}of this.dataChildren)yield[r,1];else yield*t}childrenCounts(){return[...this.ichildrenCounts()]}*ichildLinks(){for(let{child:t,data:r,points:n,reversed:o}of this.dataChildren)yield new Zt(this,t,r,n,o)}childLinks(){return[...this.ichildLinks()]}isplit(){return this.iroots()}split(){return this.roots()}connected(){return!0}multidag(){return this.pmultidag===void 0?this.pmultidag=this.childrenCountsMap()!==null||fe(this.ichildren(),t=>t.multidag()):this.pmultidag}};function lt(e){if(typeof e!="string")throw new Error(`id is supposed to be string but got type ${typeof e}`);return e}function ct(e,t){if(!e.length)throw new Error("dag contained no roots; this often indicates a cycle");for(let i of new ne(e))for(let s of i.ichildren())if(s===i)throw new Error(H`node '${i.data}' contained a self loop`);if(!t)return;let r=new Set,n=new Set,o=null;function a(i){if(r.has(i))return[];if(n.has(i))return o=i,[i];{n.add(i);let s=[];for(let u of i.ichildren())if(s=a(u),s.length)break;return n.delete(i),r.add(i),s.length&&o!==null&&s.push(i),o===i&&(o=null),s}}for(let i of e){let s=a(i);if(s.length){let u=s.reverse().map(({data:c})=>H`'${c}'`).join(" -> ");throw new Error(`dag contained a cycle: ${u}`)}}}function ro(e){return e&&ke(e)}function ft(e){var m,g,f;let t=new Map;for(let N of e)for(let{child:h}of N.dataChildren)se(t,h,N);let r=new Map(W(e,N=>{var h,b;return[N,{indeg:(b=(h=t.get(N))==null?void 0:h.length)!=null?b:0,outdeg:N.nchildLinks(),node:N}]})),n=Math.max(...W(qt(r.values(),({indeg:N,outdeg:h})=>N>0&&h>0),({indeg:N,outdeg:h})=>h-N));if(n===-1/0){let N=[];for(let{indeg:h,node:b}of r.values())h===0&&N.push(b);return N}let o=new Set,a=new Set,i=new Map;for(let N of r.values()){let{outdeg:h,indeg:b}=N;if(b===0)o.add(N);else if(h===0)a.add(N);else{let O=h-b;ze(i,O,N)}}let s=0,u=e.length,c=n,d=new Array(e.length);for(;s<u;){let N=(g=(m=ke(o))!=null?m:ke(a))!=null?g:ro(i.get(c));if(N===void 0)--c;else{let{node:h,indeg:b,outdeg:O}=N,x=N.rank=b>0&&O===0?--u:s++;d[x]=h;for(let w of(f=t.get(h))!=null?f:[]){let y=r.get(w);if(y.rank===void 0&&y.indeg>0&&y.outdeg>0){let L=y.outdeg-y.indeg;i.get(L).delete(y),--y.outdeg,y.outdeg>0?ze(i,L-1,y):a.add(y)}}for(let{child:w}of h.dataChildren){let y=r.get(w);if(!(y.rank!==void 0||y.indeg===0))if(y.outdeg===0)--y.indeg,y.indeg===0&&(a.delete(y),o.add(y));else{let L=y.outdeg-y.indeg;L===c&&++c,i.get(L).delete(y),--y.indeg,y.indeg===0?o.add(y):ze(i,L+1,y)}}}}let l=[],p=new Set;for(let[N,h]of d.entries()){let b=[];for(let O of h.dataChildren){let x=r.get(O.child);x.rank<N?x.node.dataChildren.push(new be(h,O.data,O.points,!0)):b.push(O)}b.length===h.nchildLinks()&&!p.has(h)&&l.push(h);for(let{child:O}of b)p.add(O);h.dataChildren=b}return l}function no(e,t){let r=[];for(let[n,o]of e.entries())t.has(n)||r.push(o);return r}function pe(e){function t(s){if(!s.length)throw new Error("can't connect empty data");let u=new Map,c=new Set;for(let[l,p]of s.entries()){let m=lt(e.sourceId(p,l)),g=u.get(m);g===void 0&&(g=new xe(e.nodeDatum(m,l)),u.set(m,g));let f=lt(e.targetId(p,l)),N=u.get(f);N===void 0&&(N=new xe(e.nodeDatum(f,l)),u.set(f,N)),(m!==f||!e.single)&&(g.dataChildren.push(new be(N,p)),c.add(f))}let d=e.decycle?ft([...u.values()]):no(u,c);return ct(d,!e.decycle),d.length>1?new ne(d):d[0]}function r(s){if(s===void 0)return e.sourceId;{let u=e,{sourceId:c}=u,d=B(u,["sourceId"]);return pe(T(A({},d),{sourceId:s}))}}t.sourceId=r;function n(s){if(s===void 0)return e.targetId;{let u=e,{targetId:c}=u,d=B(u,["targetId"]);return pe(T(A({},d),{targetId:s}))}}t.targetId=n;function o(s){if(s===void 0)return e.nodeDatum;{let u=e,{nodeDatum:c}=u,d=B(u,["nodeDatum"]);return pe(T(A({},d),{nodeDatum:s}))}}t.nodeDatum=o;function a(s){return s===void 0?e.single:pe(T(A({},e),{single:s}))}t.single=a;function i(s){return s===void 0?e.decycle:pe(T(A({},e),{decycle:s}))}return t.decycle=i,t}function oo(e){try{return typeof e[0]=="string"}catch(t){return!1}}function io(e){if(oo(e))return e[0];throw new Error(`default source id expected datum[0] to be a string but got datum: ${e}`)}function ao(e){try{return typeof e[1]=="string"}catch(t){return!1}}function so(e){if(ao(e))return e[1];throw new Error(`default target id expected datum[1] to be a string but got datum: ${e}`)}function uo(e){return{id:e}}function Qt(...e){if(e.length)throw new Error(`got arguments to connect(${e}), but constructor takes no arguments. These were probably meant as data which should be called as connect()(...)`);return pe({sourceId:io,targetId:so,nodeDatum:uo,single:!1,decycle:!1})}function ye(e){function t(...i){var f;if(!i.length)throw new Error("must pass in at least one node");let s=new Map,u=[];function c(N){let h=s.get(N);return h===void 0&&(h=new xe(N),s.set(N,h),u.push(h)),h}let d=i.map(c),l,p=0;for(;l=u.pop();)l.dataChildren=((f=e.childrenData(l.data,p++))!=null?f:[]).map(([N,h])=>new be(c(N),h));let m=new Set(d);for(let N of s.values())for(let{child:h}of N.dataChildren)if(m.delete(h)&&e.roots)throw new Error(H`node '${N.data}' pointed to a root`);let g=e.decycle?ft([...s.values()]):m.size?[...m]:d;return ct(g,!e.decycle),g.length>1?new ne(g):g[0]}function r(i){if(i===void 0)return e.children;{let s=e,{children:u,childrenData:c}=s,d=B(s,["children","childrenData"]);return ye(T(A({},d),{children:i,childrenData:Jt(i)}))}}t.children=r;function n(i){if(i===void 0)return e.childrenData;{let s=e,{children:u,childrenData:c}=s,d=B(s,["children","childrenData"]);return ye(T(A({},d),{children:lo(i),childrenData:i}))}}t.childrenData=n;function o(i){return i===void 0?e.roots:ye(T(A({},e),{roots:i}))}t.roots=o;function a(i){return i===void 0?e.decycle:ye(T(A({},e),{decycle:i}))}return t.decycle=a,t}function Jt(e){function t(r,n){var o;return((o=e(r,n))!=null?o:[]).map(a=>[a,void 0])}return t.wrapped=e,t}function lo(e){function t(r,n){var o;return((o=e(r,n))!=null?o:[]).map(([a])=>a)}return t.wrapped=e,t}function co(e){try{let t=e.children;return t===void 0||t instanceof Array}catch(t){return!1}}function Kt(e){if(co(e))return e.children;throw new Error(H`default children function expected datum to have a children field but got: ${e}`)}function Ae(...e){if(e.length)throw new Error(`got arguments to hierarchy(${e}), but constructor takes no arguments. These were probably meant as data which should be called as hierarchy()(...)`);return ye({children:Kt,childrenData:Jt(Kt),roots:!0,decycle:!1})}function Oe(e){function t(i){var d;if(!i.length)throw new Error("can't stratify empty data");let s=new Map;for(let[l,p]of i.entries()){let m=lt(e.id(p,l)),g=(d=e.parentData(p,l))!=null?d:[],f=new xe(p);if(s.has(m))throw new Error(`found a duplicate id: ${r}`);s.set(m,[f,g])}let u=[];for(let[l,p]of s.values()){for(let[m,g]of p){let f=s.get(m);if(!f)throw new Error(`missing id: ${m}`);let[N]=f;N.dataChildren.push(new be(l,g))}p.length||u.push(l)}let c=e.decycle?ft([...W(s.values(),([l])=>l)]):u;return ct(c,!e.decycle),c.length>1?new ne(c):c[0]}function r(i){if(i===void 0)return e.id;{let s=e,{id:u}=s,c=B(s,["id"]);return Oe(T(A({},c),{id:i}))}}t.id=r;function n(i){if(i===void 0)return e.parentData;{let s=e,{parentIds:u,parentData:c}=s,d=B(s,["parentIds","parentData"]);return Oe(T(A({},d),{parentIds:fo(i),parentData:i}))}}t.parentData=n;function o(i){if(i===void 0)return e.parentIds;{let s=e,{parentIds:u,parentData:c}=s,d=B(s,["parentIds","parentData"]);return Oe(T(A({},d),{parentIds:i,parentData:Yt(i)}))}}t.parentIds=o;function a(i){return i===void 0?e.decycle:Oe(T(A({},e),{decycle:i}))}return t.decycle=a,t}function Yt(e){function t(r,n){var o;return((o=e(r,n))!=null?o:[]).map(a=>[a,void 0])}return t.wrapped=e,t}function fo(e){function t(r,n){var o;return((o=e(r,n))!=null?o:[]).map(([a])=>a)}return t.wrapped=e,t}function po(e){try{return typeof e.id=="string"}catch(t){return!1}}function ho(e){if(po(e))return e.id;throw new Error(H`default id function expected datum to have an id field but got '${e}'`)}function mo(e){try{let t=e.parentIds;return t===void 0||t instanceof Array&&t.every(r=>typeof r=="string")}catch(t){return!1}}function Xt(e){if(mo(e))return e.parentIds;throw new Error(`default parentIds function expected datum to have a parentIds field but got: ${e}`)}function er(...e){if(e.length)throw new Error(`got arguments to stratify(${e}), but constructor takes no arguments. These were probably meant as data which should be called as stratify()(...)`);return Oe({id:ho,parentIds:Xt,parentData:Yt(Xt),decycle:!1})}function oe(e,t){return e==null||t==null?NaN:e<t?-1:e>t?1:e>=t?0:NaN}function*tr(e,t){if(t===void 0)for(let r of e)r!=null&&(r=+r)>=r&&(yield r);else{let r=-1;for(let n of e)(n=t(n,++r,e))!=null&&(n=+n)>=n&&(yield n)}}function rr(e=oe){if(e===oe)return pt;if(typeof e!="function")throw new TypeError("compare is not a function");return(t,r)=>{let n=e(t,r);return n||n===0?n:(e(r,r)===0)-(e(t,t)===0)}}function pt(e,t){return(e==null||!(e>=e))-(t==null||!(t>=t))||(e<t?-1:e>t?1:0)}function Te(e,t){let r;if(t===void 0)for(let n of e)n!=null&&(r<n||r===void 0&&n>=n)&&(r=n);else{let n=-1;for(let o of e)(o=t(o,++n,e))!=null&&(r<o||r===void 0&&o>=o)&&(r=o)}return r}function Ve(e,t){let r;if(t===void 0)for(let n of e)n!=null&&(r>n||r===void 0&&n>=n)&&(r=n);else{let n=-1;for(let o of e)(o=t(o,++n,e))!=null&&(r>o||r===void 0&&o>=o)&&(r=o)}return r}function Ee(e,t,r=0,n=e.length-1,o){for(o=o===void 0?pt:rr(o);n>r;){if(n-r>600){let u=n-r+1,c=t-r+1,d=Math.log(u),l=.5*Math.exp(2*d/3),p=.5*Math.sqrt(d*l*(u-l)/u)*(c-u/2<0?-1:1),m=Math.max(r,Math.floor(t-c*l/u+p)),g=Math.min(n,Math.floor(t+(u-c)*l/u+p));Ee(e,t,m,g,o)}let a=e[t],i=r,s=n;for(we(e,r,t),o(e[n],a)>0&&we(e,r,n);i<s;){for(we(e,i,s),++i,--s;o(e[i],a)<0;)++i;for(;o(e[s],a)>0;)--s}o(e[r],a)===0?we(e,r,s):(++s,we(e,s,n)),s<=t&&(r=s+1),t<=s&&(n=s-1)}return e}function we(e,t,r){let n=e[t];e[t]=e[r],e[r]=n}function ht(e,t,r){if(e=Float64Array.from(tr(e,r)),!!(n=e.length)){if((t=+t)<=0||n<2)return Ve(e);if(t>=1)return Te(e);var n,o=(n-1)*t,a=Math.floor(o),i=Te(Ee(e,a).subarray(0,a+1)),s=Ve(e.subarray(a+1));return i+(s-i)*(o-a)}}function he(e,t){return ht(e,.5,t)}function De(e,t=oe){let r,n=!1;if(t.length===1){let o;for(let a of e){let i=t(a);(n?oe(i,o)<0:oe(i,i)===0)&&(r=a,o=i,n=!0)}}else for(let o of e)(n?t(o,r)<0:t(o,o)===0)&&(r=o,n=!0);return r}var nr=class{constructor(t){this.uncompressed=t;this.indices=[]}getIndex(t,r){var i;let n=[];for(let[s,u]of this.indices.entries())u<=t&&n.push(s);this.uncompressed&&n.push(this.indices.length);let o=r!=null?r:0,a=(i=De(n,s=>[Math.abs(o-s),s]))!=null?i:this.indices.length;return this.setIndex(a,t),a}setIndex(t,r){this.indices[t]=r}offset(){return 0}},or=class{constructor(t){this.uncompressed=t;this.posIndices=[0];this.negIndices=[]}nextNeg(){return-this.negIndices.length-1}nextPos(){return this.posIndices.length}getIndex(t,r){var s;let n=[];for(let[u,c]of this.negIndices.entries())c<=t&&n.push(-u-1);for(let[u,c]of this.posIndices.entries())c<=t&&n.push(u);this.uncompressed&&(n.push(this.nextNeg()),n.push(this.nextPos()));let o=r!=null?r:0,a=this.negIndices.length<this.posIndices.length-1?this.nextNeg():this.nextPos(),i=(s=De(n,u=>[Math.abs(o-u),Math.abs(u),-u]))!=null?s:a;return this.setIndex(i,t),i}setIndex(t,r){t<0?this.negIndices[-t-1]=r:this.posIndices[t]=r}offset(){return this.negIndices.length}};function go(e,t){return t?new or(!e):new nr(!e)}function vo(e,t){for(let n of e)n.x=void 0;for(let n of e){n.x===void 0&&(n.x=t.getIndex(n.y));for(let o of[...n.ichildren()].sort((a,i)=>i.y-a.y))o.x===void 0&&(o.x=t.getIndex(n.y,n.x),t.setIndex(o.x,o.y))}let r=t.offset();for(let n of e)n.x+=r}function No(e,t){var o;let r=new Map;for(let a of e){a.x=void 0;for(let i of a.ichildren()){let s=r.get(i);(s===void 0||a.y<s.y)&&r.set(i,a)}}for(let a of jt(e)){if(a.x===void 0){let s=he(W(a.ichildren(),u=>u.x));a.x=t.getIndex(e.length-a.y,s)}let i=r.get(a);i!==void 0&&((o=i.x)!=null||(i.x=a.x),t.setIndex(a.x,e.length-i.y))}let n=t.offset();for(let a of e)a.x+=n}function Pe(e,t,r){function n(s){let u=go(t,r);e?vo(s,u):No(s,u)}function o(s){return s===void 0?e:Pe(s,t,r)}n.topDown=o;function a(s){return s===void 0?t:Pe(e,s,r)}n.compressed=a;function i(s){return s===void 0?r:Pe(e,t,s)}return n.bidirectional=i,n}function Be(...e){if(e.length)throw new Error(`got arguments to greedy(${e}), but constructor takes no arguments.`);return Pe(!0,!0,!1)}function bo(e){for(let n of e){if(n.x===void 0)throw new Error(H`coord didn't assign an x to node '${n}'`);if(n.x<0)throw new Error(`coord assigned an x (${n.x}) less than 0`)}let t=new Set(e.map(n=>n.x));if(!Ht(t,new Set(W(t,(n,o)=>o)))){let n=[...t].join(", ");throw new Error(`didn't assign increasing positive integers for x coordinates: ${n}`)}let r=new Map;for(let[n,o]of e.entries()){let a=r.get(o);if(a!==void 0){for(let i of e.slice(a+1,n))if(i.x===o.x)throw new Error(H`node ${i} was assigned an overlapping lane with ${o}`)}for(let i of o.ichildren())r.has(i)||r.set(i,n)}return t.size}function _e(e){function t(a){if(a.multidag())throw new Error("grid layout doesn't make sense to apply to multidags, consider pruning the edges");let{nodeWidth:i,nodeHeight:s,size:u,lane:c}=e,d=[...a.idescendants("before")];for(let[g,f]of d.entries())f.y=g;c(d);let l=bo(d);for(let g of d)g.x=(g.x+.5)*i,g.y=(g.y+.5)*s;let p=l*i,m=d.length*s;if(u!==null){let[g,f]=u;for(let N of d)N.x*=g/p,N.y*=f/m;p=g,m=f}for(let{source:g,target:f,points:N}of a.ilinks())N.length=0,g.x!==f.x&&N.push({x:g.x,y:g.y}),N.push({x:f.x,y:g.y}),N.push({x:f.x,y:f.y});return{width:p,height:m}}function r(a){if(a===void 0)return e.lane;{let i=e,{lane:s}=i,u=B(i,["lane"]);return _e(T(A({},u),{lane:a}))}}t.lane=r;function n(a){if(a===void 0){let{nodeWidth:i,nodeHeight:s}=e;return[i,s]}else{let[i,s]=a;return _e(T(A({},e),{nodeWidth:i,nodeHeight:s}))}}t.nodeSize=n;function o(a){if(a!==void 0)return _e(T(A({},e),{size:a}));if(e.size===null)return null;{let[i,s]=e.size;return[i,s]}}return t.size=o,t}function ir(...e){if(e.length)throw new Error(`got arguments to grid(${e}), but constructor takes no arguments.`);return _e({lane:Be(),nodeWidth:1,nodeHeight:1,size:null})}var jr=ut(Ur());function te(e,t,r,n,o={}){let s=jr.Solve.call({},{optimize:e,opType:t,constraints:n,variables:r,ints:o}),{feasible:a}=s,i=B(s,["feasible"]);if(!a)throw new Error("could not find a feasible simplex solution");return i}function Eo(e){let t=[],r=new Set;for(let n of e){if(!r.has(n)){let o=t.findIndex(i=>i<=n.y),a=o===-1?t.length:o;t[a]=n.y}for(let o of[...n.ichildren()].sort((a,i)=>i.y-a.y))if(!r.has(o)){let a=t.findIndex(s=>s<=n.y),i=a===-1?t.length:a;t[i]=o.y,r.add(o)}}return t.length}function Ct(e,t){function r(a){var m,g,f;let i={},s={},u={},c=new Map(W(a,(N,h)=>[N,h])),d=e?Eo(a):a.length-1;for(let N of a.keys())i[N]={opt:0,[N]:1},s[N]={max:d-1};let l=new Map;for(let[N,h]of a.entries()){let b=l.get(h);if(b!==void 0)for(let[O,x]of a.slice(b+1,N).entries()){let w=O+b+1,y=`${N}-${w}-above`;i[y]={opt:0,[y]:1},s[y]={max:1},u[y]=1;let L=`${y}-span`;i[N][L]=1,i[w][L]=-1,i[y][L]=-d,s[L]={min:1-d,max:-1};for(let D of x.ichildren()){if(D===h)continue;let C=c.get(D),S=`${y}-${C}-cross`;i[S]={opt:1,[S]:1},s[S]={max:1},u[S]=1;let z=`${S}-left`;i[N][z]=-1,i[C][z]=1,i[y][z]=d,i[S][z]=-d,s[z]={max:d};let k=`${S}-right`;i[N][k]=-1,i[C][k]=1,i[y][k]=d,i[S][k]=d,s[k]={min:0}}}for(let O of h.ichildren())l.has(O)||l.set(O,N)}if(t){let N=a.reduce((h,b)=>h+b.children().length,0);for(let[h,b]of a.entries())for(let O of b.ichildren()){let x=c.get(O),w=`${h}-${x}-dist`;i[w]={opt:1/N};let y=`${w}-upper`;i[h][y]=1,i[x][y]=-1,i[w][y]=-d,s[y]={max:0};let L=`${w}-lower`;i[h][L]=1,i[x][L]=-1,i[w][L]=d,s[L]={min:0}}}let p=te("opt","min",i,s,u);if(t||e)for(let[N,h]of a.entries())h.x=(m=p[N])!=null?m:0;else{let N=new Set;for(let b of a.keys())N.add((g=p[b])!=null?g:0);let h=new Map(W([...N].sort(),(b,O)=>[b,O]));for(let[b,O]of a.entries())O.x=h.get((f=p[b])!=null?f:0)}}function n(a){return a===void 0?e:Ct(a,t)}r.compressed=n;function o(a){return a===void 0?t:Ct(e,a)}return r.dist=o,r}function Hr(...e){if(e.length)throw new Error(`got arguments to opt(${e}), but constructor takes no arguments.`);return Ct(!1,!0)}var ln=ut(dn());function jo(e,t,r,n,o){if(!t.length)return[];let a=[[0]],i=[0],s=[[0]],u=[0];for(let l of e){let p=[0];p.push(...l),a.push(p)}i.push(...t),s.push(...t.map(()=>[0]));for(let l of r)for(let[p,m]of l.entries())s[p+1].push(-m);u.push(...n.map(l=>-l));let{solution:c,message:d}=(0,ln.solveQP)(a,i,s,u,o);if(d.length)throw new Error(`quadratic program failed: ${d}`);return c.shift(),c}function Ze(e,t,r,n,o=0){t.pop(),e.pop(),e.forEach(i=>i.pop()),r.forEach(i=>i.pop());let a=jo(e,t,r,n,o);return a.push(0),a}function cn(e){return new Map(e.flatMap(t=>t).map((t,r)=>[t,r]))}function Qe(e,t,r){let n=1+Math.max(...t.values()),o=[],a=[];for(let u of e)for(let[c,d]of F(u)){let l=t.get(c),p=t.get(d),m=new Array(n).fill(0);m[l]=1,m[p]=-1,o.push(m),a.push(-(r(c)+r(d))/2)}let i=new Array(n).fill(0);return[[...new Array(n)].map(()=>new Array(n).fill(0)),i,o,a]}function kt(e,t,r,n){e[r][r]+=n,e[r][t]-=n,e[t][r]-=n,e[t][t]+=n}function Je(e,t,r,n,o){e[n][n]+=o,e[n][r]-=2*o,e[n][t]+=o,e[r][n]-=2*o,e[r][r]+=4*o,e[r][t]-=2*o,e[t][n]+=o,e[t][r]-=2*o,e[t][t]+=o}function Ke(e,t,r,n){let o=Number.POSITIVE_INFINITY,a=Number.NEGATIVE_INFINITY;for(let s of e){let u=s[0],c=s[s.length-1];o=Math.min(o,n[r.get(u)]-t(u)/2),a=Math.max(a,n[r.get(c)]+t(c)/2)}let i=a-o;for(let s of e)for(let u of s)u.x=Math.min(Math.max(0,n[r.get(u)]-o),i);return i}function Ye(e){let t=J(Z(e,a=>a));function*r(a){var i;yield*a.ichildren(),yield*(i=t.get(a))!=null?i:[]}let n=0,o=new Map;for(let a of Z(e,i=>i))if(!o.has(a)){for(let i of ue(r,a))o.set(i,n);n++}return o}function Xe(e,t){let r=[],n=[],o=new Set;for(let a of e){let i=new Set(a.map(s=>t.get(s)));Ft(o,i)||r.push(n=[]),n.push(a),o=i}return r}function Ho(e){let[t,r,n]=e;if(t<=0||r<=0||n<=0)throw new Error("const accessors should return non-negative values");let o=()=>e;return o.value=e,o}function Fo(e){return"value"in e&&typeof e.value=="object"&&e.value.length===3&&e.value.every(t=>typeof t=="number")}function Zo(e,t){if(Fo(t)){let[r,n,o]=t.value;if(r<=0||n<=0||o<=0)throw new Error(`simplex weights must be positive, but got: ${r}, ${n}, ${o}`);return(i,s)=>{switch(+("node"in i.data)+ +("node"in s.data)){case 0:return o;case 1:return n;case 2:return r;default:throw new Error("internal error")}}}else{let r=new Map;for(let o of Z(e,a=>a))if("node"in o.data){let a=o.data.node,i=new Map;for(let s of a.ichildLinks()){let{target:u}=s,c=t(s),[d,l,p]=c;if(d<=0||l<=0||p<=0)throw new Error(`simplex weights must be positive, but got: ${d}, ${l}, ${p}`);i.set(u,c)}r.set(a,i)}return(o,a)=>{if("link"in o.data){let{source:i,target:s}=o.data.link,[,u,c]=r.get(i).get(s);return"link"in a.data?c:u}else if("link"in a.data){let{source:i,target:s}=a.data.link,[,u]=r.get(i).get(s);return u}else{let[i]=r.get(o.data.node).get(a.data.node);return i}}}}function fn(e){function t(o,a){var g;let i={},s={},u=Zo(o,e.weight),c=new Map;for(let[f,N]of Q(Z(o,h=>h))){let h=f.toString();c.set(N,h),i[h]={}}function d(f){return c.get(f)}for(let f of o)for(let[N,h]of F(f)){let b=d(N),O=d(h),x=`layer ${b} -> ${O}`,w=(a(N)+a(h))/2;s[x]={min:w},i[b][x]=-1,i[O][x]=1}for(let f of Z(o,N=>N)){let N=d(f);for(let h of f.ichildren()){let b=d(h),O=`link ${N} -> ${b}`,x=`${O} parent`;s[x]={min:0};let w=`${O} child`;s[w]={min:0},i[N][x]=1,i[N][w]=-1,i[b][x]=-1,i[b][w]=1;let y=u(f,h);i[O]={opt:y,[x]:1,[w]:1}}}let l=te("opt","min",i,s),p=0,m=0;for(let f of o){for(let b of f)b.x=(g=l[d(b)])!=null?g:0;let N=f[0];p=Math.min(p,N.x-a(N)/2);let h=f[f.length-1];m=Math.max(m,h.x+a(h)/2)}for(let f of Z(o,N=>N))f.x-=p;return m-p}function r(o,a){let i=Ye(o),s=Xe(o,i),u=s.map(d=>t(d,a)),c=Math.max(...u);if(c<=0)throw new Error("must assign nonzero width to at least one node");for(let[d,l]of s.entries()){let p=(c-u[d])/2;for(let m of l)for(let g of m)g.x+=p}return c}function n(o){if(o===void 0)return e.weight;{let a=e,{weight:i}=a,s=B(a,["weight"]);return fn(T(A({},s),{weight:o}))}}return r.weight=n,r}function et(...e){if(e.length)throw new Error(`got arguments to simplex(${e}), but constructor takes no arguments.`);return fn({weight:Ho([1,2,8])})}var pn=class{constructor(){this.mean=0;this.count=0}add(t){this.mean+=(t-this.mean)/++this.count}val(){return this.count?this.mean:void 0}},hn=()=>new pn,mn=class{constructor(){this.vals=[]}add(t){this.vals.push(t)}val(){return he(this.vals)}},zt=()=>new mn;function Qo(e,t){let r=e();for(let n of t)r.add(n);return r.val()}function gn(e,t){let r=new Map;for(let d of e){let l=t.get(d);l!==void 0&&se(r,l,d)}let n=[...r.entries()].sort(([d],[l])=>d-l).flatMap(([,d])=>d),o=new Map(e.map((d,l)=>[d,l])),a=e.filter(d=>t.get(d)===void 0),i=new Array(a.length).fill(null);function s(d,l,p,m){if(l<=d)return;let g=Math.floor((d+l)/2),f=a[g],N=o.get(f),h=0,b=[h];for(let x=p;x<m;++x)h+=o.get(n[x])<N?-1:1,b.push(h);let O=p+b.indexOf(Math.min(...b));i[g]=O,s(d,g,p,O),s(g+1,l,O,m)}s(0,a.length,0,n.length),i.push(n.length+1);let u=0,c=0;for(let[d,l]of n.entries()){for(;i[c]==d;)e[u++]=a[c++];e[u++]=l}for(;i[c]==n.length;)e[u++]=a[c++]}function vn({factory:e}){function t(n,o,a){if(a){let i=new Map(o.map(u=>[u,e()]));for(let[u,c]of n.entries())for(let d of c.ichildren())i.get(d).add(u);let s=new Map([...i.entries()].map(([u,c])=>[u,c.val()]));gn(o,s)}else{let i=new Map(o.map((u,c)=>[u,c])),s=new Map(n.map(u=>{let c=Qo(e,W(u.ichildren(),d=>i.get(d)));return[u,c]}));gn(n,s)}}function r(n){return n===void 0?e:vn({factory:n})}return t.aggregator=r,t}function ge(...e){if(e.length)throw new Error(`got arguments to agg(${e}), but constructor takes no arguments.`);return vn({factory:zt})}function Mt(e){function t(o){let a=o.slice().reverse(),i=!0;for(let s=0;s<e.passes&&i;++s){i=!1;for(let[u,c]of F(o)){let d=new Map(c.map((l,p)=>[l,p]));e.order(u,c,!0),c.some((l,p)=>d.get(l)!==p)&&(i=!0)}for(let[u,c]of F(a)){let d=new Map(c.map((l,p)=>[l,p]));e.order(c,u,!1),c.some((l,p)=>d.get(l)!==p)&&(i=!0)}}}function r(o){if(o===void 0)return e.order;{let a=e,{order:i}=a,s=B(a,["order"]);return Mt(T(A({},s),{order:o}))}}t.order=r;function n(o){if(o===void 0)return e.passes;if(o<=0)throw new Error("number of passes must be positive");return Mt(T(A({},e),{passes:o}))}return t.passes=n,t}function tt(...e){if(e.length)throw new Error(`got arguments to twoLayer(${e}), but constructor takes no arguments.`);return Mt({order:ge(),passes:1})}function At(e){function t(o){var N;let a={},i={},s={},u=new Map(W(o,(h,b)=>[h,b.toString()]));function c(h){return u.get(h)}function d(h){return a[c(h)]}function l(h,b,O,x=1){let w=d(b),y=d(O),L=`${h}: ${c(b)} -> ${c(O)}`;i[L]={min:x},w[L]=-1,y[L]=1}function p(h,b,O){l(`${h} before`,b,O,0),l(`${h} after`,O,b,0)}let m=[],g=new Map;for(let h of o){let b=c(h);s[b]=1,a[b]={opt:0};let O=e.rank(h);O!==void 0&&m.push([O,h]);let x=e.group(h);if(x!==void 0){let w=g.get(x);w?w.push(h):g.set(x,[h])}}for(let h of o)for(let[b,O]of h.ichildrenCounts())l("link",h,b,O>1?2:1),d(h).opt+=O,d(b).opt-=O;let f=m.sort(([h],[b])=>h-b);for(let[[h,b],[O,x]]of F(f))h<O?l("rank",b,x):p("rank",b,x);for(let h of g.values())for(let[b,O]of F(h))p("group",b,O);try{let h=te("opt","max",a,i,s);for(let b of o)b.value=(N=h[c(b)])!=null?N:0}catch(h){throw Ne(m.length||g.size),new Error("could not find a feasible simplex layout, check that rank or group accessors are not ill-defined")}}function r(o){if(o===void 0)return e.rank;{let a=e,{rank:i}=a,s=B(a,["rank"]);return At(T(A({},s),{rank:o}))}}t.rank=r;function n(o){if(o===void 0)return e.group;{let a=e,{group:i}=a,s=B(a,["group"]);return At(T(A({},s),{group:o}))}}return t.group=n,t}function Nn(){}function rt(...e){if(e.length)throw new Error(`got arguments to simplex(${e}), but constructor takes no arguments.`);return At({rank:Nn,group:Nn})}function bn(e,t){let r=new Map,n=new Map(e.map((a,i)=>[a,i]));function o(a,i){var u;let s=(u=r.get(a))==null?void 0:u.get(i);if(s!==void 0)return s;{let c=0;for(let p of t(a))for(let m of t(i))c+=Math.sign(n.get(p)-n.get(m));let d=r.get(a);d===void 0?r.set(a,new Map([[i,c]])):d.set(i,c);let l=r.get(i);return l===void 0?r.set(i,new Map([[a,-c]])):l.set(a,-c),c}}return o}function Jo(e,t){let r=[[0,e.length]],n;for(;n=r.pop();){let[o,a]=n;if(o>=a)continue;let i=0,s=a;for(let u=o;u<a-1;++u){let c=t(e[u],e[u+1]);c>i&&(i=c,s=u)}s!==a&&([e[s],e[s+1]]=[e[s+1],e[s]],r.push([o,s],[s+2,a]))}}function Ko(e,t){let r=new Array(e.length*(e.length-1)/2);for(;;){let n=0;for(let u=1;u<e.length;++u){let c=0,d=n;for(let l=u-1;l>=0;--l)r[d]=c,c+=t(e[l],e[u]),d-=e.length-l-1;n+=e.length-u}let o=0,a=0,i=0,s=0;for(let u=0;u<e.length-1;++u){let c=0;for(let d=u+1;d<e.length;++d){c+=t(e[u],e[d]);let l=r[o++]+c;l>a&&(a=l,i=u,s=d)}}if(a===0)break;[e[i],e[s]]=[e[s],e[i]]}}function Tt({baseOp:e,doScan:t}){function r(a,i,s){e(a,i,s);let u,c;if(s){let d=J(a);c=bn(a,l=>{var p;return(p=d.get(l))!=null?p:[]}),u=i}else c=bn(i,d=>d.ichildren()),u=a;t?Ko(u,c):Jo(u,c)}function n(a){return a===void 0?e:Tt({baseOp:a,doScan:t})}r.base=n;function o(a){return a===void 0?t:Tt({baseOp:e,doScan:a})}return r.scan=o,r}function nt(...e){if(e.length)throw new Error(`got arguments to greedy(${e}), but constructor takes no arguments.`);return Tt({baseOp:()=>{},doScan:!1})}function Yo(e){if(e.value===void 0)throw new Error(H`node with data '${e.data}' did not get a defined value during layering`);if(e.value<0)throw new Error(H`node with data '${e.data}' got an invalid (negative) value during layering: ${e.value}`);return e.value}function ot(e){let t=new Map(W(e,i=>[i,{node:i,layer:Yo(i)}]));for(let{source:i,target:s}of e.ilinks()){let u=i.nchildLinksTo(s)>1;if(u&&i.value+1>=s.value)throw new Error(H`layering left child data '${s.data}' (${s.value}) whose layer was not two more than its parent data '${i.data}' (${i.value})`);if(!u&&i.value>=s.value)throw new Error(H`layering left child data '${s.data}' (${s.value}) whose layer was not greater than its parent data '${i.data}' (${i.value})`)}function r(i){let s=i.layer+1;return("node"in i?i.node.childLinks():[i.link]).map(c=>{let d=t.get(c.target);return d.layer===s?d:{link:c,layer:s}})}let o=Ae().children(r)(...W(e.iroots(),i=>t.get(i)));Ne(!o.multidag());let a=[];for(let i of o)(a[i.data.layer]||(a[i.data.layer]=[])).push(i);if(!a[0]||!a[0].length)throw new Error("no nodes were assigned to layer 0");for(let i of a)Ne(i&&i.length);return a}function it(e){for(let t of e)for(let r of t){if("link"in r.data)continue;r.data.node.x=r.x,r.data.node.y=r.y;let n=new Map(W(r.data.node.ichildLinks(),({points:o,target:a})=>[a,o]));for(let o of r.ichildren()){let a=[{x:r.x,y:r.y}];for(;"link"in o.data;)a.push({x:o.x,y:o.y}),[o]=o.ichildren();a.push({x:o.x,y:o.y});let i=n.get(o.data.node);i.splice(0,i.length,...a)}}}function xn(e,t){for(let r of e){let n=0;for(let o of r){if(o.x===void 0)throw new Error(H`coord didn't assign an x to node '${o}'`);if(o.x<n)throw new Error(H`coord assigned an x (${o.x}) smaller than a previous node in the layer '${o}'`);n=o.x}if(n>t)throw new Error(`coord assigned an x (${n}) greater than width (${t})`)}}function yn(e,t,r){for(let n of e)for(let o of n)o.x*=t,o.y*=r}function On(e){let t=e();function r(n){return"node"in n.data?e(n.data.node):t}return r.wrapped=e,r}function Xo(e,t=!0){let r=new Map;function n(i){let s=r.get(i);if(s===void 0){s=e(i);let[u,c]=s;if(t&&(u<0||c<0))throw new Error(H`all node sizes must be non-negative, but got width ${u} and height ${c} for node '${i}'`);r.set(i,s)}return s}return[i=>n(i)[0],i=>n(i)[1]]}function Vt(e,t){let r=0;for(let n of e){let o=Math.max(...n.map(t));for(let a of n)a.y=r+o/2;r+=o}return r}function le(e){function t(u){e.layering(u);let c=ot(u),[d,l]=Xo(e.sugiNodeSize),p=Vt(c,l);if(p<=0)throw new Error("at least one node must have positive height, but total height was zero");e.decross(c);let m=e.coord(c,d);if(xn(c,m),e.size!==null){let[g,f]=e.size;yn(c,g/m,f/p),m=g,p=f}return it(c),{width:m,height:p}}function r(u){if(u===void 0)return e.layering;{let c=e,{layering:d}=c,l=B(c,["layering"]);return le(T(A({},l),{layering:u}))}}t.layering=r;function n(u){if(u===void 0)return e.decross;{let c=e,{decross:d}=c,l=B(c,["decross"]);return le(T(A({},l),{decross:u}))}}t.decross=n;function o(u){if(u===void 0)return e.coord;{let c=e,{coord:d}=c,l=B(c,["coord"]);return le(T(A({},l),{coord:u}))}}t.coord=o;function a(u){return u!==void 0?le(T(A({},e),{size:u})):e.size}t.size=a;function i(u){if(u!==void 0){let c=e,{nodeSize:d,sugiNodeSize:l}=c,p=B(c,["nodeSize","sugiNodeSize"]);return le(T(A({},p),{nodeSize:u,sugiNodeSize:On(u)}))}else return e.nodeSize}t.nodeSize=i;function s(u){if(u!==void 0){let c=e,{sugiNodeSize:d,nodeSize:l}=c,p=B(c,["sugiNodeSize","nodeSize"]);return le(T(A({},p),{sugiNodeSize:u,nodeSize:null}))}else return e.sugiNodeSize}return t.sugiNodeSize=s,t}function wn(e){return[+(e!==void 0),1]}function Dn(...e){if(e.length)throw new Error(`got arguments to sugiyama(${e}), but constructor takes no arguments.`);return le({layering:rt(),decross:tt().order(nt().base(ge())),coord:et(),size:null,nodeSize:wn,sugiNodeSize:On(wn)})}function Ln(...e){if(e.length)throw new Error(`got arguments to center(${e}), but constructor takes no arguments.`);function t(r,n){let o=r.map(i=>{let s=0;for(let u of i){let c=n(u);u.x=s+c/2,s+=c}return s}),a=Math.max(...o);if(a<=0)throw new Error("must assign nonzero width to at least one node");for(let[i,s]of r.entries()){let u=o[i],c=(a-u)/2;for(let d of s)d.x+=c}return a}return t}function Sn(...e){if(e.length)throw new Error(`got arguments to greedy(${e}), but constructor takes no arguments.`);function t(r,n){let o=ei,a=new Map;for(let l of r)for(let p of l)a.set(p,p.nchildren()+("node"in p.data?0:-3));for(let l of r)for(let p of l)for(let m of p.ichildren())a.set(m,a.get(m)+1);let[i,...s]=r,u=0,c=0;for(let l of i){let p=n(l);l.x=c+p/2,c+=p}for(let l of s){o(i,l);let p=l.map((m,g)=>[g,m]).sort(([m,g],[f,N])=>{let h=a.get(g),b=a.get(N);return h===b?m-f:b-h});for(let[m,g]of p){let f=n(g),N=g.x+f/2;for(let b of l.slice(m+1)){let O=n(b)/2;N=(b.x=Math.max(b.x,N+O))+O}c=Math.max(c,N);let h=g.x-f/2;for(let b of l.slice(0,m).reverse()){let O=n(b)/2;h=(b.x=Math.min(b.x,h-O))-O}u=Math.min(u,h)}i=l}for(let l of r)for(let p of l)p.x-=u;let d=c-u;if(d<=0)throw new Error("must assign nonzero width to at least one node");return d}return t}function ei(e,t){for(let n of t)n.x=0;let r=new Map;for(let n of e)for(let o of n.ichildren()){let a=(r.get(o)||0)+1;r.set(o,a),o.x+=(n.x-o.x)/a}}function ie(e){if(e<0)throw new Error("const accessors should return non-negative values");let t=()=>e;return t.value=e,t}function ce(e){return"value"in e&&typeof e.value=="number"}function ti(e,t){if(ce(e)){let r=e.value;for(let n of Z(t,o=>o))if("node"in n.data){let o=n.data.node;for(let a of o.ichildLinks())if(e(a)!==r)throw new Error("passed in a vertWeak accessor with a `value` property that wasn't a const accessor")}return()=>r}else{let r=new Map;for(let n of Z(t,o=>o))if("node"in n.data){let o=n.data.node,a=new Map(W(o.ichildLinks(),i=>[i.target,e(i)]));r.set(o,a)}return(n,o)=>r.get(n).get(o)}}function Cn(e){if(ce(e))return e;{let t=new Map;return r=>{let{source:n,target:o}=r,a=t.get(n);a===void 0&&(a=new Map,t.set(n,a));let i=a.get(o);if(i===void 0){let s=e(r);if(s<0)throw new Error("link weights must be non-negative");return a.set(o,s),s}else return i}}}function ri(e){if(ce(e))return e;{let t=new Map;return r=>{let n=t.get(r);if(n===void 0){let o=e(r);if(o<0)throw new Error("node weights must be non-negative");return t.set(r,o),o}else return n}}}function ae(e){function t(d,l,p){var C;let{comp:m}=e,g=cn(d),[f,N,h,b]=Qe(d,g,l),O=ti(e.vertWeak,d),x=Cn(e.vertStrong),w=Cn(e.linkCurve),y=ri(e.nodeCurve);for(let S of Z(d,z=>z)){let z=g.get(S),k=S.data,E="node"in k?k.node:k.link.source;for(let V of S.ichildren()){let P=g.get(V),M=V.data,$="node"in M?M.node:M.link.target,j="node"in k?O(E,$):x(k.link),U="node"in M?O(E,$):x(M.link),R="node"in M?y(M.node):w(M.link);kt(f,z,P,j+U);for(let re of V.ichildren()){let Y=g.get(re);Je(f,z,P,Y,R)}}}let L=new Map;for(let S of d)for(let[z,k]of F(S)){let E=p.get(z),V=p.get(k);if(E!==V){let P=L.get(E);P===void 0?L.set(E,new Set([V])):P.add(V)}}let D=new Map;for(let[S,z]of L.entries()){let k=new Set;for(let E of z){let V=ue(M=>{var $;return($=L.get(M))!=null?$:[]},E);fe(V,M=>M===S)||k.add(E)}D.set(S,k)}for(let S of d)for(let[z,k]of F(S)){let E=p.get(z),V=p.get(k);E!==V&&((C=D.get(E))==null?void 0:C.has(V))&&kt(f,g.get(z),g.get(k),m)}try{let S=Ze(f,N,h,b);return Ke(d,l,g,S)}catch(S){throw S instanceof Error&&S.message==="quadratic program failed: matrix D in quadratic function is not positive definite!"?new Error("quad objective wasn't well defined, this happens when too many of the weights were set to zero (or really small). Try changing the weight accessors to return nonzero values in more instances."):S}}function r(d,l){let p=Ye(d),m=Xe(d,p),g=m.map(N=>t(N,l,p)),f=Math.max(...g);if(f<=0)throw new Error("must assign nonzero width to at least one node");for(let[N,h]of m.entries()){let b=(f-g[N])/2;for(let O of h)for(let x of O)x.x+=b}return f}function n(d){if(d===void 0){let{vertWeak:p,vertStrong:m}=e;return ce(p)&&ce(m)?[p.value,m.value]:null}else{let[p,m]=d;if(p<0||m<0)throw new Error(`weights must be non-negative, but were ${p} and ${m}`);{let l=e,{vertWeak:g,vertStrong:f}=l,N=B(l,["vertWeak","vertStrong"]);return ae(T(A({},N),{vertWeak:ie(p),vertStrong:ie(m)}))}}}r.vertical=n;function o(d){if(d===void 0)return e.vertWeak;{let l=e,{vertWeak:p}=l,m=B(l,["vertWeak"]);return ae(T(A({},m),{vertWeak:d}))}}r.vertWeak=o;function a(d){if(d===void 0)return e.vertStrong;{let l=e,{vertStrong:p}=l,m=B(l,["vertStrong"]);return ae(T(A({},m),{vertStrong:d}))}}r.vertStrong=a;function i(d){if(d===void 0){let{linkCurve:p,nodeCurve:m}=e;return ce(p)&&ce(m)?[m.value,p.value]:null}else{let[p,m]=d;if(p<0||m<0)throw new Error(`weights must be non-negative, but were ${p} and ${m}`);{let l=e,{linkCurve:g,nodeCurve:f}=l,N=B(l,["linkCurve","nodeCurve"]);return ae(T(A({},N),{linkCurve:ie(m),nodeCurve:ie(p)}))}}}r.curve=i;function s(d){if(d===void 0)return e.linkCurve;{let l=e,{linkCurve:p}=l,m=B(l,["linkCurve"]);return ae(T(A({},m),{linkCurve:d}))}}r.linkCurve=s;function u(d){if(d===void 0)return e.nodeCurve;{let l=e,{nodeCurve:p}=l,m=B(l,["nodeCurve"]);return ae(T(A({},m),{nodeCurve:d}))}}r.nodeCurve=u;function c(d){if(d===void 0)return e.comp;if(d<=0)throw new Error(`weight must be positive, but was ${d}`);return ae(T(A({},e),{comp:d}))}return r.component=c,r}function In(...e){if(e.length)throw new Error(`got arguments to quad(${e}), but constructor takes no arguments.`);return ae({vertWeak:ie(1),vertStrong:ie(0),linkCurve:ie(1),nodeCurve:ie(0),comp:1})}function kn(...e){if(e.length)throw new Error(`got arguments to topological(${e}), but constructor takes no arguments.`);function t(r,n){for(let p of r)if(p.reduce((g,f)=>g+ +("node"in f.data),0)!==1)throw new Error("topological() only works with a topological layering");let o=new Map,a=0;for(let p of r)for(let m of p)"link"in m.data&&o.set(m,a++);for(let p of r)for(let m of p)"node"in m.data&&o.set(m,a);let[i,s,u,c]=Qe(r,o,n);for(let p of r)for(let m of p){let g=o.get(m);for(let f of m.ichildren()){let N=o.get(f);if("link"in f.data)for(let h of f.ichildren()){let b=o.get(h);Je(i,g,N,b,1)}}}let d=Ze(i,s,u,c),l=Ke(r,n,o,d);if(l<=0)throw new Error("must assign nonzero width to at least one node");return l}return t}function Et(e){function t(o){let a=o.reduce((x,w)=>x+w.length*Math.max(w.length-1,0)/2,0),i=o.reduce((x,w)=>x+w.reduce((y,L)=>y+L.nchildren(),0),0);if(e.large!=="large"&&a>1200)throw new Error('size of dag to decrossOpt is too large and will likely crash instead of complete, enable "large" graphs to run anyway');if(e.large!=="large"&&e.large!=="medium"&&(a>400||i>100))throw new Error('size of dag to decrossOpt is too large and will likely not complete, enable "medium" graphs to run anyway');let s=[];for(let[x,w]of F(o)){let y=new Set(x.flatMap(k=>k.children())),L=w.filter(k=>!y.has(k)),D=x.map(k=>k.children()).filter(k=>k.length>1);s.push([L,D]);let C=x.filter(k=>!k.nchildren()),z=[...J(x).values()];s.push([C,z])}let u=s.reduce((x,[w,y])=>y.reduce((L,D)=>L+D.length*D.length,0)*w.length,0)/4,c=1/(u+1),d=c/(a+1),l={},p={},m={},g=new Map;{let x=0;for(let w of o)for(let y of w)g.set(y,x++)}function f(...x){return x.map(w=>g.get(w)).sort((w,y)=>w-y).join(" => ")}function N(x){for(let[w,y]of x.slice(0,x.length-1).entries())for(let L of x.slice(w+1)){let D=f(y,L);m[D]=1,p[D]={max:1},l[D]={opt:-d,[D]:1}}for(let[w,y]of x.slice(0,x.length-1).entries())for(let[L,D]of x.slice(w+1).entries())for(let C of x.slice(w+L+2)){let S=f(y,D),z=f(y,C),k=f(D,C),E=f(y,D,C),V=E+"+";p[V]={max:1},l[S][V]=1,l[z][V]=-1,l[k][V]=1;let P=E+"-";p[P]={min:0},l[S][P]=1,l[z][P]=-1,l[k][P]=1}}function h(x){for(let[w,y]of x.slice(0,x.length-1).entries())for(let L of x.slice(w+1)){let D=f(y,L);for(let C of y.ichildren())for(let S of L.ichildren()){if(C===S)continue;let z=f(C,S),k=`slack (${D}) (${z})`,E=`${k} +`,V=`${k} -`;l[k]={opt:1,[E]:1,[V]:1};let P=Math.sign(g.get(C)-g.get(S)),M=Math.max(P,0);p[E]={min:M},l[D][E]=1,l[z][E]=P,p[V]={min:-M},l[D][V]=-1,l[z][V]=-P}}}function b(x,w){for(let y of x)for(let L of w)for(let[D,C]of L.entries())for(let S of L.slice(D+1)){let k=`dist ${[C,y,S].map(M=>g.get(M)).join(" => ")}`,E=`${k} normal`,V=`${k} reversed`;l[k]={opt:c,[E]:1,[V]:1};let P=0;for(let[M,$]of[[C,y],[C,S],[y,S]]){let j=f(M,$),U=Math.sign(g.get(M)-g.get($));P+=+(U>0),l[j][E]=-U,l[j][V]=U}p[E]={min:1-P},p[V]={min:P-2}}}for(let x of o)N(x);for(let x of o.slice(0,o.length-1))h(x);if(e.dist)for(let[x,w]of s)b(x,w);let O=te("opt","min",l,p,m);for(let x of o)x.sort((w,y)=>O[f(w,y)]||-1)}function r(o){return o===void 0?e.large:Et(T(A({},e),{large:o}))}t.large=r;function n(o){return o===void 0?e.dist:Et(T(A({},e),{dist:o}))}return t.dist=n,t}function zn(...e){if(e.length)throw new Error(`got arguments to opt(${e}), but constructor takes no arguments.`);return Et({large:"small",dist:!1})}var Tn=ut(An());function Vn(e){function t(n){var m;let o=e.width||Math.floor(Math.sqrt(n.size()+.5));function a([g],[f]){for(let[N,h]of g.entries()){let b=f[N];if(b===void 0)return!1;if(h<b)return!0;if(b<h)return!1}return!0}let i=new Tn.default(a),s=new Map(W(n,g=>[g,[]])),u=Me(n);for(let g of n.iroots())i.add([[],g]);let c=0,d=0,l=0,p;for(;p=i.poll();){let[,g]=p,f=(m=u.get(g))==null?void 0:m.reduce((N,[h,b])=>Math.max(N,h.value+ +(b>1)),0);l<o&&(f===void 0||f<d)?(g.value=d,l++):(g.value=d=Math.max(f!=null?f:0,d)+1,l=1);for(let N of g.ichildren()){let h=s.get(N);h.push(c),h.length===u.get(N).length&&i.add([h.reverse(),N])}c++}}function r(n){if(n===void 0)return e.width;if(n<0)throw new Error(`width must be non-negative: ${n}`);return Vn(T(A({},e),{width:n}))}return t.width=r,t}function En(...e){if(e.length)throw new Error(`got arguments to coffmanGraham(${e}), but constructor takes no arguments.`);return Vn({width:0})}function Pn(e){function t(n){var o;if(e.topDown){let a=Me(n);for(let i of n.idescendants("before"))i.value=Math.max(0,...W((o=a.get(i))!=null?o:[],([s,u])=>s.value+(u>1?2:1)))}else{let a=0;for(let i of n.idescendants("after"))i.value=Math.max(0,...W(i.ichildrenCounts(),([s,u])=>s.value+(u>1?2:1))),a=Math.max(a,i.value);for(let i of n)i.value=a-i.value}}function r(n){return n===void 0?e.topDown:Pn(T(A({},e),{topDown:n}))}return t.topDown=r,t}function Bn(...e){if(e.length)throw new Error(`got arguments to longestPath(${e}), but constructor takes no arguments.`);return Pn({topDown:!0})}function _n(...e){if(e.length)throw new Error(`got arguments to topological(${e}), but constructor takes no arguments.`);function t(r){let n=0,o;for(let a of r.idescendants("before"))o!==void 0&&o.nchildLinksTo(a)>1&&++n,a.value=n++,o=a}return t}function Pt(e){function t(o,a,i){let s=i?a:o,u=s.length*Math.max(s.length-1,0)/2,c=o.reduce((L,D)=>L+D.nchildren(),0);if(e.large!=="large"&&u>1200)throw new Error('size of dag to twolayerOpt is too large and will likely crash, enable "large" dags to run anyway');if(e.large!=="large"&&e.large!=="medium"&&(u>400||c>100))throw new Error('size of dag to twolayerOpt is too large and will likely not finish, enable "medium" dags to run anyway');let d={},l={},p={},m=new Map(s.map((L,D)=>[L,D]));function g(...L){return L.map(D=>m.get(D)).sort((D,C)=>D-C).join(" => ")}let f,N;if(i){let L=new Set(o.flatMap(D=>D.children()));f=a.filter(D=>!L.has(D)),N=o.map(D=>D.children()).filter(D=>D.length>1)}else f=o.filter(D=>!D.nchildren()),N=[...J(o).values()];let b=N.reduce((L,D)=>L+D.length*D.length,0)*f.length/4,O=1/(b+1),x=O/(u+1),w=new Map(a.map((L,D)=>[L,D]));for(let[L,D]of s.slice(0,s.length-1).entries())for(let C of s.slice(L+1)){let S=g(D,C);p[S]=1,l[S]={max:1},d[S]={opt:-x,[S]:1}}for(let[L,D]of s.slice(0,s.length-1).entries())for(let[C,S]of s.slice(L+1).entries())for(let z of s.slice(L+C+2)){let k=g(D,S),E=g(D,z),V=g(S,z),P=g(D,S,z),M=P+"+";l[M]={max:1},d[k][M]=1,d[E][M]=-1,d[V][M]=1;let $=P+"-";l[$]={min:0},d[k][$]=1,d[E][$]=-1,d[V][$]=1}for(let[L,D]of o.slice(0,o.length-1).entries())for(let C of o.slice(L+1))for(let S of D.ichildren())for(let z of C.ichildren()){if(S===z)continue;let k=i?g(S,z):g(D,C);d[k].opt+=Math.sign(w.get(S)-w.get(z))}if(e.dist)for(let L of f)for(let D of N)for(let[C,S]of D.entries())for(let z of D.slice(C+1)){let E=`dist ${[S,L,z].map($=>m.get($)).join(" => ")}`,V=`${E} normal`,P=`${E} reversed`;d[E]={opt:O,[V]:1,[P]:1};let M=0;for(let[$,j]of[[S,L],[S,z],[L,z]]){let U=g($,j),R=Math.sign(m.get($)-m.get(j));M+=+(R>0),d[U][V]=-R,d[U][P]=R}l[V]={min:1-M},l[P]={min:M-2}}let y=te("opt","min",d,l,p);s.sort((L,D)=>y[g(L,D)]||-1)}function r(o){return o===void 0?e.large:Pt(T(A({},e),{large:o}))}t.large=r;function n(o){return o===void 0?e.dist:Pt(T(A({},e),{dist:o}))}return t.dist=n,t}function Wn(...e){if(e.length)throw new Error(`got arguments to opt(${e}), but constructor takes no arguments.`);return Pt({large:"small",dist:!1})}function Rn(e,t){let r=e.findIndex(n=>n<=t);return r>=0?r:e.length}function $n(e){var i;let t=new Map(e),r=[];for(let[s,[u,c]]of e.entries()){let d=!1,l=(i=e[s+1])==null?void 0:i[0];for(let[p,{target:m}]of Q(u.ichildLinks())){let g=t.get(m);l===m&&!d?d=!0:r.push([c,g,u,p])}}r.sort(([s,u],[c,d])=>u===d?c-s:u-d);let n=new Map,o=[],a=[];for(let[s,u,c,d]of r){let l=n.get(c);l===void 0&&(l=[],n.set(c,l));let p=Rn(a,s),m=Rn(o,s);p<m?(l[d]=-p-1,a[p]=u-1):(l[d]=m+1,o[m]=u-1)}return n}function Bt(e,t,r,n){function o(s){var h;let u=[],c=0,d;for(let b of s.idescendants("before"))d!==void 0&&d.nchildLinksTo(b)>1&&++c,u.push([b,c++]),d=b;let l=$n(u),p=0,m=0;for(let b of l.values())for(let O of b)O!==void 0&&(p=Math.min(p,O),m=Math.max(m,O));let g=-p*r+e/2;for(let[b,O]of u)b.x=g,b.y=(O+.5)*t;for(let b of s){let O=(h=l.get(b))!=null?h:[];for(let[x,{target:w,points:y}]of Q(b.ichildLinks())){y.length=0,y.push({x:b.x,y:b.y});let L=O[x];if(L!==void 0){let D=(L-p+.5)*r+(L>0?e-r:0),C=b.y+t,S=w.y-t;S-C>t/2?y.push({x:D,y:C},{x:D,y:S}):y.push({x:D,y:C})}y.push({x:w.x,y:w.y})}}let f=(m-p)*r+e,N=c*t;if(n===null)return{width:f,height:N};{let[b,O]=n;for(let[x]of u)x.x*=b/f,x.y*=O/N;for(let{points:x}of s.ilinks()){let w=x.map(({x:y,y:L})=>({x:y*b/f,y:L*O/N}));x.splice(0,x.length,...w)}return{width:b,height:O}}}function a(s){if(s===void 0)return[e,t,r];{let[u,c,d]=s;return Bt(u,c,d,n)}}o.nodeSize=a;function i(s){if(s!==void 0)return Bt(e,t,r,s);if(n===null)return n;{let[u,c]=n;return[u,c]}}return o.size=i,o}function Gn(...e){if(e.length)throw new Error(`got arguments to zherebko(${e}), but constructor takes no arguments.`);return Bt(1,1,1,null)}return eo(oi);})();
return d3; })())