Cgl  0.59.9
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CglSimpleRounding.hpp
Go to the documentation of this file.
1 // $Id: CglSimpleRounding.hpp 1149 2013-10-21 18:23:53Z tkr $
2 // Copyright (C) 2000, International Business Machines
3 // Corporation and others. All Rights Reserved.
4 // This code is licensed under the terms of the Eclipse Public License (EPL).
5 
6 #ifndef CglSimpleRounding_H
7 #define CglSimpleRounding_H
8 
9 #include <string>
10 
11 #include "CglCutGenerator.hpp"
12 #include "CoinPackedMatrix.hpp"
13 
30  friend void CglSimpleRoundingUnitTest(const OsiSolverInterface * siP,
31  const std::string mpdDir );
32 
33 public:
34 
40  virtual void generateCuts( const OsiSolverInterface & si, OsiCuts & cs,
41  const CglTreeInfo info = CglTreeInfo());
43 
48 
51  const CglSimpleRounding &);
52 
54  virtual CglCutGenerator * clone() const;
55 
58  operator=(
59  const CglSimpleRounding& rhs);
60 
62  virtual
65  virtual std::string generateCpp( FILE * fp);
67 
68 private:
69 
70  // Private member methods
71 
74 
76  bool deriveAnIntegerRow(
77  const OsiSolverInterface & si,
78  int rowIndex,
79  const CoinShallowPackedVector & matrixRow,
80  CoinPackedVector & irow,
81  double & b,
82  bool * negative) const;
83 
84 
101  int size, // the length of the vector x
102  const double * x,
103  double dataTol ) const; // the precision of the data, i.e. the positive
104  // epsilon, which is equivalent to zero
105 
108  inline int gcd(int a, int b) const;
110 
114  inline int gcdv(int n, const int * const vi) const;
116 
118 
121  double epsilon_;
124 };
125 
126 
127 //-------------------------------------------------------------------
128 // Returns the greatest common denominator of two
129 // positive integers, a and b, found using Euclid's algorithm
130 //-------------------------------------------------------------------
131 int
132 CglSimpleRounding::gcd(int a, int b) const
133 {
134  if(a > b) {
135  // Swap a and b
136  int temp = a;
137  a = b;
138  b = temp;
139  }
140  int remainder = b % a;
141  if (remainder == 0) return a;
142  else return gcd(remainder,a);
143 }
144 
145 //-------------------------------------------------------------------
146 // Returns the greatest common denominator of a vector of
147 // positive integers, vi, of length n.
148 //-------------------------------------------------------------------
149 int
150 CglSimpleRounding::gcdv(int n, const int* const vi) const
151 {
152  if (n==0)
153  abort();
154 
155  if (n==1)
156  return vi[0];
157 
158  int retval=gcd(vi[0], vi[1]);
159  for (int i=2; i<n; i++){
160  retval=gcd(retval,vi[i]);
161  }
162  return retval;
163 }
164 
165 //#############################################################################
172  const std::string mpdDir );
173 
174 #endif
virtual std::string generateCpp(FILE *fp)
Create C++ lines to get to current state.
CglSimpleRounding & operator=(const CglSimpleRounding &rhs)
Assignment operator.
virtual void generateCuts(const OsiSolverInterface &si, OsiCuts &cs, const CglTreeInfo info=CglTreeInfo())
Generate simple rounding cuts for the model accessed through the solver interface.
int gcd(int a, int b) const
Returns the greatest common denominator of two positive integers, a and b.
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 &quot;is integer&quot; for all i=0,...,size-1.
Simple Rounding Cut Generator Class.
CglSimpleRounding()
Default constructor.
Information about where the cut generator is invoked from.
Definition: CglTreeInfo.hpp:15
Collections of row cuts and column cuts.
Definition: OsiCuts.hpp:19
friend void CglSimpleRoundingUnitTest(const OsiSolverInterface *siP, const std::string mpdDir)
A function that tests the methods in the CglSimpleRounding class.
Abstract Base Class for describing an interface to a solver.
virtual CglCutGenerator * clone() const
Clone.
void CglSimpleRoundingUnitTest(const OsiSolverInterface *siP, const std::string mpdDir)
A function that tests the methods in the CglSimpleRounding class.
Cut Generator Base Class.
virtual ~CglSimpleRounding()
Destructor.
double epsilon_
A value within an epsilon_ neighborhood of 0 is considered to be 0.
bool deriveAnIntegerRow(const OsiSolverInterface &si, int rowIndex, const CoinShallowPackedVector &matrixRow, CoinPackedVector &irow, double &b, bool *negative) const
Derive a &lt;= inequality in integer variables from the rowIndex-th constraint.
int gcdv(int n, const int *const vi) const
Returns the greatest common denominator of a vector of positive integers, vi, of length n...
Sparse Vector.