Cgl 0.60.2

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

- File List
- File Members

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
29 class CglSimpleRounding : public CglCutGenerator {
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
46 CglSimpleRounding ();
48
50 CglSimpleRounding (
51 const CglSimpleRounding &);
52
54 virtual CglCutGenerator * clone() const;
55
57 CglSimpleRounding &
58 operator=(
59 const CglSimpleRounding& rhs);
60
62 virtual
63 ~CglSimpleRounding ();
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
100 int power10ToMakeDoubleAnInt(
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::generateCpp
virtual std::string generateCpp(FILE *fp)
Create C++ lines to get to current state.
CglSimpleRounding::operator=
CglSimpleRounding & operator=(const CglSimpleRounding &rhs)
Assignment operator.
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::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::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, 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.
CglSimpleRounding
Simple Rounding Cut Generator Class.
Definition: CglSimpleRounding.hpp:29
CglCutGenerator.hpp
CglSimpleRounding::CglSimpleRounding
CglSimpleRounding()
Default constructor.
CglTreeInfo
Information about where the cut generator is invoked from.
Definition: CglTreeInfo.hpp:15
OsiCuts
Collections of row cuts and column cuts.
Definition: OsiCuts.hpp:19
CoinShallowPackedVector
Shallow Sparse Vector.
Definition: CoinShallowPackedVector.hpp:74
CglSimpleRounding::CglSimpleRoundingUnitTest
friend void CglSimpleRoundingUnitTest(const OsiSolverInterface *siP, const std::string mpdDir)
A function that tests the methods in the CglSimpleRounding class.
OsiSolverInterface
Abstract Base Class for describing an interface to a solver.
Definition: OsiSolverInterface.hpp:61
CglSimpleRounding::clone
virtual CglCutGenerator * clone() const
Clone.
CglSimpleRoundingUnitTest
void CglSimpleRoundingUnitTest(const OsiSolverInterface *siP, const std::string mpdDir)
A function that tests the methods in the CglSimpleRounding class.
CglCutGenerator
Cut Generator Base Class.
Definition: CglCutGenerator.hpp:23
CglSimpleRounding::~CglSimpleRounding
virtual ~CglSimpleRounding()
Destructor.
CglSimpleRounding::epsilon_
double epsilon_
A value within an epsilon_ neighborhood of 0 is considered to be 0.
Definition: CglSimpleRounding.hpp:122
CglSimpleRounding::deriveAnIntegerRow
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.
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
CoinPackedVector
Sparse Vector.
Definition: CoinPackedVector.hpp:123
CoinPackedMatrix.hpp