ROL
step/test_09.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"
51 #include "ROL_RandomVector.hpp"
52 #include "ROL_GMRES.hpp"
53 
54 //template<class Real>
55 
56 
57 
58 typedef double RealT;
59 
60 int main(int argc, char *argv[]) {
61 
62  typedef std::vector<RealT> vector;
63  typedef ROL::Vector<RealT> V;
64  typedef ROL::StdVector<RealT> SV;
65 // typedef ROL::PartitionedVector<RealT> PV;
66 
67  typedef typename vector::size_type uint;
68 
69 
70  using Teuchos::RCP;
71  using Teuchos::rcp;
72 
73  Teuchos::GlobalMPISession mpiSession(&argc, &argv);
74 
75  int iprint = argc - 1;
76  RCP<std::ostream> outStream;
77  Teuchos::oblackholestream bhs; // outputs nothing
78  if (iprint > 0)
79  outStream = rcp(&std::cout, false);
80  else
81  outStream = rcp(&bhs, false);
82 
83  int errorFlag = 0;
84 
85  try {
86 
87  uint xo_dim = 3; // Dimension of optimization vectors
88  uint ce_dim = 1; // Dimension of equality constraint
89  uint ci_dim = 4; // Dimension of inequality constraint
90 
91  RealT left = -1.0;
92  RealT right = 1.0;
93 
94  // ----[ Full primal-dual vector ]----------------
95 
96  RCP<vector> xo_rcp = rcp( new vector(xo_dim,0.0) ); // opt
97  RCP<vector> xs_rcp = rcp( new vector(ci_dim,0.0) ); // slack
98  RCP<vector> xe_rcp = rcp( new vector(ce_dim,0.0) ); // equality multipliers
99  RCP<vector> xi_rcp = rcp( new vector(ci_dim,0.0) ); // inequality multipliers
100 
101  RCP<V> xo = rcp( new SV(xo_rcp) );
102  RCP<V> xs = rcp( new SV(xs_rcp) );
103  RCP<V> xe = rcp( new SV(xe_rcp) );
104  RCP<V> xi = rcp( new SV(xi_rcp) );
105 
106  ROL::RandomizeVector(*xo,left,right);
107  ROL::RandomizeVector(*xs,left,right);
108  ROL::RandomizeVector(*xe,left,right);
109  ROL::RandomizeVector(*xi,left,right);
110 
111  RCP<V> x = ROL::CreatePartitionedVector( xo, xs, xe, xi );
112 
113 
114  // ----[ Full primal-dual direction vector ]------
115 
116  RCP<vector> vo_rcp = rcp( new vector(xo_dim,0.0) ); // opt
117  RCP<vector> vs_rcp = rcp( new vector(ci_dim,0.0) ); // slack
118  RCP<vector> ve_rcp = rcp( new vector(ce_dim,0.0) ); // equality multipliers
119  RCP<vector> vi_rcp = rcp( new vector(ci_dim,0.0) ); // inequality multipliers
120 
121  RCP<V> vo = rcp( new SV(vo_rcp) );
122  RCP<V> vs = rcp( new SV(vs_rcp) );
123  RCP<V> ve = rcp( new SV(ve_rcp) );
124  RCP<V> vi = rcp( new SV(vi_rcp) );
125 
126  ROL::RandomizeVector(*vo,left,right);
127  ROL::RandomizeVector(*vs,left,right);
128  ROL::RandomizeVector(*ve,left,right);
129  ROL::RandomizeVector(*vi,left,right);
130 
131  RCP<V> v = ROL::CreatePartitionedVector( vo, vs, ve, vi );
132 
133 
134  // ----[ Full primal-dual residual vector ]------
135 
136  RCP<vector> ro_rcp = rcp( new vector(xo_dim,0.0) ); // opt
137  RCP<vector> rs_rcp = rcp( new vector(ci_dim,0.0) ); // slack
138  RCP<vector> re_rcp = rcp( new vector(ce_dim,0.0) ); // equality multipliers
139  RCP<vector> ri_rcp = rcp( new vector(ci_dim,0.0) ); // inequality multipliers
140 
141  RCP<V> ro = rcp( new SV(vo_rcp) );
142  RCP<V> rs = rcp( new SV(vs_rcp) );
143  RCP<V> re = rcp( new SV(ve_rcp) );
144  RCP<V> ri = rcp( new SV(vi_rcp) );
145 
146  ROL::RandomizeVector(*ro,left,right);
147  ROL::RandomizeVector(*rs,left,right);
148  ROL::RandomizeVector(*re,left,right);
149  ROL::RandomizeVector(*ri,left,right);
150 
151  RCP<V> r = ROL::CreatePartitionedVector( ro, rs, re, ri );
152 
153  // ----[ Primal-dual constraint ]-------
154 
155  RCP<ROL::Objective<RealT> > obj_hs32 =
157 
158  RCP<ROL::EqualityConstraint<RealT> > eqcon_hs32 =
160 
161  RCP<ROL::EqualityConstraint<RealT> > incon_hs32 =
163 
164 
165  *outStream << "Performing finite difference check on Primal-Dual KKT system"
166  << std::endl;
167 
169 
170  PrimalDualResidual<RealT> con(obj_hs32,eqcon_hs32,incon_hs32, *x);
171 
172  con.checkApplyJacobian(*x,*v,*r,true,*outStream);
173 
174  }
175 
176  catch (std::logic_error err) {
177  *outStream << err.what() << "\n";
178  errorFlag = -1000;
179  }; // end try
180 
181  if (errorFlag != 0)
182  std::cout << "End Result: TEST FAILED\n";
183  else
184  std::cout << "End Result: TEST PASSED\n";
185 
186 
187  return 0;
188 }
189 
190 
double RealT
int main(int argc, char *argv[])
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].
Teuchos::RCP< Vector< Real > > CreatePartitionedVector(const Teuchos::RCP< Vector< Real > > &a)
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
Express the Primal-Dual Interior Point gradient as an equality constraint.
Provides the std::vector implementation of the ROL::Vector interface.
Contains definitions for W. Hock and K. Schittkowski 32nd test problem which contains both inequality...
double RealT