CoinAbcCommon.hpp

Go to the documentation of this file.
00001 /* $Id: CoinAbcCommon.hpp 1910 2013-01-27 02:00:13Z stefan $ */
00002 // Copyright (C) 2000, International Business Machines
00003 // Corporation and others, Copyright (C) 2012, FasterCoin.  All Rights Reserved.
00004 // This code is licensed under the terms of the Eclipse Public License (EPL).
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 //#include "config.h"
00021 typedef double CoinSimplexDouble;
00022 typedef int CoinSimplexInt;
00023 typedef unsigned int CoinSimplexUnsignedInt;
00024 //#define MOVE_REPLACE_PART1A
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 //#define EARLY_FACTORIZE
00041 #ifndef FAKE_CILK
00042 #include <cilk/cilk.h>
00043 #else
00044 #define cilk_for for
00045 #define cilk_spawn
00046 #define cilk_sync
00047 #endif
00048 #else
00049 #define cilk_for for
00050 #define cilk_spawn
00051 #define cilk_sync
00052 //#define ABC_PARALLEL 1
00053 #endif
00054 #define SLACK_VALUE 1
00055 #define ABC_INSTRUMENT 1 //2
00056 #if ABC_INSTRUMENT!=2
00057 // Below so can do deterministic B&B
00058 #define instrument_start(name,x)
00059 #define instrument_add(x)
00060 #define instrument_end()
00061 // one off
00062 #define instrument_do(name,x)
00063 // as end but multiply by factor
00064 #define instrument_end_and_adjust(x)
00065 #else
00066 void instrument_start(const char * type,int numberRowsEtc);
00067 void instrument_add(int count);
00068 void instrument_do(const char * type,double count);
00069 void instrument_end();
00070 void instrument_end_and_adjust(double factor);
00071 #endif
00072 #ifndef __BYTE_ORDER
00073 #include <endian.h>
00074 #endif
00075 #if __BYTE_ORDER == __LITTLE_ENDIAN
00076 #define ABC_INTEL
00077 #endif
00078 #if COIN_BIG_DOUBLE==1
00079 #undef USE_TEST_ZERO
00080 #undef USE_TEST_REALLY_ZERO
00081 #undef USE_TEST_ZERO_REGISTER
00082 #undef USE_TEST_LESS_TOLERANCE
00083 #undef USE_TEST_LESS_TOLERANCE_REGISTER
00084 #define CoinFabs(x) fabsl(x)
00085 #else
00086 #define CoinFabs(x) fabs(x)
00087 #endif
00088 #ifdef USE_TEST_ZERO
00089 #if __BYTE_ORDER == __LITTLE_ENDIAN
00090 #define TEST_DOUBLE_NONZERO(x) ((reinterpret_cast<int *>(&x))[1]!=0)
00091 #else
00092 #define TEST_DOUBLE_NONZERO(x) ((reinterpret_cast<int *>(&x))[0]!=0)
00093 #endif
00094 #else
00095 //always drop through
00096 #define TEST_DOUBLE_NONZERO(x) (true)
00097 #endif
00098 #define USE_TEST_INT_ZERO
00099 #ifdef USE_TEST_INT_ZERO
00100 #define TEST_INT_NONZERO(x) (x)
00101 #else
00102 //always drop through
00103 #define TEST_INT_NONZERO(x) (true)
00104 #endif
00105 #ifdef USE_TEST_REALLY_ZERO
00106 #if __BYTE_ORDER == __LITTLE_ENDIAN
00107 #define TEST_DOUBLE_REALLY_NONZERO(x) ((reinterpret_cast<int *>(&x))[1]!=0)
00108 #else
00109 #define TEST_DOUBLE_REALLY_NONZERO(x) ((reinterpret_cast<int *>(&x))[0]!=0)
00110 #endif
00111 #else
00112 #define TEST_DOUBLE_REALLY_NONZERO(x) (x)
00113 #endif
00114 #ifdef USE_TEST_ZERO_REGISTER
00115 #if __BYTE_ORDER == __LITTLE_ENDIAN
00116 #define TEST_DOUBLE_NONZERO_REGISTER(x) ((reinterpret_cast<int *>(&x))[1]!=0)
00117 #else
00118 #define TEST_DOUBLE_NONZERO_REGISTER(x) ((reinterpret_cast<int *>(&x))[0]!=0)
00119 #endif
00120 #else
00121 //always drop through
00122 #define TEST_DOUBLE_NONZERO_REGISTER(x) (true)
00123 #endif
00124 #define USE_FIXED_ZERO_TOLERANCE
00125 #ifdef USE_FIXED_ZERO_TOLERANCE
00126 // 3d400000... 0.5**43 approx 1.13687e-13
00127 #ifdef USE_TEST_LESS_TOLERANCE
00128 #if __BYTE_ORDER == __LITTLE_ENDIAN
00129 #define TEST_LESS_THAN_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000<0x3d400000)
00130 #define TEST_LESS_THAN_UPDATE_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000<0x3d400000)
00131 #else
00132 #define TEST_LESS_THAN_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000<0x3d400000)
00133 #define TEST_LESS_THAN_UPDATE_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000<0x3d400000)
00134 #endif
00135 #else
00136 #define TEST_LESS_THAN_TOLERANCE(x) (fabs(x)<pow(0.5,43))
00137 #define TEST_LESS_THAN_UPDATE_TOLERANCE(x) (fabs(x)<pow(0.5,43))
00138 #endif
00139 #ifdef USE_TEST_LESS_TOLERANCE_REGISTER
00140 #if __BYTE_ORDER == __LITTLE_ENDIAN
00141 #define TEST_LESS_THAN_TOLERANCE_REGISTER(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000<0x3d400000)
00142 #else
00143 #define TEST_LESS_THAN_TOLERANCE_REGISTER(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000<0x3d400000)
00144 #endif
00145 #else
00146 #define TEST_LESS_THAN_TOLERANCE_REGISTER(x) (fabs(x)<pow(0.5,43))
00147 #endif
00148 #else
00149 #define TEST_LESS_THAN_TOLERANCE(x) (fabs(x)<zeroTolerance_)
00150 #define TEST_LESS_THAN_TOLERANCE_REGISTER(x) (fabs(x)<zeroTolerance_)
00151 #endif
00152 #if COIN_BIG_DOUBLE!=1
00153 typedef unsigned int CoinExponent;
00154 #if __BYTE_ORDER == __LITTLE_ENDIAN
00155 #define ABC_EXPONENT(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000)
00156 #else
00157 #define ABC_EXPONENT(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000)
00158 #endif
00159 #define TEST_EXPONENT_LESS_THAN_TOLERANCE(x) (x<0x3d400000)
00160 #define TEST_EXPONENT_LESS_THAN_UPDATE_TOLERANCE(x) (x<0x3d400000)
00161 #define TEST_EXPONENT_NON_ZERO(x) (x)
00162 #else
00163 typedef long double  CoinExponent;
00164 #define ABC_EXPONENT(x) (x)
00165 #define TEST_EXPONENT_LESS_THAN_TOLERANCE(x) (fabs(x)<pow(0.5,43))
00166 #define TEST_EXPONENT_LESS_THAN_UPDATE_TOLERANCE(x) (fabs(x)<pow(0.5,43))
00167 #define TEST_EXPONENT_NON_ZERO(x) (x)
00168 #endif
00169 #ifdef INT_IS_8
00170 #define COINFACTORIZATION_BITS_PER_INT 64
00171 #define COINFACTORIZATION_SHIFT_PER_INT 6
00172 #define COINFACTORIZATION_MASK_PER_INT 0x3f
00173 #else
00174 #define COINFACTORIZATION_BITS_PER_INT 32
00175 #define COINFACTORIZATION_SHIFT_PER_INT 5
00176 #define COINFACTORIZATION_MASK_PER_INT 0x1f
00177 #endif
00178 #if ABC_USE_HOMEGROWN_LAPACK==1
00179 #define ABC_USE_LAPACK
00180 #endif
00181 #ifdef ABC_USE_LAPACK
00182 #define F77_FUNC(x,y) x##_
00183 #define ABC_DENSE_CODE 1
00184 /* Type of Fortran integer translated into C */
00185 #ifndef ipfint
00186 //typedef ipfint FORTRAN_INTEGER_TYPE ;
00187 typedef int ipfint;
00188 typedef const int cipfint;
00189 #endif
00190 enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102 };
00191 enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113,
00192                       AtlasConj=114};
00193 #define CLAPACK
00194 // using simple lapack interface
00195 extern "C" 
00196 {
00198   void F77_FUNC(dgetrs,DGETRS)(char *trans, cipfint *n,
00199                                cipfint *nrhs, const CoinSimplexDouble *A, cipfint *ldA,
00200                                cipfint * ipiv, CoinSimplexDouble *B, cipfint *ldB, ipfint *info,
00201                                int trans_len);
00203   void F77_FUNC(dgetrf,DGETRF)(ipfint * m, ipfint *n,
00204                                CoinSimplexDouble *A, ipfint *ldA,
00205                                ipfint * ipiv, ipfint *info);
00206   int clapack_dgetrf(const enum CBLAS_ORDER Order, const int M, const int N,
00207                      double *A, const int lda, int *ipiv);
00208   int clapack_dgetrs
00209   (const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE Trans,
00210    const int N, const int NRHS, const double *A, const int lda,
00211    const int *ipiv, double *B, const int ldb);
00212 }
00213 #else // use home grown
00214 /* Dense coding
00215    -1 use homegrown but just for factorization
00216    0 off all dense
00217    2 use homegrown for factorization and solves
00218 */
00219 #ifndef ABC_USE_HOMEGROWN_LAPACK
00220 #define ABC_DENSE_CODE 2
00221 #else
00222 #define ABC_DENSE_CODE ABC_USE_HOMEGROWN_LAPACK
00223 #endif
00224 #endif
00225 typedef unsigned char CoinCheckZero;
00226 template <class T> inline void
00227 CoinAbcMemset0(register T* to, const int size)
00228 {
00229 #ifndef NDEBUG
00230   // Some debug so check
00231   if (size < 0)
00232     throw CoinError("trying to fill negative number of entries",
00233                     "CoinAbcMemset0", "");
00234 #endif
00235   std::memset(to,0,size*sizeof(T));
00236 }
00237 template <class T> inline void
00238 CoinAbcMemcpy(register T* to, register const T* from, const int size )
00239 {
00240 #ifndef NDEBUG
00241   // Some debug so check
00242   if (size < 0)
00243     throw CoinError("trying to copy negative number of entries",
00244                     "CoinAbcMemcpy", "");
00245   
00246 #endif
00247   std::memcpy(to,from,size*sizeof(T));
00248 }
00249 class ClpSimplex;
00250 class AbcSimplex;
00251 class AbcTolerancesEtc  {
00252   
00253 public:
00254   
00255   
00256   
00258 
00259 
00260   AbcTolerancesEtc();
00261   
00263   AbcTolerancesEtc(const ClpSimplex * model);
00264   AbcTolerancesEtc(const AbcSimplex * model);
00265   
00267   AbcTolerancesEtc(const AbcTolerancesEtc &);
00268   
00270   AbcTolerancesEtc & operator=(const AbcTolerancesEtc& rhs);
00271   
00273   ~AbcTolerancesEtc ();
00275   
00276   
00277   //---------------------------------------------------------------------------
00278   
00279 public:
00281 
00282 
00283   double zeroTolerance_;
00285   double primalToleranceToGetOptimal_;
00287   double largeValue_;
00289   double alphaAccuracy_;
00291   double dualBound_;
00293   double dualTolerance_;
00295   double primalTolerance_;
00297   double infeasibilityCost_;
00307   double incomingInfeasibility_;
00308   double allowedInfeasibility_;
00310   int baseIteration_;
00312   int numberRefinements_;
00315   int forceFactorization_;
00323   int perturbation_;
00325   int dontFactorizePivots_;
00328   int maximumPivots_;
00330 };
00331 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 25 Aug 2014 for Clp by  doxygen 1.6.1