Clp 1.17.5
Loading...
Searching...
No Matches
CoinAbcCommon.hpp
Go to the documentation of this file.
1/* $Id: CoinAbcCommon.hpp 2476 2019-06-13 14:49:27Z 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" {
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);
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(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(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}
252class ClpSimplex;
253class AbcSimplex;
255
256public:
258
259
261
265
268
271
275
276 //---------------------------------------------------------------------------
277
278public:
280
281
329};
330#endif
331
332/* vi: softtabstop=2 shiftwidth=2 expandtab tabstop=2
333*/
unsigned int CoinExponent
double CoinSimplexDouble
unsigned int CoinSimplexUnsignedInt
#define instrument_do(name, x)
void CoinAbcMemset0(T *to, const int size)
#define instrument_start(name, x)
#define instrument_add(x)
void CoinAbcMemcpy(T *to, const T *from, const int size)
unsigned char CoinCheckZero
int CoinSimplexInt
#define instrument_end_and_adjust(x)
#define instrument_end()
int baseIteration_
Iteration when we entered dual or primal.
double infeasibilityCost_
Weight assigned to being infeasible in primal.
double incomingInfeasibility_
For advanced use.
int dontFactorizePivots_
If may skip final factorize then allow up to this pivots (default 20)
int forceFactorization_
Now for some reliability aids This forces re-factorization early.
AbcTolerancesEtc & operator=(const AbcTolerancesEtc &rhs)
Assignment operator.
double zeroTolerance_
Zero tolerance.
double dualTolerance_
Current dual tolerance for algorithm.
AbcTolerancesEtc(const AbcTolerancesEtc &)
Copy constructor.
AbcTolerancesEtc(const ClpSimplex *model)
Useful Constructors.
int maximumPivots_
For factorization Maximum number of pivots before factorization.
AbcTolerancesEtc(const AbcSimplex *model)
int perturbation_
Perturbation: -50 to +50 - perturb by this power of ten (-6 sounds good) 100 - auto perturb if takes ...
double primalTolerance_
Current primal tolerance for algorithm.
double dualBound_
Dual bound.
int numberRefinements_
How many iterative refinements to do.
AbcTolerancesEtc()
Default Constructor.
double alphaAccuracy_
For computing whether to re-factorize.
double primalToleranceToGetOptimal_
Primal tolerance needed to make dual feasible (<largeTolerance)
~AbcTolerancesEtc()
Destructor.
double largeValue_
Large bound value (for complementarity etc)
This solves LPs using the simplex method.
#define F77_FUNC(name, NAME)