MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MoochoPack_MoochoSolver.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef MOOCHOPACK_MOOCHO_SOLVER_HPP
43 #define MOOCHOPACK_MOOCHO_SOLVER_HPP
44 
45 #include "MoochoPack_Types.hpp"
48 
49 namespace MoochoPack {
50 
158 public:
159 
162 
173 
174  // Above: fully qualified names are needed by doxygen
175 
176 
182  };
187  };
195  };
196 
198 
201 
209  MoochoSolver(
210  const std::string &options_file_name = "Moocho.opt"
211  ,const std::string &extra_options_str = ""
212  );
213 
217 
221 
226  );
227 
242  void set_nlp(const nlp_ptr_t& nlp);
243 
248  const nlp_ptr_t& get_nlp() const;
249 
256  void set_track(const track_ptr_t& track);
257 
262  const track_ptr_t& get_track() const;
263 
282  void set_config( const config_ptr_t& config );
283 
290  const config_ptr_t& get_config() const;
291 
312  void set_options( const options_ptr_t& options );
313 
318  const options_ptr_t& get_options() const;
319 
321 
324 
340  void set_error_handling(
341  bool throw_exceptions
342  ,const ostream_ptr_t& error_out
343  );
344 
347  bool throw_exceptions() const;
348 
354  const ostream_ptr_t& error_out() const;
355 
357 
360 
388  void set_output_context(
389  const std::string &file_context_postfix
390  ,EOutputToBlackHole output_to_black_hole = OUTPUT_TO_BLACK_HOLE_DEFAULT
391  ,const int procRank = -1
392  ,const int numProcs = -1
393  );
394 
396 
399 
403  void set_output_file_tag(const std::string&);
404 
407  void do_console_outputting(bool);
408 
411  bool do_console_outputting() const;
412 
435  void set_console_out( const ostream_ptr_t& console_out );
436 
448  const ostream_ptr_t& get_console_out() const;
449 
452  void do_summary_outputting(bool);
453 
456  bool do_summary_outputting() const;
457 
475  void set_summary_out( const ostream_ptr_t& summary_out );
476 
492  const ostream_ptr_t& get_summary_out() const;
493 
496  void do_journal_outputting(bool);
497 
500  bool do_journal_outputting() const;
501 
523  void set_journal_out( const ostream_ptr_t& journal_out );
524 
540  const ostream_ptr_t& get_journal_out() const;
541 
544  void do_algo_outputting(bool);
545 
548  bool do_algo_outputting() const;
549 
552  void generate_stats_file(bool);
553 
556  bool generate_stats_file() const;
557 
579  void set_algo_out( const ostream_ptr_t& algo_out );
580 
596  const ostream_ptr_t& get_algo_out() const;
597 
604  generate_output_file(const std::string &fileNameBase) const;
605 
607 
610 
618  void update_solver() const;
619 
620 
680  ESolutionStatus solve_nlp() const;
681 
683 
686 
705 
707  const NLPSolverClientInterface& get_solver() const;
708 
710 
711 private:
712 
713  // //////////////////////////////////////
714  // Private types
715 
718 
719  // ////////////////////////////////////
720  // Private data members
721 
723 #ifndef DOXYGEN_COMPILE
724  mutable NLPAlgoContainer solver_; // Solver object.
725 #else
727 #endif
728  mutable bool reconfig_solver_; // If true then we must reconfigure the solver!
731  mutable bool test_nlp_;
732  mutable bool print_algo_;
733  mutable bool algo_timing_;
734  mutable bool generate_stats_file_;
736  mutable bool throw_exceptions_;
737  mutable std::string output_file_tag_;
741  mutable bool do_algo_outputting_;
742  mutable int configuration_;
743 #ifndef DOXYGEN_COMPILE
744  nlp_ptr_t nlp_;
745  track_ptr_t track_;
746  config_ptr_t config_;
747  options_ptr_t options_; // set by client
748  ostream_ptr_t error_out_; // set by client
749  mutable ostream_ptr_t algo_out_; // set by client
750  mutable ostream_ptr_t console_out_; // set by client
751  mutable ostream_ptr_t summary_out_; // set by client
752  mutable ostream_ptr_t journal_out_; // set by client
753  mutable options_ptr_t options_used_; // actually used (can be NULL)
754  mutable ostream_ptr_t error_out_used_; // actually used (can't be NULL)
755  mutable ostream_ptr_t console_out_used_; // actually used (can be NULL if do_console_outputting == false)
756  mutable ostream_ptr_t summary_out_used_; // actually used (can be NULL if do_summary_outputting == false)
757  mutable ostream_ptr_t journal_out_used_; // actually used (can be NULL if do_journal_outputting == false)
758  mutable ostream_ptr_t algo_out_used_; // actually used (can be NULL if do_algo_outputting == false)
759  mutable ostream_ptr_t stats_out_used_; // actually used
760  EOutputToBlackHole output_to_black_hole_;
761  std::string file_context_postfix_;
762  std::string file_proc_postfix_;
763 #endif
764 
765  // ////////////////////////////////////
766  // Private member functions
767 
769  void generate_output_streams() const;
770 
771 }; // end class MoochoSolver
772 
831 // /////////////////////////////////////////
832 // Inline members
833 
834 inline
835 void MoochoSolver::set_output_file_tag(const std::string& output_file_tag)
836 {
837  output_file_tag_ = output_file_tag;
838 }
839 
840 inline
841 void MoochoSolver::do_console_outputting(bool do_console_outputting)
842 {
844 }
845 
846 inline
848 {
849  return do_console_outputting_;
850 }
851 
852 inline
853 void MoochoSolver::do_summary_outputting(bool do_summary_outputting)
854 {
856 }
857 
858 inline
860 {
861  return do_summary_outputting_;
862 }
863 
864 inline
865 void MoochoSolver::do_journal_outputting(bool do_journal_outputting)
866 {
868 }
869 
870 inline
872 {
873  return do_journal_outputting_;
874 }
875 
876 inline
877 void MoochoSolver::do_algo_outputting(bool do_algo_outputting)
878 {
880 }
881 
882 inline
884 {
885  return do_algo_outputting_;
886 }
887 
888 inline
889 void MoochoSolver::generate_stats_file(bool generate_stats_file)
890 {
892 }
893 
894 inline
896 {
897  return generate_stats_file_;
898 }
899 
900 } // end namespace MoochoPack
901 
902 #endif // MOOCHOPACK_MOOCHO_SOLVER_HPP
const ostream_ptr_t & get_console_out() const
Get the non-const smart pointer to the set output stream for console outputting.
void set_options(const options_ptr_t &options)
Set the various options to use.
Reads from a file and/or parses from the commandline to initalize an OptionsFromStream object...
void setup_commandline_processor(Teuchos::CommandLineProcessor *clp)
Setup the commandline processor to process commandline options.
void set_output_context(const std::string &file_context_postfix, EOutputToBlackHole output_to_black_hole=OUTPUT_TO_BLACK_HOLE_DEFAULT, const int procRank=-1, const int numProcs=-1)
Setup the context for outputting.
void update_solver() const
Setup the state of the solver and get ready for a solve.
RCP< IterationPack::AlgorithmTracker > track_ptr_t
bool generate_stats_file() const
Return if a statistics file will be generated or not.
const ostream_ptr_t & get_summary_out() const
Get the non-const smart pointer to the set output stream for summary outputting.
void set_journal_out(const ostream_ptr_t &journal_out)
Set the std::ostream object to use for journal output by the MOOCHO step objects. ...
const config_ptr_t & get_config() const
Return the configuration object being used.
Implementation for NLPAlgo solver.
const ostream_ptr_t & get_journal_out() const
Get the non-const smart pointer to the set output stream for journal outputting.
RCP< NLPSolverClientInterface > solver_ptr_t
bool do_console_outputting() const
Return if console outputting is performed or not.
RCP< NLPInterfacePack::NLP > nlp_ptr_t
bool do_summary_outputting() const
Return if summary outputting is performed or not.
const track_ptr_t & get_track() const
Get the non-const smart pointer to the set AlgorithmTracker object.
const options_ptr_t & get_options() const
Get the OptionsFromStream object being used to extract the options from.
bool do_journal_outputting() const
Return if journal outputting is performed or not.
MoochoSolver(const std::string &options_file_name="Moocho.opt", const std::string &extra_options_str="")
Constructs to uninitialized.
const ostream_ptr_t & error_out() const
Return the std::ostream object used for error reporting on exceptions.
Universal interface to a MOOCHO solver.
RCP< std::ostream > generate_output_file(const std::string &fileNameBase) const
Generate an output file given a base file name.
void set_config(const config_ptr_t &config)
Set the algorithm configuration object.
const ostream_ptr_t & get_algo_out() const
Get the non-const smart pointer to the set output stream for algo outputting.
void set_console_out(const ostream_ptr_t &console_out)
Set the std::ostream object to use for console output by a MoochoTrackerConsoleStd object...
This is the most basic interface that clients use to solve an NLP.
bool do_algo_outputting() const
Return if algo outputting is performed or not.
void set_summary_out(const ostream_ptr_t &summary_out)
Set the std::ostream object to use for summary output.
NLPSolverClientInterface & get_solver()
Get the underlying NLPSolverClientInterface object.
OptionsFromStreamPack::CommandLineOptionsFromStreamProcessor commandLineOptionsFromStreamProcessor_
ESolutionStatus solve_nlp() const
Solve the NLP.
AbstractLinAlgPack::value_type value_type
const nlp_ptr_t & get_nlp() const
Get the non-const smart pointer to the set NLP object.
void set_nlp(const nlp_ptr_t &nlp)
Set the NLP to be solved.
void set_output_file_tag(const std::string &)
Set a tag for output file names for all file names that are created internally.
void set_track(const track_ptr_t &track)
RCP< OptionsFromStreamPack::OptionsFromStream > options_ptr_t
OptionsFromStreamPack::CommandLineOptionsFromStreamProcessor & commandLineOptionsFromStreamProcessor()
void set_algo_out(const ostream_ptr_t &algo_out)
Set the std::ostream object to use for algorithm output.
void set_error_handling(bool throw_exceptions, const ostream_ptr_t &error_out)
Set the error output and whether exceptions will be thrown from these functions or not...
bool throw_exceptions() const
Return if exceptions will be thrown out of this->solve_nlp().