This is the nlopt Reference Manual, version 0.0.1, generated automatically by Declt version 4.0 beta 2 "William Riker" on Sun Dec 15 07:09:41 2024 GMT+0.
The main system appears first, followed by any subsystem dependency.
nlopt
Common Lisp interface to Non-linear optimization library NLopt
Bibek Panthi <bpanthi977@gmail.com>
MIT
0.0.1
cffi
(system).
trivial-garbage
(system).
package.lisp
(file).
cffi.lisp
(file).
utils.lisp
(file).
nlopt.lisp
(file).
nloptimize.lisp
(file).
Files are sorted by type and then listed depth-first from the systems components trees.
nlopt/nlopt.asd
nlopt/package.lisp
nlopt/cffi.lisp
nlopt/utils.lisp
nlopt/nlopt.lisp
nlopt/nloptimize.lisp
nlopt/cffi.lisp
package.lisp
(file).
nlopt
(system).
add_equality_constraint
(function).
add_equality_mconstraint
(function).
add_inequality_constraint
(function).
add_inequality_mconstraint
(function).
add_precond_equality_constraint
(function).
add_precond_inequality_constraint
(function).
algorithm_name
(function).
copy
(function).
create
(function).
destroy
(function).
force_stop
(function).
get_algorithm
(function).
get_dimension
(function).
get_force_stop
(function).
get_ftol_abs
(function).
get_ftol_rel
(function).
get_initial_step
(function).
get_local_search_algorithm
(function).
get_lower_bounds
(function).
get_maxeval
(function).
get_maxtime
(function).
get_numevals
(function).
get_population
(function).
get_stopval
(function).
get_upper_bounds
(function).
get_vector_storage
(function).
get_x_weights
(function).
get_xtol_abs
(function).
get_xtol_rel
(function).
minimize
(function).
minimize_constrained
(function).
minimize_econstrained
(function).
munge_data
(function).
nlopt_get_stochastic_population
(function).
nlopt_set_stochastic_population
(function).
optimize_nlp
(function).
remove_equality_constraints
(function).
remove_inequality_constraints
(function).
result_from_string
(function).
result_to_string
(function).
set_default_initial_step
(function).
set_force_stop
(function).
set_ftol_abs
(function).
set_ftol_rel
(function).
set_initial_step
(function).
set_initial_step1
(function).
set_local_optimizer
(function).
set_local_search_algorithm
(function).
set_lower_bound
(function).
set_lower_bounds
(function).
set_lower_bounds1
(function).
set_max_objective
(function).
set_maxeval
(function).
set_maxtime
(function).
set_min_objective
(function).
set_munge
(function).
set_population
(function).
set_precond_max_objective
(function).
set_precond_min_objective
(function).
set_stopval
(function).
set_upper_bound
(function).
set_upper_bounds
(function).
set_upper_bounds1
(function).
set_vector_storage
(function).
set_x_weights
(function).
set_x_weights1
(function).
set_xtol_abs
(function).
set_xtol_abs1
(function).
set_xtol_rel
(function).
srand
(function).
srand_time
(function).
version
(function).
nlopt/utils.lisp
cffi.lisp
(file).
nlopt
(system).
%dreffing@
(function).
doubles
(function).
doubles
(type).
doubles*
(function).
doubles-array
(function).
doubles-array*
(function).
dref
(function).
(setf dref)
(function).
dreffing@
(macro).
ensure-success
(macro).
foreign-darray-to-lisp
(function).
setf-doubles
(function).
setf-doubles2
(function).
with-vector-ptr-to
(macro).
nlopt/nlopt.lisp
utils.lisp
(file).
nlopt
(system).
add-equality-constraint
(function).
add-inequality-constraint
(function).
algorithm
(function).
algorithm-name
(function).
algorithms
(function).
copy
(function).
create
(function).
force-stop
(function).
force-stop-value
(function).
(setf force-stop-value)
(function).
(setf ftol-abs)
(function).
ftol-rel
(function).
(setf ftol-rel)
(function).
initial-step
(function).
(setf initial-step)
(function).
lower-bound
(function).
(setf lower-bound)
(function).
lower-bounds
(function).
(setf lower-bounds)
(function).
maxeval
(function).
(setf maxeval)
(function).
maxtime
(function).
(setf maxtime)
(function).
numevals
(function).
optimize-nlopt
(function).
result-description
(function).
set-local-optimizer
(function).
set-max-objective
(function).
set-min-objective
(function).
set-population
(function).
set-precond-max-objective
(function).
set-precond-min-objective
(function).
srand
(function).
srand-time
(function).
stopval
(function).
(setf stopval)
(function).
upper-bound
(function).
(setf upper-bound)
(function).
upper-bounds
(function).
(setf upper-bounds)
(function).
vector-storage
(function).
(setf vector-storage)
(function).
version
(function).
x-weights
(function).
(setf x-weights)
(function).
xtol-abs
(function).
(setf xtol-abs)
(function).
xtol-rel
(function).
(setf xtol-rel)
(function).
*nlopt-instance*
(special variable).
add-equality-mconstraint
(function).
add-inequality-mconstraint
(method).
add-new-callback
(function).
callback-identifier-tclass
(class).
callbacks
(reader method).
(setf callbacks)
(writer method).
copy-object
(method).
default-initial-x
(function).
dimension
(reader method).
identifiers
(reader method).
(setf identifiers)
(writer method).
nlopt
(class).
objective
(reader method).
preconditioner
(reader method).
ptr
(reader method).
(setf ptr)
(writer method).
remove-equality-constraints
(function).
remove-inequality-constraints
(function).
nlopt/nloptimize.lisp
nlopt.lisp
(file).
nlopt
(system).
nloptimize
(macro).
%with-nlopt-constraints
(function).
%with-nlopt-inequality-constraint
(function).
%with-nlopt-lambda
(function).
%with-nlopt-optimize
(function).
%with-nlopt-satisfy
(function).
%with-nlopt-walker
(function).
filter-visible-vars
(function).
no-visible-vars?
(function).
Packages are listed by definition order.
nlopt.cffi
common-lisp
.
add_equality_constraint
(function).
add_equality_mconstraint
(function).
add_inequality_constraint
(function).
add_inequality_mconstraint
(function).
add_precond_equality_constraint
(function).
add_precond_inequality_constraint
(function).
algorithm_name
(function).
copy
(function).
create
(function).
destroy
(function).
force_stop
(function).
get_algorithm
(function).
get_dimension
(function).
get_force_stop
(function).
get_ftol_abs
(function).
get_ftol_rel
(function).
get_initial_step
(function).
get_local_search_algorithm
(function).
get_lower_bounds
(function).
get_maxeval
(function).
get_maxtime
(function).
get_numevals
(function).
get_population
(function).
get_stopval
(function).
get_upper_bounds
(function).
get_vector_storage
(function).
get_x_weights
(function).
get_xtol_abs
(function).
get_xtol_rel
(function).
minimize
(function).
minimize_constrained
(function).
minimize_econstrained
(function).
munge_data
(function).
nlopt_get_stochastic_population
(function).
nlopt_set_stochastic_population
(function).
optimize_nlp
(function).
remove_equality_constraints
(function).
remove_inequality_constraints
(function).
result_from_string
(function).
result_to_string
(function).
set_default_initial_step
(function).
set_force_stop
(function).
set_ftol_abs
(function).
set_ftol_rel
(function).
set_initial_step
(function).
set_initial_step1
(function).
set_local_optimizer
(function).
set_local_search_algorithm
(function).
set_lower_bound
(function).
set_lower_bounds
(function).
set_lower_bounds1
(function).
set_max_objective
(function).
set_maxeval
(function).
set_maxtime
(function).
set_min_objective
(function).
set_munge
(function).
set_population
(function).
set_precond_max_objective
(function).
set_precond_min_objective
(function).
set_stopval
(function).
set_upper_bound
(function).
set_upper_bounds
(function).
set_upper_bounds1
(function).
set_vector_storage
(function).
set_x_weights
(function).
set_x_weights1
(function).
set_xtol_abs
(function).
set_xtol_abs1
(function).
set_xtol_rel
(function).
srand
(function).
srand_time
(function).
version
(function).
nlopt
common-lisp
.
add-equality-constraint
(function).
add-inequality-constraint
(function).
algorithm
(function).
algorithm-name
(function).
algorithms
(function).
copy
(function).
create
(function).
force-stop
(function).
force-stop-value
(function).
(setf force-stop-value)
(function).
(setf ftol-abs)
(function).
ftol-rel
(function).
(setf ftol-rel)
(function).
initial-step
(function).
(setf initial-step)
(function).
lower-bound
(function).
(setf lower-bound)
(function).
lower-bounds
(function).
(setf lower-bounds)
(function).
maxeval
(function).
(setf maxeval)
(function).
maxtime
(function).
(setf maxtime)
(function).
nloptimize
(macro).
numevals
(function).
optimize-nlopt
(function).
result-description
(function).
set-local-optimizer
(function).
set-max-objective
(function).
set-min-objective
(function).
set-population
(function).
set-precond-max-objective
(function).
set-precond-min-objective
(function).
srand
(function).
srand-time
(function).
stopval
(function).
(setf stopval)
(function).
upper-bound
(function).
(setf upper-bound)
(function).
upper-bounds
(function).
(setf upper-bounds)
(function).
vector-storage
(function).
(setf vector-storage)
(function).
version
(function).
x-weights
(function).
(setf x-weights)
(function).
xtol-abs
(function).
(setf xtol-abs)
(function).
xtol-rel
(function).
(setf xtol-rel)
(function).
%dreffing@
(function).
%with-nlopt-constraints
(function).
%with-nlopt-inequality-constraint
(function).
%with-nlopt-lambda
(function).
%with-nlopt-optimize
(function).
%with-nlopt-satisfy
(function).
%with-nlopt-walker
(function).
*nlopt-instance*
(special variable).
add-equality-mconstraint
(function).
add-inequality-mconstraint
(generic function).
add-new-callback
(function).
callback-identifier-tclass
(class).
callbacks
(generic reader).
(setf callbacks)
(generic writer).
copy-object
(generic function).
default-initial-x
(function).
dimension
(generic reader).
doubles
(function).
doubles
(type).
doubles*
(function).
doubles-array
(function).
doubles-array*
(function).
dref
(function).
(setf dref)
(function).
dreffing@
(macro).
ensure-success
(macro).
filter-visible-vars
(function).
foreign-darray-to-lisp
(function).
identifiers
(generic reader).
(setf identifiers)
(generic writer).
nlopt
(class).
no-visible-vars?
(function).
objective
(generic reader).
preconditioner
(generic reader).
ptr
(generic reader).
(setf ptr)
(generic writer).
remove-equality-constraints
(function).
remove-inequality-constraints
(function).
setf-doubles
(function).
setf-doubles2
(function).
with-vector-ptr-to
(macro).
Definitions are sorted by export status, category, package, and then by lexicographic order.
Quick and easy way to solve an optimization problem
‘vars’ is list of symbols for variables/parameter names
‘algorithm’ is the algorithm used for solving. It must be a non-gradient algorithm :nlopt_ln_* or :nlopt_gn_*
‘initial’ is the initial values used for parameters
‘body’ can contain normal lisp code however the ‘body’ is parsed for following covenience forms
(:minimize expr) (:maximize expr) ;; sets the objective function
(:satisfy expr1 expr2 ...) ;; adds constraints
each constraint can be of the form
(+|- ...) ;; an equality constraint expr = 0
(<|<=|>|>= ...) ;; an inequality constraint or bounds on the parameter
inside the body ‘*nlopt-instance*’ can be used to refer to current nlopt instance
Add an equality constaint c(x) = 0
c(pointer to doubles x, pointer to gradient or NULL, nlopt)
tolerance ‘tol’ is used to check -tol <= c(x) <= tol
Add an inequality constaint c(x) <= 0
c(pointer to doubles x, pointer to gradient or NULL, nlopt)
tolerance ‘tol’ is used to check c(x) <= tol
Get algorithm used; Returns a keyword
Human readable name of ‘algorithm’
List of algorithms available
Make a copy of ‘nlopt’ problem
If you have subclassed the ‘nlopt’ object define a ‘copy-object’ method on your subclass
that copies all slots (including those of ‘nlopt’)
Create an Non-linear optimization object object
‘algorithm’ is one of the ‘(algorithms)’
‘dimension’ is number of parameters in the optimization problem
In certain cases, the caller may wish to force the optimization to halt, for some reason unknown to NLopt. For example, if the user presses Ctrl-C, or there is an error of some sort in the objective function. In this case, it is possible to tell NLopt to halt the optimization gracefully, returning the best point found so far, by calling the this function from within your objective or constraint functions
Returns ‘value’ set using ‘(setf (force-stop-value nlopt) value)’
Set a reason (integer value) for force stopping that can be later retrieved using ‘force-stop-value’
Set relative tolerance on function value: stop when an optimization step (or an estimate of the optimum) changes the objective function value by less than ‘tol’ multiplied by the absolute value of the function value.
Criterion is disabled if ‘tol’ is non-positive
Get relative tolerance in changes in objective function value
Set relative tolerance on function value: stop when an optimization step
(or an estimate of the optimum) changes the objective function value by
less than ‘tol’ multiplied by the absolute value of the function value.
(If there is any chance that your optimum function value is close to zero,
you might want to set an absolute tolerance with (setf (ftol-abs nlopt)) as well.)
Criterion is disabled if ‘tol’ is non-positive.
Get the initial step size
Here, x is the same as the initial guess that you plan to pass to ‘optimize-nlopt’
if you have not set the initial step and NLopt is using its heuristics, its
heuristic step size may depend on the initial x, which is why you must pass it
here.
‘dx’ is a number, list or array of doubles of length n (the dimension of the
problem) containing the (nonzero) initial step size for each component of the
optimization parameters x. If you pass nil for dx, then NLopt will use its
heuristics to determine the initial step size.
For derivative-free local-optimization algorithms, the optimizer must somehow decide on some initial step size to perturb x by when it begins the optimization. This step size should be big enough that the value of the objective changes significantly, but not too big if you want to find the local optimum nearest to x. By default, NLopt chooses this initial step size heuristically from the bounds, tolerances, and other information, but this may not always be the best choice.
Get lower bounds for parameters
Set lower bounds for parameters
bounds can be a number, list or array of doubles
Get maximum number of function evaluations
Stop when the number of function evaluations exceeds ‘maxeval’
This is not a strict maximum: the number of function evaluations may exceed ‘maxeval’ slightly,
depending upon the algorithm.
‘maxeval’ is an integer
Criterion is disabled if ‘maxeval’ is non-positive
Get maximum optimization time allowed (in seconds)
Stop when the optimization time (in seconds) exceeds maxtime.
This is not a strict maximum: the time may exceed maxtime slightly,
depending upon the algorithm and on how slow your function evaluation is.
‘time’ is a double-float
Criterion is disabled if maxtime is non-positive.
Number of function evaluations used to solve the opt problem
Optimize the NonLinear Optimization problem ‘nlopt’ with initial parameters x ‘x’ may be nil, a number, an list or a array of doubles
Gives description for halting (forcefully or sucessfully) of the optimization problem (result-description (nth-value 2 (optimize-nlopt nlopt)))
Some of the algorithms, especially MLSL and AUGLAG, use a different optimization
algorithm as a subroutine, typically for local optimization. You can change the
local search algorithm and its tolerances by calling:
(setf (local-optimizer nlopt) local-nlo
Here, ‘local-nlopt’ is another nlopt object whose parameters are used to
determine the local search algorithm, its stopping criteria, and other algorithm
parameters. (However, the objective function, bounds, and nonlinear-constraint
parameters of local_opt are ignored.) The dimension ‘n’ of ‘local-nlopt’ must match
that of ‘nlopt’.
This function makes a copy of the ‘local-nlopt’ object, so local-optimizer must be assigned to ‘nlopt’ after all criterias are set.
Set maximazation objective function where
function(pointer to doubles x,
pointer to doubles grad or NULL,
nlopt)
returns a double-float
Set minimization objective function where
function(pointer to doubles x,
pointer to doubles grad or NULL,
nlopt)
returns a double-float
Several of the stochastic search algorithms (e.g., CRS, MLSL, and ISRES) start by generating some initial ‘population’ of random points x. By default, this initial population size is chosen heuristically in some algorithm-specific way, but the initial population can by changed by this function. A ‘size’ of zero implies that the heuristic default will be used.
See documentation for ‘(set-precond-min-objective)’
If you know the Hessian (second-derivative) matrix of your objective function,
i.e. the matrix H with Hij=∂2f/∂x_i∂x_j
for an objective f, then in principle this could be used to accelerate local
optimization. In fact, even a reasonable approximation for H could be useful if
it captures information about the largest eigenvalues of H and the corresponding
eigenvectors. Such an approximate Hessian is often called a preconditioner in
the context of iterative solvers, so we adopt that terminology here.
Currently, support for preconditioners in NLopt is somewhat experimental, and is
only used in the NLOPT_LD_CCSAQ algorithm.
The preconditioner is a function
pre(pointer to doubles x,
pointer to doubles v,
nlopt)
This function should take a vector v and should compute vpre = H(x) v where H is an approximate second derivative at x. The CCSAQ algorithm requires that your matrix H be positive semidefinite, i.e. that it be real-symmetric with nonnegative eigenvalues.
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
Reset the seed based on the system time
(It is called automatically, but call this if you have set a deterministic seed using
‘srand’ and want to re-randomize the seed)
Get the current stopping value for objective function
Stop when an objective value of at least stopval is found: stop minimizing when an objective value <= stopval is found, or stop maximizing a value >= stopval is found.
Get upper bounds for parameters
Set upper bounds for parameters
bounds can be a number, list or array of doubles
Get the size/number of previous optimization gradients storage used in limited-memory ‘quasi-Newton’ alogrithms
Some of the NLopt algorithms are limited-memory ‘quasi-Newton’ algorithms, which ‘remember’ the gradients from a finite number M of the previous optimization steps in order to construct an approximate 2nd derivative matrix. The bigger M is, the more storage the algorithms require, but on the other hand they may converge faster for larger M. By default, NLopt chooses a heuristic value of M.
Passing M=0 (the default) tells NLopt to use a heuristic value. By default, NLopt currently sets M to 10 or at most 10 MiB worth of vectors, whichever is larger.
Get underlying NLopt c library versions (major, minor, bugfix)
Get the weights ‘w_i’ set for relative tolerance in updates of parameters ‘x’
Set weights ‘w_i’ for relalative tolerance in updates of parameters ‘x’ weights can be a single number, list, or array of doubles
Get the stopping tolerances set for updates in parameters ‘x’
Set absolute tolerances on optimization parameters. Stop when an optimization step
(or an estimate of the optimum) changes every parameter x[i] by less than tol[i].
Note that since nlopt creates a copy of tolerances array subsequent changes to
the caller’s tolerances have no effect on opt.
‘tolerances’ can be a number, an list or array of doubles of size n = (dimension nlopt)
Criterion is disabled if ‘tolerances’ is non-positive.
Get relative tolerance in parameters ‘x’
Set relative tolerance on optimization parameters: stop when an optimization step
(or an estimate of the optimum) causes a relative change the parameters ‘x’ by less than ‘tol’,
i.e. ∥Δx∥_w <tol * ∥x∥_w as measured by a weighted L₁ norm ∥x∥w=∑_i w_i * |x_i|,
where the weights w_i default to 1. (If there is any chance that the optimal ∥x∥ is close to zero,
you might want to set an absolute tolerance with ‘set-xtol-abs’ as well.)
Criterion is disabled if ‘tol’ is non-positive.
This variable is bound to the nlopt instance being called
replace occurance of @n with (dref x n) in body Usefull for avoiding
constaints of type (< (- (* 2 x) 5) (* 2 y) z 10) input ‘exp’ should not contain inequality sign
Return code for optimizing (first functions)
Walk the body and replace :minimize, :maximize and :satisfy with proper code
Add multiple equality constraints c_i(x) = 0; i=1,2,..m
‘function’ = ‘c’ should return list of ‘m’ doubles
c(pointer to doubles x,
pointer to gradient(jacobian) ‘∂c_i(x)/∂x_j’ or NULL, (m rows, n columns)
nlopt)
‘tol’ is tolerances as in single constaints, it can be a number, nil, list of tolerance or array of double-floats
In some applications with multiple constraints, it is more convenient to define a single function
that returns the values (and gradients) of all constraints at once. For example, different constraint
functions might share computations in some way. Or, if you have a large number of constraints, you may
wish to compute them in parallel.
Adds a callback to nlopt object and returns an struct to identify that callback
Create an array of double floats from given ‘list’ of double floats
Create an array of double floats from given ‘list’ (coerces numbers to double-float)
Create oan array of double floats of ‘size’ with ‘initial-element’
Create oan array of double floats of ‘size’ with ‘initial-element’ (coerces ‘initial-element’ to double-float)
Return element of foreign double float array (‘ptr’) at ‘index’ position
Set element of foreign double float array ‘ptr’ at ‘index’ to value ‘val’
Returns list of ‘vars’ that are seen in ‘body’ results found are stored in ‘sofar’
Remove all equality constraints
Remove all inequality constraints
Set elements of a foreign array of doubles
Set elements of a foreign array of doubles
Add multiple inequality constraints c_i(x) = 0; i=1,2,..m
‘function’ = ‘c’ should return list of ‘m’ doubles
c(m,
pointer to doubles x,
pointer to gradient(jacobian) ‘∂c_i(x)/∂x_j’, (m rows, n columns)
nlopt)
‘tol’ is tolerances as in single constaints, it can be a number, nil, list of tolerance or array of double-floats
In some applications with multiple constraints, it is more convenient to define a single function
that returns the values (and gradients) of all constraints at once. For example, different constraint
functions might share computations in some way. Or, if you have a large number of constraints, you may
wish to compute them in parallel.
foreign-struct-type
.
translatable-foreign-type
.
Number of variables
integer
0
:dimension
This slot is read-only.
Callbacks for different constraints
Preconditioner used with ‘CCSAQ’ algorithm
This slot is read-only.
Actually the nlopt c library is passed a single callback which
selects which lisp callback to use. The identifer foreign struct is used to select/identify callbacks
Jump to: | %
(
A C D E F G I L M N O P R S U V W X |
---|
Jump to: | %
(
A C D E F G I L M N O P R S U V W X |
---|
Jump to: | *
C D I O P S |
---|
Jump to: | *
C D I O P S |
---|
Jump to: | C D F N P S T U |
---|
Jump to: | C D F N P S T U |
---|