| 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 |
|
| 20 |
QpBranchingSolver::QpBranchingSolver(OsiTMINLPInterface * solver) |
| 21 |
: |
| 22 |
StrongBranchingSolver(solver) |
| 23 |
{} |
| 24 |
|
| 25 |
QpBranchingSolver::QpBranchingSolver(const QpBranchingSolver & rhs) : |
| 26 |
StrongBranchingSolver(rhs) |
| 27 |
{} |
| 28 |
|
| 29 |
QpBranchingSolver & |
| 30 |
QpBranchingSolver::operator=(const QpBranchingSolver & rhs) |
| 31 |
{ |
| 32 |
if (this != &rhs) { |
| 33 |
StrongBranchingSolver::operator=(rhs); |
| 34 |
} |
| 35 |
return *this; |
| 36 |
} |
| 37 |
|
| 38 |
QpBranchingSolver::~QpBranchingSolver () |
| 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 |
|
| 50 |
void QpBranchingSolver:: |
| 51 |
markHotStart(OsiTMINLPInterface* tminlp_interface) |
| 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 |
|
| 84 |
void QpBranchingSolver:: |
| 85 |
unmarkHotStart(OsiTMINLPInterface* tminlp_interface) |
| 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 |
|
| 96 |
TNLPSolver::ReturnStatus QpBranchingSolver:: |
| 97 |
solveFromHotStart(OsiTMINLPInterface* tminlp_interface) |
| 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 |
} |