/home/coin/SVN-release/OS-2.4.1/Bonmin/src/CbcBonmin/Heuristics/BonHeuristicLocalBranching.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 "BonHeuristicLocalBranching.hpp"
00012 #include "CbcModel.hpp"
00013 #include "OsiBranchingObject.hpp"
00014 
00015 namespace Bonmin {
00016 
00018   HeuristicLocalBranching::HeuristicLocalBranching():
00019     LocalSolverBasedHeuristic(),
00020     howOften_(100),
00021     numberSolutions_(0)
00022   {}
00024   HeuristicLocalBranching::HeuristicLocalBranching(BonminSetup * setup):
00025     LocalSolverBasedHeuristic(setup),
00026     howOften_(100),
00027     numberSolutions_(0)
00028   {}
00029 
00031   HeuristicLocalBranching::HeuristicLocalBranching
00032   (const HeuristicLocalBranching &other):
00033     LocalSolverBasedHeuristic(other),
00034     howOften_(other.howOften_),
00035     numberSolutions_(other.numberSolutions_)
00036   {}
00037 
00038   HeuristicLocalBranching::~HeuristicLocalBranching(){
00039   }
00040 
00041   void 
00042   HeuristicLocalBranching::setModel(CbcModel * model)
00043   {
00044     model_=model;
00045     //  assert(model_->solver());
00046     validate();
00047   }
00048 
00049   void
00050   HeuristicLocalBranching::validate()
00051   {
00052     assert(setup_ != NULL);
00053     OsiTMINLPInterface * nlp = dynamic_cast<OsiTMINLPInterface *>
00054       (setup_->nonlinearSolver());
00055     TMINLP2TNLP* minlp = nlp->problem();
00056     int numberColumns;
00057     int numberRows;
00058     int nnz_jac_g;
00059     int nnz_h_lag;
00060     Ipopt::TNLP::IndexStyleEnum index_style;
00061     minlp->get_nlp_info(numberColumns, numberRows, nnz_jac_g,
00062                         nnz_h_lag, index_style);
00063     const Bonmin::TMINLP::VariableType* variableType = minlp->var_types();
00064     const double* x_l = minlp->x_l();
00065     const double* x_u = minlp->x_u();
00066 
00067     for(int i=0; i<numberColumns; i++) {
00068       if ((variableType[i] != Bonmin::TMINLP::CONTINUOUS) &&
00069           (x_l[i] != 0.0 || x_u[i] != 1.0)) {
00070         setWhen(0);
00071         return;
00072       }
00073     }
00074   }
00075 
00077   int
00078   HeuristicLocalBranching::solution(double & objectiveValue,
00079                           double * newSolution)
00080   {
00081     //    if(!when() || model_->getNodeCount() || model_->getCurrentPassNumber() > 1) return 0;
00082     if (numberSolutions_>=model_->getSolutionCount())
00083       return 0;
00084     else
00085       numberSolutions_=model_->getSolutionCount();
00086 
00087     const double * bestSolution = model_->bestSolution();
00088     if (!bestSolution)
00089       return 0; // No solution found yet
00090 
00091     OsiTMINLPInterface * nlp = dynamic_cast<OsiTMINLPInterface *>
00092                                (setup_->nonlinearSolver()->clone());
00093 
00094 
00095     int numberIntegers = model_->numberIntegers();
00096     const int * integerVariable = model_->integerVariable();
00097 
00098     double* vals = new double[numberIntegers];
00099     int* inds = new int[numberIntegers];
00100 
00101     for (int i=0; i<numberIntegers; i++) {
00102       int iColumn = integerVariable[i];
00103       vals[i] = bestSolution[iColumn];
00104       inds[i] = iColumn;
00105     }
00106 
00107     double rhs_local_branching_constraint = numberIntegers / 2; //stefan: this should be the same as floor(numInt/2) since numInt and 2 are int's
00108     nlp->switchToFeasibilityProblem(numberIntegers, vals, inds, rhs_local_branching_constraint);
00109 
00110     int r_val = 0;
00111     r_val = doLocalSearch(nlp, newSolution, objectiveValue, model_->getCutoff());
00112 
00113     delete [] vals;
00114     delete [] inds;
00115 
00116     if(r_val > 0) numberSolutions_ = model_->getSolutionCount() + 1;
00117 
00118     return r_val;
00119   }
00120 
00121   void
00122   HeuristicLocalBranching::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions){
00123    roptions->SetRegisteringCategory("Undocumented MINLP Heuristics", RegisteredOptions::UndocumentedCategory);
00124    roptions->AddStringOption2(
00125      "heuristic_local_branching",
00126      "if yes runs the LocalBranching heuristic",
00127      "no",
00128      "no", "don't run it",
00129      "yes", "runs the heuristic",
00130      "");
00131     roptions->setOptionExtraInfo("heuristic_local_branching", 63);
00132   }
00133 
00135    void 
00136    HeuristicLocalBranching::Initialize(Ipopt::SmartPtr<Ipopt::OptionsList> options){
00137    }
00138 }/* ends bonmin namespace*/

Generated on Thu Nov 10 03:05:41 2011 by  doxygen 1.4.7