diff --git a/src/AppParCurves/AppParCurves_BSpGradient_BFGS.gxx b/src/AppParCurves/AppParCurves_BSpGradient_BFGS.gxx index a46c589df1..05bb3f24a3 100644 --- a/src/AppParCurves/AppParCurves_BSpGradient_BFGS.gxx +++ b/src/AppParCurves/AppParCurves_BSpGradient_BFGS.gxx @@ -23,7 +23,7 @@ AppParCurves_BSpGradient_BFGS::AppParCurves_BSpGradient_BFGS(math_MultipleVarFun const Standard_Real Tolerance2d, const Standard_Real Eps, const Standard_Integer NbIterations): - math_BFGS(F, Eps, NbIterations, Eps), + math_BFGS(F.NbVariables(), Eps, NbIterations, Eps), myTol3d(Tolerance3d), myTol2d(Tolerance2d) { diff --git a/src/AppParCurves/AppParCurves_Gradient_BFGS.gxx b/src/AppParCurves/AppParCurves_Gradient_BFGS.gxx index 291084bc00..e5c460e174 100644 --- a/src/AppParCurves/AppParCurves_Gradient_BFGS.gxx +++ b/src/AppParCurves/AppParCurves_Gradient_BFGS.gxx @@ -24,7 +24,7 @@ AppParCurves_Gradient_BFGS::AppParCurves_Gradient_BFGS(math_MultipleVarFunctionW const Standard_Real Tolerance2d, const Standard_Real Eps, const Standard_Integer NbIterations ): - math_BFGS(F, Eps, NbIterations, Eps), + math_BFGS(F.NbVariables(), Eps, NbIterations, Eps), myTol3d(Tolerance3d), myTol2d(Tolerance2d) { diff --git a/src/math/math_BFGS.cdl b/src/math/math_BFGS.cdl index 0744b11097..5c004ccffe 100644 --- a/src/math/math_BFGS.cdl +++ b/src/math/math_BFGS.cdl @@ -29,31 +29,18 @@ raises NotDone from StdFail, DimensionError from Standard is - - - Create(F: in out MultipleVarFunctionWithGradient; - StartingPoint: Vector; Tolerance: Real=1.0e-8; - NbIterations: Integer=200; ZEPS: Real=1.0e-12) - ---Purpose: - -- Given the starting point StartingPoint, - -- the Broyden-Fletcher-Goldfarb-Shanno variant of Davidson-Fletcher-Powell - -- minimization is done on the function F. - -- The tolerance required on F is given by Tolerance. - -- The solution F = Fi is found when : - -- 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1) + ZEPS). - -- The maximum number of iterations allowed is given by NbIterations. - returns BFGS; - - Create(F: in out MultipleVarFunctionWithGradient; - Tolerance: Real = 1.0e-8; - NbIterations: Integer = 200; - ZEPS: Real = 1.0e-12) - ---Purpose: Initializes the computation of the minimum of F. - -- Warning - -- A call to the Perform method must be made after this - -- initialization to effectively compute the minimum of the - -- function F. + Create(NbVariables: Integer; + Tolerance: Real = 1.0e-8; + NbIterations: Integer = 200; + ZEPS: Real = 1.0e-12) + ---Purpose: Initializes the computation of the minimum of a function with + -- NbVariables. + -- Tolerance, ZEPS and NbIterations are described in the method Perform. + -- Warning: + -- A call to the Perform method must be made after this + -- initialization to effectively compute the minimum of the + -- function F. returns BFGS; @@ -61,8 +48,13 @@ is ---C++: alias "Standard_EXPORT virtual ~math_BFGS(){Delete() ; }" Perform(me: in out; F: in out MultipleVarFunctionWithGradient; - StartingPoint: Vector) - ---Purpose: Is used internally by the constructors. + StartingPoint: Vector) + ---Purpose: Given the starting point StartingPoint, + -- minimization is done on the function F. + -- The solution F = Fi is found when : + -- 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1) + ZEPS). + -- Tolerance, ZEPS and maximum number of iterations are given + -- in the constructor. is static; diff --git a/src/math/math_BFGS.cxx b/src/math/math_BFGS.cxx index f33272297a..65e5b3a748 100644 --- a/src/math/math_BFGS.cxx +++ b/src/math/math_BFGS.cxx @@ -267,27 +267,13 @@ void math_BFGS::Perform(math_MultipleVarFunctionWithGradient& F, return 2.0 * fabs(TheMinimum - PreviousMinimum) <= XTol * (fabs(TheMinimum) + fabs(PreviousMinimum) + EPSZ); } - - math_BFGS::math_BFGS(math_MultipleVarFunctionWithGradient& F, - const math_Vector& StartingPoint, - const Standard_Real Tolerance, - const Standard_Integer NbIterations, - const Standard_Real ZEPS) - : TheLocation(1, StartingPoint.Length()), - TheGradient(1, StartingPoint.Length()) { - - XTol = Tolerance; - EPSZ = ZEPS; - Itermax = NbIterations; - Perform(F, StartingPoint); - } - math_BFGS::math_BFGS(math_MultipleVarFunctionWithGradient& F, + math_BFGS::math_BFGS(const Standard_Integer NbVariables, const Standard_Real Tolerance, const Standard_Integer NbIterations, const Standard_Real ZEPS) - : TheLocation(1, F.NbVariables()), - TheGradient(1, F.NbVariables()) { + : TheLocation(1, NbVariables), + TheGradient(1, NbVariables) { XTol = Tolerance; EPSZ = ZEPS; diff --git a/src/math/math_GlobOptMin.cxx b/src/math/math_GlobOptMin.cxx index 2ad9b165e6..30f2dbd6b5 100644 --- a/src/math/math_GlobOptMin.cxx +++ b/src/math/math_GlobOptMin.cxx @@ -232,7 +232,8 @@ Standard_Boolean math_GlobOptMin::computeLocalExtremum(const math_Vector& thePnt { math_MultipleVarFunctionWithGradient* myTmp = dynamic_cast (myFunc); - math_BFGS bfgs(*myTmp, thePnt); + math_BFGS bfgs(myTmp->NbVariables()); + bfgs.Perform(*myTmp, thePnt); if (bfgs.IsDone()) { bfgs.Location(theOutPnt);