DecompSolution.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 #ifndef DECOMP_SOLUTION_INCLUDED
00017 #define DECOMP_SOLUTION_INCLUDED
00018 
00019 //TODO: make this public AlpsDecompSolution?
00020 class DecompSolution {
00021 protected:
00023    int      m_size;
00024 
00026    double* m_values;
00027 
00029    double   m_quality;
00030 
00031 public:
00035    inline const int getSize() const {
00036       return m_size;
00037    }
00038 
00040    inline const double* getValues() const {
00041       return m_values;
00042    }
00043 
00045    inline const double getQuality() const {
00046       return m_quality;
00047    }
00048 
00049 public:
00051    virtual void print(int       precision = 4,
00052                       std::ostream& os        = std::cout) const {
00053       int i;
00054       os << std::setprecision(precision);
00055       os << std::setiosflags(std::ios::fixed | std::ios::showpoint)
00056          << std::setw(14);
00057       os << "-------------------------" << std::endl;
00058       os << "Quality  = " << getQuality() << std::endl;
00059       os << "Solution = " << std::endl;
00060 
00061       for (i = 0; i < m_size; i++) {
00062          if (!UtilIsZero(m_values[i])) {
00063             os << std::setw(15) << i << "   " << m_values[i] << std::endl;
00064          }
00065       }
00066 
00067       os << "-------------------------" << std::endl;
00068       os << std::resetiosflags(std::ios::fixed | std::ios::showpoint |
00069                                std::ios::scientific);
00070    }
00071 
00073    virtual void print(const std::vector<std::string>& colNames,
00074                       int                    precision = 2,
00075                       std::ostream&               os        = std::cout) const {
00076       int i;
00077       os << std::setprecision(precision);
00078       os << std::setiosflags(std::ios::fixed | std::ios::showpoint);
00079 
00080       //os << "-------------------------" << std::endl;
00081       //os << "obj= " << getQuality() << std::endl;
00082       for (i = 0; i < m_size; i++) {
00083          if (!UtilIsZero(m_values[i])) {
00084             os << std::setw(25) << colNames[i] << "   " << m_values[i] << std::endl;
00085          }
00086       }
00087 
00088       //os << "-------------------------" << std::endl;
00089       os << std::resetiosflags(std::ios::fixed | std::ios::showpoint |
00090                                std::ios::scientific);
00091    }
00092 
00093 public:
00095    DecompSolution(const DecompSolution& source) :
00096       m_size(source.m_size),
00097       m_values(0),
00098       m_quality(source.m_quality) {
00099       m_values = new double[m_size];
00100       CoinAssertHint(m_values, "Error: Out of Memory");
00101       memcpy(m_values, source.m_values, m_size * sizeof(double));
00102    }
00103    DecompSolution& operator=(const DecompSolution& rhs) {
00104       if (this != &rhs) {
00105          m_size    = rhs.m_size;
00106          m_quality = rhs.m_quality;
00107          m_values = new double[m_size];
00108          CoinAssertHint(m_values, "Error: Out of Memory");
00109          memcpy(m_values, rhs.m_values, m_size * sizeof(double));
00110       }
00111 
00112       return *this;
00113    }
00114 
00115 public:
00119    DecompSolution() :
00120       m_size(0),
00121       m_values(0),
00122       m_quality(1e75) {
00123    }
00124 
00126    DecompSolution(const int      size,
00127                   const double* values,
00128                   const double   quality) :
00129       m_size(size),
00130       m_values(0),
00131       m_quality(quality) {
00132       CoinAssert(m_size > 0);
00133       m_values = new double[m_size];
00134       CoinAssertHint(m_values, "Error: Out of Memory");
00135       memcpy(m_values, values, m_size * sizeof(double));
00136    }
00137 
00138    DecompSolution(const int      size,
00139                   const double* values,
00140                   const double* cost) :
00141       m_size(size),
00142       m_values(0),
00143       m_quality(0.0) {
00144       CoinAssert(m_size > 0);
00145       m_values = new double[m_size];
00146       CoinAssertHint(m_values, "Error: Out of Memory");
00147       memcpy(m_values, values, m_size * sizeof(double));
00148 
00149       //---
00150       //--- calculate quality
00151       //---
00152       for (int i = 0; i < size; i++) {
00153          m_quality += cost[i] * values[i];
00154       }
00155    }
00156 
00157    virtual ~DecompSolution() {
00158       UTIL_DELARR(m_values);
00159    };
00160 };
00161 
00162 #endif

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