ROL
ROL_TypeE_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_TYPEE_ALGORITHM_H
11 #define ROL_TYPEE_ALGORITHM_H
12 
14 #include "ROL_Objective.hpp"
15 #include "ROL_Constraint.hpp"
16 #include "ROL_Problem.hpp"
17 
22 namespace ROL {
23 namespace TypeE {
24 
25 template<typename Real>
26 struct AlgorithmState : public ROL::AlgorithmState<Real> {
27  Real searchSize;
28  Ptr<Vector<Real>> stepVec;
29  Ptr<Vector<Real>> gradientVec;
30  Ptr<Vector<Real>> constraintVec;
31 
33  : searchSize(1),
34  stepVec(nullPtr),
35  gradientVec(nullPtr),
36  constraintVec(nullPtr) {}
37 
38  void reset() {
40  searchSize = static_cast<Real>(1);
41  if (stepVec != nullPtr) {
42  stepVec->zero();
43  }
44  if (gradientVec != nullPtr) {
45  gradientVec->zero();
46  }
47  if (constraintVec != nullPtr) {
48  constraintVec->zero();
49  }
50  }
51 };
52 
53 template<typename Real>
54 class Algorithm {
55 protected:
56  const Ptr<CombinedStatusTest<Real>> status_;
57  const Ptr<AlgorithmState<Real>> state_;
58 
59  void initialize(const Vector<Real> &x,
60  const Vector<Real> &g,
61  const Vector<Real> &mul,
62  const Vector<Real> &c);
63 
64 public:
65 
66  virtual ~Algorithm() {}
67 
70  Algorithm();
71 
72  void setStatusTest( const Ptr<StatusTest<Real>> &status,
73  bool combineStatus = false);
74 
78  virtual void run( Problem<Real> &problem,
79  std::ostream &outStream = std::cout );
80 
84  virtual void run( Vector<Real> &x,
85  Objective<Real> &obj,
86  Constraint<Real> &econ,
87  Vector<Real> &emul,
88  std::ostream &outStream = std::cout );
89 
94  virtual void run( Vector<Real> &x,
95  const Vector<Real> &g,
96  Objective<Real> &obj,
97  Constraint<Real> &econ,
98  Vector<Real> &emul,
99  const Vector<Real> &eres,
100  std::ostream &outStream = std::cout) = 0;
101 
107  virtual void run( Vector<Real> &x,
108  Objective<Real> &obj,
109  Constraint<Real> &econ,
110  Vector<Real> &emul,
111  Constraint<Real> &linear_econ,
112  Vector<Real> &linear_emul,
113  std::ostream &outStream = std::cout );
114 
120  virtual void run( Vector<Real> &x,
121  const Vector<Real> &g,
122  Objective<Real> &obj,
123  Constraint<Real> &econ,
124  Vector<Real> &emul,
125  const Vector<Real> &eres,
126  Constraint<Real> &linear_econ,
127  Vector<Real> &linear_emul,
128  const Vector<Real> &linear_eres,
129  std::ostream &outStream = std::cout );
130 
133  virtual void writeHeader( std::ostream& os ) const;
134 
137  virtual void writeName( std::ostream& os ) const;
138 
141  virtual void writeOutput( std::ostream& os, const bool write_header = false ) const;
142 
143  virtual void writeExitStatus( std::ostream& os ) const;
144 
145  Ptr<const AlgorithmState<Real>> getState() const;
146  //Ptr<const AlgorithmState<Real>>& getState() const;
147 
148  void reset();
149 
150 }; // class ROL::Algorithm
151 } // namespace TypeE
152 } // namespace ROL
153 
155 
156 #endif
Provides the interface to evaluate objective functions.
virtual void writeHeader(std::ostream &os) const
Print iterate header.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
virtual void run(Problem< Real > &problem, std::ostream &outStream=std::cout)
Run algorithm on equality constrained problems (Type-E). This is the primary Type-E interface...
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:109
virtual void writeName(std::ostream &os) const
Print step name.
const Ptr< AlgorithmState< Real > > state_
virtual void writeOutput(std::ostream &os, const bool write_header=false) const
Print iterate status.
Provides an interface to check status of optimization algorithms.
void setStatusTest(const Ptr< StatusTest< Real >> &status, bool combineStatus=false)
const Ptr< CombinedStatusTest< Real > > status_
Ptr< Vector< Real > > gradientVec
virtual void writeExitStatus(std::ostream &os) const
void initialize(const Vector< Real > &x, const Vector< Real > &g, const Vector< Real > &mul, const Vector< Real > &c)
Ptr< const AlgorithmState< Real > > getState() const
Ptr< Vector< Real > > constraintVec
Algorithm()
Constructor, given a step and a status test.
Defines the general constraint operator interface.
Ptr< Vector< Real > > stepVec