|
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 // 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 #ifndef MOOCHOPACK_MOOCHO_SOLVER_HPP 00043 #define MOOCHOPACK_MOOCHO_SOLVER_HPP 00044 00045 #include "MoochoPack_Types.hpp" 00046 #include "MoochoPack_NLPAlgoContainer.hpp" 00047 #include "OptionsFromStreamPack_CommandLineOptionsFromStreamProcessor.hpp" 00048 00049 namespace MoochoPack { 00050 00157 class MoochoSolver { 00158 public: 00159 00162 00164 typedef RCP<NLPInterfacePack::NLP> nlp_ptr_t; 00166 typedef RCP<IterationPack::AlgorithmTracker> track_ptr_t; 00168 typedef RCP<NLPAlgoConfig> config_ptr_t; 00170 typedef RCP<OptionsFromStreamPack::OptionsFromStream> options_ptr_t; 00172 typedef RCP<std::ostream> ostream_ptr_t; 00173 00174 // Above: fully qualified names are needed by doxygen 00175 00176 00178 enum EOutputToBlackHole { 00179 OUTPUT_TO_BLACK_HOLE_DEFAULT 00180 ,OUTPUT_TO_BLACK_HOLE_TRUE 00181 ,OUTPUT_TO_BLACK_HOLE_FALSE 00182 }; 00184 enum EConfigOptions { 00185 MAMA_JAMA 00186 ,INTERIOR_POINT 00187 }; 00189 enum ESolutionStatus { 00190 SOLVE_RETURN_SOLVED = 0 00191 ,SOLVE_RETURN_NLP_TEST_FAILED = 1 00192 ,SOLVE_RETURN_MAX_ITER = 2 00193 ,SOLVE_RETURN_MAX_RUN_TIME = 3 00194 ,SOLVE_RETURN_EXCEPTION = 4 00195 }; 00196 00198 00201 00209 MoochoSolver( 00210 const std::string &options_file_name = "Moocho.opt" 00211 ,const std::string &extra_options_str = "" 00212 ); 00213 00215 OptionsFromStreamPack::CommandLineOptionsFromStreamProcessor& 00216 commandLineOptionsFromStreamProcessor(); 00217 00219 const OptionsFromStreamPack::CommandLineOptionsFromStreamProcessor& 00220 commandLineOptionsFromStreamProcessor() const; 00221 00224 void setup_commandline_processor( 00225 Teuchos::CommandLineProcessor *clp 00226 ); 00227 00242 void set_nlp(const nlp_ptr_t& nlp); 00243 00248 const nlp_ptr_t& get_nlp() const; 00249 00256 void set_track(const track_ptr_t& track); 00257 00262 const track_ptr_t& get_track() const; 00263 00282 void set_config( const config_ptr_t& config ); 00283 00290 const config_ptr_t& get_config() const; 00291 00312 void set_options( const options_ptr_t& options ); 00313 00318 const options_ptr_t& get_options() const; 00319 00321 00324 00340 void set_error_handling( 00341 bool throw_exceptions 00342 ,const ostream_ptr_t& error_out 00343 ); 00344 00347 bool throw_exceptions() const; 00348 00354 const ostream_ptr_t& error_out() const; 00355 00357 00360 00388 void set_output_context( 00389 const std::string &file_context_postfix 00390 ,EOutputToBlackHole output_to_black_hole = OUTPUT_TO_BLACK_HOLE_DEFAULT 00391 ,const int procRank = -1 00392 ,const int numProcs = -1 00393 ); 00394 00396 00399 00403 void set_output_file_tag(const std::string&); 00404 00407 void do_console_outputting(bool); 00408 00411 bool do_console_outputting() const; 00412 00435 void set_console_out( const ostream_ptr_t& console_out ); 00436 00448 const ostream_ptr_t& get_console_out() const; 00449 00452 void do_summary_outputting(bool); 00453 00456 bool do_summary_outputting() const; 00457 00475 void set_summary_out( const ostream_ptr_t& summary_out ); 00476 00492 const ostream_ptr_t& get_summary_out() const; 00493 00496 void do_journal_outputting(bool); 00497 00500 bool do_journal_outputting() const; 00501 00523 void set_journal_out( const ostream_ptr_t& journal_out ); 00524 00540 const ostream_ptr_t& get_journal_out() const; 00541 00544 void do_algo_outputting(bool); 00545 00548 bool do_algo_outputting() const; 00549 00552 void generate_stats_file(bool); 00553 00556 bool generate_stats_file() const; 00557 00579 void set_algo_out( const ostream_ptr_t& algo_out ); 00580 00596 const ostream_ptr_t& get_algo_out() const; 00597 00603 RCP<std::ostream> 00604 generate_output_file(const std::string &fileNameBase) const; 00605 00607 00610 00618 void update_solver() const; 00619 00620 00680 ESolutionStatus solve_nlp() const; 00681 00683 00686 00704 NLPSolverClientInterface& get_solver(); 00705 00707 const NLPSolverClientInterface& get_solver() const; 00708 00710 00711 private: 00712 00713 // ////////////////////////////////////// 00714 // Private types 00715 00717 typedef RCP<NLPSolverClientInterface> solver_ptr_t; 00718 00719 // //////////////////////////////////// 00720 // Private data members 00721 00722 mutable OptionsFromStreamPack::CommandLineOptionsFromStreamProcessor commandLineOptionsFromStreamProcessor_; 00723 #ifndef DOXYGEN_COMPILE 00724 mutable NLPAlgoContainer solver_; // Solver object. 00725 #else 00726 mutable NLPAlgoContainer solver; 00727 #endif 00728 mutable bool reconfig_solver_; // If true then we must reconfigure the solver! 00729 mutable value_type workspace_MB_; 00730 mutable value_type obj_scale_; 00731 mutable bool test_nlp_; 00732 mutable bool print_algo_; 00733 mutable bool algo_timing_; 00734 mutable bool generate_stats_file_; 00735 mutable bool print_opt_grp_not_accessed_; 00736 mutable bool throw_exceptions_; 00737 mutable std::string output_file_tag_; 00738 mutable bool do_console_outputting_; 00739 mutable bool do_summary_outputting_; 00740 mutable bool do_journal_outputting_; 00741 mutable bool do_algo_outputting_; 00742 mutable int configuration_; 00743 #ifndef DOXYGEN_COMPILE 00744 nlp_ptr_t nlp_; 00745 track_ptr_t track_; 00746 config_ptr_t config_; 00747 options_ptr_t options_; // set by client 00748 ostream_ptr_t error_out_; // set by client 00749 mutable ostream_ptr_t algo_out_; // set by client 00750 mutable ostream_ptr_t console_out_; // set by client 00751 mutable ostream_ptr_t summary_out_; // set by client 00752 mutable ostream_ptr_t journal_out_; // set by client 00753 mutable options_ptr_t options_used_; // actually used (can be NULL) 00754 mutable ostream_ptr_t error_out_used_; // actually used (can't be NULL) 00755 mutable ostream_ptr_t console_out_used_; // actually used (can be NULL if do_console_outputting == false) 00756 mutable ostream_ptr_t summary_out_used_; // actually used (can be NULL if do_summary_outputting == false) 00757 mutable ostream_ptr_t journal_out_used_; // actually used (can be NULL if do_journal_outputting == false) 00758 mutable ostream_ptr_t algo_out_used_; // actually used (can be NULL if do_algo_outputting == false) 00759 mutable ostream_ptr_t stats_out_used_; // actually used 00760 EOutputToBlackHole output_to_black_hole_; 00761 std::string file_context_postfix_; 00762 std::string file_proc_postfix_; 00763 #endif 00764 00765 // //////////////////////////////////// 00766 // Private member functions 00767 00769 void generate_output_streams() const; 00770 00771 }; // end class MoochoSolver 00772 00831 // ///////////////////////////////////////// 00832 // Inline members 00833 00834 inline 00835 void MoochoSolver::set_output_file_tag(const std::string& output_file_tag) 00836 { 00837 output_file_tag_ = output_file_tag; 00838 } 00839 00840 inline 00841 void MoochoSolver::do_console_outputting(bool do_console_outputting) 00842 { 00843 do_console_outputting_ = do_console_outputting; 00844 } 00845 00846 inline 00847 bool MoochoSolver::do_console_outputting() const 00848 { 00849 return do_console_outputting_; 00850 } 00851 00852 inline 00853 void MoochoSolver::do_summary_outputting(bool do_summary_outputting) 00854 { 00855 do_summary_outputting_ = do_summary_outputting; 00856 } 00857 00858 inline 00859 bool MoochoSolver::do_summary_outputting() const 00860 { 00861 return do_summary_outputting_; 00862 } 00863 00864 inline 00865 void MoochoSolver::do_journal_outputting(bool do_journal_outputting) 00866 { 00867 do_journal_outputting_ = do_journal_outputting; 00868 } 00869 00870 inline 00871 bool MoochoSolver::do_journal_outputting() const 00872 { 00873 return do_journal_outputting_; 00874 } 00875 00876 inline 00877 void MoochoSolver::do_algo_outputting(bool do_algo_outputting) 00878 { 00879 do_algo_outputting_ = do_algo_outputting; 00880 } 00881 00882 inline 00883 bool MoochoSolver::do_algo_outputting() const 00884 { 00885 return do_algo_outputting_; 00886 } 00887 00888 inline 00889 void MoochoSolver::generate_stats_file(bool generate_stats_file) 00890 { 00891 generate_stats_file_ = generate_stats_file; 00892 } 00893 00894 inline 00895 bool MoochoSolver::generate_stats_file() const 00896 { 00897 return generate_stats_file_; 00898 } 00899 00900 } // end namespace MoochoPack 00901 00902 #endif // MOOCHOPACK_MOOCHO_SOLVER_HPP
1.7.6.1