|
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 00044 #include "MoochoPack_TangentialStepWithoutBounds_Step.hpp" 00045 #include "MoochoPack_EvalNewPointTailoredApproach_Step.hpp" 00046 #include "MoochoPack_Exceptions.hpp" 00047 #include "MoochoPack_moocho_algo_conversion.hpp" 00048 #include "IterationPack_print_algorithm_step.hpp" 00049 #include "NLPInterfacePack_NLPDirect.hpp" 00050 #include "AbstractLinAlgPack_MatrixSymOpNonsing.hpp" 00051 #include "AbstractLinAlgPack_MatrixOpOut.hpp" 00052 #include "AbstractLinAlgPack_VectorMutable.hpp" 00053 #include "AbstractLinAlgPack_VectorStdOps.hpp" 00054 #include "AbstractLinAlgPack_VectorOut.hpp" 00055 #include "AbstractLinAlgPack_assert_print_nan_inf.hpp" 00056 #include "AbstractLinAlgPack_LinAlgOpPack.hpp" 00057 #include "Teuchos_dyn_cast.hpp" 00058 #include "Teuchos_Assert.hpp" 00059 00060 00061 namespace LinAlgOpPack { 00062 using AbstractLinAlgPack::Vp_StMtV; 00063 } 00064 00065 00066 namespace MoochoPack { 00067 00068 00069 TangentialStepWithoutBounds_Step::TangentialStepWithoutBounds_Step() 00070 :max_pz_norm_(-1.0), 00071 num_pz_damp_iters_(0) 00072 {} 00073 00074 00075 bool TangentialStepWithoutBounds_Step::do_step( 00076 Algorithm& _algo, poss_type step_poss, IterationPack::EDoStepType type 00077 ,poss_type assoc_step_poss 00078 ) 00079 { 00080 00081 using std::endl; 00082 using BLAS_Cpp::no_trans; 00083 using Teuchos::dyn_cast; 00084 using AbstractLinAlgPack::assert_print_nan_inf; 00085 using AbstractLinAlgPack::Vt_S; 00086 using AbstractLinAlgPack::Vp_StV; 00087 using AbstractLinAlgPack::V_InvMtV; 00088 using LinAlgOpPack::V_StV; 00089 using LinAlgOpPack::V_MtV; 00090 00091 NLPAlgo &algo = rsqp_algo(_algo); 00092 NLPAlgoState &s = algo.rsqp_state(); 00093 00094 EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level(); 00095 EJournalOutputLevel ns_olevel = algo.algo_cntr().null_space_journal_output_level(); 00096 std::ostream& out = algo.track().journal_out(); 00097 00098 // print step header. 00099 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00100 using IterationPack::print_algorithm_step; 00101 print_algorithm_step( algo, step_poss, type, assoc_step_poss, out ); 00102 } 00103 00104 if( algo.nlp().num_bounded_x() ) 00105 TEUCHOS_TEST_FOR_EXCEPTION( 00106 true, std::logic_error 00107 ,"TangentialStepWithoutBounds_Step::do_step(...): Error, " 00108 "can't solve for pz for NLP with undecomposed constraints or " 00109 "has bounds on the variables"); 00110 00111 // Comupte qp_grad which is an approximation to rGf + Z' * HL * Y * py 00112 00113 // qp_grad_k = rGf_k 00114 VectorMutable &qp_grad_k = s.qp_grad().set_k(0) = s.rGf().get_k(0); 00115 00116 IterQuantityAccess<value_type> &zeta_iq = s.zeta(); 00117 IterQuantityAccess<VectorMutable> &w_iq = s.w(); 00118 if( w_iq.updated_k(0) && zeta_iq.updated_k(0) ) { 00119 // qp_grad += zeta * w 00120 Vp_StV( &qp_grad_k, zeta_iq.get_k(0), w_iq.get_k(0) ); 00121 } 00122 00123 // Solve the system pz = - inv(rHL) * qp_grad 00124 VectorMutable &pz_k = s.pz().set_k(0); 00125 const MatrixSymOpNonsing &rHL_k = dyn_cast<MatrixSymOpNonsing>(s.rHL().get_k(0)); 00126 V_InvMtV( &pz_k, rHL_k, no_trans, qp_grad_k ); 00127 Vt_S( &pz_k, -1.0 ); 00128 00129 // nu = 0.0 00130 s.nu().set_k(0) = 0.0; 00131 00132 value_type pz_norm_inf = -1.0; 00133 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00134 pz_norm_inf = pz_k.norm_inf(); 00135 out << "\n||pz_k||inf = " << pz_norm_inf << endl; 00136 } 00137 if( static_cast<int>(ns_olevel) >= static_cast<int>(PRINT_VECTORS) ) 00138 out << "\npz_k = \n" << pz_k << std::endl; 00139 00140 // Check to see if we need to dampen pz 00141 const bool dampen_pz = max_pz_norm() >= 0.0 && s.k() <= num_pz_damp_iters(); 00142 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00143 out 00144 << "\nChecking if we need to dampen pz:" 00145 << " ( (max_pz_norm="<<max_pz_norm()<<") >= 0.0 )" 00146 << " && ( (k="<<s.k()<<") <= (num_pz_damp_iters="<<num_pz_damp_iters()<<") ) : " 00147 << ( dampen_pz ? "true, dampen pz ..." : "false, no dampen pz!" ) 00148 << endl; 00149 } 00150 00151 if ( dampen_pz ) { 00152 // pz_new = ( max_pz_norm / pz_norm_inf ) * pz 00153 if (pz_norm_inf < 0.0 ) 00154 pz_norm_inf = pz_k.norm_inf(); 00155 const value_type pz_damp_factor = ( max_pz_norm() / pz_norm_inf ); 00156 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00157 out 00158 << "\npz_damp_factor = max_pz_norm / ||pz||inf = " 00159 << max_pz_norm() << " / " << pz_norm_inf << " = " 00160 << pz_damp_factor; 00161 } 00162 Vt_S( &pz_k, pz_damp_factor ); 00163 } 00164 00165 // Zpz = Z * pz 00166 V_MtV( &s.Zpz().set_k(0), s.Z().get_k(0), no_trans, pz_k ); 00167 00168 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) { 00169 out << "\n||pz_k||inf = " << s.pz().get_k(0).norm_inf() 00170 << "\n||Zpz_k||2 = " << s.Zpz().get_k(0).norm_2() << std::endl; 00171 } 00172 00173 if( static_cast<int>(ns_olevel) >= static_cast<int>(PRINT_VECTORS) ) { 00174 out << "\npz_k = \n" << s.pz().get_k(0); 00175 out << std::endl; 00176 } 00177 00178 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) ) { 00179 out << "\nnu_k = \n" << s.nu().get_k(0); 00180 out << "\nZpz_k = \n" << s.Zpz().get_k(0); 00181 out << std::endl; 00182 } 00183 00184 if(algo.algo_cntr().check_results()) { 00185 assert_print_nan_inf(s.pz().get_k(0), "pz_k",true,&out); 00186 assert_print_nan_inf(s.Zpz().get_k(0), "Zpz_k",true,&out); 00187 } 00188 00189 return true; 00190 } 00191 00192 00193 void TangentialStepWithoutBounds_Step::print_step( const Algorithm& algo 00194 , poss_type step_poss, IterationPack::EDoStepType type, poss_type assoc_step_poss 00195 , std::ostream& out, const std::string& L ) const 00196 { 00197 out 00198 << L << "*** Calculate the null space step by solving an unconstrainted QP\n" 00199 << L << "qp_grad_k = rGf_k + zeta_k * w_k\n" 00200 << L << "solve:\n" 00201 << L << " min qp_grad_k' * pz_k + 1/2 * pz_k' * rHL_k * pz_k\n" 00202 << L << " pz_k <: R^(n-r)\n" 00203 << L << "Zpz_k = Z_k * pz_k\n" 00204 << L << "nu_k = 0\n"; 00205 } 00206 00207 00208 } // end namespace MoochoPack
1.7.6.1