BonQpBranchingSolver.cpp
Go to the documentation of this file.
1 // Copyright (C) 2006, 2008 International Business Machines
2 // Corporation and others. All Rights Reserved.
3 // Authors: Andreas Waechter, Pierre Bonami
4 
5 #include "BonminConfig.h"
6 
7 #include "CoinPragma.hpp"
8 
9 #define Verbose
10 #include "BonQpBranchingSolver.hpp"
11 
12 #ifdef COIN_HAS_FILTERSQP
13 #include "BonFilterSolver.hpp"
14 #include "BonBqpdSolver.hpp"
15 #endif
16 
17 namespace Bonmin
18 {
19 
21  :
22  StrongBranchingSolver(solver)
23  {}
24 
27  {}
28 
31  {
32  if (this != &rhs) {
34  }
35  return *this;
36  }
37 
39  {
40 #ifdef TIME_BQPD
41  printf("QPBRANCH Timings for %i sbs\n", times_.numsolve);
42  printf("QPBRANCH %i pivots\n", times_.pivots);
43  printf("QPBRANCH Creating : %g\n", times_.create);
44  printf("QPBRANCH Solving : %g\n", times_.solve);
45  printf("QPBRANCH Warming : %g\n", times_.warm_start);
46  printf("QPBRANCH Resolving : %g\n", times_.resolve);
47 #endif
48  }
49 
52  {
53  TMINLP2TNLP* tminlp2tnlp = tminlp_interface->problem();
54  branching_tqp_ = new BranchingTQP(tminlp2tnlp);
55 
56  first_solve_ = true;
57 #ifdef COIN_HAS_FILTERSQP
58  FilterSolver* filter_solver =
59  dynamic_cast<FilterSolver*> (tminlp_interface->solver());
60  if (filter_solver) {
61  Ipopt::SmartPtr<BqpdSolver> qp_solver =
62  new BqpdSolver(RegOptions(), Options(), Jnlst(), tminlp_interface->prefix());
63 #if 1
64  // Solve the QP with the original bounds and set the hot start
65  // information
66  TNLPSolver::ReturnStatus retstatus;
67  retstatus = qp_solver->OptimizeTNLP(GetRawPtr(branching_tqp_));
68  if (retstatus == TNLPSolver::solvedOptimal ||
69  retstatus == TNLPSolver::solvedOptimalTol) {
70  first_solve_ = false;
71  qp_solver->markHotStart();
72  }
73 #endif
74  tqp_solver_ = GetRawPtr(qp_solver);
75  //tqp_solver_ = new FilterSolver(RegOptions(), Options(), Jnlst());
76  }
77 #endif
78  if (IsNull(tqp_solver_)) {
79  tqp_solver_ = tminlp_interface->solver()->clone();
80  }
81  tqp_solver_->enableWarmStart();
82  }
83 
86  {
87  // Free memory
88 #ifdef TIME_BQPD
89  BqpdSolver * qp_solver = dynamic_cast<BqpdSolver *>(GetRawPtr(tqp_solver_));
90  if(qp_solver) times_ += qp_solver->times();
91 #endif
92  branching_tqp_ = NULL;
93  tqp_solver_ = NULL;
94  }
95 
98  {
99  TNLPSolver::ReturnStatus retstatus;
100  if (first_solve_) {
101  retstatus = tqp_solver_->OptimizeTNLP(GetRawPtr(branching_tqp_));
102  }
103  else {
104  retstatus = tqp_solver_->ReOptimizeTNLP(GetRawPtr(branching_tqp_));
105  }
106 
107  if (retstatus == TNLPSolver::solvedOptimal ||
108  retstatus == TNLPSolver::solvedOptimalTol) {
109  // don't way we solve the problem, since otherwise the pseudo costs
110  // are updated and that is maybe not so good???
111  //retstatus = TNLPSolver::iterationLimit;
112  first_solve_ = false;
113  }
114  //retstatus = TNLPSolver::iterationLimit;
115  return retstatus;
116  }
117 
118 }
virtual Ipopt::SmartPtr< TNLPSolver > clone()=0
virtual copy constructor
This class is the base class for a solver that can be used in BonOsiSolverInterface to perform the st...
virtual TNLPSolver::ReturnStatus solveFromHotStart(OsiTMINLPInterface *tminlp_interface)
Called to solve the current TMINLP (with changed bound information)
virtual void unmarkHotStart(OsiTMINLPInterface *tminlp_interface)
Called after all strong branching solves in a node.
const TMINLP2TNLP * problem() const
get pointer to the TMINLP2TNLP adapter
This class chooses a variable to branch on.
This is class provides an Osi interface for a Mixed Integer Linear Program expressed as a TMINLP (so ...
Ipopt::SmartPtr< BranchingTQP > branching_tqp_
virtual ~QpBranchingSolver()
Destructor.
Ipopt::SmartPtr< Ipopt::Journalist > & Jnlst()
QpBranchingSolver()
Default Constructor.
const Bonmin::TNLPSolver * solver() const
bool IsNull(const OSSmartPtr< U > &smart_ptr)
Definition: OSSmartPtr.hpp:471
U * GetRawPtr(const OSSmartPtr< U > &smart_ptr)
Definition: OSSmartPtr.hpp:452
Ipopt::SmartPtr< TNLPSolver > tqp_solver_
ReturnStatus
Standard return statuses for a solver.
const char * prefix() const
Default Constructor.
StrongBranchingSolver & operator=(const StrongBranchingSolver &rhs)
Assignment operator.
QpBranchingSolver & operator=(const QpBranchingSolver &rhs)
Assignment operator.
This is an adapter class that converts a TMINLP2TNLP object into a TNLP, which is now just a QP...
virtual void markHotStart(OsiTMINLPInterface *tminlp_interface)
Called to initialize solver before a bunch of strong branching solves.
This is an adapter class that converts a TMINLP to a TNLP to be solved by Ipopt.
Ipopt::SmartPtr< Ipopt::OptionsList > & Options()
Ipopt::SmartPtr< RegisteredOptions > & RegOptions()