Ipopt Documentation  
 
Loading...
Searching...
No Matches
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
19namespace Ipopt
20{
21
22template<typename T>
23inline T Max(
24 T a,
25 T b
26)
27{
28 return std::max(a, b);
29}
30
31template<typename T>
32inline T Max(
33 T a,
34 T b,
35 T c
36)
37{
38 return std::max(std::max(a, b), c);
39}
40
41template<typename T>
42inline 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
52template<typename T>
53inline T Min(
54 T a,
55 T b
56)
57{
58 return std::min(a, b);
59}
60
61template<typename T>
62inline T Min(
63 T a,
64 T b,
65 T c
66)
67{
68 return std::min(std::min(a, b), c);
69}
70
71template<typename T>
72inline 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,
113);
114
116#ifdef __GNUC__
118#endif
120 char* str,
121 long size,
122 const char* format,
123 ...
124);
125
135template<typename T>
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 {
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
#define DBG_ASSERT(test)
Definition IpDebug.hpp:27
Templated class which stores one entry for the CachedResult class.
#define IPOPTLIB_EXPORT
This file contains a base class for all exceptions and a set of macros to help with exceptions.
IPOPTLIB_EXPORT Number CpuTime()
method determining CPU time
IPOPTLIB_EXPORT Number SysTime()
method determining system time
IPOPTLIB_EXPORT bool IsFiniteNumber(Number val)
Function returning true iff the argument is a valid double number (not NaN or Inf).
IPOPTLIB_EXPORT bool Compare_le(Number lhs, Number rhs, Number BasVal)
Method for comparing two numbers within machine precision.
IPOPTLIB_EXPORT void IpResetRandom01()
Function resetting the random number generator.
T Max(T a, T b)
Definition IpUtils.hpp:23
T Min(T a, T b)
Definition IpUtils.hpp:53
ipnumber Number
Type of all numbers.
Definition IpTypes.hpp:17
IPOPTLIB_EXPORT int Snprintf(char *str, long size, const char *format,...)
Method for printing a formatted output to a string with given size.
IPOPTLIB_EXPORT Number WallclockTime()
method determining wallclock time since first call
IPOPTLIB_EXPORT Number IpRandom01()
Function returning a random number between 0 and 1.
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