Dip 0.95.0
Loading...
Searching...
No Matches
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// Authors: Matthew Galati, SAS Institute Inc. (matthew.galati@sas.com) //
8// Ted Ralphs, Lehigh University (ted@lehigh.edu) //
9// Jiadong Wang, Lehigh University (jiw408@lehigh.edu) //
10// //
11// Copyright (C) 2002-2019, Lehigh University, Matthew Galati, Ted Ralphs //
12// All Rights Reserved. //
13//===========================================================================//
14
15#ifndef UTIL_MACROS_DECOMP_INCLUDED
16#define UTIL_MACROS_DECOMP_INCLUDED
17
18// =========================================================================
19#define UTIL_USE_TIMERS
20
21// =========================================================================
22#include "Decomp.h"
23#include "CoinError.hpp"
24#include "CoinPackedVector.hpp"
26
27// =========================================================================
28class DecompApp;
29
30// =========================================================================
31#ifdef UTIL_USE_TIMERS
32#include "UtilTimer.h"
33//NOTE: this is not thread safe!
35static std::map<std::string, UtilTimer> globalTimerFuncMap;
36#endif
37
38// =========================================================================
39#define UtilException(msg,methodN,classN) \
40 CoinError(msg,methodN,classN,__FILE__,__LINE__)
41#define UtilExceptionMemory(methodN,classN) \
42 UtilException("Out of memory",methodN,classN)
43
44
45// =========================================================================
46// Debug Macros
47// =========================================================================
48#ifdef UTIL_USE_TIMERS
49// ------------------------------------------------------------------------- //
50inline void UtilPrintFuncBegin(std::ostream* os,
51 const std::string& classTag,
52 const std::string& funcName,
53 const int logLevel,
54 const int logLimit)
55{
56 const size_t nDashes = 30;
57 std::string funcKey = classTag + funcName;
58 UtilTimer& thisFuncTimer = globalTimerFuncMap[funcKey];
59 thisFuncTimer.reset();
60
61 if (logLevel >= logLimit) {
62 size_t i;
63 std::string funcBegin = "<--- " + funcName + " ";
64
65 for (i = funcBegin.size(); i < nDashes; i++) {
66 funcBegin += "-";
67 }
68
69 (*os) << std::left << std::setw(9) << classTag << ": "
70 << std::setprecision(3) << std::setw(8) << globalTimer.getRealTime()
71 << " [CPU: " << std::setprecision(3) << std::setw(8)
72 << globalTimer.getCpuTime() << "] " << funcBegin << "\n";
73 }
74}
75
76// ------------------------------------------------------------------------- //
77inline void UtilPrintFuncEnd(std::ostream* os,
78 const std::string& classTag,
79 const std::string& funcName,
80 const int logLevel,
81 const int logLimit)
82{
83 const size_t nDashes = 30;
84 std::string funcKey = classTag + funcName;
85 UtilTimer& thisFuncTimer = globalTimerFuncMap[funcKey];
86
87 if (logLevel >= logLimit) {
88 size_t i;
89 std::string funcEnd = " --- " + funcName + " ";
90
91 for (i = funcEnd.size(); i < nDashes; i++) {
92 funcEnd += "-";
93 }
94
95 funcEnd += ">";
96 (*os) << std::left << std::setw(9) << classTag << ": "
97 << std::setprecision(3) << std::setw(8) << globalTimer.getRealTime()
98 << " [CPU: " << std::setprecision(4) << std::setw(8)
99 << globalTimer.getCpuTime() << "] " << funcEnd << " funcT = "
100 << std::setprecision(3) << std::setw(8) << thisFuncTimer.getCpuTime()
101 << "\n";
102 }
103}
104
105#else
106
107// ------------------------------------------------------------------------- //
108inline void UtilPrintFuncBegin(ostream* os,
109 const string& classTag,
110 const string& funcName,
111 const int logLevel,
112 const int logLimit)
113{
114 const int nDashes = 30;
115
116 if (logLevel >= logLimit) {
117 int i;
118 string funcBegin = "<--- " + funcName + " ";
119
120 for (i = funcBegin.size(); i < nDashes; i++) {
121 funcBegin += "-";
122 }
123
124 (*os) << left << setw(9) << classTag << ": " << funcBegin << "\n";
125 }
126}
127
128// ------------------------------------------------------------------------- //
129inline void UtilPrintFuncEnd(ostream* os,
130 const string& classTag,
131 const string& funcName,
132 const int logLevel,
133 const int logLimit)
134{
135 const int nDashes = 30;
136
137 if (logLevel >= logLimit) {
138 int i;
139 string funcEnd = " --- " + funcName + " ";
140
141 for (i = funcEnd.size(); i < nDashes; i++) {
142 funcEnd += "-";
143 }
144
145 funcEnd += ">";
146 (*os) << left << setw(9) << classTag << ": " << funcEnd << "\n";
147 }
148}
149
150#endif
151
152// =========================================================================
153// COIN Macros
154// TODO: anything that depends on COIN should probably not be in util lib
155// =========================================================================
156
157// ------------------------------------------------------------------------- //
161inline double UtilCalculateGap(const double boundLB,
162 const double boundUB,
163 double infinity)
164{
165 double gap = infinity;
166
167 if (boundLB > -infinity && boundUB < infinity) {
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);
183void UtilPackedVectorFromDense(const int len,
184 const double* dense,
185 const double etol,
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
void UtilPrintFuncEnd(std::ostream *os, const std::string &classTag, const std::string &funcName, const int logLevel, const int logLimit)
CoinPackedVector * UtilPackedVectorFromDense(const int len, const double *dense, const double etol)
void UtilPrintFuncBegin(std::ostream *os, const std::string &classTag, const std::string &funcName, const int logLevel, const int logLimit)
double UtilCalculateGap(const double boundLB, const double boundUB, double infinity)
Calculate gap: |(ub-lb)|/|lb|.
void UtilPrintPackedVector(const CoinPackedVector &v, std::ostream *os=&std::cout, DecompApp *app=0)
static std::map< std::string, UtilTimer > globalTimerFuncMap
static UtilTimer globalTimer
The main application class.
Definition DecompApp.h:48
void reset()
Reset.
Definition UtilTimer.h:44
double getCpuTime()
Get cpu time.
Definition UtilTimer.h:67