+ add Levenberg-Marquardt and DogLeg algorithms in freegcs (from ickby)

+ use fallback solvers in Sketch::solve and ask for users feedback
+ improve tooltip text


git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5112 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
logari81
2011-11-10 18:29:52 +00:00
parent 6a9dff8129
commit 5f186325e5
4 changed files with 374 additions and 23 deletions

View File

@@ -1303,22 +1303,51 @@ int Sketch::addSymmetricConstraint(int geoId1, PointPos pos1, int geoId2, PointP
int Sketch::solve() {
if (!isInitMove) {
GCSsys.clearByTag(-1);
GCSsys.clearByTag(-2);
InitParameters.resize(Parameters.size());
int i=0;
for (std::vector<double*>::iterator it = Parameters.begin(); it != Parameters.end(); ++it, i++) {
InitParameters[i] = **it;
GCSsys.addConstraintEqual(*it, &InitParameters[i], -2);
}
GCSsys.initSolution(Parameters);
}
Base::TimeInfo start_time;
// solving with freegcs
int ret = GCSsys.solve();
// (either with SQP solver for two subsystems or
// with the default DogLeg solver for a single subsystem)
int ret = GCSsys.solve(GCS::DogLeg);
if (ret != GCS::Success && !isInitMove) {
// if we are not in dragging mode and the solver fails we try
// alternative solvers
ret = GCSsys.solve(GCS::BFGS);
if (ret == GCS::Success) {
Base::Console().Warning("Important: the BFGS solver succeeded where the DogLeg solver had failed.\n");
Base::Console().Warning("If you see this message please report a way of reproducing this result at\n");
Base::Console().Warning("https://sourceforge.net/apps/mantisbt/free-cad/main_page.php\n");
}
else {
ret = GCSsys.solve(GCS::LevenbergMarquardt);
if (ret == GCS::Success) {
Base::Console().Warning("Important: the LevenbergMarquardt solver succeeded where the DogLeg and BFGS solvers have failed.\n");
Base::Console().Warning("If you see this message please report a way of reproducing this result at\n");
Base::Console().Warning("https://sourceforge.net/apps/mantisbt/free-cad/main_page.php\n");
} else {
// last resort: augment the system with a second subsystem and use the SQP solver
GCSsys.clearByTag(-1);
GCSsys.clearByTag(-2);
InitParameters.resize(Parameters.size());
int i=0;
for (std::vector<double*>::iterator it = Parameters.begin(); it != Parameters.end(); ++it, i++) {
InitParameters[i] = **it;
GCSsys.addConstraintEqual(*it, &InitParameters[i], -2);
}
GCSsys.initSolution(Parameters);
ret = GCSsys.solve();
if (ret == GCS::Success) {
Base::Console().Warning("Important: the SQP solver succeeded where all single subsystem solvers have failed.\n");
Base::Console().Warning("If you see this message please report a way of reproducing this result at\n");
Base::Console().Warning("https://sourceforge.net/apps/mantisbt/free-cad/main_page.php\n");
}
}
}
}
// if successfully solve write the parameter back
if (ret == GCS::Success) {
GCSsys.applySolution();