Problem with data exchange and dynamic sets Topic is solved

Problems with syntax of GAMS
Post Reply
Afccruz
User
User
Posts: 2
Joined: 3 years ago

Problem with data exchange and dynamic sets

Post by Afccruz »

Hi! I've been trying to exchange data from Excel to GAMS. I checked a Youtube video, and ran this code:

Code: Select all

Set i nodes /1,2,3,4,5,6,7,8,9,10,11,12/;

Parameter Dst(i,i) Distances between two nodes;

$onmulti
$onecho > ficheiroteste.txt
dset=i rng=a1 rdim=1
par=Dst rng=DistanceDur!a1 rdim=1 cdim=1
$offecho
$offmulti

$call GDXXRW InstanzCPLEX_HCSRP_10_2.xlsx trace=3 @ficheiroteste.txt
$GDXIN  InstanzCPLEX_HCSRP_10_2.gdx
$LOADm  i
$LOAD   Dst
$GDXIN

Display Dst;
This works, as I am able to transfer the 12 nodes to GAMS and successfully build a table with them. If I then remove the defined nodes, and leave it strictly like this:

Code: Select all

Set i nodes;

Parameter Dst(i,i) Distances between two nodes;

$onmulti
$onecho > ficheiroteste.txt
dset=i rng=a1 rdim=1
par=Dst rng=DistanceDur!a1 rdim=1 cdim=1
$offecho
$offmulti

$call GDXXRW InstanzCPLEX_HCSRP_10_2.xlsx trace=3 @ficheiroteste.txt
$GDXIN  InstanzCPLEX_HCSRP_10_2.gdx
$LOADm  i
$LOAD   Dst
$GDXIN

Display Dst;
The set nodes becomes flexible, meaning that I can add or remove a node in the Excel, and it will respectively appear or disappear in the GAMS log. However, this only works if the Excel has only one sheet. If I have more than one, no error occurs, but the values of the nodes are not loaded, and in the GAMS log the parameter Dst is presented as an empty table.
Can anyone help me? It would be helpful if I could use more than in the Excel file I'm working, so that I could have more sets there, instead of having to create an Excel file for each set.
Thankyou very much!
GFA
User
User
Posts: 50
Joined: 5 years ago

Re: Problem with data exchange and dynamic sets

Post by GFA »

Hi Afccruz,

Didn't test it but looking at your code I think you need to provide a sheetname for set "i" in ficheiroteste.txt (like you did for the Dst parameter, sheet DistanceDur): rng=<sheetname>!a1

You can also write a log-file of the GDXXRW call which may give you some hints:

Code: Select all

 $call GDXXRW InstanzCPLEX_HCSRP_10_2.xlsx trace=3 @ficheiroteste.txt log=logfile.txt 
Regards,
GFA
Afccruz
User
User
Posts: 2
Joined: 3 years ago

Re: Problem with data exchange and dynamic sets

Post by Afccruz »

Thanks!
It worked!
Post Reply