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_BracketMinimum_HeaderFile |
18 | #define _math_BracketMinimum_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_OStream.hxx> |
27 | class StdFail_NotDone; |
28 | class math_Function; |
29 | |
30 | |
31 | //! Given two distinct initial points, BracketMinimum |
32 | //! implements the computation of three points (a, b, c) which |
33 | //! bracket the minimum of the function and verify A less than |
f79b19a1 |
34 | //! B, B less than C and F(B) less than F(A), F(B) less than F(C). |
35 | //! |
36 | //! The algorithm supports conditional optimization. By default no limits are |
37 | //! applied to the parameter change. The method SetLimits defines the allowed range. |
38 | //! If no minimum is found in limits then IsDone() will return false. The user |
39 | //! is in charge of providing A and B to be in limits. |
40 | class math_BracketMinimum |
42cf5bc1 |
41 | { |
42 | public: |
43 | |
44 | DEFINE_STANDARD_ALLOC |
45 | |
f79b19a1 |
46 | //! Constructor preparing A and B parameters only. It does not perform the job. |
0f57ab75 |
47 | math_BracketMinimum(const Standard_Real A, const Standard_Real B); |
42cf5bc1 |
48 | |
49 | //! Given two initial values this class computes a |
50 | //! bracketing triplet of abscissae Ax, Bx, Cx |
51 | //! (such that Bx is between Ax and Cx, F(Bx) is |
52 | //! less than both F(Bx) and F(Cx)) the Brent minimization is done |
53 | //! on the function F. |
54 | Standard_EXPORT math_BracketMinimum(math_Function& F, const Standard_Real A, const Standard_Real B); |
55 | |
56 | |
57 | //! Given two initial values this class computes a |
58 | //! bracketing triplet of abscissae Ax, Bx, Cx |
59 | //! (such that Bx is between Ax and Cx, F(Bx) is |
60 | //! less than both F(Bx) and F(Cx)) the Brent minimization is done |
61 | //! on the function F. |
62 | //! This constructor has to be used if F(A) is known. |
63 | Standard_EXPORT math_BracketMinimum(math_Function& F, const Standard_Real A, const Standard_Real B, const Standard_Real FA); |
64 | |
65 | |
66 | //! Given two initial values this class computes a |
67 | //! bracketing triplet of abscissae Ax, Bx, Cx |
68 | //! (such that Bx is between Ax and Cx, F(Bx) is |
69 | //! less than both F(Bx) and F(Cx)) the Brent minimization is done |
70 | //! on the function F. |
71 | //! This constructor has to be used if F(A) and F(B) are known. |
72 | Standard_EXPORT math_BracketMinimum(math_Function& F, const Standard_Real A, const Standard_Real B, const Standard_Real FA, const Standard_Real FB); |
f79b19a1 |
73 | |
74 | //! Set limits of the parameter. By default no limits are applied to the parameter change. |
75 | //! If no minimum is found in limits then IsDone() will return false. The user |
76 | //! is in charge of providing A and B to be in limits. |
77 | void SetLimits(const Standard_Real theLeft, const Standard_Real theRight); |
78 | |
79 | //! Set function value at A |
80 | void SetFA(const Standard_Real theValue); |
81 | |
82 | //! Set function value at B |
83 | void SetFB(const Standard_Real theValue); |
84 | |
85 | //! The method performing the job. It is called automatically by constructors with the function. |
86 | Standard_EXPORT void Perform(math_Function& F); |
87 | |
42cf5bc1 |
88 | //! Returns true if the computations are successful, otherwise returns false. |
f79b19a1 |
89 | Standard_Boolean IsDone() const; |
42cf5bc1 |
90 | |
91 | //! Returns the bracketed triplet of abscissae. |
92 | //! Exceptions |
93 | //! StdFail_NotDone if the algorithm fails (and IsDone returns false). |
94 | Standard_EXPORT void Values (Standard_Real& A, Standard_Real& B, Standard_Real& C) const; |
95 | |
96 | //! returns the bracketed triplet function values. |
97 | //! Exceptions |
98 | //! StdFail_NotDone if the algorithm fails (and IsDone returns false). |
99 | Standard_EXPORT void FunctionValues (Standard_Real& FA, Standard_Real& FB, Standard_Real& FC) const; |
100 | |
101 | //! Prints on the stream o information on the current state |
102 | //! of the object. |
103 | //! Is used to redefine the operator <<. |
104 | Standard_EXPORT void Dump (Standard_OStream& o) const; |
105 | |
f79b19a1 |
106 | private: |
42cf5bc1 |
107 | |
f79b19a1 |
108 | //! Limit the given value to become within the range [myLeft, myRight]. |
109 | Standard_Real Limited(const Standard_Real theValue) const; |
42cf5bc1 |
110 | |
f79b19a1 |
111 | //! Limit the value of C (see Limited) and compute the function in it. |
112 | //! If C occurs to be between A and B then swap parameters and function |
113 | //! values of B and C. |
114 | //! Return false in the case of C becomes equal to B or function calculation |
115 | //! failure. |
116 | Standard_Boolean LimitAndMayBeSwap(math_Function& F, const Standard_Real theA, |
117 | Standard_Real& theB, Standard_Real& theFB, |
118 | Standard_Real& theC, Standard_Real& theFC) const; |
42cf5bc1 |
119 | |
120 | private: |
121 | |
42cf5bc1 |
122 | Standard_Boolean Done; |
123 | Standard_Real Ax; |
124 | Standard_Real Bx; |
125 | Standard_Real Cx; |
126 | Standard_Real FAx; |
127 | Standard_Real FBx; |
128 | Standard_Real FCx; |
f79b19a1 |
129 | Standard_Real myLeft; |
130 | Standard_Real myRight; |
131 | Standard_Boolean myIsLimited; |
42cf5bc1 |
132 | Standard_Boolean myFA; |
133 | Standard_Boolean myFB; |
134 | |
135 | |
136 | }; |
137 | |
138 | |
139 | #include <math_BracketMinimum.lxx> |
140 | |
141 | |
142 | |
143 | |
144 | |
145 | #endif // _math_BracketMinimum_HeaderFile |