MoochoPack : Framework for Large-Scale Optimization Algorithms Version of the Day
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 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00038 // 
00039 // ***********************************************************************
00040 // @HEADER
00041 
00042 #include <sstream>
00043 #include <typeinfo>
00044 
00045 #include "MoochoPack_NLPAlgoState.hpp"
00046 #include "ConstrainedOptPack_MeritFuncNLP.hpp"
00047 #include "AbstractLinAlgPack_MatrixSymOp.hpp"
00048 #include "AbstractLinAlgPack_MatrixOpNonsing.hpp"
00049 #include "Teuchos_dyn_cast.hpp"
00050 
00051 #include "IterationPack_IterQuantityAccess.hpp"
00052 #include "IterationPack_cast_iq.hpp"
00053 #include "IterationPack_IterQuantityAccessContiguous.hpp"
00054 
00055 // NLPAlgoState iteration quantities names
00056 
00057 // Iteration Info
00058 const std::string MoochoPack::num_basis_name    = "num_basis";
00059 // NLP Problem Info 
00060 const std::string MoochoPack::x_name        = "x";
00061 const std::string MoochoPack::f_name        = "f";
00062 const std::string MoochoPack::Gf_name       = "Gf";
00063 const std::string MoochoPack::HL_name       = "HL";
00064 const std::string MoochoPack::c_name        = "c";
00065 const std::string MoochoPack::Gc_name       = "Gc";
00066 // Constraint Gradient Null Space / Range Space Decomposition Info
00067 const std::string MoochoPack::Y_name        = "Y";
00068 const std::string MoochoPack::Z_name        = "Z";
00069 const std::string MoochoPack::R_name        = "R";
00070 const std::string MoochoPack::Uy_name       = "Uy";
00071 const std::string MoochoPack::Uz_name       = "Uz";
00072 // Search Direction Info
00073 const std::string MoochoPack::py_name       = "py";
00074 const std::string MoochoPack::Ypy_name        = "Ypy";
00075 const std::string MoochoPack::pz_name       = "pz";
00076 const std::string MoochoPack::Zpz_name        = "Zpz";
00077 const std::string MoochoPack::d_name        = "d";
00078 // Reduced QP Subproblem Info
00079 const std::string MoochoPack::rGf_name        = "rGf";
00080 const std::string MoochoPack::rHL_name        = "rHL";
00081 const std::string MoochoPack::w_name        = "w";
00082 const std::string MoochoPack::zeta_name     = "zeta";
00083 const std::string MoochoPack::qp_grad_name      = "qp_grad";
00084 const std::string MoochoPack::eta_name        = "eta";
00085 // Global Convergence Info
00086 const std::string MoochoPack::alpha_name      = "alpha";
00087 const std::string MoochoPack::merit_func_nlp_name = "merit_func_nlp";
00088 const std::string MoochoPack::mu_name       = "mu";
00089 const std::string MoochoPack::phi_name        = "phi";
00090 // KKT Info
00091 const std::string MoochoPack::opt_kkt_err_name    = "opt_kkt_err";
00092 const std::string MoochoPack::feas_kkt_err_name = "feas_kkt_err";
00093 const std::string MoochoPack::comp_kkt_err_name = "comp_kkt_err";
00094 const std::string MoochoPack::GL_name       = "GL";
00095 const std::string MoochoPack::rGL_name        = "rGL";
00096 const std::string MoochoPack::lambda_name     = "lambda";
00097 const std::string MoochoPack::nu_name       = "nu";
00098 
00099 namespace MoochoPack {
00100 
00101 // Constructors / initializers
00102 
00103 void NLPAlgoState::set_space_range (const vec_space_ptr_t& space_range )
00104 {
00105   space_range_ = space_range;
00106   update_vector_factories(VST_SPACE_RANGE,space_range);
00107 }
00108 
00109 void NLPAlgoState::set_space_null (const vec_space_ptr_t& space_null )
00110 {
00111   space_null_ = space_null;
00112   update_vector_factories(VST_SPACE_NULL,space_null);
00113 }
00114 
00115 NLPAlgoState::NLPAlgoState(
00116   const decomp_sys_ptr_t& decomp_sys
00117   ,const vec_space_ptr_t& space_x
00118   ,const vec_space_ptr_t& space_c
00119   ,const vec_space_ptr_t& space_range
00120   ,const vec_space_ptr_t& space_null
00121   )
00122   :decomp_sys_(decomp_sys)
00123   ,space_x_(space_x)
00124   ,space_c_(space_c)
00125   ,space_range_(space_range)
00126   ,space_null_(space_null)
00127 {}
00128 
00129 // Iteration Info
00130 
00131 STATE_INDEX_IQ_DEF(  NLPAlgoState,              num_basis, num_basis_name          )
00132 
00133 // NLP Problem Info
00134 
00135 STATE_VECTOR_IQ_DEF( NLPAlgoState,              x,         x_name,  get_space_x(), VST_SPACE_X  )
00136 STATE_SCALAR_IQ_DEF( NLPAlgoState,              f,         f_name                               )
00137 STATE_IQ_DEF(        NLPAlgoState, MatrixSymOp, HL,        HL_name                              )
00138 STATE_VECTOR_IQ_DEF( NLPAlgoState,              Gf,        Gf_name, get_space_x(), VST_SPACE_X  )
00139 STATE_VECTOR_IQ_DEF( NLPAlgoState,              c,         c_name,  get_space_c(), VST_SPACE_C  )
00140 STATE_IQ_DEF(        NLPAlgoState, MatrixOp,    Gc,        Gc_name                              )
00141 
00142 // Constraint Gradient Null Space / Range Space Decomposition Info
00143 
00144 STATE_IQ_DEF(        NLPAlgoState, MatrixOp,        Y,  Y_name                  )
00145 STATE_IQ_DEF(        NLPAlgoState, MatrixOp,        Z,  Z_name                  )
00146 STATE_IQ_DEF(        NLPAlgoState, MatrixOpNonsing, R,  R_name                  )
00147 STATE_IQ_DEF(        NLPAlgoState, MatrixOp,        Uy, Uy_name                 )
00148 STATE_IQ_DEF(        NLPAlgoState, MatrixOp,        Uz, Uz_name                 )
00149 
00150 // Search Direction Info
00151 
00152 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  py,  py_name,   get_space_range(), VST_SPACE_RANGE )
00153 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  Ypy, Ypy_name,  get_space_x(),     VST_SPACE_X     )
00154 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  pz,  pz_name,   get_space_null(),  VST_SPACE_NULL  )
00155 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  Zpz, Zpz_name,  get_space_x(),     VST_SPACE_X     )
00156 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  d,   d_name,    get_space_x(),     VST_SPACE_X     )
00157 
00158 // QP Subproblem Info
00159 
00160 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  rGf,     rGf_name,      get_space_null(), VST_SPACE_NULL )
00161 STATE_IQ_DEF(        NLPAlgoState, MatrixSymOp,     rHL,     rHL_name                                        )
00162 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  w,       w_name,        get_space_null(), VST_SPACE_NULL ) 
00163 STATE_SCALAR_IQ_DEF( NLPAlgoState,                  zeta,    zeta_name                                       )
00164 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  qp_grad, qp_grad_name,  get_space_null(), VST_SPACE_NULL )
00165 STATE_SCALAR_IQ_DEF( NLPAlgoState,                  eta,     eta_name                                        )
00166 
00167 // Global Convergence Info
00168 
00169 STATE_SCALAR_IQ_DEF( NLPAlgoState,                  alpha,          alpha_name          )
00170 STATE_IQ_DEF(        NLPAlgoState, MeritFuncNLP,    merit_func_nlp, merit_func_nlp_name )
00171 STATE_SCALAR_IQ_DEF( NLPAlgoState,                  mu,             mu_name             )
00172 STATE_SCALAR_IQ_DEF( NLPAlgoState,                  phi,            phi_name            )
00173 
00174 // KKT Info
00175 
00176 STATE_SCALAR_IQ_DEF( NLPAlgoState,                  opt_kkt_err,    opt_kkt_err_name                                    )
00177 STATE_SCALAR_IQ_DEF( NLPAlgoState,                  feas_kkt_err,   feas_kkt_err_name                                   )
00178 STATE_SCALAR_IQ_DEF( NLPAlgoState,                  comp_kkt_err,   comp_kkt_err_name                                   )
00179 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  GL,             GL_name,           get_space_x(),    VST_SPACE_X    )
00180 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  rGL,            rGL_name,          get_space_null(), VST_SPACE_NULL )
00181 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  lambda,         lambda_name,       get_space_c(),    VST_SPACE_C    )
00182 STATE_VECTOR_IQ_DEF( NLPAlgoState,                  nu,             nu_name,           get_space_x(),    VST_SPACE_X    )
00183 
00184 // protected
00185 
00186 void NLPAlgoState::update_iq_id(
00187   const std::string&                iq_name
00188   ,iq_id_encap*                     iq_id
00189   ) const
00190 {
00191   namespace rcp = MemMngPack;
00192   if(iq_id->iq_id == DOES_NOT_EXIST)
00193     iq_id->iq_id = this->get_iter_quant_id(iq_name);
00194   TEUCHOS_TEST_FOR_EXCEPTION(
00195     iq_id->iq_id == DOES_NOT_EXIST, DoesNotExist
00196     ,"NLPAlgoState::update_iq_id(iq_name,iq_id) : Error, "
00197     " The iteration quantity with name \'" << iq_name <<
00198     "\' does not exist!" );
00199 }
00200 
00201 void NLPAlgoState::update_index_type_iq_id(
00202   const std::string&                iq_name
00203   ,iq_id_encap*                     iq_id
00204   )
00205 {
00206   namespace rcp = MemMngPack;
00207   if(iq_id->iq_id == DOES_NOT_EXIST) {
00208     iq_id_type
00209       _iq_id = this->get_iter_quant_id(iq_name);
00210     if(_iq_id == DOES_NOT_EXIST) {
00211       iq_id->iq_id = this->set_iter_quant(
00212         iq_name
00213         ,Teuchos::rcp(
00214           new IterQuantityAccessContiguous<index_type>(
00215             1
00216             ,iq_name
00217 #ifdef _MIPS_CXX
00218             ,Teuchos::RCP<Teuchos::AbstractFactoryStd<index_type,index_type> >(
00219               new Teuchos::AbstractFactoryStd<index_type,index_type>())
00220 #endif
00221             )
00222           )
00223         );
00224     }
00225     else {
00226       iq_id->iq_id = _iq_id;
00227     }
00228   }
00229 }
00230 
00231 void NLPAlgoState::update_value_type_iq_id(
00232   const std::string&                iq_name
00233   ,iq_id_encap*                     iq_id
00234   )
00235 {
00236   namespace rcp = MemMngPack;
00237   if(iq_id->iq_id == DOES_NOT_EXIST) {
00238     iq_id_type
00239       _iq_id = this->get_iter_quant_id(iq_name);
00240     if(_iq_id == DOES_NOT_EXIST) {
00241       iq_id->iq_id = this->set_iter_quant(
00242         iq_name
00243         ,Teuchos::rcp(
00244           new IterQuantityAccessContiguous<value_type>(
00245             1
00246             ,iq_name
00247 #ifdef _MIPS_CXX
00248             ,Teuchos::RCP<Teuchos::AbstractFactoryStd<value_type,value_type> >(
00249               new Teuchos::AbstractFactoryStd<value_type,value_type>())
00250 #endif
00251             )
00252           )
00253         );
00254     }
00255     else {
00256       iq_id->iq_id = _iq_id;
00257     }
00258   }
00259 }
00260 
00261 void NLPAlgoState::update_vector_iq_id(
00262   const std::string&                iq_name
00263   ,const VectorSpace::space_ptr_t&  vec_space
00264   ,EVecSpaceType                    vec_space_type
00265   ,iq_id_encap*                     iq_id
00266   )
00267 {
00268   namespace rcp = MemMngPack;
00269   if(iq_id->iq_id == DOES_NOT_EXIST) {
00270     iq_id_type
00271       _iq_id = this->get_iter_quant_id(iq_name);
00272     if(_iq_id == DOES_NOT_EXIST) {
00273       iq_id->iq_id = this->set_iter_quant(
00274         iq_name
00275         ,Teuchos::rcp(
00276           new IterQuantityAccessContiguous<VectorMutable>(
00277             1
00278             ,iq_name
00279             ,vec_space
00280             )
00281           )
00282         );
00283     }
00284     else {
00285       iq_id->iq_id = _iq_id;
00286     }
00287     // Record the list of vectors for a given vector space. 
00288     vector_iqs_lists_[vec_space_type].push_back(iq_id->iq_id);
00289   }
00290 }
00291 
00292 // private
00293 
00294 void NLPAlgoState::update_vector_factories(
00295   EVecSpaceType             vec_space_type
00296   ,const vec_space_ptr_t&   vec_space
00297   )
00298 {
00299   using Teuchos::dyn_cast;
00300   iq_vector_list_t  &iq_vector_list = vector_iqs_lists_[vec_space_type];
00301   for( iq_vector_list_t::const_iterator iq_itr = iq_vector_list.begin(); iq_itr != iq_vector_list.end(); ++iq_itr )
00302     dyn_cast<IterQuantityAccessContiguous<VectorMutable> >(this->iter_quant(*iq_itr)).set_factory(vec_space);
00303 }
00304 
00305 } // end namespace MoochoPack
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends