Dip  0.95.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 // Authors: Matthew Galati, SAS Institute Inc. (matthew.galati@sas.com) //
8 // Ted Ralphs, Lehigh University (ted@lehigh.edu) //
9 // Jiadong Wang, Lehigh University (jiw408@lehigh.edu) //
10 // //
11 // Copyright (C) 2002-2019, Lehigh University, Matthew Galati, Ted Ralphs //
12 // All Rights Reserved. //
13 //===========================================================================//
14 
15 //===========================================================================//
16 #ifndef AlpsDecompNodeDesc_h_
17 #define AlpsDecompNodeDesc_h_
18 
19 //===========================================================================//
20 #include "AlpsEncoded.h"
21 #include "AlpsNodeDesc.h"
22 #include "AlpsDecompModel.h"
23 #include "UtilMacrosAlps.h"
24 
25 //===========================================================================//
26 class CoinWarmStartBasis;
27 
28 //===========================================================================//
52 //===========================================================================//
53 
54 //===========================================================================//
56 
57 private:
58 
59  //----------------------------------------------------------------------//
64  //----------------------------------------------------------------------//
65 
69  std::string m_classTag;
70 
71 public:
73  double* lowerBounds_;
75  double* upperBounds_;
81  std::vector< std::pair<int, double> > branched_;
82 
83  //THINK: different derivations for different algos? need?
86 
87 public:
88 
91  AlpsNodeDesc(),
92  branchedDir_(0),
93  basis_(NULL) {
94  }
95 
98  :
99  AlpsNodeDesc(m),
100  branchedDir_(0),
101  basis_(NULL) {
102  }
103 
105  const double* lb,
106  const double* ub)
107  :
108  AlpsNodeDesc(m),
109  branchedDir_(0),
110  basis_(NULL) {
112  assert(numberCols_);
113  lowerBounds_ = new double [numberCols_];
114  upperBounds_ = new double [numberCols_];
115  memcpy(lowerBounds_, lb, sizeof(double)*numberCols_);
116  memcpy(upperBounds_, ub, sizeof(double)*numberCols_);
117  }
118 
121  if (lowerBounds_ != 0) {
122  delete [] lowerBounds_;
123  lowerBounds_ = 0;
124  }
125 
126  if (upperBounds_ != 0) {
127  delete [] upperBounds_;
128  upperBounds_ = 0;
129  }
130 
131  delete basis_;
132  }
133 
136  if (basis_) {
137  delete basis_;
138  }
139 
140  basis_ = ws;
141  ws = NULL;
142  }
143 
146  return basis_;
147  }
148 
150  void setBranchedDir(int d) {
151  branchedDir_ = d;
152  }
153 
155  int getBranchedDir() const {
156  return branchedDir_;
157  }
158 
160  void setBranched(std::vector< std::pair<int, double> > b) {
161  branched_ = b;
162  }
163 
165  std::vector< std::pair<int, double> > getBranched() const {
166  return branched_;
167  }
168 
169 protected:
170 
171  //---
172  //--- helper functions for encode/decode
173  //---
174 
178  encoded->writeRep(branchedDir_);
179  // Basis
180  int ava = 0;
181 
182  if (basis_) {
183  ava = 1;
184  encoded->writeRep(ava);
185  //should this be a util func or blis func?
186  //seems pretty standard, alps/coin util type stuff
188  } else {
189  encoded->writeRep(ava);
190  }
191 
192  return status;
193  }
194 
198  encoded.readRep(branchedDir_);
199  // Basis
200  int ava;
201  encoded.readRep(ava);
202 
203  if (ava == 1) {
204  basis_ = UtilAlpsDecodeWarmStart(encoded, &status);
205  } else {
206  basis_ = NULL;
207  }
208 
209  return status;
210  }
211 
212 public:
213 
214  //---
215  //--- pure virtual functions from AlpsNodeDesc or AlpsNodeDesc
216  //---
217 
219  virtual AlpsReturnStatus encode(AlpsEncoded* encoded) const {
221  status = encodeAlpsDecomp(encoded);
222  return status;
223  }
224 
226  virtual AlpsReturnStatus decode(AlpsEncoded& encoded) {
228  status = decodeAlpsDecomp(encoded);
229  return status;
230  }
231 
232 };
233 #endif
AlpsReturnStatus
AlpsReturnStatusOk
CoinWarmStartBasis * UtilAlpsDecodeWarmStart(AlpsEncoded &encoded, AlpsReturnStatus *rc)
Unpack coin warm start from an encoded object.
int UtilAlpsEncodeWarmStart(AlpsEncoded *encoded, const CoinWarmStartBasis *ws)
Pack coin warm start into an encoded object.
Derivation of AlpsModel for DECOMP.
const int getNumCoreCols() const
Get number of cols in core decomp model.
Derivation of AlpsNodeDesc for DECOMP.
double * lowerBounds_
lower bounds in original space
double * upperBounds_
upper bounds in original space
virtual ~AlpsDecompNodeDesc()
Destructor.
std::vector< std::pair< int, double > > getBranched() const
Get branching set.
int branchedDir_
Branched direction to create it.
virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const
Pack node description into an encoded.
virtual AlpsReturnStatus decode(AlpsEncoded &encoded)
Unpack a node description from an encoded.
CoinWarmStartBasis * basis_
Warm start.
CoinWarmStartBasis * getBasis() const
Get warm start basis.
AlpsDecompNodeDesc(AlpsDecompModel *m, const double *lb, const double *ub)
AlpsDecompNodeDesc(AlpsModel *m)
Useful constructor.
void setBranchedDir(int d)
Set branching direction.
int numberCols_
number of columns in original space
AlpsDecompNodeDesc()
Default constructor.
std::vector< std::pair< int, double > > branched_
Branched set of indices/values to create it.
int getBranchedDir() const
Get branching direction.
void setBranched(std::vector< std::pair< int, double > > b)
Set branching set.
void setBasis(CoinWarmStartBasis *&ws)
Set basis.
AlpsReturnStatus decodeAlpsDecomp(AlpsEncoded &encoded)
Unpack blis portion of node description from an encoded.
AlpsReturnStatus encodeAlpsDecomp(AlpsEncoded *encoded) const
Pack blis portion of node description into an encoded.
AlpsEncoded & readRep(T &value)
AlpsEncoded & writeRep(const T &value)