ROL
step/test_12.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
14#define USE_HESSVEC 0
15
16#include "Teuchos_GlobalMPISession.hpp"
17
18#include "ROL_Step.hpp"
20
21#include <iostream>
22
23typedef double RealT;
24
25int main(int argc, char *argv[]) {
26
27 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
28
29 // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided.
30 int iprint = argc - 1;
31 ROL::Ptr<std::ostream> outStream;
32 ROL::nullstream bhs; // outputs nothing
33 if (iprint > 0)
34 outStream = ROL::makePtrFromRef(std::cout);
35 else
36 outStream = ROL::makePtrFromRef(bhs);
37
38 int errorFlag = 0;
39 ROL::Ptr<ROL::Vector<RealT> > x0;
40 std::vector<ROL::Ptr<ROL::Vector<RealT> > > x;
41 ROL::Ptr<ROL::OptimizationProblem<RealT> > problem;
42 ROL::GetTestProblem<RealT>(problem,x0,x,ROL::TESTOPTPROBLEM_HS1);
43 ROL::Ptr<ROL::Objective<RealT> > obj = problem->getObjective();
44 ROL::Ptr<ROL::BoundConstraint<RealT> > bnd = problem->getBoundConstraint();
46
47 // *** Test body.
49 int thrown = 0;
50 try {
51 try {
52 step.compute(*x0,*x[0],*obj,*bnd,algo_state);
53 }
55 *outStream << exc.what() << std::endl;
56 thrown++;
57 };
58 try {
59 step.update(*x0,*x[0],*obj,*bnd,algo_state);
60 }
62 *outStream << exc.what() << std::endl;
63 thrown++;
64 };
65 try {
66 step.printName();
67 }
69 *outStream << exc.what() << std::endl;
70 thrown++;
71 };
72 try {
73 step.printHeader();
74 }
76 *outStream << exc.what() << std::endl;
77 thrown++;
78 };
79 try {
80 step.print(algo_state,true);
81 }
83 *outStream << exc.what() << std::endl;
84 thrown++;
85 };
86 errorFlag = (thrown==5) ? 0 : 1;
87 }
88 catch (std::logic_error& err) {
89 *outStream << err.what() << std::endl;
90 errorFlag = -1000;
91 }; // end try
92
93 if (errorFlag != 0)
94 std::cout << "End Result: TEST FAILED" << std::endl;
95 else
96 std::cout << "End Result: TEST PASSED" << std::endl;
97
98 return 0;
99
100}
101
Contains definitions of test objective functions.
Provides the interface to compute optimization steps.
Definition ROL_Step.hpp:34
virtual std::string print(AlgorithmState< Real > &algo_state, bool printHeader=false) const
Print iterate status.
Definition ROL_Step.hpp:171
virtual void compute(Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Compute step.
Definition ROL_Step.hpp:109
virtual std::string printName(void) const
Print step name.
Definition ROL_Step.hpp:165
virtual std::string printHeader(void) const
Print iterate header.
Definition ROL_Step.hpp:159
virtual void update(Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Update step, if successful.
Definition ROL_Step.hpp:117
int main(int argc, char *argv[])
double RealT
State for algorithm class. Will be used for restarts.