ROL
ROL_TypeU_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_TYPEU_ALGORITHM_H
11#define ROL_TYPEU_ALGORITHM_H
12
14#include "ROL_Objective.hpp"
15#include "ROL_Constraint.hpp"
16#include "ROL_Problem.hpp"
17
22namespace ROL {
23namespace TypeU {
24
25template<typename Real>
26struct AlgorithmState : public ROL::AlgorithmState<Real> {
28 Ptr<Vector<Real>> stepVec;
29 Ptr<Vector<Real>> gradientVec;
30
32 : searchSize(1),
33 stepVec(nullPtr),
34 gradientVec(nullPtr) {}
35
36 void reset() {
38 searchSize = static_cast<Real>(1);
39 if (stepVec != nullPtr) {
40 stepVec->zero();
41 }
42 if (gradientVec != nullPtr) {
43 gradientVec->zero();
44 }
45 }
46};
47
48template<typename Real>
49class Algorithm {
50protected:
51 const Ptr<CombinedStatusTest<Real>> status_;
52 const Ptr<AlgorithmState<Real>> state_;
53
54 void initialize(const Vector<Real> &x, const Vector<Real> &g);
55
56public:
57
58 virtual ~Algorithm() {}
59
62 Algorithm();
63
64 void setStatusTest(const Ptr<StatusTest<Real>> &status,
65 bool combineStatus = false);
66
70 virtual void run( Problem<Real> &problem,
71 std::ostream &outStream = std::cout );
72
76 virtual void run( Vector<Real> &x,
77 Objective<Real> &obj,
78 std::ostream &outStream = std::cout );
79
85 virtual void run( Vector<Real> &x,
86 Objective<Real> &obj,
87 Constraint<Real> &linear_con,
88 Vector<Real> &linear_mul,
89 std::ostream &outStream = std::cout );
90
96 virtual void run( Vector<Real> &x,
97 const Vector<Real> &g,
98 Objective<Real> &obj,
99 Constraint<Real> &linear_con,
100 Vector<Real> &linear_mul,
101 const Vector<Real> &linear_c,
102 std::ostream &outStream = std::cout );
103
108 virtual void run( Vector<Real> &x,
109 const Vector<Real> &g,
110 Objective<Real> &obj,
111 std::ostream &outStream = std::cout) = 0;
112
115 virtual void writeHeader( std::ostream& os ) const;
116
119 virtual void writeName( std::ostream& os ) const;
120
123 virtual void writeOutput( std::ostream& os, const bool write_header = false ) const;
124
125 virtual void writeExitStatus( std::ostream& os ) const;
126
127 //Ptr<const AlgorithmState<Real>>& getState() const;
128 Ptr<const AlgorithmState<Real>> getState() const;
129
130 void reset();
131
132}; // class ROL::TypeU::Algorithm
133} // namespace TypeU
134} // namespace ROL
135
137
138#endif
Defines the general constraint operator interface.
Provides the interface to evaluate objective functions.
Provides an interface to check status of optimization algorithms.
Provides an interface to run unconstrained optimization algorithms.
Algorithm()
Constructor, given a step and a status test.
const Ptr< CombinedStatusTest< Real > > status_
Ptr< const AlgorithmState< Real > > getState() const
void initialize(const Vector< Real > &x, const Vector< Real > &g)
virtual void writeExitStatus(std::ostream &os) const
virtual void writeHeader(std::ostream &os) const
Print iterate header.
virtual void writeName(std::ostream &os) const
Print step name.
virtual void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, std::ostream &outStream=std::cout)=0
Run algorithm on unconstrained problems (Type-U). This general interface supports the use of dual opt...
void setStatusTest(const Ptr< StatusTest< Real > > &status, bool combineStatus=false)
const Ptr< AlgorithmState< Real > > state_
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 writeOutput(std::ostream &os, const bool write_header=false) const
Print iterate status.
Defines the linear algebra or vector space interface.
State for algorithm class. Will be used for restarts.
Ptr< Vector< Real > > gradientVec