|
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 // 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 <assert.h> 00043 00044 #include "NLPInterfacePack_test_nlp_direct.hpp" 00045 #include "NLPInterfacePack_CalcFiniteDiffProd.hpp" 00046 #include "NLPInterfacePack_CalcFiniteDiffProdSetOptions.hpp" 00047 #include "NLPInterfacePack_NLPTester.hpp" 00048 #include "NLPInterfacePack_NLPTesterSetOptions.hpp" 00049 #include "NLPInterfacePack_NLPDirectTester.hpp" 00050 #include "NLPInterfacePack_NLPDirectTesterSetOptions.hpp" 00051 #include "NLPInterfacePack_NLPDirect.hpp" 00052 #include "AbstractLinAlgPack_VectorSpace.hpp" 00053 #include "AbstractLinAlgPack_VectorSpaceTester.hpp" 00054 #include "AbstractLinAlgPack_VectorSpaceTesterSetOptions.hpp" 00055 #include "AbstractLinAlgPack_VectorMutable.hpp" 00056 #include "AbstractLinAlgPack_VectorOut.hpp" 00057 #include "AbstractLinAlgPack_MatrixOp.hpp" 00058 #include "AbstractLinAlgPack_MatrixOpOut.hpp" 00059 #include "TestingHelperPack_update_success.hpp" 00060 00061 bool NLPInterfacePack::test_nlp_direct( 00062 NLPDirect *nlp 00063 ,OptionsFromStreamPack::OptionsFromStream *options 00064 ,std::ostream *out 00065 ) 00066 { 00067 using TestingHelperPack::update_success; 00068 00069 bool result; 00070 bool success = true; 00071 00072 Teuchos::VerboseObjectTempState<NLP> 00073 nlpOutputTempState(Teuchos::rcp(nlp,false),Teuchos::getFancyOStream(Teuchos::rcp(out,false)),Teuchos::VERB_LOW); 00074 00075 if(out) 00076 *out 00077 << "\n****************************" 00078 << "\n*** test_nlp_direct(...) ***" 00079 << "\n*****************************\n"; 00080 00081 nlp->initialize(true); 00082 00083 // Test the DVector spaces 00084 if(out) 00085 *out << "\nTesting the vector spaces ...\n"; 00086 00087 VectorSpaceTester vec_space_tester; 00088 if(options) { 00089 VectorSpaceTesterSetOptions 00090 opt_setter(&vec_space_tester); 00091 opt_setter.set_options(*options); 00092 } 00093 00094 if(out) 00095 *out << "\nTesting nlp->space_x() ...\n"; 00096 result = vec_space_tester.check_vector_space(*nlp->space_x(),out); 00097 if(out) { 00098 if(result) 00099 *out << "nlp->space_x() checks out!\n"; 00100 else 00101 *out << "nlp->space_x() check failed!\n"; 00102 } 00103 update_success( result, &success ); 00104 if(out) 00105 *out << "\nTesting nlp->space_x()->sub_space(nlp->var_dep()) ...\n"; 00106 result = vec_space_tester.check_vector_space( 00107 *nlp->space_x()->sub_space(nlp->var_dep()),out); 00108 if(out) { 00109 if(result) 00110 *out << "nlp->space_x()->sub_space(nlp->var_dep()) checks out!\n"; 00111 else 00112 *out << "nlp->space_x()->sub_space(nlp->var_dep()) check failed!\n"; 00113 } 00114 update_success( result, &success ); 00115 if(out) 00116 *out << "\nTesting nlp->space_x()->sub_space(nlp->var_indep()) ...\n"; 00117 result = vec_space_tester.check_vector_space( 00118 *nlp->space_x()->sub_space(nlp->var_indep()),out); 00119 if(out) { 00120 if(result) 00121 *out << "nlp->space_x()->sub_space(nlp->var_indep()) checks out!\n"; 00122 else 00123 *out << "nlp->space_x()->sub_space(nlp->var_indep()) check failed!\n"; 00124 } 00125 update_success( result, &success ); 00126 if(out) 00127 *out << "\nTesting nlp->space_c() ...\n"; 00128 result = vec_space_tester.check_vector_space(*nlp->space_c(),out); 00129 if(out) { 00130 if(result) 00131 *out << "nlp->space_c() checks out!\n"; 00132 else 00133 *out << "nlp->space_c() check failed!\n"; 00134 } 00135 update_success( result, &success ); 00136 if(out) 00137 *out << "\nTesting nlp->space_c()->sub_space(nlp->con_decomp()) ...\n"; 00138 result = vec_space_tester.check_vector_space( 00139 *nlp->space_c()->sub_space(nlp->con_decomp()),out); 00140 if(out) { 00141 if(result) 00142 *out << "nlp->space_c()->sub_space(nlp->con_decomp()) checks out!\n"; 00143 else 00144 *out << "nlp->space_c()->sub_space(nlp->con_decomp()) check failed!\n"; 00145 } 00146 update_success( result, &success ); 00147 if( nlp->con_decomp().size() < nlp->m() ) { 00148 if(out) 00149 *out << "\nTesting nlp->space_c()->sub_space(nlp->con_undecomp()) ...\n"; 00150 result = vec_space_tester.check_vector_space( 00151 *nlp->space_c()->sub_space(nlp->con_undecomp()),out); 00152 if(out) { 00153 if(result) 00154 *out << "nlp->space_c()->sub_space(nlp->con_undecomp()) checks out!\n"; 00155 else 00156 *out << "nlp->space_c()->sub_space(nlp->con_undecomp()) check failed!\n"; 00157 } 00158 update_success( result, &success ); 00159 } 00160 00161 // Test the NLP interface first! 00162 00163 NLPTester nlp_tester; 00164 if(options) { 00165 NLPTesterSetOptions 00166 nlp_tester_opt_setter(&nlp_tester); 00167 nlp_tester_opt_setter.set_options(*options); 00168 } 00169 const bool print_all_warnings = nlp_tester.print_all(); 00170 00171 result = nlp_tester.test_interface( 00172 nlp, nlp->xinit(), print_all_warnings, out ); 00173 update_success( result, &success ); 00174 00175 // Test the NLPDirect interface now! 00176 00177 const bool supports_Gf = nlp->supports_Gf(); 00178 00179 if(out) 00180 *out << "\nCalling nlp->calc_point(...) at nlp->xinit() ...\n"; 00181 const size_type 00182 n = nlp->n(), 00183 m = nlp->m(); 00184 const Range1D 00185 var_dep = nlp->var_dep(), 00186 var_indep = nlp->var_indep(), 00187 con_decomp = nlp->con_decomp(), 00188 con_undecomp = nlp->con_undecomp(); 00189 VectorSpace::vec_mut_ptr_t 00190 c = nlp->space_c()->create_member(), 00191 Gf = nlp->space_x()->create_member(), 00192 py = nlp->space_x()->sub_space(var_dep)->create_member(), 00193 rGf = nlp->space_x()->sub_space(var_indep)->create_member(); 00194 NLPDirect::mat_fcty_ptr_t::element_type::obj_ptr_t 00195 GcU = con_decomp.size() < m ? nlp->factory_GcU()->create() : Teuchos::null, 00196 D = nlp->factory_D()->create(), 00197 Uz = con_decomp.size() < m ? nlp->factory_Uz()->create() : Teuchos::null; 00198 nlp->calc_point( 00199 nlp->xinit(), NULL, c.get(), true, supports_Gf?Gf.get():NULL, py.get(), rGf.get() 00200 ,GcU.get(), D.get(), Uz.get() ); 00201 if(out) { 00202 if(supports_Gf) { 00203 *out << "\n||Gf||inf = " << Gf->norm_inf(); 00204 if(nlp_tester.print_all()) 00205 *out << "\nGf =\n" << *Gf; 00206 } 00207 *out << "\n||py||inf = " << py->norm_inf(); 00208 if(nlp_tester.print_all()) 00209 *out << "\npy =\n" << *py; 00210 *out << "\n||rGf||inf = " << rGf->norm_inf(); 00211 if(nlp_tester.print_all()) 00212 *out << "\nrGf =\n" << *rGf; 00213 if(nlp_tester.print_all()) 00214 *out << "\nD =\n" << *D; 00215 if( con_decomp.size() < m ) { 00216 TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Print GcU and Uz 00217 } 00218 *out << "\n"; 00219 } 00220 00221 CalcFiniteDiffProd 00222 calc_fd_prod; 00223 if(options) { 00224 CalcFiniteDiffProdSetOptions 00225 options_setter( &calc_fd_prod ); 00226 options_setter.set_options(*options); 00227 } 00228 NLPDirectTester 00229 nlp_first_order_direct_tester(Teuchos::rcp(&calc_fd_prod,false)); 00230 if(options) { 00231 NLPDirectTesterSetOptions 00232 nlp_tester_opt_setter(&nlp_first_order_direct_tester); 00233 nlp_tester_opt_setter.set_options(*options); 00234 } 00235 result = nlp_first_order_direct_tester.finite_diff_check( 00236 nlp, nlp->xinit() 00237 ,nlp->num_bounded_x() ? &nlp->xl() : NULL 00238 ,nlp->num_bounded_x() ? &nlp->xu() : NULL 00239 ,c.get() 00240 ,supports_Gf?Gf.get():NULL,py.get(),rGf.get(),GcU.get(),D.get(),Uz.get() 00241 ,print_all_warnings, out 00242 ); 00243 update_success( result, &success ); 00244 00245 return success; 00246 }
1.7.6.1