|
MoochoPack : Framework for Large-Scale Optimization Algorithms 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 "MoochoPack_DecompositionSystemStateStepBuilderStd.hpp" 00030 00031 // NLP Stuff 00032 00033 #include "NLPInterfacePack_NLPSecondOrder.hpp" 00034 #include "NLPInterfacePack_NLPDirect.hpp" 00035 #include "NLPInterfacePack_NLPVarReductPerm.hpp" 00036 #include "NLPInterfacePack_NLPDirectTester.hpp" 00037 #include "NLPInterfacePack_NLPDirectTesterSetOptions.hpp" 00038 00039 // Basis system and direct sparse solvers 00040 00041 #include "AbstractLinAlgPack_BasisSystemTester.hpp" 00042 #include "AbstractLinAlgPack_BasisSystemTesterSetOptions.hpp" 00043 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 00044 #include "ConstrainedOptPack_DecompositionSystemVarReductPermStd.hpp" 00045 #endif 00046 00047 // Range/null decomposition 00048 00049 #include "AbstractLinAlgPack_MatrixSymIdent.hpp" 00050 #include "MoochoPack_DecompositionSystemHandlerVarReductPerm_Strategy.hpp" 00051 #include "MoochoPack_DecompositionSystemHandlerStd_Strategy.hpp" 00052 #include "ConstrainedOptPack_DecompositionSystemTester.hpp" 00053 #include "ConstrainedOptPack_DecompositionSystemTesterSetOptions.hpp" 00054 #include "ConstrainedOptPack_DecompositionSystemCoordinate.hpp" 00055 #include "ConstrainedOptPack_DecompositionSystemOrthogonal.hpp" 00056 00057 // Iteration quantities 00058 00059 #include "ConstrainedOptPack_MatrixIdentConcatStd.hpp" // Y, Z 00060 #include "AbstractLinAlgPack_MatrixSymOpNonsing.hpp" 00061 00062 // Eval new point 00063 00064 #include "MoochoPack_EvalNewPointStd_StepSetOptions.hpp" 00065 #include "MoochoPack_EvalNewPointTailoredApproach_StepSetOptions.hpp" 00066 #include "MoochoPack_EvalNewPointTailoredApproachCoordinate_Step.hpp" 00067 #include "MoochoPack_EvalNewPointTailoredApproachOrthogonal_Step.hpp" 00068 00069 // Other classes 00070 00071 #include "MoochoPack_NLPAlgoState.hpp" 00072 #include "MoochoPack_NewDecompositionSelectionStd_Strategy.hpp" 00073 #include "ConstrainedOptPack_VariableBoundsTesterSetOptions.hpp" 00074 #include "NLPInterfacePack_CalcFiniteDiffProdSetOptions.hpp" 00075 #include "NLPInterfacePack_NLPFirstDerivTester.hpp" 00076 #include "NLPInterfacePack_NLPFirstDerivTesterSetOptions.hpp" 00077 00078 // Common utilities 00079 #include "OptionsFromStreamPack_StringToIntMap.hpp" 00080 #include "OptionsFromStreamPack_StringToBool.hpp" 00081 #include "OptionsFromStreamPack_OptionsFromStream.hpp" 00082 #include "Teuchos_TestForException.hpp" 00083 #include "Teuchos_dyn_cast.hpp" 00084 00085 namespace { 00086 const int DEFAULT_MAX_DOF_QUASI_NEWTON_DENSE = 200; 00087 } // end namespace 00088 00089 namespace MoochoPack { 00090 00091 // 00092 // Here is where we define the default values for the algorithm. These 00093 // should agree with what are in the Moocho.opt.NLPAlgoConfigMamaJama file. 00094 // 00095 DecompositionSystemStateStepBuilderStd::SOptionValues::SOptionValues() 00096 :null_space_matrix_type_(NULL_SPACE_MATRIX_AUTO) 00097 ,range_space_matrix_type_(RANGE_SPACE_MATRIX_AUTO) 00098 ,max_dof_quasi_newton_dense_(-1) 00099 {} 00100 00101 DecompositionSystemStateStepBuilderStd::DecompositionSystemStateStepBuilderStd() 00102 {} 00103 00104 void DecompositionSystemStateStepBuilderStd::set_options( const options_ptr_t& options ) 00105 { 00106 options_ = options; 00107 } 00108 00109 const DecompositionSystemStateStepBuilderStd::options_ptr_t& 00110 DecompositionSystemStateStepBuilderStd::get_options() const 00111 { 00112 return options_; 00113 } 00114 00115 void DecompositionSystemStateStepBuilderStd::process_nlp_and_options( 00116 std::ostream *trase_out 00117 ,NLP &nlp 00118 ,NLPFirstOrder **nlp_foi 00119 ,NLPSecondOrder **nlp_soi 00120 ,NLPDirect **nlp_fod 00121 ,bool *tailored_approach 00122 ) 00123 { 00124 00125 // 00126 // Probe the NLP interfaces 00127 // 00128 00129 // Get the dimensions of the NLP 00130 const size_type 00131 n = nlp.n(), 00132 m = nlp.m(), 00133 r = m, // ToDo: Compute this for real! 00134 dof = n - r; 00135 00136 if(trase_out) 00137 *trase_out << "\n*** Probing the NLP object for supported interfaces ...\n"; 00138 00139 // Determine which NLP interface is supported 00140 *nlp_foi = dynamic_cast<NLPFirstOrder*>(&nlp); 00141 *nlp_soi = dynamic_cast<NLPSecondOrder*>(&nlp); 00142 *nlp_fod = dynamic_cast<NLPDirect*>(&nlp); 00143 *tailored_approach = false; 00144 if( *nlp_foi ) { 00145 if(trase_out) 00146 *trase_out << "\nDetected that NLP object supports the NLPFirstOrder interface!\n"; 00147 *tailored_approach = false; 00148 } 00149 else if( *nlp_fod ) { 00150 if(trase_out) 00151 *trase_out << "\nDetected that NLP object supports the NLPDirect interface!\n"; 00152 *tailored_approach = true; 00153 } 00154 else { 00155 TEST_FOR_EXCEPTION( 00156 true, std::logic_error 00157 ,"NLPAlgoConfigMamaJama::config_algo_cntr(...) : Error, " 00158 "the NLP object of type \'" << typeName(nlp) << 00159 "\' does not support the NLPFirstOrder or NLPDirect " 00160 "interfaces!" ); 00161 } 00162 if( *nlp_soi ) { 00163 if(trase_out) 00164 *trase_out << "\nDetected that NLP object also supports the NLPSecondOrder interface!\n"; 00165 } 00166 00167 // 00168 // Process the options 00169 // 00170 00171 // Readin the options 00172 if(options_.get()) { 00173 readin_options( *options_, &uov_, trase_out ); 00174 } 00175 else { 00176 if(trase_out) { 00177 *trase_out 00178 << "\n*** Warning, no OptionsFromStream object was set so a default set" 00179 " of options will be used!\n"; 00180 } 00181 } 00182 00183 // Set default 00184 if( uov_.max_dof_quasi_newton_dense_ < 0 ) 00185 cov_.max_dof_quasi_newton_dense_ = DEFAULT_MAX_DOF_QUASI_NEWTON_DENSE; 00186 else 00187 cov_.max_dof_quasi_newton_dense_ = uov_.max_dof_quasi_newton_dense_; 00188 00189 // Decide what type of range-space matrix to use 00190 if( r && uov_.range_space_matrix_type_ == RANGE_SPACE_MATRIX_AUTO ) { 00191 const bool use_orth = (dof*dof/r) <= cov_.max_dof_quasi_newton_dense_*cov_.max_dof_quasi_newton_dense_; 00192 if(trase_out) 00193 *trase_out 00194 << "\nrange_space_matrix == AUTO:" 00195 << "\n(n-r)^2/r = (" << dof << ")^2/r = " << (dof*dof/r) 00196 << ( use_orth ? " <= " : " > " ) << "max_dof_quasi_newton_dense^2 = (" 00197 << cov_.max_dof_quasi_newton_dense_ << ")^2 = " 00198 << cov_.max_dof_quasi_newton_dense_*cov_.max_dof_quasi_newton_dense_ 00199 << ( use_orth 00200 ? "\nsetting range_space_matrix = ORTHOGONAL\n" 00201 : "\nsetting range_space_matrix = COORDINATE\n" ); 00202 cov_.range_space_matrix_type_ = 00203 ( use_orth 00204 ? RANGE_SPACE_MATRIX_ORTHOGONAL 00205 : RANGE_SPACE_MATRIX_COORDINATE ); 00206 } 00207 00208 // Set the default options that where not already set yet 00209 set_default_options(uov_,&cov_,trase_out); 00210 00211 } 00212 00213 void DecompositionSystemStateStepBuilderStd::create_decomp_sys( 00214 std::ostream *trase_out 00215 ,NLP &nlp 00216 ,NLPFirstOrder *nlp_foi 00217 ,NLPSecondOrder *nlp_soi 00218 ,NLPDirect *nlp_fod 00219 ,bool tailored_approach 00220 ,Teuchos::RCP<DecompositionSystem> *decomp_sys 00221 ) 00222 { 00223 namespace mmp = MemMngPack; 00224 using Teuchos::RCP; 00225 00226 const size_type 00227 m = nlp.m(); 00228 00229 if( m == 0 ) { 00230 *decomp_sys = Teuchos::null; 00231 return; 00232 } 00233 00234 RCP<BasisSystem> basis_sys = Teuchos::null; 00235 if(!tailored_approach) { 00236 // Set the default basis system if one is not set 00237 basis_sys = nlp_foi->basis_sys(); 00238 if( basis_sys.get() == NULL ) { 00239 TEST_FOR_EXCEPTION( 00240 true, std::logic_error 00241 ,"\nA basis system object was not specified by the NLPFirstOrder object of type \'" 00242 << typeName(nlp) << "\' and we can not build a rSQP algorithm without one!" ); 00243 00244 } 00245 // Create the testing object for the basis system and set it up. 00246 RCP<BasisSystemTester> 00247 basis_sys_tester = Teuchos::rcp(new BasisSystemTester()); 00248 if(options_.get()) { 00249 BasisSystemTesterSetOptions 00250 opt_setter(basis_sys_tester.get()); 00251 opt_setter.set_options(*options_); 00252 } 00253 // Determine what type of null space matrix to use 00254 DecompositionSystemVarReduct::EExplicitImplicit 00255 D_imp; 00256 switch( cov_.null_space_matrix_type_ ) { 00257 case NULL_SPACE_MATRIX_AUTO: 00258 D_imp = DecompositionSystemVarReduct::MAT_IMP_AUTO; 00259 break; 00260 case NULL_SPACE_MATRIX_EXPLICIT: 00261 D_imp = DecompositionSystemVarReduct::MAT_IMP_EXPLICIT; 00262 break; 00263 case NULL_SPACE_MATRIX_IMPLICIT: 00264 D_imp = DecompositionSystemVarReduct::MAT_IMP_IMPLICIT; 00265 break; 00266 default: 00267 TEST_FOR_EXCEPT(true); 00268 } 00269 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 00270 // See if the basis system object supports basis permutations 00271 basis_sys_perm_ = Teuchos::rcp_dynamic_cast<BasisSystemPerm>(basis_sys); 00272 #endif 00273 // Create the DecompositionSystem implementation object 00274 typedef RCP<DecompositionSystemVarReductImp> decomp_sys_imp_ptr_t; 00275 decomp_sys_imp_ptr_t decomp_sys_imp; 00276 switch( cov_.range_space_matrix_type_ ) { 00277 case RANGE_SPACE_MATRIX_COORDINATE: 00278 decomp_sys_imp 00279 = Teuchos::rcp(new DecompositionSystemCoordinate( 00280 nlp.space_x() 00281 ,nlp.space_c() 00282 ,basis_sys // Will have basis_sys_->var_dep().size() == 0 if permutation 00283 ,basis_sys_tester 00284 ,D_imp 00285 ) ); 00286 break; 00287 case RANGE_SPACE_MATRIX_ORTHOGONAL: { 00288 decomp_sys_imp 00289 = Teuchos::rcp(new DecompositionSystemOrthogonal( 00290 nlp.space_x() 00291 ,nlp.space_c() 00292 ,basis_sys // Will have basis_sys_->var_dep().size() == 0 if permutation 00293 ,basis_sys_tester 00294 ) ); 00295 break; 00296 } 00297 default: 00298 TEST_FOR_EXCEPT(true); // only a local error 00299 } 00300 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 00301 // Create the actual DecompositionSystem object being used 00302 if( basis_sys_perm_.get() != NULL ) { 00303 if(trase_out) 00304 *trase_out 00305 << "\nThe BasisSystem object with concreate type \'" << typeName(*basis_sys) 00306 << "\' supports the BasisSystemPerm interface.\n" 00307 << "Using DecompositionSystemVarReductPermStd to support basis permutations ...\n"; 00308 *decomp_sys = Teuchos::rcp( 00309 new DecompositionSystemVarReductPermStd( 00310 decomp_sys_imp 00311 ,basis_sys_perm_ 00312 ,false // basis_selected 00313 ,D_imp 00314 ) ); 00315 } 00316 else { 00317 #endif 00318 if(trase_out) 00319 *trase_out 00320 << "\nThe BasisSystem object with concreate type \'" << typeName(*basis_sys) 00321 << "\' does not support the BasisSystemPerm interface.\n" 00322 << "Using " << typeName(*decomp_sys_imp) << " with a fixed basis ...\n"; 00323 decomp_sys_imp->initialize( 00324 nlp.space_x() 00325 ,nlp.space_c() 00326 ,basis_sys // Must already be ready to go with a basis selection! 00327 ); 00328 *decomp_sys = decomp_sys_imp; 00329 } 00330 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 00331 } 00332 #endif 00333 } 00334 00335 void DecompositionSystemStateStepBuilderStd::add_iter_quantities( 00336 std::ostream *trase_out 00337 ,NLP &nlp 00338 ,NLPFirstOrder *nlp_foi 00339 ,NLPSecondOrder *nlp_soi 00340 ,NLPDirect *nlp_fod 00341 ,bool tailored_approach 00342 ,const Teuchos::RCP<DecompositionSystem> &decomp_sys 00343 ,const Teuchos::RCP<NLPAlgoState> &state 00344 ) 00345 { 00346 namespace mmp = MemMngPack; 00347 using Teuchos::dyn_cast; 00348 00349 const size_type 00350 n = nlp.n(), 00351 m = nlp.m(); 00352 00353 if( tailored_approach ) { 00354 // NLPDirect 00355 TEST_FOR_EXCEPT( !( nlp_fod->con_undecomp().size() == 0 ) ); 00356 // ToDo: Add the necessary iteration quantities when con_undecomp().size() > 0 is supported! 00357 } 00358 else { 00359 // NLPFirstOrder 00360 if(m) 00361 state->set_iter_quant( 00362 Gc_name 00363 ,Teuchos::rcp( 00364 new IterQuantityAccessContiguous<MatrixOp>( 00365 1 00366 ,Gc_name 00367 ,nlp_foi->factory_Gc() 00368 ) 00369 ) 00370 ); 00371 if(nlp_soi) 00372 state->set_iter_quant( 00373 HL_name 00374 ,Teuchos::rcp( 00375 new IterQuantityAccessContiguous<MatrixSymOp>( 00376 1 00377 ,HL_name 00378 ,nlp_soi->factory_HL() 00379 ) 00380 ) 00381 ); 00382 } 00383 00384 // 00385 // Set the algorithm specific matrix objects 00386 // 00387 00388 // Add range/null decomposition matrices 00389 00390 if( m ) { 00391 if(tailored_approach) { 00392 // Z 00393 state->set_iter_quant( 00394 Z_name 00395 ,Teuchos::rcp( 00396 new IterQuantityAccessContiguous<MatrixOp>( 00397 1 00398 ,Z_name 00399 ,Teuchos::rcp(new Teuchos::AbstractFactoryStd<MatrixOp,MatrixIdentConcatStd>) 00400 ) 00401 ) 00402 ); 00403 // Y 00404 state->set_iter_quant( 00405 Y_name 00406 ,Teuchos::rcp( 00407 new IterQuantityAccessContiguous<MatrixOp>( 00408 1 00409 ,Y_name 00410 ,Teuchos::rcp(new Teuchos::AbstractFactoryStd<MatrixOp,MatrixIdentConcatStd>) 00411 ) 00412 ) 00413 ); 00414 // ToDo: Add matrix iq object for Uz 00415 // ToDo: Add matrix iq object for Uy 00416 } 00417 else { 00418 if( n > m ) { 00419 // Z 00420 state->set_iter_quant( 00421 Z_name 00422 ,Teuchos::rcp( 00423 new IterQuantityAccessContiguous<MatrixOp>( 00424 1 00425 ,Z_name 00426 ,decomp_sys->factory_Z() 00427 ) 00428 ) 00429 ); 00430 // Y 00431 state->set_iter_quant( 00432 Y_name 00433 ,Teuchos::rcp( 00434 new IterQuantityAccessContiguous<MatrixOp>( 00435 1 00436 ,Y_name 00437 ,decomp_sys->factory_Y() 00438 ) 00439 ) 00440 ); 00441 // R 00442 state->set_iter_quant( 00443 R_name 00444 ,Teuchos::rcp( 00445 new IterQuantityAccessContiguous<MatrixOpNonsing>( 00446 1 00447 ,R_name 00448 ,decomp_sys->factory_R() 00449 ) 00450 ) 00451 ); 00452 // Uz 00453 state->set_iter_quant( 00454 Uz_name 00455 ,Teuchos::rcp( 00456 new IterQuantityAccessContiguous<MatrixOp>( 00457 1 00458 ,Uz_name 00459 ,decomp_sys->factory_Uz() 00460 ) 00461 ) 00462 ); 00463 // Uy 00464 state->set_iter_quant( 00465 Uy_name 00466 ,Teuchos::rcp( 00467 new IterQuantityAccessContiguous<MatrixOp>( 00468 1 00469 ,Uy_name 00470 ,decomp_sys->factory_Uy() 00471 ) 00472 ) 00473 ); 00474 } 00475 else { 00476 // Y 00477 state->set_iter_quant( 00478 Y_name 00479 ,Teuchos::rcp( 00480 new IterQuantityAccessContiguous<MatrixOp>( 00481 1 00482 ,Y_name 00483 ,Teuchos::rcp(new Teuchos::AbstractFactoryStd<MatrixOp,MatrixSymIdent>()) 00484 ) 00485 ) 00486 ); 00487 // R 00488 state->set_iter_quant( 00489 R_name 00490 ,Teuchos::rcp( 00491 new IterQuantityAccessContiguous<MatrixOpNonsing>( 00492 1 00493 ,R_name 00494 ,dyn_cast<NLPFirstOrder>(nlp).basis_sys()->factory_C() 00495 ) 00496 ) 00497 ); 00498 } 00499 } 00500 } 00501 else { 00502 // Z 00503 state->set_iter_quant( 00504 Z_name 00505 ,Teuchos::rcp( 00506 new IterQuantityAccessContiguous<MatrixOp>( 00507 1 00508 ,Z_name 00509 ,Teuchos::rcp(new Teuchos::AbstractFactoryStd<MatrixOp,MatrixSymIdent>()) 00510 ) 00511 ) 00512 ); 00513 } 00514 00515 } 00516 00517 void DecompositionSystemStateStepBuilderStd::create_eval_new_point( 00518 std::ostream *trase_out 00519 ,NLP &nlp 00520 ,NLPFirstOrder *nlp_foi 00521 ,NLPSecondOrder *nlp_soi 00522 ,NLPDirect *nlp_fod 00523 ,bool tailored_approach 00524 ,const Teuchos::RCP<DecompositionSystem> &decomp_sys 00525 ,Teuchos::RCP<IterationPack::AlgorithmStep> *eval_new_point_step 00526 ,Teuchos::RCP<CalcFiniteDiffProd> *calc_fd_prod 00527 ,Teuchos::RCP<VariableBoundsTester> *bounds_tester 00528 ,Teuchos::RCP<NewDecompositionSelection_Strategy> *new_decomp_selection_strategy 00529 ) 00530 { 00531 namespace mmp = MemMngPack; 00532 using Teuchos::RCP; 00533 00534 const size_type 00535 m = nlp.m(), 00536 nb = nlp.num_bounded_x(); 00537 00538 typedef RCP<DecompositionSystemHandler_Strategy> decomp_sys_handler_ptr_t; 00539 decomp_sys_handler_ptr_t decomp_sys_handler = Teuchos::null; 00540 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 00541 typedef RCP<DecompositionSystemHandlerSelectNew_Strategy> decomp_sys_handler_select_new_ptr_t; 00542 decomp_sys_handler_select_new_ptr_t decomp_sys_handler_select_new = Teuchos::null; 00543 #endif 00544 00545 // Create the variable bounds testing object. 00546 if(nb) { // has variable bounds? 00547 const value_type var_bounds_warning_tol = 1e-10; 00548 const value_type var_bounds_error_tol = 1e-5; 00549 *bounds_tester = Teuchos::rcp( 00550 new VariableBoundsTester( 00551 var_bounds_warning_tol // default warning tolerance 00552 ,var_bounds_error_tol // default error tolerance 00553 ) ); 00554 if(options_.get()) { 00555 ConstrainedOptPack::VariableBoundsTesterSetOptions 00556 options_setter( bounds_tester->get() ); 00557 options_setter.set_options(*options_); 00558 } 00559 } 00560 00561 // Create the finite difference class 00562 *calc_fd_prod = Teuchos::rcp(new CalcFiniteDiffProd()); 00563 if(options_.get()) { 00564 ConstrainedOptPack::CalcFiniteDiffProdSetOptions 00565 options_setter( calc_fd_prod->get() ); 00566 options_setter.set_options(*options_); 00567 } 00568 00569 if( m ) { 00570 00571 // Decomposition system handler 00572 if( nlp_foi ) { 00573 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 00574 if( basis_sys_perm_.get() ) 00575 decomp_sys_handler = decomp_sys_handler_select_new 00576 = Teuchos::rcp( new DecompositionSystemHandlerVarReductPerm_Strategy ); 00577 else 00578 #endif 00579 decomp_sys_handler = Teuchos::rcp( new DecompositionSystemHandlerStd_Strategy ); 00580 } 00581 00582 #ifndef MOOCHO_NO_BASIS_PERM_DIRECT_SOLVERS 00583 // NewDecompositionSelectionStd_Strategy 00584 if( decomp_sys_handler_select_new.get() ) { 00585 *new_decomp_selection_strategy = Teuchos::rcp( 00586 new NewDecompositionSelectionStd_Strategy(decomp_sys_handler_select_new) 00587 ); 00588 } 00589 #else 00590 *new_decomp_selection_strategy = Teuchos::null; 00591 #endif 00592 00593 } 00594 else { 00595 decomp_sys_handler = Teuchos::null; 00596 *new_decomp_selection_strategy = Teuchos::null; 00597 } 00598 00599 // 00600 // EvalNewPoint_Step 00601 // 00602 00603 // Create the step object 00604 if( tailored_approach ) { 00605 // create and setup the derivative tester 00606 typedef Teuchos::RCP<NLPDirectTester> deriv_tester_ptr_t; 00607 deriv_tester_ptr_t 00608 deriv_tester = Teuchos::rcp( 00609 new NLPDirectTester( 00610 *calc_fd_prod 00611 ,NLPDirectTester::FD_DIRECTIONAL // Gf testing 00612 ,NLPDirectTester::FD_DIRECTIONAL // -Inv(C)*N testing 00613 ) ); 00614 if(options_.get()) { 00615 NLPInterfacePack::NLPDirectTesterSetOptions 00616 options_setter(deriv_tester.get()); 00617 options_setter.set_options(*options_); 00618 } 00619 // create the step 00620 typedef Teuchos::RCP<EvalNewPointTailoredApproach_Step> _eval_new_point_step_ptr_t; 00621 _eval_new_point_step_ptr_t 00622 _eval_new_point_step = Teuchos::null; 00623 switch( cov_.range_space_matrix_type_ ) { 00624 case RANGE_SPACE_MATRIX_COORDINATE: 00625 _eval_new_point_step 00626 = Teuchos::rcp(new EvalNewPointTailoredApproachCoordinate_Step(deriv_tester,*bounds_tester)); 00627 break; 00628 case RANGE_SPACE_MATRIX_ORTHOGONAL: 00629 _eval_new_point_step 00630 = Teuchos::rcp(new EvalNewPointTailoredApproachOrthogonal_Step(deriv_tester,*bounds_tester) ); 00631 break; 00632 default: 00633 TEST_FOR_EXCEPT(true); // only a local error 00634 } 00635 if(options_.get()) { 00636 EvalNewPointTailoredApproach_StepSetOptions 00637 options_setter(_eval_new_point_step.get()); 00638 options_setter.set_options(*options_); 00639 } 00640 *eval_new_point_step = _eval_new_point_step; 00641 } 00642 else { 00643 // create and setup the derivative tester 00644 typedef Teuchos::RCP<NLPFirstDerivTester> deriv_tester_ptr_t; 00645 deriv_tester_ptr_t 00646 deriv_tester = Teuchos::rcp( 00647 new NLPFirstDerivTester( 00648 *calc_fd_prod 00649 ,NLPFirstDerivTester::FD_DIRECTIONAL 00650 ) ); 00651 if(options_.get()) { 00652 NLPInterfacePack::NLPFirstDerivTesterSetOptions 00653 options_setter(deriv_tester.get()); 00654 options_setter.set_options(*options_); 00655 } 00656 // create and setup the decomposition system tester 00657 typedef Teuchos::RCP<DecompositionSystemTester> decomp_sys_tester_ptr_t; 00658 decomp_sys_tester_ptr_t 00659 decomp_sys_tester = Teuchos::rcp( new DecompositionSystemTester() ); 00660 if(options_.get()) { 00661 DecompositionSystemTesterSetOptions 00662 options_setter(decomp_sys_tester.get()); 00663 options_setter.set_options(*options_); 00664 } 00665 Teuchos::RCP<EvalNewPointStd_Step> 00666 _eval_new_point_step = Teuchos::rcp( 00667 new EvalNewPointStd_Step( 00668 decomp_sys_handler 00669 ,deriv_tester 00670 ,*bounds_tester 00671 ,decomp_sys_tester 00672 ) ); 00673 if(options_.get()) { 00674 EvalNewPointStd_StepSetOptions 00675 options_setter(_eval_new_point_step.get()); 00676 options_setter.set_options(*options_); 00677 } 00678 *eval_new_point_step = _eval_new_point_step; 00679 } 00680 } 00681 00682 // static 00683 00684 void DecompositionSystemStateStepBuilderStd::readin_options( 00685 const OptionsFromStreamPack::OptionsFromStream& options 00686 ,SOptionValues *ov, std::ostream* trase_out 00687 ) 00688 { 00689 namespace ofsp = OptionsFromStreamPack; 00690 using ofsp::OptionsFromStream; 00691 typedef OptionsFromStream::options_group_t options_group_t; 00692 using ofsp::StringToIntMap; 00693 using ofsp::StringToBool; 00694 00695 TEST_FOR_EXCEPT( !( ov ) ); // only a local class error 00696 00697 const std::string opt_grp_name = "DecompositionSystemStateStepBuilderStd"; 00698 const OptionsFromStream::options_group_t optgrp = options.options_group( opt_grp_name ); 00699 if( OptionsFromStream::options_group_exists( optgrp ) ) { 00700 00701 const int num_opts = 3; 00702 enum EBuilder { 00703 NULL_SPACE_MATRIX 00704 ,RANGE_SPACE_MATRIX 00705 ,MAX_DOF_QUASI_NEWTON_DENSE 00706 }; 00707 const char* SBuilder[num_opts] = { 00708 "null_space_matrix" 00709 ,"range_space_matrix" 00710 ,"max_dof_quasi_newton_dense" 00711 }; 00712 StringToIntMap map( opt_grp_name, num_opts, SBuilder ); 00713 00714 options_group_t::const_iterator itr = optgrp.begin(); 00715 for( ; itr != optgrp.end(); ++itr ) { 00716 switch( (EBuilder)map( ofsp::option_name(itr) ) ) { 00717 case NULL_SPACE_MATRIX: 00718 { 00719 const std::string &opt_val = ofsp::option_value(itr); 00720 if( opt_val == "EXPLICIT" ) { 00721 ov->null_space_matrix_type_ = NULL_SPACE_MATRIX_EXPLICIT; 00722 } else if( opt_val == "IMPLICIT" ) { 00723 ov->null_space_matrix_type_ = NULL_SPACE_MATRIX_IMPLICIT; 00724 } else if( opt_val == "AUTO" ) { 00725 ov->null_space_matrix_type_ = NULL_SPACE_MATRIX_AUTO; 00726 } else { 00727 TEST_FOR_EXCEPTION( 00728 true, std::invalid_argument 00729 ,"NLPAlgoConfigMamaJama::readin_options(...) : " 00730 "Error, incorrect value for \"null_space_matrix\" " 00731 ", Only the options for Z of EXPLICIT, IMPLICIT" 00732 ", and AUTO are avalible." ); 00733 } 00734 break; 00735 } 00736 case RANGE_SPACE_MATRIX: 00737 { 00738 const std::string &opt_val = ofsp::option_value(itr); 00739 if( opt_val == "COORDINATE" ) 00740 ov->range_space_matrix_type_ = RANGE_SPACE_MATRIX_COORDINATE; 00741 else if( opt_val == "ORTHOGONAL" ) 00742 ov->range_space_matrix_type_ = RANGE_SPACE_MATRIX_ORTHOGONAL; 00743 else if( opt_val == "AUTO" ) 00744 ov->range_space_matrix_type_ = RANGE_SPACE_MATRIX_AUTO; 00745 else 00746 TEST_FOR_EXCEPTION( 00747 true, std::invalid_argument 00748 ,"NLPAlgoConfigMamaJama::readin_options(...) : " 00749 "Error, incorrect value for \"range_space_matrix\" " 00750 ", Only the options for Z of COORDINATE," 00751 ", ORTHOGONAL and AUTO are avalible." ); 00752 break; 00753 } 00754 case MAX_DOF_QUASI_NEWTON_DENSE: 00755 ov->max_dof_quasi_newton_dense_ = std::atoi( ofsp::option_value(itr).c_str() ); 00756 break; 00757 default: 00758 TEST_FOR_EXCEPT(true); // this would be a local programming error only. 00759 } 00760 } 00761 } 00762 else { 00763 if(trase_out) 00764 *trase_out 00765 << "\n\n*** Warning! The options group \"DecompositionSystemStateStepBuilderStd\" was not found.\n" 00766 << "Using a default set of options instead ... \n"; 00767 } 00768 } 00769 00770 void DecompositionSystemStateStepBuilderStd::set_default_options( 00771 const SOptionValues& uov 00772 ,SOptionValues *cov 00773 ,std::ostream* trase_out 00774 ) 00775 { 00776 00777 TEST_FOR_EXCEPT( !( cov ) ); 00778 00779 if(trase_out) 00780 *trase_out 00781 << "\n*** Setting option defaults for options not set by the user or determined some other way ...\n"; 00782 00783 if( cov->null_space_matrix_type_ == NULL_SPACE_MATRIX_AUTO && uov.null_space_matrix_type_ == NULL_SPACE_MATRIX_AUTO ) { 00784 if(trase_out) 00785 *trase_out 00786 << "\nnull_space_matrix_type == AUTO: Let the algorithm deside as it goes along\n"; 00787 } 00788 else if(cov->null_space_matrix_type_ == NULL_SPACE_MATRIX_AUTO) { 00789 cov->null_space_matrix_type_ = uov.null_space_matrix_type_; 00790 } 00791 if( cov->range_space_matrix_type_ == RANGE_SPACE_MATRIX_AUTO && uov.range_space_matrix_type_ == RANGE_SPACE_MATRIX_AUTO ) { 00792 if(trase_out) 00793 *trase_out 00794 << "\nrange_space_matrix_type == AUTO: Let the algorithm deside as it goes along\n"; 00795 } 00796 else if(cov->range_space_matrix_type_ == RANGE_SPACE_MATRIX_AUTO) { 00797 cov->range_space_matrix_type_ = uov.range_space_matrix_type_; 00798 } 00799 if( cov->max_dof_quasi_newton_dense_ < 0 && uov.max_dof_quasi_newton_dense_ < 0 ) { 00800 if(trase_out) 00801 *trase_out 00802 << "\nmax_dof_quasi_newton_dense < 0 : setting max_dof_quasi_newton_dense = "<<DEFAULT_MAX_DOF_QUASI_NEWTON_DENSE<<"\n"; 00803 cov->max_dof_quasi_newton_dense_ = DEFAULT_MAX_DOF_QUASI_NEWTON_DENSE; 00804 } 00805 else if(cov->max_dof_quasi_newton_dense_ < 0) { 00806 cov->max_dof_quasi_newton_dense_ = uov.max_dof_quasi_newton_dense_; 00807 } 00808 if(trase_out) 00809 *trase_out 00810 << "\n*** End setting default options\n"; 00811 } 00812 00813 } // end class MoochoPack
1.7.4