NLPInterfacePack: C++ Interfaces and Implementation for Non-Linear Programs Version of the Day
NLPInterfacePack_NLPBarrier.cpp
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 <math.h>
00043 #include <iostream>
00044 #include <limits>
00045 
00046 #include "NLPInterfacePack_NLPBarrier.hpp"
00047 #include "AbstractLinAlgPack_VectorSpace.hpp"
00048 #include "AbstractLinAlgPack_VectorAuxiliaryOps.hpp"
00049 #include "AbstractLinAlgPack_VectorOut.hpp"
00050 #include "Teuchos_Assert.hpp"
00051 
00052 namespace NLPInterfacePack {
00053 
00054 NLPBarrier::NLPBarrier()
00055   :
00056   barrier_term_(0.0),
00057   objective_term_(0.0),
00058   nlp_(Teuchos::null)
00059   {
00060   }
00061 
00062 
00063 void NLPBarrier::InitializeFromNLP(
00064   Teuchos::RCP<NLP> original_nlp
00065   )
00066   {
00067   TEUCHOS_TEST_FOR_EXCEPTION(
00068     !original_nlp.get(),
00069     std::logic_error,
00070     "null nlp passed to NLPBarrier decorator"
00071     );
00072 
00073   nlp_ = Teuchos::rcp_dynamic_cast<NLPObjGrad>(original_nlp);
00074 
00075   TEUCHOS_TEST_FOR_EXCEPTION(
00076     !nlp_.get(),
00077     std::logic_error,
00078     "non NLPObjGrad NLP passed to NLPBarrier decorator"
00079     );
00080   }
00081 
00082 void NLPBarrier::mu(const value_type mu)
00083   {
00084   mu_ = mu;
00085   }
00086 
00087 value_type NLPBarrier::barrier_term() const
00088   {
00089   return barrier_term_;
00090   }
00091 
00092 value_type NLPBarrier::objective_term() const
00093   {
00094   return objective_term_;
00095   }
00096 
00097 const Teuchos::RCP<Vector> NLPBarrier::grad_barrier_term() const
00098   {
00099   return grad_barrier_term_;
00100   }
00101 
00102 const Teuchos::RCP<Vector>  NLPBarrier::grad_objective_term() const
00103   {
00104   return grad_objective_term_;
00105   }
00106 
00107 
00108 void NLPBarrier::calc_f(const Vector& x, bool newx) const
00109   {
00110   nlp_->calc_f(x, newx);
00111   value_type* f_val = nlp_->get_f();
00112 
00113   objective_term_ = *f_val;
00114   barrier_term_   = CalculateBarrierTerm(x);
00115 
00116   (*f_val) += barrier_term_;
00117   }
00118 
00119 void NLPBarrier::calc_Gf(const Vector& x, bool newx) const
00120   {
00121   using AbstractLinAlgPack::inv_of_difference;
00122 
00123      nlp_->calc_Gf(x, newx);
00124   grad_objective_term_ = nlp_->get_Gf()->clone();
00125 
00126   //std::cout << "grad_objective_term=\n";
00127   //grad_objective_term_->output(std::cout);
00128 
00129   if (!grad_barrier_term_temp_.get())
00130     { grad_barrier_term_temp_ = grad_objective_term_->space().create_member(); }
00131 
00132   if (!grad_barrier_term_.get())
00133     { grad_barrier_term_ = grad_objective_term_->space().create_member(); } 
00134 
00135   *grad_barrier_term_temp_ = 0.0;
00136   *grad_barrier_term_ = 0.0;  
00137 
00138   inv_of_difference(mu_, nlp_->xu(), x, grad_barrier_term_.get());
00139    //std::cout << "mu*invXU=\n";
00140   //grad_barrier_term_->output(std::cout);
00141 
00142   inv_of_difference(mu_, x, nlp_->xl(), grad_barrier_term_temp_.get());
00143    //std::cout << "mu*invXL=\n";
00144   //grad_barrier_term_temp_->output(std::cout);
00145 
00146   grad_barrier_term_->axpy(-1.0, *grad_barrier_term_temp_);
00147 
00148   nlp_->get_Gf()->axpy(1.0, *grad_barrier_term_);
00149 
00150   //std::cout << "grad_objective_term with barrier=\n";
00151   //nlp_->get_Gf()->output(std::cout);
00152   }
00153 
00154 void NLPBarrier::imp_calc_f(
00155   const Vector& x, 
00156   bool newx, 
00157   const ZeroOrderInfo& zero_order_info
00158   ) const
00159   {
00160   TEUCHOS_TEST_FOR_EXCEPT( !( false && !"This should never get called." ) );
00161   }
00162 
00163 void NLPBarrier::imp_calc_c(
00164   const Vector& x, 
00165   bool newx, 
00166   const ZeroOrderInfo& zero_order_info
00167   ) const
00168   {
00169   TEUCHOS_TEST_FOR_EXCEPT( !( false && !"This should never get called." ) );
00170   }
00171 
00172 void NLPBarrier::imp_calc_c_breve(
00173   const Vector& x, 
00174   bool newx, 
00175   const ZeroOrderInfo& zero_order_info_breve
00176   ) const
00177   { 
00178   TEUCHOS_TEST_FOR_EXCEPT( !( false && !"This should never get called." ) );
00179   }
00180 
00181 void NLPBarrier::imp_calc_h_breve(
00182   const Vector& x, 
00183   bool newx, 
00184   const ZeroOrderInfo& zero_order_info_breve
00185   ) const
00186   { 
00187   TEUCHOS_TEST_FOR_EXCEPT( !( false && !"This should never get called." ) );
00188   }
00189 
00190 void NLPBarrier::imp_calc_Gf(
00191   const Vector& x,
00192   bool newx, 
00193   const ObjGradInfo& obj_grad_info
00194   ) const
00195   {
00196   TEUCHOS_TEST_FOR_EXCEPT( !( false && !"This should never get called." ) );
00197   }
00198 
00199 
00200 value_type NLPBarrier::CalculateBarrierTerm(const Vector& x) const
00201   {
00202   using AbstractLinAlgPack::log_bound_barrier;
00203   barrier_term_ = log_bound_barrier(x, xl(), xu());
00204 //  std::cerr << "NLPBarrier::CalculateBarrierTerm(x) : (1) barrier_term_ = " << barrier_term_ << std::endl;
00205   barrier_term_ *= -mu_;
00206 //  std::cerr << "NLPBarrier::CalculateBarrierTerm(x) : (2) barrier_term_ = " << barrier_term_ << std::endl;
00207   return barrier_term_;
00208   }
00209 
00210 } // end namespace NLPInterfacePack
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends