MOOCHO  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
NLPInterfacePack_ExampleNLPObjGrad.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 EXAMPLE_NLP_OBJ_GRADIENT_H
43 #define EXAMPLE_NLP_OBJ_GRADIENT_H
44 
45 #include "NLPInterfacePack_NLPObjGrad.hpp"
46 #include "AbstractLinAlgPack_VectorMutable.hpp"
47 #include "AbstractLinAlgPack_VectorSpace.hpp"
48 #include "AbstractLinAlgPack_VectorSpaceBlocked.hpp"
49 #include "Teuchos_Assert.hpp"
50 
51 namespace NLPInterfacePack {
52 
72 class ExampleNLPObjGrad : virtual public NLPObjGrad {
73 public:
74 
89  const VectorSpace::space_ptr_t& vec_space
90  ,value_type xo
91  ,bool has_bounds
92  ,bool dep_bounded
93  );
94 
97 
99  virtual Range1D var_dep() const;
101  virtual Range1D var_indep() const;
102 
104 
107 
109  void initialize(bool test_setup);
111  bool is_initialized() const;
113  size_type n() const;
115  size_type m() const;
117  vec_space_ptr_t space_x() const;
119  vec_space_ptr_t space_c() const;
121  size_type num_bounded_x() const;
125  bool force_xinit_in_bounds() const;
127  const Vector& xinit() const;
129  const Vector& xl() const;
131  const Vector& xu() const;
133  value_type max_var_bounds_viol() const;
135  void scale_f( value_type scale_f );
137  value_type scale_f() const;
140  const Vector& x
141  ,const Vector* lambda
142  ,const Vector* nu
143  ,bool optimal
144  );
145 
147 
148 protected:
149 
152 
154  void imp_calc_f(
155  const Vector& x, bool newx
156  ,const ZeroOrderInfo& zero_order_info) const;
158  void imp_calc_c(
159  const Vector& x, bool newx
160  ,const ZeroOrderInfo& zero_order_info) const;
162  void imp_calc_h(const Vector& x, bool newx, const ZeroOrderInfo& zero_order_info) const;
163 
165 
168 
170  void imp_calc_Gf(
171  const Vector& x, bool newx
172  ,const ObjGradInfo& obj_grad_info) const;
173 
175 
176 private:
177 
178  // /////////////////////////////////////////
179  // Private data members
180 
181  VectorSpace::space_ptr_t vec_space_; // The vector space for dependent and indepenent variables and c(x).
182  VectorSpace::space_ptr_t vec_space_comp_; // Composite vector space for x = [ xD; xI ]
183  Range1D var_dep_; // Range for dependnet variables.
184  Range1D var_indep_; // Range for independent variables.
185 
186  bool initialized_; // flag for if initialized has been called.
187  value_type obj_scale_; // default = 1.0;
188  bool has_bounds_; // default = true
189  bool force_xinit_in_bounds_; // default = true.
190 
191  size_type n_; // Number of variables in the problem.
192  VectorSpace::vec_mut_ptr_t xinit_; // Initial guess.
193  VectorSpace::vec_mut_ptr_t xl_; // lower bounds.
194  VectorSpace::vec_mut_ptr_t xu_; // upper bounds.
195 
196  // /////////////////////////////////////////
197  // Private member functions
198 
200  void assert_is_initialized() const;
201 
202 }; // end class ExampleNLPObjGrad
203 
204 // ///////////////////////////////////////////////
205 // Inline member functions
206 
207 inline
208 void ExampleNLPObjGrad::assert_is_initialized() const
209 {
210  typedef NLPInterfacePack::NLP NLP;
213  ,"ExampleNLPObjGrad::assert_is_initialized() : Error, "
214  "ExampleNLPObjGrad::initialize() has not been called yet." );
215 }
216 
217 } // end namespace NLPInterfacePack
218 
219 #endif // EXAMPLE_NLP_OBJ_GRADIENT_H
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
const ZeroOrderInfo zero_order_info() const
void imp_calc_f(const Vector &x, bool newx, const ZeroOrderInfo &zero_order_info) const
void report_final_solution(const Vector &x, const Vector *lambda, const Vector *nu, bool optimal)
void imp_calc_c(const Vector &x, bool newx, const ZeroOrderInfo &zero_order_info) const
size_t size_type
void imp_calc_h(const Vector &x, bool newx, const ZeroOrderInfo &zero_order_info) const
This implementation does nothing (should never be called though).
Simple example NLP subclass to illustrate how to implement the NLPObjGrad interface for a specialized...
ExampleNLPObjGrad(const VectorSpace::space_ptr_t &vec_space, value_type xo, bool has_bounds, bool dep_bounded)
Constructor.
void imp_calc_Gf(const Vector &x, bool newx, const ObjGradInfo &obj_grad_info) const