Dip  0.92.4
BcpsDecompNodeDesc.h
Go to the documentation of this file.
1 //===========================================================================//
2 // This file is part of the Decomp Solver Framework. //
3 // //
4 // Decomp is distributed under the Common Public License as part of the //
5 // COIN-OR repository (http://www.coin-or.org). //
6 // //
7 // Author: Matthew Galati, SAS Institute Inc. (matthew.galati@sas.com) //
8 // //
9 // Copyright (C) 2002-2007, Lehigh University, Matthew Galati, and Ted Ralphs//
10 // All Rights Reserved. //
11 //===========================================================================//
12 
13 //copyright
14 
15 //===========================================================================//
16 #ifndef BcpsDecompNodeDesc_h_
17 #define BcpsDecompNodeDesc_h_
18 
19 //===========================================================================//
20 #include "AlpsEncoded.h"
21 #include "BcpsNodeDesc.h"
22 #include "BcpsDecompModel.h"
23 #include "UtilMacrosAlps.h"
24 
25 //===========================================================================//
26 class CoinWarmStartBasis;
27 //class BcpsDecompModel;
28 
29 //===========================================================================//
30 //---
31 //--- BcpsDecompNodeDesc is derived from BcpsNodeDesc
32 //--- BcpsNodeDesc has no virtual functions
33 //--- BcpsNodeDesc is derived from AlpsNodeDesc
34 //--- AlpsNodeDesc virtual methods that must be derived:
35 //--- (1) encode ?? needed for serial ??
36 //--- (2) decode
37 //---
38 
39 //===========================================================================//
40 class BcpsDecompNodeDesc : public BcpsNodeDesc {
41 
42  private:
43 
44  public:
45  /* Here, we need to fill in what the node description will look
46  like. For now, we will not use differencing -- just explicitly
47  represent it. Probably this means that we will just store the
48  original problem data and a list of the variables that have been
49  fixed. */
50 
52  double* lowerBounds_;
54  double* upperBounds_;
55 
61 
62 
65 
68 
70  double branchedVal_;
71 
72  //THINK: different derivations for different algos?
75 
76  public:
77 
80  BcpsNodeDesc(),
81  branchedDir_(0),
82  branchedInd_(-1),
83  branchedVal_(0.0),
84  basis_(NULL)
85  {}
86 
88  //TODO: BlisModel as arg? or should be BcpsModel?
89  //BcpsDecompNodeDesc(BcpsDecompModel * m)
90  BcpsDecompNodeDesc(BcpsModel * m)
91  :
92  BcpsNodeDesc(m),
93  branchedDir_(0),
94  branchedInd_(-1),
95  branchedVal_(0.0),
96  basis_(NULL)
97  {}
98 
100  const double * lb,
101  const double * ub)
102  :
103  BcpsNodeDesc(m),
104  branchedDir_(0),
105  branchedInd_(-1),
106  branchedVal_(0.0),
107  basis_(NULL)
108  {
109  numberRows_ = m->getNumRows();
110  numberCols_ = m->getNumCols();
111  assert(numberRows_ && numberCols_);
112  lowerBounds_ = new double [numberCols_];
113  upperBounds_ = new double [numberCols_];
114  memcpy(lowerBounds_, lb, sizeof(double)*numberCols_);
115  memcpy(upperBounds_, ub, sizeof(double)*numberCols_);
116  }
117 
119  virtual ~BcpsDecompNodeDesc() {
120  if (lowerBounds_ != 0) {
121  delete [] lowerBounds_;
122  lowerBounds_ = 0;
123  }
124  if (upperBounds_ != 0) {
125  delete [] upperBounds_;
126  upperBounds_ = 0;
127  }
128  delete basis_;
129  }
130 
133  if (basis_) { delete basis_; }
134  basis_= ws;
135  ws = NULL;
136  }
137 
139  CoinWarmStartBasis * getBasis() const { return basis_; }
140 
141  void setBranchedOn(int b) { branchedInd_ = b; }
142  int getBranchedOn() const { return branchedInd_; }
143 
145  void setBranchedDir(int d) { branchedDir_ = d; }
146 
148  int getBranchedDir() const { return branchedDir_; }
149 
151  void setBranchedInd(int d) { branchedInd_ = d; }
152 
154  int getBranchedInd() const { return branchedInd_; }
155 
157  void setBranchedVal(double d) { branchedVal_ = d; }
158 
160  double getBranchedVal() const { return branchedVal_; }
161 
162  protected:
163 
164  //---
165  //--- helper functions for encode/decode
166  //---
167 
171 
172  encoded->writeRep(branchedDir_);
173  encoded->writeRep(branchedInd_);
174  encoded->writeRep(branchedVal_);
175 
176  // Basis
177  int ava = 0;
178  if (basis_) {
179  ava = 1;
180  encoded->writeRep(ava);
181  //should this be a util func or blis func?
182  //seems pretty standard, alps/coin util type stuff
184  }
185  else {
186  encoded->writeRep(ava);
187  }
188 
189  return status;
190  }
191 
195 
196  encoded.readRep(branchedDir_);
197  encoded.readRep(branchedInd_);
198  encoded.readRep(branchedVal_);
199 
200  // Basis
201  int ava;
202  encoded.readRep(ava);
203  if (ava == 1) {
204  basis_ = UtilAlpsDecodeWarmStart(encoded, &status);
205  }
206  else {
207  basis_ = NULL;
208  }
209 
210  return status;
211  }
212 
213  public:
214 
215  //---
216  //--- pure virtual functions from BcpsNodeDesc or AlpsNodeDesc
217  //---
218 
220  virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const {
222 
223  status = encodeBcps(encoded);
224  status = encodeBcpsDecomp(encoded);
225 
226  return status;
227  }
228 
230  virtual AlpsReturnStatus decode(AlpsEncoded &encoded) {
231 
233 
234  status = decodeBcps(encoded);
235  status = decodeBcpsDecomp(encoded);
236 
237  return status;
238  }
239 
240 };
241 #endif
void setBranchedInd(int d)
Set branching object index.
double branchedVal_
Branched value to create it.
AlpsEncoded & readRep(T &value)
Read a single object of type <code>T</code> from <code>repsentation_ .
Definition: AlpsEncoded.h:173
AlpsEncoded & writeRep(const T &value)
Write a single object of type <code>T</code> in <code>repsentation_ .
Definition: AlpsEncoded.h:163
AlpsReturnStatus
Definition: Alps.h:118
double getBranchedVal() const
Get branching direction.
virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const
Pack node description into an encoded.
CoinWarmStartBasis * basis_
Warm start.
int numberRows_
Number of rows in problem (before these cuts).
BcpsDecompNodeDesc(BcpsModel *m)
Useful constructor.
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
BcpsDecompNodeDesc()
Default constructor.
int branchedDir_
Branched direction to create it.
CoinWarmStartBasis * UtilAlpsDecodeWarmStart(AlpsEncoded &encoded, AlpsReturnStatus *rc)
Unpack coin warm start from an encoded object.
int branchedInd_
Branched object index to create it.
int getBranchedInd() const
Get branching object index.
AlpsReturnStatus encodeBcpsDecomp(AlpsEncoded *encoded) const
Pack blis portion of node description into an encoded.
CoinWarmStartBasis * getBasis() const
Get warm start basis.
void setBasis(CoinWarmStartBasis *&ws)
Set basis.
virtual ~BcpsDecompNodeDesc()
Destructor.
void setBranchedVal(double d)
Set branching value.
void setBranchedDir(int d)
Set branching direction.
AlpsReturnStatus decodeBcpsDecomp(AlpsEncoded &encoded)
Unpack blis portion of node description from an encoded.
int getBranchedDir() const
Get branching direction.
int UtilAlpsEncodeWarmStart(AlpsEncoded *encoded, const CoinWarmStartBasis *ws)
Pack coin warm start into an encoded object.
virtual AlpsReturnStatus decode(AlpsEncoded &encoded)
Unpack a node description from an encoded.
int getBranchedOn() const
The default COIN simplex (basis-oriented) warm start class.
BcpsDecompNodeDesc(BcpsDecompModel *m, const double *lb, const double *ub)