Cgl  0.60.7
CglSimpleRounding.hpp
Go to the documentation of this file.
1 // $Id$
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 //#############################################################################
171 void CglSimpleRoundingUnitTest(const OsiSolverInterface * siP,
172  const std::string mpdDir );
173 
174 #endif
CglSimpleRounding::clone
virtual CglCutGenerator * clone() const
Clone.
CglTreeInfo
Information about where the cut generator is invoked from.
Definition: CglTreeInfo.hpp:15
CglSimpleRoundingUnitTest
void CglSimpleRoundingUnitTest(const OsiSolverInterface *siP, const std::string mpdDir)
A function that tests the methods in the CglSimpleRounding class.
CglSimpleRounding::generateCuts
virtual void generateCuts(const OsiSolverInterface &si, OsiCuts &cs, const CglTreeInfo info=CglTreeInfo())
Generate simple rounding cuts for the model accessed through the solver interface.
CglSimpleRounding::gcdv
int gcdv(int n, const int *const vi) const
Returns the greatest common denominator of a vector of positive integers, vi, of length n.
Definition: CglSimpleRounding.hpp:150
CglSimpleRounding::CglSimpleRoundingUnitTest
friend void CglSimpleRoundingUnitTest(const OsiSolverInterface *siP, const std::string mpdDir)
A function that tests the methods in the CglSimpleRounding class.
CglSimpleRounding::generateCpp
virtual std::string generateCpp(FILE *fp)
Create C++ lines to get to current state.
CglSimpleRounding::deriveAnIntegerRow
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.
CglSimpleRounding::power10ToMakeDoubleAnInt
int power10ToMakeDoubleAnInt(int size, const double *x, double dataTol) const
Given a vector of doubles, x, with size elements and a positive tolerance, dataTol,...
CglSimpleRounding::CglSimpleRounding
CglSimpleRounding()
Default constructor.
CglCutGenerator.hpp
CglCutGenerator
Cut Generator Base Class.
Definition: CglCutGenerator.hpp:23
CglSimpleRounding::~CglSimpleRounding
virtual ~CglSimpleRounding()
Destructor.
CglSimpleRounding
Simple Rounding Cut Generator Class.
Definition: CglSimpleRounding.hpp:29
CglSimpleRounding::epsilon_
double epsilon_
A value within an epsilon_ neighborhood of 0 is considered to be 0.
Definition: CglSimpleRounding.hpp:122
CglSimpleRounding::gcd
int gcd(int a, int b) const
Returns the greatest common denominator of two positive integers, a and b.
Definition: CglSimpleRounding.hpp:132
CglSimpleRounding::operator=
CglSimpleRounding & operator=(const CglSimpleRounding &rhs)
Assignment operator.