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 
21 namespace ROL {
22 namespace TypeP {
23 
24 template<typename Real>
25 struct AlgorithmState : public ROL::AlgorithmState<Real> {
27  Ptr<Vector<Real>> stepVec, gradientVec;
28  int nprox, nsval, nnval;
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 
55 template<typename Real>
56 class Algorithm {
57 protected:
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 
70 public:
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.
Real ROL_INF(void)
Definition: ROL_Types.hpp:71
virtual void writeOutput(std::ostream &os, bool write_header=false) const
Print iterate status.
void pgstep(Vector< Real > &pgiter, Vector< Real > &pgstep, Objective< Real > &nobj, const Vector< Real > &x, const Vector< Real > &dg, Real t, Real &tol) const
Ptr< Vector< Real > > stepVec
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
void setStatusTest(const Ptr< StatusTest< Real >> &status, bool combineStatus=false)
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:109
virtual void writeHeader(std::ostream &os) const
Print iterate header.
virtual void writeName(std::ostream &os) const
Print step name.
const Ptr< AlgorithmState< Real > > state_
Provides an interface to check status of optimization algorithms.
const Ptr< CombinedStatusTest< Real > > status_
Provides an interface to run optimization algorithms to minimize composite optimization problems f+ph...
virtual void writeExitStatus(std::ostream &os) 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.
void initialize(const Vector< Real > &x, const Vector< Real > &g)
Ptr< Vector< Real > > gradientVec
Algorithm()
Constructor, given a step and a status test.
Ptr< const AlgorithmState< Real > > getState() const