ROL
ROL_TypeG_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_TYPEG_ALGORITHM_H
11#define ROL_TYPEG_ALGORITHM_H
12
14#include "ROL_Objective.hpp"
15#include "ROL_Constraint.hpp"
18#include "ROL_Problem.hpp"
19
24namespace ROL {
25namespace TypeG {
26
27template<typename Real>
28struct AlgorithmState : public ROL::AlgorithmState<Real> {
30 Ptr<Vector<Real>> stepVec;
31 Ptr<Vector<Real>> gradientVec;
32 Ptr<Vector<Real>> constraintVec;
33
35 : searchSize(1),
36 stepVec(nullPtr),
37 gradientVec(nullPtr),
38 constraintVec(nullPtr) {}
39
40 void reset() {
42 searchSize = static_cast<Real>(1);
43 if (stepVec != nullPtr) {
44 stepVec->zero();
45 }
46 if (gradientVec != nullPtr) {
47 gradientVec->zero();
48 }
49 if (constraintVec != nullPtr) {
50 constraintVec->zero();
51 }
52 }
53};
54
55template<typename Real>
56class Algorithm {
57protected:
58 const Ptr<CombinedStatusTest<Real>> status_;
59 const Ptr<AlgorithmState<Real>> state_;
60 Ptr<PolyhedralProjection<Real>> proj_;
61
62 void initialize( const Vector<Real> &x,
63 const Vector<Real> &g,
64 const Vector<Real> &mul,
65 const Vector<Real> &c);
66
67public:
68
69 virtual ~Algorithm() {}
70
73 Algorithm();
74
75 void setStatusTest( const Ptr<StatusTest<Real>> &status,
76 bool combineStatus = false);
77
81 virtual void run( Problem<Real> &problem,
82 std::ostream &outStream = std::cout );
83
87 virtual void run( Vector<Real> &x,
88 Objective<Real> &obj,
90 Constraint<Real> &econ,
91 Vector<Real> &emul,
92 std::ostream &outStream = std::cout );
93
97 virtual void run( Vector<Real> &x,
98 Objective<Real> &obj,
99 Constraint<Real> &icon,
100 Vector<Real> &imul,
102 std::ostream &outStream = std::cout );
103
107 virtual void run( Vector<Real> &x,
108 Objective<Real> &obj,
110 Constraint<Real> &icon,
111 Vector<Real> &imul,
113 std::ostream &outStream = std::cout );
114
118 virtual void run( Vector<Real> &x,
119 Objective<Real> &obj,
120 Constraint<Real> &econ,
121 Vector<Real> &emul,
122 Constraint<Real> &icon,
123 Vector<Real> &imul,
125 std::ostream &outStream = std::cout );
126
130 virtual void run( Vector<Real> &x,
131 Objective<Real> &obj,
133 Constraint<Real> &econ,
134 Vector<Real> &emul,
135 Constraint<Real> &icon,
136 Vector<Real> &imul,
138 std::ostream &outStream = std::cout );
139
140
144 virtual void run( Vector<Real> &x,
145 const Vector<Real> &g,
146 Objective<Real> &obj,
148 Constraint<Real> &econ,
149 Vector<Real> &emul,
150 const Vector<Real> &eres,
151 std::ostream &outStream = std::cout ) = 0;
152
156 virtual void run( Vector<Real> &x,
157 const Vector<Real> &g,
158 Objective<Real> &obj,
159 Constraint<Real> &icon,
160 Vector<Real> &imul,
162 const Vector<Real> &ires,
163 std::ostream &outStream = std::cout );
164
168 virtual void run( Vector<Real> &x,
169 const Vector<Real> &g,
170 Objective<Real> &obj,
172 Constraint<Real> &icon,
173 Vector<Real> &imul,
175 const Vector<Real> &ires,
176 std::ostream &outStream = std::cout );
177
181 virtual void run( Vector<Real> &x,
182 const Vector<Real> &g,
183 Objective<Real> &obj,
184 Constraint<Real> &econ,
185 Vector<Real> &emul,
186 const Vector<Real> &eres,
187 Constraint<Real> &icon,
188 Vector<Real> &imul,
190 const Vector<Real> &ires,
191 std::ostream &outStream = std::cout );
192
196 virtual void run( Vector<Real> &x,
197 const Vector<Real> &g,
198 Objective<Real> &obj,
200 Constraint<Real> &econ,
201 Vector<Real> &emul,
202 const Vector<Real> &eres,
203 Constraint<Real> &icon,
204 Vector<Real> &imul,
206 const Vector<Real> &ires,
207 std::ostream &outStream = std::cout );
208
209
210
211
215 virtual void run( Vector<Real> &x,
216 Objective<Real> &obj,
218 Constraint<Real> &econ,
219 Vector<Real> &emul,
220 Constraint<Real> &linear_econ,
221 Vector<Real> &linear_emul,
222 std::ostream &outStream = std::cout );
223
227 virtual void run( Vector<Real> &x,
228 Objective<Real> &obj,
229 Constraint<Real> &icon,
230 Vector<Real> &imul,
232 Constraint<Real> &linear_econ,
233 Vector<Real> &linear_emul,
234 std::ostream &outStream = std::cout );
235
239 virtual void run( Vector<Real> &x,
240 Objective<Real> &obj,
242 Constraint<Real> &icon,
243 Vector<Real> &imul,
245 Constraint<Real> &linear_econ,
246 Vector<Real> &linear_emul,
247 std::ostream &outStream = std::cout );
248
252 virtual void run( Vector<Real> &x,
253 Objective<Real> &obj,
254 Constraint<Real> &econ,
255 Vector<Real> &emul,
256 Constraint<Real> &icon,
257 Vector<Real> &imul,
259 Constraint<Real> &linear_econ,
260 Vector<Real> &linear_emul,
261 std::ostream &outStream = std::cout );
262
266 virtual void run( Vector<Real> &x,
267 Objective<Real> &obj,
269 Constraint<Real> &econ,
270 Vector<Real> &emul,
271 Constraint<Real> &icon,
272 Vector<Real> &imul,
274 Constraint<Real> &linear_econ,
275 Vector<Real> &linear_emul,
276 std::ostream &outStream = std::cout );
277
278
279
280
284 virtual void run( Vector<Real> &x,
285 const Vector<Real> &g,
286 Objective<Real> &obj,
288 Constraint<Real> &econ,
289 Vector<Real> &emul,
290 const Vector<Real> &eres,
291 Constraint<Real> &linear_econ,
292 Vector<Real> &linear_emul,
293 const Vector<Real> &linear_eres,
294 std::ostream &outStream = std::cout );
295
299 virtual void run( Vector<Real> &x,
300 const Vector<Real> &g,
301 Objective<Real> &obj,
302 Constraint<Real> &icon,
303 Vector<Real> &imul,
305 const Vector<Real> &ires,
306 Constraint<Real> &linear_econ,
307 Vector<Real> &linear_emul,
308 const Vector<Real> &linear_eres,
309 std::ostream &outStream = std::cout );
310
314 virtual void run( Vector<Real> &x,
315 const Vector<Real> &g,
316 Objective<Real> &obj,
318 Constraint<Real> &icon,
319 Vector<Real> &imul,
321 const Vector<Real> &ires,
322 Constraint<Real> &linear_econ,
323 Vector<Real> &linear_emul,
324 const Vector<Real> &linear_eres,
325 std::ostream &outStream = std::cout );
326
330 virtual void run( Vector<Real> &x,
331 const Vector<Real> &g,
332 Objective<Real> &obj,
333 Constraint<Real> &econ,
334 Vector<Real> &emul,
335 const Vector<Real> &eres,
336 Constraint<Real> &icon,
337 Vector<Real> &imul,
339 const Vector<Real> &ires,
340 Constraint<Real> &linear_econ,
341 Vector<Real> &linear_emul,
342 const Vector<Real> &linear_eres,
343 std::ostream &outStream = std::cout );
344
348 virtual void run( Vector<Real> &x,
349 const Vector<Real> &g,
350 Objective<Real> &obj,
352 Constraint<Real> &econ,
353 Vector<Real> &emul,
354 const Vector<Real> &eres,
355 Constraint<Real> &icon,
356 Vector<Real> &imul,
358 const Vector<Real> &ires,
359 Constraint<Real> &linear_econ,
360 Vector<Real> &linear_emul,
361 const Vector<Real> &linear_eres,
362 std::ostream &outStream = std::cout );
363
366 virtual void writeHeader( std::ostream& os ) const;
367
370 virtual void writeName( std::ostream& os ) const;
371
374 virtual void writeOutput( std::ostream& os, const bool write_header = false ) const;
375
376 virtual void writeExitStatus( std::ostream& os ) const;
377
378 //Ptr<const AlgorithmState<Real>>& getState() const;
379 Ptr<const AlgorithmState<Real>> getState() const;
380
381 void reset();
382
383}; // class ROL::Algorithm
384
385} // namespace TypeG
386} // namespace ROL
387
389
390#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 general constrained optimization algorithms.
virtual void run(Problem< Real > &problem, std::ostream &outStream=std::cout)
Run algorithm on general constrained problems (Type-G). This is the primary Type-G interface.
virtual void writeOutput(std::ostream &os, const bool write_header=false) const
Print iterate status.
virtual void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, Constraint< Real > &econ, Vector< Real > &emul, const Vector< Real > &eres, std::ostream &outStream=std::cout)=0
Run algorithm on general constrained problems (Type-G). This is the primary Type-G interface.
virtual void writeName(std::ostream &os) const
Print step name.
Algorithm()
Constructor, given a step and a status test.
virtual void writeHeader(std::ostream &os) const
Print iterate header.
void initialize(const Vector< Real > &x, const Vector< Real > &g, const Vector< Real > &mul, const Vector< Real > &c)
Ptr< const AlgorithmState< Real > > getState() const
virtual void writeExitStatus(std::ostream &os) const
const Ptr< CombinedStatusTest< Real > > status_
Ptr< PolyhedralProjection< Real > > proj_
void setStatusTest(const Ptr< StatusTest< Real > > &status, bool combineStatus=false)
const Ptr< AlgorithmState< Real > > state_
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