/home/coin/SVN-release/CoinAll-1.1.0/SYMPHONY/include/sym_macros.h

Go to the documentation of this file.
00001 /*===========================================================================*/
00002 /*                                                                           */
00003 /* This file is part of the SYMPHONY MILP Solver Framework.                  */
00004 /*                                                                           */
00005 /* SYMPHONY was jointly developed by Ted Ralphs (tkralphs@lehigh.edu) and    */
00006 /* Laci Ladanyi (ladanyi@us.ibm.com).                                        */
00007 /*                                                                           */
00008 /* (c) Copyright 2000-2008 Ted Ralphs. All Rights Reserved.                  */
00009 /*                                                                           */
00010 /* This software is licensed under the Common Public License. Please see     */
00011 /* accompanying file for terms.                                              */
00012 /*                                                                           */
00013 /*===========================================================================*/
00014 
00015 #ifndef _BB_MACROS_H
00016 #define _BB_MACROS_H
00017 
00018 /*-------------------------- Random number generator ------------------------*/
00019 
00020 #if defined(_MSC_VER) || defined (__MNO_CYGWIN)/* Different function call in
00021                                                   Windows */ 
00022 #define SRANDOM(seed) srand(seed)
00023 #define RANDOM() rand()
00024 #else
00025 #define SRANDOM(seed) srandom(seed)
00026 #define RANDOM() random()
00027 #endif
00028 
00029 /*---------------------------- Allocation macros ----------------------------*/
00030 
00031 #ifdef REMALLOC
00032 #undef REMALLOC
00033 #endif
00034 #define REMALLOC(ptr, ptrtype, oldsize, newsize, block_size)    \
00035 {                                                               \
00036    if (!ptr || (oldsize < newsize)){                            \
00037       FREE(ptr);                                                \
00038       oldsize = (newsize) + (block_size);                       \
00039       ptr = (ptrtype *) malloc((oldsize) * sizeof(ptrtype));    \
00040    }                                                            \
00041 }
00042 
00043 #ifdef REALLOC
00044 #undef REALLOC
00045 #endif
00046 #define REALLOC(ptr, ptrtype, oldsize, newsize, block_size)                  \
00047 {                                                                            \
00048    if (!ptr || (oldsize < newsize)){                                         \
00049       oldsize = (newsize) + (block_size);                                    \
00050       ptr = (ptrtype *) realloc((char *)ptr, ((oldsize) * sizeof(ptrtype))); \
00051    }                                                                         \
00052 }
00053 
00054 /*---------------------------- PVM macros -----------------------------------*/
00055 
00056 #define READ_INT_DESC(desc)                                                   \
00057 {                                                                             \
00058    receive_int_array(&(desc).size, 1);                                        \
00059    if ((desc).size > 0){                                                      \
00060       REMALLOC((desc).list, int, (desc).maxsize, (desc).size, BB_BUNCH);      \
00061       receive_int_array((desc).list, (desc).size);                            \
00062    }                                                                          \
00063 }
00064 
00065 #define READ_CHAR_ARRAY_WITH_SIZE(cptr, cnum, maxcnum)  \
00066 {                                                               \
00067    receive_int_array(&cnum, 1);                                 \
00068    if (cnum > 0){                                               \
00069       REMALLOC(cptr, char, maxcnum, cnum, BB_BUNCH);            \
00070       receive_char_array(cptr, cnum);                           \
00071    }                                                            \
00072 }
00073       
00074 #define READ_STR_LIST(snum, ssize, cptr, sptr)          \
00075 {                                                               \
00076    if (snum > 0){                                               \
00077       sptr = (char **) malloc(snum * sizeof(char *));           \
00078       cptr = (char *)  malloc(ssize * snum * CSIZE);            \
00079       receive_char_array(cptr, snum * ssize);                   \
00080       for (i = 0; i < snum; i++)                                \
00081          sptr[i] = cptr + i * ssize;                            \
00082    }                                                            \
00083 }
00084 
00085 
00086 /*--------------------- Parameter reading macros ----------------------------*/
00087 
00088 #define READPAR_ERROR(x)                                                \
00089 {                                                                       \
00090    (void) fprintf(stderr, "\nio: error reading parameter %s\n\n", x);   \
00091    exit(1);                                                             \
00092 }
00093 
00094 #define READ_INT_PAR(par)                                               \
00095 if (sscanf(value, "%i", &(par)) != 1){                                  \
00096    (void) fprintf(stderr, "\nio: error reading parameter %s\n\n", key); \
00097    exit(1);                                                             \
00098 }
00099 
00100 #define READ_STR_PAR(par)                                               \
00101 if (sscanf(value, "%s", par) != 1){                                     \
00102    (void) fprintf(stderr, "\nio: error reading parameter %s\n\n", key); \
00103    exit(1);                                                             \
00104 }
00105 
00106 #define READ_DBL_PAR(par)                                               \
00107 if (sscanf(value, "%lf", &(par)) != 1){                                 \
00108    (void) fprintf(stderr, "\nio: error reading parameter %s\n\n", key); \
00109    exit(1);                                                             \
00110 }
00111 
00112 #define READ_STRINT_PAR(par, str_array, array_size, value)                 \
00113 {                                                                          \
00114    for (i = array_size-1; i >= 0; i--){                                    \
00115       if (! strcmp(str_array[i].str, value)){                              \
00116          par |= str_array[i].code;                                         \
00117          break;                                                            \
00118       }                                                                    \
00119    }                                                                       \
00120    if (i < 0){                                                             \
00121       (void) fprintf(stderr, "\nio: error reading parameter %s\n\n", key); \
00122       exit(1);                                                             \
00123    }                                                                       \
00124 }
00125 
00126 /*------------------------ Copying macros -----------------------------------*/
00127 
00128 #define COPY_DBL_ARRAY_DESC(newad, oldad)                                  \
00129 if (newad.size > 0){                                                       \
00130    newad.stat = (int *) malloc(newad.size*ISIZE);                          \
00131    memcpy((char *)newad.stat, (char *)oldad.stat, oldad.size*ISIZE);       \
00132    if (newad.type == WRT_PARENT){                                          \
00133       newad.list = (int *) malloc(oldad.size*ISIZE);                       \
00134       memcpy((char *)newad.list, (char *)oldad.list, oldad.size*ISIZE);    \
00135    }                                                                       \
00136 }
00137 
00138 #define COPY_STAT(newad, oldad)                                            \
00139 if (newad.size > 0){                                                       \
00140    newad.stat = (int *) malloc(newad.size*ISIZE);                          \
00141    memcpy((char *)newad.stat, (char *)oldad.stat, oldad.size*ISIZE);       \
00142 }
00143 
00144 #define COPY_ARRAY_DESC(newad, oldad)                                      \
00145 newad = oldad;                                                             \
00146 if (newad.size > 0){                                                       \
00147    newad.list = (int *) malloc(oldad.size*ISIZE);                          \
00148    memcpy((char *)newad.list, (char *)oldad.list, oldad.size*ISIZE);       \
00149 }
00150 
00151 /*--------------- Macro for calling user functions --------------------------*/
00152 
00153 #define CALL_USER_FUNCTION(f)                                              \
00154 switch (f){                                                                \
00155  case USER_ERROR:                                                          \
00156    printf("\n\n*********User error detected -- aborting***********\n\n");  \
00157    return(ERROR__USER);                                                    \
00158  default:                                                                  \
00159    break;                                                                  \
00160 }
00161    
00162 /*------------- Macro for calling wrapper functions -------------------------*/
00163 
00164 #define CALL_WRAPPER_FUNCTION(f)                                           \
00165 if ((termcode = f) < 0)                                                    \
00166    return(termcode);
00167 
00168 /*---------------------- Standard macros ------------------------------------*/
00169 
00170 #ifdef FREE
00171 #undef FREE
00172 #endif
00173 #define FREE(p) if (p) {(void)free((char *)(p)); p = NULL;}
00174 
00175 #ifndef MIN
00176 #undef MIN
00177 #define MIN(a,b) ((a) < (b) ? (a) : (b))
00178 #endif
00179 
00180 #ifdef MAX
00181 #undef MAX
00182 #endif
00183 #define MAX(a,b) ((a) > (b) ? (a) : (b))
00184 
00185 
00186 #ifdef isset
00187 #   undef isset
00188 #   undef isclr
00189 #endif
00190 #ifdef ISSET_WITH_NBBY
00191 #   ifndef NBBY
00192 #      define NBBY 8
00193 #   endif
00194 #   define isset(a, i)     (((a)[(i)/NBBY] >> ((i) % NBBY)) & 1)
00195 #else
00196 #   define LOG_OF_BITS_PER_BYTE 3
00197 #   define BITS_PER_BYTE_LESS_ONE 7
00198 #   define isset(a, i)  (((a)[(i) >> LOG_OF_BITS_PER_BYTE] >> \
00199                           ((i) & BITS_PER_BYTE_LESS_ONE)) & 1)
00200 #endif
00201 #define isclr(a, i)  (! isset(a, i))
00202 
00203 #ifdef setbit
00204 #   undef setbit
00205 #endif
00206 #ifdef ISSET_WITH_NBBY
00207 #   ifndef NBBY
00208 #      define NBBY 8
00209 #   endif
00210 #   define setbit(a, i) ((a)[(i)/NBBY] |= (1 << ((i) % NBBY)))
00211 #else
00212 #   ifndef LOG_OF_BITS_PER_BYTE
00213 #      define LOG_OF_BITS_PER_BYTE 3
00214 #      define BITS_PER_BYTE_LESS_ONE 7
00215 #   endif
00216 #   define setbit(a, i) ((a)[(i) >> LOG_OF_BITS_PER_BYTE] |= \
00217                          (1 << ((i) & BITS_PER_BYTE_LESS_ONE)))
00218 #endif
00219 
00220 #endif

Generated on Sun Nov 14 14:06:42 2010 for Coin-All by  doxygen 1.4.7