MOOCHO (Single Doxygen Collection) Version of the Day
MoochoPack_CheckDescentQuasiNormalStep_Step.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 // 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 <ostream>
00043 
00044 #include "MoochoPack_CheckDescentQuasiNormalStep_Step.hpp"
00045 #include "MoochoPack_Exceptions.hpp"
00046 #include "MoochoPack_moocho_algo_conversion.hpp"
00047 #include "IterationPack_print_algorithm_step.hpp"
00048 #include "AbstractLinAlgPack_VectorSpace.hpp"
00049 #include "AbstractLinAlgPack_VectorMutable.hpp"
00050 #include "AbstractLinAlgPack_VectorOut.hpp"
00051 #include "AbstractLinAlgPack_VectorStdOps.hpp"
00052 #include "AbstractLinAlgPack_MatrixOp.hpp"
00053 #include "AbstractLinAlgPack_LinAlgOpPack.hpp"
00054 #include "Teuchos_Assert.hpp"
00055 
00056 namespace MoochoPack {
00057 
00058 CheckDescentQuasiNormalStep_Step::CheckDescentQuasiNormalStep_Step(
00059   const calc_fd_prod_ptr_t&   calc_fd_prod
00060   )
00061   :calc_fd_prod_(calc_fd_prod)
00062 {}
00063 
00064 bool CheckDescentQuasiNormalStep_Step::do_step(
00065   Algorithm& _algo, poss_type step_poss, IterationPack::EDoStepType type
00066   ,poss_type assoc_step_poss
00067   )
00068 {
00069   using BLAS_Cpp::no_trans;
00070   using AbstractLinAlgPack::dot;
00071   using LinAlgOpPack::V_MtV;
00072 
00073   NLPAlgo         &algo        = rsqp_algo(_algo);
00074   NLPAlgoState    &s           = algo.rsqp_state();
00075   NLP             &nlp         = algo.nlp();
00076   const Range1D   equ_decomp   = s.equ_decomp();
00077 
00078   EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
00079   std::ostream& out = algo.track().journal_out();
00080 
00081   // print step header.
00082   if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
00083     using IterationPack::print_algorithm_step;
00084     print_algorithm_step( algo, step_poss, type, assoc_step_poss, out );
00085   }
00086   
00087   const size_type
00088     nb = nlp.num_bounded_x();
00089 
00090   // Get iteration quantities
00091   IterQuantityAccess<VectorMutable>
00092     &c_iq   = s.c(),
00093     &Ypy_iq = s.Ypy();
00094   const Vector::vec_ptr_t
00095     cd_k = c_iq.get_k(0).sub_view(equ_decomp);
00096   const Vector
00097     &Ypy_k = Ypy_iq.get_k(0);
00098   
00099   value_type descent_c = -1.0;
00100   if( s.get_iter_quant_id( Gc_name ) != AlgorithmState::DOES_NOT_EXIST ) {
00101     if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
00102       out << "\nGc_k exists; compute descent_c = c_k(equ_decomp)'*Gc_k(:,equ_decomp)'*Ypy_k ...\n";
00103     }
00104     const MatrixOp::mat_ptr_t
00105       Gcd_k = s.Gc().get_k(0).sub_view(Range1D(),equ_decomp);
00106     VectorSpace::vec_mut_ptr_t
00107       t = cd_k->space().create_member();
00108     V_MtV( t.get(), *Gcd_k, BLAS_Cpp::trans, Ypy_k );
00109     if( static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) ) {
00110       out << "\nGc_k(:,equ_decomp)'*Ypy_k =\n" << *t;
00111     }
00112     descent_c = dot( *cd_k, *t );
00113   }
00114   else {
00115     if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
00116       out << "\nGc_k does not exist; compute descent_c = c_k(equ_decomp)'*FDGc_k(:,equ_decomp)'*Ypy_k "
00117         << "using finite differences ...\n";
00118     }
00119     VectorSpace::vec_mut_ptr_t
00120       t = nlp.space_c()->create_member();
00121     calc_fd_prod().calc_deriv_product(
00122       s.x().get_k(0),nb?&nlp.xl():NULL,nb?&nlp.xu():NULL
00123       ,Ypy_k,NULL,&c_iq.get_k(0),true,&nlp
00124       ,NULL,t.get()
00125       ,static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ? &out : NULL
00126       );
00127     if( static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) ) {
00128       out << "\nFDGc_k(:,equ_decomp)'*Ypy_k =\n" << *t->sub_view(equ_decomp);
00129     }
00130     descent_c = dot( *cd_k, *t->sub_view(equ_decomp) );
00131   }
00132 
00133   if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
00134     out << "\ndescent_c = " << descent_c << std::endl;
00135   }
00136 
00137   if( descent_c > 0.0 ) { // ToDo: add some allowance for > 0.0 for finite difference errors!
00138     if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) {
00139       out << "\nError, descent_c > 0.0; this is not a descent direction\n"
00140         << "Throw TestFailed and terminate the algorithm ...\n";
00141     }
00142     TEUCHOS_TEST_FOR_EXCEPTION(
00143       true, TestFailed
00144       ,"CheckDescentQuasiNormalStep_Step::do_step(...) : Error, descent for the decomposed constraints "
00145       "with respect to the quasi-normal step c_k(equ_decomp)'*FDGc_k(:,equ_decomp)'*Ypy_k = "
00146       << descent_c << " > 0.0;  This is not a descent direction!\n" );
00147   }
00148 
00149   return true;
00150 }
00151 
00152 void CheckDescentQuasiNormalStep_Step::print_step(
00153   const Algorithm& algo, poss_type step_poss, IterationPack::EDoStepType type
00154   ,poss_type assoc_step_poss, std::ostream& out, const std::string& L
00155   ) const
00156 {
00157   out
00158     << L << "*** Check for descent in the decomposed equality constraints for the quasi-normal step\n"
00159     << L << "if Gc_k exists then\n"
00160     << L << "  descent_c = c_k(equ_decomp)'*Gc_k(:,equ_decomp)'*Ypy_k\n"
00161     << L << "else\n"
00162     << L << "  descent_c = c_k(equ_decomp)'*FDGc(:,equ_decomp)'*Ypy_k (finite diff.)\n"
00163     << L << "end\n"
00164     << L << "if descent > 0.0 then\n"
00165     << L << "  throw TestFailed exception!\n"
00166     << L << "end\n"
00167     ;
00168 }
00169 
00170 } // end namespace MoochoPack
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines