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