SoPlex Doxygen Documentation
spxdefines.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of the class library */
4 /* SoPlex --- the Sequential object-oriented simPlex. */
5 /* */
6 /* Copyright (C) 1996-2012 Konrad-Zuse-Zentrum */
7 /* fuer Informationstechnik Berlin */
8 /* */
9 /* SoPlex is distributed under the terms of the ZIB Academic Licence. */
10 /* */
11 /* You should have received a copy of the ZIB Academic License */
12 /* along with SoPlex; see the file COPYING. If not email to soplex@zib.de. */
13 /* */
14 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
15 
16 /**@file spxdefines.h
17  * @brief Debugging, floating point type and parameter definitions.
18  *
19  * In optimized code with \c NDEBUG defined, only
20  * \ref soplex::SPxOut::INFO1 "INFO1",
21  * \ref soplex::SPxOut::INFO2 "INFO2", and
22  * \ref soplex::SPxOut::INFO3 "INFO3" are set.
23  * If \c NDEBUG is not defined, the code within #TRACE is used.
24  * If \c DEBUGGING is defined, the code within
25  * \ref soplex::SPxOut::DEBUG "DEBUG" is also used.
26  * If \c TRACE_METHOD is defined, the method tracing with #METHOD is
27  * activated.
28  *
29  * If \c WITH_LONG_DOUBLE is defined, all Real numbers are of type
30  * long double instead of just double.
31  */
32 #ifndef _SPXDEFINES_H_
33 #define _SPXDEFINES_H_
34 
35 #include <math.h>
36 
37 #ifdef TRACE_METHOD
38 #include "tracemethod.h"
39 #endif
40 
41 
42 
43 
44 namespace soplex
45 {
46 #define SOPLEX_VERSION 171
47 #define SOPLEX_SUBVERSION 0
48 
49 /*-----------------------------------------------------------------------------
50  * Assertion Macros etc.
51  *-----------------------------------------------------------------------------
52  */
53 
54 /**
55  \brief Macro to turn some assertions into warnings.
56 
57  If both \c NDEBUG and \c WITH_WARNINGS are defined then the failed
58  assertion is converted to a warning. In all other cases this macro is
59  equivalent to assert().
60 
61  @param prefix Short string for grepping in source code.
62  @param expr Expression that must be satisfied.
63 */
64 #if defined (NDEBUG) && defined (WITH_WARNINGS)
65 #define ASSERT_WARN( prefix, expr ) \
66  if ( !( expr ) ) \
67  { \
68  MSG_WARNING( spxout \
69  << prefix \
70  << " failed assertion on line " << __LINE__ \
71  << " in file " << __FILE__ << ": " \
72  << #expr \
73  << std::endl; ); \
74  }
75 #else // just a normal assert
76 #define ASSERT_WARN( prefix, expr ) ( assert( expr ) )
77 #endif
78 
79 
80 
81 /*-----------------------------------------------------------------------------
82  * Debugging Macros etc.
83  *-----------------------------------------------------------------------------
84  */
85 
86 /**
87  Executes \p do_something with verbosity level \p verbosity, resetting
88  the old verbosity level afterwards.
89  Usually the parameter \p do_something prints something out.
90  This is an internal define used by MSG_ERROR, MSG_WARNING, etc.
91 */
92 #ifdef DISABLE_VERBOSITY
93 #define DO_WITH_TMP_VERBOSITY( verbosity, do_something ) {}
94 #else
95 #define DO_WITH_TMP_VERBOSITY( verbosity, do_something ) \
96  { const SPxOut::Verbosity old_verbosity = spxout.getVerbosity(); \
97  spxout.setVerbosity( verbosity ); \
98  do_something; \
99  spxout.setVerbosity( old_verbosity ); }
100 #endif
101 
102 /// Prints out message \p x if the verbosity level is at least SPxOut::ERROR.
103 #define MSG_ERROR(x) { DO_WITH_TMP_VERBOSITY( SPxOut::ERROR, x ) }
104 /// Prints out message \p x if the verbosity level is at least SPxOut::WARNING.
105 #define MSG_WARNING(x) { DO_WITH_TMP_VERBOSITY( SPxOut::WARNING, x ) }
106 /// Prints out message \p x if the verbosity level is at least SPxOut::INFO1.
107 #define MSG_INFO1(x) { DO_WITH_TMP_VERBOSITY( SPxOut::INFO1, x ) }
108 /// Prints out message \p x if the verbosity level is at least SPxOut::INFO2.
109 #define MSG_INFO2(x) { DO_WITH_TMP_VERBOSITY( SPxOut::INFO2, x ) }
110 /// Prints out message \p x if the verbosity level is at least SPxOut::INFO3.
111 #define MSG_INFO3(x) { DO_WITH_TMP_VERBOSITY( SPxOut::INFO3, x ) }
112 
113 extern bool msginconsistent(const char* name, const char* file, int line);
114 
115 #define MSGinconsistent(name) msginconsistent(name, __FILE__, __LINE__)
116 
117 #ifndef NDEBUG
118 // print output in any case, regardless of Param::verbose():
119 #define TRACE(x) { DO_WITH_TMP_VERBOSITY( SPxOut::ERROR, x ) }
120 #else
121 #define TRACE(x) /**/
122 #endif //!NDEBUG
123 
124 #if defined(DEBUGGING)
125 // print output in any case, regardless of Param::verbose():
126 #define MSG_DEBUG(x) { DO_WITH_TMP_VERBOSITY( SPxOut::DEBUG, x ) }
127 #else
128 #define MSG_DEBUG(x) /**/
129 #endif //!DEBUGGING
130 
131 #if defined(TRACE_METHOD)
132 // print output in any case, regardless of Param::verbose():
133 // NB: We cannot use DO_WITH_TMP_VERBOSITY since it wraps its argument in an
134 // own block to avoid name clashes. This, however, keeps the indentation
135 // at 0, destroying the call tree information.
136 #define METHOD(x) \
137  const SPxOut::Verbosity method_old_verbosity = spxout.getVerbosity(); \
138  spxout.setVerbosity( SPxOut::ERROR ); \
139  soplex::TraceMethod _trace_method_(x, __FILE__, __LINE__); \
140  spxout.setVerbosity( method_old_verbosity );
141 #else
142 #define METHOD(x) /**/
143 #endif // !TRACE_METHOD
144 
145 /*-----------------------------------------------------------------------------
146  * Long double support, Parameters and Epsilons
147  *-----------------------------------------------------------------------------
148  */
149 
150 
151 
152 #ifdef WITH_LONG_DOUBLE
153 
154 
155 typedef long double Real;
156 
157 #ifndef REAL
158 #define REAL(x) x##L
159 #endif
160 /// default allowed bound violation
161 #ifndef DEFAULT_BND_VIOL
162 #define DEFAULT_BND_VIOL 1e-12
163 #endif
164 /// default allowed additive zero: 1.0 + EPS_ZERO == 1.0
165 #ifndef DEFAULT_EPS_ZERO
166 #define DEFAULT_EPS_ZERO 1e-28
167 #endif
168 /// epsilon for factorization
169 #ifndef DEFAULT_EPS_FACTOR
170 #define DEFAULT_EPS_FACTOR 1e-30
171 #endif
172 /// epsilon for factorization update
173 #ifndef DEFAULT_EPS_UPDATE
174 #define DEFAULT_EPS_UPDATE 1e-26
175 #endif
176 ///
177 #define DEFAULT_INFINITY 1e100
178 
179 
180 #else
181 
182 #ifdef WITH_FLOAT
183 
184 typedef float Real;
185 
186 #ifndef REAL
187 #define REAL(x) x
188 #endif
189 /// default allowed bound violation
190 #ifndef DEFAULT_BND_VIOL
191 #define DEFAULT_BND_VIOL 1e-1
192 #endif
193 /// default allowed additive zero: 1.0 + EPS_ZERO == 1.0
194 #ifndef DEFAULT_EPS_ZERO
195 #define DEFAULT_EPS_ZERO 1e-7
196 #endif
197 #ifndef DEFAULT_EPS_FACTOR
198 #define DEFAULT_EPS_FACTOR 1e-7
199 #endif
200 #ifndef DEFAULT_EPS_UPDATE
201 #define DEFAULT_EPS_UPDATE 1e-6
202 #endif
203 #define DEFAULT_INFINITY 1e100
204 
205 
206 #else
207 
208 typedef double Real;
209 
210 #ifndef REAL
211 #define REAL(x) x
212 #endif
213 /// default allowed bound violation
214 #ifndef DEFAULT_BND_VIOL
215 #define DEFAULT_BND_VIOL 1e-6
216 #endif
217 /// default allowed additive zero: 1.0 + EPS_ZERO == 1.0
218 #ifndef DEFAULT_EPS_ZERO
219 #define DEFAULT_EPS_ZERO 1e-16
220 #endif
221 #ifndef DEFAULT_EPS_FACTOR
222 #define DEFAULT_EPS_FACTOR 1e-20
223 #endif
224 #ifndef DEFAULT_EPS_UPDATE
225 #define DEFAULT_EPS_UPDATE 1e-16
226 #endif
227 #define DEFAULT_INFINITY 1e100
228 
229 
230 
231 
232 
233 #endif // !WITH_FLOAT
234 #endif // !WITH_LONG_DOUBLE
235 
236 extern const Real infinity;
237 
238 class Param
239 {
240 private:
241 
242  //------------------------------------
243  /**@name Data */
244  //@{
245  /// default allowed additive zero: 1.0 + EPS_ZERO == 1.0
246  static Real s_epsilon;
247  /// epsilon for factorization
249  /// epsilon for factorization update
251  /// verbosity level
252  static int s_verbose;
253  //@}
254 
255 public:
256 
257  //------------------------------------
258  /**@name Access / modification */
259  //@{
260  ///
261  inline static Real epsilon()
262  {
263  return s_epsilon;
264  }
265  ///
266  static void setEpsilon(Real eps);
267  ///
268  inline static Real epsilonFactorization()
269  {
271  }
272  ///
273  static void setEpsilonFactorization(Real eps);
274  ///
275  inline static Real epsilonUpdate()
276  {
277  return s_epsilon_update;
278  }
279  ///
280  static void setEpsilonUpdate(Real eps);
281  /// returns verbosity level
282  inline static int verbose()
283  {
284  return s_verbose;
285  }
286  /// sets verbosity level
287  static void setVerbose(int p_verbose);
288  //@}
289 };
290 
291 /// returns max(|a|,|b|)
292 inline static Real maxAbs(Real a, Real b)
293 {
294  const Real absa = fabs(a);
295  const Real absb = fabs(b);
296 
297  return absa > absb ? absa : absb;
298 }
299 
300 /// returns (a-b) / max(|a|,|b|,1.0)
301 inline static Real relDiff(Real a, Real b)
302 {
303  return (a - b) / (maxAbs(a, b) > 1.0 ? maxAbs(a, b) : 1.0);
304 }
305 
306 /// returns \c true iff |a-b| <= eps
307 inline bool EQ(Real a, Real b, Real eps = Param::epsilon())
308 {
309  return fabs(a - b) <= eps;
310 }
311 
312 /// returns \c true iff |a-b| > eps
313 inline bool NE(Real a, Real b, Real eps = Param::epsilon())
314 {
315  return fabs(a - b) > eps;
316 }
317 
318 /// returns \c true iff a < b + eps
319 inline bool LT(Real a, Real b, Real eps = Param::epsilon())
320 {
321  return (a - b) < -eps;
322 }
323 
324 /// returns \c true iff a <= b + eps
325 inline bool LE(Real a, Real b, Real eps = Param::epsilon())
326 {
327  return (a - b) < eps;
328 }
329 
330 /// returns \c true iff a > b + eps
331 inline bool GT(Real a, Real b, Real eps = Param::epsilon())
332 {
333  return (a - b) > eps;
334 }
335 
336 /// returns \c true iff a >= b + eps
337 inline bool GE(Real a, Real b, Real eps = Param::epsilon())
338 {
339  return (a - b) > -eps;
340 }
341 
342 /// returns \c true iff |a| <= eps
343 inline bool isZero(Real a, Real eps = Param::epsilon())
344 {
345  return fabs(a) <= eps;
346 }
347 
348 /// returns \c true iff |a| > eps
349 inline bool isNotZero(Real a, Real eps = Param::epsilon())
350 {
351  return fabs(a) > eps;
352 }
353 
354 /// returns \c true iff |relDiff(a,b)| <= eps
355 inline bool EQrel(Real a, Real b, Real eps = Param::epsilon())
356 {
357  return fabs(relDiff(a, b)) <= eps;
358 }
359 
360 /// returns \c true iff |relDiff(a,b)| > eps
361 inline bool NErel(Real a, Real b, Real eps = Param::epsilon())
362 {
363  return fabs(relDiff(a, b)) > eps;
364 }
365 
366 /// returns \c true iff relDiff(a,b) <= -eps
367 inline bool LTrel(Real a, Real b, Real eps = Param::epsilon())
368 {
369  return relDiff(a, b) <= -eps;
370 }
371 
372 /// returns \c true iff relDiff(a,b) <= eps
373 inline bool LErel(Real a, Real b, Real eps = Param::epsilon())
374 {
375  return relDiff(a, b) <= eps;
376 }
377 
378 /// returns \c true iff relDiff(a,b) > eps
379 inline bool GTrel(Real a, Real b, Real eps = Param::epsilon())
380 {
381  return relDiff(a, b) > eps;
382 }
383 
384 /// returns \c true iff relDiff(a,b) > -eps
385 inline bool GErel(Real a, Real b, Real eps = Param::epsilon())
386 {
387  return relDiff(a, b) > -eps;
388 }
389 
390 } // namespace soplex
391 #endif // _SPXDEFINES_H_
392 
393 //-----------------------------------------------------------------------------
394 //Emacs Local Variables:
395 //Emacs mode:c++
396 //Emacs c-basic-offset:3
397 //Emacs tab-width:8
398 //Emacs indent-tabs-mode:nil
399 //Emacs End:
400 //-----------------------------------------------------------------------------
401 
402 
403