MoochoPack_NLPAlgoState.cpp

00001 // @HEADER
00002 // ***********************************************************************
00003 // 
00004 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00005 //                  Copyright (2003) Sandia Corporation
00006 // 
00007 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00008 // license for use of this work by or on behalf of the U.S. Government.
00009 // 
00010 // This library is free software; you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as
00012 // published by the Free Software Foundation; either version 2.1 of the
00013 // License, or (at your option) any later version.
00014 //  
00015 // This library is distributed in the hope that it will be useful, but
00016 // WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 // Lesser General Public License for more details.
00019 //  
00020 // You should have received a copy of the GNU Lesser General Public
00021 // License along with this library; if not, write to the Free Software
00022 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00023 // USA
00024 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00025 // 
00026 // ***********************************************************************
00027 // @HEADER
00028 
00029 #include <sstream>
00030 #include <typeinfo>
00031 
00032 #include "MoochoPack_NLPAlgoState.hpp"
00033 #include "ConstrainedOptPack_MeritFuncNLP.hpp"
00034 #include "AbstractLinAlgPack_MatrixSymOp.hpp"
00035 #include "AbstractLinAlgPack_MatrixOpNonsing.hpp"
00036 #include "Teuchos_dyn_cast.hpp"
00037 
00038 #include "IterationPack_IterQuantityAccess.hpp"
00039 #include "IterationPack_cast_iq.hpp"
00040 #include "IterationPack_IterQuantityAccessContiguous.hpp"
00041 
00042 // NLPAlgoState iteration quantities names
00043 
00044 // Iteration Info
00045 const std::string MoochoPack::num_basis_name    = "num_basis";
00046 // NLP Problem Info 
00047 const std::string MoochoPack::x_name        = "x";
00048 const std::string MoochoPack::f_name        = "f";
00049 const std::string MoochoPack::Gf_name       = "Gf";
00050 const std::string MoochoPack::HL_name       = "HL";
00051 const std::string MoochoPack::c_name        = "c";
00052 const std::string MoochoPack::Gc_name       = "Gc";
00053 // Constraint Gradient Null Space / Range Space Decomposition Info
00054 const std::string MoochoPack::Y_name        = "Y";
00055 const std::string MoochoPack::Z_name        = "Z";
00056 const std::string MoochoPack::R_name        = "R";
00057 const std::string MoochoPack::Uy_name       = "Uy";
00058 const std::string MoochoPack::Uz_name       = "Uz";
00059 // Search Direction Info
00060 const std::string MoochoPack::py_name       = "py";
00061 const std::string MoochoPack::Ypy_name        = "Ypy";
00062 const std::string MoochoPack::pz_name       = "pz";
00063 const std::string MoochoPack::Zpz_name        = "Zpz";
00064 const std::string MoochoPack::d_name        = "d";
00065 // Reduced QP Subproblem Info
00066 const std::string MoochoPack::rGf_name        = "rGf";
00067 const std::string MoochoPack::rHL_name        = "rHL";
00068 const std::string MoochoPack::w_name        = "w";
00069 const std::string MoochoPack::zeta_name     = "zeta";
00070 const std::string MoochoPack::qp_grad_name      = "qp_grad";
00071 const std::string MoochoPack::eta_name        = "eta";
00072 // Global Convergence Info
00073 const std::string MoochoPack::alpha_name      = "alpha";
00074 const std::string MoochoPack::merit_func_nlp_name = "merit_func_nlp";
00075 const std::string MoochoPack::mu_name       = "mu";
00076 const std::string MoochoPack::phi_name        = "phi";
00077 // KKT Info
00078 const std::string MoochoPack::opt_kkt_err_name    = "opt_kkt_err";
00079 const std::string MoochoPack::feas_kkt_err_name = "feas_kkt_err";
00080 const std::string MoochoPack::comp_kkt_err_name = "comp_kkt_err";
00081 const std::string MoochoPack::GL_name       = "GL";
00082 const std::string MoochoPack::rGL_name        = "rGL";
00083 const std::string MoochoPack::lambda_name     = "lambda";
00084 const std::string MoochoPack::nu_name       = "nu";
00085 
00086 namespace MoochoPack {
00087 
00088 // Constructors / initializers
00089 
00090 void NLPAlgoState::set_space_range (const vec_space_ptr_t& space_range )
00091 {
00092   space_range_ = space_range;
00093   update_vector_factories(VST_SPACE_RANGE,space_range);
00094 }
00095 
00096 void NLPAlgoState::set_space_null (const vec_space_ptr_t& space_null )
00097 {
00098   space_null_ = space_null;
00099   update_vector_factories(VST_SPACE_NULL,space_null);
00100 }
00101 
00102 NLPAlgoState::NLPAlgoState(
00103   const decomp_sys_ptr_t& decomp_sys
00104   ,const vec_space_ptr_t& space_x
00105   ,const vec_space_ptr_t& space_c
00106   ,const vec_space_ptr_t& space_range
00107   ,const vec_space_ptr_t& space_null
00108   )
00109   :decomp_sys_(decomp_sys)
00110   ,space_x_(space_x)
00111   ,space_c_(space_c)
00112   ,space_range_(space_range)
00113   ,space_null_(space_null)
00114 {}
00115 
00116 // Iteration Info
00117 
00118 STATE_INDEX_IQ_DEF(  NLPAlgoState,              num_basis, num_basis_name          )
00119 
00120 // NLP Problem Info
00121 
00122 STATE_VECTOR_IQ_DEF( NLPAlgoState,              x,         x_name,  get_space_x(), VST_SPACE_X  )
00123 STATE_SCALAR_IQ_DEF( NLPAlgoState,              f,         f_name                               )
00124 STATE_IQ_DEF(        NLPAlgoState, MatrixSymOp, HL,        HL_name                              )
00125 STATE_VECTOR_IQ_DEF( NLPAlgoState,              Gf,        Gf_name, get_space_x(), VST_SPACE_X  )
00126 STATE_VECTOR_IQ_DEF( NLPAlgoState,              c,         c_name,  get_space_c(), VST_SPACE_C  )
00127 STATE_IQ_DEF(        NLPAlgoState, MatrixOp,    Gc,        Gc_name                              )
00128 
00129 // Constraint Gradient Null Space / Range Space Decomposition Info
00130 
00131 STATE_IQ_DEF(        NLPAlgoState, MatrixOp,        Y,  Y_name                  )
00132 STATE_IQ_DEF(        NLPAlgoState, MatrixOp,        Z,  Z_name                  )
00133 STATE_IQ_DEF(        NLPAlgoState, MatrixOpNonsing, R,  R_name                  )
00134 STATE_IQ_DEF(        NLPAlgoState, MatrixOp,        Uy, Uy_name                 )
00135 STATE_IQ_DEF(        NLPAlgoState, MatrixOp,        Uz, Uz_name                 )
00136 
00137 // Search Direction Info
00138 
00139 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  py,  py_name,   get_space_range(), VST_SPACE_RANGE )
00140 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  Ypy, Ypy_name,  get_space_x(),     VST_SPACE_X     )
00141 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  pz,  pz_name,   get_space_null(),  VST_SPACE_NULL  )
00142 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  Zpz, Zpz_name,  get_space_x(),     VST_SPACE_X     )
00143 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  d,   d_name,    get_space_x(),     VST_SPACE_X     )
00144 
00145 // QP Subproblem Info
00146 
00147 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  rGf,     rGf_name,      get_space_null(), VST_SPACE_NULL )
00148 STATE_IQ_DEF(        NLPAlgoState, MatrixSymOp,     rHL,     rHL_name                                        )
00149 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  w,       w_name,        get_space_null(), VST_SPACE_NULL ) 
00150 STATE_SCALAR_IQ_DEF( NLPAlgoState,                  zeta,    zeta_name                                       )
00151 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  qp_grad, qp_grad_name,  get_space_null(), VST_SPACE_NULL )
00152 STATE_SCALAR_IQ_DEF( NLPAlgoState,                  eta,     eta_name                                        )
00153 
00154 // Global Convergence Info
00155 
00156 STATE_SCALAR_IQ_DEF( NLPAlgoState,                  alpha,          alpha_name          )
00157 STATE_IQ_DEF(        NLPAlgoState, MeritFuncNLP,    merit_func_nlp, merit_func_nlp_name )
00158 STATE_SCALAR_IQ_DEF( NLPAlgoState,                  mu,             mu_name             )
00159 STATE_SCALAR_IQ_DEF( NLPAlgoState,                  phi,            phi_name            )
00160 
00161 // KKT Info
00162 
00163 STATE_SCALAR_IQ_DEF( NLPAlgoState,                  opt_kkt_err,    opt_kkt_err_name                                    )
00164 STATE_SCALAR_IQ_DEF( NLPAlgoState,                  feas_kkt_err,   feas_kkt_err_name                                   )
00165 STATE_SCALAR_IQ_DEF( NLPAlgoState,                  comp_kkt_err,   comp_kkt_err_name                                   )
00166 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  GL,             GL_name,           get_space_x(),    VST_SPACE_X    )
00167 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  rGL,            rGL_name,          get_space_null(), VST_SPACE_NULL )
00168 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  lambda,         lambda_name,       get_space_c(),    VST_SPACE_C    )
00169 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  nu,             nu_name,           get_space_x(),    VST_SPACE_X    )
00170 
00171 // protected
00172 
00173 void NLPAlgoState::update_iq_id(
00174   const std::string&                iq_name
00175   ,iq_id_encap*                     iq_id
00176   ) const
00177 {
00178   namespace rcp = MemMngPack;
00179   if(iq_id->iq_id == DOES_NOT_EXIST)
00180     iq_id->iq_id = this->get_iter_quant_id(iq_name);
00181   TEST_FOR_EXCEPTION(
00182     iq_id->iq_id == DOES_NOT_EXIST, DoesNotExist
00183     ,"NLPAlgoState::update_iq_id(iq_name,iq_id) : Error, "
00184     " The iteration quantity with name \'" << iq_name <<
00185     "\' does not exist!" );
00186 }
00187 
00188 void NLPAlgoState::update_index_type_iq_id(
00189   const std::string&                iq_name
00190   ,iq_id_encap*                     iq_id
00191   )
00192 {
00193   namespace rcp = MemMngPack;
00194   if(iq_id->iq_id == DOES_NOT_EXIST) {
00195     iq_id_type
00196       _iq_id = this->get_iter_quant_id(iq_name);
00197     if(_iq_id == DOES_NOT_EXIST) {
00198       iq_id->iq_id = this->set_iter_quant(
00199         iq_name
00200         ,Teuchos::rcp(
00201           new IterQuantityAccessContiguous<index_type>(
00202             1
00203             ,iq_name
00204 #ifdef _MIPS_CXX
00205             ,Teuchos::RCP<Teuchos::AbstractFactoryStd<index_type,index_type> >(
00206               new Teuchos::AbstractFactoryStd<index_type,index_type>())
00207 #endif
00208             )
00209           )
00210         );
00211     }
00212     else {
00213       iq_id->iq_id = _iq_id;
00214     }
00215   }
00216 }
00217 
00218 void NLPAlgoState::update_value_type_iq_id(
00219   const std::string&                iq_name
00220   ,iq_id_encap*                     iq_id
00221   )
00222 {
00223   namespace rcp = MemMngPack;
00224   if(iq_id->iq_id == DOES_NOT_EXIST) {
00225     iq_id_type
00226       _iq_id = this->get_iter_quant_id(iq_name);
00227     if(_iq_id == DOES_NOT_EXIST) {
00228       iq_id->iq_id = this->set_iter_quant(
00229         iq_name
00230         ,Teuchos::rcp(
00231           new IterQuantityAccessContiguous<value_type>(
00232             1
00233             ,iq_name
00234 #ifdef _MIPS_CXX
00235             ,Teuchos::RCP<Teuchos::AbstractFactoryStd<value_type,value_type> >(
00236               new Teuchos::AbstractFactoryStd<value_type,value_type>())
00237 #endif
00238             )
00239           )
00240         );
00241     }
00242     else {
00243       iq_id->iq_id = _iq_id;
00244     }
00245   }
00246 }
00247 
00248 void NLPAlgoState::update_vector_iq_id(
00249   const std::string&                iq_name
00250   ,const VectorSpace::space_ptr_t&  vec_space
00251   ,EVecSpaceType                    vec_space_type
00252   ,iq_id_encap*                     iq_id
00253   )
00254 {
00255   namespace rcp = MemMngPack;
00256   if(iq_id->iq_id == DOES_NOT_EXIST) {
00257     iq_id_type
00258       _iq_id = this->get_iter_quant_id(iq_name);
00259     if(_iq_id == DOES_NOT_EXIST) {
00260       iq_id->iq_id = this->set_iter_quant(
00261         iq_name
00262         ,Teuchos::rcp(
00263           new IterQuantityAccessContiguous<VectorMutable>(
00264             1
00265             ,iq_name
00266             ,vec_space
00267             )
00268           )
00269         );
00270     }
00271     else {
00272       iq_id->iq_id = _iq_id;
00273     }
00274     // Record the list of vectors for a given vector space. 
00275     vector_iqs_lists_[vec_space_type].push_back(iq_id->iq_id);
00276   }
00277 }
00278 
00279 // private
00280 
00281 void NLPAlgoState::update_vector_factories(
00282   EVecSpaceType             vec_space_type
00283   ,const vec_space_ptr_t&   vec_space
00284   )
00285 {
00286   using Teuchos::dyn_cast;
00287   iq_vector_list_t  &iq_vector_list = vector_iqs_lists_[vec_space_type];
00288   for( iq_vector_list_t::const_iterator iq_itr = iq_vector_list.begin(); iq_itr != iq_vector_list.end(); ++iq_itr )
00289     dyn_cast<IterQuantityAccessContiguous<VectorMutable> >(this->iter_quant(*iq_itr)).set_factory(vec_space);
00290 }
00291 
00292 } // end namespace MoochoPack

Generated on Wed May 12 21:51:20 2010 for MoochoPack : Framework for Large-Scale Optimization Algorithms by  doxygen 1.4.7