MoochoPack_CalcLambdaIndepStd_AddedStep.cpp

00001 #if 0
00002 
00003 // @HEADER
00004 // ***********************************************************************
00005 // 
00006 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00007 //                  Copyright (2003) Sandia Corporation
00008 // 
00009 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00010 // license for use of this work by or on behalf of the U.S. Government.
00011 // 
00012 // This library is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU Lesser General Public License as
00014 // published by the Free Software Foundation; either version 2.1 of the
00015 // License, or (at your option) any later version.
00016 //  
00017 // This library is distributed in the hope that it will be useful, but
00018 // WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 // Lesser General Public License for more details.
00021 //  
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License along with this library; if not, write to the Free Software
00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025 // USA
00026 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00027 // 
00028 // ***********************************************************************
00029 // @HEADER
00030 
00031 #include <ostream>
00032 
00033 #include "MoochoPack_CalcLambdaIndepStd_AddedStep.hpp"
00034 #include "MoochoPack_moocho_algo_conversion.hpp"
00035 #include "IterationPack_print_algorithm_step.hpp"
00036 #include "ConstrainedOptPack_ComputeMinMult.hpp"
00037 #include "ConstrainedOptPack/src/VectorWithNorms.h"
00038 #include "AbstractLinAlgPack_SpVectorOp.hpp"
00039 #include "AbstractLinAlgPack/src/AbstractLinAlgPack_MatrixOp.hpp"
00040 #include "DenseLinAlgPack_LinAlgOpPack.hpp"
00041 #include "DenseLinAlgPack_DVectorOp.hpp"
00042 #include "DenseLinAlgPack_DVectorOut.hpp"
00043 
00044 namespace LinAlgOpPack {
00045   using AbstractLinAlgPack::Vp_StV;
00046   using AbstractLinAlgPack::Vp_StMtV;
00047 }
00048 
00049 bool MoochoPack::CalcLambdaIndepStd_AddedStep::do_step(Algorithm& _algo
00050   , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss)
00051 {
00052 
00053   using BLAS_Cpp::no_trans;
00054   using BLAS_Cpp::trans;
00055 
00056   using DenseLinAlgPack::Vt_S;
00057   using DenseLinAlgPack::norm_inf;
00058 
00059   using AbstractLinAlgPack::Vp_StMtV;
00060   
00061   using ConstrainedOptPack::min_abs;
00062 
00063   using LinAlgOpPack::Vp_V;
00064   using LinAlgOpPack::V_StMtV;
00065   using LinAlgOpPack::Vp_MtV;
00066 
00067   NLPAlgo &algo = rsqp_algo(_algo);
00068   NLPAlgoState  &s    = algo.rsqp_state();
00069   Range1D   decomp  = s.equ_decomp();
00070   
00071   EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
00072   std::ostream& out = algo.track().journal_out();
00073 
00074   // print step header.
00075   if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
00076     using IterationPack::print_algorithm_step;
00077     print_algorithm_step( algo, step_poss, type, assoc_step_poss, out );
00078   }
00079 
00080   // Compute: lambda(decomp) = inv(Gc(decomp)'* Y)' * ( - Y' * (Gf + nu) - U' * lambda(undecomp) )
00081   // where U = Gc(undecomp)' * Y
00082 
00083   // Must resize lambda here explicitly since we will only be updating a region of it.
00084   // If lambda(undecomp) has already been updated then lambda will have been resized
00085   // already but lambda(decomp) will not be initialized yet.
00086   if( !s.lambda().updated_k(0) ) s.lambda().set_k(0).v().resize( algo.nlp().m() );
00087   
00088   DVectorSlice lambda_decomp = s.lambda().get_k(0).v()(decomp);
00089   
00090   // lambda_decomp_tmp1 = - Y' * (Gf + nu)
00091   if( algo.nlp().has_bounds() ) {
00092     // _tmp = Gf + nu
00093     DVector _tmp = s.Gf().get_k(0)();
00094     DVectorSlice _vs_tmp = _tmp;  // only create this DVectorSlice once
00095     Vp_V( &_vs_tmp, s.nu().get_k(0)() );
00096     // lambda_decomp_tmp1 = - Y' * _tmp
00097     V_StMtV( &lambda_decomp, -1.0, s.Y().get_k(0), trans, _vs_tmp );
00098   }
00099   else {
00100     // lambda_decomp__tmp1 = - Y' * Gf
00101     V_StMtV( &lambda_decomp, -1.0, s.Y().get_k(0), trans, s.Gf().get_k(0)() );
00102   }
00103 
00104   // lambda_decomp_tmp2 = lambda_decomp_tmp1 - U' * lambda(undecomp)
00105   if( algo.nlp().r() < algo.nlp().m() ) {
00106     Range1D undecomp = s.equ_undecomp();
00107     Vp_StMtV( &lambda_decomp, -1.0, s.U().get_k(0), trans, s.lambda().get_k(0).v()(undecomp) );
00108   }
00109   // else lambda(decomp)_tmp2 = lambda(decomp)_tmp1
00110 
00111   // lambda_decomp = inv(Gc(decomp)'* Y)' * lambda_decomp_tmp2
00112   s.decomp_sys().solve_transAtY( lambda_decomp, trans, &lambda_decomp );
00113 
00114   if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
00115     out << "\nmax(|lambda_k(equ_decomp)(i)|) = " << norm_inf(lambda_decomp)
00116       << "\nmin(|lambda_k(equ_decomp)(i)|) = " << min_abs(lambda_decomp)  << std::endl;
00117   }
00118 
00119   if( static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) ) {
00120     out << "\nlambda_k(equ_decomp) = \n" << lambda_decomp;
00121   }
00122 
00123   return true;
00124 }
00125 
00126 void MoochoPack::CalcLambdaIndepStd_AddedStep::print_step( const Algorithm& algo
00127   , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss
00128   , std::ostream& out, const std::string& L ) const
00129 {
00130   out
00131     << L << "*** Calculate the Lagrange multipliers for the decomposed constraints\n"
00132     << L << "lambda_k(equ_decomp) = - inv(Gc_k(:,equ_decomp)'*Y_k)\n"
00133     << L << "                        * (Y_k'*(Gf_k + nu_k) + U_k'*lambda_k(equ_undecomp))\n";
00134 }
00135 
00136 #endif // 0

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