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

- File List
- File Members

# /home/coin/svn-release/Blis-0.93.2/Bcps/examples/Blis/BlisVariable.h

Go to the documentation of this file.

    00001 /*===========================================================================*
    00002  * This file is part of the Bcps Linear 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-2011, 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         if (size_ > 0) {
    00076             delete [] indices_; indices_ = NULL;
    00077             delete [] values_; values_ = NULL;
    00078         }
    00079     }
    00080
    00083     int getSize() const     { return size_; }
    00084     int* getIndices() const { return indices_; }
    00085     double* getValues()     { return values_; }
    00090     void setData(int s, const int *ind, const double *val) {
    00091         if (size_ < s) {
    00092             delete [] indices_; indices_ = NULL;
    00093             delete [] values_; values_ = NULL;
    00094             indices_ = new int [s];
    00095             values_ = new double [s];
    00096         }
    00097         size_ = s;
    00098         memcpy(indices_, ind, sizeof(int) * s);
    00099         memcpy(values_, val, sizeof(double) * s);
    00100     }
    00103  protected:
    00104
    00106     AlpsReturnStatus encodeBlis(AlpsEncoded *encoded) {
    00107         AlpsReturnStatus status = AlpsReturnStatusOk;
    00108
    00109         encoded->writeRep(objCoef_);
    00110         encoded->writeRep(indices_, size_);
    00111         encoded->writeRep(values_, size_);
    00112
    00113         return status;
    00114     }
    00115
    00117     AlpsReturnStatus decodeBlis(AlpsEncoded &encoded) {
    00118         AlpsReturnStatus status = AlpsReturnStatusOk;
    00119
    00120         encoded.readRep(objCoef_);
    00121         encoded.readRep(indices_, size_);
    00122         encoded.readRep(values_, size_);
    00123
    00124         return status;
    00125     }
    00126
    00127  public:
    00128
    00130     virtual AlpsReturnStatus encode(AlpsEncoded *encoded){
    00131         AlpsReturnStatus status;
    00132
    00133         status = encodeBcpsObject(encoded);
    00134         status = encodeBlis(encoded);
    00135
    00136         return status;
    00137     }
    00138
    00140     virtual AlpsKnowledge* decode(AlpsEncoded &encoded) const {
    00141         AlpsReturnStatus status = AlpsReturnStatusOk;
    00142         BlisVariable * var = new BlisVariable();
    00143
    00144         // Unpack Bcps part.
    00145         status = var->decodeBcpsObject(encoded);
    00146         if (status) {
    00147             throw CoinError("Failed to decode Bcps part of var",
    00148                             "decode",
    00149                             "BlisObject");
    00150         }
    00151
    00152         // Unpack Blis part.
    00153         status = var->decodeBlis(encoded);
    00154         if (status) {
    00155             throw CoinError("Failed to decode Blis part of var",
    00156                             "decode",
    00157                             "BlisObject");
    00158         }
    00159         return var;
    00160     }
    00161
    00162 };
    00163
    00164 //#############################################################################
    00165
    00166 #endif /* End of file */
    00167