|
NLPInterfacePack: C++ Interfaces and Implementation for Non-Linear Programs
Version of the Day
|
00001 // @HEADER 00002 // *********************************************************************** 00003 // 00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization 00005 // Copyright (2003) Sandia Corporation 00006 // 00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive 00008 // license for use of this work by or on behalf of the U.S. Government. 00009 // 00010 // Redistribution and use in source and binary forms, with or without 00011 // modification, are permitted provided that the following conditions are 00012 // met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. Neither the name of the Corporation nor the names of the 00022 // contributors may be used to endorse or promote products derived from 00023 // this software without specific prior written permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY 00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE 00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00036 // 00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 00038 // 00039 // *********************************************************************** 00040 // @HEADER 00041 00042 #ifndef NLP_SERIAL_PREPROCESS_EXPL_JAC_H 00043 #define NLP_SERIAL_PREPROCESS_EXPL_JAC_H 00044 00045 #include <valarray> 00046 00047 #include "NLPInterfacePack_NLPSerialPreprocess.hpp" 00048 #include "NLPInterfacePack_NLPFirstOrder.hpp" 00049 #include "AbstractLinAlgPack_BasisSystemFactoryStd.hpp" 00050 #include "DenseLinAlgPack_DVectorClass.hpp" 00051 #include "Teuchos_AbstractFactory.hpp" 00052 #include "Teuchos_StandardCompositionMacros.hpp" 00053 00054 namespace NLPInterfacePack { 00055 00093 class NLPSerialPreprocessExplJac 00094 : virtual public NLPSerialPreprocess 00095 , virtual public NLPFirstOrder 00096 { 00097 public: 00098 00101 00103 typedef Teuchos::RCP< 00104 const Teuchos::AbstractFactory<MatrixOp> > factory_mat_ptr_t; 00105 00107 00110 00112 STANDARD_COMPOSITION_MEMBERS( BasisSystemFactory, basis_sys_fcty ); 00113 00116 NLPSerialPreprocessExplJac( 00117 const basis_sys_fcty_ptr_t &basis_sys_fcty = Teuchos::rcp(new BasisSystemFactoryStd()) 00118 ,const factory_mat_ptr_t &factory_Gc_full = Teuchos::null 00119 ); 00120 00131 void set_factory_Gc_full( const factory_mat_ptr_t &factory_Gc_full ); 00132 00134 00137 00139 void set_options( const options_ptr_t& options ); 00141 const options_ptr_t& get_options() const; 00143 void initialize(bool test_setup); 00145 bool is_initialized() const; 00146 00148 00151 00153 const mat_fcty_ptr_t factory_Gc() const; 00155 const basis_sys_ptr_t basis_sys() const; 00157 void set_Gc(MatrixOp* Gc); 00158 00160 00163 00165 bool get_next_basis( 00166 Permutation* P_var, Range1D* var_dep 00167 ,Permutation* P_equ, Range1D* equ_decomp 00168 ); 00170 void set_basis( 00171 const Permutation &P_var, const Range1D &var_dep 00172 ,const Permutation *P_equ, const Range1D *equ_decomp 00173 ); 00174 00176 00177 00178 protected: 00179 00182 00184 void imp_calc_Gc( 00185 const Vector& x, bool newx 00186 ,const FirstOrderInfo& first_order_info 00187 ) const; 00188 00190 00193 00227 struct FirstOrderExplInfo { 00229 typedef std::valarray<value_type> val_t; 00231 typedef std::valarray<index_type> ivect_t; 00232 // 00233 typedef std::valarray<index_type> jvect_t; 00235 FirstOrderExplInfo() 00236 :Gc_val(NULL), Gc_ivect(NULL), Gc_jvect(NULL) 00237 ,Gh_val(NULL), Gh_ivect(NULL), Gh_jvect(NULL) 00238 ,f(NULL) 00239 {} 00241 FirstOrderExplInfo( 00242 index_type* Gc_nz_in, val_t* Gc_val_in, ivect_t* Gc_ivect_in, jvect_t* Gc_jvect_in 00243 ,index_type* Gh_nz_in, val_t* Gh_val_in, ivect_t* Gh_ivect_in, jvect_t* Gh_jvect_in 00244 ,const ObjGradInfoSerial& obj_grad 00245 ) 00246 :Gc_nz(Gc_nz_in), Gc_val(Gc_val_in), Gc_ivect(Gc_ivect_in), Gc_jvect(Gc_jvect_in) 00247 ,Gh_nz(Gh_nz_in), Gh_val(Gh_val_in), Gh_ivect(Gh_ivect_in), Gh_jvect(Gh_jvect_in) 00248 ,Gf(obj_grad.Gf), f(obj_grad.f), c(obj_grad.c), h(obj_grad.h) 00249 {} 00251 size_type* Gc_nz; 00253 val_t* Gc_val; 00255 ivect_t* Gc_ivect; 00257 jvect_t* Gc_jvect; 00259 size_type* Gh_nz; 00261 val_t* Gh_val; 00263 ivect_t* Gh_ivect; 00265 jvect_t* Gh_jvect; 00267 DVector* Gf; 00269 value_type* f; 00271 DVector* c; 00273 DVector* h; 00274 }; // end struct FirstOrderExplInfo 00275 00277 00280 00287 virtual size_type imp_Gc_nz_orig() const = 0; 00288 00295 virtual size_type imp_Gh_nz_orig() const = 0; 00296 00337 virtual void imp_calc_Gc_orig( 00338 const DVectorSlice& x_full, bool newx 00339 , const FirstOrderExplInfo& first_order_expl_info 00340 ) const = 0; 00341 00382 virtual void imp_calc_Gh_orig( 00383 const DVectorSlice& x_full, bool newx 00384 , const FirstOrderExplInfo& first_order_expl_info 00385 ) const = 0; 00386 00388 00391 00393 void assert_initialized() const; 00394 00396 const FirstOrderExplInfo first_order_expl_info() const; 00397 00399 00400 private: 00401 00402 // //////////////////////////////////////// 00403 // Private data members 00404 00405 bool initialized_; // Flag for if the NLP has has been properly initialized 00406 bool test_setup_; // Flag for if to test the setup of things or not 00407 options_ptr_t options_; // The options being used 00408 00409 factory_mat_ptr_t factory_Gc_full_; 00410 mat_fcty_ptr_t factory_Gc_; 00411 00412 mutable size_type Gc_nz_orig_; // Number of nonzeros in the original NLP Gc 00413 mutable size_type Gh_nz_orig_; // Number of nonzeros in the original NLP Gh 00414 mutable size_type Gc_nz_full_; // Number of nonzeros in the full NLP Gc 00415 mutable size_type Gh_nz_full_; // Number of nonzeros in the full NLP Gh 00416 mutable FirstOrderExplInfo::val_t Gc_val_orig_; // Storage for explicit nonzeros of full Gc 00417 mutable FirstOrderExplInfo::ivect_t Gc_ivect_orig_; 00418 mutable FirstOrderExplInfo::jvect_t Gc_jvect_orig_; 00419 mutable FirstOrderExplInfo::val_t Gh_val_orig_; // Storage for explicit nonzeros of orig Gh 00420 mutable FirstOrderExplInfo::ivect_t Gh_ivect_orig_; 00421 mutable FirstOrderExplInfo::jvect_t Gh_jvect_orig_; 00422 00423 mutable bool Gc_perm_new_basis_updated_; // Flag for if a new basis was set! 00424 00425 // //////////////////////////// 00426 // Private member functions 00427 00428 // 00429 void imp_calc_Gc_or_Gh( 00430 bool calc_Gc 00431 ,const Vector& x, bool newx 00432 ,const FirstOrderInfo& first_order_info 00433 ) const; 00434 00435 // 00436 void imp_fill_jacobian_entries( 00437 size_type n // [in] 00438 ,size_type n_full // [in] 00439 ,bool load_struct // [in] If true, then the structure is loaded also 00440 ,const index_type col_offset // [in] Offset for filled column indexes 00441 ,const value_type *val_full // [in] Values (!=NULL) 00442 ,const value_type *val_full_end // [in] Values end (!=NULL) 00443 ,const index_type *ivect_full // [in] Row indexes (!=NULL) 00444 ,const index_type *jvect_full // [in] Column indexes (!=NULL) 00445 ,index_type *nz // [in/out] Number of nonzeros added (!=NULL) 00446 ,value_type *val_itr // [out] Values to fill (!=NULL) 00447 ,index_type *ivect_itr // [out] Row indexes (can be NULL if load_struct == false) 00448 ,index_type *jvect_itr // [out] Column indexes (can be NULL if load_struct == false) 00449 ) const; 00450 00451 }; // end class NLPSerialPreprocessExplJac 00452 00453 // /////////////////////////// 00454 // inline members 00455 00456 inline 00457 const NLPSerialPreprocessExplJac::FirstOrderExplInfo 00458 NLPSerialPreprocessExplJac::first_order_expl_info() const 00459 { 00460 return FirstOrderExplInfo( 00461 &Gc_nz_orig_ 00462 ,&Gc_val_orig_ 00463 ,&Gc_ivect_orig_ 00464 ,&Gc_jvect_orig_ 00465 ,&Gh_nz_orig_ 00466 ,&Gh_val_orig_ 00467 ,&Gh_ivect_orig_ 00468 ,&Gh_jvect_orig_ 00469 ,obj_grad_orig_info() 00470 ); 00471 } 00472 00473 } // end namespace NLPInterfacePack 00474 00475 #endif // NLP_SERIAL_PREPROCESS_EXPL_JAC_H
1.7.6.1