0025571: Avoid base Classes without virtual Destructors
[occt.git] / src / math / math_FRPR.hxx
1 // Created on: 1991-05-14
2 // Created by: Laurent PAINNOT
3 // Copyright (c) 1991-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #ifndef _math_FRPR_HeaderFile
18 #define _math_FRPR_HeaderFile
19
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
23
24 #include <Standard_Boolean.hxx>
25 #include <math_Vector.hxx>
26 #include <Standard_Real.hxx>
27 #include <Standard_Integer.hxx>
28 #include <math_Status.hxx>
29 #include <Standard_OStream.hxx>
30 class Standard_DimensionError;
31 class StdFail_NotDone;
32 class math_MultipleVarFunctionWithGradient;
33
34
35
36 //! this class implements the Fletcher-Reeves-Polak_Ribiere minimization
37 //! algorithm of a function of multiple variables.
38 //! Knowledge of the function's gradient is required.
39 class math_FRPR 
40 {
41 public:
42
43   DEFINE_STANDARD_ALLOC
44
45   
46
47   //! Initializes the computation of the minimum of F.
48   //! Warning: constructor does not perform computations.
49   Standard_EXPORT math_FRPR(const math_MultipleVarFunctionWithGradient& theFunction, const Standard_Real theTolerance, const Standard_Integer theNbIterations = 200, const Standard_Real theZEPS = 1.0e-12);
50   
51   //! Destructor alias.
52   Standard_EXPORT void Delete() const;
53   Standard_EXPORT virtual ~math_FRPR();
54   
55
56   //! The solution F = Fi is found when
57   //! 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1) + ZEPS).
58   Standard_EXPORT void Perform (math_MultipleVarFunctionWithGradient& theFunction, const math_Vector& theStartingPoint);
59   
60
61   //! The solution F = Fi is found when:
62   //! 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1)) + ZEPS.
63   //! The maximum number of iterations allowed is given by NbIterations.
64     virtual Standard_Boolean IsSolutionReached (math_MultipleVarFunctionWithGradient& theFunction);
65   
66   //! Returns true if the computations are successful, otherwise returns false.
67     Standard_Boolean IsDone() const;
68   
69   //! returns the location vector of the minimum.
70   //! Exception NotDone is raised if the minimum was not found.
71     const math_Vector& Location() const;
72   
73   //! outputs the location vector of the minimum in Loc.
74   //! Exception NotDone is raised if the minimum was not found.
75   //! Exception DimensionError is raised if the range of Loc is not
76   //! equal to the range of the StartingPoint.
77     void Location (math_Vector& Loc) const;
78   
79   //! returns the value of the minimum.
80   //! Exception NotDone is raised if the minimum was not found.
81     Standard_Real Minimum() const;
82   
83   //! returns the gradient vector at the minimum.
84   //! Exception NotDone is raised if the minimum was not found.
85     const math_Vector& Gradient() const;
86   
87   //! outputs the gradient vector at the minimum in Grad.
88   //! Exception NotDone is raised if the minimum was not found.
89   //! Exception DimensionError is raised if the range of Grad is not
90   //! equal to the range of the StartingPoint.
91     void Gradient (math_Vector& Grad) const;
92   
93   //! returns the number of iterations really done during the
94   //! computation of the minimum.
95   //! Exception NotDone is raised if the minimum was not found.
96     Standard_Integer NbIterations() const;
97   
98   //! Prints on the stream o information on the current state
99   //! of the object.
100   //! Is used to redefine the operator <<.
101   Standard_EXPORT void Dump (Standard_OStream& o) const;
102
103
104
105
106 protected:
107
108
109
110   math_Vector TheLocation;
111   math_Vector TheGradient;
112   Standard_Real TheMinimum;
113   Standard_Real PreviousMinimum;
114   Standard_Real XTol;
115   Standard_Real EPSZ;
116
117
118 private:
119
120
121
122   Standard_Boolean Done;
123   Standard_Integer Iter;
124   Standard_Integer State;
125   math_Status TheStatus;
126   Standard_Integer Itermax;
127
128
129 };
130
131
132 #include <math_FRPR.lxx>
133
134
135
136
137
138 #endif // _math_FRPR_HeaderFile