Commit 22cd9c4a authored by Martin Marinov's avatar Martin Marinov
Browse files

Moved and Rafactored StopWatch to Base/Utils. Added DEB_time_func and...

Moved and Rafactored StopWatch to Base/Utils. Added DEB_time_func and DEB_time_session macros in a new header Base/Debug/DebTime.hh

[git-p4: depot-paths = "//ReForm/ReForm/main/CoMISo/": change = 11256]
parent a9532c38
......@@ -11,7 +11,7 @@
#include "LinearConstraint.hh"
#include "BoundConstraint.hh"
#include "ConeConstraint.hh"
#include <CoMISo/Utils/StopWatch.hh>
#include <Base/Debug/DebTime.hh>
#if COMISO_CPLEX_AVAILABLE
......@@ -31,7 +31,6 @@ solve2(NProblemInterface* _problem,
const double _time_limit,
const bool _silent)
{
MY_PAUSE;
try
{
//----------------------------------------------
......@@ -639,14 +638,13 @@ solve(NProblemInterface* _problem,
const double _time_limit,
const bool _silent)
{
MY_PAUSE;
// std::cerr << "Warning: CPLEXSolver does not support lazy constraints yet -> solve with all constraints instead" << std::endl;
// std::vector<NConstraintInterface*> C;
// std::copy(_constraints.begin(),_constraints.end(),std::back_inserter(C));
// return solve(_problem, C, _time_limit, _silent);
StopWatch sw; sw.start();
DEB_time_func_def;
bool feasible_point_found = false;
int cur_pass = 0;
......@@ -902,8 +900,6 @@ solve(NProblemInterface* _problem,
}
}
const double overall_time = sw.stop()/1000.0;
//----------------------------------------------------------------------------
// 4. output statistics
//----------------------------------------------------------------------------
......@@ -918,7 +914,6 @@ solve(NProblemInterface* _problem,
// }
std::cerr <<"############# CPLEX with lazy constraints statistics ###############" << std::endl;
std::cerr << "overall time: " << overall_time << "s" << std::endl;
std::cerr << "#passes : " << cur_pass << "( of " << _max_passes << ")" << std::endl;
for(unsigned int i=0; i<n_inf.size(); ++i)
std::cerr << "pass " << i << " induced " << n_inf[i] << " infeasible and " << n_almost_inf[i] << " almost infeasible" << std::endl;
......
......@@ -14,12 +14,11 @@
#include "GUROBISolver.hh"
#include <CoMISo/Utils/StopWatch.hh>
#include <Base/Debug/DebTime.hh>
#include <Base/Utils/OutcomeUtils.hh>
#include <stdexcept>
#include <Base/Debug/DebOut.hh>
DEB_module("NSLV")
......@@ -268,14 +267,13 @@ solve(NProblemInterface* _problem,
const double _time_limit,
const bool _silent)
{
DEB_enter_func;
DEB_time_func_def;
// // hack! solve with all constraints
// std::vector<NConstraintInterface*> all_constraints;
// std::copy(_constraints.begin(),_constraints.end(),std::back_inserter(all_constraints));
// std::copy(_lazy_constraints.begin(),_lazy_constraints.end(),std::back_inserter(all_constraints));
//
// return solve(_problem, all_constraints, _discrete_constraints, _time_limit);
StopWatch sw; sw.start();
bool feasible_point_found = false;
int cur_pass = 0;
......
......@@ -15,8 +15,7 @@
#include "IPOPTSolver.hh"
#include <Base/Utils/OutcomeUtils.hh>
#include <Base/Debug/DebOut.hh>
#include <Base/Debug/DebTime.hh>
#include <IpTNLP.hpp>
#include <IpIpoptApplication.hpp>
......@@ -339,8 +338,8 @@ IPOPTSolver::IPOPTSolver()
IPOPTSolver::~IPOPTSolver()
{ delete impl_; }
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
static void throw_ipopt_solve_failure(Ipopt::ApplicationReturnStatus const status)
......@@ -384,7 +383,7 @@ static void throw_ipopt_solve_failure(Ipopt::ApplicationReturnStatus const statu
void IPOPTSolver::solve(NProblemInterface* _problem,
const std::vector<NConstraintInterface*>& _constraints)
{
DEB_enter_func;
DEB_time_func_def;
//----------------------------------------------------------------------------
// 1. Create an instance of IPOPT NLP
//----------------------------------------------------------------------------
......@@ -429,10 +428,9 @@ void IPOPTSolver::solve(NProblemInterface* _problem,
//----------------------------------------------------------------------------
// 4. output statistics
//----------------------------------------------------------------------------
if (!(status == Ipopt::Solve_Succeeded || status == Ipopt::Solved_To_Acceptable_Level))
{
if (!(status == Ipopt::Solve_Succeeded ||
status == Ipopt::Solved_To_Acceptable_Level))
throw_ipopt_solve_failure(status);
}
// Retrieve some statistics about the solve
Ipopt::Index iter_count = impl_->app_->Statistics()->IterationCount();
......@@ -455,12 +453,10 @@ void IPOPTSolver::solve(
const double _almost_infeasible,
const int _max_passes )
{
DEB_enter_func;
DEB_time_func_def;
//----------------------------------------------------------------------------
// 0. Initialize IPOPT Applicaiton
// 0. Initialize IPOPT Application
//----------------------------------------------------------------------------
StopWatch sw; sw.start();
// Initialize the IpoptApplication and process the options
Ipopt::ApplicationReturnStatus status;
......@@ -629,12 +625,11 @@ void IPOPTSolver::solve(
status = impl_->app_->OptimizeTNLP( np);
}
const double overall_time = sw.stop()/1000.0;
//----------------------------------------------------------------------------
// 4. output statistics
//----------------------------------------------------------------------------
if (!(status == Ipopt::Solve_Succeeded || status == Ipopt::Solved_To_Acceptable_Level))
if (!(status == Ipopt::Solve_Succeeded ||
status == Ipopt::Solved_To_Acceptable_Level))
throw_ipopt_solve_failure(status);
// Retrieve some statistics about the solve
......@@ -647,7 +642,6 @@ void IPOPTSolver::solve(
<< final_obj << "\n");
DEB_out(2, "############# IPOPT with lazy constraints statistics ###############\n");
DEB_out(2, "overall time: " << overall_time << "s\n");
DEB_out(2, "#passes : " << cur_pass << "( of " << _max_passes << ")\n");
for(unsigned int i=0; i<n_inf.size(); ++i)
DEB_out(3, "pass " << i << " induced " << n_inf[i]
......
......@@ -16,7 +16,6 @@
//== INCLUDES =================================================================
#include <CoMISo/Config/CoMISoDefines.hh>
#include <CoMISo/Utils/StopWatch.hh>
#include <vector>
#include <cstddef>
#include <gmm/gmm.h>
......
......@@ -23,7 +23,6 @@
#include <climits>
#include <CoMISo/Utils/VSToolsT.hh>
#include <CoMISo/Utils/StopWatch.hh>
#include <gmm/gmm.h>
#include <CoMISo/Config/CoMISoDefines.hh>
......
......@@ -11,7 +11,7 @@
//== INCLUDES =================================================================
#include <CoMISo/Utils/StopWatch.hh>
#include <Base/Utils/StopWatch.hh>
#include <gmm/gmm.h>
#include "NProblemInterface.hh"
#include <CoMISo/Config/CoMISoDefines.hh>
......@@ -67,8 +67,8 @@ protected:
private:
NProblemInterface* base_;
StopWatch swg_;
StopWatch sw_;
Base::StopWatch swg_;
Base::StopWatch sw_;
// timings
double timing_eval_f_;
......
......@@ -36,9 +36,9 @@
#include <gmm/gmm.h>
#include "GMM_Tools.hh"
#include <float.h>
#include <CoMISo/Utils/StopWatch.hh>
#include <CoMISo/Utils/MutablePriorityQueueT.hh>
#include <Base/Utils/StopWatch.hh>
#include <Base/Debug/DebOut.hh>
DEB_module("SOLV");
......@@ -153,7 +153,7 @@ solve(
// if( _show_timings) std::cerr << __FUNCTION__ << "\n Initial dimension: " << nrows << " x " << ncols << ", number of constraints: " << ncons << std::endl;
// // StopWatch for Timings
// COMISO::StopWatch sw, sw2; sw.start(); sw2.start();
// Base::StopWatch sw, sw2; sw.start(); sw2.start();
// // c_elim[i] = index of variable which is eliminated in condition i
// // or -1 if condition is invalid
......@@ -228,7 +228,7 @@ solve(
<< " use reordering: " << use_constraint_reordering() << "\n")
// StopWatch for Timings
COMISO::StopWatch sw, sw2; sw.start(); sw2.start();
Base::StopWatch sw, sw2; sw.start(); sw2.start();
// c_elim[i] = index of variable which is eliminated in condition i
// or -1 if condition is invalid
......@@ -339,7 +339,7 @@ resolve(
{
DEB_enter_func;
// StopWatch for Timings
COMISO::StopWatch sw;
Base::StopWatch sw;
sw.start();
// apply stored updates and eliminations to exchanged rhs
......@@ -403,7 +403,7 @@ make_constraints_independent(
gmm::clear(rhs_update_table_.D_);
for(unsigned int i=0; i<nr; ++i) rhs_update_table_.D_(i,i) = 1.0;
// COMISO::StopWatch sw;
// Base::StopWatch sw;
// number of variables
int n_vars = gmm::mat_ncols(_constraints);
......@@ -592,7 +592,7 @@ make_constraints_independent_reordering(
gmm::clear(rhs_update_table_.D_);
for(unsigned int i=0; i<nr; ++i) rhs_update_table_.D_(i,i) = 1.0;
// COMISO::StopWatch sw;
// Base::StopWatch sw;
// number of variables
int n_vars = gmm::mat_ncols(_constraints);
......@@ -965,7 +965,7 @@ eliminate_constraints(
CSCMatrixT& _Acsc)
{
DEB_enter_func;
COMISO::StopWatch sw;
Base::StopWatch sw;
sw.start();
// define iterator on matrix A and on constraints C
typedef typename gmm::linalg_traits<SVector2T>::const_iterator AIter;
......@@ -1168,8 +1168,8 @@ setup_and_solve_system( CMatrixT& _B,
if( _show_miso_settings)
miso_.show_options_dialog();
COMISO::StopWatch s1;
COMISO::StopWatch sw; sw.start();
Base::StopWatch s1;
Base::StopWatch sw; sw.start();
unsigned int m = gmm::mat_nrows(_B);
unsigned int n = gmm::mat_ncols(_B);
......@@ -1220,7 +1220,7 @@ setup_and_solve_system( CMatrixT& _B,
double setup_time = sw.stop()/1000.0;
COMISO::StopWatch misw;
Base::StopWatch misw;
misw.start();
// miso solve
miso_.solve( BtBCSC, _x, rhs, _idx_to_round);
......
......@@ -40,7 +40,6 @@
#include <CoMISo/Config/CoMISoDefines.hh>
#include <CoMISo/Utils/StopWatch.hh>
#include <iostream>
#include <vector>
......@@ -104,7 +103,6 @@ private:
Eigen::SimplicialLDLT<Eigen::SparseMatrix<double> > ldlt_;
bool show_timings_;
StopWatch sw_;
};
//=============================================================================
......
......@@ -33,7 +33,7 @@
#include <CoMISo/Solver/Eigen_Tools.hh>
#include <CoMISo/Solver/EigenLDLTSolver.hh>
#include <Base/Debug/DebOut.hh>
#include <Base/Debug/DebTime.hh>
DEB_module("SOLV")
......@@ -43,15 +43,11 @@ namespace COMISO {
template< class GMM_MatrixT>
bool EigenLDLTSolver::calc_system_gmm( const GMM_MatrixT& _mat)
{
DEB_enter_func;
if(show_timings_) sw_.start();
DEB_time_func_def;
Eigen::SparseMatrix<double> E;
COMISO_EIGEN::gmm_to_eigen(_mat, E);
DEB_out_if(show_timings_, 2, "EigenLDLT Timing GMM convert: "
<< sw_.stop()/1000.0 << "s\n#nnz: " << E.nonZeros() << "\n");
return calc_system_eigen( E);
}
......@@ -62,15 +58,11 @@ bool EigenLDLTSolver::calc_system_gmm( const GMM_MatrixT& _mat)
template< class GMM_MatrixT>
bool EigenLDLTSolver::update_system_gmm( const GMM_MatrixT& _mat)
{
DEB_enter_func;
if(show_timings_) sw_.start();
DEB_time_func_def;
Eigen::SparseMatrix<double> E;
COMISO_EIGEN::gmm_to_eigen(_mat, E);
DEB_out_if(show_timings_, 2, "EigenLDLT Timing GMM convert: "
<< sw_.stop()/1000.0 << "s\n#nnz: " << E.nonZeros() << "\n");
return update_system_eigen( E);
}
......@@ -79,17 +71,11 @@ bool EigenLDLTSolver::update_system_gmm( const GMM_MatrixT& _mat)
template< class Eigen_MatrixT>
bool EigenLDLTSolver::calc_system_eigen( const Eigen_MatrixT& _mat)
{
DEB_enter_func;
n_ = _mat.rows();
if(show_timings_) sw_.start();
DEB_time_func_def;
n_ = _mat.rows();
ldlt_.compute(_mat);
DEB_out_if(show_timings_, 2, "EigenLDLT Timing EIGEN compute: "
<< sw_.stop()/1000.0 << "s\n");
return (ldlt_.info()==Eigen::Success);
return (ldlt_.info()==Eigen::Success);
}
//-----------------------------------------------------------------------------
......@@ -97,14 +83,9 @@ bool EigenLDLTSolver::calc_system_eigen( const Eigen_MatrixT& _mat)
template< class Eigen_MatrixT>
bool EigenLDLTSolver::update_system_eigen( const Eigen_MatrixT& _mat)
{
DEB_enter_func;
if(show_timings_) sw_.start();
DEB_time_func_def;
ldlt_.factorize(_mat);
DEB_out_if(show_timings_, 2, "EigenLDLT Timing EIGEN factorize: "
<< sw_.stop()/1000.0 << "s\n")
return (ldlt_.info()==Eigen::Success );
}
......
......@@ -41,7 +41,6 @@
#include "Eigen_Tools.hh"
#include <queue>
#include <CoMISo/Utils/StopWatch.hh>
#include <CoMISo/Utils/VSToolsT.hh>
#include <gmm/gmm.h>
......
......@@ -38,7 +38,6 @@
#define GMM_USES_LAPACK
#include <gmm/gmm_lapack_interface.h>
#include <queue>
#include <CoMISo/Utils/StopWatch.hh>
#include <CoMISo/Utils/VSToolsT.hh>
......
......@@ -39,10 +39,10 @@
//#include <ilcplex/cplex.h>
#endif
#include <CoMISo/Utils/StopWatch.hh>
#include <Base/Debug/DebOut.hh>
#include <Base/Utils/OutcomeUtils.hh>
#include <Base/Utils/StopWatch.hh>
#include <gmm/gmm.h>
#include <float.h>
......@@ -113,8 +113,6 @@ MISolver::solve(
DEB_out(2, "# integer variables: " << _to_round.size()
<< "\n# continuous variables: " << _x.size()-_to_round.size() << "\n")
MY_PAUSE;
// nothing to solve?
if( gmm::mat_ncols(_A) == 0 || gmm::mat_nrows(_A) == 0)
return;
......@@ -146,7 +144,6 @@ MISolver::solve_cplex(
{
DEB_enter_func;
DEB_out(2, "gurobi_max_time_: " << gurobi_max_time_ << "\n")
MY_PAUSE;
#if COMISO_CPLEX_AVAILABLE
......@@ -289,7 +286,7 @@ MISolver::solve_direct_rounding(
// check solver performance (only for testing!!!)
{
StopWatch sw;
Base::StopWatch sw;
// hack
const bool enable_performance_test = false;
......@@ -417,7 +414,7 @@ MISolver::solve_iterative(
{
DEB_enter_func;
// StopWatch
COMISO::StopWatch sw;
Base::StopWatch sw;
double time_search_next_integer = 0;
// some statistics
......@@ -636,7 +633,7 @@ void MISolver::solve_multiple_rounding(
{
DEB_enter_func
// StopWatch
COMISO::StopWatch sw;
Base::StopWatch sw;
double time_search_next_integer = 0;
// some statistics
......
......@@ -40,8 +40,6 @@
#include <CoMISo/Config/config.hh>
#include "GMM_Tools.hh"
#include <CoMISo/Utils/StopWatch.hh>
#include <iostream>
#include <vector>
......@@ -156,7 +154,6 @@ private:
std::vector<Int> rowind_;
bool show_timings_;
StopWatch sw_;
};
//=============================================================================
......
set(my_headers
${CMAKE_CURRENT_SOURCE_DIR}/MutablePriorityQueueT.hh
${CMAKE_CURRENT_SOURCE_DIR}/SmartPointer.hh
${CMAKE_CURRENT_SOURCE_DIR}/StopWatch.hh
${CMAKE_CURRENT_SOURCE_DIR}/VSToolsT.hh
PARENT_SCOPE
)
......
//=============================================================================
//
// OpenFlipper
// Copyright (C) 2008 by Computer Graphics Group, RWTH Aachen
// www.openflipper.org
//
//-----------------------------------------------------------------------------
//
// License
//
// OpenFlipper is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// OpenFlipper is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with OpenFlipper. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
//
// $Revision: 3468 $
// $Author: moebius $
// $Date: 2008-10-17 14:58:52 +0200 (Fri, 17 Oct 2008) $
//
//=============================================================================
//=============================================================================
//
// CLASS StopWatch
//
//=============================================================================
#ifndef COMISO_STOPWATCH_HH
#define COMISO_STOPWATCH_HH
//== INCLUDES =================================================================
#include <conio.h>
#include <exception>
#include <iostream>
#ifdef _WIN32
#include <windows.h>
#else // Linux
#include <sys/time.h>
#endif
#include <CoMISo/Config/CoMISoDefines.hh>
//== NAMESPACES ===============================================================
namespace COMISO {
//== CLASS DEFINITION =========================================================
/** \class StopWatch StopWatch.hh <COMISO/Utils/StopWatch.hh>
This class can be used for measuring time, providing milli-second
precision by using the gettimeofday() funtion. It is e.g. used in
the class COMISO::TimedTracing.
**/
class COMISODLLEXPORT StopWatch
{
public:
/// Constructor
StopWatch() {
#ifdef _WIN32
QueryPerformanceFrequency(&freq_);
#else
starttime_.tv_sec = starttime_.tv_usec = 0;
endtime_.tv_sec = endtime_.tv_usec = 0;
#endif
}
/// Destructor
~StopWatch() {}
/// Start time measurement
void start() {
#ifdef _WIN32
QueryPerformanceCounter(&starttime_);
#else
starttime_ = current_time();
#endif
}
/// Restart, return time elapsed until now.
double restart() {
#ifdef _WIN32
QueryPerformanceCounter(&endtime_);
#else
endtime_ = current_time();
#endif
double t = elapsed();
start();
return t;
}
/// Stop time measurement, return time.
double stop() {
#ifdef _WIN32
QueryPerformanceCounter(&endtime_);
#else
endtime_ = current_time();
#endif
return elapsed();
}
/// Get the total time in milli-seconds (watch has to be stopped).
double elapsed() const {
#ifdef _WIN32
return (double)(endtime_.QuadPart - starttime_.QuadPart)
/ (double)freq_.QuadPart * 1000.0f;
#else
return ((endtime_.tv_sec - starttime_.tv_sec )*1000.0 +
(endtime_.tv_usec - starttime_.tv_usec)*0.001);
#endif
}
private:
#ifdef _WIN32
LARGE_INTEGER starttime_, endtime_;
LARGE_INTEGER freq_;
#else // Linux
timeval current_time() const {
struct timeval tv;
gettimeofday(&tv, 0);
return tv;
}
timeval starttime_, endtime_;
#endif
};
void my_pause(const char* __caller);
#define MY_PAUSE my_pause(__FUNCTION__)
//=============================================================================
} // namespace COMISO
//=============================================================================
#endif // COMISO_STOPWATCH_HH defined
//=============================================================================