ROL
ROL_TypeP_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_TYPEP_ALGORITHM_H
45#define ROL_TYPEP_ALGORITHM_H
46
48#include "ROL_Objective.hpp"
49#include "ROL_Problem.hpp"
50
54
55namespace ROL {
56namespace TypeP {
57
58template<typename Real>
59struct AlgorithmState : public ROL::AlgorithmState<Real> {
61 Ptr<Vector<Real>> stepVec, gradientVec;
63
65 : searchSize(1),
66 svalue(ROL_INF<Real>()),
67 nvalue(ROL_INF<Real>()),
68 stepVec(nullPtr),
69 gradientVec(nullPtr),
70 nprox(0),
71 nsval(0),
72 nnval(0) {}
73
74 void reset() {
76 searchSize = static_cast<Real>(1);
79 if (stepVec != nullPtr)
80 stepVec->zero();
81 if (gradientVec != nullPtr)
82 gradientVec->zero();
83 nprox = 0;
84 nsval = 0;
85 nnval = 0;
86 }
87};
88
89template<typename Real>
90class Algorithm {
91protected:
92 const Ptr<CombinedStatusTest<Real>> status_;
93 const Ptr<AlgorithmState<Real>> state_;
94
95 void initialize(const Vector<Real> &x, const Vector<Real> &g);
96 void pgstep(Vector<Real> &pgiter, // pgiter = Prox(x - t dg)
97 Vector<Real> &pgstep, // pgstep = pgiter - x
98 Objective<Real> &nobj, // nobj = nonsmooth objective
99 const Vector<Real> &x, // x = current iterate
100 const Vector<Real> &dg, // dg = dual of current gradient
101 Real t, // t = prox parameter
102 Real &tol) const;
103
104public:
105
106 virtual ~Algorithm() {}
107
110 Algorithm();
111
112 void setStatusTest(const Ptr<StatusTest<Real>> &status,
113 bool combineStatus = false);
114
118 virtual void run( Problem<Real> &problem,
119 std::ostream &outStream = std::cout );
120
124 virtual void run( Vector<Real> &x,
125 Objective<Real> &sobj,
126 Objective<Real> &nobj,
127 std::ostream &outStream = std::cout );
128
133 virtual void run( Vector<Real> &x,
134 const Vector<Real> &g,
135 Objective<Real> &sobj,
136 Objective<Real> &nobj,
137 std::ostream &outStream = std::cout) = 0;
138
141 virtual void writeHeader( std::ostream& os ) const;
142
145 virtual void writeName( std::ostream& os ) const;
146
149 virtual void writeOutput( std::ostream& os, bool write_header = false ) const;
150
151 virtual void writeExitStatus( std::ostream& os ) const;
152
153 //Ptr<const AlgorithmState<Real>>& getState() const;
154 Ptr<const AlgorithmState<Real>> getState() const;
155
156 void reset();
157
158}; // class ROL::TypeP::Algorithm
159} // namespace TypeP
160} // namespace ROL
161
163
164#endif
Provides the interface to evaluate objective functions.
Provides an interface to check status of optimization algorithms.
void pgstep(Vector< Real > &pgiter, Vector< Real > &pgstep, Objective< Real > &nobj, const Vector< Real > &x, const Vector< Real > &dg, Real t, Real &tol) const
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.
Ptr< const AlgorithmState< Real > > getState() const
const Ptr< AlgorithmState< Real > > state_
Algorithm()
Constructor, given a step and a status test.
virtual void writeHeader(std::ostream &os) const
Print iterate header.
virtual void writeExitStatus(std::ostream &os) const
virtual void writeOutput(std::ostream &os, bool write_header=false) const
Print iterate status.
const Ptr< CombinedStatusTest< Real > > status_
void setStatusTest(const Ptr< StatusTest< Real > > &status, bool combineStatus=false)
virtual void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &sobj, Objective< Real > &nobj, std::ostream &outStream=std::cout)=0
Run algorithm on unconstrained problems (Type-U). This general interface supports the use of dual opt...
void initialize(const Vector< Real > &x, const Vector< Real > &g)
Defines the linear algebra or vector space interface.
Real ROL_INF(void)
State for algorithm class. Will be used for restarts.
Ptr< Vector< Real > > gradientVec