1 -- Created on: 1991-05-14
2 -- Created by: Laurent PAINNOT
3 -- Copyright (c) 1991-1999 Matra Datavision
4 -- Copyright (c) 1999-2012 OPEN CASCADE SAS
6 -- The content of this file is subject to the Open CASCADE Technology Public
7 -- License Version 6.5 (the "License"). You may not use the content of this file
8 -- except in compliance with the License. Please obtain a copy of the License
9 -- at http://www.opencascade.org and read it completely before using this file.
11 -- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 -- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 -- The Original Code and all software distributed under the License is
15 -- distributed on an "AS IS" basis, without warranty of any kind, and the
16 -- Initial Developer hereby disclaims all such warranties, including without
17 -- limitation, any warranties of merchantability, fitness for a particular
18 -- purpose or non-infringement. Please see the License for the specific terms
19 -- and conditions governing the rights and limitations under the License.
26 -- This class implements the Broyden-Fletcher-Goldfarb-Shanno variant of
27 -- Davidson-Fletcher-Powell minimization algorithm of a function of
28 -- multiple variables.Knowledge of the function's gradient is required.
30 uses Vector from math, Matrix from math,
31 MultipleVarFunctionWithGradient from math,
35 raises NotDone from StdFail,
36 DimensionError from Standard
41 Create(F: in out MultipleVarFunctionWithGradient;
42 StartingPoint: Vector; Tolerance: Real=1.0e-8;
43 NbIterations: Integer=200; ZEPS: Real=1.0e-12)
45 -- Given the starting point StartingPoint,
46 -- the Broyden-Fletcher-Goldfarb-Shanno variant of Davidson-Fletcher-Powell
47 -- minimization is done on the function F.
48 -- The tolerance required on F is given by Tolerance.
49 -- The solution F = Fi is found when :
50 -- 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1) + ZEPS).
51 -- The maximum number of iterations allowed is given by NbIterations.
55 Create(F: in out MultipleVarFunctionWithGradient;
56 Tolerance: Real = 1.0e-8;
57 NbIterations: Integer = 200;
59 ---Purpose: Initializes the computation of the minimum of F.
61 -- A call to the Perform method must be made after this
62 -- initialization to effectively compute the minimum of the
67 Delete(me:out) is virtual;
68 ---C++: alias "Standard_EXPORT virtual ~math_BFGS(){Delete() ; }"
70 Perform(me: in out; F: in out MultipleVarFunctionWithGradient;
71 StartingPoint: Vector)
72 ---Purpose: Is used internally by the constructors.
77 IsSolutionReached(me; F: in out MultipleVarFunctionWithGradient)
79 -- This method is called at the end of each iteration to check if the
81 -- It can be redefined in a sub-class to implement a specific test to
82 -- stop the iterations.
89 ---Purpose: Returns true if the computations are successful, otherwise returns false.
97 ---Purpose: returns the location vector of the minimum.
98 -- Exception NotDone is raised if the minimum was not found.
100 ---C++: return const&
106 Location(me; Loc: out Vector)
107 ---Purpose: outputs the location vector of the minimum in Loc.
108 -- Exception NotDone is raised if the minimum was not found.
109 -- Exception DimensionError is raised if the range of Loc is not
110 -- equal to the range of the StartingPoint.
113 raises DimensionError,
119 ---Purpose: returns the value of the minimum.
120 -- Exception NotDone is raised if the minimum was not found.
129 ---Purpose: Returns the gradient vector at the minimum.
130 -- Exception NotDone is raised if the minimum was not found.
132 ---C++: return const&
138 Gradient(me; Grad: out Vector)
139 ---Purpose: Returns the value of the gradient vector at the minimum in Grad.
140 -- Exception NotDone is raised if the minimum was not found.
141 -- Exception DimensionError is raised if the range of Grad is not
142 -- equal to the range of the StartingPoint.
144 raises DimensionError,
150 ---Purpose: Returns the number of iterations really done in the
151 -- calculation of the minimum.
152 -- The exception NotDone is raised if the minimum was not found.
159 Dump(me; o: in out OStream)
160 ---Purpose: Prints on the stream o information on the current state
162 -- Is used to redefine the operator <<.
170 TheStatus: Status is protected;
171 TheLocation: Vector is protected;
172 TheGradient: Vector is protected;
173 PreviousMinimum: Real is protected;
174 TheMinimum: Real is protected;
175 XTol: Real is protected;
176 EPSZ: Real is protected;
177 nbiter: Integer is protected;