mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-08-04 13:13:25 +03:00
0025720: Incorrect code of math classes can lead to unpredicted behavior of algorithms
The calling of virtual methods has been removed from constructors & destructors: math_BissecNewton math_BrentMinimum math_FRPR math_FunctionSetRoot math_NewtonFunctionSetRoot math_NewtonMinimum math_Powell
This commit is contained in:
@@ -647,17 +647,23 @@ gp_Pnt2d Bisector_BisecCC::ValueAndDist (const Standard_Real U,
|
|||||||
if (Abs(FInit) < EpsH) {
|
if (Abs(FInit) < EpsH) {
|
||||||
U2 = VInit;
|
U2 = VInit;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
math_BissecNewton SolNew (H,VMin - EpsH100,VMax + EpsH100,EpsH,10);
|
{
|
||||||
if (SolNew.IsDone()) {
|
math_BissecNewton aNewSolution(EpsH);
|
||||||
U2 = SolNew.Root();
|
aNewSolution.Perform(H, VMin - EpsH100, VMax + EpsH100, 10);
|
||||||
|
|
||||||
|
if (aNewSolution.IsDone())
|
||||||
|
{
|
||||||
|
U2 = aNewSolution.Root();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
math_FunctionRoot SolRoot (H,VInit,EpsH,VMin - EpsH100,VMax + EpsH100);
|
math_FunctionRoot SolRoot (H,VInit,EpsH,VMin - EpsH100,VMax + EpsH100);
|
||||||
if (SolRoot.IsDone()) {
|
|
||||||
|
if (SolRoot.IsDone())
|
||||||
U2 = SolRoot.Root();
|
U2 = SolRoot.Root();
|
||||||
}
|
else
|
||||||
else { Valid = Standard_False;}
|
Valid = Standard_False;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -346,12 +346,14 @@ void Bisector_Inter::NeighbourPerform(const Handle(Bisector_BisecCC)& Bis1,
|
|||||||
if (UMin - Eps > UMax + Eps) {return;}
|
if (UMin - Eps > UMax + Eps) {return;}
|
||||||
|
|
||||||
// Solution F = 0 to find the common point.
|
// Solution F = 0 to find the common point.
|
||||||
Bisector_FunctionInter Fint (Guide,Bis1,BisTemp);
|
Bisector_FunctionInter Fint(Guide,Bis1,BisTemp);
|
||||||
math_BissecNewton Sol (Fint,UMin,UMax,Tol,20);
|
|
||||||
if (Sol.IsDone()) {
|
math_BissecNewton aSolution(Tol);
|
||||||
USol = Sol.Root();
|
aSolution.Perform(Fint, UMin, UMax, 20);
|
||||||
}
|
|
||||||
else { return; }
|
if (aSolution.IsDone())
|
||||||
|
USol = aSolution.Root();
|
||||||
|
else return;
|
||||||
|
|
||||||
PSol = BisTemp ->ValueAndDist(USol,U1,U2,Dist);
|
PSol = BisTemp ->ValueAndDist(USol,U1,U2,Dist);
|
||||||
|
|
||||||
|
@@ -338,7 +338,8 @@ void Extrema_ExtPExtS::Perform (const gp_Pnt& P)
|
|||||||
Pe = ProjectPnt (anOrtogSection, myDirection, E),
|
Pe = ProjectPnt (anOrtogSection, myDirection, E),
|
||||||
V = gp_Vec(E,Pe) * gp_Vec(myDirection);
|
V = gp_Vec(E,Pe) * gp_Vec(myDirection);
|
||||||
UV(1) = U; UV(2) = V;
|
UV(1) = U; UV(2) = V;
|
||||||
math_FunctionSetRoot aFSR (myF,UV,Tol,UVinf,UVsup);
|
math_FunctionSetRoot aFSR (myF, Tol);
|
||||||
|
aFSR.Perform(myF, UV, UVinf, UVsup);
|
||||||
// for (Standard_Integer k=1 ; k <= myF.NbExt();
|
// for (Standard_Integer k=1 ; k <= myF.NbExt();
|
||||||
Standard_Integer k;
|
Standard_Integer k;
|
||||||
for ( k=1 ; k <= myF.NbExt(); k++) {
|
for ( k=1 ; k <= myF.NbExt(); k++) {
|
||||||
|
@@ -289,7 +289,8 @@ void Extrema_GenExtCS::Perform (const Adaptor3d_Curve& C,
|
|||||||
math_PSO aPSO(&aFunc, TUVinf, TUVsup, aStep);
|
math_PSO aPSO(&aFunc, TUVinf, TUVsup, aStep);
|
||||||
aPSO.Perform(aParticles, aNbParticles, aValue, TUV);
|
aPSO.Perform(aParticles, aNbParticles, aValue, TUV);
|
||||||
|
|
||||||
math_FunctionSetRoot anA (myF, TUV, Tol, TUVinf, TUVsup, 100, Standard_False);
|
math_FunctionSetRoot anA(myF, Tol);
|
||||||
|
anA.Perform(myF, TUV, TUVinf, TUVsup);
|
||||||
|
|
||||||
myDone = Standard_True;
|
myDone = Standard_True;
|
||||||
}
|
}
|
||||||
|
@@ -778,8 +778,8 @@ void Extrema_GenExtPS::FindSolution(const gp_Pnt& /*P*/,
|
|||||||
UVsup(1) = myusup;
|
UVsup(1) = myusup;
|
||||||
UVsup(2) = myvsup;
|
UVsup(2) = myvsup;
|
||||||
|
|
||||||
const Standard_Integer aNbMaxIter = 100;
|
math_FunctionSetRoot S(myF, Tol);
|
||||||
math_FunctionSetRoot S (myF, UV, Tol, UVinf, UVsup, aNbMaxIter);
|
S.Perform(myF, UV, UVinf, UVsup);
|
||||||
|
|
||||||
myDone = Standard_True;
|
myDone = Standard_True;
|
||||||
}
|
}
|
||||||
|
@@ -266,14 +266,16 @@ b- Calcul des minima:
|
|||||||
UV(3) = U20 + (N2Umin - 1) * PasU2;
|
UV(3) = U20 + (N2Umin - 1) * PasU2;
|
||||||
UV(4) = V20 + (N2Vmin - 1) * PasV2;
|
UV(4) = V20 + (N2Vmin - 1) * PasV2;
|
||||||
|
|
||||||
math_FunctionSetRoot SR1 (myF,UV,Tol,UVinf,UVsup);
|
math_FunctionSetRoot SR1(myF, Tol);
|
||||||
|
SR1.Perform(myF, UV, UVinf, UVsup);
|
||||||
|
|
||||||
UV(1) = U10 + (N1Umax - 1) * PasU1;
|
UV(1) = U10 + (N1Umax - 1) * PasU1;
|
||||||
UV(2) = V10 + (N1Vmax - 1) * PasV1;
|
UV(2) = V10 + (N1Vmax - 1) * PasV1;
|
||||||
UV(3) = U20 + (N2Umax - 1) * PasU2;
|
UV(3) = U20 + (N2Umax - 1) * PasU2;
|
||||||
UV(4) = V20 + (N2Vmax - 1) * PasV2;
|
UV(4) = V20 + (N2Vmax - 1) * PasV2;
|
||||||
|
|
||||||
math_FunctionSetRoot SR2 (myF,UV,Tol,UVinf,UVsup);
|
math_FunctionSetRoot SR2(myF, Tol);
|
||||||
|
SR2.Perform(myF, UV, UVinf, UVsup);
|
||||||
|
|
||||||
myDone = Standard_True;
|
myDone = Standard_True;
|
||||||
}
|
}
|
||||||
|
@@ -82,7 +82,9 @@ Methode:
|
|||||||
Uusup(1)=Usup;
|
Uusup(1)=Usup;
|
||||||
Uusup(2)=Vsup;
|
Uusup(2)=Vsup;
|
||||||
|
|
||||||
math_FunctionSetRoot S (F,Start,Tol,Uuinf,Uusup);
|
math_FunctionSetRoot S(F, Tol);
|
||||||
|
S.Perform(F, Start, Uuinf, Uusup);
|
||||||
|
|
||||||
if (S.IsDone() && F.NbExt() > 0) {
|
if (S.IsDone() && F.NbExt() > 0) {
|
||||||
mySqDist = F.SquareDistance(1);
|
mySqDist = F.SquareDistance(1);
|
||||||
F.Points(1,myPoint1,myPoint2);
|
F.Points(1,myPoint1,myPoint2);
|
||||||
|
@@ -89,7 +89,8 @@ void Extrema_GenLocateExtCS::Perform(const Adaptor3d_Curve& C,
|
|||||||
BSup(2) = Usup;
|
BSup(2) = Usup;
|
||||||
BSup(3) = Vsup;
|
BSup(3) = Vsup;
|
||||||
|
|
||||||
math_FunctionSetRoot SR (F, Start,Tol, BInf, BSup);
|
math_FunctionSetRoot SR (F, Tol);
|
||||||
|
SR.Perform(F, Start, BInf, BSup);
|
||||||
if (!SR.IsDone())
|
if (!SR.IsDone())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@@ -75,7 +75,8 @@ Method:
|
|||||||
BSup(1) = Usup;
|
BSup(1) = Usup;
|
||||||
BSup(2) = Vsup;
|
BSup(2) = Vsup;
|
||||||
|
|
||||||
math_FunctionSetRoot SR (F, Start,Tol, BInf, BSup);
|
math_FunctionSetRoot SR (F, Tol);
|
||||||
|
SR.Perform(F, Start, BInf, BSup);
|
||||||
if (!SR.IsDone())
|
if (!SR.IsDone())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@@ -97,7 +97,8 @@ void Extrema_GenLocateExtSS::Perform(const Adaptor3d_Surface& S1,
|
|||||||
BSup(3) = Usup2;
|
BSup(3) = Usup2;
|
||||||
BSup(4) = Vsup2;
|
BSup(4) = Vsup2;
|
||||||
|
|
||||||
math_FunctionSetRoot SR (F, Start,Tol, BInf, BSup);
|
math_FunctionSetRoot SR (F, Tol);
|
||||||
|
SR.Perform(F, Start, BInf, BSup);
|
||||||
if (!SR.IsDone())
|
if (!SR.IsDone())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@@ -23,50 +23,30 @@ uses
|
|||||||
MultipleVarFunctionWithHessian from math
|
MultipleVarFunctionWithHessian from math
|
||||||
|
|
||||||
is
|
is
|
||||||
Create(F: in out MultipleVarFunctionWithHessian;
|
Create(theFunction: in MultipleVarFunctionWithHessian;
|
||||||
StartingPoint: Vector;
|
theSpatialTolerance: Real = 1.0e-7;
|
||||||
SpatialTolerance : Real = 1.0e-7;
|
theCriteriumTolerance: Real=1.0e-7;
|
||||||
CriteriumTolerance: Real = 1.0e-2;
|
theNbIterations: Integer=40;
|
||||||
NbIterations: Integer=40;
|
theConvexity: Real=1.0e-6;
|
||||||
Convexity: Real=1.0e-6;
|
theWithSingularity: Boolean = Standard_True)
|
||||||
WithSingularity : Boolean = Standard_True)
|
|
||||||
---Purpose: -- Given the starting point StartingPoint,
|
|
||||||
-- The tolerance required on the solution is given by
|
|
||||||
-- Tolerance.
|
|
||||||
-- Iteration are stopped if
|
|
||||||
-- (!WithSingularity) and H(F(Xi)) is not definite
|
|
||||||
-- positive (if the smaller eigenvalue of H < Convexity)
|
|
||||||
-- or IsConverged() returns True for 2 successives Iterations.
|
|
||||||
-- Warning: Obsolete Constructor (because IsConverged can not be redefined
|
|
||||||
-- with this. )
|
|
||||||
returns Newton;
|
|
||||||
|
|
||||||
Create(F: in out MultipleVarFunctionWithHessian;
|
|
||||||
SpatialTolerance : Real = 1.0e-7;
|
|
||||||
Tolerance: Real=1.0e-7;
|
|
||||||
NbIterations: Integer=40;
|
|
||||||
Convexity: Real=1.0e-6;
|
|
||||||
WithSingularity : Boolean = Standard_True)
|
|
||||||
---Purpose:
|
---Purpose:
|
||||||
-- The tolerance required on the solution is given by
|
-- The tolerance required on the solution is given by Tolerance.
|
||||||
-- Tolerance.
|
-- Iteration are stopped if (!WithSingularity) and H(F(Xi)) is not definite
|
||||||
-- Iteration are stopped if
|
-- positive (if the smaller eigenvalue of H < Convexity)
|
||||||
-- (!WithSingularity) and H(F(Xi)) is not definite
|
-- or IsConverged() returns True for 2 successives Iterations.
|
||||||
-- positive (if the smaller eigenvalue of H < Convexity)
|
-- Warning: This constructor do not computation
|
||||||
-- or IsConverged() returns True for 2 successives Iterations.
|
|
||||||
-- Warning: This constructor do not computation
|
|
||||||
returns Newton;
|
returns Newton;
|
||||||
|
|
||||||
IsConverged(me)
|
IsConverged(me)
|
||||||
---Purpose: This method is called at the end of each
|
---Purpose:
|
||||||
-- iteration to check the convergence :
|
-- This method is called at the end of each
|
||||||
-- || Xi+1 - Xi || < SpatialTolerance/100 Or
|
-- iteration to check the convergence :
|
||||||
-- || Xi+1 - Xi || < SpatialTolerance and
|
-- || Xi+1 - Xi || < SpatialTolerance/100 Or
|
||||||
-- |F(Xi+1) - F(Xi)| < CriteriumTolerance * |F(xi)|
|
-- || Xi+1 - Xi || < SpatialTolerance and
|
||||||
-- It can be redefined in a sub-class to implement a specific test.
|
-- |F(Xi+1) - F(Xi)| < CriteriumTolerance * |F(xi)|
|
||||||
|
-- It can be redefined in a sub-class to implement a specific test.
|
||||||
returns Boolean
|
|
||||||
is redefined;
|
returns Boolean is redefined;
|
||||||
|
|
||||||
fields
|
fields
|
||||||
mySpTol : Real;
|
mySpTol : Real;
|
||||||
|
@@ -16,44 +16,37 @@
|
|||||||
|
|
||||||
#include <FairCurve_Newton.ixx>
|
#include <FairCurve_Newton.ixx>
|
||||||
|
|
||||||
FairCurve_Newton::FairCurve_Newton(math_MultipleVarFunctionWithHessian& F,
|
//=======================================================================
|
||||||
const math_Vector& StartingPoint,
|
//function : FairCurve_Newton
|
||||||
const Standard_Real SpatialTolerance,
|
//purpose : Constructor
|
||||||
const Standard_Real CriteriumTolerance,
|
//=======================================================================
|
||||||
const Standard_Integer NbIterations,
|
FairCurve_Newton::FairCurve_Newton(
|
||||||
const Standard_Real Convexity,
|
const math_MultipleVarFunctionWithHessian& theFunction,
|
||||||
const Standard_Boolean WithSingularity)
|
const Standard_Real theSpatialTolerance,
|
||||||
:math_NewtonMinimum(F, StartingPoint, CriteriumTolerance,
|
const Standard_Real theCriteriumTolerance,
|
||||||
NbIterations, Convexity, WithSingularity),
|
const Standard_Integer theNbIterations,
|
||||||
mySpTol(SpatialTolerance)
|
const Standard_Real theConvexity,
|
||||||
|
const Standard_Boolean theWithSingularity
|
||||||
|
)
|
||||||
|
: math_NewtonMinimum(theFunction,
|
||||||
|
theCriteriumTolerance,
|
||||||
|
theNbIterations,
|
||||||
|
theConvexity,
|
||||||
|
theWithSingularity),
|
||||||
|
mySpTol(theSpatialTolerance)
|
||||||
{
|
{
|
||||||
// Attention this writing is wrong as FairCurve_Newton::IsConverged() is not
|
|
||||||
// used in the constructor of NewtonMinimum !!
|
|
||||||
}
|
|
||||||
|
|
||||||
FairCurve_Newton::FairCurve_Newton(math_MultipleVarFunctionWithHessian& F,
|
|
||||||
const Standard_Real SpatialTolerance,
|
|
||||||
const Standard_Real CriteriumTolerance,
|
|
||||||
const Standard_Integer NbIterations,
|
|
||||||
const Standard_Real Convexity,
|
|
||||||
const Standard_Boolean WithSingularity)
|
|
||||||
:math_NewtonMinimum(F, CriteriumTolerance,
|
|
||||||
NbIterations, Convexity, WithSingularity),
|
|
||||||
mySpTol(SpatialTolerance)
|
|
||||||
|
|
||||||
{
|
|
||||||
// It is much better
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : IsConverged
|
||||||
|
//purpose : Convert if the steps are too small or if the criterion
|
||||||
|
// progresses little with a reasonable step, this last
|
||||||
|
// requirement allows detecting infinite slidings
|
||||||
|
// (case when the criterion varies troo slowly).
|
||||||
|
//=======================================================================
|
||||||
Standard_Boolean FairCurve_Newton::IsConverged() const
|
Standard_Boolean FairCurve_Newton::IsConverged() const
|
||||||
// Convert if the steps are too small
|
|
||||||
// or if the criterion progresses little with a reasonable step, this last requirement
|
|
||||||
// allows detecting infinite slidings,
|
|
||||||
// (case when the criterion varies troo slowly).
|
|
||||||
{
|
{
|
||||||
Standard_Real N = TheStep.Norm();
|
const Standard_Real N = TheStep.Norm();
|
||||||
return ( (N <= mySpTol/100 ) ||
|
return ( N <= 0.01 * mySpTol ) || ( N <= mySpTol &&
|
||||||
( Abs(TheMinimum-PreviousMinimum) <= XTol*Abs(PreviousMinimum)
|
Abs(TheMinimum - PreviousMinimum) <= XTol * Abs(PreviousMinimum));
|
||||||
&& N<=mySpTol) );
|
|
||||||
}
|
}
|
||||||
|
@@ -91,7 +91,8 @@ Geom2dGcc_Circ2d2TanOnIter (const GccEnt_QualifiedLin& Qualified1 ,
|
|||||||
gp_Pnt2d point3 = ElCLib::Value(Param3,OnLine);
|
gp_Pnt2d point3 = ElCLib::Value(Param3,OnLine);
|
||||||
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
||||||
Geom2dGcc_FunctionTanCuCuOnCu Func(L1,Cu2,OnLine,Ufirst(4));
|
Geom2dGcc_FunctionTanCuCuOnCu Func(L1,Cu2,OnLine,Ufirst(4));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
@@ -192,7 +193,8 @@ Geom2dGcc_Circ2d2TanOnIter (const Geom2dGcc_QCurve& Qualified1 ,
|
|||||||
gp_Pnt2d point3 = ElCLib::Value(Param3,OnLine);
|
gp_Pnt2d point3 = ElCLib::Value(Param3,OnLine);
|
||||||
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
||||||
Geom2dGcc_FunctionTanCuCuOnCu Func(Cu1,Cu2,OnLine,Ufirst(4));
|
Geom2dGcc_FunctionTanCuCuOnCu Func(Cu1,Cu2,OnLine,Ufirst(4));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
@@ -288,7 +290,8 @@ Geom2dGcc_Circ2d2TanOnIter (const Geom2dGcc_QCurve& Qualified1 ,
|
|||||||
gp_Pnt2d point3 = ElCLib::Value(Param2,OnLine);
|
gp_Pnt2d point3 = ElCLib::Value(Param2,OnLine);
|
||||||
Ufirst(3) = (point3.Distance(Point2)+point3.Distance(point1))/2.;
|
Ufirst(3) = (point3.Distance(Point2)+point3.Distance(point1))/2.;
|
||||||
Geom2dGcc_FunctionTanCuCuOnCu Func(Cu1,Point2,OnLine,Ufirst(3));
|
Geom2dGcc_FunctionTanCuCuOnCu Func(Cu1,Point2,OnLine,Ufirst(3));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
@@ -381,7 +384,8 @@ Geom2dGcc_Circ2d2TanOnIter (const GccEnt_QualifiedCirc& Qualified1 ,
|
|||||||
gp_Pnt2d point3 = ElCLib::Value(Param3,OnLine);
|
gp_Pnt2d point3 = ElCLib::Value(Param3,OnLine);
|
||||||
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
||||||
Geom2dGcc_FunctionTanCuCuOnCu Func(C1,Cu2,OnLine,Ufirst(4));
|
Geom2dGcc_FunctionTanCuCuOnCu Func(C1,Cu2,OnLine,Ufirst(4));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
@@ -488,7 +492,8 @@ Geom2dGcc_Circ2d2TanOnIter (const GccEnt_QualifiedCirc& Qualified1 ,
|
|||||||
gp_Pnt2d point3 = ElCLib::Value(Param3,OnCirc);
|
gp_Pnt2d point3 = ElCLib::Value(Param3,OnCirc);
|
||||||
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
||||||
Geom2dGcc_FunctionTanCuCuOnCu Func(C1,Cu2,OnCirc,Ufirst(4));
|
Geom2dGcc_FunctionTanCuCuOnCu Func(C1,Cu2,OnCirc,Ufirst(4));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
@@ -592,7 +597,8 @@ Geom2dGcc_Circ2d2TanOnIter (const GccEnt_QualifiedLin& Qualified1 ,
|
|||||||
gp_Pnt2d point3 = ElCLib::Value(Param3,OnCirc);
|
gp_Pnt2d point3 = ElCLib::Value(Param3,OnCirc);
|
||||||
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
||||||
Geom2dGcc_FunctionTanCuCuOnCu Func(L1,Cu2,OnCirc,Ufirst(4));
|
Geom2dGcc_FunctionTanCuCuOnCu Func(L1,Cu2,OnCirc,Ufirst(4));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
@@ -696,7 +702,8 @@ Geom2dGcc_Circ2d2TanOnIter (const Geom2dGcc_QCurve& Qualified1 ,
|
|||||||
gp_Pnt2d point3(OnCirc.Location().XY()+R1*gp_XY(Cos(Param3),Sin(Param3)));
|
gp_Pnt2d point3(OnCirc.Location().XY()+R1*gp_XY(Cos(Param3),Sin(Param3)));
|
||||||
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
||||||
Geom2dGcc_FunctionTanCuCuOnCu Func(Cu1,Cu2,OnCirc,Ufirst(4));
|
Geom2dGcc_FunctionTanCuCuOnCu Func(Cu1,Cu2,OnCirc,Ufirst(4));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
@@ -796,7 +803,8 @@ Geom2dGcc_Circ2d2TanOnIter (const Geom2dGcc_QCurve& Qualified1 ,
|
|||||||
gp_Pnt2d point3 = ElCLib::Value(Param2,OnCirc);
|
gp_Pnt2d point3 = ElCLib::Value(Param2,OnCirc);
|
||||||
Ufirst(3) = (point3.Distance(Point2)+point3.Distance(point1))/2.;
|
Ufirst(3) = (point3.Distance(Point2)+point3.Distance(point1))/2.;
|
||||||
Geom2dGcc_FunctionTanCuCuOnCu Func(Cu1,Point2,OnCirc,Ufirst(3));
|
Geom2dGcc_FunctionTanCuCuOnCu Func(Cu1,Point2,OnCirc,Ufirst(3));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
@@ -889,7 +897,8 @@ Geom2dGcc_Circ2d2TanOnIter (const Geom2dGcc_QCurve& Qualified1 ,
|
|||||||
gp_Pnt2d point3 = Geom2dGcc_CurveTool::Value(OnCurv,Param3);
|
gp_Pnt2d point3 = Geom2dGcc_CurveTool::Value(OnCurv,Param3);
|
||||||
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
||||||
Geom2dGcc_FunctionTanCuCuOnCu Func(Cu1,Cu2,OnCurv,Ufirst(4));
|
Geom2dGcc_FunctionTanCuCuOnCu Func(Cu1,Cu2,OnCurv,Ufirst(4));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
@@ -994,7 +1003,8 @@ Geom2dGcc_Circ2d2TanOnIter (const GccEnt_QualifiedCirc& Qualified1 ,
|
|||||||
gp_Pnt2d point3 = Geom2dGcc_CurveTool::Value(OnCurv,ParamOn);
|
gp_Pnt2d point3 = Geom2dGcc_CurveTool::Value(OnCurv,ParamOn);
|
||||||
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
||||||
Geom2dGcc_FunctionTanCuCuOnCu Func(C1,Cu2,OnCurv,Ufirst(4));
|
Geom2dGcc_FunctionTanCuCuOnCu Func(C1,Cu2,OnCurv,Ufirst(4));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
@@ -1095,7 +1105,8 @@ Geom2dGcc_Circ2d2TanOnIter (const GccEnt_QualifiedLin& Qualified1 ,
|
|||||||
gp_Pnt2d point3 = Geom2dGcc_CurveTool::Value(OnCurv,ParamOn);
|
gp_Pnt2d point3 = Geom2dGcc_CurveTool::Value(OnCurv,ParamOn);
|
||||||
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
Ufirst(4) = (point3.Distance(point2)+point3.Distance(point1))/2.;
|
||||||
Geom2dGcc_FunctionTanCuCuOnCu Func(L1,Cu2,OnCurv,Ufirst(4));
|
Geom2dGcc_FunctionTanCuCuOnCu Func(L1,Cu2,OnCurv,Ufirst(4));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
@@ -1186,7 +1197,8 @@ Geom2dGcc_Circ2d2TanOnIter (const Geom2dGcc_QCurve& Qualified1 ,
|
|||||||
gp_Pnt2d point3 = Geom2dGcc_CurveTool::Value(OnCurv,ParamOn);
|
gp_Pnt2d point3 = Geom2dGcc_CurveTool::Value(OnCurv,ParamOn);
|
||||||
Ufirst(3) = (point3.Distance(Point2)+point3.Distance(point1))/2.;
|
Ufirst(3) = (point3.Distance(Point2)+point3.Distance(point1))/2.;
|
||||||
Geom2dGcc_FunctionTanCuCuOnCu Func(Cu1,Point2,OnCurv,Ufirst(3));
|
Geom2dGcc_FunctionTanCuCuOnCu Func(Cu1,Point2,OnCurv,Ufirst(3));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
|
@@ -89,7 +89,8 @@ Geom2dGcc_Circ2d3TanIter (const Geom2dGcc_QCurve& Qualified1 ,
|
|||||||
tol(1) = Geom2dGcc_CurveTool::EpsX(Cu1,Abs(Tolerance));
|
tol(1) = Geom2dGcc_CurveTool::EpsX(Cu1,Abs(Tolerance));
|
||||||
tol(2) = Geom2dGcc_CurveTool::EpsX(Cu2,Abs(Tolerance));
|
tol(2) = Geom2dGcc_CurveTool::EpsX(Cu2,Abs(Tolerance));
|
||||||
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu3,Abs(Tolerance));
|
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu3,Abs(Tolerance));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
@@ -212,7 +213,8 @@ Geom2dGcc_Circ2d3TanIter (const GccEnt_QualifiedCirc& Qualified1 ,
|
|||||||
tol(1) = 2.e-15*M_PI;
|
tol(1) = 2.e-15*M_PI;
|
||||||
tol(2) = Geom2dGcc_CurveTool::EpsX(Cu2,Abs(Tolerance));
|
tol(2) = Geom2dGcc_CurveTool::EpsX(Cu2,Abs(Tolerance));
|
||||||
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu3,Abs(Tolerance));
|
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu3,Abs(Tolerance));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
@@ -340,7 +342,8 @@ Geom2dGcc_Circ2d3TanIter (const GccEnt_QualifiedCirc& Qualified1 ,
|
|||||||
tol(1) = 2.e-15*M_PI;
|
tol(1) = 2.e-15*M_PI;
|
||||||
tol(2) = 2.e-15*M_PI;
|
tol(2) = 2.e-15*M_PI;
|
||||||
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu3,Abs(Tolerance));
|
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu3,Abs(Tolerance));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
@@ -471,7 +474,8 @@ Geom2dGcc_Circ2d3TanIter (const GccEnt_QualifiedLin& Qualified1 ,
|
|||||||
tol(1) = 1.e-15;
|
tol(1) = 1.e-15;
|
||||||
tol(2) = Geom2dGcc_CurveTool::EpsX(Cu2,Abs(Tolerance));
|
tol(2) = Geom2dGcc_CurveTool::EpsX(Cu2,Abs(Tolerance));
|
||||||
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu3,Abs(Tolerance));
|
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu3,Abs(Tolerance));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
@@ -602,7 +606,8 @@ Geom2dGcc_Circ2d3TanIter (const GccEnt_QualifiedLin& Qualified1 ,
|
|||||||
tol(1) = 1.e-15;
|
tol(1) = 1.e-15;
|
||||||
tol(2) = 1.e-15;
|
tol(2) = 1.e-15;
|
||||||
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu3,Abs(Tolerance));
|
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu3,Abs(Tolerance));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
@@ -726,7 +731,8 @@ Geom2dGcc_Circ2d3TanIter (const Geom2dGcc_QCurve& Qualified1 ,
|
|||||||
tol(1) = 2.e-15*M_PI;
|
tol(1) = 2.e-15*M_PI;
|
||||||
tol(2) = Geom2dGcc_CurveTool::EpsX(Cu1,Abs(Tolerance));
|
tol(2) = Geom2dGcc_CurveTool::EpsX(Cu1,Abs(Tolerance));
|
||||||
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu2,Abs(Tolerance));
|
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu2,Abs(Tolerance));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
@@ -839,7 +845,8 @@ Geom2dGcc_Circ2d3TanIter (const Geom2dGcc_QCurve& Qualified1 ,
|
|||||||
tol(1) = 2.e-15*M_PI;
|
tol(1) = 2.e-15*M_PI;
|
||||||
tol(2) = 2.e-15*M_PI;
|
tol(2) = 2.e-15*M_PI;
|
||||||
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu1,Abs(Tolerance));
|
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu1,Abs(Tolerance));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
@@ -949,7 +956,8 @@ Geom2dGcc_Circ2d3TanIter (const GccEnt_QualifiedLin& Qualified1 ,
|
|||||||
tol(1) = 2.e-15;
|
tol(1) = 2.e-15;
|
||||||
tol(2) = 1.e-15;
|
tol(2) = 1.e-15;
|
||||||
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu2,Abs(Tolerance));
|
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu2,Abs(Tolerance));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
@@ -1068,7 +1076,8 @@ Geom2dGcc_Circ2d3TanIter (const GccEnt_QualifiedCirc& Qualified1 ,
|
|||||||
tol(1) = 2.e-15*M_PI;
|
tol(1) = 2.e-15*M_PI;
|
||||||
tol(2) = 1.e-15;
|
tol(2) = 1.e-15;
|
||||||
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu3,Abs(Tolerance));
|
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu3,Abs(Tolerance));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
@@ -1195,7 +1204,8 @@ Geom2dGcc_Circ2d3TanIter (const GccEnt_QualifiedCirc& Qualified1 ,
|
|||||||
tol(1) = 2.e-15*M_PI;
|
tol(1) = 2.e-15*M_PI;
|
||||||
tol(2) = 2.e-15*M_PI;
|
tol(2) = 2.e-15*M_PI;
|
||||||
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu2,Abs(Tolerance));
|
tol(3) = Geom2dGcc_CurveTool::EpsX(Cu2,Abs(Tolerance));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
Func.Value(Ufirst,Umin);
|
Func.Value(Ufirst,Umin);
|
||||||
|
@@ -144,7 +144,8 @@ Geom2dGcc_Lin2d2TanIter (const Geom2dGcc_QCurve& Qualified1 ,
|
|||||||
Ufirst(2) = Param2;
|
Ufirst(2) = Param2;
|
||||||
tol(1) = Geom2dGcc_CurveTool::EpsX(Cu1,Abs(Tolang));
|
tol(1) = Geom2dGcc_CurveTool::EpsX(Cu1,Abs(Tolang));
|
||||||
tol(2) = Geom2dGcc_CurveTool::EpsX(Cu2,Abs(Tolang));
|
tol(2) = Geom2dGcc_CurveTool::EpsX(Cu2,Abs(Tolang));
|
||||||
math_FunctionSetRoot Root(Func,Ufirst,tol,Umin,Umax);
|
math_FunctionSetRoot Root(Func, tol);
|
||||||
|
Root.Perform(Func, Ufirst, Umin, Umax);
|
||||||
if (Root.IsDone()) {
|
if (Root.IsDone()) {
|
||||||
Root.Root(Ufirst);
|
Root.Root(Ufirst);
|
||||||
// Modified by Sergey KHROMOV - Thu Apr 5 17:45:00 2001 Begin
|
// Modified by Sergey KHROMOV - Thu Apr 5 17:45:00 2001 Begin
|
||||||
|
@@ -310,30 +310,27 @@ GeomFill_LocationDraft::GeomFill_LocationDraft
|
|||||||
GeomFill_FunctionDraft E(mySurf , G);
|
GeomFill_FunctionDraft E(mySurf , G);
|
||||||
|
|
||||||
// resolution
|
// resolution
|
||||||
math_NewtonFunctionSetRoot Result(E, X, XTol, FTol, Iter);
|
math_NewtonFunctionSetRoot Result(E, XTol, FTol, Iter);
|
||||||
|
Result.Perform(E, X);
|
||||||
|
|
||||||
if (Result.IsDone())
|
if (Result.IsDone())
|
||||||
{
|
{
|
||||||
math_Vector R(1,3);
|
math_Vector R(1,3);
|
||||||
Result.Root(R); // solution
|
Result.Root(R); // solution
|
||||||
|
|
||||||
gp_Pnt2d p (R(2), R(3)); // point sur la surface
|
gp_Pnt2d p (R(2), R(3)); // point sur la surface
|
||||||
gp_Pnt2d q (R(1), Param); // point de la courbe
|
gp_Pnt2d q (R(1), Param); // point de la courbe
|
||||||
Poles2d.SetValue(1,p);
|
Poles2d.SetValue(1,p);
|
||||||
Poles2d.SetValue(2,q);
|
Poles2d.SetValue(2,q);
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return Standard_False;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
return Standard_False;
|
||||||
|
}
|
||||||
|
}// if_Intersec
|
||||||
|
|
||||||
|
// la generatrice n'intersecte pas la surface d'arret
|
||||||
}// if_Intersec
|
|
||||||
|
|
||||||
// la generatrice n'intersecte pas la surface d'arret
|
|
||||||
return Standard_True;
|
return Standard_True;
|
||||||
}
|
}
|
||||||
|
|
||||||
//==================================================================
|
//==================================================================
|
||||||
//Function: D1
|
//Function: D1
|
||||||
@@ -427,44 +424,44 @@ GeomFill_LocationDraft::GeomFill_LocationDraft
|
|||||||
|
|
||||||
|
|
||||||
// resolution
|
// resolution
|
||||||
math_NewtonFunctionSetRoot Result (E, X, XTol, FTol, Iter);
|
math_NewtonFunctionSetRoot Result(E, XTol, FTol, Iter);
|
||||||
|
Result.Perform(E, X);
|
||||||
|
|
||||||
if (Result.IsDone())
|
if (Result.IsDone())
|
||||||
{
|
{
|
||||||
math_Vector R(1,3);
|
math_Vector R(1,3);
|
||||||
Result.Root(R); // solution
|
Result.Root(R); // solution
|
||||||
|
|
||||||
gp_Pnt2d p (R(2), R(3)); // point sur la surface
|
|
||||||
gp_Pnt2d q (R(1), Param); // point de la courbe
|
|
||||||
Poles2d.SetValue(1,p);
|
|
||||||
Poles2d.SetValue(2,q);
|
|
||||||
|
|
||||||
// derivee de la fonction par rapport a Param
|
gp_Pnt2d p (R(2), R(3)); // point sur la surface
|
||||||
math_Vector DEDT(1,3,0);
|
gp_Pnt2d q (R(1), Param); // point de la courbe
|
||||||
E.DerivT(myTrimmed, Param, R(1), DN, myAngle, DEDT); // dE/dt => DEDT
|
Poles2d.SetValue(1,p);
|
||||||
|
Poles2d.SetValue(2,q);
|
||||||
|
|
||||||
math_Vector DSDT (1,3,0);
|
// derivee de la fonction par rapport a Param
|
||||||
math_Matrix DEDX (1,3,1,3,0);
|
math_Vector DEDT(1,3,0);
|
||||||
E.Derivatives(R, DEDX); // dE/dx au point R => DEDX
|
E.DerivT(myTrimmed, Param, R(1), DN, myAngle, DEDT); // dE/dt => DEDT
|
||||||
|
|
||||||
// resolution du syst. lin. : DEDX*DSDT = -DEDT
|
math_Vector DSDT (1,3,0);
|
||||||
math_Gauss Ga(DEDX);
|
math_Matrix DEDX (1,3,1,3,0);
|
||||||
if (Ga.IsDone())
|
E.Derivatives(R, DEDX); // dE/dx au point R => DEDX
|
||||||
{
|
|
||||||
Ga.Solve (DEDT.Opposite(), DSDT); // resolution du syst. lin.
|
|
||||||
gp_Vec2d dp (DSDT(2), DSDT(3)); // surface
|
|
||||||
gp_Vec2d dq (DSDT(1), 1); // courbe
|
|
||||||
DPoles2d.SetValue(1, dp);
|
|
||||||
DPoles2d.SetValue(2, dq);
|
|
||||||
}//if
|
|
||||||
|
|
||||||
|
// resolution du syst. lin. : DEDX*DSDT = -DEDT
|
||||||
}//if_Result
|
math_Gauss Ga(DEDX);
|
||||||
|
if (Ga.IsDone())
|
||||||
|
{
|
||||||
|
Ga.Solve (DEDT.Opposite(), DSDT); // resolution du syst. lin.
|
||||||
|
gp_Vec2d dp (DSDT(2), DSDT(3)); // surface
|
||||||
|
gp_Vec2d dq (DSDT(1), 1); // courbe
|
||||||
|
DPoles2d.SetValue(1, dp);
|
||||||
|
DPoles2d.SetValue(2, dq);
|
||||||
|
}//if
|
||||||
|
|
||||||
|
|
||||||
|
}//if_Result
|
||||||
else {// la generatrice n'intersecte pas la surface d'arret
|
else {// la generatrice n'intersecte pas la surface d'arret
|
||||||
return Standard_False;
|
return Standard_False;
|
||||||
}
|
}
|
||||||
}// if_Intersec
|
}// if_Intersec
|
||||||
|
|
||||||
return Standard_True;
|
return Standard_True;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -564,7 +561,8 @@ GeomFill_LocationDraft::GeomFill_LocationDraft
|
|||||||
|
|
||||||
|
|
||||||
// resolution
|
// resolution
|
||||||
math_NewtonFunctionSetRoot Result (E, X, XTol, FTol, Iter);
|
math_NewtonFunctionSetRoot Result (E, XTol, FTol, Iter);
|
||||||
|
Result.Perform(E, X);
|
||||||
|
|
||||||
if (Result.IsDone())
|
if (Result.IsDone())
|
||||||
{
|
{
|
||||||
|
@@ -349,34 +349,34 @@ static void InGoodPeriod(const Standard_Real Prec,
|
|||||||
#endif
|
#endif
|
||||||
Standard_Boolean SOS=Standard_False;
|
Standard_Boolean SOS=Standard_False;
|
||||||
if (ii>1) {
|
if (ii>1) {
|
||||||
// Intersection de secour entre surf revol et guide
|
// Intersection de secour entre surf revol et guide
|
||||||
// equation
|
// equation
|
||||||
X(1) = myPoles2d->Value(1,ii-1).Y();
|
X(1) = myPoles2d->Value(1,ii-1).Y();
|
||||||
X(2) = myPoles2d->Value(2,ii-1).X();
|
X(2) = myPoles2d->Value(2,ii-1).X();
|
||||||
X(3) = myPoles2d->Value(2,ii-1).Y();
|
X(3) = myPoles2d->Value(2,ii-1).Y();
|
||||||
GeomFill_FunctionGuide E (mySec, myGuide, U);
|
GeomFill_FunctionGuide E (mySec, myGuide, U);
|
||||||
E.SetParam(U, P, T.XYZ(), N.XYZ());
|
E.SetParam(U, P, T.XYZ(), N.XYZ());
|
||||||
// resolution => angle
|
// resolution => angle
|
||||||
math_FunctionSetRoot Result(E, X, TolRes,
|
math_FunctionSetRoot Result(E, TolRes);
|
||||||
Inf, Sup);
|
Result.Perform(E, X, Inf, Sup);
|
||||||
|
|
||||||
if (Result.IsDone() &&
|
if (Result.IsDone() &&
|
||||||
(Result.FunctionSetErrors().Norm() < TolRes(1)*TolRes(1)) ) {
|
(Result.FunctionSetErrors().Norm() < TolRes(1)*TolRes(1)) ) {
|
||||||
#ifdef OCCT_DEBUG
|
#ifdef OCCT_DEBUG
|
||||||
cout << "Ratrappage Reussi !" << endl;
|
cout << "Ratrappage Reussi !" << endl;
|
||||||
#endif
|
#endif
|
||||||
SOS = Standard_True;
|
SOS = Standard_True;
|
||||||
math_Vector RR(1,3);
|
math_Vector RR(1,3);
|
||||||
Result.Root(RR);
|
Result.Root(RR);
|
||||||
PInt.SetValues(P, RR(2), RR(3), RR(1), IntCurveSurface_Out);
|
PInt.SetValues(P, RR(2), RR(3), RR(1), IntCurveSurface_Out);
|
||||||
theU = PInt.U();
|
theU = PInt.U();
|
||||||
theV = PInt.V();
|
theV = PInt.V();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
#ifdef OCCT_DEBUG
|
#ifdef OCCT_DEBUG
|
||||||
cout << "Echec du Ratrappage !" << endl;
|
cout << "Echec du Ratrappage !" << endl;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!SOS) {
|
if (!SOS) {
|
||||||
myStatus = GeomFill_ImpossibleContact;
|
myStatus = GeomFill_ImpossibleContact;
|
||||||
@@ -614,8 +614,8 @@ static void InGoodPeriod(const Standard_Real Prec,
|
|||||||
GeomFill_FunctionGuide E (mySec, myGuide, U);
|
GeomFill_FunctionGuide E (mySec, myGuide, U);
|
||||||
E.SetParam(Param, P, t, n);
|
E.SetParam(Param, P, t, n);
|
||||||
// resolution => angle
|
// resolution => angle
|
||||||
math_FunctionSetRoot Result(E, X, TolRes,
|
math_FunctionSetRoot Result(E, TolRes, Iter);
|
||||||
Inf, Sup, Iter);
|
Result.Perform(E, X, Inf, Sup);
|
||||||
|
|
||||||
if (Result.IsDone()) {
|
if (Result.IsDone()) {
|
||||||
// solution
|
// solution
|
||||||
@@ -682,11 +682,11 @@ static void InGoodPeriod(const Standard_Real Prec,
|
|||||||
GeomFill_FunctionGuide E (mySec, myGuide, myFirstS +
|
GeomFill_FunctionGuide E (mySec, myGuide, myFirstS +
|
||||||
(Param-myCurve->FirstParameter())*ratio);
|
(Param-myCurve->FirstParameter())*ratio);
|
||||||
E.SetParam(Param, P, t, n);
|
E.SetParam(Param, P, t, n);
|
||||||
|
|
||||||
// resolution
|
// resolution
|
||||||
math_FunctionSetRoot Result(E, X, TolRes,
|
math_FunctionSetRoot Result(E, TolRes, Iter);
|
||||||
Inf, Sup, Iter);
|
Result.Perform(E, X, Inf, Sup);
|
||||||
|
|
||||||
if (Result.IsDone()) {
|
if (Result.IsDone()) {
|
||||||
// solution
|
// solution
|
||||||
Result.Root(R);
|
Result.Root(R);
|
||||||
|
@@ -198,12 +198,8 @@ void IntCurve_ExactIntersectionPoint::Roots(Standard_Real& U,Standard_Real& V) {
|
|||||||
|
|
||||||
void IntCurve_ExactIntersectionPoint::MathPerform(void)
|
void IntCurve_ExactIntersectionPoint::MathPerform(void)
|
||||||
{
|
{
|
||||||
math_FunctionSetRoot Fct( FctDist
|
math_FunctionSetRoot Fct(FctDist, ToleranceVector, 60);
|
||||||
,StartingPoint
|
Fct.Perform(FctDist, StartingPoint, BInfVector, BSupVector);
|
||||||
,ToleranceVector
|
|
||||||
,BInfVector
|
|
||||||
,BSupVector
|
|
||||||
,60);
|
|
||||||
|
|
||||||
if(Fct.IsDone()) {
|
if(Fct.IsDone()) {
|
||||||
Fct.Root(Root); nbroots = 1;
|
Fct.Root(Root); nbroots = 1;
|
||||||
|
@@ -72,15 +72,17 @@ ProjLib_PrjResolve::ProjLib_PrjResolve(const Adaptor3d_Curve& C,const Adaptor3d_
|
|||||||
// if (!S1.IsDone()) { return; }
|
// if (!S1.IsDone()) { return; }
|
||||||
// }
|
// }
|
||||||
// else {
|
// else {
|
||||||
math_NewtonFunctionSetRoot SR (F, Tol, 1.e-10);
|
math_NewtonFunctionSetRoot SR (F, Tol, 1.e-10);
|
||||||
SR.Perform(F, Start, BInf, BSup);
|
SR.Perform(F, Start, BInf, BSup);
|
||||||
// if (!SR.IsDone()) { return; }
|
// if (!SR.IsDone()) { return; }
|
||||||
if (!SR.IsDone()) {
|
if (!SR.IsDone())
|
||||||
math_FunctionSetRoot S1 (F, Start,Tol, BInf, BSup);
|
{
|
||||||
if (!S1.IsDone()) { return; }
|
math_FunctionSetRoot S1 (F, Tol);
|
||||||
}
|
S1.Perform(F, Start, BInf, BSup);
|
||||||
|
|
||||||
|
|
||||||
|
if (!S1.IsDone())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mySolution.SetXY(F.Solution().XY());
|
mySolution.SetXY(F.Solution().XY());
|
||||||
|
|
||||||
|
@@ -30,41 +30,34 @@ raises NotDone from StdFail
|
|||||||
|
|
||||||
is
|
is
|
||||||
|
|
||||||
|
Create(theXTolerance: in Real) returns BissecNewton;
|
||||||
|
---Purpose: Constructor.
|
||||||
|
-- @param theXTolerance - algorithm tolerance.
|
||||||
|
|
||||||
Perform(me: in out; F: out FunctionWithDerivative;
|
Perform(me: in out; F: out FunctionWithDerivative;
|
||||||
Bound1, Bound2: Real;
|
Bound1, Bound2: Real;
|
||||||
NbIterations: Integer)
|
NbIterations: Integer = 100)
|
||||||
|
---Purpose:
|
||||||
|
-- A combination of Newton-Raphson and bissection methods is done to find
|
||||||
|
-- the root of the function F between the bounds Bound1 and Bound2
|
||||||
|
-- on the function F.
|
||||||
|
-- The tolerance required on the root is given by TolX.
|
||||||
|
-- The solution is found when:
|
||||||
|
-- abs(Xi - Xi-1) <= TolX and F(Xi) * F(Xi-1) <= 0
|
||||||
|
-- The maximum number of iterations allowed is given by NbIterations.
|
||||||
|
is static;
|
||||||
|
|
||||||
is static protected;
|
|
||||||
|
|
||||||
|
|
||||||
Create(F: in out FunctionWithDerivative;
|
IsSolutionReached(me: in out; theFunction: out FunctionWithDerivative)
|
||||||
Bound1, Bound2, TolX: Real;
|
---Purpose:
|
||||||
NbIterations: Integer = 100)
|
-- This method is called at the end of each iteration to check if the
|
||||||
---Purpose:
|
-- solution has been found.
|
||||||
-- A combination of Newton-Raphson and bissection methods is done to find
|
-- It can be redefined in a sub-class to implement a specific test to
|
||||||
-- the root of the function F between the bounds Bound1 and Bound2.
|
-- stop the iterations.
|
||||||
-- on the function F.
|
---C++: inline
|
||||||
-- The tolerance required on the root is given by TolX.
|
returns Boolean is virtual;
|
||||||
-- The solution is found when :
|
|
||||||
-- abs(Xi - Xi-1) <= TolX and F(Xi) * F(Xi-1) <= 0
|
|
||||||
-- The maximum number of iterations allowed is given by NbIterations.
|
|
||||||
|
|
||||||
returns BissecNewton;
|
|
||||||
|
|
||||||
---C++: alias " Standard_EXPORT virtual ~math_BissecNewton();"
|
|
||||||
|
|
||||||
IsSolutionReached(me: in out; F: out FunctionWithDerivative)
|
|
||||||
---Purpose:
|
|
||||||
-- This method is called at the end of each iteration to check if the
|
|
||||||
-- solution has been found.
|
|
||||||
-- It can be redefined in a sub-class to implement a specific test to
|
|
||||||
-- stop the iterations.
|
|
||||||
|
|
||||||
returns Boolean
|
|
||||||
is virtual;
|
|
||||||
|
|
||||||
|
|
||||||
IsDone(me)
|
IsDone(me)
|
||||||
---Purpose: Tests is the root has been successfully found.
|
---Purpose: Tests is the root has been successfully found.
|
||||||
---C++: inline
|
---C++: inline
|
||||||
@@ -99,7 +92,7 @@ is
|
|||||||
raises NotDone
|
raises NotDone
|
||||||
is static;
|
is static;
|
||||||
|
|
||||||
|
|
||||||
Dump(me; o: in out OStream)
|
Dump(me; o: in out OStream)
|
||||||
---Purpose: Prints on the stream o information on the current state
|
---Purpose: Prints on the stream o information on the current state
|
||||||
-- of the object.
|
-- of the object.
|
||||||
@@ -108,6 +101,12 @@ is
|
|||||||
is static;
|
is static;
|
||||||
|
|
||||||
|
|
||||||
|
Delete(me) is static;
|
||||||
|
---Purpose: Destructor alias.
|
||||||
|
---C++: inline
|
||||||
|
---C++: alias " Standard_EXPORT virtual ~math_BissecNewton();"
|
||||||
|
|
||||||
|
|
||||||
fields
|
fields
|
||||||
|
|
||||||
Done: Boolean;
|
Done: Boolean;
|
||||||
|
@@ -15,14 +15,37 @@
|
|||||||
#include <math_BissecNewton.ixx>
|
#include <math_BissecNewton.ixx>
|
||||||
#include <math_FunctionWithDerivative.hxx>
|
#include <math_FunctionWithDerivative.hxx>
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : math_BissecNewton
|
||||||
|
//purpose : Constructor
|
||||||
|
//=======================================================================
|
||||||
|
math_BissecNewton::math_BissecNewton(const Standard_Real theXTolerance)
|
||||||
|
: TheStatus(math_NotBracketed),
|
||||||
|
XTol (theXTolerance),
|
||||||
|
x (0.0),
|
||||||
|
dx (0.0),
|
||||||
|
f (0.0),
|
||||||
|
df (0.0),
|
||||||
|
Done (Standard_False)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : ~math_BissecNewton
|
||||||
|
//purpose : Destructor
|
||||||
|
//=======================================================================
|
||||||
math_BissecNewton::~math_BissecNewton()
|
math_BissecNewton::~math_BissecNewton()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : Perform
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
void math_BissecNewton::Perform(math_FunctionWithDerivative& F,
|
void math_BissecNewton::Perform(math_FunctionWithDerivative& F,
|
||||||
const Standard_Real Bound1,
|
const Standard_Real Bound1,
|
||||||
const Standard_Real Bound2,
|
const Standard_Real Bound2,
|
||||||
const Standard_Integer NbIterations)
|
const Standard_Integer NbIterations)
|
||||||
{
|
{
|
||||||
Standard_Boolean GOOD;
|
Standard_Boolean GOOD;
|
||||||
Standard_Integer j;
|
Standard_Integer j;
|
||||||
@@ -125,25 +148,10 @@ void math_BissecNewton::Perform(math_FunctionWithDerivative& F,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Standard_Boolean math_BissecNewton::IsSolutionReached
|
//=======================================================================
|
||||||
//(math_FunctionWithDerivative& F)
|
//function : Dump
|
||||||
(math_FunctionWithDerivative& )
|
//purpose :
|
||||||
{
|
//=======================================================================
|
||||||
return Abs(dx) <= XTol;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
math_BissecNewton::math_BissecNewton(math_FunctionWithDerivative& F,
|
|
||||||
const Standard_Real Bound1,
|
|
||||||
const Standard_Real Bound2,
|
|
||||||
const Standard_Real TolX,
|
|
||||||
const Standard_Integer NbIterations) {
|
|
||||||
|
|
||||||
XTol = TolX;
|
|
||||||
Perform(F, Bound1, Bound2, NbIterations);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void math_BissecNewton::Dump(Standard_OStream& o) const {
|
void math_BissecNewton::Dump(Standard_OStream& o) const {
|
||||||
|
|
||||||
o << "math_BissecNewton ";
|
o << "math_BissecNewton ";
|
||||||
|
@@ -14,6 +14,16 @@
|
|||||||
|
|
||||||
#include <StdFail_NotDone.hxx>
|
#include <StdFail_NotDone.hxx>
|
||||||
|
|
||||||
|
inline void math_BissecNewton::Delete() const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Standard_Boolean math_BissecNewton::IsSolutionReached(math_FunctionWithDerivative&)
|
||||||
|
{
|
||||||
|
return Abs(dx) <= XTol;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Standard_OStream& operator<<(Standard_OStream& o,
|
inline Standard_OStream& operator<<(Standard_OStream& o,
|
||||||
const math_BissecNewton& Bi)
|
const math_BissecNewton& Bi)
|
||||||
{
|
{
|
||||||
|
@@ -32,63 +32,46 @@ is
|
|||||||
Create(TolX: Real;
|
Create(TolX: Real;
|
||||||
NbIterations: Integer = 100;
|
NbIterations: Integer = 100;
|
||||||
ZEPS: Real = 1.0e-12)
|
ZEPS: Real = 1.0e-12)
|
||||||
---Purpose:
|
---Purpose:
|
||||||
-- This constructor should be used in a sub-class to initialize
|
-- This constructor should be used in a sub-class to initialize
|
||||||
-- correctly all the fields of this class.
|
-- correctly all the fields of this class.
|
||||||
|
|
||||||
returns BrentMinimum;
|
returns BrentMinimum;
|
||||||
|
|
||||||
|
|
||||||
Create(TolX: Real; Fbx: Real;
|
Create(TolX: Real; Fbx: Real;
|
||||||
NbIterations: Integer = 100;
|
NbIterations: Integer = 100;
|
||||||
ZEPS: Real = 1.0e-12)
|
ZEPS: Real = 1.0e-12)
|
||||||
---Purpose:
|
---Purpose:
|
||||||
-- This constructor should be used in a sub-class to initialize
|
-- This constructor should be used in a sub-class to initialize
|
||||||
-- correctly all the fields of this class.
|
-- correctly all the fields of this class.
|
||||||
-- It has to be used if F(Bx) is known.
|
-- It has to be used if F(Bx) is known.
|
||||||
|
|
||||||
returns BrentMinimum;
|
returns BrentMinimum;
|
||||||
|
|
||||||
|
|
||||||
|
Delete(me) is static;
|
||||||
Create(F: in out Function; Ax, Bx, Cx, TolX: Real;
|
---Purpose: Destructor alias.
|
||||||
NbIterations: Integer = 100; ZEPS: Real=1.0e-12)
|
---C++: inline
|
||||||
---Purpose:
|
|
||||||
-- Given a bracketing triplet of abscissae Ax, Bx, Cx
|
|
||||||
-- (such as Bx is between Ax and Cx, F(Bx) is
|
|
||||||
-- less than both F(Bx) and F(Cx)) the Brent minimization is done
|
|
||||||
-- on the function F.
|
|
||||||
-- The tolerance required on F is given by Tolerance.
|
|
||||||
-- The solution is found when :
|
|
||||||
-- abs(Xi - Xi-1) <= TolX * abs(Xi) + ZEPS;
|
|
||||||
-- The maximum number of iterations allowed is given by NbIterations.
|
|
||||||
|
|
||||||
returns BrentMinimum;
|
|
||||||
|
|
||||||
---C++: alias " Standard_EXPORT virtual ~math_BrentMinimum();"
|
---C++: alias " Standard_EXPORT virtual ~math_BrentMinimum();"
|
||||||
|
|
||||||
Perform(me: in out; F: in out Function;
|
|
||||||
Ax, Bx, Cx: Real)
|
|
||||||
---Purpose:
|
|
||||||
-- Brent minimization is performed on function F from a given
|
|
||||||
-- bracketing triplet of abscissas Ax, Bx, Cx (such that Bx is
|
|
||||||
-- between Ax and Cx, F(Bx) is less than both F(Bx) and F(Cx))
|
|
||||||
-- Warning
|
|
||||||
-- The initialization constructors must have been called
|
|
||||||
-- before the call to the Perform method.
|
|
||||||
|
|
||||||
|
Perform(me: in out; F: in out Function;
|
||||||
|
Ax, Bx, Cx: Real)
|
||||||
|
---Purpose:
|
||||||
|
-- Brent minimization is performed on function F from a given
|
||||||
|
-- bracketing triplet of abscissas Ax, Bx, Cx (such that Bx is
|
||||||
|
-- between Ax and Cx, F(Bx) is less than both F(Bx) and F(Cx))
|
||||||
|
-- The solution is found when: abs(Xi - Xi-1) <= TolX * abs(Xi) + ZEPS;
|
||||||
is static;
|
is static;
|
||||||
|
|
||||||
|
|
||||||
IsSolutionReached(me: in out; F: in out Function)
|
IsSolutionReached(me: in out; theFunction: in out Function)
|
||||||
---Purpose:
|
---Purpose:
|
||||||
-- This method is called at the end of each iteration to check if the
|
-- This method is called at the end of each iteration to check if the
|
||||||
-- solution is found.
|
-- solution is found.
|
||||||
-- It can be redefined in a sub-class to implement a specific test to
|
-- It can be redefined in a sub-class to implement a specific test to
|
||||||
-- stop the iterations.
|
-- stop the iterations.
|
||||||
|
---C++:inline
|
||||||
returns Boolean
|
returns Boolean is virtual;
|
||||||
is virtual;
|
|
||||||
|
|
||||||
|
|
||||||
IsDone(me)
|
IsDone(me)
|
||||||
@@ -137,7 +120,6 @@ is
|
|||||||
is static;
|
is static;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fields
|
fields
|
||||||
|
|
||||||
Done: Boolean;
|
Done: Boolean;
|
||||||
|
@@ -23,15 +23,68 @@
|
|||||||
#define SIGN(a,b) ((b) > 0.0 ? fabs(a) : -fabs(a))
|
#define SIGN(a,b) ((b) > 0.0 ? fabs(a) : -fabs(a))
|
||||||
#define SHFT(a,b,c,d) (a)=(b);(b)=(c);(c)=(d)
|
#define SHFT(a,b,c,d) (a)=(b);(b)=(c);(c)=(d)
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : math_BrentMinimum
|
||||||
|
//purpose : Constructor
|
||||||
|
//=======================================================================
|
||||||
|
math_BrentMinimum::math_BrentMinimum(const Standard_Real theTolX,
|
||||||
|
const Standard_Integer theNbIterations,
|
||||||
|
const Standard_Real theZEPS)
|
||||||
|
: a (0.0),
|
||||||
|
b (0.0),
|
||||||
|
x (0.0),
|
||||||
|
fx (0.0),
|
||||||
|
fv (0.0),
|
||||||
|
fw (0.0),
|
||||||
|
XTol(theTolX),
|
||||||
|
EPSZ(theZEPS),
|
||||||
|
Done (Standard_False),
|
||||||
|
iter (0),
|
||||||
|
Itermax(theNbIterations),
|
||||||
|
myF (Standard_False)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : math_BrentMinimum
|
||||||
|
//purpose : Constructor
|
||||||
|
//=======================================================================
|
||||||
|
math_BrentMinimum::math_BrentMinimum(const Standard_Real theTolX,
|
||||||
|
const Standard_Real theFbx,
|
||||||
|
const Standard_Integer theNbIterations,
|
||||||
|
const Standard_Real theZEPS)
|
||||||
|
: a (0.0),
|
||||||
|
b (0.0),
|
||||||
|
x (0.0),
|
||||||
|
fx (theFbx),
|
||||||
|
fv (0.0),
|
||||||
|
fw (0.0),
|
||||||
|
XTol(theTolX),
|
||||||
|
EPSZ(theZEPS),
|
||||||
|
Done (Standard_False),
|
||||||
|
iter (0),
|
||||||
|
Itermax(theNbIterations),
|
||||||
|
myF (Standard_True)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : ~math_BrentMinimum
|
||||||
|
//purpose : Destructor
|
||||||
|
//=======================================================================
|
||||||
math_BrentMinimum::~math_BrentMinimum()
|
math_BrentMinimum::~math_BrentMinimum()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : Perform
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
void math_BrentMinimum::Perform(math_Function& F,
|
void math_BrentMinimum::Perform(math_Function& F,
|
||||||
const Standard_Real ax,
|
const Standard_Real ax,
|
||||||
const Standard_Real bx,
|
const Standard_Real bx,
|
||||||
const Standard_Real cx) {
|
const Standard_Real cx)
|
||||||
|
{
|
||||||
Standard_Boolean OK;
|
Standard_Boolean OK;
|
||||||
Standard_Real etemp, fu, p, q, r;
|
Standard_Real etemp, fu, p, q, r;
|
||||||
Standard_Real tol1, tol2, u, v, w, xm;
|
Standard_Real tol1, tol2, u, v, w, xm;
|
||||||
@@ -104,70 +157,20 @@ void math_BrentMinimum::Perform(math_Function& F,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
math_BrentMinimum::math_BrentMinimum(math_Function& F,
|
//function : Dump
|
||||||
const Standard_Real Ax,
|
//purpose :
|
||||||
const Standard_Real Bx,
|
//=======================================================================
|
||||||
const Standard_Real Cx,
|
void math_BrentMinimum::Dump(Standard_OStream& o) const
|
||||||
const Standard_Real TolX,
|
{
|
||||||
const Standard_Integer NbIterations,
|
o << "math_BrentMinimum ";
|
||||||
const Standard_Real ZEPS) {
|
if(Done) {
|
||||||
|
o << " Status = Done \n";
|
||||||
XTol = TolX;
|
o << " Location value = " << x <<"\n";
|
||||||
EPSZ = ZEPS;
|
o << " Minimum value = " << fx << "\n";
|
||||||
Itermax = NbIterations;
|
o << " Number of iterations = " << iter <<"\n";
|
||||||
myF = Standard_False;
|
|
||||||
Perform(F, Ax, Bx, Cx);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Constructeur d'initialisation des champs.
|
|
||||||
|
|
||||||
math_BrentMinimum::math_BrentMinimum(const Standard_Real TolX,
|
|
||||||
const Standard_Integer NbIterations,
|
|
||||||
const Standard_Real ZEPS) {
|
|
||||||
myF = Standard_False;
|
|
||||||
XTol = TolX;
|
|
||||||
EPSZ = ZEPS;
|
|
||||||
Itermax = NbIterations;
|
|
||||||
}
|
|
||||||
|
|
||||||
math_BrentMinimum::math_BrentMinimum(const Standard_Real TolX,
|
|
||||||
const Standard_Real Fbx,
|
|
||||||
const Standard_Integer NbIterations,
|
|
||||||
const Standard_Real ZEPS) {
|
|
||||||
|
|
||||||
fx = Fbx;
|
|
||||||
myF = Standard_True;
|
|
||||||
XTol = TolX;
|
|
||||||
EPSZ = ZEPS;
|
|
||||||
Itermax = NbIterations;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Standard_Boolean math_BrentMinimum::IsSolutionReached(math_Function& F) {
|
|
||||||
Standard_Boolean math_BrentMinimum::IsSolutionReached(math_Function& ) {
|
|
||||||
|
|
||||||
// Standard_Real xm = 0.5 * (a + b);
|
|
||||||
// modified by NIZHNY-MKK Mon Oct 3 17:45:57 2005.BEGIN
|
|
||||||
// Standard_Real tol = XTol * fabs(x) + EPSZ;
|
|
||||||
// return fabs(x - xm) <= 2.0 * tol - 0.5 * (b - a);
|
|
||||||
Standard_Real TwoTol = 2.0 *(XTol * fabs(x) + EPSZ);
|
|
||||||
return ((x <= (TwoTol + a)) && (x >= (b - TwoTol)));
|
|
||||||
// modified by NIZHNY-MKK Mon Oct 3 17:46:00 2005.END
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
o << " Status = not Done \n";
|
||||||
|
}
|
||||||
void math_BrentMinimum::Dump(Standard_OStream& o) const {
|
}
|
||||||
o << "math_BrentMinimum ";
|
|
||||||
if(Done) {
|
|
||||||
o << " Status = Done \n";
|
|
||||||
o << " Location value = " << x <<"\n";
|
|
||||||
o << " Minimum value = " << fx << "\n";
|
|
||||||
o << " Number of iterations = " << iter <<"\n";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
o << " Status = not Done \n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -14,7 +14,23 @@
|
|||||||
|
|
||||||
#include <StdFail_NotDone.hxx>
|
#include <StdFail_NotDone.hxx>
|
||||||
|
|
||||||
inline Standard_Boolean math_BrentMinimum::IsDone() const { return Done; }
|
inline void math_BrentMinimum::Delete() const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Standard_Boolean math_BrentMinimum::IsSolutionReached(math_Function&)
|
||||||
|
{
|
||||||
|
const Standard_Real TwoTol = 2.0 * (XTol * fabs(x) + EPSZ);
|
||||||
|
return (x <= (TwoTol + a)) && (x >= (b - TwoTol));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Standard_Boolean math_BrentMinimum::IsDone() const
|
||||||
|
{
|
||||||
|
return Done;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline Standard_OStream& operator<< (Standard_OStream& o,
|
inline Standard_OStream& operator<< (Standard_OStream& o,
|
||||||
const math_BrentMinimum& Br)
|
const math_BrentMinimum& Br)
|
||||||
|
@@ -30,53 +30,40 @@ raises DimensionError from Standard,
|
|||||||
|
|
||||||
is
|
is
|
||||||
|
|
||||||
Create(F: in out MultipleVarFunctionWithGradient;
|
Create(theFunction: in MultipleVarFunctionWithGradient;
|
||||||
StartingPoint: Vector; Tolerance: Real;
|
theTolerance: Real;
|
||||||
NbIterations: Integer=200; ZEPS: Real=1.0e-12)
|
theNbIterations: Integer = 200;
|
||||||
---Purpose: Computes FRPR minimization function F from input vector
|
theZEPS: Real = 1.0e-12)
|
||||||
-- StartingPoint. The solution F = Fi is found when 2.0 *
|
---Purpose:
|
||||||
-- abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1) +
|
-- Initializes the computation of the minimum of F.
|
||||||
-- ZEPS). The maximum number of iterations allowed is given
|
-- Warning: constructor does not perform computations.
|
||||||
-- by NbIterations.
|
|
||||||
returns FRPR;
|
|
||||||
|
|
||||||
|
|
||||||
Create(F: in out MultipleVarFunctionWithGradient;
|
|
||||||
Tolerance: Real;
|
|
||||||
NbIterations: Integer = 200;
|
|
||||||
ZEPS: Real = 1.0e-12)
|
|
||||||
---Purpose: Purpose
|
|
||||||
-- Initializes the computation of the minimum of F.
|
|
||||||
-- Warning
|
|
||||||
-- A call to the Perform method must be made after this
|
|
||||||
-- initialization to compute the minimum of the function.
|
|
||||||
returns FRPR;
|
returns FRPR;
|
||||||
|
|
||||||
|
Delete(me) is static;
|
||||||
|
---Purpose: Destructor alias.
|
||||||
---C++: alias " Standard_EXPORT virtual ~math_FRPR();"
|
---C++: alias " Standard_EXPORT virtual ~math_FRPR();"
|
||||||
|
|
||||||
Perform(me: in out; F: in out MultipleVarFunctionWithGradient;
|
|
||||||
StartingPoint: Vector)
|
|
||||||
---Purpose: Use this method after a call to the initialization constructor
|
|
||||||
-- to compute the minimum of function F.
|
|
||||||
-- Warning
|
|
||||||
-- The initialization constructor must have been called before
|
|
||||||
-- the Perform method is called
|
|
||||||
|
|
||||||
|
Perform(me: in out;
|
||||||
|
theFunction: in out MultipleVarFunctionWithGradient;
|
||||||
|
theStartingPoint: Vector)
|
||||||
|
---Purpose:
|
||||||
|
-- The solution F = Fi is found when
|
||||||
|
-- 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1) + ZEPS).
|
||||||
is static;
|
is static;
|
||||||
|
|
||||||
|
|
||||||
IsSolutionReached(me: in out; F: in out MultipleVarFunctionWithGradient)
|
IsSolutionReached(me: in out; theFunction: in out MultipleVarFunctionWithGradient)
|
||||||
---Purpose:
|
---Purpose:
|
||||||
-- The solution F = Fi is found when :
|
-- The solution F = Fi is found when:
|
||||||
-- 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1)) + ZEPS.
|
-- 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1)) + ZEPS.
|
||||||
-- The maximum number of iterations allowed is given by NbIterations.
|
-- The maximum number of iterations allowed is given by NbIterations.
|
||||||
|
---C++:inline
|
||||||
returns Boolean
|
returns Boolean is virtual;
|
||||||
is virtual;
|
|
||||||
|
|
||||||
|
|
||||||
IsDone(me)
|
IsDone(me)
|
||||||
---Purpose: Returns true if the computations are successful, otherwise returns false.
|
---Purpose: Returns true if the computations are successful, otherwise returns false.
|
||||||
---C++: inline
|
---C++: inline
|
||||||
returns Boolean
|
returns Boolean
|
||||||
is static;
|
is static;
|
||||||
@@ -158,6 +145,7 @@ is
|
|||||||
|
|
||||||
|
|
||||||
fields
|
fields
|
||||||
|
|
||||||
Done: Boolean;
|
Done: Boolean;
|
||||||
TheLocation: Vector is protected;
|
TheLocation: Vector is protected;
|
||||||
TheGradient: Vector is protected;
|
TheGradient: Vector is protected;
|
||||||
|
@@ -88,8 +88,9 @@ static Standard_Boolean MinimizeDirection(math_Vector& P,
|
|||||||
math_BracketMinimum Bracket(F, 0.0, 1.0);
|
math_BracketMinimum Bracket(F, 0.0, 1.0);
|
||||||
if(Bracket.IsDone()) {
|
if(Bracket.IsDone()) {
|
||||||
Bracket.Values(ax, xx, bx);
|
Bracket.Values(ax, xx, bx);
|
||||||
math_BrentMinimum Sol(F, ax, xx, bx, 1.0e-10, 100);
|
math_BrentMinimum Sol(1.e-10);
|
||||||
if(Sol.IsDone()) {
|
Sol.Perform(F, ax, xx, bx);
|
||||||
|
if (Sol.IsDone()) {
|
||||||
Standard_Real Scale = Sol.Location();
|
Standard_Real Scale = Sol.Location();
|
||||||
Result = Sol.Minimum();
|
Result = Sol.Minimum();
|
||||||
Dir.Multiply(Scale);
|
Dir.Multiply(Scale);
|
||||||
@@ -100,10 +101,45 @@ static Standard_Boolean MinimizeDirection(math_Vector& P,
|
|||||||
return Standard_False;
|
return Standard_False;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : math_FRPR
|
||||||
|
//purpose : Constructor
|
||||||
|
//=======================================================================
|
||||||
|
math_FRPR::math_FRPR(const math_MultipleVarFunctionWithGradient& theFunction,
|
||||||
|
const Standard_Real theTolerance,
|
||||||
|
const Standard_Integer theNbIterations,
|
||||||
|
const Standard_Real theZEPS)
|
||||||
|
|
||||||
|
: TheLocation(1, theFunction.NbVariables()),
|
||||||
|
TheGradient(1, theFunction.NbVariables()),
|
||||||
|
TheMinimum (0.0),
|
||||||
|
PreviousMinimum(0.0),
|
||||||
|
XTol (theTolerance),
|
||||||
|
EPSZ (theZEPS),
|
||||||
|
Done (Standard_False),
|
||||||
|
Iter (0),
|
||||||
|
State (0),
|
||||||
|
TheStatus (math_NotBracketed),
|
||||||
|
Itermax (theNbIterations)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : ~math_FRPR
|
||||||
|
//purpose : Destructor
|
||||||
|
//=======================================================================
|
||||||
|
math_FRPR::~math_FRPR()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : Perform
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
void math_FRPR::Perform(math_MultipleVarFunctionWithGradient& F,
|
void math_FRPR::Perform(math_MultipleVarFunctionWithGradient& F,
|
||||||
const math_Vector& StartingPoint) {
|
const math_Vector& StartingPoint)
|
||||||
|
{
|
||||||
Standard_Boolean Good;
|
Standard_Boolean Good;
|
||||||
Standard_Integer n = TheLocation.Length();
|
Standard_Integer n = TheLocation.Length();
|
||||||
Standard_Integer j, its;
|
Standard_Integer j, its;
|
||||||
@@ -140,7 +176,7 @@ void math_FRPR::Perform(math_MultipleVarFunctionWithGradient& F,
|
|||||||
}
|
}
|
||||||
if(IsSolutionReached(F)) {
|
if(IsSolutionReached(F)) {
|
||||||
Done = Standard_True;
|
Done = Standard_True;
|
||||||
State = F.GetStateNumber();
|
State = F.GetStateNumber();
|
||||||
TheStatus = math_OK;
|
TheStatus = math_OK;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -175,64 +211,25 @@ void math_FRPR::Perform(math_MultipleVarFunctionWithGradient& F,
|
|||||||
Done = Standard_False;
|
Done = Standard_False;
|
||||||
TheStatus = math_TooManyIterations;
|
TheStatus = math_TooManyIterations;
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
//=======================================================================
|
||||||
|
//function : Dump
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
Standard_Boolean math_FRPR::IsSolutionReached(
|
void math_FRPR::Dump(Standard_OStream& o) const
|
||||||
// math_MultipleVarFunctionWithGradient& F) {
|
{
|
||||||
math_MultipleVarFunctionWithGradient& ) {
|
o << "math_FRPR ";
|
||||||
|
if(Done) {
|
||||||
return (2.0 * fabs(TheMinimum - PreviousMinimum)) <=
|
o << " Status = Done \n";
|
||||||
XTol * (fabs(TheMinimum) + fabs(PreviousMinimum) + EPSZ);
|
o << " Location Vector = "<< TheLocation << "\n";
|
||||||
}
|
o << " Minimum value = " << TheMinimum <<"\n";
|
||||||
|
o << " Number of iterations = " << Iter <<"\n";
|
||||||
math_FRPR::math_FRPR(math_MultipleVarFunctionWithGradient& F,
|
}
|
||||||
const math_Vector& StartingPoint,
|
else {
|
||||||
const Standard_Real Tolerance,
|
o << " Status = not Done because " << (Standard_Integer)TheStatus << "\n";
|
||||||
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_FRPR::math_FRPR(math_MultipleVarFunctionWithGradient& F,
|
|
||||||
const Standard_Real Tolerance,
|
|
||||||
const Standard_Integer NbIterations,
|
|
||||||
const Standard_Real ZEPS)
|
|
||||||
: TheLocation(1, F.NbVariables()),
|
|
||||||
TheGradient(1, F.NbVariables()) {
|
|
||||||
|
|
||||||
XTol = Tolerance;
|
|
||||||
EPSZ = ZEPS;
|
|
||||||
Itermax = NbIterations;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
math_FRPR::~math_FRPR()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void math_FRPR::Dump(Standard_OStream& o) const {
|
|
||||||
|
|
||||||
o << "math_FRPR ";
|
|
||||||
if(Done) {
|
|
||||||
o << " Status = Done \n";
|
|
||||||
o << " Location Vector = "<< TheLocation << "\n";
|
|
||||||
o << " Minimum value = " << TheMinimum <<"\n";
|
|
||||||
o << " Number of iterations = " << Iter <<"\n";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
o << " Status = not Done because " << (Standard_Integer)TheStatus << "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@@ -15,8 +15,21 @@
|
|||||||
#include <StdFail_NotDone.hxx>
|
#include <StdFail_NotDone.hxx>
|
||||||
#include <math_Vector.hxx>
|
#include <math_Vector.hxx>
|
||||||
|
|
||||||
|
inline void math_FRPR::Delete() const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
inline Standard_Boolean math_FRPR::IsDone() const { return Done; }
|
inline Standard_Boolean math_FRPR::IsSolutionReached(math_MultipleVarFunctionWithGradient&)
|
||||||
|
{
|
||||||
|
return 2.0 * fabs(TheMinimum - PreviousMinimum) <=
|
||||||
|
XTol * (fabs(TheMinimum) + fabs(PreviousMinimum) + EPSZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Standard_Boolean math_FRPR::IsDone() const
|
||||||
|
{
|
||||||
|
return Done;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
inline Standard_OStream& operator<<(Standard_OStream& o,
|
inline Standard_OStream& operator<<(Standard_OStream& o,
|
||||||
const math_FRPR& Fr)
|
const math_FRPR& Fr)
|
||||||
|
@@ -76,7 +76,8 @@ class math_MyFunctionSetWithDerivatives : public math_FunctionSetWithDerivatives
|
|||||||
math_MyFunctionSetWithDerivatives Ff(F);
|
math_MyFunctionSetWithDerivatives Ff(F);
|
||||||
V(1)=Guess;
|
V(1)=Guess;
|
||||||
Tol(1) = Tolerance;
|
Tol(1) = Tolerance;
|
||||||
math_FunctionSetRoot Sol(Ff,V,Tol,NbIterations);
|
math_FunctionSetRoot Sol(Ff, Tol, NbIterations);
|
||||||
|
Sol.Perform(Ff, V);
|
||||||
Done = Sol.IsDone();
|
Done = Sol.IsDone();
|
||||||
if (Done) {
|
if (Done) {
|
||||||
F.GetStateNumber();
|
F.GetStateNumber();
|
||||||
@@ -98,7 +99,8 @@ class math_MyFunctionSetWithDerivatives : public math_FunctionSetWithDerivatives
|
|||||||
Tol(1) = Tolerance;
|
Tol(1) = Tolerance;
|
||||||
Aa(1)=A;
|
Aa(1)=A;
|
||||||
Bb(1)=B;
|
Bb(1)=B;
|
||||||
math_FunctionSetRoot Sol(Ff,V,Tol,Aa,Bb,NbIterations);
|
math_FunctionSetRoot Sol(Ff, Tol, NbIterations);
|
||||||
|
Sol.Perform(Ff, V, Aa, Bb);
|
||||||
Done = Sol.IsDone();
|
Done = Sol.IsDone();
|
||||||
if (Done) {
|
if (Done) {
|
||||||
F.GetStateNumber();
|
F.GetStateNumber();
|
||||||
|
@@ -57,66 +57,52 @@ is
|
|||||||
-- constructor.
|
-- constructor.
|
||||||
|
|
||||||
returns FunctionSetRoot from math;
|
returns FunctionSetRoot from math;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Create(F: in out FunctionSetWithDerivatives; StartingPoint: Vector;
|
|
||||||
Tolerance: Vector; NbIterations: Integer = 100)
|
|
||||||
---Purpose: is used to improve the root of the function F
|
|
||||||
-- from the initial guess StartingPoint.
|
|
||||||
-- The maximum number of iterations allowed is given by
|
|
||||||
-- NbIterations.
|
|
||||||
-- In this case, the solution is found when:
|
|
||||||
-- abs(Xi - Xi-1)(j) <= Tolerance(j) for all unknowns.
|
|
||||||
|
|
||||||
returns FunctionSetRoot from math;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Create(F: in out FunctionSetWithDerivatives; StartingPoint: Vector;
|
|
||||||
Tolerance: Vector; infBound, supBound: Vector;
|
|
||||||
NbIterations: Integer = 100; theStopOnDivergent : Boolean from Standard = Standard_False)
|
|
||||||
---Purpose: is used to improve the root of the function F
|
|
||||||
-- from the initial guess StartingPoint.
|
|
||||||
-- The maximum number of iterations allowed is given
|
|
||||||
-- by NbIterations.
|
|
||||||
-- In this case, the solution is found when:
|
|
||||||
-- abs(Xi - Xi-1) <= Tolerance for all unknowns.
|
|
||||||
|
|
||||||
returns FunctionSetRoot from math;
|
|
||||||
|
|
||||||
|
Delete(me) is static;
|
||||||
|
---Purpose: Destructor alias.
|
||||||
---C++: alias " Standard_EXPORT virtual ~math_FunctionSetRoot();"
|
---C++: alias " Standard_EXPORT virtual ~math_FunctionSetRoot();"
|
||||||
|
|
||||||
|
|
||||||
SetTolerance(me: in out; Tolerance: Vector)
|
SetTolerance(me: in out; Tolerance: Vector)
|
||||||
---Purpose: Initializes the tolerance values.
|
---Purpose: Initializes the tolerance values.
|
||||||
|
|
||||||
is static;
|
is static;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Perform(me: in out; F: in out FunctionSetWithDerivatives;
|
|
||||||
StartingPoint: Vector;
|
|
||||||
infBound, supBound: Vector; theStopOnDivergent : Boolean from Standard = Standard_False)
|
|
||||||
---Purpose: Improves the root of function F from the initial guess
|
|
||||||
-- StartingPoint. infBound and supBound may be given to constrain the solution.
|
|
||||||
-- Warning
|
|
||||||
-- This method is called when computation of the solution is
|
|
||||||
-- not performed by the constructors.
|
|
||||||
|
|
||||||
is static;
|
|
||||||
|
|
||||||
|
|
||||||
IsSolutionReached(me: in out; F: in out FunctionSetWithDerivatives)
|
IsSolutionReached(me: in out; F: in out FunctionSetWithDerivatives)
|
||||||
---Purpose: This routine is called at the end of each iteration
|
---Purpose: This routine is called at the end of each iteration
|
||||||
-- to check if the solution was found. It can be redefined
|
-- to check if the solution was found. It can be redefined
|
||||||
-- in a sub-class to implement a specific test to stop the
|
-- in a sub-class to implement a specific test to stop the iterations.
|
||||||
-- iterations.
|
-- In this case, the solution is found when: abs(Xi - Xi-1) <= Tolerance
|
||||||
-- In this case, the solution is found when:
|
-- for all unknowns.
|
||||||
-- abs(Xi - Xi-1) <= Tolerance for all unknowns.
|
---C++: inline
|
||||||
|
|
||||||
returns Boolean is virtual;
|
returns Boolean is virtual;
|
||||||
|
|
||||||
|
|
||||||
|
Perform(me: in out;
|
||||||
|
theFunction: in out FunctionSetWithDerivatives;
|
||||||
|
theStartingPoint: Vector;
|
||||||
|
theStopOnDivergent: Boolean from Standard = Standard_False)
|
||||||
|
---Purpose:
|
||||||
|
-- Improves the root of function from the initial guess point.
|
||||||
|
-- The infinum and supremum may be given to constrain the solution.
|
||||||
|
-- In this case, the solution is found when: abs(Xi - Xi-1)(j) <= Tolerance(j)
|
||||||
|
-- for all unknowns.
|
||||||
|
is static;
|
||||||
|
|
||||||
|
|
||||||
|
Perform(me: in out;
|
||||||
|
theFunction: in out FunctionSetWithDerivatives;
|
||||||
|
theStartingPoint: Vector;
|
||||||
|
theInfBound, theSupBound: Vector;
|
||||||
|
theStopOnDivergent: Boolean from Standard = Standard_False)
|
||||||
|
---Purpose:
|
||||||
|
-- Improves the root of function from the initial guess point.
|
||||||
|
-- The infinum and supremum may be given to constrain the solution.
|
||||||
|
-- In this case, the solution is found when: abs(Xi - Xi-1) <= Tolerance
|
||||||
|
-- for all unknowns.
|
||||||
|
is static;
|
||||||
|
|
||||||
|
|
||||||
IsDone(me)
|
IsDone(me)
|
||||||
---Purpose:
|
---Purpose:
|
||||||
-- Returns true if the computations are successful, otherwise returns false.
|
-- Returns true if the computations are successful, otherwise returns false.
|
||||||
|
@@ -228,8 +228,12 @@ static Standard_Boolean MinimizeDirection(const math_Vector& P0,
|
|||||||
FSR_DEBUG (" minimisation dans la direction")
|
FSR_DEBUG (" minimisation dans la direction")
|
||||||
ax = -1; bx = 0;
|
ax = -1; bx = 0;
|
||||||
cx = (P2-P1).Norm()*invnorme;
|
cx = (P2-P1).Norm()*invnorme;
|
||||||
if (cx < 1.e-2) return Standard_False;
|
if (cx < 1.e-2)
|
||||||
math_BrentMinimum Sol(F, ax, bx, cx, tol1d, 100, tol1d);
|
return Standard_False;
|
||||||
|
|
||||||
|
math_BrentMinimum Sol(tol1d, 100, tol1d);
|
||||||
|
Sol.Perform(F, ax, bx, cx);
|
||||||
|
|
||||||
if(Sol.IsDone()) {
|
if(Sol.IsDone()) {
|
||||||
tsol = Sol.Location();
|
tsol = Sol.Location();
|
||||||
if (Sol.Minimum() < F1) {
|
if (Sol.Minimum() < F1) {
|
||||||
@@ -322,7 +326,10 @@ static Standard_Boolean MinimizeDirection(const math_Vector& P,
|
|||||||
ax = 0.0; bx = tsol; cx = 1.0;
|
ax = 0.0; bx = tsol; cx = 1.0;
|
||||||
}
|
}
|
||||||
FSR_DEBUG(" minimisation dans la direction");
|
FSR_DEBUG(" minimisation dans la direction");
|
||||||
math_BrentMinimum Sol(F, ax, bx, cx, tol1d, 100, tol1d);
|
|
||||||
|
math_BrentMinimum Sol(tol1d, 100, tol1d);
|
||||||
|
Sol.Perform(F, ax, bx, cx);
|
||||||
|
|
||||||
if(Sol.IsDone()) {
|
if(Sol.IsDone()) {
|
||||||
if (Sol.Minimum() <= Result) {
|
if (Sol.Minimum() <= Result) {
|
||||||
tsol = Sol.Location();
|
tsol = Sol.Location();
|
||||||
@@ -551,155 +558,109 @@ Standard_Boolean Bounds(const math_Vector& InfBound,
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : math_FunctionSetRoot
|
||||||
|
//purpose : Constructor
|
||||||
|
//=======================================================================
|
||||||
|
math_FunctionSetRoot::math_FunctionSetRoot(
|
||||||
|
math_FunctionSetWithDerivatives& theFunction,
|
||||||
|
const math_Vector& theTolerance,
|
||||||
|
const Standard_Integer theNbIterations)
|
||||||
|
|
||||||
math_FunctionSetRoot::math_FunctionSetRoot(math_FunctionSetWithDerivatives& F,
|
: Delta(1, theFunction.NbVariables()),
|
||||||
const math_Vector& Tolerance,
|
Sol (1, theFunction.NbVariables()),
|
||||||
const Standard_Integer NbIterations) :
|
DF (1, theFunction.NbEquations() , 1, theFunction.NbVariables()),
|
||||||
Delta(1, F.NbVariables()),
|
Tol (1, theFunction.NbVariables()),
|
||||||
Sol(1, F.NbVariables()),
|
Done (Standard_False),
|
||||||
DF(1, F.NbEquations(),
|
Kount (0),
|
||||||
1, F.NbVariables()),
|
State (0),
|
||||||
Tol(1,F.NbVariables()),
|
Itermax (theNbIterations),
|
||||||
|
InfBound(1, theFunction.NbVariables(), RealFirst()),
|
||||||
InfBound(1, F.NbVariables()),
|
SupBound(1, theFunction.NbVariables(), RealLast ()),
|
||||||
SupBound(1, F.NbVariables()),
|
SolSave (1, theFunction.NbVariables()),
|
||||||
|
GH (1, theFunction.NbVariables()),
|
||||||
SolSave(1, F.NbVariables()),
|
DH (1, theFunction.NbVariables()),
|
||||||
GH(1, F.NbVariables()),
|
DHSave (1, theFunction.NbVariables()),
|
||||||
DH(1, F.NbVariables()),
|
FF (1, theFunction.NbEquations()),
|
||||||
DHSave(1, F.NbVariables()),
|
PreviousSolution(1, theFunction.NbVariables()),
|
||||||
FF(1, F.NbEquations()),
|
Save (0, theNbIterations),
|
||||||
PreviousSolution(1, F.NbVariables()),
|
Constraints(1, theFunction.NbVariables()),
|
||||||
Save(0, NbIterations),
|
Temp1 (1, theFunction.NbVariables()),
|
||||||
Constraints(1, F.NbVariables()),
|
Temp2 (1, theFunction.NbVariables()),
|
||||||
Temp1(1, F.NbVariables()),
|
Temp3 (1, theFunction.NbVariables()),
|
||||||
Temp2(1, F.NbVariables()),
|
Temp4 (1, theFunction.NbEquations()),
|
||||||
Temp3(1, F.NbVariables()),
|
myIsDivergent(Standard_False)
|
||||||
Temp4(1, F.NbEquations())
|
|
||||||
|
|
||||||
{
|
{
|
||||||
for (Standard_Integer i = 1; i <= Tol.Length(); i++) {
|
SetTolerance(theTolerance);
|
||||||
Tol(i) =Tolerance(i);
|
|
||||||
}
|
|
||||||
Itermax = NbIterations;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
math_FunctionSetRoot::math_FunctionSetRoot(math_FunctionSetWithDerivatives& F,
|
//=======================================================================
|
||||||
const Standard_Integer NbIterations) :
|
//function : math_FunctionSetRoot
|
||||||
Delta(1, F.NbVariables()),
|
//purpose : Constructor
|
||||||
Sol(1, F.NbVariables()),
|
//=======================================================================
|
||||||
DF(1, F.NbEquations(),
|
math_FunctionSetRoot::math_FunctionSetRoot(math_FunctionSetWithDerivatives& theFunction,
|
||||||
1, F.NbVariables()),
|
const Standard_Integer theNbIterations)
|
||||||
Tol(1, F.NbVariables()),
|
|
||||||
|
|
||||||
InfBound(1, F.NbVariables()),
|
|
||||||
SupBound(1, F.NbVariables()),
|
|
||||||
|
|
||||||
SolSave(1, F.NbVariables()),
|
|
||||||
GH(1, F.NbVariables()),
|
|
||||||
DH(1, F.NbVariables()),
|
|
||||||
DHSave(1, F.NbVariables()),
|
|
||||||
FF(1, F.NbEquations()),
|
|
||||||
PreviousSolution(1, F.NbVariables()),
|
|
||||||
Save(0, NbIterations),
|
|
||||||
Constraints(1, F.NbVariables()),
|
|
||||||
Temp1(1, F.NbVariables()),
|
|
||||||
Temp2(1, F.NbVariables()),
|
|
||||||
Temp3(1, F.NbVariables()),
|
|
||||||
Temp4(1, F.NbEquations())
|
|
||||||
|
|
||||||
|
: Delta(1, theFunction.NbVariables()),
|
||||||
|
Sol (1, theFunction.NbVariables()),
|
||||||
|
DF (1, theFunction.NbEquations() , 1, theFunction.NbVariables()),
|
||||||
|
Tol (1, theFunction.NbVariables()),
|
||||||
|
Done (Standard_False),
|
||||||
|
Kount (0),
|
||||||
|
State (0),
|
||||||
|
Itermax (theNbIterations),
|
||||||
|
InfBound(1, theFunction.NbVariables(), RealFirst()),
|
||||||
|
SupBound(1, theFunction.NbVariables(), RealLast ()),
|
||||||
|
SolSave (1, theFunction.NbVariables()),
|
||||||
|
GH (1, theFunction.NbVariables()),
|
||||||
|
DH (1, theFunction.NbVariables()),
|
||||||
|
DHSave (1, theFunction.NbVariables()),
|
||||||
|
FF (1, theFunction.NbEquations()),
|
||||||
|
PreviousSolution(1, theFunction.NbVariables()),
|
||||||
|
Save (0, theNbIterations),
|
||||||
|
Constraints(1, theFunction.NbVariables()),
|
||||||
|
Temp1 (1, theFunction.NbVariables()),
|
||||||
|
Temp2 (1, theFunction.NbVariables()),
|
||||||
|
Temp3 (1, theFunction.NbVariables()),
|
||||||
|
Temp4 (1, theFunction.NbEquations()),
|
||||||
|
myIsDivergent(Standard_False)
|
||||||
{
|
{
|
||||||
Itermax = NbIterations;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
math_FunctionSetRoot::math_FunctionSetRoot(math_FunctionSetWithDerivatives& F,
|
|
||||||
const math_Vector& StartingPoint,
|
|
||||||
const math_Vector& Tolerance,
|
|
||||||
const math_Vector& infBound,
|
|
||||||
const math_Vector& supBound,
|
|
||||||
const Standard_Integer NbIterations,
|
|
||||||
Standard_Boolean theStopOnDivergent) :
|
|
||||||
Delta(1, F.NbVariables()),
|
|
||||||
Sol(1, F.NbVariables()),
|
|
||||||
DF(1, F.NbEquations(),
|
|
||||||
1, F.NbVariables()),
|
|
||||||
Tol(1,F.NbVariables()),
|
|
||||||
|
|
||||||
|
|
||||||
InfBound(1, F.NbVariables()),
|
|
||||||
SupBound(1, F.NbVariables()),
|
|
||||||
|
|
||||||
SolSave(1, F.NbVariables()),
|
|
||||||
GH(1, F.NbVariables()),
|
|
||||||
DH(1, F.NbVariables()),
|
|
||||||
DHSave(1, F.NbVariables()),
|
|
||||||
FF(1, F.NbEquations()),
|
|
||||||
PreviousSolution(1, F.NbVariables()),
|
|
||||||
Save(0, NbIterations),
|
|
||||||
Constraints(1, F.NbVariables()),
|
|
||||||
Temp1(1, F.NbVariables()),
|
|
||||||
Temp2(1, F.NbVariables()),
|
|
||||||
Temp3(1, F.NbVariables()),
|
|
||||||
Temp4(1, F.NbEquations())
|
|
||||||
|
|
||||||
{
|
|
||||||
|
|
||||||
for (Standard_Integer i = 1; i <= Tol.Length(); i++) {
|
|
||||||
Tol(i) =Tolerance(i);
|
|
||||||
}
|
|
||||||
Itermax = NbIterations;
|
|
||||||
Perform(F, StartingPoint, infBound, supBound, theStopOnDivergent);
|
|
||||||
}
|
|
||||||
|
|
||||||
math_FunctionSetRoot::math_FunctionSetRoot(math_FunctionSetWithDerivatives& F,
|
|
||||||
const math_Vector& StartingPoint,
|
|
||||||
const math_Vector& Tolerance,
|
|
||||||
const Standard_Integer NbIterations) :
|
|
||||||
Delta(1, F.NbVariables()),
|
|
||||||
Sol(1, F.NbVariables()),
|
|
||||||
DF(1, F.NbEquations(),
|
|
||||||
1, StartingPoint.Length()),
|
|
||||||
Tol(1,F.NbVariables()),
|
|
||||||
|
|
||||||
InfBound(1, F.NbVariables()),
|
|
||||||
SupBound(1, F.NbVariables()),
|
|
||||||
|
|
||||||
SolSave(1, F.NbVariables()),
|
|
||||||
GH(1, F.NbVariables()),
|
|
||||||
DH(1, F.NbVariables()),
|
|
||||||
DHSave(1, F.NbVariables()),
|
|
||||||
FF(1, F.NbEquations()),
|
|
||||||
PreviousSolution(1, F.NbVariables()),
|
|
||||||
Save(0, NbIterations),
|
|
||||||
Constraints(1, F.NbVariables()),
|
|
||||||
Temp1(1, F.NbVariables()),
|
|
||||||
Temp2(1, F.NbVariables()),
|
|
||||||
Temp3(1, F.NbVariables()),
|
|
||||||
Temp4(1, F.NbEquations())
|
|
||||||
|
|
||||||
{
|
|
||||||
for (Standard_Integer i = 1; i <= Tol.Length(); i++) {
|
|
||||||
Tol(i) = Tolerance(i);
|
|
||||||
}
|
|
||||||
Itermax = NbIterations;
|
|
||||||
InfBound.Init(RealFirst());
|
|
||||||
SupBound.Init(RealLast());
|
|
||||||
Perform(F, StartingPoint, InfBound, SupBound);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : ~math_FunctionSetRoot
|
||||||
|
//purpose : Destructor
|
||||||
|
//=======================================================================
|
||||||
math_FunctionSetRoot::~math_FunctionSetRoot()
|
math_FunctionSetRoot::~math_FunctionSetRoot()
|
||||||
{
|
{
|
||||||
|
Delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
void math_FunctionSetRoot::SetTolerance(const math_Vector& Tolerance)
|
//=======================================================================
|
||||||
|
//function : SetTolerance
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
|
void math_FunctionSetRoot::SetTolerance(const math_Vector& theTolerance)
|
||||||
{
|
{
|
||||||
for (Standard_Integer i = 1; i <= Tol.Length(); i++) {
|
for (Standard_Integer i = 1; i <= Tol.Length(); ++i)
|
||||||
Tol(i) = Tolerance(i);
|
Tol(i) = theTolerance(i);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : Perform
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
|
void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& theFunction,
|
||||||
|
const math_Vector& theStartingPoint,
|
||||||
|
const Standard_Boolean theStopOnDivergent)
|
||||||
|
{
|
||||||
|
Perform(theFunction, theStartingPoint, InfBound, SupBound, theStopOnDivergent);
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : Perform
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F,
|
void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F,
|
||||||
const math_Vector& StartingPoint,
|
const math_Vector& StartingPoint,
|
||||||
const math_Vector& theInfBound,
|
const math_Vector& theInfBound,
|
||||||
@@ -1232,38 +1193,40 @@ void math_FunctionSetRoot::Perform(math_FunctionSetWithDerivatives& F,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : Dump
|
||||||
|
//purpose :
|
||||||
Standard_Boolean math_FunctionSetRoot::IsSolutionReached(math_FunctionSetWithDerivatives& ) {
|
//=======================================================================
|
||||||
for(Standard_Integer i = 1; i<= Sol.Length(); i++) {
|
void math_FunctionSetRoot::Dump(Standard_OStream& o) const
|
||||||
if(Abs(Delta(i)) > Tol(i)) {return Standard_False;}
|
{
|
||||||
}
|
o << " math_FunctionSetRoot";
|
||||||
return Standard_True;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void math_FunctionSetRoot::Dump(Standard_OStream& o) const {
|
|
||||||
o<<" math_FunctionSetRoot";
|
|
||||||
if (Done) {
|
if (Done) {
|
||||||
o << " Status = Done\n";
|
o << " Status = Done\n";
|
||||||
o << " Location value = " << Sol << "\n";
|
o << " Location value = " << Sol << "\n";
|
||||||
o << " Number of iterations = " << Kount << "\n";
|
o << " Number of iterations = " << Kount << "\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
o<<"Status = Not Done\n";
|
o << "Status = Not Done\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
void math_FunctionSetRoot::Root(math_Vector& Root) const{
|
//function : Root
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
|
void math_FunctionSetRoot::Root(math_Vector& Root) const
|
||||||
|
{
|
||||||
StdFail_NotDone_Raise_if(!Done, " ");
|
StdFail_NotDone_Raise_if(!Done, " ");
|
||||||
Standard_DimensionError_Raise_if(Root.Length() != Sol.Length(), " ");
|
Standard_DimensionError_Raise_if(Root.Length() != Sol.Length(), " ");
|
||||||
Root = Sol;
|
Root = Sol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
void math_FunctionSetRoot::FunctionSetErrors(math_Vector& Err) const{
|
//function : FunctionSetErrors
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
|
void math_FunctionSetRoot::FunctionSetErrors(math_Vector& Err) const
|
||||||
|
{
|
||||||
StdFail_NotDone_Raise_if(!Done, " ");
|
StdFail_NotDone_Raise_if(!Done, " ");
|
||||||
Standard_DimensionError_Raise_if(Err.Length() != Sol.Length(), " ");
|
Standard_DimensionError_Raise_if(Err.Length() != Sol.Length(), " ");
|
||||||
Err = Delta;
|
Err = Delta;
|
||||||
|
@@ -15,8 +15,26 @@
|
|||||||
#include <StdFail_NotDone.hxx>
|
#include <StdFail_NotDone.hxx>
|
||||||
#include <Standard_DimensionError.hxx>
|
#include <Standard_DimensionError.hxx>
|
||||||
|
|
||||||
|
inline void math_FunctionSetRoot::Delete() const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Standard_Boolean math_FunctionSetRoot::IsSolutionReached(math_FunctionSetWithDerivatives&)
|
||||||
|
{
|
||||||
|
for (Standard_Integer i = 1; i <= Sol.Length(); ++i)
|
||||||
|
if ( Abs(Delta(i)) > Tol(i) )
|
||||||
|
return Standard_False;
|
||||||
|
|
||||||
|
return Standard_True;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline Standard_Boolean math_FunctionSetRoot::IsDone() const
|
||||||
|
{
|
||||||
|
return Done;
|
||||||
|
}
|
||||||
|
|
||||||
inline Standard_Boolean math_FunctionSetRoot::IsDone() const { return Done; }
|
|
||||||
|
|
||||||
inline Standard_OStream& operator<<(Standard_OStream& o,
|
inline Standard_OStream& operator<<(Standard_OStream& o,
|
||||||
const math_FunctionSetRoot& F)
|
const math_FunctionSetRoot& F)
|
||||||
|
@@ -247,7 +247,9 @@ Standard_Boolean math_GlobOptMin::computeLocalExtremum(const math_Vector& thePnt
|
|||||||
math_MultipleVarFunctionWithHessian* myTmp =
|
math_MultipleVarFunctionWithHessian* myTmp =
|
||||||
dynamic_cast<math_MultipleVarFunctionWithHessian*> (myFunc);
|
dynamic_cast<math_MultipleVarFunctionWithHessian*> (myFunc);
|
||||||
|
|
||||||
math_NewtonMinimum newtonMinimum(*myTmp, thePnt);
|
math_NewtonMinimum newtonMinimum(*myTmp);
|
||||||
|
newtonMinimum.Perform(*myTmp, thePnt);
|
||||||
|
|
||||||
if (newtonMinimum.IsDone())
|
if (newtonMinimum.IsDone())
|
||||||
{
|
{
|
||||||
newtonMinimum.Location(theOutPnt);
|
newtonMinimum.Location(theOutPnt);
|
||||||
@@ -278,7 +280,8 @@ Standard_Boolean math_GlobOptMin::computeLocalExtremum(const math_Vector& thePnt
|
|||||||
for(i = 1; i <= myN; i++)
|
for(i = 1; i <= myN; i++)
|
||||||
m(1, 1) = 1.0;
|
m(1, 1) = 1.0;
|
||||||
|
|
||||||
math_Powell powell(*myFunc, thePnt, m, 1e-10);
|
math_Powell powell(*myFunc, 1e-10);
|
||||||
|
powell.Perform(*myFunc, thePnt, m);
|
||||||
|
|
||||||
if (powell.IsDone())
|
if (powell.IsDone())
|
||||||
{
|
{
|
||||||
|
@@ -30,96 +30,66 @@ raises NotDone from StdFail,
|
|||||||
|
|
||||||
is
|
is
|
||||||
|
|
||||||
Create(F: in out FunctionSetWithDerivatives;
|
Create(theFunction: in out FunctionSetWithDerivatives;
|
||||||
XTol: Vector; FTol: Real;
|
theXTolerance: Vector; theFTolerance: Real;
|
||||||
NbIterations: Integer = 100)
|
tehNbIterations: Integer = 100)
|
||||||
---Purpose:
|
---Purpose:
|
||||||
-- This constructor should be used in a sub-class to initialize
|
-- Initialize correctly all the fields of this class.
|
||||||
-- correctly all the fields of this class.
|
-- The range (1, F.NbVariables()) must be especially respected for
|
||||||
-- The range (1, F.NbVariables()) must be especially respected for
|
-- all vectors and matrix declarations.
|
||||||
-- all vectors and matrix declarations.
|
returns NewtonFunctionSetRoot;
|
||||||
|
|
||||||
returns NewtonFunctionSetRoot;
|
|
||||||
|
|
||||||
|
|
||||||
Create(F: in out FunctionSetWithDerivatives;
|
|
||||||
FTol: Real; NbIterations: Integer = 100)
|
|
||||||
---Purpose:
|
|
||||||
-- This constructor should be used in a sub-class to initialize
|
|
||||||
-- correctly all the fields of this class.
|
|
||||||
-- The range (1, F.NbVariables()) must be especially respected for
|
|
||||||
-- all vectors and matrix declarations.
|
|
||||||
-- The method SetTolerance must be called before performing the
|
|
||||||
-- algorithm.
|
|
||||||
|
|
||||||
returns NewtonFunctionSetRoot;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Create(F: in out FunctionSetWithDerivatives;
|
|
||||||
StartingPoint: Vector;
|
|
||||||
XTol: Vector; FTol: Real;
|
|
||||||
NbIterations: Integer = 100)
|
|
||||||
---Purpose:
|
|
||||||
-- The Newton method is done to improve the root of the function F
|
|
||||||
-- from the initial guess StartingPoint.
|
|
||||||
-- The tolerance required on the root is given by Tolerance.
|
|
||||||
-- The solution is found when :
|
|
||||||
-- abs(Xj - Xj-1)(i) <= XTol(i) and abs(Fi) <= FTol for all i;
|
|
||||||
-- The maximum number of iterations allowed is given by NbIterations.
|
|
||||||
|
|
||||||
returns NewtonFunctionSetRoot;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Create(F: in out FunctionSetWithDerivatives;
|
Create(theFunction: in out FunctionSetWithDerivatives;
|
||||||
StartingPoint: Vector;
|
theFTolerance: Real; theNbIterations: Integer = 100)
|
||||||
InfBound, SupBound: Vector;
|
---Purpose:
|
||||||
XTol: Vector; FTol: Real;
|
-- This constructor should be used in a sub-class to initialize
|
||||||
NbIterations: Integer = 100)
|
-- correctly all the fields of this class.
|
||||||
---Purpose:
|
-- The range (1, F.NbVariables()) must be especially respected for
|
||||||
-- The Newton method is done to improve the root of the function F
|
-- all vectors and matrix declarations.
|
||||||
-- from the initial guess StartingPoint.
|
-- The method SetTolerance must be called before performing the algorithm.
|
||||||
-- The tolerance required on the root is given by Tolerance.
|
returns NewtonFunctionSetRoot;
|
||||||
-- The solution is found when :
|
|
||||||
-- abs(Xj - Xj-1)(i) <= XTol(i) and abs(Fi) <= FTol for all i;
|
|
||||||
-- The maximum number of iterations allowed is given by NbIterations.
|
|
||||||
|
|
||||||
returns NewtonFunctionSetRoot;
|
|
||||||
|
|
||||||
|
|
||||||
|
Delete(me) is static;
|
||||||
|
---Purpose: Destructor alias.
|
||||||
---C++: alias " Standard_EXPORT virtual ~math_NewtonFunctionSetRoot();"
|
---C++: alias " Standard_EXPORT virtual ~math_NewtonFunctionSetRoot();"
|
||||||
|
|
||||||
|
|
||||||
SetTolerance(me: in out; XTol: Vector)
|
SetTolerance(me: in out; XTol: Vector)
|
||||||
---Purpose: Initializes the tolerance values for the unknowns.
|
---Purpose: Initializes the tolerance values for the unknowns.
|
||||||
|
is static;
|
||||||
is static;
|
|
||||||
|
|
||||||
|
Perform(me: in out; theFunction: in out FunctionSetWithDerivatives; theStartingPoint: Vector)
|
||||||
Perform(me: in out; F:in out FunctionSetWithDerivatives;
|
---Purpose:
|
||||||
StartingPoint: Vector;
|
-- The Newton method is done to improve the root of the function
|
||||||
InfBound, SupBound: Vector)
|
-- from the initial guess point. The solution is found when:
|
||||||
---Purpose: Improves the root of function F from the initial guess
|
-- abs(Xj - Xj-1)(i) <= XTol(i) and abs(Fi) <= FTol for all i;
|
||||||
-- StartingPoint. infBound and supBound may be given, to constrain the solution.
|
is static;
|
||||||
-- Warning
|
|
||||||
-- This method must be called when the solution is not computed by the constructors.
|
|
||||||
|
Perform(me: in out; theFunction: in out FunctionSetWithDerivatives;
|
||||||
|
theStartingPoint: Vector; theInfBound, theSupBound: Vector)
|
||||||
|
---Purpose:
|
||||||
|
-- The Newton method is done to improve the root of the function
|
||||||
|
-- from the initial guess point. Bounds may be given, to constrain the solution.
|
||||||
|
-- The solution is found when:
|
||||||
|
-- abs(Xj - Xj-1)(i) <= XTol(i) and abs(Fi) <= FTol for all i;
|
||||||
is static;
|
is static;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
IsSolutionReached(me: in out; F: in out FunctionSetWithDerivatives)
|
IsSolutionReached(me: in out; F: in out FunctionSetWithDerivatives)
|
||||||
---Purpose:
|
---Purpose:
|
||||||
-- This method is called at the end of each iteration to check if the
|
-- This method is called at the end of each iteration to check if the
|
||||||
-- solution is found.
|
-- solution is found.
|
||||||
-- Vectors DeltaX, Fvalues and Jacobian Matrix are consistent with the
|
-- Vectors DeltaX, Fvalues and Jacobian Matrix are consistent with the
|
||||||
-- possible solution Vector Sol and can be inspected to decide whether
|
-- possible solution Vector Sol and can be inspected to decide whether
|
||||||
-- the solution is reached or not.
|
-- the solution is reached or not.
|
||||||
|
---C++: inline
|
||||||
|
returns Boolean is virtual;
|
||||||
|
|
||||||
|
|
||||||
returns Boolean
|
|
||||||
is virtual;
|
|
||||||
|
|
||||||
|
|
||||||
IsDone(me)
|
IsDone(me)
|
||||||
---Purpose: Returns true if the computations are successful, otherwise returns false.
|
---Purpose: Returns true if the computations are successful, otherwise returns false.
|
||||||
---C++: inline
|
---C++: inline
|
||||||
|
@@ -22,128 +22,93 @@
|
|||||||
#include <math_Recipes.hxx>
|
#include <math_Recipes.hxx>
|
||||||
#include <math_FunctionSetWithDerivatives.hxx>
|
#include <math_FunctionSetWithDerivatives.hxx>
|
||||||
|
|
||||||
Standard_Boolean math_NewtonFunctionSetRoot::IsSolutionReached
|
|
||||||
// (math_FunctionSetWithDerivatives& F)
|
|
||||||
(math_FunctionSetWithDerivatives& )
|
|
||||||
{
|
|
||||||
|
|
||||||
for(Standard_Integer i = DeltaX.Lower(); i <= DeltaX.Upper(); i++) {
|
|
||||||
if(Abs(DeltaX(i)) > TolX(i) || Abs(FValues(i)) > TolF) return Standard_False;
|
|
||||||
}
|
|
||||||
return Standard_True;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Constructeurs d'initialisation des champs (pour utiliser Perform)
|
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : math_NewtonFunctionSetRoot
|
||||||
|
//purpose : Constructor
|
||||||
|
//=======================================================================
|
||||||
math_NewtonFunctionSetRoot::math_NewtonFunctionSetRoot(
|
math_NewtonFunctionSetRoot::math_NewtonFunctionSetRoot(
|
||||||
math_FunctionSetWithDerivatives& F,
|
math_FunctionSetWithDerivatives& theFunction,
|
||||||
const math_Vector& XTol,
|
const math_Vector& theXTolerance,
|
||||||
const Standard_Real FTol,
|
const Standard_Real theFTolerance,
|
||||||
const Standard_Integer NbIterations):
|
const Standard_Integer theNbIterations)
|
||||||
TolX(1, F.NbVariables()),
|
|
||||||
TolF(FTol),
|
: TolX (1, theFunction.NbVariables()),
|
||||||
Indx(1, F.NbVariables()),
|
TolF (theFTolerance),
|
||||||
Scratch(1, F.NbVariables()),
|
Indx (1, theFunction.NbVariables()),
|
||||||
Sol(1, F.NbVariables()),
|
Scratch (1, theFunction.NbVariables()),
|
||||||
DeltaX(1, F.NbVariables()),
|
Sol (1, theFunction.NbVariables()),
|
||||||
FValues(1, F.NbVariables()),
|
DeltaX (1, theFunction.NbVariables()),
|
||||||
Jacobian(1, F.NbVariables(),
|
FValues (1, theFunction.NbVariables()),
|
||||||
1, F.NbVariables()),
|
Jacobian(1, theFunction.NbVariables(), 1, theFunction.NbVariables()),
|
||||||
Itermax(NbIterations)
|
Done (Standard_False),
|
||||||
|
State (0),
|
||||||
|
Iter (0),
|
||||||
|
Itermax (theNbIterations)
|
||||||
{
|
{
|
||||||
for (Standard_Integer i = 1; i <= TolX.Length(); i++) {
|
SetTolerance(theXTolerance);
|
||||||
TolX(i) = XTol(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : math_NewtonFunctionSetRoot
|
||||||
|
//purpose : Constructor
|
||||||
|
//=======================================================================
|
||||||
math_NewtonFunctionSetRoot::math_NewtonFunctionSetRoot(
|
math_NewtonFunctionSetRoot::math_NewtonFunctionSetRoot(
|
||||||
math_FunctionSetWithDerivatives& F,
|
math_FunctionSetWithDerivatives& theFunction,
|
||||||
const Standard_Real FTol,
|
const Standard_Real theFTolerance,
|
||||||
const Standard_Integer NbIterations):
|
const Standard_Integer theNbIterations)
|
||||||
TolX(1, F.NbVariables()),
|
|
||||||
TolF(FTol),
|
: TolX (1, theFunction.NbVariables()),
|
||||||
Indx(1, F.NbVariables()),
|
TolF (theFTolerance),
|
||||||
Scratch(1, F.NbVariables()),
|
Indx (1, theFunction.NbVariables()),
|
||||||
Sol(1, F.NbVariables()),
|
Scratch (1, theFunction.NbVariables()),
|
||||||
DeltaX(1, F.NbVariables()),
|
Sol (1, theFunction.NbVariables()),
|
||||||
FValues(1, F.NbVariables()),
|
DeltaX (1, theFunction.NbVariables()),
|
||||||
Jacobian(1, F.NbVariables(),
|
FValues (1, theFunction.NbVariables()),
|
||||||
1, F.NbVariables()),
|
Jacobian(1, theFunction.NbVariables(), 1, theFunction.NbVariables()),
|
||||||
Itermax(NbIterations)
|
Done (Standard_False),
|
||||||
|
State (0),
|
||||||
|
Iter (0),
|
||||||
|
Itermax (theNbIterations)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
math_NewtonFunctionSetRoot::math_NewtonFunctionSetRoot
|
//function : ~math_NewtonFunctionSetRoot
|
||||||
(math_FunctionSetWithDerivatives& F,
|
//purpose : Destructor
|
||||||
const math_Vector& StartingPoint,
|
//=======================================================================
|
||||||
const math_Vector& XTol,
|
|
||||||
const Standard_Real FTol,
|
|
||||||
const Standard_Integer NbIterations) :
|
|
||||||
|
|
||||||
TolX(1, F.NbVariables()),
|
|
||||||
TolF(FTol),
|
|
||||||
Indx (1, F.NbVariables()),
|
|
||||||
Scratch (1, F.NbVariables()),
|
|
||||||
Sol (1, F.NbVariables()),
|
|
||||||
DeltaX (1, F.NbVariables()),
|
|
||||||
FValues (1, F.NbVariables()),
|
|
||||||
Jacobian(1, F.NbVariables(),
|
|
||||||
1, F.NbVariables()),
|
|
||||||
Itermax(NbIterations)
|
|
||||||
{
|
|
||||||
for (Standard_Integer i = 1; i <= TolX.Length(); i++) {
|
|
||||||
TolX(i) = XTol(i);
|
|
||||||
}
|
|
||||||
math_Vector UFirst(1, F.NbVariables()),
|
|
||||||
ULast(1, F.NbVariables());
|
|
||||||
UFirst.Init(RealFirst());
|
|
||||||
ULast.Init(RealLast());
|
|
||||||
Perform(F, StartingPoint, UFirst, ULast);
|
|
||||||
}
|
|
||||||
|
|
||||||
math_NewtonFunctionSetRoot::math_NewtonFunctionSetRoot
|
|
||||||
(math_FunctionSetWithDerivatives& F,
|
|
||||||
const math_Vector& StartingPoint,
|
|
||||||
const math_Vector& InfBound,
|
|
||||||
const math_Vector& SupBound,
|
|
||||||
const math_Vector& XTol,
|
|
||||||
const Standard_Real FTol,
|
|
||||||
const Standard_Integer NbIterations) :
|
|
||||||
|
|
||||||
TolX(1, F.NbVariables()),
|
|
||||||
TolF(FTol),
|
|
||||||
Indx (1, F.NbVariables()),
|
|
||||||
Scratch (1, F.NbVariables()),
|
|
||||||
Sol (1, F.NbVariables()),
|
|
||||||
DeltaX (1, F.NbVariables()),
|
|
||||||
FValues (1, F.NbVariables()),
|
|
||||||
Jacobian(1, F.NbVariables(),
|
|
||||||
1, F.NbVariables()),
|
|
||||||
Itermax(NbIterations)
|
|
||||||
{
|
|
||||||
for (Standard_Integer i = 1; i <= TolX.Length(); i++) {
|
|
||||||
TolX(i) = XTol(i);
|
|
||||||
}
|
|
||||||
Perform(F, StartingPoint, InfBound, SupBound);
|
|
||||||
}
|
|
||||||
|
|
||||||
math_NewtonFunctionSetRoot::~math_NewtonFunctionSetRoot()
|
math_NewtonFunctionSetRoot::~math_NewtonFunctionSetRoot()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void math_NewtonFunctionSetRoot::SetTolerance
|
//=======================================================================
|
||||||
(const math_Vector& XTol)
|
//function : SetTolerance
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
|
void math_NewtonFunctionSetRoot::SetTolerance(const math_Vector& theXTolerance)
|
||||||
{
|
{
|
||||||
for (Standard_Integer i = 1; i <= TolX.Length(); i++) {
|
for (Standard_Integer i = 1; i <= TolX.Length(); ++i)
|
||||||
TolX(i) = XTol(i);
|
TolX(i) = theXTolerance(i);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : Perform
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
|
void math_NewtonFunctionSetRoot::Perform(
|
||||||
|
math_FunctionSetWithDerivatives& theFunction,
|
||||||
|
const math_Vector& theStartingPoint)
|
||||||
|
{
|
||||||
|
const math_Vector anInf(1, theFunction.NbVariables(), RealFirst());
|
||||||
|
const math_Vector aSup (1, theFunction.NbVariables(), RealLast ());
|
||||||
|
|
||||||
|
Perform(theFunction, theStartingPoint, anInf, aSup);
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : Perform
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
void math_NewtonFunctionSetRoot::Perform(
|
void math_NewtonFunctionSetRoot::Perform(
|
||||||
math_FunctionSetWithDerivatives& F,
|
math_FunctionSetWithDerivatives& F,
|
||||||
const math_Vector& StartingPoint,
|
const math_Vector& StartingPoint,
|
||||||
@@ -184,6 +149,10 @@ void math_NewtonFunctionSetRoot::Perform(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : Dump
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
void math_NewtonFunctionSetRoot::Dump(Standard_OStream& o) const
|
void math_NewtonFunctionSetRoot::Dump(Standard_OStream& o) const
|
||||||
{
|
{
|
||||||
o <<"math_NewtonFunctionSetRoot ";
|
o <<"math_NewtonFunctionSetRoot ";
|
||||||
|
@@ -14,8 +14,23 @@
|
|||||||
|
|
||||||
#include <StdFail_NotDone.hxx>
|
#include <StdFail_NotDone.hxx>
|
||||||
|
|
||||||
inline Standard_Boolean math_NewtonFunctionSetRoot::IsDone() const
|
inline void math_NewtonFunctionSetRoot::Delete() const
|
||||||
{ return Done;}
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Standard_Boolean math_NewtonFunctionSetRoot::IsSolutionReached(math_FunctionSetWithDerivatives&)
|
||||||
|
{
|
||||||
|
for (Standard_Integer i = DeltaX.Lower(); i <= DeltaX.Upper(); ++i)
|
||||||
|
if ( Abs(DeltaX(i)) > TolX(i) || Abs(FValues(i)) > TolF )
|
||||||
|
return Standard_False;
|
||||||
|
|
||||||
|
return Standard_True;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Standard_Boolean math_NewtonFunctionSetRoot::IsDone() const
|
||||||
|
{
|
||||||
|
return Done;
|
||||||
|
}
|
||||||
|
|
||||||
inline Standard_OStream& operator<<(Standard_OStream& o,
|
inline Standard_OStream& operator<<(Standard_OStream& o,
|
||||||
const math_NewtonFunctionSetRoot& N)
|
const math_NewtonFunctionSetRoot& N)
|
||||||
|
@@ -28,57 +28,41 @@ raises NotDone, DimensionError
|
|||||||
|
|
||||||
is
|
is
|
||||||
|
|
||||||
Create(F: in out MultipleVarFunctionWithHessian;
|
Create(theFunction: in MultipleVarFunctionWithHessian;
|
||||||
StartingPoint: Vector;
|
theTolerance: Real=1.0e-7;
|
||||||
Tolerance: Real=1.0e-7;
|
theNbIterations: Integer=40;
|
||||||
NbIterations: Integer=40;
|
theConvexity: Real=1.0e-6;
|
||||||
Convexity: Real=1.0e-6;
|
theWithSingularity: Boolean = Standard_True)
|
||||||
WithSingularity : Boolean = Standard_True)
|
---Purpose:
|
||||||
---Purpose: -- Given the starting point StartingPoint,
|
-- The tolerance required on the solution is given by Tolerance.
|
||||||
-- The tolerance required on the solution is given by
|
-- Iteration are stopped if (!WithSingularity) and H(F(Xi)) is not definite
|
||||||
-- Tolerance.
|
-- positive (if the smaller eigenvalue of H < Convexity)
|
||||||
-- Iteration are stopped if
|
-- or IsConverged() returns True for 2 successives Iterations.
|
||||||
-- (!WithSingularity) and H(F(Xi)) is not definite
|
-- Warning: This constructor does not perform computation.
|
||||||
-- positive (if the smaller eigenvalue of H < Convexity)
|
|
||||||
-- or IsConverged() returns True for 2 successives Iterations.
|
|
||||||
-- Warning: Obsolete Constructor (because IsConverged can not be redefined
|
|
||||||
-- with this. )
|
|
||||||
returns NewtonMinimum;
|
returns NewtonMinimum;
|
||||||
|
|
||||||
Create(F: in out MultipleVarFunctionWithHessian;
|
|
||||||
Tolerance: Real=1.0e-7;
|
Perform(me: in out; theFunction: in out MultipleVarFunctionWithHessian;
|
||||||
NbIterations: Integer=40;
|
theStartingPoint: Vector)
|
||||||
Convexity: Real=1.0e-6;
|
---Purpose: Search the solution.
|
||||||
WithSingularity : Boolean = Standard_True)
|
|
||||||
---Purpose:
|
|
||||||
-- The tolerance required on the solution is given by
|
|
||||||
-- Tolerance.
|
|
||||||
-- Iteration are stopped if
|
|
||||||
-- (!WithSingularity) and H(F(Xi)) is not definite
|
|
||||||
-- positive (if the smaller eigenvalue of H < Convexity)
|
|
||||||
-- or IsConverged() returns True for 2 successives Iterations.
|
|
||||||
-- Warning: This constructor do not computation
|
|
||||||
returns NewtonMinimum;
|
|
||||||
|
|
||||||
---C++: alias " Standard_EXPORT virtual ~math_NewtonMinimum();"
|
|
||||||
|
|
||||||
Perform(me: in out; F: in out MultipleVarFunctionWithHessian;
|
|
||||||
StartingPoint: Vector)
|
|
||||||
---Purpose: Search the solution.
|
|
||||||
is static;
|
is static;
|
||||||
|
|
||||||
|
|
||||||
|
Delete(me) is static;
|
||||||
|
---Purpose: Destructor alias.
|
||||||
|
---C++: inline
|
||||||
|
---C++: alias " Standard_EXPORT virtual ~math_NewtonMinimum();"
|
||||||
|
|
||||||
|
|
||||||
IsConverged(me)
|
IsConverged(me)
|
||||||
---Purpose: This method is called at the end of each
|
---Purpose:
|
||||||
-- iteration to check the convergence :
|
-- This method is called at the end of each iteration to check the convergence:
|
||||||
-- || Xi+1 - Xi || < Tolerance
|
-- || Xi+1 - Xi || < Tolerance or || F(Xi+1) - F(Xi)|| < Tolerance * || F(Xi) ||
|
||||||
-- or || F(Xi+1) - F(Xi)|| < Tolerance * || F(Xi) ||
|
-- It can be redefined in a sub-class to implement a specific test.
|
||||||
-- It can be redefined in a sub-class to implement a specific test.
|
---C++: inline
|
||||||
|
returns Boolean is virtual;
|
||||||
returns Boolean
|
|
||||||
is virtual;
|
|
||||||
|
|
||||||
|
|
||||||
IsDone(me)
|
IsDone(me)
|
||||||
---Purpose: Tests if an error has occured.
|
---Purpose: Tests if an error has occured.
|
||||||
---C++: inline
|
---C++: inline
|
||||||
|
@@ -25,58 +25,49 @@
|
|||||||
#include <math_Gauss.hxx>
|
#include <math_Gauss.hxx>
|
||||||
#include <math_Jacobi.hxx>
|
#include <math_Jacobi.hxx>
|
||||||
|
|
||||||
//============================================================================
|
//=======================================================================
|
||||||
math_NewtonMinimum::math_NewtonMinimum(math_MultipleVarFunctionWithHessian& F,
|
//function : math_NewtonMinimum
|
||||||
const math_Vector& StartingPoint,
|
//purpose : Constructor
|
||||||
const Standard_Real Tolerance,
|
//=======================================================================
|
||||||
const Standard_Integer NbIterations,
|
math_NewtonMinimum::math_NewtonMinimum(
|
||||||
const Standard_Real Convexity,
|
const math_MultipleVarFunctionWithHessian& theFunction,
|
||||||
const Standard_Boolean WithSingularity)
|
const Standard_Real theTolerance,
|
||||||
//============================================================================
|
const Standard_Integer theNbIterations,
|
||||||
: TheLocation(1, F.NbVariables()),
|
const Standard_Real theConvexity,
|
||||||
TheGradient(1, F.NbVariables()),
|
const Standard_Boolean theWithSingularity
|
||||||
TheStep(1, F.NbVariables(), 10*Tolerance),
|
)
|
||||||
TheHessian(1, F.NbVariables(), 1, F.NbVariables() )
|
: TheStatus (math_NotBracketed),
|
||||||
|
TheLocation(1, theFunction.NbVariables()),
|
||||||
|
TheGradient(1, theFunction.NbVariables()),
|
||||||
|
TheStep (1, theFunction.NbVariables(), 10.0 * theTolerance),
|
||||||
|
TheHessian (1, theFunction.NbVariables(), 1, theFunction.NbVariables()),
|
||||||
|
PreviousMinimum (0.0),
|
||||||
|
TheMinimum (0.0),
|
||||||
|
MinEigenValue (0.0),
|
||||||
|
XTol (theTolerance),
|
||||||
|
CTol (theConvexity),
|
||||||
|
nbiter (0),
|
||||||
|
NoConvexTreatement(theWithSingularity),
|
||||||
|
Convex (Standard_True),
|
||||||
|
Done (Standard_False),
|
||||||
|
Itermax (theNbIterations)
|
||||||
{
|
{
|
||||||
XTol = Tolerance;
|
|
||||||
CTol = Convexity;
|
|
||||||
Itermax = NbIterations;
|
|
||||||
NoConvexTreatement = WithSingularity;
|
|
||||||
Convex = Standard_True;
|
|
||||||
// Done = Standard_True;
|
|
||||||
// TheStatus = math_OK;
|
|
||||||
Perform ( F, StartingPoint);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
//=======================================================================
|
||||||
math_NewtonMinimum::math_NewtonMinimum(math_MultipleVarFunctionWithHessian& F,
|
//function : ~math_NewtonMinimum
|
||||||
const Standard_Real Tolerance,
|
//purpose : Destructor
|
||||||
const Standard_Integer NbIterations,
|
//=======================================================================
|
||||||
const Standard_Real Convexity,
|
|
||||||
const Standard_Boolean WithSingularity)
|
|
||||||
//============================================================================
|
|
||||||
: TheLocation(1, F.NbVariables()),
|
|
||||||
TheGradient(1, F.NbVariables()),
|
|
||||||
TheStep(1, F.NbVariables(), 10*Tolerance),
|
|
||||||
TheHessian(1, F.NbVariables(), 1, F.NbVariables() )
|
|
||||||
{
|
|
||||||
XTol = Tolerance;
|
|
||||||
CTol = Convexity;
|
|
||||||
Itermax = NbIterations;
|
|
||||||
NoConvexTreatement = WithSingularity;
|
|
||||||
Convex = Standard_True;
|
|
||||||
Done = Standard_False;
|
|
||||||
TheStatus = math_NotBracketed;
|
|
||||||
}
|
|
||||||
//============================================================================
|
|
||||||
math_NewtonMinimum::~math_NewtonMinimum()
|
math_NewtonMinimum::~math_NewtonMinimum()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
//=======================================================================
|
||||||
|
//function : Perform
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
void math_NewtonMinimum::Perform(math_MultipleVarFunctionWithHessian& F,
|
void math_NewtonMinimum::Perform(math_MultipleVarFunctionWithHessian& F,
|
||||||
const math_Vector& StartingPoint)
|
const math_Vector& StartingPoint)
|
||||||
//============================================================================
|
|
||||||
{
|
{
|
||||||
math_Vector Point1 (1, F.NbVariables());
|
math_Vector Point1 (1, F.NbVariables());
|
||||||
Point1 = StartingPoint;
|
Point1 = StartingPoint;
|
||||||
@@ -191,26 +182,20 @@ void math_NewtonMinimum::Perform(math_MultipleVarFunctionWithHessian& F,
|
|||||||
TheLocation = *precedent;
|
TheLocation = *precedent;
|
||||||
}
|
}
|
||||||
|
|
||||||
//============================================================================
|
//=======================================================================
|
||||||
Standard_Boolean math_NewtonMinimum::IsConverged() const
|
//function : Dump
|
||||||
//============================================================================
|
//purpose :
|
||||||
{
|
//=======================================================================
|
||||||
return ( (TheStep.Norm() <= XTol ) ||
|
|
||||||
( Abs(TheMinimum-PreviousMinimum) <= XTol*Abs(PreviousMinimum) ));
|
|
||||||
}
|
|
||||||
|
|
||||||
//============================================================================
|
|
||||||
void math_NewtonMinimum::Dump(Standard_OStream& o) const
|
void math_NewtonMinimum::Dump(Standard_OStream& o) const
|
||||||
//============================================================================
|
|
||||||
{
|
{
|
||||||
o<< "math_Newton Optimisation: ";
|
o<< "math_Newton Optimisation: ";
|
||||||
o << " Done =" << Done << endl;
|
o << " Done =" << Done << endl;
|
||||||
o << " Status = " << (Standard_Integer)TheStatus << endl;
|
o << " Status = " << (Standard_Integer)TheStatus << endl;
|
||||||
o <<" Location Vector = " << Location() << endl;
|
o << " Location Vector = " << Location() << endl;
|
||||||
o <<" Minimum value = "<< Minimum()<< endl;
|
o << " Minimum value = "<< Minimum()<< endl;
|
||||||
o <<" Previous value = "<< PreviousMinimum << endl;
|
o << " Previous value = "<< PreviousMinimum << endl;
|
||||||
o <<" Number of iterations = " <<NbIterations() << endl;
|
o << " Number of iterations = " <<NbIterations() << endl;
|
||||||
o <<" Convexity = " << Convex << endl;
|
o << " Convexity = " << Convex << endl;
|
||||||
o <<" Eigen Value = " << MinEigenValue << endl;
|
o << " Eigen Value = " << MinEigenValue << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -16,6 +16,16 @@
|
|||||||
|
|
||||||
#include <StdFail_NotDone.hxx>
|
#include <StdFail_NotDone.hxx>
|
||||||
|
|
||||||
|
inline void math_NewtonMinimum::Delete() const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Standard_Boolean math_NewtonMinimum::IsConverged() const
|
||||||
|
{
|
||||||
|
return ( (TheStep.Norm() <= XTol ) ||
|
||||||
|
( Abs(TheMinimum-PreviousMinimum) <= XTol * Abs(PreviousMinimum) ));
|
||||||
|
}
|
||||||
|
|
||||||
inline Standard_Boolean math_NewtonMinimum::IsDone() const
|
inline Standard_Boolean math_NewtonMinimum::IsDone() const
|
||||||
{
|
{
|
||||||
return Done;
|
return Done;
|
||||||
|
@@ -27,52 +27,37 @@ raises NotDone from StdFail,
|
|||||||
|
|
||||||
is
|
is
|
||||||
|
|
||||||
Create(F: in out MultipleVarFunction; StartingPoint: Vector;
|
Create(theFunction: in MultipleVarFunction;
|
||||||
StartingDirections: Matrix; Tolerance: Real;
|
theTolerance: Real; theNbIterations: Integer = 200; theZEPS: Real = 1.0e-12)
|
||||||
NbIterations: Integer=200; ZEPS: Real=1.0e-12)
|
---Purpose: Constructor. Initialize new entity.
|
||||||
---Purpose:
|
|
||||||
-- Computes Powell minimization on the function F given
|
|
||||||
-- StartingPoint, and an initial matrix StartingDirection
|
|
||||||
-- whose columns contain the initial set of directions. 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 Powell;
|
|
||||||
|
|
||||||
|
|
||||||
Create(F: in out MultipleVarFunction;
|
|
||||||
Tolerance: Real;
|
|
||||||
NbIterations: Integer = 200;
|
|
||||||
ZEPS: Real = 1.0e-12)
|
|
||||||
---Purpose: is used in a sub-class to initialize correctly all the fields
|
|
||||||
-- of this class.
|
|
||||||
|
|
||||||
returns Powell;
|
returns Powell;
|
||||||
|
|
||||||
|
|
||||||
|
Delete(me) is static;
|
||||||
|
---Purpose: Destructor alias
|
||||||
|
---C++: inline
|
||||||
---C++: alias " Standard_EXPORT virtual ~math_Powell();"
|
---C++: alias " Standard_EXPORT virtual ~math_Powell();"
|
||||||
|
|
||||||
Perform(me: in out;F: in out MultipleVarFunction;
|
|
||||||
StartingPoint: Vector;
|
|
||||||
StartingDirections: Matrix)
|
|
||||||
---Purpose: Use this method after a call to the initialization constructor
|
|
||||||
-- to compute the minimum of function F.
|
|
||||||
-- Warning
|
|
||||||
-- The initialization constructor must have been called before
|
|
||||||
-- the Perform method is called.
|
|
||||||
|
|
||||||
|
|
||||||
|
Perform(me: in out; theFunction: in out MultipleVarFunction; theStartingPoint: Vector; theStartingDirections: Matrix)
|
||||||
|
---Purpose:
|
||||||
|
-- Computes Powell minimization on the function F given
|
||||||
|
-- theStartingPoint, and an initial matrix theStartingDirection
|
||||||
|
-- whose columns contain the initial set of directions.
|
||||||
|
-- The solution F = Fi is found when:
|
||||||
|
-- 2.0 * abs(Fi - Fi-1) =< Tolerance * (abs(Fi) + abs(Fi-1) + ZEPS).
|
||||||
is static;
|
is static;
|
||||||
|
|
||||||
|
|
||||||
IsSolutionReached(me: in out; F: in out MultipleVarFunction)
|
IsSolutionReached(me: in out; theFunction: in out MultipleVarFunction)
|
||||||
---Purpose:
|
---Purpose:
|
||||||
-- solution F = Fi is found when :
|
-- Solution F = Fi is found when:
|
||||||
-- 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1)) + ZEPS.
|
-- 2.0 * abs(Fi - Fi-1) <= Tolerance * (abs(Fi) + abs(Fi-1)) + ZEPS.
|
||||||
-- The maximum number of iterations allowed is given by NbIterations.
|
-- The maximum number of iterations allowed is given by NbIterations.
|
||||||
|
---C++: inline
|
||||||
returns Boolean
|
returns Boolean is virtual;
|
||||||
is virtual;
|
|
||||||
|
|
||||||
|
|
||||||
IsDone(me)
|
IsDone(me)
|
||||||
---Purpose: Returns true if the computations are successful, otherwise returns false.
|
---Purpose: Returns true if the computations are successful, otherwise returns false.
|
||||||
---C++: inline
|
---C++: inline
|
||||||
@@ -150,4 +135,3 @@ State: Integer;
|
|||||||
Itermax: Integer;
|
Itermax: Integer;
|
||||||
|
|
||||||
end Powell;
|
end Powell;
|
||||||
|
|
||||||
|
@@ -92,7 +92,8 @@ static Standard_Boolean MinimizeDirection(math_Vector& P,
|
|||||||
math_BracketMinimum Bracket(F, 0.0, 1.0);
|
math_BracketMinimum Bracket(F, 0.0, 1.0);
|
||||||
if (Bracket.IsDone()) {
|
if (Bracket.IsDone()) {
|
||||||
Bracket.Values(ax, xx, bx);
|
Bracket.Values(ax, xx, bx);
|
||||||
math_BrentMinimum Sol(F, ax, xx, bx, 1.0e-10, 100);
|
math_BrentMinimum Sol(1.0e-10);
|
||||||
|
Sol.Perform(F, ax, xx, bx);
|
||||||
if (Sol.IsDone()) {
|
if (Sol.IsDone()) {
|
||||||
Standard_Real Scale = Sol.Location();
|
Standard_Real Scale = Sol.Location();
|
||||||
Result = Sol.Minimum();
|
Result = Sol.Minimum();
|
||||||
@@ -104,15 +105,45 @@ static Standard_Boolean MinimizeDirection(math_Vector& P,
|
|||||||
return Standard_False;
|
return Standard_False;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : math_Powell
|
||||||
|
//purpose : Constructor
|
||||||
|
//=======================================================================
|
||||||
|
math_Powell::math_Powell(const math_MultipleVarFunction& theFunction,
|
||||||
|
const Standard_Real theTolerance,
|
||||||
|
const Standard_Integer theNbIterations,
|
||||||
|
const Standard_Real theZEPS)
|
||||||
|
: TheLocation (1, theFunction.NbVariables()),
|
||||||
|
TheMinimum (RealLast()),
|
||||||
|
TheLocationError(RealLast()),
|
||||||
|
PreviousMinimum (RealLast()),
|
||||||
|
XTol (theTolerance),
|
||||||
|
EPSZ (theZEPS),
|
||||||
|
Done (Standard_False),
|
||||||
|
Iter (0),
|
||||||
|
TheStatus (math_NotBracketed),
|
||||||
|
TheDirections (1, theFunction.NbVariables(), 1, theFunction.NbVariables()),
|
||||||
|
State (0),
|
||||||
|
Itermax (theNbIterations)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : ~math_Powell
|
||||||
|
//purpose : Destructor
|
||||||
|
//=======================================================================
|
||||||
math_Powell::~math_Powell()
|
math_Powell::~math_Powell()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : Perform
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
void math_Powell::Perform(math_MultipleVarFunction& F,
|
void math_Powell::Perform(math_MultipleVarFunction& F,
|
||||||
const math_Vector& StartingPoint,
|
const math_Vector& StartingPoint,
|
||||||
const math_Matrix& StartingDirections) {
|
const math_Matrix& StartingDirections)
|
||||||
|
{
|
||||||
|
|
||||||
Done = Standard_False;
|
Done = Standard_False;
|
||||||
Standard_Integer i, ibig, j;
|
Standard_Integer i, ibig, j;
|
||||||
Standard_Real t, fptt, del;
|
Standard_Real t, fptt, del;
|
||||||
@@ -195,48 +226,13 @@ void math_Powell::Perform(math_MultipleVarFunction& F,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Standard_Boolean math_Powell::IsSolutionReached(
|
|
||||||
// math_MultipleVarFunction& F) {
|
|
||||||
math_MultipleVarFunction& ) {
|
|
||||||
|
|
||||||
return 2.0*fabs(PreviousMinimum - TheMinimum) <=
|
|
||||||
XTol*(fabs(PreviousMinimum)+fabs(TheMinimum) + EPSZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
math_Powell::math_Powell(math_MultipleVarFunction& F,
|
|
||||||
const math_Vector& StartingPoint,
|
|
||||||
const math_Matrix& StartingDirections,
|
|
||||||
const Standard_Real Tolerance,
|
|
||||||
const Standard_Integer NbIterations,
|
|
||||||
const Standard_Real ZEPS) :
|
|
||||||
TheLocation(1, F.NbVariables()),
|
|
||||||
TheDirections(1, F.NbVariables(),
|
|
||||||
1, F.NbVariables()) {
|
|
||||||
|
|
||||||
XTol = Tolerance;
|
|
||||||
EPSZ = ZEPS;
|
|
||||||
Itermax = NbIterations;
|
|
||||||
Perform(F, StartingPoint, StartingDirections);
|
|
||||||
}
|
|
||||||
|
|
||||||
math_Powell::math_Powell(math_MultipleVarFunction& F,
|
|
||||||
const Standard_Real Tolerance,
|
|
||||||
const Standard_Integer NbIterations,
|
|
||||||
const Standard_Real ZEPS) :
|
|
||||||
TheLocation(1, F.NbVariables()),
|
|
||||||
TheDirections(1, F.NbVariables(),
|
|
||||||
1, F.NbVariables()) {
|
|
||||||
|
|
||||||
XTol = Tolerance;
|
|
||||||
EPSZ = ZEPS;
|
|
||||||
Itermax = NbIterations;
|
|
||||||
}
|
|
||||||
|
|
||||||
void math_Powell::Dump(Standard_OStream& o) const {
|
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : Dump
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
|
void math_Powell::Dump(Standard_OStream& o) const
|
||||||
|
{
|
||||||
o << "math_Powell resolution:";
|
o << "math_Powell resolution:";
|
||||||
if(Done) {
|
if(Done) {
|
||||||
o << " Status = Done \n";
|
o << " Status = Done \n";
|
||||||
|
@@ -15,7 +15,20 @@
|
|||||||
#include <StdFail_NotDone.hxx>
|
#include <StdFail_NotDone.hxx>
|
||||||
#include <math_Vector.hxx>
|
#include <math_Vector.hxx>
|
||||||
|
|
||||||
inline Standard_Boolean math_Powell::IsDone() const { return Done; }
|
inline void math_Powell::Delete() const
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Standard_Boolean math_Powell::IsSolutionReached(math_MultipleVarFunction&)
|
||||||
|
{
|
||||||
|
return 2.0 * fabs(PreviousMinimum - TheMinimum) <=
|
||||||
|
XTol * (fabs(PreviousMinimum) + fabs(TheMinimum) + EPSZ);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline Standard_Boolean math_Powell::IsDone() const
|
||||||
|
{
|
||||||
|
return Done;
|
||||||
|
}
|
||||||
|
|
||||||
inline Standard_OStream& operator<<(Standard_OStream& o,
|
inline Standard_OStream& operator<<(Standard_OStream& o,
|
||||||
const math_Powell& P)
|
const math_Powell& P)
|
||||||
|
Reference in New Issue
Block a user