ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
test
step
step/test_08.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_GlobalMPISession.hpp"
15
16
#include "
ROL_HS29.hpp
"
17
#include "
ROL_Algorithm.hpp
"
18
19
typedef
double
RealT
;
20
21
int
main
(
int
argc,
char
*argv[]) {
22
23
24
25
26
typedef
std::vector<RealT> vec;
27
typedef
ROL::StdVector<RealT>
SV;
28
29
ROL::GlobalMPISession mpiSession(&argc, &argv);
30
31
int
iprint = argc - 1;
32
ROL::Ptr<std::ostream> outStream;
33
ROL::nullstream
bhs;
// outputs nothing
34
if
(iprint > 0)
35
outStream = ROL::makePtrFromRef(std::cout);
36
else
37
outStream = ROL::makePtrFromRef(bhs);
38
39
int
errorFlag = 0;
40
41
try
{
42
43
int
xopt_dim = 3;
// Dimension of optimization vectors
44
int
ci_dim = 1;
// Dimension of inequality constraint
45
46
ROL::Ptr<vec> xopt_ptr = ROL::makePtr<vec>(xopt_dim,1.0);
// Feasible initial guess
47
48
ROL::Ptr<vec> li_ptr = ROL::makePtr<vec>(ci_dim,0.0);
49
50
ROL::PtrV xopt = ROL::makePtr<SV>(xopt_ptr);
51
ROL::PtrV li = ROL::makePtr<SV>(li_ptr);
52
53
// Original obective
54
using
ROL::ZOO::Objective_HS29
;
55
using
ROL::ZOO::InequalityConstraint_HS29
;
56
57
auto
obj_hs29 = ROL::makePtr<Objective_HS29<RealT>>();
58
auto
incon_hs29 = ROL::makePtr<InequalityConstraint_HS29<RealT>>();
59
60
61
std::string stepname =
"Interior Point"
;
62
63
RealT
mu = 0.1;
// Initial penalty parameter
64
RealT
factor = 0.1;
// Penalty reduction factor
65
66
// Set solver parameters
67
parlist->sublist(
"General"
).set(
"Print Verbosity"
,1);
68
69
parlist->sublist(
"Step"
).sublist(
"Interior Point"
).set(
"Initial Barrier Penalty"
,mu);
70
parlist->sublist(
"Step"
).sublist(
"Interior Point"
).set(
"Minimium Barrier Penalty"
,1e-8);
71
parlist->sublist(
"Step"
).sublist(
"Interior Point"
).set(
"Barrier Penalty Reduction Factor"
,factor);
72
parlist->sublist(
"Step"
).sublist(
"Interior Point"
).set(
"Subproblem Iteration Limit"
,30);
73
74
parlist->sublist(
"Step"
).sublist(
"Composite Step"
).sublist(
"Optimality System Solver"
).set(
"Nominal Relative Tolerance"
,1.e-4);
75
parlist->sublist(
"Step"
).sublist(
"Composite Step"
).sublist(
"Optimality System Solver"
).set(
"Fix Tolerance"
,
true
);
76
parlist->sublist(
"Step"
).sublist(
"Composite Step"
).sublist(
"Tangential Subproblem Solver"
).set(
"Iteration Limit"
,20);
77
parlist->sublist(
"Step"
).sublist(
"Composite Step"
).sublist(
"Tangential Subproblem Solver"
).set(
"Relative Tolerance"
,1e-2);
78
parlist->sublist(
"Step"
).sublist(
"Composite Step"
).set(
"Output Level"
,0);
79
80
parlist->sublist(
"Status Test"
).set(
"Gradient Tolerance"
,1.e-12);
81
parlist->sublist(
"Status Test"
).set(
"Constraint Tolerance"
,1.e-8);
82
parlist->sublist(
"Status Test"
).set(
"Step Tolerance"
,1.e-8);
83
parlist->sublist(
"Status Test"
).set(
"Iteration Limit"
,100);
84
85
ROL::OptimizationProblem<RealT>
problem( obj_hs29, xopt, incon_hs29, li, parlist);
86
87
// Define algorithm.
88
ROL::Ptr<ROL::Algorithm<RealT> > algo;
89
algo = ROL::makePtr<ROL::Algorithm<RealT>>(stepname,*parlist);
90
91
algo->run(problem,
true
,*outStream);
92
93
94
95
*outStream << std::endl << std::setw(20) <<
"Computed Minimizer"
<< std::endl;
96
for
(
int
i=0;i<xopt_dim;++i ) {
97
*outStream << std::setw(20) << (*xopt_ptr)[i] << std::endl;
98
}
99
100
*outStream <<
"Exact minimizers: x* = (a,b,c), (a,-b,-c), (-a,b,-c), (-a,-b,c)"
<< std::endl;
101
*outStream <<
"Where a=4, b="
<< 2*std::sqrt(2) <<
", and c=2"
<< std::endl;
102
103
}
104
catch
(std::logic_error& err) {
105
*outStream << err.what() <<
"\n"
;
106
errorFlag = -1000;
107
};
// end try
108
109
if
(errorFlag != 0)
110
std::cout <<
"End Result: TEST FAILED\n"
;
111
else
112
std::cout <<
"End Result: TEST PASSED\n"
;
113
114
return
0;
115
116
117
118
}
ROL_Algorithm.hpp
ROL_HS29.hpp
Contains definitions for W. Hock and K. Schittkowski 32nd test problem which contains only inequality...
ROL::OptimizationProblem
Definition
ROL_OptimizationProblem.hpp:54
ROL::StdVector
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Definition
ROL_StdVector.hpp:27
ROL::ZOO::InequalityConstraint_HS29
Definition
ROL_HS29.hpp:85
ROL::ZOO::Objective_HS29
Definition
ROL_HS29.hpp:27
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/test_08.cpp:21
Generated by
1.17.0