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 "ROL_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
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
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}
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