|
|
|||
File indexing completed on 2026-09-16 09:17:48
0001 // Created on: 1991-05-14 0002 // Created by: Laurent PAINNOT 0003 // Copyright (c) 1991-1999 Matra Datavision 0004 // Copyright (c) 1999-2014 OPEN CASCADE SAS 0005 // 0006 // This file is part of Open CASCADE Technology software library. 0007 // 0008 // This library is free software; you can redistribute it and/or modify it under 0009 // the terms of the GNU Lesser General Public License version 2.1 as published 0010 // by the Free Software Foundation, with special exception defined in the file 0011 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT 0012 // distribution for complete text of the license and disclaimer of any warranty. 0013 // 0014 // Alternatively, this file may be used under the terms of Open CASCADE 0015 // commercial license or contractual agreement. 0016 0017 #ifndef _math_BFGS_HeaderFile 0018 #define _math_BFGS_HeaderFile 0019 0020 #include <Standard.hxx> 0021 #include <Standard_DefineAlloc.hxx> 0022 #include <Standard_Handle.hxx> 0023 0024 #include <math_Status.hxx> 0025 #include <math_Vector.hxx> 0026 #include <Standard_OStream.hxx> 0027 class math_MultipleVarFunctionWithGradient; 0028 0029 //! This class implements the Broyden-Fletcher-Goldfarb-Shanno variant of 0030 //! Davidson-Fletcher-Powell minimization algorithm of a function of 0031 //! multiple variables.Knowledge of the function's gradient is required. 0032 //! 0033 //! It is possible to solve conditional optimization problem on hyperparallelepiped. 0034 //! Method SetBoundary is used to define hyperparallelepiped borders. With boundaries 0035 //! defined, the algorithm will not make evaluations of the function outside of the 0036 //! borders. 0037 class math_BFGS 0038 { 0039 public: 0040 DEFINE_STANDARD_ALLOC 0041 0042 //! Initializes the computation of the minimum of a function with 0043 //! NbVariables. 0044 //! Tolerance, ZEPS and NbIterations are described in the method Perform. 0045 //! Warning: 0046 //! A call to the Perform method must be made after this 0047 //! initialization to effectively compute the minimum of the 0048 //! function F. 0049 Standard_EXPORT math_BFGS(const int NbVariables, 0050 const double Tolerance = 1.0e-8, 0051 const int NbIterations = 200, 0052 const double ZEPS = 1.0e-12); 0053 0054 Standard_EXPORT virtual ~math_BFGS(); 0055 0056 //! Set boundaries for conditional optimization. 0057 //! The expected indices range of vectors is [1, NbVariables]. 0058 Standard_EXPORT void SetBoundary(const math_Vector& theLeftBorder, 0059 const math_Vector& theRightBorder); 0060 0061 //! Given the starting point StartingPoint, 0062 //! minimization is done on the function F. 0063 //! The solution F = Fi is found when : 0064 //! 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1) + ZEPS). 0065 //! Tolerance, ZEPS and maximum number of iterations are given 0066 //! in the constructor. 0067 Standard_EXPORT void Perform(math_MultipleVarFunctionWithGradient& F, 0068 const math_Vector& StartingPoint); 0069 0070 //! This method is called at the end of each iteration to check if the 0071 //! solution is found. 0072 //! It can be redefined in a sub-class to implement a specific test to 0073 //! stop the iterations. 0074 Standard_EXPORT virtual bool IsSolutionReached(math_MultipleVarFunctionWithGradient& F) const; 0075 0076 //! Returns true if the computations are successful, otherwise returns false. 0077 bool IsDone() const; 0078 0079 //! returns the location vector of the minimum. 0080 //! Exception NotDone is raised if the minimum was not found. 0081 const math_Vector& Location() const; 0082 0083 //! outputs the location vector of the minimum in Loc. 0084 //! Exception NotDone is raised if the minimum was not found. 0085 //! Exception DimensionError is raised if the range of Loc is not 0086 //! equal to the range of the StartingPoint. 0087 void Location(math_Vector& Loc) const; 0088 0089 //! returns the value of the minimum. 0090 //! Exception NotDone is raised if the minimum was not found. 0091 double Minimum() const; 0092 0093 //! Returns the gradient vector at the minimum. 0094 //! Exception NotDone is raised if the minimum was not found. 0095 const math_Vector& Gradient() const; 0096 0097 //! Returns the value of the gradient vector at the minimum in Grad. 0098 //! Exception NotDone is raised if the minimum was not found. 0099 //! Exception DimensionError is raised if the range of Grad is not 0100 //! equal to the range of the StartingPoint. 0101 void Gradient(math_Vector& Grad) const; 0102 0103 //! Returns the number of iterations really done in the 0104 //! calculation of the minimum. 0105 //! The exception NotDone is raised if the minimum was not found. 0106 int NbIterations() const; 0107 0108 //! Prints on the stream o information on the current state 0109 //! of the object. 0110 //! Is used to redefine the operator <<. 0111 Standard_EXPORT void Dump(Standard_OStream& o) const; 0112 0113 protected: 0114 math_Status TheStatus; 0115 math_Vector TheLocation; 0116 math_Vector TheGradient; 0117 double PreviousMinimum; 0118 double TheMinimum; 0119 double XTol; 0120 double EPSZ; 0121 int nbiter; 0122 bool myIsBoundsDefined; 0123 math_Vector myLeft; 0124 math_Vector myRight; 0125 0126 private: 0127 bool Done; 0128 int Itermax; 0129 }; 0130 0131 #include <math_BFGS.lxx> 0132 0133 #endif // _math_BFGS_HeaderFile
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|