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

Generated on Sun Nov 14 14:06:30 2010 for Coin-All by  doxygen 1.4.7