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