00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "BonLocalSolverBasedHeuristic.hpp"
00010 #include "BonCbc.hpp"
00011
00012 namespace Bonmin {
00013 LocalSolverBasedHeuristic::LocalSolverBasedHeuristic():
00014 CbcHeuristic(),
00015 setup_(NULL),
00016 time_limit_(60),
00017 max_number_nodes_(1000),
00018 max_number_solutions_(10){
00019 }
00020 LocalSolverBasedHeuristic::LocalSolverBasedHeuristic(BonminSetup * setup):
00021 CbcHeuristic(),
00022 setup_(setup),
00023 time_limit_(60),
00024 max_number_nodes_(1000),
00025 max_number_solutions_(10){
00026 Initialize(setup->options());
00027 }
00028
00029 LocalSolverBasedHeuristic::LocalSolverBasedHeuristic(const LocalSolverBasedHeuristic & other):
00030 CbcHeuristic(other),
00031 setup_(other.setup_),
00032 time_limit_(other.time_limit_),
00033 max_number_nodes_(other.max_number_nodes_),
00034 max_number_solutions_(other.max_number_solutions_) {
00035 }
00036
00037 LocalSolverBasedHeuristic::~LocalSolverBasedHeuristic(){
00038 }
00039
00040 LocalSolverBasedHeuristic &
00041 LocalSolverBasedHeuristic::operator=(const LocalSolverBasedHeuristic& rhs){
00042 if(this != &rhs){
00043 CbcHeuristic::operator=(rhs);
00044 setup_ = rhs.setup_;
00045 }
00046 return *this;
00047 }
00048
00049 void
00050 LocalSolverBasedHeuristic::changeIfNotSet(Ipopt::SmartPtr<Bonmin::OptionsList> options,
00051 std::string prefix,
00052 const std::string &option,
00053 const std::string &value){
00054 int dummy;
00055 if(!options->GetEnumValue(option,dummy,prefix))
00056 options->SetStringValue(prefix + option, value, true, true);
00057
00058 }
00059 void
00060 LocalSolverBasedHeuristic::changeIfNotSet(Ipopt::SmartPtr<Bonmin::OptionsList> options,
00061 std::string prefix,
00062 const std::string &option,
00063 const double &value){
00064 double dummy;
00065 if(!options->GetNumericValue(option,dummy,prefix))
00066 options->SetNumericValue(prefix + option, value, true, true);
00067
00068 }
00069 void
00070 LocalSolverBasedHeuristic::changeIfNotSet(Ipopt::SmartPtr<Bonmin::OptionsList> options,
00071 std::string prefix,
00072 const std::string &option,
00073 const int &value){
00074 int dummy;
00075 if(!options->GetIntegerValue(option,dummy,prefix))
00076 options->SetIntegerValue(prefix + option, value, true, true);
00077
00078 }
00079
00080 void
00081 LocalSolverBasedHeuristic::setupDefaults(Ipopt::SmartPtr<Bonmin::OptionsList> options){
00082 std::string prefix = "local_solver.";
00083 changeIfNotSet(options, prefix, "algorithm", "B-QG");
00084 changeIfNotSet(options, prefix, "variable_selection", "most-fractional");
00085 changeIfNotSet(options, prefix, "time_limit", 60.);
00086 changeIfNotSet(options, prefix, "node_limit", 1000);
00087 changeIfNotSet(options, prefix, "solution_limit", 5);
00088 }
00089
00090 int
00091 LocalSolverBasedHeuristic::doLocalSearch(OsiTMINLPInterface * solver,
00092 double *solution,
00093 double & solValue,
00094 double cutoff,std::string prefix) const{
00095 BonminSetup * mysetup = setup_->clone(*solver, prefix);
00096 Bab bb;
00097 mysetup->setDoubleParameter(BabSetupBase::Cutoff, cutoff);
00098 mysetup->setIntParameter(BabSetupBase::NumberStrong, 0);
00099 bb(mysetup);
00100 int r_val = 0;
00101 if(bb.bestSolution()){
00102 CoinCopyN(bb.bestSolution(), solver->getNumCols(), solution);
00103 solValue = bb.bestObj();
00104 r_val = 1;
00105 }
00106 delete mysetup;
00107 return r_val;
00108 }
00109
00111 void
00112 LocalSolverBasedHeuristic::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions){
00113 }
00114
00116 void
00117 LocalSolverBasedHeuristic::Initialize(Ipopt::SmartPtr<Bonmin::OptionsList> options){
00119 setupDefaults(options);
00120 }
00121 }
00122