ROL
step/test_08.cpp
Go to the documentation of this file.
1// @HEADER
2// ************************************************************************
3//
4// Rapid Optimization Library (ROL) Package
5// Copyright (2014) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact lead developers:
38//
39// Drew Kouri (dpkouri@sandia.gov) and
40// Denis Ridzal (dridzal@sandia.gov)
41//
42// ************************************************************************
43// @HEADER
44
49#include "Teuchos_GlobalMPISession.hpp"
50
51#include "ROL_HS29.hpp"
52#include "ROL_Algorithm.hpp"
53
54typedef double RealT;
55
56int main(int argc, char *argv[]) {
57
58
59
60
61 typedef std::vector<RealT> vec;
62 typedef ROL::StdVector<RealT> SV;
63 typedef ROL::Ptr<ROL::Vector<RealT> > ROL::PtrV;
64
65 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
66
67 int iprint = argc - 1;
68 ROL::Ptr<std::ostream> outStream;
69 ROL::nullstream bhs; // outputs nothing
70 if (iprint > 0)
71 outStream = ROL::makePtrFromRef(std::cout);
72 else
73 outStream = ROL::makePtrFromRef(bhs);
74
75 int errorFlag = 0;
76
77 try {
78
79 int xopt_dim = 3; // Dimension of optimization vectors
80 int ci_dim = 1; // Dimension of inequality constraint
81
82 ROL::Ptr<vec> xopt_ptr = ROL::makePtr<vec>(xopt_dim,1.0); // Feasible initial guess
83
84 ROL::Ptr<vec> li_ptr = ROL::makePtr<vec>(ci_dim,0.0);
85
86 ROL::PtrV xopt = ROL::makePtr<SV>(xopt_ptr);
87 ROL::PtrV li = ROL::makePtr<SV>(li_ptr);
88
89 // Original obective
92
93 ROL::Ptr<ROL::Objective<RealT> > obj_hs29 = ROL::makePtr<Objective_HS29<RealT>>();
94 ROL::Ptr<ROL::InequalityConstraint<RealT> > incon_hs29 = ROL::makePtr<InequalityConstraint_HS29<RealT>>();
95
96
97 std::string stepname = "Interior Point";
98
99 RealT mu = 0.1; // Initial penalty parameter
100 RealT factor = 0.1; // Penalty reduction factor
101
102 // Set solver parameters
103 parlist->sublist("General").set("Print Verbosity",1);
104
105 parlist->sublist("Step").sublist("Interior Point").set("Initial Barrier Penalty",mu);
106 parlist->sublist("Step").sublist("Interior Point").set("Minimium Barrier Penalty",1e-8);
107 parlist->sublist("Step").sublist("Interior Point").set("Barrier Penalty Reduction Factor",factor);
108 parlist->sublist("Step").sublist("Interior Point").set("Subproblem Iteration Limit",30);
109
110 parlist->sublist("Step").sublist("Composite Step").sublist("Optimality System Solver").set("Nominal Relative Tolerance",1.e-4);
111 parlist->sublist("Step").sublist("Composite Step").sublist("Optimality System Solver").set("Fix Tolerance",true);
112 parlist->sublist("Step").sublist("Composite Step").sublist("Tangential Subproblem Solver").set("Iteration Limit",20);
113 parlist->sublist("Step").sublist("Composite Step").sublist("Tangential Subproblem Solver").set("Relative Tolerance",1e-2);
114 parlist->sublist("Step").sublist("Composite Step").set("Output Level",0);
115
116 parlist->sublist("Status Test").set("Gradient Tolerance",1.e-12);
117 parlist->sublist("Status Test").set("Constraint Tolerance",1.e-8);
118 parlist->sublist("Status Test").set("Step Tolerance",1.e-8);
119 parlist->sublist("Status Test").set("Iteration Limit",100);
120
121 ROL::OptimizationProblem<RealT> problem( obj_hs29, xopt, incon_hs29, li, parlist);
122
123 // Define algorithm.
124 ROL::Ptr<ROL::Algorithm<RealT> > algo;
125 algo = ROL::makePtr<ROL::Algorithm<RealT>>(stepname,*parlist);
126
127 algo->run(problem,true,*outStream);
128
129
130
131 *outStream << std::endl << std::setw(20) << "Computed Minimizer" << std::endl;
132 for( int i=0;i<xopt_dim;++i ) {
133 *outStream << std::setw(20) << (*xopt_ptr)[i] << std::endl;
134 }
135
136 *outStream << "Exact minimizers: x* = (a,b,c), (a,-b,-c), (-a,b,-c), (-a,-b,c)" << std::endl;
137 *outStream << "Where a=4, b=" << 2*std::sqrt(2) << ", and c=2" << std::endl;
138
139 }
140 catch (std::logic_error& err) {
141 *outStream << err.what() << "\n";
142 errorFlag = -1000;
143 }; // end try
144
145 if (errorFlag != 0)
146 std::cout << "End Result: TEST FAILED\n";
147 else
148 std::cout << "End Result: TEST PASSED\n";
149
150 return 0;
151
152
153
154}
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