Commit 0f80ddd6 authored by Jan Möbius's avatar Jan Möbius

Fixed most windows compilation problems with used classes

git-svn-id: http://www.openflipper.org/svnrepo/CoMISo/trunk@81 1355f012-dd97-4b2f-ae87-10fa9f823a57
parent 32934e82
......@@ -17,6 +17,36 @@ namespace COMISO {
//== IMPLEMENTATION ==========================================================
/// Constructor
LinearConstraintHandlerPenalty::LinearConstraintHandlerPenalty() : penalty_(10000) {}
//-----------------------------------------------------------------------------
/// Destructor
LinearConstraintHandlerPenalty::~LinearConstraintHandlerPenalty()
{}
//-----------------------------------------------------------------------------
// penalty weight
double& LinearConstraintHandlerPenalty::penalty()
{ return penalty_; }
//-----------------------------------------------------------------------------
// number of variables
int LinearConstraintHandlerPenalty::n()
{return n_;}
//-----------------------------------------------------------------------------
// number of linearly independent constraints (n-n_reduced)
int LinearConstraintHandlerPenalty::n_constraints()
{ return m_;}
//-----------------------------------------------------------------------------
void
LinearConstraintHandlerPenalty::
initialize( const std::vector<double>& _c)
......
......@@ -45,25 +45,23 @@ public:
typedef gmm::array1D_reference<double*> VectorPT;
/// Constructor
LinearConstraintHandlerPenalty() : penalty_(10000) {}
LinearConstraintHandlerPenalty();
// initialize Constructor
template<class MatrixT, class VectorT>
LinearConstraintHandlerPenalty( const MatrixT& _C, const VectorT& _c) : penalty_(10000)
{initialize(_C, _c); }
LinearConstraintHandlerPenalty( const MatrixT& _C, const VectorT& _c);
/// Destructor
~LinearConstraintHandlerPenalty() {}
~LinearConstraintHandlerPenalty();
// penalty weight
double& penalty() { return penalty_; }
double& penalty();
// number of variables
int n() {return n_;}
int n();
// number of linearly independent constraints (n-n_reduced)
int n_constraints() { return m_;}
int n_constraints();
// initialize new constraints
template<class MatrixT, class VectorT>
......
......@@ -16,6 +16,12 @@ namespace COMISO {
//== IMPLEMENTATION ==========================================================
// initialize Constructor
template<class MatrixT, class VectorT>
LinearConstraintHandlerPenalty::LinearConstraintHandlerPenalty( const MatrixT& _C, const VectorT& _c) :
penalty_(10000)
{initialize(_C, _c); }
template<class MatrixT, class VectorT>
void
LinearConstraintHandlerPenalty::
......
//=============================================================================
//
// CLASS NConstraintGmmInterface
//
//=============================================================================
//== INCLUDES =================================================================
#include "NConstraintGmmInterface.hh"
//== FORWARDDECLARATIONS ======================================================
//== NAMESPACES ===============================================================
namespace COMISO {
//== IMPLEMENTATION =========================================================
NConstraintGmmInterface::NConstraintGmmInterface(const ConstraintType _type ) :
type_(_type) {}
NConstraintGmmInterface::~NConstraintGmmInterface() {}
NConstraintGmmInterface::ConstraintType NConstraintGmmInterface::constraint_type ( ) { return type_; }
bool NConstraintGmmInterface::is_satisfied ( const double* _x, double _eps )
{
switch( type_)
{
case NC_EQUAL : return (fabs(eval_constraint(_x)) <= _eps); break;
case NC_LESS_EQUAL : return ( eval_constraint(_x) <= _eps); break;
case NC_GREATER_EQUAL: return ( eval_constraint(_x) >= -_eps); break;
}
return false;
}
double NConstraintGmmInterface::gradient_update_factor( const double* _x, double _eps )
{
double val = eval_constraint(_x);
bool upper_bound_ok = ( val <= _eps);
bool lower_bound_ok = ( val >= -_eps);
if(upper_bound_ok)
{
if(lower_bound_ok || type_ == NC_LESS_EQUAL) return 0.0;
else return 1.0;
}
else
{
if(lower_bound_ok && type_ == NC_GREATER_EQUAL) return 0.0;
else return -1.0;
}
}
//=============================================================================
} // namespace COMISO
//=============================================================================
......@@ -43,46 +43,21 @@ public:
enum ConstraintType {NC_EQUAL, NC_LESS_EQUAL, NC_GREATER_EQUAL};
/// Default constructor
NConstraintGmmInterface(const ConstraintType _type = NC_EQUAL) : type_(_type) {}
NConstraintGmmInterface(const ConstraintType _type = NC_EQUAL);
/// Destructor
~NConstraintGmmInterface() {}
~NConstraintGmmInterface();
virtual int n_unknowns ( ) = 0;
virtual double eval_constraint ( const double* _x ) = 0;
virtual void eval_gradient ( const double* _x, SVectorNP& _g ) = 0;
virtual void eval_hessian ( const double* _x, SMatrixNP& _h ) = 0;
virtual ConstraintType constraint_type ( ) { return type_; }
virtual bool is_satisfied ( const double* _x, double _eps = 1e-6 )
{
switch( type_)
{
case NC_EQUAL : return (fabs(eval_constraint(_x)) <= _eps); break;
case NC_LESS_EQUAL : return ( eval_constraint(_x) <= _eps); break;
case NC_GREATER_EQUAL: return ( eval_constraint(_x) >= -_eps); break;
}
return false;
}
virtual double gradient_update_factor( const double* _x, double _eps = 1e-6 )
{
double val = eval_constraint(_x);
bool upper_bound_ok = ( val <= _eps);
bool lower_bound_ok = ( val >= -_eps);
if(upper_bound_ok)
{
if(lower_bound_ok || type_ == NC_LESS_EQUAL) return 0.0;
else return 1.0;
}
else
{
if(lower_bound_ok && type_ == NC_GREATER_EQUAL) return 0.0;
else return -1.0;
}
}
virtual ConstraintType constraint_type ( );
virtual bool is_satisfied ( const double* _x, double _eps = 1e-6 );
virtual double gradient_update_factor( const double* _x, double _eps = 1e-6 );
private:
......
......@@ -14,7 +14,7 @@
#include <iostream>
#include <iomanip>
#include <ACG/Utils/StopWatch.hh>
#include <CoMISo/Utils/StopWatch.hh>
#include <gmm/gmm.h>
#include "NProblemGmmInterface.hh"
......
//=============================================================================
//
// CLASS NPTiming
//
//=============================================================================
//== INCLUDES =================================================================
#include <iostream>
#include <iomanip>
#include "NPTiming.hh"
//== FORWARDDECLARATIONS ======================================================
//== NAMESPACES ===============================================================
namespace COMISO {
//== CLASS DEFINITION =========================================================
/// Default constructor
NPTiming::NPTiming(NProblemGmmInterface* _base) : base_(_base) {start_timing();}
/// Destructor
NPTiming::~NPTiming() {}
int NPTiming::n_unknowns ()
{
return base_->n_unknowns();
}
void NPTiming::initial_x( double* _x )
{
base_->initial_x(_x);
}
double NPTiming::eval_f( const double* _x )
{
++n_eval_f_;
sw_.start();
double f = base_->eval_f(_x);
timing_eval_f_ += sw_.stop();
return f;
}
void NPTiming::eval_gradient( const double* _x, double* _g)
{
++n_eval_gradient_;
sw_.start();
base_->eval_gradient(_x, _g);
timing_eval_gradient_ += sw_.stop();
}
void NPTiming::eval_hessian ( const double* _x, SMatrixNP& _H)
{
++n_eval_hessian_;
sw_.start();
base_->eval_hessian(_x, _H);
timing_eval_hessian_ += sw_.stop();
}
void NPTiming::store_result ( const double* _x )
{
base_->store_result(_x);
print_statistics();
}
void NPTiming::start_timing()
{
swg_.start();
timing_eval_f_ = 0.0;
timing_eval_gradient_ = 0.0;
timing_eval_hessian_ = 0.0;
n_eval_f_ = 0;
n_eval_gradient_ = 0;
n_eval_hessian_ = 0;
}
void NPTiming::print_statistics()
{
double time_total = swg_.stop();
double time_np = timing_eval_f_ + timing_eval_gradient_ + timing_eval_hessian_;
std::cerr << "######## NP-Timings ########" << std::endl;
std::cerr << "total time : " << time_total/1000.0 << "s\n";
std::cerr << "total time NP : " << time_np/1000.0 << "s (" << time_np/time_total*100.0 << " %)\n";
std::cerr << std::fixed << std::setprecision(5)
<< "eval_f time : " << timing_eval_f_/1000.0
<< "s ( #evals: " << n_eval_f_ << " -> avg "
<< timing_eval_f_/(1000.0*double(n_eval_f_)) << "s )\n"
<< "eval_grad time: " << timing_eval_gradient_/1000.0
<< "s ( #evals: " << n_eval_gradient_ << " -> avg "
<< timing_eval_gradient_/(1000.0*double(n_eval_gradient_)) << "s )\n"
<< "eval_hess time: " << timing_eval_hessian_/1000.0
<< "s ( #evals: " << n_eval_hessian_ << " -> avg "
<< timing_eval_hessian_/(1000.0*double(n_eval_hessian_)) << "s )\n";
}
//=============================================================================
} // namespace COMISO
//=============================================================================
......@@ -11,13 +11,9 @@
//== INCLUDES =================================================================
#include <iostream>
#include <iomanip>
#include <ACG/Utils/StopWatch.hh>
#include <CoMISo/Utils/StopWatch.hh>
#include <gmm/gmm.h>
#include "NProblemGmmInterface.hh"
#include <CoMISo/Config/CoMISoDefines.hh>
//== FORWARDDECLARATIONS ======================================================
......@@ -41,90 +37,28 @@ class COMISODLLEXPORT NPTiming : public NProblemGmmInterface
public:
/// Default constructor
NPTiming(NProblemGmmInterface* _base) : base_(_base) {start_timing();}
NPTiming(NProblemGmmInterface* _base);
/// Destructor
~NPTiming() {}
virtual int n_unknowns ()
{
return base_->n_unknowns();
}
virtual void initial_x( double* _x )
{
base_->initial_x(_x);
}
virtual double eval_f( const double* _x )
{
++n_eval_f_;
sw_.start();
double f = base_->eval_f(_x);
timing_eval_f_ += sw_.stop();
return f;
}
virtual void eval_gradient( const double* _x, double* _g)
{
++n_eval_gradient_;
sw_.start();
base_->eval_gradient(_x, _g);
timing_eval_gradient_ += sw_.stop();
}
virtual void eval_hessian ( const double* _x, SMatrixNP& _H)
{
++n_eval_hessian_;
sw_.start();
base_->eval_hessian(_x, _H);
timing_eval_hessian_ += sw_.stop();
}
virtual void store_result ( const double* _x )
{
base_->store_result(_x);
print_statistics();
}
void start_timing()
{
swg_.start();
timing_eval_f_ = 0.0;
timing_eval_gradient_ = 0.0;
timing_eval_hessian_ = 0.0;
n_eval_f_ = 0;
n_eval_gradient_ = 0;
n_eval_hessian_ = 0;
}
~NPTiming();
protected:
virtual int n_unknowns ();
void print_statistics()
{
double time_total = swg_.stop();
virtual void initial_x( double* _x );
double time_np = timing_eval_f_ + timing_eval_gradient_ + timing_eval_hessian_;
virtual double eval_f( const double* _x );
virtual void eval_gradient( const double* _x, double* _g);
virtual void eval_hessian ( const double* _x, SMatrixNP& _H);
std::cerr << "######## NP-Timings ########" << std::endl;
std::cerr << "total time : " << time_total/1000.0 << "s\n";
std::cerr << "total time NP : " << time_np/1000.0 << "s (" << time_np/time_total*100.0 << " %)\n";
virtual void store_result ( const double* _x );
void start_timing();
protected:
std::cerr << std::fixed << std::setprecision(5)
<< "eval_f time : " << timing_eval_f_/1000.0
<< "s ( #evals: " << n_eval_f_ << " -> avg "
<< timing_eval_f_/(1000.0*double(n_eval_f_)) << "s )\n"
<< "eval_grad time: " << timing_eval_gradient_/1000.0
<< "s ( #evals: " << n_eval_gradient_ << " -> avg "
<< timing_eval_gradient_/(1000.0*double(n_eval_gradient_)) << "s )\n"
<< "eval_hess time: " << timing_eval_hessian_/1000.0
<< "s ( #evals: " << n_eval_hessian_ << " -> avg "
<< timing_eval_hessian_/(1000.0*double(n_eval_hessian_)) << "s )\n";
}
void print_statistics();
private:
NProblemGmmInterface* base_;
......
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