|
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 #include <iostream> 00045 00046 #include "AbstractLinAlgPack_MatrixSymDiagStd.hpp" 00047 #include "AbstractLinAlgPack_VectorStdOps.hpp" 00048 #include "AbstractLinAlgPack_VectorOut.hpp" 00049 #include "AbstractLinAlgPack_VectorAuxiliaryOps.hpp" 00050 #include "AbstractLinAlgPack_assert_print_nan_inf.hpp" 00051 #include "NLPInterfacePack_NLPFirstOrder.hpp" 00052 #include "IterationPack_print_algorithm_step.hpp" 00053 #include "MoochoPack_IpState.hpp" 00054 #include "MoochoPack_PreEvalNewPointBarrier_Step.hpp" 00055 #include "MoochoPack_moocho_algo_conversion.hpp" 00056 00057 #include "OptionsFromStreamPack_StringToBool.hpp" 00058 00059 #include "Teuchos_dyn_cast.hpp" 00060 00061 namespace MoochoPack { 00062 00063 PreEvalNewPointBarrier_Step::PreEvalNewPointBarrier_Step( 00064 const value_type relative_bound_push, 00065 const value_type absolute_bound_push 00066 ) 00067 : 00068 relative_bound_push_(relative_bound_push), 00069 absolute_bound_push_(absolute_bound_push) 00070 {} 00071 00072 bool PreEvalNewPointBarrier_Step::do_step( 00073 Algorithm& _algo, poss_type step_poss, IterationPack::EDoStepType type 00074 ,poss_type assoc_step_poss 00075 ) 00076 { 00077 using Teuchos::dyn_cast; 00078 using IterationPack::print_algorithm_step; 00079 using AbstractLinAlgPack::force_in_bounds_buffer; 00080 00081 NLPAlgo &algo = dyn_cast<NLPAlgo>(_algo); 00082 IpState &s = dyn_cast<IpState>(_algo.state()); 00083 NLP &nlp = algo.nlp(); 00084 NLPFirstOrder *nlp_foi = dynamic_cast<NLPFirstOrder*>(&nlp); 00085 00086 EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level(); 00087 std::ostream& out = algo.track().journal_out(); 00088 00089 if(!nlp.is_initialized()) 00090 nlp.initialize(algo.algo_cntr().check_results()); 00091 00092 // print step header. 00093 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) 00094 { 00095 using IterationPack::print_algorithm_step; 00096 print_algorithm_step( _algo, step_poss, type, assoc_step_poss, out ); 00097 } 00098 00099 IterQuantityAccess<value_type> &barrier_parameter_iq = s.barrier_parameter(); 00100 IterQuantityAccess<VectorMutable> &x_iq = s.x(); 00101 00102 if( x_iq.last_updated() == IterQuantity::NONE_UPDATED ) 00103 { 00104 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) 00105 { 00106 out << "\nInitialize x with x_k = nlp.xinit() ...\n" 00107 << " and push x_k within bounds.\n"; 00108 } 00109 VectorMutable& x_k = x_iq.set_k(0) = nlp.xinit(); 00110 00111 // apply transformation operator to push x sufficiently within bounds 00112 force_in_bounds_buffer(relative_bound_push_, 00113 absolute_bound_push_, 00114 nlp.xl(), 00115 nlp.xu(), 00116 &x_k); 00117 00118 // evaluate the func and constraints 00119 IterQuantityAccess<value_type> 00120 &f_iq = s.f(); 00121 IterQuantityAccess<VectorMutable> 00122 &Gf_iq = s.Gf(), 00123 *c_iq = nlp.m() > 0 ? &s.c() : NULL; 00124 IterQuantityAccess<MatrixOp> 00125 *Gc_iq = nlp_foi ? &s.Gc() : NULL; 00126 00127 using AbstractLinAlgPack::assert_print_nan_inf; 00128 assert_print_nan_inf(x_k, "x", true, NULL); // With throw exception if Inf or NaN! 00129 00130 // Wipe out storage for computed iteration quantities (just in case?) : RAB: 7/29/2002 00131 if(f_iq.updated_k(0)) 00132 f_iq.set_not_updated_k(0); 00133 if(Gf_iq.updated_k(0)) 00134 Gf_iq.set_not_updated_k(0); 00135 if (c_iq) 00136 { 00137 if(c_iq->updated_k(0)) 00138 c_iq->set_not_updated_k(0); 00139 } 00140 if (nlp_foi) 00141 { 00142 if(Gc_iq->updated_k(0)) 00143 Gc_iq->set_not_updated_k(0); 00144 } 00145 } 00146 00147 if (barrier_parameter_iq.last_updated() == IterQuantity::NONE_UPDATED) 00148 { 00149 barrier_parameter_iq.set_k(-1) = 0.1; // RAB: 7/29/2002: This should be parameterized! (allow user to set this!) 00150 } 00151 00152 // Print vector information 00153 if( static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) ) 00154 { 00155 out << "x_k =\n" << x_iq.get_k(0); 00156 } 00157 00158 return true; 00159 } 00160 00161 00162 void PreEvalNewPointBarrier_Step::print_step( 00163 const Algorithm& _algo, poss_type step_poss, IterationPack::EDoStepType type 00164 ,poss_type assoc_step_poss, std::ostream& out, const std::string& L 00165 ) const 00166 { 00167 //const NLPAlgo &algo = rsqp_algo(_algo); 00168 //const NLPAlgoState &s = algo.rsqp_state(); 00169 out << L << "# Evaluate information specific to primal / dual barrier algorithms\n" 00170 << L << "if (x never updated) then\n" 00171 << L << " x_k = nlp.xinit()\n" 00172 << L << " force_in_bounds(x_k)\n" 00173 << L << " set f_k not updated\n" 00174 << L << " set Gf_k not updated\n" 00175 << L << " if (m > 0) then\n" 00176 << L << " set c_k not updated\n" 00177 << L << " set Gc_k not updated\n" 00178 << L << "end\n"; 00179 } 00180 00181 00182 namespace { 00183 00184 const int local_num_options = 2; 00185 00186 enum local_EOptions 00187 { 00188 RELATIVE_BOUND_PUSH, 00189 ABSOLUTE_BOUND_PUSH 00190 }; 00191 00192 const char* local_SOptions[local_num_options] = 00193 { 00194 "relative_bound_push", 00195 "absolute_bound_push" 00196 }; 00197 00198 } 00199 00200 00201 PreEvalNewPointBarrier_StepSetOptions::PreEvalNewPointBarrier_StepSetOptions( 00202 PreEvalNewPointBarrier_Step* target 00203 , const char opt_grp_name[] ) 00204 : 00205 OptionsFromStreamPack::SetOptionsFromStreamNode( 00206 opt_grp_name, local_num_options, local_SOptions ), 00207 OptionsFromStreamPack::SetOptionsToTargetBase< PreEvalNewPointBarrier_Step >( target ) 00208 { 00209 } 00210 00211 void PreEvalNewPointBarrier_StepSetOptions::setOption( 00212 int option_num, const std::string& option_value ) 00213 { 00214 using OptionsFromStreamPack::StringToBool; 00215 00216 typedef PreEvalNewPointBarrier_Step target_t; 00217 switch( (local_EOptions)option_num ) 00218 { 00219 case RELATIVE_BOUND_PUSH: 00220 target().relative_bound_push(std::atof(option_value.c_str())); 00221 break; 00222 case ABSOLUTE_BOUND_PUSH: 00223 target().absolute_bound_push(std::atof(option_value.c_str())); 00224 break; 00225 default: 00226 TEUCHOS_TEST_FOR_EXCEPT(true); // Local error only? 00227 } 00228 } 00229 00230 } // end namespace MoochoPack
1.7.6.1