Commit e6b3580a authored by David Bommes's avatar David Bommes
Browse files

fixed coneConstraint wrong hessian evaluation and missing obj_factor in ipoptSolver

git-svn-id: http://www.openflipper.org/svnrepo/CoMISo/trunk@210 1355f012-dd97-4b2f-ae87-10fa9f823a57
parent 3f83e4f2
......@@ -30,7 +30,7 @@
#include <CoMISo/NSolver/LinearConstraint.hh>
#include <CoMISo/NSolver/NPDerivativeChecker.hh>
#include <CoMISo/NSolver/CPLEXSolver.hh>
#include <CoMISo/NSolver/IPOPTSolver.hh>
// solve least squares problem for x=1, y=2 and x-2y+z = 1
// with hard constraints x =-3, z>=3, z^2 >= x^2+y^2
......@@ -86,21 +86,29 @@ int main(void)
cc.Q()(0,0) = 1.0;
cc.Q()(1,1) = 1.0;
// check if IPOPT solver available in current configuration
#if( COMISO_CPLEX_AVAILABLE)
std::cout << "---------- 3) Get CPLEX solver... " << std::endl;
COMISO::CPLEXSolver cplx;
std::cout << "---------- 4) Solve..." << std::endl;
// fill constraint vector
std::vector<COMISO::NConstraintInterface*> constraints;
constraints.push_back(&lc);
constraints.push_back(&bc);
constraints.push_back(&cc);
// check if CPLEX solver available in current configuration
#if( COMISO_CPLEX_AVAILABLE)
std::cout << "---------- 3) Solve with CPLEX solver... " << std::endl;
COMISO::CPLEXSolver cplx;
cplx.solve(&lsqp, constraints);
#endif
// check if IPOPT solver available in current configuration
#if( COMISO_IPOPT_AVAILABLE)
std::cout << "---------- 3) Solve with IPOPT solver... " << std::endl;
COMISO::IPOPTSolver ipopt;
ipopt.app().Options()->SetStringValue("derivative_test", "second-order");
ipopt.solve(&lsqp, constraints);
#endif
std::cout << "---------- 5) Print solution..." << std::endl;
for( int i=0; i<n; ++i)
std::cerr << "x_" << i << " = " << lsqp.x()[i] << std::endl;
......
......@@ -30,7 +30,7 @@ ConeConstraint::ConeConstraint()
{
Q_.clear();
i_ = 1.0;
c_ = 1.0;
}
// cone constraint of the form -> 0.5*(c_ * x(i_)^2 - x^T Q_ x) >= 0
......@@ -121,7 +121,8 @@ void ConeConstraint::eval_gradient( const double* _x, SVectorNC& _g )
void ConeConstraint::eval_hessian ( const double* _x, SMatrixNC& _h )
{
_h = Q_;
Q_(i_,i_) += c_;
_h.scale(-1.0);
_h(i_,i_) += c_;
}
......
......@@ -751,7 +751,7 @@ bool NProblemIPOPT::eval_h(Index n, const Number* x, bool new_x,
// store lower triangular part only
if(it.row() >= it.col())
{
values[gi] = it.value();
values[gi] = obj_factor*it.value();
++gi;
}
}
......@@ -778,7 +778,7 @@ bool NProblemIPOPT::eval_h(Index n, const Number* x, bool new_x,
// error check
if( gi != nele_hess)
std::cerr << "Warning: number of non-zeros in Hessian of Lagrangian is incorrect: "
std::cerr << "Warning: number of non-zeros in Hessian of Lagrangian is incorrect2: "
<< gi << " vs " << nele_hess << std::endl;
}
return true;
......
......@@ -140,6 +140,14 @@ public:
}
}
// scale matrix by scalar
void scale(const VT _s)
{
typename std::map<PII, VT>::iterator m_it = data_.begin();
for(; m_it != data_.end(); ++m_it)
m_it->second *=_s;
}
void print()
{
iterator it = begin();
......
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