ROL
step/test_07.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_HS32.hpp"
17#include "ROL_Algorithm.hpp"
18
19
20typedef double RealT;
21
22int main(int argc, char *argv[]) {
23
24
25
26
27 typedef std::vector<RealT> vec;
28 typedef ROL::StdVector<RealT> SV;
29 typedef ROL::Ptr<ROL::Vector<RealT> > ROL::PtrV;
30
31// typedef ROL::PartitionedVector<RealT> PV;
32
33
34 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
35
36 int iprint = argc - 1;
37 ROL::Ptr<std::ostream> outStream;
38 ROL::nullstream bhs; // outputs nothing
39 if (iprint > 0)
40 outStream = ROL::makePtrFromRef(std::cout);
41 else
42 outStream = ROL::makePtrFromRef(bhs);
43
44 int errorFlag = 0;
45
46 try {
47
48 int xopt_dim = 3; // Dimension of optimization vectors
49 int ce_dim = 1; // Dimension of equality constraint
50 int ci_dim = 4; // Dimension of inequality constraint
51
52 // Exact solution
53 ROL::Ptr<vec> x_exact_ptr = ROL::makePtr<vec>(xopt_dim,0.0);
54 (*x_exact_ptr)[xopt_dim-1] = 1.0;
55
56 ROL::Ptr<vec> xopt_ptr = ROL::makePtr<vec>(xopt_dim,0.0); // Optimization variables
57
58 ROL::Ptr<vec> le_ptr = ROL::makePtr<vec>(ce_dim,0.0); // Equality multiplier
59 ROL::Ptr<vec> li_ptr = ROL::makePtr<vec>(ci_dim,0.0); // Inequality multiplier
60
61 // Feasible initial guess
62 (*xopt_ptr)[0] = 0.1;
63 (*xopt_ptr)[1] = 0.7;
64 (*xopt_ptr)[2] = 0.2;
65
66 ROL::PtrV xopt = ROL::makePtr<SV>(xopt_ptr);
67 ROL::PtrV le = ROL::makePtr<SV>(le_ptr);
68 ROL::PtrV li = ROL::makePtr<SV>(li_ptr);
69
73
74 ROL::Ptr<ROL::Objective<RealT> > obj_hs32 = ROL::makePtr<Objective_HS32<RealT>>();
75 ROL::Ptr<ROL::EqualityConstraint<RealT> > eqcon_hs32 = ROL::makePtr<EqualityConstraint_HS32<RealT>>();
76 ROL::Ptr<ROL::InequalityConstraint<RealT> > incon_hs32 = ROL::makePtr<InequalityConstraint_HS32<RealT>>();
77
78
79 std::string stepname = "Interior Point";
80
81 RealT mu = 0.1; // Initial penalty parameter
82 RealT factor = 0.1; // Penalty reduction factor
83
84 // Set solver parameters
85 parlist->sublist("Step").sublist("Interior Point").set("Initial Barrier Penalty",mu);
86 parlist->sublist("Step").sublist("Interior Point").set("Minimium Barrier Penalty",1e-8);
87 parlist->sublist("Step").sublist("Interior Point").set("Barrier Penalty Reduction Factor",factor);
88 parlist->sublist("Step").sublist("Interior Point").set("Subproblem Iteration Limit",30);
89
90 parlist->sublist("Step").sublist("Composite Step").sublist("Optimality System Solver").set("Nominal Relative Tolerance",1.e-4);
91 parlist->sublist("Step").sublist("Composite Step").sublist("Optimality System Solver").set("Fix Tolerance",true);
92 parlist->sublist("Step").sublist("Composite Step").sublist("Tangential Subproblem Solver").set("Iteration Limit",20);
93 parlist->sublist("Step").sublist("Composite Step").sublist("Tangential Subproblem Solver").set("Relative Tolerance",1e-2);
94 parlist->sublist("Step").sublist("Composite Step").set("Output Level",0);
95
96 parlist->sublist("Status Test").set("Gradient Tolerance",1.e-12);
97 parlist->sublist("Status Test").set("Constraint Tolerance",1.e-8);
98 parlist->sublist("Status Test").set("Step Tolerance",1.e-8);
99 parlist->sublist("Status Test").set("Iteration Limit",100);
100
101 ROL::OptimizationProblem<RealT> problem( obj_hs32, xopt, eqcon_hs32, le, incon_hs32, li, parlist);
102
103 // Define algorithm.
104 ROL::Ptr<ROL::Algorithm<RealT> > algo;
105 algo = ROL::makePtr<ROL::Algorithm<RealT>>(stepname,*parlist);
106
107 algo->run(problem,true,*outStream);
108
109 *outStream << std::endl << std::setw(20) << "Computed Minimizer" << std::setw(20) << "Exact Minimizer" << std::endl;
110 for( int i=0;i<xopt_dim;++i ) {
111 *outStream << std::setw(20) << (*xopt_ptr)[i] << std::setw(20) << (*x_exact_ptr)[i] << std::endl;
112 }
113 }
114 catch (std::logic_error& err) {
115 *outStream << err.what() << "\n";
116 errorFlag = -1000;
117 }; // end try
118
119 if (errorFlag != 0)
120 std::cout << "End Result: TEST FAILED\n";
121 else
122 std::cout << "End Result: TEST PASSED\n";
123
124 return 0;
125}
126
Contains definitions for W. Hock and K. Schittkowski 32nd test problem which contains both 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