Bonmin
1.7
|
00001 // Copyright (C) 2007 International Business Machines and others. 00002 // All Rights Reserved. 00003 // This code is published under the Common Public License. 00004 // 00005 // $Id: BonCutStrengthener.hpp 1858 2011-06-18 20:13:40Z stefan $ 00006 // 00007 // Author: Andreas Waechter IBM 2007-03-29 00008 00009 #ifndef __BONCUTSTRENGTHENER_HPP__ 00010 #define __BONCUTSTRENGTHENER_HPP__ 00011 00012 #include "BonTMINLP.hpp" 00013 #include "CoinPackedVector.hpp" 00014 #include "BonTNLPSolver.hpp" 00015 00016 namespace Bonmin 00017 { 00018 enum CutStrengtheningType{ 00019 CS_None=0, 00020 CS_StrengthenedGlobal=1, 00021 CS_UnstrengthenedGlobal_StrengthenedLocal=2, 00022 CS_StrengthenedGlobal_StrengthenedLocal=3 00023 }; 00024 00025 enum DisjunctiveCutType{ 00026 DC_None=0, 00027 DC_MostFractional=1 00028 }; 00029 00032 class CutStrengthener: public Ipopt::ReferencedObject 00033 { 00036 class StrengtheningTNLP: public Ipopt::TNLP { 00037 public: 00039 StrengtheningTNLP(Ipopt::SmartPtr<TMINLP> tminlp, 00040 const CoinPackedVector& cut, 00041 bool lower_bound, 00042 Ipopt::Index n, 00043 const Ipopt::Number* starting_point, 00044 const double* x_l_orig, 00045 const double* x_u_orig, 00046 Ipopt::Index constr_index, 00047 Ipopt::Index nvar_constr , 00048 const Ipopt::Index* jCol); 00049 00051 ~StrengtheningTNLP(); 00052 00056 virtual bool get_nlp_info(Ipopt::Index& n, Ipopt::Index& m, Ipopt::Index& nnz_jac_g, 00057 Ipopt::Index& nnz_h_lag, Ipopt::TNLP::IndexStyleEnum& index_style); 00058 00060 virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number* x_l, Ipopt::Number* x_u, 00061 Ipopt::Index m, Ipopt::Number* g_l, Ipopt::Number* g_u); 00062 00064 virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number* x, 00065 bool init_z, Ipopt::Number* z_L, Ipopt::Number* z_U, 00066 Ipopt::Index m, bool init_lambda, 00067 Ipopt::Number* lambda); 00068 00070 virtual bool eval_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x, Ipopt::Number& obj_value); 00071 00073 virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x, Ipopt::Number* grad_f); 00074 00076 virtual bool eval_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x, Ipopt::Index m, Ipopt::Number* g); 00077 00082 virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x, 00083 Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index* iRow, Ipopt::Index *jCol, 00084 Ipopt::Number* values); 00085 00090 virtual bool eval_h(Ipopt::Index n, const Ipopt::Number* x, bool new_x, 00091 Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number* lambda, 00092 bool new_lambda, Ipopt::Index nele_hess, Ipopt::Index* iRow, 00093 Ipopt::Index* jCol, Ipopt::Number* values); 00094 00096 00099 virtual void finalize_solution(Ipopt::SolverReturn status, 00100 Ipopt::Index n, const Ipopt::Number* x, const Ipopt::Number* z_L, const Ipopt::Number* z_U, 00101 Ipopt::Index m, const Ipopt::Number* g, const Ipopt::Number* lambda, 00102 Ipopt::Number obj_value, 00103 const Ipopt::IpoptData* ip_data, 00104 Ipopt::IpoptCalculatedQuantities* ip_cq); 00106 00108 Ipopt::Number StrengthenedBound() const; 00109 00110 private: 00113 StrengtheningTNLP(); 00114 StrengtheningTNLP(const StrengtheningTNLP&); 00115 StrengtheningTNLP& operator=(const StrengtheningTNLP&); 00117 00120 const Ipopt::SmartPtr<TMINLP> tminlp_; 00121 00123 Ipopt::Number* obj_grad_; 00124 00126 const Ipopt::Index n_orig_; 00127 00129 Ipopt::Index m_orig_; 00130 00132 Ipopt::Number* starting_point_; 00133 00136 Ipopt::Number* x_full_; 00137 00139 Ipopt::Number* x_l_; 00140 00142 Ipopt::Number* x_u_; 00143 00145 const Ipopt::Index constr_index_; 00146 00148 const Ipopt::Index nvar_constr_; 00149 00151 Ipopt::Index* var_indices_; 00152 00154 bool lower_bound_; 00155 00157 bool have_final_bound_; 00158 00160 Ipopt::Number strengthened_bound_; 00161 00163 Ipopt::Number* grad_f_; 00164 00166 void update_x_full(const Ipopt::Number *x); 00167 }; 00168 00169 public: 00174 CutStrengthener(Ipopt::SmartPtr<TNLPSolver> tnlp_solver, 00175 Ipopt::SmartPtr<Ipopt::OptionsList> options); 00176 00178 virtual ~CutStrengthener(); 00180 00182 bool ComputeCuts(OsiCuts &cs, 00183 TMINLP* tminlp, 00184 TMINLP2TNLP* problem, 00185 const int gindex, CoinPackedVector& cut, 00186 double& cut_lb, double& cut_ub, 00187 const double g_val, const double g_lb, 00188 const double g_ub, 00189 int n, const double* x, 00190 double infty); 00191 00192 private: 00202 CutStrengthener(); 00203 00205 CutStrengthener(const CutStrengthener&); 00206 00208 void operator=(const CutStrengthener&); 00210 00212 bool StrengthenCut(Ipopt::SmartPtr<TMINLP> tminlp , 00213 int constr_index , 00214 const CoinPackedVector& row , 00215 int n , 00216 const double* x , 00217 const double* x_l , 00218 const double* x_u , 00219 double& lb, 00220 double& ub); 00221 00223 bool HandleOneCut(bool is_tight, TMINLP* tminlp, 00224 TMINLP2TNLP* problem, 00225 const double* minlp_lb, 00226 const double* minlp_ub, 00227 const int gindex, CoinPackedVector& cut, 00228 double& cut_lb, double& cut_ub, 00229 int n, const double* x, 00230 double infty); 00231 00233 Ipopt::SmartPtr<TNLPSolver> tnlp_solver_; 00234 00236 int cut_strengthening_type_; 00238 int disjunctive_cut_type_; 00240 int oa_log_level_; 00241 }; 00242 00243 } // namespace Ipopt 00244 #endif