Dip-All  0.91.0
AlpsDecompNodeDesc.h
Go to the documentation of this file.
1 //===========================================================================//
2 // This file is part of the DIP Solver Framework. //
3 // //
4 // DIP is distributed under the Eclipse 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 // Conceptual Design: Matthew Galati, SAS Institute Inc. //
10 // Ted Ralphs, Lehigh University //
11 // //
12 // Copyright (C) 2002-2015, Lehigh University, Matthew Galati, Ted Ralphs //
13 // All Rights Reserved. //
14 //===========================================================================//
15 
16 //===========================================================================//
17 #ifndef AlpsDecompNodeDesc_h_
18 #define AlpsDecompNodeDesc_h_
19 
20 //===========================================================================//
21 #include "AlpsEncoded.h"
22 #include "AlpsNodeDesc.h"
23 #include "AlpsDecompModel.h"
24 #include "UtilMacrosAlps.h"
25 
26 //===========================================================================//
27 class CoinWarmStartBasis;
28 
29 //===========================================================================//
53 //===========================================================================//
54 
55 //===========================================================================//
57 
58 private:
59 
60  //----------------------------------------------------------------------//
65  //----------------------------------------------------------------------//
66 
70  std::string m_classTag;
71 
72 public:
74  double* lowerBounds_;
76  double* upperBounds_;
82  std::vector< std::pair<int, double> > branched_;
83 
84  //THINK: different derivations for different algos? need?
87 
88 public:
89 
92  AlpsNodeDesc(),
93  branchedDir_(0),
94  basis_(NULL) {
95  }
96 
99  :
100  AlpsNodeDesc(m),
101  branchedDir_(0),
102  basis_(NULL) {
103  }
104 
106  const double* lb,
107  const double* ub)
108  :
109  AlpsNodeDesc(m),
110  branchedDir_(0),
111  basis_(NULL) {
113  assert(numberCols_);
114  lowerBounds_ = new double [numberCols_];
115  upperBounds_ = new double [numberCols_];
116  memcpy(lowerBounds_, lb, sizeof(double)*numberCols_);
117  memcpy(upperBounds_, ub, sizeof(double)*numberCols_);
118  }
119 
122  if (lowerBounds_ != 0) {
123  delete [] lowerBounds_;
124  lowerBounds_ = 0;
125  }
126 
127  if (upperBounds_ != 0) {
128  delete [] upperBounds_;
129  upperBounds_ = 0;
130  }
131 
132  delete basis_;
133  }
134 
137  if (basis_) {
138  delete basis_;
139  }
140 
141  basis_ = ws;
142  ws = NULL;
143  }
144 
147  return basis_;
148  }
149 
151  void setBranchedDir(int d) {
152  branchedDir_ = d;
153  }
154 
156  int getBranchedDir() const {
157  return branchedDir_;
158  }
159 
161  void setBranched(std::vector< std::pair<int, double> > b) {
162  branched_ = b;
163  }
164 
166  std::vector< std::pair<int, double> > getBranched() const {
167  return branched_;
168  }
169 
170 protected:
171 
172  //---
173  //--- helper functions for encode/decode
174  //---
175 
179  encoded->writeRep(branchedDir_);
180  // Basis
181  int ava = 0;
182 
183  if (basis_) {
184  ava = 1;
185  encoded->writeRep(ava);
186  //should this be a util func or blis func?
187  //seems pretty standard, alps/coin util type stuff
189  } else {
190  encoded->writeRep(ava);
191  }
192 
193  return status;
194  }
195 
199  encoded.readRep(branchedDir_);
200  // Basis
201  int ava;
202  encoded.readRep(ava);
203 
204  if (ava == 1) {
205  basis_ = UtilAlpsDecodeWarmStart(encoded, &status);
206  } else {
207  basis_ = NULL;
208  }
209 
210  return status;
211  }
212 
213 public:
214 
215  //---
216  //--- pure virtual functions from AlpsNodeDesc or AlpsNodeDesc
217  //---
218 
220  virtual AlpsReturnStatus encode(AlpsEncoded* encoded) const {
222  status = encodeAlpsDecomp(encoded);
223  return status;
224  }
225 
227  virtual AlpsReturnStatus decode(AlpsEncoded& encoded) {
229  status = decodeAlpsDecomp(encoded);
230  return status;
231  }
232 
233 };
234 #endif
Derivation of AlpsNodeDesc for DECOMP.
int numberCols_
number of columns in original space
void setBranchedDir(int d)
Set branching direction.
AlpsEncoded & readRep(T &value)
Read a single object of type &lt;code&gt;T&lt;/code&gt; from &lt;code&gt;repsentation_ .
Definition: AlpsEncoded.h:173
AlpsEncoded & writeRep(const T &value)
Write a single object of type &lt;code&gt;T&lt;/code&gt; in &lt;code&gt;repsentation_ .
Definition: AlpsEncoded.h:163
int getBranchedDir() const
Get branching direction.
AlpsDecompNodeDesc(AlpsModel *m)
Useful constructor.
AlpsReturnStatus
Definition: Alps.h:118
AlpsDecompNodeDesc(AlpsDecompModel *m, const double *lb, const double *ub)
Store the name of the class (for logging/debugging) - &quot;who am I?&quot;.
AlpsDecompNodeDesc()
Default constructor.
std::vector< std::pair< int, double > > branched_
Branched set of indices/values to create it.
void setBranched(std::vector< std::pair< int, double > > b)
Set branching set.
std::string m_classTag
Store the name of the class (for logging/debugging) - &quot;who am I?&quot;.
AlpsReturnStatus decodeAlpsDecomp(AlpsEncoded &encoded)
Unpack blis portion of node description from an encoded.
This data structure is to contain the packed form of an encodable knowledge.
Definition: AlpsEncoded.h:25
double * lowerBounds_
lower bounds in original space
virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const
Pack node description into an encoded.
Derivation of AlpsModel for DECOMP.
double * upperBounds_
upper bounds in original space
CoinWarmStartBasis * UtilAlpsDecodeWarmStart(AlpsEncoded &encoded, AlpsReturnStatus *rc)
Unpack coin warm start from an encoded object.
CoinWarmStartBasis * getBasis() const
Get warm start basis.
virtual AlpsReturnStatus decode(AlpsEncoded &encoded)
Unpack a node description from an encoded.
virtual ~AlpsDecompNodeDesc()
Destructor.
const int getNumCoreCols() const
Get number of cols in core decomp model.
CoinWarmStartBasis * basis_
Warm start.
std::vector< std::pair< int, double > > getBranched() const
Get branching set.
AlpsReturnStatus encodeAlpsDecomp(AlpsEncoded *encoded) const
Pack blis portion of node description into an encoded.
int UtilAlpsEncodeWarmStart(AlpsEncoded *encoded, const CoinWarmStartBasis *ws)
Pack coin warm start into an encoded object.
void setBasis(CoinWarmStartBasis *&ws)
Set basis.
A class to refer to the description of a search tree node.
Definition: AlpsNodeDesc.h:35
The default COIN simplex (basis-oriented) warm start class.
int branchedDir_
Branched direction to create it.