NLPInterfacePack: C++ Interfaces and Implementation for Non-Linear Programs Version of the Day
NLPInterfacePack_NLP.hpp
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_H
00043 #define NLP_H
00044 
00045 #include <stdexcept>
00046 #include <string>
00047 
00048 #include "NLPInterfacePack_Types.hpp"
00049 #include "AbstractLinAlgPack_VectorMutable.hpp"
00050 #include "AbstractLinAlgPack_Permutation.hpp"
00051 #include "StandardCompositionRelationshipsPack.hpp"
00052 #include "Teuchos_RCP.hpp"
00053 #include "Teuchos_VerboseObject.hpp"
00054 
00055 namespace OptionsFromStreamPack {
00056   class OptionsFromStream;
00057 }
00058 
00059 namespace NLPInterfacePack {
00060 
00303 class NLP : virtual public Teuchos::VerboseObject<NLP> {
00304 public:
00305   
00306   typedef AbstractLinAlgPack::Vector         Vector;         // doxygen likes typedef?
00307   typedef AbstractLinAlgPack::VectorMutable  VectorMutable;  // doxygen likes typedef?
00308   
00310   typedef Teuchos::RCP<const VectorSpace>  vec_space_ptr_t;
00311 
00313   typedef Teuchos::RCP<
00314     const OptionsFromStreamPack::OptionsFromStream>             options_ptr_t;
00315 
00318 
00320   class UnInitialized : public std::logic_error
00321   {public: UnInitialized(const std::string& what_arg) : std::logic_error(what_arg) {}};
00322 
00324   class InvalidInitialization : public std::logic_error
00325   {public: InvalidInitialization(const std::string& what_arg) : std::logic_error(what_arg) {}};
00326 
00328   class IncompatibleType : public std::logic_error
00329   {public: IncompatibleType(const std::string& what_arg) : std::logic_error(what_arg) {}};
00330 
00332   class NoBounds : public std::logic_error
00333   {public: NoBounds(const std::string& what_arg) : std::logic_error(what_arg) {}};
00334 
00336 
00338   static value_type infinite_bound();
00339 
00342 
00344   NLP();
00346   virtual ~NLP();
00347 
00349   
00352 
00361   virtual void force_xinit_in_bounds(bool force_xinit_in_bounds) = 0;
00364   virtual bool force_xinit_in_bounds() const = 0;
00376   virtual void set_options( const options_ptr_t& options );
00381   virtual const options_ptr_t& get_options() const;
00395   virtual void initialize( bool test_setup = false );
00398   virtual bool is_initialized() const = 0;
00399 
00401 
00404 
00413   virtual size_type n() const;
00422   virtual size_type m() const;
00423 
00425 
00428 
00439   virtual vec_space_ptr_t space_x() const = 0;
00451   virtual vec_space_ptr_t space_c() const = 0;
00452 
00454 
00457 
00465   virtual size_type num_bounded_x() const = 0;
00474   virtual const Vector& xl() const = 0;
00483   virtual const Vector& xu() const = 0;
00484 
00495   virtual value_type max_var_bounds_viol() const = 0;
00496 
00498 
00501 
00512   virtual const Vector& xinit() const = 0;
00531   virtual void get_init_lagrange_mult(
00532     VectorMutable*   lambda
00533     ,VectorMutable*  nu
00534     ) const;
00535 
00537 
00540 
00553   virtual void set_f(value_type* f);
00560   virtual value_type* get_f();
00568   virtual value_type& f();
00576    virtual const value_type& f() const;
00577 
00579 
00582 
00597   virtual void set_c(VectorMutable* c);
00600   virtual VectorMutable* get_c();
00608   virtual VectorMutable& c();
00616   virtual const Vector& c() const;
00617 
00619 
00622   
00639   virtual void unset_quantities();
00640 
00642 
00645 
00656   virtual void scale_f( value_type scale_f ) = 0;
00663   virtual value_type scale_f() const = 0;
00686   virtual void calc_f(const Vector& x, bool newx = true) const;
00709   virtual void calc_c(const Vector& x, bool newx = true) const;
00710 
00712 
00715 
00730   virtual void report_final_solution(
00731     const Vector&    x
00732     ,const Vector*   lambda
00733     ,const Vector*   nu
00734     ,bool            is_optimal
00735     );
00736 
00738 
00741 
00749   virtual size_type num_f_evals() const;
00757   virtual size_type num_c_evals() const;
00758 
00760 
00763 
00769   virtual size_type ns() const;
00770 
00784   virtual vec_space_ptr_t space_c_breve() const;
00785 
00799   virtual vec_space_ptr_t space_h_breve() const;
00800 
00812   virtual const Vector& hl_breve() const;
00813 
00824   virtual const Vector& hu_breve() const;
00825 
00840   virtual void set_c_breve(VectorMutable* c_breve);
00843   virtual VectorMutable* get_c_breve();
00851   virtual VectorMutable& c_breve();
00859   virtual const Vector& c_breve() const;
00860 
00875   virtual void set_h_breve(VectorMutable* h_breve);
00878   virtual VectorMutable* get_h_breve();
00886   virtual VectorMutable& h_breve();
00894   virtual const Vector& h_breve() const;
00895 
00908   virtual const Permutation& P_var() const;
00909 
00923   virtual const Permutation& P_equ() const;
00924 
00948   virtual void calc_c_breve(const Vector& x, bool newx = true) const;
00949 
00973   virtual void calc_h_breve(const Vector& x, bool newx = true) const;
00974 
00976 
00982   struct ZeroOrderInfo {
00983   public:
00985         ZeroOrderInfo() : f(NULL), c(NULL), h(NULL)
00986     {}
00988     ZeroOrderInfo( value_type* f_in, VectorMutable* c_in, VectorMutable* h_in )
00989       : f(f_in), c(c_in), h(h_in)
00990     {}
00992     value_type*           f;
00994     VectorMutable*  c;
00996     VectorMutable*  h;
00997   }; // end struct ZeroOrderInfo
00998 
01000   const ZeroOrderInfo zero_order_info() const;
01001 
01003   const ZeroOrderInfo zero_order_info_breve() const;
01004 
01005 protected:
01006 
01009 
01030   virtual void imp_calc_f(const Vector& x, bool newx, const ZeroOrderInfo& zero_order_info) const = 0;
01051   virtual void imp_calc_c(const Vector& x, bool newx, const ZeroOrderInfo& zero_order_info) const = 0;
01071   virtual void imp_calc_c_breve(const Vector& x, bool newx, const ZeroOrderInfo& zero_order_info_breve) const;
01091   virtual void imp_calc_h_breve(const Vector& x, bool newx, const ZeroOrderInfo& zero_order_info_breve) const;
01092 
01094 
01096   template<class T>
01097   void assert_ref_set(T* p, std::string info) const {
01098     StandardCompositionRelationshipsPack::assert_role_name_set(p, false, info);
01099   }
01100 
01101 private:
01102 
01103   // ////////////////////////////////////////
01104   // Private data members
01105 
01106 #ifdef DOXYGEN_COMPILE
01107   AbstractLinAlgPack::VectorSpace *space_x;
01108   AbstractLinAlgPack::VectorSpace *space_c;
01109   AbstractLinAlgPack::VectorSpace *space_c_breve;
01110   AbstractLinAlgPack::VectorSpace *space_h_breve;
01111   Permutation                     *P_var;
01112   Permtuation                     *P_equ;
01113 #else
01114   Teuchos::RCP<Permutation>  P_var_;
01115   Teuchos::RCP<Permutation>  P_equ_;
01116 #endif
01117   mutable ZeroOrderInfo           first_order_info_;
01118   mutable ZeroOrderInfo           first_order_info_breve_;
01119   mutable size_type       num_f_evals_;
01120   mutable size_type       num_c_evals_;
01121   
01122 };  // end class NLP
01123 
01124 // /////////////////
01125 // Inline members
01126 
01127 inline
01128 const NLP::ZeroOrderInfo NLP::zero_order_info() const
01129 {
01130   return first_order_info_;
01131 }
01132 
01133 inline
01134 const NLP::ZeroOrderInfo NLP::zero_order_info_breve() const
01135 {
01136   return first_order_info_breve_;
01137 }
01138 
01139 } // end namespace NLPInterfacePack 
01140 
01141 #endif // NLP_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends