From: RLN and KGV <> Date: Fri, 22 Jul 2011 07:59:36 +0000 (+0000) Subject: Rollback integration OCC22567 Speed up of math_FunctionSetRoot (used in Extrema) X-Git-Tag: V6_5_2~65 X-Git-Url: http://git.dev.opencascade.org/gitweb/?p=occt.git;a=commitdiff_plain;h=fbadd2ccceb89cf909f2e70740253814113b0bdf Rollback integration OCC22567 Speed up of math_FunctionSetRoot (used in Extrema) --- diff --git a/src/math/math_FunctionSetRoot.cxx b/src/math/math_FunctionSetRoot.cxx index bf67329973..6866e54aec 100755 --- a/src/math/math_FunctionSetRoot.cxx +++ b/src/math/math_FunctionSetRoot.cxx @@ -49,6 +49,8 @@ // On change de direction //============================================================================ +static Standard_Boolean mydebug = Standard_False; + class MyDirFunction : public math_Function { @@ -200,6 +202,7 @@ static Standard_Boolean MinimizeDirection(const math_Vector& P0, F.Initialize(P1, Delta); // (2) On minimise + if (mydebug)cout << " minimisation dans la direction" << endl; ax = -1; bx = 0; cx = (P2-P1).Norm()*invnorme; if (cx < 1.e-2) return Standard_False; @@ -240,6 +243,8 @@ static Standard_Boolean MinimizeDirection(const math_Vector& P, // (1) On realise une premiere interpolation quadratique Standard_Real ax, bx, cx, df1, df2, Delta, tsol, fsol, tsolbis; + if (mydebug) { cout << " essai d interpolation" << endl;} + df1 = Gradient*Dir; df2 = DGradient*Dir; @@ -259,7 +264,7 @@ static Standard_Boolean MinimizeDirection(const math_Vector& P, Delta = bx*bx - 4*ax*cx; if (Delta > 1.e-9) { // il y a des racines, on prend la plus proche de 0 - Delta = sqrt(Delta); + Delta = Sqrt(Delta); tsol = -(bx + Delta); tsolbis = (Delta - bx); if (Abs(tsolbis) < Abs(tsol)) tsol = tsolbis; @@ -280,6 +285,7 @@ static Standard_Boolean MinimizeDirection(const math_Vector& P, if (fsol Neq) { math_SVD Solut(DF); @@ -447,28 +457,22 @@ static void SearchDirection(const math_Matrix& DF, //==================================================== -Standard_Boolean Bounds(const math_Vector& InfBound, - const math_Vector& SupBound, - const math_Vector& Tol, - math_Vector& Sol, - const math_Vector& SolSave, - math_IntegerVector& Constraints, - math_Vector& Delta, - Standard_Boolean& theIsNewSol) +Standard_Boolean Bounds(const math_Vector& InfBound, + const math_Vector& SupBound, + const math_Vector& Tol, + math_Vector& Sol, + const math_Vector& SolSave, + math_IntegerVector& Constraints, + math_Vector& Delta) // -// Purpose: Trims an initial solution Sol to be within a domain defined by -// InfBound and SupBound. Delta will contain a distance between final Sol and -// SolSave. -// IsNewSol returns False, if final Sol fully coincides with SolSave, i.e. -// if SolSave already lied on a boundary and initial Sol was fully beyond it +// Purpose : Troncate un pas d'optimisation pour rester +// dans le domaine, Delta donne le pas final //====================================================== { Standard_Boolean Out = Standard_False; Standard_Integer i, Ninc = Sol.Length(); Standard_Real monratio = 1; - theIsNewSol = Standard_True; - // Calcul du ratio de recadrage for (i = 1; i <= Ninc; i++) { Constraints(i) = 0; @@ -480,36 +484,28 @@ Standard_Boolean Bounds(const math_Vector& InfBound, else if(Sol(i) < InfBound(i)) { Constraints(i) = 1; Out = Standard_True; - // Delta(i) is negative - if (-Delta(i) > Tol(i)) // Afin d'eviter des ratio nulles pour rien - monratio = Min(monratio, (InfBound(i) - SolSave(i))/Delta(i) ); + if (Abs(Delta(i)) > Tol(i)) // Afin d'eviter des ratio nulles pour rien + monratio = Min(monratio, Abs( (SolSave(i)-InfBound(i))/Delta(i)) ); } else if (Sol(i) > SupBound(i)) { Constraints(i) = 1; Out = Standard_True; - // Delta(i) is positive - if (Delta(i) > Tol(i)) - monratio = Min(monratio, (SupBound(i) - SolSave(i))/Delta(i) ); + if (Abs(Delta(i)) > Tol(i)) + monratio = Min(monratio, Abs( (SolSave(i)-SupBound(i))/Delta(i)) ); } } if (Out){ // Troncature et derniers recadrage pour blinder (pb numeriques) - if (monratio == 0.0) { - theIsNewSol = Standard_False; - Sol = SolSave; - Delta.Init (0.0); - } else { - Delta *= monratio; - Sol = SolSave+Delta; - for (i = 1; i <= Ninc; i++) { - if(Sol(i) < InfBound(i)) { - Sol(i) = InfBound(i); - Delta(i) = Sol(i) - SolSave(i); - } - else if (Sol(i) > SupBound(i)) { - Sol(i) = SupBound(i); - Delta(i) = Sol(i) - SolSave(i); - } + Delta *= monratio; + Sol = SolSave+Delta; + for (i = 1; i <= Ninc; i++) { + if(Sol(i) < InfBound(i)) { + Sol(i) = InfBound(i); + Delta(i) = Sol(i) - SolSave(i); + } + else if (Sol(i) > SupBound(i)) { + Sol(i) = SupBound(i); + Delta(i) = Sol(i) - SolSave(i); } } } @@ -680,10 +676,10 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F, (SupBound.Length() != Ninc)) { Standard_DimensionError:: Raise(); } Standard_Integer i; - Standard_Boolean ChangeDirection = Standard_False, Sort = Standard_False, isNewSol = Standard_False; + Standard_Boolean ChangeDirection = Standard_False, Sort = Standard_False; Standard_Boolean Good, Verif; Standard_Boolean Stop; - const Standard_Real EpsSqrt = 1.e-16, Eps = 1.e-32, Eps2 = 1.e-64, Progres = 0.005; + Standard_Real Eps = 1.e-32, Progres = 0.005; Standard_Real F2, PreviousMinimum, Dy, OldF; Standard_Real Ambda, Ambda2, Gnr1, Oldgr; math_Vector InvLengthMax(1, Ninc); // Pour bloquer les pas a 1/4 du domaine @@ -718,9 +714,14 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F, // Le rang 0 de Save ne doit servir q'au test accelarteur en fin de boucle // s'il on est dejas sur la solution, il faut leurer ce test pour eviter // de faire une seconde iteration... - Save(0) = Max (F2, EpsSqrt); + Save(0) = Max (F2, Sqrt(Eps)); + + if (mydebug) { + cout << "=== Mode Debug de Function Set Root"<