1 // Created on: 1996-02-28
2 // Created by: Philippe MANGIN
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #ifndef _math_NewtonMinimum_HeaderFile
18 #define _math_NewtonMinimum_HeaderFile
20 #include <Standard.hxx>
21 #include <Standard_DefineAlloc.hxx>
22 #include <Standard_Handle.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <math_Status.hxx>
26 #include <math_Vector.hxx>
27 #include <math_Matrix.hxx>
28 #include <Standard_Real.hxx>
29 #include <Standard_Integer.hxx>
30 #include <Standard_OStream.hxx>
31 class StdFail_NotDone;
32 class Standard_DimensionError;
33 class math_MultipleVarFunctionWithHessian;
37 class math_NewtonMinimum
45 //! The tolerance required on the solution is given by Tolerance.
46 //! Iteration are stopped if (!WithSingularity) and H(F(Xi)) is not definite
47 //! positive (if the smaller eigenvalue of H < Convexity)
48 //! or IsConverged() returns True for 2 successives Iterations.
49 //! Warning: This constructor does not perform computation.
50 Standard_EXPORT math_NewtonMinimum(const math_MultipleVarFunctionWithHessian& theFunction, const Standard_Real theTolerance = 1.0e-7, const Standard_Integer theNbIterations = 40, const Standard_Real theConvexity = 1.0e-6, const Standard_Boolean theWithSingularity = Standard_True);
52 //! Search the solution.
53 Standard_EXPORT void Perform (math_MultipleVarFunctionWithHessian& theFunction, const math_Vector& theStartingPoint);
56 Standard_EXPORT virtual ~math_NewtonMinimum();
59 //! This method is called at the end of each iteration to check the convergence:
60 //! || Xi+1 - Xi || < Tolerance or || F(Xi+1) - F(Xi)|| < Tolerance * || F(Xi) ||
61 //! It can be redefined in a sub-class to implement a specific test.
62 virtual Standard_Boolean IsConverged() const;
64 //! Tests if an error has occured.
65 Standard_Boolean IsDone() const;
67 //! Tests if the Function is convexe during optimization.
68 Standard_Boolean IsConvex() const;
70 //! returns the location vector of the minimum.
71 //! Exception NotDone is raised if an error has occured.
72 const math_Vector& Location() const;
74 //! outputs the location vector of the minimum in Loc.
75 //! Exception NotDone is raised if an error has occured.
76 //! Exception DimensionError is raised if the range of Loc is not
77 //! equal to the range of the StartingPoint.
78 void Location (math_Vector& Loc) const;
81 Standard_EXPORT void SetBoundary (const math_Vector& theLeftBorder, const math_Vector& theRightBorder);
83 //! returns the value of the minimum.
84 //! Exception NotDone is raised if the minimum was not found.
85 Standard_Real Minimum() const;
87 //! returns the gradient vector at the minimum.
88 //! Exception NotDone is raised if an error has occured.the minimum was not found.
89 const math_Vector& Gradient() const;
91 //! outputs the gradient vector at the minimum in Grad.
92 //! Exception NotDone is raised if the minimum was not found.
93 //! Exception DimensionError is raised if the range of Grad is not
94 //! equal to the range of the StartingPoint.
95 void Gradient (math_Vector& Grad) const;
97 //! returns the number of iterations really done in the
98 //! calculation of the minimum.
99 //! The exception NotDone is raised if an error has occured.
100 Standard_Integer NbIterations() const;
102 //! Returns the Status of computation.
103 //! The exception NotDone is raised if an error has occured.
104 math_Status GetStatus() const;
107 //! Prints on the stream o information on the current state
109 //! Is used to redefine the operator <<.
110 Standard_EXPORT void Dump (Standard_OStream& o) const;
119 math_Status TheStatus;
120 math_Vector TheLocation;
121 math_Vector TheGradient;
123 math_Matrix TheHessian;
124 Standard_Real PreviousMinimum;
125 Standard_Real TheMinimum;
126 Standard_Real MinEigenValue;
129 Standard_Integer nbiter;
130 Standard_Boolean NoConvexTreatement;
131 Standard_Boolean Convex;
132 Standard_Boolean myIsBoundsDefined;
141 Standard_Boolean Done;
142 Standard_Integer Itermax;
148 #include <math_NewtonMinimum.lxx>
154 #endif // _math_NewtonMinimum_HeaderFile