b311480e |
1 | -- Created on: 1991-05-14 |
2 | -- Created by: Laurent PAINNOT |
3 | -- Copyright (c) 1991-1999 Matra Datavision |
4 | -- Copyright (c) 1999-2012 OPEN CASCADE SAS |
5 | -- |
6 | -- The content of this file is subject to the Open CASCADE Technology Public |
7 | -- License Version 6.5 (the "License"). You may not use the content of this file |
8 | -- except in compliance with the License. Please obtain a copy of the License |
9 | -- at http://www.opencascade.org and read it completely before using this file. |
10 | -- |
11 | -- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
12 | -- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
13 | -- |
14 | -- The Original Code and all software distributed under the License is |
15 | -- distributed on an "AS IS" basis, without warranty of any kind, and the |
16 | -- Initial Developer hereby disclaims all such warranties, including without |
17 | -- limitation, any warranties of merchantability, fitness for a particular |
18 | -- purpose or non-infringement. Please see the License for the specific terms |
19 | -- and conditions governing the rights and limitations under the License. |
20 | |
7fd59977 |
21 | |
22 | |
23 | class BrentMinimum from math |
24 | ---Purpose: |
25 | -- This class implements the Brent's method to find the minimum of |
26 | -- a function of a single variable. |
27 | -- No knowledge of the derivative is required. |
28 | |
29 | uses Matrix from math, |
30 | Vector from math, |
31 | Function from math, |
32 | OStream from Standard |
33 | |
34 | raises NotDone from StdFail |
35 | |
36 | is |
37 | |
38 | Create(TolX: Real; |
39 | NbIterations: Integer = 100; |
40 | ZEPS: Real = 1.0e-12) |
41 | ---Purpose: |
42 | -- This constructor should be used in a sub-class to initialize |
43 | -- correctly all the fields of this class. |
44 | |
45 | returns BrentMinimum; |
46 | |
47 | |
48 | Create(TolX: Real; Fbx: Real; |
49 | NbIterations: Integer = 100; |
50 | ZEPS: Real = 1.0e-12) |
51 | ---Purpose: |
52 | -- This constructor should be used in a sub-class to initialize |
53 | -- correctly all the fields of this class. |
54 | -- It has to be used if F(Bx) is known. |
55 | |
56 | returns BrentMinimum; |
57 | |
58 | |
59 | |
60 | Create(F: in out Function; Ax, Bx, Cx, TolX: Real; |
61 | NbIterations: Integer = 100; ZEPS: Real=1.0e-12) |
62 | ---Purpose: |
63 | -- Given a bracketing triplet of abscissae Ax, Bx, Cx |
64 | -- (such as Bx is between Ax and Cx, F(Bx) is |
65 | -- less than both F(Bx) and F(Cx)) the Brent minimization is done |
66 | -- on the function F. |
67 | -- The tolerance required on F is given by Tolerance. |
68 | -- The solution is found when : |
69 | -- abs(Xi - Xi-1) <= TolX * abs(Xi) + ZEPS; |
70 | -- The maximum number of iterations allowed is given by NbIterations. |
71 | |
72 | returns BrentMinimum; |
73 | |
74 | |
75 | Perform(me: in out; F: in out Function; |
76 | Ax, Bx, Cx: Real) |
77 | ---Purpose: |
78 | -- Brent minimization is performed on function F from a given |
79 | -- bracketing triplet of abscissas Ax, Bx, Cx (such that Bx is |
80 | -- between Ax and Cx, F(Bx) is less than both F(Bx) and F(Cx)) |
81 | -- Warning |
82 | -- The initialization constructors must have been called |
83 | -- before the call to the Perform method. |
84 | |
85 | is static; |
86 | |
87 | |
88 | IsSolutionReached(me: in out; F: in out Function) |
89 | ---Purpose: |
90 | -- This method is called at the end of each iteration to check if the |
91 | -- solution is found. |
92 | -- It can be redefined in a sub-class to implement a specific test to |
93 | -- stop the iterations. |
94 | |
95 | returns Boolean |
96 | is virtual; |
97 | |
98 | |
99 | IsDone(me) |
100 | ---Purpose: Returns true if the computations are successful, otherwise returns false. |
101 | ---C++: inline |
102 | |
103 | returns Boolean |
104 | is static; |
105 | |
106 | |
107 | Location(me) |
108 | ---Purpose: returns the location value of the minimum. |
109 | -- Exception NotDone is raised if the minimum was not found. |
110 | ---C++: inline |
111 | returns Real |
112 | raises NotDone |
113 | is static; |
114 | |
115 | |
116 | Minimum(me) |
117 | ---Purpose: returns the value of the minimum. |
118 | -- Exception NotDone is raised if the minimum was not found. |
119 | ---C++: inline |
120 | |
121 | returns Real |
122 | raises NotDone |
123 | is static; |
124 | |
125 | |
126 | NbIterations(me) |
127 | ---Purpose: returns the number of iterations really done during the |
128 | -- computation of the minimum. |
129 | -- Exception NotDone is raised if the minimum was not found. |
130 | ---C++: inline |
131 | |
132 | returns Integer |
133 | raises NotDone |
134 | is static; |
135 | |
136 | |
137 | Dump(me; o: in out OStream) |
138 | ---Purpose: Prints on the stream o information on the current state |
139 | -- of the object. |
140 | -- Is used to redefine the operator <<. |
141 | |
142 | is static; |
143 | |
144 | |
145 | |
146 | fields |
147 | |
148 | Done: Boolean; |
149 | a: Real is protected; |
150 | b: Real is protected; |
151 | x: Real is protected; |
152 | fx: Real is protected; |
153 | fv: Real is protected; |
154 | fw: Real is protected; |
155 | iter: Integer; |
156 | XTol: Real is protected; |
157 | EPSZ: Real is protected; |
158 | Itermax: Integer; |
159 | myF: Boolean; |
160 | |
161 | end BrentMinimum; |