42cf5bc1 |
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_BrentMinimum_HeaderFile |
18 | #define _math_BrentMinimum_HeaderFile |
19 | |
20 | #include <Standard.hxx> |
21 | #include <Standard_DefineAlloc.hxx> |
22 | #include <Standard_Handle.hxx> |
23 | |
24 | #include <Standard_Boolean.hxx> |
25 | #include <Standard_Real.hxx> |
26 | #include <Standard_Integer.hxx> |
27 | #include <Standard_OStream.hxx> |
28 | class StdFail_NotDone; |
29 | class math_Function; |
30 | |
31 | |
32 | |
33 | //! This class implements the Brent's method to find the minimum of |
34 | //! a function of a single variable. |
35 | //! No knowledge of the derivative is required. |
36 | class math_BrentMinimum |
37 | { |
38 | public: |
39 | |
40 | DEFINE_STANDARD_ALLOC |
41 | |
42 | |
43 | |
44 | //! This constructor should be used in a sub-class to initialize |
45 | //! correctly all the fields of this class. |
46 | Standard_EXPORT math_BrentMinimum(const Standard_Real TolX, const Standard_Integer NbIterations = 100, const Standard_Real ZEPS = 1.0e-12); |
47 | |
48 | |
49 | //! This constructor should be used in a sub-class to initialize |
50 | //! correctly all the fields of this class. |
51 | //! It has to be used if F(Bx) is known. |
52 | Standard_EXPORT math_BrentMinimum(const Standard_Real TolX, const Standard_Real Fbx, const Standard_Integer NbIterations = 100, const Standard_Real ZEPS = 1.0e-12); |
53 | |
e6f550da |
54 | //! Destructor |
42cf5bc1 |
55 | Standard_EXPORT virtual ~math_BrentMinimum(); |
56 | |
57 | |
58 | //! Brent minimization is performed on function F from a given |
59 | //! bracketing triplet of abscissas Ax, Bx, Cx (such that Bx is |
60 | //! between Ax and Cx, F(Bx) is less than both F(Bx) and F(Cx)) |
61 | //! The solution is found when: abs(Xi - Xi-1) <= TolX * abs(Xi) + ZEPS; |
62 | Standard_EXPORT void Perform (math_Function& F, const Standard_Real Ax, const Standard_Real Bx, const Standard_Real Cx); |
63 | |
64 | |
65 | //! This method is called at the end of each iteration to check if the |
66 | //! solution is found. |
67 | //! It can be redefined in a sub-class to implement a specific test to |
68 | //! stop the iterations. |
69 | virtual Standard_Boolean IsSolutionReached (math_Function& theFunction); |
70 | |
71 | //! Returns true if the computations are successful, otherwise returns false. |
72 | Standard_Boolean IsDone() const; |
73 | |
74 | //! returns the location value of the minimum. |
75 | //! Exception NotDone is raised if the minimum was not found. |
76 | Standard_Real Location() const; |
77 | |
78 | //! returns the value of the minimum. |
79 | //! Exception NotDone is raised if the minimum was not found. |
80 | Standard_Real Minimum() const; |
81 | |
82 | //! returns the number of iterations really done during the |
83 | //! computation of the minimum. |
84 | //! Exception NotDone is raised if the minimum was not found. |
85 | Standard_Integer NbIterations() const; |
86 | |
87 | //! Prints on the stream o information on the current state |
88 | //! of the object. |
89 | //! Is used to redefine the operator <<. |
90 | Standard_EXPORT void Dump (Standard_OStream& o) const; |
91 | |
92 | |
93 | |
94 | |
95 | protected: |
96 | |
97 | |
98 | |
99 | Standard_Real a; |
100 | Standard_Real b; |
101 | Standard_Real x; |
102 | Standard_Real fx; |
103 | Standard_Real fv; |
104 | Standard_Real fw; |
105 | Standard_Real XTol; |
106 | Standard_Real EPSZ; |
107 | |
108 | |
109 | private: |
110 | |
111 | |
112 | |
113 | Standard_Boolean Done; |
114 | Standard_Integer iter; |
115 | Standard_Integer Itermax; |
116 | Standard_Boolean myF; |
117 | |
118 | |
119 | }; |
120 | |
121 | |
122 | #include <math_BrentMinimum.lxx> |
123 | |
124 | |
125 | |
126 | |
127 | |
128 | #endif // _math_BrentMinimum_HeaderFile |