ROL
function/test_11.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
16#include "ROL_HS2.hpp"
17#include "ROL_StdVector.hpp"
18#include "ROL_RandomVector.hpp"
19#include "ROL_Stream.hpp"
20#include "Teuchos_GlobalMPISession.hpp"
21//#include <fenv.h>
22
23typedef double RealT;
24
25int main(int argc, char *argv[]) {
26 //feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
27
28 typedef ROL::Vector<RealT> V;
29 typedef ROL::Objective<RealT> OBJ;
30 typedef ROL::BoundConstraint<RealT> CON;
31
32 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
33
34 // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided.
35 int iprint = argc - 1;
36 ROL::Ptr<std::ostream> outStream;
37 ROL::nullstream bhs; // outputs nothing
38 if (iprint > 0)
39 outStream = ROL::makePtrFromRef(std::cout);
40 else
41 outStream = ROL::makePtrFromRef(bhs);
42
43 // Save the format state of the original std::cout.
44 ROL::nullstream oldFormatState;
45 oldFormatState.copyfmt(std::cout);
46
47 RealT zero(0);
48
49 ROL::Ptr<V> x0;
50 ROL::Ptr<V> x;
51 ROL::Ptr<V> g;
52 ROL::Ptr<OBJ> obj;
53 ROL::Ptr<CON> con;
54 ROL::Ptr<OBJ> model;
55
57 obj = HS2.getObjective();
58 con = HS2.getBoundConstraint();
59 x0 = HS2.getInitialGuess();
60 x = HS2.getSolution();
61
62 g = x->dual().clone();
63
64 // Need to evaluate the gradient to construct the model
65 obj->gradient(*g,*x,zero);
66
67 model = ROL::makePtr<ROL::ColemanLiModel<RealT>>(*obj,*con,*x,*g);
68
69 ROL::Ptr<V> s = x->clone();
70 ROL::Ptr<V> v = x->clone();
71 ROL::Ptr<V> u = x->clone();
72
73 ROL::RandomizeVector(*s,-1.0,1.0);
74 ROL::RandomizeVector(*u,-1.0,1.0);
75 ROL::RandomizeVector(*v,-1.0,1.0);
76
77 model->checkGradient(*s,*v);
78 model->checkHessVec(*s,*v);
79 model->checkHessSym(*s,*u,*v);
80
81 return 0;
82}
83
84
Vector< Real > V
Contains definitions for W. Hock and K. Schittkowski 2nd test function.
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
Provides the interface to apply upper and lower bound constraints.
Provides the interface to evaluate objective functions.
Defines the linear algebra or vector space interface.
Ptr< Vector< Real > > getSolution(const int i=0) const
Definition ROL_HS2.hpp:132
Ptr< BoundConstraint< Real > > getBoundConstraint(void) const
Definition ROL_HS2.hpp:144
Ptr< Objective< Real > > getObjective(void) const
Definition ROL_HS2.hpp:118
Ptr< Vector< Real > > getInitialGuess(void) const
Definition ROL_HS2.hpp:123
int main(int argc, char *argv[])
double RealT
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,...