ROL
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 "ROL_HS29.hpp"
50 #include "ROL_Algorithm.hpp"
51 
52 typedef double RealT;
53 
54 int main(int argc, char *argv[]) {
55 
56  using Teuchos::RCP;
57  using Teuchos::rcp;
58 
59  typedef std::vector<RealT> vec;
60  typedef ROL::StdVector<RealT> SV;
61  typedef RCP<ROL::Vector<RealT> > RCPV;
62 
63  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
64 
65  int iprint = argc - 1;
66  RCP<std::ostream> outStream;
67  Teuchos::oblackholestream bhs; // outputs nothing
68  if (iprint > 0)
69  outStream = rcp(&std::cout, false);
70  else
71  outStream = rcp(&bhs, false);
72 
73  int errorFlag = 0;
74 
75  try {
76 
77  int xopt_dim = 3; // Dimension of optimization vectors
78  int ci_dim = 1; // Dimension of inequality constraint
79 
80  RCP<vec> xopt_rcp = rcp( new vec(xopt_dim,1.0) ); // Feasible initial guess
81 
82  RCP<vec> li_rcp = rcp( new vec(ci_dim,0.0) );
83 
84  RCPV xopt = rcp( new SV(xopt_rcp) );
85  RCPV li = rcp( new SV(li_rcp) );
86 
87  // Original obective
90 
91  RCP<ROL::Objective<RealT> > obj_hs29 = rcp( new Objective_HS29<RealT> );
92  RCP<ROL::InequalityConstraint<RealT> > incon_hs29 = rcp( new InequalityConstraint_HS29<RealT> );
93 
94  RCP<Teuchos::ParameterList> parlist = rcp(new Teuchos::ParameterList);
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  ROL::OptimizationProblem<RealT> problem( obj_hs29, xopt, incon_hs29, li, parlist);
118 
119  // Define algorithm.
120  RCP<ROL::Algorithm<RealT> > algo;
121  algo = rcp( new ROL::Algorithm<RealT>(stepname,*parlist) );
122 
123  algo->run(problem,true,*outStream);
124 
125 
126 
127  *outStream << std::endl << std::setw(20) << "Computed Minimizer" << std::endl;
128  for( int i=0;i<xopt_dim;++i ) {
129  *outStream << std::setw(20) << (*xopt_rcp)[i] << std::endl;
130  }
131 
132  *outStream << "Exact minimizers: x* = (a,b,c), (a,-b,-c), (-a,b,-c), (-a,-b,c)" << std::endl;
133  *outStream << "Where a=4, b=" << 2*std::sqrt(2) << ", and c=2" << std::endl;
134 
135  }
136  catch (std::logic_error err) {
137  *outStream << err.what() << "\n";
138  errorFlag = -1000;
139  }; // end try
140 
141  if (errorFlag != 0)
142  std::cout << "End Result: TEST FAILED\n";
143  else
144  std::cout << "End Result: TEST PASSED\n";
145 
146  return 0;
147 
148 
149 
150 }
Contains definitions for W. Hock and K. Schittkowski 32nd test problem which contains only inequality...
double RealT
Definition: test_08.cpp:52
Provides the std::vector implementation of the ROL::Vector interface.
int main(int argc, char *argv[])
Definition: test_08.cpp:54
Provides an interface to run optimization algorithms.
double RealT