Clp  1.17.8
CoinAbcCommon.hpp
Go to the documentation of this file.
1 /* $Id$ */
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,
191  CblasColMajor = 102 };
192 enum CBLAS_TRANSPOSE { CblasNoTrans = 111,
193  CblasTrans = 112,
194  CblasConjTrans = 113,
195  AtlasConj = 114 };
196 //#define CLAPACK
197 // using simple lapack interface
198 extern "C" {
200 void F77_FUNC(dgetrs, DGETRS)(char *trans, cipfint *n,
201  cipfint *nrhs, const CoinSimplexDouble *A, cipfint *ldA,
202  cipfint *ipiv, CoinSimplexDouble *B, cipfint *ldB, ipfint *info,
203  int trans_len);
205 void F77_FUNC(dgetrf, DGETRF)(ipfint *m, ipfint *n,
206  CoinSimplexDouble *A, ipfint *ldA,
207  ipfint *ipiv, ipfint *info);
208 int clapack_dgetrf(const enum CBLAS_ORDER Order, const int M, const int N,
209  double *A, const int lda, int *ipiv);
210 int clapack_dgetrs(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE Trans,
211  const int N, const int NRHS, const double *A, const int lda,
212  const int *ipiv, double *B, const int ldb);
213 }
214 #else // use home grown
215 /* Dense coding
216  -1 use homegrown but just for factorization
217  0 off all dense
218  2 use homegrown for factorization and solves
219 */
220 #ifndef ABC_USE_HOMEGROWN_LAPACK
221 #define ABC_DENSE_CODE 2
222 #else
223 #define ABC_DENSE_CODE ABC_USE_HOMEGROWN_LAPACK
224 #endif
225 #endif
226 typedef unsigned char CoinCheckZero;
227 template < class T >
228 inline void
229 CoinAbcMemset0(T *to, const int size)
230 {
231 #ifndef NDEBUG
232  // Some debug so check
233  if (size < 0)
234  throw CoinError("trying to fill negative number of entries",
235  "CoinAbcMemset0", "");
236 #endif
237  std::memset(to, 0, size * sizeof(T));
238 }
239 template < class T >
240 inline void
241 CoinAbcMemcpy(T *to, const T *from, const int size)
242 {
243 #ifndef NDEBUG
244  // Some debug so check
245  if (size < 0)
246  throw CoinError("trying to copy negative number of entries",
247  "CoinAbcMemcpy", "");
248 
249 #endif
250  std::memcpy(to, from, size * sizeof(T));
251 }
252 class ClpSimplex;
253 class AbcSimplex;
255 
256 public:
258 
261 
263  AbcTolerancesEtc(const ClpSimplex *model);
264  AbcTolerancesEtc(const AbcSimplex *model);
265 
268 
271 
275 
276  //---------------------------------------------------------------------------
277 
278 public:
280 
281  double zeroTolerance_;
286  double largeValue_;
290  double dualBound_;
329 };
330 #endif
331 
332 /* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
333 */
ClpSimplex
This solves LPs using the simplex method.
Definition: ClpSimplex.hpp:106
instrument_start
#define instrument_start(name, x)
Definition: CoinAbcCommon.hpp:58
AbcTolerancesEtc::operator=
AbcTolerancesEtc & operator=(const AbcTolerancesEtc &rhs)
Assignment operator.
instrument_end_and_adjust
#define instrument_end_and_adjust(x)
Definition: CoinAbcCommon.hpp:64
AbcTolerancesEtc::dualTolerance_
double dualTolerance_
Current dual tolerance for algorithm.
Definition: CoinAbcCommon.hpp:292
AbcTolerancesEtc::forceFactorization_
int forceFactorization_
Now for some reliability aids This forces re-factorization early.
Definition: CoinAbcCommon.hpp:314
AbcTolerancesEtc::~AbcTolerancesEtc
~AbcTolerancesEtc()
Destructor.
AbcTolerancesEtc::primalToleranceToGetOptimal_
double primalToleranceToGetOptimal_
Primal tolerance needed to make dual feasible (<largeTolerance)
Definition: CoinAbcCommon.hpp:284
AbcTolerancesEtc::AbcTolerancesEtc
AbcTolerancesEtc()
Default Constructor.
AbcTolerancesEtc::infeasibilityCost_
double infeasibilityCost_
Weight assigned to being infeasible in primal.
Definition: CoinAbcCommon.hpp:296
AbcTolerancesEtc::dualBound_
double dualBound_
Dual bound.
Definition: CoinAbcCommon.hpp:290
AbcTolerancesEtc::zeroTolerance_
double zeroTolerance_
Zero tolerance.
Definition: CoinAbcCommon.hpp:282
AbcTolerancesEtc::maximumPivots_
int maximumPivots_
For factorization Maximum number of pivots before factorization.
Definition: CoinAbcCommon.hpp:327
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:322
AbcTolerancesEtc::largeValue_
double largeValue_
Large bound value (for complementarity etc)
Definition: CoinAbcCommon.hpp:286
instrument_do
#define instrument_do(name, x)
Definition: CoinAbcCommon.hpp:62
AbcCommon.hpp
AbcTolerancesEtc::alphaAccuracy_
double alphaAccuracy_
For computing whether to re-factorize.
Definition: CoinAbcCommon.hpp:288
CoinSimplexUnsignedInt
unsigned int CoinSimplexUnsignedInt
Definition: CoinAbcCommon.hpp:23
CoinAbcMemset0
void CoinAbcMemset0(T *to, const int size)
Definition: CoinAbcCommon.hpp:229
instrument_end
#define instrument_end()
Definition: CoinAbcCommon.hpp:60
AbcTolerancesEtc::numberRefinements_
int numberRefinements_
How many iterative refinements to do.
Definition: CoinAbcCommon.hpp:311
AbcTolerancesEtc::allowedInfeasibility_
double allowedInfeasibility_
Definition: CoinAbcCommon.hpp:307
CoinCheckZero
unsigned char CoinCheckZero
Definition: CoinAbcCommon.hpp:226
AbcSimplex
Definition: AbcSimplex.hpp:62
CoinExponent
unsigned int CoinExponent
Definition: CoinAbcCommon.hpp:153
CoinAbcMemcpy
void CoinAbcMemcpy(T *to, const T *from, const int size)
Definition: CoinAbcCommon.hpp:241
AbcTolerancesEtc::baseIteration_
int baseIteration_
Iteration when we entered dual or primal.
Definition: CoinAbcCommon.hpp:309
AbcTolerancesEtc::primalTolerance_
double primalTolerance_
Current primal tolerance for algorithm.
Definition: CoinAbcCommon.hpp:294
AbcTolerancesEtc::dontFactorizePivots_
int dontFactorizePivots_
If may skip final factorize then allow up to this pivots (default 20)
Definition: CoinAbcCommon.hpp:324
instrument_add
#define instrument_add(x)
Definition: CoinAbcCommon.hpp:59
CoinSimplexInt
int CoinSimplexInt
Definition: CoinAbcCommon.hpp:22
AbcTolerancesEtc
Definition: CoinAbcCommon.hpp:254
AbcTolerancesEtc::incomingInfeasibility_
double incomingInfeasibility_
For advanced use.
Definition: CoinAbcCommon.hpp:306
CoinSimplexDouble
double CoinSimplexDouble
Definition: CoinAbcCommon.hpp:21