I've been tasked with implementing an optimization routine to run on Android (so I can use Java libraries, or C++ ones). It currently exists in both R and Excel (using Solver's GRG Nonlinear option). Since I don't know R, and Solver is a black box, I'm struggling.
I'm trying to achieve this using Apache Math Commons, since it contains an implementation of Nelder-Mead, which is what the R code is using.
Any help at all is hugely appreciated.
Edit: Changed to a single-param example which should run to completion in R.
fun = function(X) { Y = 5151 - 1735 * (0.945 ^ X[1]) - 3416 Py = 100 R = Y * Py Px = 200 C = X[1] * Px P = Y * Py-X[1] * Px write(sprintf("[%s] -> %.5f", X[1], P), stdout()) plot(P) return(P) } A = matrix(c(-200, 0), ncol=1, byrow=TRUE) B = c(-5000) xinit = c(0) xan = constrOptim(theta=xinit, f=fun, grad=NULL, ui=A, ci=B,control=list(fnscale=-1),method = "Nelder-Mead") xan$par xan$value
0 comments:
Post a Comment