ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
test
vector
vector/test_06.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
13
14
#include "
ROL_ProfiledVector.hpp
"
15
#include "
ROL_StdVector.hpp
"
16
#include "
ROL_Zakharov.hpp
"
17
#include "
ROL_Algorithm.hpp
"
18
#include "
ROL_TrustRegionStep.hpp
"
19
#include "
ROL_StatusTest.hpp
"
20
#include "
ROL_Stream.hpp
"
21
22
#include "ROL_GlobalMPISession.hpp"
23
24
typedef
int
OrdinalT
;
25
typedef
double
RealT
;
26
27
template
<>
28
ROL::VectorFunctionCalls<int>
29
ROL::ProfiledVector<int,RealT>::functionCalls_
=
ROL::VectorFunctionCalls<int>
();
30
31
int
main
(
int
argc,
char
*argv[]) {
32
33
34
using
ROL::ParameterList;
35
36
typedef
std::vector<RealT> vector;
37
38
typedef
ROL::Vector<RealT>
V
;
39
typedef
ROL::StdVector<RealT>
SV;
40
41
ROL::GlobalMPISession mpiSession(&argc, &argv,0);
42
43
int
iprint = argc - 1;
44
ROL::Ptr<std::ostream> outStream;
45
ROL::nullstream
bhs;
// outputs nothing
46
if
(iprint > 0)
47
outStream = ROL::makePtrFromRef(std::cout);
48
else
49
outStream = ROL::makePtrFromRef(bhs);
50
51
int
errorFlag = 0;
52
53
try
{
54
// Dimension of the optimization vector
55
int
dim
= 10;
56
57
std::string paramfile =
"parameters.xml"
;
58
auto
parlist = ROL::getParametersFromXmlFile(paramfile);
59
60
// Define algorithm.
61
ROL::Ptr<ROL::Step<RealT>>
62
step = ROL::makePtr<ROL::TrustRegionStep<RealT>>(*parlist);
63
ROL::Ptr<ROL::StatusTest<RealT>>
64
status = ROL::makePtr<ROL::StatusTest<RealT>>(*parlist);
65
ROL::Algorithm<RealT>
algo(step,status,
false
);
66
67
ROL::Ptr<vector> x_ptr = ROL::makePtr<vector>(
dim
,1.0);
68
ROL::Ptr<vector> k_ptr = ROL::makePtr<vector>(
dim
);
69
70
for
(
int
i=0;i<
dim
;++i) {
71
(*k_ptr)[i] = 1.0 + i;
72
}
73
74
ROL::Ptr<V> xs = ROL::makePtr<SV>(x_ptr);
75
ROL::Ptr<V> ks = ROL::makePtr<SV>(k_ptr);
76
77
// Create ProfiledVector objects
78
ROL::ProfiledVector<int,RealT>
xpf(xs);
79
ROL::Ptr<V> kpf = ROL::makePtr<ROL::ProfiledVector<int,RealT>>(ks);
80
81
ROL::ZOO::Objective_Zakharov<RealT>
obj(kpf);
82
83
// Run algorithm.
84
algo.
run
(xpf, obj,
true
, *outStream);
85
86
// Display number of function calls
87
ROL::printVectorFunctionCalls
(xpf, *outStream);
88
}
89
90
catch
(std::logic_error& err) {
91
*outStream << err.what() <<
"\n"
;
92
errorFlag = -1000;
93
};
// end try
94
95
if
(errorFlag != 0)
96
std::cout <<
"End Result: TEST FAILED\n"
;
97
else
98
std::cout <<
"End Result: TEST PASSED\n"
;
99
100
return
0;
101
}
ROL_Algorithm.hpp
V
Vector< Real > V
Definition
ROL_BlockOperator2Diagonal.hpp:46
ROL_ProfiledVector.hpp
ROL_StatusTest.hpp
ROL_StdVector.hpp
ROL_Stream.hpp
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
ROL_TrustRegionStep.hpp
ROL_Zakharov.hpp
Contains definitions for the Zakharov function as evaluated using only the ROL::Vector interface.
ROL::Algorithm
Provides an interface to run unconstrained optimization algorithms.
Definition
ROL_Algorithm.hpp:29
ROL::Algorithm::run
virtual std::vector< std::string > run(Vector< Real > &x, Objective< Real > &obj, bool print=false, std::ostream &outStream=std::cout, bool printVectors=false, std::ostream &vectorStream=std::cout)
Run algorithm on unconstrained problems (Type-U). This is the primary Type-U interface.
Definition
ROL_Algorithm.hpp:68
ROL::ProfiledVector
By keeping a pointer to this in a derived Vector class, a tally of all methods is kept for profiling ...
Definition
ROL_ProfiledVector.hpp:101
ROL::ProfiledVector::functionCalls_
static VectorFunctionCalls< Ordinal > functionCalls_
Definition
ROL_ProfiledVector.hpp:107
ROL::StdVector
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Definition
ROL_StdVector.hpp:27
ROL::Vector
Defines the linear algebra or vector space interface.
Definition
ROL_Vector.hpp:51
ROL::ZOO::Objective_Zakharov
Zakharov function.
Definition
ROL_Zakharov.hpp:62
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
ROL::printVectorFunctionCalls
void printVectorFunctionCalls(const ProfiledVector< Ordinal, Real > &x, std::ostream &outStream=std::cout)
Definition
ROL_ProfiledVector.hpp:74
ROL::VectorFunctionCalls
Definition
ROL_ProfiledVector.hpp:36
main
int main(int argc, char *argv[])
Definition
vector/test_06.cpp:31
OrdinalT
int OrdinalT
Definition
vector/test_06.cpp:24
dim
constexpr auto dim
Definition
vector/test_11.cpp:23
Generated by
1.17.0