automatizing gams

Dear gams-user friends,

I am finding trouble when trying to automatize GAMS. Let me explain myself:

I want to run a model on a set of (many) instances. Each instance is defined in a txt file, which contains input data. Such file is added to my model by means of an $include instruction. Besides, I want to keep certain parameters and variables (objective function values, running times, etc.) in an excel file.

Is there a way to automatize all this, without having to change the input-data files and the output files one by one right after the instances are executed?

Thank you so much in advance!

Fede


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 http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

\

Dear Federico,

The easiest way that I can think of at this moment is to make a routine in VBA to write a txt file, then save it to gms file, then run it. For the parameters, you just need to set those up as strings and insert them in the text writing routine. I know the text writing routine is going to be a big long tedious file, but this is sort of a brute force way to do it; simple, but labor intense at the beginning.

Hope it’s useful.

Best,
Ismail Fahmi (http://bit.ly/OCVW6a)


On Mon, Jun 3, 2013 at 9:01 AM, Federico Perea wrote:

Dear gams-user friends,

I am finding trouble when trying to automatize GAMS. Let me explain myself:

I want to run a model on a set of (many) instances. Each instance is defined in a txt file, which contains input data. Such file is added to my model by means of an $include instruction. Besides, I want to keep certain parameters and variables (objective function values, running times, etc.) in an excel file.

Is there a way to automatize all this, without having to change the input-data files and the output files one by one right after the instances are executed?

Thank you so much in advance!

Fede


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 http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.





\

Thank you very much and have a pleasant day.



Sincerely,



Ismail Fahmi

Doctoral Candidate

Process Systems Engineering Group

Chemical Engineering

University of Tulsa


Resume, References, and Transcript: http://bit.ly/OCVW6a



Keplinger Hall Room U319

800 S Tucker Dr

Tulsa, OK 74104

(918) 812-1280


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 http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

\

Fede: From my experience, a practical way to do what you want is to use excel as a “driver”, and from VBA run gams, modify the input files and gather the results. I do not recommend using the gdx utilities, but that’s my experience. I was putting together a tutorial with examples (mostly on the VBA side, which is really easy to learn anyways) to do so but I never found the time to complete it, so if you choose to go that way, we can probably share the learning.

Hope you can get through with what you want.

Regards
Claudio




On Mon, Jun 3, 2013 at 11:01 AM, Federico Perea wrote:

Dear gams-user friends,

I am finding trouble when trying to automatize GAMS. Let me explain myself:

I want to run a model on a set of (many) instances. Each instance is defined in a txt file, which contains input data. Such file is added to my model by means of an $include instruction. Besides, I want to keep certain parameters and variables (objective function values, running times, etc.) in an excel file.

Is there a way to automatize all this, without having to change the input-data files and the output files one by one right after the instances are executed?

Thank you so much in advance!

Fede


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 http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



\

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 http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

\

Reply-to: gamsworld@googlegroups.com

Thank you all for your suggestions.

Frank, the ideas in your gms file are very interesting, but I don’t think they can be applied to my situation. The thing is that I have “n” scenarios. Scenario “i” is saved in file Scenario_i.txt . I want to run the “n” scenarios keeping some variables and parameters values in an Excel sheet. The results with Scenario_i.txt should be stored in the ith row of the excel file.

Ismail and Claudio, I’ll try to apply your ideas (for which I’m gonna need the help of someone more into computer science than myself :wink:

Again, thank you for your interest in my problem. I’ll keep this little chat updated with my (hopefully future) progress.

Best regards

Fede



On Mon, Jun 3, 2013 at 5:20 PM, Frank Ward wrote:

Frederico,



Attached is a medium sized (farm management) GAMS model that defines a separate set with multiple set elements in each set. It lets you run the same model for different combinations of parameter values.



Am also attaching an excel spreadsheet that the model writes to.



Hope it helps.



Frank Ward







From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of Federico Perea
Sent: Monday, June 03, 2013 8:01 AM
To: gamsworld@googlegroups.com
Subject: automatizing gams



Dear gams-user friends,



I am finding trouble when trying to automatize GAMS. Let me explain myself:



I want to run a model on a set of (many) instances. Each instance is defined in a txt file, which contains input data. Such file is added to my model by means of an $include instruction. Besides, I want to keep certain parameters and variables (objective function values, running times, etc.) in an excel file.



Is there a way to automatize all this, without having to change the input-data files and the output files one by one right after the instances are executed?



Thank you so much in advance!



Fede


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 http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


\

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 http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



\

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 http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

\

Fede,

If you are familiar with the language, Python has been a great tool for managing multiple tools.

The few lines below work to write an include file and take two inputs, Switches (a Dict-type with parameters and keys) and InputDir (a string to your input directory).

An example of Switches:
Switches = { ‘SwA’ : 1 , ‘SwB’ : 1 , ‘SwC’ : 1; ‘SwLoadPoint’ : 1 }

An example of InputDir:
InputDir = r"C:\Users\Max\Documents\gamsdir\projdir"

#begin Python code
import os

def WriteIncludeFile(Switches,InputDir):


#CHANGE TO INPUT DIRECTORY
os.chdir(InputDir)

#OPEN A NEW INCLUDE FILE FOR WRITING
#(WB: CREATE NEW FILE IF NONE EXISTS, OVERWRITE IF ONE DOES EXIST):
SwitchesIncFile = open(‘switches.inc’, “wb”)

#WRITE EACH VALUE OF SWITCHES IN SWITCHES.INC SO THAT IT IS READABLE BY GAMS
with SwitchesIncFile as f_out:

#FOR EACH SWITCH IN THE SWITCHES DICTIONARY
for key in Switches:

#WRITE THAT KEY’S SWNAME FROM THE DICTIONARY AND THE VALUE ASSIGNED TO THE SWITCH
SwitchesIncFile.write(key + “=” + str(Switches[key]) +“;” + “\n”)

#CLOSE THE SWITCHES.INC FILE
SwitchesIncFile.close()
os.system(‘call gams fedesmodel.gms lo=2’)
#end python code

If you would like to do this for multiple cases, you could loop over a list of dictionaries. For example:

SwitchesList = [
{ ‘SwA’ : 1 , ‘SwB’ : 1 , ‘SwC’ : 1; ‘SwLoadPoint’ : 1 },
{ ‘SwA’ : 0 , ‘SwB’ : 1 , ‘SwC’ : 1; ‘SwLoadPoint’ : 1 }
]

for Switches in SwitchesList:
WriteIncludeFile(Switches,InputDir):
os.system(‘call gams fedesmodel.gms lo=2’)


Remember to have the GAMS executable path stored as an environmental variable if you plan to use the command line. You can change the options on the command line as well, I prefer lo=2 when running from python since it will store a separate log file.

Best,
Max

On Monday, June 3, 2013 10:01:01 AM UTC-4, fedperea wrote:

Dear gams-user friends,

I am finding trouble when trying to automatize GAMS. Let me explain myself:

I want to run a model on a set of (many) instances. Each instance is defined in a txt file, which contains input data. Such file is added to my model by means of an $include instruction. Besides, I want to keep certain parameters and variables (objective function values, running times, etc.) in an excel file.

Is there a way to automatize all this, without having to change the input-data files and the output files one by one right after the instances are executed?

Thank you so much in advance!

Fede


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 http://groups.google.com/group/gamsworld?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

\