MoochoPack_CalcReducedGradLagrangianStd_AddedStep.cpp

Go to the documentation of this file.
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 <ostream>
00030 #include "MoochoPack_CalcReducedGradLagrangianStd_AddedStep.hpp"
00031 #include "MoochoPack_NLPAlgoContainer.hpp"
00032 #include "MoochoPack_moocho_algo_conversion.hpp"
00033 #include "IterationPack_print_algorithm_step.hpp"
00034 #include "AbstractLinAlgPack_MatrixOp.hpp"
00035 #include "AbstractLinAlgPack_VectorSpace.hpp"
00036 #include "AbstractLinAlgPack_VectorMutable.hpp"
00037 #include "AbstractLinAlgPack_VectorOut.hpp"
00038 #include "AbstractLinAlgPack_VectorStdOps.hpp"
00039 #include "AbstractLinAlgPack_LinAlgOpPack.hpp"
00040 
00041 namespace LinAlgOpPack {
00042   using AbstractLinAlgPack::Vp_StV;
00043   using AbstractLinAlgPack::Vp_StMtV;
00044 }
00045 
00046 namespace MoochoPack {
00047 
00048 bool CalcReducedGradLagrangianStd_AddedStep::do_step(
00049   Algorithm& _algo, poss_type step_poss, IterationPack::EDoStepType type
00050   ,poss_type assoc_step_poss
00051   )
00052 {
00053   using BLAS_Cpp::trans;
00054   using LinAlgOpPack::V_VpV;
00055   using LinAlgOpPack::V_MtV;
00056   using LinAlgOpPack::Vp_V;
00057   using LinAlgOpPack::Vp_MtV;
00058 
00059   NLPAlgo         &algo  = rsqp_algo(_algo);
00060   NLPAlgoState    &s     = algo.rsqp_state();
00061 
00062   EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
00063   EJournalOutputLevel ns_olevel = algo.algo_cntr().null_space_journal_output_level();
00064   std::ostream& out = algo.track().journal_out();
00065 
00066   // print step header.
00067   if( static_cast<int>(ns_olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
00068     using IterationPack::print_algorithm_step;
00069     print_algorithm_step( algo, step_poss, type, assoc_step_poss, out );
00070   }
00071 
00072   // Calculate: rGL = rGf + Z' * nu + Uz' * lambda(equ_undecomp)
00073 
00074   IterQuantityAccess<VectorMutable>
00075     &rGL_iq  = s.rGL(),
00076     &nu_iq   = s.nu(),
00077     &Gf_iq   = s.Gf();
00078 
00079   VectorMutable &rGL_k = rGL_iq.set_k(0);
00080 
00081   if( nu_iq.updated_k(0) && nu_iq.get_k(0).nz() > 0 ) {
00082     // Compute rGL = Z'*(Gf + nu) to reduce the effect of roundoff in this
00083     // catastropic cancelation
00084     const Vector &nu_k = nu_iq.get_k(0);
00085     VectorSpace::vec_mut_ptr_t
00086       tmp = nu_k.space().create_member();
00087 
00088     if( (int)olevel >= (int)PRINT_VECTORS )
00089       out << "\nnu_k = \n" << nu_k;
00090     V_VpV( tmp.get(), Gf_iq.get_k(0), nu_k );
00091     if( (int)olevel >= (int)PRINT_VECTORS )
00092       out << "\nGf_k+nu_k = \n" << *tmp;
00093     V_MtV(  &rGL_k, s.Z().get_k(0), trans, *tmp );
00094     if( (int)ns_olevel >= (int)PRINT_VECTORS )
00095       out << "\nrGL_k = \n" << rGL_k;
00096   }
00097   else {
00098     rGL_k = s.rGf().get_k(0);
00099   }
00100 
00101   // ToDo: Add terms for undecomposed equalities and inequalities!
00102   // + Uz' * lambda(equ_undecomp)
00103 
00104   if( static_cast<int>(ns_olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
00105     out << "\n||rGL_k||inf = " << rGL_k.norm_inf() << "\n";
00106   }
00107 
00108   if( static_cast<int>(ns_olevel) >= static_cast<int>(PRINT_VECTORS) ) {
00109     out << "\nrGL_k = \n" << rGL_k;
00110   }
00111 
00112   return true;
00113 }
00114 
00115 void CalcReducedGradLagrangianStd_AddedStep::print_step(
00116   const Algorithm& algo
00117   ,poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss
00118   ,std::ostream& out, const std::string& L
00119   ) const
00120 {
00121   out
00122     << L << "*** Evaluate the reduced gradient of the Lagrangian\n"
00123     << L << "if nu_k is updated and nu_k.nz() > 0 then\n"
00124     << L << "    rGL_k = Z_k' * (Gf_k + nu_k) + Uz_k' * lambda_k(equ_undecomp)\n"
00125     << L << "else\n"
00126     << L << "    rGL_k = rGf_k + Uz_k' * lambda_k(equ_undecomp)\n"
00127     << L << "end\n";
00128 }
00129 
00130 } // end namespace MoochoPack

Generated on Tue Jul 13 09:30:52 2010 for MOOCHO (Single Doxygen Collection) by  doxygen 1.4.7