From: azv Date: Tue, 11 Sep 2018 05:08:05 +0000 (+0300) Subject: Issue #2617: Use a sequence of solvers X-Git-Tag: V9_2_0a1~35 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=138377e120674c0ba848b03e013f248d8bbcf20c;p=modules%2Fshaper.git Issue #2617: Use a sequence of solvers Use Levenberg-Marquardt solver every time when DogLeg is failed to solve a set of constraints. --- diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp index a49487878..f4cfa9942 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp @@ -165,6 +165,12 @@ PlaneGCSSolver_Solver::SolveStatus PlaneGCSSolver_Solver::solve() diagnose(); aResult = (GCS::SolveStatus)myEquationSystem->solve(myParameters); } + + if (aResult == GCS::Failed) { + // DogLeg solver failed without conflicting constraints, try to use Levenberg-Marquardt solver + aResult = (GCS::SolveStatus)myEquationSystem->solve(myParameters, true, + GCS::LevenbergMarquardt); + } Events_LongOp::end(this); // collect information about conflicting constraints every time, @@ -173,30 +179,6 @@ PlaneGCSSolver_Solver::SolveStatus PlaneGCSSolver_Solver::solve() collectConflicting(); if (!myConflictingIDs.empty()) aResult = GCS::Failed; - else if (aResult == GCS::Failed) { - // DogLeg solver failed without conflicting constraints, try to use Levenberg-Marquardt solver - // if there are point-line distance constraints - ConstraintMap::iterator aCIt = myConstraints.begin(); - for (; aCIt != myConstraints.end(); ++aCIt) { - if (aCIt->second.size() <= 1) - continue; - std::set::const_iterator anIt = aCIt->second.begin(); - for (; anIt != aCIt->second.end(); ++anIt) - if ((*anIt)->getTypeId() == GCS::P2LDistance) - break; - if (anIt != aCIt->second.end()) - break; - } - - if (aCIt != myConstraints.end()) { - aResult = (GCS::SolveStatus)myEquationSystem->solve( - myParameters, true, GCS::LevenbergMarquardt); - myConfCollected = false; - collectConflicting(); - if (!myConflictingIDs.empty()) - aResult = GCS::Failed; - } - } SolveStatus aStatus; if (aResult == GCS::Failed) @@ -225,7 +207,7 @@ bool PlaneGCSSolver_Solver::isConflicting(const ConstraintID& theConstraint) con return myConflictingIDs.find((int)theConstraint) != myConflictingIDs.end(); } -void PlaneGCSSolver_Solver::collectConflicting() +void PlaneGCSSolver_Solver::collectConflicting(bool withRedundant) { GCS::VEC_I aConflict; myEquationSystem->getConflicting(aConflict); @@ -233,10 +215,12 @@ void PlaneGCSSolver_Solver::collectConflicting() for (GCS::VEC_I::const_iterator anIt = aConflict.begin(); anIt != aConflict.end(); ++anIt) myConflictingIDs.insert((*anIt) / THE_CONSTRAINT_MULT); - myEquationSystem->getRedundant(aConflict); - // convert PlaneGCS constraint IDs to SketchPlugin's ID - for (GCS::VEC_I::const_iterator anIt = aConflict.begin(); anIt != aConflict.end(); ++anIt) - myConflictingIDs.insert((*anIt) / THE_CONSTRAINT_MULT); + if (withRedundant) { + myEquationSystem->getRedundant(aConflict); + // convert PlaneGCS constraint IDs to SketchPlugin's ID + for (GCS::VEC_I::const_iterator anIt = aConflict.begin(); anIt != aConflict.end(); ++anIt) + myConflictingIDs.insert((*anIt) / THE_CONSTRAINT_MULT); + } myConfCollected = true; } diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h index 0b4ba42e6..7f302d8b6 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h @@ -83,7 +83,7 @@ public: int dof(); private: - void collectConflicting(); + void collectConflicting(bool withRedundant = true); /// \brief Add fictive constraint if the sketch contains temporary constraints only void addFictiveConstraintIfNecessary();