/home/coin/SVN-release/OS-2.4.2/Bonmin/src/CbcBonmin/Heuristics/BonHeuristicRINS.cpp

Go to the documentation of this file.
00001 // (C) Copyright CNRS and International Business Machines Corporation
00002 // All Rights Reserved.
00003 // This code is published under the Common Public License.
00004 //
00005 // Authors :
00006 // Pierre Bonami, LIF Université de la Méditérannée-CNRS
00007 // Joao Goncalves, International Business Machines Corporation
00008 //
00009 // Date : 06/18/2008
00010 
00011 #include "BonHeuristicRINS.hpp"
00012 #include "CbcModel.hpp"
00013 #include "OsiBranchingObject.hpp"
00014 
00015 //#define DEBUG_BON_HEURISTIC_RINS
00016 
00017 namespace Bonmin {
00018 
00020   HeuristicRINS::HeuristicRINS():
00021     LocalSolverBasedHeuristic(),
00022     howOften_(10),
00023     numberSolutions_(0)
00024   {}
00026   HeuristicRINS::HeuristicRINS(BonminSetup * setup):
00027     LocalSolverBasedHeuristic(setup),
00028     howOften_(10),
00029     numberSolutions_(0){
00030   }
00031 
00033   HeuristicRINS::HeuristicRINS
00034   (const HeuristicRINS &other):
00035     LocalSolverBasedHeuristic(other),
00036     howOften_(other.howOften_),
00037     numberSolutions_(other.numberSolutions_)
00038   {}
00039 
00040   HeuristicRINS::~HeuristicRINS(){
00041   }
00042 
00044   int
00045   HeuristicRINS::solution(double & objectiveValue,
00046                           double * newSolution)
00047   {
00048     if(!howOften_ || model_->getNodeCount() % howOften_ != 0) return 0;
00049     numberSolutions_=model_->getSolutionCount();
00050 
00051     const double * bestSolution = model_->bestSolution();
00052     if (!bestSolution){
00053 #ifdef DEBUG_BON_HEURISTIC_RINS
00054     std::cout<<"exited RINS b"<<std::endl;
00055 #endif
00056       return 0; // No solution found yet
00057     }
00058     OsiTMINLPInterface * nlp = dynamic_cast<OsiTMINLPInterface *>
00059                                (model_->solver());
00060     if(nlp == NULL){
00061        nlp = dynamic_cast<OsiTMINLPInterface *>
00062                          (setup_->nonlinearSolver()->clone());
00063      }
00064      else {
00065        nlp = dynamic_cast<OsiTMINLPInterface *>(nlp->clone());
00066     }
00067 
00068     int numberIntegers = model_->numberIntegers();
00069     const int * integerVariable = model_->integerVariable();
00070 
00071     const double * currentSolution = model_->getColSolution();
00072 
00073     double primalTolerance;
00074     nlp->getDblParam(OsiPrimalTolerance,primalTolerance);
00075 
00076     int nFix=0;
00077     for (int i=0; i<numberIntegers; i++) {
00078       int iColumn=integerVariable[i];
00079       const OsiObject * object = model_->object(i);
00080       // get original bounds
00081       double originalLower;
00082       double originalUpper;
00083       getIntegerInformation(object, originalLower, originalUpper); 
00084       double valueInt=bestSolution[iColumn];
00085       if (valueInt<originalLower) {
00086         valueInt=originalLower;
00087       } else if (valueInt>originalUpper) {
00088         valueInt=originalUpper;
00089       }
00090       if (fabs(currentSolution[iColumn]-valueInt)<10.0*primalTolerance) {
00091         double nearest=floor(valueInt+0.5);
00092         nlp->setColLower(iColumn,nearest);
00093         nlp->setColUpper(iColumn,nearest);
00094         nFix++;
00095       }
00096     }
00097 
00098     int r_val = 0;
00099     if(nFix > numberIntegers/10) {
00100 #ifdef DEBUG_BON_HEURISTIC_RINS
00101       std::cout<<"cutoff = "<<model_->getCutoff()<<std::endl;
00102 #endif
00103       r_val = doLocalSearch(nlp, newSolution, objectiveValue, model_->getCutoff(), "rins.");
00104 #ifdef DEBUG_BON_HEURISTIC_RINS
00105       std::cout<<"executed RINS "<<r_val<<std::endl;
00106 #endif
00107     }
00108     else {numberSolutions_ --;}
00109 
00110     if(r_val > 0) {
00111       numberSolutions_ = model_->getSolutionCount() + 1;
00112       howOften_ = std::max(10, howOften_ / 2);
00113     }
00114     else
00115       howOften_ = std::min(10000,2*howOften_);
00116     return r_val;
00117   }
00118 
00119   void
00120   HeuristicRINS::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions){
00121    roptions->SetRegisteringCategory("MINLP Heuristics", RegisteredOptions::BonminCategory);
00122    roptions->AddStringOption2(
00123      "heuristic_RINS",
00124      "if yes runs the RINS heuristic",
00125      "no",
00126      "no", "don't run it",
00127      "yes", "runs the heuristic",
00128      "");
00129     roptions->setOptionExtraInfo("heuristic_RINS", 63);
00130   }
00131 
00133    void 
00134    HeuristicRINS::Initialize(Ipopt::SmartPtr<Ipopt::OptionsList> options){
00135    }
00136 }/* ends bonmin namespace*/

Generated on Wed Nov 30 03:03:54 2011 by  doxygen 1.4.7