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