NLopt Reference
From AbInitio
(diff) ←Older revision | Current revision | Newer revision→ (diff)
NLopt |
Download |
Release notes |
FAQ |
NLopt manual |
Introduction |
Installation |
Tutorial |
Reference |
Algorithms |
License and Copyright |
NLopt is a library, not a stand-alone program—it is designed to be called from your own program in C, C++, Fortran, Matlab, GNU Octave, or other languages. This reference section describes the programming interface (API) of NLopt in the C language. The reference manuals for other languages can be found at:
- [[NLopt C++ Reference]]
- NLopt Fortran Reference
- NLopt Matlab Reference
- NLopt Python Reference
- NLopt Guile Reference
The old API from versions of NLopt prior to 2.0 is deprecated, but continues to be supported for backwards compatibility. You can find it described in the NLopt Deprecated API Reference.
Other sources of information include the Unix man page: On Unix, you can run e.g. man nlopt
for documentation of C API. In Matlab and GNU Octave, the corresponding command is to type help nlopt_optimize
.
Contents |
Compiling and linking your program to NLopt
An NLopt program in C should include the NLopt header file:
#include <nlopt.h>
For programs in compiled languages like C or Fortran, when you compile your program you will have to link it to the NLopt library. This is in addition to including the header file (#include <nlopt.h>
in C or #include <nlopt.hpp>
in C++). On Unix, you would normally link with a command something like:
compiler ...source/object files... -lnlopt -lm -o myprogram
where compiler is cc
, f77
, g++
, or whatever is appropriate for your machine/language.
Note: the -lnlopt -lm
options, which link to the NLopt library (and the math library, which it requires), must come after your source/object files. In general, the rule is that if A depends upon B, then A must come before B in the link command.
Note: the above example assumes that you have installed the NLopt library in a place where the compiler knows to find it (e.g. in a standard directory like /usr/lib
or /usr/local/lib
). If you installed somewhere else (e.g. in your home directory if you are not a system administrator), then you will need to use a -L
flag to tell the compiler where to find the library. See the installation manual.
The nlopt_opt object
TO DO.
Objective function
TO DO.
Nonlinear constraints
TO DO.
Stopping criteria
TO DO.
Return values
TO DO.
Local/subsidiary optimization algorithm
TO DO.
Initial step size
TO DO.
Stochastic population
TO DO.
Pseudorandom numbers
For stochastic optimization algorithms, we use pseudorandom numbers generated by the Mersenne Twister algorithm, based on code from Makoto Matsumoto. By default, the seed for the random numbers is generated from the system time, so that you will get a different sequence of pseudorandom numbers each time you run your program. If you want to use a "deterministic" sequence of pseudorandom numbers, i.e. the same sequence from run to run, you can set the seed by calling:
void nlopt_srand(unsigned long seed);
Some of the algorithms also support using low-discrepancy sequences (LDS), sometimes known as quasi-random numbers. NLopt uses the Sobol LDS, which is implemented for up to 1111 dimensions.
To reset the seed based on the system time, you can call:
void nlopt_srand_time(void);
(Normally, you don't need to call this as it is called automatically. However, it might be useful if you want to "re-randomize" the pseudorandom numbers after calling nlopt_srand
to set a deterministic seed.)
Version number
To determine the version number of NLopt at runtime, you can call:
void nlopt_version(int *major, int *minor, int *bugfix);
For example, NLopt version 3.1.4 would return *major=3
, *minor=1
, and *bugfix=4
.