Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

OsiColCut Class Reference

#include <OsiColCut.hpp>

Inheritance diagram for OsiColCut:

OsiCut List of all members.

Public Member Functions

Setting column bounds
void setLbs (int nElements, const int *colIndices, const double *lbElements)
 Set column lower bounds.

void setLbs (const CoinPackedVector &lbs)
 Set column lower bounds from a packed vector.

void setUbs (int nElements, const int *colIndices, const double *ubElements)
 Set column upper bounds.

void setUbs (const CoinPackedVector &ubs)
 Set column upper bounds from a packed vector.

Getting column bounds
const CoinPackedVectorlbs () const
 Get column lower bounds.

const CoinPackedVectorubs () const
 Get column upper bounds.

Comparison operators
virtual bool operator== (const OsiColCut &rhs) const
virtual bool operator!= (const OsiColCut &rhs) const
 not equal

Sanity checks on cut
virtual bool consistent () const
virtual bool consistent (const OsiSolverInterface &im) const
virtual bool infeasible (const OsiSolverInterface &im) const
virtual double violated (const double *solution) const
Constructors and destructors
OsiColCutoperator= (const OsiColCut &rhs)
 Assignment operator.

 OsiColCut (const OsiColCut &)
 Copy constructor.

 OsiColCut ()
 Default Constructor.

virtual OsiColCutclone () const
 Clone.

virtual ~OsiColCut ()
 Destructor.

Debug stuff
virtual void print () const
 Print cuts in collection.


Private Attributes

Private member data
CoinPackedVector lbs_
 Lower bounds.

CoinPackedVector ubs_
 Upper bounds.


Friends

void OsiColCutUnitTest (const OsiSolverInterface *baseSiP, const std::string &mpsDir)

Detailed Description

Column Cut Class

Column Cut Class has:

Definition at line 21 of file OsiColCut.hpp.


Member Function Documentation

bool OsiColCut::consistent const OsiSolverInterface im  )  const [inline, virtual]
 

Returns true if cut is consistent with respect to the solver interface's model. This checks to ensure that the lower & upperbound packed vectors:

  • do not have an index >= the number of column is the model.

Implements OsiCut.

Definition at line 230 of file OsiColCut.hpp.

References CoinPackedVectorBase::getMaxIndex(), OsiSolverInterface::getNumCols(), lbs(), and ubs().

00231 {  
00232   const CoinPackedVector & lb = lbs();
00233   const CoinPackedVector & ub = ubs();
00234   
00235   // Test for consistent cut.
00236   if ( lb.getMaxIndex() >= im.getNumCols() ) return false;
00237   if ( ub.getMaxIndex() >= im.getNumCols() ) return false;
00238   
00239   return true;
00240 }

bool OsiColCut::consistent  )  const [inline, virtual]
 

Returns true if the cut is consistent with respect to itself. This checks to ensure that:

  • The bound vectors do not have duplicate indices,
  • The bound vectors indices are >=0

Implements OsiCut.

Definition at line 217 of file OsiColCut.hpp.

References CoinPackedVectorBase::duplicateIndex(), CoinPackedVectorBase::getMinIndex(), lbs(), and ubs().

00218 {
00219   const CoinPackedVector & lb = lbs();
00220   const CoinPackedVector & ub = ubs();
00221   // Test for consistent cut.
00222   // Are packed vectors consistent?
00223   lb.duplicateIndex("consistent", "OsiColCut");
00224   ub.duplicateIndex("consistent", "OsiColCut");
00225   if ( lb.getMinIndex() < 0 ) return false;
00226   if ( ub.getMinIndex() < 0 ) return false;
00227   return true;
00228 }

bool OsiColCut::infeasible const OsiSolverInterface im  )  const [inline, virtual]
 

Returns true if the cut is infeasible with respect to its bounds and the column bounds in the solver interface's models. This checks whether:

  • the maximum of the new and existing lower bounds is strictly greater than the minimum of the new and existing upper bounds.

Implements OsiCut.

Definition at line 281 of file OsiColCut.hpp.

References OsiSolverInterface::getColLower(), OsiSolverInterface::getColUpper(), CoinPackedVector::getElements(), CoinPackedVector::getIndices(), CoinPackedVector::getNumElements(), CoinPackedVectorBase::isExistingIndex(), lbs(), and ubs().

00282 {
00283   const double * oldColLb = im.getColLower();
00284   const double * oldColUb = im.getColUpper();
00285   const CoinPackedVector & cutLbs = lbs();
00286   const CoinPackedVector & cutUbs = ubs();
00287   int i;
00288   
00289   for ( i=0; i<cutLbs.getNumElements(); i++ ) {
00290     int colIndx = cutLbs.getIndices()[i];
00291     double newLb= cutLbs.getElements()[i] > oldColLb[colIndx] ?
00292        cutLbs.getElements()[i] : oldColLb[colIndx];
00293 
00294     double newUb = oldColUb[colIndx];
00295     if ( cutUbs.isExistingIndex(colIndx) )
00296       if ( cutUbs[colIndx] < newUb ) newUb = cutUbs[colIndx];
00297       if ( newLb > newUb ) 
00298         return true;
00299   }
00300   
00301   for ( i=0; i<cutUbs.getNumElements(); i++ ) {
00302     int colIndx = cutUbs.getIndices()[i];
00303     double newUb = cutUbs.getElements()[i] < oldColUb[colIndx] ?
00304        cutUbs.getElements()[i] : oldColUb[colIndx];
00305     double newLb = oldColLb[colIndx];
00306     if ( cutLbs.isExistingIndex(colIndx) )
00307       if ( cutLbs[colIndx] > newLb ) newLb = cutLbs[colIndx];
00308       if ( newUb < newLb ) 
00309         return true;
00310   }
00311   
00312   return false;
00313 }

bool OsiColCut::operator== const OsiColCut rhs  )  const [inline, virtual]
 

equal - true if lower bounds, upper bounds, and OsiCut are equal.

Definition at line 195 of file OsiColCut.hpp.

References lbs(), OsiCut::operator!=(), and ubs().

00197 {
00198   if ( this->OsiCut::operator!=(rhs) ) 
00199     return false;
00200   if ( lbs() != rhs.lbs() ) 
00201     return false;
00202   if ( ubs() != rhs.ubs() ) 
00203     return false;
00204   return true;
00205 }

virtual double OsiColCut::violated const double *  solution  )  const [virtual]
 

Returns infeasibility of the cut with respect to solution passed in i.e. is positive if cuts off that solution. solution is getNumCols() long..

Implements OsiCut.


Friends And Related Function Documentation

void OsiColCutUnitTest const OsiSolverInterface baseSiP,
const std::string &  mpsDir
[friend]
 

A function that tests the methods in the OsiColCut class. The only reason for it not to be a member method is that this way it doesn't have to be compiled into the library. And that's a gain, because the library should be compiled with optimization on, but this method should be compiled with debugging.

Definition at line 20 of file OsiColCutTest.cpp.

00022 {
00023 
00024   // Test default constructor
00025   {
00026     OsiColCut r;
00027     assert( r.lbs_.getIndices()==NULL );
00028     assert( r.lbs_.getElements()==NULL );
00029     assert( r.ubs_.getIndices()==NULL );
00030     assert( r.ubs_.getElements()==NULL );
00031     assert( r.lbs_.getNumElements()==0);
00032     assert( r.ubs_.getNumElements()==0);
00033   }
00034 
00035   // Test set and get methods
00036   const int ne = 4;
00037   int inx[ne] = { 1, 3, 4, 7 };
00038   double el[ne] = { 1.2, 3.4, 5.6, 7.8 };
00039   const int ne3 = 0;
00040   int * inx3=NULL;
00041   double * el3= NULL;
00042   {
00043     OsiColCut r;    
00044     assert( r.lbs().getNumElements()==0 );
00045     assert( r.ubs().getNumElements()==0 );
00046         
00047     // Test setting/getting bounds
00048     r.setLbs( ne, inx, el );
00049     r.setEffectiveness(222.);
00050     assert( r.lbs().getNumElements()==ne );
00051     for ( int i=0; i<ne; i++ ) {
00052       assert( r.lbs().getIndices()[i] == inx[i] );
00053       assert( r.lbs().getElements()[i] == el[i] );
00054     }
00055     assert( r.effectiveness()==222. );
00056     
00057     r.setUbs( ne3, inx3, el3 );
00058     assert( r.ubs().getNumElements()==0 );
00059     assert( r.ubs().getIndices()==NULL );
00060     assert( r.ubs().getElements()==NULL );
00061     
00062   } 
00063   
00064   // Test copy constructor and assignment operator
00065   {
00066     OsiColCut rhs;
00067     {
00068       OsiColCut r;
00069       OsiColCut rC1(r);
00070       assert( rC1.lbs().getNumElements()==r.lbs().getNumElements() );
00071       assert( rC1.ubs().getNumElements()==r.ubs().getNumElements() );
00072   
00073       r.setLbs( ne, inx, el );
00074       r.setUbs( ne, inx, el );
00075       r.setEffectiveness(121.);
00076 
00077       assert( rC1.lbs().getNumElements()!=r.lbs().getNumElements() );
00078       assert( rC1.ubs().getNumElements()!=r.ubs().getNumElements() );
00079                 
00080       OsiColCut rC2(r);
00081       assert( rC2.lbs().getNumElements()==r.lbs().getNumElements() );
00082       assert( rC2.ubs().getNumElements()==r.ubs().getNumElements() );
00083       assert( rC2.lbs().getNumElements()==ne );
00084       assert( rC2.ubs().getNumElements()==ne );
00085       for ( int i=0; i<ne; i++ ) {
00086         assert( rC2.lbs().getIndices()[i] == inx[i] );
00087         assert( rC2.lbs().getElements()[i] == el[i] );
00088         assert( rC2.ubs().getIndices()[i] == inx[i] );
00089         assert( rC2.ubs().getElements()[i] == el[i] );
00090       }
00091       assert( rC2.effectiveness()==121. );
00092       
00093       rhs=rC2;
00094     }
00095     // Test that rhs has correct values even though lhs has gone out of scope
00096     assert( rhs.lbs().getNumElements()==ne );
00097     assert( rhs.ubs().getNumElements()==ne );
00098     for ( int i=0; i<ne; i++ ) {
00099       assert( rhs.lbs().getIndices()[i] == inx[i] );
00100       assert( rhs.lbs().getElements()[i] == el[i] );
00101       assert( rhs.ubs().getIndices()[i] == inx[i] );
00102       assert( rhs.ubs().getElements()[i] == el[i] );
00103     }  
00104     assert( rhs.effectiveness()==121. );
00105   }
00106 
00107   // Test setting bounds with packed vector and operator==
00108   {    
00109     const int ne1 = 4;
00110     int inx1[ne] = { 1, 3, 4, 7 };
00111     double el1[ne] = { 1.2, 3.4, 5.6, 7.8 };
00112     const int ne2 = 2;
00113     int inx2[ne2]={ 1, 3 };
00114     double el2[ne2]= { 1.2, 3.4 };
00115     CoinPackedVector v1,v2;
00116     v1.setVector(ne1,inx1,el1);
00117     v2.setVector(ne2,inx2,el2);
00118     
00119     OsiColCut c1,c2;
00120     assert(   c1==c2  );
00121     assert( !(c1!=c2) );
00122     
00123     c1.setLbs(v1);
00124     assert(   c1 != c2  );
00125     assert( !(c1 == c2) );
00126     
00127     assert( c1.lbs()==v1 );
00128     c1.setUbs(v2);
00129     assert( c1.ubs()==v2 );
00130     c1.setEffectiveness(3.);
00131     assert( c1.effectiveness()==3. );
00132 
00133     {
00134       OsiColCut c3(c1);
00135       assert(   c3==c1 );
00136       assert( !(c3!=c1) );
00137     }
00138     {
00139       OsiColCut c3(c1);
00140       c3.setLbs(v2);
00141       assert(   c3!=c1 );
00142       assert( !(c3==c1) );
00143     }
00144     {
00145       OsiColCut c3(c1);
00146       c3.setUbs(v1);
00147       assert(   c3!=c1 );
00148       assert( !(c3==c1) );
00149     }
00150     {
00151       OsiColCut c3(c1);
00152       c3.setEffectiveness(5.);
00153       assert(   c3!=c1 );
00154       assert( !(c3==c1) );
00155     }
00156   }
00157 
00158   // internal consistency 
00159   {
00160     const int ne = 1;
00161     int inx[ne] = { -3 };
00162     double el[ne] = { 1.2 };
00163     OsiColCut r; 
00164     r.setLbs( ne, inx, el );
00165     assert( !r.consistent() );
00166   }
00167   {
00168     const int ne = 1;
00169     int inx[ne] = { -3 };
00170     double el[ne] = { 1.2 };
00171     OsiColCut r; 
00172     r.setUbs( ne, inx, el );
00173     assert( !r.consistent() );
00174   }
00175   {
00176     const int ne = 1;
00177     int inx[ne] = { 100 };
00178     double el[ne] = { 1.2 };
00179     const int ne1 = 2;
00180     int inx1[ne1] = { 50, 100 };
00181     double el1[ne1] = { 100., 100. };
00182     OsiColCut r; 
00183     r.setUbs( ne, inx, el );
00184     r.setLbs( ne1, inx1, el1 );
00185     assert( r.consistent() );
00186 
00187     OsiSolverInterface * imP = baseSiP->clone();
00188     std::string fn = mpsDir+"exmip1";
00189     imP->readMps(fn.c_str(),"mps");
00190     assert( !r.consistent(*imP) );
00191     delete imP;
00192   }
00193   {
00194     const int ne = 1;
00195     int inx[ne] = { 100 };
00196     double el[ne] = { 1.2 };
00197     const int ne1 = 2;
00198     int inx1[ne1] = { 50, 100 };
00199     double el1[ne1] = { 100., 1. };
00200     OsiColCut r; 
00201     r.setUbs( ne, inx, el );
00202     r.setLbs( ne1, inx1, el1 );
00203     assert( r.consistent() );
00204   }
00205   {
00206     // Test consistent(IntegerModel) method.
00207     OsiSolverInterface * imP = baseSiP->clone();
00208     std::string fn = mpsDir+"exmip1";
00209     imP->readMps(fn.c_str(),"mps");
00210     
00211     OsiColCut cut;
00212     const int ne=1;
00213     int inx[ne]={20};
00214     double el[ne]={0.25};
00215     cut.setLbs(ne,inx,el);
00216     assert( !cut.consistent(*imP) );
00217     
00218     cut.setLbs(0,NULL,NULL);
00219     cut.setUbs(ne,inx,el); 
00220     assert( !cut.consistent(*imP) );
00221     
00222     inx[0]=4;
00223     cut.setLbs(ne,inx,el);
00224     cut.setUbs(0,NULL,NULL); 
00225     assert( cut.consistent(*imP) );
00226     
00227     el[0]=4.5;
00228     cut.setLbs(0,NULL,NULL);
00229     cut.setUbs(ne,inx,el); 
00230     assert( cut.consistent(*imP) );
00231 
00232     cut.setLbs(ne,inx,el);
00233     cut.setUbs(0,NULL,NULL); 
00234     assert( cut.consistent(*imP) );  // Vailid but infeasible
00235     assert( cut.infeasible(*imP) );
00236     
00237     el[0]=3.0;
00238     cut.setLbs(ne,inx,el);
00239     cut.setUbs(ne,inx,el); 
00240     assert( cut.consistent(*imP) ); 
00241     delete imP;
00242   }
00243   {
00244     //Test infeasible(im) method
00245     // Test consistent(IntegerModel) method.
00246     OsiSolverInterface * imP = baseSiP->clone();
00247     std::string fn = mpsDir+"exmip1";
00248     imP->readMps(fn.c_str(),"mps");
00249     
00250     OsiColCut cut;
00251     const int ne=1;
00252     int inx[ne]={4};
00253     double el[ne]={4.5};
00254     cut.setLbs(ne,inx,el);
00255     assert( cut.infeasible(*imP) );
00256 
00257     el[0]=0.25;
00258     cut.setLbs(0,NULL,NULL);
00259     cut.setUbs(ne,inx,el);
00260     assert( cut.infeasible(*imP) ); 
00261     
00262     el[0]=3.0;
00263     cut.setLbs(ne,inx,el);
00264     cut.setUbs(ne,inx,el); 
00265     assert( !cut.infeasible(*imP) );
00266 
00267     delete imP;
00268   }
00269   {
00270     //Test violation
00271 
00272     double solution[]={1.0};
00273     OsiColCut cut;
00274     const int ne=1;
00275     int inx[ne]={0};
00276     double el[ne]={4.5};
00277     cut.setLbs(ne,inx,el);
00278     assert( cut.violated(solution) );
00279 
00280     el[0]=0.25;
00281     cut.setLbs(0,NULL,NULL);
00282     cut.setUbs(ne,inx,el);
00283     assert( cut.violated(solution) );
00284     
00285     el[0]=1.0;
00286     cut.setLbs(ne,inx,el);
00287     cut.setUbs(ne,inx,el); 
00288     assert( !cut.violated(solution) );
00289 
00290   }
00291 }


The documentation for this class was generated from the following file:
Generated on Wed Dec 3 14:35:39 2003 for Osi by doxygen 1.3.5