DecompCutOsi.h

Go to the documentation of this file.
00001 //===========================================================================//
00002 // This file is part of the Decomp Solver Framework.                         //
00003 //                                                                           //
00004 // Decomp is distributed under the Common Public License as part of the      //
00005 // COIN-OR repository (http://www.coin-or.org).                              //
00006 //                                                                           //
00007 // Author: Matthew Galati, SAS Institute Inc. (matthew.galati@sas.com)       //
00008 //                                                                           //
00009 // Copyright (C) 2002-2007, Lehigh University, Matthew Galati, and Ted Ralphs//
00010 // All Rights Reserved.                                                      //
00011 //===========================================================================//
00012 
00013 
00014 #ifndef DECOMP_CUTOSI_HPP
00015 #define DECOMP_CUTOSI_HPP
00016 
00017 
00018 #include "UtilHash.h"
00019 #include "DecompCut.h"
00020 #include "OsiRowCut.hpp"
00021 
00022 //THINK:
00023 //why?? if we really want to be able to let the user use OsiRowCut's
00024 //then just make this public OsiRowCut or something... then need multiple
00025 //inheritance? how does ABC do?
00026 
00027 //really want a generic cut implementation here...
00028 //or just use osi?
00029 
00030 
00031 class DecompCutOsi : public DecompCut {
00032 private:
00033    DecompCutOsi(const DecompVar&);
00034    DecompCutOsi& operator=(const DecompVar&);
00035 
00036 private:
00037    OsiRowCut m_osiCut;
00038    /* THINK: seems a waste to have to copy construct the OsiRowCut, a pointer
00039       should be enough - but error on pure virtual */
00040    /* at least make it a pointer to OsiRowCut? */
00041 public:
00042    //is this an expensive operation?
00043    //temp fix
00044    char sense() const {
00045       double lb_ = m_osiCut.lb();
00046       double ub_ = m_osiCut.ub();
00047 
00048       if      ( lb_ == ub_ ) {
00049          return 'E';
00050       } else if ( lb_ == -DecompInf && ub_ == DecompInf ) {
00051          return 'N';
00052       } else if ( lb_ == -DecompInf ) {
00053          return 'L';
00054       } else if ( ub_ == DecompInf ) {
00055          return 'G';
00056       } else {
00057          return 'R';
00058       }
00059    }
00060 
00061    double rhs() const {
00062       double lb_ = m_osiCut.lb();
00063       double ub_ = m_osiCut.ub();
00064 
00065       if      ( lb_ == ub_ ) {
00066          return ub_;
00067       } else if ( lb_ == -DecompInf && ub_ == DecompInf ) {
00068          return 0.0;
00069       } else if ( lb_ == -DecompInf ) {
00070          return ub_;
00071       } else if ( ub_ == DecompInf ) {
00072          return lb_;
00073       } else {
00074          return ub_;
00075       }
00076    }
00077 
00078    void setStringHash() {
00079       //we cannot trust osi row cuts sense, since cpx and clp have different infinities...
00080       m_strHash = UtilCreateStringHash(m_osiCut.row().getNumElements(),
00081                                        m_osiCut.row().getIndices(),
00082                                        m_osiCut.row().getElements(),
00083                                        //m_osiCut.sense(),
00084                                        sense(),
00085                                        //m_osiCut.rhs()
00086                                        rhs()
00087                                       );
00088       //ranges?
00089    }
00090    void setStringHash(CoinPackedVector* row) {
00091       m_strHash = UtilCreateStringHash(row->getNumElements(),
00092                                        row->getIndices(),
00093                                        row->getElements(),
00094                                        //m_osiCut.sense(),
00095                                        sense(),
00096                                        //m_osiCut.rhs()
00097                                        rhs()
00098                                       );
00099       //ranges?
00100    }
00101 
00102    void setBounds() {
00103       setLowerBound(m_osiCut.lb());
00104       setUpperBound(m_osiCut.ub());
00105    }
00106 
00107    //think about when is this used?
00108    void expandCutToRow(CoinPackedVector* row) {
00109       row->setVector(m_osiCut.row().getNumElements(),
00110                      m_osiCut.row().getIndices(),
00111                      m_osiCut.row().getElements(),
00112                      DECOMP_TEST_DUPINDEX);
00113       /* TODO: tests for dups by default - shut this off for production */
00114    }
00115 
00116 public:
00117    void print(ostream* os = &cout) const {
00118       (*os).precision(2);
00119       (*os) << endl;
00120       const int*     ind = m_osiCut.row().getIndices();
00121       const double* els = m_osiCut.row().getElements();
00122 
00123       for (int i = 0; i < m_osiCut.row().getNumElements(); i++) {
00124          (*os) << " + " << els[i] << " x[" << ind[i] << "]";
00125       }
00126 
00127       if (getLowerBound() < -1.0e10 / 2) { //INF?
00128          (*os) << " lb: -INF";
00129       } else {
00130          (*os) << " lb: " << getLowerBound();
00131       }
00132 
00133       if (getUpperBound() > 1.0e10 / 2) { //INF?
00134          (*os) << " ub: INF";
00135       } else {
00136          (*os) << " ub: " << getUpperBound();
00137       }
00138 
00139       (*os) << " vio: " << getViolation() << "\n";
00140    }
00141 
00142 public:
00143    DecompCutOsi(OsiRowCut& osiCut)
00144       : DecompCut(), m_osiCut(osiCut) {
00145       setBounds();
00146    };
00147    virtual ~DecompCutOsi() {}
00148 
00149 };
00150 
00151 #endif

Generated on 12 Mar 2015 for Dip-All by  doxygen 1.6.1