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.
\