ROL
ROL_TypeP_Algorithm.hpp
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
10#ifndef ROL_TYPEP_ALGORITHM_H
11#define ROL_TYPEP_ALGORITHM_H
12
14#include "ROL_Objective.hpp"
15#include "ROL_Problem.hpp"
16
21namespace ROL {
22namespace TypeP {
23
24template<typename Real>
25struct AlgorithmState : public ROL::AlgorithmState<Real> {
27 Ptr<Vector<Real>> stepVec, gradientVec;
29
31 : searchSize(1),
32 svalue(ROL_INF<Real>()),
33 nvalue(ROL_INF<Real>()),
34 stepVec(nullPtr),
35 gradientVec(nullPtr),
36 nprox(0),
37 nsval(0),
38 nnval(0) {}
39
40 void reset() {
42 searchSize = static_cast<Real>(1);
43 svalue = ROL_INF<Real>();
44 nvalue = ROL_INF<Real>();
45 if (stepVec != nullPtr)
46 stepVec->zero();
47 if (gradientVec != nullPtr)
48 gradientVec->zero();
49 nprox = 0;
50 nsval = 0;
51 nnval = 0;
52 }
53};
54
55template<typename Real>
56class Algorithm {
57protected:
58 const Ptr<CombinedStatusTest<Real>> status_;
59 const Ptr<AlgorithmState<Real>> state_;
60
61 void initialize(const Vector<Real> &x, const Vector<Real> &g);
62 void pgstep(Vector<Real> &pgiter, // pgiter = Prox(x - t dg)
63 Vector<Real> &pgstep, // pgstep = pgiter - x
64 Objective<Real> &nobj, // nobj = nonsmooth objective
65 const Vector<Real> &x, // x = current iterate
66 const Vector<Real> &dg, // dg = dual of current gradient
67 Real t, // t = prox parameter
68 Real &tol) const;
69
70public:
71
72 virtual ~Algorithm() {}
73
76 Algorithm();
77
78 void setStatusTest(const Ptr<StatusTest<Real>> &status,
79 bool combineStatus = false);
80
84 virtual void run( Problem<Real> &problem,
85 std::ostream &outStream = std::cout );
86
90 virtual void run( Vector<Real> &x,
91 Objective<Real> &sobj,
92 Objective<Real> &nobj,
93 std::ostream &outStream = std::cout );
94
99 virtual void run( Vector<Real> &x,
100 const Vector<Real> &g,
101 Objective<Real> &sobj,
102 Objective<Real> &nobj,
103 std::ostream &outStream = std::cout) = 0;
104
107 virtual void writeHeader( std::ostream& os ) const;
108
111 virtual void writeName( std::ostream& os ) const;
112
115 virtual void writeOutput( std::ostream& os, bool write_header = false ) const;
116
117 virtual void writeExitStatus( std::ostream& os ) const;
118
119 //Ptr<const AlgorithmState<Real>>& getState() const;
120 Ptr<const AlgorithmState<Real>> getState() const;
121
122 void reset();
123
124}; // class ROL::TypeP::Algorithm
125} // namespace TypeP
126} // namespace ROL
127
129
130#endif
Provides the interface to evaluate objective functions.
Provides an interface to check status of optimization algorithms.
Provides an interface to run optimization algorithms to minimize composite optimization problems f+ph...
void pgstep(Vector< Real > &pgiter, Vector< Real > &pgstep, Objective< Real > &nobj, const Vector< Real > &x, const Vector< Real > &dg, Real t, Real &tol) const
virtual void run(Problem< Real > &problem, std::ostream &outStream=std::cout)
Run algorithm on unconstrained problems (Type-U). This is the primary Type-U interface.
virtual void writeName(std::ostream &os) const
Print step name.
Ptr< const AlgorithmState< Real > > getState() const
const Ptr< AlgorithmState< Real > > state_
Algorithm()
Constructor, given a step and a status test.
virtual void writeHeader(std::ostream &os) const
Print iterate header.
virtual void writeExitStatus(std::ostream &os) const
virtual void writeOutput(std::ostream &os, bool write_header=false) const
Print iterate status.
const Ptr< CombinedStatusTest< Real > > status_
void setStatusTest(const Ptr< StatusTest< Real > > &status, bool combineStatus=false)
virtual void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &sobj, Objective< Real > &nobj, std::ostream &outStream=std::cout)=0
Run algorithm on unconstrained problems (Type-U). This general interface supports the use of dual opt...
void initialize(const Vector< Real > &x, const Vector< Real > &g)
Defines the linear algebra or vector space interface.
Real ROL_INF(void)
Definition ROL_Types.hpp:71
State for algorithm class. Will be used for restarts.
Ptr< Vector< Real > > gradientVec