NLPInterfacePack_test_nlp_direct.cpp

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

Generated on Tue Oct 20 12:51:48 2009 for MOOCHO (Single Doxygen Collection) by doxygen 1.4.7