ROL
ROL_TypeU_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_TYPEU_ALGORITHM_H
45#define ROL_TYPEU_ALGORITHM_H
46
48#include "ROL_Objective.hpp"
49#include "ROL_Constraint.hpp"
50#include "ROL_Problem.hpp"
51
55
56namespace ROL {
57namespace TypeU {
58
59template<typename Real>
60struct AlgorithmState : public ROL::AlgorithmState<Real> {
62 Ptr<Vector<Real>> stepVec;
63 Ptr<Vector<Real>> gradientVec;
64
66 : searchSize(1),
67 stepVec(nullPtr),
68 gradientVec(nullPtr) {}
69
70 void reset() {
72 searchSize = static_cast<Real>(1);
73 if (stepVec != nullPtr) {
74 stepVec->zero();
75 }
76 if (gradientVec != nullPtr) {
77 gradientVec->zero();
78 }
79 }
80};
81
82template<typename Real>
83class Algorithm {
84protected:
85 const Ptr<CombinedStatusTest<Real>> status_;
86 const Ptr<AlgorithmState<Real>> state_;
87
88 void initialize(const Vector<Real> &x, const Vector<Real> &g);
89
90public:
91
92 virtual ~Algorithm() {}
93
97
98 void setStatusTest(const Ptr<StatusTest<Real>> &status,
99 bool combineStatus = false);
100
104 virtual void run( Problem<Real> &problem,
105 std::ostream &outStream = std::cout );
106
110 virtual void run( Vector<Real> &x,
111 Objective<Real> &obj,
112 std::ostream &outStream = std::cout );
113
119 virtual void run( Vector<Real> &x,
120 Objective<Real> &obj,
121 Constraint<Real> &linear_con,
122 Vector<Real> &linear_mul,
123 std::ostream &outStream = std::cout );
124
130 virtual void run( Vector<Real> &x,
131 const Vector<Real> &g,
132 Objective<Real> &obj,
133 Constraint<Real> &linear_con,
134 Vector<Real> &linear_mul,
135 const Vector<Real> &linear_c,
136 std::ostream &outStream = std::cout );
137
142 virtual void run( Vector<Real> &x,
143 const Vector<Real> &g,
144 Objective<Real> &obj,
145 std::ostream &outStream = std::cout) = 0;
146
149 virtual void writeHeader( std::ostream& os ) const;
150
153 virtual void writeName( std::ostream& os ) const;
154
157 virtual void writeOutput( std::ostream& os, bool write_header = false ) const;
158
159 virtual void writeExitStatus( std::ostream& os ) const;
160
161 //Ptr<const AlgorithmState<Real>>& getState() const;
162 Ptr<const AlgorithmState<Real>> getState() const;
163
164 void reset();
165
166}; // class ROL::TypeU::Algorithm
167} // namespace TypeU
168} // namespace ROL
169
171
172#endif
Defines the general constraint operator interface.
Provides the interface to evaluate objective functions.
Provides an interface to check status of optimization algorithms.
Algorithm()
Constructor, given a step and a status test.
virtual void run(Vector< Real > &x, Objective< Real > &obj, Constraint< Real > &linear_con, Vector< Real > &linear_mul, std::ostream &outStream=std::cout)
Run algorithm on unconstrained problems with explicit linear equality constraints (Type-U)....
const Ptr< CombinedStatusTest< Real > > status_
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 writeName(std::ostream &os) const
Print step name.
virtual void writeHeader(std::ostream &os) const
Print iterate header.
Ptr< const AlgorithmState< Real > > getState() const
void initialize(const Vector< Real > &x, const Vector< Real > &g)
virtual void run(Vector< Real > &x, Objective< Real > &obj, std::ostream &outStream=std::cout)
Run algorithm on unconstrained problems (Type-U). This is the primary Type-U interface.
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...
virtual void writeOutput(std::ostream &os, bool write_header=false) const
Print iterate status.
virtual void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, Constraint< Real > &linear_con, Vector< Real > &linear_mul, const Vector< Real > &linear_c, std::ostream &outStream=std::cout)
Run algorithm on unconstrained problems with explicit linear equality constraints (Type-U)....
void setStatusTest(const Ptr< StatusTest< Real > > &status, bool combineStatus=false)
const Ptr< AlgorithmState< Real > > state_
virtual void writeExitStatus(std::ostream &os) const
Defines the linear algebra or vector space interface.
State for algorithm class. Will be used for restarts.
Ptr< Vector< Real > > gradientVec