00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef RSQP_STATE_H
00030 #define RSQP_STATE_H
00031
00032 #include <deque>
00033
00034 #include "MoochoPack_Types.hpp"
00035 #include "IterationPack_IterQuantityAccess.hpp"
00036 #include "IterationPack_AlgorithmState.hpp"
00037 #include "IterationPack_cast_iq.hpp"
00038 #include "IterationPack_IterQuantityAccessContiguous.hpp"
00039 #include "AbstractLinAlgPack_VectorSpace.hpp"
00040 #include "AbstractLinAlgPack_Permutation.hpp"
00041 #include "ConstrainedOptPack_DecompositionSystem.hpp"
00042 #include "AbstractLinAlgPack_MatrixOp.hpp"
00043
00044 #include "Teuchos_StandardCompositionMacros.hpp"
00045 #include "Teuchos_StandardMemberCompositionMacros.hpp"
00046
00047 namespace MoochoPack {
00048
00054
00055
00056 extern const std::string num_basis_name;
00057
00058 extern const std::string x_name;
00059 extern const std::string f_name;
00060 extern const std::string Gf_name;
00061 extern const std::string HL_name;
00062 extern const std::string c_name;
00063 extern const std::string h_name;
00064 extern const std::string Gc_name;
00065
00066 extern const std::string Y_name;
00067 extern const std::string Z_name;
00068 extern const std::string R_name;
00069 extern const std::string Uy_name;
00070 extern const std::string Uz_name;
00071
00072 extern const std::string py_name;
00073 extern const std::string Ypy_name;
00074 extern const std::string pz_name;
00075 extern const std::string Zpz_name;
00076 extern const std::string d_name;
00077
00078 extern const std::string rGf_name;
00079 extern const std::string rHL_name;
00080 extern const std::string w_name;
00081 extern const std::string zeta_name;
00082 extern const std::string qp_grad_name;
00083 extern const std::string eta_name;
00084
00085 extern const std::string alpha_name;
00086 extern const std::string merit_func_nlp_name;
00087 extern const std::string mu_name;
00088 extern const std::string phi_name;
00089
00090 extern const std::string opt_kkt_err_name;
00091 extern const std::string feas_kkt_err_name;
00092 extern const std::string comp_kkt_err_name;
00093 extern const std::string GL_name;
00094 extern const std::string rGL_name;
00095 extern const std::string lambda_name;
00096 extern const std::string nu_name;
00097
00099
00110
00113 #define STATE_IQ_DECL(TYPE,NAME) \
00114 virtual IterQuantityAccess<TYPE>& NAME(); \
00115 virtual const IterQuantityAccess<TYPE>& NAME() const; \
00116 private: \
00117 iq_id_encap NAME ## _iq_id_; \
00118 public:
00119
00122 #define STATE_INDEX_IQ_DECL(NAME) \
00123 STATE_IQ_DECL(index_type,NAME) \
00124
00125
00127 #define STATE_SCALAR_IQ_DECL(NAME) \
00128 STATE_IQ_DECL(value_type,NAME) \
00129
00130
00132 #define STATE_VECTOR_IQ_DECL(NAME) \
00133 STATE_IQ_DECL(VectorMutable,NAME) \
00134
00135
00142 #define STATE_IQ_DEF(CLASS,TYPE,NAME,NAME_STR) \
00143 IterQuantityAccess<TYPE>& \
00144 CLASS::NAME() \
00145 { \
00146 update_iq_id( NAME_STR, &NAME ## _iq_id_ ); \
00147 return IterationPack::cast_iq<TYPE>( \
00148 *this, NAME ## _iq_id_.iq_id, NAME_STR ); \
00149 } \
00150 const IterQuantityAccess<TYPE>& \
00151 CLASS::NAME() const \
00152 { \
00153 return const_cast<CLASS*>(this)->NAME(); \
00154 }
00155
00160 #define STATE_INDEX_IQ_DEF(CLASS,NAME,NAME_STR) \
00161 IterQuantityAccess<index_type>& \
00162 CLASS::NAME() \
00163 { \
00164 update_index_type_iq_id( NAME_STR, &NAME ## _iq_id_ ); \
00165 return IterationPack::cast_iq<index_type>( \
00166 *this, NAME ## _iq_id_.iq_id, NAME_STR ); \
00167 } \
00168 const IterQuantityAccess<index_type>& \
00169 CLASS::NAME() const \
00170 { \
00171 return const_cast<CLASS*>(this)->NAME(); \
00172 }
00173
00178 #define STATE_SCALAR_IQ_DEF(CLASS,NAME,NAME_STR) \
00179 IterQuantityAccess<value_type>& \
00180 CLASS::NAME() \
00181 { \
00182 update_value_type_iq_id( NAME_STR, &NAME ## _iq_id_ ); \
00183 return IterationPack::cast_iq<value_type>( \
00184 *this, NAME ## _iq_id_.iq_id, NAME_STR ); \
00185 } \
00186 const IterQuantityAccess<value_type>& \
00187 CLASS::NAME() const \
00188 { \
00189 return const_cast<CLASS*>(this)->NAME(); \
00190 }
00191
00201 #define STATE_VECTOR_IQ_DEF(CLASS,NAME,NAME_STR,VEC_SPC,VEC_RN) \
00202 IterQuantityAccess<VectorMutable>& \
00203 CLASS::NAME() \
00204 { \
00205 update_vector_iq_id( NAME_STR, VEC_SPC, VEC_RN, &NAME ## _iq_id_ ); \
00206 return IterationPack::cast_iq<VectorMutable>( \
00207 *this, NAME ## _iq_id_.iq_id, NAME_STR ); \
00208 } \
00209 const IterQuantityAccess<VectorMutable>& \
00210 CLASS::NAME() const \
00211 { \
00212 return const_cast<CLASS*>(this)->NAME(); \
00213 }
00214
00216
00251 class NLPAlgoState
00252 : public IterationPack::AlgorithmState
00253 {
00254 public:
00255
00258
00260 class InvalidType : public std::logic_error
00261 {public: InvalidType(const std::string& what_arg) : std::logic_error(what_arg) {}};
00262
00264 typedef Teuchos::RCP<const VectorSpace> vec_space_ptr_t;
00265
00267
00268 protected:
00269
00270
00271
00272
00274 struct iq_id_encap {
00275 iq_id_encap() : iq_id(DOES_NOT_EXIST) {}
00276 iq_id_type iq_id;
00277 };
00278
00279 public:
00280
00283
00284
00285
00286
00288 STANDARD_COMPOSITION_MEMBERS( DecompositionSystem, decomp_sys );
00290 STANDARD_CONST_COMPOSITION_MEMBERS( VectorSpace, space_x );
00292 STANDARD_CONST_COMPOSITION_MEMBERS( VectorSpace, space_c );
00299 void set_space_range (const vec_space_ptr_t& space_range );
00300 vec_space_ptr_t& get_space_range();
00301 const vec_space_ptr_t& get_space_range() const;
00302 const VectorSpace& space_range() const;
00309 void set_space_null (const vec_space_ptr_t& space_null );
00310 vec_space_ptr_t& get_space_null();
00311 const vec_space_ptr_t& get_space_null() const;
00312 const VectorSpace& space_null() const;
00313
00318 NLPAlgoState(
00319 const decomp_sys_ptr_t& decomp_sys = Teuchos::null
00320 ,const vec_space_ptr_t& space_x = Teuchos::null
00321 ,const vec_space_ptr_t& space_c = Teuchos::null
00322 ,const vec_space_ptr_t& space_range = Teuchos::null
00323 ,const vec_space_ptr_t& space_null = Teuchos::null
00324 );
00325
00327 virtual ~NLPAlgoState() {}
00328
00330
00333
00335 STATE_INDEX_IQ_DECL(num_basis)
00336
00337
00338
00339
00341
00343 STATE_VECTOR_IQ_DECL(x)
00345 STATE_SCALAR_IQ_DECL(f)
00347 STATE_VECTOR_IQ_DECL(Gf)
00349 STATE_IQ_DECL(MatrixSymOp,HL)
00351 STATE_VECTOR_IQ_DECL(c)
00353 STATE_IQ_DECL(MatrixOp,Gc)
00354
00356
00359
00361 STATE_IQ_DECL(MatrixOp,Y)
00363 STATE_IQ_DECL(MatrixOp,Z)
00365 STATE_IQ_DECL(MatrixOpNonsing,R)
00367 STATE_IQ_DECL(MatrixOp,Uy)
00369 STATE_IQ_DECL(MatrixOp,Uz)
00370
00372
00375
00377 STATE_VECTOR_IQ_DECL(py)
00379 STATE_VECTOR_IQ_DECL(Ypy)
00381 STATE_VECTOR_IQ_DECL(pz)
00383 STATE_VECTOR_IQ_DECL(Zpz)
00385 STATE_VECTOR_IQ_DECL(d)
00386
00388
00391
00393 STATE_VECTOR_IQ_DECL(rGf)
00395 STATE_IQ_DECL(MatrixSymOp,rHL)
00397 STATE_VECTOR_IQ_DECL(w)
00399 STATE_SCALAR_IQ_DECL(zeta)
00401 STATE_VECTOR_IQ_DECL(qp_grad)
00403 STATE_SCALAR_IQ_DECL(eta)
00404
00406
00409
00411 STATE_SCALAR_IQ_DECL(alpha)
00413 STATE_IQ_DECL(MeritFuncNLP,merit_func_nlp)
00415 STATE_SCALAR_IQ_DECL(mu)
00417 STATE_SCALAR_IQ_DECL(phi)
00418
00420
00423
00425 STATE_SCALAR_IQ_DECL(opt_kkt_err)
00427 STATE_SCALAR_IQ_DECL(feas_kkt_err)
00429 STATE_SCALAR_IQ_DECL(comp_kkt_err)
00431 STATE_VECTOR_IQ_DECL(GL)
00433 STATE_VECTOR_IQ_DECL(rGL)
00435 STATE_VECTOR_IQ_DECL(lambda)
00437 STATE_VECTOR_IQ_DECL(nu)
00438
00440
00443
00445 STANDARD_MEMBER_COMPOSITION_MEMBERS( Range1D, var_dep );
00447 STANDARD_MEMBER_COMPOSITION_MEMBERS( Range1D, var_indep );
00448
00450 STANDARD_MEMBER_COMPOSITION_MEMBERS( Range1D, equ_decomp );
00452 STANDARD_MEMBER_COMPOSITION_MEMBERS( Range1D, equ_undecomp );
00453
00455
00458
00460 STANDARD_COMPOSITION_MEMBERS( Permutation, P_var_current );
00462 STANDARD_COMPOSITION_MEMBERS( Permutation, P_var_last );
00464 STANDARD_COMPOSITION_MEMBERS( Permutation, P_equ_current );
00466 STANDARD_COMPOSITION_MEMBERS( Permutation, P_equ_last );
00467
00469
00470 protected:
00471
00472 enum { NUM_VEC_SPACE_TYPES = 5 };
00473 enum EVecSpaceType {
00474 VST_SPACE_X = 0
00475 ,VST_SPACE_C = 1
00476 ,VST_SPACE_RANGE = 2
00477 ,VST_SPACE_NULL = 3
00478 };
00479
00480
00481
00482
00483
00484
00485
00487 void update_iq_id(
00488 const std::string& iq_name
00489 ,iq_id_encap* iq_id
00490 ) const;
00492 void update_index_type_iq_id(
00493 const std::string& iq_name
00494 ,iq_id_encap* iq_id
00495 );
00497 void update_value_type_iq_id(
00498 const std::string& iq_name
00499 ,iq_id_encap* iq_id
00500 );
00502 void update_vector_iq_id(
00503 const std::string& iq_name
00504 ,const VectorSpace::space_ptr_t& vec_space
00505 ,EVecSpaceType vec_space_type
00506 ,iq_id_encap* iq_id
00507 );
00508
00509 private:
00510
00511
00512
00513
00514 typedef std::deque<iq_id_type> iq_vector_list_t;
00515
00516
00517
00518
00519 vec_space_ptr_t space_range_;
00520 vec_space_ptr_t space_null_;
00521
00522 iq_vector_list_t vector_iqs_lists_[NUM_VEC_SPACE_TYPES];
00523
00524
00525
00526
00527
00528
00529 void update_vector_factories(
00530 EVecSpaceType vec_space_type
00531 ,const vec_space_ptr_t& vec_space
00532 );
00533
00534
00535 NLPAlgoState(const NLPAlgoState&);
00536 NLPAlgoState& operator=(const NLPAlgoState&);
00537
00538 };
00539
00540
00541
00542
00543 inline
00544 NLPAlgoState::vec_space_ptr_t& NLPAlgoState::get_space_range()
00545 { return space_range_ ; }
00546
00547 inline
00548 const NLPAlgoState::vec_space_ptr_t& NLPAlgoState::get_space_range() const
00549 { return space_range_; }
00550
00551 inline
00552 const VectorSpace& NLPAlgoState::space_range() const
00553 { return *space_range_; }
00554
00555 inline
00556 NLPAlgoState::vec_space_ptr_t& NLPAlgoState::get_space_null()
00557 { return space_null_ ; }
00558
00559 inline
00560 const NLPAlgoState::vec_space_ptr_t& NLPAlgoState::get_space_null() const
00561 { return space_null_; }
00562
00563 inline
00564 const VectorSpace& NLPAlgoState::space_null() const
00565 { return *space_null_; }
00566
00567 }
00568
00569 #endif // RSQP_STATE_H