NLPInterfacePack_NLPThyraModelEvaluatorBase.hpp

Go to the documentation of this file.
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 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #ifndef NLPIP_NLP_THYRA_MODEL_EVALUATOR_BASE_HPP
00030 #define NLPIP_NLP_THYRA_MODEL_EVALUATOR_BASE_HPP
00031 
00032 #include <vector>
00033 
00034 #include "NLPInterfacePack_NLPFirstOrder.hpp"
00035 #include "AbstractLinAlgPack_VectorSpace.hpp"
00036 #include "Thyra_ModelEvaluator.hpp"
00037 #include "Teuchos_TestForException.hpp"
00038 
00039 namespace AbstractLinAlgPack { class VectorSpaceThyra; }
00040 
00041 namespace NLPInterfacePack {
00042 
00078 class NLPThyraModelEvaluatorBase : virtual public NLPObjGrad {
00079 public:
00080 
00083 
00085   void initialize(bool test_setup);
00087   bool is_initialized() const;
00089   vec_space_ptr_t space_x() const;
00091   vec_space_ptr_t space_c() const;
00093     size_type num_bounded_x() const;
00095   void force_xinit_in_bounds(bool force_xinit_in_bounds);
00097   bool force_xinit_in_bounds() const;
00099   const Vector& xinit() const;
00101   const Vector& xl() const;
00103   const Vector& xu() const;
00105   value_type max_var_bounds_viol() const;
00107   void set_f(value_type* f);
00109   void set_c(VectorMutable* c);
00111   void unset_quantities();
00113   void scale_f( value_type scale_f );
00115   value_type scale_f() const;
00117   void report_final_solution(
00118     const Vector&    x
00119     ,const Vector*   lambda
00120     ,const Vector*   nu
00121     ,bool            optimal
00122     );
00123 
00125 
00128 
00130   void set_Gf(VectorMutable* Gf);
00131 
00133 
00134 protected:
00135 
00138 
00140   void imp_calc_f(
00141     const Vector& x, bool newx
00142     ,const ZeroOrderInfo& zero_order_info) const;
00144   void imp_calc_c(
00145     const Vector& x, bool newx
00146     ,const ZeroOrderInfo& zero_order_info) const;
00147 
00149 
00152 
00154   void imp_calc_Gf(
00155     const Vector& x, bool newx
00156     ,const ObjGradInfo& obj_grad_info) const;
00157 
00159 
00160 protected:
00161 
00164 
00166   NLPThyraModelEvaluatorBase();
00167 
00188   void initializeBase(
00189     const Teuchos::RefCountPtr<Thyra::ModelEvaluator<value_type> >  &model
00190     ,const int                                                      p_idx
00191     ,const int                                                      g_idx
00192     );
00193 
00195   void updateInitialGuessAndBounds();
00196 
00198   void assert_is_initialized() const;
00200   void copy_from_model_x( const Thyra::VectorBase<value_type>* model_x, VectorMutable* x_D ) const;
00202   void copy_from_model_p( const Thyra::VectorBase<value_type> *model_p, VectorMutable* x_I ) const;
00204   void set_x(
00205     const Vector                                      &x
00206     ,Thyra::ModelEvaluatorBase::InArgs<value_type>    *model_inArgs_inout
00207     ) const;
00209   void preprocessBaseInOutArgs(
00210     const Vector                                      &x
00211     ,bool                                             newx
00212     ,const ZeroOrderInfo                              *zero_order_info
00213     ,const ObjGradInfo                                *obj_grad_info
00214     ,const NLPFirstOrder::FirstOrderInfo              *first_order_info
00215     ,Thyra::ModelEvaluatorBase::InArgs<value_type>    *model_inArgs_inout
00216     ,Thyra::ModelEvaluatorBase::OutArgs<value_type>   *model_outArgs_inout
00217     ,MatrixOp*                                        *Gc_out
00218     ,VectorMutable*                                   *Gf_out
00219     ,value_type*                                      *f_out
00220     ,VectorMutable*                                   *c_out
00221     ) const;
00223   void postprocessBaseOutArgs(
00224     Thyra::ModelEvaluatorBase::OutArgs<value_type>        *model_outArgs_inout
00225     ,VectorMutable                                        *Gf
00226     ,value_type                                           *f
00227     ,VectorMutable                                        *c
00228     ) const;
00229     
00231 
00232 //private: // ToDo: Make these private and refactor the other classes ...
00233 
00234   // /////////////////////////////////////////
00235   // Private types
00236 
00237   typedef Teuchos::RefCountPtr<const AbstractLinAlgPack::VectorSpaceThyra> VectorSpaceThyra_ptr_t;
00238 
00239   // /////////////////////////////////////////
00240   // Private data members
00241 
00242   bool                                initialized_;  // flag for if initialized has been called.
00243   value_type                          obj_scale_;    // default = 1.0;
00244   bool                                has_bounds_;   // True if has bounds
00245   bool                                force_xinit_in_bounds_; // default = true.
00246   index_type                          num_bounded_x_;
00247   Teuchos::RefCountPtr<Thyra::ModelEvaluator<value_type> >
00248                                       model_;
00249   int                                 p_idx_;
00250   int                                 g_idx_;
00251   bool                                DfDp_supports_op_;
00252   bool                                DfDp_supports_mv_;
00253   VectorSpace::space_ptr_t            space_x_;      // Space for the variables
00254   VectorSpaceThyra_ptr_t              space_c_;      // Space for the constraints
00255   NLPFirstOrder::mat_fcty_ptr_t       factory_Gc_;   // Factory for Gc
00256   NLPFirstOrder::basis_sys_ptr_t      basis_sys_;    // The basis system
00257   VectorSpace::vec_mut_ptr_t          xinit_;        // Initial guess.
00258   VectorSpace::vec_mut_ptr_t          xl_;           // lower bounds.
00259   VectorSpace::vec_mut_ptr_t          xu_;           // upper bounds.
00260 
00261   Teuchos::RefCountPtr<Thyra::VectorBase<value_type> >                     model_g_;
00262 
00263   mutable bool model_g_updated_;
00264   mutable bool model_Dg_updated_;
00265 
00266   mutable bool f_updated_;
00267   mutable bool c_updated_;
00268   mutable bool Gf_updated_;
00269   mutable bool Gc_updated_;
00270 
00271   // /////////////////////////////////////////
00272   // Private member functions
00273 
00275   void evalModel( 
00276     const Vector            &x
00277     ,bool                   newx
00278     ,const ZeroOrderInfo    *zero_order_info  // != NULL if only zero-order info
00279     ,const ObjGradInfo      *obj_grad_info    // != NULL if obj-grad and below info
00280     ) const;
00281 
00282 };  // end class NLPThyraModelEvaluatorBase
00283 
00284 } // end namespace NLPInterfacePack
00285 
00286 #endif  // NLPIP_NLP_THYRA_MODEL_EVALUATOR_BASE_HPP

Generated on Thu Sep 18 12:35:19 2008 for MOOCHO (Single Doxygen Collection) by doxygen 1.3.9.1