BonAuxInfos.cpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines Corporation 2007
2 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Pierre Bonami, International Business Machines Corporation
7 //
8 // Date : 04/23/2007
9 
10 #include "BonminConfig.h"
11 #include "BonAuxInfos.hpp"
12 #include "CoinHelperFunctions.hpp"
13 #include "CoinFinite.hpp"
14 
15 namespace Bonmin
16 {
18  AuxInfo::AuxInfo(int type):
19  OsiBabSolver(type),
20  infeasibleNode_(false),
21  objValue_ (COIN_DBL_MAX),
22  nlpSolution_(NULL),
23  numcols_(0),
24  hasNlpSolution_(false),
25  bestSolution2_(make_referenced(std::vector<double>())),
26  bestObj2_(make_referenced(COIN_DBL_MAX))
27  {}
28 
30  AuxInfo::AuxInfo(const OsiBabSolver &other):
31  OsiBabSolver(other),
32  infeasibleNode_(false),
33  objValue_ (COIN_DBL_MAX),
34  nlpSolution_(NULL),
35  numcols_(0),
36  hasNlpSolution_(false),
37  bestSolution2_(make_referenced(std::vector<double>())),
38  bestObj2_(make_referenced(COIN_DBL_MAX))
39  {}
40 
42  AuxInfo::AuxInfo(const AuxInfo &other):
43  OsiBabSolver(other),
44  infeasibleNode_(other.infeasibleNode_),
45  objValue_ (other.objValue_),
46  nlpSolution_(NULL),
47  numcols_(other.numcols_),
48  hasNlpSolution_(other.hasNlpSolution_),
49  bestSolution2_(other.bestSolution2_),
50  bestObj2_(other.bestObj2_)
51  {
52  if (other.nlpSolution_!=NULL) {
53  assert(numcols_ > 0);
54  nlpSolution_ = new double[numcols_ + 1];
55  CoinCopyN(other.nlpSolution_, numcols_+1, nlpSolution_);
56  }
57  }
58 
61  {
62  if (nlpSolution_ != NULL)
63  delete [] nlpSolution_;
64  }
65 
67  OsiAuxInfo *
69  {
70  return new AuxInfo(*this);
71  }
72 
74  {return hasNlpSolution_ ? objValue_ : COIN_DBL_MAX;}
75 
77  void
78  AuxInfo::setNlpSolution(const double * sol, int numcols, double objValue)
79  {
80  if (numcols_ < numcols) {
81  delete [] nlpSolution_;
82  nlpSolution_ = NULL;
83  }
84  if (nlpSolution_ == NULL) {
85  nlpSolution_ = new double[numcols + 1];
86  numcols_ = numcols;
87  }
88  CoinCopyN(sol, numcols, nlpSolution_);
89  nlpSolution_[numcols] = objValue;
90  objValue_ = objValue;
91  }
92 
93 }/* end namespace Bonmin*/
94 
double * nlpSolution_
nlp solution found by heuristic if any.
Definition: BonAuxInfos.hpp:97
A small wrap around std::vector to give easy access to array for interfacing with fortran code...
Definition: BonTypes.hpp:9
SimpleReferenced< X > * make_referenced(X other)
Definition: BonTypes.hpp:87
int numcols_
numcols_ gives the size of nlpSolution_.
Definition: BonAuxInfos.hpp:99
double objValue_
value of the objective function of this nlp solution
Definition: BonAuxInfos.hpp:95
bool hasNlpSolution_
say if has a solution.
void setNlpSolution(const double *sol, int numcols, double objValue)
Pass a solution found by an nlp solver.
Definition: BonAuxInfos.cpp:78
AuxInfo(int type)
Default constructor.
Definition: BonAuxInfos.cpp:18
double nlpObjValue()
Get objective value of nlp solution found, or +infinity if none exists.
Definition: BonAuxInfos.cpp:73
virtual ~AuxInfo()
Destructor.
Definition: BonAuxInfos.cpp:60
Bonmin class for passing info between components of branch-and-cuts.
Definition: BonAuxInfos.hpp:23
virtual OsiAuxInfo * clone() const
Virtual copy constructor.
Definition: BonAuxInfos.cpp:68