MoochoPack_MoochoSolver.hpp

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 Teuchos::RCP<
00152     NLPInterfacePack::NLP>                                       nlp_ptr_t; // full path needed by doxygen
00154   typedef Teuchos::RCP<
00155     IterationPack::AlgorithmTracker>                        track_ptr_t; // full path needed by doxygen
00157   typedef Teuchos::RCP<NLPAlgoConfig>    config_ptr_t;
00159   typedef Teuchos::RCP<
00160     OptionsFromStreamPack::OptionsFromStream>                    options_ptr_t;
00162   typedef Teuchos::RCP<std::ostream>       ostream_ptr_t;
00164   enum EOutputToBlackHole {
00165     OUTPUT_TO_BLACK_HOLE_DEFAULT
00166     ,OUTPUT_TO_BLACK_HOLE_TRUE
00167     ,OUTPUT_TO_BLACK_HOLE_FALSE
00168   };
00170   enum EConfigOptions {
00171     MAMA_JAMA
00172     ,INTERIOR_POINT
00173   };
00175   enum ESolutionStatus {
00176     SOLVE_RETURN_SOLVED            =  0
00177     ,SOLVE_RETURN_NLP_TEST_FAILED  =  1
00178     ,SOLVE_RETURN_MAX_ITER         =  2
00179     ,SOLVE_RETURN_MAX_RUN_TIME     =  3
00180     ,SOLVE_RETURN_EXCEPTION        =  4
00181   };
00182 
00184 
00187 
00195   MoochoSolver(
00196     const std::string &options_file_name = "Moocho.opt"
00197     ,const std::string &extra_options_str = ""
00198     );
00199 
00201   OptionsFromStreamPack::CommandLineOptionsFromStreamProcessor&
00202   commandLineOptionsFromStreamProcessor();
00203 
00205   const OptionsFromStreamPack::CommandLineOptionsFromStreamProcessor&
00206   commandLineOptionsFromStreamProcessor() const;
00207 
00210   void setup_commandline_processor(
00211     Teuchos::CommandLineProcessor *clp
00212     );
00213 
00228   void set_nlp(const nlp_ptr_t& nlp);
00229   
00234   const nlp_ptr_t& get_nlp() const;
00235   
00242   void set_track(const track_ptr_t& track);
00243   
00248   const track_ptr_t& get_track() const;
00249 
00268   void set_config( const config_ptr_t& config );
00269 
00276   const config_ptr_t& get_config() const;
00277 
00298   void set_options( const options_ptr_t& options );
00299 
00304   const options_ptr_t& get_options() const;
00305 
00307 
00310 
00326   void set_error_handling(
00327     bool                    throw_exceptions
00328     ,const ostream_ptr_t&   error_out
00329     );
00330 
00333   bool throw_exceptions() const;
00334 
00340   const ostream_ptr_t& error_out() const;
00341 
00343 
00346 
00374   void set_output_context(
00375     const std::string    &file_context_postfix
00376     ,EOutputToBlackHole  output_to_black_hole  = OUTPUT_TO_BLACK_HOLE_DEFAULT
00377     ,const int           procRank              = -1           
00378     ,const int           numProcs              = -1
00379     );
00380   
00382 
00385 
00389   void set_output_file_tag(const std::string&);
00390 
00393   void do_console_outputting(bool);
00394 
00397   bool do_console_outputting() const;
00398 
00421   void set_console_out( const ostream_ptr_t& console_out );
00422 
00434   const ostream_ptr_t& get_console_out() const;
00435   
00438   void do_summary_outputting(bool);
00439 
00442   bool do_summary_outputting() const;
00443 
00461   void set_summary_out( const ostream_ptr_t& summary_out );
00462   
00478   const ostream_ptr_t& get_summary_out() const;
00479 
00482   void do_journal_outputting(bool);
00483 
00486   bool do_journal_outputting() const;
00487 
00509   void set_journal_out( const ostream_ptr_t& journal_out );
00510   
00526   const ostream_ptr_t& get_journal_out() const;
00527 
00530   void do_algo_outputting(bool);
00531 
00534   bool do_algo_outputting() const;
00535 
00538   void generate_stats_file(bool);
00539 
00542   bool generate_stats_file() const;
00543 
00565   void set_algo_out( const ostream_ptr_t& algo_out );
00566   
00582   const ostream_ptr_t& get_algo_out() const;
00583 
00589   Teuchos::RCP<std::ostream>
00590   generate_output_file(const std::string &fileNameBase) const;
00591 
00593 
00596 
00604   void update_solver() const;
00605 
00606 
00666   ESolutionStatus solve_nlp() const;
00667 
00669 
00672 
00690   NLPSolverClientInterface& get_solver();
00691 
00693   const NLPSolverClientInterface& get_solver() const;
00694   
00696 
00697 private:
00698 
00699   // //////////////////////////////////////
00700   // Private types
00701 
00703   typedef Teuchos::RCP<NLPSolverClientInterface>    solver_ptr_t;
00704     
00705   // ////////////////////////////////////
00706   // Private data members
00707 
00708   mutable OptionsFromStreamPack::CommandLineOptionsFromStreamProcessor commandLineOptionsFromStreamProcessor_;
00709 #ifndef DOXYGEN_COMPILE
00710   mutable NLPAlgoContainer solver_;          // Solver object.
00711 #else
00712   mutable NLPAlgoContainer solver;
00713 #endif
00714   mutable bool              reconfig_solver_; // If true then we must reconfigure the solver!
00715   mutable value_type        workspace_MB_;
00716   mutable value_type        obj_scale_;
00717   mutable bool              test_nlp_;
00718   mutable bool              print_algo_;
00719   mutable bool              algo_timing_;
00720   mutable bool              generate_stats_file_;
00721   mutable bool              print_opt_grp_not_accessed_;
00722   mutable bool              throw_exceptions_;
00723   mutable std::string       output_file_tag_;
00724   mutable bool              do_console_outputting_;
00725   mutable bool              do_summary_outputting_;
00726   mutable bool              do_journal_outputting_;
00727   mutable bool              do_algo_outputting_;
00728   mutable int               configuration_;
00729 #ifndef DOXYGEN_COMPILE
00730   nlp_ptr_t                 nlp_;
00731   track_ptr_t               track_;
00732   config_ptr_t              config_;
00733   options_ptr_t             options_;          // set by client
00734   ostream_ptr_t             error_out_;        // set by client
00735   mutable ostream_ptr_t     algo_out_;         // set by client
00736   mutable ostream_ptr_t     console_out_;      // set by client
00737   mutable ostream_ptr_t     summary_out_;      // set by client
00738   mutable ostream_ptr_t     journal_out_;      // set by client
00739   mutable options_ptr_t     options_used_;     // actually used (can be NULL)
00740   mutable ostream_ptr_t     error_out_used_;   // actually used (can't be NULL)
00741   mutable ostream_ptr_t     console_out_used_; // actually used (can be NULL if do_console_outputting == false)
00742   mutable ostream_ptr_t     summary_out_used_; // actually used (can be NULL if do_summary_outputting == false)
00743   mutable ostream_ptr_t     journal_out_used_; // actually used (can be NULL if do_journal_outputting == false)
00744   mutable ostream_ptr_t     algo_out_used_;    // actually used (can be NULL if do_algo_outputting == false)
00745   mutable ostream_ptr_t     stats_out_used_;   // actually used
00746   EOutputToBlackHole        output_to_black_hole_;
00747   std::string               file_context_postfix_;
00748   std::string               file_proc_postfix_;
00749 #endif
00750 
00751   // ////////////////////////////////////
00752   // Private member functions
00753 
00755   void generate_output_streams() const;
00756 
00757 }; // end class MoochoSolver
00758 
00817 // /////////////////////////////////////////
00818 // Inline members
00819 
00820 inline
00821 void MoochoSolver::set_output_file_tag(const std::string& output_file_tag)
00822 {
00823   output_file_tag_ = output_file_tag;
00824 }
00825 
00826 inline
00827 void MoochoSolver::do_console_outputting(bool do_console_outputting)
00828 {
00829   do_console_outputting_ = do_console_outputting;
00830 }
00831 
00832 inline
00833 bool MoochoSolver::do_console_outputting() const
00834 {
00835   return do_console_outputting_;
00836 }
00837 
00838 inline
00839 void MoochoSolver::do_summary_outputting(bool do_summary_outputting)
00840 {
00841   do_summary_outputting_ = do_summary_outputting;
00842 }
00843 
00844 inline
00845 bool MoochoSolver::do_summary_outputting() const
00846 {
00847   return do_summary_outputting_;
00848 }
00849 
00850 inline
00851 void MoochoSolver::do_journal_outputting(bool do_journal_outputting)
00852 {
00853   do_journal_outputting_ = do_journal_outputting;
00854 }
00855 
00856 inline
00857 bool MoochoSolver::do_journal_outputting() const
00858 {
00859   return do_journal_outputting_;
00860 }
00861 
00862 inline
00863 void MoochoSolver::do_algo_outputting(bool do_algo_outputting)
00864 {
00865   do_algo_outputting_ = do_algo_outputting;
00866 }
00867 
00868 inline
00869 bool MoochoSolver::do_algo_outputting() const
00870 {
00871   return do_algo_outputting_;
00872 }
00873 
00874 inline
00875 void MoochoSolver::generate_stats_file(bool generate_stats_file)
00876 {
00877   generate_stats_file_ = generate_stats_file;
00878 }
00879 
00880 inline
00881 bool MoochoSolver::generate_stats_file() const
00882 {
00883   return generate_stats_file_;
00884 }
00885 
00886 } // end namespace MoochoPack
00887 
00888 #endif // MOOCHOPACK_MOOCHO_SOLVER_HPP

Generated on Wed May 12 21:51:20 2010 for MoochoPack : Framework for Large-Scale Optimization Algorithms by  doxygen 1.4.7