00001
00002
00003
00004
00005
00006 #ifndef CglSimpleRounding_H
00007 #define CglSimpleRounding_H
00008
00009 #include <string>
00010
00011 #include "CglCutGenerator.hpp"
00012 #include "CoinPackedMatrix.hpp"
00013
00029 class CglSimpleRounding : public CglCutGenerator {
00030 friend void CglSimpleRoundingUnitTest(const OsiSolverInterface * siP,
00031 const std::string mpdDir );
00032
00033 public:
00034
00040 virtual void generateCuts( const OsiSolverInterface & si, OsiCuts & cs,
00041 const CglTreeInfo info = CglTreeInfo());
00043
00046
00047 CglSimpleRounding ();
00048
00050 CglSimpleRounding (
00051 const CglSimpleRounding &);
00052
00054 virtual CglCutGenerator * clone() const;
00055
00057 CglSimpleRounding &
00058 operator=(
00059 const CglSimpleRounding& rhs);
00060
00062 virtual
00063 ~CglSimpleRounding ();
00065 virtual std::string generateCpp( FILE * fp);
00067
00068 private:
00069
00070
00071
00074
00076 bool deriveAnIntegerRow(
00077 const OsiSolverInterface & si,
00078 int rowIndex,
00079 const CoinShallowPackedVector & matrixRow,
00080 CoinPackedVector & irow,
00081 double & b,
00082 bool * negative) const;
00083
00084
00100 int power10ToMakeDoubleAnInt(
00101 int size,
00102 const double * x,
00103 double dataTol ) const;
00104
00105
00108
00109 inline int gcd(int a, int b) const;
00110
00114 inline int gcdv(int n, const int * const vi) const;
00116
00118
00121
00122 double epsilon_;
00124 };
00125
00126
00127
00128
00129
00130
00131 int
00132 CglSimpleRounding::gcd(int a, int b) const
00133 {
00134 if(a > b) {
00135
00136 int temp = a;
00137 a = b;
00138 b = temp;
00139 }
00140 int remainder = b % a;
00141 if (remainder == 0) return a;
00142 else return gcd(remainder,a);
00143 }
00144
00145
00146
00147
00148
00149 int
00150 CglSimpleRounding::gcdv(int n, const int* const vi) const
00151 {
00152 if (n==0)
00153 abort();
00154
00155 if (n==1)
00156 return vi[0];
00157
00158 int retval=gcd(vi[0], vi[1]);
00159 for (int i=2; i<n; i++){
00160 retval=gcd(retval,vi[i]);
00161 }
00162 return retval;
00163 }
00164
00165
00171 void CglSimpleRoundingUnitTest(const OsiSolverInterface * siP,
00172 const std::string mpdDir );
00173
00174 #endif