NLPInterfacePack: C++ Interfaces and Implementation for Non-Linear Programs  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 
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;
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
1111  Permutation *P_var;
1112  Permtuation *P_equ;
1113 #else
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
1129 {
1130  return first_order_info_;
1131 }
1132 
1133 inline
1135 {
1136  return first_order_info_breve_;
1137 }
1138 
1139 } // end namespace NLPInterfacePack
1140 
1141 #endif // NLP_H
virtual value_type & f()
Returns non-const *this->get_f().
Thrown if an incompatible object is used.
virtual void calc_c(const Vector &x, bool newx=true) const
Update the constraint residual vector for c at the point x and put it in the stored reference...
VectorMutable * c
Pointer to constraints residual c (Will be NULL if not set)
virtual size_type ns() const
Return the number of slack variables (i.e. number of general inequalities).
virtual void report_final_solution(const Vector &x, const Vector *lambda, const Vector *nu, bool is_optimal)
Used by the solver to report the final solution and multipliers.
ZeroOrderInfo(value_type *f_in, VectorMutable *c_in, VectorMutable *h_in)
virtual size_type num_c_evals() const
Gives the number of constraint function c(x) evaluations called by the solver since initialize() was ...
virtual value_type scale_f() const =0
Return the scaling being used for the objective function.
virtual VectorMutable & c_breve()
Returns non-const *this->get_c_breve().
virtual VectorMutable * get_c_breve()
Return pointer passed to this->set_c_breve().
virtual vec_space_ptr_t space_x() const =0
Vector space object for unknown variables x (dimension n).
virtual vec_space_ptr_t space_c_breve() const
Vector space object for the original equalities c_breve(x_breve)
virtual void get_init_lagrange_mult(VectorMutable *lambda, VectorMutable *nu) const
Get the initial value of the Lagrange multipliers lambda.
const ZeroOrderInfo zero_order_info() const
Return pointer to set quantities.
virtual void imp_calc_c_breve(const Vector &x, bool newx, const ZeroOrderInfo &zero_order_info_breve) const
Overridden to compute c_breve(x_breve) and perhaps f(x) and/or h_breve(x_breve)
virtual void imp_calc_f(const Vector &x, bool newx, const ZeroOrderInfo &zero_order_info) const =0
Overridden to compute f(x) (and perhaps other quantities if set).
void assert_ref_set(T *p, std::string info) const
Assert referece has been set for a quanity.
virtual void set_options(const options_ptr_t &options)
Set the options that this NLP may be interested in.
virtual void imp_calc_h_breve(const Vector &x, bool newx, const ZeroOrderInfo &zero_order_info_breve) const
Overridden to compute h_breve(x_breve) and perhaps f(x) and/or c_breve(x_breve).
virtual void imp_calc_c(const Vector &x, bool newx, const ZeroOrderInfo &zero_order_info) const =0
Overridden to compute c(x) and perhaps f(x) and/or h(x) (if multiple calculaiton = true)...
virtual void unset_quantities()
Call to unset all storage quantities (both in this class and all subclasses).
virtual const Vector & hl_breve() const
Returns a reference to the vector of lower bounds on the general inequality constraints h_breve(x_bre...
virtual void calc_f(const Vector &x, bool newx=true) const
Update the value for the objective f at the point x and put it in the stored reference.
virtual size_type n() const
Return the number of variables.
virtual vec_space_ptr_t space_c() const =0
Vector space object for general equality constraints c(x) (dimension m).
virtual const Vector & xl() const =0
Returns the lower bounds on the variables x.
size_t size_type
const ZeroOrderInfo zero_order_info_breve() const
Return pointer to set hat quantities.
virtual size_type num_bounded_x() const =0
Returns the number of variables in x(i) for which xl(i)> -infinite_bound() or xu(i) < +infinite_bound...
Teuchos::RCP< const OptionsFromStreamPack::OptionsFromStream > options_ptr_t
virtual void set_c(VectorMutable *c)
Set a pointer to a vector to be updated when this->calc_c() is called.
virtual bool force_xinit_in_bounds() const =0
Returns if the initial point must be within the bounds.
virtual const Vector & xu() const =0
Returns a reference to the vector of upper bounds on the variables x.
virtual value_type * get_f()
Return pointer passed to this->set_f().
Teuchos::RCP< const VectorSpace > vec_space_ptr_t
virtual ~NLP()
Destructor that cleans all the memory it owns.
Struct for objective and constriants (pointer).
virtual const options_ptr_t & get_options() const
Get the OptionsFromStream object being used to extract the options from.
NLP interface class {abstract}.
virtual vec_space_ptr_t space_h_breve() const
Vector space object for the original inequalities h_breve(x_breve)
Thrown if any member functions are called before initialize() has been called.
virtual const Permutation & P_var() const
Return the permutation object for the variables.
virtual value_type max_var_bounds_viol() const =0
Set the maximum absolute value for which the variable bounds may be violated by when computing functi...
NLP()
Initialize to no reference set to calculation quanities.
virtual void set_c_breve(VectorMutable *c_breve)
Set a pointer to a vector to be updated when this->calc_c_breve() is called.
virtual const Permutation & P_equ() const
Return the permutation object for the constraints.
virtual const Vector & hu_breve() const
Returns a reference to the vector of upper bounds on the general inequality constraints h_breve(x_bre...
virtual void calc_h_breve(const Vector &x, bool newx=true) const
Update the constraint residual vector for h_breve at the point x and put it in the stored reference...
value_type * f
Pointer to objective function f (Will be NULL if not set)
virtual void set_h_breve(VectorMutable *h_breve)
Set a pointer to a vector to be updated when this->calc_h_breve() is called.
virtual bool is_initialized() const =0
Return if this is initialized.
virtual void calc_c_breve(const Vector &x, bool newx=true) const
Update the constraint residual vector for c_breve at the point x and put it in the stored reference...
virtual const Vector & xinit() const =0
Returns a reference to the vector of the initial guess for the solution x.
Thrown some bounds do not existe.
Thrown from initialize() if some logical error occured.
virtual size_type m() const
Return the number of general equality constraints.
virtual void initialize(bool test_setup=false)
Initialize the NLP before it is used.
virtual size_type num_f_evals() const
Gives the number of object function f(x) evaluations called by the solver since initialize() was call...
virtual VectorMutable * get_h_breve()
Return pointer passed to this->set_h_breve().
static value_type infinite_bound()
Value for an infinite bound.
virtual VectorMutable * get_c()
Return pointer passed to this->set_c().
VectorMutable * h
Pointer to inequality constraints h (Will be NULL if not set)
virtual void set_f(value_type *f)
Set a pointer to an value to be updated when this->calc_f() is called.
virtual VectorMutable & c()
Returns non-const *this->get_c().
virtual VectorMutable & h_breve()
Returns non-const *this->get_h_breve().