| 1 |
// Copyright (C) 2006, 2007 International Business Machines |
| 2 |
// Corporation and others. All Rights Reserved. |
| 3 |
|
| 4 |
#include "CoinPragma.hpp" |
| 5 |
#include "BonCurvBranchingSolver.hpp" |
| 6 |
|
| 7 |
namespace Bonmin |
| 8 |
{ |
| 9 |
|
| 10 |
CurvBranchingSolver::CurvBranchingSolver(OsiTMINLPInterface * solver) : |
| 11 |
StrongBranchingSolver(solver), |
| 12 |
orig_d_(NULL), |
| 13 |
projected_d_(NULL), |
| 14 |
x_l_orig_(NULL), |
| 15 |
x_u_orig_(NULL), |
| 16 |
g_l_orig_(NULL), |
| 17 |
g_u_orig_(NULL), |
| 18 |
solution_(NULL), |
| 19 |
duals_(NULL) |
| 20 |
{} |
| 21 |
|
| 22 |
CurvBranchingSolver::CurvBranchingSolver(const CurvBranchingSolver & rhs) : |
| 23 |
StrongBranchingSolver(rhs), |
| 24 |
orig_d_(NULL), |
| 25 |
projected_d_(NULL), |
| 26 |
x_l_orig_(NULL), |
| 27 |
x_u_orig_(NULL), |
| 28 |
g_l_orig_(NULL), |
| 29 |
g_u_orig_(NULL), |
| 30 |
solution_(NULL), |
| 31 |
duals_(NULL) |
| 32 |
{} |
| 33 |
|
| 34 |
CurvBranchingSolver & |
| 35 |
CurvBranchingSolver::operator=(const CurvBranchingSolver & rhs) |
| 36 |
{ |
| 37 |
assert(!x_l_orig_); |
| 38 |
if (this != &rhs) { |
| 39 |
StrongBranchingSolver::operator=(rhs); |
| 40 |
} |
| 41 |
return *this; |
| 42 |
} |
| 43 |
|
| 44 |
CurvBranchingSolver::~CurvBranchingSolver () |
| 45 |
{ |
| 46 |
delete [] orig_d_; |
| 47 |
delete [] projected_d_; |
| 48 |
delete [] x_l_orig_; |
| 49 |
delete [] x_u_orig_; |
| 50 |
delete [] g_l_orig_; |
| 51 |
delete [] g_u_orig_; |
| 52 |
delete [] solution_; |
| 53 |
delete [] duals_; |
| 54 |
} |
| 55 |
|
| 56 |
void CurvBranchingSolver:: |
| 57 |
markHotStart(OsiTMINLPInterface* tminlp_interface) |
| 58 |
{ |
| 59 |
if (IsNull(cur_estimator_)) { |
| 60 |
// Get a curvature estimator |
| 61 |
cur_estimator_ = new CurvatureEstimator(Jnlst(), Options(), |
| 62 |
tminlp_interface->problem()); |
| 63 |
} |
| 64 |
|
| 65 |
new_bounds_ = true; |
| 66 |
new_x_ = true; |
| 67 |
new_mults_ = true; |
| 68 |
|
| 69 |
delete [] solution_; |
| 70 |
delete [] duals_; |
| 71 |
solution_ = NULL; |
| 72 |
duals_ = NULL; |
| 73 |
|
| 74 |
numCols_ = tminlp_interface->getNumCols(); |
| 75 |
numRows_ = tminlp_interface->getNumRows(); |
| 76 |
solution_ = CoinCopyOfArray(tminlp_interface->problem()->x_sol(), numCols_); |
| 77 |
duals_ = CoinCopyOfArray(tminlp_interface->problem()->duals_sol(), |
| 78 |
numRows_ + 2*numCols_); |
| 79 |
obj_value_ = tminlp_interface->problem()->obj_value(); |
| 80 |
|
| 81 |
delete [] orig_d_; |
| 82 |
delete [] projected_d_; |
| 83 |
orig_d_ = NULL; |
| 84 |
projected_d_ = NULL; |
| 85 |
orig_d_ = new double[numCols_]; |
| 86 |
projected_d_ = new double[numCols_]; |
| 87 |
|
| 88 |
// Get a copy of the current bounds |
| 89 |
delete [] x_l_orig_; |
| 90 |
delete [] x_u_orig_; |
| 91 |
delete [] g_l_orig_; |
| 92 |
delete [] g_u_orig_; |
| 93 |
x_l_orig_ = NULL; |
| 94 |
x_u_orig_ = NULL; |
| 95 |
g_l_orig_ = NULL; |
| 96 |
g_u_orig_ = NULL; |
| 97 |
x_l_orig_ = new Number[numCols_]; |
| 98 |
x_u_orig_ = new Number[numCols_]; |
| 99 |
g_l_orig_ = new Number[numRows_]; |
| 100 |
g_u_orig_ = new Number[numRows_]; |
| 101 |
|
| 102 |
#ifndef NDEBUG |
| 103 |
bool retval = |
| 104 |
#endif |
| 105 |
tminlp_interface->problem()-> |
| 106 |
get_bounds_info(numCols_, x_l_orig_, x_u_orig_, |
| 107 |
numRows_, g_l_orig_, g_u_orig_); |
| 108 |
assert(retval); |
| 109 |
} |
| 110 |
|
| 111 |
void CurvBranchingSolver:: |
| 112 |
unmarkHotStart(OsiTMINLPInterface* tminlp_interface) |
| 113 |
{ |
| 114 |
// Free memory |
| 115 |
delete [] solution_; |
| 116 |
delete [] duals_; |
| 117 |
solution_ = NULL; |
| 118 |
duals_ = NULL; |
| 119 |
delete [] orig_d_; |
| 120 |
delete [] projected_d_; |
| 121 |
orig_d_ = NULL; |
| 122 |
projected_d_ = NULL; |
| 123 |
delete [] x_l_orig_; |
| 124 |
delete [] x_u_orig_; |
| 125 |
delete [] g_l_orig_; |
| 126 |
delete [] g_u_orig_; |
| 127 |
x_l_orig_ = NULL; |
| 128 |
x_u_orig_ = NULL; |
| 129 |
g_l_orig_ = NULL; |
| 130 |
g_u_orig_ = NULL; |
| 131 |
} |
| 132 |
|
| 133 |
TNLPSolver::ReturnStatus CurvBranchingSolver:: |
| 134 |
solveFromHotStart(OsiTMINLPInterface* tminlp_interface) |
| 135 |
{ |
| 136 |
// return iteration limit reached as status, so that it is |
| 137 |
// clear we don't have a feasible point |
| 138 |
TNLPSolver::ReturnStatus retstatus = TNLPSolver::iterationLimit; |
| 139 |
|
| 140 |
const double* z_L = duals_; |
| 141 |
const double* z_U = z_L + numCols_; |
| 142 |
const double* lam = z_U + numCols_; |
| 143 |
|
| 144 |
// get the current points |
| 145 |
const double* b_L = tminlp_interface->getColLower(); |
| 146 |
const double* b_U = tminlp_interface->getColUpper(); |
| 147 |
|
| 148 |
// Compute the step from the current point to the solution |
| 149 |
// ToDo: If we know what changes, we can be more efficient |
| 150 |
for (int i=0; i<numCols_; i++) { |
| 151 |
if (b_L[i]>solution_[i]) { |
| 152 |
orig_d_[i] = solution_[i]-b_L[i]; |
| 153 |
} |
| 154 |
else if (b_U[i]<solution_[i]) { |
| 155 |
orig_d_[i] = solution_[i]-b_U[i]; |
| 156 |
} |
| 157 |
else { |
| 158 |
orig_d_[i] = 0.; |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
double gradLagTd; |
| 163 |
double dTHLagd; |
| 164 |
bool retval = |
| 165 |
cur_estimator_->ComputeNullSpaceCurvature( |
| 166 |
numCols_, solution_, new_x_, x_l_orig_, x_u_orig_, |
| 167 |
g_l_orig_, g_u_orig_, new_bounds_, z_L, z_U, |
| 168 |
numRows_, lam, new_mults_, orig_d_, projected_d_, |
| 169 |
gradLagTd, dTHLagd); |
| 170 |
|
| 171 |
if (!retval) { |
| 172 |
retstatus = TNLPSolver::computationError; |
| 173 |
} |
| 174 |
else { |
| 175 |
new_bounds_ = false; |
| 176 |
new_x_ = false; |
| 177 |
new_mults_ = false; |
| 178 |
const double alpha = 1.0; // Think about this |
| 179 |
double new_obj_value = obj_value_ + |
| 180 |
alpha*gradLagTd + 0.5*alpha*alpha*dTHLagd; |
| 181 |
tminlp_interface->problem()->set_obj_value(new_obj_value); |
| 182 |
} |
| 183 |
|
| 184 |
return retstatus; |
| 185 |
} |
| 186 |
|
| 187 |
|
| 188 |
} |