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