MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MoochoPack_NLPAlgoState.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef RSQP_STATE_H
43 #define RSQP_STATE_H
44 
45 #include <deque>
46 
47 #include "MoochoPack_Types.hpp"
56 //#include "DenseLinAlgPack_IVector.hpp"
59 
60 namespace MoochoPack {
61 
67 
68 // Iteration Info
69 extern const std::string num_basis_name;
70 // NLP Problem Info
71 extern const std::string x_name;
72 extern const std::string f_name;
73 extern const std::string Gf_name;
74 extern const std::string HL_name;
75 extern const std::string c_name;
76 extern const std::string h_name;
77 extern const std::string Gc_name;
78 // Constraint Gradient Null Space / Range Space Decomposition Info
79 extern const std::string Y_name;
80 extern const std::string Z_name;
81 extern const std::string R_name;
82 extern const std::string Uy_name;
83 extern const std::string Uz_name;
84 // Search Direction Info
85 extern const std::string py_name;
86 extern const std::string Ypy_name;
87 extern const std::string pz_name;
88 extern const std::string Zpz_name;
89 extern const std::string d_name;
90 // Reduced QP Subproblem Info
91 extern const std::string rGf_name;
92 extern const std::string rHL_name;
93 extern const std::string w_name;
94 extern const std::string zeta_name;
95 extern const std::string qp_grad_name;
96 extern const std::string eta_name;
97 // Global Convergence Info
98 extern const std::string alpha_name;
99 extern const std::string merit_func_nlp_name;
100 extern const std::string mu_name;
101 extern const std::string phi_name;
102 // KKT Info
103 extern const std::string opt_kkt_err_name;
104 extern const std::string feas_kkt_err_name;
105 extern const std::string comp_kkt_err_name;
106 extern const std::string GL_name;
107 extern const std::string rGL_name;
108 extern const std::string lambda_name;
109 extern const std::string nu_name;
110 
112 
123 
126 #define STATE_IQ_DECL(TYPE,NAME) \
127  virtual IterQuantityAccess<TYPE>& NAME(); \
128  virtual const IterQuantityAccess<TYPE>& NAME() const; \
129 private: \
130  iq_id_encap NAME ## _iq_id_; \
131 public:
132 
135 #define STATE_INDEX_IQ_DECL(NAME) \
136  STATE_IQ_DECL(index_type,NAME) \
137 
138 
140 #define STATE_SCALAR_IQ_DECL(NAME) \
141  STATE_IQ_DECL(value_type,NAME) \
142 
143 
145 #define STATE_VECTOR_IQ_DECL(NAME) \
146  STATE_IQ_DECL(VectorMutable,NAME) \
147 
148 
155 #define STATE_IQ_DEF(CLASS,TYPE,NAME,NAME_STR) \
156 IterQuantityAccess<TYPE>& \
157 CLASS::NAME() \
158 { \
159  update_iq_id( NAME_STR, &NAME ## _iq_id_ ); \
160  return IterationPack::cast_iq<TYPE>( \
161  *this, NAME ## _iq_id_.iq_id, NAME_STR ); \
162 } \
163 const IterQuantityAccess<TYPE>& \
164 CLASS::NAME() const \
165 { \
166  return const_cast<CLASS*>(this)->NAME(); \
167 }
168 
173 #define STATE_INDEX_IQ_DEF(CLASS,NAME,NAME_STR) \
174 IterQuantityAccess<index_type>& \
175 CLASS::NAME() \
176 { \
177  update_index_type_iq_id( NAME_STR, &NAME ## _iq_id_ ); \
178  return IterationPack::cast_iq<index_type>( \
179  *this, NAME ## _iq_id_.iq_id, NAME_STR ); \
180 } \
181 const IterQuantityAccess<index_type>& \
182 CLASS::NAME() const \
183 { \
184  return const_cast<CLASS*>(this)->NAME(); \
185 }
186 
191 #define STATE_SCALAR_IQ_DEF(CLASS,NAME,NAME_STR) \
192 IterQuantityAccess<value_type>& \
193 CLASS::NAME() \
194 { \
195  update_value_type_iq_id( NAME_STR, &NAME ## _iq_id_ ); \
196  return IterationPack::cast_iq<value_type>( \
197  *this, NAME ## _iq_id_.iq_id, NAME_STR ); \
198 } \
199 const IterQuantityAccess<value_type>& \
200 CLASS::NAME() const \
201 { \
202  return const_cast<CLASS*>(this)->NAME(); \
203 }
204 
214 #define STATE_VECTOR_IQ_DEF(CLASS,NAME,NAME_STR,VEC_SPC,VEC_RN) \
215 IterQuantityAccess<VectorMutable>& \
216 CLASS::NAME() \
217 { \
218  update_vector_iq_id( NAME_STR, VEC_SPC, VEC_RN, &NAME ## _iq_id_ ); \
219  return IterationPack::cast_iq<VectorMutable>( \
220  *this, NAME ## _iq_id_.iq_id, NAME_STR ); \
221 } \
222 const IterQuantityAccess<VectorMutable>& \
223 CLASS::NAME() const \
224 { \
225  return const_cast<CLASS*>(this)->NAME(); \
226 }
227 
229 
265  : public IterationPack::AlgorithmState // doxygen needs full path
266 {
267 public:
268 
271 
273  class InvalidType : public std::logic_error
274  {public: InvalidType(const std::string& what_arg) : std::logic_error(what_arg) {}};
275 
278 
280 
281 protected:
282 
283  // /////////////////////////////
284  // Protected types.
285 
287  struct iq_id_encap {
290  };
291 
292 public:
293 
296 
297  // ToDo: Implement all set_space_xx methods to update factories
298  // for all vector iteration quantities.
299 
301  STANDARD_COMPOSITION_MEMBERS( DecompositionSystem, decomp_sys );
303  STANDARD_CONST_COMPOSITION_MEMBERS( VectorSpace, space_x );
305  STANDARD_CONST_COMPOSITION_MEMBERS( VectorSpace, space_c );
314  const vec_space_ptr_t& get_space_range() const;
315  const VectorSpace& space_range() const;
324  const vec_space_ptr_t& get_space_null() const;
325  const VectorSpace& space_null() const;
326 
331  NLPAlgoState(
332  const decomp_sys_ptr_t& decomp_sys = Teuchos::null
333  ,const vec_space_ptr_t& space_x = Teuchos::null
334  ,const vec_space_ptr_t& space_c = Teuchos::null
337  );
338 
340  virtual ~NLPAlgoState() {}
341 
343 
346 
348  STATE_INDEX_IQ_DECL(num_basis)
349 
350  //@}
351 
352 
354 
362  STATE_IQ_DECL(MatrixSymOp,HL)
366  STATE_IQ_DECL(MatrixOp,Gc)
367 
369 
372 
374  STATE_IQ_DECL(MatrixOp,Y)
376  STATE_IQ_DECL(MatrixOp,Z)
378  STATE_IQ_DECL(MatrixOpNonsing,R)
380  STATE_IQ_DECL(MatrixOp,Uy)
382  STATE_IQ_DECL(MatrixOp,Uz)
383 
385 
388 
399 
401 
404 
408  STATE_IQ_DECL(MatrixSymOp,rHL)
414  STATE_VECTOR_IQ_DECL(qp_grad)
417 
419 
422 
424  STATE_SCALAR_IQ_DECL(alpha)
426  STATE_IQ_DECL(MeritFuncNLP,merit_func_nlp)
431 
433 
436 
438  STATE_SCALAR_IQ_DECL(opt_kkt_err)
440  STATE_SCALAR_IQ_DECL(feas_kkt_err)
442  STATE_SCALAR_IQ_DECL(comp_kkt_err)
448  STATE_VECTOR_IQ_DECL(lambda)
451 
453 
456 
460  STANDARD_MEMBER_COMPOSITION_MEMBERS( Range1D, var_indep );
461 
463  STANDARD_MEMBER_COMPOSITION_MEMBERS( Range1D, equ_decomp );
465  STANDARD_MEMBER_COMPOSITION_MEMBERS( Range1D, equ_undecomp );
466 
468 
471 
473  STANDARD_COMPOSITION_MEMBERS( Permutation, P_var_current );
475  STANDARD_COMPOSITION_MEMBERS( Permutation, P_var_last );
477  STANDARD_COMPOSITION_MEMBERS( Permutation, P_equ_current );
479  STANDARD_COMPOSITION_MEMBERS( Permutation, P_equ_last );
480 
482 
483 protected:
484 
485  enum { NUM_VEC_SPACE_TYPES = 5 };
491  };
492 
493  // /////////////////////////////
494  // Protected member functions
495 
496  // These implementations are used to avoid code blot and help in debugging
497  // (can't debug macros very well).
498 
500  void update_iq_id(
501  const std::string& iq_name
502  ,iq_id_encap* iq_id
503  ) const;
506  const std::string& iq_name
507  ,iq_id_encap* iq_id
508  );
511  const std::string& iq_name
512  ,iq_id_encap* iq_id
513  );
515  void update_vector_iq_id(
516  const std::string& iq_name
517  ,const VectorSpace::space_ptr_t& vec_space
518  ,EVecSpaceType vec_space_type
519  ,iq_id_encap* iq_id
520  );
521 
522 private:
523 
524  // ////////////////////////////
525  // Private types
526 
527  typedef std::deque<iq_id_type> iq_vector_list_t;
528 
529  // ////////////////////////////
530  // Private data member
531 
534 
536 
537  // ////////////////////////////
538  // Private member functions.
539 
540  // Update the vector factories for all of the iteration quantities
541  // in the input list.
543  EVecSpaceType vec_space_type
544  ,const vec_space_ptr_t& vec_space
545  );
546 
547  // not defined and not to be called
548  NLPAlgoState(const NLPAlgoState&);
550 
551 }; // end class NLPAlgoState
552 
553 // ////////////////////////////////////
554 // Inline members
555 
556 inline
558 { return space_range_ ; }
559 
560 inline
562 { return space_range_; }
563 
564 inline
565 const VectorSpace& NLPAlgoState::space_range() const
566 { return *space_range_; }
567 
568 inline
570 { return space_null_ ; }
571 
572 inline
574 { return space_null_; }
575 
576 inline
577 const VectorSpace& NLPAlgoState::space_null() const
578 { return *space_null_; }
579 
580 } // end namespace MoochoPack
581 
582 #endif // RSQP_STATE_H
f_dbl_prec const f_int f_dbl_prec * Y
iq_vector_list_t vector_iqs_lists_[NUM_VEC_SPACE_TYPES]
void update_iq_id(const std::string &iq_name, iq_id_encap *iq_id) const
const std::string opt_kkt_err_name
#define STATE_IQ_DECL(TYPE, NAME)
Add class declarations for an arbitrary iteration quantity.
const std::string lambda_name
const VectorSpace & space_null() const
const std::string GL_name
const std::string eta_name
const std::string h_name
const std::string feas_kkt_err_name
const std::string alpha_name
std::deque< iq_id_type > iq_vector_list_t
const std::string c_name
const std::string zeta_name
const std::string Ypy_name
const std::string rGL_name
#define STATE_SCALAR_IQ_DECL(NAME)
Add class declarations for a scalar (i.e. value_type) iteration quantity.
const std::string Gc_name
const std::string x_name
const std::string num_basis_name
const std::string Y_name
const VectorSpace & space_range() const
void update_vector_iq_id(const std::string &iq_name, const VectorSpace::space_ptr_t &vec_space, EVecSpaceType vec_space_type, iq_id_encap *iq_id)
const std::string Gf_name
const std::string Zpz_name
const std::string merit_func_nlp_name
const f_int f_dbl_prec const f_int f_int const f_int f_int const f_dbl_prec f_int f_int f_dbl_prec w[]
const std::string f_name
const std::string phi_name
void update_value_type_iq_id(const std::string &iq_name, iq_id_encap *iq_id)
const std::string pz_name
const std::string comp_kkt_err_name
Reduced space SQP state encapsulation interface.
const std::string rGf_name
Abstacts a set of iteration quantities for an iterative algorithm.
STANDARD_COMPOSITION_MEMBERS(DecompositionSystem, decomp_sys)
Set the DecompositionSystem object that all share.
Teuchos::RCP< const VectorSpace > vec_space_ptr_t
#define STATE_INDEX_IQ_DECL(NAME)
Add class declarations for an index (i.e. index_type) iteration quantity.
void update_vector_factories(EVecSpaceType vec_space_type, const vec_space_ptr_t &vec_space)
const std::string Z_name
Thrown if an iteration quantity is of an invalid type.
const std::string mu_name
const std::string py_name
const std::string rHL_name
void set_space_null(const vec_space_ptr_t &space_null)
Set the VectorSpace of the null space (pz).
const std::string HL_name
const std::string qp_grad_name
const std::string Uy_name
NLPAlgoState & operator=(const NLPAlgoState &)
void update_index_type_iq_id(const std::string &iq_name, iq_id_encap *iq_id)
NLPAlgoState(const decomp_sys_ptr_t &decomp_sys=Teuchos::null, const vec_space_ptr_t &space_x=Teuchos::null, const vec_space_ptr_t &space_c=Teuchos::null, const vec_space_ptr_t &space_range=Teuchos::null, const vec_space_ptr_t &space_null=Teuchos::null)
Construct.
const std::string nu_name
const std::string w_name
const std::string Uz_name
const std::string d_name
STANDARD_CONST_COMPOSITION_MEMBERS(VectorSpace, space_x)
Set the VectorSpace of x.
STANDARD_MEMBER_COMPOSITION_MEMBERS(Range1D, var_dep)
Range of dependent variables [1,r].
const std::string R_name
void set_space_range(const vec_space_ptr_t &space_range)
Set the VectorSpace of the range space (py).
#define STATE_VECTOR_IQ_DECL(NAME)
Add class declarations for a VectorMutable iteration quantity.