// (C) Copyright International Business Machines Corporation and Carnegie Mellon University 2006, 2008 // All Rights Reserved. // This code is published under the Eclipse Public License. // // Authors : // Andreas Waechter, International Business Machines Corporation // (derived from BonTMINLP2TNLP.cpp) 12/22/2006 // Authors : #include "BonBranchingTQP.hpp" #include "IpBlas.hpp" #include "IpAlgTypes.hpp" #include #include #include using namespace Ipopt; namespace Bonmin { BranchingTQP::BranchingTQP(SmartPtr tminlp2tnlp) : tminlp2tnlp_(tminlp2tnlp) { bool retval = tminlp2tnlp_->get_nlp_info(n_, m_, nnz_jac_g_, nnz_h_lag_, index_style_); ASSERT_EXCEPTION(retval, TMINLP_INVALID, "Can't get NLP infor in BranchingTQP"); //DBG_ASSERT(x_sol_); //DBG_ASSERT(duals_sol_); obj_grad_ = new Number[n_]; obj_hess_ = new Number[nnz_h_lag_]; obj_hess_irow_ = new Index[nnz_h_lag_]; obj_hess_jcol_ = new Index[nnz_h_lag_]; g_vals_ = new Number[m_]; g_jac_ = new Number[nnz_jac_g_]; g_jac_irow_ = new Index[nnz_jac_g_]; g_jac_jcol_ = new Index[nnz_jac_g_]; const Number* x_sol = tminlp2tnlp_->x_sol(); const Number* duals_sol = tminlp2tnlp_->duals_sol(); // Compute all nonlinear values at the starting point so that we // have all the information for the QP bool new_x = true; // ToDo: maybe NOT new? retval = tminlp2tnlp_->eval_f(n_, x_sol, new_x, obj_val_); ASSERT_EXCEPTION(retval, TMINLP_INVALID, "Can't evaluate objective function in BranchingTQP"); new_x = false; retval = tminlp2tnlp_->eval_grad_f(n_, x_sol, new_x, obj_grad_); ASSERT_EXCEPTION(retval, TMINLP_INVALID, "Can't evaluate objective gradient in BranchingTQP"); bool new_lambda = true; // ToDo: maybe NOT new? retval = tminlp2tnlp_->eval_h(n_, x_sol, new_x, 1., m_, duals_sol + 2 * n_, new_lambda, nnz_h_lag_, obj_hess_irow_, obj_hess_jcol_, NULL); ASSERT_EXCEPTION(retval, TMINLP_INVALID, "Can't evaluate objective Hessian structure in BranchingTQP"); if (index_style_ == TNLP::FORTRAN_STYLE) { for (Index i=0; ieval_h(n_, x_sol, new_x, 1., m_, duals_sol + 2*n_, new_lambda, nnz_h_lag_, NULL, NULL, obj_hess_); ASSERT_EXCEPTION(retval, TMINLP_INVALID, "Can't evaluate objective Hessian values in BranchingTQP"); retval = tminlp2tnlp_->eval_g(n_, x_sol, new_x, m_, g_vals_); ASSERT_EXCEPTION(retval, TMINLP_INVALID, "Can't evaluate constraint values in BranchingTQP"); retval = tminlp2tnlp_->eval_jac_g(n_, x_sol, new_x, m_, nnz_jac_g_, g_jac_irow_, g_jac_jcol_, NULL); ASSERT_EXCEPTION(retval, TMINLP_INVALID, "Can't evaluate constraint Jacobian structure in BranchingTQP"); if (index_style_ == TNLP::FORTRAN_STYLE) { for (Index i=0; ieval_jac_g(n_, x_sol, new_x, m_, nnz_jac_g_, NULL, NULL, g_jac_); ASSERT_EXCEPTION(retval, TMINLP_INVALID, "Can't evaluate constraint Jacobian values in BranchingTQP"); // Keep copy of original x_sol and duals_sol values x_sol_copy_ = new Number[n_]; IpBlasDcopy(n_, x_sol, 1, x_sol_copy_, 1); duals_sol_copy_ = new Number[m_ + 2*n_]; IpBlasDcopy(m_+2*n_, duals_sol, 1, duals_sol_copy_, 1); #if 0 for (int i=0; iget_bounds_info(n, x_l, x_u, m, g_l, g_u); // correct for displacement for (int i=0; ifinalize_solution(status, n, xx, z_L, z_U, m, g, lambda, obj, ip_data, ip_cq); delete [] xx; } } // namespace Ipopt