From 03c3539dbfac10e38abc5f7fec8fefb8966d388e Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Mon, 23 Apr 2018 14:20:15 +0200 Subject: [PATCH] GCS: Improvement in redundant constraint detection ================================================== The solver uses some heuristics to determine the "redundant to remove" and notify it to the user. Basically it would pick the solver redundant constraint that affects most groups of redundants (popularity contest). In the simple cases, all the redundants are equally popular and the popularity contest is untied by using the tagid (let say for simplicity it is the number at sketcher level Constraint3, the tagid=3). This means that in simple cases, the solver systematically decides that the redundant constraint to handle from those showing a linear dependency is the one appearing the last. This commits changes the way to untie the popularity contest, by giving more priority to those sketcher constraints that need a lower number of solver constraints (in other words, those constraints that remove a lower amount of DoF). In case of tie, the tagid is then used to break the tie. At least: fixes #3434 fixes #1557 --- src/Mod/Sketcher/App/planegcs/GCS.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Mod/Sketcher/App/planegcs/GCS.cpp b/src/Mod/Sketcher/App/planegcs/GCS.cpp index 4e8bee11c9..ceff36fa6f 100644 --- a/src/Mod/Sketcher/App/planegcs/GCS.cpp +++ b/src/Mod/Sketcher/App/planegcs/GCS.cpp @@ -3685,7 +3685,10 @@ int System::diagnose(Algorithm alg) if (result1 == std::end(pdrivenlist)) pdiagnoselist.push_back(plist[j]); } - + + // map tag to a tag multiplicity (the number of solver constraints associated with the same tag) + std::map< int , int> tagmultiplicity; + Eigen::MatrixXd J(clist.size(), pdiagnoselist.size()); int count=0; for (std::vector::iterator constr=clist.begin(); constr != clist.end(); ++constr) { @@ -3695,6 +3698,12 @@ int System::diagnose(Algorithm alg) for (int j=0; j < int(pdiagnoselist.size()); j++) { J(count-1,j) = (*constr)->grad(pdiagnoselist[j]); } + + // parallel processing: create tag multiplicity map + if(tagmultiplicity.find((*constr)->getTag()) == tagmultiplicity.end()) + tagmultiplicity[(*constr)->getTag()] = 0; + else + tagmultiplicity[(*constr)->getTag()]++; } } @@ -4021,7 +4030,13 @@ int System::diagnose(Algorithm alg) it != conflictingMap.end(); ++it) { if (static_cast(it->second.size()) > maxPopularity || (static_cast(it->second.size()) == maxPopularity && mostPopular && - it->first->getTag() > mostPopular->getTag())) { + tagmultiplicity[it->first->getTag()] < tagmultiplicity[mostPopular->getTag()]) || + + (static_cast(it->second.size()) == maxPopularity && mostPopular && + tagmultiplicity[it->first->getTag()] == tagmultiplicity[mostPopular->getTag()] && + it->first->getTag() > mostPopular->getTag()) + + ) { mostPopular = it->first; maxPopularity = it->second.size(); }