1 // (C) Copyright CNRS
2 // This code is published under the Eclipse Public License.
3 //
4 // Authors :
5 // Pierre Bonami, LIF Université de la Méditérannée-CNRS
6 //
7 // Date : 02/18/2009
8 
9 #include "BonPumpForMinlp.hpp"
10 #include "CbcModel.hpp"
11 #include "OsiBranchingObject.hpp"
12 
13 namespace Bonmin {
14 
15   /** Default constructor*/
PumpForMinlp()16   PumpForMinlp::PumpForMinlp():
17     LocalSolverBasedHeuristic(){
18   }
19   /** Constructor with setup.*/
PumpForMinlp(BonminSetup * setup)20   PumpForMinlp::PumpForMinlp(BonminSetup * setup):
21     LocalSolverBasedHeuristic(setup){
22     setupDefaults(setup->options());
23   }
24 
25   /** Copy constructor.*/
PumpForMinlp(const PumpForMinlp & other)26   PumpForMinlp::PumpForMinlp
27              (const PumpForMinlp &other):
28     LocalSolverBasedHeuristic(other){
29   }
30 
~PumpForMinlp()31   PumpForMinlp::~PumpForMinlp(){
32   }
33 
34   /** Runs heuristic*/
35   int
solution(double & objectiveValue,double * newSolution)36   PumpForMinlp::solution(double & objectiveValue,
37                                  double * newSolution){
38     if(model_->getNodeCount() || model_->getCurrentPassNumber() > 1) return 0;
39     if(model_->getSolutionCount()) return 0;
40     //int numberObjects = model_->numberObjects();
41     //OsiObject ** objects = model_->objects();
42     OsiTMINLPInterface * nlp = dynamic_cast<OsiTMINLPInterface *>
43                                (setup_->nonlinearSolver()->clone());
44 
45     OsiBranchingInformation info = model_->usefulInformation();
46 
47     double cutoff = info.cutoff_;
48     int r_val = doLocalSearch(nlp, newSolution, objectiveValue, cutoff, "pump_for_minlp.");
49     return r_val;
50   }
51 
52    void
setupDefaults(Ipopt::SmartPtr<Ipopt::OptionsList> options)53    PumpForMinlp::setupDefaults(Ipopt::SmartPtr<Ipopt::OptionsList> options){
54      //int dummy;
55      std::string prefix = "pump_for_minlp.";
56      changeIfNotSet(options, prefix, "algorithm", "B-iFP");
57      changeIfNotSet(options, prefix, "time_limit", 30.);
58    }
59 
60 
61   void
registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions)62   PumpForMinlp::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions){
63    roptions->SetRegisteringCategory("Primal Heuristics", RegisteredOptions::BonminCategory);
64    roptions->AddStringOption2(
65      "pump_for_minlp",
66      "whether to run the feasibility pump heuristic for MINLP",
67      "no",
68      "no", "",
69      "yes", "",
70      "");
71     roptions->setOptionExtraInfo("pump_for_minlp", 63);
72   }
73 
74    /** Initiaize using passed options.*/
75    void
Initialize(Ipopt::SmartPtr<Ipopt::OptionsList> options)76    PumpForMinlp::Initialize(Ipopt::SmartPtr<Ipopt::OptionsList> options){
77    }
78 }/* ends bonmin namespace*/
79 
80