BcpsDecompNodeDesc.h

Go to the documentation of this file.
00001 //===========================================================================//
00002 // This file is part of the Decomp Solver Framework.                         //
00003 //                                                                           //
00004 // Decomp is distributed under the Common 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 // Copyright (C) 2002-2007, Lehigh University, Matthew Galati, and Ted Ralphs//
00010 // All Rights Reserved.                                                      //
00011 //===========================================================================//
00012 
00013 //copyright
00014 
00015 //===========================================================================//
00016 #ifndef BcpsDecompNodeDesc_h_
00017 #define BcpsDecompNodeDesc_h_
00018 
00019 //===========================================================================//
00020 #include "AlpsEncoded.h"
00021 #include "BcpsNodeDesc.h"
00022 #include "BcpsDecompModel.h"
00023 #include "UtilMacrosAlps.h"
00024 
00025 //===========================================================================//
00026 class CoinWarmStartBasis;
00027 //class BcpsDecompModel;
00028 
00029 //===========================================================================//
00030 //---
00031 //--- BcpsDecompNodeDesc is derived from BcpsNodeDesc
00032 //---   BcpsNodeDesc has no virtual functions
00033 //--- BcpsNodeDesc       is derived from AlpsNodeDesc
00034 //---   AlpsNodeDesc virtual methods that must be derived:
00035 //---      (1) encode ?? needed for serial ??
00036 //---      (2) decode
00037 //---      
00038 
00039 //===========================================================================//
00040 class BcpsDecompNodeDesc : public BcpsNodeDesc {
00041   
00042  private:
00043     
00044  public:
00045   /* Here, we need to fill in what the node description will look
00046      like. For now, we will not use differencing -- just explicitly
00047      represent it. Probably this means that we will just store the
00048        original problem data and a list of the variables that have been
00049        fixed. */
00050   
00052   double* lowerBounds_;
00054   double* upperBounds_;
00055   
00058   int numberRows_;
00060   int numberCols_;
00061 
00062 
00064     int branchedDir_;
00065 
00067     int branchedInd_;
00068 
00070     double branchedVal_;
00071 
00072     //THINK: different derivations for different algos?
00074     CoinWarmStartBasis *basis_;
00075     
00076  public:
00077 
00079     BcpsDecompNodeDesc() :
00080         BcpsNodeDesc(),
00081         branchedDir_(0),
00082         branchedInd_(-1),
00083         branchedVal_(0.0),
00084     basis_(NULL)
00085         {}
00086 
00088     //TODO: BlisModel as arg? or should be BcpsModel?
00089     //BcpsDecompNodeDesc(BcpsDecompModel * m) 
00090     BcpsDecompNodeDesc(BcpsModel * m) 
00091     :
00092     BcpsNodeDesc(m),
00093         branchedDir_(0),
00094         branchedInd_(-1),
00095         branchedVal_(0.0),
00096     basis_(NULL)
00097     {}
00098 
00099     BcpsDecompNodeDesc(BcpsDecompModel * m, 
00100                        const double    * lb, 
00101                        const double    * ub) 
00102     :
00103       BcpsNodeDesc(m),
00104       branchedDir_(0),
00105       branchedInd_(-1),
00106       branchedVal_(0.0),
00107       basis_(NULL)
00108       {
00109         numberRows_ = m->getNumRows();
00110         numberCols_ = m->getNumCols();
00111         assert(numberRows_ && numberCols_);
00112         lowerBounds_ = new double [numberCols_];
00113         upperBounds_ = new double [numberCols_];
00114         memcpy(lowerBounds_, lb, sizeof(double)*numberCols_);
00115         memcpy(upperBounds_, ub, sizeof(double)*numberCols_);
00116       }
00117 
00119     virtual ~BcpsDecompNodeDesc() { 
00120       if (lowerBounds_ != 0) {
00121         delete [] lowerBounds_;
00122         lowerBounds_ = 0;
00123       }
00124       if (upperBounds_ != 0) {
00125         delete [] upperBounds_;
00126         upperBounds_ = 0;
00127       }
00128       delete basis_; 
00129     }
00130 
00132     void setBasis(CoinWarmStartBasis *&ws) { 
00133         if (basis_) { delete basis_; }
00134         basis_= ws;
00135         ws = NULL; 
00136     }
00137 
00139     CoinWarmStartBasis * getBasis() const { return basis_; }
00140 
00141     void setBranchedOn(int b) { branchedInd_ = b; }
00142     int getBranchedOn() const { return branchedInd_; }
00143 
00145     void setBranchedDir(int d) { branchedDir_ = d; }
00146 
00148     int getBranchedDir() const { return branchedDir_; }
00149 
00151     void setBranchedInd(int d) { branchedInd_ = d; }
00152 
00154     int getBranchedInd() const { return branchedInd_; }
00155 
00157     void setBranchedVal(double d) { branchedVal_ = d; }
00158 
00160     double getBranchedVal() const { return branchedVal_; }
00161 
00162  protected:
00163 
00164     //---
00165     //--- helper functions for encode/decode
00166     //---
00167 
00169     AlpsReturnStatus encodeBcpsDecomp(AlpsEncoded *encoded) const {
00170     AlpsReturnStatus status = AlpsReturnStatusOk;
00171 
00172     encoded->writeRep(branchedDir_);
00173     encoded->writeRep(branchedInd_);
00174     encoded->writeRep(branchedVal_);
00175 
00176     // Basis
00177     int ava = 0;
00178     if (basis_) {
00179         ava = 1;
00180         encoded->writeRep(ava);
00181             //should this be a util func or blis func?
00182             //seems pretty standard, alps/coin util type stuff
00183         UtilAlpsEncodeWarmStart(encoded, basis_);
00184     }
00185     else {
00186         encoded->writeRep(ava);
00187     }
00188     
00189     return status;
00190     }
00191 
00193     AlpsReturnStatus decodeBcpsDecomp(AlpsEncoded &encoded) {
00194     AlpsReturnStatus status = AlpsReturnStatusOk;
00195     
00196     encoded.readRep(branchedDir_);
00197     encoded.readRep(branchedInd_);
00198     encoded.readRep(branchedVal_);
00199     
00200     // Basis
00201     int ava;
00202     encoded.readRep(ava);
00203     if (ava == 1) {
00204         basis_ = UtilAlpsDecodeWarmStart(encoded, &status);
00205     }
00206     else {
00207         basis_ = NULL;
00208     }
00209     
00210     return status;
00211     }
00212 
00213  public:
00214 
00215     //---
00216     //--- pure virtual functions from BcpsNodeDesc or AlpsNodeDesc
00217     //---  
00218     
00220     virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const {
00221         AlpsReturnStatus status = AlpsReturnStatusOk;
00222     
00223     status = encodeBcps(encoded);
00224     status = encodeBcpsDecomp(encoded);
00225     
00226     return status;
00227     }
00228 
00230     virtual AlpsReturnStatus decode(AlpsEncoded &encoded) {
00231     
00232         AlpsReturnStatus status = AlpsReturnStatusOk;
00233     
00234     status = decodeBcps(encoded);
00235     status = decodeBcpsDecomp(encoded);
00236 
00237     return status;
00238     }
00239     
00240 };
00241 #endif

Generated on 12 Feb 2015 for Dip-All by  doxygen 1.6.1