After the execution of the code using GamsPY. Is there a way to evaluate the code as if written in GAMS. Is it possible to convert a code from python to Gams and vice versa?
Yes, it is. If you want to see code that is executed with GAMS, you can set debugging_level of the container as “keep” and run container.generateGamsString()
at any point in time. Example:
from gamspy import Container, Set
m = Container(debugging_level="keep")
I = Set(m, "i")
print(m.generateGamsString())
See Inspecting Generated GAMS String section of the documentation for more details.
The output of this function can be a bit verbose because of the extra compiler directives added by GAMSPy such as $onMultiR. Alternatively, you can convert your GAMSPy to the equivalent GAMS model with toGams()
function:
from gamspy import Container, Set, Model
m = Container(debugging_level="keep")
...
...
Definition of your model here
...
...
model = Model(<arguments for your model>)
model.toGams("<path_to_the_directory>")
The vice versa (GAMS → GAMSPy) is not possible at the moment.
2 Likes