- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

CoinAbcCommon.hpp
Go to the documentation of this file.
1 /* $Id: CoinAbcCommon.hpp 2074 2014-12-10 09:43:54Z forrest $ */
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 //gcc4.9 main branch has not got cilk_for!!!!!!!!!!!
44 #ifdef GCC_4_9
45 #undef cilk_for
46 #define cilk_for for
47 #endif
48 #else
49 #define cilk_for for
50 #define cilk_spawn
51 #define cilk_sync
52 #endif
53 #else
54 #define cilk_for for
55 #define cilk_spawn
56 #define cilk_sync
57 //#define ABC_PARALLEL 1
58 #endif
59 #define SLACK_VALUE 1
60 #define ABC_INSTRUMENT 1 //2
61 #if ABC_INSTRUMENT!=2
62 // Below so can do deterministic B&B
63 #define instrument_start(name,x)
64 #define instrument_add(x)
65 #define instrument_end()
66 // one off
67 #define instrument_do(name,x)
68 // as end but multiply by factor
69 #define instrument_end_and_adjust(x)
70 #else
71 void instrument_start(const char * type,int numberRowsEtc);
72 void instrument_add(int count);
73 void instrument_do(const char * type,double count);
74 void instrument_end();
75 void instrument_end_and_adjust(double factor);
76 #endif
77 #ifndef __BYTE_ORDER
78 #include <endian.h>
79 #endif
80 #if __BYTE_ORDER == __LITTLE_ENDIAN
81 #define ABC_INTEL
82 #endif
83 #if COIN_BIG_DOUBLE==1
84 #undef USE_TEST_ZERO
85 #undef USE_TEST_REALLY_ZERO
86 #undef USE_TEST_ZERO_REGISTER
87 #undef USE_TEST_LESS_TOLERANCE
88 #undef USE_TEST_LESS_TOLERANCE_REGISTER
89 #define CoinFabs(x) fabsl(x)
90 #else
91 #define CoinFabs(x) fabs(x)
92 #endif
93 #ifdef USE_TEST_ZERO
94 #if __BYTE_ORDER == __LITTLE_ENDIAN
95 #define TEST_DOUBLE_NONZERO(x) ((reinterpret_cast<int *>(&x))[1]!=0)
96 #else
97 #define TEST_DOUBLE_NONZERO(x) ((reinterpret_cast<int *>(&x))[0]!=0)
98 #endif
99 #else
100 //always drop through
101 #define TEST_DOUBLE_NONZERO(x) (true)
102 #endif
103 #define USE_TEST_INT_ZERO
104 #ifdef USE_TEST_INT_ZERO
105 #define TEST_INT_NONZERO(x) (x)
106 #else
107 //always drop through
108 #define TEST_INT_NONZERO(x) (true)
109 #endif
110 #ifdef USE_TEST_REALLY_ZERO
111 #if __BYTE_ORDER == __LITTLE_ENDIAN
112 #define TEST_DOUBLE_REALLY_NONZERO(x) ((reinterpret_cast<int *>(&x))[1]!=0)
113 #else
114 #define TEST_DOUBLE_REALLY_NONZERO(x) ((reinterpret_cast<int *>(&x))[0]!=0)
115 #endif
116 #else
117 #define TEST_DOUBLE_REALLY_NONZERO(x) (x)
118 #endif
119 #ifdef USE_TEST_ZERO_REGISTER
120 #if __BYTE_ORDER == __LITTLE_ENDIAN
121 #define TEST_DOUBLE_NONZERO_REGISTER(x) ((reinterpret_cast<int *>(&x))[1]!=0)
122 #else
123 #define TEST_DOUBLE_NONZERO_REGISTER(x) ((reinterpret_cast<int *>(&x))[0]!=0)
124 #endif
125 #else
126 //always drop through
127 #define TEST_DOUBLE_NONZERO_REGISTER(x) (true)
128 #endif
129 #define USE_FIXED_ZERO_TOLERANCE
130 #ifdef USE_FIXED_ZERO_TOLERANCE
131 // 3d400000... 0.5**43 approx 1.13687e-13
132 #ifdef USE_TEST_LESS_TOLERANCE
133 #if __BYTE_ORDER == __LITTLE_ENDIAN
134 #define TEST_LESS_THAN_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000<0x3d400000)
135 #define TEST_LESS_THAN_UPDATE_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000<0x3d400000)
136 #else
137 #define TEST_LESS_THAN_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000<0x3d400000)
138 #define TEST_LESS_THAN_UPDATE_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000<0x3d400000)
139 #endif
140 #else
141 #define TEST_LESS_THAN_TOLERANCE(x) (fabs(x)<pow(0.5,43))
142 #define TEST_LESS_THAN_UPDATE_TOLERANCE(x) (fabs(x)<pow(0.5,43))
143 #endif
144 #ifdef USE_TEST_LESS_TOLERANCE_REGISTER
145 #if __BYTE_ORDER == __LITTLE_ENDIAN
146 #define TEST_LESS_THAN_TOLERANCE_REGISTER(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000<0x3d400000)
147 #else
148 #define TEST_LESS_THAN_TOLERANCE_REGISTER(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000<0x3d400000)
149 #endif
150 #else
151 #define TEST_LESS_THAN_TOLERANCE_REGISTER(x) (fabs(x)<pow(0.5,43))
152 #endif
153 #else
154 #define TEST_LESS_THAN_TOLERANCE(x) (fabs(x)<zeroTolerance_)
155 #define TEST_LESS_THAN_TOLERANCE_REGISTER(x) (fabs(x)<zeroTolerance_)
156 #endif
157 #if COIN_BIG_DOUBLE!=1
158 typedef unsigned int CoinExponent;
159 #if __BYTE_ORDER == __LITTLE_ENDIAN
160 #define ABC_EXPONENT(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000)
161 #else
162 #define ABC_EXPONENT(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000)
163 #endif
164 #define TEST_EXPONENT_LESS_THAN_TOLERANCE(x) (x<0x3d400000)
165 #define TEST_EXPONENT_LESS_THAN_UPDATE_TOLERANCE(x) (x<0x3d400000)
166 #define TEST_EXPONENT_NON_ZERO(x) (x)
167 #else
168 typedef long double CoinExponent;
169 #define ABC_EXPONENT(x) (x)
170 #define TEST_EXPONENT_LESS_THAN_TOLERANCE(x) (fabs(x)<pow(0.5,43))
171 #define TEST_EXPONENT_LESS_THAN_UPDATE_TOLERANCE(x) (fabs(x)<pow(0.5,43))
172 #define TEST_EXPONENT_NON_ZERO(x) (x)
173 #endif
174 #ifdef INT_IS_8
175 #define COINFACTORIZATION_BITS_PER_INT 64
176 #define COINFACTORIZATION_SHIFT_PER_INT 6
177 #define COINFACTORIZATION_MASK_PER_INT 0x3f
178 #else
179 #define COINFACTORIZATION_BITS_PER_INT 32
180 #define COINFACTORIZATION_SHIFT_PER_INT 5
181 #define COINFACTORIZATION_MASK_PER_INT 0x1f
182 #endif
183 #if ABC_USE_HOMEGROWN_LAPACK==1
184 #define ABC_USE_LAPACK
185 #endif
186 #ifdef ABC_USE_LAPACK
187 #define F77_FUNC(x,y) x##_
188 #define ABC_DENSE_CODE 1
189 /* Type of Fortran integer translated into C */
190 #ifndef ipfint
191 //typedef ipfint FORTRAN_INTEGER_TYPE ;
192 typedef int ipfint;
193 typedef const int cipfint;
194 #endif
195 enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102 };
196 enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113,
197 AtlasConj=114};
198 //#define CLAPACK
199 // using simple lapack interface
200 extern "C"
201 {
203 void F77_FUNC(dgetrs,DGETRS)(char *trans, cipfint *n,
204 cipfint *nrhs, const CoinSimplexDouble *A, cipfint *ldA,
205 cipfint * ipiv, CoinSimplexDouble *B, cipfint *ldB, ipfint *info,
206 int trans_len);
208 void F77_FUNC(dgetrf,DGETRF)(ipfint * m, ipfint *n,
209 CoinSimplexDouble *A, ipfint *ldA,
210 ipfint * ipiv, ipfint *info);
211 int clapack_dgetrf(const enum CBLAS_ORDER Order, const int M, const int N,
212 double *A, const int lda, int *ipiv);
213 int clapack_dgetrs
214 (const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE Trans,
215 const int N, const int NRHS, const double *A, const int lda,
216 const int *ipiv, double *B, const int ldb);
217 }
218 #else // use home grown
219 /* Dense coding
220 -1 use homegrown but just for factorization
221 0 off all dense
222 2 use homegrown for factorization and solves
223 */
224 #ifndef ABC_USE_HOMEGROWN_LAPACK
225 #define ABC_DENSE_CODE 2
226 #else
227 #define ABC_DENSE_CODE ABC_USE_HOMEGROWN_LAPACK
228 #endif
229 #endif
230 typedef unsigned char CoinCheckZero;
231 template <class T> inline void
232 CoinAbcMemset0(register T* to, const int size)
233 {
234 #ifndef NDEBUG
235 // Some debug so check
236 if (size < 0)
237 throw CoinError("trying to fill negative number of entries",
238 "CoinAbcMemset0", "");
239 #endif
240 std::memset(to,0,size*sizeof(T));
241 }
242 template <class T> inline void
243 CoinAbcMemcpy(register T* to, register const T* from, const int size )
244 {
245 #ifndef NDEBUG
246 // Some debug so check
247 if (size < 0)
248 throw CoinError("trying to copy negative number of entries",
249 "CoinAbcMemcpy", "");
250
251 #endif
252 std::memcpy(to,from,size*sizeof(T));
253 }
254 class ClpSimplex;
255 class AbcSimplex;
256 class AbcTolerancesEtc {
257
258 public:
259
260
261
263
264 AbcTolerancesEtc();
266
268 AbcTolerancesEtc(const ClpSimplex * model);
269 AbcTolerancesEtc(const AbcSimplex * model);
270
272 AbcTolerancesEtc(const AbcTolerancesEtc &);
273
275 AbcTolerancesEtc & operator=(const AbcTolerancesEtc& rhs);
276
278 ~AbcTolerancesEtc ();
280
281
282 //---------------------------------------------------------------------------
283
284 public:
286
287 double zeroTolerance_;
290 double primalToleranceToGetOptimal_;
292 double largeValue_;
294 double alphaAccuracy_;
296 double dualBound_;
298 double dualTolerance_;
300 double primalTolerance_;
302 double infeasibilityCost_;
312 double incomingInfeasibility_;
313 double allowedInfeasibility_;
315 int baseIteration_;
317 int numberRefinements_;
320 int forceFactorization_;
328 int perturbation_;
330 int dontFactorizePivots_;
333 int maximumPivots_;
335 };
336 #endif
AbcTolerancesEtc::allowedInfeasibility_
double allowedInfeasibility_
Zero tolerance.
Definition: CoinAbcCommon.hpp:313
AbcSimplex
Definition: AbcSimplex.hpp:62
AbcTolerancesEtc::primalToleranceToGetOptimal_
double primalToleranceToGetOptimal_
Primal tolerance needed to make dual feasible (&lt;largeTolerance)
Definition: CoinAbcCommon.hpp:290
CoinSimplexDouble
double CoinSimplexDouble
Definition: CoinAbcCommon.hpp:21
AbcTolerancesEtc::maximumPivots_
int maximumPivots_
For factorization Maximum number of pivots before factorization.
Definition: CoinAbcCommon.hpp:333
AbcTolerancesEtc::numberRefinements_
int numberRefinements_
How many iterative refinements to do.
Definition: CoinAbcCommon.hpp:317
AbcTolerancesEtc::largeValue_
double largeValue_
Large bound value (for complementarity etc)
Definition: CoinAbcCommon.hpp:292
AbcCommon.hpp
CoinHelperFunctions.hpp
AbcTolerancesEtc::dualBound_
double dualBound_
Dual bound.
Definition: CoinAbcCommon.hpp:296
AbcTolerancesEtc::forceFactorization_
int forceFactorization_
Now for some reliability aids This forces re-factorization early.
Definition: CoinAbcCommon.hpp:320
AbcTolerancesEtc::baseIteration_
int baseIteration_
Iteration when we entered dual or primal.
Definition: CoinAbcCommon.hpp:315
CoinExponent
unsigned int CoinExponent
Definition: CoinAbcCommon.hpp:158
CoinSimplexInt
int CoinSimplexInt
Definition: CoinAbcCommon.hpp:22
AbcTolerancesEtc::alphaAccuracy_
double alphaAccuracy_
For computing whether to re-factorize.
Definition: CoinAbcCommon.hpp:294
CoinAbcMemset0
void CoinAbcMemset0(register T *to, const int size)
Definition: CoinAbcCommon.hpp:232
CoinUtilsConfig.h
AbcTolerancesEtc::incomingInfeasibility_
double incomingInfeasibility_
For advanced use.
Definition: CoinAbcCommon.hpp:312
F77_FUNC
#define F77_FUNC(name, NAME)
Definition: configall_system_msc.h:11
AbcTolerancesEtc::operator=
AbcTolerancesEtc & operator=(const AbcTolerancesEtc &rhs)
Assignment operator.
AbcTolerancesEtc
Definition: CoinAbcCommon.hpp:256
AbcTolerancesEtc::perturbation_
int perturbation_
Perturbation: -50 to +50 - perturb by this power of ten (-6 sounds good) 100 - auto perturb if takes ...
Definition: CoinAbcCommon.hpp:328
AbcTolerancesEtc::infeasibilityCost_
double infeasibilityCost_
Weight assigned to being infeasible in primal.
Definition: CoinAbcCommon.hpp:302
AbcTolerancesEtc::~AbcTolerancesEtc
~AbcTolerancesEtc()
Destructor.
ClpSimplex
This solves LPs using the simplex method.
Definition: ClpSimplex.hpp:70
instrument_do
#define instrument_do(name, x)
Definition: CoinAbcCommon.hpp:67
CoinPragma.hpp
CoinError
Error Class thrown by an exception.
Definition: CoinError.hpp:42
AbcTolerancesEtc::dontFactorizePivots_
int dontFactorizePivots_
If may skip final factorize then allow up to this pivots (default 20)
Definition: CoinAbcCommon.hpp:330
AbcTolerancesEtc::primalTolerance_
double primalTolerance_
Current primal tolerance for algorithm.
Definition: CoinAbcCommon.hpp:300
instrument_end
#define instrument_end()
Definition: CoinAbcCommon.hpp:65
CoinAbcMemcpy
void CoinAbcMemcpy(register T *to, register const T *from, const int size)
Definition: CoinAbcCommon.hpp:243
instrument_start
#define instrument_start(name, x)
Definition: CoinAbcCommon.hpp:63
CoinCheckZero
unsigned char CoinCheckZero
Definition: CoinAbcCommon.hpp:230
instrument_add
#define instrument_add(x)
Definition: CoinAbcCommon.hpp:64
CoinSimplexUnsignedInt
unsigned int CoinSimplexUnsignedInt
Definition: CoinAbcCommon.hpp:23
AbcTolerancesEtc::AbcTolerancesEtc
AbcTolerancesEtc()
Default Constructor.
AbcTolerancesEtc::zeroTolerance_
double zeroTolerance_
Zero tolerance.
Definition: CoinAbcCommon.hpp:288
instrument_end_and_adjust
#define instrument_end_and_adjust(x)
Definition: CoinAbcCommon.hpp:69
AbcTolerancesEtc::dualTolerance_
double dualTolerance_
Current dual tolerance for algorithm.
Definition: CoinAbcCommon.hpp:298