nloptr provides an R interface to NLopt, a free/open-source library for nonlinear optimization providing a common interface to a number of different optimization routines which can handle nonlinear constraints and lower and upper bounds for the controls.
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
nloptr is an R interface to NLopt, a free/open-source library for nonlinear optimization started by Steven G. Johnson, providing a common interface for a number of different free optimization routines available online as well as original implementations of various other algorithms. It can be used to solve general nonlinear programming problems with nonlinear constraints and lower and upper bounds for the controls, such as
$$ \min_{x \in \mathbb{R}^n} \quad f(x), $$
s.t. $g(x) \le 0$, $h(x) = 0$ and $\ell \le x \le u$.
The NLopt library is available under the GNU Lesser General Public License (LGPL), and the copyrights are owned by a variety of authors. See the website for information on how to cite NLopt and the algorithms you use.
On Windows, either the latest version 2.7.1
of NLopt from rwinlib (windows-release) or the v2.7.1
build from the rtools42
toolchain (windows2022-devel) is used. So there is nothing else to be done.
On Unix-like platforms, we use pkg-config
to find a suitable system build of NLopt (i.e. with version >= 2.7.0
).
CMAKE_BIN
is searched on the PATH
and, alternatively, on a macOS-specific location. If that variable cannot be set, install will abort suggesting ways of installing CMake. The minimal version requirement on cmake
is >= 3.15.0
.Minimal version requirement for cmake
is 3.2.0
.
You can install CMake by following CMake installation instructions. The important thing is that you add the CMake binary to your PATH
:
PATH
. Note that the location of the CMake binary is always /Applications/CMake.app/Contents/bin/cmake
. Hence, nloptr knows where to find it even if you do not update your PATH
.Alternatively, you can set an environment variable CMAKE_BIN
pointing to a CMake binary of your liking on your computer for nloptr to use.
You can install nloptr from CRAN using:
install.packages("nloptr")
Alternatively, you can install the development version from GitHub:
# install.packages("remotes")
remotes::install_github("astamm/nloptr")
I would like to express my sincere gratitude to Dirk Eddelbuettel, Jeroen Ooms, Tomas Kalibera, Uwe Ligges and Jelmer Ypma for their contributions and the very instructive discussions about the pros and cons of various build strategies in R packages.
Steven G. Johnson, The NLopt nonlinear-optimization package, https://nlopt.readthedocs.io/en/latest/