Cgl 0.60.8
Loading...
Searching...
No Matches
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
33public:
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
59 const CglSimpleRounding& rhs);
60
62 virtual
65 virtual std::string generateCpp( FILE * fp);
67
68private:
69
70 // Private member methods
71
74
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
109 inline int gcd(int a, int b) const;
110
114 inline int gcdv(int n, const int * const vi) const;
116
118
122 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//-------------------------------------------------------------------
131int
132CglSimpleRounding::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//-------------------------------------------------------------------
149int
150CglSimpleRounding::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//#############################################################################
171void CglSimpleRoundingUnitTest(const OsiSolverInterface * siP,
172 const std::string mpdDir );
173
174#endif
void CglSimpleRoundingUnitTest(const OsiSolverInterface *siP, const std::string mpdDir)
A function that tests the methods in the CglSimpleRounding class.
Cut Generator Base Class.
Simple Rounding Cut Generator Class.
double epsilon_
A value within an epsilon_ neighborhood of 0 is considered to be 0.
int gcdv(int n, const int *const vi) const
Returns the greatest common denominator of a vector of positive integers, vi, of length n.
CglSimpleRounding()
Default constructor.
virtual std::string generateCpp(FILE *fp)
Create C++ lines to get to current state.
CglSimpleRounding(const CglSimpleRounding &)
Copy constructor.
virtual CglCutGenerator * clone() const
Clone.
virtual ~CglSimpleRounding()
Destructor.
int gcd(int a, int b) const
Returns the greatest common denominator of two positive integers, a and b.
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 power10ToMakeDoubleAnInt(int size, const double *x, double dataTol) const
Given a vector of doubles, x, with size elements and a positive tolerance, dataTol,...
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.
friend void CglSimpleRoundingUnitTest(const OsiSolverInterface *siP, const std::string mpdDir)
A function that tests the methods in the CglSimpleRounding class.
CglSimpleRounding & operator=(const CglSimpleRounding &rhs)
Assignment operator.
Information about where the cut generator is invoked from.