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