coin-Cgl
CglSimpleRounding.hpp
Go to the documentation of this file.
1 // Copyright (C) 2000, International Business Machines
2 // Corporation and others. All Rights Reserved.
3 #ifndef CglSimpleRounding_H
4 #define CglSimpleRounding_H
5 
6 #include <string>
7 
8 #include "CglCutGenerator.hpp"
9 #include "CoinPackedMatrix.hpp"
10 
27  friend void CglSimpleRoundingUnitTest(const OsiSolverInterface * siP,
28  const std::string mpdDir );
29 
30 public:
31 
37  virtual void generateCuts( const OsiSolverInterface & si, OsiCuts & cs,
38  const CglTreeInfo info = CglTreeInfo()) const;
40 
45 
48  const CglSimpleRounding &);
49 
51  virtual CglCutGenerator * clone() const;
52 
55  operator=(
56  const CglSimpleRounding& rhs);
57 
59  virtual
62  virtual std::string generateCpp( FILE * fp);
64 
65 private:
66 
67  // Private member methods
68 
71 
73  bool deriveAnIntegerRow(
74  const OsiSolverInterface & si,
75  int rowIndex,
76  const CoinShallowPackedVector & matrixRow,
77  CoinPackedVector & irow,
78  double & b,
79  bool * negative) const;
80 
81 
98  int size, // the length of the vector x
99  const double * x,
100  double dataTol ) const; // the precision of the data, i.e. the positive
101  // epsilon, which is equivalent to zero
102 
105  inline int gcd(int a, int b) const;
107 
111  inline int gcdv(int n, const int * const vi) const;
113 
115 
118  double epsilon_;
121 };
122 
123 
124 //-------------------------------------------------------------------
125 // Returns the greatest common denominator of two
126 // positive integers, a and b, found using Euclid's algorithm
127 //-------------------------------------------------------------------
128 int
129 CglSimpleRounding::gcd(int a, int b) const
130 {
131  if(a > b) {
132  // Swap a and b
133  int temp = a;
134  a = b;
135  b = temp;
136  }
137  int remainder = b % a;
138  if (remainder == 0) return a;
139  else return gcd(remainder,a);
140 }
141 
142 //-------------------------------------------------------------------
143 // Returns the greatest common denominator of a vector of
144 // positive integers, vi, of length n.
145 //-------------------------------------------------------------------
146 int
147 CglSimpleRounding::gcdv(int n, const int* const vi) const
148 {
149  if (n==0)
150  abort();
151 
152  if (n==1)
153  return vi[0];
154 
155  int retval=gcd(vi[0], vi[1]);
156  for (int i=2; i<n; i++){
157  retval=gcd(retval,vi[i]);
158  }
159  return retval;
160 }
161 
162 //#############################################################################
168 void CglSimpleRoundingUnitTest(const OsiSolverInterface * siP,
169  const std::string mpdDir );
170 
171 #endif