BonFixAndSolveHeuristic.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 "CbcModel.hpp"
11 #include "OsiBranchingObject.hpp"
12 
13 namespace Bonmin {
14 
18  {
19  }
23  {
24  }
25 
28  (const FixAndSolveHeuristic &other):
30  }
31 
33  }
34 
36  int
37  FixAndSolveHeuristic::solution(double & objectiveValue,
38  double * newSolution){
39  //if(model_->getNodeCount() || model_->getCurrentPassNumber() > 1) return 0;
40  if(model_->getSolutionCount() > 0) return 0;
41  if(model_->getNodeCount() > 1000) return 0;
42  if(model_->getNodeCount() % 100 != 0) return 0;
43  int numberObjects = model_->numberObjects();
44  OsiObject ** objects = model_->objects();
45 
46  OsiTMINLPInterface * nlp = dynamic_cast<OsiTMINLPInterface *>
47  (model_->solver());
48  if(nlp == NULL){
49  nlp = dynamic_cast<OsiTMINLPInterface *>
51  }
52  else {
53  nlp = dynamic_cast<OsiTMINLPInterface *>(nlp->clone());
54  }
55 
56  OsiBranchingInformation info = model_->usefulInformation();
57  info.solution_ = model_->getColSolution();
58 
59  int dummy;
60  int nFixed = 0;
61  for(int i = 0 ; i < numberObjects; i++){
62  if(objects[i]->infeasibility(&info, dummy) == 0.){
63  objects[i]->feasibleRegion(nlp, &info);
64  nFixed ++;
65  }
66  }
67  if(nFixed < numberObjects / 3) return 0;
68  double cutoff = info.cutoff_;
69  int r_val = doLocalSearch(nlp, newSolution, objectiveValue, cutoff);
70  delete nlp;
71  return r_val;
72  }
73 
74  void
76  roptions->SetRegisteringCategory("Primal Heuristics (undocumented)", RegisteredOptions::UndocumentedCategory);
77  roptions->AddStringOption2(
78  "fix_and_solve_heuristic",
79  "if yes runs a heuristic at root where fixes all variables integer in the continuous solution",
80  "no",
81  "no", "don't run it",
82  "yes", "runs the heuristic",
83  "");
84  roptions->setOptionExtraInfo("fix_and_solve_heuristic", 63);
85  }
86 
88  void
90  }
91 }/* ends bonmin namespace*/
virtual ~FixAndSolveHeuristic()
Destructor.
void fint fint fint real fint real real real real real real real real real fint real fint fint fint real fint fint fint fint * info
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
void Initialize(Ipopt::SmartPtr< Ipopt::OptionsList > options)
Initiaize using passed options.
OsiSolverInterface * clone(bool copyData=true) const
Virtual copy constructor.
FixAndSolveHeuristic()
Default constructor.
static void registerOptions(Ipopt::SmartPtr< Bonmin::RegisteredOptions > roptions)
Register the options common to all local search based heuristics.
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.
int solution(double &objectiveValue, double *newSolution)
Runs heuristic.
OsiTMINLPInterface * nonlinearSolver()
Pointer to the non-linear solver used.
BonminSetup * setup_
Setup to use for local searches (will make copies).