problem with syntax of the equation

I’m new with optimization and GAMS. I not sure how to declare the Manning equation. This equation describe the flow dynamic on free flow condition, considering geometry and viscosity.

I declared scalar and variables as:
man manning coef / 1.30e-2 /
q(n,n) flow (m3 per s)
ir(n,n) inclination (m per m)
am(n,n) area (m
2)
pm(n,n) perimeter (m)

and the equation like
mann… man*q(n,n)/sqrt(ir(n,n) =e= (am(n,n)(5/3)/(pm(n,n)(2/3))

but i’m not shure if is the correct form

the variable that I need to find is “ir”.
But “am” and “pm” may vary depending on the “ir” variable as well, because of another energy equation and other free surface flux conditions.

My question is, the form that I declared the equation (mann) is correct or I need to isolate the variable “ir” that I need to find? to have convergency or have a faster model.

Looks fine, and as long as you have at least as many equations as variables in your model, there is nothing wrong with using an implicit definition of this variable.
Cheers
Renger

Thanks a lot.

I am new to GAMS…I have interfaced matlab and gams…however while solving it, I am getting the error 149 and 148…Can someone help…Parameters f, b_L…etc are column vectors whereas Cmat and H are matrices…Can anyone help me?


Set j /123/;
Set i /1
75/;
Set k/ 123/;
Set l/1
75/;
Set m/175/;
Set n /1
23/;
Set p /123/;
Set q /1
23/;
Set r /1*23/;




Parameter Cmat(i,j);
Parameter f(k);
Parameter H(n,n);
Parameter b_L(l)
Parameter b_U(m)
Parameter x_L(p)
Parameter x_U(q);

$GDXIN ‘MtoG1’
$LOADIDX Cmat f H b_L b_U x_L x_U
$GDXIN

Free Variables var, func;
Equations
obj
con1
con2;
obj … func =e= 0.5 * var^T * H(n,n) * var + f(k)^T * var;

con1 … x_L(p) =l= var =l= x_U(q);

con2 … b_L(l) =l= Cmat(i,j) * var =l= b_U(m);
Model project1 / all / ;
Solve project1 using NLP minimizing func;
*Parameter xval;
*xval=x.l;
*Execute_UnloadIdx ‘GtoM1’ xval;
*display x.l

Hi

You could search in this forum: It will give you 16 pages with posts with the same answer… (and read the guidelines).

Cheers

Renger

PS. If you enter code in your post, use the code block (the symbol in the menu bar of the editor with the </> sign on it. This keeps the code nicely formatted and readable.

I just want to know whether the matrices from matlab workspace is loaded in the same way as they are…If the matrix is a column vector, which is considered as one dimensional variable, how can I write the transpose of that variable ? Please help me…

I have loaded the matrices from matlab. Now some of the matrices are column vectors and the elements are mostly zeros. I want to know whether they are loaded as column vectors in gams. How to write transpose of a variable. If my variable is x1 with j rows and 1 column, how can I write the transpose of x1…Will it be x1(j)^T?

Hi
Why do you want to have a transposed vector. Multiplying a vector with a matrix can be done in Gams without the use of transposing.

set i /i1*i4/;
set j /j1*j5/;
parameter x(i), m(i,j);
x(i) = uniform(0,1);
m(i,j) = uniform(0,1);
display x, m;

* Multiplying m with x:

parameter leftm(j);

leftm(j) = sum(i, x(i) * m(i,j));

display leftm;

* transposing M

parameter mt;
mt(j,i) = m(i,j);

display mt;

parameter rightm(j);

rightm(j) = sum(i, x(i) * mt(j,i));

display rightm;

If, for whatever reason, you want to have a column vector you can do this as follows:

parameter xc(i,*);

xc(i,"Mytransposed") = x(i);
display xc;

    mytranspo~

i1       0.172
i2       0.843
i3       0.550
i4       0.301
    mytranspo~

i1       0.172
i2       0.843
i3       0.550
i4       0.301

Cheers
Renger

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

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 undestand
eq(i) and eq(i,j)
but GAMS undestand eq(a(i,j))??

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

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

I found my answer in the GAMS examples: [waterx.gms]
loss(a(n,np))…
h(n) - h(np) =e= [hlossdist(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);

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

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);

Table    node(n,*) dados dos nos

                    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.

---- 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:

---- 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

Hi,

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

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

Hence, it cannot be zero.

I hope this helps!

Fred

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.