BYU-PRISM / GEKKO

GEKKO Python for Machine Learning and Dynamic Optimization
https://machinelearning.byu.edu
Other
595 stars 104 forks source link

List and/or iterate over variables in model #4

Closed abe-mart closed 6 years ago

abe-mart commented 6 years ago

When using the syntax m.x = m.Var(), it would be nice to be able to list the variables that are currently stored in the model, something like print(m.Vars()) perhaps. It would also be nice to be able to iterate over the variables:

for var in m: 
    var.value = 0
abe-mart commented 6 years ago

Turns out this is already implemented, but not documented that I can find: list(m.variables) or

for v in m.variables:
    print(v)
abe-mart commented 6 years ago

This is now in the documentation. Thanks!