Loading...
Searching...
No Matches
CglSimpleRounding.hpp
Go to the documentation of this file.
// $Id$
// Copyright (C) 2000, International Business Machines
// Corporation and others. All Rights Reserved.
// This code is licensed under the terms of the Eclipse Public License (EPL).
#ifndef CglSimpleRounding_H
#define CglSimpleRounding_H
#include <string>
#include "CglCutGenerator.hpp"
#include "CoinPackedMatrix.hpp"
class CglSimpleRounding : public CglCutGenerator {
friend void CglSimpleRoundingUnitTest(const OsiSolverInterface * siP,
const std::string mpdDir );
public:
virtual void generateCuts( const OsiSolverInterface & si, OsiCuts & cs,
const CglTreeInfo info = CglTreeInfo());
CglSimpleRounding ();
CglSimpleRounding (
const CglSimpleRounding &);
virtual CglCutGenerator * clone() const;
CglSimpleRounding &
operator=(
const CglSimpleRounding& rhs);
virtual
~CglSimpleRounding ();
virtual std::string generateCpp( FILE * fp);
private:
// Private member methods
bool deriveAnIntegerRow(
const OsiSolverInterface & si,
int rowIndex,
const CoinShallowPackedVector & matrixRow,
CoinPackedVector & irow,
double & b,
bool * negative) const;
int power10ToMakeDoubleAnInt(
int size, // the length of the vector x
const double * x,
double dataTol ) const; // the precision of the data, i.e. the positive
// epsilon, which is equivalent to zero
inline int gcd(int a, int b) const;
inline int gcdv(int n, const int * const vi) const;
double epsilon_;
};
//-------------------------------------------------------------------
// Returns the greatest common denominator of two
// positive integers, a and b, found using Euclid's algorithm
//-------------------------------------------------------------------
int
CglSimpleRounding::gcd(int a, int b) const
{
if(a > b) {
// Swap a and b
int temp = a;
a = b;
b = temp;
}
int remainder = b % a;
if (remainder == 0) return a;
else return gcd(remainder,a);
}
//-------------------------------------------------------------------
// Returns the greatest common denominator of a vector of
// positive integers, vi, of length n.
//-------------------------------------------------------------------
int
CglSimpleRounding::gcdv(int n, const int* const vi) const
{
if (n==0)
abort();
if (n==1)
return vi[0];
int retval=gcd(vi[0], vi[1]);
for (int i=2; i<n; i++){
retval=gcd(retval,vi[i]);
}
return retval;
}
//#############################################################################
void CglSimpleRoundingUnitTest(const OsiSolverInterface * siP,
const std::string mpdDir );
#endif
CglCutGenerator.hpp
CglSimpleRoundingUnitTest
void CglSimpleRoundingUnitTest(const OsiSolverInterface *siP, const std::string mpdDir)
A function that tests the methods in the CglSimpleRounding class.
CglCutGenerator::CglCutGenerator
CglCutGenerator()
Default constructor.
CglSimpleRounding::epsilon_
double epsilon_
A value within an epsilon_ neighborhood of 0 is considered to be 0.
Definition CglSimpleRounding.hpp:122
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::CglSimpleRounding
CglSimpleRounding()
Default constructor.
CglSimpleRounding::generateCpp
virtual std::string generateCpp(FILE *fp)
Create C++ lines to get to current state.
CglSimpleRounding::CglSimpleRounding
CglSimpleRounding(const CglSimpleRounding &)
Copy constructor.
CglSimpleRounding::clone
virtual CglCutGenerator * clone() const
Clone.
CglSimpleRounding::~CglSimpleRounding
virtual ~CglSimpleRounding()
Destructor.
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::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::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::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::CglSimpleRoundingUnitTest
friend void CglSimpleRoundingUnitTest(const OsiSolverInterface *siP, const std::string mpdDir)
A function that tests the methods in the CglSimpleRounding class.
CglSimpleRounding::operator=
CglSimpleRounding & operator=(const CglSimpleRounding &rhs)
Assignment operator.
CglTreeInfo
Information about where the cut generator is invoked from.
Definition CglTreeInfo.hpp:15