MOOCHO (Single Doxygen Collection) Version of the Day
MoochoPack_PreProcessBarrierLineSearch_Step.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 // 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 #include <math.h>
00046 
00047 #include "AbstractLinAlgPack_assert_print_nan_inf.hpp"
00048 #include "AbstractLinAlgPack_VectorAuxiliaryOps.hpp"
00049 #include "AbstractLinAlgPack_MatrixSymDiagStd.hpp"
00050 #include "AbstractLinAlgPack_VectorOut.hpp"
00051 #include "AbstractLinAlgPack_LinAlgOpPack.hpp"
00052 #include "NLPInterfacePack_NLPBarrier.hpp"
00053 #include "MoochoPack_PreProcessBarrierLineSearch_Step.hpp"
00054 #include "MoochoPack_IpState.hpp"
00055 #include "MoochoPack_moocho_algo_conversion.hpp"
00056 #include "IterationPack_print_algorithm_step.hpp"
00057 #include "Teuchos_dyn_cast.hpp"
00058 #include "Teuchos_Assert.hpp"
00059 
00060 #define min(a,b) ( (a < b) ? a : b )
00061 #define max(a,b) ( (a > b) ? a : b )
00062 
00063 namespace MoochoPack {
00064 
00065 PreProcessBarrierLineSearch_Step::PreProcessBarrierLineSearch_Step(
00066   Teuchos::RCP<NLPInterfacePack::NLPBarrier> barrier_nlp,
00067   const value_type tau_boundary_frac
00068   )
00069   :
00070   tau_boundary_frac_(tau_boundary_frac),
00071   barrier_nlp_(barrier_nlp),
00072   filter_(FILTER_IQ_STRING)
00073 {
00074   TEUCHOS_TEST_FOR_EXCEPTION(
00075     !barrier_nlp_.get(),
00076     std::logic_error,
00077     "PreProcessBarrierLineSearch_Step given NULL NLPBarrier."
00078     );
00079 }
00080   
00081 
00082 bool PreProcessBarrierLineSearch_Step::do_step(
00083   Algorithm& _algo, poss_type step_poss, IterationPack::EDoStepType type
00084   ,poss_type assoc_step_poss
00085   )
00086 {
00087   using Teuchos::dyn_cast;
00088   using IterationPack::print_algorithm_step;
00089     using AbstractLinAlgPack::assert_print_nan_inf;
00090   using AbstractLinAlgPack::fraction_to_boundary;
00091   using AbstractLinAlgPack::fraction_to_zero_boundary;
00092   using LinAlgOpPack::Vp_StV;
00093 
00094   NLPAlgo            &algo   = dyn_cast<NLPAlgo>(_algo);
00095   IpState             &s      = dyn_cast<IpState>(_algo.state());
00096   NLP                 &nlp    = algo.nlp();
00097 
00098   EJournalOutputLevel olevel = algo.algo_cntr().journal_output_level();
00099   std::ostream& out = algo.track().journal_out();
00100   
00101   // print step header.
00102   if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) 
00103   {
00104     using IterationPack::print_algorithm_step;
00105     print_algorithm_step( _algo, step_poss, type, assoc_step_poss, out );
00106   }
00107 
00108   const value_type& mu_k = s.barrier_parameter().get_k(0);
00109 
00110   // if using filter and u changed, clear filter
00111   if (filter_.exists_in(s))
00112   {
00113     if ( s.barrier_parameter().updated_k(-1) )
00114     {
00115       const value_type mu_km1 = s.barrier_parameter().get_k(-1);
00116       if (mu_k != mu_km1)
00117       {
00118         if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) ) 
00119         {
00120           out << "\nBarrier Parameter changed - resetting the filter ...\n";
00121         }
00122         // reset the filter
00123         MoochoPack::Filter_T &filter_k = filter_(s).set_k(0);
00124         filter_k.clear();
00125       }
00126     }
00127   }
00128 
00129   // Update the barrier parameter in the NLP
00130   barrier_nlp_->mu(s.barrier_parameter().get_k(0));
00131     
00132   // Calculate the barrier k terms
00133   barrier_nlp_->set_Gf( &(s.grad_barrier_obj().set_k(0)) );
00134   barrier_nlp_->calc_Gf(s.x().get_k(0), true);
00135 
00136   barrier_nlp_->set_f( &(s.barrier_obj().set_k(0)) );
00137   barrier_nlp_->calc_f(s.x().get_k(0), true);
00138 
00139 
00140   // Calculate the k+1 terms
00141   // Get iteration quantities...
00142   value_type& alpha_k = s.alpha().set_k(0);
00143   value_type& alpha_vl_k = s.alpha_vl().set_k(0);
00144   value_type& alpha_vu_k = s.alpha_vu().set_k(0);
00145 
00146   const Vector& x_k = s.x().get_k(0);
00147   VectorMutable& x_kp1 = s.x().set_k(+1);
00148 
00149   const Vector& d_k = s.d().get_k(0);
00150   const Vector& dvl_k = s.dvl().get_k(0);
00151   const Vector& dvu_k = s.dvu().get_k(0);
00152 
00153   const Vector& vl_k = s.Vl().get_k(0).diag();
00154   VectorMutable& vl_kp1 = s.Vl().set_k(+1).diag();
00155 
00156   const Vector& vu_k = s.Vu().get_k(0).diag();
00157   VectorMutable& vu_kp1 = s.Vu().set_k(+1).diag();
00158 
00159   alpha_k = fraction_to_boundary(
00160     tau_boundary_frac_, 
00161     x_k, 
00162     d_k,
00163     nlp.xl(),
00164     nlp.xu()
00165     );
00166 
00167   alpha_vl_k = fraction_to_zero_boundary(
00168     tau_boundary_frac_,
00169     vl_k,
00170     dvl_k
00171     );
00172 
00173   alpha_vu_k = fraction_to_zero_boundary(
00174     tau_boundary_frac_,
00175     vu_k,
00176     dvu_k
00177     );
00178 
00179   TEUCHOS_TEST_FOR_EXCEPT( !( alpha_k <= 1.0 && alpha_vl_k <= 1.0 && alpha_vu_k <= 1.0 ) );
00180   TEUCHOS_TEST_FOR_EXCEPT( !( alpha_k >= 0.0 && alpha_vl_k >= 0.0 && alpha_vu_k >= 0.0 ) );
00181 
00182   x_kp1 = x_k;
00183   Vp_StV( &x_kp1, alpha_k, d_k);
00184 
00185   alpha_vl_k = alpha_vu_k = min(alpha_vl_k, alpha_vu_k);
00186 
00187   vl_kp1 = vl_k;
00188   Vp_StV( &vl_kp1, alpha_vl_k, dvl_k);
00189 
00190   vu_kp1 = vu_k;
00191   Vp_StV( &vu_kp1, alpha_vu_k, dvu_k);
00192  
00193 
00194     IterQuantityAccess<VectorMutable>
00195     *c_iq   = nlp.m() > 0 ? &s.c() : NULL;
00196 
00197     if (assert_print_nan_inf(x_kp1, "x", true, NULL))
00198   {
00199     // Calcuate f and c at the new point.
00200     barrier_nlp_->unset_quantities();
00201     barrier_nlp_->set_f( &s.barrier_obj().set_k(+1) );
00202     if (c_iq) {
00203       barrier_nlp_->set_c( &c_iq->set_k(+1) );
00204       barrier_nlp_->calc_c( x_kp1, true );
00205     }
00206     barrier_nlp_->calc_f( x_kp1, false ); 
00207     barrier_nlp_->unset_quantities();
00208   }
00209   
00210   if( static_cast<int>(olevel) >= static_cast<int>(PRINT_ALGORITHM_STEPS) )
00211   {
00212     out << "\nalpha_vl_k = " << alpha_vl_k
00213       << "\nalpha_vu_k = " << alpha_vu_k
00214       << "\nalpha_k    = " << alpha_k
00215       << std::endl;
00216   }
00217 
00218   if( static_cast<int>(olevel) >= static_cast<int>(PRINT_VECTORS) ) 
00219   {
00220     out << "\nvl_kp1 = \n" << vl_kp1
00221       << "\nvu_kp1 = \n" << vu_kp1
00222       << "\nx_kp1 = \n" << x_kp1;
00223   }
00224 
00225   return true;
00226 }
00227 
00228 void PreProcessBarrierLineSearch_Step::print_step(
00229   const Algorithm& _algo, poss_type step_poss, IterationPack::EDoStepType type
00230   ,poss_type assoc_step_poss, std::ostream& out, const std::string& L
00231   ) const
00232 {
00233   //const NLPAlgo   &algo = rsqp_algo(_algo);
00234   //const NLPAlgoState  &s    = algo.rsqp_state();
00235   out << L << "*** calculate alpha max by the fraction to boundary rule\n"
00236     << L << "ToDo: Complete documentation\n";
00237 }
00238 
00239 namespace {
00240 
00241 const int local_num_options = 1;
00242 
00243 enum local_EOptions 
00244 {
00245   TAU_BOUNDARY_FRAC
00246 };
00247 
00248 const char* local_SOptions[local_num_options] = 
00249 {
00250   "tau_boundary_frac"
00251 };
00252 
00253 }
00254 
00255  
00256 PreProcessBarrierLineSearch_StepSetOptions::PreProcessBarrierLineSearch_StepSetOptions(
00257   PreProcessBarrierLineSearch_Step* target
00258   , const char opt_grp_name[] )
00259   :
00260   OptionsFromStreamPack::SetOptionsFromStreamNode(
00261     opt_grp_name, local_num_options, local_SOptions ),
00262   OptionsFromStreamPack::SetOptionsToTargetBase< PreProcessBarrierLineSearch_Step >( target )
00263 {}
00264 
00265 void PreProcessBarrierLineSearch_StepSetOptions::setOption( 
00266   int option_num, const std::string& option_value )
00267 {
00268   typedef PreProcessBarrierLineSearch_Step target_t;
00269   switch( (local_EOptions)option_num ) 
00270   {
00271     case TAU_BOUNDARY_FRAC:
00272       target().tau_boundary_frac(std::atof(option_value.c_str()));
00273       break;
00274     default:
00275       TEUCHOS_TEST_FOR_EXCEPT(true);  // Local error only?
00276   }
00277 }
00278 
00279 } // end namespace MoochoPack 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines