Equilibrium modelling - GAMS vs Mathematica

Problems with modeling
Post Reply
saeed
User
User
Posts: 4
Joined: 5 months ago

Equilibrium modelling - GAMS vs Mathematica

Post by saeed » 6 days ago

Hello!

I have been trying to write a model written originally in Mathematica, and I find that GAMS gives less precise solutions. The code below is a simplified version of a portion of the model. I am now trying to re-create my base, and it gives me a solutions that are a bit off: GAMS finds pc=2.151. It should be 3.61. 3.61 is the true price from our base data, and Mathematica is able to find this from the equations below. Is there a fix for this? Or an explanation of what is GAMS doing relative to Mathematica; so that I can explain the difference?

The difference in price is significant enough that my Prof. (who does not use GAMS), feels Mathematica is then a better solver...

Any help appreciated!

Wajiha

Code: Select all

Positive Variables qcdx, qcdd, qcst, pc;
EQUATION  cornexpdemand  ;
 cornexpdemand   .. qcdx =e= 4123029.1453/(pc**(0.5)) ;
EQUATION  cornfooddemand  ;
 cornfooddemand  .. qcdd =e= 10259876.724/(pc**(0.1));
EQUATION  cornsupply   ;
 cornsupply      .. qcst =e= (9552850.67262715*(pc**(0.4)))/(1.14**(0.4)) ;
EQUATION  cornmkteqm  ;
 cornmkteqm      .. qcdx + qcdd - qcst =e= 0 ;
Model corn2 /all/ ;
 pc.LO = 1.0E-6         ;
 pc.L  = 1.0            ;
SOLVE corn2 using CNS    ;

User avatar
bussieck
Moderator
Moderator
Posts: 68
Joined: 1 year ago

Re: Equilibrium modelling - GAMS vs Mathematica

Post by bussieck » 6 days ago

A value of 3.61 can't be right. If you do the reverse calculation you get:

Code: Select all

pc.l = 3.61;
$ondotl;
qcdx.l = 4123029.1453/(pc**(0.5));
qcdd.l = 10259876.724/(pc**(0.1));
qcst.l = (9552850.67262715*(pc**(0.4)))/(1.14**(0.4)) ;
scalar sumqcdxqcdd; sumqcdxqcdd = qcdx + qcdd;
display sumqcdxqcdd, qcst.l;
you get

Code: Select all

----     17 PARAMETER sumqcdxqcdd          =  1.119386E+7  
            VARIABLE qcst.L                =  1.514865E+7  
Next, I wrote an optimization model that tries to comes as close to pc=3.61 but the "closest" solution (solved to global optimality) is 2.1509:

Code: Select all

Positive Variables qcdx, qcdd, qcst, pc;
EQUATION  cornexpdemand  ;
 cornexpdemand   .. qcdx =e= 4123029.1453/(pc**(0.5)) ;
EQUATION  cornfooddemand  ;
 cornfooddemand  .. qcdd =e= 10259876.724/(pc**(0.1));
EQUATION  cornsupply   ;
 cornsupply      .. qcst =e= (9552850.67262715*(pc**(0.4)))/(1.14**(0.4)) ;
EQUATION  cornmkteqm  ;
 cornmkteqm      .. qcdx + qcdd - qcst =e= 0 ;
variable obj; equation defdiff;
defdiff.. sqr(3.61-pc) =e= obj;
Model corn2 /all/ ;
pc.lo = 0.1;
SOLVE corn2 using nlp min obj    ;
with the solution listing:

Code: Select all

                           LOWER          LEVEL          UPPER         MARGINAL

---- VAR qcdx                .       2811264.8903        +INF             .          
---- VAR qcdd                .       9503404.5123        +INF             .          
---- VAR qcst                .       1.2314669E+7        +INF             .          
---- VAR pc                 0.1000         2.1509        +INF             .          
---- VAR obj               -INF            2.1288        +INF             .          
So I wonder about your correct transfer from Mathematica to GAMS code....

-Michael

saeed
User
User
Posts: 4
Joined: 5 months ago

Re: Equilibrium modelling - GAMS vs Mathematica

Post by saeed » 6 days ago

Thank you for this. I did check everything repeatedly - but I do see from what you have done there is something wrong. I will check again.

Thanks!

Post Reply