BonInitHeuristic.cpp
Go to the documentation of this file.
1 /* $Id: BonInitHeuristic.cpp 886 2012-08-05 17:50:04Z pbelotti $ */
2 // (C) Copyright International Business Machines Corporation 2007
3 // All Rights Reserved.
4 // This code is published under the Eclipse Public License (EPL).
5 //
6 // Authors :
7 // Andreas Waechter, International Business Machines Corporation
8 //
9 // Date : 12/07/2007
10 
11 #include "BonInitHeuristic.hpp"
12 #include "CoinHelperFunctions.hpp"
13 #include "CouenneRecordBestSol.hpp"
14 
15 using namespace Couenne;
16 
17 InitHeuristic::InitHeuristic (double objValue, const double* sol,
18  CouenneProblem& cp):
19  CbcHeuristic(),
20  objValue_(COIN_DBL_MAX),
21  sol_(NULL)
22 {
23  when_ = 1; // to be run at root
24 
25  setHeuristicName("InitHeuristic");
26  nVars_ = cp.nVars();
27 
28  if (cp.checkNLP0 (sol, objValue, true, false, true, true)) {
29 
30 // #ifdef FM_CHECKNLP2
31 // (cp.checkNLP2(sol, 0, false, true, true, cp.getFeasTol()))
32 // #else
33 // (cp.checkNLP (sol, objValue, true)) // true for recomputing objValue
34 // #endif
35 
36  sol_ = new double [nVars_];
37 
38 #ifdef FM_CHECKNLP2
40  objValue_ = rs->getModSolVal();
41  CoinCopyN (rs->getModSol(nVars_), nVars_, sol_);
42 #else
43  objValue_ = objValue;
44  CoinCopyN (sol, cp.nOrigVars (), sol_);
45  cp.getAuxs(sol_);
46 #endif
47  }
48 }
49 
51  :
52  CbcHeuristic(other),
53  objValue_(other.objValue_),
54  nVars_(other.nVars_)
55 {
56  if (other.sol_) {
57  sol_ = new double[nVars_];
58  CoinCopyN(other.sol_, nVars_, sol_);
59  }
60  else {
61  sol_ = NULL;
62  }
63 }
64 
65 CbcHeuristic *
67  return new InitHeuristic(*this);
68 }
69 
72  if(this != &rhs){
73  CbcHeuristic::operator=(rhs);
74  objValue_ = rhs.objValue_;
75  nVars_ = rhs.nVars_;
76  if (sol_) {
77  delete [] sol_;
78  sol_ = NULL;
79  }
80 
81  if (rhs.sol_) {
82  sol_ = new double[nVars_];
83  CoinCopyN(rhs.sol_, nVars_, sol_);
84  }
85  }
86  return *this;
87 }
88 
90  if(sol_)
91  delete [] sol_;
92 }
93 
94 int
95 InitHeuristic::solution(double & objectiveValue, double * newSolution){
96 
97  if (!sol_) return 0;
98 
99  int retval = 0;
100  if (objValue_ < objectiveValue) {
101  CoinCopyN(sol_, nVars_, newSolution);
102  objectiveValue = objValue_;
103  retval = 1;
104  }
105  delete [] sol_;
106  sol_ = NULL;
107 
108  return retval;
109 }
110 
int nVars() const
Total number of variables.
virtual ~InitHeuristic()
Destructor.
bool checkNLP0(const double *solution, double &obj, bool recompute_obj=false, const bool careAboutObj=false, const bool stopAtFirstViol=true, const bool checkAll=false, const double precision=-1) const
And finally a method to get both.
Definition: checkNLP.cpp:959
A heuristic that stores the initial solution of the NLP.
InitHeuristic & operator=(const InitHeuristic &rhs)
Assignment operator.
void getAuxs(CouNumber *) const
Get auxiliary variables from original variables.
Definition: problem.cpp:162
int nVars_
Size of array sol.
virtual int solution(double &objectiveValue, double *newSolution)
Run heuristic, return 1 if a better solution than the one passed is found and 0 otherwise.
CouenneRecordBestSol * getRecordBestSol() const
returns recorded best solution
Class for MINLP problems with symbolic information.
virtual CbcHeuristic * clone() const
Clone.
int nOrigVars() const
Number of orig. variables.
InitHeuristic()
Default constructor.
double * sol_
point from initial solve
double objValue_
objective function value from initial solve
double * getModSol(const int expectedCard)