DecompCutOsi.h

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

Generated on 5 Apr 2015 for Dip-All by  doxygen 1.6.1