69 #include "Teuchos_GlobalMPISession.hpp"
73 int main(
int argc,
char *argv[]) {
75 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
79 int iprint = argc - 1;
80 ROL::Ptr<std::ostream> outStream;
83 outStream = ROL::makePtrFromRef(std::cout);
85 outStream = ROL::makePtrFromRef(bhs);
90 RealT tol = 1e4*std::sqrt(ROL::ROL_EPSILON<RealT>());
91 ROL::ParameterList list;
92 list.sublist(
"Status Test").set(
"Gradient Tolerance",1e-12);
93 list.sublist(
"Status Test").set(
"Constraint Tolerance",1e-12);
94 list.sublist(
"Status Test").set(
"Step Tolerance",1e-14);
95 list.sublist(
"Step").set(
"Type",
"Trust Region");
96 list.sublist(
"Step").sublist(
"Trust Region").set(
"Subproblem Solver",
"Truncated CG");
97 list.sublist(
"Step").sublist(
"Augmented Lagrangian").set(
"Print Intermediate Optimization History",
true);
98 ROL::Ptr<ROL::Vector<RealT>> sol, mul, s, ds, Ps, imul, c;
99 ROL::Ptr<ROL::Objective<RealT>> obj, tobj;
100 ROL::Ptr<ROL::Constraint<RealT>> con, icon, tcon;
101 ROL::Ptr<ROL::BoundConstraint<RealT>> ibnd;
102 ROL::Ptr<ROL::ExplicitLinearConstraint<RealT>> elc;
103 ROL::Ptr<ROL::OptimizationProblem<RealT>> problem;
104 ROL::Ptr<ROL::OptimizationSolver<RealT>> solver;
105 std::vector<RealT> data;
106 RealT e1(0), e2(0), e3(0), e4(0), e5(0), err(0);
108 *outStream <<
"Hock and Schittkowski Problem #9" << std::endl << std::endl;
115 elc = ROL::makePtr<ROL::ExplicitLinearConstraint<RealT>>(con,obj,sol,mul);
116 tobj = elc->getTransformedObjective();
117 s = sol->clone(); s->randomize();
118 ds = sol->clone(); ds->randomize();
120 obj->checkGradient(*s,*ds,
true,*outStream);
121 obj->checkHessVec(*s,*ds,
true,*outStream);
122 tobj->checkGradient(*s,*ds,
true,*outStream);
123 tobj->checkHessVec(*s,*ds,
true,*outStream);
126 problem = ROL::makePtr<ROL::OptimizationProblem<RealT>>(tobj,s);
127 solver = ROL::makePtr<ROL::OptimizationSolver<RealT>>(*problem,list);
128 solver->solve(*outStream);
132 Ps->plus(*elc->getFeasibleVector());
134 data = *ROL::staticPtrCast<ROL::StdVector<RealT>>(Ps)->getVector();
135 e1 = (data[0]+
static_cast<RealT>(3))/
static_cast<RealT>(12);
136 e2 = (data[1]+
static_cast<RealT>(4))/
static_cast<RealT>(16);
137 *outStream <<
" x1 = " << data[0] <<
" x2 = " << data[1] << std::endl;
138 err = std::max(std::abs(e1-std::round(e1)),std::abs(e2-std::round(e2)));
139 *outStream <<
" Max-Error = " << err << std::endl;
140 errorFlag = (err > tol ? 1 : 0);
142 *outStream << std::endl <<
"Hock and Schittkowski Problem #28" << std::endl << std::endl;
149 elc = ROL::makePtr<ROL::ExplicitLinearConstraint<RealT>>(con,obj,sol,mul);
150 tobj = elc->getTransformedObjective();
151 s = sol->clone(); s->randomize();
152 ds = sol->clone(); ds->randomize();
154 obj->checkGradient(*s,*ds,
true,*outStream);
155 obj->checkHessVec(*s,*ds,
true,*outStream);
156 tobj->checkGradient(*s,*ds,
true,*outStream);
157 tobj->checkHessVec(*s,*ds,
true,*outStream);
160 problem = ROL::makePtr<ROL::OptimizationProblem<RealT>>(tobj,s);
161 solver = ROL::makePtr<ROL::OptimizationSolver<RealT>>(*problem,list);
162 solver->solve(*outStream);
166 Ps->plus(*elc->getFeasibleVector());
168 data = *ROL::staticPtrCast<ROL::StdVector<RealT>>(Ps)->getVector();
169 e1 = (data[0]-
static_cast<RealT>(0.5));
170 e2 = (data[1]+
static_cast<RealT>(0.5));
171 e3 = (data[2]-
static_cast<RealT>(0.5));
172 *outStream <<
" x1 = " << data[0] <<
" x2 = " << data[1] <<
" x3 = " << data[2] << std::endl;
173 err = std::max(std::max(std::abs(e1),std::abs(e2)),std::abs(e3));
174 *outStream <<
" Max-Error = " << err << std::endl;
175 errorFlag += (err > tol ? 1 : 0);
177 *outStream << std::endl <<
"Hock and Schittkowski Problem #48" << std::endl << std::endl;
184 elc = ROL::makePtr<ROL::ExplicitLinearConstraint<RealT>>(con,obj,sol,mul);
185 tobj = elc->getTransformedObjective();
186 s = sol->clone(); s->randomize();
187 ds = sol->clone(); ds->randomize();
189 obj->checkGradient(*s,*ds,
true,*outStream);
190 obj->checkHessVec(*s,*ds,
true,*outStream);
191 tobj->checkGradient(*s,*ds,
true,*outStream);
192 tobj->checkHessVec(*s,*ds,
true,*outStream);
195 problem = ROL::makePtr<ROL::OptimizationProblem<RealT>>(tobj,s);
196 solver = ROL::makePtr<ROL::OptimizationSolver<RealT>>(*problem,list);
197 solver->solve(*outStream);
201 Ps->plus(*elc->getFeasibleVector());
203 data = *ROL::staticPtrCast<ROL::StdVector<RealT>>(Ps)->getVector();
204 e1 = (data[0]-
static_cast<RealT>(1));
205 e2 = (data[1]-
static_cast<RealT>(1));
206 e3 = (data[2]-
static_cast<RealT>(1));
207 e4 = (data[3]-
static_cast<RealT>(1));
208 e5 = (data[4]-
static_cast<RealT>(1));
209 *outStream <<
" x1 = " << data[0] <<
" x2 = " << data[1]
210 <<
" x3 = " << data[2] <<
" x4 = " << data[3]
211 <<
" x5 = " << data[4] << std::endl;
212 err = std::max(std::max(std::max(std::max(std::abs(e1),std::abs(e2)),std::abs(e3)),std::abs(e4)),std::abs(e5));
213 *outStream <<
" Max-Error = " << err << std::endl;
214 errorFlag += (err > tol ? 1 : 0);
216 *outStream << std::endl <<
"Hock and Schittkowski Problem #49" << std::endl << std::endl;
223 elc = ROL::makePtr<ROL::ExplicitLinearConstraint<RealT>>(con,obj,sol,mul);
224 tobj = elc->getTransformedObjective();
225 s = sol->clone(); s->randomize();
226 ds = sol->clone(); ds->randomize();
228 obj->checkGradient(*s,*ds,
true,*outStream);
229 obj->checkHessVec(*s,*ds,
true,*outStream);
230 tobj->checkGradient(*s,*ds,
true,*outStream);
231 tobj->checkHessVec(*s,*ds,
true,*outStream);
234 problem = ROL::makePtr<ROL::OptimizationProblem<RealT>>(tobj,s);
235 solver = ROL::makePtr<ROL::OptimizationSolver<RealT>>(*problem,list);
236 solver->solve(*outStream);
240 Ps->plus(*elc->getFeasibleVector());
242 data = *ROL::staticPtrCast<ROL::StdVector<RealT>>(Ps)->getVector();
243 e1 = (data[0]-
static_cast<RealT>(1));
244 e2 = (data[1]-
static_cast<RealT>(1));
245 e3 = (data[2]-
static_cast<RealT>(1));
246 e4 = (data[3]-
static_cast<RealT>(1));
247 e5 = (data[4]-
static_cast<RealT>(1));
248 *outStream <<
" x1 = " << data[0] <<
" x2 = " << data[1]
249 <<
" x3 = " << data[2] <<
" x4 = " << data[3]
250 <<
" x5 = " << data[4] << std::endl;
251 err = std::max(std::max(std::max(std::max(std::abs(e1),std::abs(e2)),std::abs(e3)),std::abs(e4)),std::abs(e5));
252 *outStream <<
" Max-Error = " << err << std::endl;
253 errorFlag += (err > tol ? 1 : 0);
255 *outStream << std::endl <<
"Hock and Schittkowski Problem #50" << std::endl << std::endl;
262 elc = ROL::makePtr<ROL::ExplicitLinearConstraint<RealT>>(con,obj,sol,mul);
263 tobj = elc->getTransformedObjective();
264 s = sol->clone(); s->randomize();
265 ds = sol->clone(); ds->randomize();
267 obj->checkGradient(*s,*ds,
true,*outStream);
268 obj->checkHessVec(*s,*ds,
true,*outStream);
269 tobj->checkGradient(*s,*ds,
true,*outStream);
270 tobj->checkHessVec(*s,*ds,
true,*outStream);
273 problem = ROL::makePtr<ROL::OptimizationProblem<RealT>>(tobj,s);
274 solver = ROL::makePtr<ROL::OptimizationSolver<RealT>>(*problem,list);
275 solver->solve(*outStream);
279 Ps->plus(*elc->getFeasibleVector());
281 data = *ROL::staticPtrCast<ROL::StdVector<RealT>>(Ps)->getVector();
282 e1 = (data[0]-
static_cast<RealT>(1));
283 e2 = (data[1]-
static_cast<RealT>(1));
284 e3 = (data[2]-
static_cast<RealT>(1));
285 e4 = (data[3]-
static_cast<RealT>(1));
286 e5 = (data[4]-
static_cast<RealT>(1));
287 *outStream <<
" x1 = " << data[0] <<
" x2 = " << data[1]
288 <<
" x3 = " << data[2] <<
" x4 = " << data[3]
289 <<
" x5 = " << data[4] << std::endl;
290 err = std::max(std::max(std::max(std::max(std::abs(e1),std::abs(e2)),std::abs(e3)),std::abs(e4)),std::abs(e5));
291 *outStream <<
" Max-Error = " << err << std::endl;
292 errorFlag += (err > tol ? 1 : 0);
294 *outStream << std::endl <<
"Hock and Schittkowski Problem #51" << std::endl << std::endl;
301 elc = ROL::makePtr<ROL::ExplicitLinearConstraint<RealT>>(con,obj,sol,mul);
302 tobj = elc->getTransformedObjective();
303 s = sol->clone(); s->randomize();
304 ds = sol->clone(); ds->randomize();
306 obj->checkGradient(*s,*ds,
true,*outStream);
307 obj->checkHessVec(*s,*ds,
true,*outStream);
308 tobj->checkGradient(*s,*ds,
true,*outStream);
309 tobj->checkHessVec(*s,*ds,
true,*outStream);
312 problem = ROL::makePtr<ROL::OptimizationProblem<RealT>>(tobj,s);
313 solver = ROL::makePtr<ROL::OptimizationSolver<RealT>>(*problem,list);
314 solver->solve(*outStream);
318 Ps->plus(*elc->getFeasibleVector());
320 data = *ROL::staticPtrCast<ROL::StdVector<RealT>>(Ps)->getVector();
321 e1 = (data[0]-
static_cast<RealT>(1));
322 e2 = (data[1]-
static_cast<RealT>(1));
323 e3 = (data[2]-
static_cast<RealT>(1));
324 e4 = (data[3]-
static_cast<RealT>(1));
325 e5 = (data[4]-
static_cast<RealT>(1));
326 *outStream <<
" x1 = " << data[0] <<
" x2 = " << data[1]
327 <<
" x3 = " << data[2] <<
" x4 = " << data[3]
328 <<
" x5 = " << data[4] << std::endl;
329 err = std::max(std::max(std::max(std::max(std::abs(e1),std::abs(e2)),std::abs(e3)),std::abs(e4)),std::abs(e5));
330 *outStream <<
" Max-Error = " << err << std::endl;
331 errorFlag += (err > tol ? 1 : 0);
333 *outStream << std::endl <<
"Hock and Schittkowski Problem #52" << std::endl << std::endl;
340 elc = ROL::makePtr<ROL::ExplicitLinearConstraint<RealT>>(con,obj,sol,mul);
341 tobj = elc->getTransformedObjective();
342 s = sol->clone(); s->randomize();
343 ds = sol->clone(); ds->randomize();
345 obj->checkGradient(*s,*ds,
true,*outStream);
346 obj->checkHessVec(*s,*ds,
true,*outStream);
347 tobj->checkGradient(*s,*ds,
true,*outStream);
348 tobj->checkHessVec(*s,*ds,
true,*outStream);
351 problem = ROL::makePtr<ROL::OptimizationProblem<RealT>>(tobj,s);
352 solver = ROL::makePtr<ROL::OptimizationSolver<RealT>>(*problem,list);
353 solver->solve(*outStream);
357 Ps->plus(*elc->getFeasibleVector());
359 data = *ROL::staticPtrCast<ROL::StdVector<RealT>>(Ps)->getVector();
360 e1 = (data[0]-
static_cast<RealT>(-33.0/349.0));
361 e2 = (data[1]-
static_cast<RealT>(11.0/349.0));
362 e3 = (data[2]-
static_cast<RealT>(180.0/349.0));
363 e4 = (data[3]-
static_cast<RealT>(-158.0/349.0));
364 e5 = (data[4]-
static_cast<RealT>(11.0/349.0));
365 *outStream <<
" x1 = " << data[0] <<
" x2 = " << data[1]
366 <<
" x3 = " << data[2] <<
" x4 = " << data[3]
367 <<
" x5 = " << data[4] << std::endl;
368 err = std::max(std::max(std::max(std::max(std::abs(e1),std::abs(e2)),std::abs(e3)),std::abs(e4)),std::abs(e5));
369 *outStream <<
" Max-Error = " << err << std::endl;
370 errorFlag += (err > tol ? 1 : 0);
372 *outStream << std::endl <<
"Hock and Schittkowski Problem #14" << std::endl << std::endl;
373 list.sublist(
"Step").set(
"Type",
"Moreau-Yosida Penalty");
383 elc = ROL::makePtr<ROL::ExplicitLinearConstraint<RealT>>(con,obj,icon,sol,mul);
384 tobj = elc->getTransformedObjective();
385 tcon = elc->getTransformedConstraint();
386 s = sol->clone(); s->randomize();
387 ds = sol->clone(); ds->randomize();
388 c = imul->clone(); c->randomize();
390 obj->checkGradient(*s,*ds,
true,*outStream);
391 obj->checkHessVec(*s,*ds,
true,*outStream);
392 tobj->checkGradient(*s,*ds,
true,*outStream);
393 tobj->checkHessVec(*s,*ds,
true,*outStream);
394 tcon->checkApplyJacobian(*s,*ds,*c,
true,*outStream);
395 tcon->checkApplyAdjointJacobian(*s,*c,*c,*ds,
true,*outStream);
396 tcon->checkApplyAdjointHessian(*s,*c,*ds,*s,
true,*outStream);
399 problem = ROL::makePtr<ROL::OptimizationProblem<RealT>>(tobj,s,tcon,imul,ibnd);
400 solver = ROL::makePtr<ROL::OptimizationSolver<RealT>>(*problem,list);
401 solver->solve(*outStream);
405 Ps->plus(*elc->getFeasibleVector());
407 data = *ROL::staticPtrCast<ROL::StdVector<RealT>>(Ps)->getVector();
408 e1 = (data[0]-
static_cast<RealT>(0.5 *(std::sqrt(7)-1.0)));
409 e2 = (data[1]-
static_cast<RealT>(0.25*(std::sqrt(7)+1.0)));
410 *outStream <<
" x1 = " << data[0] <<
" x2 = " << data[1] << std::endl;
411 err = std::max(std::abs(e1),std::abs(e2));
412 *outStream <<
" Max-Error = " << err << std::endl;
413 errorFlag += (err > tol ? 1 : 0);
415 *outStream << std::endl <<
"Hock and Schittkowski Problem #42" << std::endl << std::endl;
416 list.sublist(
"Step").set(
"Type",
"Composite Step");
425 elc = ROL::makePtr<ROL::ExplicitLinearConstraint<RealT>>(con,obj,icon,sol,mul);
426 tobj = elc->getTransformedObjective();
427 tcon = elc->getTransformedConstraint();
428 s = sol->clone(); s->randomize();
429 ds = sol->clone(); ds->randomize();
430 c = imul->clone(); c->randomize();
432 obj->checkGradient(*s,*ds,
true,*outStream);
433 obj->checkHessVec(*s,*ds,
true,*outStream);
434 tobj->checkGradient(*s,*ds,
true,*outStream);
435 tobj->checkHessVec(*s,*ds,
true,*outStream);
436 tcon->checkApplyJacobian(*s,*ds,*c,
true,*outStream);
437 tcon->checkApplyAdjointJacobian(*s,*c,*c,*ds,
true,*outStream);
438 tcon->checkApplyAdjointHessian(*s,*c,*ds,*s,
true,*outStream);
441 problem = ROL::makePtr<ROL::OptimizationProblem<RealT>>(tobj,s,tcon,imul);
442 solver = ROL::makePtr<ROL::OptimizationSolver<RealT>>(*problem,list);
443 solver->solve(*outStream);
447 Ps->plus(*elc->getFeasibleVector());
449 data = *ROL::staticPtrCast<ROL::StdVector<RealT>>(Ps)->getVector();
450 e1 = (data[0]-
static_cast<RealT>(2.0));
451 e2 = (data[1]-
static_cast<RealT>(2.0));
452 e3 = (data[2]-
static_cast<RealT>(0.6*std::sqrt(2.0)));
453 e4 = (data[3]-
static_cast<RealT>(0.8*std::sqrt(2.0)));
454 *outStream <<
" x1 = " << data[0] <<
" x2 = " << data[1]
455 <<
" x3 = " << data[2] <<
" x4 = " << data[3] << std::endl;
456 err = std::max(std::max(std::max(std::abs(e1),std::abs(e2)),std::abs(e3)),std::abs(e4));
457 *outStream <<
" Max-Error = " << err << std::endl;
458 errorFlag += (err > tol ? 1 : 0);
461 catch (std::logic_error& err) {
462 *outStream << err.what() <<
"\n";
467 std::cout <<
"End Result: TEST FAILED\n";
469 std::cout <<
"End Result: TEST PASSED\n";
Contains definitions for W. Hock and K. Schittkowski 14th test function.
Contains definitions for W. Hock and K. Schittkowski 28th test function.
Contains definitions for W. Hock and K. Schittkowski 42th test function.
Contains definitions for W. Hock and K. Schittkowski 48th test function.
Contains definitions for W. Hock and K. Schittkowski 49th test function.
Contains definitions for W. Hock and K. Schittkowski 50th test function.
Contains definitions for W. Hock and K. Schittkowski 51th test function.
Contains definitions for W. Hock and K. Schittkowski 52nd test function.
Contains definitions for W. Hock and K. Schittkowski 9th test function.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
Ptr< Objective< Real > > getObjective(void) const
Ptr< Constraint< Real > > getInequalityConstraint(void) const
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Ptr< Vector< Real > > getInequalityMultiplier(void) const
Ptr< BoundConstraint< Real > > getSlackBoundConstraint(void) const
Ptr< Vector< Real > > getInitialGuess(void) const
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Ptr< Vector< Real > > getInitialGuess(void) const
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Ptr< Objective< Real > > getObjective(void) const
Ptr< Objective< Real > > getObjective(void) const
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Ptr< Vector< Real > > getInitialGuess(void) const
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Ptr< Vector< Real > > getInitialGuess(void) const
Ptr< Objective< Real > > getObjective(void) const
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Ptr< Vector< Real > > getInitialGuess(void) const
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Ptr< Objective< Real > > getObjective(void) const
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Ptr< Objective< Real > > getObjective(void) const
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Ptr< Vector< Real > > getInitialGuess(void) const
Ptr< Objective< Real > > getObjective(void) const
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Ptr< Vector< Real > > getInitialGuess(void) const
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Ptr< Objective< Real > > getObjective(void) const
Ptr< Vector< Real > > getInitialGuess(void) const
Ptr< Vector< Real > > getEqualityMultiplier(void) const
Ptr< Vector< Real > > getInitialGuess(void) const
Ptr< Objective< Real > > getObjective(void) const
Ptr< Constraint< Real > > getEqualityConstraint(void) const
Ptr< Vector< Real > > getEqualityMultiplier(void) const
int main(int argc, char *argv[])
basic_nullstream< char, char_traits< char > > nullstream