-
-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Access named variables and params #52
Comments
One way that I have done this before is pack the variables back into the
model object.
def getModel():
m = GEKKO()
m.x = m.Var(value=5, name='x')
return m
m = getModel()
print(m.x)
…On Wed, Jan 9, 2019 at 2:16 PM Eric Mansfield ***@***.***> wrote:
Say I have the following, where I want to reuse a model in multiple
places. Other than using the gekko model's built-in _variables attribute,
is there a "right" way to access the variable x?
def getModel():
m = GEKKO()
m.Var(value=5, name='x')
return m
m = getModel()# How to access variable x?
Putting x in the global scope is not what I intend.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#52>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/ASiToep6mj9BG_Xcjsge085G8vmYyW0Tks5vBlxEgaJpZM4Z4PAb>
.
|
Nice and clean. Thank you. Still, I suppose having a method that returns a dictionary of variables, parameters, etc. wouldn't hurt, would it? It's possible you could have a collision with a built-in attribute of the model. |
I like your idea to create a dictionary of variables such as:
There is checking in the GEKKO code to avoid collisions with built-in variable names. This isn't a problem, especially if you don't give your variables or parameters a non-default name. Feel free to open the issue again if you'd like more development work on this. |
Say I have the following, where I want to reuse a model in multiple places. Other than using the gekko model's built-in
_variables
attribute, is there a "right" way to access the variablex
?Putting
x
in the global scope is not what I intend.The text was updated successfully, but these errors were encountered: