ROL
step/test_10.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 // Drew Kouri (dpkouri@sandia.gov) and
39 // Denis Ridzal (dridzal@sandia.gov)
40 //
41 // ************************************************************************
42 // @HEADER
43 
48 #define USE_HESSVEC 1
49 
50 #include "ROL_TestObjectives.hpp"
51 #include "ROL_Algorithm.hpp"
52 #include "Teuchos_oblackholestream.hpp"
53 #include "Teuchos_GlobalMPISession.hpp"
54 #include "Teuchos_XMLParameterListHelpers.hpp"
55 
56 #include <iostream>
57 
58 typedef double RealT;
59 
60 int main(int argc, char *argv[]) {
61 
62  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
63 
64  // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided.
65  int iprint = argc - 1;
66  Teuchos::RCP<std::ostream> outStream;
67  Teuchos::oblackholestream bhs; // outputs nothing
68  if (iprint > 0)
69  outStream = Teuchos::rcp(&std::cout, false);
70  else
71  outStream = Teuchos::rcp(&bhs, false);
72 
73  int errorFlag = 0;
74 
75  // *** Test body.
76 
77  try {
78  // Get Objective Function
79  Teuchos::RCP<ROL::Vector<RealT> > x0, z;
80  Teuchos::RCP<ROL::Objective<RealT> > obj;
81  Teuchos::RCP<ROL::BoundConstraint<RealT> > con;
82  ROL::getTestObjectives<RealT>(obj,con,x0,z,ROL::TESTOPTPROBLEM_HS38);
83  Teuchos::RCP<ROL::Vector<RealT> > x = x0->clone();;
84  x->set(*x0);
85  // Parse input
86  std::string filename = "input.xml";
87  Teuchos::RCP<Teuchos::ParameterList> parlist = Teuchos::rcp( new Teuchos::ParameterList() );
88  Teuchos::updateParametersFromXmlFile( filename, parlist.ptr() );
89  parlist->sublist("General").set("Inexact Hessian-Times-A-Vector",true);
90 #if USE_HESSVEC
91  parlist->sublist("General").set("Inexact Hessian-Times-A-Vector",false);
92 #endif
93 
94  RealT mu = 0.1; // Initial penalty parameter
95  RealT factor = 0.1; // Penalty reduction factor
96 
97  // Set solver parameters
98  parlist->sublist("Step").set("Type","Interior Point");
99  parlist->sublist("Step").sublist("Interior Point").set("Initial Barrier Penalty",mu);
100  parlist->sublist("Step").sublist("Interior Point").set("Minimum Barrier Penalty",1e-8);
101  parlist->sublist("Step").sublist("Interior Point").set("Barrier Penalty Reduction Factor",factor);
102  parlist->sublist("Step").sublist("Interior Point").set("Subproblem Iteration Limit",30);
103 
104  parlist->sublist("Step").sublist("Composite Step").sublist("Optimality System Solver").set("Nominal Relative Tolerance",1.e-4);
105  parlist->sublist("Step").sublist("Composite Step").sublist("Optimality System Solver").set("Fix Tolerance",true);
106  parlist->sublist("Step").sublist("Composite Step").sublist("Tangential Subproblem Solver").set("Iteration Limit",20);
107  parlist->sublist("Step").sublist("Composite Step").sublist("Tangential Subproblem Solver").set("Relative Tolerance",1e-2);
108  parlist->sublist("Step").sublist("Composite Step").set("Output Level",0);
109 
110  parlist->sublist("Status Test").set("Gradient Tolerance",1.e-12);
111  parlist->sublist("Status Test").set("Constraint Tolerance",1.e-8);
112  parlist->sublist("Status Test").set("Step Tolerance",1.e-8);
113  parlist->sublist("Status Test").set("Iteration Limit",100);
114 
115  // Solve optimization problem with interior points
116  ROL::OptimizationProblem<RealT> optProb(obj,x,con,parlist);
117  ROL::Algorithm<RealT> algo("Interior Point",*parlist,false);
118  algo.run(optProb, true, *outStream);
119 
120  // Compute Error
121  z->axpy(-1.0,*x);
122  *outStream << std::endl << "Norm of Error: " << z->norm() << std::endl;
123  }
124  catch (std::logic_error err) {
125  *outStream << err.what() << std::endl;
126  errorFlag = -1000;
127  }; // end try
128 
129  if (errorFlag != 0)
130  std::cout << "End Result: TEST FAILED" << std::endl;
131  else
132  std::cout << "End Result: TEST PASSED" << std::endl;
133 
134  return 0;
135 
136 }
137 
double RealT
Contains definitions of test objective functions.
int main(int argc, char *argv[])
Provides an interface to run optimization algorithms.
virtual std::vector< std::string > run(Vector< Real > &x, Objective< Real > &obj, bool print=false, std::ostream &outStream=std::cout)
Run algorithm on unconstrained problems (Type-U). This is the primary Type-U interface.
double RealT