]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2617: Use a sequence of solvers
authorazv <azv@opencascade.com>
Tue, 11 Sep 2018 05:08:05 +0000 (08:08 +0300)
committerazv <azv@opencascade.com>
Fri, 14 Sep 2018 08:54:26 +0000 (11:54 +0300)
Use Levenberg-Marquardt solver every time when DogLeg is failed to solve a set of constraints.

src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h

index a49487878b7dbc309abfa6a8e21ef17e2513ceb9..f4cfa9942ebe9444d805b709e48cc6c4d930593e 100644 (file)
@@ -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<GCSConstraintPtr>::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;
 }
index 0b4ba42e650640f3a3f01052fb91182e2fdeaffd..7f302d8b66011b4f119faebeb8c58e2caae7ff3a 100644 (file)
@@ -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();