Linking GAMS and Matlab

Questions on using the GAMS APIs (Python, .NET, etc.)
Post Reply
Bahar_Mdi
User
User
Posts: 19
Joined: 1 year ago

Linking GAMS and Matlab

Post by Bahar_Mdi » 1 month ago

Dear all,

I'm trying to call a gams model from Matlab, but every time it executes the GAMS command, I get the " gdxxrw.exe has stopped working" error.
The model reads the data from excel files and I run the model within the gams IDE just fine!
But when I remove the following codes which are related to importing data from Excel to my gams model, the link between gams and Matlab works properly.

$onecho > data.txt
dset=i rng=i!A1 cdim=1
dset=j rng=j!A1 cdim=1
$offecho

$call GDXXRW Data_Transport.xlsx @data.txt
$GDXIN Data_Transport.gdx
$LOAD i,j
$GDXIN

a sample code is provided in the following. As I said when I substitute i and j with I /1,2/ and j /1,2,3/ instead of importing them from Excel, the link works properly.
________________________________________________________________________

$set matout "'matsol.gdx',x,z";
Set
i 'canning plants'
j 'markets';


$onecho > data.txt
dset=i rng=i!A1 cdim=1
dset=j rng=j!A1 cdim=1
$offecho

$call GDXXRW Data_Transport.xlsx @data.txt
$GDXIN Data_Transport.gdx
$LOAD i,j
$GDXIN

Parameter
a(i) 'capacity of plant i in cases'
/ 1 350
2 600 /

b(j) 'demand at market j in cases'
/ 1 325
2 300
3 275 /;

Table d(i,j) 'distance in thousands of miles'
1 2 3
1 2.5 1.7 1.8
2 2.5 1.8 1.4;

Scalar f 'freight in dollars per case per thousand miles' / 90 /;

Parameter c(i,j) 'transport cost in thousands of dollars per case';
c(i,j) = f*d(i,j)/1000;

Variable
x(i,j) 'shipment quantities in cases'
z 'total transportation costs in thousands of dollars';

Positive Variable x;

Equation
cost 'define objective function'
supply(i) 'observe supply limit at plant i'
demand(j) 'satisfy demand at market j';

cost.. z =e= sum((i,j), c(i,j)*x(i,j));

supply(i).. sum(j, x(i,j)) =l= a(i);

demand(j).. sum(i, x(i,j)) =g= b(j);

Model transport / all /;

solve transport using lp minimizing z;

display x.l;
execute_unload %matout%;
________________________________________________________________________

I appreciate it if someone can help me.
Thanks and regards,
Bahar

Post Reply