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
22namespace ROL {
23namespace TypeE {
24
25template<typename Real>
26struct AlgorithmState : public ROL::AlgorithmState<Real> {
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
53template<typename Real>
54class Algorithm {
55protected:
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
64public:
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
Defines the general constraint operator interface.
Provides the interface to evaluate objective functions.
Provides an interface to check status of optimization algorithms.
virtual void writeName(std::ostream &os) const
Print step name.
virtual void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, Constraint< Real > &econ, Vector< Real > &emul, const Vector< Real > &eres, std::ostream &outStream=std::cout)=0
Run algorithm on equality constrained problems (Type-E). This general interface supports the use of d...
void initialize(const Vector< Real > &x, const Vector< Real > &g, const Vector< Real > &mul, const Vector< Real > &c)
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.
virtual void writeExitStatus(std::ostream &os) const
virtual void writeHeader(std::ostream &os) const
Print iterate header.
Ptr< const AlgorithmState< Real > > getState() const
Algorithm()
Constructor, given a step and a status test.
virtual void writeOutput(std::ostream &os, const bool write_header=false) const
Print iterate status.
const Ptr< AlgorithmState< Real > > state_
void setStatusTest(const Ptr< StatusTest< Real > > &status, bool combineStatus=false)
const Ptr< CombinedStatusTest< Real > > status_
Defines the linear algebra or vector space interface.
State for algorithm class. Will be used for restarts.
Ptr< Vector< Real > > constraintVec
Ptr< Vector< Real > > gradientVec