Alps  2.0.2
AbcNodeDesc.h
Go to the documentation of this file.
1 /*===========================================================================*
2  * This file is part of the Abstract Library for Parallel Search (ALPS). *
3  * *
4  * ALPS is distributed under the Eclipse Public License as part of the *
5  * COIN-OR repository (http://www.coin-or.org). *
6  * *
7  * Authors: *
8  * *
9  * Yan Xu, Lehigh University *
10  * Aykut Bulut, Lehigh University *
11  * Ted Ralphs, Lehigh University *
12  * *
13  * Conceptual Design: *
14  * *
15  * Yan Xu, Lehigh University *
16  * Ted Ralphs, Lehigh University *
17  * Laszlo Ladanyi, IBM T.J. Watson Research Center *
18  * Matthew Saltzman, Clemson University *
19  * *
20  * *
21  * Copyright (C) 2001-2019, Lehigh University, Yan Xu, Aykut Bulut, and *
22  * Ted Ralphs. *
23  * All Rights Reserved. *
24  *===========================================================================*/
25 
26 
27 //#############################################################################
28 // This file is modified from SbbNode.hpp
29 //#############################################################################
30 
31 #ifndef AbcNodeDesc_h_
32 #define AbcNodeDesc_h_
33 
34 #include "CoinHelperFunctions.hpp"
35 #include "CoinWarmStartBasis.hpp"
36 
37 #include "AlpsNodeDesc.h"
38 #include "AbcModel.h"
39 
40 class OsiSolverInterface;
41 
42 class OsiCuts;
43 class OsiRowCut;
44 class OsiRowCutDebugger;
45 
46 class AbcModel;
47 class AbcNode;
48 
49 //#############################################################################
50 
51 
52 class AbcNodeDesc : public AlpsNodeDesc {
53 
54  private:
55 
56  /* Here, we need to fill in what the node description will look
57  like. For now, we will not use differencing -- just explicitly
58  represent it. Probably this means that we will just store the
59  original problem data and a list of the variables that have been
60  fixed. */
61 
63  double* lowerBounds_;
65  double* upperBounds_;
66 
72 
75 
78 
81  public:
83  :
84  AlpsNodeDesc(),
85  lowerBounds_(0),
86  upperBounds_(0),
87  numberRows_(0),
88  numberCols_(0),
89  branchedOn_(-8),
90  branchedOnVal_(0),
91  branchedDir_(1)
92  {
93  }
94 
95  virtual ~AbcNodeDesc() {
96  if (lowerBounds_ != 0) {
97  delete [] lowerBounds_;
98  lowerBounds_ = 0;
99  }
100  if (upperBounds_ != 0) {
101  delete [] upperBounds_;
102  upperBounds_ = 0;
103  }
104  }
105 
106  double* lowerBounds()
107  {
108  if(lowerBounds_ == 0) {
109  AbcModel * m = dynamic_cast<AbcModel*>(broker()->getModel());
110  const int num = m->getNumCols();
111  const double* lb = m->getColLower();
112  lowerBounds_ = new double [num];
113  memcpy(lowerBounds_, lb, sizeof(double)*num);
114 // std::cout << "AbcNodeDesc::lowerBounds--num=" << num
115 // <<std::endl;
116  }
117  return lowerBounds_;
118  }
119 
120  void setLowerBounds(const double* lb, const int size)
121  {
122  if(!lowerBounds_) {
123  lowerBounds_ = new double [size];
124  }
125  CoinCopyN(lb, size, lowerBounds_);
126  }
127 
128  void setLowerBound(const int index, const double lb)
129  {
130  if(!lowerBounds_) {
131  AbcModel * model = dynamic_cast<AbcModel*>(broker()->getModel());
132  const int numCols = model->getNumCols();
133  assert(numCols > index);
134  lowerBounds_ = new double [numCols];
135  }
136 
137  lowerBounds_[index] = lb;
138  }
139 
140  double* upperBounds()
141  {
142  if(upperBounds_ == 0) {
143  AbcModel* m = dynamic_cast<AbcModel*>(broker()->getModel());
144  const int num = m->getNumCols();
145  const double* ub = m->getColUpper();
146  upperBounds_ = new double [num];
147  memcpy(upperBounds_, ub, sizeof(double)*num);
148  }
149  return upperBounds_;
150  }
151 
152  void setUpperBounds(const double* ub, const int size)
153  {
154  if(!upperBounds_) {
155  upperBounds_ = new double [size];
156  }
157  CoinCopyN(ub, size, upperBounds_);
158  }
159 
160  void setUpperBound(const int index, const double ub)
161  {
162  if (!upperBounds_) {
163  AbcModel * model = dynamic_cast<AbcModel*>(broker()->getModel());
164  const int numCols = model->getNumCols();
165  assert(numCols > index);
166  upperBounds_ = new double [numCols];
167  }
168 
169  upperBounds_[index] = ub;
170  }
172  void setBranchedOn(int b) { branchedOn_ = b; }
174  void setBranchedDir(int d) { branchedDir_ = d; }
176  void setBranchedOnValue(double b) { branchedOnVal_ = b; }
178  int getBranchedOn() const { return branchedOn_; }
180  int getBranchedDir() const { return branchedDir_; }
182  double getBranchedOnValue() const { return branchedOnVal_; }
183 
184  virtual AlpsReturnStatus encode(AlpsEncoded * encoded) const {
185  std::cerr << "Not implemented!" << std::endl;
186  throw std::exception();
187  }
188 
190  std::cerr << "Not implemented!" << std::endl;
191  throw std::exception();
192  }
193 
194  virtual AlpsNodeDesc * decode(AlpsEncoded & encoded) const {
195  std::cerr << "Not implemented!" << std::endl;
196  throw std::exception();
197  }
198 
199 };
200 
201 #endif
AbcNodeDesc::encode
virtual AlpsReturnStatus encode(AlpsEncoded *encoded) const
Pack this node description into the given AlpsEncoded object.
Definition: AbcNodeDesc.h:184
AlpsReturnStatus
AlpsReturnStatus
Definition: Alps.h:261
AbcNodeDesc::upperBounds_
double * upperBounds_
Definition: AbcNodeDesc.h:65
AbcNodeDesc::upperBounds
double * upperBounds()
Definition: AbcNodeDesc.h:140
AbcModel::getColUpper
const double * getColUpper() const
Get pointer to array[getNumCols()] of column upper bounds.
Definition: AbcModel.h:521
AbcNodeDesc::branchedOn_
int branchedOn_
The index of the branching variable.
Definition: AbcNodeDesc.h:74
AbcNodeDesc::setUpperBounds
void setUpperBounds(const double *ub, const int size)
Definition: AbcNodeDesc.h:152
AbcNodeDesc::lowerBounds_
double * lowerBounds_
Definition: AbcNodeDesc.h:63
AlpsEncoded
Definition: AlpsEncoded.h:64
AbcNodeDesc::setBranchedOnValue
void setBranchedOnValue(double b)
Definition: AbcNodeDesc.h:176
AbcNodeDesc::setUpperBound
void setUpperBound(const int index, const double ub)
Definition: AbcNodeDesc.h:160
AbcModel::getColLower
const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
Definition: AbcModel.h:517
AlpsNodeDesc
This is an abstract base class for subproblem data to be stored in a tree node.
Definition: AlpsNodeDesc.h:45
AbcNodeDesc::branchedOnVal_
double branchedOnVal_
The solution value (non-integral) of the branching variable.
Definition: AbcNodeDesc.h:77
AlpsKnowledge::broker
AlpsKnowledgeBroker * broker()
Get pointer to the knowledge broker.
Definition: AlpsKnowledge.h:86
AbcNodeDesc::AbcNodeDesc
AbcNodeDesc()
Definition: AbcNodeDesc.h:82
AbcModel::getNumCols
int getNumCols() const
Get number of columns.
Definition: AbcModel.h:505
AbcNodeDesc::numberRows_
int numberRows_
Number of rows in problem (before these cuts).
Definition: AbcNodeDesc.h:69
AbcNodeDesc::setLowerBounds
void setLowerBounds(const double *lb, const int size)
Definition: AbcNodeDesc.h:120
AbcNodeDesc::getBranchedOnValue
double getBranchedOnValue() const
Definition: AbcNodeDesc.h:182
AlpsNodeDesc.h
AbcNodeDesc::setBranchedDir
void setBranchedDir(int d)
Definition: AbcNodeDesc.h:174
AbcNodeDesc
Definition: AbcNodeDesc.h:52
AbcNodeDesc::decode
virtual AlpsNodeDesc * decode(AlpsEncoded &encoded) const
Decode the given AlpsEncoded object into a new AlpsKnowledge object and return a pointer to it.
Definition: AbcNodeDesc.h:194
AbcNodeDesc::numberCols_
int numberCols_
Definition: AbcNodeDesc.h:71
AbcNodeDesc::~AbcNodeDesc
virtual ~AbcNodeDesc()
Definition: AbcNodeDesc.h:95
AbcModel
Model class for ALPS Branch and Cut.
Definition: AbcModel.h:59
AbcNodeDesc::getBranchedDir
int getBranchedDir() const
Definition: AbcNodeDesc.h:180
AbcModel.h
AbcNodeDesc::decodeToSelf
virtual AlpsReturnStatus decodeToSelf(AlpsEncoded &encoded)
Unpack fields from the given AlpsEncoded object.
Definition: AbcNodeDesc.h:189
AbcNodeDesc::lowerBounds
double * lowerBounds()
Definition: AbcNodeDesc.h:106
AbcNodeDesc::setBranchedOn
void setBranchedOn(int b)
Definition: AbcNodeDesc.h:172
AlpsKnowledgeBroker::getModel
AlpsModel * getModel()
Definition: AlpsKnowledgeBroker.h:245
AbcNodeDesc::branchedDir_
int branchedDir_
Branching direction.
Definition: AbcNodeDesc.h:80
AbcNodeDesc::setLowerBound
void setLowerBound(const int index, const double lb)
Definition: AbcNodeDesc.h:128
AbcNodeDesc::getBranchedOn
int getBranchedOn() const
Definition: AbcNodeDesc.h:178