ROL
ROL_TypeE_Algorithm.hpp
Go to the documentation of this file.
1// @HEADER
2// ************************************************************************
3//
4// Rapid Optimization Library (ROL) Package
5// Copyright (2014) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact lead developers:
38// Drew Kouri (dpkouri@sandia.gov) and
39// Denis Ridzal (dridzal@sandia.gov)
40//
41// ************************************************************************
42// @HEADER
43
44#ifndef ROL_TYPEE_ALGORITHM_H
45#define ROL_TYPEE_ALGORITHM_H
46
48#include "ROL_Objective.hpp"
49#include "ROL_Constraint.hpp"
50#include "ROL_Problem.hpp"
51
56namespace ROL {
57namespace TypeE {
58
59template<typename Real>
60struct AlgorithmState : public ROL::AlgorithmState<Real> {
62 Ptr<Vector<Real>> stepVec;
63 Ptr<Vector<Real>> gradientVec;
64 Ptr<Vector<Real>> constraintVec;
65
67 : searchSize(1),
68 stepVec(nullPtr),
69 gradientVec(nullPtr),
70 constraintVec(nullPtr) {}
71
72 void reset() {
74 searchSize = static_cast<Real>(1);
75 if (stepVec != nullPtr) {
76 stepVec->zero();
77 }
78 if (gradientVec != nullPtr) {
79 gradientVec->zero();
80 }
81 if (constraintVec != nullPtr) {
82 constraintVec->zero();
83 }
84 }
85};
86
87template<typename Real>
88class Algorithm {
89protected:
90 const Ptr<CombinedStatusTest<Real>> status_;
91 const Ptr<AlgorithmState<Real>> state_;
92
93 void initialize(const Vector<Real> &x,
94 const Vector<Real> &g,
95 const Vector<Real> &mul,
96 const Vector<Real> &c);
97
98public:
99
100 virtual ~Algorithm() {}
101
104 Algorithm();
105
106 void setStatusTest( const Ptr<StatusTest<Real>> &status,
107 bool combineStatus = false);
108
112 virtual void run( Problem<Real> &problem,
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 std::ostream &outStream = std::cout );
123
128 virtual void run( Vector<Real> &x,
129 const Vector<Real> &g,
130 Objective<Real> &obj,
131 Constraint<Real> &econ,
132 Vector<Real> &emul,
133 const Vector<Real> &eres,
134 std::ostream &outStream = std::cout) = 0;
135
141 virtual void run( Vector<Real> &x,
142 Objective<Real> &obj,
143 Constraint<Real> &econ,
144 Vector<Real> &emul,
145 Constraint<Real> &linear_econ,
146 Vector<Real> &linear_emul,
147 std::ostream &outStream = std::cout );
148
154 virtual void run( Vector<Real> &x,
155 const Vector<Real> &g,
156 Objective<Real> &obj,
157 Constraint<Real> &econ,
158 Vector<Real> &emul,
159 const Vector<Real> &eres,
160 Constraint<Real> &linear_econ,
161 Vector<Real> &linear_emul,
162 const Vector<Real> &linear_eres,
163 std::ostream &outStream = std::cout );
164
167 virtual void writeHeader( std::ostream& os ) const;
168
171 virtual void writeName( std::ostream& os ) const;
172
175 virtual void writeOutput( std::ostream& os, bool write_header = false ) const;
176
177 virtual void writeExitStatus( std::ostream& os ) const;
178
179 Ptr<const AlgorithmState<Real>> getState() const;
180 //Ptr<const AlgorithmState<Real>>& getState() const;
181
182 void reset();
183
184}; // class ROL::Algorithm
185} // namespace TypeE
186} // namespace ROL
187
189
190#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...
virtual void writeOutput(std::ostream &os, bool write_header=false) const
Print iterate status.
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.
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.
Definition: ROL_Vector.hpp:84
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:143
Ptr< Vector< Real > > stepVec
Ptr< Vector< Real > > constraintVec
Ptr< Vector< Real > > gradientVec