|
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 #ifndef MOOCHOPACK_MOOCHO_SOLVER_HPP 00030 #define MOOCHOPACK_MOOCHO_SOLVER_HPP 00031 00032 #include "MoochoPack_Types.hpp" 00033 #include "MoochoPack_NLPAlgoContainer.hpp" 00034 #include "OptionsFromStreamPack_CommandLineOptionsFromStreamProcessor.hpp" 00035 00036 namespace MoochoPack { 00037 00144 class MoochoSolver { 00145 public: 00146 00149 00151 typedef RCP<NLPInterfacePack::NLP> nlp_ptr_t; 00153 typedef RCP<IterationPack::AlgorithmTracker> track_ptr_t; 00155 typedef RCP<NLPAlgoConfig> config_ptr_t; 00157 typedef RCP<OptionsFromStreamPack::OptionsFromStream> options_ptr_t; 00159 typedef RCP<std::ostream> ostream_ptr_t; 00160 00161 // Above: fully qualified names are needed by doxygen 00162 00163 00165 enum EOutputToBlackHole { 00166 OUTPUT_TO_BLACK_HOLE_DEFAULT 00167 ,OUTPUT_TO_BLACK_HOLE_TRUE 00168 ,OUTPUT_TO_BLACK_HOLE_FALSE 00169 }; 00171 enum EConfigOptions { 00172 MAMA_JAMA 00173 ,INTERIOR_POINT 00174 }; 00176 enum ESolutionStatus { 00177 SOLVE_RETURN_SOLVED = 0 00178 ,SOLVE_RETURN_NLP_TEST_FAILED = 1 00179 ,SOLVE_RETURN_MAX_ITER = 2 00180 ,SOLVE_RETURN_MAX_RUN_TIME = 3 00181 ,SOLVE_RETURN_EXCEPTION = 4 00182 }; 00183 00185 00188 00196 MoochoSolver( 00197 const std::string &options_file_name = "Moocho.opt" 00198 ,const std::string &extra_options_str = "" 00199 ); 00200 00202 OptionsFromStreamPack::CommandLineOptionsFromStreamProcessor& 00203 commandLineOptionsFromStreamProcessor(); 00204 00206 const OptionsFromStreamPack::CommandLineOptionsFromStreamProcessor& 00207 commandLineOptionsFromStreamProcessor() const; 00208 00211 void setup_commandline_processor( 00212 Teuchos::CommandLineProcessor *clp 00213 ); 00214 00229 void set_nlp(const nlp_ptr_t& nlp); 00230 00235 const nlp_ptr_t& get_nlp() const; 00236 00243 void set_track(const track_ptr_t& track); 00244 00249 const track_ptr_t& get_track() const; 00250 00269 void set_config( const config_ptr_t& config ); 00270 00277 const config_ptr_t& get_config() const; 00278 00299 void set_options( const options_ptr_t& options ); 00300 00305 const options_ptr_t& get_options() const; 00306 00308 00311 00327 void set_error_handling( 00328 bool throw_exceptions 00329 ,const ostream_ptr_t& error_out 00330 ); 00331 00334 bool throw_exceptions() const; 00335 00341 const ostream_ptr_t& error_out() const; 00342 00344 00347 00375 void set_output_context( 00376 const std::string &file_context_postfix 00377 ,EOutputToBlackHole output_to_black_hole = OUTPUT_TO_BLACK_HOLE_DEFAULT 00378 ,const int procRank = -1 00379 ,const int numProcs = -1 00380 ); 00381 00383 00386 00390 void set_output_file_tag(const std::string&); 00391 00394 void do_console_outputting(bool); 00395 00398 bool do_console_outputting() const; 00399 00422 void set_console_out( const ostream_ptr_t& console_out ); 00423 00435 const ostream_ptr_t& get_console_out() const; 00436 00439 void do_summary_outputting(bool); 00440 00443 bool do_summary_outputting() const; 00444 00462 void set_summary_out( const ostream_ptr_t& summary_out ); 00463 00479 const ostream_ptr_t& get_summary_out() const; 00480 00483 void do_journal_outputting(bool); 00484 00487 bool do_journal_outputting() const; 00488 00510 void set_journal_out( const ostream_ptr_t& journal_out ); 00511 00527 const ostream_ptr_t& get_journal_out() const; 00528 00531 void do_algo_outputting(bool); 00532 00535 bool do_algo_outputting() const; 00536 00539 void generate_stats_file(bool); 00540 00543 bool generate_stats_file() const; 00544 00566 void set_algo_out( const ostream_ptr_t& algo_out ); 00567 00583 const ostream_ptr_t& get_algo_out() const; 00584 00590 RCP<std::ostream> 00591 generate_output_file(const std::string &fileNameBase) const; 00592 00594 00597 00605 void update_solver() const; 00606 00607 00667 ESolutionStatus solve_nlp() const; 00668 00670 00673 00691 NLPSolverClientInterface& get_solver(); 00692 00694 const NLPSolverClientInterface& get_solver() const; 00695 00697 00698 private: 00699 00700 // ////////////////////////////////////// 00701 // Private types 00702 00704 typedef RCP<NLPSolverClientInterface> solver_ptr_t; 00705 00706 // //////////////////////////////////// 00707 // Private data members 00708 00709 mutable OptionsFromStreamPack::CommandLineOptionsFromStreamProcessor commandLineOptionsFromStreamProcessor_; 00710 #ifndef DOXYGEN_COMPILE 00711 mutable NLPAlgoContainer solver_; // Solver object. 00712 #else 00713 mutable NLPAlgoContainer solver; 00714 #endif 00715 mutable bool reconfig_solver_; // If true then we must reconfigure the solver! 00716 mutable value_type workspace_MB_; 00717 mutable value_type obj_scale_; 00718 mutable bool test_nlp_; 00719 mutable bool print_algo_; 00720 mutable bool algo_timing_; 00721 mutable bool generate_stats_file_; 00722 mutable bool print_opt_grp_not_accessed_; 00723 mutable bool throw_exceptions_; 00724 mutable std::string output_file_tag_; 00725 mutable bool do_console_outputting_; 00726 mutable bool do_summary_outputting_; 00727 mutable bool do_journal_outputting_; 00728 mutable bool do_algo_outputting_; 00729 mutable int configuration_; 00730 #ifndef DOXYGEN_COMPILE 00731 nlp_ptr_t nlp_; 00732 track_ptr_t track_; 00733 config_ptr_t config_; 00734 options_ptr_t options_; // set by client 00735 ostream_ptr_t error_out_; // set by client 00736 mutable ostream_ptr_t algo_out_; // set by client 00737 mutable ostream_ptr_t console_out_; // set by client 00738 mutable ostream_ptr_t summary_out_; // set by client 00739 mutable ostream_ptr_t journal_out_; // set by client 00740 mutable options_ptr_t options_used_; // actually used (can be NULL) 00741 mutable ostream_ptr_t error_out_used_; // actually used (can't be NULL) 00742 mutable ostream_ptr_t console_out_used_; // actually used (can be NULL if do_console_outputting == false) 00743 mutable ostream_ptr_t summary_out_used_; // actually used (can be NULL if do_summary_outputting == false) 00744 mutable ostream_ptr_t journal_out_used_; // actually used (can be NULL if do_journal_outputting == false) 00745 mutable ostream_ptr_t algo_out_used_; // actually used (can be NULL if do_algo_outputting == false) 00746 mutable ostream_ptr_t stats_out_used_; // actually used 00747 EOutputToBlackHole output_to_black_hole_; 00748 std::string file_context_postfix_; 00749 std::string file_proc_postfix_; 00750 #endif 00751 00752 // //////////////////////////////////// 00753 // Private member functions 00754 00756 void generate_output_streams() const; 00757 00758 }; // end class MoochoSolver 00759 00818 // ///////////////////////////////////////// 00819 // Inline members 00820 00821 inline 00822 void MoochoSolver::set_output_file_tag(const std::string& output_file_tag) 00823 { 00824 output_file_tag_ = output_file_tag; 00825 } 00826 00827 inline 00828 void MoochoSolver::do_console_outputting(bool do_console_outputting) 00829 { 00830 do_console_outputting_ = do_console_outputting; 00831 } 00832 00833 inline 00834 bool MoochoSolver::do_console_outputting() const 00835 { 00836 return do_console_outputting_; 00837 } 00838 00839 inline 00840 void MoochoSolver::do_summary_outputting(bool do_summary_outputting) 00841 { 00842 do_summary_outputting_ = do_summary_outputting; 00843 } 00844 00845 inline 00846 bool MoochoSolver::do_summary_outputting() const 00847 { 00848 return do_summary_outputting_; 00849 } 00850 00851 inline 00852 void MoochoSolver::do_journal_outputting(bool do_journal_outputting) 00853 { 00854 do_journal_outputting_ = do_journal_outputting; 00855 } 00856 00857 inline 00858 bool MoochoSolver::do_journal_outputting() const 00859 { 00860 return do_journal_outputting_; 00861 } 00862 00863 inline 00864 void MoochoSolver::do_algo_outputting(bool do_algo_outputting) 00865 { 00866 do_algo_outputting_ = do_algo_outputting; 00867 } 00868 00869 inline 00870 bool MoochoSolver::do_algo_outputting() const 00871 { 00872 return do_algo_outputting_; 00873 } 00874 00875 inline 00876 void MoochoSolver::generate_stats_file(bool generate_stats_file) 00877 { 00878 generate_stats_file_ = generate_stats_file; 00879 } 00880 00881 inline 00882 bool MoochoSolver::generate_stats_file() const 00883 { 00884 return generate_stats_file_; 00885 } 00886 00887 } // end namespace MoochoPack 00888 00889 #endif // MOOCHOPACK_MOOCHO_SOLVER_HPP
1.7.4