MOOCHO  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
NLPInterfacePack_ExampleNLPDirectRun.cpp
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 
43 #include <assert.h>
44 
45 #include <fstream>
46 #include <fstream>
47 #include <iostream>
48 #include <iomanip>
49 #include <typeinfo>
50 
51 #include "NLPInterfacePack_ExampleNLPDirectRun.hpp"
52 #include "NLPInterfacePack_ExampleNLPDirect.hpp"
53 #include "MoochoPack_NLPAlgoConfigMamaJama.hpp"
54 #include "IterationPack_AlgorithmTracker.hpp"
55 #include "AbstractLinAlgPack_VectorSpace.hpp"
56 #include "AbstractLinAlgPack_BasisSystem.hpp"
57 #include "OptionsFromStreamPack_OptionsFromStream.hpp"
58 
61  const VectorSpace& vec_space
62  ,value_type xo
63  ,bool has_bounds
64  ,bool dep_bounded
65  ,std::ostream* console_out
66  ,std::ostream* error_out
67  ,bool throw_solve_exception
68  ,std::ostream* algo_out
69  ,std::ostream* summary_out
70  ,std::ostream* journal_out
71  )
72 {
73  using std::endl;
74  using std::setw;
75  namespace rcp = MemMngPack;
76  using Teuchos::RCP;
77  namespace ofsp = OptionsFromStreamPack;
78  using ofsp::OptionsFromStream;
79  namespace rsqp = MoochoPack;
80  using rsqp::MoochoSolver;
81  using rsqp::NLPAlgoConfigMamaJama;
82 
83  MoochoSolver::ESolutionStatus
84  solve_return = MoochoSolver::SOLVE_RETURN_EXCEPTION;
85 
86  int err = 0;
87 
88  int w = 15;
89  int prec = 8;
90 
91  if(console_out)
92  *console_out
93  << std::setprecision(prec)
94  << std::scientific
95  << "***************************************************\n"
96  << "*** Running Tests on ExampleNLPDirect ***\n"
97  << "***************************************************\n"
98  << "\nUsing a vector space of type \'" << typeName(vec_space) << "\'"
99  << "\nwith a dimension of vec_space.dim() = " << vec_space.dim()
100  << std::endl;
101 
102  // Create the nlp
104  nlp(VectorSpace::space_ptr_t(&vec_space,false),xo,has_bounds,dep_bounded);
105 
106  // Create the solver object and set it up
107  MoochoSolver solver;
108  solver.set_nlp(Teuchos::rcp(&nlp,false)); // Set the NLP!
109  solver.set_error_handling( // set up outputting
110  throw_solve_exception
111  ,Teuchos::rcp(error_out,false)
112  );
113  solver.set_console_out(Teuchos::rcp(console_out,false));
114  solver.set_summary_out(Teuchos::rcp(summary_out,false));
115  solver.set_journal_out(Teuchos::rcp(journal_out,false));
116  solver.set_algo_out( Teuchos::rcp(algo_out,false) );
117 
118  // Run MOOCHO using the MamaJama configuration
119  solve_return = solver.solve_nlp();
120 
121  return solve_return;
122 }
MoochoPack::MoochoSolver::ESolutionStatus ExampleNLPDirectRun(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...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Simple example NLP subclass to illustrate how to implement the NLPDirect interface for a specialized ...
std::string typeName(const T &t)