ROL
ROL_TypeB_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_TYPEB_ALGORITHM_H
11#define ROL_TYPEB_ALGORITHM_H
12
14#include "ROL_Objective.hpp"
15#include "ROL_Constraint.hpp"
18#include "ROL_Problem.hpp"
19
24namespace ROL {
25namespace TypeB {
26
27template<typename Real>
28struct AlgorithmState : public ROL::AlgorithmState<Real> {
30 Ptr<Vector<Real>> stepVec;
31 Ptr<Vector<Real>> gradientVec;
32 int nproj;
33
35 : searchSize(1),
36 stepVec(nullPtr),
37 gradientVec(nullPtr),
38 nproj(0) {}
39
40 void reset() {
42 searchSize = static_cast<Real>(1);
43 if (stepVec != nullPtr) stepVec->zero();
44 if (gradientVec != nullPtr) gradientVec->zero();
45 nproj = 0;
46 }
47};
48
49template<typename Real>
50class Algorithm {
51protected:
52 const Ptr<CombinedStatusTest<Real>> status_;
53 const Ptr<AlgorithmState<Real>> state_;
54 Ptr<PolyhedralProjection<Real>> proj_;
55
56 void initialize(const Vector<Real> &x, const Vector<Real> &g);
57
58 Real optimalityCriterion(const Vector<Real> &x, const Vector<Real> &g, Vector<Real> &primal,
59 std::ostream &outStream = std::cout) const;
60
61public:
62
63 virtual ~Algorithm() {}
64
67 Algorithm();
68
69 void setStatusTest(const Ptr<StatusTest<Real>> &status,
70 const bool combineStatus = false);
71
75 virtual void run( Problem<Real> &problem,
76 std::ostream &outStream = std::cout );
77
81 virtual void run( Vector<Real> &x,
82 Objective<Real> &obj,
84 std::ostream &outStream = std::cout );
85
90 virtual void run( Vector<Real> &x,
91 const Vector<Real> &g,
92 Objective<Real> &obj,
94 std::ostream &outStream = std::cout) = 0;
95
101 virtual void run( Vector<Real> &x,
102 Objective<Real> &obj,
104 Constraint<Real> &linear_econ,
105 Vector<Real> &linear_emul,
106 std::ostream &outStream = std::cout );
107
113 virtual void run( Vector<Real> &x,
114 const Vector<Real> &g,
115 Objective<Real> &obj,
117 Constraint<Real> &linear_econ,
118 Vector<Real> &linear_emul,
119 const Vector<Real> &linear_eres,
120 std::ostream &outStream = std::cout );
121
127 virtual void run( Vector<Real> &x,
128 Objective<Real> &obj,
130 Constraint<Real> &linear_icon,
131 Vector<Real> &linear_imul,
132 BoundConstraint<Real> &linear_ibnd,
133 std::ostream &outStream = std::cout );
134
140 virtual void run( Vector<Real> &x,
141 const Vector<Real> &g,
142 Objective<Real> &obj,
144 Constraint<Real> &linear_icon,
145 Vector<Real> &linear_imul,
146 BoundConstraint<Real> &linear_ibnd,
147 const Vector<Real> &linear_ires,
148 std::ostream &outStream = std::cout );
149
155 virtual void run( Vector<Real> &x,
156 Objective<Real> &obj,
158 Constraint<Real> &linear_econ,
159 Vector<Real> &linear_emul,
160 Constraint<Real> &linear_icon,
161 Vector<Real> &linear_imul,
162 BoundConstraint<Real> &linear_ibnd,
163 std::ostream &outStream = std::cout );
164
170 virtual void run( Vector<Real> &x,
171 const Vector<Real> &g,
172 Objective<Real> &obj,
174 Constraint<Real> &linear_econ,
175 Vector<Real> &linear_emul,
176 const Vector<Real> &linear_eres,
177 Constraint<Real> &linear_icon,
178 Vector<Real> &linear_imul,
179 BoundConstraint<Real> &linear_ibnd,
180 const Vector<Real> &linear_ires,
181 std::ostream &outStream = std::cout );
182
185 virtual void writeHeader( std::ostream& os ) const;
186
189 virtual void writeName( std::ostream& os ) const;
190
193 virtual void writeOutput( std::ostream& os, const bool write_header = false ) const;
194
195 virtual void writeExitStatus( std::ostream& os ) const;
196
197 //Ptr<const AlgorithmState<Real>>& getState() const;
198 Ptr<const AlgorithmState<Real>> getState() const;
199
200 void reset();
201
202}; // class ROL::Type::Algorithm
203
204} // namespace TypeB
205} // namespace ROL
206
208
209#endif
Provides the interface to apply upper and lower bound constraints.
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 bound constrained optimization algorithms.
virtual void run(Problem< Real > &problem, std::ostream &outStream=std::cout)
Run algorithm on bound constrained problems (Type-B). This is the primary Type-B interface.
Ptr< PolyhedralProjection< Real > > proj_
void initialize(const Vector< Real > &x, const Vector< Real > &g)
virtual void writeHeader(std::ostream &os) const
Print iterate header.
Real optimalityCriterion(const Vector< Real > &x, const Vector< Real > &g, Vector< Real > &primal, std::ostream &outStream=std::cout) const
Algorithm()
Constructor, given a step and a status test.
virtual void writeExitStatus(std::ostream &os) const
virtual void writeName(std::ostream &os) const
Print step name.
const Ptr< AlgorithmState< Real > > state_
const Ptr< CombinedStatusTest< Real > > status_
virtual void writeOutput(std::ostream &os, const bool write_header=false) const
Print iterate status.
Ptr< const AlgorithmState< Real > > getState() const
virtual void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, std::ostream &outStream=std::cout)=0
Run algorithm on bound constrained problems (Type-B). This general interface supports the use of dual...
void setStatusTest(const Ptr< StatusTest< Real > > &status, const bool combineStatus=false)
Defines the linear algebra or vector space interface.
State for algorithm class. Will be used for restarts.
Ptr< Vector< Real > > gradientVec