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_NLPSerialPreprocessExplJac.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_SERIAL_PREPROCESS_EXPL_JAC_H
43 #define NLP_SERIAL_PREPROCESS_EXPL_JAC_H
44 
45 #include <valarray>
46 
47 #include "NLPInterfacePack_NLPSerialPreprocess.hpp"
48 #include "NLPInterfacePack_NLPFirstOrder.hpp"
49 #include "AbstractLinAlgPack_BasisSystemFactoryStd.hpp"
50 #include "DenseLinAlgPack_DVectorClass.hpp"
51 #include "Teuchos_AbstractFactory.hpp"
53 
54 namespace NLPInterfacePack {
55 
94  : virtual public NLPSerialPreprocess
95  , virtual public NLPFirstOrder
96 {
97 public:
98 
101 
103  typedef Teuchos::RCP<
105 
107 
110 
112  STANDARD_COMPOSITION_MEMBERS( BasisSystemFactory, basis_sys_fcty );
113 
117  const basis_sys_fcty_ptr_t &basis_sys_fcty = Teuchos::rcp(new BasisSystemFactoryStd())
118  ,const factory_mat_ptr_t &factory_Gc_full = Teuchos::null
119  );
120 
131  void set_factory_Gc_full( const factory_mat_ptr_t &factory_Gc_full );
132 
134 
137 
139  void set_options( const options_ptr_t& options );
141  const options_ptr_t& get_options() const;
143  void initialize(bool test_setup);
145  bool is_initialized() const;
146 
148 
151 
153  const mat_fcty_ptr_t factory_Gc() const;
155  const basis_sys_ptr_t basis_sys() const;
157  void set_Gc(MatrixOp* Gc);
158 
160 
163 
165  bool get_next_basis(
166  Permutation* P_var, Range1D* var_dep
167  ,Permutation* P_equ, Range1D* equ_decomp
168  );
170  void set_basis(
171  const Permutation &P_var, const Range1D &var_dep
172  ,const Permutation *P_equ, const Range1D *equ_decomp
173  );
174 
176 
177 
178 protected:
179 
182 
184  void imp_calc_Gc(
185  const Vector& x, bool newx
187  ) const;
188 
190 
193 
229  typedef std::valarray<value_type> val_t;
231  typedef std::valarray<index_type> ivect_t;
232  //
233  typedef std::valarray<index_type> jvect_t;
236  :Gc_val(NULL), Gc_ivect(NULL), Gc_jvect(NULL)
237  ,Gh_val(NULL), Gh_ivect(NULL), Gh_jvect(NULL)
238  ,f(NULL)
239  {}
242  index_type* Gc_nz_in, val_t* Gc_val_in, ivect_t* Gc_ivect_in, jvect_t* Gc_jvect_in
243  ,index_type* Gh_nz_in, val_t* Gh_val_in, ivect_t* Gh_ivect_in, jvect_t* Gh_jvect_in
244  ,const ObjGradInfoSerial& obj_grad
245  )
246  :Gc_nz(Gc_nz_in), Gc_val(Gc_val_in), Gc_ivect(Gc_ivect_in), Gc_jvect(Gc_jvect_in)
247  ,Gh_nz(Gh_nz_in), Gh_val(Gh_val_in), Gh_ivect(Gh_ivect_in), Gh_jvect(Gh_jvect_in)
248  ,Gf(obj_grad.Gf), f(obj_grad.f), c(obj_grad.c), h(obj_grad.h)
249  {}
257  jvect_t* Gc_jvect;
265  jvect_t* Gh_jvect;
267  DVector* Gf;
269  value_type* f;
271  DVector* c;
273  DVector* h;
274  }; // end struct FirstOrderExplInfo
275 
277 
280 
287  virtual size_type imp_Gc_nz_orig() const = 0;
288 
295  virtual size_type imp_Gh_nz_orig() const = 0;
296 
337  virtual void imp_calc_Gc_orig(
338  const DVectorSlice& x_full, bool newx
340  ) const = 0;
341 
382  virtual void imp_calc_Gh_orig(
383  const DVectorSlice& x_full, bool newx
385  ) const = 0;
386 
388 
391 
393  void assert_initialized() const;
394 
397 
399 
400 private:
401 
402  // ////////////////////////////////////////
403  // Private data members
404 
405  bool initialized_; // Flag for if the NLP has has been properly initialized
406  bool test_setup_; // Flag for if to test the setup of things or not
407  options_ptr_t options_; // The options being used
408 
409  factory_mat_ptr_t factory_Gc_full_;
410  mat_fcty_ptr_t factory_Gc_;
411 
412  mutable size_type Gc_nz_orig_; // Number of nonzeros in the original NLP Gc
413  mutable size_type Gh_nz_orig_; // Number of nonzeros in the original NLP Gh
414  mutable size_type Gc_nz_full_; // Number of nonzeros in the full NLP Gc
415  mutable size_type Gh_nz_full_; // Number of nonzeros in the full NLP Gh
416  mutable FirstOrderExplInfo::val_t Gc_val_orig_; // Storage for explicit nonzeros of full Gc
417  mutable FirstOrderExplInfo::ivect_t Gc_ivect_orig_;
418  mutable FirstOrderExplInfo::jvect_t Gc_jvect_orig_;
419  mutable FirstOrderExplInfo::val_t Gh_val_orig_; // Storage for explicit nonzeros of orig Gh
420  mutable FirstOrderExplInfo::ivect_t Gh_ivect_orig_;
421  mutable FirstOrderExplInfo::jvect_t Gh_jvect_orig_;
422 
423  mutable bool Gc_perm_new_basis_updated_; // Flag for if a new basis was set!
424 
425  // ////////////////////////////
426  // Private member functions
427 
428  //
429  void imp_calc_Gc_or_Gh(
430  bool calc_Gc
431  ,const Vector& x, bool newx
433  ) const;
434 
435  //
436  void imp_fill_jacobian_entries(
437  size_type n // [in]
438  ,size_type n_full // [in]
439  ,bool load_struct // [in] If true, then the structure is loaded also
440  ,const index_type col_offset // [in] Offset for filled column indexes
441  ,const value_type *val_full // [in] Values (!=NULL)
442  ,const value_type *val_full_end // [in] Values end (!=NULL)
443  ,const index_type *ivect_full // [in] Row indexes (!=NULL)
444  ,const index_type *jvect_full // [in] Column indexes (!=NULL)
445  ,index_type *nz // [in/out] Number of nonzeros added (!=NULL)
446  ,value_type *val_itr // [out] Values to fill (!=NULL)
447  ,index_type *ivect_itr // [out] Row indexes (can be NULL if load_struct == false)
448  ,index_type *jvect_itr // [out] Column indexes (can be NULL if load_struct == false)
449  ) const;
450 
451 }; // end class NLPSerialPreprocessExplJac
452 
453 // ///////////////////////////
454 // inline members
455 
456 inline
459 {
460  return FirstOrderExplInfo(
461  &Gc_nz_orig_
462  ,&Gc_val_orig_
463  ,&Gc_ivect_orig_
464  ,&Gc_jvect_orig_
465  ,&Gh_nz_orig_
466  ,&Gh_val_orig_
467  ,&Gh_ivect_orig_
468  ,&Gh_jvect_orig_
470  );
471 }
472 
473 } // end namespace NLPInterfacePack
474 
475 #endif // NLP_SERIAL_PREPROCESS_EXPL_JAC_H
void set_basis(const Permutation &P_var, const Range1D &var_dep, const Permutation *P_equ, const Range1D *equ_decomp)
virtual void calc_Gc(const Vector &x, bool newx=true) const
Update the matrix for Gc at the point x and put it in the stored reference.
NLP node subclass complementing NLPSerialPreprocess for explicit Jacobians.
const basis_sys_ptr_t basis_sys() const
Calls basis_sys_fcty()->create()
void set_factory_Gc_full(const factory_mat_ptr_t &factory_Gc_full)
Initialize with matrix factory for original matrices Gc.
NLPSerialPreprocessExplJac(const basis_sys_fcty_ptr_t &basis_sys_fcty=Teuchos::rcp(new BasisSystemFactoryStd()), const factory_mat_ptr_t &factory_Gc_full=Teuchos::null)
Calls this->set_basis_sys_fcty() and this->set_mat_factories() methods.
bool get_next_basis(Permutation *P_var, Range1D *var_dep, Permutation *P_equ, Range1D *equ_decomp)
const FirstOrderInfo first_order_info() const
Return objective gradient and zero order information.
NLP node implementation subclass for preprocessing and basis manipulation.
DVectorSlice x_full() const
Give reference to current x_full.
FirstOrderExplInfo(index_type *Gc_nz_in, val_t *Gc_val_in, ivect_t *Gc_ivect_in, jvect_t *Gc_jvect_in, index_type *Gh_nz_in, val_t *Gh_val_in, ivect_t *Gh_ivect_in, jvect_t *Gh_jvect_in, const ObjGradInfoSerial &obj_grad)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual void imp_calc_Gh_orig(const DVectorSlice &x_full, bool newx, const FirstOrderExplInfo &first_order_expl_info) const =0
Calculate the COOR matrix for the gradient for all of the h(x) constaints in the original NLP...
size_t size_type
Struct for zero and first order quantities (pointers)
Teuchos::RCP< const OptionsFromStreamPack::OptionsFromStream > options_ptr_t
Teuchos::RCP< const Teuchos::AbstractFactory< MatrixOp > > factory_mat_ptr_t
Struct for zero and explicit first order quantities that subclass must fill in.
virtual size_type imp_Gh_nz_orig() const =0
Return the number of nonzero elements in Gh before elements are removed for fixed variables...
void set_Gc(MatrixOp *Gc)
Validates the type of Gc is correct.
NLP first order information interface class {abstract}.
virtual void imp_calc_Gc_orig(const DVectorSlice &x_full, bool newx, const FirstOrderExplInfo &first_order_expl_info) const =0
Calculate the COOR matrix for the gradient for all of the c(x) constaints in the original NLP...
virtual size_type imp_Gc_nz_orig() const =0
Return the number of nonzero elements in Gc before elements are removed for fixed variables...
virtual MatrixOp & Gc()
Returns non-const *this->get_Gc().
void set_options(const options_ptr_t &options)
Passes these options on to this->basis_sys_fcty().set_options(options).
void assert_initialized() const
Assert if we have been initizlized (throws UnInitialized)
Struct for serial gradient (objective), objective and constriants (pointers)
void imp_calc_Gc(const Vector &x, bool newx, const FirstOrderInfo &first_order_info) const
STANDARD_COMPOSITION_MEMBERS(BasisSystemFactory, basis_sys_fcty)
Set the BasisSystemFactory object used to create the basis system.