Hello, GAMS experts
Recently, I am studying ‘embeddedCode Python:’ at GAMS model. is it possible to use ‘def’ to define new function at Embedded Python?
GAMS Code
embeddedCode Python:
def my_function(x, y):
return x+y
my_function
endEmbeddedCode
GAMS Code
Thank you so much in advance!
My question was clear by myself. the example code is like below.
Scalar parA, parB;
Scalar parResult;
parA = 10;
parB = 20;
option clear=parResult;
embeddedCode Python:
x = list(gams.get("parA"))[0]
y = list(gams.get("parB"))[0]
def plus(x, y):
return x+y
def minus(x, y):
return x-y
z = plus(x, y) + minus(x, y)
print("\n the results of Python function is \n", x, y, z)
gams.set('parResult', [z])
endEmbeddedCode parResult
Display parResult;
Have a good day.