NLP is a package for the solution of the unconstrained
minimization of a real-valued function f(x). It uses the Memoryless
Quasi-Newton Method (self scaling BFGS). A description of this method
can be found in the following book:
Linear and Nonlinear Programming
David G. Luenberger
Addison-Wesley, 1984, ISBN 0-201-15794-2
The NLP package can be downloaded here.
Example of package use:
-- f : real-valued function.
-- x : vector of variables.
-- g : gradient vector of f(x).
-- n : number of variables.
-- maxminor : an upper bound for the number of iterations (usually 10 * n).
-- minor : number of iterations.
-- maxnorm : an upper bound for the infinity norm of the gradient vector.
-- optimal : boolean variable (true if success).
-- maxlsi : an upper bound for the number of cubic fits of the line search.
-- It must be greater that one (usually 20).
-- lstol : Controls the accuracy of the line search. It must lie in the
-- range 0.0 <= lstol < 1.0. Decreasing lstol tends to increase the accuracy
-- of the line search (usually 0.1).
-- author: Vinicius Fernando Arcaro
-- e-mail: vfa@turing.unicamp.br, vfa@widesoft.com.br
-- date: October, 1996
with
text_io,
ada.long_float_text_io,
ada.numerics.long_elementary_functions,
unchecked_deallocation,
terminology,
nlp;
procedure test is
use
text_io,
ada.long_float_text_io;
optimal : boolean;
n,maxminor,maxlsi,minor : integer;
maxnorm,lstol,f,a : long_float;
x,g : terminology.fvector_ptr;
procedure free_fvector is new unchecked_deallocation(terminology.fvector,terminology.fvector_ptr);
procedure energy (n : in integer;
f : out long_float;
x : in terminology.fvector_ptr;
g : in terminology.fvector_ptr) is
use
ada.numerics.long_elementary_functions;
begin
f := (x(1) - a) ** 4 + (x(1) - a * x(2)) ** 2;
g(1) := 4.0 * (x(1) - a) ** 3 + 2.0 * (x(1) - a * x(2));
g(2) := -2.0 * a * (x(1) - a * x(2));
end energy;
procedure equilibrium is new nlp.minimize(energy);
begin
-- global variable to be used by procedure energy
a := 2.0;
-- parameters to be used by procedure equilibrium
n := 2;
maxminor := 10 * n;
maxlsi := 20;
maxnorm := 1.0E-04;
lstol := 1.0E-01;
-- dynamic memory allocation
x := new terminology.fvector (1 .. n);
g := new terminology.fvector (1 .. n);
-- starting point
x(1) := 0.0;
x(2) := 3.0;
equilibrium(n,maxminor,maxlsi,
minor,
maxnorm,lstol,
f,
x,g,
optimal);
put("x(1) = ");
put(x(1));
new_line;
put("x(2) = ");
put(x(2));
new_line;
-- dynamic memory deallocation
free_fvector(x);
free_fvector(g);
end test;
|