00001
00002
00003
00004 #include "CoinPragma.hpp"
00005 #include "BonCurvBranchingSolver.hpp"
00006
00007 namespace Bonmin
00008 {
00009
00010 CurvBranchingSolver::CurvBranchingSolver(OsiTMINLPInterface * solver) :
00011 StrongBranchingSolver(solver),
00012 orig_d_(NULL),
00013 projected_d_(NULL),
00014 x_l_orig_(NULL),
00015 x_u_orig_(NULL),
00016 g_l_orig_(NULL),
00017 g_u_orig_(NULL),
00018 solution_(NULL),
00019 duals_(NULL)
00020 {}
00021
00022 CurvBranchingSolver::CurvBranchingSolver(const CurvBranchingSolver & rhs) :
00023 StrongBranchingSolver(rhs),
00024 orig_d_(NULL),
00025 projected_d_(NULL),
00026 x_l_orig_(NULL),
00027 x_u_orig_(NULL),
00028 g_l_orig_(NULL),
00029 g_u_orig_(NULL),
00030 solution_(NULL),
00031 duals_(NULL)
00032 {}
00033
00034 CurvBranchingSolver &
00035 CurvBranchingSolver::operator=(const CurvBranchingSolver & rhs)
00036 {
00037 assert(!x_l_orig_);
00038 if (this != &rhs) {
00039 StrongBranchingSolver::operator=(rhs);
00040 }
00041 return *this;
00042 }
00043
00044 CurvBranchingSolver::~CurvBranchingSolver ()
00045 {
00046 delete [] orig_d_;
00047 delete [] projected_d_;
00048 delete [] x_l_orig_;
00049 delete [] x_u_orig_;
00050 delete [] g_l_orig_;
00051 delete [] g_u_orig_;
00052 delete [] solution_;
00053 delete [] duals_;
00054 }
00055
00056 void CurvBranchingSolver::
00057 markHotStart(OsiTMINLPInterface* tminlp_interface)
00058 {
00059 if (IsNull(cur_estimator_)) {
00060
00061 cur_estimator_ = new CurvatureEstimator(Jnlst(), Options(),
00062 tminlp_interface->problem());
00063 }
00064
00065 new_bounds_ = true;
00066 new_x_ = true;
00067 new_mults_ = true;
00068
00069 delete [] solution_;
00070 delete [] duals_;
00071 solution_ = NULL;
00072 duals_ = NULL;
00073
00074 numCols_ = tminlp_interface->getNumCols();
00075 numRows_ = tminlp_interface->getNumRows();
00076 solution_ = CoinCopyOfArray(tminlp_interface->problem()->x_sol(), numCols_);
00077 duals_ = CoinCopyOfArray(tminlp_interface->problem()->duals_sol(),
00078 numRows_ + 2*numCols_);
00079 obj_value_ = tminlp_interface->problem()->obj_value();
00080
00081 delete [] orig_d_;
00082 delete [] projected_d_;
00083 orig_d_ = NULL;
00084 projected_d_ = NULL;
00085 orig_d_ = new double[numCols_];
00086 projected_d_ = new double[numCols_];
00087
00088
00089 delete [] x_l_orig_;
00090 delete [] x_u_orig_;
00091 delete [] g_l_orig_;
00092 delete [] g_u_orig_;
00093 x_l_orig_ = NULL;
00094 x_u_orig_ = NULL;
00095 g_l_orig_ = NULL;
00096 g_u_orig_ = NULL;
00097 x_l_orig_ = new Number[numCols_];
00098 x_u_orig_ = new Number[numCols_];
00099 g_l_orig_ = new Number[numRows_];
00100 g_u_orig_ = new Number[numRows_];
00101
00102 #ifndef NDEBUG
00103 bool retval =
00104 #endif
00105 tminlp_interface->problem()->
00106 get_bounds_info(numCols_, x_l_orig_, x_u_orig_,
00107 numRows_, g_l_orig_, g_u_orig_);
00108 assert(retval);
00109 }
00110
00111 void CurvBranchingSolver::
00112 unmarkHotStart(OsiTMINLPInterface* tminlp_interface)
00113 {
00114
00115 delete [] solution_;
00116 delete [] duals_;
00117 solution_ = NULL;
00118 duals_ = NULL;
00119 delete [] orig_d_;
00120 delete [] projected_d_;
00121 orig_d_ = NULL;
00122 projected_d_ = NULL;
00123 delete [] x_l_orig_;
00124 delete [] x_u_orig_;
00125 delete [] g_l_orig_;
00126 delete [] g_u_orig_;
00127 x_l_orig_ = NULL;
00128 x_u_orig_ = NULL;
00129 g_l_orig_ = NULL;
00130 g_u_orig_ = NULL;
00131 }
00132
00133 TNLPSolver::ReturnStatus CurvBranchingSolver::
00134 solveFromHotStart(OsiTMINLPInterface* tminlp_interface)
00135 {
00136
00137
00138 TNLPSolver::ReturnStatus retstatus = TNLPSolver::iterationLimit;
00139
00140 const double* z_L = duals_;
00141 const double* z_U = z_L + numCols_;
00142 const double* lam = z_U + numCols_;
00143
00144
00145 const double* b_L = tminlp_interface->getColLower();
00146 const double* b_U = tminlp_interface->getColUpper();
00147
00148
00149
00150 for (int i=0; i<numCols_; i++) {
00151 if (b_L[i]>solution_[i]) {
00152 orig_d_[i] = solution_[i]-b_L[i];
00153 }
00154 else if (b_U[i]<solution_[i]) {
00155 orig_d_[i] = solution_[i]-b_U[i];
00156 }
00157 else {
00158 orig_d_[i] = 0.;
00159 }
00160 }
00161
00162 double gradLagTd;
00163 double dTHLagd;
00164 bool retval =
00165 cur_estimator_->ComputeNullSpaceCurvature(
00166 numCols_, solution_, new_x_, x_l_orig_, x_u_orig_,
00167 g_l_orig_, g_u_orig_, new_bounds_, z_L, z_U,
00168 numRows_, lam, new_mults_, orig_d_, projected_d_,
00169 gradLagTd, dTHLagd);
00170
00171 if (!retval) {
00172 retstatus = TNLPSolver::computationError;
00173 }
00174 else {
00175 new_bounds_ = false;
00176 new_x_ = false;
00177 new_mults_ = false;
00178 const double alpha = 1.0;
00179 double new_obj_value = obj_value_ +
00180 alpha*gradLagTd + 0.5*alpha*alpha*dTHLagd;
00181 tminlp_interface->problem()->set_obj_value(new_obj_value);
00182 }
00183
00184 return retstatus;
00185 }
00186
00187
00188 }