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

- File List
- File Members

# /home/coin/svn-release/Blis-0.94.1/Blis/src/BlisVariable.h

Go to the documentation of this file.

    00001 /*===========================================================================*
    00002  * This file is part of the BiCePS Linear Integer Solver (BLIS).             *
    00003  *                                                                           *
    00004  * BLIS is distributed under the Eclipse 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  *                                                                           *
    00020  * Copyright (C) 2001-2013, Lehigh University, Yan Xu, and Ted Ralphs.       *
    00021  * All Rights Reserved.                                                      *
    00022  *===========================================================================*/
    00023
    00024 #ifndef BlisVariable_h_
    00025 #define BlisVariable_h_
    00026
    00027 #include "BcpsObject.h"
    00028
    00029 //#############################################################################
    00030
    00031 class BlisVariable : public BcpsVariable {
    00032
    00033  private:
    00034
    00035     double objCoef_;
    00036     int size_;
    00037     int *indices_;
    00038     double *values_;
    00039
    00040  public:
    00041
    00042     BlisVariable() : objCoef_(0.0), size_(0), indices_(NULL), values_(NULL) {}
    00043
    00044     BlisVariable(double obj, int s, const int *ind, const double *val)
    00045         {
    00046             objCoef_ = obj;
    00047             size_ = s;
    00048             indices_ = new int [s];
    00049             values_ = new double [s];
    00050             memcpy(indices_, ind, s * sizeof(int));
    00051             memcpy(values_, val, s * sizeof(double));
    00052         }
    00053
    00054     BlisVariable(double lbh, double ubh, double lbs, double ubs)
    00055         :
    00056         BcpsVariable(lbh, ubh, lbs, ubs),
    00057         objCoef_(0.0),
    00058         size_(0), indices_(NULL), values_(NULL)
    00059         {}
    00060
    00061     BlisVariable(double lbh, double ubh, double lbs, double ubs,
    00062                  double obj, int s, const int *ind, const double *val)
    00063         :
    00064         BcpsVariable(lbh, ubh, lbs, ubs)
    00065         {
    00066             objCoef_ = obj;
    00067             size_ = s;
    00068             indices_ = new int [s];
    00069             values_ = new double [s];
    00070             memcpy(indices_, ind, s * sizeof(int));
    00071             memcpy(values_, val, s * sizeof(double));
    00072         }
    00073
    00074     virtual ~BlisVariable(){
    00075         delete [] indices_; indices_ = NULL;
    00076         delete [] values_; values_ = NULL;
    00077     }
    00078
    00081     double getObjCoef()    { return objCoef_; }
    00082     int getSize() const     { return size_; }
    00083     int* getIndices() const { return indices_; }
    00084     double* getValues()     { return values_; }
    00089     void setData(int s, const int *ind, const double *val) {
    00090         if (size_ < s) {
    00091             delete [] indices_; indices_ = NULL;
    00092             delete [] values_; values_ = NULL;
    00093             indices_ = new int [s];
    00094             values_ = new double [s];
    00095         }
    00096         size_ = s;
    00097         memcpy(indices_, ind, sizeof(int) * s);
    00098         memcpy(values_, val, sizeof(double) * s);
    00099     }
    00100     void setObjCoef(double coef)    { objCoef_ = coef; }
    00103  protected:
    00104
    00106     AlpsReturnStatus encodeBlis(AlpsEncoded *encoded) {
    00107         AlpsReturnStatus status = AlpsReturnStatusOk;
    00108
    00109         //std::cout << "****** encodeBlis var: size_ = " << size_ << std::endl;
    00110
    00111         encoded->writeRep(objCoef_);
    00112         encoded->writeRep(indices_, size_);
    00113         encoded->writeRep(values_, size_);
    00114
    00115         return status;
    00116     }
    00117
    00119     AlpsReturnStatus decodeBlis(AlpsEncoded &encoded) {
    00120         AlpsReturnStatus status = AlpsReturnStatusOk;
    00121
    00122         encoded.readRep(objCoef_);
    00123         encoded.readRep(indices_, size_);
    00124         encoded.readRep(values_, size_);
    00125
    00126         //std::cout << "****** decodeBlis var: size_ = " << size_ << std::endl;
    00127
    00128         return status;
    00129     }
    00130
    00131  public:
    00132
    00133     using AlpsKnowledge::encode ;
    00135     virtual AlpsReturnStatus encode(AlpsEncoded *encoded){
    00136         AlpsReturnStatus status;
    00137
    00138         status = encodeBcpsObject(encoded);
    00139         status = encodeBlis(encoded);
    00140
    00141         return status;
    00142     }
    00143
    00145     virtual AlpsKnowledge* decode(AlpsEncoded &encoded) const {
    00146         AlpsReturnStatus status = AlpsReturnStatusOk;
    00147         BlisVariable * var = new BlisVariable();
    00148
    00149         // Unpack Bcps part.
    00150         status = var->decodeBcpsObject(encoded);
    00151         if (status) {
    00152             throw CoinError("Failed to decode Bcps part of var",
    00153                             "decode",
    00154                             "BlisObject");
    00155         }
    00156
    00157         // Unpack Blis part.
    00158         status = var->decodeBlis(encoded);
    00159         if (status) {
    00160             throw CoinError("Failed to decode Blis part of var",
    00161                             "decode",
    00162                             "BlisObject");
    00163         }
    00164         return var;
    00165     }
    00166
    00167 };
    00168
    00169 //#############################################################################
    00170
    00171 #endif /* End of file */
    00172