- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

# /home/coin/svn-release/Alps-1.5.2/Cgl/src/CglSimpleRounding/CglSimpleRounding.hpp

Go to the documentation of this file.

    00001 // $Id: CglSimpleRounding.hpp 1149 2013-10-21 18:23:53Z tkr $
    00002 // Copyright (C) 2000, International Business Machines
    00003 // Corporation and others.  All Rights Reserved.
    00004 // This code is licensed under the terms of the Eclipse Public License (EPL).
    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   // Private member methods
    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,               // the length of the vector x
    00102        const double * x,
    00103        double dataTol ) const; // the precision of the data, i.e. the positive
    00104                                // epsilon, which is equivalent to zero
    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 // Returns the greatest common denominator of two
    00129 // positive integers, a and b, found using Euclid's algorithm
    00130 //-------------------------------------------------------------------
    00131 int
    00132 CglSimpleRounding::gcd(int a, int b) const
    00133 {
    00134   if(a > b) {
    00135     // Swap a and b
    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 // Returns the greatest common denominator of a vector of
    00147 // positive integers, vi, of length n.
    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