UtilMacrosDecomp.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef UTIL_MACROS_DECOMP_INCLUDED
00017 #define UTIL_MACROS_DECOMP_INCLUDED
00018
00019
00020 #define UTIL_USE_TIMERS
00021
00022
00023 #include "Decomp.h"
00024 #include "CoinError.hpp"
00025 #include "CoinPackedVector.hpp"
00026 #include "CoinHelperFunctions.hpp"
00027
00028
00029 class DecompApp;
00030
00031
00032 #ifdef UTIL_USE_TIMERS
00033 #include "UtilTimer.h"
00034
00035 static UtilTimer globalTimer;
00036 static std::map<std::string, UtilTimer> globalTimerFuncMap;
00037 #endif
00038
00039
00040 #define UtilException(msg,methodN,classN) \
00041 CoinError(msg,methodN,classN,__FILE__,__LINE__)
00042 #define UtilExceptionMemory(methodN,classN) \
00043 UtilException("Out of memory",methodN,classN)
00044
00045
00046
00047
00048
00049 #ifdef UTIL_USE_TIMERS
00050
00051 inline void UtilPrintFuncBegin(std::ostream* os,
00052 const std::string& classTag,
00053 const std::string& funcName,
00054 const int logLevel,
00055 const int logLimit)
00056 {
00057 const size_t nDashes = 30;
00058 std::string funcKey = classTag + funcName;
00059 UtilTimer& thisFuncTimer = globalTimerFuncMap[funcKey];
00060 thisFuncTimer.reset();
00061
00062 if (logLevel >= logLimit) {
00063 size_t i;
00064 std::string funcBegin = "<--- " + funcName + " ";
00065
00066 for (i = funcBegin.size(); i < nDashes; i++) {
00067 funcBegin += "-";
00068 }
00069
00070 (*os) << std::left << std::setw(9) << classTag << ": "
00071 << std::setprecision(3) << std::setw(8) << globalTimer.getRealTime()
00072 << " [CPU: " << std::setprecision(3) << std::setw(8)
00073 << globalTimer.getCpuTime() << "] " << funcBegin << "\n";
00074 }
00075 }
00076
00077
00078 inline void UtilPrintFuncEnd(std::ostream* os,
00079 const std::string& classTag,
00080 const std::string& funcName,
00081 const int logLevel,
00082 const int logLimit)
00083 {
00084 const size_t nDashes = 30;
00085 std::string funcKey = classTag + funcName;
00086 UtilTimer& thisFuncTimer = globalTimerFuncMap[funcKey];
00087
00088 if (logLevel >= logLimit) {
00089 size_t i;
00090 std::string funcEnd = " --- " + funcName + " ";
00091
00092 for (i = funcEnd.size(); i < nDashes; i++) {
00093 funcEnd += "-";
00094 }
00095
00096 funcEnd += ">";
00097 (*os) << std::left << std::setw(9) << classTag << ": "
00098 << std::setprecision(3) << std::setw(8) << globalTimer.getRealTime()
00099 << " [CPU: " << std::setprecision(4) << std::setw(8)
00100 << globalTimer.getCpuTime() << "] " << funcEnd << " funcT = "
00101 << std::setprecision(3) << std::setw(8) << thisFuncTimer.getCpuTime()
00102 << "\n";
00103 }
00104 }
00105
00106 #else
00107
00108
00109 inline void UtilPrintFuncBegin(ostream* os,
00110 const string& classTag,
00111 const string& funcName,
00112 const int logLevel,
00113 const int logLimit)
00114 {
00115 const int nDashes = 30;
00116
00117 if (logLevel >= logLimit) {
00118 int i;
00119 string funcBegin = "<--- " + funcName + " ";
00120
00121 for (i = funcBegin.size(); i < nDashes; i++) {
00122 funcBegin += "-";
00123 }
00124
00125 (*os) << left << setw(9) << classTag << ": " << funcBegin << "\n";
00126 }
00127 }
00128
00129
00130 inline void UtilPrintFuncEnd(ostream* os,
00131 const string& classTag,
00132 const string& funcName,
00133 const int logLevel,
00134 const int logLimit)
00135 {
00136 const int nDashes = 30;
00137
00138 if (logLevel >= logLimit) {
00139 int i;
00140 string funcEnd = " --- " + funcName + " ";
00141
00142 for (i = funcEnd.size(); i < nDashes; i++) {
00143 funcEnd += "-";
00144 }
00145
00146 funcEnd += ">";
00147 (*os) << left << setw(9) << classTag << ": " << funcEnd << "\n";
00148 }
00149 }
00150
00151 #endif
00152
00153
00154
00155
00156
00157
00158
00162 inline double UtilCalculateGap(const double boundLB,
00163 const double boundUB)
00164 {
00165 double gap = DecompInf;
00166
00167 if (boundLB > -DecompInf && boundUB < DecompInf) {
00168 if (boundLB != 0.0) {
00169 gap = fabs(boundUB - boundLB) / fabs(boundLB);
00170 } else {
00171 gap = fabs(boundUB);
00172 }
00173 }
00174
00175 return gap;
00176 }
00177
00178
00179
00180 CoinPackedVector* UtilPackedVectorFromDense(const int len,
00181 const double* dense,
00182 const double etol);
00183 void UtilPackedVectorFromDense(const int len,
00184 const double* dense,
00185 const double etol,
00186 CoinPackedVector& v);
00187
00188 void UtilPrintPackedVector(const CoinPackedVector& v,
00189 std::ostream* os = &std::cout,
00190 DecompApp* app = 0);
00191 void UtilPrintPackedVector(const CoinPackedVector& v,
00192 std::ostream* os,
00193 const std::vector<std::string>& colNames,
00194 const double* value = NULL);
00195
00196
00197
00198 #endif