ROL
step/test_09.cpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // Rapid Optimization Library (ROL) Package
4 //
5 // Copyright 2014 NTESS and the ROL contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
14 #include "Teuchos_GlobalMPISession.hpp"
15 
16 #include "ROL_HS32.hpp"
17 #include "ROL_InteriorPointPrimalDualResidual.hpp"
18 #include "ROL_RandomVector.hpp"
19 #include "ROL_GMRES.hpp"
20 
21 //template<class Real>
22 
23 
24 
25 typedef double RealT;
26 
27 int main(int argc, char *argv[]) {
28 
29  typedef std::vector<RealT> vector;
30  typedef ROL::Vector<RealT> V;
31  typedef ROL::StdVector<RealT> SV;
32 // typedef ROL::PartitionedVector<RealT> PV;
33 
34  typedef typename vector::size_type uint;
35 
36 
37 
38 
39 
40  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
41 
42  int iprint = argc - 1;
43  ROL::Ptr<std::ostream> outStream;
44  ROL::nullstream bhs; // outputs nothing
45  if (iprint > 0)
46  outStream = ROL::makePtrFromRef(std::cout);
47  else
48  outStream = ROL::makePtrFromRef(bhs);
49 
50  int errorFlag = 0;
51 
52  try {
53 
54  uint xo_dim = 3; // Dimension of optimization vectors
55  uint ce_dim = 1; // Dimension of equality constraint
56  uint ci_dim = 4; // Dimension of inequality constraint
57 
58  RealT left = -1.0;
59  RealT right = 1.0;
60 
61  // ----[ Full primal-dual vector ]----------------
62 
63  ROL::Ptr<vector> xo_ptr = ROL::makePtr<vector>(xo_dim,0.0); // opt
64  ROL::Ptr<vector> xs_ptr = ROL::makePtr<vector>(ci_dim,0.0); // slack
65  ROL::Ptr<vector> xe_ptr = ROL::makePtr<vector>(ce_dim,0.0); // equality multipliers
66  ROL::Ptr<vector> xi_ptr = ROL::makePtr<vector>(ci_dim,0.0); // inequality multipliers
67 
68  ROL::Ptr<V> xo = ROL::makePtr<SV>(xo_ptr);
69  ROL::Ptr<V> xs = ROL::makePtr<SV>(xs_ptr);
70  ROL::Ptr<V> xe = ROL::makePtr<SV>(xe_ptr);
71  ROL::Ptr<V> xi = ROL::makePtr<SV>(xi_ptr);
72 
73  ROL::RandomizeVector(*xo,left,right);
74  ROL::RandomizeVector(*xs,left,right);
75  ROL::RandomizeVector(*xe,left,right);
76  ROL::RandomizeVector(*xi,left,right);
77 
78  ROL::Ptr<V> x = ROL::CreatePartitionedVector( xo, xs, xe, xi );
79 
80 
81  // ----[ Full primal-dual direction vector ]------
82 
83  ROL::Ptr<vector> vo_ptr = ROL::makePtr<vector>(xo_dim,0.0); // opt
84  ROL::Ptr<vector> vs_ptr = ROL::makePtr<vector>(ci_dim,0.0); // slack
85  ROL::Ptr<vector> ve_ptr = ROL::makePtr<vector>(ce_dim,0.0); // equality multipliers
86  ROL::Ptr<vector> vi_ptr = ROL::makePtr<vector>(ci_dim,0.0); // inequality multipliers
87 
88  ROL::Ptr<V> vo = ROL::makePtr<SV>(vo_ptr);
89  ROL::Ptr<V> vs = ROL::makePtr<SV>(vs_ptr);
90  ROL::Ptr<V> ve = ROL::makePtr<SV>(ve_ptr);
91  ROL::Ptr<V> vi = ROL::makePtr<SV>(vi_ptr);
92 
93  ROL::RandomizeVector(*vo,left,right);
94  ROL::RandomizeVector(*vs,left,right);
95  ROL::RandomizeVector(*ve,left,right);
96  ROL::RandomizeVector(*vi,left,right);
97 
98  ROL::Ptr<V> v = ROL::CreatePartitionedVector( vo, vs, ve, vi );
99 
100 
101  // ----[ Full primal-dual residual vector ]------
102 
103  ROL::Ptr<vector> ro_ptr = ROL::makePtr<vector>(xo_dim,0.0); // opt
104  ROL::Ptr<vector> rs_ptr = ROL::makePtr<vector>(ci_dim,0.0); // slack
105  ROL::Ptr<vector> re_ptr = ROL::makePtr<vector>(ce_dim,0.0); // equality multipliers
106  ROL::Ptr<vector> ri_ptr = ROL::makePtr<vector>(ci_dim,0.0); // inequality multipliers
107 
108  ROL::Ptr<V> ro = ROL::makePtr<SV>(vo_ptr);
109  ROL::Ptr<V> rs = ROL::makePtr<SV>(vs_ptr);
110  ROL::Ptr<V> re = ROL::makePtr<SV>(ve_ptr);
111  ROL::Ptr<V> ri = ROL::makePtr<SV>(vi_ptr);
112 
113  ROL::RandomizeVector(*ro,left,right);
114  ROL::RandomizeVector(*rs,left,right);
115  ROL::RandomizeVector(*re,left,right);
116  ROL::RandomizeVector(*ri,left,right);
117 
118  ROL::Ptr<V> r = ROL::CreatePartitionedVector( ro, rs, re, ri );
119 
120  // ----[ Primal-dual constraint ]-------
121 
122  ROL::Ptr<ROL::Objective<RealT> > obj_hs32 =
123  ROL::makePtr<ROL::ZOO::Objective_HS32<RealT>>();
124 
125  ROL::Ptr<ROL::EqualityConstraint<RealT> > eqcon_hs32 =
126  ROL::makePtr<ROL::ZOO::EqualityConstraint_HS32<RealT>>();
127 
128  ROL::Ptr<ROL::EqualityConstraint<RealT> > incon_hs32 =
129  ROL::makePtr<ROL::ZOO::InequalityConstraint_HS32<RealT>>();
130 
131 
132  *outStream << "Performing finite difference check on Primal-Dual KKT system"
133  << std::endl;
134 
136 
137  PrimalDualResidual<RealT> con(obj_hs32,eqcon_hs32,incon_hs32, *x);
138 
139  con.checkApplyJacobian(*x,*v,*r,true,*outStream);
140 
141  }
142 
143  catch (std::logic_error& err) {
144  *outStream << err.what() << "\n";
145  errorFlag = -1000;
146  }; // end try
147 
148  if (errorFlag != 0)
149  std::cout << "End Result: TEST FAILED\n";
150  else
151  std::cout << "End Result: TEST PASSED\n";
152 
153 
154  return 0;
155 }
156 
157 
typename PV< Real >::size_type size_type
ROL::Ptr< Vector< Real > > CreatePartitionedVector(const ROL::Ptr< Vector< Real >> &a)
void RandomizeVector(Vector< Real > &x, const Real &lower=0.0, const Real &upper=1.0)
Fill a ROL::Vector with uniformly-distributed random numbers in the interval [lower,upper].
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
Vector< Real > V
basic_nullstream< char, std::char_traits< char >> nullstream
Definition: ROL_Stream.hpp:36
Express the Primal-Dual Interior Point gradient as an equality constraint.
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...
int main(int argc, char *argv[])