1 /* _______________________________________________________________________ 2 3 DAKOTA: Design Analysis Kit for Optimization and Terascale Applications 4 Copyright 2014-2020 National Technology & Engineering Solutions of Sandia, LLC (NTESS). 5 This software is distributed under the GNU Lesser General Public License. 6 For more information, see the README file in the top Dakota directory. 7 _______________________________________________________________________ */ 8 9 //- Class: rSQPOptimizer 10 //- Description: Wrapper class for rSQP++ 11 //- Owner: Roscoe Bartlett 12 //- Checked by: 13 //- Version: $Id: rSQPOptimizer.H 6492 2009-12-19 00:04:28Z briadam $ 14 15 #ifndef RSQP_OPTIMIZER_H 16 #define RSQP_OPTIMIZER_H 17 18 #include "DakotaOptimizer.H" 19 #include "NLPInterfacePack/src/serial/NLPSerialPreprocessExplJac.hpp" 20 21 namespace Dakota { 22 class rSQPOptimizer; 23 } // namespace Dakota 24 25 namespace NLPInterfacePack { 26 27 class NLPDakota : public NLPSerialPreprocessExplJac 28 { 29 public: 30 31 /** @name Constructors / initializers */ 32 //@{ 33 34 /// 35 /** Constructor. 36 * 37 * ToDo: Finish documentation! 38 */ 39 NLPDakota( 40 Dakota::Model *model 41 ,rSQPOptimizer *dakota_rsqp_opt 42 ,size_type num_lin_eq 43 ,size_type num_nonlin_eq 44 ,size_type num_lin_ineq 45 ,size_type num_nonlin_ineq 46 ); 47 48 //@} 49 50 /** @name Accessors */ 51 //@{ 52 53 /// dakota_x()54 const Dakota::RealVector& dakota_x() const { return dakota_x_; } 55 /// dakota_functions()56 const Dakota::RealVector& dakota_functions() const { return dakota_functions_; } 57 58 //@} 59 60 /** @name Overridden public members from NLP */ 61 //@{ 62 63 /// 64 void initialize(bool test_setup); 65 /// 66 bool is_initialized() const; 67 /// 68 value_type max_var_bounds_viol() const; 69 /// 70 void set_multi_calc(bool multi_calc) const; 71 /// 72 bool multi_calc() const; 73 74 //@} 75 76 /** @name Overridden from NLPVarReductPerm */ 77 //@{ 78 79 /// 80 bool nlp_selects_basis() const; 81 82 //@} 83 84 protected: 85 86 /** @name Overridden protected methods from NLPSerialPreprocess */ 87 //@{ 88 89 /// 90 bool imp_nlp_has_changed() const; 91 /// 92 size_type imp_n_orig() const; 93 /// 94 size_type imp_m_orig() const; 95 /// 96 size_type imp_mI_orig() const; 97 /// 98 const DVectorSlice imp_xinit_orig() const; 99 /// 100 bool imp_has_var_bounds() const; 101 /// 102 const DVectorSlice imp_xl_orig() const; 103 /// 104 const DVectorSlice imp_xu_orig() const; 105 /// 106 const DVectorSlice imp_hl_orig() const; 107 /// 108 const DVectorSlice imp_hu_orig() const; 109 /// 110 void imp_calc_f_orig( 111 const DVectorSlice &x_full 112 ,bool newx 113 ,const ZeroOrderInfoSerial &zero_order_info 114 ) const; 115 /// 116 void imp_calc_c_orig( 117 const DVectorSlice &x_full 118 ,bool newx 119 ,const ZeroOrderInfoSerial &zero_order_info 120 ) const; 121 /// 122 void imp_calc_h_orig( 123 const DVectorSlice &x_full 124 ,bool newx 125 ,const ZeroOrderInfoSerial &zero_order_info 126 ) const; 127 /// 128 void imp_calc_Gf_orig( 129 const DVectorSlice &x_full 130 ,bool newx 131 ,const ObjGradInfoSerial &obj_grad_info 132 ) const; 133 /// 134 void imp_report_orig_final_solution( 135 const DVectorSlice &x_orig 136 ,const DVectorSlice *lambda_orig 137 ,const DVectorSlice *lambdaI_orig 138 ,const DVectorSlice *nu_orig 139 ,bool is_optimal 140 ) const; 141 142 //@} 143 144 /** @name Overridden protected methods from NLPSerialPreprocessExplJac */ 145 //@{ 146 147 /// 148 size_type imp_Gc_nz_orig() const; 149 /// 150 size_type imp_Gh_nz_orig() const; 151 /// 152 void imp_calc_Gc_orig( 153 const DVectorSlice& x_full, bool newx 154 ,const FirstOrderExplInfo& first_order_expl_info 155 ) const; 156 /// 157 void imp_calc_Gh_orig( 158 const DVectorSlice& x_full, bool newx 159 ,const FirstOrderExplInfo& first_order_expl_info 160 ) const; 161 162 //@} 163 164 private: 165 166 // ///////////////////////////////////////// 167 // Private types 168 169 enum ERequiredFunc { 170 CALC_F = 0 171 ,CALC_C = 1 172 ,CALC_H = 2 173 ,CALC_GF = 3 174 ,CALC_GC = 4 175 ,CALC_GH = 5 176 }; 177 178 // ///////////////////////////////////////// 179 // Private data members 180 181 Dakota::Model *model_; 182 rSQPOptimizer *dakota_rsqp_opt_; 183 int num_objectives_; 184 185 bool is_initialized_; 186 187 bool has_var_bounds_; 188 189 mutable bool multi_calc_; 190 191 Dakota::RealVector multi_obj_weights_; 192 size_type num_lin_eq_; 193 size_type num_nonlin_eq_; 194 size_type num_lin_ineq_; 195 size_type num_nonlin_ineq_; 196 197 value_type invalid_func_value_; 198 value_type dakota_failed_value_; 199 200 size_type n_orig_; 201 size_type m_orig_; 202 size_type mI_orig_; 203 204 size_type Gc_orig_nz_; 205 size_type Gh_orig_nz_; 206 207 DVector xinit_orig_; 208 DVector xl_orig_; 209 DVector xu_orig_; 210 DVector hl_orig_; 211 DVector hu_orig_; 212 213 mutable bool f_orig_updated_; 214 mutable bool c_orig_updated_; 215 mutable bool h_orig_updated_; 216 mutable bool Gf_orig_updated_; 217 mutable bool Gc_orig_updated_; 218 mutable bool Gh_orig_updated_; 219 220 mutable Dakota::RealVector dakota_x_; 221 mutable Dakota::RealVector dakota_functions_; 222 mutable Dakota::ShortArray dakota_asv_; 223 224 // ///////////////////////////////////////// 225 // Private member functions 226 227 /// 228 void assert_is_initialized() const; 229 230 /// 231 void imp_calc_point( 232 ERequiredFunc required 233 ,const DVectorSlice &x_full 234 ,bool newx 235 ,const ZeroOrderInfoSerial *zero_order_info 236 ,const ObjGradInfoSerial *obj_grad_info 237 ,const FirstOrderExplInfo *first_order_expl_info 238 ) const; 239 240 // Not defined and not to be called 241 NLPDakota(); 242 NLPDakota(const NLPDakota&); 243 NLPDakota& operator=(const NLPDakota&); 244 245 }; // end class NLPDakota 246 247 } // end namespace NLPInterfacePack 248 249 250 namespace Dakota { 251 252 /// 253 /** Wrapper class for the rSQP++ optimization library. 254 * 255 * The rSQPOptimizer class provides a wrapper for rSQP++, a C++ 256 * sequential quadratic programming library written by Roscoe Bartlett. 257 * rSQP++ can currently be used in NAND mode, although use of its SAND 258 * mode for reduced-space SQP is planned. rSQPOptimizer uses a 259 * NLPDakota object to perform the function evaluations. 260 * 261 * The user input mappings will ultimately include: 262 * <tt>max_iterations</tt>, <tt>convergence_tolerance</tt>, 263 * <tt>output_verbosity</tt>. 264 */ 265 266 class rSQPOptimizer: public Optimizer 267 { 268 public: 269 270 /// 271 rSQPOptimizer(Model& model); 272 273 /// 274 ~rSQPOptimizer(); 275 276 /// num_objectives()277 int num_objectives() const 278 { return numObjectiveFns; } 279 /// lin_ineq_lb()280 const RealVector& lin_ineq_lb() const 281 { return iteratedModel.linear_ineq_constraint_lower_bounds(); } 282 /// lin_ineq_ub()283 const RealVector& lin_ineq_ub() const 284 { return iteratedModel.linear_ineq_constraint_upper_bounds(); } 285 /// nonlin_ineq_lb()286 const RealVector& nonlin_ineq_lb() const 287 { return iteratedModel.nonlinear_ineq_constraint_lower_bounds(); } 288 /// nonlin_ineq_ub()289 const RealVector& nonlin_ineq_ub() const 290 { return iteratedModel.nonlinear_ineq_constraint_upper_bounds(); } 291 /// lin_eq_targ()292 const RealVector& lin_eq_targ() const 293 { return iteratedModel.linear_eq_constraint_targets(); } 294 /// nonlin_eq_targ()295 const RealVector& nonlin_eq_targ() const 296 { return iteratedModel.nonlinear_eq_constraint_targets(); } 297 /// lin_eq_jac()298 const RealMatrix& lin_eq_jac() const 299 { return iteratedModel.linear_eq_constraint_coeffs(); } 300 /// lin_ineq_jac()301 const RealMatrix& lin_ineq_jac() const 302 { return iteratedModel.linear_ineq_constraint_coeffs(); } 303 304 /** @name Overridden from Optimizer */ 305 //@{ 306 307 /// 308 void find_optimum(); 309 310 //@} 311 312 private: 313 314 Model *model_; 315 NLPInterfacePack::NLPDakota nlp_; 316 317 }; 318 319 } // namespace Dakota 320 321 #endif 322