|
MoochoPack : Framework for Large-Scale Optimization Algorithms
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 RSQP_STATE_H 00043 #define RSQP_STATE_H 00044 00045 #include <deque> 00046 00047 #include "MoochoPack_Types.hpp" 00048 #include "IterationPack_IterQuantityAccess.hpp" 00049 #include "IterationPack_AlgorithmState.hpp" 00050 #include "IterationPack_cast_iq.hpp" 00051 #include "IterationPack_IterQuantityAccessContiguous.hpp" 00052 #include "AbstractLinAlgPack_VectorSpace.hpp" 00053 #include "AbstractLinAlgPack_Permutation.hpp" 00054 #include "ConstrainedOptPack_DecompositionSystem.hpp" 00055 #include "AbstractLinAlgPack_MatrixOp.hpp" 00056 //#include "DenseLinAlgPack_IVector.hpp" 00057 #include "Teuchos_StandardCompositionMacros.hpp" 00058 #include "Teuchos_StandardMemberCompositionMacros.hpp" 00059 00060 namespace MoochoPack { 00061 00067 00068 // Iteration Info 00069 extern const std::string num_basis_name; 00070 // NLP Problem Info 00071 extern const std::string x_name; 00072 extern const std::string f_name; 00073 extern const std::string Gf_name; 00074 extern const std::string HL_name; 00075 extern const std::string c_name; 00076 extern const std::string h_name; 00077 extern const std::string Gc_name; 00078 // Constraint Gradient Null Space / Range Space Decomposition Info 00079 extern const std::string Y_name; 00080 extern const std::string Z_name; 00081 extern const std::string R_name; 00082 extern const std::string Uy_name; 00083 extern const std::string Uz_name; 00084 // Search Direction Info 00085 extern const std::string py_name; 00086 extern const std::string Ypy_name; 00087 extern const std::string pz_name; 00088 extern const std::string Zpz_name; 00089 extern const std::string d_name; 00090 // Reduced QP Subproblem Info 00091 extern const std::string rGf_name; 00092 extern const std::string rHL_name; 00093 extern const std::string w_name; 00094 extern const std::string zeta_name; 00095 extern const std::string qp_grad_name; 00096 extern const std::string eta_name; 00097 // Global Convergence Info 00098 extern const std::string alpha_name; 00099 extern const std::string merit_func_nlp_name; 00100 extern const std::string mu_name; 00101 extern const std::string phi_name; 00102 // KKT Info 00103 extern const std::string opt_kkt_err_name; 00104 extern const std::string feas_kkt_err_name; 00105 extern const std::string comp_kkt_err_name; 00106 extern const std::string GL_name; 00107 extern const std::string rGL_name; 00108 extern const std::string lambda_name; 00109 extern const std::string nu_name; 00110 00112 00123 00126 #define STATE_IQ_DECL(TYPE,NAME) \ 00127 virtual IterQuantityAccess<TYPE>& NAME(); \ 00128 virtual const IterQuantityAccess<TYPE>& NAME() const; \ 00129 private: \ 00130 iq_id_encap NAME ## _iq_id_; \ 00131 public: 00132 00135 #define STATE_INDEX_IQ_DECL(NAME) \ 00136 STATE_IQ_DECL(index_type,NAME) \ 00137 00138 00140 #define STATE_SCALAR_IQ_DECL(NAME) \ 00141 STATE_IQ_DECL(value_type,NAME) \ 00142 00143 00145 #define STATE_VECTOR_IQ_DECL(NAME) \ 00146 STATE_IQ_DECL(VectorMutable,NAME) \ 00147 00148 00155 #define STATE_IQ_DEF(CLASS,TYPE,NAME,NAME_STR) \ 00156 IterQuantityAccess<TYPE>& \ 00157 CLASS::NAME() \ 00158 { \ 00159 update_iq_id( NAME_STR, &NAME ## _iq_id_ ); \ 00160 return IterationPack::cast_iq<TYPE>( \ 00161 *this, NAME ## _iq_id_.iq_id, NAME_STR ); \ 00162 } \ 00163 const IterQuantityAccess<TYPE>& \ 00164 CLASS::NAME() const \ 00165 { \ 00166 return const_cast<CLASS*>(this)->NAME(); \ 00167 } 00168 00173 #define STATE_INDEX_IQ_DEF(CLASS,NAME,NAME_STR) \ 00174 IterQuantityAccess<index_type>& \ 00175 CLASS::NAME() \ 00176 { \ 00177 update_index_type_iq_id( NAME_STR, &NAME ## _iq_id_ ); \ 00178 return IterationPack::cast_iq<index_type>( \ 00179 *this, NAME ## _iq_id_.iq_id, NAME_STR ); \ 00180 } \ 00181 const IterQuantityAccess<index_type>& \ 00182 CLASS::NAME() const \ 00183 { \ 00184 return const_cast<CLASS*>(this)->NAME(); \ 00185 } 00186 00191 #define STATE_SCALAR_IQ_DEF(CLASS,NAME,NAME_STR) \ 00192 IterQuantityAccess<value_type>& \ 00193 CLASS::NAME() \ 00194 { \ 00195 update_value_type_iq_id( NAME_STR, &NAME ## _iq_id_ ); \ 00196 return IterationPack::cast_iq<value_type>( \ 00197 *this, NAME ## _iq_id_.iq_id, NAME_STR ); \ 00198 } \ 00199 const IterQuantityAccess<value_type>& \ 00200 CLASS::NAME() const \ 00201 { \ 00202 return const_cast<CLASS*>(this)->NAME(); \ 00203 } 00204 00214 #define STATE_VECTOR_IQ_DEF(CLASS,NAME,NAME_STR,VEC_SPC,VEC_RN) \ 00215 IterQuantityAccess<VectorMutable>& \ 00216 CLASS::NAME() \ 00217 { \ 00218 update_vector_iq_id( NAME_STR, VEC_SPC, VEC_RN, &NAME ## _iq_id_ ); \ 00219 return IterationPack::cast_iq<VectorMutable>( \ 00220 *this, NAME ## _iq_id_.iq_id, NAME_STR ); \ 00221 } \ 00222 const IterQuantityAccess<VectorMutable>& \ 00223 CLASS::NAME() const \ 00224 { \ 00225 return const_cast<CLASS*>(this)->NAME(); \ 00226 } 00227 00229 00264 class NLPAlgoState 00265 : public IterationPack::AlgorithmState // doxygen needs full path 00266 { 00267 public: 00268 00271 00273 class InvalidType : public std::logic_error 00274 {public: InvalidType(const std::string& what_arg) : std::logic_error(what_arg) {}}; 00275 00277 typedef Teuchos::RCP<const VectorSpace> vec_space_ptr_t; 00278 00280 00281 protected: 00282 00283 // ///////////////////////////// 00284 // Protected types. 00285 00287 struct iq_id_encap { 00288 iq_id_encap() : iq_id(DOES_NOT_EXIST) {} 00289 iq_id_type iq_id; 00290 }; 00291 00292 public: 00293 00296 00297 // ToDo: Implement all set_space_xx methods to update factories 00298 // for all vector iteration quantities. 00299 00301 STANDARD_COMPOSITION_MEMBERS( DecompositionSystem, decomp_sys ); 00303 STANDARD_CONST_COMPOSITION_MEMBERS( VectorSpace, space_x ); 00305 STANDARD_CONST_COMPOSITION_MEMBERS( VectorSpace, space_c ); 00312 void set_space_range (const vec_space_ptr_t& space_range ); 00313 vec_space_ptr_t& get_space_range(); 00314 const vec_space_ptr_t& get_space_range() const; 00315 const VectorSpace& space_range() const; 00322 void set_space_null (const vec_space_ptr_t& space_null ); 00323 vec_space_ptr_t& get_space_null(); 00324 const vec_space_ptr_t& get_space_null() const; 00325 const VectorSpace& space_null() const; 00326 00331 NLPAlgoState( 00332 const decomp_sys_ptr_t& decomp_sys = Teuchos::null 00333 ,const vec_space_ptr_t& space_x = Teuchos::null 00334 ,const vec_space_ptr_t& space_c = Teuchos::null 00335 ,const vec_space_ptr_t& space_range = Teuchos::null 00336 ,const vec_space_ptr_t& space_null = Teuchos::null 00337 ); 00338 00340 virtual ~NLPAlgoState() {} 00341 00343 00346 00348 STATE_INDEX_IQ_DECL(num_basis) 00349 00350 //@} 00351 00352 00354 00356 STATE_VECTOR_IQ_DECL(x) 00358 STATE_SCALAR_IQ_DECL(f) 00360 STATE_VECTOR_IQ_DECL(Gf) 00362 STATE_IQ_DECL(MatrixSymOp,HL) 00364 STATE_VECTOR_IQ_DECL(c) 00366 STATE_IQ_DECL(MatrixOp,Gc) 00367 00369 00372 00374 STATE_IQ_DECL(MatrixOp,Y) 00376 STATE_IQ_DECL(MatrixOp,Z) 00378 STATE_IQ_DECL(MatrixOpNonsing,R) 00380 STATE_IQ_DECL(MatrixOp,Uy) 00382 STATE_IQ_DECL(MatrixOp,Uz) 00383 00385 00388 00390 STATE_VECTOR_IQ_DECL(py) 00392 STATE_VECTOR_IQ_DECL(Ypy) 00394 STATE_VECTOR_IQ_DECL(pz) 00396 STATE_VECTOR_IQ_DECL(Zpz) 00398 STATE_VECTOR_IQ_DECL(d) 00399 00401 00404 00406 STATE_VECTOR_IQ_DECL(rGf) 00408 STATE_IQ_DECL(MatrixSymOp,rHL) 00410 STATE_VECTOR_IQ_DECL(w) 00412 STATE_SCALAR_IQ_DECL(zeta) 00414 STATE_VECTOR_IQ_DECL(qp_grad) 00416 STATE_SCALAR_IQ_DECL(eta) 00417 00419 00422 00424 STATE_SCALAR_IQ_DECL(alpha) 00426 STATE_IQ_DECL(MeritFuncNLP,merit_func_nlp) 00428 STATE_SCALAR_IQ_DECL(mu) 00430 STATE_SCALAR_IQ_DECL(phi) 00431 00433 00436 00438 STATE_SCALAR_IQ_DECL(opt_kkt_err) 00440 STATE_SCALAR_IQ_DECL(feas_kkt_err) 00442 STATE_SCALAR_IQ_DECL(comp_kkt_err) 00444 STATE_VECTOR_IQ_DECL(GL) 00446 STATE_VECTOR_IQ_DECL(rGL) 00448 STATE_VECTOR_IQ_DECL(lambda) 00450 STATE_VECTOR_IQ_DECL(nu) 00451 00453 00456 00458 STANDARD_MEMBER_COMPOSITION_MEMBERS( Range1D, var_dep ); 00460 STANDARD_MEMBER_COMPOSITION_MEMBERS( Range1D, var_indep ); 00461 00463 STANDARD_MEMBER_COMPOSITION_MEMBERS( Range1D, equ_decomp ); 00465 STANDARD_MEMBER_COMPOSITION_MEMBERS( Range1D, equ_undecomp ); 00466 00468 00471 00473 STANDARD_COMPOSITION_MEMBERS( Permutation, P_var_current ); 00475 STANDARD_COMPOSITION_MEMBERS( Permutation, P_var_last ); 00477 STANDARD_COMPOSITION_MEMBERS( Permutation, P_equ_current ); 00479 STANDARD_COMPOSITION_MEMBERS( Permutation, P_equ_last ); 00480 00482 00483 protected: 00484 00485 enum { NUM_VEC_SPACE_TYPES = 5 }; 00486 enum EVecSpaceType { 00487 VST_SPACE_X = 0 00488 ,VST_SPACE_C = 1 00489 ,VST_SPACE_RANGE = 2 00490 ,VST_SPACE_NULL = 3 00491 }; 00492 00493 // ///////////////////////////// 00494 // Protected member functions 00495 00496 // These implementations are used to avoid code blot and help in debugging 00497 // (can't debug macros very well). 00498 00500 void update_iq_id( 00501 const std::string& iq_name 00502 ,iq_id_encap* iq_id 00503 ) const; 00505 void update_index_type_iq_id( 00506 const std::string& iq_name 00507 ,iq_id_encap* iq_id 00508 ); 00510 void update_value_type_iq_id( 00511 const std::string& iq_name 00512 ,iq_id_encap* iq_id 00513 ); 00515 void update_vector_iq_id( 00516 const std::string& iq_name 00517 ,const VectorSpace::space_ptr_t& vec_space 00518 ,EVecSpaceType vec_space_type 00519 ,iq_id_encap* iq_id 00520 ); 00521 00522 private: 00523 00524 // //////////////////////////// 00525 // Private types 00526 00527 typedef std::deque<iq_id_type> iq_vector_list_t; 00528 00529 // //////////////////////////// 00530 // Private data member 00531 00532 vec_space_ptr_t space_range_; 00533 vec_space_ptr_t space_null_; 00534 00535 iq_vector_list_t vector_iqs_lists_[NUM_VEC_SPACE_TYPES]; 00536 00537 // //////////////////////////// 00538 // Private member functions. 00539 00540 // Update the vector factories for all of the iteration quantities 00541 // in the input list. 00542 void update_vector_factories( 00543 EVecSpaceType vec_space_type 00544 ,const vec_space_ptr_t& vec_space 00545 ); 00546 00547 // not defined and not to be called 00548 NLPAlgoState(const NLPAlgoState&); 00549 NLPAlgoState& operator=(const NLPAlgoState&); 00550 00551 }; // end class NLPAlgoState 00552 00553 // //////////////////////////////////// 00554 // Inline members 00555 00556 inline 00557 NLPAlgoState::vec_space_ptr_t& NLPAlgoState::get_space_range() 00558 { return space_range_ ; } 00559 00560 inline 00561 const NLPAlgoState::vec_space_ptr_t& NLPAlgoState::get_space_range() const 00562 { return space_range_; } 00563 00564 inline 00565 const VectorSpace& NLPAlgoState::space_range() const 00566 { return *space_range_; } 00567 00568 inline 00569 NLPAlgoState::vec_space_ptr_t& NLPAlgoState::get_space_null() 00570 { return space_null_ ; } 00571 00572 inline 00573 const NLPAlgoState::vec_space_ptr_t& NLPAlgoState::get_space_null() const 00574 { return space_null_; } 00575 00576 inline 00577 const VectorSpace& NLPAlgoState::space_null() const 00578 { return *space_null_; } 00579 00580 } // end namespace MoochoPack 00581 00582 #endif // RSQP_STATE_H
1.7.6.1