source: trunk/Clp/src/CoinAbcCommon.hpp @ 2030

Last change on this file since 2030 was 1910, checked in by stefan, 7 years ago
  • add configure option --enable-aboca={1,2,3,4,yes,no}
  • compile Aboca source only if --enable-aboca set (instead of compiling empty source files)
  • fix svn properties
  • Property svn:keywords set to Id
File size: 9.8 KB
Line 
1/* $Id: CoinAbcCommon.hpp 1910 2013-01-27 02:00:13Z 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"
21typedef double CoinSimplexDouble;
22typedef int CoinSimplexInt;
23typedef 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
66void instrument_start(const char * type,int numberRowsEtc);
67void instrument_add(int count);
68void instrument_do(const char * type,double count);
69void instrument_end();
70void 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
153typedef 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
163typedef 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 ;
187typedef int ipfint;
188typedef const int cipfint;
189#endif
190enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102 };
191enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113,
192                      AtlasConj=114};
193#define CLAPACK
194// using simple lapack interface
195extern "C" 
196{
197  /** LAPACK Fortran subroutine DGETRS. */
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);
202  /** LAPACK Fortran subroutine DGETRF. */
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
225typedef unsigned char CoinCheckZero;
226template <class T> inline void
227CoinAbcMemset0(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}
237template <class T> inline void
238CoinAbcMemcpy(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}
249class ClpSimplex;
250class AbcSimplex;
251class AbcTolerancesEtc  {
252 
253public:
254 
255 
256 
257  ///@name Constructors and destructors
258  //@{
259  /// Default Constructor
260  AbcTolerancesEtc();
261 
262  /// Useful Constructors
263  AbcTolerancesEtc(const ClpSimplex * model);
264  AbcTolerancesEtc(const AbcSimplex * model);
265 
266  /// Copy constructor
267  AbcTolerancesEtc(const AbcTolerancesEtc &);
268 
269  /// Assignment operator
270  AbcTolerancesEtc & operator=(const AbcTolerancesEtc& rhs);
271 
272  /// Destructor
273  ~AbcTolerancesEtc ();
274  //@}
275 
276 
277  //---------------------------------------------------------------------------
278 
279public:
280  ///@name Public member data
281  //@{
282  /// Zero tolerance
283  double zeroTolerance_;
284  /// Primal tolerance needed to make dual feasible (<largeTolerance)
285  double primalToleranceToGetOptimal_;
286  /// Large bound value (for complementarity etc)
287  double largeValue_;
288  /// For computing whether to re-factorize
289  double alphaAccuracy_;
290  /// Dual bound
291  double dualBound_;
292  /// Current dual tolerance for algorithm
293  double dualTolerance_;
294  /// Current primal tolerance for algorithm
295  double primalTolerance_;
296  /// Weight assigned to being infeasible in primal
297  double infeasibilityCost_;
298  /** For advanced use.  When doing iterative solves things can get
299      nasty so on values pass if incoming solution has largest
300      infeasibility < incomingInfeasibility throw out variables
301      from basis until largest infeasibility < allowedInfeasibility.
302      if allowedInfeasibility>= incomingInfeasibility this is
303      always possible altough you may end up with an all slack basis.
304     
305      Defaults are 1.0,10.0
306  */
307  double incomingInfeasibility_;
308  double allowedInfeasibility_;
309  /// Iteration when we entered dual or primal
310  int baseIteration_;
311  /// How many iterative refinements to do
312  int numberRefinements_;
313  /** Now for some reliability aids
314      This forces re-factorization early */
315  int forceFactorization_;
316  /** Perturbation:
317      -50 to +50 - perturb by this power of ten (-6 sounds good)
318      100 - auto perturb if takes too long (1.0e-6 largest nonzero)
319      101 - we are perturbed
320      102 - don't try perturbing again
321      default is 100
322  */
323  int perturbation_;
324  /// If may skip final factorize then allow up to this pivots (default 20)
325  int dontFactorizePivots_;
326  /// For factorization
327  /// Maximum number of pivots before factorization
328  int maximumPivots_;
329  //@}
330};
331#endif
Note: See TracBrowser for help on using the repository browser.