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