ROL
step/test_11.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_HS24.hpp"
52#include "ROL_Algorithm.hpp"
54
55int main(int argc, char *argv[]) {
56
57
58
59
60 typedef double RealT;
61
62 typedef ROL::Vector<RealT> V;
64 typedef ROL::Objective<RealT> OBJ;
65 typedef ROL::InequalityConstraint<RealT> INEQ;
66
67
68
69 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
70
71 int iprint = argc - 1;
72 ROL::Ptr<std::ostream> outStream;
73 ROL::nullstream bhs; // outputs nothing
74 if (iprint > 0)
75 outStream = ROL::makePtrFromRef(std::cout);
76 else
77 outStream = ROL::makePtrFromRef(bhs);
78
79 int errorFlag = 0;
80
81 try {
82
84 ROL::Ptr<V> x = HS24.getInitialGuess();
85 ROL::Ptr<V> xs = HS24.getSolution();
86 ROL::Ptr<V> inmul = HS24.getInequalityMultiplier();
87
88 ROL::Ptr<BC> bnd = HS24.getBoundConstraint();
89 ROL::Ptr<OBJ> obj = HS24.getObjective();
90 ROL::Ptr<INEQ> incon = HS24.getInequalityConstraint();
91 ROL::Ptr<BC> inbnd = HS24.getSlackBoundConstraint();
92
93
94
95 std::string stepname = "Interior Point";
96
97 RealT mu = 0.1; // Initial penalty parameter
98 RealT factor = 0.1; // Penalty reduction factor
99
100 // Set solver parameters
101 parlist->sublist("Step").sublist("Interior Point").set("Initial Barrier Penalty",mu);
102 parlist->sublist("Step").sublist("Interior Point").set("Minimium Barrier Penalty",1e-8);
103 parlist->sublist("Step").sublist("Interior Point").set("Barrier Penalty Reduction Factor",factor);
104 parlist->sublist("Step").sublist("Interior Point").set("Subproblem Iteration Limit",30);
105
106 parlist->sublist("Step").sublist("Composite Step").sublist("Optimality System Solver").set("Nominal Relative Tolerance",1.e-4);
107 parlist->sublist("Step").sublist("Composite Step").sublist("Optimality System Solver").set("Fix Tolerance",true);
108 parlist->sublist("Step").sublist("Composite Step").sublist("Tangential Subproblem Solver").set("Iteration Limit",20);
109 parlist->sublist("Step").sublist("Composite Step").sublist("Tangential Subproblem Solver").set("Relative Tolerance",1e-2);
110 parlist->sublist("Step").sublist("Composite Step").set("Output Level",0);
111
112 parlist->sublist("Status Test").set("Gradient Tolerance",1.e-12);
113 parlist->sublist("Status Test").set("Constraint Tolerance",1.e-8);
114 parlist->sublist("Status Test").set("Step Tolerance",1.e-8);
115 parlist->sublist("Status Test").set("Iteration Limit",100);
116
117 // Define Optimization Problem
118 ROL::OptimizationProblem<RealT> problem( obj, x, bnd, incon, inmul, inbnd );
119
120 ROL::Ptr<V> d = x->clone();
121 RandomizeVector(*d);
122
123// problem.checkObjectiveGradient(*d);
124// problem.checkObjectiveHessVec(*d);
125
126 // Define algorithm.
127 ROL::Ptr<ROL::Algorithm<RealT> > algo;
128 algo = ROL::makePtr<ROL::Algorithm<RealT>>(stepname,*parlist);
129
130 algo->run(problem,true,*outStream);
131
132 x->axpy(-1.0,*xs);
133
134 if( x->norm()>= 1e-4 )
135 {
136 ++errorFlag;
137 }
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}
Vector< Real > V
Contains definitions for W. Hock and K. Schittkowski 24th test problem which contains bound and inequ...
Provides the interface to apply upper and lower bound constraints.
Provides the interface to evaluate objective functions.
Defines the linear algebra or vector space interface.
Ptr< BoundConstraint< Real > > getSlackBoundConstraint(void) const
Definition ROL_HS24.hpp:215
Ptr< Constraint< Real > > getInequalityConstraint(void) const
Definition ROL_HS24.hpp:177
Ptr< Vector< Real > > getInitialGuess(void) const
Definition ROL_HS24.hpp:194
Ptr< Vector< Real > > getInequalityMultiplier(void) const
Definition ROL_HS24.hpp:210
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition ROL_HS24.hpp:202
Ptr< Objective< Real > > getObjective(void) const
Definition ROL_HS24.hpp:173
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition ROL_HS24.hpp:181
int main(int argc, char *argv[])