Skip to content
Snippets Groups Projects
Commit 9a79b4b8 authored by Joan Vallvé Navarro's avatar Joan Vallvé Navarro
Browse files

implemented and working

parent 0fd6a732
No related branches found
No related tags found
1 merge request!386Resolve "IterationUpdateCallback checking total cost decreased"
Pipeline #5743 passed
...@@ -19,17 +19,29 @@ class IterationUpdateCallback : public ceres::IterationCallback ...@@ -19,17 +19,29 @@ class IterationUpdateCallback : public ceres::IterationCallback
explicit IterationUpdateCallback(ProblemPtr _problem, bool verbose = false) explicit IterationUpdateCallback(ProblemPtr _problem, bool verbose = false)
: problem_(_problem) : problem_(_problem)
, verbose_(verbose) , verbose_(verbose)
, initial_cost_(0)
{} {}
~IterationUpdateCallback() {} ~IterationUpdateCallback() {}
ceres::CallbackReturnType operator()(const ceres::IterationSummary& summary) override ceres::CallbackReturnType operator()(const ceres::IterationSummary& summary) override
{ {
if (summary.iteration == 0)
initial_cost_ = summary.cost;
if (problem_->getStateBlockNotificationMapSize() != 0 or if (problem_->getStateBlockNotificationMapSize() != 0 or
problem_->getFactorNotificationMapSize() != 0) problem_->getFactorNotificationMapSize() != 0)
{ {
WOLF_INFO_COND(verbose_, "Stopping solver to update the problem!"); if (summary.cost >= initial_cost_)
return ceres::SOLVER_TERMINATE_SUCCESSFULLY; {
WOLF_INFO_COND(verbose_, "Stopping solver to update the problem! ABORTING since cost didn't decrease. Iteration ", summary.iteration);
return ceres::SOLVER_ABORT;
}
else
{
WOLF_INFO_COND(verbose_, "Stopping solver to update the problem! SUCCESS since cost decreased. Iteration ", summary.iteration);
return ceres::SOLVER_TERMINATE_SUCCESSFULLY;
}
} }
return ceres::SOLVER_CONTINUE; return ceres::SOLVER_CONTINUE;
} }
...@@ -37,6 +49,7 @@ class IterationUpdateCallback : public ceres::IterationCallback ...@@ -37,6 +49,7 @@ class IterationUpdateCallback : public ceres::IterationCallback
private: private:
ProblemPtr problem_; ProblemPtr problem_;
bool verbose_; bool verbose_;
double initial_cost_;
}; };
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment