Sum of Rows = Sum of Columns

I have a variable xij, and I want to code essentially: ∑xi(j=n)=∑x(i=n)j for all values of n. I tried using the line eq6(i,j)… sum(i, Q(i,j)) =e= sum(j, Q(i,j)); which is not correct.
Another way of saying this is that I want to code Input = Output

What is the correct way to write this in GAMS?

Hi
The problem is that you use both i and j in two different ways: as an index for the equation and as summation index.
You need an alias:

alias(i,ai), (j,aj);
eq6(i,j).. sum(ai, Q(ai,j)) =e= sum(aj, Q(i,aj));

This resolves the confusion on what to do with “i” and “j”.
Cheers
Renger

Is there also a way to write Q(i,j) = Q(j,i), IE Flow from i to j equals flow from j to i?

Hi,

Often, if you have a square matrix Q(i,j), the sets i and j are the same, e.g. you have alias(i,j). In this case, to force Q to be symmetric, you could do:

equation forceSym(i,j);
forceSym(i,j)$[ord(i) < ord(j)].. Q(i,j) =e= Q(j,i);

Note that if you have such a constraint, you could enforce the eq6 mentioned earlier in this thread on just the lower or upper triangle of the matrix:

eq6(i,j)$[ord(i) <= ord(j)].. sum(ai, Q(ai,j)) =e= sum(aj, Q(i,aj));

-Steve

I think I may be missing something. The line “forceSym(i,j)$[ord(i) < ord(j)]… Q(i,j) =e= Q(j,i);” results in the error: “Domain violation for set”

It would make it easier to help if you followed the posting rules:
https://forum.gamsworld.org/app.php/rules