## Flow equation

Problems with syntax of GAMS
Alexanre.ito
User
Posts: 18
Joined: 10 months ago

### Flow equation

Hi,
I'm trying to write a code to calculate the flow of a snippet.
The section should receive the flow of the previous sections.
But my problem is the matrix "q(n,np)" depends on itself.

Code: Select all

``````Set     n       nodes   / n1 * n48 /
a(n,n)  arcos   / n1.(n2,n9), n2.(n1,n3), n3.(n2,n4), n4.(n3,n5,n10),
n5.(n4,n6,n11), n6.(n5,n7), n7.(n6,n8), n8.(n7,n17),
n9.(n1,n13), n10.(n4,n14), n11.(n5,n15), n12.(n8,n16),
n13.(n9,n17), n14.(n10,n20), n15.(n11,n21),
n16.(n12,n24), n17.(n13,n18,n25), n18.(n17,n19),
n19.(n18,n20), n20.(n14,n19,n21,n28),
n21.(n15,n20,n22,n29), n22.(n21,n23), n23.(n22,n24),
n24.(n16,n23,n33), n25.(n17,n26,n33), n26.(n25,n27),
n27.(n26,n28), n28.(n20,n27,n29,n34),
n29.(n21,n28,n30,n35), n30.(n29,n31), n31.(n30,n32),
n32.(n24,n31,n36), n33.(n25,n37), n34.(n28,n38),
n35.(n29,n39), n36.(n32,n40), n37.(n33,n41),
n38.(n34,n44), n39.(n35,n45), n40.(n36,n48),
n41.(n37,n42), n42.(n41,n43), n43.(n42,n44),
n44.(n38,n43,n45), n45.(n39,n44,n46),
n46.(n45,n47), n47.(n46,n48), n48.(n40,n47)/
si(n)   saida   /n48/
cont(n) contribution; cont(n)=yes; cont(si)=no; display cont;
alias(n,np);

Scalar q /10/;

Variables ar(n,np)
qn(n,np)
xq;

binary variable ar(n,np);

Equation flow
qalter;

qalter(n,np).. xq(n,np) =l= qn(n,np);

flow(n,np)\$ar(n,np)..  qn(n,np) =e= sum(np,xq(n,np)) + q;``````
Gams Show the Error..

Code: Select all

`````` vazao(n,np)\$ar(n,np)..  qn(n,np) =e= sum(np,xq(n,np)) + q;
\$125

125  Set is under control already

**** 1 ERROR(S)   0 WARNING(S)``````
I tried to use the equation to maintain the linear equation

Code: Select all

``qalter(n,np).. xq(n,np) =l= qn(n,np);``
Please could someone give me some idea

Renger
Posts: 550
Joined: 3 years ago

### Re: Flow equation

Hi
You can use -1 for the previous index and the \$-sign to constrain the summation, like this

Code: Select all

``````alias(m, am);

Q(m,n) = sum(am\$(ord(am) < ord(m)+1),  Q(am-1,n)X(am-1,n))+ QIN(am,n);
``````
Note, that you have to use an alias, as you can't sum over m as it is already used for indicating the variable Q(m,n), so Gams complains over using m in two concflicting ways (error 125).

I hope this helps

Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist

Alexanre.ito
User
Posts: 18
Joined: 10 months ago

### Re: Flow equation

Using this expretion

Code: Select all

``Q(m,n) = sum(am\$(ord(am) < ord(m)+1),  Q(am-1,n)X(am-1,n))``
Q(m,n) and Q(am-1,n)

GAMS will use the same matrix of data, in this case, will use the same matriz of the flow data?

Renger
Posts: 550
Joined: 3 years ago

### Re: Flow equation

I think it should be:

Code: Select all

``````alias(np,anp);
flow(n,np)\$ar(n,np)..  QN(n,np) =e= sum(anp\$(ord(anp) < ord(np), XN(n,anp)) + q;``````
.
This will take all XN for which the first index is the same as in QN (i.e. 'n') and the second index anp goes from the first element of np to the one just before n.
Hope this clarifies it.
CHeers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist