GlobiPack Package Browser (Single Doxygen Collection) Version of the Day
GlobiPack_BrentsLineSearch_def.hpp
Go to the documentation of this file.
00001 /*
00002 // @HEADER
00003 // ***********************************************************************
00004 // 
00005 //    GlobiPack: Collection of Scalar 1D globalizaton utilities
00006 //                 Copyright (2009) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // This library is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU Lesser General Public License as
00013 // published by the Free Software Foundation; either version 2.1 of the
00014 // License, or (at your option) any later version.
00015 // 
00016 // This library is distributed in the hope that it will be useful, but
00017 // WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019 // Lesser General Public License for more details.
00020 // 
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License along with this library; if not, write to the Free Software
00023 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00024 // USA
00025 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00026 // 
00027 // ***********************************************************************
00028 // @HEADER
00029 */
00030 
00031 #ifndef GLOBIPACK_BRENTS_LINE_SEARCH_DEF_HPP
00032 #define GLOBIPACK_BRENTS_LINE_SEARCH_DEF_HPP
00033 
00034 
00035 #include "GlobiPack_BrentsLineSearch_decl.hpp"
00036 #include "Teuchos_TabularOutputter.hpp"
00037 
00038 
00039 namespace GlobiPack {
00040 
00041 
00042 // Constructor/Initializers/Accessors
00043 
00044 
00045 template<typename Scalar>
00046 BrentsLineSearch<Scalar>::BrentsLineSearch()
00047 {}
00048 
00049 
00050 template<typename Scalar>
00051 const GoldenQuadInterpBracket<Scalar>&
00052 BrentsLineSearch<Scalar>::bracket() const
00053 {
00054   return bracket_;
00055 }
00056 
00057 
00058 template<typename Scalar>
00059 const Brents1DMinimization<Scalar>&
00060 BrentsLineSearch<Scalar>::brentsMin() const
00061 {
00062   return brentsMin_;
00063 }
00064 
00065 
00066 // Overridden from ParameterListAcceptor
00067 
00068 
00069 template<class Scalar>
00070 void BrentsLineSearch<Scalar>::setParameterList(
00071   RCP<ParameterList> const& paramList
00072   )
00073 {
00074   typedef ScalarTraits<Scalar> ST;
00075   namespace BLSU = BrentsLineSearchUtils;
00076   using Teuchos::sublist;
00077   paramList->validateParametersAndSetDefaults(*this->getValidParameters());
00078   bracket_.setParameterList(sublist(paramList, BLSU::bracket_name, true));
00079   brentsMin_.setParameterList(sublist(paramList, BLSU::minimize_name, true));
00080   setMyParamList(paramList);
00081 }
00082 
00083 
00084 template<class Scalar>
00085 RCP<const ParameterList>
00086 BrentsLineSearch<Scalar>::getValidParameters() const
00087 {
00088   namespace BLSU = BrentsLineSearchUtils;
00089   static RCP<const ParameterList> validPL;
00090   if (is_null(validPL)) {
00091     RCP<Teuchos::ParameterList>
00092       pl = Teuchos::rcp(new Teuchos::ParameterList());
00093     pl->sublist(BLSU::bracket_name).setParameters(
00094       *bracket_.getValidParameters()
00095       ).disableRecursiveValidation();
00096     pl->sublist(BLSU::minimize_name).setParameters(
00097       *brentsMin_.getValidParameters()
00098       ).disableRecursiveValidation();
00099     validPL = pl;
00100   }
00101   return validPL;
00102 }
00103 
00104 
00105 // Overrridden from LineSearchBase
00106 
00107 
00108 template<typename Scalar>
00109 bool BrentsLineSearch<Scalar>::requiresBaseDeriv() const
00110 {
00111   return false;
00112 }
00113 
00114 
00115 template<typename Scalar>
00116 bool BrentsLineSearch<Scalar>::requiresDerivEvals() const
00117 {
00118   return false;
00119 }
00120 
00121 
00122 template<typename Scalar>
00123 bool BrentsLineSearch<Scalar>::doLineSearch(
00124   const MeritFunc1DBase<Scalar> &phi,
00125   const PointEval1D<Scalar> &point_k,
00126   const Ptr<PointEval1D<Scalar> > &point_kp1,
00127   const Ptr<int> &numIters
00128   ) const
00129 {
00130 
00131   using Teuchos::as;
00132   using Teuchos::OSTab;
00133   using Teuchos::outArg;
00134   using Teuchos::inOutArg;
00135   typedef ScalarTraits<Scalar> ST;
00136   typedef PointEval1D<Scalar> PE1D;
00137 
00138 #ifdef TEUCHOS_DEBUG
00139   TEUCHOS_ASSERT_EQUALITY(point_k.alpha, ST::zero());
00140   TEUCHOS_ASSERT_INEQUALITY(point_k.phi, !=, PE1D::valNotGiven());
00141   TEUCHOS_ASSERT_EQUALITY(point_k.Dphi, PE1D::valNotGiven());
00142   TEUCHOS_ASSERT(!is_null(point_kp1));
00143   TEUCHOS_ASSERT_INEQUALITY(point_kp1->alpha, >, ST::zero());
00144   TEUCHOS_ASSERT_INEQUALITY(point_kp1->phi, !=, PE1D::valNotGiven());
00145   TEUCHOS_ASSERT_EQUALITY(point_kp1->Dphi, PE1D::valNotGiven());
00146 #endif
00147 
00148   const RCP<Teuchos::FancyOStream> out = this->getOStream();
00149   bracket_.setOStream(out);
00150   brentsMin_.setOStream(out);
00151 
00152   *out << "\nStarting bracketing and brents 1D minimization linesearch ...\n";
00153 
00154   OSTab tab(out);
00155 
00156   int totalNumIters = 0;
00157 
00158   PointEval1D<Scalar> p_l = point_k;
00159   PointEval1D<Scalar> &p_m = *point_kp1; // Update in place!
00160   PointEval1D<Scalar> p_u;
00161 
00162   bool success = true;
00163 
00164   // A) Bracket the minimum
00165 
00166   int numBracketIters = -1;
00167 
00168   const bool bracketSuccess = bracket_.bracketMinimum(
00169     phi, inOutArg(p_l), inOutArg(p_m), outArg(p_u), outArg(numBracketIters) );
00170 
00171   if (!bracketSuccess) success = false;
00172 
00173   totalNumIters += numBracketIters;
00174 
00175   // B) Do approximate mimimization in the bracket
00176 
00177   if (bracketSuccess) {
00178 
00179     int numBrentsIters = -1;
00180     
00181     const bool brentsSuccess = brentsMin_.approxMinimize(
00182       phi, p_l, inOutArg(p_m), p_u, outArg(numBrentsIters) );
00183     
00184     if (!brentsSuccess) success = false;
00185     
00186     totalNumIters += numBrentsIters;
00187 
00188   }
00189 
00190   // C) Overall success?
00191 
00192   if (!is_null(numIters))
00193     *numIters = totalNumIters;
00194 
00195   return success;
00196   
00197 }
00198 
00199 
00200 } // namespace GlobiPack
00201 
00202 
00203 #endif // GLOBIPACK_BRENTS_LINE_SEARCH_DEF_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends