|
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 <assert.h> 00030 00031 #include "NLPInterfacePack_test_nlp_first_order.hpp" 00032 #include "NLPInterfacePack_CalcFiniteDiffProd.hpp" 00033 #include "NLPInterfacePack_CalcFiniteDiffProdSetOptions.hpp" 00034 #include "NLPInterfacePack_NLPTester.hpp" 00035 #include "NLPInterfacePack_NLPTesterSetOptions.hpp" 00036 #include "NLPInterfacePack_NLPFirstDerivTester.hpp" 00037 #include "NLPInterfacePack_NLPFirstDerivTesterSetOptions.hpp" 00038 #include "NLPInterfacePack_NLPFirstOrder.hpp" 00039 #include "AbstractLinAlgPack_VectorSpace.hpp" 00040 #include "AbstractLinAlgPack_VectorSpaceTester.hpp" 00041 #include "AbstractLinAlgPack_VectorSpaceTesterSetOptions.hpp" 00042 #include "AbstractLinAlgPack_VectorMutable.hpp" 00043 #include "AbstractLinAlgPack_VectorOut.hpp" 00044 #include "AbstractLinAlgPack_MatrixOp.hpp" 00045 #include "AbstractLinAlgPack_MatrixOpOut.hpp" 00046 #include "TestingHelperPack_update_success.hpp" 00047 #include "Teuchos_FancyOStream.hpp" 00048 00049 bool NLPInterfacePack::test_nlp_first_order( 00050 NLPFirstOrder *nlp 00051 ,OptionsFromStreamPack::OptionsFromStream *options 00052 ,std::ostream *out 00053 ) 00054 { 00055 namespace rcp = MemMngPack; 00056 using TestingHelperPack::update_success; 00057 00058 bool result; 00059 bool success = true; 00060 00061 Teuchos::VerboseObjectTempState<NLP> 00062 nlpOutputTempState(Teuchos::rcp(nlp,false),Teuchos::getFancyOStream(Teuchos::rcp(out,false)),Teuchos::VERB_LOW); 00063 00064 if(out) 00065 *out << "\n*********************************" 00066 << "\n*** test_nlp_first_order(...) ***" 00067 << "\n*********************************\n"; 00068 00069 nlp->initialize(true); 00070 00071 // Test the DVector spaces 00072 if(out) 00073 *out << "\nTesting the vector spaces ...\n"; 00074 00075 VectorSpaceTester vec_space_tester; 00076 if(options) { 00077 VectorSpaceTesterSetOptions 00078 opt_setter(&vec_space_tester); 00079 opt_setter.set_options(*options); 00080 } 00081 00082 if(out) 00083 *out << "\nTesting nlp->space_x() ...\n"; 00084 result = vec_space_tester.check_vector_space(*nlp->space_x(),out); 00085 if(out) { 00086 if(result) 00087 *out << "nlp->space_x() checks out!\n"; 00088 else 00089 *out << "nlp->space_x() check failed!\n"; 00090 } 00091 update_success( result, &success ); 00092 00093 if( nlp->m() ) { 00094 if(out) 00095 *out << "\nTesting nlp->space_c() ...\n"; 00096 result = vec_space_tester.check_vector_space(*nlp->space_c(),out); 00097 if(out) { 00098 if(result) 00099 *out << "nlp->space_c() checks out!\n"; 00100 else 00101 *out << "nlp->space_c() check failed!\n"; 00102 } 00103 update_success( result, &success ); 00104 } 00105 00106 // Test the NLP interface first! 00107 00108 NLPTester nlp_tester; 00109 if(options) { 00110 NLPTesterSetOptions 00111 nlp_tester_opt_setter(&nlp_tester); 00112 nlp_tester_opt_setter.set_options(*options); 00113 } 00114 const bool print_all_warnings = nlp_tester.print_all(); 00115 00116 result = nlp_tester.test_interface( 00117 nlp, nlp->xinit(), print_all_warnings, out ); 00118 update_success( result, &success ); 00119 00120 // Test the NLPFirstOrder interface now! 00121 00122 const size_type 00123 n = nlp->n(), 00124 m = nlp->m(); 00125 VectorSpace::vec_mut_ptr_t 00126 c = m ? nlp->space_c()->create_member() : Teuchos::null, 00127 Gf = nlp->space_x()->create_member(); 00128 NLPFirstOrder::mat_fcty_ptr_t::element_type::obj_ptr_t 00129 Gc = m ? nlp->factory_Gc()->create() : Teuchos::null; 00130 00131 if(m) { 00132 if(out) 00133 *out << "\nCalling nlp->calc_Gc(...) at nlp->xinit() ...\n"; 00134 nlp->set_Gc( Gc.get() ); 00135 nlp->calc_Gc( nlp->xinit(), true ); 00136 if(nlp_tester.print_all()) { 00137 *out << "\nGc =\n" << *Gc; 00138 } 00139 } 00140 00141 if(out) 00142 *out << "\nCalling nlp->calc_Gf(...) at nlp->xinit() ...\n"; 00143 nlp->set_Gf( Gf.get() ); 00144 nlp->calc_Gf( nlp->xinit(), m == 0 ); 00145 if(nlp_tester.print_all()) 00146 *out << "\nGf =\n" << *Gf; 00147 00148 CalcFiniteDiffProd 00149 calc_fd_prod; 00150 if(options) { 00151 CalcFiniteDiffProdSetOptions 00152 options_setter( &calc_fd_prod ); 00153 options_setter.set_options(*options); 00154 } 00155 NLPFirstDerivTester 00156 nlp_first_derivatives_tester(Teuchos::rcp(&calc_fd_prod,false)); 00157 if(options) { 00158 NLPFirstDerivTesterSetOptions 00159 nlp_tester_opt_setter(&nlp_first_derivatives_tester); 00160 nlp_tester_opt_setter.set_options(*options); 00161 } 00162 result = nlp_first_derivatives_tester.finite_diff_check( 00163 nlp, nlp->xinit() 00164 ,nlp->num_bounded_x() ? &nlp->xl() : NULL 00165 ,nlp->num_bounded_x() ? &nlp->xu() : NULL 00166 ,Gc.get(), Gf.get() 00167 ,print_all_warnings, out 00168 ); 00169 update_success( result, &success ); 00170 00171 return success; 00172 }
1.7.4