Gams how to write equations?

859 views Asked by At

I want to write these equations:

    X21+X22+X23+X24=55
    X11+X12+X13+X14=90
    X11+X21<=H1*Y11+H2*Y21+H3*Y31

I know I should use SUM function but I don't know it exactly but i can't convert them. how can I write them in equation section? here is the part of my code:

SETS
i   regions /shomal,jonub/
j   cities  /shiraz,esfahan,hamedan,yazd/
k   palaieshgahha /p1,p2,p3/;

PARAMETERS
         Y(k,j) pk Ntekhab shavad ia nashavad /1,0/
         S(k) sarmaieye  avalie /400000,600000,950000/
         H(k) zarfiate palaieshgah /20,35,50/;

 Table c(i,j)  cost 1milion boshke b milion rial
                    shiraz  esfahan   hamedan   yazd
      shomal         120        90         75     80
      jonub          45         65         110    95;

 VARIABLES
       X(i,j)   tedad milion boshke
       Y(k,j)      Ntekhabe palaieshgah
         Z       total cost;
POSITIVE VARIABLE X ;
EQUATIONS
//I have problem here
2

There are 2 answers

0
kon psych On

rafaelcidade's answer needs some corrections i.e instead of

eqn2.. sum(i, X('shomal', i))  =e= 90;

should be

eqn2.. sum(j, X('shomal', j))  =e= 90;

and instead of

eqn3.. X('jonub', 'shiraz') + X('jonub', 'shiraz') =le= H('p1') * Y('shomal','shiraz') + ... ;

should be

eqn3.. sum(i,x(i,'shiraz') =le= sum(k,H(k)*Y(k,'shiraz'));

another option is define a set of equations on set i defining first two equations as

Parameter val(i) = /55,90/;
Equations eqn_block1(i) 'first block of equations';
eqn_block1(i).. sum(j,X(i,j)) =e= val(i);

Another observation on question is that you defined Y as both parameter and variable. You also defined two values for the parameter which I am not sure if it is wrong but in case it isn't the remaining values will be zero. You probably wanted to define a parameter Y(i) and not Y(k,j)

Anyway, if the values of Y are known then you should not define it as variable. You can find another example with sum and more details in the following tutorial http://www.gams.com/dd/docs/gams/Tutorial.pdf

0
rafaelcidade On

Try:

EQUATIONS 

eqn1 First Equation
eqn2 Second Equation
eqn3 Third Equation;

eqn1.. sum(j, X('jonub', j)) =e= 55;

eqn2.. sum(i, X('shomal', i))  =e= 90;

eqn3.. X('jonub', 'shiraz') + X('jonub', 'shiraz') =le= H('p1') * Y('shomal','shiraz') + ... ;