Sketcher: Improvements: Solver Advanced control

===============================================

- Increased solver debug
- Changing default values from float to string, as float has "only" a precision of 12 decimals.
- Default values as macros
This commit is contained in:
Abdullah Tahiri 2015-06-20 19:17:57 +02:00 committed by wmayer
parent 516b0d3c56
commit f3592c1216
4 changed files with 162 additions and 32 deletions

View File

@ -1112,6 +1112,18 @@ int System::solve_BFGS(SubSystem *subsys, bool isFine, bool isRedundantsolving)
int maxIterNumber = isRedundantsolving?
(sketchSizeMultiplierRedundant?maxIterRedundant * xsize:maxIterRedundant):
(sketchSizeMultiplier?maxIter * xsize:maxIter);
if(debugMode==IterationLevel) {
std::stringstream stream;
stream << "BFGS: convergence: " << (isRedundantsolving?convergenceRedundant:convergence)
<< ", xsize: " << xsize
<< ", maxIter: " << maxIterNumber << "\n";
const std::string tmp = stream.str();
Base::Console().Log(tmp.c_str());
}
double divergingLim = 1e6*err + 1e12;
double h_norm;
@ -1150,10 +1162,9 @@ int System::solve_BFGS(SubSystem *subsys, bool isFine, bool isRedundantsolving)
if(debugMode==IterationLevel) {
std::stringstream stream;
// Iteration: 1, residual: 1e-3, tolg: 1e-5, tolx: 1e-3
stream << "BFGS, Iteration: " << iter
<< ", err(eps): " << err
stream << "BFGS, Iteration: " << iter
<< ", err: " << err
<< ", h_norm: " << h_norm << "\n";
const std::string tmp = stream.str();
@ -1198,6 +1209,21 @@ int System::solve_LM(SubSystem* subsys, bool isRedundantsolving)
double eps=isRedundantsolving?LM_epsRedundant:LM_eps;
double eps1=isRedundantsolving?LM_eps1Redundant:LM_eps1;
double tau=isRedundantsolving?LM_tauRedundant:LM_tau;
if(debugMode==IterationLevel) {
std::stringstream stream;
stream << "LM: eps: " << eps
<< ", eps1: " << eps1
<< ", tau: " << tau
<< ", convergence: " << (isRedundantsolving?convergenceRedundant:convergence)
<< ", xsize: " << xsize
<< ", maxIter: " << maxIterNumber << "\n";
const std::string tmp = stream.str();
Base::Console().Log(tmp.c_str());
}
double nu=2, mu=0;
int iter=0, stop=0;
for (iter=0; iter < maxIterNumber && !stop; ++iter) {
@ -1328,12 +1354,30 @@ int System::solve_DL(SubSystem* subsys, bool isRedundantsolving)
double tolg=isRedundantsolving?DL_tolgRedundant:DL_tolg;
double tolx=isRedundantsolving?DL_tolxRedundant:DL_tolx;
double tolf=isRedundantsolving?DL_tolfRedundant:DL_tolf;
int xsize = subsys->pSize();
int csize = subsys->cSize();
if (xsize == 0)
return Success;
int maxIterNumber = isRedundantsolving?
(sketchSizeMultiplierRedundant?maxIterRedundant * xsize:maxIterRedundant):
(sketchSizeMultiplier?maxIter * xsize:maxIter);
if(debugMode==IterationLevel) {
std::stringstream stream;
stream << "DL: tolg: " << tolg
<< ", tolx: " << tolx
<< ", tolf: " << tolf
<< ", convergence: " << (isRedundantsolving?convergenceRedundant:convergence)
<< ", xsize: " << xsize
<< ", maxIter: " << maxIterNumber << "\n";
const std::string tmp = stream.str();
Base::Console().Log(tmp.c_str());
}
Eigen::VectorXd x(xsize), x_new(xsize);
Eigen::VectorXd fx(csize), fx_new(csize);
@ -1352,10 +1396,6 @@ int System::solve_DL(SubSystem* subsys, bool isRedundantsolving)
// get the infinity norm fx_inf and g_inf
double g_inf = g.lpNorm<Eigen::Infinity>();
double fx_inf = fx.lpNorm<Eigen::Infinity>();
int maxIterNumber = isRedundantsolving?
(sketchSizeMultiplierRedundant?maxIterRedundant * xsize:maxIterRedundant):
(sketchSizeMultiplier?maxIter * xsize:maxIter);
double divergingLim = 1e6*err + 1e12;

View File

@ -44,6 +44,20 @@
#include "ViewProviderSketch.h"
#define LM_EPS 1E-10
#define LM_EPS1 1E-80
#define LM_TAU 1E-3
#define DL_TOLG 1E-80
#define DL_TOLX 1E-80
#define DL_TOLF 1E-10
#define CONVERGENCE 1E-10
#define MAX_ITER 100
#define DEFAULT_SOLVER 2 // DL=2, LM=1, BFGS=0
#define DEFAULT_RSOLVER 2 // DL=2, LM=1, BFGS=0
#define DEFAULT_QRSOLVER 1 // DENSE=0, SPARSEQR=1
#define DEFAULT_SOLVER_DEBUG 1 // None=0, Minimal=1, IterationLevel=2
#define MAX_ITER_MULTIPLIER true
using namespace SketcherGui;
using namespace Gui::TaskView;
@ -62,7 +76,7 @@ TaskSketcherSolverAdvanced::TaskSketcherSolverAdvanced(ViewProviderSketch *sketc
ui->comboBoxDefaultSolver->onRestore();
ui->spinBoxMaxIter->onRestore();
ui->checkBoxSketchSizeMultiplier->onRestore();
ui->lineEditCovergence->onRestore();
ui->lineEditConvergence->onRestore();
ui->comboBoxQRMethod->onRestore();
ui->comboBoxRedundantDefaultSolver->onRestore();
ui->spinBoxRedundantSolverMaxIterations->onRestore();
@ -88,6 +102,9 @@ void TaskSketcherSolverAdvanced::updateDefaultMethodParameters(void)
ui->labelSolverParam1->setText(QString::fromLatin1(""));
ui->labelSolverParam2->setText(QString::fromLatin1(""));
ui->labelSolverParam3->setText(QString::fromLatin1(""));
ui->lineEditSolverParam1->clear();
ui->lineEditSolverParam2->clear();
ui->lineEditSolverParam3->clear();
ui->lineEditSolverParam1->setDisabled(true);
ui->lineEditSolverParam2->setDisabled(true);
ui->lineEditSolverParam3->setDisabled(true);
@ -100,9 +117,9 @@ void TaskSketcherSolverAdvanced::updateDefaultMethodParameters(void)
ui->lineEditSolverParam1->setEnabled(true);
ui->lineEditSolverParam2->setEnabled(true);
ui->lineEditSolverParam3->setEnabled(true);
double eps = hGrp->GetFloat("LM_eps",1E-10);
double eps1 = hGrp->GetFloat("LM_eps1",1E-80);
double tau = hGrp->GetFloat("LM_tau",1E-3);
double eps = ::atof(hGrp->GetASCII("LM_eps",QString::number(LM_EPS).toUtf8()).c_str());
double eps1 = ::atof(hGrp->GetASCII("LM_eps1",QString::number(LM_EPS1).toUtf8()).c_str());
double tau = ::atof(hGrp->GetASCII("LM_tau",QString::number(LM_TAU).toUtf8()).c_str());
ui->lineEditSolverParam1->setText(QString::number(eps).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper()));
ui->lineEditSolverParam2->setText(QString::number(eps1).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper()));
ui->lineEditSolverParam3->setText(QString::number(tau).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper()));
@ -119,9 +136,9 @@ void TaskSketcherSolverAdvanced::updateDefaultMethodParameters(void)
ui->lineEditSolverParam1->setEnabled(true);
ui->lineEditSolverParam2->setEnabled(true);
ui->lineEditSolverParam3->setEnabled(true);
double tolg = hGrp->GetFloat("DL_tolg",1E-80);
double tolx = hGrp->GetFloat("DL_tolx",1E-80);
double tolf = hGrp->GetFloat("DL_tolf",1E-10);
double tolg = ::atof(hGrp->GetASCII("DL_tolg",QString::number(DL_TOLG).toUtf8()).c_str());
double tolx = ::atof(hGrp->GetASCII("DL_tolx",QString::number(DL_TOLX).toUtf8()).c_str());
double tolf = ::atof(hGrp->GetASCII("DL_tolf",QString::number(DL_TOLF).toUtf8()).c_str());
ui->lineEditSolverParam1->setText(QString::number(tolg).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper()));
ui->lineEditSolverParam2->setText(QString::number(tolx).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper()));
ui->lineEditSolverParam3->setText(QString::number(tolf).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper()));
@ -143,6 +160,9 @@ void TaskSketcherSolverAdvanced::updateRedundantMethodParameters(void)
ui->labelRedundantSolverParam1->setText(QString::fromLatin1(""));
ui->labelRedundantSolverParam2->setText(QString::fromLatin1(""));
ui->labelRedundantSolverParam3->setText(QString::fromLatin1(""));
ui->lineEditRedundantSolverParam1->clear();
ui->lineEditRedundantSolverParam2->clear();
ui->lineEditRedundantSolverParam3->clear();
ui->lineEditRedundantSolverParam1->setDisabled(true);
ui->lineEditRedundantSolverParam2->setDisabled(true);
ui->lineEditRedundantSolverParam3->setDisabled(true);
@ -155,9 +175,9 @@ void TaskSketcherSolverAdvanced::updateRedundantMethodParameters(void)
ui->lineEditRedundantSolverParam1->setEnabled(true);
ui->lineEditRedundantSolverParam2->setEnabled(true);
ui->lineEditRedundantSolverParam3->setEnabled(true);
double eps = hGrp->GetFloat("Redundant_LM_eps",1E-10);
double eps1 = hGrp->GetFloat("Redundant_LM_eps1",1E-80);
double tau = hGrp->GetFloat("Redundant_LM_tau",1E-3);
double eps = ::atof(hGrp->GetASCII("Redundant_LM_eps",QString::number(LM_EPS).toUtf8()).c_str());
double eps1 = ::atof(hGrp->GetASCII("Redundant_LM_eps1",QString::number(LM_EPS1).toUtf8()).c_str());
double tau = ::atof(hGrp->GetASCII("Redundant_LM_tau",QString::number(LM_TAU).toUtf8()).c_str());
ui->lineEditRedundantSolverParam1->setText(QString::number(eps).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper()));
ui->lineEditRedundantSolverParam2->setText(QString::number(eps1).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper()));
ui->lineEditRedundantSolverParam3->setText(QString::number(tau).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper()));
@ -174,9 +194,9 @@ void TaskSketcherSolverAdvanced::updateRedundantMethodParameters(void)
ui->lineEditRedundantSolverParam1->setEnabled(true);
ui->lineEditRedundantSolverParam2->setEnabled(true);
ui->lineEditRedundantSolverParam3->setEnabled(true);
double tolg = hGrp->GetFloat("Redundant_DL_tolg",1E-80);
double tolx = hGrp->GetFloat("Redundant_DL_tolx",1E-80);
double tolf = hGrp->GetFloat("Redundant_DL_tolf",1E-10);
double tolg = ::atof(hGrp->GetASCII("Redundant_DL_tolg",QString::number(DL_TOLG).toUtf8()).c_str());
double tolx = ::atof(hGrp->GetASCII("Redundant_DL_tolx",QString::number(DL_TOLX).toUtf8()).c_str());
double tolf = ::atof(hGrp->GetASCII("Redundant_DL_tolf",QString::number(DL_TOLF).toUtf8()).c_str());
ui->lineEditRedundantSolverParam1->setText(QString::number(tolg).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper()));
ui->lineEditRedundantSolverParam2->setText(QString::number(tolx).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper()));
ui->lineEditRedundantSolverParam3->setText(QString::number(tolf).remove(QString::fromLatin1("+").replace(QString::fromLatin1("e0"),QString::fromLatin1("E")).toUpper()));
@ -381,16 +401,16 @@ void TaskSketcherSolverAdvanced::on_checkBoxSketchSizeMultiplier_stateChanged(in
}
}
void TaskSketcherSolverAdvanced::on_lineEditCovergence_editingFinished()
void TaskSketcherSolverAdvanced::on_lineEditConvergence_editingFinished()
{
QString text = ui->lineEditCovergence->text();
QString text = ui->lineEditConvergence->text();
double val = text.toDouble();
QString sci = QString::number(val);
sci.remove(QString::fromLatin1("+"));
sci.replace(QString::fromLatin1("e0"),QString::fromLatin1("E"));
ui->lineEditCovergence->setText(sci.toUpper());
ui->lineEditConvergence->setText(sci.toUpper());
ui->lineEditCovergence->onSave();
ui->lineEditConvergence->onSave();
sketchView->getSketchObject()->getSolvedSketch().setConvergence(val);
}
@ -446,6 +466,53 @@ void TaskSketcherSolverAdvanced::on_comboBoxDebugMode_currentIndexChanged(int in
sketchView->getSketchObject()->getSolvedSketch().setDebugMode((GCS::DebugMode) index);
}
void TaskSketcherSolverAdvanced::on_pushButtonSolve_clicked(bool checked/* = false*/)
{
sketchView->getSketchObject()->solve();
}
void TaskSketcherSolverAdvanced::on_pushButtonDefaults_clicked(bool checked/* = false*/)
{
// Algorithm params for default solvers
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Mod/Sketcher/SolverAdvanced");
hGrp->SetASCII("LM_eps",QString::number(LM_EPS).toUtf8());
hGrp->SetASCII("LM_eps1",QString::number(LM_EPS1).toUtf8());
hGrp->SetASCII("LM_tau",QString::number(LM_TAU).toUtf8());
hGrp->SetASCII("DL_tolg",QString::number(DL_TOLG).toUtf8());
hGrp->SetASCII("DL_tolx",QString::number(DL_TOLX).toUtf8());
hGrp->SetASCII("DL_tolf",QString::number(DL_TOLF).toUtf8());
hGrp->SetASCII("Redundant_LM_eps",QString::number(LM_EPS).toUtf8());
hGrp->SetASCII("Redundant_LM_eps1",QString::number(LM_EPS1).toUtf8());
hGrp->SetASCII("Redundant_LM_tau",QString::number(LM_TAU).toUtf8());
hGrp->SetASCII("Redundant_DL_tolg",QString::number(DL_TOLG).toUtf8());
hGrp->SetASCII("Redundant_DL_tolx",QString::number(DL_TOLX).toUtf8());
hGrp->SetASCII("Redundant_DL_tolf",QString::number(DL_TOLF).toUtf8());
// Set other settings
hGrp->SetInt("DefaultSolver",DEFAULT_SOLVER);
hGrp->SetInt("RedundantDefaultSolver",DEFAULT_RSOLVER);
hGrp->SetInt("MaxIter",MAX_ITER);
hGrp->SetInt("RedundantSolverMaxIterations",MAX_ITER);
hGrp->SetBool("SketchSizeMultiplier",MAX_ITER_MULTIPLIER);
hGrp->SetBool("RedundantSketchSizeMultiplier",MAX_ITER_MULTIPLIER);
hGrp->SetASCII("Convergence",QString::number(CONVERGENCE).toUtf8());
hGrp->SetASCII("RedundantConvergence",QString::number(CONVERGENCE).toUtf8());
hGrp->SetInt("QRMethod",DEFAULT_QRSOLVER);
hGrp->SetInt("DebugMode",DEFAULT_SOLVER_DEBUG);
ui->comboBoxDefaultSolver->onRestore();
ui->spinBoxMaxIter->onRestore();
ui->checkBoxSketchSizeMultiplier->onRestore();
ui->lineEditConvergence->onRestore();
ui->comboBoxQRMethod->onRestore();
ui->comboBoxRedundantDefaultSolver->onRestore();
ui->spinBoxRedundantSolverMaxIterations->onRestore();
ui->checkBoxRedundantSketchSizeMultiplier->onRestore();
ui->lineEditRedundantConvergence->onRestore();
ui->comboBoxDebugMode->onRestore();
updateSketchObject();
}
void TaskSketcherSolverAdvanced::updateSketchObject(void)
{
sketchView->getSketchObject()->getSolvedSketch().setDebugMode((GCS::DebugMode) ui->comboBoxDebugMode->currentIndex());
@ -454,7 +521,7 @@ void TaskSketcherSolverAdvanced::updateSketchObject(void)
sketchView->getSketchObject()->getSolvedSketch().defaultSolverRedundant=(GCS::Algorithm) ui->comboBoxRedundantDefaultSolver->currentIndex();
sketchView->getSketchObject()->getSolvedSketch().setQRAlgorithm((GCS::QRAlgorithm) ui->comboBoxQRMethod->currentIndex());
sketchView->getSketchObject()->getSolvedSketch().setConvergenceRedundant(ui->lineEditRedundantConvergence->text().toDouble());
sketchView->getSketchObject()->getSolvedSketch().setConvergence(ui->lineEditCovergence->text().toDouble());
sketchView->getSketchObject()->getSolvedSketch().setConvergence(ui->lineEditConvergence->text().toDouble());
sketchView->getSketchObject()->getSolvedSketch().setSketchSizeMultiplier(ui->checkBoxSketchSizeMultiplier->isChecked());
sketchView->getSketchObject()->getSolvedSketch().setMaxIter(ui->spinBoxMaxIter->value());
sketchView->getSketchObject()->getSolvedSketch().defaultSolver=(GCS::Algorithm) ui->comboBoxDefaultSolver->currentIndex();

View File

@ -50,7 +50,7 @@ private Q_SLOTS:
void on_comboBoxDefaultSolver_currentIndexChanged(int index);
void on_spinBoxMaxIter_valueChanged(int i);
void on_checkBoxSketchSizeMultiplier_stateChanged(int state);
void on_lineEditCovergence_editingFinished();
void on_lineEditConvergence_editingFinished();
void on_comboBoxQRMethod_currentIndexChanged(int index);
void on_comboBoxRedundantDefaultSolver_currentIndexChanged(int index);
void on_lineEditRedundantConvergence_editingFinished();
@ -62,8 +62,10 @@ private Q_SLOTS:
void on_lineEditSolverParam2_editingFinished();
void on_lineEditRedundantSolverParam2_editingFinished();
void on_lineEditSolverParam3_editingFinished();
void on_lineEditRedundantSolverParam3_editingFinished();
void on_lineEditRedundantSolverParam3_editingFinished();
void on_pushButtonDefaults_clicked(bool checked = false);
void on_pushButtonSolve_clicked(bool checked = false);
protected:
void updateDefaultMethodParameters(void);
void updateRedundantMethodParameters(void);

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>326</width>
<height>619</height>
<height>628</height>
</rect>
</property>
<property name="windowTitle">
@ -138,7 +138,7 @@
</widget>
</item>
<item>
<widget class="Gui::PrefLineEdit" name="lineEditCovergence">
<widget class="Gui::PrefLineEdit" name="lineEditConvergence">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
@ -149,7 +149,7 @@
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="prefEntry" stdset="0">
<cstring>Covergence</cstring>
<cstring>Convergence</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Mod/Sketcher/SolverAdvanced</cstring>
@ -281,6 +281,9 @@
</item>
<item>
<widget class="Gui::PrefComboBox" name="comboBoxRedundantDefaultSolver">
<property name="currentIndex">
<number>2</number>
</property>
<property name="prefEntry" stdset="0">
<cstring>RedundantDefaultSolver</cstring>
</property>
@ -516,6 +519,24 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_17">
<item>
<widget class="QPushButton" name="pushButtonSolve">
<property name="text">
<string>Solve</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonDefaults">
<property name="text">
<string>Set Defaults</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>