57 using Teuchos::dyn_cast;
58 const SV &xs = dyn_cast<
const SV>(x);
59 Teuchos::RCP<const std::vector<Real> > x_rcp = xs.
getVector();
61 for(
int i=0;i<xs.dimension();++i) {
62 std::cout << (*x_rcp)[i] << std::endl;
69 typedef typename PV::size_type size_type;
70 size_type n =
static_cast<size_type
>(i);
71 using Teuchos::dyn_cast;
72 const PV &xp = dyn_cast<
const PV>(x);
78 int main(
int argc,
char *argv[]) {
83 typedef std::vector<RealT> vec;
85 typedef RCP<ROL::Vector<RealT> > RCPV;
90 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
92 int iprint = argc - 1;
93 RCP<std::ostream> outStream;
94 Teuchos::oblackholestream bhs;
96 outStream = rcp(&std::cout,
false);
98 outStream = rcp(&bhs,
false);
108 RCP<vec> xopt_rcp = rcp(
new vec(xopt_dim,0.0) );
109 RCP<vec> dopt_rcp = rcp(
new vec(xopt_dim,0.0) );
110 RCP<vec> vopt_rcp = rcp(
new vec(xopt_dim,0.0) );
112 RCP<vec> vec_rcp = rcp(
new vec(ce_dim,1.0) );
113 RCP<vec> vel_rcp = rcp(
new vec(ce_dim,1.0) );
115 RCP<vec> vic_rcp = rcp(
new vec(ci_dim,0.0) );
116 RCP<vec> vil_rcp = rcp(
new vec(ci_dim,0.0) );
119 RCP<vec> xs_rcp = rcp(
new vec(ci_dim,1.0) );
120 RCP<vec> vs_rcp = rcp(
new vec(ci_dim,0.0) );
121 RCP<vec> ds_rcp = rcp(
new vec(ci_dim,0.0) );
124 (*xopt_rcp)[0] = 0.1;
125 (*xopt_rcp)[1] = 0.7;
126 (*xopt_rcp)[2] = 0.2;
128 RealT left = -1e0, right = 1e0;
129 for (
int i=0; i<xopt_dim; i++) {
130 (*dopt_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
131 (*vopt_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
134 for (
int i=0; i<ci_dim; i++) {
135 (*vic_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
136 (*vil_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
137 (*vs_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
138 (*ds_rcp)[i] = ( (
RealT)rand() / (
RealT)RAND_MAX ) * (right - left) + left;
141 RCPV xopt = rcp(
new SV(xopt_rcp) );
142 RCPV dopt = rcp(
new SV(dopt_rcp) );
143 RCPV vopt = rcp(
new SV(vopt_rcp) );
144 RCPV vec = rcp(
new SV(vec_rcp) );
145 RCPV vel = rcp(
new SV(vel_rcp) );
146 RCPV vic = rcp(
new SV(vic_rcp) );
147 RCPV vil = rcp(
new SV(vil_rcp) );
148 RCPV xs = rcp(
new SV(xs_rcp) );
149 RCPV vs = rcp(
new SV(vs_rcp) );
150 RCPV ds = rcp(
new SV(ds_rcp) );
166 RCP<ROL::Objective<RealT> > ipobj =
169 RCP<ROL::EqualityConstraint<RealT> > eqcon_hs32 =
172 RCP<ROL::EqualityConstraint<RealT> > incon_hs32 =
176 RCP<ROL::EqualityConstraint<RealT> > ipcon =
179 *outStream <<
"\nChecking individual objectives and constraints separately\n" << std::endl;
181 *outStream <<
"\nObjective\n" << std::endl;
182 obj_hs32->checkGradient(*xopt,*dopt,
true,*outStream);
183 obj_hs32->checkHessVec(*xopt,*vopt,
true,*outStream);
186 *outStream <<
"\nEquality Constraint\n" << std::endl;
187 eqcon_hs32->checkApplyJacobian(*xopt,*vopt,*vec,
true,*outStream);
188 eqcon_hs32->checkApplyAdjointJacobian(*xopt,*vel,*vec,*xopt,
true,*outStream);
190 *outStream <<
"\nInequality Constraint\n" << std::endl;
191 incon_hs32->checkApplyJacobian(*xopt,*vopt,*vic,
true,*outStream);
192 incon_hs32->checkApplyAdjointJacobian(*xopt,*vil,*vic,*xopt,
true,*outStream);
193 incon_hs32->checkApplyAdjointHessian(*xopt,*vil,*dopt,*xopt,
true,*outStream);
196 *outStream <<
"\nCheck Interior Point objective\n" << std::endl;
197 ipobj->checkGradient(*x,*d,
true,*outStream);
198 ipobj->checkHessVec(*x,*v,
true,*outStream);
200 *outStream <<
"\nCheck Interior Point constraints\n" << std::endl;
201 ipcon->checkApplyJacobian(*x,*v,*vc,
true,*outStream);
202 ipcon->checkApplyAdjointJacobian(*x,*vl,*vc,*x,
true,*outStream);
203 ipcon->checkApplyAdjointHessian(*x,*vl,*d,*x,
true,*outStream);
206 catch (std::logic_error err) {
207 *outStream << err.what() <<
"\n";
212 std::cout <<
"End Result: TEST FAILED\n";
214 std::cout <<
"End Result: TEST PASSED\n";
Teuchos::RCP< const std::vector< Element > > getVector() const
Has both inequality and equality constraints. Treat inequality constraint as equality with slack vari...
Defines the linear algebra of vector space on a generic partitioned vector.
Teuchos::RCP< Vector< Real > > CreatePartitionedVector(Teuchos::RCP< Vector< Real > > &a)
Defines the linear algebra or vector space interface.
Provides the std::vector implementation of the ROL::Vector interface.
void print_vector(const ROL::Vector< Real > &x)
int main(int argc, char *argv[])
Adds barrier term to generic objective.
Contains definitions for W. Hock and K. Schittkowski 32nd test problem which contains both inequality...
Log barrier objective for interior point methods.
void print_subvector(const ROL::Vector< Real > &x, const int i)