Hi,
I am trying to get the level values of my variable using embeddedcode: Python to do some transformation on them in Python and finally output a CSV file. I am running into an issue while doing gams.get(‘x.l’). There must be some other way to get the level values. Does anyone have any idea how to do this?
Thanks in advance
Hi,
With gams.get() in embedded code Python, you will get all values of a symbol - e.g. level, marginal, etc. for a GAMS variable and need to process them manually afterwards. Here is some code snippet that reads and prints a variable x:
embeddedCode Python:
var_x = list(gams.get('x'))
print(var_x)
endEmbeddedCode
For more information see the documentation for embedded Python code: https://www.gams.com/latest/docs/UG_EmbeddedCode.html?search=embedded%20code#UG_EmbeddedCode_Python
Depending on the transformations that you want to do, GAMS Connect might also be helpful for you:
embeddedCode Connect:
- GAMSReader: # read variable x from GAMS into the Connect database
symbols:
- name: x
- Projection: # turn variable x into parameter x_new with level values only
name: x.l(i,j)
newName: x_new(i,j)
asParameter: True
- CSVWriter: # write x_new to CSV
file: x_level.csv
name: x_new
endembeddedCode
For more information on GAMS Connect, see the documentation: https://www.gams.com/latest/docs/UG_GAMSCONNECT.html
Best,
Clemens