## how to add fromula at parameter Topic is solved

Questions on using the GAMS APIs (Python, .NET, etc.)
Monika1111
User Posts: 2
Joined: 1 year ago

### how to add fromula at parameter

Hallo, my name is Monika I am a student and a beginner in GAMS modelling. I have a problem with formulation of one special task. I am solving clasical linear programing problem for maximization of function but in sensitivity analysis. I want to ask if it si posible to add formula into parameters and how to add it. Concretely I need to ad formula for calculation of profit "c(j) zisk". I have there numbers defined, but I would like to replace it with formula calculated from a table "a(i,j)" particularly it should be rows : N1, N2, T1, which are costs for material, costs for labour and revenues. Therefore for calculation profit the formula can be: c(j)= a('T1',j) - a('N1',j) - a('N2',j).I need it for a further calculation. Because I need to lower the revenues of "Dojnice" that is a('T1', '6'), till the revenue will be 0. And it cannot happend without that profit formula. Can you help me with this problem please? I dont know what to do with it. My program is attached and also a table a(i,j). So is it posible to add formula to define a parameter c(j)? or how can this problem be solwed? Thank you.

Program:
program.docx
(12.54 KiB) Downloaded 123 times
\$Title Optimalna struktura vyroby podniku

Sets
i vsetky podmienky
/D1 Orná pôda [ha]
D2 Jadr.krmivo [t]
D3 Bil.teliat [ks]
D4 Bil. MHD [ks]
D5 Jal:býci [ks]
Z1 Ovos [ha]
Z2 Cukrová repa [ha]
Z3 VRK [ha]
Z4 Krm.zmesi [t]
Z5 Bil.zel.krmivo [t]
Z6 Dojnice [ks]
Z7 Reprod.dojn. [ks]
Z8 Nákup KZ [t]
N1 PN [tis. Eur]
N2 MN [tis. Eur]
P1 Kuk.na sil. [ha]
P2 SNL [t]
P3 ŠH [t]
T1 Tržby [tis. Eur]/

d(i) podmienky typu direktiva /D1*D5/
z(i) podmienky typu zdroj /Z1*Z8/
n(i) podmienky typu naklady /N1*N2/
p(i) podmienky typu poziadavky /P1*P3/
t(i) podmienky typu trzby /T1/

j premenne
/1 Pšenica [ha]
2 Ovos [ha]
3 Cukr. r. [ha]
4 Kuk.na sil. [ha]
5 Viacroč.krm.[ha]
6 Dojnice [ks]
7 Telce [ks]
8 Jalovice [ks]
9 Výkrm HD [ks]
10 Predaj obil [t]
11 Nákup KZ [t]/;

Parameters
b(i) prave strany
/D1 400.00
D2 50.00
D3 0.00
D4 0.00
D5 0.00
Z1 30.00
Z2 80.00
Z3 100.00
Z4 0.00
Z5 0.00
Z6 80.00
Z7 0.00
Z8 100.00
N1 700.00
N2 2000.00
P1 50.00
P2 20.00
P3 50.00
T1 4000.00/
c(j) zisk
/1 -3.42
2 -3.15
3 7.77
4 -4.50
5 -3.35
6 10.70
7 -1.10
8 2.70
9 9.77
10 2.30
11 -1.90/;

Table a(i,j) lp
\$Call=xls2gms r=A1:L20 i=a.xls o=lpp.inc
\$include lpp.inc
;

Variables

x(j) objem vyroby
f hodnota ucelovej funkcie - max zisk
m hodnota min zisku;

Positive variable x;

Equations

direktiva(d) direktivne podmienky a bilancie
zdroje(z) podmienky typu zdroj
naklady (n) podmienky typu naklady
poziadavky(p) podmienky typu poziadavky
trzby (t) podmienky typu trzby
zisk hodnota UF;

direktiva(d).. sum(j,a(d,j)*x(j)) =e= b(d);
zdroje(z).. sum(j,a(z,j)*x(j)) =l= b(z);
naklady (n).. sum(j,a(n,j)*x(j)) =l= b(n);
poziadavky(p).. sum(j,a(p,j)*x(j)) =g= b(p);
trzby (t).. sum(j,a(t,j)*x(j)) =g= b(t);
zisk.. sum(j,c(j)*x(j)) =e= f;

Model struktura Optimalna struktura vyroby podniku /all/;

Solve struktura using LP maximizing f;

Renger
Posts: 639
Joined: 4 years ago

### Re: how to add fromula at parameter

Hi
I might be missing the point, but why don't you use the profit equation as described in your question?

Code: Select all

``````equation profit(j)  Profit equation;
c(j)=E=  a('T1',j) - a('N1',j) - a('N2',j)
``````
If you paste code, please use the button "</>" in the editor. It will keep the formatting.
Furthermore, without the table a itself, it might be difficult to check what you are doing.

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

Monika1111
User Posts: 2
Joined: 1 year ago

### Re: how to add fromula at parameter

Thank you for answer. I tried it before to use that formula as an equation but it does not work. It declared error. I dont know why maybe because of the existence of relation between last two equations? So I want to express c(j) as an formula, therefore I removed this c(j) from the parametres whith values and add this equation of c(j) which you recomended me. And it declared error in the line, which before did not: "56 Endogenous operands for * not allowed in linear models". And because of that it does not work. This error should be in the line 105 where is written: "Solve struktura using LP maximizing f;", but as I said it was not there before adding this equation. Im sending in the attachement the screenshot of the error and also edited program and excel table.
Again thank you for your help.

program.txt
(3.43 KiB) Downloaded 121 times
Attachments
a.xls
(24.5 KiB) Downloaded 112 times

Renger
Posts: 639
Joined: 4 years ago

### Re: how to add fromula at parameter

Hi
You made your model non-linear as the variables C and X are multiplied with each other.
If you change your solve instruction into

Code: Select all

``````Solve struktura using NLP maximizing f;
``````
it solves nicely.
Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist