/home/coin/SVN-release/OS-2.4.2/Bonmin/src/Algorithms/Branching/BonCurvBranchingSolver.cpp

Go to the documentation of this file.
00001 // Copyright (C) 2006, 2007 International Business Machines
00002 // Corporation and others.  All Rights Reserved.
00003 #if defined(_MSC_VER)
00004 // Turn off compiler warning about long names
00005 #  pragma warning(disable:4786)
00006 #endif
00007 
00008 #include "BonCurvBranchingSolver.hpp"
00009 
00010 namespace Bonmin
00011 {
00012 
00013   CurvBranchingSolver::CurvBranchingSolver(OsiTMINLPInterface * solver) :
00014       StrongBranchingSolver(solver),
00015       orig_d_(NULL),
00016       projected_d_(NULL),
00017       x_l_orig_(NULL),
00018       x_u_orig_(NULL),
00019       g_l_orig_(NULL),
00020       g_u_orig_(NULL),
00021       solution_(NULL),
00022       duals_(NULL)
00023   {}
00024 
00025   CurvBranchingSolver::CurvBranchingSolver(const CurvBranchingSolver & rhs) :
00026       StrongBranchingSolver(rhs),
00027       orig_d_(NULL),
00028       projected_d_(NULL),
00029       x_l_orig_(NULL),
00030       x_u_orig_(NULL),
00031       g_l_orig_(NULL),
00032       g_u_orig_(NULL),
00033       solution_(NULL),
00034       duals_(NULL)
00035   {}
00036 
00037   CurvBranchingSolver &
00038   CurvBranchingSolver::operator=(const CurvBranchingSolver & rhs)
00039   {
00040     assert(!x_l_orig_);
00041     if (this != &rhs) {
00042       StrongBranchingSolver::operator=(rhs);
00043     }
00044     return *this;
00045   }
00046 
00047   CurvBranchingSolver::~CurvBranchingSolver ()
00048   {
00049     delete [] orig_d_;
00050     delete [] projected_d_;
00051     delete [] x_l_orig_;
00052     delete [] x_u_orig_;
00053     delete [] g_l_orig_;
00054     delete [] g_u_orig_;
00055     delete [] solution_;
00056     delete [] duals_;
00057   }
00058 
00059   void CurvBranchingSolver::
00060   markHotStart(OsiTMINLPInterface* tminlp_interface)
00061   {
00062     if (IsNull(cur_estimator_)) {
00063       // Get a curvature estimator
00064       cur_estimator_ = new CurvatureEstimator(Jnlst(), Options(),
00065           tminlp_interface->problem());
00066     }
00067 
00068     new_bounds_ = true;
00069     new_x_ = true;
00070     new_mults_ = true;
00071 
00072     delete [] solution_;
00073     delete [] duals_;
00074     solution_ =  NULL;
00075     duals_ =  NULL;
00076 
00077     numCols_ = tminlp_interface->getNumCols();
00078     numRows_ = tminlp_interface->getNumRows();
00079     solution_ = CoinCopyOfArray(tminlp_interface->problem()->x_sol(), numCols_);
00080     duals_ = CoinCopyOfArray(tminlp_interface->problem()->duals_sol(),
00081         numRows_ + 2*numCols_);
00082     obj_value_ = tminlp_interface->problem()->obj_value();
00083 
00084     delete [] orig_d_;
00085     delete [] projected_d_;
00086     orig_d_ = NULL;
00087     projected_d_ = NULL;
00088     orig_d_ = new double[numCols_];
00089     projected_d_ = new double[numCols_];
00090 
00091     // Get a copy of the current bounds
00092     delete [] x_l_orig_;
00093     delete [] x_u_orig_;
00094     delete [] g_l_orig_;
00095     delete [] g_u_orig_;
00096     x_l_orig_ = NULL;
00097     x_u_orig_ = NULL;
00098     g_l_orig_ = NULL;
00099     g_u_orig_ = NULL;
00100     x_l_orig_ = new Number[numCols_];
00101     x_u_orig_ = new Number[numCols_];
00102     g_l_orig_ = new Number[numRows_];
00103     g_u_orig_ = new Number[numRows_];
00104 
00105 #ifndef NDEBUG
00106     bool retval =
00107 #endif
00108       tminlp_interface->problem()->
00109       get_bounds_info(numCols_, x_l_orig_, x_u_orig_,
00110           numRows_, g_l_orig_, g_u_orig_);
00111     assert(retval);
00112   }
00113 
00114   void CurvBranchingSolver::
00115   unmarkHotStart(OsiTMINLPInterface* tminlp_interface)
00116   {
00117     // Free memory
00118     delete [] solution_;
00119     delete [] duals_;
00120     solution_ =  NULL;
00121     duals_ =  NULL;
00122     delete [] orig_d_;
00123     delete [] projected_d_;
00124     orig_d_ = NULL;
00125     projected_d_ = NULL;
00126     delete [] x_l_orig_;
00127     delete [] x_u_orig_;
00128     delete [] g_l_orig_;
00129     delete [] g_u_orig_;
00130     x_l_orig_ = NULL;
00131     x_u_orig_ = NULL;
00132     g_l_orig_ = NULL;
00133     g_u_orig_ = NULL;
00134   }
00135 
00136   TNLPSolver::ReturnStatus CurvBranchingSolver::
00137   solveFromHotStart(OsiTMINLPInterface* tminlp_interface)
00138   {
00139     // return iteration limit reached as status, so that it is
00140     // clear we don't have a feasible point
00141     TNLPSolver::ReturnStatus retstatus = TNLPSolver::iterationLimit;
00142 
00143     const double* z_L = duals_;
00144     const double* z_U = z_L + numCols_;
00145     const double* lam = z_U + numCols_;
00146 
00147     // get the current points
00148     const double* b_L = tminlp_interface->getColLower();
00149     const double* b_U = tminlp_interface->getColUpper();
00150 
00151     // Compute the step from the current point to the solution
00152     // ToDo: If we know what changes, we can be more efficient
00153     for (int i=0; i<numCols_; i++) {
00154       if (b_L[i]>solution_[i]) {
00155         orig_d_[i] = solution_[i]-b_L[i];
00156       }
00157       else if (b_U[i]<solution_[i]) {
00158         orig_d_[i] = solution_[i]-b_U[i];
00159       }
00160       else {
00161         orig_d_[i] = 0.;
00162       }
00163     }
00164 
00165     double gradLagTd;
00166     double dTHLagd;
00167     bool retval =
00168       cur_estimator_->ComputeNullSpaceCurvature(
00169         numCols_, solution_, new_x_, x_l_orig_, x_u_orig_,
00170         g_l_orig_, g_u_orig_, new_bounds_, z_L, z_U,
00171         numRows_, lam, new_mults_, orig_d_, projected_d_,
00172         gradLagTd, dTHLagd);
00173 
00174     if (!retval) {
00175       retstatus = TNLPSolver::computationError;
00176     }
00177     else {
00178       new_bounds_ = false;
00179       new_x_ = false;
00180       new_mults_ = false;
00181       const double alpha = 1.0; // Think about this
00182       double new_obj_value = obj_value_ +
00183           alpha*gradLagTd + 0.5*alpha*alpha*dTHLagd;
00184       tminlp_interface->problem()->set_obj_value(new_obj_value);
00185     }
00186 
00187     return retstatus;
00188   }
00189 
00190 
00191 }

Generated on Wed Nov 30 03:03:53 2011 by  doxygen 1.4.7