## problem with syntax of the equation Topic is solved

Problems with syntax of GAMS
Alexanre.ito
User
Posts: 27
Joined: 1 year ago

### Re: problem with syntax of the equation

Alexanre.ito wrote:
1 year ago
I'd like to know
if GAMS undestand this situation
...
n nodes / n1 * n48 /
a(n,n) /..../;
....
alias(n,np,i,j);
...
q(n) - scalar
q(a) - variable
...
eq1(a(i,j)).. q(a(n,np)) =e= sum(q(a(n,np)\$(np=i)) + q(n)
GAMS undestand
eq(i) and eq(i,j)
but GAMS undestand eq(a(i,j))??

Alexanre.ito
User
Posts: 27
Joined: 1 year ago

### Re: problem with syntax of the equation

Renger wrote:
1 year ago
Hi

It is not clear what you want to do with this equation. My advice: write it down as a proper mathematical expression, read how to use the sum in GAMS as well as the \$-sign, and proceed from there.

Cheers

Renger
GAMS understand :
eq(i)..
eq(i,j)..

but GAMS undestand:
eq(a(i,j)).. ???

Alexanre.ito
User
Posts: 27
Joined: 1 year ago

### Re: problem with syntax of the equation

Alexanre.ito wrote:
1 year ago
I'd like to know
if GAMS undestand this situation
...
n nodes / n1 * n48 /
a(n,n) /..../;
....
alias(n,np,i,j);
...
q(n) - scalar
q(a) - variable
...
eq1(a(i,j)).. q(a(n,np)) =e= sum(q(a(n,np)\$(np=i)) + q(n)

GAMS understand :
eq(i)
eq(i,j)

but GAMS undestand:
eq(a(i,j)) ???

my objective is to elaborate an equation that the flow of some arc considering the sum of all arcs that end at the beginning node of the arc that I want to analyse
I found my answer in the GAMS examples: [waterx.gms]
loss(a(n,np))..
h(n) - h(np) =e= [hloss*dist(a)*(qp(a)+qn(a))**(qpow-1)*(qp(a)-qn(a))/d(a)**dpow] \$(qpow <> 2) +
[hloss*dist(a)*(qp(a)+qn(a))* (qp(a)-qn(a))/d(a)**dpow] \$(qpow = 2);

Alexanre.ito
User
Posts: 27
Joined: 1 year ago

### Re: problem with syntax of the equation

I'm developing a simple problem of water transport. But I need a help, someone please could help me.

In my code the flow conservation equation at each node, is working.
(I'm using waterx.gms as reference).

But I need a code that exclude tubes which have zero flow.

I tried to multiply by the binary however it didn't work as I expected.
(You can see the expression in "*")

In my case

Code: Select all

``````Set     n       nodes   / n1 * n12 /
* anel simples a(n,n)
a(n,n)  arcos   / n1.n2, n2.n3, n3.n4, n4.n6, n6.n8 , n8.n12
n5.n7, n7.n9, n9.n10, n10.n11, n11.n12
n1.n5 /
si(n)   saida   / n12 /
cont(n) contribucao; cont(n)=yes; cont(si)=no; display cont;
alias(n,np);

Q           cota
*             (m**3 per s)      (m)
n1         10            10
n2         20           9.8
n3         30           9.6
n4         40           9.4
n5          5          9.9
n6         60           9.2
n7         15          9.7
n8         70           9.0
n9         25          9.5
n10        35          9.3
n11        45          9.1
n12                    8.1;

Scalar
dmin       minimum diameter of pipe        / 0.15   /
dmax       maximum diameter of pipe        / 2.00   /
;

Variables
qp(n,n)        flow on each arc - positive       (m**3 per sec)
qn(n,n)        flow on each arc - negative       (m**3 per sec)
d(n,n)         pipe diameter for each arc        (m)
*         dt(n,n)        diam teste
s(n)           vazão de saída da rede            (m**3 per sec)

qma(n,n)       vazão máxima no trecho            (m**3 per sec)

cost           total discounted costs            (custo aleatorio)
pen            objective penalty
;

Positive variables qp, qn(n,np);

Binary variable qb(n,np);

Equation

cons(n)    equação da conservação de vazão de cada nó
qpup(n,np) positive bounds
qnup(n,np) negative bounds
qamx(n,np) vazão máxima
*                 diam(n,np) determinação do diametro

dpen        penalty definition
fo          função objetivo
;

cons(n)..   sum(a(np,n), qp(a)-qn(a)) - sum(a(n,np), qp(a)-qn(a)) - s(n)\$si(n) =e= node(n,"Q");

qpup(a)..   qp(a) =l=  qma(a)*qb(a);
qnup(a)..   qn(a) =l=  qma(a)*(1-qb(a));

qamx(a)..   qma(a) =e= sum(n, node(n,"Q"));

*diam(a)..   d(a) =e= dt(a)*qb(a);

dpen..      pen   =e= sum(a, d(a));

fo..        cost  =e= pen ;

*  bounds

d.lo(n,np)\$a(n,np) = dmin;                 d.up(n,np)\$a(n,np) = dmax;

*  initial values

d.l(n,np)\$a(n,np)  = 0.1;

Model network /all/;

network.domlim  =   1000;
network.iterlim = 100000;

Solve network using minlp minimizing cost``````
In my case, I'm looking for the answer, that pepe d(n1 .n5)=0.0, because qn(n1.n5) is "." zero.

Code: Select all

``````---- VAR qn  flow on each arc - negative       (m**3 per sec)

LOWER     LEVEL     UPPER    MARGINAL

n1 .n2       .       10.000      +INF       .
n1 .n5       .         .             +INF       EPS
n2 .n3       .       30.000      +INF       .
n3 .n4       .       60.000      +INF       .
n4 .n6       .      100.000     +INF       .
n5 .n7       .        5.000      +INF       .
n6 .n8       .      160.000     +INF       .
n7 .n9       .       20.000     +INF       .
n8 .n12      .      230.000     +INF       .
n9 .n10      .       45.000     +INF       .
n10.n11      .       80.000     +INF       .
n11.n12      .      125.000     +INF       .

---- VAR d  pipe diameter for each arc        (m)

LOWER     LEVEL     UPPER    MARGINAL

n1 .n2      0.150     0.150     2.000     1.000
n1 .n5      0.150      0.0     2.000     1.000
n2 .n3      0.150     0.150     2.000     1.000
n3 .n4      0.150     0.150     2.000     1.000
n4 .n6      0.150     0.150     2.000     1.000
n5 .n7      0.150     0.150     2.000     1.000
n6 .n8      0.150     0.150     2.000     1.000
n7 .n9      0.150     0.150     2.000     1.000
n8 .n12     0.150     0.150     2.000     1.000
n9 .n10     0.150     0.150     2.000     1.000
n10.n11     0.150     0.150     2.000     1.000
n11.n12     0.150     0.150     2.000     1.000``````
And if is possible the binary:

Code: Select all

``````---- VAR qb

LOWER     LEVEL     UPPER    MARGINAL

n1 .n2       .         1.0        1.000      EPS
n1 .n5       .           .         1.000      EPS
n2 .n3       .         1.0        1.000      EPS
n3 .n4       .         1.0        1.000      EPS
n4 .n6       .         1.0        1.000      EPS
n5 .n7       .         1.0        1.000      EPS
n6 .n8       .         1.0        1.000      EPS
n7 .n9       .         1.0        1.000      EPS
n8 .n12      .         1.0        1.000      EPS
n9 .n10      .         1.0        1.000      EPS
n10.n11      .         1.0        1.000      EPS
n11.n12      .         1.0        1.000      EPS       ``````

Fred
Posts: 245
Joined: 4 years ago

### Re: problem with syntax of the equation

Hi,

You set a lower bound of 0.15 for d(n1 .n5):

Code: Select all

`````` d.lo(n,np)\$a(n,np) = dmin;
``````
Hence, it cannot be zero.

I hope this helps!

Fred

Alexanre.ito
User
Posts: 27
Joined: 1 year ago

### Re: problem with syntax of the equation

Yes, you're right
I need to improve!!

I need this lower bound, during the calculation.

But the diameter need to be Zero, when is not allowed a tube, in other words, when flow is Zero, the diameter is zero too.
Fred wrote:
8 months ago
Hi,

You set a lower bound of 0.15 for d(n1 .n5):

Code: Select all

`````` d.lo(n,np)\$a(n,np) = dmin;
``````
Hence, it cannot be zero.

I hope this helps!

Fred