Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-09-30 09: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_Powell_HeaderFile
0018 #define _math_Powell_HeaderFile
0019 
0020 #include <Standard.hxx>
0021 #include <Standard_DefineAlloc.hxx>
0022 
0023 #include <math_Vector.hxx>
0024 #include <Standard_Integer.hxx>
0025 #include <math_Status.hxx>
0026 #include <math_Matrix.hxx>
0027 #include <Standard_OStream.hxx>
0028 class math_MultipleVarFunction;
0029 
0030 //! This class implements the Powell method to find the minimum of
0031 //! function of multiple variables (the gradient does not have to be known).
0032 class math_Powell
0033 {
0034 public:
0035   DEFINE_STANDARD_ALLOC
0036 
0037   //! Constructor. Initialize new entity.
0038   Standard_EXPORT math_Powell(const math_MultipleVarFunction& theFunction,
0039                               const double                    theTolerance,
0040                               const int                       theNbIterations = 200,
0041                               const double                    theZEPS         = 1.0e-12);
0042 
0043   //! Destructor
0044   Standard_EXPORT virtual ~math_Powell();
0045 
0046   //! Computes Powell minimization on the function F given
0047   //! theStartingPoint, and an initial matrix theStartingDirection
0048   //! whose columns contain the initial set of directions.
0049   //! The solution F = Fi is found when:
0050   //! 2.0 * abs(Fi - Fi-1) =< Tolerance * (abs(Fi) + abs(Fi-1) + ZEPS).
0051   Standard_EXPORT void Perform(math_MultipleVarFunction& theFunction,
0052                                const math_Vector&        theStartingPoint,
0053                                const math_Matrix&        theStartingDirections);
0054 
0055   //! Solution F = Fi is found when:
0056   //! 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1)) + ZEPS.
0057   //! The maximum number of iterations allowed is given by NbIterations.
0058   virtual bool IsSolutionReached(math_MultipleVarFunction& theFunction);
0059 
0060   //! Returns true if the computations are successful, otherwise returns false.
0061   bool IsDone() const;
0062 
0063   //! returns the location vector of the minimum.
0064   //! Exception NotDone is raised if the minimum was not found.
0065   const math_Vector& Location() const;
0066 
0067   //! outputs the location vector of the minimum in Loc.
0068   //! Exception NotDone is raised if the minimum was not found.
0069   //! Exception DimensionError is raised if the range of Loc is not
0070   //! equal to the range of the StartingPoint.
0071   void Location(math_Vector& Loc) const;
0072 
0073   //! Returns the value of the minimum.
0074   //! Exception NotDone is raised if the minimum was not found.
0075   double Minimum() const;
0076 
0077   //! Returns the number of iterations really done during the
0078   //! computation of the minimum.
0079   //! Exception NotDone is raised if the minimum was not found.
0080   int NbIterations() const;
0081 
0082   //! Prints information on the current state of the object.
0083   //! Is used to redefine the operator <<.
0084   Standard_EXPORT void Dump(Standard_OStream& o) const;
0085 
0086 protected:
0087   math_Vector TheLocation;
0088   double      TheMinimum;
0089   double      TheLocationError;
0090   double      PreviousMinimum;
0091   double      XTol;
0092   double      EPSZ;
0093 
0094 private:
0095   bool        Done;
0096   int         Iter;
0097   math_Status TheStatus;
0098   math_Matrix TheDirections;
0099   int         State;
0100   int         Itermax;
0101 };
0102 
0103 #include <math_Powell.lxx>
0104 
0105 #endif // _math_Powell_HeaderFile