ROL
test_07.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_HS32.hpp"
50 #include "ROL_Algorithm.hpp"
51 
52 
53 typedef double RealT;
54 
55 int main(int argc, char *argv[]) {
56 
57  using Teuchos::RCP;
58  using Teuchos::rcp;
59 
60  typedef std::vector<RealT> vec;
61  typedef ROL::StdVector<RealT> SV;
62  typedef RCP<ROL::Vector<RealT> > RCPV;
63 
64 // typedef ROL::PartitionedVector<RealT> PV;
65 
66 
67  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
68 
69  int iprint = argc - 1;
70  RCP<std::ostream> outStream;
71  Teuchos::oblackholestream bhs; // outputs nothing
72  if (iprint > 0)
73  outStream = rcp(&std::cout, false);
74  else
75  outStream = rcp(&bhs, false);
76 
77  int errorFlag = 0;
78 
79  try {
80 
81  int xopt_dim = 3; // Dimension of optimization vectors
82  int ce_dim = 1; // Dimension of equality constraint
83  int ci_dim = 4; // Dimension of inequality constraint
84 
85  // Exact solution
86  RCP<vec> x_exact_rcp = rcp( new vec(xopt_dim,0.0) );
87  (*x_exact_rcp)[xopt_dim-1] = 1.0;
88 
89  RCP<vec> xopt_rcp = rcp( new vec(xopt_dim,0.0) ); // Optimization variables
90 
91  RCP<vec> le_rcp = rcp( new vec(ce_dim,0.0) ); // Equality multiplier
92  RCP<vec> li_rcp = rcp( new vec(ci_dim,0.0) ); // Inequality multiplier
93 
94  // Feasible initial guess
95  (*xopt_rcp)[0] = 0.1;
96  (*xopt_rcp)[1] = 0.7;
97  (*xopt_rcp)[2] = 0.2;
98 
99  RCPV xopt = rcp( new SV(xopt_rcp) );
100  RCPV le = rcp( new SV(le_rcp) );
101  RCPV li = rcp( new SV(li_rcp) );
102 
106 
107  RCP<ROL::Objective<RealT> > obj_hs32 = rcp( new Objective_HS32<RealT> );
108  RCP<ROL::EqualityConstraint<RealT> > eqcon_hs32 = rcp( new EqualityConstraint_HS32<RealT> );
109  RCP<ROL::InequalityConstraint<RealT> > incon_hs32 = rcp( new InequalityConstraint_HS32<RealT> );
110 
111  RCP<Teuchos::ParameterList> parlist = rcp(new Teuchos::ParameterList);
112  std::string stepname = "Interior Point";
113 
114  RealT mu = 0.1; // Initial penalty parameter
115  RealT factor = 0.1; // Penalty reduction factor
116 
117  // Set solver parameters
118  parlist->sublist("Step").sublist("Interior Point").set("Initial Barrier Penalty",mu);
119  parlist->sublist("Step").sublist("Interior Point").set("Minimium Barrier Penalty",1e-8);
120  parlist->sublist("Step").sublist("Interior Point").set("Barrier Penalty Reduction Factor",factor);
121  parlist->sublist("Step").sublist("Interior Point").set("Subproblem Iteration Limit",30);
122 
123  parlist->sublist("Step").sublist("Composite Step").sublist("Optimality System Solver").set("Nominal Relative Tolerance",1.e-4);
124  parlist->sublist("Step").sublist("Composite Step").sublist("Optimality System Solver").set("Fix Tolerance",true);
125  parlist->sublist("Step").sublist("Composite Step").sublist("Tangential Subproblem Solver").set("Iteration Limit",20);
126  parlist->sublist("Step").sublist("Composite Step").sublist("Tangential Subproblem Solver").set("Relative Tolerance",1e-2);
127  parlist->sublist("Step").sublist("Composite Step").set("Output Level",0);
128 
129  parlist->sublist("Status Test").set("Gradient Tolerance",1.e-12);
130  parlist->sublist("Status Test").set("Constraint Tolerance",1.e-8);
131  parlist->sublist("Status Test").set("Step Tolerance",1.e-8);
132  parlist->sublist("Status Test").set("Iteration Limit",100);
133 
134  ROL::OptimizationProblem<RealT> problem( obj_hs32, xopt, eqcon_hs32, le, incon_hs32, li, parlist);
135 
136  // Define algorithm.
137  RCP<ROL::Algorithm<RealT> > algo;
138  algo = rcp( new ROL::Algorithm<RealT>(stepname,*parlist) );
139 
140  algo->run(problem,true,*outStream);
141 
142  *outStream << std::endl << std::setw(20) << "Computed Minimizer" << std::setw(20) << "Exact Minimizer" << std::endl;
143  for( int i=0;i<xopt_dim;++i ) {
144  *outStream << std::setw(20) << (*xopt_rcp)[i] << std::setw(20) << (*x_exact_rcp)[i] << std::endl;
145  }
146  }
147  catch (std::logic_error err) {
148  *outStream << err.what() << "\n";
149  errorFlag = -1000;
150  }; // end try
151 
152  if (errorFlag != 0)
153  std::cout << "End Result: TEST FAILED\n";
154  else
155  std::cout << "End Result: TEST PASSED\n";
156 
157  return 0;
158 }
159 
double RealT
Definition: test_07.cpp:53
Provides the std::vector implementation of the ROL::Vector interface.
Provides an interface to run optimization algorithms.
int main(int argc, char *argv[])
Definition: test_07.cpp:55
Contains definitions for W. Hock and K. Schittkowski 32nd test problem which contains both inequality...
double RealT