Commit 05602e3c authored by Max Lyon's avatar Max Lyon
Browse files

add variable to check if newton solver is converged

parent eb3391b2
...@@ -23,6 +23,7 @@ solve(NProblemGmmInterface* _problem) ...@@ -23,6 +23,7 @@ solve(NProblemGmmInterface* _problem)
{ {
DEB_enter_func; DEB_enter_func;
#if COMISO_SUITESPARSE_AVAILABLE #if COMISO_SUITESPARSE_AVAILABLE
converged_ = true;
// get problem size // get problem size
int n = _problem->n_unknowns(); int n = _problem->n_unknowns();
...@@ -98,16 +99,19 @@ solve(NProblemGmmInterface* _problem) ...@@ -98,16 +99,19 @@ solve(NProblemGmmInterface* _problem)
_problem->store_result(P(x)); _problem->store_result(P(x));
DEB_line(2, "Newton solver reached max regularization but did not " DEB_line(2, "Newton solver reached max regularization but did not "
"converge"); "converge");
converged_ = false;
return false; return false;
} }
} }
} }
_problem->store_result(P(x)); _problem->store_result(P(x));
DEB_line(2, "Newton Solver did not converge!!! after iterations."); DEB_line(2, "Newton Solver did not converge!!! after iterations.");
converged_ = false;
return false; return false;
#else #else
DEB_warning(1,"NewtonSolver requires not-available CholmodSolver"); DEB_warning(1,"NewtonSolver requires not-available CholmodSolver");
converged_ = false;
return false; return false;
#endif #endif
} }
...@@ -120,6 +124,7 @@ int NewtonSolver::solve(NProblemInterface* _problem, const SMatrixD& _A, ...@@ -120,6 +124,7 @@ int NewtonSolver::solve(NProblemInterface* _problem, const SMatrixD& _A,
const VectorD& _b) const VectorD& _b)
{ {
DEB_time_func_def; DEB_time_func_def;
converged_ = false;
const double KKT_res_eps = 1e-6; const double KKT_res_eps = 1e-6;
const int max_KKT_regularization_iters = 40; const int max_KKT_regularization_iters = 40;
...@@ -251,8 +256,11 @@ int NewtonSolver::solve(NProblemInterface* _problem, const SMatrixD& _A, ...@@ -251,8 +256,11 @@ int NewtonSolver::solve(NProblemInterface* _problem, const SMatrixD& _A,
<< ", KKT residual^2 = " << kkt_res2); << ", KKT residual^2 = " << kkt_res2);
// converged? // converged?
if(newton_decrement < eps_ || std::abs(t) < eps_ls_) if(newton_decrement < eps_ || std::abs(t) < eps_ls_ )
{
converged_ = true;
break; break;
}
++iter; ++iter;
} }
...@@ -398,11 +406,11 @@ bool NewtonSolver::numerical_factorization(SMatrixD& _KKT) ...@@ -398,11 +406,11 @@ bool NewtonSolver::numerical_factorization(SMatrixD& _KKT)
DEB_enter_func; DEB_enter_func;
switch(solver_type_) switch(solver_type_)
{ {
case LS_EigenLU: case LS_EigenLU:
lu_solver_.factorize(_KKT); lu_solver_.factorize(_KKT);
return (lu_solver_.info() == Eigen::Success); return (lu_solver_.info() == Eigen::Success);
#if COMISO_SUITESPARSE_AVAILABLE #if COMISO_SUITESPARSE_AVAILABLE
case LS_Umfpack: case LS_Umfpack:
umfpack_solver_.factorize(_KKT); umfpack_solver_.factorize(_KKT);
return (umfpack_solver_.info() == Eigen::Success); return (umfpack_solver_.info() == Eigen::Success);
#endif #endif
......
...@@ -84,6 +84,8 @@ public: ...@@ -84,6 +84,8 @@ public:
solver_type_ = _st; solver_type_ = _st;
} }
bool converged() { return converged_; }
protected: protected:
bool factorize(NProblemInterface* _problem, const SMatrixD& _A, bool factorize(NProblemInterface* _problem, const SMatrixD& _A,
...@@ -149,6 +151,8 @@ private: ...@@ -149,6 +151,8 @@ private:
// deprecated // deprecated
bool constant_hessian_structure_; bool constant_hessian_structure_;
bool converged_;
}; };
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment