00001
00002
00003
00004
00005 #ifndef CoinAbcCommon_H
00006 #define CoinAbcCommon_H
00007 #ifndef COIN_FAC_NEW
00008 #define COIN_FAC_NEW
00009 #endif
00010
00011 #include "CoinPragma.hpp"
00012 #include "CoinUtilsConfig.h"
00013 #include <iostream>
00014 #include <string>
00015 #include <cassert>
00016 #include <cstdio>
00017 #include <cmath>
00018 #include "AbcCommon.hpp"
00019 #include "CoinHelperFunctions.hpp"
00020
00021 typedef double CoinSimplexDouble;
00022 typedef int CoinSimplexInt;
00023 typedef unsigned int CoinSimplexUnsignedInt;
00024
00025 #if defined(_MSC_VER)
00026 #define ABC_INLINE __forceinline
00027 #elif defined(__GNUC__)
00028 #define ABC_INLINE __attribute__((always_inline))
00029 #else
00030 #define ABC_INLINE
00031 #endif
00032 #ifndef ABC_PARALLEL
00033 #ifdef HAS_CILK
00034 #define ABC_PARALLEL 2
00035 #else
00036 #define ABC_PARALLEL 0
00037 #endif
00038 #endif
00039 #if ABC_PARALLEL==2
00040
00041 #ifndef FAKE_CILK
00042 #include <cilk/cilk.h>
00043
00044 #ifdef GCC_4_9
00045 #undef cilk_for
00046 #define cilk_for for
00047 #endif
00048 #else
00049 #define cilk_for for
00050 #define cilk_spawn
00051 #define cilk_sync
00052 #endif
00053 #else
00054 #define cilk_for for
00055 #define cilk_spawn
00056 #define cilk_sync
00057
00058 #endif
00059 #define SLACK_VALUE 1
00060 #define ABC_INSTRUMENT 1 //2
00061 #if ABC_INSTRUMENT!=2
00062
00063 #define instrument_start(name,x)
00064 #define instrument_add(x)
00065 #define instrument_end()
00066
00067 #define instrument_do(name,x)
00068
00069 #define instrument_end_and_adjust(x)
00070 #else
00071 void instrument_start(const char * type,int numberRowsEtc);
00072 void instrument_add(int count);
00073 void instrument_do(const char * type,double count);
00074 void instrument_end();
00075 void instrument_end_and_adjust(double factor);
00076 #endif
00077 #ifndef __BYTE_ORDER
00078 #include <endian.h>
00079 #endif
00080 #if __BYTE_ORDER == __LITTLE_ENDIAN
00081 #define ABC_INTEL
00082 #endif
00083 #if COIN_BIG_DOUBLE==1
00084 #undef USE_TEST_ZERO
00085 #undef USE_TEST_REALLY_ZERO
00086 #undef USE_TEST_ZERO_REGISTER
00087 #undef USE_TEST_LESS_TOLERANCE
00088 #undef USE_TEST_LESS_TOLERANCE_REGISTER
00089 #define CoinFabs(x) fabsl(x)
00090 #else
00091 #define CoinFabs(x) fabs(x)
00092 #endif
00093 #ifdef USE_TEST_ZERO
00094 #if __BYTE_ORDER == __LITTLE_ENDIAN
00095 #define TEST_DOUBLE_NONZERO(x) ((reinterpret_cast<int *>(&x))[1]!=0)
00096 #else
00097 #define TEST_DOUBLE_NONZERO(x) ((reinterpret_cast<int *>(&x))[0]!=0)
00098 #endif
00099 #else
00100
00101 #define TEST_DOUBLE_NONZERO(x) (true)
00102 #endif
00103 #define USE_TEST_INT_ZERO
00104 #ifdef USE_TEST_INT_ZERO
00105 #define TEST_INT_NONZERO(x) (x)
00106 #else
00107
00108 #define TEST_INT_NONZERO(x) (true)
00109 #endif
00110 #ifdef USE_TEST_REALLY_ZERO
00111 #if __BYTE_ORDER == __LITTLE_ENDIAN
00112 #define TEST_DOUBLE_REALLY_NONZERO(x) ((reinterpret_cast<int *>(&x))[1]!=0)
00113 #else
00114 #define TEST_DOUBLE_REALLY_NONZERO(x) ((reinterpret_cast<int *>(&x))[0]!=0)
00115 #endif
00116 #else
00117 #define TEST_DOUBLE_REALLY_NONZERO(x) (x)
00118 #endif
00119 #ifdef USE_TEST_ZERO_REGISTER
00120 #if __BYTE_ORDER == __LITTLE_ENDIAN
00121 #define TEST_DOUBLE_NONZERO_REGISTER(x) ((reinterpret_cast<int *>(&x))[1]!=0)
00122 #else
00123 #define TEST_DOUBLE_NONZERO_REGISTER(x) ((reinterpret_cast<int *>(&x))[0]!=0)
00124 #endif
00125 #else
00126
00127 #define TEST_DOUBLE_NONZERO_REGISTER(x) (true)
00128 #endif
00129 #define USE_FIXED_ZERO_TOLERANCE
00130 #ifdef USE_FIXED_ZERO_TOLERANCE
00131
00132 #ifdef USE_TEST_LESS_TOLERANCE
00133 #if __BYTE_ORDER == __LITTLE_ENDIAN
00134 #define TEST_LESS_THAN_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000<0x3d400000)
00135 #define TEST_LESS_THAN_UPDATE_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000<0x3d400000)
00136 #else
00137 #define TEST_LESS_THAN_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000<0x3d400000)
00138 #define TEST_LESS_THAN_UPDATE_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000<0x3d400000)
00139 #endif
00140 #else
00141 #define TEST_LESS_THAN_TOLERANCE(x) (fabs(x)<pow(0.5,43))
00142 #define TEST_LESS_THAN_UPDATE_TOLERANCE(x) (fabs(x)<pow(0.5,43))
00143 #endif
00144 #ifdef USE_TEST_LESS_TOLERANCE_REGISTER
00145 #if __BYTE_ORDER == __LITTLE_ENDIAN
00146 #define TEST_LESS_THAN_TOLERANCE_REGISTER(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000<0x3d400000)
00147 #else
00148 #define TEST_LESS_THAN_TOLERANCE_REGISTER(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000<0x3d400000)
00149 #endif
00150 #else
00151 #define TEST_LESS_THAN_TOLERANCE_REGISTER(x) (fabs(x)<pow(0.5,43))
00152 #endif
00153 #else
00154 #define TEST_LESS_THAN_TOLERANCE(x) (fabs(x)<zeroTolerance_)
00155 #define TEST_LESS_THAN_TOLERANCE_REGISTER(x) (fabs(x)<zeroTolerance_)
00156 #endif
00157 #if COIN_BIG_DOUBLE!=1
00158 typedef unsigned int CoinExponent;
00159 #if __BYTE_ORDER == __LITTLE_ENDIAN
00160 #define ABC_EXPONENT(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000)
00161 #else
00162 #define ABC_EXPONENT(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000)
00163 #endif
00164 #define TEST_EXPONENT_LESS_THAN_TOLERANCE(x) (x<0x3d400000)
00165 #define TEST_EXPONENT_LESS_THAN_UPDATE_TOLERANCE(x) (x<0x3d400000)
00166 #define TEST_EXPONENT_NON_ZERO(x) (x)
00167 #else
00168 typedef long double CoinExponent;
00169 #define ABC_EXPONENT(x) (x)
00170 #define TEST_EXPONENT_LESS_THAN_TOLERANCE(x) (fabs(x)<pow(0.5,43))
00171 #define TEST_EXPONENT_LESS_THAN_UPDATE_TOLERANCE(x) (fabs(x)<pow(0.5,43))
00172 #define TEST_EXPONENT_NON_ZERO(x) (x)
00173 #endif
00174 #ifdef INT_IS_8
00175 #define COINFACTORIZATION_BITS_PER_INT 64
00176 #define COINFACTORIZATION_SHIFT_PER_INT 6
00177 #define COINFACTORIZATION_MASK_PER_INT 0x3f
00178 #else
00179 #define COINFACTORIZATION_BITS_PER_INT 32
00180 #define COINFACTORIZATION_SHIFT_PER_INT 5
00181 #define COINFACTORIZATION_MASK_PER_INT 0x1f
00182 #endif
00183 #if ABC_USE_HOMEGROWN_LAPACK==1
00184 #define ABC_USE_LAPACK
00185 #endif
00186 #ifdef ABC_USE_LAPACK
00187 #define F77_FUNC(x,y) x##_
00188 #define ABC_DENSE_CODE 1
00189
00190 #ifndef ipfint
00191
00192 typedef int ipfint;
00193 typedef const int cipfint;
00194 #endif
00195 enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102 };
00196 enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113,
00197 AtlasConj=114};
00198
00199
00200 extern "C"
00201 {
00203 void F77_FUNC(dgetrs,DGETRS)(char *trans, cipfint *n,
00204 cipfint *nrhs, const CoinSimplexDouble *A, cipfint *ldA,
00205 cipfint * ipiv, CoinSimplexDouble *B, cipfint *ldB, ipfint *info,
00206 int trans_len);
00208 void F77_FUNC(dgetrf,DGETRF)(ipfint * m, ipfint *n,
00209 CoinSimplexDouble *A, ipfint *ldA,
00210 ipfint * ipiv, ipfint *info);
00211 int clapack_dgetrf(const enum CBLAS_ORDER Order, const int M, const int N,
00212 double *A, const int lda, int *ipiv);
00213 int clapack_dgetrs
00214 (const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE Trans,
00215 const int N, const int NRHS, const double *A, const int lda,
00216 const int *ipiv, double *B, const int ldb);
00217 }
00218 #else // use home grown
00219
00220
00221
00222
00223
00224 #ifndef ABC_USE_HOMEGROWN_LAPACK
00225 #define ABC_DENSE_CODE 2
00226 #else
00227 #define ABC_DENSE_CODE ABC_USE_HOMEGROWN_LAPACK
00228 #endif
00229 #endif
00230 typedef unsigned char CoinCheckZero;
00231 template <class T> inline void
00232 CoinAbcMemset0(register T* to, const int size)
00233 {
00234 #ifndef NDEBUG
00235
00236 if (size < 0)
00237 throw CoinError("trying to fill negative number of entries",
00238 "CoinAbcMemset0", "");
00239 #endif
00240 std::memset(to,0,size*sizeof(T));
00241 }
00242 template <class T> inline void
00243 CoinAbcMemcpy(register T* to, register const T* from, const int size )
00244 {
00245 #ifndef NDEBUG
00246
00247 if (size < 0)
00248 throw CoinError("trying to copy negative number of entries",
00249 "CoinAbcMemcpy", "");
00250
00251 #endif
00252 std::memcpy(to,from,size*sizeof(T));
00253 }
00254 class ClpSimplex;
00255 class AbcSimplex;
00256 class AbcTolerancesEtc {
00257
00258 public:
00259
00260
00261
00263
00264
00265 AbcTolerancesEtc();
00266
00268 AbcTolerancesEtc(const ClpSimplex * model);
00269 AbcTolerancesEtc(const AbcSimplex * model);
00270
00272 AbcTolerancesEtc(const AbcTolerancesEtc &);
00273
00275 AbcTolerancesEtc & operator=(const AbcTolerancesEtc& rhs);
00276
00278 ~AbcTolerancesEtc ();
00280
00281
00282
00283
00284 public:
00286
00287
00288 double zeroTolerance_;
00290 double primalToleranceToGetOptimal_;
00292 double largeValue_;
00294 double alphaAccuracy_;
00296 double dualBound_;
00298 double dualTolerance_;
00300 double primalTolerance_;
00302 double infeasibilityCost_;
00312 double incomingInfeasibility_;
00313 double allowedInfeasibility_;
00315 int baseIteration_;
00317 int numberRefinements_;
00320 int forceFactorization_;
00328 int perturbation_;
00330 int dontFactorizePivots_;
00333 int maximumPivots_;
00335 };
00336 #endif