NLPInterfacePack: C++ Interfaces and Implementation for Non-Linear Programs  Version of the Day
NLPInterfacePack_NLP.hpp
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 NLP_H
43 #define NLP_H
44 
45 #include <stdexcept>
46 #include <string>
47 
48 #include "NLPInterfacePack_Types.hpp"
49 #include "AbstractLinAlgPack_VectorMutable.hpp"
50 #include "AbstractLinAlgPack_Permutation.hpp"
51 #include "StandardCompositionRelationshipsPack.hpp"
52 #include "Teuchos_RCP.hpp"
53 #include "Teuchos_VerboseObject.hpp"
54 
55 namespace OptionsFromStreamPack {
56  class OptionsFromStream;
57 }
58 
59 namespace NLPInterfacePack {
60 
303 class NLP : virtual public Teuchos::VerboseObject<NLP> {
304 public:
305 
306  typedef AbstractLinAlgPack::Vector Vector; // doxygen likes typedef?
307  typedef AbstractLinAlgPack::VectorMutable VectorMutable; // doxygen likes typedef?
308 
310  typedef Teuchos::RCP<const VectorSpace> vec_space_ptr_t;
311 
313  typedef Teuchos::RCP<
315 
318 
320  class UnInitialized : public std::logic_error
321  {public: UnInitialized(const std::string& what_arg) : std::logic_error(what_arg) {}};
322 
324  class InvalidInitialization : public std::logic_error
325  {public: InvalidInitialization(const std::string& what_arg) : std::logic_error(what_arg) {}};
326 
328  class IncompatibleType : public std::logic_error
329  {public: IncompatibleType(const std::string& what_arg) : std::logic_error(what_arg) {}};
330 
332  class NoBounds : public std::logic_error
333  {public: NoBounds(const std::string& what_arg) : std::logic_error(what_arg) {}};
334 
336 
338  static value_type infinite_bound();
339 
342 
344  NLP();
346  virtual ~NLP();
347 
349 
352 
361  virtual void force_xinit_in_bounds(bool force_xinit_in_bounds) = 0;
364  virtual bool force_xinit_in_bounds() const = 0;
376  virtual void set_options( const options_ptr_t& options );
381  virtual const options_ptr_t& get_options() const;
395  virtual void initialize( bool test_setup = false );
398  virtual bool is_initialized() const = 0;
399 
401 
404 
413  virtual size_type n() const;
422  virtual size_type m() const;
423 
425 
428 
439  virtual vec_space_ptr_t space_x() const = 0;
451  virtual vec_space_ptr_t space_c() const = 0;
452 
454 
457 
465  virtual size_type num_bounded_x() const = 0;
474  virtual const Vector& xl() const = 0;
483  virtual const Vector& xu() const = 0;
484 
495  virtual value_type max_var_bounds_viol() const = 0;
496 
498 
501 
512  virtual const Vector& xinit() const = 0;
531  virtual void get_init_lagrange_mult(
532  VectorMutable* lambda
533  ,VectorMutable* nu
534  ) const;
535 
537 
540 
553  virtual void set_f(value_type* f);
560  virtual value_type* get_f();
568  virtual value_type& f();
576  virtual const value_type& f() const;
577 
579 
582 
597  virtual void set_c(VectorMutable* c);
600  virtual VectorMutable* get_c();
608  virtual VectorMutable& c();
616  virtual const Vector& c() const;
617 
619 
622 
639  virtual void unset_quantities();
640 
642 
645 
656  virtual void scale_f( value_type scale_f ) = 0;
663  virtual value_type scale_f() const = 0;
686  virtual void calc_f(const Vector& x, bool newx = true) const;
709  virtual void calc_c(const Vector& x, bool newx = true) const;
710 
712 
715 
730  virtual void report_final_solution(
731  const Vector& x
732  ,const Vector* lambda
733  ,const Vector* nu
734  ,bool is_optimal
735  );
736 
738 
741 
749  virtual size_type num_f_evals() const;
757  virtual size_type num_c_evals() const;
758 
760 
763 
769  virtual size_type ns() const;
770 
784  virtual vec_space_ptr_t space_c_breve() const;
785 
799  virtual vec_space_ptr_t space_h_breve() const;
800 
812  virtual const Vector& hl_breve() const;
813 
824  virtual const Vector& hu_breve() const;
825 
840  virtual void set_c_breve(VectorMutable* c_breve);
843  virtual VectorMutable* get_c_breve();
851  virtual VectorMutable& c_breve();
859  virtual const Vector& c_breve() const;
860 
875  virtual void set_h_breve(VectorMutable* h_breve);
878  virtual VectorMutable* get_h_breve();
886  virtual VectorMutable& h_breve();
894  virtual const Vector& h_breve() const;
895 
908  virtual const Permutation& P_var() const;
909 
923  virtual const Permutation& P_equ() const;
924 
948  virtual void calc_c_breve(const Vector& x, bool newx = true) const;
949 
973  virtual void calc_h_breve(const Vector& x, bool newx = true) const;
974 
976 
982  struct ZeroOrderInfo {
983  public:
985  ZeroOrderInfo() : f(NULL), c(NULL), h(NULL)
986  {}
988  ZeroOrderInfo( value_type* f_in, VectorMutable* c_in, VectorMutable* h_in )
989  : f(f_in), c(c_in), h(h_in)
990  {}
992  value_type* f;
994  VectorMutable* c;
996  VectorMutable* h;
997  }; // end struct ZeroOrderInfo
998 
1000  const ZeroOrderInfo zero_order_info() const;
1001 
1003  const ZeroOrderInfo zero_order_info_breve() const;
1004 
1005 protected:
1006 
1009 
1030  virtual void imp_calc_f(const Vector& x, bool newx, const ZeroOrderInfo& zero_order_info) const = 0;
1051  virtual void imp_calc_c(const Vector& x, bool newx, const ZeroOrderInfo& zero_order_info) const = 0;
1071  virtual void imp_calc_c_breve(const Vector& x, bool newx, const ZeroOrderInfo& zero_order_info_breve) const;
1091  virtual void imp_calc_h_breve(const Vector& x, bool newx, const ZeroOrderInfo& zero_order_info_breve) const;
1092 
1094 
1096  template<class T>
1097  void assert_ref_set(T* p, std::string info) const {
1098  StandardCompositionRelationshipsPack::assert_role_name_set(p, false, info);
1099  }
1100 
1101 private:
1102 
1103  // ////////////////////////////////////////
1104  // Private data members
1105 
1106 #ifdef DOXYGEN_COMPILE
1109  AbstractLinAlgPack::VectorSpace *space_c_breve;
1110  AbstractLinAlgPack::VectorSpace *space_h_breve;
1111  Permutation *P_var;
1112  Permtuation *P_equ;
1113 #else
1114  Teuchos::RCP<Permutation> P_var_;
1115  Teuchos::RCP<Permutation> P_equ_;
1116 #endif
1117  mutable ZeroOrderInfo first_order_info_;
1118  mutable ZeroOrderInfo first_order_info_breve_;
1119  mutable size_type num_f_evals_;
1120  mutable size_type num_c_evals_;
1121 
1122 }; // end class NLP
1123 
1124 // /////////////////
1125 // Inline members
1126 
1127 inline
1128 const NLP::ZeroOrderInfo NLP::zero_order_info() const
1129 {
1130  return first_order_info_;
1131 }
1132 
1133 inline
1134 const NLP::ZeroOrderInfo NLP::zero_order_info_breve() const
1135 {
1136  return first_order_info_breve_;
1137 }
1138 
1139 } // end namespace NLPInterfacePack
1140 
1141 #endif // NLP_H
Thrown if an incompatible object is used.
VectorMutable * c
Pointer to constraints residual c (Will be NULL if not set)
ZeroOrderInfo(value_type *f_in, VectorMutable *c_in, VectorMutable *h_in)
void assert_ref_set(T *p, std::string info) const
Assert referece has been set for a quanity.
size_t size_type
Teuchos::RCP< const OptionsFromStreamPack::OptionsFromStream > options_ptr_t
Teuchos::RCP< const VectorSpace > vec_space_ptr_t
Struct for objective and constriants (pointer).
NLP interface class {abstract}.
Thrown if any member functions are called before initialize() has been called.
value_type * f
Pointer to objective function f (Will be NULL if not set)
Thrown some bounds do not existe.
Thrown from initialize() if some logical error occured.
VectorMutable * h
Pointer to inequality constraints h (Will be NULL if not set)