I ran into a problem where I need to implement constrained optimization in Rcpp. Can anyone provide some hints on how to do this?
1) I searched for current Rcpp packages but did not find one that can do optimization with (linear) constraints.
2) I was thinking of calling R function optim() in Rcpp but was informed that it's not a good idea to call an R function in Rcpp iteratively.
3) I tried to work with the dlib library (provided by R package dlib), but I got errors when defining the example function given in http://dlib.net/optimization_ex.cpp.html.
My Rcpp codes:
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::plugins(cpp11)]]
// [[Rcpp::depends(dlib)]]
#include <dlib/optimization.h>
using namespace dlib;
using namespace std;
typedef matrix<double,0,1> column_vector;
// [[Rcpp::export]]
double rosen (const column_vector& m)
{
const double x = m(0);
const double y = m(1);
double res = 100.0*pow(y - x*x,2) + pow(1 - x,2);
return(res);
}
The error message:
no matching constructor for initialization of
'dlib::matrix<double,0,1,dlib::memory_manager_stateless_kernel_1,
dlib::row_major_layout>'
I'm a beginner with Rcpp and hope someone can point me to the right direction. Thanks!