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"
49 #include "ROL_BoundConstraint.hpp"
51 #include "ROL_Types.hpp"
52 #include "Teuchos_ParameterList.hpp"
53 
60 namespace ROL {
61 
62 // We need a forward declaration here, because some steps are algorithms.
63 template<class Real>
64 class Algorithm;
65 
66 template <class Real>
67 class Step {
68 private:
69  Teuchos::RCP<StepState<Real> > state_;
70 
71 protected:
72  Teuchos::RCP<StepState<Real> > getState(void) {
73  return this->state_;
74  }
75 
76 public:
77 
78  virtual ~Step() {}
79 
80  Step(void) {
81  state_ = Teuchos::rcp( new StepState<Real> );
82  }
83 
84 
87  virtual void initialize( Vector<Real> &x, const Vector<Real> &g,
89  AlgorithmState<Real> &algo_state ) {
90  initialize(x,x,g,obj,con,algo_state);
91  }
92 
95  virtual void initialize( Vector<Real> &x, const Vector<Real> &s, const Vector<Real> &g,
97  AlgorithmState<Real> &algo_state ) {
98  Real tol = std::sqrt(ROL_EPSILON);
99  // Initialize state descent direction and gradient storage
100  state_->descentVec = s.clone();
101  state_->gradientVec = g.clone();
102  state_->searchSize = 0.0;
103  // Project x onto constraint set
104  if ( con.isActivated() ) {
105  con.project(x);
106  }
107  // Update objective function, get value, and get gradient
108  obj.update(x,true,algo_state.iter);
109  algo_state.value = obj.value(x,tol);
110  algo_state.nfval++;
111  obj.gradient(*(state_->gradientVec),x,tol);
112  algo_state.ngrad++;
113  if ( con.isActivated() ) {
114  Teuchos::RCP<Vector<Real> > xnew = x.clone();
115  xnew->set(x);
116  xnew->axpy(-1.0,(Step<Real>::state_->gradientVec)->dual());
117  con.project(*xnew);
118  xnew->axpy(-1.0,x);
119  algo_state.gnorm = xnew->norm();
120  }
121  else {
122  algo_state.gnorm = (state_->gradientVec)->norm();
123  }
124  }
125 
128  virtual void initialize( Vector<Real> &x, const Vector<Real> &g, Vector<Real> &l, const Vector<Real> &c,
130  AlgorithmState<Real> &algo_state ) {
131  }
132 
135  virtual void initialize( Vector<Real> &x, const Vector<Real> &g, Vector<Real> &l, const Vector<Real> &c,
137  AlgorithmState<Real> &algo_state ) {
138  }
139 
142  virtual void compute( Vector<Real> &s, const Vector<Real> &x, Objective<Real> &obj,
143  BoundConstraint<Real> &con,
144  AlgorithmState<Real> &algo_state ) = 0;
145 
148  virtual void update( Vector<Real> &x, const Vector<Real> &s, Objective<Real> &obj,
150  AlgorithmState<Real> &algo_state ) = 0;
151 
154  virtual void compute( Vector<Real> &s, const Vector<Real> &x, const Vector<Real> &l,
156  AlgorithmState<Real> &algo_state ) {}
157 
160  virtual void update( Vector<Real> &x, Vector<Real> &l, const Vector<Real> &s,
162  AlgorithmState<Real> &algo_state ) {}
163 
166  virtual void compute( Vector<Real> &s, const Vector<Real> &x, const Vector<Real> &l,
169  AlgorithmState<Real> &algo_state ) {}
170 
173  virtual void update( Vector<Real> &x, Vector<Real> &l, const Vector<Real> &s,
176  AlgorithmState<Real> &algo_state ) {}
177 
180  virtual std::string printHeader( void ) const = 0;
181 
184  virtual std::string printName( void ) const = 0;
185 
188  virtual std::string print( AlgorithmState<Real> &algo_state, bool printHeader = false ) const = 0;
189 
192  virtual Teuchos::RCP<const StepState<Real> > getStepState(void) const {
193  return this->state_;
194  }
195 
196  // struct StepState (scalars, vectors) map?
197 
198  // getState
199 
200  // setState
201 
202 }; // class Step
203 
204 } // namespace ROL
205 
206 #endif
Provides the interface to evaluate objective functions.
virtual void compute(Vector< Real > &s, const Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)=0
Compute step.
virtual std::string printName(void) const =0
Print step name.
virtual ~Step()
Definition: ROL_Step.hpp:78
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
Provides the interface to compute optimization steps.
Definition: ROL_Step.hpp:67
virtual void compute(Vector< Real > &s, const Vector< Real > &x, const Vector< Real > &l, Objective< Real > &obj, EqualityConstraint< Real > &con, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Compute step (equality constraints).
Definition: ROL_Step.hpp:166
virtual void update(Vector< Real > &x, const Vector< Real > &s, Objective< Real > &obj, BoundConstraint< Real > &con, AlgorithmState< Real > &algo_state)=0
Update step, if successful.
Teuchos::RCP< StepState< Real > > state_
Definition: ROL_Step.hpp:69
Teuchos::RCP< StepState< Real > > getState(void)
Definition: ROL_Step.hpp:72
Contains definitions of custom data types in ROL.
virtual void update(Vector< Real > &x, Vector< Real > &l, const Vector< Real > &s, Objective< Real > &obj, EqualityConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Update step, if successful (equality constraints).
Definition: ROL_Step.hpp:160
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void compute(Vector< Real > &s, const Vector< Real > &x, const Vector< Real > &l, Objective< Real > &obj, EqualityConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Compute step (equality constraints).
Definition: ROL_Step.hpp:154
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:95
virtual void update(Vector< Real > &x, Vector< Real > &l, const Vector< Real > &s, Objective< Real > &obj, EqualityConstraint< Real > &con, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Update step, if successful (equality constraints).
Definition: ROL_Step.hpp:173
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:74
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:77
Step(void)
Definition: ROL_Step.hpp:80
virtual std::string print(AlgorithmState< Real > &algo_state, bool printHeader=false) const =0
Print iterate status.
virtual void gradient(Vector< Real > &g, const Vector< Real > &x, Real &tol)
Compute gradient.
bool isActivated(void)
Check if bounds are on.
Defines the equality constraint operator interface.
virtual Teuchos::RCP< const StepState< Real > > getStepState(void) const
Get state for step object.
Definition: ROL_Step.hpp:192
State for step class. Will be used for restarts.
Definition: ROL_Types.hpp:107
Provides the interface to apply upper and lower bound constraints.
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:87
virtual std::string printHeader(void) const =0
Print iterate header.
virtual void initialize(Vector< Real > &x, const Vector< Real > &g, Vector< Real > &l, const Vector< Real > &c, Objective< Real > &obj, EqualityConstraint< Real > &con, AlgorithmState< Real > &algo_state)
Initialize step with equality constraint.
Definition: ROL_Step.hpp:128
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update objective function.
virtual void initialize(Vector< Real > &x, const Vector< Real > &g, Vector< Real > &l, const Vector< Real > &c, Objective< Real > &obj, EqualityConstraint< Real > &con, BoundConstraint< Real > &bnd, AlgorithmState< Real > &algo_state)
Initialize step with equality constraint.
Definition: ROL_Step.hpp:135
virtual void project(Vector< Real > &x)
Project optimization variables onto the bounds.
static const double ROL_EPSILON
Platform-dependent machine epsilon.
Definition: ROL_Types.hpp:118