]>
Commit | Line | Data |
---|---|---|
4bbaf12b | 1 | // Created on: 2014-01-20 |
2 | // Created by: Alexaner Malyshev | |
4b65fc77 | 3 | // Copyright (c) 2014-2015 OPEN CASCADE SAS |
4bbaf12b | 4 | // |
5 | // This file is part of Open CASCADE Technology software library. | |
6 | // | |
7 | // This library is free software; you can redistribute it and/or modify it under | |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published | |
9 | // by the Free Software Foundation, with special exception defined in the file | |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
11 | // distribution for complete text of the license and disclaimer of any warranty. | |
12 | // | |
13 | // Alternatively, this file may be used under the terms of Open CASCADE | |
14 | // commercial license or contractual agreement. | |
15 | ||
16 | #ifndef _math_GlobOptMin_HeaderFile | |
17 | #define _math_GlobOptMin_HeaderFile | |
18 | ||
4b65fc77 | 19 | #include <gp_Pnt.hxx> |
20 | #include <gp_Pnt2d.hxx> | |
50bc8f96 | 21 | #include <NCollection_CellFilter.hxx> |
4bbaf12b | 22 | #include <math_MultipleVarFunction.hxx> |
23 | #include <NCollection_Sequence.hxx> | |
24 | #include <Standard_Type.hxx> | |
25 | ||
50bc8f96 | 26 | class NCollection_CellFilter_Inspector |
4b65fc77 | 27 | { |
28 | public: | |
29 | ||
30 | //! Points and target type | |
31 | typedef math_Vector Point; | |
32 | typedef math_Vector Target; | |
33 | ||
50bc8f96 | 34 | NCollection_CellFilter_Inspector(const Standard_Integer theDim, |
35 | const Standard_Real theTol) | |
4b65fc77 | 36 | : myCurrent(1, theDim) |
37 | { | |
38 | myTol = theTol * theTol; | |
39 | myIsFind = Standard_False; | |
40 | Dimension = theDim; | |
41 | } | |
42 | ||
43 | //! Access to co-ordinate | |
44 | static Standard_Real Coord (int i, const Point &thePnt) | |
45 | { | |
46 | return thePnt(i + 1); | |
47 | } | |
48 | ||
49 | //! Auxiliary method to shift point by each coordinate on given value; | |
50 | //! useful for preparing a points range for Inspect with tolerance | |
51 | void Shift (const Point& thePnt, | |
52 | const NCollection_Array1<Standard_Real> &theTol, | |
53 | Point& theLowPnt, | |
54 | Point& theUppPnt) const | |
55 | { | |
56 | for(Standard_Integer anIdx = 1; anIdx <= Dimension; anIdx++) | |
57 | { | |
58 | theLowPnt(anIdx) = thePnt(anIdx) - theTol(anIdx - 1); | |
59 | theUppPnt(anIdx) = thePnt(anIdx) + theTol(anIdx - 1); | |
60 | } | |
61 | } | |
62 | ||
63 | void ClearFind() | |
64 | { | |
65 | myIsFind = Standard_False; | |
66 | } | |
67 | ||
68 | Standard_Boolean isFind() | |
69 | { | |
70 | return myIsFind; | |
71 | } | |
72 | ||
73 | //! Set current point to search for coincidence | |
74 | void SetCurrent (const math_Vector& theCurPnt) | |
75 | { | |
76 | myCurrent = theCurPnt; | |
77 | } | |
78 | ||
79 | //! Implementation of inspection method | |
80 | NCollection_CellFilter_Action Inspect (const Target& theObject) | |
81 | { | |
82 | Standard_Real aSqDist = (myCurrent - theObject).Norm2(); | |
83 | ||
84 | if(aSqDist < myTol) | |
85 | { | |
86 | myIsFind = Standard_True; | |
87 | } | |
88 | ||
89 | return CellFilter_Keep; | |
90 | } | |
91 | ||
92 | private: | |
93 | Standard_Real myTol; | |
94 | math_Vector myCurrent; | |
95 | Standard_Boolean myIsFind; | |
96 | Standard_Integer Dimension; | |
97 | }; | |
98 | ||
4bbaf12b | 99 | //! This class represents Evtushenko's algorithm of global optimization based on nonuniform mesh.<br> |
100 | //! Article: Yu. Evtushenko. Numerical methods for finding global extreme (case of a non-uniform mesh). <br> | |
101 | //! U.S.S.R. Comput. Maths. Math. Phys., Vol. 11, N 6, pp. 38-54. | |
102 | ||
103 | class math_GlobOptMin | |
104 | { | |
105 | public: | |
106 | ||
107 | Standard_EXPORT math_GlobOptMin(math_MultipleVarFunction* theFunc, | |
3f733bb1 | 108 | const math_Vector& theLowerBorder, |
109 | const math_Vector& theUpperBorder, | |
5493d334 | 110 | const Standard_Real theC = 9, |
111 | const Standard_Real theDiscretizationTol = 1.0e-2, | |
112 | const Standard_Real theSameTol = 1.0e-7); | |
4bbaf12b | 113 | |
114 | Standard_EXPORT void SetGlobalParams(math_MultipleVarFunction* theFunc, | |
3f733bb1 | 115 | const math_Vector& theLowerBorder, |
116 | const math_Vector& theUpperBorder, | |
5493d334 | 117 | const Standard_Real theC = 9, |
118 | const Standard_Real theDiscretizationTol = 1.0e-2, | |
119 | const Standard_Real theSameTol = 1.0e-7); | |
4bbaf12b | 120 | |
121 | Standard_EXPORT void SetLocalParams(const math_Vector& theLocalA, | |
122 | const math_Vector& theLocalB); | |
123 | ||
5493d334 | 124 | Standard_EXPORT void SetTol(const Standard_Real theDiscretizationTol, |
125 | const Standard_Real theSameTol); | |
126 | ||
127 | Standard_EXPORT void GetTol(Standard_Real& theDiscretizationTol, | |
128 | Standard_Real& theSameTol); | |
129 | ||
4bbaf12b | 130 | Standard_EXPORT ~math_GlobOptMin(); |
131 | ||
78e7cada | 132 | //! @param isFindSingleSolution - defines whether to find single solution or all solutions. |
133 | Standard_EXPORT void Perform(const Standard_Boolean isFindSingleSolution = Standard_False); | |
4bbaf12b | 134 | |
135 | //! Get best functional value. | |
136 | Standard_EXPORT Standard_Real GetF(); | |
137 | ||
797d11c6 | 138 | //! Return count of global extremas. |
4bbaf12b | 139 | Standard_EXPORT Standard_Integer NbExtrema(); |
140 | ||
3f733bb1 | 141 | //! Return solution theIndex, 1 <= theIndex <= NbExtrema. |
4bbaf12b | 142 | Standard_EXPORT void Points(const Standard_Integer theIndex, math_Vector& theSol); |
143 | ||
836d7b64 | 144 | Standard_EXPORT Standard_Boolean isDone(); |
145 | ||
146 | //! Set functional minimal value. | |
147 | Standard_EXPORT void SetFunctionalMinimalValue(const Standard_Real theMinimalValue); | |
148 | ||
1907fb9a | 149 | //! Lock/Unlock Lipchitz constant for internal modifications. |
150 | Standard_EXPORT void SetLipConstState(const Standard_Boolean theFlag); | |
151 | ||
836d7b64 | 152 | //! Get functional minimal value. |
153 | Standard_EXPORT Standard_Real GetFunctionalMinimalValue(); | |
5493d334 | 154 | |
5333268d | 155 | //! Get continuity of local borders splits. |
156 | inline Standard_Integer GetContinuity() const {return myCont; } | |
157 | ||
158 | //! Set continuity of local borders splits. | |
159 | inline void SetContinuity(const Standard_Integer theCont) { myCont = theCont; } | |
160 | ||
4bbaf12b | 161 | private: |
162 | ||
4b65fc77 | 163 | // Compute cell size. |
164 | void initCellSize(); | |
165 | ||
1907fb9a | 166 | // Compute initial solution |
167 | void ComputeInitSol(); | |
168 | ||
4bbaf12b | 169 | math_GlobOptMin & operator = (const math_GlobOptMin & theOther); |
170 | ||
171 | Standard_Boolean computeLocalExtremum(const math_Vector& thePnt, Standard_Real& theVal, math_Vector& theOutPnt); | |
172 | ||
173 | void computeGlobalExtremum(Standard_Integer theIndex); | |
174 | ||
836d7b64 | 175 | //! Check possibility to stop computations. |
176 | //! Find single solution + in neighbourhood of best possible solution. | |
177 | Standard_Boolean CheckFunctionalStopCriteria(); | |
178 | ||
797d11c6 | 179 | //! Computes starting value / approximation: |
3f733bb1 | 180 | //! myF - initial best value. |
181 | //! myY - initial best point. | |
182 | //! myC - approximation of Lipschitz constant. | |
183 | //! to imporve convergence speed. | |
797d11c6 | 184 | void computeInitialValues(); |
185 | ||
3f733bb1 | 186 | //! Check that myA <= thePnt <= myB |
4bbaf12b | 187 | Standard_Boolean isInside(const math_Vector& thePnt); |
188 | ||
3f733bb1 | 189 | //! Check presence of thePnt in GlobOpt sequence. |
4bbaf12b | 190 | Standard_Boolean isStored(const math_Vector &thePnt); |
4bbaf12b | 191 | |
192 | // Input. | |
193 | math_MultipleVarFunction* myFunc; | |
194 | Standard_Integer myN; | |
195 | math_Vector myA; // Left border on current C2 interval. | |
196 | math_Vector myB; // Right border on current C2 interval. | |
197 | math_Vector myGlobA; // Global left border. | |
198 | math_Vector myGlobB; // Global right border. | |
5493d334 | 199 | Standard_Real myTol; // Discretization tolerance, default 1.0e-2. |
200 | Standard_Real mySameTol; // points with ||p1 - p2|| < mySameTol is equal, | |
201 | // function values |val1 - val2| * 0.01 < mySameTol is equal, | |
202 | // default value is 1.0e-7. | |
1907fb9a | 203 | Standard_Real myC; //Lipchitz constant, default 9 |
204 | Standard_Real myInitC; // Lipchitz constant initial value. | |
78e7cada | 205 | Standard_Boolean myIsFindSingleSolution; // Default value is false. |
836d7b64 | 206 | Standard_Real myFunctionalMinimalValue; // Default value is -Precision::Infinite |
1907fb9a | 207 | Standard_Boolean myIsConstLocked; // Is constant locked for modifications. |
4bbaf12b | 208 | |
209 | // Output. | |
210 | Standard_Boolean myDone; | |
211 | NCollection_Sequence<Standard_Real> myY;// Current solutions. | |
212 | Standard_Integer mySolCount; // Count of solutions. | |
213 | ||
214 | // Algorithm data. | |
215 | Standard_Real myZ; | |
4bbaf12b | 216 | Standard_Real myE1; // Border coeff. |
217 | Standard_Real myE2; // Minimum step size. | |
218 | Standard_Real myE3; // Local extrema starting parameter. | |
219 | ||
5493d334 | 220 | math_Vector myX; // Current modified solution. |
221 | math_Vector myTmp; // Current modified solution. | |
4bbaf12b | 222 | math_Vector myV; // Steps array. |
5493d334 | 223 | math_Vector myMaxV; // Max Steps array. |
1907fb9a | 224 | Standard_Real myLastStep; // Last step. |
3f733bb1 | 225 | math_Vector myExpandCoeff; // Define expand coefficient between neighboring indiced dimensions. |
4bbaf12b | 226 | |
4b65fc77 | 227 | NCollection_Array1<Standard_Real> myCellSize; |
228 | Standard_Integer myMinCellFilterSol; | |
229 | Standard_Boolean isFirstCellFilterInvoke; | |
50bc8f96 | 230 | NCollection_CellFilter<NCollection_CellFilter_Inspector> myFilter; |
4b65fc77 | 231 | |
5333268d | 232 | // Continuity of local borders. |
233 | Standard_Integer myCont; | |
234 | ||
4bbaf12b | 235 | Standard_Real myF; // Current value of Global optimum. |
236 | }; | |
237 | ||
4bbaf12b | 238 | #endif |