DecompCut.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_CUT_INCLUDED
00015 #define DECOMP_CUT_INCLUDED
00016 
00017 //a cut in terms of the original x variables
00018 
00019 //by default it could look for OSI-CGL cuts? for CP procedures
00020 //or the user can provide its own cut generator - force them to return
00021 //a common cut structure?
00022 
00023 //the user might have some compact way to store its cut, for example
00024 //with TSP cuts, they just want to store the customer set, and then
00025 //they override a function called expandCutToRow which tells this base
00026 //class how to expand into the LP
00027 
00028 #include "UtilHash.h"
00029 #include "DecompPortable.h"
00030 
00031 #include "CoinError.hpp"
00032 #include <iostream>
00033 using namespace std;
00034 
00035 class DecompCut {
00036 private:
00037    DecompCut(const DecompCut&);
00038    DecompCut& operator=(const DecompCut&);
00039 
00040 private:
00041    double           m_lb;        //row lower bound
00042    double           m_ub;        //row upper bound
00043    //THINK, or they can stick in as sense/rhs
00044    double           m_violation; //current violation
00045    int              m_effCnt;    //effectiveness counter
00046 
00047 protected:
00048    string           m_strHash;
00049    //TODO - use distance instead of violation? see SAS
00050 
00051 public:
00052    inline double    getLowerBound()   const {
00053       return m_lb;
00054    }
00055    inline double    getUpperBound()   const {
00056       return m_ub;
00057    }
00058    inline double    getViolation()    const {
00059       return m_violation;
00060    }
00061    inline int       getEffCnt()       const {
00062       return m_effCnt;
00063    }
00064    inline string    getStrHash()      const {
00065       return m_strHash;
00066    }
00067 
00068 public:
00069    inline void      setLowerBound(const double lb) {
00070       m_lb = lb;
00071    }
00072    inline void      setUpperBound(const double ub) {
00073       m_ub = ub;
00074    }
00075    inline void      setViolation(const double violation) {
00076       m_violation = violation;
00077    }
00078 
00079    bool calcViolation(const CoinPackedVector* row,
00080                       const double*              x);
00081 
00082 public:
00083    //but these should be optional to user! after they show us how to
00084    //expandCutToRow... then we should be able to handle the hashing and
00085    //checking isSame, etc... the user can override it, if they can do it
00086    //faster - but we should not force them
00087 
00088    //now it is essentially a DecompCutOsi
00089    virtual void     setStringHash(CoinPackedVector* row) {
00090       //the user can override this if they can do it faster... also
00091       //should link up with isSame
00092       char sense;
00093       double rhs, range;
00094       UtilBoundToSense(getLowerBound(),
00095                        getUpperBound(), DecompInf,
00096                        sense, rhs, range);
00097       m_strHash = UtilCreateStringHash(row->getNumElements(),
00098                                        row->getIndices(),
00099                                        row->getElements(),
00100                                        sense, rhs);
00101       //need backup for user
00102       //throw CoinError("Method was invoked but not overridden.",
00103       //            "setStringHash", "DecompCut");1
00104    }
00105 
00106    virtual void     expandCutToRow(CoinPackedVector* row) {
00107       throw CoinError("Method was invoked but not overridden.",
00108                       "expandCutToRow", "DecompCut");
00109    }
00110 
00111    virtual void     setBounds() {
00112       throw CoinError("Method was invoked but not overridden.",
00113                       "setBounds", "DecompCut");
00114    }
00115 
00116    virtual bool     isSame(const DecompCut* cut) const {
00117       return false;
00118    }
00119 
00120    virtual void     print(ostream* os = &cout) const;
00121 
00122 public:
00123    inline void resetEffCnt() {
00124       m_effCnt = 0;
00125    }
00126 
00129    inline void increaseEffCnt() {
00130       m_effCnt = m_effCnt <= 0 ? 1 : m_effCnt + 1;
00131    }
00132 
00135    inline void decreaseEffCnt() {
00136       m_effCnt = m_effCnt >= 0 ? -1 : m_effCnt - 1;
00137    }
00138 
00139 public:
00140    DecompCut() :
00141       m_lb       (0.0),
00142       m_ub       (0.0),
00143       m_violation(0.0),
00144       m_effCnt   (0),
00145       m_strHash  () {
00146    };
00147    virtual ~DecompCut() {};
00148 
00149 };
00150 
00151 #endif

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