MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
NLPInterfacePack_ExampleNLPFirstOrderRun.cpp
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 #ifdef _INTEL_CXX
43 // disable Intel C++ 5.0 warnings about debugger limitations
44 #pragma warning(disable : 985)
45 #endif
46 
47 #include <assert.h>
48 
49 #include <fstream>
50 #include <fstream>
51 #include <iostream>
52 #include <iomanip>
53 #include <typeinfo>
54 
63 
66  const VectorSpace& vec_space
67  ,value_type xo
68  ,bool has_bounds
69  ,bool dep_bounded
70  ,std::ostream* console_out
71  ,std::ostream* error_out
72  ,bool throw_solve_exception
73  ,std::ostream* algo_out
74  ,std::ostream* summary_out
75  ,std::ostream* journal_out
76  )
77 {
78  using std::endl;
79  using std::setw;
80  namespace rcp = MemMngPack;
81  using Teuchos::RCP;
82  namespace ofsp = OptionsFromStreamPack;
83  using ofsp::OptionsFromStream;
84  namespace rsqp = MoochoPack;
85  using rsqp::MoochoSolver;
86  using rsqp::NLPAlgoConfigMamaJama;
87 
88  MoochoSolver::ESolutionStatus
89  solve_return = MoochoSolver::SOLVE_RETURN_EXCEPTION;
90 
91  int prec = 8;
92 
93  if(console_out)
94  *console_out
95  << std::setprecision(prec)
96  << std::scientific
97  << "*************************************************\n"
98  << "*** Running Tests on ExampleNLPFirstOrder ***\n"
99  << "*************************************************\n"
100  << "\nUsing a vector space of type \'" << typeName(vec_space) << "\'"
101  << "\nwith a dimension of vec_space.dim() = " << vec_space.dim()
102  << std::endl;
103 
104  // Create the nlp
106  nlp(VectorSpace::space_ptr_t(&vec_space,false),xo,has_bounds,dep_bounded);
107 
108  // Create the solver object and set it up
109  MoochoSolver solver;
110  solver.set_nlp(Teuchos::rcp(&nlp,false)); // Set nlp
111  // set up outputting
112  solver.set_error_handling(
113  throw_solve_exception
114  ,Teuchos::rcp(error_out,false)
115  );
116  solver.set_console_out(Teuchos::rcp(console_out,false));
117  solver.set_summary_out(Teuchos::rcp(summary_out,false));
118  solver.set_journal_out(Teuchos::rcp(journal_out,false));
119  solver.set_algo_out( Teuchos::rcp(algo_out,false) );
120 
121  // Run MOOCHO using the MamaJama configuration
122  solve_return = solver.solve_nlp();
123 
124  return solve_return;
125 }
MoochoPack::MoochoSolver::ESolutionStatus ExampleNLPFirstOrderRun(const VectorSpace &vec_space, value_type xo, bool has_bounds, bool dep_bounded, std::ostream *console_out, std::ostream *error_out, bool throw_solve_exception=false, std::ostream *algo_out=NULL, std::ostream *summary_out=NULL, std::ostream *journal_out=NULL)
Function accepts a VectorSpace object and then uses it to define an example NLP and run MoochoPack::M...
std::string typeName(const T &t)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Simple example NLP subclass to illustrate how to implement the NLPFirstOrder interface for a speciali...
AbstractLinAlgPack::value_type value_type