BcpsDecompNodeDesc.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 class BcpsDecompNodeDesc : public BcpsNodeDesc {
00041
00042 private:
00043
00044 public:
00045
00046
00047
00048
00049
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
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
00089
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
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
00177 int ava = 0;
00178 if (basis_) {
00179 ava = 1;
00180 encoded->writeRep(ava);
00181
00182
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
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
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