Commit b43f521c authored by Mike Kremer's avatar Mike Kremer

Added new ADOLC NConstraint interface. Fixed some compilation errors.

git-svn-id: http://www.openflipper.org/svnrepo/CoMISo/trunk@252 1355f012-dd97-4b2f-ae87-10fa9f823a57
parent 890c9d0a
......@@ -26,22 +26,22 @@
//== NAMESPACES ===============================================================
namespace COMISO {
namespace COMISO {
//== CLASS DEFINITION =========================================================
/** \class NProblemGmmInterface NProblemGmmInterface.hh <ACG/.../NPRoblemGmmInterface.hh>
Brief Description.
A more elaborate description follows.
*/
class COMISODLLEXPORT NConstraintInterface
{
public:
// define Sparse Datatypes
typedef Eigen::SparseVector<double> SVectorNC;
typedef SuperSparseMatrixT<double> SMatrixNC;
......@@ -51,7 +51,7 @@ public:
/// Default constructor
NConstraintInterface(const ConstraintType _type = NC_EQUAL, double _eps = 1e-6) : type_(_type) {}
/// Destructor
virtual ~NConstraintInterface() {}
......@@ -77,6 +77,7 @@ public:
virtual bool is_linear() const { return false;}
virtual bool constant_gradient() const { return false;}
virtual bool constant_hessian () const { return false;}
virtual bool sparse_hessian() const { return true; }
virtual double gradient_update_factor( const double* _x, double _eps = 1e-6)
{
......
......@@ -213,7 +213,7 @@ public:
ec = sparse_hess(tape_, n_unknowns_, 0, _x, &nz, &r_ind, &c_ind, &val, opt);
}
assert(*nz >= 0);
assert(nz >= 0);
assert(r_ind != NULL);
assert(c_ind != NULL);
assert(val != NULL);
......
This diff is collapsed.
......@@ -138,14 +138,14 @@ public:
y_d >>= y;
delete[] xa;
trace_off();
#ifdef ADOLC_STATS
print_stats();
#endif
delete[] xa;
tape_available_ = true;
}
......@@ -295,95 +295,6 @@ public:
}
}
// automatic evaluation of hessian
// this function avoids data structure conversions and gives access to the raw sparse data type
virtual void eval_hessian_sparse(const double* _x, int& _nz, unsigned int*& _r_idx, unsigned int*& _c_idx, double*& _val)
{
// tape update required?
if(!tape_available_ || always_retape_)
eval_f(_x);
int opt[2] = {0, 0};
bool sparsity_pattern_available = bool(sparse_r_ind_p_);
int ec = sparse_hess( tape_,
this->n_unknowns(),
sparsity_pattern_available,
_x,
&sparse_nz_,
&sparse_r_ind_p_,
&sparse_c_ind_p_,
&sparse_val_p_,
opt);
if(ec < 0)
{
#ifdef ADOLC_RET_CODES
std::cout << __FUNCTION__ << " invokes retaping of function due to discontinuity! Return code: " << ec << std::endl;
#endif
// Retape function if return code indicates discontinuity
tape_available_ = false;
eval_f(_x);
ec = sparse_hess( tape_,
this->n_unknowns(),
sparsity_pattern_available,
_x,
&sparse_nz_,
&sparse_r_ind_p_,
&sparse_c_ind_p_,
&sparse_val_p_,
opt);
}
// data should be available now
assert(sparse_r_ind_p_ != NULL);
assert(sparse_c_ind_p_ != NULL);
assert(sparse_val_p_ != NULL);
// return result
_nz = sparse_nz_;
_r_idx = sparse_r_ind_p_;
_c_idx = sparse_c_ind_p_;
_val = sparse_val_p_;
#ifdef ADOLC_RET_CODES
std::cout << "Info: sparse_hessian() returned code " << ec << std::endl;
#endif
}
// automatic evaluation of hessian
// this function avoids data structure conversions and gives access to the raw dense data type
virtual void eval_hessian_dense(const double* _x, double**& _H)
{
// tape update required?
if(!tape_available_ || always_retape_)
eval_f(_x);
allocate_dense_hessian();
int ec = hessian(tape_, this->n_unknowns(), const_cast<double*>(_x), dense_hessian_);
if(ec < 0) {
#ifdef ADOLC_RET_CODES
std::cout << __FUNCTION__ << " invokes retaping of function due to discontinuity! Return code: " << ec << std::endl;
#endif
// Retape function if return code indicates discontinuity
tape_available_ = false;
eval_f(_x);
ec = hessian(tape_, this->n_unknowns(), const_cast<double*>(_x), dense_hessian_);
}
// copy pointer to result
_H = dense_hessian_;
#ifdef ADOLC_RET_CODES
std::cout << "Info: hessian() returned code " << ec << std::endl;
#endif
}
private:
void allocate_dense_hessian()
......
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