How to: export all my sets and parameter values into a gams readable file

Archive of Gamsworld Google Group
Post Reply
Archiver
User
User
Posts: 7876
Joined: 7 years ago

How to: export all my sets and parameter values into a gams readable file

Post by Archiver »


I am convinced I have seen this mentioned somewhere as possible, but I cannot seem to find a command for it.

I have a model and we read data from various different places, Excel and text files etc. After reading the data in we make various calculations to this data and also generate new parameters/sets. I would like to dump this final collection of sets and parameters out into a .gms file that can later be picked up by another gams model and taken as the input data.

Because it will be read into another model it needs to have the "set/parameter/scalar" declarations.

As a simple example, after reading in our data and doing a bunch of calculations I would like to automatically output a file with the following contents, which represents all the sets and parameters in my model:

set days /Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday/;
set weekend(days) /Saturday, Sunday/;
scalar DAYSINWEEK /7/;
set item / newspaper, banana /;
parameter ITEMCOST(item) / newspaper 1, banana 0.5 /;

etc



Is there a command in gams that will do this dump for me?

Thanks in advance
Andy

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

RE: How to: export all my sets and parameter values into a gams readable file

Post by Archiver »


Hi Andy

Just add

execute_unload ‘allmystuff.gdx’;



and you will have everythin in a gdx file which then can be used to send to an excel file (for example).

Cheers

Renger

From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of AC
Sent: Thursday, March 24, 2016 5:02 AM
To: gamsworld
Subject: How to: export all my sets and parameter values into a gams readable file



I am convinced I have seen this mentioned somewhere as possible, but I cannot seem to find a command for it.

I have a model and we read data from various different places, Excel and text files etc. After reading the data in we make various calculations to this data and also generate new parameters/sets. I would like to dump this final collection of sets and parameters out into a .gms file that can later be picked up by another gams model and taken as the input data.

Because it will be read into another model it needs to have the "set/parameter/scalar" declarations.

As a simple example, after reading in our data and doing a bunch of calculations I would like to automatically output a file with the following contents, which represents all the sets and parameters in my model:

set days /Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday/;
set weekend(days) /Saturday, Sunday/;
scalar DAYSINWEEK /7/;
set item / newspaper, banana /;
parameter ITEMCOST(item) / newspaper 1, banana 0.5 /;

etc



Is there a command in gams that will do this dump for me?

Thanks in advance
Andy

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.



--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: How to: export all my sets and parameter values into a gams readable file

Post by Archiver »

Andy,

Try the example below, evolved from yours:

set days /Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday/;
set weekend(days) /Saturday, Sunday/;
scalar DAYSINWEEK /7/;
set item / newspaper, banana /;
parameter ITEMCOST(item) / newspaper 1, banana 0.5 /;

execute_unload 'selected', days, weekend, daysinweek, item, itemcost;
execute_unload 'all';

execute 'gdxdump selected.gdx noData > selected.gms';
execute 'gdxdump all.gdx noData > all.gms';


Renger suggested the execute_unload call to send data to GDX. You can select the symbols to write to GDX, or just write all of them. You can then call the gdxdump utility with the noData option to write some GAMS source code to declare the sets/parameters involved and read the data from GDX. If you have a look at the selected.gms and all.gms files that result from running the example above it should be mostly self-explanatory. If some of the details are murky, don't hesitate to ask about them.

-Steve

On Thu, Mar 24, 2016 at 12:02 AM, AC wrote:

I am convinced I have seen this mentioned somewhere as possible, but I cannot seem to find a command for it.

I have a model and we read data from various different places, Excel and text files etc. After reading the data in we make various calculations to this data and also generate new parameters/sets. I would like to dump this final collection of sets and parameters out into a .gms file that can later be picked up by another gams model and taken as the input data.

Because it will be read into another model it needs to have the "set/parameter/scalar" declarations.

As a simple example, after reading in our data and doing a bunch of calculations I would like to automatically output a file with the following contents, which represents all the sets and parameters in my model:

set days /Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday/;
set weekend(days) /Saturday, Sunday/;
scalar DAYSINWEEK /7/;
set item / newspaper, banana /;
parameter ITEMCOST(item) / newspaper 1, banana 0.5 /;

etc



Is there a command in gams that will do this dump for me?

Thanks in advance
Andy

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.




--
Steven Dirkse, Ph.D.
GAMS Development Corp., Washington DC
Voice: (202)342-0180 Fax: (202)342-0181
sdirkse@gams.com
http://www.gams.com
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: How to: export all my sets and parameter values into a gams readable file

Post by Archiver »


Thanks Steven/Renger, this gives me what I am after.

On Sunday, March 27, 2016 at 2:41:38 PM UTC+13, Steven Dirkse wrote:

Andy,

Try the example below, evolved from yours:

set days /Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday/;
set weekend(days) /Saturday, Sunday/;
scalar DAYSINWEEK /7/;
set item / newspaper, banana /;
parameter ITEMCOST(item) / newspaper 1, banana 0.5 /;

execute_unload 'selected', days, weekend, daysinweek, item, itemcost;
execute_unload 'all';

execute 'gdxdump selected.gdx noData > selected.gms';
execute 'gdxdump all.gdx noData > all.gms';


Renger suggested the execute_unload call to send data to GDX. You can select the symbols to write to GDX, or just write all of them. You can then call the gdxdump utility with the noData option to write some GAMS source code to declare the sets/parameters involved and read the data from GDX. If you have a look at the selected.gms and all.gms files that result from running the example above it should be mostly self-explanatory. If some of the details are murky, don't hesitate to ask about them.

-Steve

On Thu, Mar 24, 2016 at 12:02 AM, AC wrote:

I am convinced I have seen this mentioned somewhere as possible, but I cannot seem to find a command for it.

I have a model and we read data from various different places, Excel and text files etc. After reading the data in we make various calculations to this data and also generate new parameters/sets. I would like to dump this final collection of sets and parameters out into a .gms file that can later be picked up by another gams model and taken as the input data.

Because it will be read into another model it needs to have the "set/parameter/scalar" declarations.

As a simple example, after reading in our data and doing a bunch of calculations I would like to automatically output a file with the following contents, which represents all the sets and parameters in my model:

set days /Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday/;
set weekend(days) /Saturday, Sunday/;
scalar DAYSINWEEK /7/;
set item / newspaper, banana /;
parameter ITEMCOST(item) / newspaper 1, banana 0.5 /;

etc



Is there a command in gams that will do this dump for me?

Thanks in advance
Andy

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.




--
Steven Dirkse, Ph.D.
GAMS Development Corp., Washington DC
Voice: (202)342-0180 Fax: (202)342-0181
sdi...@gams.com
http://www.gams.com

--
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Post Reply