Clp  1.15.5
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
CoinAbcCommon.hpp
Go to the documentation of this file.
1 /* $Id: CoinAbcCommon.hpp 1910 2013-01-27 02:00:13Z stefan $ */
2 // Copyright (C) 2000, International Business Machines
3 // Corporation and others, Copyright (C) 2012, FasterCoin. All Rights Reserved.
4 // This code is licensed under the terms of the Eclipse Public License (EPL).
5 #ifndef CoinAbcCommon_H
6 #define CoinAbcCommon_H
7 #ifndef COIN_FAC_NEW
8 #define COIN_FAC_NEW
9 #endif
10 
11 #include "CoinPragma.hpp"
12 #include "CoinUtilsConfig.h"
13 #include <iostream>
14 #include <string>
15 #include <cassert>
16 #include <cstdio>
17 #include <cmath>
18 #include "AbcCommon.hpp"
19 #include "CoinHelperFunctions.hpp"
20 //#include "config.h"
21 typedef double CoinSimplexDouble;
22 typedef int CoinSimplexInt;
23 typedef unsigned int CoinSimplexUnsignedInt;
24 //#define MOVE_REPLACE_PART1A
25 #if defined(_MSC_VER)
26 #define ABC_INLINE __forceinline
27 #elif defined(__GNUC__)
28 #define ABC_INLINE __attribute__((always_inline))
29 #else
30 #define ABC_INLINE
31 #endif
32 #ifndef ABC_PARALLEL
33 #ifdef HAS_CILK
34 #define ABC_PARALLEL 2
35 #else
36 #define ABC_PARALLEL 0
37 #endif
38 #endif
39 #if ABC_PARALLEL==2
40 //#define EARLY_FACTORIZE
41 #ifndef FAKE_CILK
42 #include <cilk/cilk.h>
43 #else
44 #define cilk_for for
45 #define cilk_spawn
46 #define cilk_sync
47 #endif
48 #else
49 #define cilk_for for
50 #define cilk_spawn
51 #define cilk_sync
52 //#define ABC_PARALLEL 1
53 #endif
54 #define SLACK_VALUE 1
55 #define ABC_INSTRUMENT 1 //2
56 #if ABC_INSTRUMENT!=2
57 // Below so can do deterministic B&B
58 #define instrument_start(name,x)
59 #define instrument_add(x)
60 #define instrument_end()
61 // one off
62 #define instrument_do(name,x)
63 // as end but multiply by factor
64 #define instrument_end_and_adjust(x)
65 #else
66 void instrument_start(const char * type,int numberRowsEtc);
67 void instrument_add(int count);
68 void instrument_do(const char * type,double count);
69 void instrument_end();
70 void instrument_end_and_adjust(double factor);
71 #endif
72 #ifndef __BYTE_ORDER
73 #include <endian.h>
74 #endif
75 #if __BYTE_ORDER == __LITTLE_ENDIAN
76 #define ABC_INTEL
77 #endif
78 #if COIN_BIG_DOUBLE==1
79 #undef USE_TEST_ZERO
80 #undef USE_TEST_REALLY_ZERO
81 #undef USE_TEST_ZERO_REGISTER
82 #undef USE_TEST_LESS_TOLERANCE
83 #undef USE_TEST_LESS_TOLERANCE_REGISTER
84 #define CoinFabs(x) fabsl(x)
85 #else
86 #define CoinFabs(x) fabs(x)
87 #endif
88 #ifdef USE_TEST_ZERO
89 #if __BYTE_ORDER == __LITTLE_ENDIAN
90 #define TEST_DOUBLE_NONZERO(x) ((reinterpret_cast<int *>(&x))[1]!=0)
91 #else
92 #define TEST_DOUBLE_NONZERO(x) ((reinterpret_cast<int *>(&x))[0]!=0)
93 #endif
94 #else
95 //always drop through
96 #define TEST_DOUBLE_NONZERO(x) (true)
97 #endif
98 #define USE_TEST_INT_ZERO
99 #ifdef USE_TEST_INT_ZERO
100 #define TEST_INT_NONZERO(x) (x)
101 #else
102 //always drop through
103 #define TEST_INT_NONZERO(x) (true)
104 #endif
105 #ifdef USE_TEST_REALLY_ZERO
106 #if __BYTE_ORDER == __LITTLE_ENDIAN
107 #define TEST_DOUBLE_REALLY_NONZERO(x) ((reinterpret_cast<int *>(&x))[1]!=0)
108 #else
109 #define TEST_DOUBLE_REALLY_NONZERO(x) ((reinterpret_cast<int *>(&x))[0]!=0)
110 #endif
111 #else
112 #define TEST_DOUBLE_REALLY_NONZERO(x) (x)
113 #endif
114 #ifdef USE_TEST_ZERO_REGISTER
115 #if __BYTE_ORDER == __LITTLE_ENDIAN
116 #define TEST_DOUBLE_NONZERO_REGISTER(x) ((reinterpret_cast<int *>(&x))[1]!=0)
117 #else
118 #define TEST_DOUBLE_NONZERO_REGISTER(x) ((reinterpret_cast<int *>(&x))[0]!=0)
119 #endif
120 #else
121 //always drop through
122 #define TEST_DOUBLE_NONZERO_REGISTER(x) (true)
123 #endif
124 #define USE_FIXED_ZERO_TOLERANCE
125 #ifdef USE_FIXED_ZERO_TOLERANCE
126 // 3d400000... 0.5**43 approx 1.13687e-13
127 #ifdef USE_TEST_LESS_TOLERANCE
128 #if __BYTE_ORDER == __LITTLE_ENDIAN
129 #define TEST_LESS_THAN_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000<0x3d400000)
130 #define TEST_LESS_THAN_UPDATE_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000<0x3d400000)
131 #else
132 #define TEST_LESS_THAN_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000<0x3d400000)
133 #define TEST_LESS_THAN_UPDATE_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000<0x3d400000)
134 #endif
135 #else
136 #define TEST_LESS_THAN_TOLERANCE(x) (fabs(x)<pow(0.5,43))
137 #define TEST_LESS_THAN_UPDATE_TOLERANCE(x) (fabs(x)<pow(0.5,43))
138 #endif
139 #ifdef USE_TEST_LESS_TOLERANCE_REGISTER
140 #if __BYTE_ORDER == __LITTLE_ENDIAN
141 #define TEST_LESS_THAN_TOLERANCE_REGISTER(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000<0x3d400000)
142 #else
143 #define TEST_LESS_THAN_TOLERANCE_REGISTER(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000<0x3d400000)
144 #endif
145 #else
146 #define TEST_LESS_THAN_TOLERANCE_REGISTER(x) (fabs(x)<pow(0.5,43))
147 #endif
148 #else
149 #define TEST_LESS_THAN_TOLERANCE(x) (fabs(x)<zeroTolerance_)
150 #define TEST_LESS_THAN_TOLERANCE_REGISTER(x) (fabs(x)<zeroTolerance_)
151 #endif
152 #if COIN_BIG_DOUBLE!=1
153 typedef unsigned int CoinExponent;
154 #if __BYTE_ORDER == __LITTLE_ENDIAN
155 #define ABC_EXPONENT(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000)
156 #else
157 #define ABC_EXPONENT(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000)
158 #endif
159 #define TEST_EXPONENT_LESS_THAN_TOLERANCE(x) (x<0x3d400000)
160 #define TEST_EXPONENT_LESS_THAN_UPDATE_TOLERANCE(x) (x<0x3d400000)
161 #define TEST_EXPONENT_NON_ZERO(x) (x)
162 #else
163 typedef long double CoinExponent;
164 #define ABC_EXPONENT(x) (x)
165 #define TEST_EXPONENT_LESS_THAN_TOLERANCE(x) (fabs(x)<pow(0.5,43))
166 #define TEST_EXPONENT_LESS_THAN_UPDATE_TOLERANCE(x) (fabs(x)<pow(0.5,43))
167 #define TEST_EXPONENT_NON_ZERO(x) (x)
168 #endif
169 #ifdef INT_IS_8
170 #define COINFACTORIZATION_BITS_PER_INT 64
171 #define COINFACTORIZATION_SHIFT_PER_INT 6
172 #define COINFACTORIZATION_MASK_PER_INT 0x3f
173 #else
174 #define COINFACTORIZATION_BITS_PER_INT 32
175 #define COINFACTORIZATION_SHIFT_PER_INT 5
176 #define COINFACTORIZATION_MASK_PER_INT 0x1f
177 #endif
178 #if ABC_USE_HOMEGROWN_LAPACK==1
179 #define ABC_USE_LAPACK
180 #endif
181 #ifdef ABC_USE_LAPACK
182 #define F77_FUNC(x,y) x##_
183 #define ABC_DENSE_CODE 1
184 /* Type of Fortran integer translated into C */
185 #ifndef ipfint
186 //typedef ipfint FORTRAN_INTEGER_TYPE ;
187 typedef int ipfint;
188 typedef const int cipfint;
189 #endif
190 enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102 };
191 enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113,
192  AtlasConj=114};
193 #define CLAPACK
194 // using simple lapack interface
195 extern "C"
196 {
198  void F77_FUNC(dgetrs,DGETRS)(char *trans, cipfint *n,
199  cipfint *nrhs, const CoinSimplexDouble *A, cipfint *ldA,
200  cipfint * ipiv, CoinSimplexDouble *B, cipfint *ldB, ipfint *info,
201  int trans_len);
203  void F77_FUNC(dgetrf,DGETRF)(ipfint * m, ipfint *n,
204  CoinSimplexDouble *A, ipfint *ldA,
205  ipfint * ipiv, ipfint *info);
206  int clapack_dgetrf(const enum CBLAS_ORDER Order, const int M, const int N,
207  double *A, const int lda, int *ipiv);
208  int clapack_dgetrs
209  (const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE Trans,
210  const int N, const int NRHS, const double *A, const int lda,
211  const int *ipiv, double *B, const int ldb);
212 }
213 #else // use home grown
214 /* Dense coding
215  -1 use homegrown but just for factorization
216  0 off all dense
217  2 use homegrown for factorization and solves
218 */
219 #ifndef ABC_USE_HOMEGROWN_LAPACK
220 #define ABC_DENSE_CODE 2
221 #else
222 #define ABC_DENSE_CODE ABC_USE_HOMEGROWN_LAPACK
223 #endif
224 #endif
225 typedef unsigned char CoinCheckZero;
226 template <class T> inline void
227 CoinAbcMemset0(register T* to, const int size)
228 {
229 #ifndef NDEBUG
230  // Some debug so check
231  if (size < 0)
232  throw CoinError("trying to fill negative number of entries",
233  "CoinAbcMemset0", "");
234 #endif
235  std::memset(to,0,size*sizeof(T));
236 }
237 template <class T> inline void
238 CoinAbcMemcpy(register T* to, register const T* from, const int size )
239 {
240 #ifndef NDEBUG
241  // Some debug so check
242  if (size < 0)
243  throw CoinError("trying to copy negative number of entries",
244  "CoinAbcMemcpy", "");
245 
246 #endif
247  std::memcpy(to,from,size*sizeof(T));
248 }
249 class ClpSimplex;
250 class AbcSimplex;
252 
253 public:
254 
255 
256 
258 
261 
263  AbcTolerancesEtc(const ClpSimplex * model);
264  AbcTolerancesEtc(const AbcSimplex * model);
265 
268 
271 
275 
276 
277  //---------------------------------------------------------------------------
278 
279 public:
281 
282  double zeroTolerance_;
287  double largeValue_;
291  double dualBound_;
330 };
331 #endif
int baseIteration_
Iteration when we entered dual or primal.
double allowedInfeasibility_
double primalTolerance_
Current primal tolerance for algorithm.
#define instrument_end_and_adjust(x)
double CoinSimplexDouble
double incomingInfeasibility_
For advanced use.
double dualTolerance_
Current dual tolerance for algorithm.
int dontFactorizePivots_
If may skip final factorize then allow up to this pivots (default 20)
void CoinAbcMemcpy(register T *to, register const T *from, const int size)
This solves LPs using the simplex method.
Definition: ClpSimplex.hpp:55
double primalToleranceToGetOptimal_
Primal tolerance needed to make dual feasible (&lt;largeTolerance)
AbcTolerancesEtc()
Default Constructor.
int forceFactorization_
Now for some reliability aids This forces re-factorization early.
unsigned char CoinCheckZero
~AbcTolerancesEtc()
Destructor.
double zeroTolerance_
Zero tolerance.
AbcTolerancesEtc & operator=(const AbcTolerancesEtc &rhs)
Assignment operator.
double largeValue_
Large bound value (for complementarity etc)
double dualBound_
Dual bound.
#define instrument_start(name, x)
#define instrument_add(x)
void CoinAbcMemset0(register T *to, const int size)
#define instrument_do(name, x)
double infeasibilityCost_
Weight assigned to being infeasible in primal.
int CoinSimplexInt
int perturbation_
Perturbation: -50 to +50 - perturb by this power of ten (-6 sounds good) 100 - auto perturb if takes ...
int numberRefinements_
How many iterative refinements to do.
double alphaAccuracy_
For computing whether to re-factorize.
unsigned int CoinExponent
int maximumPivots_
For factorization Maximum number of pivots before factorization.
#define instrument_end()
unsigned int CoinSimplexUnsignedInt