MoochoPack_MoochoSolver.hpp

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 #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::RefCountPtr<
00152     NLPInterfacePack::NLP>                                       nlp_ptr_t; // full path needed by doxygen
00154   typedef Teuchos::RefCountPtr<
00155     IterationPack::AlgorithmTracker>                        track_ptr_t; // full path needed by doxygen
00157   typedef Teuchos::RefCountPtr<NLPAlgoConfig>    config_ptr_t;
00159   typedef Teuchos::RefCountPtr<
00160     OptionsFromStreamPack::OptionsFromStream>                    options_ptr_t;
00162   typedef Teuchos::RefCountPtr<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 
00354   void set_output_context(
00355     const std::string    &file_context_postfix
00356     ,EOutputToBlackHole  output_to_black_hole  = OUTPUT_TO_BLACK_HOLE_DEFAULT
00357     ,const int           procRank              = -1           
00358     ,const int           numProcs              = -1
00359     );
00360   
00362 
00365 
00368   void do_console_outputting(bool);
00369 
00372   bool do_console_outputting() const;
00373 
00396   void set_console_out( const ostream_ptr_t& console_out );
00397 
00409   const ostream_ptr_t& get_console_out() const;
00410   
00413   void do_summary_outputting(bool);
00414 
00417   bool do_summary_outputting() const;
00418 
00436   void set_summary_out( const ostream_ptr_t& summary_out );
00437   
00453   const ostream_ptr_t& get_summary_out() const;
00454 
00457   void do_journal_outputting(bool);
00458 
00461   bool do_journal_outputting() const;
00462 
00484   void set_journal_out( const ostream_ptr_t& journal_out );
00485   
00501   const ostream_ptr_t& get_journal_out() const;
00502 
00505   void do_algo_outputting(bool);
00506 
00509   bool do_algo_outputting() const;
00510 
00513   void generate_stats_file(bool);
00514 
00517   bool generate_stats_file() const;
00518 
00540   void set_algo_out( const ostream_ptr_t& algo_out );
00541   
00557   const ostream_ptr_t& get_algo_out() const;
00558 
00560 
00563 
00623   ESolutionStatus solve_nlp() const;
00624 
00626 
00629 
00647   NLPSolverClientInterface& get_solver();
00648 
00650   const NLPSolverClientInterface& get_solver() const;
00651   
00653 
00654 private:
00655 
00656   // //////////////////////////////////////
00657   // Private types
00658 
00660   typedef Teuchos::RefCountPtr<NLPSolverClientInterface>    solver_ptr_t;
00661     
00662   // ////////////////////////////////////
00663   // Private data members
00664 
00665   mutable OptionsFromStreamPack::CommandLineOptionsFromStreamProcessor commandLineOptionsFromStreamProcessor_;
00666 #ifndef DOXYGEN_COMPILE
00667   mutable NLPAlgoContainer solver_;          // Solver object.
00668 #else
00669   mutable NLPAlgoContainer solver;
00670 #endif
00671   mutable bool              reconfig_solver_; // If true then we must reconfigure the solver!
00672   mutable value_type        workspace_MB_;
00673   mutable value_type        obj_scale_;
00674   mutable bool              test_nlp_;
00675   mutable bool              print_algo_;
00676   mutable bool              algo_timing_;
00677   mutable bool              generate_stats_file_;
00678   mutable bool              print_opt_grp_not_accessed_;
00679   mutable bool              throw_exceptions_;
00680   mutable bool              do_console_outputting_;
00681   mutable bool              do_summary_outputting_;
00682   mutable bool              do_journal_outputting_;
00683   mutable bool              do_algo_outputting_;
00684   mutable int               configuration_;
00685 #ifndef DOXYGEN_COMPILE
00686   nlp_ptr_t                 nlp_;
00687   track_ptr_t               track_;
00688   config_ptr_t              config_;
00689   options_ptr_t             options_;          // set by client
00690   ostream_ptr_t             error_out_;        // set by client
00691   ostream_ptr_t             algo_out_;         // set by client
00692   ostream_ptr_t             console_out_;      // set by client
00693   ostream_ptr_t             summary_out_;      // set by client
00694   ostream_ptr_t             journal_out_;      // set by client
00695   mutable options_ptr_t     options_used_;     // actually used (can be NULL)
00696   mutable ostream_ptr_t     error_out_used_;   // actually used (can't be NULL)
00697   mutable ostream_ptr_t     console_out_used_; // actually used (can be NULL if do_console_outputting == false)
00698   mutable ostream_ptr_t     summary_out_used_; // actually used (can be NULL if do_summary_outputting == false)
00699   mutable ostream_ptr_t     journal_out_used_; // actually used (can be NULL if do_journal_outputting == false)
00700   mutable ostream_ptr_t     algo_out_used_;    // actually used (can be NULL if do_algo_outputting == false)
00701   mutable ostream_ptr_t     stats_out_used_;   // actually used
00702   EOutputToBlackHole        output_to_black_hole_;
00703   std::string               file_context_postfix_;
00704   std::string               file_proc_postfix_;
00705 #endif
00706 
00707   // ////////////////////////////////////
00708   // Private member functions
00709 
00711   Teuchos::RefCountPtr<std::ostream> generate_output_file(const std::string &fileNameBase) const;
00712 
00714   void generate_output_streams() const;
00715 
00717   void update_solver() const;
00718 
00719 }; // end class MoochoSolver
00720 
00779 // /////////////////////////////////////////
00780 // Inline members
00781 
00782 inline
00783 void MoochoSolver::do_console_outputting(bool do_console_outputting)
00784 {
00785   do_console_outputting_ = do_console_outputting;
00786 }
00787 
00788 inline
00789 bool MoochoSolver::do_console_outputting() const
00790 {
00791   return do_console_outputting_;
00792 }
00793 
00794 inline
00795 void MoochoSolver::do_summary_outputting(bool do_summary_outputting)
00796 {
00797   do_summary_outputting_ = do_summary_outputting;
00798 }
00799 
00800 inline
00801 bool MoochoSolver::do_summary_outputting() const
00802 {
00803   return do_summary_outputting_;
00804 }
00805 
00806 inline
00807 void MoochoSolver::do_journal_outputting(bool do_journal_outputting)
00808 {
00809   do_journal_outputting_ = do_journal_outputting;
00810 }
00811 
00812 inline
00813 bool MoochoSolver::do_journal_outputting() const
00814 {
00815   return do_journal_outputting_;
00816 }
00817 
00818 inline
00819 void MoochoSolver::do_algo_outputting(bool do_algo_outputting)
00820 {
00821   do_algo_outputting_ = do_algo_outputting;
00822 }
00823 
00824 inline
00825 bool MoochoSolver::do_algo_outputting() const
00826 {
00827   return do_algo_outputting_;
00828 }
00829 
00830 inline
00831 void MoochoSolver::generate_stats_file(bool generate_stats_file)
00832 {
00833   generate_stats_file_ = generate_stats_file;
00834 }
00835 
00836 inline
00837 bool MoochoSolver::generate_stats_file() const
00838 {
00839   return generate_stats_file_;
00840 }
00841 
00842 } // end namespace MoochoPack
00843 
00844 #endif // MOOCHOPACK_MOOCHO_SOLVER_HPP

Generated on Thu Sep 18 12:35:17 2008 for MOOCHO (Single Doxygen Collection) by doxygen 1.3.9.1