13 #ifndef UTIL_MACROS_INCLUDED
14 #define UTIL_MACROS_INCLUDED
28 #define UTIL_DELPTR(x) if(x) {delete x; x = 0;}
29 #define UTIL_DELARR(x) if(x) {delete [] x; x = 0;}
34 #define UTIL_DEBUG(param, level, x) if(param > level) {x fflush(stdout);}
35 #define UTIL_DEBUG0(x) {x fflush(stdout);}
38 template <
class T>
inline void
42 typename vector<T>::const_iterator it;
45 for (it = v.begin(); it != v.end(); it++) {
51 template <
class T>
inline void
55 typename list<T>::const_iterator it;
58 for (it = v.begin(); it != v.end(); it++) {
130 return ((n * n) - n) / 2;
136 return i > j ? (i * (i - 1) / 2) + j : (j * (j - 1) / 2) + i;
147 (*os) <<
"(" << setw(2) << uv.first <<
"," << setw(2) << uv.second <<
") ";
157 template <
class T>
inline void
164 template <
class T>
inline void
167 std::fill_n(back_inserter(v), size, value);
175 int val = init + size;
178 for (ii = size; ii-- != 0; ) {
190 int i, val = init + size;
192 for (i = init; i < val; i++) {
204 double rand01 =
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
205 return a + (rand01 * (b - a));
211 double rand01 =
static_cast<double>(rand()) / static_cast<double>(RAND_MAX);
212 return a +
static_cast<int>(rand01 * (b - a));
220 inline double UtilAve(
const vector<double> & x)
222 return std::accumulate(x.begin(), x.end(), 0.0) / x.size();
228 return std::accumulate(x.begin(), x.end(), 0.0) / x.size();
235 return std::accumulate(x, x + len, 0.0) / len;
245 double floor_x = floor(x);
246 double floor_xplus = floor(x + 0.5);
248 if (fabs(floor_xplus - x) < (
UtilEpsilon * (fabs(floor_xplus) + 1.0))) {
257 const double* arrDbl,
265 const double* arrDbl,
273 const double etol = 1.0e-8)
275 return fabs(x) < etol;
289 typename vector<T*>::iterator first,
290 typename vector<T*>::iterator last)
292 typename vector<T*>::iterator it;
294 for (it = first; it != last; it++) {
298 vectorPtr.erase(first, last);
309 typename list<T*>::iterator first,
310 typename list<T*>::iterator last)
312 typename list<T*>::iterator it;
314 for (it = first; it != last; it++) {
318 listPtr.erase(first, last);
329 const double etol = 1.0e-10)
338 transform(arr, arr + arrLen, arr, negate<T>());
356 transform(arr, arr + arrLen, arr,
AddOffset<T>(offset));
378 transform(arr, arr + arrLen, arr,
Perturb(randLB, randUB));
393 for (
int i = 0; i < len; i++) {
475 const pair<S, T> & y) {
476 return x.second > y.second;
484 const pair<S, T> & y) {
485 return x.second < y.second;
494 const pair<int, double> & y) {
495 return x.second < y.second;
497 bool operator()(
const pair< pair<int, int>,
double> & x,
498 const pair< pair<int, int>,
double> & y) {
499 return x.second < y.second;
507 const pair<int, double> & y) {
508 return x.second > y.second;
517 #if defined(_MSC_VER)
532 string errMessage =
"Error: Filename = ";
533 errMessage += fileName;
534 errMessage +=
" failed to open.";
552 string::size_type pos = s.find_last_not_of(t);
554 if (pos != string::npos) {
556 pos = s.find_first_not_of(
' ');
558 if (pos != string::npos) {
562 s.erase(s.begin(), s.end());
580 for (i = 0; s[i] !=
'\0'; i++) {
581 s[i] =
static_cast<char>(tolower(s[i]));
600 for (i = 0; s[i] !=
'\0'; i++) {
601 s[i] =
static_cast<char>(toupper(s[i]));
int UtilIndexU(const int i, const int j)
CoinPackedVector * UtilPackedVectorFromDense(const int len, const double *dense, const double etol)
void UtilSenseToBound(const char sense, const double rhs, const double range, const double inf, double &lb, double &ub)
void UtilDeleteVectorPtr(vector< T * > &vectorPtr, typename vector< T * >::iterator first, typename vector< T * >::iterator last)
void UtilNegateArr(const int arrLen, T *arr)
bool UtilIsZero(const double x, const double etol=1.0e-8)
void UtilPrintList(const list< T > &v, ostream *os=&cout)
int UtilNumEdgesU(const int n)
void UtilBoundToSense(const double lb, const double ub, const double inf, char &sense, double &rhs, double &range)
pair< int, int > UtilBothEndsU(const int index)
void UtilPerturbCost(const int seed, const int arrLen, const double randLB, const double randUB, double *arr)
double UtilAve(const vector< double > &x)
#define CoinAssertHint(expression, hint)
string & UtilStrToUpper(string &s)
void UtilPrintEdge(const int index, ostream *os=&cout)
void UtilIotaN(int *first, const int size, const int init)
void UtilDeleteListPtr(list< T * > &listPtr, typename list< T * >::iterator first, typename list< T * >::iterator last)
void UtilOpenFile(ifstream &fs, const char *fileName)
void UtilPrintVector(const vector< T > &v, ostream *os=&cout)
double UtilFracPart(const double x)
void UtilPrintPackedVector(const CoinPackedVector &v, ostream *os=&cout, DecompApp *app=0)
void UtilAddOffsetArr(const int arrLen, T offset, T *arr)
void UtilFillN(T *to, const int size, const T value)
void CoinFillN(T *to, const CoinBigIndex size, const T value)
This helper function fills an array with a given value.
Error Class thrown by an exception.
string UtilIntToStr(const int i)
Perturb(double randLB, double randUB)
bool operator()(const pair< S, T > &x, const pair< S, T > &y)
bool UtilIsIntegral(const double x, const double etol=1.0e-10)
bool operator()(const pair< S, T > &x, const pair< S, T > &y)
double UtilURand(const double a, const double b)
string & UtilStrTrim(string &s, const string &t=UtilSpaces)
void UtilFlipRowLtoG(const int len, double *els, char &sense, double &rhs)
int UtilScaleDblToIntArr(const int arrLen, const double *arrDbl, int *arrInt, const double oneDbl, int *oneInt, const double epstol=UtilEpsilon)
string & UtilStrToLower(string &s)
The main application class.
double operator()(const double &k)