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
virtual std::string generateCpp(FILE *fp)
Create C++ lines to get to current state.
void CglSimpleRoundingUnitTest(const OsiSolverInterface *siP, const std::string mpdDir)
A function that tests the methods in the CglSimpleRounding class.
virtual ~CglSimpleRounding()
Destructor.
int gcdv(int n, const int *const vi) const
Returns the greatest common denominator of a vector of positive integers, vi, of length n...
double epsilon_
A value within an epsilon_ neighborhood of 0 is considered to be 0.
friend void CglSimpleRoundingUnitTest(const OsiSolverInterface *siP, const std::string mpdDir)
A function that tests the methods in the CglSimpleRounding class.
virtual void generateCuts(const OsiSolverInterface &si, OsiCuts &cs, const CglTreeInfo info=CglTreeInfo()) const
Generate simple rounding cuts for the model accessed through the solver interface.
CglSimpleRounding & operator=(const CglSimpleRounding &rhs)
Assignment operator.
Simple Rounding Cut Generator Class
bool deriveAnIntegerRow(const OsiSolverInterface &si, int rowIndex, const CoinShallowPackedVector &matrixRow, CoinPackedVector &irow, double &b, bool *negative) const
Derive a <= inequality in integer variables from the rowIndex-th constraint.
virtual CglCutGenerator * clone() const
Clone.
Cut Generator Base Class.
CglSimpleRounding()
Default constructor.
int power10ToMakeDoubleAnInt(int size, const double *x, double dataTol) const
Given a vector of doubles, x, with size elements and a positive tolerance, dataTol, this method returns the smallest power of 10 needed so that x[i]*10**power "is integer" for all i=0,...,size-1.
int gcd(int a, int b) const
Returns the greatest common denominator of two positive integers, a and b.
Information about where the cut generator is invoked from.
Definition: CglTreeInfo.hpp:13