| 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 |
|
| 9 |
#include "BonDummyPump.hpp" |
| 10 |
#include "CbcModel.hpp" |
| 11 |
#include "OsiBranchingObject.hpp" |
| 12 |
|
| 13 |
namespace Bonmin { |
| 14 |
|
| 15 |
/** Default constructor*/ |
| 16 |
DummyPump::DummyPump(): |
| 17 |
LocalSolverBasedHeuristic(){ |
| 18 |
} |
| 19 |
/** Constructor with setup.*/ |
| 20 |
DummyPump::DummyPump(BonminSetup * setup): |
| 21 |
LocalSolverBasedHeuristic(setup){ |
| 22 |
} |
| 23 |
|
| 24 |
/** Copy constructor.*/ |
| 25 |
DummyPump::DummyPump |
| 26 |
(const DummyPump &other): |
| 27 |
LocalSolverBasedHeuristic(other){ |
| 28 |
} |
| 29 |
|
| 30 |
DummyPump::~DummyPump(){ |
| 31 |
} |
| 32 |
|
| 33 |
/** Runs heuristic*/ |
| 34 |
int |
| 35 |
DummyPump::solution(double & objectiveValue, |
| 36 |
double * newSolution){ |
| 37 |
if(model_->getNodeCount() || model_->getCurrentPassNumber() > 1) return 0; |
| 38 |
//int numberObjects = model_->numberObjects(); |
| 39 |
//OsiObject ** objects = model_->objects(); |
| 40 |
OsiTMINLPInterface * nlp = dynamic_cast<OsiTMINLPInterface *> |
| 41 |
(setup_->nonlinearSolver()->clone()); |
| 42 |
|
| 43 |
OsiBranchingInformation info = model_->usefulInformation(); |
| 44 |
info.solution_ = model_->getColSolution(); |
| 45 |
int numcols = model_->getNumCols(); |
| 46 |
vector<double> vals; |
| 47 |
vector<int> inds; |
| 48 |
|
| 49 |
for(int i = 0 ;i < numcols ; i++){ |
| 50 |
if(nlp->isInteger(i)){ |
| 51 |
vals.push_back(info.solution_[i]); |
| 52 |
inds.push_back(i); |
| 53 |
} |
| 54 |
} |
| 55 |
nlp->switchToFeasibilityProblem(inds.size(), vals(), inds(), 1., 0., 1); |
| 56 |
|
| 57 |
double cutoff = info.cutoff_; |
| 58 |
int r_val = doLocalSearch(nlp, newSolution, objectiveValue, cutoff); |
| 59 |
delete nlp; |
| 60 |
return r_val; |
| 61 |
} |
| 62 |
|
| 63 |
void |
| 64 |
DummyPump::registerOptions(Ipopt::SmartPtr<Bonmin::RegisteredOptions> roptions){ |
| 65 |
roptions->SetRegisteringCategory("Primal Heuristics (undocumented)", RegisteredOptions::UndocumentedCategory); |
| 66 |
roptions->AddStringOption2( |
| 67 |
"dummy_pump_heuristic", |
| 68 |
"if yes runs a heuristic which looks like a dummy FP", |
| 69 |
"no", |
| 70 |
"no", "don't run it", |
| 71 |
"yes", "runs the heuristic", |
| 72 |
""); |
| 73 |
roptions->setOptionExtraInfo("dummy_pump_heuristic", 63); |
| 74 |
} |
| 75 |
|
| 76 |
/** Initiaize using passed options.*/ |
| 77 |
void |
| 78 |
DummyPump::Initialize(Ipopt::SmartPtr<Ipopt::OptionsList> options){ |
| 79 |
} |
| 80 |
}/* ends bonmin namespace*/ |