ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
test
step
fletcher
step/fletcher/test_01.cpp
Go to the documentation of this file.
1
// @HEADER
2
// *****************************************************************************
3
// Rapid Optimization Library (ROL) Package
4
//
5
// Copyright 2014 NTESS and the ROL contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
14
15
#include "
ROL_SimpleEqConstrained.hpp
"
16
#include "
ROL_OptimizationProblem.hpp
"
17
#include "
ROL_OptimizationSolver.hpp
"
18
#include "
ROL_Fletcher.hpp
"
19
20
#include "
ROL_Stream.hpp
"
21
#include "ROL_GlobalMPISession.hpp"
22
23
24
#include <iostream>
25
26
typedef
double
RealT
;
27
28
int
main
(
int
argc,
char
*argv[]) {
29
30
ROL::GlobalMPISession mpiSession(&argc, &argv);
31
32
std::string filename =
"input.xml"
;
33
34
auto
parlist = ROL::getParametersFromXmlFile( filename );
35
36
using
Opt =
ROL::OptimizationProblem<RealT>
;
37
using
V
=
ROL::Vector<RealT>
;
38
39
// This little trick lets us print to std::cout only if a (dummy) command-line argument is provided.
40
int
iprint = argc - 1;
41
ROL::Ptr<std::ostream> outStream;
42
ROL::nullstream
bhs;
// outputs nothing
43
if
(iprint > 0)
44
outStream = ROL::makePtrFromRef(std::cout);
45
else
46
outStream = ROL::makePtrFromRef(bhs);
47
48
// Save the format state of the original std::cout.
49
ROL::nullstream
oldFormatState;
50
oldFormatState.copyfmt(std::cout);
51
52
int
errorFlag = 0;
53
54
// *** Test body.
55
56
try
{
57
58
// Set up optimization problem
59
ROL::Ptr<V> x;
60
std::vector<ROL::Ptr<V> > sol;
61
ROL::Ptr<Opt> optProb;
62
ROL::ZOO::getSimpleEqConstrained<RealT>
SEC;
63
SEC.
get
( optProb, x, sol );
64
ROL::Ptr<V> error = x->clone();
65
66
// Solve optimization problem
67
ROL::OptimizationSolver<RealT>
optSolver(*optProb, *parlist);
68
optSolver.
solve
(*outStream);
69
70
error->set(*sol[0]);
71
error->axpy(
static_cast<
RealT
>
(-1), *x);
72
RealT
solnErr = error->norm();
73
74
*outStream <<
"Distance from true solution: "
<< solnErr <<
"\n"
;
75
76
errorFlag += (solnErr < static_cast<RealT>(1e-6)) ? 0 : 1;
77
}
78
catch
(std::logic_error& err) {
79
*outStream << err.what() <<
"\n"
;
80
errorFlag = -1000;
81
};
// end try
82
83
if
(errorFlag != 0)
84
std::cout <<
"End Result: TEST FAILED\n"
;
85
else
86
std::cout <<
"End Result: TEST PASSED\n"
;
87
88
// reset format state of std::cout
89
std::cout.copyfmt(oldFormatState);
90
91
return
0;
92
}
V
Vector< Real > V
Definition
ROL_BlockOperator2Diagonal.hpp:46
ROL_Fletcher.hpp
ROL_OptimizationProblem.hpp
ROL_OptimizationSolver.hpp
ROL_SimpleEqConstrained.hpp
Contains definitions for the equality constrained NLP from Nocedal/Wright, 2nd edition,...
ROL_Stream.hpp
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
ROL::OptimizationProblem
Definition
ROL_OptimizationProblem.hpp:54
ROL::OptimizationSolver
Provides a simplified interface for solving a wide range of optimization problems.
Definition
ROL_OptimizationSolver.hpp:29
ROL::OptimizationSolver::solve
int solve(const ROL::Ptr< StatusTest< Real > > &status=ROL::nullPtr, const bool combineStatus=true)
Solve optimization problem with no iteration output.
Definition
ROL_OptimizationSolver.hpp:180
ROL::TestProblem::get
void get(Ptr< OptimizationProblem< Real > > &problem, Ptr< Vector< Real > > &x0, std::vector< Ptr< Vector< Real > > > &x) const
Definition
ROL_TestProblem.hpp:54
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL::ZOO::getSimpleEqConstrained
Definition
ROL_SimpleEqConstrained.hpp:408
RealT
double RealT
Definition
function/constraint/test_01.cpp:29
ROL::details::nullstream
basic_nullstream< char, std::char_traits< char > > nullstream
Definition
ROL_Stream.hpp:36
main
int main(int argc, char *argv[])
Definition
step/fletcher/test_01.cpp:28
Generated by
1.17.0