File indexing completed on 2025-01-18 10:04:14
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016 #ifndef _math_GlobOptMin_HeaderFile
0017 #define _math_GlobOptMin_HeaderFile
0018
0019 #include <gp_Pnt.hxx>
0020 #include <NCollection_CellFilter.hxx>
0021 #include <math_MultipleVarFunction.hxx>
0022 #include <NCollection_Sequence.hxx>
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 class math_GlobOptMin
0050 {
0051 public:
0052
0053
0054
0055
0056
0057
0058
0059
0060 Standard_EXPORT math_GlobOptMin(math_MultipleVarFunction* theFunc,
0061 const math_Vector& theLowerBorder,
0062 const math_Vector& theUpperBorder,
0063 const Standard_Real theC = 9,
0064 const Standard_Real theDiscretizationTol = 1.0e-2,
0065 const Standard_Real theSameTol = 1.0e-7);
0066
0067
0068
0069
0070
0071
0072
0073 Standard_EXPORT void SetGlobalParams(math_MultipleVarFunction* theFunc,
0074 const math_Vector& theLowerBorder,
0075 const math_Vector& theUpperBorder,
0076 const Standard_Real theC = 9,
0077 const Standard_Real theDiscretizationTol = 1.0e-2,
0078 const Standard_Real theSameTol = 1.0e-7);
0079
0080
0081
0082
0083 Standard_EXPORT void SetLocalParams(const math_Vector& theLocalA,
0084 const math_Vector& theLocalB);
0085
0086
0087
0088
0089 Standard_EXPORT void SetTol(const Standard_Real theDiscretizationTol,
0090 const Standard_Real theSameTol);
0091
0092
0093
0094
0095 Standard_EXPORT void GetTol(Standard_Real& theDiscretizationTol,
0096 Standard_Real& theSameTol);
0097
0098
0099 Standard_EXPORT void Perform(const Standard_Boolean isFindSingleSolution = Standard_False);
0100
0101
0102 Standard_EXPORT void Points(const Standard_Integer theIndex, math_Vector& theSol);
0103
0104
0105 inline void SetContinuity(const Standard_Integer theCont) { myCont = theCont; }
0106 inline Standard_Integer GetContinuity() const {return myCont; }
0107
0108
0109 inline void SetFunctionalMinimalValue(const Standard_Real theMinimalValue)
0110 { myFunctionalMinimalValue = theMinimalValue; }
0111 inline Standard_Real GetFunctionalMinimalValue() const {return myFunctionalMinimalValue;}
0112
0113
0114
0115 inline void SetLipConstState(const Standard_Boolean theFlag) {myIsConstLocked = theFlag; }
0116 inline Standard_Boolean GetLipConstState() const { return myIsConstLocked; }
0117
0118
0119 inline Standard_Boolean isDone() const {return myDone; }
0120
0121
0122 inline Standard_Real GetF() const {return myF;}
0123
0124
0125 inline Standard_Integer NbExtrema() const {return mySolCount;}
0126
0127 private:
0128
0129
0130 class NCollection_CellFilter_Inspector
0131 {
0132 public:
0133
0134
0135 typedef math_Vector Point;
0136 typedef math_Vector Target;
0137
0138 NCollection_CellFilter_Inspector(const Standard_Integer theDim,
0139 const Standard_Real theTol)
0140 : myCurrent(1, theDim)
0141 {
0142 myTol = theTol * theTol;
0143 myIsFind = Standard_False;
0144 Dimension = theDim;
0145 }
0146
0147
0148 static Standard_Real Coord (int i, const Point &thePnt)
0149 {
0150 return thePnt(i + 1);
0151 }
0152
0153
0154
0155 void Shift (const Point& thePnt,
0156 const NCollection_Array1<Standard_Real> &theTol,
0157 Point& theLowPnt,
0158 Point& theUppPnt) const
0159 {
0160 for(Standard_Integer anIdx = 1; anIdx <= Dimension; anIdx++)
0161 {
0162 theLowPnt(anIdx) = thePnt(anIdx) - theTol(anIdx - 1);
0163 theUppPnt(anIdx) = thePnt(anIdx) + theTol(anIdx - 1);
0164 }
0165 }
0166
0167 void ClearFind()
0168 {
0169 myIsFind = Standard_False;
0170 }
0171
0172 Standard_Boolean isFind()
0173 {
0174 return myIsFind;
0175 }
0176
0177
0178 void SetCurrent (const math_Vector& theCurPnt)
0179 {
0180 myCurrent = theCurPnt;
0181 }
0182
0183
0184 NCollection_CellFilter_Action Inspect (const Target& theObject)
0185 {
0186 Standard_Real aSqDist = (myCurrent - theObject).Norm2();
0187
0188 if(aSqDist < myTol)
0189 {
0190 myIsFind = Standard_True;
0191 }
0192
0193 return CellFilter_Keep;
0194 }
0195
0196 private:
0197 Standard_Real myTol;
0198 math_Vector myCurrent;
0199 Standard_Boolean myIsFind;
0200 Standard_Integer Dimension;
0201 };
0202
0203
0204
0205 void initCellSize();
0206
0207
0208 void ComputeInitSol();
0209
0210 math_GlobOptMin & operator = (const math_GlobOptMin & theOther);
0211
0212 Standard_Boolean computeLocalExtremum(const math_Vector& thePnt, Standard_Real& theVal, math_Vector& theOutPnt);
0213
0214 void computeGlobalExtremum(Standard_Integer theIndex);
0215
0216
0217
0218 Standard_Boolean CheckFunctionalStopCriteria();
0219
0220
0221
0222
0223
0224
0225 void computeInitialValues();
0226
0227
0228 Standard_Boolean isInside(const math_Vector& thePnt);
0229
0230
0231 Standard_Boolean isStored(const math_Vector &thePnt);
0232
0233
0234
0235
0236 void checkAddCandidate(const math_Vector& thePnt,
0237 const Standard_Real theValue);
0238
0239
0240
0241 math_MultipleVarFunction* myFunc;
0242 Standard_Integer myN;
0243 math_Vector myA;
0244 math_Vector myB;
0245 math_Vector myGlobA;
0246 math_Vector myGlobB;
0247 Standard_Real myTol;
0248 Standard_Real mySameTol;
0249
0250
0251 Standard_Real myC;
0252 Standard_Real myInitC;
0253 Standard_Boolean myIsFindSingleSolution;
0254 Standard_Real myFunctionalMinimalValue;
0255 Standard_Boolean myIsConstLocked;
0256
0257
0258 Standard_Boolean myDone;
0259 NCollection_Sequence<Standard_Real> myY;
0260 Standard_Integer mySolCount;
0261
0262
0263 Standard_Real myZ;
0264 Standard_Real myE1;
0265 Standard_Real myE2;
0266 Standard_Real myE3;
0267
0268 math_Vector myX;
0269 math_Vector myTmp;
0270 math_Vector myV;
0271 math_Vector myMaxV;
0272 Standard_Real myLastStep;
0273
0274 NCollection_Array1<Standard_Real> myCellSize;
0275 Standard_Integer myMinCellFilterSol;
0276 Standard_Boolean isFirstCellFilterInvoke;
0277 NCollection_CellFilter<NCollection_CellFilter_Inspector> myFilter;
0278
0279
0280 Standard_Integer myCont;
0281
0282 Standard_Real myF;
0283 };
0284
0285 #endif