b311480e |
1 | -- Created on: 1991-05-14 |
2 | -- Created by: Laurent PAINNOT |
3 | -- Copyright (c) 1991-1999 Matra Datavision |
973c2be1 |
4 | -- Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | -- |
973c2be1 |
6 | -- This file is part of Open CASCADE Technology software library. |
b311480e |
7 | -- |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
13 | -- |
973c2be1 |
14 | -- Alternatively, this file may be used under the terms of Open CASCADE |
15 | -- commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | class BrentMinimum from math |
18 | ---Purpose: |
19 | -- This class implements the Brent's method to find the minimum of |
20 | -- a function of a single variable. |
21 | -- No knowledge of the derivative is required. |
22 | |
23 | uses Matrix from math, |
24 | Vector from math, |
25 | Function from math, |
26 | OStream from Standard |
27 | |
28 | raises NotDone from StdFail |
29 | |
30 | is |
31 | |
32 | Create(TolX: Real; |
33 | NbIterations: Integer = 100; |
34 | ZEPS: Real = 1.0e-12) |
35 | ---Purpose: |
36 | -- This constructor should be used in a sub-class to initialize |
37 | -- correctly all the fields of this class. |
38 | |
39 | returns BrentMinimum; |
40 | |
41 | |
42 | Create(TolX: Real; Fbx: Real; |
43 | NbIterations: Integer = 100; |
44 | ZEPS: Real = 1.0e-12) |
45 | ---Purpose: |
46 | -- This constructor should be used in a sub-class to initialize |
47 | -- correctly all the fields of this class. |
48 | -- It has to be used if F(Bx) is known. |
49 | |
50 | returns BrentMinimum; |
51 | |
52 | |
53 | |
54 | Create(F: in out Function; Ax, Bx, Cx, TolX: Real; |
55 | NbIterations: Integer = 100; ZEPS: Real=1.0e-12) |
56 | ---Purpose: |
57 | -- Given a bracketing triplet of abscissae Ax, Bx, Cx |
58 | -- (such as Bx is between Ax and Cx, F(Bx) is |
59 | -- less than both F(Bx) and F(Cx)) the Brent minimization is done |
60 | -- on the function F. |
61 | -- The tolerance required on F is given by Tolerance. |
62 | -- The solution is found when : |
63 | -- abs(Xi - Xi-1) <= TolX * abs(Xi) + ZEPS; |
64 | -- The maximum number of iterations allowed is given by NbIterations. |
65 | |
66 | returns BrentMinimum; |
6da30ff1 |
67 | |
68 | ---C++: alias " Standard_EXPORT virtual ~math_BrentMinimum();" |
69 | |
7fd59977 |
70 | Perform(me: in out; F: in out Function; |
71 | Ax, Bx, Cx: Real) |
72 | ---Purpose: |
73 | -- Brent minimization is performed on function F from a given |
74 | -- bracketing triplet of abscissas Ax, Bx, Cx (such that Bx is |
75 | -- between Ax and Cx, F(Bx) is less than both F(Bx) and F(Cx)) |
76 | -- Warning |
77 | -- The initialization constructors must have been called |
78 | -- before the call to the Perform method. |
79 | |
80 | is static; |
81 | |
82 | |
83 | IsSolutionReached(me: in out; F: in out Function) |
84 | ---Purpose: |
85 | -- This method is called at the end of each iteration to check if the |
86 | -- solution is found. |
87 | -- It can be redefined in a sub-class to implement a specific test to |
88 | -- stop the iterations. |
6da30ff1 |
89 | |
7fd59977 |
90 | returns Boolean |
91 | is virtual; |
6da30ff1 |
92 | |
93 | |
7fd59977 |
94 | IsDone(me) |
95 | ---Purpose: Returns true if the computations are successful, otherwise returns false. |
96 | ---C++: inline |
97 | |
98 | returns Boolean |
99 | is static; |
100 | |
101 | |
102 | Location(me) |
103 | ---Purpose: returns the location value of the minimum. |
104 | -- Exception NotDone is raised if the minimum was not found. |
105 | ---C++: inline |
106 | returns Real |
107 | raises NotDone |
108 | is static; |
109 | |
110 | |
111 | Minimum(me) |
112 | ---Purpose: returns the value of the minimum. |
113 | -- Exception NotDone is raised if the minimum was not found. |
114 | ---C++: inline |
115 | |
116 | returns Real |
117 | raises NotDone |
118 | is static; |
119 | |
120 | |
121 | NbIterations(me) |
122 | ---Purpose: returns the number of iterations really done during the |
123 | -- computation of the minimum. |
124 | -- Exception NotDone is raised if the minimum was not found. |
125 | ---C++: inline |
126 | |
127 | returns Integer |
128 | raises NotDone |
129 | is static; |
130 | |
131 | |
132 | Dump(me; o: in out OStream) |
133 | ---Purpose: Prints on the stream o information on the current state |
134 | -- of the object. |
135 | -- Is used to redefine the operator <<. |
136 | |
137 | is static; |
138 | |
139 | |
140 | |
141 | fields |
142 | |
143 | Done: Boolean; |
144 | a: Real is protected; |
145 | b: Real is protected; |
146 | x: Real is protected; |
147 | fx: Real is protected; |
148 | fv: Real is protected; |
149 | fw: Real is protected; |
150 | iter: Integer; |
151 | XTol: Real is protected; |
152 | EPSZ: Real is protected; |
153 | Itermax: Integer; |
154 | myF: Boolean; |
155 | |
156 | end BrentMinimum; |