MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NLPInterfacePack_NLPThyraModelEvaluatorBase.hpp
Go to the documentation of this file.
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 NLPIP_NLP_THYRA_MODEL_EVALUATOR_BASE_HPP
43 #define NLPIP_NLP_THYRA_MODEL_EVALUATOR_BASE_HPP
44 
45 #include <vector>
46 
49 #include "Thyra_ModelEvaluator.hpp"
50 #include "Teuchos_Assert.hpp"
52 
53 namespace AbstractLinAlgPack { class VectorSpaceThyra; }
54 
55 namespace NLPInterfacePack {
56 
92 class NLPThyraModelEvaluatorBase : virtual public NLPObjGrad {
93 public:
94 
96  STANDARD_MEMBER_COMPOSITION_MEMBERS( bool, showModelEvaluatorTrace );
97 
100 
102  void initialize(bool test_setup);
104  bool is_initialized() const;
106  vec_space_ptr_t space_x() const;
108  vec_space_ptr_t space_c() const;
110  size_type num_bounded_x() const;
114  bool force_xinit_in_bounds() const;
116  const Vector& xinit() const;
118  const Vector& xl() const;
120  const Vector& xu() const;
124  void set_f(value_type* f);
126  void set_c(VectorMutable* c);
128  void unset_quantities();
130  void scale_f( value_type scale_f );
132  value_type scale_f() const;
135  const Vector& x
136  ,const Vector* lambda
137  ,const Vector* nu
138  ,bool optimal
139  );
140 
142 
145 
147  void set_Gf(VectorMutable* Gf);
148 
150 
151 protected:
152 
155 
157  void imp_calc_f(
158  const Vector& x, bool newx
159  ,const ZeroOrderInfo& zero_order_info) const;
161  void imp_calc_c(
162  const Vector& x, bool newx
163  ,const ZeroOrderInfo& zero_order_info) const;
164 
166 
169 
171  void imp_calc_Gf(
172  const Vector& x, bool newx
173  ,const ObjGradInfo& obj_grad_info) const;
174 
176 
177 protected:
178 
181 
184 
205  void initializeBase(
206  const Teuchos::RCP<Thyra::ModelEvaluator<value_type> > &model
207  ,const int p_idx
208  ,const int g_idx
209  );
210 
212  void updateInitialGuessAndBounds() const;
213 
215  void assert_is_initialized() const;
217  void copy_from_model_x( const Thyra::VectorBase<value_type>* model_x, VectorMutable* x_D ) const;
219  void copy_from_model_p( const Thyra::VectorBase<value_type> *model_p, VectorMutable* x_I ) const;
221  void set_x(
222  const Vector &x
223  ,Thyra::ModelEvaluatorBase::InArgs<value_type> *model_inArgs_inout
224  ) const;
227  const Vector &x
228  ,bool newx
229  ,const ZeroOrderInfo *zero_order_info
230  ,const ObjGradInfo *obj_grad_info
231  ,const NLPFirstOrder::FirstOrderInfo *first_order_info
232  ,Thyra::ModelEvaluatorBase::InArgs<value_type> *model_inArgs_inout
233  ,Thyra::ModelEvaluatorBase::OutArgs<value_type> *model_outArgs_inout
234  ,MatrixOp* *Gc_out
235  ,VectorMutable* *Gf_out
236  ,value_type* *f_out
237  ,VectorMutable* *c_out
238  ) const;
241  Thyra::ModelEvaluatorBase::OutArgs<value_type> *model_outArgs_inout
242  ,VectorMutable *Gf
243  ,value_type *f
244  ,VectorMutable *c
245  ) const;
246 
248 
249 //private: // ToDo: Make these private and refactor the other classes ...
250 
251  // /////////////////////////////////////////
252  // Private types
253 
255 
256  // /////////////////////////////////////////
257  // Private data members
258 
259  bool initialized_; // flag for if initialized has been called.
260  value_type obj_scale_; // default = 1.0;
261  bool has_bounds_; // True if has bounds
262  bool force_xinit_in_bounds_; // default = true.
266  int p_idx_;
267  int g_idx_;
270  VectorSpace::space_ptr_t space_x_; // Space for the variables
271  VectorSpaceThyra_ptr_t space_c_; // Space for the constraints
275  VectorSpace::vec_mut_ptr_t xinit_; // Initial guess.
276  VectorSpace::vec_mut_ptr_t xl_; // lower bounds.
277  VectorSpace::vec_mut_ptr_t xu_; // upper bounds.
278 
280 
281  mutable bool model_g_updated_;
282  mutable bool model_Dg_updated_;
283 
284  mutable bool f_updated_;
285  mutable bool c_updated_;
286  mutable bool Gf_updated_;
287  mutable bool Gc_updated_;
288 
289  // /////////////////////////////////////////
290  // Private member functions
291 
293  void evalModel(
294  const Vector &x
295  ,bool newx
296  ,const ZeroOrderInfo *zero_order_info // != NULL if only zero-order info
297  ,const ObjGradInfo *obj_grad_info // != NULL if obj-grad and below info
298  ) const;
299 
300 }; // end class NLPThyraModelEvaluatorBase
301 
302 } // end namespace NLPInterfacePack
303 
304 #endif // NLPIP_NLP_THYRA_MODEL_EVALUATOR_BASE_HPP
NLP interface class that adds gradient information for the objective function {abstract}.
virtual value_type & f()
Returns non-const *this->get_f().
AbstractLinAlgPack::size_type size_type
Struct for gradient (objective), objective and constriants (pointers)
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
void postprocessBaseOutArgs(Thyra::ModelEvaluatorBase::OutArgs< value_type > *model_outArgs_inout, VectorMutable *Gf, value_type *f, VectorMutable *c) const
void initializeBase(const Teuchos::RCP< Thyra::ModelEvaluator< value_type > > &model, const int p_idx, const int g_idx)
Initialize given a Thyra::ModelEvaluator and a description of how to interpret it.
const ZeroOrderInfo zero_order_info() const
Return pointer to set quantities.
const ObjGradInfo obj_grad_info() const
Return objective gradient and zero order information.
void report_final_solution(const Vector &x, const Vector *lambda, const Vector *nu, bool optimal)
void imp_calc_f(const Vector &x, bool newx, const ZeroOrderInfo &zero_order_info) const
Teuchos::RCP< const AbstractLinAlgPack::VectorSpaceThyra > VectorSpaceThyra_ptr_t
void imp_calc_Gf(const Vector &x, bool newx, const ObjGradInfo &obj_grad_info) const
void copy_from_model_p(const Thyra::VectorBase< value_type > *model_p, VectorMutable *x_I) const
void copy_from_model_x(const Thyra::VectorBase< value_type > *model_x, VectorMutable *x_D) const
Struct for zero and first order quantities (pointers)
Implements the base NLP interface using a Thyra::ModelEvaluator object.
void preprocessBaseInOutArgs(const Vector &x, bool newx, const ZeroOrderInfo *zero_order_info, const ObjGradInfo *obj_grad_info, const NLPFirstOrder::FirstOrderInfo *first_order_info, Thyra::ModelEvaluatorBase::InArgs< value_type > *model_inArgs_inout, Thyra::ModelEvaluatorBase::OutArgs< value_type > *model_outArgs_inout, MatrixOp **Gc_out, VectorMutable **Gf_out, value_type **f_out, VectorMutable **c_out) const
Struct for objective and constriants (pointer).
Teuchos::RCP< Thyra::ModelEvaluator< value_type > > model_
AbstractLinAlgPack::value_type value_type
void set_x(const Vector &x, Thyra::ModelEvaluatorBase::InArgs< value_type > *model_inArgs_inout) const
Abstract interface for mutable coordinate vectors {abstract}.
STANDARD_MEMBER_COMPOSITION_MEMBERS(bool, showModelEvaluatorTrace)
Set if a trace of the model evaluations is shown or not.
void updateInitialGuessAndBounds() const
Update the initial guess and bounds .
virtual VectorMutable & Gf()
Returns non-const *this->get_Gf().
void imp_calc_c(const Vector &x, bool newx, const ZeroOrderInfo &zero_order_info) const
void evalModel(const Vector &x, bool newx, const ZeroOrderInfo *zero_order_info, const ObjGradInfo *obj_grad_info) const
virtual VectorMutable & c()
Returns non-const *this->get_c().