00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "BonInitHeuristic.hpp"
00012 #include "CoinHelperFunctions.hpp"
00013 #include "CouenneRecordBestSol.hpp"
00014
00015 using namespace Couenne;
00016
00017 InitHeuristic::InitHeuristic (double objValue, const double* sol,
00018 CouenneProblem& cp):
00019 CbcHeuristic(),
00020 objValue_(COIN_DBL_MAX),
00021 sol_(NULL)
00022 {
00023 when_ = 1;
00024
00025 setHeuristicName("InitHeuristic");
00026 nVars_ = cp.nVars();
00027
00028 if (cp.checkNLP0 (sol, objValue, true, false, true, true)) {
00029
00030
00031
00032
00033
00034
00035
00036 sol_ = new double [nVars_];
00037
00038 #ifdef FM_CHECKNLP2
00039 CouenneRecordBestSol *rs = cp.getRecordBestSol();
00040 objValue_ = rs->getModSolVal();
00041 CoinCopyN (rs->getModSol(nVars_), nVars_, sol_);
00042 #else
00043 objValue_ = objValue;
00044 CoinCopyN (sol, cp.nOrigVars (), sol_);
00045 cp.getAuxs(sol_);
00046 #endif
00047 }
00048 }
00049
00050 InitHeuristic::InitHeuristic(const InitHeuristic & other)
00051 :
00052 CbcHeuristic(other),
00053 objValue_(other.objValue_),
00054 nVars_(other.nVars_)
00055 {
00056 if (other.sol_) {
00057 sol_ = new double[nVars_];
00058 CoinCopyN(other.sol_, nVars_, sol_);
00059 }
00060 else {
00061 sol_ = NULL;
00062 }
00063 }
00064
00065 CbcHeuristic *
00066 InitHeuristic::clone() const{
00067 return new InitHeuristic(*this);
00068 }
00069
00070 InitHeuristic &
00071 InitHeuristic::operator=(const InitHeuristic & rhs){
00072 if(this != &rhs){
00073 CbcHeuristic::operator=(rhs);
00074 objValue_ = rhs.objValue_;
00075 nVars_ = rhs.nVars_;
00076 if (sol_) {
00077 delete [] sol_;
00078 sol_ = NULL;
00079 }
00080
00081 if (rhs.sol_) {
00082 sol_ = new double[nVars_];
00083 CoinCopyN(rhs.sol_, nVars_, sol_);
00084 }
00085 }
00086 return *this;
00087 }
00088
00089 InitHeuristic::~InitHeuristic(){
00090 if(sol_)
00091 delete [] sol_;
00092 }
00093
00094 int
00095 InitHeuristic::solution(double & objectiveValue, double * newSolution){
00096
00097 if (!sol_) return 0;
00098
00099 int retval = 0;
00100 if (objValue_ < objectiveValue) {
00101 CoinCopyN(sol_, nVars_, newSolution);
00102 objectiveValue = objValue_;
00103 retval = 1;
00104 }
00105 delete [] sol_;
00106 sol_ = NULL;
00107
00108 return retval;
00109 }
00110