|
ConstrainedOptPack: C++ Tools for Constrained (and Unconstrained) Optimization 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 "ConstrainedOptPack_MeritFuncNLPModL1.hpp" 00030 #include "AbstractLinAlgPack_VectorMutable.hpp" 00031 #include "AbstractLinAlgPack_VectorStdOps.hpp" 00032 #include "Teuchos_TestForException.hpp" 00033 00034 namespace ConstrainedOptPack { 00035 00036 MeritFuncNLPModL1::MeritFuncNLPModL1() 00037 : deriv_(0.0) 00038 {} 00039 00040 // Overridden from MeritFuncNLP 00041 00042 value_type MeritFuncNLPModL1::value( 00043 value_type f 00044 ,const Vector *c 00045 ,const Vector *h 00046 ,const Vector *hl 00047 ,const Vector *hu 00048 ) const 00049 { 00050 TEST_FOR_EXCEPTION( 00051 h || hl || hu, std::logic_error 00052 ,"MeritFuncNLPModL1::value(...) : Error! general inequalities are not supported!" ); 00053 /* 00054 using DenseLinAlgPack::norm_1; 00055 return f + local_constr_term( mu_, c, "calc_deriv" ); 00056 */ 00057 TEST_FOR_EXCEPT(true); // ToDo: Write a reduction operator for the above operation 00058 return 0.0; 00059 } 00060 00061 value_type MeritFuncNLPModL1::deriv() const 00062 { 00063 return deriv_; 00064 } 00065 00066 void MeritFuncNLPModL1::print_merit_func( 00067 std::ostream& out, const std::string& L 00068 ) const 00069 { 00070 out 00071 << L << "*** Define a modified L1 merit funciton that uses different\n" 00072 << L << "*** penalty parameters for each constriant.\n" 00073 << L << "*** (assumes Gc_k'*d_k + c_k = 0):\n" 00074 << L << "phi(f,c) = f + sum( mu(j) * abs(c(j)), j = 1,...,m )\n" 00075 << L << "Dphi(x_k,d_k) = Gf_k' * d_k - sum( mu(j) * abs(c(j)), j = 1,...,m )\n"; 00076 } 00077 00078 // Overridden from MeritFuncNLPDirecDeriv 00079 00080 value_type MeritFuncNLPModL1::calc_deriv( 00081 const Vector &Gf_k 00082 ,const Vector *c_k 00083 ,const Vector *h_k 00084 ,const Vector *hl 00085 ,const Vector *hu 00086 ,const Vector &d_k 00087 ) 00088 { 00089 TEST_FOR_EXCEPTION( 00090 h_k || hl || hu, std::logic_error 00091 ,"MeritFuncNLPModL1::value(...) : Error! general inequalities are not supported!" ); 00092 /* 00093 using DenseLinAlgPack::dot; using DenseLinAlgPack::norm_1; 00094 return deriv_ = dot( Gf_k, d_k ) - local_constr_term( mu_, c_k, "calc_deriv" ); 00095 */ 00096 TEST_FOR_EXCEPT(true); // ToDo: Write a reduction operator for the above operation 00097 return 0.0; 00098 } 00099 00100 // Overridden from MeritFuncPenaltyParam 00101 00102 void MeritFuncNLPModL1::set_space_c( const VectorSpace::space_ptr_t& space_c ) 00103 { 00104 mu_ = space_c->create_member(); 00105 *mu_ = 0.0; 00106 } 00107 00108 VectorMutable& MeritFuncNLPModL1::set_mu() 00109 { 00110 return *mu_; 00111 } 00112 00113 const Vector& MeritFuncNLPModL1::get_mu() const 00114 { 00115 return *mu_; 00116 } 00117 00118 } // end namespace ConstrainedOptPack 00119 00120 /* ToDo: Write a reduction operator for the following! 00121 00122 namespace { 00123 00124 value_type local_constr_term( const DVector& mu, const DVectorSlice& c 00125 , const char func_name[] ) 00126 { 00127 if( mu.size() != c.size() ) { 00128 std::ostringstream omsg; 00129 omsg 00130 << "MeritFuncNLPModL1::" << func_name << "(...) : " 00131 << "Error, the sizes mu.size() == " << mu.size() 00132 << " != c.size() == " << c.size(); 00133 throw ConstrainedOptPack::MeritFuncNLP::InvalidInitialization(omsg.str()); 00134 } 00135 value_type r = 0.0; 00136 DVector::const_iterator 00137 mu_itr = mu.begin(); 00138 DVectorSlice::const_iterator 00139 c_itr = c.begin(); 00140 while( mu_itr != mu.end() ) 00141 r += *mu_itr++ * ::fabs( *c_itr++ ); 00142 return r; 00143 } 00144 00145 } // end namespace 00146 00147 */
1.7.4