Ipopt Documentation  
IpUtils.hpp
Go to the documentation of this file.
1 // Copyright (C) 2004, 2009 International Business Machines and others.
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13
6 
7 #ifndef __IPUTILS_HPP__
8 #define __IPUTILS_HPP__
9 
10 // Standard Ip Include Files
11 #include "IpTypes.hpp"
12 #include "IpDebug.hpp"
13 
14 #include <algorithm>
15 #include <limits>
16 #include <stdexcept>
17 #include <sstream>
18 
19 namespace Ipopt
20 {
21 
22 template<typename T>
23 inline T Max(
24  T a,
25  T b
26 )
27 {
28  return std::max(a, b);
29 }
30 
31 template<typename T>
32 inline T Max(
33  T a,
34  T b,
35  T c
36 )
37 {
38  return std::max(std::max(a, b), c);
39 }
40 
41 template<typename T>
42 inline T Max(
43  T a,
44  T b,
45  T c,
46  T d
47 )
48 {
49  return std::max(std::max(a, b), std::max(c, d));
50 }
51 
52 template<typename T>
53 inline T Min(
54  T a,
55  T b
56 )
57 {
58  return std::min(a, b);
59 }
60 
61 template<typename T>
62 inline T Min(
63  T a,
64  T b,
65  T c
66 )
67 {
68  return std::min(std::min(a, b), c);
69 }
70 
71 template<typename T>
72 inline T Min(
73  T a,
74  T b,
75  T c,
76  T d
77 )
78 {
79  return std::min(std::min(a, b), std::min(c, d));
80 }
81 
85  Number val
86 );
87 
90 
93 
96 
99 
102 
110  Number lhs,
111  Number rhs,
112  Number BasVal
113 );
114 
116 #ifdef __GNUC__
117 __attribute__((format(printf, 3, 4)))
118 #endif
120  char* str,
121  long size,
122  const char* format,
123  ...
124 );
125 
135 template<typename T>
136 inline void ComputeMemIncrease(
137  T& len,
138  double recommended,
139  T min,
140  const char* context
141 )
142 {
143  if( recommended >= std::numeric_limits<T>::max() )
144  {
145  // increase len to the maximum possible, if that is still an increase
146  if( len < std::numeric_limits<T>::max() )
147  {
148  len = std::numeric_limits<T>::max();
149  }
150  else
151  {
152  DBG_ASSERT(context != NULL);
153  std::stringstream what;
154  what << "Cannot allocate more than " << std::numeric_limits<T>::max()*sizeof(T) << " bytes for " << context << " due to limitation on integer type";
155  throw std::overflow_error(what.str());
156  }
157  }
158  else
159  {
160  len = Max(min, (T) recommended);
161  }
162 }
163 
164 } //namespace Ipopt
165 
166 #endif
Ipopt::Compare_le
IPOPTLIB_EXPORT bool Compare_le(Number lhs, Number rhs, Number BasVal)
Method for comparing two numbers within machine precision.
Ipopt::ComputeMemIncrease
void ComputeMemIncrease(T &len, double recommended, T min, const char *context)
Method to calculate new length for a memory increase based on a recommendation and limits in integer ...
Definition: IpUtils.hpp:136
Ipopt::Min
T Min(T a, T b)
Definition: IpUtils.hpp:53
Ipopt::IsFiniteNumber
IPOPTLIB_EXPORT bool IsFiniteNumber(Number val)
Function returning true iff the argument is a valid double number (not NaN or Inf).
Ipopt
This file contains a base class for all exceptions and a set of macros to help with exceptions.
Definition: IpInexactAlgBuilder.hpp:14
IPOPTLIB_EXPORT
#define IPOPTLIB_EXPORT
Definition: config_default.h:10
IpTypes.hpp
Ipopt::IpRandom01
IPOPTLIB_EXPORT Number IpRandom01()
Function returning a random number between 0 and 1.
Ipopt::Number
ipnumber Number
Type of all numbers.
Definition: IpTypes.hpp:17
Ipopt::Snprintf
IPOPTLIB_EXPORT int Snprintf(char *str, long size, const char *format,...)
Method for printing a formatted output to a string with given size.
Ipopt::SysTime
IPOPTLIB_EXPORT Number SysTime()
method determining system time
Ipopt::CpuTime
IPOPTLIB_EXPORT Number CpuTime()
method determining CPU time
Ipopt::IpResetRandom01
IPOPTLIB_EXPORT void IpResetRandom01()
Function resetting the random number generator.
Ipopt::Max
T Max(T a, T b)
Definition: IpUtils.hpp:23
Ipopt::WallclockTime
IPOPTLIB_EXPORT Number WallclockTime()
method determining wallclock time since first call
DBG_ASSERT
#define DBG_ASSERT(test)
Definition: IpDebug.hpp:27
IpDebug.hpp