BonLocalSolverBasedHeuristic.cpp
Go to the documentation of this file.
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 : 06/18/2008
8 
10 #include "BonCbc.hpp"
11 
12 namespace Bonmin {
14  CbcHeuristic(),
15  setup_(NULL),
16  time_limit_(60),
17  max_number_nodes_(1000),
18  max_number_solutions_(10){
19  }
21  CbcHeuristic(),
22  setup_(setup),
23  time_limit_(60),
24  max_number_nodes_(1000),
25  max_number_solutions_(10){
26  Initialize(setup->options());
27  }
28 
30  CbcHeuristic(other),
31  setup_(other.setup_),
32  time_limit_(other.time_limit_),
33  max_number_nodes_(other.max_number_nodes_),
34  max_number_solutions_(other.max_number_solutions_) {
35  }
36 
38  }
39 
42  if(this != &rhs){
43  CbcHeuristic::operator=(rhs);
44  setup_ = rhs.setup_;
45  }
46  return *this;
47  }
48 
49  void
51  std::string prefix,
52  const std::string &option,
53  const std::string &value){
54  int dummy;
55  if(!options->GetEnumValue(option,dummy,prefix))
56  options->SetStringValue(prefix + option, value, true, true);
57 
58  }
59  void
61  std::string prefix,
62  const std::string &option,
63  const double &value){
64  double dummy;
65  if(!options->GetNumericValue(option,dummy,prefix))
66  options->SetNumericValue(prefix + option, value, true, true);
67 
68  }
69  void
71  std::string prefix,
72  const std::string &option,
73  const int &value){
74  int dummy;
75  if(!options->GetIntegerValue(option,dummy,prefix))
76  options->SetIntegerValue(prefix + option, value, true, true);
77 
78  }
79 
80  void
82  std::string prefix = "local_solver.";
83  changeIfNotSet(options, prefix, "algorithm", "B-QG");
84  changeIfNotSet(options, prefix, "variable_selection", "most-fractional");
85  changeIfNotSet(options, prefix, "time_limit", 60.);
86  changeIfNotSet(options, prefix, "node_limit", 1000);
87  changeIfNotSet(options, prefix, "solution_limit", 5);
88  }
89 
90  int
92  double *solution,
93  double & solValue,
94  double cutoff,std::string prefix) const{
95  BonminSetup * mysetup = setup_->clone(*solver, prefix);
96  Bab bb;
97  mysetup->setDoubleParameter(BabSetupBase::Cutoff, cutoff);
99  bb(mysetup);
100  int r_val = 0;
101  if(bb.bestSolution()){
102  CoinCopyN(bb.bestSolution(), solver->getNumCols(), solution);
103  solValue = bb.bestObj();
104  r_val = 1;
105  }
106  delete mysetup;
107  return r_val;
108  }
109 
111  void
113  }
114 
116  void
119  setupDefaults(options);
120  }
121 } /* Ends Bonmin namespace.*/
122 
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register the options common to all local search based heuristics.
Number of candidates for strong branching.
virtual int getNumCols() const
Get number of columns.
double bestObj() const
return objective value of the bestSolution
Definition: BonCbc.hpp:52
virtual BabSetupBase * clone() const
virtual copy constructor.
LocalSolverBasedHeuristic & operator=(const LocalSolverBasedHeuristic &rhs)
Assignment operator.
int doLocalSearch(OsiTMINLPInterface *solver, double *solution, double &solValue, double cutoff, std::string prefix="local_solver.") const
Do a local search based on setup and passed solver.
void Initialize(Ipopt::SmartPtr< Ipopt::OptionsList > options)
Initiaize using passed options.
void setDoubleParameter(const DoubleParameter &p, const double v)
Return value of double parameter.
virtual int solution(double &objectiveValue, double *newSolution)=0
Performs heuristic.
static void changeIfNotSet(Ipopt::SmartPtr< Ipopt::OptionsList > options, std::string prefix, const std::string &option, const std::string &value)
virtual void setupDefaults(Ipopt::SmartPtr< Ipopt::OptionsList > options)
Setup the defaults.
const double * bestSolution() const
get the best solution known to the problem (is optimal if MipStatus is FeasibleOptimal).
Definition: BonCbc.hpp:47
Ipopt::SmartPtr< Ipopt::OptionsList > options()
Acces list of Options.
void setIntParameter(const IntParameter &p, const int v)
Return value of integer parameter.
static char prefix[100]
Definition: BM_lp.cpp:26
BonminSetup * setup_
Setup to use for local searches (will make copies).