BYU-PRISM / GEKKO

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

Error when trying to use it in R via reticulate package #100

Closed GitHunter0 closed 2 years ago

GitHunter0 commented 3 years ago

Python modules are accessible in R via reticulate package. Unfortunately, it is not working for GEKKO, the formulas are not being recognized as such.

I am receiving these kind of error messages when trying to pass equations like in m$Equation(x1 + x2 == 7): Error in x1 + x2 : non-numeric argument to binary operator.

library(reticulate)
gekko <- reticulate::import("gekko")
m <- gekko$GEKKO(remote=TRUE) 
x1 = m$Var(value=1, lb=1, ub=5)
x2 = m$Var(value=5, lb=1, ub=5)
x3 = m$Var(value=5, lb=1, ub=5)
x4 = m$Var(value=1, lb=1, ub=5)
m$Equation(x1 + x2 == 7)
m$Equation(x1 * x2 * x3 * x4 >= 25)
m$Obj(x1 * x4 * (x1 + x2 + x3) + x3)  
m$solve(disp=TRUE)  

I would really like to use GEKKO in R, is there some tweak we can do to make that possible?

Thank you

APMonitor commented 3 years ago

This is an interesting question but I'm not very familiar with R. I posted the question on StackOverflow to see if there is any help from the R community. https://stackoverflow.com/questions/65291603/error-when-trying-to-use-python-gekko-in-r-via-reticulate-package

GitHunter0 commented 3 years ago

Hey @APMonitor, I appreciate the initiative, GEKKO is a great package and hopefully R users will be able to take advantage of it too.

APMonitor commented 2 years ago

Discussion and potential solutions for running gekko in R are posted on StackOverflow: