Net, Loading and unloading of resources Topic is solved

Problems with syntax of GAMS
Post Reply
YCCC97
User
User
Posts: 6
Joined: 2 years ago

Net, Loading and unloading of resources

Post by YCCC97 »

image.png

Hello guys, i would like to know how to do the coding for the equation section if i want to let the model automatically let the positive value of NVS equals to "LVS" and negative value of NVS equals to -ULVS/0.9. And how to do the coding for CVS? Many thanks!

Eq8nvs(i,d).. NVS(i,d) =E= VSS(i,d)-IVSD(i,d);
Eq8e(i,d).. CVS(i,'d1')=E= VSS(i,'d1')-IVSD(i,'d1');
Eq8f(i,d).. CVS(i,d)=E= CVS(i,d-1)+[VSS(i,d)]-IVSD(i,d);

im doing it halfway and stucked...

NVS = net vs resource
LVS = loading of VS into storage tank
ULVS=unloading of VS from storage tank
CVS=cumulative of VS resources.
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: Net, Loading and unloading of resources

Post by abhosekar »

Looks like all these are parameters. You don't need =e= type equations for this. This are simply assignments like you do in a normal program.

what do you mean by "positive value of NVS equal to "LVS"" if you already have a value, do you want to reset it? Do you already have values for NVS?
If so,
NVS(i,d)$(NVS(i,d) > 0) = LVS(i,d);

NVS(i,d)$(NVS(i,d) < 0) = -ULVS(i,d)/0.9;

If all of these are not parameters, then your question does not make sense because variables don't have values. They have values only after solve.

Hope this helps.

- Atharv
YCCC97
User
User
Posts: 6
Joined: 2 years ago

Re: Net, Loading and unloading of resources

Post by YCCC97 »

Hi, i do realised that should be put under parameter too! However, i would required to use some variables obtain from the equation section and put in the parameter section, but then the error shows "a suffix is missing..."


Cmole(j)=sum[i,Cij(i,j)]/Cmw;
Hmole(j)=sum[i,Hij(i,j)]/Hmw;
Omole(j)=sum[i,Oij(i,j)]/Omw;
Nmole(j)=sum[i,Nij(i,j)]/Nmw;

abhosekar wrote: 2 years ago Looks like all these are parameters. You don't need =e= type equations for this. This are simply assignments like you do in a normal program.

what do you mean by "positive value of NVS equal to "LVS"" if you already have a value, do you want to reset it? Do you already have values for NVS?
If so,
NVS(i,d)$(NVS(i,d) > 0) = LVS(i,d);

NVS(i,d)$(NVS(i,d) < 0) = -ULVS(i,d)/0.9;

If all of these are not parameters, then your question does not make sense because variables don't have values. They have values only after solve.

Hope this helps.

- Atharv
Last edited by YCCC97 2 years ago, edited 1 time in total.
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: Net, Loading and unloading of resources

Post by abhosekar »

After solve, variables have much more information than just the solution. They have (.l, .lo, .up, .scale, .m). Please take a look at variable attributes for more details: https://www.gams.com/latest/docs/UG_Var ... Attributes
When you just write variablename, GAMS does not understand which one of these you really want. This is why you get suffix is missing error. You should use .l

Code: Select all

Cmole(j)=sum[i,Cij.l(i,j)]/Cmw;
Hmole(j)=sum[i,Hij.l(i,j)]/Hmw;
Omole(j)=sum[i,Oij.l(i,j)]/Omw;
Nmole(j)=sum[i,Nij.l(i,j)]/Nmw;
Please use code blacks like the one I have used here if you post a code fragment/entire code. This way other users can just copy and run your code.

- Atharv
YCCC97
User
User
Posts: 6
Joined: 2 years ago

Re: Net, Loading and unloading of resources

Post by YCCC97 »

Many thanks for your advises and tips! Never know i can include the variable attributes like you show. God bless you.
abhosekar wrote: 2 years ago After solve, variables have much more information than just the solution. They have (.l, .lo, .up, .scale, .m). Please take a look at variable attributes for more details: https://www.gams.com/latest/docs/UG_Var ... Attributes
When you just write variablename, GAMS does not understand which one of these you really want. This is why you get suffix is missing error. You should use .l

Code: Select all

Cmole(j)=sum[i,Cij.l(i,j)]/Cmw;
Hmole(j)=sum[i,Hij.l(i,j)]/Hmw;
Omole(j)=sum[i,Oij.l(i,j)]/Omw;
Nmole(j)=sum[i,Nij.l(i,j)]/Nmw;
Please use code blacks like the one I have used here if you post a code fragment/entire code. This way other users can just copy and run your code.

- Atharv
YCCC97
User
User
Posts: 6
Joined: 2 years ago

Re: Net, Loading and unloading of resources

Post by YCCC97 »

Good day, after i code LVS and ULVS under parameter, and added suffix to the variable, it showed Symbol declared but no values have been assigned. Is it because i code the parameter section at wrong sequence??

Code: Select all

$onuellist

Set
i  supply /i1*i2/
j  demand /j1/
d number of days in a time cycle /d1*d7/
OW organic waste 1=swine manure 2=rice straw /OW1*OW2/
*VSS daily volatile solid supply
;

Parameter MFi(i) mass flow of supply
*i1=swine manure; i2=rice straw;
/
i1 99
i2 99
/
;

Parameter MFj(j) mass flow of demand
*j1=methane
/
j1  20
/
;

Parameter CNi(i) CN of supply
*i1=swine manure;
*i2=rice straw;
/
i1  15.8
i2  44.1
/
;

Parameter CNj(j) CN of demand
*j1=methane
/
j1  27.4
/
;

Parameter j1_kWh(d) daily energy demand per house @kWh
/
d1 22
d2 23
d3 21
d4 23
d5 22
d6 25.5
d7 25.8
/
;

Parameter dummy(d) daily energy demand per house @kWh
/
d1 1
d2 1
d3 1
d4 1
d5 1
d6 1
d7 1
/
;

*Parameter VSS1(d) daily VS for supply 1
*/
*d1 204
*d2 132
*d3 120
*d4 156
*d5 132
*d6 59
*d7 34
*/
*;

*Parameter VSS2(d) daily VS for supply 2
*/
*d1 299
*d2 325
*d3 286
*d4 273
*d5 338
*d6 0
*d7 0
*/
*;

*Table VSS(d,i) daily Volatile solid supply
*         i1    i2
*d1       204   299
*d2       132   325
*d3       120   286
*d4       156   273
*d5       132   338
*d6        59   0
*d7        34   0
*;

Table VSS(i,d) daily Volatile solid supply
         d1    d2     d3     d4     d5     d6     d7
i1       204   132    120    156    132    59     32
i2       299   325    286    273    338    0      0

;

Parameter TS(i) total solid percentage
/
i1 30.4
i2 92.9
/
;

Parameter C(i) carbon in the total solid percentage
/
i1 34.8
i2 39.7
/
;

Parameter H(i) hydrogen in the total solid percentage
/
i1 4.7
i2 5.4
/
;

Parameter O(i) oxygen in the total solid percentage
/
i1 30.3
i2 38.2
/
;

Parameter N(i) nitrogen in the total solid percentage
/
i1 2.2
i2 0.9
/
;

Parameter Other(i) other components in the total solid percentage
/
i1 28
i2 15.8
/
;

Parameter CN(i) CN ratio
/
i1 15.8
i2 44.1
/
;

Parameter VS(i) volatile solid in the total solid percentage
/
i1 22
i2 81.6
/
;

Parameter
Ci(i) C of supply,Cj(j) C of demand,
Ni(i) N of supply,Nj(j) N of demand
;
Ci(i)=[CNi(i)/(CNi(i)+1)]*MFi(i);
Cj(j)=CNj(j)/(CNj(j)+1)*MFj(j);
Ni(i)=MFi(i)-Ci(i);
Nj(j)=MFj(j)-Cj(j);

Scalar
Unit unit of houses /50/
CN_ch4 CN ratio required by methane /27.4/
Cmw  carbon molecular weight /12/
Hmw  hydrogen molecular weight /1/
Omw  oxygen molecular weight /16/
Nmw  nitrogen molecular weight /14/
;

Parameter
j50_kWh(d) total daily energy demand for 50 houses @kWh,
j_ch4 equivalent of methane demand for 50 houses @m3 CH4,
p_m4 average production of methane
p_ch4 daily production of methane,
n_ch4 daily net methane,
c_ch4 daily methane cumulative
;
j50_kWh(d)=j1_kWh(d)*50;
j_ch4(d)=j50_kWh(d)/10;
p_m4=sum[d,j_ch4(d)]/7;
p_ch4(d) = p_m4*dummy(d);
n_ch4(d)=p_ch4(d)-j_ch4(d);
c_ch4('d1')=p_ch4('d1')-j_ch4('d1');
c_ch4('d2')=c_ch4('d1')+p_ch4('d2')-j_ch4('d2');
c_ch4('d3')=c_ch4('d2')+p_ch4('d3')-j_ch4('d3');
c_ch4('d4')=c_ch4('d3')+p_ch4('d4')-j_ch4('d4');
c_ch4('d5')=c_ch4('d4')+p_ch4('d5')-j_ch4('d5');
c_ch4('d6')=c_ch4('d5')+p_ch4('d6')-j_ch4('d6');
c_ch4('d7')=c_ch4('d6')+p_ch4('d7')-j_ch4('d7');
*c_ch4(d)=C_ch4(d-1)+p_ch4(d)-j_ch4(d);

Variable
OF       Objective function
NVS        Net VS
MFij       Mass flowrate from supply to demand
Frij(i,j)  Fraction of supply to demand

;

Positive variable

Cij        Carbon from supply to demand
Nij        Nitrogen from supply to demand
Hij        Hydrogen from supply to demand
Oij        Oxygen from supply to demand
Otherij    Other from supply to demand

Cmole      Carbon mole received by each demand
Hmole      Hydrogen mole received by each demand
Omole      Oxygen mole received by each demand
Nmole      Nitrogen mole received by each demand
TP_ch4     Theoretical ch4 production based on the feedstock composition
TP_co2     Theoretical co2 production based on the feedstock composition
TP_nh3     Theoretical nh3 production based on the feedstock composition
TA_fac     Theoretical-actual factor for the production
AP_co2     Actual co2 production based on the feedstock composition
AP_nh3     Actual nh3 production based on the feedstock composition
Biogas_s   Biogas storage capacity
TVS        TOtal vs demand
TVSD       Daily Total VS demand
IVS        Individual VS demand
IVSD       Daily Individual VS demand
CVS        Cumulative VS
CVSmax     maximum cumulative VS
y          individual mass percentage of supply
;

Equation
Eq1      Total MF of supply must equal or less than supply to demand
Eq2a     Sending C and N simultaneously from supply to demand side
Eq2b     Sending C and N simultaneously from supply to demand side
Eq2c     Sending C and N simultaneously from supply to demand side
Eq2d     Sending H from supply to demand side
Eq2e     Sending O from supply to demand side
Eq2f     Sending other components from supply to demand side
Eq3      Total fraction used for each supply must less than 1

Eq4a    Sum of demand MF must equal to sum of supply and external supply
Eq4b    Sum of demand C must equal to sum of supply and external supply
Eq4c    Sum of demand N must equal to sum of supply and external supply
Eq0F    OF minimize the utilization of ES

Eq5a    Carbon mole received by each supply
Eq5B    Hydrogen mole received by each supply
Eq5C    Oxygen mole received by each supply
Eq5D    Nitrogen mole received by each supply

Eq6a    Theoretical CH4 production @ m3 per kg VS
Eq6b    Theoretical CO2 production @ m3 per kg VS
Eq6c    Theoretical NH3 production @ m3 per kg VS

Eq7a    Actual CH4 production @ m3 per kg VS
Eq7b    Actual CO2 production @ m3 per kg VS
Eq7c    Actual NH3 production @ m3 per kg VS
Eq7d    Biogas storage capacity

Eq8a     total VS demand
Eq8b     daily total VS demand
Eq8c     individual VS demand
Eqy      mass percentage
Eq8d     daily Individual VS demand
Eq8NVS   daily net VS
Eq8e     cumulative VS
Eq8f     cumulative VS

*Eq9a       CVSmax
*Eq9b       OW storage
;

Eq1(i)..        (MFi(i))=G=sum[(j),MFij(i,j)];
Eq2a(i,j)..      MFij(i,j) =E=(Frij(i,j))*[Ci(i)+Ni(i)];
Eq2b(i,j)..      Cij(i,j) =E= Frij(i,j)*Ci(i);
Eq2c(i,j)..      Nij(i,j) =E= Frij(i,j)*Ni(i);
Eq2d(i,j)..      Hij(i,j) =E= [H(i)/C(i)]*[Cij(i,j)];
Eq2e(i,j)..      Oij(i,j) =E= [O(i)/C(i)]*[Cij(i,j)];
Eq2f(i,j)..      Otherij(i,j) =E=[Other(i)/C(i)]*[Cij(i,j)];
Eq3(i,j)..       Frij(i,j)=L=1;

Eq4a(j)..        MFj(j)=E=sum[i,MFij(i,j)];
Eq4b(j)..        Cj(j)=E=sum(i,Cij(i,j));
Eq4c(j)..        Nj(j)=E=sum(i,Nij(i,j));

Eq5a(j)..        Cmole(j)=E=sum[i,Cij(i,j)]/Cmw;
Eq5b(j)..        Hmole(j)=E=sum[i,Hij(i,j)]/Hmw;
Eq5c(j)..        Omole(j)=E=sum[i,Oij(i,j)]/Omw;
Eq5d(j)..        Nmole(j)=E=sum[i,Nij(i,j)]/Nmw;

Eq6a(j)..        TP_ch4(j)*[12*Cmole(j)+Hmole(j)+16*Omole(j)+14*Nmole(j)]=E={22.4*[0.5*Cmole(j)+0.125*Hmole(j)-0.25*Omole(j)-0.375*Nmole(j)]*0.8};
Eq6b(j)..        TP_co2(j)*[12*Cmole(j)+Hmole(j)+16*Omole(j)+14*Nmole(j)]=E={22.4*[0.5*Cmole(j)-0.125*Hmole(j)+0.25*Omole(j)+0.375*Nmole(j)]*0.8};
Eq6c(j)..        TP_nh3(j)*[12*Cmole(j)+Hmole(j)+16*Omole(j)+14*Nmole(j)]=E={22.4*Nmole(j)*0.8};

Eq7a..           TA_fac*sum(j,TP_ch4(j))=E=[smax(d,c_ch4(d))];
Eq7b(j)..        AP_co2(j)=E=TP_co2(j)*TA_fac;
Eq7c(j)..        AP_nh3(j)=E=TP_nh3(j)*TA_fac;
Eq7d(j)..        Biogas_S(j)=E=[smax(d,c_ch4(d))]+AP_co2(j)+AP_nh3(j);

Eq8a..            TVS*sum(j,TP_ch4(j))=E=sum[d,p_ch4(d)]/7;
Eq8b(d)..         TVSD(d)=E=TVS*dummy(d);
Eq8c(i,j)..       IVS(i,j) =E= [Cij(i,j)+Hij(i,j)+Oij(i,j)+Nij(i,j)+Otherij(i,j)];
Eqy(i,j)..        y(i,j)*{IVS('i1',j)+IVS('i2',j)}=E= IVS(i,j);
Eq8d(i,d)..       IVSD(i,d) =E=sum(j,y(i,j))*TVSD(d);
Eq8nvs(i,d)..     NVS(i,d) =E= VSS(i,d)-IVSD(i,d);
Eq8e(i,d)..       CVS(i,'d1')=E= VSS(i,'d1')-IVSD(i,'d1');
Eq8f(i,d)..       CVS(i,d)=E= CVS(i,d-1)+[VSS(i,d)]-IVSD(i,d);

*Eq9a(i)..         CVSmax(i) =E= smax(d,CVS(i,d))*1;
*Eq9b(i)..        OWSS(i)*sum(i,TS(i))*sum(i,VS(i)) =E= sum(d,CVSmax(i,d));

Eq0F..    OF =E= sum[(i,j),MFij(i,j)]*1;

Parameter
LVS(i,d) VS loading,
ULVS(i,d) VS unloading
;
NVS.l(i,d)$(NVS.l(i,d) > 0) = LVS(i,d);
NVS(i,d)$(NVS(i,d) < 0) = -ULVS(i,d)/0.9;

Model abc /all/;

solve abc us dnlp max OF;

Display
MFi,MFj,MFij.l,
CNi,CNj,
Ci,Cj,Cij.l,
Ni,Nj,Nij.l,
Frij.L
*,OF.L,

MFi,CNi,Ci,Ni,
MFj,CNj,Cj,Nj,
MFij.l,Cij.l,Nij.l,Hij.l,Oij.l,Otherij.l,
Frij.L
*,OF.L,

j50_kWh,j_ch4,p_ch4,c_ch4,
Cmole.l,Hmole.l,Omole.l,Nmole.l,TP_ch4.l,TP_co2.l,TP_nh3.l,
TA_fac.l,AP_co2.l,AP_nh3.l,Biogas_s.L,TVSD.L,IVS.L,y.l,IVSD.L,NVS.l,VSS,CVS.L


abhosekar wrote: 2 years ago After solve, variables have much more information than just the solution. They have (.l, .lo, .up, .scale, .m). Please take a look at variable attributes for more details: https://www.gams.com/latest/docs/UG_Var ... Attributes
When you just write variablename, GAMS does not understand which one of these you really want. This is why you get suffix is missing error. You should use .l

Code: Select all

Cmole(j)=sum[i,Cij.l(i,j)]/Cmw;
Hmole(j)=sum[i,Hij.l(i,j)]/Hmw;
Omole(j)=sum[i,Oij.l(i,j)]/Omw;
Nmole(j)=sum[i,Nij.l(i,j)]/Nmw;
Please use code blacks like the one I have used here if you post a code fragment/entire code. This way other users can just copy and run your code.

- Atharv
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: Net, Loading and unloading of resources

Post by abhosekar »

There are many many fundamentally wrong things in this piece of code. Brings me back to my initial comment
"what do you mean by "positive value of NVS equal to "LVS"" if you already have a value, do you want to reset it? Do you already have values for NVS?"

Parameter
LVS(i,d) VS loading,
ULVS(i,d) VS unloading
;

When you say this you mean that you "know" the value of LVS and ULVS before you solve.

When you say that NVS depends on LVS, and by the above statement (i.e., you know LVS), you should also know NVS, therefore NVS should be a parameter as well.

Note that variables have values only "after" solve. So I don't know what you want to do and it will be good for you to invest some time understanding the concepts of parameters and variables. So the following statement is meaningless because there are no .l values.
NVS.l(i,d)$(NVS.l(i,d) > 0) = LVS(i,d);

I don't know what you want to model but I can confirm that this current logical sequence in your model is wrong.

- Atharv
YCCC97
User
User
Posts: 6
Joined: 2 years ago

Re: Net, Loading and unloading of resources

Post by YCCC97 »

Greetings! My bad as i wanna rush my things but thanks for pointing out my unseen/unpractical attitude in solving GAMS while not really understand all those fundamental. I had tried your method and finally solved my problem! :D Thanks again! :D
abhosekar wrote: 2 years ago There are many many fundamentally wrong things in this piece of code. Brings me back to my initial comment
"what do you mean by "positive value of NVS equal to "LVS"" if you already have a value, do you want to reset it? Do you already have values for NVS?"

Parameter
LVS(i,d) VS loading,
ULVS(i,d) VS unloading
;

When you say this you mean that you "know" the value of LVS and ULVS before you solve.

When you say that NVS depends on LVS, and by the above statement (i.e., you know LVS), you should also know NVS, therefore NVS should be a parameter as well.

Note that variables have values only "after" solve. So I don't know what you want to do and it will be good for you to invest some time understanding the concepts of parameters and variables. So the following statement is meaningless because there are no .l values.
NVS.l(i,d)$(NVS.l(i,d) > 0) = LVS(i,d);

I don't know what you want to model but I can confirm that this current logical sequence in your model is wrong.

- Atharv
Post Reply