Skip to content

Commit

Permalink
added class for post step (#54)
Browse files Browse the repository at this point in the history
* added class for post step
  • Loading branch information
teseoch authored Dec 7, 2023
1 parent 8a8c103 commit eab76b4
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/polysolve/nonlinear/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set(SOURCES
Solver.cpp
Problem.hpp
Problem.cpp
PostStepData.hpp
PostStepData.cpp
)

source_group(TREE "${CMAKE_CURRENT_SOURCE_DIR}" PREFIX "Source Files" FILES ${SOURCES})
Expand Down
11 changes: 11 additions & 0 deletions src/polysolve/nonlinear/PostStepData.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "PostStepData.hpp"

namespace polysolve::nonlinear
{
PostStepData::PostStepData(const int iter_num,
const Eigen::VectorXd &x,
const Eigen::VectorXd &grad)
: iter_num(iter_num), x(x), grad(grad)
{
}
} // namespace polysolve::nonlinear
19 changes: 19 additions & 0 deletions src/polysolve/nonlinear/PostStepData.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#pragma once

#include <polysolve/Types.hpp>

namespace polysolve::nonlinear
{

class PostStepData
{
public:
PostStepData(const int iter_num,
const Eigen::VectorXd &x,
const Eigen::VectorXd &grad);

const int iter_num;
const Eigen::VectorXd &x;
const Eigen::VectorXd &grad;
};
} // namespace polysolve::nonlinear
4 changes: 3 additions & 1 deletion src/polysolve/nonlinear/Problem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <polysolve/Types.hpp>

#include "PostStepData.hpp"

#include <cppoptlib/problem.h>

#include <memory>
Expand Down Expand Up @@ -33,7 +35,7 @@ namespace polysolve::nonlinear

virtual void line_search_begin(const TVector &x0, const TVector &x1) {}
virtual void line_search_end() {}
virtual void post_step(const int iter_num, const TVector &x) {}
virtual void post_step(const PostStepData &data) {}

virtual void set_project_to_psd(bool val) {}

Expand Down
6 changes: 4 additions & 2 deletions src/polysolve/nonlinear/Solver.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

#include "Solver.hpp"

#include "PostStepData.hpp"

#include "descent_strategies/BFGS.hpp"
#include "descent_strategies/Newton.hpp"
#include "descent_strategies/GradientDescent.hpp"
Expand Down Expand Up @@ -191,7 +193,7 @@ namespace polysolve::nonlinear
objFunc.solution_changed(x);
}

objFunc.post_step(this->m_current.iterations, x);
objFunc.post_step(PostStepData(this->m_current.iterations, x, grad));

const auto g_norm_tol = this->m_stop.gradNorm;
this->m_stop.gradNorm = first_grad_norm_tol;
Expand Down Expand Up @@ -371,7 +373,7 @@ namespace polysolve::nonlinear
m_logger.debug("[{}][{}] Objective decided to stop", name(), m_line_search->name());
}

objFunc.post_step(this->m_current.iterations, x);
objFunc.post_step(PostStepData(this->m_current.iterations, x, grad));

if (f_delta < this->m_stop.fDelta)
f_delta_step_cnt++;
Expand Down

0 comments on commit eab76b4

Please sign in to comment.