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

- File List
- File Members

# /home/coin/SVN-release/Alps-1.2.1/Osi/src/Osi/OsiColCut.hpp

Go to the documentation of this file.

    00001 // Copyright (C) 2000, International Business Machines
    00002 // Corporation and others.  All Rights Reserved.
    00003 #ifndef OsiColCut_H
    00004 #define OsiColCut_H
    00005
    00006 #include <string>
    00007
    00008 #include "CoinPackedVector.hpp"
    00009
    00010 #include "OsiCollections.hpp"
    00011 #include "OsiCut.hpp"
    00012
    00021 class OsiColCut : public OsiCut {
    00022    friend void OsiColCutUnitTest(const OsiSolverInterface * baseSiP,
    00023                                  const std::string & mpsDir);
    00024
    00025 public:
    00026
    00027   //----------------------------------------------------------------
    00028
    00031
    00032   inline void setLbs(
    00033     int nElements,
    00034     const int * colIndices,
    00035     const double * lbElements );
    00036
    00038   inline void setLbs( const CoinPackedVector & lbs );
    00039
    00041   inline void setUbs(
    00042     int nElements,
    00043     const int * colIndices,
    00044     const double * ubElements );
    00045
    00047   inline void setUbs( const CoinPackedVector & ubs );
    00049
    00050   //----------------------------------------------------------------
    00051
    00054
    00055   inline const CoinPackedVector & lbs() const;
    00057   inline const CoinPackedVector & ubs() const;
    00059
    00062 #if __GNUC__ != 2
    00063   using OsiCut::operator== ;
    00064 #endif
    00065
    00068   inline virtual bool operator==(const OsiColCut& rhs) const;
    00069
    00070 #if __GNUC__ != 2
    00071   using OsiCut::operator!= ;
    00072 #endif
    00074   inline virtual bool operator!=(const OsiColCut& rhs) const;
    00075
    00076
    00077
    00078   //----------------------------------------------------------------
    00079
    00089   inline virtual bool consistent() const;
    00090
    00098   inline virtual bool consistent(const OsiSolverInterface& im) const;
    00099
    00108   inline virtual bool infeasible(const OsiSolverInterface &im) const;
    00113   virtual double violated(const double * solution) const;
    00115
    00116   //----------------------------------------------------------------
    00117
    00120
    00121   OsiColCut & operator=( const OsiColCut& rhs);
    00122
    00124   OsiColCut ( const OsiColCut &);
    00125
    00127   OsiColCut ();
    00128
    00130   virtual OsiColCut * clone() const;
    00131
    00133   virtual ~OsiColCut ();
    00135
    00138
    00139   virtual void print() const;
    00141
    00142 private:
    00143
    00146
    00147   CoinPackedVector lbs_;
    00149   CoinPackedVector ubs_;
    00151
    00152 };
    00153
    00154
    00155
    00156 //-------------------------------------------------------------------
    00157 // Set lower & upper bound vectors
    00158 //-------------------------------------------------------------------
    00159 void OsiColCut::setLbs(
    00160                        int size,
    00161                        const int * colIndices,
    00162                        const double * lbElements )
    00163 {
    00164   lbs_.setVector(size,colIndices,lbElements);
    00165 }
    00166 //
    00167 void OsiColCut::setUbs(
    00168                        int size,
    00169                        const int * colIndices,
    00170                        const double * ubElements )
    00171 {
    00172   ubs_.setVector(size,colIndices,ubElements);
    00173 }
    00174 //
    00175 void OsiColCut::setLbs( const CoinPackedVector & lbs )
    00176 {
    00177   lbs_ = lbs;
    00178 }
    00179 //
    00180 void OsiColCut::setUbs( const CoinPackedVector & ubs )
    00181 {
    00182   ubs_ = ubs;
    00183 }
    00184
    00185 //-------------------------------------------------------------------
    00186 // Get Column Lower Bounds and Column Upper Bounds
    00187 //-------------------------------------------------------------------
    00188 const CoinPackedVector & OsiColCut::lbs() const
    00189 {
    00190   return lbs_;
    00191 }
    00192 //
    00193 const CoinPackedVector & OsiColCut::ubs() const
    00194 {
    00195   return ubs_;
    00196 }
    00197
    00198 //----------------------------------------------------------------
    00199 // == operator
    00200 //-------------------------------------------------------------------
    00201 bool
    00202 OsiColCut::operator==(
    00203                       const OsiColCut& rhs) const
    00204 {
    00205   if ( this->OsiCut::operator!=(rhs) )
    00206     return false;
    00207   if ( lbs() != rhs.lbs() )
    00208     return false;
    00209   if ( ubs() != rhs.ubs() )
    00210     return false;
    00211   return true;
    00212 }
    00213 //
    00214 bool
    00215 OsiColCut::operator!=(
    00216                       const OsiColCut& rhs) const
    00217 {
    00218   return !( (*this)==rhs );
    00219 }
    00220
    00221 //----------------------------------------------------------------
    00222 // consistent & infeasible
    00223 //-------------------------------------------------------------------
    00224 bool OsiColCut::consistent() const
    00225 {
    00226   const CoinPackedVector & lb = lbs();
    00227   const CoinPackedVector & ub = ubs();
    00228   // Test for consistent cut.
    00229   // Are packed vectors consistent?
    00230   lb.duplicateIndex("consistent", "OsiColCut");
    00231   ub.duplicateIndex("consistent", "OsiColCut");
    00232   if ( lb.getMinIndex() < 0 ) return false;
    00233   if ( ub.getMinIndex() < 0 ) return false;
    00234   return true;
    00235 }
    00236 //
    00237 bool OsiColCut::consistent(const OsiSolverInterface& im) const
    00238 {
    00239   const CoinPackedVector & lb = lbs();
    00240   const CoinPackedVector & ub = ubs();
    00241
    00242   // Test for consistent cut.
    00243   if ( lb.getMaxIndex() >= im.getNumCols() ) return false;
    00244   if ( ub.getMaxIndex() >= im.getNumCols() ) return false;
    00245
    00246   return true;
    00247 }
    00248
    00249 #if 0
    00250 bool OsiColCut::feasible(const OsiSolverInterface &im) const
    00251 {
    00252   const double * oldColLb = im.getColLower();
    00253   const double * oldColUb = im.getColUpper();
    00254   const CoinPackedVector & cutLbs = lbs();
    00255   const CoinPackedVector & cutUbs = ubs();
    00256   int i;
    00257
    00258   for ( i=0; i<cutLbs.size(); i++ ) {
    00259     int colIndx = cutLbs.indices()[i];
    00260     double newLb;
    00261     if ( cutLbs.elements()[i] > oldColLb[colIndx] )
    00262       newLb = cutLbs.elements()[i];
    00263     else
    00264       newLb = oldColLb[colIndx];
    00265
    00266     double newUb = oldColUb[colIndx];
    00267     if ( cutUbs.indexExists(colIndx) )
    00268       if ( cutUbs[colIndx] < newUb ) newUb = cutUbs[colIndx];
    00269       if ( newLb > newUb )
    00270         return false;
    00271   }
    00272
    00273   for ( i=0; i<cutUbs.size(); i++ ) {
    00274     int colIndx = cutUbs.indices()[i];
    00275     double newUb = cutUbs.elements()[i] < oldColUb[colIndx] ? cutUbs.elements()[i] : oldColUb[colIndx];
    00276     double newLb = oldColLb[colIndx];
    00277     if ( cutLbs.indexExists(colIndx) )
    00278       if ( cutLbs[colIndx] > newLb ) newLb = cutLbs[colIndx];
    00279       if ( newUb < newLb )
    00280         return false;
    00281   }
    00282
    00283   return true;
    00284 }
    00285 #endif
    00286
    00287
    00288 bool OsiColCut::infeasible(const OsiSolverInterface &im) const
    00289 {
    00290   const double * oldColLb = im.getColLower();
    00291   const double * oldColUb = im.getColUpper();
    00292   const CoinPackedVector & cutLbs = lbs();
    00293   const CoinPackedVector & cutUbs = ubs();
    00294   int i;
    00295
    00296   for ( i=0; i<cutLbs.getNumElements(); i++ ) {
    00297     int colIndx = cutLbs.getIndices()[i];
    00298     double newLb= cutLbs.getElements()[i] > oldColLb[colIndx] ?
    00299        cutLbs.getElements()[i] : oldColLb[colIndx];
    00300
    00301     double newUb = oldColUb[colIndx];
    00302     if ( cutUbs.isExistingIndex(colIndx) )
    00303       if ( cutUbs[colIndx] < newUb ) newUb = cutUbs[colIndx];
    00304       if ( newLb > newUb )
    00305         return true;
    00306   }
    00307
    00308   for ( i=0; i<cutUbs.getNumElements(); i++ ) {
    00309     int colIndx = cutUbs.getIndices()[i];
    00310     double newUb = cutUbs.getElements()[i] < oldColUb[colIndx] ?
    00311        cutUbs.getElements()[i] : oldColUb[colIndx];
    00312     double newLb = oldColLb[colIndx];
    00313     if ( cutLbs.isExistingIndex(colIndx) )
    00314       if ( cutLbs[colIndx] > newLb ) newLb = cutLbs[colIndx];
    00315       if ( newUb < newLb )
    00316         return true;
    00317   }
    00318
    00319   return false;
    00320 }
    00321
    00322 //#############################################################################
    00328 void
    00329 OsiColCutUnitTest(const OsiSolverInterface * baseSiP,
    00330                   const std::string & mpsDir);
    00331
    00332 #endif