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
00029 #ifdef FM_CHECKNLP2
00030 (cp.checkNLP2(sol, 0, false, true, true, cp.getFeasTol()))
00031 #else
00032 (cp.checkNLP (sol, objValue, true))
00033 #endif
00034 {
00035 sol_ = new double [nVars_];
00036
00037 #ifdef FM_CHECKNLP2
00038 CouenneRecordBestSol *rs = cp.getRecordBestSol();
00039 objValue_ = rs->getModSolVal();
00040 CoinCopyN (rs->getModSol(nVars_), nVars_, sol_);
00041 #else
00042 objValue_ = objValue;
00043 CoinCopyN (sol, cp.nOrigVars (), sol_);
00044 cp.getAuxs(sol_);
00045 #endif
00046 }
00047 }
00048
00049 InitHeuristic::InitHeuristic(const InitHeuristic & other)
00050 :
00051 CbcHeuristic(other),
00052 objValue_(other.objValue_),
00053 nVars_(other.nVars_)
00054 {
00055 if (other.sol_) {
00056 sol_ = new double[nVars_];
00057 CoinCopyN(other.sol_, nVars_, sol_);
00058 }
00059 else {
00060 sol_ = NULL;
00061 }
00062 }
00063
00064 CbcHeuristic *
00065 InitHeuristic::clone() const{
00066 return new InitHeuristic(*this);
00067 }
00068
00069 InitHeuristic &
00070 InitHeuristic::operator=(const InitHeuristic & rhs){
00071 if(this != &rhs){
00072 CbcHeuristic::operator=(rhs);
00073 objValue_ = rhs.objValue_;
00074 nVars_ = rhs.nVars_;
00075 if (sol_) {
00076 delete [] sol_;
00077 sol_ = NULL;
00078 }
00079
00080 if (rhs.sol_) {
00081 sol_ = new double[nVars_];
00082 CoinCopyN(rhs.sol_, nVars_, sol_);
00083 }
00084 }
00085 return *this;
00086 }
00087
00088 InitHeuristic::~InitHeuristic(){
00089 if(sol_)
00090 delete [] sol_;
00091 }
00092
00093 int
00094 InitHeuristic::solution(double & objectiveValue, double * newSolution){
00095
00096 if (!sol_) return 0;
00097
00098 int retval = 0;
00099 if (objValue_ < objectiveValue) {
00100 CoinCopyN(sol_, nVars_, newSolution);
00101 objectiveValue = objValue_;
00102 retval = 1;
00103 }
00104 delete [] sol_;
00105 sol_ = NULL;
00106
00107 return retval;
00108 }
00109