0025719: Boolean operations can crash
authormsv <msv@opencascade.com>
Fri, 23 Jan 2015 15:07:15 +0000 (18:07 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 29 Jan 2015 10:13:59 +0000 (13:13 +0300)
Suppress math_BFGS constructor that calls the method Perform that in its turn calls the virtual method IsSolutionReached.

src/AppParCurves/AppParCurves_BSpGradient_BFGS.gxx
src/AppParCurves/AppParCurves_Gradient_BFGS.gxx
src/math/math_BFGS.cdl
src/math/math_BFGS.cxx
src/math/math_GlobOptMin.cxx

index a46c589..05bb3f2 100644 (file)
@@ -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) 
 {
index 291084b..e5c460e 100644 (file)
@@ -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) 
 {
index 0744b11..5c004cc 100644 (file)
@@ -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;
 
index f332722..65e5b3a 100644 (file)
@@ -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;
index 2ad9b16..30f2dbd 100644 (file)
@@ -232,7 +232,8 @@ Standard_Boolean math_GlobOptMin::computeLocalExtremum(const math_Vector& thePnt
   {
     math_MultipleVarFunctionWithGradient* myTmp = 
       dynamic_cast<math_MultipleVarFunctionWithGradient*> (myFunc);
-    math_BFGS bfgs(*myTmp, thePnt);
+    math_BFGS bfgs(myTmp->NbVariables());
+    bfgs.Perform(*myTmp, thePnt);
     if (bfgs.IsDone())
     {
       bfgs.Location(theOutPnt);