Bonmin
1.7
|
00001 // Copyright (C) 2004, International Business Machines and others. 00002 // All Rights Reserved. 00003 // This code is published under the Common Public License. 00004 // 00005 // 00006 // Authors: Pierre Bonami 06/10/2005 00007 00008 #ifndef _TNLP2FPNLP_HPP_ 00009 #define _TNLP2FPNLP_HPP_ 00010 00011 #include "IpTNLP.hpp" 00012 #include "BonTMINLP.hpp" 00013 #include "IpSmartPtr.hpp" 00014 #include "BonTypes.hpp" 00015 00016 namespace Bonmin 00017 { 00022 class TNLP2FPNLP : public Ipopt::TNLP 00023 { 00024 public: 00028 TNLP2FPNLP(const Ipopt::SmartPtr<Ipopt::TNLP> tnlp, double objectiveScalingFactor = 100); 00029 00031 TNLP2FPNLP(const Ipopt::SmartPtr<TNLP> tnlp, const Ipopt::SmartPtr<TNLP2FPNLP> other); 00032 00034 virtual ~TNLP2FPNLP(); 00036 void use(Ipopt::SmartPtr<TNLP> tnlp){ 00037 tnlp_ = GetRawPtr(tnlp);} 00040 00041 void set_use_feasibility_pump_objective(bool use_feasibility_pump_objective) 00042 { use_feasibility_pump_objective_ = use_feasibility_pump_objective; } 00043 00046 void set_use_cutoff_constraint(bool use_cutoff_constraint) 00047 { use_cutoff_constraint_ = use_cutoff_constraint; } 00048 00050 void set_use_local_branching_constraint(bool use_local_branching_constraint) 00051 { use_local_branching_constraint_ = use_local_branching_constraint; } 00053 00056 00057 void set_cutoff(Ipopt::Number cutoff); 00058 00060 void set_rhs_local_branching_constraint(double rhs_local_branching_constraint) 00061 { assert(rhs_local_branching_constraint >= 0); 00062 rhs_local_branching_constraint_ = rhs_local_branching_constraint; } 00064 00073 void set_dist_to_point_obj(size_t n, const Ipopt::Number * vals, const Ipopt::Index * inds); 00074 00076 void setSigma(double sigma){ 00077 assert(sigma >= 0.); 00078 sigma_ = sigma;} 00080 void setLambda(double lambda){ 00081 assert(lambda >= 0. && lambda <= 1.); 00082 lambda_ = lambda;} 00084 void setNorm(int norm){ 00085 assert(norm >0 && norm < 3); 00086 norm_ = norm;} 00088 00092 virtual bool get_nlp_info(Ipopt::Index& n, Ipopt::Index& m, Ipopt::Index& nnz_jac_g, 00093 Ipopt::Index& nnz_h_lag, Ipopt::TNLP::IndexStyleEnum& index_style); 00094 00097 virtual bool get_bounds_info(Ipopt::Index n, Ipopt::Number* x_l, Ipopt::Number* x_u, 00098 Ipopt::Index m, Ipopt::Number* g_l, Ipopt::Number* g_u); 00099 00102 virtual bool get_starting_point(Ipopt::Index n, bool init_x, Ipopt::Number* x, 00103 bool init_z, Ipopt::Number* z_L, Ipopt::Number* z_U, 00104 Ipopt::Index m, bool init_lambda, 00105 Ipopt::Number* lambda) 00106 { 00107 int m2 = m; 00108 if(use_cutoff_constraint_) { 00109 m2--; 00110 if(lambda!=NULL)lambda[m2] = 0; 00111 } 00112 if(use_local_branching_constraint_) { 00113 m2--; 00114 if(lambda!= NULL)lambda[m2] = 0; 00115 } 00116 int ret_code = tnlp_->get_starting_point(n, init_x, x, 00117 init_z, z_L, z_U, m2, init_lambda, lambda); 00118 return ret_code; 00119 } 00120 00122 virtual bool eval_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x, 00123 Ipopt::Number& obj_value); 00124 00127 virtual bool eval_grad_f(Ipopt::Index n, const Ipopt::Number* x, bool new_x, 00128 Ipopt::Number* grad_f); 00129 00132 virtual bool eval_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x, 00133 Ipopt::Index m, Ipopt::Number* g); 00134 00136 virtual bool eval_jac_g(Ipopt::Index n, const Ipopt::Number* x, bool new_x, 00137 Ipopt::Index m, Ipopt::Index nele_jac, Ipopt::Index* iRow, 00138 Ipopt::Index *jCol, Ipopt::Number* values); 00139 00141 virtual bool eval_h(Ipopt::Index n, const Ipopt::Number* x, bool new_x, 00142 Ipopt::Number obj_factor, Ipopt::Index m, const Ipopt::Number* lambda, 00143 bool new_lambda, Ipopt::Index nele_hess, 00144 Ipopt::Index* iRow, Ipopt::Index* jCol, Ipopt::Number* values); 00146 00150 virtual void finalize_solution(Ipopt::SolverReturn status, 00151 Ipopt::Index n, const Ipopt::Number* x, const Ipopt::Number* z_L, const Ipopt::Number* z_U, 00152 Ipopt::Index m, const Ipopt::Number* g, const Ipopt::Number* lambda, 00153 Ipopt::Number obj_value, 00154 const Ipopt::IpoptData* ip_data, 00155 Ipopt::IpoptCalculatedQuantities* ip_cq); 00157 00158 virtual bool get_variables_linearity(Ipopt::Index n, LinearityType* var_types) 00159 { 00160 return tnlp_->get_variables_linearity(n, var_types);; 00161 } 00162 00166 virtual bool get_constraints_linearity(Ipopt::Index m, LinearityType* const_types) 00167 { 00168 int m2 = m; 00169 if(use_cutoff_constraint_) { 00170 m2--; 00171 const_types[m2] = Ipopt::TNLP::NON_LINEAR; 00172 } 00173 if(use_local_branching_constraint_) { 00174 m2--; 00175 const_types[m2] = Ipopt::TNLP::LINEAR; 00176 } 00177 return tnlp_->get_constraints_linearity(m2, const_types); 00178 } 00181 void setObjectiveScaling(double value) 00182 { 00183 objectiveScalingFactor_ = value; 00184 } 00185 double getObjectiveScaling() const 00186 { 00187 return objectiveScalingFactor_; 00188 } 00189 00190 private: 00194 double dist_to_point(const Ipopt::Number *x); 00196 00205 TNLP2FPNLP(); 00206 00208 TNLP2FPNLP(const TNLP2FPNLP&); 00209 00211 void operator=(const TNLP2FPNLP&); 00213 00215 Ipopt::SmartPtr<TNLP> tnlp_; 00216 00219 00220 vector<Ipopt::Index> inds_; 00222 vector<Ipopt::Number> vals_; 00225 double lambda_; 00227 double sigma_; 00229 int norm_; 00231 00233 double objectiveScalingFactor_; 00234 00237 00238 bool use_feasibility_pump_objective_; 00239 00242 bool use_cutoff_constraint_; 00243 00245 bool use_local_branching_constraint_; 00247 00250 00251 double cutoff_; 00252 00254 double rhs_local_branching_constraint_; 00256 00258 Ipopt::TNLP::IndexStyleEnum index_style_; 00259 00260 }; 00261 00262 } // namespace Ipopt 00263 00264 #endif /*_TNLP2FPNLP_HPP_*/