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

- File List
- File Members

# /home/coin/SVN-release/Blis-0.91.0/Bcps/src/BcpsSolution.h

Go to the documentation of this file.

    00001 /*===========================================================================*
    00002  * This file is part of the Branch, Constrain and Price Software (BiCePS)    *
    00003  *                                                                           *
    00004  * BiCePS is distributed under the Common Public License as part of the      *
    00005  * COIN-OR repository (http://www.coin-or.org).                              *
    00006  *                                                                           *
    00007  * Authors:                                                                  *
    00008  *                                                                           *
    00009  *          Yan Xu, Lehigh University                                        *
    00010  *          Ted Ralphs, Lehigh University                                    *
    00011  *                                                                           *
    00012  * Conceptual Design:                                                        *
    00013  *                                                                           *
    00014  *          Yan Xu, Lehigh University                                        *
    00015  *          Ted Ralphs, Lehigh University                                    *
    00016  *          Laszlo Ladanyi, IBM T.J. Watson Research Center                  *
    00017  *          Matthew Saltzman, Clemson University                             *
    00018  *                                                                           *
    00019  * Copyright (C) 2001-2009, Lehigh University, Yan Xu, and Ted Ralphs.       *
    00020  * All Rights Reserved.                                                      *
    00021  *===========================================================================*/
    00022
    00023 #ifndef BcpsSolution_h_
    00024 #define BcpsSolution_h_
    00025
    00026 #include "AlpsSolution.h"
    00027 #include "BcpsObject.h"
    00028
    00029 //#############################################################################
    00032 //#############################################################################
    00033
    00034 class BcpsSolution : public AlpsSolution {
    00035
    00036  private:
    00037
    00038     BcpsSolution(const BcpsSolution&);
    00039     BcpsSolution& operator=(const BcpsSolution&);
    00040
    00041  protected:
    00042
    00044     int size_;
    00045
    00047     BcpsObject_p *objects_;
    00048
    00050     double* values_;
    00051
    00053     double quality_;
    00054
    00055  public:
    00056
    00058     BcpsSolution()
    00059         :
    00060         size_(0), objects_(NULL), values_(NULL), quality_(ALPS_OBJ_MAX)
    00061         {}
    00062
    00064     BcpsSolution(int size, const double *values, double q)
    00065         :
    00066         size_(size), objects_(NULL), values_(NULL), quality_(q) {
    00067
    00068         if (size > 0) {
    00069             values_ = new double [size];
    00070             memcpy(values_, values, sizeof(double) * size);
    00071         }
    00072         else {
    00073             std::cout << "ERROR: Solution size = " << size << std::endl;
    00074             assert(size > 0);
    00075         }
    00076     }
    00077
    00080     BcpsSolution(int size, BcpsObject_p*& objects, double*& values, double q)
    00081         :
    00082         size_(size), objects_(objects), values_(values), quality_(q) {
    00083         objects = NULL;
    00084         values = NULL;
    00085     }
    00086
    00088     virtual ~BcpsSolution() {
    00089         if (objects_) {
    00090             for (int i = 0; i < size_; ++i) {
    00091                 delete objects_[i];
    00092             }
    00093             delete[] objects_;
    00094         }
    00095         delete[] values_;
    00096     }
    00097
    00100     inline int getSize() const { return size_; }
    00101     inline const BcpsObject_p* getObjects() const { return objects_; }
    00102     inline const double* getValues() const { return values_; }
    00103     inline double getQuality() const { return quality_; }
    00108     inline void setSize(int s) { size_ = s; }
    00109     inline void assignObjects(BcpsObject_p *& obj){
    00110         objects_ = obj;
    00111         obj = NULL;
    00112     }
    00113     inline void setValues(const double *vs, int s) {
    00114         if (!values_) delete [] values_;
    00115         values_ = new double [s];
    00116         size_ = s;
    00117         memcpy(values_, vs, s * sizeof(double));
    00118     }
    00119     inline void setQuality(double q) { quality_ = q; }
    00125     virtual BcpsSolution* selectNonzeros(const double etol = 1e-5) const;
    00126     virtual BcpsSolution* selectFractional(const double etol = 1e-5) const;
    00130     virtual void print(std::ostream& os) const {
    00131         for (int j = 0; j < size_; ++j) {
    00132             if (values_[j] > 1.0e-15 || values_[j] < -1.0e-15) {
    00133                 os << "x[" << j << "] = " << values_[j] << std::endl;
    00134             }
    00135         }
    00136     }
    00137
    00138     //------------------------------------------------------
    00139     // Parallel.
    00140     //------------------------------------------------------
    00141
    00143     AlpsReturnStatus encodeBcps(AlpsEncoded *encoded) const;
    00144
    00146     AlpsReturnStatus decodeBcps(AlpsEncoded & encoded);
    00147
    00148 };
    00149
    00150 //#############################################################################
    00151 //#############################################################################
    00152
    00153 #endif