1 // Copyright (C) 2008 International Business Machines and others. 2 // All Rights Reserved. 3 // This code is published under the Eclipse Public License. 4 // 5 // $Id$ 6 // 7 // Authors: Andreas Waechter IBM 2008-08-10 8 9 #ifndef __IPTNLPREDUCER_HPP__ 10 #define __IPTNLPREDUCER_HPP__ 11 12 #include "IpTNLP.hpp" 13 14 namespace Ipopt 15 { 16 /** This is a wrapper around a given TNLP class that takes out a 17 * list of constraints that are given to the constructor. It is 18 * provided for convenience, if one wants to experiment with 19 * problems that consist of only a subset of the constraints. But 20 * keep in mind that this is not efficient, since behind the scenes 21 * we are still evaluation all functions and derivatives, and are 22 * making copies of the original data. */ 23 class TNLPReducer : public TNLP 24 { 25 public: 26 /**@name Constructors/Destructors */ 27 //@{ 28 /** Constructor is given the indices of the constraints that 29 * should be taken out of the problem statement, as well as the 30 * original TNLP. */ 31 TNLPReducer(TNLP& tnlp, Index n_g_skip, const Index* index_g_skip, 32 Index n_xL_skip, const Index* index_xL_skip, 33 Index n_xU_skip, const Index* index_xU_skip, 34 Index n_x_fix, const Index* index_f_fix); 35 36 /** Default destructor */ 37 virtual ~TNLPReducer(); 38 //@} 39 40 /** @name Overloaded methods from TNLP */ 41 virtual bool get_nlp_info(Index& n, Index& m, Index& nnz_jac_g, 42 Index& nnz_h_lag, IndexStyleEnum& index_style); 43 44 virtual bool get_bounds_info(Index n, Number* x_l, Number* x_u, 45 Index m, Number* g_l, Number* g_u); 46 47 virtual bool get_scaling_parameters(Number& obj_scaling, 48 bool& use_x_scaling, Index n, 49 Number* x_scaling, 50 bool& use_g_scaling, Index m, 51 Number* g_scaling); 52 53 virtual bool get_variables_linearity(Index n, LinearityType* var_types); 54 55 virtual bool get_constraints_linearity(Index m, LinearityType* const_types); 56 57 virtual bool get_starting_point(Index n, bool init_x, Number* x, 58 bool init_z, Number* z_L, Number* z_U, 59 Index m, bool init_lambda, 60 Number* lambda); 61 62 virtual bool get_warm_start_iterate(IteratesVector& warm_start_iterate); 63 64 virtual bool eval_f(Index n, const Number* x, bool new_x, 65 Number& obj_value); 66 67 virtual bool eval_grad_f(Index n, const Number* x, bool new_x, 68 Number* grad_f); 69 70 virtual bool eval_g(Index n, const Number* x, bool new_x, 71 Index m, Number* g); 72 73 virtual bool eval_jac_g(Index n, const Number* x, bool new_x, 74 Index m, Index nele_jac, Index* iRow, 75 Index *jCol, Number* values); 76 77 virtual bool eval_h(Index n, const Number* x, bool new_x, 78 Number obj_factor, Index m, const Number* lambda, 79 bool new_lambda, Index nele_hess, 80 Index* iRow, Index* jCol, Number* values); 81 82 virtual void finalize_solution(SolverReturn status, 83 Index n, const Number* x, const Number* z_L, const Number* z_U, 84 Index m, const Number* g, const Number* lambda, 85 Number obj_value, 86 const IpoptData* ip_data, 87 IpoptCalculatedQuantities* ip_cq); 88 89 virtual bool intermediate_callback(AlgorithmMode mode, 90 Index iter, Number obj_value, 91 Number inf_pr, Number inf_du, 92 Number mu, Number d_norm, 93 Number regularization_size, 94 Number alpha_du, Number alpha_pr, 95 Index ls_trials, 96 const IpoptData* ip_data, 97 IpoptCalculatedQuantities* ip_cq); 98 99 virtual Index get_number_of_nonlinear_variables(); 100 101 virtual bool get_list_of_nonlinear_variables(Index num_nonlin_vars, 102 Index* pos_nonlin_vars); 103 //@} 104 105 private: 106 /**@name Default Compiler Generated Methods 107 * (Hidden to avoid implicit creation/calling). 108 * These methods are not implemented and 109 * we do not want the compiler to implement 110 * them for us, so we declare them private 111 * and do not define them. This ensures that 112 * they will not be implicitly created/called. */ 113 //@{ 114 /** Default Constructor */ 115 TNLPReducer(); 116 117 /** Copy Constructor */ 118 TNLPReducer(const TNLPReducer&); 119 120 /** Overloaded Equals Operator */ 121 void operator=(const TNLPReducer&); 122 //@} 123 124 /** @name original TNLP */ 125 //@{ 126 SmartPtr<TNLP> tnlp_; 127 Index m_orig_; 128 Index nnz_jac_g_orig_; 129 //@} 130 131 /** Number of constraints to be skipped */ 132 Index n_g_skip_; 133 134 /** Array of indices of the constraints that are to be skipped. 135 * This is provided at the beginning in the constructor. */ 136 Index* index_g_skip_; 137 138 /** Index style for original problem. Internally, we use C-Style 139 * now. */ 140 IndexStyleEnum index_style_orig_; 141 142 /** Map from original constraints to new constraints. A -1 means 143 * that a constraint is skipped. */ 144 Index* g_keep_map_; 145 146 /** Number of constraints in reduced NLP */ 147 Index m_reduced_; 148 149 /** Number of Jacobian nonzeros in the reduced NLP */ 150 Index nnz_jac_g_reduced_; 151 152 /** Number of Jacobian nonzeros that are skipped */ 153 Index nnz_jac_g_skipped_; 154 155 /** Array of Jacobian elements that are to be skipped. This is in 156 * increasing order. */ 157 Index* jac_g_skipped_; 158 159 /** Number of lower variable bounds to be skipped. */ 160 Index n_xL_skip_; 161 162 /** Array of indices of the lower variable bounds to be skipped. */ 163 Index* index_xL_skip_; 164 165 /** Number of upper variable bounds to be skipped. */ 166 Index n_xU_skip_; 167 168 /** Array of indices of the upper variable bounds to be skipped. */ 169 Index* index_xU_skip_; 170 171 /** Number of variables that are to be fixed to initial value. */ 172 Index n_x_fix_; 173 174 /** Array of indices of the variables that are to be fixed. */ 175 Index* index_x_fix_; 176 }; 177 178 } // namespace Ipopt 179 180 #endif 181