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

Last change on this file since 1879 was 1878, checked in by forrest, 7 years ago

minor changes to implement Aboca

File size: 9.9 KB
Line 
1/* $Id: CoinAbcCommon.hpp.cpp 1448 2011-06-19 15:34:41Z 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#if defined(_MSC_VER)
8// Turn off compiler warning about long names
9#  pragma warning(disable:4786)
10#endif
11#ifndef COIN_FAC_NEW
12#define COIN_FAC_NEW
13#endif
14
15#include "CoinUtilsConfig.h"
16#include <iostream>
17#include <string>
18#include <cassert>
19#include <cstdio>
20#include <cmath>
21#include "AbcCommon.hpp"
22#include "CoinHelperFunctions.hpp"
23//#include "config.h"
24typedef double CoinSimplexDouble;
25typedef int CoinSimplexInt;
26typedef unsigned int CoinSimplexUnsignedInt;
27//#define MOVE_REPLACE_PART1A
28#if defined(_MSC_VER)
29#define ABC_INLINE __forceinline
30#elif defined(__GNUC__)
31#define ABC_INLINE __attribute__((always_inline))
32#else
33#define ABC_INLINE
34#endif
35#ifndef ABC_PARALLEL
36#ifdef HAS_CILK
37#define ABC_PARALLEL 2
38#else
39#define ABC_PARALLEL 0
40#endif
41#endif
42#if ABC_PARALLEL==2
43//#define EARLY_FACTORIZE
44#ifndef FAKE_CILK
45#include <cilk/cilk.h>
46#else
47#define cilk_for for
48#define cilk_spawn
49#define cilk_sync
50#endif
51#else
52#define cilk_for for
53#define cilk_spawn
54#define cilk_sync
55//#define ABC_PARALLEL 1
56#endif
57#define SLACK_VALUE 1
58#define ABC_INSTRUMENT 1 //2
59#if ABC_INSTRUMENT!=2
60// Below so can do deterministic B&B
61#define instrument_start(name,x)
62#define instrument_add(x)
63#define instrument_end()
64// one off
65#define instrument_do(name,x)
66// as end but multiply by factor
67#define instrument_end_and_adjust(x)
68#else
69void instrument_start(const char * type,int numberRowsEtc);
70void instrument_add(int count);
71void instrument_do(const char * type,double count);
72void instrument_end();
73void instrument_end_and_adjust(double factor);
74#endif
75#ifndef __BYTE_ORDER
76#include <endian.h>
77#endif
78#if __BYTE_ORDER == __LITTLE_ENDIAN
79#define ABC_INTEL
80#endif
81#if COIN_BIG_DOUBLE==1
82#undef USE_TEST_ZERO
83#undef USE_TEST_REALLY_ZERO
84#undef USE_TEST_ZERO_REGISTER
85#undef USE_TEST_LESS_TOLERANCE
86#undef USE_TEST_LESS_TOLERANCE_REGISTER
87#define CoinFabs(x) fabsl(x)
88#else
89#define CoinFabs(x) fabs(x)
90#endif
91#ifdef USE_TEST_ZERO
92#if __BYTE_ORDER == __LITTLE_ENDIAN
93#define TEST_DOUBLE_NONZERO(x) ((reinterpret_cast<int *>(&x))[1]!=0)
94#else
95#define TEST_DOUBLE_NONZERO(x) ((reinterpret_cast<int *>(&x))[0]!=0)
96#endif
97#else
98//always drop through
99#define TEST_DOUBLE_NONZERO(x) (true)
100#endif
101#define USE_TEST_INT_ZERO
102#ifdef USE_TEST_INT_ZERO
103#define TEST_INT_NONZERO(x) (x)
104#else
105//always drop through
106#define TEST_INT_NONZERO(x) (true)
107#endif
108#ifdef USE_TEST_REALLY_ZERO
109#if __BYTE_ORDER == __LITTLE_ENDIAN
110#define TEST_DOUBLE_REALLY_NONZERO(x) ((reinterpret_cast<int *>(&x))[1]!=0)
111#else
112#define TEST_DOUBLE_REALLY_NONZERO(x) ((reinterpret_cast<int *>(&x))[0]!=0)
113#endif
114#else
115#define TEST_DOUBLE_REALLY_NONZERO(x) (x)
116#endif
117#ifdef USE_TEST_ZERO_REGISTER
118#if __BYTE_ORDER == __LITTLE_ENDIAN
119#define TEST_DOUBLE_NONZERO_REGISTER(x) ((reinterpret_cast<int *>(&x))[1]!=0)
120#else
121#define TEST_DOUBLE_NONZERO_REGISTER(x) ((reinterpret_cast<int *>(&x))[0]!=0)
122#endif
123#else
124//always drop through
125#define TEST_DOUBLE_NONZERO_REGISTER(x) (true)
126#endif
127#define USE_FIXED_ZERO_TOLERANCE
128#ifdef USE_FIXED_ZERO_TOLERANCE
129// 3d400000... 0.5**43 approx 1.13687e-13
130#ifdef USE_TEST_LESS_TOLERANCE
131#if __BYTE_ORDER == __LITTLE_ENDIAN
132#define TEST_LESS_THAN_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000<0x3d400000)
133#define TEST_LESS_THAN_UPDATE_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000<0x3d400000)
134#else
135#define TEST_LESS_THAN_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000<0x3d400000)
136#define TEST_LESS_THAN_UPDATE_TOLERANCE(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000<0x3d400000)
137#endif
138#else
139#define TEST_LESS_THAN_TOLERANCE(x) (fabs(x)<pow(0.5,43))
140#define TEST_LESS_THAN_UPDATE_TOLERANCE(x) (fabs(x)<pow(0.5,43))
141#endif
142#ifdef USE_TEST_LESS_TOLERANCE_REGISTER
143#if __BYTE_ORDER == __LITTLE_ENDIAN
144#define TEST_LESS_THAN_TOLERANCE_REGISTER(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000<0x3d400000)
145#else
146#define TEST_LESS_THAN_TOLERANCE_REGISTER(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000<0x3d400000)
147#endif
148#else
149#define TEST_LESS_THAN_TOLERANCE_REGISTER(x) (fabs(x)<pow(0.5,43))
150#endif
151#else
152#define TEST_LESS_THAN_TOLERANCE(x) (fabs(x)<zeroTolerance_)
153#define TEST_LESS_THAN_TOLERANCE_REGISTER(x) (fabs(x)<zeroTolerance_)
154#endif
155#if COIN_BIG_DOUBLE!=1
156typedef unsigned int CoinExponent;
157#if __BYTE_ORDER == __LITTLE_ENDIAN
158#define ABC_EXPONENT(x) ((reinterpret_cast<int *>(&x))[1]&0x7ff00000)
159#else
160#define ABC_EXPONENT(x) ((reinterpret_cast<int *>(&x))[0]&0x7ff00000)
161#endif
162#define TEST_EXPONENT_LESS_THAN_TOLERANCE(x) (x<0x3d400000)
163#define TEST_EXPONENT_LESS_THAN_UPDATE_TOLERANCE(x) (x<0x3d400000)
164#define TEST_EXPONENT_NON_ZERO(x) (x)
165#else
166typedef long double  CoinExponent;
167#define ABC_EXPONENT(x) (x)
168#define TEST_EXPONENT_LESS_THAN_TOLERANCE(x) (fabs(x)<pow(0.5,43))
169#define TEST_EXPONENT_LESS_THAN_UPDATE_TOLERANCE(x) (fabs(x)<pow(0.5,43))
170#define TEST_EXPONENT_NON_ZERO(x) (x)
171#endif
172#ifdef INT_IS_8
173#define COINFACTORIZATION_BITS_PER_INT 64
174#define COINFACTORIZATION_SHIFT_PER_INT 6
175#define COINFACTORIZATION_MASK_PER_INT 0x3f
176#else
177#define COINFACTORIZATION_BITS_PER_INT 32
178#define COINFACTORIZATION_SHIFT_PER_INT 5
179#define COINFACTORIZATION_MASK_PER_INT 0x1f
180#endif
181#if ABC_USE_HOMEGROWN_LAPACK==1
182#define ABC_USE_LAPACK
183#endif
184#ifdef ABC_USE_LAPACK
185#define F77_FUNC(x,y) x##_
186#define ABC_DENSE_CODE 1
187/* Type of Fortran integer translated into C */
188#ifndef ipfint
189//typedef ipfint FORTRAN_INTEGER_TYPE ;
190typedef int ipfint;
191typedef const int cipfint;
192#endif
193enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102 };
194enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113,
195                      AtlasConj=114};
196#define CLAPACK
197// using simple lapack interface
198extern "C" 
199{
200  /** LAPACK Fortran subroutine DGETRS. */
201  void F77_FUNC(dgetrs,DGETRS)(char *trans, cipfint *n,
202                               cipfint *nrhs, const CoinSimplexDouble *A, cipfint *ldA,
203                               cipfint * ipiv, CoinSimplexDouble *B, cipfint *ldB, ipfint *info,
204                               int trans_len);
205  /** LAPACK Fortran subroutine DGETRF. */
206  void F77_FUNC(dgetrf,DGETRF)(ipfint * m, ipfint *n,
207                               CoinSimplexDouble *A, ipfint *ldA,
208                               ipfint * ipiv, ipfint *info);
209  int clapack_dgetrf(const enum CBLAS_ORDER Order, const int M, const int N,
210                     double *A, const int lda, int *ipiv);
211  int clapack_dgetrs
212  (const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE Trans,
213   const int N, const int NRHS, const double *A, const int lda,
214   const int *ipiv, double *B, const int ldb);
215}
216#else // use home grown
217/* Dense coding
218   -1 use homegrown but just for factorization
219   0 off all dense
220   2 use homegrown for factorization and solves
221*/
222#ifndef ABC_USE_HOMEGROWN_LAPACK
223#define ABC_DENSE_CODE 2
224#else
225#define ABC_DENSE_CODE ABC_USE_HOMEGROWN_LAPACK
226#endif
227#endif
228typedef unsigned char CoinCheckZero;
229template <class T> inline void
230CoinAbcMemset0(register T* to, const int size)
231{
232#ifndef NDEBUG
233  // Some debug so check
234  if (size < 0)
235    throw CoinError("trying to fill negative number of entries",
236                    "CoinAbcMemset0", "");
237#endif
238  std::memset(to,0,size*sizeof(T));
239}
240template <class T> inline void
241CoinAbcMemcpy(register T* to, register 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}
252class ClpSimplex;
253class AbcSimplex;
254class AbcTolerancesEtc  {
255 
256public:
257 
258 
259 
260  ///@name Constructors and destructors
261  //@{
262  /// Default Constructor
263  AbcTolerancesEtc();
264 
265  /// Useful Constructors
266  AbcTolerancesEtc(const ClpSimplex * model);
267  AbcTolerancesEtc(const AbcSimplex * model);
268 
269  /// Copy constructor
270  AbcTolerancesEtc(const AbcTolerancesEtc &);
271 
272  /// Assignment operator
273  AbcTolerancesEtc & operator=(const AbcTolerancesEtc& rhs);
274 
275  /// Destructor
276  ~AbcTolerancesEtc ();
277  //@}
278 
279 
280  //---------------------------------------------------------------------------
281 
282public:
283  ///@name Public member data
284  //@{
285  /// Zero tolerance
286  double zeroTolerance_;
287  /// Primal tolerance needed to make dual feasible (<largeTolerance)
288  double primalToleranceToGetOptimal_;
289  /// Large bound value (for complementarity etc)
290  double largeValue_;
291  /// For computing whether to re-factorize
292  double alphaAccuracy_;
293  /// Dual bound
294  double dualBound_;
295  /// Current dual tolerance for algorithm
296  double dualTolerance_;
297  /// Current primal tolerance for algorithm
298  double primalTolerance_;
299  /// Weight assigned to being infeasible in primal
300  double infeasibilityCost_;
301  /** For advanced use.  When doing iterative solves things can get
302      nasty so on values pass if incoming solution has largest
303      infeasibility < incomingInfeasibility throw out variables
304      from basis until largest infeasibility < allowedInfeasibility.
305      if allowedInfeasibility>= incomingInfeasibility this is
306      always possible altough you may end up with an all slack basis.
307     
308      Defaults are 1.0,10.0
309  */
310  double incomingInfeasibility_;
311  double allowedInfeasibility_;
312  /// Iteration when we entered dual or primal
313  int baseIteration_;
314  /// How many iterative refinements to do
315  int numberRefinements_;
316  /** Now for some reliability aids
317      This forces re-factorization early */
318  int forceFactorization_;
319  /** Perturbation:
320      -50 to +50 - perturb by this power of ten (-6 sounds good)
321      100 - auto perturb if takes too long (1.0e-6 largest nonzero)
322      101 - we are perturbed
323      102 - don't try perturbing again
324      default is 100
325  */
326  int perturbation_;
327  /// If may skip final factorize then allow up to this pivots (default 20)
328  int dontFactorizePivots_;
329  /// For factorization
330  /// Maximum number of pivots before factorization
331  int maximumPivots_;
332  //@}
333};
334#endif
Note: See TracBrowser for help on using the repository browser.