TMinimizer v2.0


TMinimizer - nonvisual Delphi component for scientific calculation. It implements several methods of local minimization. The objective function can be specified in symbolical form.

Methods implemented:

Also TMinimizer implements constrained optimization algorithm using penalty function.


Description

Properties:

property Iteration : integer; - returns the number of current iteration during minimization.

property ConstValue[Index: string]: double; - returns/sets value of const defined by Index (constant name).

property Constraint[Index: integer]: string; - returns/sets value of Index-th constraint.

Published properties:

property DllPath : string; - path to MinimizeLib.dll.

property Symbolic : boolean; - specifies whether TMinimizer will use Formula property and symbolically evaluate derivatives.

property Constrained : boolean; - specifies whether TMinimizer should solve constrained minimization problem subject constraints specified by Constraint array (if Symbolic is true) or by OnEvaluateConstraint event handler.

property Restart : boolean; - specifies whether TMinimizer will restart minimization procedure to obtain more precise result.

property Formula : string; - symbolical expression of objective function.

property Vars : string; - coma divided list of names in Formula string treated as arguments of minimization algorithm.

property Consts : string; - coma divided list of names in Formula string treated as constants.

property n : integer; - specifies dimension of minimization problem.

property Method : TMinMethod; - specifies minimization algorithm.

TMinMethod = (mmRosen, mmDavidon, mmFletcher, mmBroyden, mmReeves, mmPshenichny, mmSDescent, mmNewton);

property MaxIteration : integer; - specifies maximum iteration allowed (0 - infinity)

property Eps1 : double; - specifies first stop condition (||xi-xi-1|| < Eps1).

property Eps2 : double; - specifies second stop condition (|f(xi)-f(xi-1)| < Eps2).

property R : double; - specifies initial value of penalty parameter.

property C : double; - specifies multiplier for penalty parameter.

Methods:

procedure Stop; - stop the minimization.

procedure PrepareSymbolic(fmethod : TMinMethod); - compiles function expression specified by Formula property into bytecode, also if needed computes and compiles gradient and Hessian depended on minimization algorithm specified.

function F(var x : array of double) : double; - computes value of function in x.

function G(var x : array of double; index:integer) : double; - computes value of index-th constraint in x.

procedure Grad(var x : array of double; var res : array of double); - computes gradient of function in x, returns result in res.

procedure Hesse(var x : array of double; res : ppdouble); - computes Hessian of function in x, returns result in res.

function Minimize(var x : array of double) : double; - minimize function with initial point x.

function ConstraintCount : integer; - returns constraint count.

procedure AddConstraint(Value: string); - adds new constraint. Constraint should be expressed as symbolic formula with the same variables as objective function. The value of constraint should be less then zero inside feasible region.

procedure DelConstraint(Index : integer); - deletes constraint with specified index.

Events:

property OnIteration : TCallBack; - occurs when algorithm starts new iteration.
TCallBack = procedure (f : double; var x : Array of double; n:integer) of Object;

property OnEvaluateF : TOnEvaluateF; - occurs when TMinimizer needs to evaluate function.
TOnEvaluateF = procedure (var x : array of double; var f:double) of Object;
Write this event handler if Symbolic set to false. Result should be returned in f parameter.

property OnEvaluateGrad : TOnEvaluateGrad; - occurs when TMinimizer needs to evaluate gradient.
TOnEvaluateGrad = procedure (var x: array of double; var res:array of double; n:integer) of Object;
Write this event handler if Symbolic set to false. Result should be returned in res parameter.

property OnEvaluateHesse : TOnEvaluateHesse; - occurs when TMinimizer needs to evaluate Hessian.
TOnEvaluateHesse = procedure (var x : array of double; var res : ppdouble; n : integer) of Object;
Write this event handler if Symbolic set to false. Result should be returned in res parameter.

property OnEvaluateConstraint : TOnEvaluateConstraint; - occurs when TMinimizer needs to evaluate value of constraint.
TOnEvaluateConstraint = procedure (var x : array of double; var f:double) of Object;


How to use

Specify path to MinimizeLib.dll in DllPath property. If function specified symbolically in Formula property, set Symbolic to true. Specify names of variables in Vars property, the rest names treated as constants and should by specified in Consts property. Set values of constants by ConstValue array property. If you want/should evaluate function numerically, write OnEvaluateF event handler. For all methods except Rosenbrock write also OnEvaluateGrad event handler. For Newton method write OnEvaluateHesse event handler. The result should be returned in res parameter of ppdouble type. To treat res as matrix add variable definition H : array of array of double absolute res;. If OnEvaluateGrad and/or OnEvaluateHesse event handlers not implemented TMinimizer will compute derivatives by numerical approximation.

Specify minimization algorithm, number of variables in Method and n properties respectively. Specify stop conditions in MaxIteration, Eps1, Eps2 properties.

For big dimensional minimization problems algorithms can stop far from real minimum. In this case set Restart to true. So TMinimizer will restart minimization procedure until result of minimization be the same as previous.

If you want control minimization process write OnIteration event handler. Event handler takes three parameters: f - current function value, x - current point, n - dimension. To obtain number of current iteration use Iteration property. To stop minimization call Stop procedure.
Finally call Minimize method.

If your need to solve constrained optimization problem use AddConstraint and DelConstraint methods and Constraint[Index] property to define constraints. If you want/should evaluate constraints numerically, write OnEvaluateConstraint event handler. Constraints should result in negative value inside feasible region. Specify values for R and C parameters. Then you should set Constrained property to true and call Minimize method.

Constrained minimization performed as iterative minimization procedure of penalty function. Penalty function has the form

Pk(x) = F(x) + rk * Σi[max(0,gi(x)]2,

where F(x) - objective function, gi - i-th constraint, rk - penalty parameter on k-th iteration.
The sequence of rk is strictly increased: r0 := R; rk+1 = C * rk, where R and C specified by corresponded properties of TMinimizer.
Result of constrained optimization will be found slightly outside feasible region. If objective function not specified outside feasible region implemented technique can't be used to solve optimization problem.

Important! Due to nondifferentiable penalty function TMinimizer always uses Rosenbrock algorithm during constrained minimization.


History
Author

Artem Parlyuk, e-mail:info@artsoft.name, http://artsoft.name

Minimizelib.dll based on source code obtained from Prof. Boris Y. Lemeshko (Dean of Department of Applied Mathematics and Informatics of Novosibirsk State Technical University, e-mail: heard@fpm.ami.nstu.ru).


License and disclaimer agreement

IMPORTANT - READ CAREFULLY

This license and disclaimer statement constitutes a legal agreement ("License Agreement") between you (either as an individual or a single entity) and Artem Parlyuk (the "Author"), for this software product in this particular case TMinimizer Delphi component ("Software"), including any software, media, and accompanying on-line or printed documentation.

BY DOWNLOADING, INSTALLING, COPYING, OR OTHERWISE USING THE SOFTWARE, YOU AGREE TO BE BOUND BY ALL OF THE TERMS AND CONDITIONS OF THIS LICENSE AND DISCLAIMER AGREEMENT. If you do not agree with the terms and conditions of this agreement, you must promptly cease all use of the software and destroy all copies of this software and all of its component parts in your possession or under your control.

This Software is owned by Author and is protected by copyright law and international copyright treaty.

This Software is freeware. You are granted the permission to use Software in your own applications for private purposes. You are granted the permission to use Software in your own applications for commercial purposes, provided your software contains the copyright notice "TMinimizer Delphi component Copyright (c) by Artem Parlyuk" and link to the Author site (http://artsoft.name) and Author e-mail (mailto:info@artsoft.name).

You can freely distribute copies of the main archive as long as no alterations are made to the contents and no charge is raised except a reasonable fee for distributing costs. You may not remove copyright notices from copies of the Software. You may not claim this Software as written by anyone but Author, Artem Parlyuk.

The author has taken all possible care to ensure the software is error-free, however the author disavows any potential liability arising from any use of the software. This software is provided "as is" and without any warranties expressed or implied, including, but not limited to, implied warranties of fitness for a particular purpose, and non-infringement. You expressly acknowledge and agree that use of the Software is at your sole risk.

In no event shall the author be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use this software or documentation, even if the author has been advised of the possibility of such damages.

Any feedback given to the Author will be treated as non-confidential. The Author may use any feedback free of charge without limitation.