NLopt-js
NLopt-js is a port of the nlopt C++ optimization library
It uses a WebAssembly compiled subset of the nlopt library, and implements a garbage collection mechanism to manage memory
Usage
NLopt-js can be installed via npm or yarn
npm install nlopt-js
yarn add nlopt-js
In a node application or in the browser (using webpack)
const nlopt = // ES6: import nlopt from 'nlopt-js'async { await nloptready const opt = nloptAlgorithmLD_SLSQP 2; opt; const res = opt; // Flush the GC nloptGC;};
Documentation
The documentation is available at NLopt-js
Build
Make sure Emscripten is intalled & activated in your terminal session
source path/to/emsdk/emsdk_env.sh./emcc -v
Dowload the latest version of the nlopt library and extract it under
lib/nlopt
Now build a bytecode shared library
mkdir build; cd buildemcmake cmake ..emmake make
It should generate a shared library bytecode file named libnlopt.bc
Now to compile the wasm binary, run the following command
mkdir buildemcc -I lib/nlopt/build -I lib/nlopt/src/api -Isrc lib/nlopt/build/libnlopt.a -s DISABLE_EXCEPTION_CATCHING=0 -s ASSERTIONS=0 -O3 -s ALLOW_MEMORY_GROWTH=1 -s MODULARIZE=1 --bind -o build/nlopt_gen.js src/cpp/embind.cc
Generate the documentation
The documentation is generated from classes descriptions using documentation.js
documentation build src/classes/ -f json -o docs/doc.json