Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:04:14

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 
0030 
0031 //! This class implements the Broyden-Fletcher-Goldfarb-Shanno variant of
0032 //! Davidson-Fletcher-Powell minimization algorithm of a function of
0033 //! multiple variables.Knowledge of the function's gradient is required.
0034 //!
0035 //! It is possible to solve conditional optimization problem on hyperparallelepiped.
0036 //! Method SetBoundary is used to define hyperparallelepiped borders. With boundaries
0037 //! defined, the algorithm will not make evaluations of the function outside of the
0038 //! borders.
0039 class math_BFGS 
0040 {
0041 public:
0042 
0043   DEFINE_STANDARD_ALLOC
0044 
0045   
0046   //! Initializes the computation of the minimum of a function with
0047   //! NbVariables.
0048   //! Tolerance, ZEPS and NbIterations are described in the method Perform.
0049   //! Warning:
0050   //! A call to the Perform method must be made after this
0051   //! initialization to effectively compute the minimum of the
0052   //! function F.
0053   Standard_EXPORT math_BFGS(const Standard_Integer NbVariables, const Standard_Real Tolerance = 1.0e-8, const Standard_Integer NbIterations = 200, const Standard_Real ZEPS = 1.0e-12);
0054 
0055   Standard_EXPORT virtual ~math_BFGS();
0056 
0057   //! Set boundaries for conditional optimization.
0058   //! The expected indices range of vectors is [1, NbVariables].
0059   Standard_EXPORT void SetBoundary(const math_Vector& theLeftBorder, 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, const math_Vector& StartingPoint);
0068   
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 Standard_Boolean IsSolutionReached (math_MultipleVarFunctionWithGradient& F) const;
0075   
0076   //! Returns true if the computations are successful, otherwise returns false.
0077     Standard_Boolean 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     Standard_Real 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     Standard_Integer 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 
0114 
0115 
0116 protected:
0117 
0118 
0119 
0120   math_Status TheStatus;
0121   math_Vector TheLocation;
0122   math_Vector TheGradient;
0123   Standard_Real PreviousMinimum;
0124   Standard_Real TheMinimum;
0125   Standard_Real XTol;
0126   Standard_Real EPSZ;
0127   Standard_Integer nbiter;
0128   Standard_Boolean myIsBoundsDefined;
0129   math_Vector myLeft;
0130   math_Vector myRight;
0131 
0132 
0133 private:
0134 
0135 
0136 
0137   Standard_Boolean Done;
0138   Standard_Integer Itermax;
0139 
0140 
0141 };
0142 
0143 
0144 #include <math_BFGS.lxx>
0145 
0146 
0147 
0148 
0149 
0150 #endif // _math_BFGS_HeaderFile