Skip to content
NLopt bindings for julia
Pull request Compare This branch is even with MetalNinjas:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
src/nlopt
LICENSE.md
README.md

README.md

julia-nlopt

NLopt bindings for julia. See here for the documentation of nlopt.

Usage

Example using a L-BFGS optimizer. The objective function returns a tuple where the first value contains the function evaluation and the second the gradient evaluation.

x = [-1.2,1,-1.2,1]

function obj(x)
  fx = 0
  g = Array(Float64,length(x))
  for i = 1:2:length(x)
    f1 = 1-x[i]
    f2 = 10* (x[i+1] - x[i]^2)
    g[i+1] = 20.0 * f2
    g[i] = -2.0 * (x[i] * g[i+1] + f1)
    fx += f1^2 + f2^2
  end
  return (fx,g)
end

nlopt_optimize(NLopt(:ld_lbfgs,
                     :ftol_abs, 1e-8,
                     :maxeval, 2000,
                     :min_objective, obj), x)
Something went wrong with that request. Please try again.