ROL
dual-spaces/simple-eq-constr-1/example_01.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// Drew Kouri (dpkouri@sandia.gov) and
39// Denis Ridzal (dridzal@sandia.gov)
40//
41// ************************************************************************
42// @HEADER
43
50#include "ROL_Solver.hpp"
51#include "ROL_Stream.hpp"
52#include "Teuchos_GlobalMPISession.hpp"
53
54#include <iostream>
55//#include <fenv.h>
56
57typedef double RealT;
58
59/*** Declare four vector spaces. ***/
60
61// Forward declarations:
62
63template <class Real, class Element=Real>
64class OptStdVector; // Optimization space.
65
66template <class Real, class Element=Real>
67class OptDualStdVector; // Dual optimization space.
68
69template <class Real, class Element=Real>
70class ConStdVector; // Constraint space.
71
72template <class Real, class Element=Real>
73class ConDualStdVector; // Dual constraint space.
74
75// Vector space definitions:
76
77// Optimization space.
78template <class Real, class Element>
79class OptStdVector : public ROL::Vector<Real> {
80
81typedef std::vector<Element> vector;
83typedef typename vector::size_type uint;
84
85private:
86ROL::Ptr<std::vector<Element> > std_vec_;
87mutable ROL::Ptr<OptDualStdVector<Real> > dual_vec_;
88
89public:
90
91OptStdVector(const ROL::Ptr<std::vector<Element> > & std_vec) : std_vec_(std_vec), dual_vec_(ROL::nullPtr) {}
92
93void plus( const ROL::Vector<Real> &x ) {
94
95
96 ROL::Ptr<const vector> xp = dynamic_cast<const OptStdVector&>(x).getVector();
97
98 uint dimension = std_vec_->size();
99 for (uint i=0; i<dimension; i++) {
100 (*std_vec_)[i] += (*xp)[i];
101 }
102}
103
104void scale( const Real alpha ) {
105 uint dimension = std_vec_->size();
106 for (uint i=0; i<dimension; i++) {
107 (*std_vec_)[i] *= alpha;
108 }
109}
110
111Real dot( const ROL::Vector<Real> &x ) const {
112
113
114
115 ROL::Ptr<const vector> xp = dynamic_cast<const OptStdVector&>(x).getVector();
116 Real val = 0;
117
118 uint dimension = std_vec_->size();
119 for (uint i=0; i<dimension; i++) {
120 val += (*std_vec_)[i]*(*xp)[i];
121 }
122 return val;
123}
124
125Real norm() const {
126 Real val = 0;
127 val = std::sqrt( dot(*this) );
128 return val;
129}
130
131ROL::Ptr<ROL::Vector<Real> > clone() const {
132 return ROL::makePtr<OptStdVector>( ROL::makePtr<std::vector<Element>>(std_vec_->size()) );
133}
134
135ROL::Ptr<const std::vector<Element> > getVector() const {
136 return std_vec_;
137}
138
139ROL::Ptr<std::vector<Element> > getVector() {
140 return std_vec_;
141}
142
143ROL::Ptr<ROL::Vector<Real> > basis( const int i ) const {
144
145 ROL::Ptr<vector> e_ptr = ROL::makePtr<vector>(std_vec_->size(),0.0);
146 ROL::Ptr<V> e = ROL::makePtr<OptStdVector>( e_ptr );
147 (*e_ptr)[i] = 1.0;
148 return e;
149}
150
151int dimension() const {return static_cast<int>(std_vec_->size());}
152
153const ROL::Vector<Real> & dual() const {
154 dual_vec_ = ROL::makePtr<OptDualStdVector<Real>>( ROL::makePtr<std::vector<Element>>(*std_vec_) );
155 return *dual_vec_;
156}
157
158Real apply( const ROL::Vector<Real> &x ) const {
159 Real val = 0;
160
161 ROL::Ptr<const vector> xvalptr = dynamic_cast<const OptDualStdVector<Real,Element>&>(x).getVector();
162 uint dimension = std_vec_->size();
163 for (uint i=0; i<dimension; i++) {
164 val += (*std_vec_)[i]*(*xvalptr)[i];
165 }
166 return val;
167}
168
169}; // class OptStdVector
170
171
172// Dual optimization space.
173template <class Real, class Element>
174class OptDualStdVector : public ROL::Vector<Real> {
175
176typedef std::vector<Element> vector;
178typedef typename vector::size_type uint;
179
180private:
181ROL::Ptr<std::vector<Element> > std_vec_;
182mutable ROL::Ptr<OptStdVector<Real> > dual_vec_;
183
184public:
185
186OptDualStdVector(const ROL::Ptr<std::vector<Element> > & std_vec) : std_vec_(std_vec), dual_vec_(ROL::nullPtr) {}
187
188void plus( const ROL::Vector<Real> &x ) {
189
190 ROL::Ptr<const vector> xp = dynamic_cast<const OptDualStdVector&>(x).getVector();
191 uint dimension = std_vec_->size();
192 for (uint i=0; i<dimension; i++) {
193 (*std_vec_)[i] += (*xp)[i];
194 }
195}
196
197void scale( const Real alpha ) {
198 uint dimension = std_vec_->size();
199 for (uint i=0; i<dimension; i++) {
200 (*std_vec_)[i] *= alpha;
201 }
202}
203
204Real dot( const ROL::Vector<Real> &x ) const {
205
206 ROL::Ptr<const vector> xp = dynamic_cast<const OptDualStdVector&>(x).getVector();
207 Real val = 0;
208 uint dimension = std_vec_->size();
209 for (uint i=0; i<dimension; i++) {
210 val += (*std_vec_)[i]*(*xp)[i];
211 }
212 return val;
213}
214
215Real norm() const {
216 Real val = 0;
217 val = std::sqrt( dot(*this) );
218 return val;
219}
220
221ROL::Ptr<ROL::Vector<Real> > clone() const {
222 return ROL::makePtr<OptDualStdVector>( ROL::makePtr<std::vector<Element>>(std_vec_->size()) );
223}
224
225ROL::Ptr<const std::vector<Element> > getVector() const {
226 return std_vec_;
227}
228
229ROL::Ptr<std::vector<Element> > getVector() {
230 return std_vec_;
231}
232
233ROL::Ptr<ROL::Vector<Real> > basis( const int i ) const {
234
235 ROL::Ptr<vector> e_ptr = ROL::makePtr<vector>( std_vec_->size(), 0.0 );
236 ROL::Ptr<V> e = ROL::makePtr<OptDualStdVector>( e_ptr );
237 (*e_ptr)[i] = 1.0;
238 return e;
239}
240
241int dimension() const {return static_cast<int>(std_vec_->size());}
242
243const ROL::Vector<Real> & dual() const {
244 dual_vec_ = ROL::makePtr<OptStdVector<Real>>( ROL::makePtr<std::vector<Element>>(*std_vec_) );
245 return *dual_vec_;
246}
247
248Real apply( const ROL::Vector<Real> &x ) const {
249 Real val = 0;
250
251 ROL::Ptr<const vector> xvalptr = dynamic_cast<const OptStdVector<Real,Element>&>(x).getVector();
252 uint dimension = std_vec_->size();
253 for (uint i=0; i<dimension; i++) {
254 val += (*std_vec_)[i]*(*xvalptr)[i];
255 }
256 return val;
257}
258
259}; // class OptDualStdVector
260
261
262// Constraint space.
263template <class Real, class Element>
264class ConStdVector : public ROL::Vector<Real> {
265
266typedef std::vector<Element> vector;
268typedef typename vector::size_type uint;
269
270private:
271ROL::Ptr<std::vector<Element> > std_vec_;
272mutable ROL::Ptr<ConDualStdVector<Real> > dual_vec_;
273
274public:
275
276ConStdVector(const ROL::Ptr<std::vector<Element> > & std_vec) : std_vec_(std_vec), dual_vec_(ROL::nullPtr) {}
277
278void plus( const ROL::Vector<Real> &x ) {
279
280 ROL::Ptr<const vector> xp = dynamic_cast<const ConStdVector&>(x).getVector();
281 uint dimension = std_vec_->size();
282 for (uint i=0; i<dimension; i++) {
283 (*std_vec_)[i] += (*xp)[i];
284 }
285}
286
287void scale( const Real alpha ) {
288 uint dimension = std_vec_->size();
289 for (uint i=0; i<dimension; i++) {
290 (*std_vec_)[i] *= alpha;
291 }
292}
293
294Real dot( const ROL::Vector<Real> &x ) const {
295
296 ROL::Ptr<const vector> xp = dynamic_cast<const ConStdVector&>(x).getVector();
297 Real val = 0;
298 uint dimension = std_vec_->size();
299 for (uint i=0; i<dimension; i++) {
300 val += (*std_vec_)[i]*(*xp)[i];
301 }
302 return val;
303}
304
305Real norm() const {
306 Real val = 0;
307 val = std::sqrt( dot(*this) );
308 return val;
309}
310
311ROL::Ptr<ROL::Vector<Real> > clone() const {
312 return ROL::makePtr<ConStdVector>( ROL::makePtr<std::vector<Element>>(std_vec_->size()));
313}
314
315ROL::Ptr<const std::vector<Element> > getVector() const {
316 return std_vec_;
317}
318
319ROL::Ptr<std::vector<Element> > getVector() {
320 return std_vec_;
321}
322
323ROL::Ptr<ROL::Vector<Real> > basis( const int i ) const {
324
325 ROL::Ptr<vector> e_ptr = ROL::makePtr<vector>(std_vec_->size(), 0.0);
326 ROL::Ptr<V> e = ROL::makePtr<ConStdVector>( e_ptr );
327 (*e_ptr)[i] = 1.0;
328 return e;
329}
330
331int dimension() const {return static_cast<int>(std_vec_->size());}
332
333const ROL::Vector<Real> & dual() const {
334 dual_vec_ = ROL::makePtr<ConDualStdVector<Real>>( ROL::makePtr<std::vector<Element>>(*std_vec_) );
335 return *dual_vec_;
336}
337
338Real apply( const ROL::Vector<Real> &x ) const {
339 Real val = 0;
340
341 ROL::Ptr<const vector> xvalptr = dynamic_cast<const ConDualStdVector<Real,Element>&>(x).getVector();
342 uint dimension = std_vec_->size();
343 for (uint i=0; i<dimension; i++) {
344 val += (*std_vec_)[i]*(*xvalptr)[i];
345 }
346 return val;
347}
348
349}; // class ConStdVector
350
351
352// Dual constraint space.
353template <class Real, class Element>
354class ConDualStdVector : public ROL::Vector<Real> {
355
356 typedef std::vector<Element> vector;
358 typedef typename vector::size_type uint;
359
360private:
361
362ROL::Ptr<std::vector<Element> > std_vec_;
363mutable ROL::Ptr<ConStdVector<Real> > dual_vec_;
364
365public:
366
367ConDualStdVector(const ROL::Ptr<std::vector<Element> > & std_vec) : std_vec_(std_vec), dual_vec_(ROL::nullPtr) {}
368
369void plus( const ROL::Vector<Real> &x ) {
370
371 ROL::Ptr<const vector> xp = dynamic_cast<const ConDualStdVector&>(x).getVector();
372 uint dimension = std_vec_->size();
373 for (uint i=0; i<dimension; i++) {
374 (*std_vec_)[i] += (*xp)[i];
375 }
376}
377
378void scale( const Real alpha ) {
379 uint dimension = std_vec_->size();
380 for (uint i=0; i<dimension; i++) {
381 (*std_vec_)[i] *= alpha;
382 }
383}
384
385Real dot( const ROL::Vector<Real> &x ) const {
386
387 ROL::Ptr<const vector> xp = dynamic_cast<const ConDualStdVector&>(x).getVector();
388 Real val = 0;
389 uint dimension = std_vec_->size();
390 for (uint i=0; i<dimension; i++) {
391 val += (*std_vec_)[i]*(*xp)[i];
392 }
393 return val;
394}
395
396Real norm() const {
397 Real val = 0;
398 val = std::sqrt( dot(*this) );
399 return val;
400}
401
402ROL::Ptr<ROL::Vector<Real> > clone() const {
403 return ROL::makePtr<ConDualStdVector>( ROL::makePtr<std::vector<Element>>(std_vec_->size()));
404}
405
406ROL::Ptr<const std::vector<Element> > getVector() const {
407 return std_vec_;
408}
409
410ROL::Ptr<std::vector<Element> > getVector() {
411 return std_vec_;
412}
413
414ROL::Ptr<ROL::Vector<Real> > basis( const int i ) const {
415
416 ROL::Ptr<vector> e_ptr = ROL::makePtr<vector>(std_vec_->size(),0.0);
417 ROL::Ptr<V> e = ROL::makePtr<ConDualStdVector>(e_ptr);
418 (*e_ptr)[i] = 1.0;
419 return e;
420}
421
422int dimension() const {return static_cast<int>(std_vec_->size());}
423
424const ROL::Vector<Real> & dual() const {
425 dual_vec_ = ROL::makePtr<ConStdVector<Real>>( ROL::makePtr<std::vector<Element>>(*std_vec_) );
426 return *dual_vec_;
427}
428
429Real apply( const ROL::Vector<Real> &x ) const {
430 Real val = 0;
431
432 ROL::Ptr<const vector> xvalptr = dynamic_cast<const ConStdVector<Real,Element>&>(x).getVector();
433 uint dimension = std_vec_->size();
434 for (uint i=0; i<dimension; i++) {
435 val += (*std_vec_)[i]*(*xvalptr)[i];
436 }
437 return val;
438}
439
440}; // class ConDualStdVector
441
442/*** End of declaration of four vector spaces. ***/
443
444
445int main(int argc, char *argv[]) {
446 //feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
447
448 typedef std::vector<RealT> vector;
449 typedef vector::size_type uint;
450
451 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
452
453 // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided.
454 int iprint = argc - 1;
455 ROL::Ptr<std::ostream> outStream;
456 ROL::nullstream bhs; // outputs nothing
457 if (iprint > 0)
458 outStream = ROL::makePtrFromRef(std::cout);
459 else
460 outStream = ROL::makePtrFromRef(bhs);
461
462 int errorFlag = 0;
463
464 // *** Example body.
465
466 try {
467
468 uint dim = 5;
469 uint nc = 3;
470 ROL::Ptr<ROL::Objective<RealT> > obj;
471 ROL::Ptr<ROL::Constraint<RealT> > constr;
472 ROL::Ptr<vector> x_ptr = ROL::makePtr<vector>(dim, 0.0);
473 ROL::Ptr<vector> sol_ptr = ROL::makePtr<vector>(dim, 0.0);
474 ROL::Ptr<OptStdVector<RealT>> x = ROL::makePtr<OptStdVector<RealT>>(x_ptr); // Iteration vector.
475 ROL::Ptr<OptStdVector<RealT>> sol = ROL::makePtr<OptStdVector<RealT>>(sol_ptr); // Reference solution vector.
476
477 // Retrieve objective, constraint, iteration vector, solution vector.
478 ROL::ZOO::getSimpleEqConstrained <RealT, OptStdVector<RealT>, OptDualStdVector<RealT>, ConStdVector<RealT>, ConDualStdVector<RealT> > SEC;
479 obj = SEC.getObjective();
480 constr = SEC.getEqualityConstraint();
481 x->set(*SEC.getInitialGuess());
482 sol->set(*SEC.getSolution());
483
484 // Run derivative checks, etc.
485 RealT left = -1e0, right = 1e0;
486 ROL::Ptr<vector> xtest_ptr = ROL::makePtr<vector>(dim, 0.0);
487 ROL::Ptr<vector> g_ptr = ROL::makePtr<vector>(dim, 0.0);
488 ROL::Ptr<vector> d_ptr = ROL::makePtr<vector>(dim, 0.0);
489 ROL::Ptr<vector> gd_ptr = ROL::makePtr<vector>(dim, 0.0);
490 ROL::Ptr<vector> v_ptr = ROL::makePtr<vector>(dim, 0.0);
491 ROL::Ptr<vector> vc_ptr = ROL::makePtr<vector>(nc, 0.0);
492 ROL::Ptr<vector> vl_ptr = ROL::makePtr<vector>(nc, 0.0);
493 ROL::Ptr<OptStdVector<RealT>> xtest = ROL::makePtr<OptStdVector<RealT>>(xtest_ptr);
494 ROL::Ptr<OptDualStdVector<RealT>> g = ROL::makePtr<OptDualStdVector<RealT>>(g_ptr);
495 ROL::Ptr<OptStdVector<RealT>> d = ROL::makePtr<OptStdVector<RealT>>(d_ptr);
496 ROL::Ptr<OptDualStdVector<RealT>> gd = ROL::makePtr<OptDualStdVector<RealT>>(gd_ptr);
497 ROL::Ptr<OptStdVector<RealT>> v = ROL::makePtr<OptStdVector<RealT>>(v_ptr);
498 ROL::Ptr<ConStdVector<RealT>> vc = ROL::makePtr<ConStdVector<RealT>>(vc_ptr);
499 ROL::Ptr<ConDualStdVector<RealT>> vl = ROL::makePtr<ConDualStdVector<RealT>>(vl_ptr);
500 // set xtest, d, v
501 for (uint i=0; i<dim; i++) {
502 (*xtest_ptr)[i] = ( (RealT)rand() / (RealT)RAND_MAX ) * (right - left) + left;
503 (*d_ptr)[i] = ( (RealT)rand() / (RealT)RAND_MAX ) * (right - left) + left;
504 (*gd_ptr)[i] = ( (RealT)rand() / (RealT)RAND_MAX ) * (right - left) + left;
505 (*v_ptr)[i] = ( (RealT)rand() / (RealT)RAND_MAX ) * (right - left) + left;
506 }
507 // set vc, vl
508 for (uint i=0; i<nc; i++) {
509 (*vc_ptr)[i] = ( (RealT)rand() / (RealT)RAND_MAX ) * (right - left) + left;
510 (*vl_ptr)[i] = ( (RealT)rand() / (RealT)RAND_MAX ) * (right - left) + left;
511 }
512 obj->checkGradient(*xtest, *g, *d, true, *outStream); *outStream << std::endl;
513 obj->checkHessVec(*xtest, *g, *v, true, *outStream); *outStream << std::endl;
514 obj->checkHessSym(*xtest, *g, *d, *v, true, *outStream); *outStream << std::endl;
515 constr->checkApplyJacobian(*xtest, *v, *vc, true, *outStream); *outStream << std::endl;
516 constr->checkApplyAdjointJacobian(*xtest, *vl, *vc, *g, true, *outStream); *outStream << std::endl;
517 constr->checkApplyAdjointHessian(*xtest, *vl, *d, *g, true, *outStream); *outStream << std::endl;
518
519 ROL::Ptr<vector> v1_ptr = ROL::makePtr<vector>(dim, 0.0);
520 ROL::Ptr<vector> v2_ptr = ROL::makePtr<vector>(nc, 0.0);
521 ROL::Ptr<OptStdVector<RealT>> v1 = ROL::makePtr<OptStdVector<RealT>>(v1_ptr);
522 ROL::Ptr<ConDualStdVector<RealT>> v2 = ROL::makePtr<ConDualStdVector<RealT>>(v2_ptr);
523 RealT augtol = 1e-8;
524 constr->solveAugmentedSystem(*v1, *v2, *gd, *vc, *xtest, augtol);
525
526 // Define problem.
527 vl->zero(); vc->zero(); g->zero();
528 ROL::Ptr<ROL::Problem<RealT>>
529 problem = ROL::makePtr<ROL::Problem<RealT>>(obj,x,g);
530 problem->addConstraint("Equality",constr,ROL::staticPtrCast<ROL::Vector<RealT>>(vl),ROL::staticPtrCast<ROL::Vector<RealT>>(vc));
531 problem->finalize(false,true,*outStream);
532
533 // Define algorithm.
534 ROL::ParameterList parlist;
535 std::string stepname = "Augmented Lagrangian";
536 parlist.sublist("General").set("Output Level",1);
537 parlist.sublist("Step").set("Type",stepname);
538 parlist.sublist("Step").sublist(stepname).sublist("Optimality System Solver").set("Nominal Relative Tolerance",1e-4);
539 parlist.sublist("Step").sublist(stepname).sublist("Optimality System Solver").set("Fix Tolerance",true);
540 parlist.sublist("Step").sublist(stepname).sublist("Tangential Subproblem Solver").set("Iteration Limit",20);
541 parlist.sublist("Step").sublist(stepname).sublist("Tangential Subproblem Solver").set("Relative Tolerance",1e-2);
542 parlist.sublist("Step").sublist(stepname).set("Output Level",0);
543 parlist.sublist("Status Test").set("Gradient Tolerance",1.e-12);
544 parlist.sublist("Status Test").set("Constraint Tolerance",1.e-12);
545 parlist.sublist("Status Test").set("Step Tolerance",1.e-18);
546 parlist.sublist("Status Test").set("Iteration Limit",100);
547 ROL::Ptr<ROL::Solver<RealT>> solver
548 = ROL::makePtr<ROL::Solver<RealT>>(problem,parlist);
549
550 // Run Algorithm
551 //(*x_ptr)[0] = 3.0; (*x_ptr)[1] = 2.0; (*x_ptr)[2] = 2.0; (*x_ptr)[3] = 1.0; (*x_ptr)[4] = 1.0;
552 //(*x_ptr)[0] = -5.0; (*x_ptr)[1] = -5.0; (*x_ptr)[2] = -5.0; (*x_ptr)[3] = -6.0; (*x_ptr)[4] = -6.0;
553 solver->solve(*outStream);
554
555 // Compute Error
556 *outStream << "\nReference solution x_r =\n";
557 *outStream << std::scientific << " " << (*sol_ptr)[0] << "\n";
558 *outStream << std::scientific << " " << (*sol_ptr)[1] << "\n";
559 *outStream << std::scientific << " " << (*sol_ptr)[2] << "\n";
560 *outStream << std::scientific << " " << (*sol_ptr)[3] << "\n";
561 *outStream << std::scientific << " " << (*sol_ptr)[4] << "\n";
562 *outStream << "\nOptimal solution x =\n";
563 *outStream << std::scientific << " " << (*x_ptr)[0] << "\n";
564 *outStream << std::scientific << " " << (*x_ptr)[1] << "\n";
565 *outStream << std::scientific << " " << (*x_ptr)[2] << "\n";
566 *outStream << std::scientific << " " << (*x_ptr)[3] << "\n";
567 *outStream << std::scientific << " " << (*x_ptr)[4] << "\n";
568 x->axpy(-1.0, *sol);
569 RealT abserr = x->norm();
570 RealT relerr = abserr/sol->norm();
571 *outStream << std::scientific << "\n Absolute Error: " << abserr;
572 *outStream << std::scientific << "\n Relative Error: " << relerr << "\n";
573 if ( relerr > sqrt(ROL::ROL_EPSILON<RealT>()) ) {
574 errorFlag += 1;
575 }
576 }
577 catch (std::logic_error& err) {
578 *outStream << err.what() << "\n";
579 errorFlag = -1000;
580 }; // end try
581
582 if (errorFlag != 0)
583 std::cout << "End Result: TEST FAILED\n";
584 else
585 std::cout << "End Result: TEST PASSED\n";
586
587 return 0;
588
589}
590
Contains definitions for the equality constrained NLP from Nocedal/Wright, 2nd edition,...
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
ROL::Ptr< const std::vector< Element > > getVector() const
ROL::Ptr< ConStdVector< Real > > dual_vec_
ROL::Ptr< ROL::Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
ROL::Ptr< ROL::Vector< Real > > basis(const int i) const
Return i-th basis vector.
void plus(const ROL::Vector< Real > &x)
Compute , where .
int dimension() const
Return dimension of the vector space.
Real apply(const ROL::Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
ConDualStdVector(const ROL::Ptr< std::vector< Element > > &std_vec)
void scale(const Real alpha)
Compute where .
ROL::Ptr< std::vector< Element > > getVector()
const ROL::Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
ROL::Ptr< std::vector< Element > > std_vec_
Real dot(const ROL::Vector< Real > &x) const
Compute where .
ROL::Ptr< ConDualStdVector< Real > > dual_vec_
ROL::Ptr< std::vector< Element > > std_vec_
ROL::Ptr< ROL::Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
const ROL::Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
Real dot(const ROL::Vector< Real > &x) const
Compute where .
void plus(const ROL::Vector< Real > &x)
Compute , where .
void scale(const Real alpha)
Compute where .
Real apply(const ROL::Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
ConStdVector(const ROL::Ptr< std::vector< Element > > &std_vec)
ROL::Ptr< ROL::Vector< Real > > basis(const int i) const
Return i-th basis vector.
ROL::Ptr< std::vector< Element > > getVector()
ROL::Ptr< const std::vector< Element > > getVector() const
int dimension() const
Return dimension of the vector space.
int dimension() const
Return dimension of the vector space.
ROL::Ptr< ROL::Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
ROL::Ptr< ROL::Vector< Real > > basis(const int i) const
Return i-th basis vector.
void scale(const Real alpha)
Compute where .
Real dot(const ROL::Vector< Real > &x) const
Compute where .
void plus(const ROL::Vector< Real > &x)
Compute , where .
const ROL::Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
Real apply(const ROL::Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
ROL::Ptr< std::vector< Element > > std_vec_
ROL::Ptr< const std::vector< Element > > getVector() const
ROL::Ptr< std::vector< Element > > getVector()
ROL::Ptr< OptStdVector< Real > > dual_vec_
OptDualStdVector(const ROL::Ptr< std::vector< Element > > &std_vec)
ROL::Ptr< const std::vector< Element > > getVector() const
ROL::Ptr< ROL::Vector< Real > > basis(const int i) const
Return i-th basis vector.
void plus(const ROL::Vector< Real > &x)
Compute , where .
Real dot(const ROL::Vector< Real > &x) const
Compute where .
ROL::Ptr< std::vector< Element > > getVector()
const ROL::Vector< Real > & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
int dimension() const
Return dimension of the vector space.
OptStdVector(const ROL::Ptr< std::vector< Element > > &std_vec)
ROL::Ptr< ROL::Vector< Real > > clone() const
Clone to make a new (uninitialized) vector.
ROL::Ptr< OptDualStdVector< Real > > dual_vec_
ROL::Ptr< std::vector< Element > > std_vec_
Real apply(const ROL::Vector< Real > &x) const
Apply to a dual vector. This is equivalent to the call .
void scale(const Real alpha)
Compute where .
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:84
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:209
int main(int argc, char *argv[])
constexpr auto dim