Dip  0.92.4
Classes | Macros | Enumerations | Functions | Variables
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)   floor(x+0.5)
 
#define UTIL_DELPTR(x)   if(x) {delete x; x = 0;}
 
#define UTIL_DELARR(x)   if(x) {delete [] x; x = 0;}
 
#define UTIL_DEBUG(param, level, x)   if(param >= level) {x fflush(stdout);}
 
#define UTIL_MSG(param, level, x)   if(param >= level) {x fflush(stdout);}
 
#define UtilAssert(expression, errorMsg, os)   assert(expresssion)
 

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

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

Definition at line 44 of file UtilMacros.h.

Referenced by AlpsKnowledgePool::getMaxNumKnowledges().

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

Definition at line 48 of file UtilMacros.h.

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

Definition at line 64 of file UtilMacros.h.

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

Definition at line 65 of file UtilMacros.h.

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

Definition at line 75 of file UtilMacros.h.

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

Definition at line 79 of file UtilMacros.h.

Referenced by DecompAlgoD::setObjBoundIP(), and DecompAlgo::setObjBoundIP().

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

Definition at line 84 of file UtilMacros.h.

Enumeration Type Documentation

enum UtilStatus
Enumerator
UtilStatusOk 
UtilStatusFileIO 

Definition at line 56 of file UtilMacros.h.

Function Documentation

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.

Referenced by DecompParam::dumpSettings().

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.

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.

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

Definition at line 136 of file UtilMacros.h.

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.

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

Definition at line 164 of file UtilMacros.h.

int UtilNumEdgesU ( const int  n)
inline

Definition at line 222 of file UtilMacros.h.

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

Definition at line 228 of file UtilMacros.h.

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

Definition at line 237 of file UtilMacros.h.

References UtilBothEndsU().

std::string UtilEdgeToStr ( const int  index)
inline

Definition at line 246 of file UtilMacros.h.

References UtilBothEndsU().

Referenced by VRP_Concorde::setExpandedCost().

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

Definition at line 261 of file UtilMacros.h.

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

Definition at line 272 of file UtilMacros.h.

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

Definition at line 278 of file UtilMacros.h.

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

Definition at line 291 of file UtilMacros.h.

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

Definition at line 308 of file UtilMacros.h.

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

Definition at line 315 of file UtilMacros.h.

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

Definition at line 322 of file UtilMacros.h.

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

Definition at line 338 of file UtilMacros.h.

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

Definition at line 345 of file UtilMacros.h.

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

Definition at line 352 of file UtilMacros.h.

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

Definition at line 363 of file UtilMacros.h.

std::string UtilStringRandom ( int  iLength)
inline

Definition at line 384 of file UtilMacros.h.

References srand.

Referenced by VRP_Concorde::solveTSP().

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

Definition at line 414 of file UtilMacros.h.

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

Definition at line 439 of file UtilMacros.h.

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

Definition at line 458 of file UtilMacros.h.

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

Definition at line 480 of file UtilMacros.h.

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

Definition at line 486 of file UtilMacros.h.

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

Definition at line 504 of file UtilMacros.h.

double UtilFracPart ( const double  x)
inline

Definition at line 521 of file UtilMacros.h.

References UtilEpsilon.

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 
)
inline

Definition at line 548 of file UtilMacros.h.

std::string UtilIntToStr ( const int  i)
inline

Definition at line 555 of file UtilMacros.h.

std::string UtilDblToStr ( const double  x,
const int  precision = -1,
const double  tooBig = UtilSmallerThanTooBig 
)
inline
void UtilPrintMemUsage ( std::ostream *  os = &std::cout,
int  logLevel = 0,
int  logLimit = 2 
)
inline

Definition at line 588 of file UtilMacros.h.

References UtilDblToStr().

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.

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

Definition at line 624 of file UtilMacros.h.

References UtilDeleteVectorPtr().

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.

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

Definition at line 644 of file UtilMacros.h.

References UtilDeleteListPtr().

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)

Definition at line 665 of file UtilMacros.h.

References UtilDeleteMapPtr().

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.

References UtilDeleteVectorPtr().

Referenced by UtilDeleteMapVecPtr().

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

Definition at line 687 of file UtilMacros.h.

References UtilDeleteMapVecPtr().

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

Definition at line 693 of file UtilMacros.h.

References UtilIsZero().

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

Definition at line 700 of file UtilMacros.h.

References UtilIsIntegral().

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

Definition at line 716 of file UtilMacros.h.

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

Definition at line 733 of file UtilMacros.h.

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.

References srand.

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

Definition at line 763 of file UtilMacros.h.

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.

References UtilIsZero().

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.

std::string UtilDirSlash ( )
inline

Definition at line 870 of file UtilMacros.h.

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

Definition at line 882 of file UtilMacros.h.

References UtilStatusFileIO, and UtilStatusOk.

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

Definition at line 902 of file UtilMacros.h.

References UtilStatusFileIO, and UtilStatusOk.

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

Definition at line 922 of file UtilMacros.h.

References UtilOpenFile().

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

Definition at line 929 of file UtilMacros.h.

References UtilOpenFile().

Variable Documentation

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

Definition at line 39 of file UtilMacros.h.

const double UtilEpsilon = 1.0e-6

Definition at line 40 of file UtilMacros.h.

const double UtilTooBig = 1.0e20

Definition at line 41 of file UtilMacros.h.

const double UtilSmallerThanTooBig = 1.0e19

Definition at line 42 of file UtilMacros.h.