ROL
ROL_Step.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_STEP_H
45#define ROL_STEP_H
46
47#include "ROL_Vector.hpp"
48#include "ROL_Objective.hpp"
50#include "ROL_Constraint.hpp"
51#include "ROL_Types.hpp"
52
53#include "ROL_ParameterList.hpp"
54
61namespace ROL {
62
63// We need a forward declaration here, because some steps are algorithms.
64template<class Real>
65class Algorithm;
66
67template <class Real>
68class Step {
69private:
70 ROL::Ptr<StepState<Real> > state_;
71
72protected:
73 ROL::Ptr<StepState<Real> > getState(void) {
74 return state_;
75 }
76
77public:
78
79 virtual ~Step() {}
80
81 Step(void) {
82 state_ = ROL::makePtr<StepState<Real>>();
83 }
84
85
88 virtual void initialize( Vector<Real> &x, const Vector<Real> &g,
90 AlgorithmState<Real> &algo_state ) {
91 initialize(x,x,g,obj,con,algo_state);
92 }
93
96 virtual void initialize( Vector<Real> &x, const Vector<Real> &s, const Vector<Real> &g,
98 AlgorithmState<Real> &algo_state ) {
99 Real tol = std::sqrt(ROL_EPSILON<Real>()), one(1), zero(0);
100 // Initialize state descent direction and gradient storage
101 state_->descentVec = s.clone();
102 state_->gradientVec = g.clone();
103 state_->searchSize = zero;
104 // Project x onto constraint set
105 if ( con.isActivated() ) {
106 con.project(x);
107 }
108 // Update objective function, get value, and get gradient
109 obj.update(x,true,algo_state.iter);
110 algo_state.value = obj.value(x,tol);
111 algo_state.nfval++;
112 obj.gradient(*(state_->gradientVec),x,tol);
113 algo_state.ngrad++;
114 if ( con.isActivated() ) {
115 ROL::Ptr<Vector<Real> > xnew = x.clone();
116 xnew->set(x);
117 xnew->axpy(-one,(Step<Real>::state_->gradientVec)->dual());
118 con.project(*xnew);
119 xnew->axpy(-one,x);
120 algo_state.gnorm = xnew->norm();
121 }
122 else {
123 algo_state.gnorm = (state_->gradientVec)->norm();
124 }
125 }
126
129 virtual void initialize( Vector<Real> &x, const Vector<Real> &g, Vector<Real> &l, const Vector<Real> &c,
131 AlgorithmState<Real> &algo_state ) {
132 }
133
136 virtual void initialize( Vector<Real> &x, const Vector<Real> &g, Vector<Real> &l, const Vector<Real> &c,
138 AlgorithmState<Real> &algo_state ) {
139 }
140
143 virtual void compute( Vector<Real> &s, const Vector<Real> &x,
145 AlgorithmState<Real> &algo_state ) {
146 throw Exception::NotImplemented(">>> ROL::Step::compute(s,x,obj,bnd,algo_state) is not implemented!");
147 }
148
151 virtual void update( Vector<Real> &x, const Vector<Real> &s,
153 AlgorithmState<Real> &algo_state ) {
154 throw Exception::NotImplemented(">>> ROL::Step::update(x,s,obj,bnd,algo_state) is not implemented!");
155 }
156
159 virtual void compute( Vector<Real> &s, const Vector<Real> &x, const Vector<Real> &l,
161 AlgorithmState<Real> &algo_state ) {
162 throw Exception::NotImplemented(">>> ROL::Step::compute(s,x,l,obj,con,algo_state) is not implemented!");
163 }
164
167 virtual void update( Vector<Real> &x, Vector<Real> &l, const Vector<Real> &s,
169 AlgorithmState<Real> &algo_state ) {
170 throw Exception::NotImplemented(">>> ROL::Step::update(x,s,l,obj,bnd,con,algo_state) is not implemented!");
171 }
172
175 virtual void compute( Vector<Real> &s, const Vector<Real> &x, const Vector<Real> &l,
178 AlgorithmState<Real> &algo_state ) {
179 throw Exception::NotImplemented(">>> ROL::Step::compute(s,x,l,obj,bnd,con,algo_state) is not implemented!");
180 }
181
184 virtual void update( Vector<Real> &x, Vector<Real> &l, const Vector<Real> &s,
187 AlgorithmState<Real> &algo_state ) {
188 throw Exception::NotImplemented(">>> ROL::Step::update(x,s,l,obj,bnd,con,algo_state) is not implemented!");
189 }
190
193 virtual std::string printHeader( void ) const {
194 throw Exception::NotImplemented(">>> ROL::Step::printHeader() is not implemented!");
195 }
196
199 virtual std::string printName( void ) const {
200 throw Exception::NotImplemented(">>> ROL::Step::printName() is not implemented!");
201 }
202
205 virtual std::string print( AlgorithmState<Real> &algo_state, bool printHeader = false ) const {
206 throw Exception::NotImplemented(">>> ROL::Step::print(algo_state,printHeader) is not implemented!");
207 }
208
211 const ROL::Ptr<const StepState<Real> > getStepState(void) const {
212 return state_;
213 }
214
217 void reset(const Real searchSize = 1.0) {
218 state_->reset(searchSize);
219 }
220
221 // struct StepState (scalars, vectors) map?
222
223 // getState
224
225 // setState
226
227}; // class Step
228
229} // namespace ROL
230
231#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:68
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:88
ROL::Ptr< StepState< Real > > getState(void)
Definition ROL_Step.hpp:73
virtual std::string print(AlgorithmState< Real > &algo_state, bool printHeader=false) const
Print iterate status.
Definition ROL_Step.hpp:205
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:143
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:159
void reset(const Real searchSize=1.0)
Get state for step object.
Definition ROL_Step.hpp:217
virtual std::string printName(void) const
Print step name.
Definition ROL_Step.hpp:199
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:136
ROL::Ptr< StepState< Real > > state_
Definition ROL_Step.hpp:70
virtual ~Step()
Definition ROL_Step.hpp:79
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:184
virtual std::string printHeader(void) const
Print iterate header.
Definition ROL_Step.hpp:193
Step(void)
Definition ROL_Step.hpp:81
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:96
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:129
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:167
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:175
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:151
const ROL::Ptr< const StepState< Real > > getStepState(void) const
Get state for step object.
Definition ROL_Step.hpp:211
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.