source: stable/1.17/Clp/src/CoinAbcCommon.hpp @ 2439

Last change on this file since 2439 was 2385, checked in by unxusr, 11 months ago

formatting

  • Property svn:keywords set to Id
File size: 9.8 KB
Line 
1/* $Id: CoinAbcCommon.hpp 2385 2019-01-06 19:43:06Z 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"
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,
191  CblasColMajor = 102 };
192enum CBLAS_TRANSPOSE { CblasNoTrans = 111,
193  CblasTrans = 112,
194  CblasConjTrans = 113,
195  AtlasConj = 114 };
196//#define CLAPACK
197// using simple lapack interface
198extern "C" {
199/** LAPACK Fortran subroutine DGETRS. */
200void 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);
204/** LAPACK Fortran subroutine DGETRF. */
205void F77_FUNC(dgetrf, DGETRF)(ipfint *m, ipfint *n,
206  CoinSimplexDouble *A, ipfint *ldA,
207  ipfint *ipiv, ipfint *info);
208int clapack_dgetrf(const enum CBLAS_ORDER Order, const int M, const int N,
209  double *A, const int lda, int *ipiv);
210int 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
226typedef unsigned char CoinCheckZero;
227template < class T >
228inline void
229CoinAbcMemset0(register 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}
239template < class T >
240inline 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  ///@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
278public:
279  ///@name Public member data
280  //@{
281  /// Zero tolerance
282  double zeroTolerance_;
283  /// Primal tolerance needed to make dual feasible (<largeTolerance)
284  double primalToleranceToGetOptimal_;
285  /// Large bound value (for complementarity etc)
286  double largeValue_;
287  /// For computing whether to re-factorize
288  double alphaAccuracy_;
289  /// Dual bound
290  double dualBound_;
291  /// Current dual tolerance for algorithm
292  double dualTolerance_;
293  /// Current primal tolerance for algorithm
294  double primalTolerance_;
295  /// Weight assigned to being infeasible in primal
296  double infeasibilityCost_;
297  /** For advanced use.  When doing iterative solves things can get
298      nasty so on values pass if incoming solution has largest
299      infeasibility < incomingInfeasibility throw out variables
300      from basis until largest infeasibility < allowedInfeasibility.
301      if allowedInfeasibility>= incomingInfeasibility this is
302      always possible altough you may end up with an all slack basis.
303     
304      Defaults are 1.0,10.0
305  */
306  double incomingInfeasibility_;
307  double allowedInfeasibility_;
308  /// Iteration when we entered dual or primal
309  int baseIteration_;
310  /// How many iterative refinements to do
311  int numberRefinements_;
312  /** Now for some reliability aids
313      This forces re-factorization early */
314  int forceFactorization_;
315  /** Perturbation:
316      -50 to +50 - perturb by this power of ten (-6 sounds good)
317      100 - auto perturb if takes too long (1.0e-6 largest nonzero)
318      101 - we are perturbed
319      102 - don't try perturbing again
320      default is 100
321  */
322  int perturbation_;
323  /// If may skip final factorize then allow up to this pivots (default 20)
324  int dontFactorizePivots_;
325  /// For factorization
326  /// Maximum number of pivots before factorization
327  int maximumPivots_;
328  //@}
329};
330#endif
331
332/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
333*/
Note: See TracBrowser for help on using the repository browser.