Dip 0.95.0
Loading...
Searching...
No Matches
UtilMacros.h File Reference
#include <cstdio>
#include <cassert>
#include <vector>
#include <list>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <algorithm>
#include <functional>
#include <string>
#include <map>
#include <climits>
#include <cmath>
#include <cstring>
#include <ctime>
#include <memory>
+ Include dependency graph for UtilMacros.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  AddOffset< T >
 
struct  Perturb
 
class  UtilIsGreaterThan< S, T >
 
class  UtilIsLessThan< S, T >
 

Macros

#define INT_MAX   (static_cast<int>((~(static_cast<unsigned int>(0))) >> 1))
 
#define round(x)
 
#define UTIL_DELPTR(x)
 
#define UTIL_DELARR(x)
 
#define UTIL_DEBUG(param, level, x)
 
#define UTIL_MSG(param, level, x)
 
#define UtilAssert(expression, errorMsg, os)
 

Enumerations

enum  UtilStatus { UtilStatusOk = 0 , UtilStatusFileIO }
 

Functions

void UtilPrintParameter (std::ostream *os, const std::string &section, const std::string &name, const int value)
 
void UtilPrintParameter (std::ostream *os, const std::string &section, const std::string &name, const double value)
 
void UtilPrintParameter (std::ostream *os, const std::string &section, const std::string &name, const std::string &value)
 
template<class T >
void UtilPrintVector (const std::vector< T > &v, std::ostream *os=&std::cout)
 
template<class T >
void UtilPrintVector (const std::vector< T > &v, const std::vector< std::string > &label, std::ostream *os=&std::cout)
 
template<class T >
void UtilPrintList (const std::list< T > &v, std::ostream *os=&std::cout)
 
int UtilNumEdgesU (const int n)
 
int UtilIndexU (const int i, const int j)
 
std::pair< int, int > UtilBothEndsU (const int index)
 
void UtilPrintEdge (const int index, std::ostream *os=&std::cout)
 
std::string UtilEdgeToStr (const int index)
 
template<class T >
void UtilFillN (T *to, const int size, const T value)
 
template<class T >
void UtilFillN (std::vector< T > &v, const int size, const T value)
 
void UtilIotaN (int *first, const int size, const int init)
 
void UtilIotaN (std::vector< int > &first, const int size, const int init)
 
double UtilURand (const double a, const double b)
 
int UtilURand (const int a, const int b)
 
double UtilNormRand (const double mean, const double sigma)
 
double UtilAve (const std::vector< double > &x)
 
double UtilAve (const std::vector< int > &x)
 
double UtilAve (const double *x, const int len)
 
void UtilStringTokenize (std::string const &input, std::string const &delimiters, std::vector< std::string > &tokens)
 
std::string UtilStringRandom (int iLength)
 
std::string & UtilStrTrim (std::string &s, const std::string &t=UtilSpaces)
 
std::string & UtilStrToLower (std::string &s)
 
std::string & UtilStrToUpper (std::string &s)
 
template<class T >
int UtilGetSize (const std::vector< T > &vec)
 
bool UtilIsInSet (const int value, const int *set, const int setSize)
 
int UtilNumNonzeros (const double *x, const int len, const double etol=1.0e-8)
 
double UtilFracPart (const double x)
 
int UtilScaleDblToIntArr (const int arrLen, const double *arrDbl, int *arrInt, const double oneDbl, int *oneInt, const double epstol=UtilEpsilon)
 
int UtilScaleDblToIntArr (const int arrLen, const double *arrDbl, int *arrInt, const double epstol=UtilEpsilon)
 
bool UtilIsZero (const double x, const double etol=1.0e-8)
 
std::string UtilIntToStr (const int i)
 
std::string UtilDblToStr (const double x, const int precision=-1, const double tooBig=UtilSmallerThanTooBig)
 
void UtilPrintMemUsage (std::ostream *os=&std::cout, int logLevel=0, int logLimit=2)
 
template<class T >
void UtilDeleteVectorPtr (std::vector< T * > &vectorPtr, typename std::vector< T * >::iterator first, typename std::vector< T * >::iterator last)
 
template<class T >
void UtilDeleteVectorPtr (std::vector< T * > &vectorPtr)
 
template<class T >
void UtilDeleteListPtr (std::list< T * > &listPtr, typename std::list< T * >::iterator first, typename std::list< T * >::iterator last)
 
template<class T >
void UtilDeleteListPtr (std::list< T * > &listPtr)
 
template<class S , class T >
void UtilDeleteMapPtr (std::map< S, T * > &mapPtr, typename std::map< S, T * >::iterator first, typename std::map< S, T * >::iterator last)
 
template<class S , class T >
void UtilDeleteMapPtr (std::map< S, T * > &mapPtr)
 
template<class S , class T >
void UtilDeleteMapVecPtr (std::map< S, std::vector< T * > > &mapPtr, typename std::map< S, std::vector< T * > >::iterator first, typename std::map< S, std::vector< T * > >::iterator last)
 
template<class S , class T >
void UtilDeleteMapVecPtr (std::map< S, std::vector< T * > > &mapPtr)
 
bool UtilIsIntegral (const double x, const double etol=1.0e-10)
 
bool UtilIsIntegral (const double *x, const int len, const double etol=1.0e-10)
 
template<class T >
void UtilNegateArr (const int arrLen, T *arr)
 
template<class T >
void UtilAddOffsetArr (const int arrLen, T offset, T *arr)
 
void UtilPerturbCost (const int seed, const int arrLen, const double randLB, const double randUB, double *arr)
 
void UtilFlipRowLtoG (const int len, double *els, char &sense, double &rhs)
 
void UtilBoundToSense (const double lb, const double ub, const double inf, char &sense, double &rhs, double &range)
 
void UtilSenseToBound (const char sense, const double rhs, const double range, const double inf, double &lb, double &ub)
 
std::string UtilDirSlash ()
 
int UtilOpenFile (std::ofstream &os, const char *fileName)
 
int UtilOpenFile (std::ifstream &is, const char *fileName)
 
int UtilOpenFile (std::ofstream &os, const std::string &fileName)
 
int UtilOpenFile (std::ifstream &is, const std::string &fileName)
 

Variables

const std::string UtilSpaces = " \t\r\n"
 
const double UtilEpsilon = 1.0e-6
 
const double UtilTooBig = 1.0e20
 
const double UtilSmallerThanTooBig = 1.0e19
 

Macro Definition Documentation

◆ INT_MAX

#define INT_MAX   (static_cast<int>((~(static_cast<unsigned int>(0))) >> 1))

Definition at line 44 of file UtilMacros.h.

◆ round

#define round ( x)
Value:
floor(x+0.5)

Definition at line 48 of file UtilMacros.h.

◆ UTIL_DELPTR

#define UTIL_DELPTR ( x)
Value:
if(x) {delete x; x = 0;}

Definition at line 64 of file UtilMacros.h.

◆ UTIL_DELARR

#define UTIL_DELARR ( x)
Value:
if(x) {delete [] x; x = 0;}

Definition at line 65 of file UtilMacros.h.

◆ UTIL_DEBUG

#define UTIL_DEBUG ( param,
level,
x )
Value:
if(param >= level) {x fflush(stdout);}

Definition at line 75 of file UtilMacros.h.

◆ UTIL_MSG

#define UTIL_MSG ( param,
level,
x )
Value:
if(param >= level) {x fflush(stdout);}

Definition at line 79 of file UtilMacros.h.

◆ UtilAssert

#define UtilAssert ( expression,
errorMsg,
os )
Value:
assert(expresssion)

Definition at line 84 of file UtilMacros.h.

Enumeration Type Documentation

◆ UtilStatus

enum UtilStatus
Enumerator
UtilStatusOk 
UtilStatusFileIO 

Definition at line 56 of file UtilMacros.h.

Function Documentation

◆ UtilPrintParameter() [1/3]

void UtilPrintParameter ( std::ostream * os,
const std::string & section,
const std::string & name,
const int value )
inline

Definition at line 101 of file UtilMacros.h.

◆ UtilPrintParameter() [2/3]

void UtilPrintParameter ( std::ostream * os,
const std::string & section,
const std::string & name,
const double value )
inline

Definition at line 112 of file UtilMacros.h.

◆ UtilPrintParameter() [3/3]

void UtilPrintParameter ( std::ostream * os,
const std::string & section,
const std::string & name,
const std::string & value )
inline

Definition at line 123 of file UtilMacros.h.

◆ UtilPrintVector() [1/2]

template<class T >
void UtilPrintVector ( const std::vector< T > & v,
std::ostream * os = &std::cout )
inline

Definition at line 136 of file UtilMacros.h.

◆ UtilPrintVector() [2/2]

template<class T >
void UtilPrintVector ( const std::vector< T > & v,
const std::vector< std::string > & label,
std::ostream * os = &std::cout )
inline

Definition at line 150 of file UtilMacros.h.

◆ UtilPrintList()

template<class T >
void UtilPrintList ( const std::list< T > & v,
std::ostream * os = &std::cout )
inline

Definition at line 164 of file UtilMacros.h.

◆ UtilNumEdgesU()

int UtilNumEdgesU ( const int n)
inline

Definition at line 222 of file UtilMacros.h.

◆ UtilIndexU()

int UtilIndexU ( const int i,
const int j )
inline

Definition at line 228 of file UtilMacros.h.

◆ UtilBothEndsU()

std::pair< int, int > UtilBothEndsU ( const int index)

◆ UtilPrintEdge()

void UtilPrintEdge ( const int index,
std::ostream * os = &std::cout )
inline

Definition at line 237 of file UtilMacros.h.

◆ UtilEdgeToStr()

std::string UtilEdgeToStr ( const int index)
inline

Definition at line 246 of file UtilMacros.h.

◆ UtilFillN() [1/2]

template<class T >
void UtilFillN ( T * to,
const int size,
const T value )
inline

Definition at line 261 of file UtilMacros.h.

◆ UtilFillN() [2/2]

template<class T >
void UtilFillN ( std::vector< T > & v,
const int size,
const T value )
inline

Definition at line 272 of file UtilMacros.h.

◆ UtilIotaN() [1/2]

void UtilIotaN ( int * first,
const int size,
const int init )
inline

Definition at line 278 of file UtilMacros.h.

◆ UtilIotaN() [2/2]

void UtilIotaN ( std::vector< int > & first,
const int size,
const int init )
inline

Definition at line 291 of file UtilMacros.h.

◆ UtilURand() [1/2]

double UtilURand ( const double a,
const double b )
inline

Definition at line 308 of file UtilMacros.h.

◆ UtilURand() [2/2]

int UtilURand ( const int a,
const int b )
inline

Definition at line 315 of file UtilMacros.h.

◆ UtilNormRand()

double UtilNormRand ( const double mean,
const double sigma )
inline

Definition at line 322 of file UtilMacros.h.

◆ UtilAve() [1/3]

double UtilAve ( const std::vector< double > & x)
inline

Definition at line 338 of file UtilMacros.h.

◆ UtilAve() [2/3]

double UtilAve ( const std::vector< int > & x)
inline

Definition at line 345 of file UtilMacros.h.

◆ UtilAve() [3/3]

double UtilAve ( const double * x,
const int len )
inline

Definition at line 352 of file UtilMacros.h.

◆ UtilStringTokenize()

void UtilStringTokenize ( std::string const & input,
std::string const & delimiters,
std::vector< std::string > & tokens )
inline

Definition at line 363 of file UtilMacros.h.

◆ UtilStringRandom()

std::string UtilStringRandom ( int iLength)
inline

Definition at line 384 of file UtilMacros.h.

◆ UtilStrTrim()

std::string & UtilStrTrim ( std::string & s,
const std::string & t = UtilSpaces )
inline

Definition at line 414 of file UtilMacros.h.

◆ UtilStrToLower()

std::string & UtilStrToLower ( std::string & s)
inline

Definition at line 439 of file UtilMacros.h.

◆ UtilStrToUpper()

std::string & UtilStrToUpper ( std::string & s)
inline

Definition at line 458 of file UtilMacros.h.

◆ UtilGetSize()

template<class T >
int UtilGetSize ( const std::vector< T > & vec)
inline

Definition at line 480 of file UtilMacros.h.

◆ UtilIsInSet()

bool UtilIsInSet ( const int value,
const int * set,
const int setSize )
inline

Definition at line 486 of file UtilMacros.h.

◆ UtilNumNonzeros()

int UtilNumNonzeros ( const double * x,
const int len,
const double etol = 1.0e-8 )
inline

Definition at line 504 of file UtilMacros.h.

◆ UtilFracPart()

double UtilFracPart ( const double x)
inline

Definition at line 521 of file UtilMacros.h.

◆ UtilScaleDblToIntArr() [1/2]

int UtilScaleDblToIntArr ( const int arrLen,
const double * arrDbl,
int * arrInt,
const double oneDbl,
int * oneInt,
const double epstol = UtilEpsilon )

◆ UtilScaleDblToIntArr() [2/2]

int UtilScaleDblToIntArr ( const int arrLen,
const double * arrDbl,
int * arrInt,
const double epstol = UtilEpsilon )

◆ UtilIsZero()

bool UtilIsZero ( const double x,
const double etol = 1.0e-8 )
inline

Definition at line 548 of file UtilMacros.h.

◆ UtilIntToStr()

std::string UtilIntToStr ( const int i)
inline

Definition at line 555 of file UtilMacros.h.

◆ UtilDblToStr()

std::string UtilDblToStr ( const double x,
const int precision = -1,
const double tooBig = UtilSmallerThanTooBig )
inline

Definition at line 563 of file UtilMacros.h.

◆ UtilPrintMemUsage()

void UtilPrintMemUsage ( std::ostream * os = &std::cout,
int logLevel = 0,
int logLimit = 2 )
inline

Definition at line 588 of file UtilMacros.h.

◆ UtilDeleteVectorPtr() [1/2]

template<class T >
void UtilDeleteVectorPtr ( std::vector< T * > & vectorPtr,
typename std::vector< T * >::iterator first,
typename std::vector< T * >::iterator last )

Definition at line 610 of file UtilMacros.h.

◆ UtilDeleteVectorPtr() [2/2]

template<class T >
void UtilDeleteVectorPtr ( std::vector< T * > & vectorPtr)

Definition at line 624 of file UtilMacros.h.

◆ UtilDeleteListPtr() [1/2]

template<class T >
void UtilDeleteListPtr ( std::list< T * > & listPtr,
typename std::list< T * >::iterator first,
typename std::list< T * >::iterator last )

Definition at line 630 of file UtilMacros.h.

◆ UtilDeleteListPtr() [2/2]

template<class T >
void UtilDeleteListPtr ( std::list< T * > & listPtr)

Definition at line 644 of file UtilMacros.h.

◆ UtilDeleteMapPtr() [1/2]

template<class S , class T >
void UtilDeleteMapPtr ( std::map< S, T * > & mapPtr,
typename std::map< S, T * >::iterator first,
typename std::map< S, T * >::iterator last )

Definition at line 651 of file UtilMacros.h.

◆ UtilDeleteMapPtr() [2/2]

template<class S , class T >
void UtilDeleteMapPtr ( std::map< S, T * > & mapPtr)

Definition at line 665 of file UtilMacros.h.

◆ UtilDeleteMapVecPtr() [1/2]

template<class S , class T >
void UtilDeleteMapVecPtr ( std::map< S, std::vector< T * > > & mapPtr,
typename std::map< S, std::vector< T * > >::iterator first,
typename std::map< S, std::vector< T * > >::iterator last )

Definition at line 672 of file UtilMacros.h.

◆ UtilDeleteMapVecPtr() [2/2]

template<class S , class T >
void UtilDeleteMapVecPtr ( std::map< S, std::vector< T * > > & mapPtr)

Definition at line 687 of file UtilMacros.h.

◆ UtilIsIntegral() [1/2]

bool UtilIsIntegral ( const double x,
const double etol = 1.0e-10 )
inline

Definition at line 693 of file UtilMacros.h.

◆ UtilIsIntegral() [2/2]

bool UtilIsIntegral ( const double * x,
const int len,
const double etol = 1.0e-10 )
inline

Definition at line 700 of file UtilMacros.h.

◆ UtilNegateArr()

template<class T >
void UtilNegateArr ( const int arrLen,
T * arr )
inline

Definition at line 716 of file UtilMacros.h.

◆ UtilAddOffsetArr()

template<class T >
void UtilAddOffsetArr ( const int arrLen,
T offset,
T * arr )
inline

Definition at line 733 of file UtilMacros.h.

◆ UtilPerturbCost()

void UtilPerturbCost ( const int seed,
const int arrLen,
const double randLB,
const double randUB,
double * arr )
inline

Definition at line 752 of file UtilMacros.h.

◆ UtilFlipRowLtoG()

void UtilFlipRowLtoG ( const int len,
double * els,
char & sense,
double & rhs )
inline

Definition at line 763 of file UtilMacros.h.

◆ UtilBoundToSense()

void UtilBoundToSense ( const double lb,
const double ub,
const double inf,
char & sense,
double & rhs,
double & range )
inline

Definition at line 785 of file UtilMacros.h.

◆ UtilSenseToBound()

void UtilSenseToBound ( const char sense,
const double rhs,
const double range,
const double inf,
double & lb,
double & ub )
inline

Definition at line 820 of file UtilMacros.h.

◆ UtilDirSlash()

std::string UtilDirSlash ( )
inline

Definition at line 870 of file UtilMacros.h.

◆ UtilOpenFile() [1/4]

int UtilOpenFile ( std::ofstream & os,
const char * fileName )
inline

Definition at line 882 of file UtilMacros.h.

◆ UtilOpenFile() [2/4]

int UtilOpenFile ( std::ifstream & is,
const char * fileName )
inline

Definition at line 902 of file UtilMacros.h.

◆ UtilOpenFile() [3/4]

int UtilOpenFile ( std::ofstream & os,
const std::string & fileName )
inline

Definition at line 922 of file UtilMacros.h.

◆ UtilOpenFile() [4/4]

int UtilOpenFile ( std::ifstream & is,
const std::string & fileName )
inline

Definition at line 929 of file UtilMacros.h.

Variable Documentation

◆ UtilSpaces

const std::string UtilSpaces = " \t\r\n"

Definition at line 39 of file UtilMacros.h.

◆ UtilEpsilon

const double UtilEpsilon = 1.0e-6

Definition at line 40 of file UtilMacros.h.

◆ UtilTooBig

const double UtilTooBig = 1.0e20

Definition at line 41 of file UtilMacros.h.

◆ UtilSmallerThanTooBig

const double UtilSmallerThanTooBig = 1.0e19

Definition at line 42 of file UtilMacros.h.