Bonmin 1.4trunk
|
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$ 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 using namespace Ipopt; 00019 00020 enum CutStrengtheningType{ 00021 CS_None=0, 00022 CS_StrengthenedGlobal=1, 00023 CS_UnstrengthenedGlobal_StrengthenedLocal=2, 00024 CS_StrengthenedGlobal_StrengthenedLocal=3 00025 }; 00026 00027 enum DisjunctiveCutType{ 00028 DC_None=0, 00029 DC_MostFractional=1 00030 }; 00031 00034 class CutStrengthener: public ReferencedObject 00035 { 00038 class StrengtheningTNLP: public TNLP { 00039 public: 00041 StrengtheningTNLP(SmartPtr<TMINLP> tminlp, 00042 const CoinPackedVector& cut, 00043 bool lower_bound, 00044 Index n, 00045 const Number* starting_point, 00046 const double* x_l_orig, 00047 const double* x_u_orig, 00048 Index constr_index, 00049 Index nvar_constr , 00050 const Index* jCol); 00051 00053 ~StrengtheningTNLP(); 00054 00058 virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, 00059 Index& nnz_h_lag, IndexStyleEnum& index_style); 00060 00062 virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u, 00063 Index m, Number* g_l, Number* g_u); 00064 00066 virtual bool get_starting_point(Index n, bool init_x, Number* x, 00067 bool init_z, Number* z_L, Number* z_U, 00068 Index m, bool init_lambda, 00069 Number* lambda); 00070 00072 virtual bool eval_f(Index n, const Number* x, bool new_x, Number& obj_value); 00073 00075 virtual bool eval_grad_f(Index n, const Number* x, bool new_x, Number* grad_f); 00076 00078 virtual bool eval_g(Index n, const Number* x, bool new_x, Index m, Number* g); 00079 00084 virtual bool eval_jac_g(Index n, const Number* x, bool new_x, 00085 Index m, Index nele_jac, Index* iRow, Index *jCol, 00086 Number* values); 00087 00092 virtual bool eval_h(Index n, const Number* x, bool new_x, 00093 Number obj_factor, Index m, const Number* lambda, 00094 bool new_lambda, Index nele_hess, Index* iRow, 00095 Index* jCol, Number* values); 00096 00098 00101 virtual void finalize_solution(SolverReturn status, 00102 Index n, const Number* x, const Number* z_L, const Number* z_U, 00103 Index m, const Number* g, const Number* lambda, 00104 Number obj_value, 00105 const IpoptData* ip_data, 00106 IpoptCalculatedQuantities* ip_cq); 00108 00110 Number StrengthenedBound() const; 00111 00112 private: 00115 StrengtheningTNLP(); 00116 StrengtheningTNLP(const StrengtheningTNLP&); 00117 StrengtheningTNLP& operator=(const StrengtheningTNLP&); 00119 00122 const SmartPtr<TMINLP> tminlp_; 00123 00125 Number* obj_grad_; 00126 00128 const Index n_orig_; 00129 00131 Index m_orig_; 00132 00134 Number* starting_point_; 00135 00138 Number* x_full_; 00139 00141 Number* x_l_; 00142 00144 Number* x_u_; 00145 00147 const Index constr_index_; 00148 00150 const Index nvar_constr_; 00151 00153 Index* var_indices_; 00154 00156 bool lower_bound_; 00157 00159 bool have_final_bound_; 00160 00162 Number strengthened_bound_; 00163 00165 Number* grad_f_; 00166 00168 void update_x_full(const Number *x); 00169 }; 00170 00171 public: 00176 CutStrengthener(SmartPtr<TNLPSolver> tnlp_solver, 00177 SmartPtr<OptionsList> options); 00178 00180 virtual ~CutStrengthener(); 00182 00184 bool ComputeCuts(OsiCuts &cs, 00185 TMINLP* tminlp, 00186 TMINLP2TNLP* problem, 00187 const int gindex, CoinPackedVector& cut, 00188 double& cut_lb, double& cut_ub, 00189 const double g_val, const double g_lb, 00190 const double g_ub, 00191 int n, const double* x, 00192 double infty); 00193 00194 private: 00204 CutStrengthener(); 00205 00207 CutStrengthener(const CutStrengthener&); 00208 00210 void operator=(const CutStrengthener&); 00212 00214 bool StrengthenCut(SmartPtr<TMINLP> tminlp , 00215 int constr_index , 00216 const CoinPackedVector& row , 00217 int n , 00218 const double* x , 00219 const double* x_l , 00220 const double* x_u , 00221 double& lb, 00222 double& ub); 00223 00225 bool HandleOneCut(bool is_tight, TMINLP* tminlp, 00226 TMINLP2TNLP* problem, 00227 const double* minlp_lb, 00228 const double* minlp_ub, 00229 const int gindex, CoinPackedVector& cut, 00230 double& cut_lb, double& cut_ub, 00231 int n, const double* x, 00232 double infty); 00233 00235 SmartPtr<TNLPSolver> tnlp_solver_; 00236 00238 int cut_strengthening_type_; 00240 int disjunctive_cut_type_; 00242 int oa_log_level_; 00243 }; 00244 00245 } // namespace Ipopt 00246 #endif