MoochoPack_DecompositionSystemHandlerStd_Strategy.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 <typeinfo>
00031 
00032 #include "MoochoPack_DecompositionSystemHandlerStd_Strategy.hpp"
00033 #include "MoochoPack_Exceptions.hpp"
00034 #include "MoochoPack_moocho_algo_conversion.hpp"
00035 #include "IterationPack_print_algorithm_step.hpp"
00036 #include "ConstrainedOptPack_DecompositionSystem.hpp"
00037 #include "NLPInterfacePack_NLPFirstOrder.hpp"
00038 #include "AbstractLinAlgPack_BasisSystem.hpp"
00039 #include "AbstractLinAlgPack_MatrixOpNonsing.hpp"
00040 #include "AbstractLinAlgPack_MatrixOpOut.hpp"
00041 #include "AbstractLinAlgPack_VectorMutable.hpp"
00042 #include "AbstractLinAlgPack_VectorStdOps.hpp"
00043 #include "AbstractLinAlgPack_VectorOut.hpp"
00044 #include "AbstractLinAlgPack_LinAlgOpPack.hpp"
00045 #include "AbstractLinAlgPack_MatrixSymIdent.hpp"
00046 #include "AbstractLinAlgPack_assert_print_nan_inf.hpp"
00047 #include "Teuchos_dyn_cast.hpp"
00048 #include "Teuchos_TestForException.hpp"
00049 
00050 namespace MoochoPack {
00051 
00052 // Constructors / initializers
00053 
00054 DecompositionSystemHandlerStd_Strategy::DecompositionSystemHandlerStd_Strategy()
00055 {}
00056 
00057 // Overridden from DecompositionSystemHandler_Strategy
00058 
00059 bool DecompositionSystemHandlerStd_Strategy::update_decomposition(
00060   NLPAlgo                                &algo
00061   ,NLPAlgoState                          &s
00062   ,NLPFirstOrder                         &nlp
00063   ,EDecompSysTesting                     decomp_sys_testing
00064   ,EDecompSysPrintLevel                  decomp_sys_testing_print_level
00065   ,bool                                  *new_decomp_selected
00066   )
00067 {
00068   using Teuchos::dyn_cast;
00069 
00070   EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
00071   std::ostream& out = algo.track().journal_out();
00072 
00073   const size_type
00074     n  = nlp.n(),
00075     m  = nlp.m(),
00076     r  = s.decomp_sys().equ_decomp().size();
00077 
00078   // Get the iteration quantity container objects
00079   IterQuantityAccess<MatrixOp>
00080     *Gc_iq  = ( m  > 0 )              ? &s.Gc() : NULL,
00081     *Z_iq   = ( n > m && r > 0 )      ? &s.Z()  : NULL,
00082     *Y_iq   = ( r > 0 )               ? &s.Y()  : NULL,
00083     *Uz_iq  = ( m  > 0 && m  > r )    ? &s.Uz() : NULL,
00084     *Uy_iq  = ( m  > 0 && m  > r )    ? &s.Uy() : NULL;
00085   IterQuantityAccess<MatrixOpNonsing>
00086     *R_iq   = ( m > 0 )               ? &s.R()  : NULL;
00087 
00088   if( n > m ) {
00089 
00090     //
00091     // Update range/null decomposition
00092     //
00093     
00094     // Determine if we will test the decomp_sys or not
00095     const DecompositionSystem::ERunTests
00096       ds_test_what = ( ( decomp_sys_testing == DST_TEST
00097                  || ( decomp_sys_testing == DST_DEFAULT
00098                   && algo.algo_cntr().check_results() ) )
00099                ? DecompositionSystem::RUN_TESTS
00100                : DecompositionSystem::NO_TESTS );
00101     
00102     // Determine the output level for decomp_sys        
00103     DecompositionSystem::EOutputLevel ds_olevel;
00104     switch(olevel) {
00105       case PRINT_NOTHING:
00106       case PRINT_BASIC_ALGORITHM_INFO:
00107         ds_olevel = DecompositionSystem::PRINT_NONE;
00108         break;
00109       case PRINT_ALGORITHM_STEPS:
00110       case PRINT_ACTIVE_SET:
00111         ds_olevel = DecompositionSystem::PRINT_BASIC_INFO;
00112         break;
00113       case PRINT_VECTORS:
00114         ds_olevel = DecompositionSystem::PRINT_VECTORS;
00115         break;
00116       case PRINT_ITERATION_QUANTITIES:
00117         ds_olevel = DecompositionSystem::PRINT_EVERY_THING;
00118         break;
00119       default:
00120         TEST_FOR_EXCEPT(true); // Should not get here!
00121     };
00122     
00123     // Form the decomposition of Gc and update the decomposition system matrices
00124     if( olevel >= PRINT_ALGORITHM_STEPS ) {
00125       out << "\nUpdating the range/null decompostion matrices ...\n";
00126     }
00127     s.decomp_sys().update_decomp(
00128       &out                               // out
00129       ,ds_olevel                         // olevel
00130       ,ds_test_what                      // test_what
00131       ,Gc_iq->get_k(0)                   // Gc
00132       ,&Z_iq->set_k(0)                   // Z
00133       ,&Y_iq->set_k(0)                   // Y
00134       ,&R_iq->set_k(0)                   // R
00135       ,Uz_iq ? &Uz_iq->set_k(0) : NULL   // Uz
00136       ,Uy_iq ? &Uy_iq->set_k(0) : NULL   // Uy
00137       ,DecompositionSystem::MATRICES_ALLOW_DEP_IMPS // ToDo: Change this!
00138       );
00139     s.equ_decomp(   s.decomp_sys().equ_decomp()   );
00140     s.equ_undecomp( s.decomp_sys().equ_undecomp() );
00141     
00142     *new_decomp_selected = false;
00143 
00144   }
00145   else {
00146     //
00147     // Update decomposition
00148     //
00149     // R = C
00150     // Y = I
00151     //
00152     const BasisSystem &basis_sys = *nlp.basis_sys();
00153     basis_sys.update_basis(
00154       Gc_iq->get_k(0)                        // Gc
00155       ,&R_iq->set_k(0 )                      // C
00156       ,NULL                                  // D
00157       ,NULL                                  // GcUP
00158       ,BasisSystem::MATRICES_ALLOW_DEP_IMPS  // Meaningless
00159       ,static_cast<int>(olevel) >= static_cast<int>(PRINT_BASIC_ALGORITHM_INFO) ? &out : NULL
00160       );
00161     dyn_cast<MatrixSymIdent>(Y_iq->set_k(0)).initialize( nlp.space_x() );
00162     s.equ_decomp(   basis_sys.equ_decomp()   );
00163     s.equ_undecomp( basis_sys.equ_undecomp() );
00164   }
00165   
00166   return true;
00167 }
00168 
00169 void DecompositionSystemHandlerStd_Strategy::print_update_decomposition(
00170   const NLPAlgo                          &algo
00171   ,const NLPAlgoState                    &s
00172   ,std::ostream                          &out
00173   ,const std::string                     &L
00174   ) const
00175 {
00176   using Teuchos::dyn_cast;
00177 
00178   const NLPFirstOrder &nlp = dyn_cast<const NLPFirstOrder>(algo.nlp());
00179   const size_type n  = nlp.n(), m = nlp.m(), r = nlp.basis_sys()->equ_decomp().size();
00180   out
00181     << L << "*** Updating the range/null decomposition.\n";
00182   if( n == m && m == r ) {
00183     out
00184       << L << "R = C\n"
00185       << L << "Y = I\n";
00186   }
00187   else {
00188     out
00189       << L << "begin update decomposition\n"
00190       << L << "(class = \'" << typeName(s.decomp_sys()) << "\')\n"
00191       ;
00192     s.decomp_sys().print_update_decomp( out, L + "  " );
00193     out
00194       << L << "end update decomposition\n"
00195       ;
00196   }
00197 }
00198 
00199 } // end namespace MoochoPack

Generated on Tue Oct 20 12:51:46 2009 for MOOCHO (Single Doxygen Collection) by doxygen 1.4.7