Dip-All  0.91.0
UtilMacrosDecomp.h
Go to the documentation of this file.
1 //===========================================================================//
2 // This file is part of the DIP Solver Framework. //
3 // //
4 // DIP is distributed under the Eclipse Public License as part of the //
5 // COIN-OR repository (http://www.coin-or.org). //
6 // //
7 // Author: Matthew Galati, SAS Institute Inc. (matthew.galati@sas.com) //
8 // //
9 // Conceptual Design: Matthew Galati, SAS Institute Inc. //
10 // Ted Ralphs, Lehigh University //
11 // //
12 // Copyright (C) 2002-2015, Lehigh University, Matthew Galati, Ted Ralphs //
13 // All Rights Reserved. //
14 //===========================================================================//
15 
16 #ifndef UTIL_MACROS_DECOMP_INCLUDED
17 #define UTIL_MACROS_DECOMP_INCLUDED
18 
19 // =========================================================================
20 #define UTIL_USE_TIMERS
21 
22 // =========================================================================
23 #include "Decomp.h"
24 #include "CoinError.hpp"
25 #include "CoinPackedVector.hpp"
26 #include "CoinHelperFunctions.hpp"
27 
28 // =========================================================================
29 class DecompApp;
30 
31 // =========================================================================
32 #ifdef UTIL_USE_TIMERS
33 #include "UtilTimer.h"
34 //NOTE: this is not thread safe!
35 static UtilTimer globalTimer;
36 static std::map<std::string, UtilTimer> globalTimerFuncMap;
37 #endif
38 
39 // =========================================================================
40 #define UtilException(msg,methodN,classN) \
41  CoinError(msg,methodN,classN,__FILE__,__LINE__)
42 #define UtilExceptionMemory(methodN,classN) \
43  UtilException("Out of memory",methodN,classN)
44 
45 
46 // =========================================================================
47 // Debug Macros
48 // =========================================================================
49 #ifdef UTIL_USE_TIMERS
50 // ------------------------------------------------------------------------- //
51 inline void UtilPrintFuncBegin(std::ostream* os,
52  const std::string& classTag,
53  const std::string& funcName,
54  const int logLevel,
55  const int logLimit)
56 {
57  const size_t nDashes = 30;
58  std::string funcKey = classTag + funcName;
59  UtilTimer& thisFuncTimer = globalTimerFuncMap[funcKey];
60  thisFuncTimer.reset();
61 
62  if (logLevel >= logLimit) {
63  size_t i;
64  std::string funcBegin = "<--- " + funcName + " ";
65 
66  for (i = funcBegin.size(); i < nDashes; i++) {
67  funcBegin += "-";
68  }
69 
70  (*os) << std::left << std::setw(9) << classTag << ": "
71  << std::setprecision(3) << std::setw(8) << globalTimer.getRealTime()
72  << " [CPU: " << std::setprecision(3) << std::setw(8)
73  << globalTimer.getCpuTime() << "] " << funcBegin << "\n";
74  }
75 }
76 
77 // ------------------------------------------------------------------------- //
78 inline void UtilPrintFuncEnd(std::ostream* os,
79  const std::string& classTag,
80  const std::string& funcName,
81  const int logLevel,
82  const int logLimit)
83 {
84  const size_t nDashes = 30;
85  std::string funcKey = classTag + funcName;
86  UtilTimer& thisFuncTimer = globalTimerFuncMap[funcKey];
87 
88  if (logLevel >= logLimit) {
89  size_t i;
90  std::string funcEnd = " --- " + funcName + " ";
91 
92  for (i = funcEnd.size(); i < nDashes; i++) {
93  funcEnd += "-";
94  }
95 
96  funcEnd += ">";
97  (*os) << std::left << std::setw(9) << classTag << ": "
98  << std::setprecision(3) << std::setw(8) << globalTimer.getRealTime()
99  << " [CPU: " << std::setprecision(4) << std::setw(8)
100  << globalTimer.getCpuTime() << "] " << funcEnd << " funcT = "
101  << std::setprecision(3) << std::setw(8) << thisFuncTimer.getCpuTime()
102  << "\n";
103  }
104 }
105 
106 #else
107 
108 // ------------------------------------------------------------------------- //
109 inline void UtilPrintFuncBegin(ostream* os,
110  const string& classTag,
111  const string& funcName,
112  const int logLevel,
113  const int logLimit)
114 {
115  const int nDashes = 30;
116 
117  if (logLevel >= logLimit) {
118  int i;
119  string funcBegin = "<--- " + funcName + " ";
120 
121  for (i = funcBegin.size(); i < nDashes; i++) {
122  funcBegin += "-";
123  }
124 
125  (*os) << left << setw(9) << classTag << ": " << funcBegin << "\n";
126  }
127 }
128 
129 // ------------------------------------------------------------------------- //
130 inline void UtilPrintFuncEnd(ostream* os,
131  const string& classTag,
132  const string& funcName,
133  const int logLevel,
134  const int logLimit)
135 {
136  const int nDashes = 30;
137 
138  if (logLevel >= logLimit) {
139  int i;
140  string funcEnd = " --- " + funcName + " ";
141 
142  for (i = funcEnd.size(); i < nDashes; i++) {
143  funcEnd += "-";
144  }
145 
146  funcEnd += ">";
147  (*os) << left << setw(9) << classTag << ": " << funcEnd << "\n";
148  }
149 }
150 
151 #endif
152 
153 // =========================================================================
154 // COIN Macros
155 // TODO: anything that depends on COIN should probably not be in util lib
156 // =========================================================================
157 
158 // ------------------------------------------------------------------------- //
162 inline double UtilCalculateGap(const double boundLB,
163  const double boundUB)
164 {
165  double gap = DecompInf;
166 
167  if (boundLB > -DecompInf && boundUB < DecompInf) {
168  if (boundLB != 0.0) {
169  gap = fabs(boundUB - boundLB) / fabs(boundLB);
170  } else {
171  gap = fabs(boundUB);
172  }
173  }
174 
175  return gap;
176 }
177 
178 
179 // ------------------------------------------------------------------------- //
181  const double* dense,
182  const double etol);
183 void UtilPackedVectorFromDense(const int len,
184  const double* dense,
185  const double etol,
186  CoinPackedVector& v);
187 
189  std::ostream* os = &std::cout,
190  DecompApp* app = 0);
192  std::ostream* os,
193  const std::vector<std::string>& colNames,
194  const double* value = NULL);
195 
196 
197 
198 #endif
CoinPackedVector * UtilPackedVectorFromDense(const int len, const double *dense, const double etol)
double getCpuTime()
Get cpu time.
Definition: UtilTimer.h:68
double UtilCalculateGap(const double boundLB, const double boundUB)
Calculate gap: |(ub-lb)|/|lb|.
static UtilTimer globalTimer
double getRealTime()
Get wallClock time.
Definition: UtilTimer.h:75
void reset()
Reset.
Definition: UtilTimer.h:45
void UtilPrintPackedVector(const CoinPackedVector &v, ostream *os=&cout, DecompApp *app=0)
Sparse Vector.
void UtilPrintFuncBegin(std::ostream *os, const std::string &classTag, const std::string &funcName, const int logLevel, const int logLimit)
void UtilPrintFuncEnd(std::ostream *os, const std::string &classTag, const std::string &funcName, const int logLevel, const int logLimit)
static std::map< std::string, UtilTimer > globalTimerFuncMap
The main application class.
Definition: DecompApp.h:50