/home/coin/SVN-release/OS-2.1.1/Couenne/src/main/BonInitHeuristic.cpp

Go to the documentation of this file.
00001 /* $Id: BonInitHeuristic.cpp 154 2009-06-16 18:52:53Z pbelotti $ */
00002 // (C) Copyright International Business Machines Corporation 2007 
00003 // All Rights Reserved.
00004 // This code is published under the Common Public License.
00005 //
00006 // Authors :
00007 // Andreas Waechter, International Business Machines Corporation
00008 //
00009 // Date : 12/07/2007
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; // to be run at root
00023 
00024     setHeuristicName("InitHeuristic");
00025     nVars_ = cp.nVars();
00026 
00027     if (cp.checkNLP (sol, objValue, true)) { // true for recomputing objValue
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 }

Generated on Mon May 3 03:05:21 2010 by  doxygen 1.4.7