ROL
ROL_Step.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_STEP_H
11#define ROL_STEP_H
12
13#include "ROL_Vector.hpp"
14#include "ROL_Objective.hpp"
16#include "ROL_Constraint.hpp"
17#include "ROL_Types.hpp"
18
19#include "ROL_ParameterList.hpp"
20
27namespace ROL {
28
29// We need a forward declaration here, because some steps are algorithms.
30template<class Real>
31class Algorithm;
32
33template <class Real>
34class Step {
35private:
36 ROL::Ptr<StepState<Real> > state_;
37
38protected:
39 ROL::Ptr<StepState<Real> > getState(void) {
40 return state_;
41 }
42
43public:
44
45 virtual ~Step() {}
46
47 Step(void) {
48 state_ = ROL::makePtr<StepState<Real>>();
49 }
50
51
54 virtual void initialize( Vector<Real> &x, const Vector<Real> &g,
56 AlgorithmState<Real> &algo_state ) {
57 initialize(x,x,g,obj,con,algo_state);
58 }
59
62 virtual void initialize( Vector<Real> &x, const Vector<Real> &s, const Vector<Real> &g,
64 AlgorithmState<Real> &algo_state ) {
65 Real tol = std::sqrt(ROL_EPSILON<Real>()), one(1), zero(0);
66 // Initialize state descent direction and gradient storage
67 state_->descentVec = s.clone();
68 state_->gradientVec = g.clone();
69 state_->searchSize = zero;
70 // Project x onto constraint set
71 if ( con.isActivated() ) {
72 con.project(x);
73 }
74 // Update objective function, get value, and get gradient
75 obj.update(x,true,algo_state.iter);
76 algo_state.value = obj.value(x,tol);
77 algo_state.nfval++;
78 obj.gradient(*(state_->gradientVec),x,tol);
79 algo_state.ngrad++;
80 if ( con.isActivated() ) {
81 ROL::Ptr<Vector<Real> > xnew = x.clone();
82 xnew->set(x);
83 xnew->axpy(-one,(Step<Real>::state_->gradientVec)->dual());
84 con.project(*xnew);
85 xnew->axpy(-one,x);
86 algo_state.gnorm = xnew->norm();
87 }
88 else {
89 algo_state.gnorm = (state_->gradientVec)->norm();
90 }
91 }
92
95 virtual void initialize( Vector<Real> &x, const Vector<Real> &g, Vector<Real> &l, const Vector<Real> &c,
97 AlgorithmState<Real> &algo_state ) {
98 }
99
102 virtual void initialize( Vector<Real> &x, const Vector<Real> &g, Vector<Real> &l, const Vector<Real> &c,
104 AlgorithmState<Real> &algo_state ) {
105 }
106
109 virtual void compute( Vector<Real> &s, const Vector<Real> &x,
111 AlgorithmState<Real> &algo_state ) {
112 throw Exception::NotImplemented(">>> ROL::Step::compute(s,x,obj,bnd,algo_state) is not implemented!");
113 }
114
117 virtual void update( Vector<Real> &x, const Vector<Real> &s,
119 AlgorithmState<Real> &algo_state ) {
120 throw Exception::NotImplemented(">>> ROL::Step::update(x,s,obj,bnd,algo_state) is not implemented!");
121 }
122
125 virtual void compute( Vector<Real> &s, const Vector<Real> &x, const Vector<Real> &l,
127 AlgorithmState<Real> &algo_state ) {
128 throw Exception::NotImplemented(">>> ROL::Step::compute(s,x,l,obj,con,algo_state) is not implemented!");
129 }
130
133 virtual void update( Vector<Real> &x, Vector<Real> &l, const Vector<Real> &s,
135 AlgorithmState<Real> &algo_state ) {
136 throw Exception::NotImplemented(">>> ROL::Step::update(x,s,l,obj,bnd,con,algo_state) is not implemented!");
137 }
138
141 virtual void compute( Vector<Real> &s, const Vector<Real> &x, const Vector<Real> &l,
144 AlgorithmState<Real> &algo_state ) {
145 throw Exception::NotImplemented(">>> ROL::Step::compute(s,x,l,obj,bnd,con,algo_state) is not implemented!");
146 }
147
150 virtual void update( Vector<Real> &x, Vector<Real> &l, const Vector<Real> &s,
153 AlgorithmState<Real> &algo_state ) {
154 throw Exception::NotImplemented(">>> ROL::Step::update(x,s,l,obj,bnd,con,algo_state) is not implemented!");
155 }
156
159 virtual std::string printHeader( void ) const {
160 throw Exception::NotImplemented(">>> ROL::Step::printHeader() is not implemented!");
161 }
162
165 virtual std::string printName( void ) const {
166 throw Exception::NotImplemented(">>> ROL::Step::printName() is not implemented!");
167 }
168
171 virtual std::string print( AlgorithmState<Real> &algo_state, bool printHeader = false ) const {
172 throw Exception::NotImplemented(">>> ROL::Step::print(algo_state,printHeader) is not implemented!");
173 }
174
177 const ROL::Ptr<const StepState<Real> > getStepState(void) const {
178 return state_;
179 }
180
183 void reset(const Real searchSize = 1.0) {
184 state_->reset(searchSize);
185 }
186
187 // struct StepState (scalars, vectors) map?
188
189 // getState
190
191 // setState
192
193}; // class Step
194
195} // namespace ROL
196
197#endif
Objective_SerialSimOpt(const Ptr< Obj > &obj, const V &ui) z0_ zero()
Contains definitions of custom data types in ROL.
Provides the interface to apply upper and lower bound constraints.
bool isActivated(void) const
Check if bounds are on.
virtual void project(Vector< Real > &x)
Project optimization variables onto the bounds.
Defines the general constraint operator interface.
Provides the interface to evaluate objective functions.
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update objective function.
Provides the interface to compute optimization steps.
Definition ROL_Step.hpp:34
virtual void initialize(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Initialize step with bound constraint.
Definition ROL_Step.hpp:54
ROL::Ptr< StepState< Real > > getState(void)
Definition ROL_Step.hpp:39
virtual std::string print(AlgorithmState< Real > &algo_state, bool printHeader=false) const
Print iterate status.
Definition ROL_Step.hpp:171
virtual void compute(Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Compute step.
Definition ROL_Step.hpp:109
virtual void compute(Vector< Real > &s, const Vector< Real > &x, const Vector< Real > &l, Objective< Real > &obj, Constraint< Real > &con, AlgorithmState< Real > &algo_state)
Compute step (equality constraints).
Definition ROL_Step.hpp:125
void reset(const Real searchSize=1.0)
Get state for step object.
Definition ROL_Step.hpp:183
virtual std::string printName(void) const
Print step name.
Definition ROL_Step.hpp:165
virtual void initialize(Vector< Real > &x, const Vector< Real > &g, Vector< Real > &l, const Vector< Real > &c, Objective< Real > &obj, Constraint< Real > &con, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Initialize step with equality constraint.
Definition ROL_Step.hpp:102
ROL::Ptr< StepState< Real > > state_
Definition ROL_Step.hpp:36
virtual ~Step()
Definition ROL_Step.hpp:45
virtual void update(Vector< Real > &x, Vector< Real > &l, const Vector< Real > &s, Objective< Real > &obj, Constraint< Real > &con, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Update step, if successful (equality constraints).
Definition ROL_Step.hpp:150
virtual std::string printHeader(void) const
Print iterate header.
Definition ROL_Step.hpp:159
Step(void)
Definition ROL_Step.hpp:47
virtual void initialize(Vector< Real > &x, const Vector< Real > &s, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Initialize step with bound constraint.
Definition ROL_Step.hpp:62
virtual void initialize(Vector< Real > &x, const Vector< Real > &g, Vector< Real > &l, const Vector< Real > &c, Objective< Real > &obj, Constraint< Real > &con, AlgorithmState< Real > &algo_state)
Initialize step with equality constraint.
Definition ROL_Step.hpp:95
virtual void update(Vector< Real > &x, Vector< Real > &l, const Vector< Real > &s, Objective< Real > &obj, Constraint< Real > &con, AlgorithmState< Real > &algo_state)
Update step, if successful (equality constraints).
Definition ROL_Step.hpp:133
virtual void compute(Vector< Real > &s, const Vector< Real > &x, const Vector< Real > &l, Objective< Real > &obj, Constraint< Real > &con, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Compute step (equality constraints).
Definition ROL_Step.hpp:141
virtual void update(Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Update step, if successful.
Definition ROL_Step.hpp:117
const ROL::Ptr< const StepState< Real > > getStepState(void) const
Get state for step object.
Definition ROL_Step.hpp:177
Defines the linear algebra or vector space interface.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
State for algorithm class. Will be used for restarts.