* === to check the SAM imbalance Parameter gap(u) gap between the row-sum and the column-sum; gap(u)=sum(v, SAM(u,v)-SAM(v,u)); Display gap; * === Matrix Balancing === Variable SAMx(u,v) adjusted SAM values SAMy objective value ; Equation ROWCOL(u) row-sum and column-sum consisntency objSAM obj to be minimized; ; ROWCOL(u).. sum(v,SAMx(u,v)-SAMx(v,u))=e=0; objSAM.. SAMy =e= sum((u,v)$SAM(u,v), sqr(SAMx(u,v)/SAM(u,v)-1)); * Imposing constraints to keep signs of the original SAM values. SAMx.up(u,v) =inf$(SAM(u,v) gt 0) +0$(SAM(u,v) le 0); SAMx.lo(u,v) =0$(SAM(u,v) ge 0) -inf$(SAM(u,v) lt 0); * Initialization of variable SAMx.l(u,v) =SAM(u,v); Model SAMadj /all/; SOlve SAMadj minimizing SAMy using NLP; Parameter dSAM(u,v) deviation of the new SAM from the original SAM [%] sSAM(u,v) deviation of the new SAM from the original SAM [value]; dSAM(u,v)$SAM(u,v)=(SAMx.l(u,v)/SAM(u,v)-1)*100; sSAM(u,v)=SAMx.l(u,v)-SAM(u,v); Display dSAM, sSAM; * Replacing with the balanced SAM data SAM(u,v)=SAMx.l(u,v); * === end of Matrix Balancing =========================