Commit 316abeed authored by Martin Marinov's avatar Martin Marinov

Merge remote-tracking branch 'ReForm/master' into merge-from-ReForm

parents fba5e448 2f9a8a6e
Pipeline #14101 passed with stages
in 4 minutes and 37 seconds
......@@ -3,15 +3,18 @@
#include <CoMISo/Config/config.hh>
#include <CoMISo/Utils/StopWatch.hh>
#include <vector>
#include <CoMISo/NSolver/NProblemInterface.hh>
#include <Base/Code/Quality.hh>
#include <Base/Debug/DebOut.hh>
LOW_CODE_QUALITY_SECTION_BEGIN
#include <Eigen/Eigen>
#include <Eigen/Core>
#include <Eigen/Sparse>
LOW_CODE_QUALITY_SECTION_END
#include <vector>
//== NAMESPACES ===============================================================
......@@ -26,36 +29,31 @@ public:
// typedef Eigen::DynamicSparseMatrix<double,Eigen::ColMajor> SMatrixNP;
QuadraticProblem()
: A_(0,0), b_(Eigen::VectorXd::Index(0)), c_(0.0)
{
}
: A_(0, 0), b_(Eigen::VectorXd::Index(0)), c_(0.0)
{}
QuadraticProblem(SMatrixNP& _A, Eigen::VectorXd& _b, const double _c)
: A_(_A), c_(_c)
QuadraticProblem(SMatrixNP& _A, const Eigen::VectorXd& _b, const double _c)
{
if(A_.rows() != A_.cols())
std::cerr << "Warning: matrix not square in QuadraticProblem" << std::endl;
b_ = _b;
x_ = Eigen::VectorXd::Zero(A_.cols());
set_A(_A);
set_b(_b);
set_c(_c);
}
// number of unknowns
virtual int n_unknowns()
{
return A_.rows();
return A_.rows();
}
// initial value where the optimization should start from
virtual void initial_x(double* _x)
{
for( int i=0; i<this->n_unknowns(); ++i)
_x[i] = x_[i];
for (int i = 0; i < this->n_unknowns(); ++i)
_x[i] = x_[i];
}
// function evaluation at location _x
virtual double eval_f( const double* _x )
virtual double eval_f(const double* _x)
{
Eigen::Map<const Eigen::VectorXd> x(_x, this->n_unknowns());
......@@ -63,22 +61,22 @@ public:
}
// gradient evaluation at location _x
virtual void eval_gradient( const double* _x, double* _g)
virtual void eval_gradient(const double* _x, double* _g)
{
Eigen::Map<const Eigen::VectorXd> x(_x, this->n_unknowns());
Eigen::Map<Eigen::VectorXd> g(_g, this->n_unknowns());
g = A_*x - b_;
}
}
// hessian matrix evaluation at location _x
virtual void eval_hessian ( const double* _x, SMatrixNP& _H)
virtual void eval_hessian(const double* _x, SMatrixNP& _H)
{
_H = A_;
}
// print result
virtual void store_result ( const double* _x )
virtual void store_result(const double* _x)
{
Eigen::Map<const Eigen::VectorXd> x(_x, this->n_unknowns());
x_ = x;
......@@ -89,16 +87,15 @@ public:
double c() const {return c_;}
// get current solution
Eigen::VectorXd& x() { return x_;}
Eigen::VectorXd& x() { return x_; }
// advanced properties
virtual bool constant_hessian() const { return true; }
virtual bool constant_hessian() const { return true; }
void set_A(const SMatrixNP& _A)
{
DEB_error_if(_A.rows() != _A.cols(), "Square matrix expected");
A_ = _A;
if(A_.rows() != A_.cols())
std::cerr << "Warning: matrix not square in QuadraticProblem" << std::endl;
x_ = Eigen::VectorXd::Zero(A_.cols());
}
......@@ -107,19 +104,18 @@ public:
b_ = _b;
}
void set_c( const double _c)
void set_c(const double _c)
{
c_ = _c;
}
private:
// quadratic problem 0.5*x^T A x -x^t b + c
SMatrixNP A_;
Eigen::VectorXd b_;
double c_;
// current solution, which is also used as initial value
Eigen::VectorXd x_;
SMatrixNP A_;
Eigen::VectorXd b_;
double c_;
// current solution, which is also used as initial value
Eigen::VectorXd x_;
};
//=============================================================================
......
Markdown is supported
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