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?
Sum of Rows = Sum of Columns
Re: Sum of Rows = Sum of Columns
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:
This resolves the confusion on what to do with "i" and "j".
Cheers
Renger
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:
Code: Select all
alias(i,ai), (j,aj);
eq6(i,j).. sum(ai, Q(ai,j)) =e= sum(aj, Q(i,aj));
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Enjoy modeling even more: Read my blog on modeling at The lazy economist
Re: Sum of Rows = Sum of Columns
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?
Re: Sum of Rows = Sum of Columns
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:
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:
-Steve
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:
Code: Select all
equation forceSym(i,j);
forceSym(i,j)$[ord(i) < ord(j)].. Q(i,j) =e= Q(j,i);
Code: Select all
eq6(i,j)$[ord(i) <= ord(j)].. sum(ai, Q(ai,j)) =e= sum(aj, Q(i,aj));
Re: Sum of Rows = Sum of Columns
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"
Re: Sum of Rows = Sum of Columns
It would make it easier to help if you followed the posting rules:
app.php/rules
app.php/rules