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
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _math_BrentMinimum_HeaderFile
18 #define _math_BrentMinimum_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <Standard_Real.hxx>
26 #include <Standard_Integer.hxx>
27 #include <Standard_OStream.hxx>
28 class StdFail_NotDone;
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
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);
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);
55 Standard_EXPORT virtual ~math_BrentMinimum();
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);
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);
71 //! Returns true if the computations are successful, otherwise returns false.
72 Standard_Boolean IsDone() const;
74 //! returns the location value of the minimum.
75 //! Exception NotDone is raised if the minimum was not found.
76 Standard_Real Location() const;
78 //! returns the value of the minimum.
79 //! Exception NotDone is raised if the minimum was not found.
80 Standard_Real Minimum() const;
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;
87 //! Prints on the stream o information on the current state
89 //! Is used to redefine the operator <<.
90 Standard_EXPORT void Dump (Standard_OStream& o) const;
113 Standard_Boolean Done;
114 Standard_Integer iter;
115 Standard_Integer Itermax;
116 Standard_Boolean myF;
122 #include <math_BrentMinimum.lxx>
128 #endif // _math_BrentMinimum_HeaderFile