Debian Codegraph @

Bonmin/src/Interfaces/BonAuxInfos.cpp

raw
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 {
17 /** Default constructor.*/
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
29 /** Constructor from OsiBabSolver.*/
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
41 /** Copy constructor.*/
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
59 /** Destructor.*/
60 AuxInfo::~AuxInfo()
61 {
62 if (nlpSolution_ != NULL)
63 delete [] nlpSolution_;
64 }
65
66 /** Virtual copy constructor.*/
67 OsiAuxInfo *
68 AuxInfo::clone() const
69 {
70 return new AuxInfo(*this);
71 }
72
73 double AuxInfo::nlpObjValue ()
74 {return hasNlpSolution_ ? objValue_ : COIN_DBL_MAX;}
75
76 /** Pass a solution found by an nlp solver.*/
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