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  * Ted Ralphs, Lehigh University *
11  * *
12  * Conceptual Design: *
13  * *
14  * Yan Xu, Lehigh University *
15  * Ted Ralphs, Lehigh University *
16  * Laszlo Ladanyi, IBM T.J. Watson Research Center *
17  * Matthew Saltzman, Clemson University *
18  * *
19  * *
20  * Copyright (C) 2001-2013, Lehigh University, Yan Xu, and Ted Ralphs. *
21  *===========================================================================*/
22 
23 //#############################################################################
24 // This file is modified from SbbNode.hpp
25 //#############################################################################
26 
27 #ifndef AbcNodeDesc_h_
28 #define AbcNodeDesc_h_
29 
30 #include "CoinHelperFunctions.hpp"
31 #include "CoinWarmStartBasis.hpp"
32 
33 #include "AlpsNodeDesc.h"
34 #include "AbcModel.h"
35 
36 class OsiSolverInterface;
37 
38 class OsiCuts;
39 class OsiRowCut;
40 class OsiRowCutDebugger;
41 
42 class AbcModel;
43 class AbcNode;
44 
45 //#############################################################################
46 
47 
48 class AbcNodeDesc : public AlpsNodeDesc {
49 
50  private:
51 
52  /* Here, we need to fill in what the node description will look
53  like. For now, we will not use differencing -- just explicitly
54  represent it. Probably this means that we will just store the
55  original problem data and a list of the variables that have been
56  fixed. */
57 
59  double* lowerBounds_;
61  double* upperBounds_;
62 
68 
71 
74 
77  public:
79  :
80  AlpsNodeDesc(0),
81  lowerBounds_(0),
82  upperBounds_(0),
83  numberRows_(0),
84  numberCols_(0),
85  branchedOn_(-8),
86  branchedOnVal_(0),
87  branchedDir_(1)
88  {
89  }
90 
92  :
93  AlpsNodeDesc(m),
94  lowerBounds_(0),
95  upperBounds_(0),
96  numberRows_(0),
97  numberCols_(0),
98  branchedOn_(-9),
99  branchedOnVal_(0),
100  branchedDir_(1)
101  {
102  }
103 
104  AbcNodeDesc(AbcModel* m, const double* lb, const double* ub)
105  :
106  AlpsNodeDesc(m),
107  branchedOn_(-10),
108  branchedOnVal_(0),
109  branchedDir_(1)
110  {
111  numberRows_ = m->solver()->getNumRows();
112  numberCols_ = m->solver()->getNumCols();
113  assert(numberRows_ && 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 
120  virtual ~AbcNodeDesc() {
121  if (lowerBounds_ != 0) {
122  delete [] lowerBounds_;
123  lowerBounds_ = 0;
124  }
125  if (upperBounds_ != 0) {
126  delete [] upperBounds_;
127  upperBounds_ = 0;
128  }
129  }
130 
131  double* lowerBounds()
132  {
133  if(lowerBounds_ == 0) {
134  assert(model_);
135  AbcModel* m = dynamic_cast<AbcModel*>(model_);
136  const int num = m->getNumCols();
137  const double* lb = m->getColLower();
138  lowerBounds_ = new double [num];
139  memcpy(lowerBounds_, lb, sizeof(double)*num);
140 // std::cout << "AbcNodeDesc::lowerBounds--num=" << num
141 // <<std::endl;
142  }
143  return lowerBounds_;
144  }
145 
146  void setLowerBounds(const double* lb, const int size)
147  {
148  if(!lowerBounds_) {
149  lowerBounds_ = new double [size];
150  }
151  CoinCopyN(lb, size, lowerBounds_);
152  }
153 
154  void setLowerBound(const int index, const double lb)
155  {
156  if(!lowerBounds_) {
157  AbcModel * model = dynamic_cast<AbcModel*>(model_);
158  const int numCols = model->getNumCols();
159  assert(numCols > index);
160  lowerBounds_ = new double [numCols];
161  }
162 
163  lowerBounds_[index] = lb;
164  }
165 
166  double* upperBounds()
167  {
168  if(upperBounds_ == 0) {
169  assert(model_);
170  AbcModel* m = dynamic_cast<AbcModel*>(model_);
171  const int num = m->getNumCols();
172  const double* ub = m->getColUpper();
173  upperBounds_ = new double [num];
174  memcpy(upperBounds_, ub, sizeof(double)*num);
175  }
176  return upperBounds_;
177  }
178 
179  void setUpperBounds(const double* ub, const int size)
180  {
181  if(!upperBounds_) {
182  upperBounds_ = new double [size];
183  }
184  CoinCopyN(ub, size, upperBounds_);
185  }
186 
187  void setUpperBound(const int index, const double ub)
188  {
189  if (!upperBounds_) {
190  AbcModel * model = dynamic_cast<AbcModel*>(model_);
191  const int numCols = model->getNumCols();
192  assert(numCols > index);
193  upperBounds_ = new double [numCols];
194  }
195 
196  upperBounds_[index] = ub;
197  }
199  void setBranchedOn(int b) { branchedOn_ = b; }
201  void setBranchedDir(int d) { branchedDir_ = d; }
203  void setBranchedOnValue(double b) { branchedOnVal_ = b; }
205  int getBranchedOn() const { return branchedOn_; }
207  int getBranchedDir() const { return branchedDir_; }
209  double getBranchedOnValue() const { return branchedOnVal_; }
210 };
211 
212 #endif
double * upperBounds()
Definition: AbcNodeDesc.h:166
void setBranchedDir(int d)
Definition: AbcNodeDesc.h:201
void setLowerBounds(const double *lb, const int size)
Definition: AbcNodeDesc.h:146
int getNumCols() const
Get number of columns.
Definition: AbcModel.h:501
void setUpperBounds(const double *ub, const int size)
Definition: AbcNodeDesc.h:179
void setBranchedOnValue(double b)
Definition: AbcNodeDesc.h:203
Row Cut Class.
Definition: OsiRowCut.hpp:29
double branchedOnVal_
The solution value (non-integral) of the branching variable.
Definition: AbcNodeDesc.h:73
AbcNodeDesc(AbcModel *m, const double *lb, const double *ub)
Definition: AbcNodeDesc.h:104
virtual int getNumCols() const =0
Get the number of columns.
const double * getColLower() const
Get pointer to array[getNumCols()] of column lower bounds.
Definition: AbcModel.h:513
Collections of row cuts and column cuts.
Definition: OsiCuts.hpp:19
int numberRows_
Number of rows in problem (before these cuts).
Definition: AbcNodeDesc.h:65
void CoinCopyN(register const T *from, const int size, register T *to)
This helper function copies an array to another location using Duff&#39;s device (for a speedup of ~2)...
AbcNodeDesc(AbcModel *m)
Definition: AbcNodeDesc.h:91
virtual ~AbcNodeDesc()
Definition: AbcNodeDesc.h:120
void setBranchedOn(int b)
Definition: AbcNodeDesc.h:199
virtual int getNumRows() const =0
Get the number of rows.
int getBranchedOn() const
Definition: AbcNodeDesc.h:205
double * upperBounds_
Definition: AbcNodeDesc.h:61
double * lowerBounds()
Definition: AbcNodeDesc.h:131
int branchedOn_
The index of the branching variable.
Definition: AbcNodeDesc.h:70
int branchedDir_
Branching direction.
Definition: AbcNodeDesc.h:76
Abstract Base Class for describing an interface to a solver.
OsiSolverInterface * solver() const
Returns solver - has current state.
Definition: AbcModel.h:398
const double * getColUpper() const
Get pointer to array[getNumCols()] of column upper bounds.
Definition: AbcModel.h:517
void setUpperBound(const int index, const double ub)
Definition: AbcNodeDesc.h:187
AlpsModel * model_
A pointer to model.
Definition: AlpsNodeDesc.h:41
Validate cuts against a known solution.
int numberCols_
Definition: AbcNodeDesc.h:67
double * lowerBounds_
Definition: AbcNodeDesc.h:59
int getBranchedDir() const
Definition: AbcNodeDesc.h:207
void setLowerBound(const int index, const double lb)
Definition: AbcNodeDesc.h:154
A class to refer to the description of a search tree node.
Definition: AlpsNodeDesc.h:35
Model class for ALPS Branch and Cut.
Definition: AbcModel.h:55
double getBranchedOnValue() const
Definition: AbcNodeDesc.h:209