/home/coin/SVN-release/OS-1.1.1/Bonmin/experimental/NotConvex/BonInitHeuristic.cpp

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

Generated on Tue Sep 30 03:01:22 2008 by  doxygen 1.4.7