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 template <class Real>
63 class Step {
64 private:
65  Teuchos::RCP<StepState<Real> > state_;
66 
67 protected:
68  Teuchos::RCP<StepState<Real> > getState(void) {
69  return this->state_;
70  }
71 
72 public:
73 
74  virtual ~Step() {}
75 
76  Step(void) {
77  state_ = Teuchos::rcp( new StepState<Real> );
78  }
79 
80 
83  virtual void initialize( Vector<Real> &x, const Vector<Real> &g,
85  AlgorithmState<Real> &algo_state ) {
86  initialize(x,x,g,obj,con,algo_state);
87  }
88 
91  virtual void initialize( Vector<Real> &x, const Vector<Real> &s, const Vector<Real> &g,
93  AlgorithmState<Real> &algo_state ) {
94  Real tol = std::sqrt(ROL_EPSILON);
95  // Initialize state descent direction and gradient storage
96  state_->descentVec = s.clone();
97  state_->gradientVec = g.clone();
98  state_->searchSize = 0.0;
99  // Project x onto constraint set
100  if ( con.isActivated() ) {
101  con.project(x);
102  }
103  // Update objective function, get value, and get gradient
104  obj.update(x,true,algo_state.iter);
105  algo_state.value = obj.value(x,tol);
106  algo_state.nfval++;
107  obj.gradient(*(state_->gradientVec),x,tol);
108  algo_state.ngrad++;
109  if ( con.isActivated() ) {
110  Teuchos::RCP<Vector<Real> > xnew = x.clone();
111  xnew->set(x);
112  xnew->axpy(-1.0,(Step<Real>::state_->gradientVec)->dual());
113  con.project(*xnew);
114  xnew->axpy(-1.0,x);
115  algo_state.gnorm = xnew->norm();
116  }
117  else {
118  algo_state.gnorm = (state_->gradientVec)->norm();
119  }
120  }
121 
124  virtual void initialize( Vector<Real> &x, const Vector<Real> &g, Vector<Real> &l, const Vector<Real> &c,
126  AlgorithmState<Real> &algo_state ) {
127  }
128 
131  virtual void initialize( Vector<Real> &x, const Vector<Real> &g, Vector<Real> &l, const Vector<Real> &c,
133  AlgorithmState<Real> &algo_state ) {
134  }
135 
138  virtual void compute( Vector<Real> &s, const Vector<Real> &x, Objective<Real> &obj,
139  BoundConstraint<Real> &con,
140  AlgorithmState<Real> &algo_state ) = 0;
141 
144  virtual void update( Vector<Real> &x, const Vector<Real> &s, Objective<Real> &obj,
146  AlgorithmState<Real> &algo_state ) = 0;
147 
150  virtual void compute( Vector<Real> &s, const Vector<Real> &x, const Vector<Real> &l,
152  AlgorithmState<Real> &algo_state ) {}
153 
156  virtual void update( Vector<Real> &x, Vector<Real> &l, const Vector<Real> &s,
158  AlgorithmState<Real> &algo_state ) {}
159 
162  virtual void compute( Vector<Real> &s, const Vector<Real> &x, const Vector<Real> &l,
165  AlgorithmState<Real> &algo_state ) {}
166 
169  virtual void update( Vector<Real> &x, Vector<Real> &l, const Vector<Real> &s,
172  AlgorithmState<Real> &algo_state ) {}
173 
176  virtual std::string printHeader( void ) const = 0;
177 
180  virtual std::string printName( void ) const = 0;
181 
184  virtual std::string print( AlgorithmState<Real> &algo_state, bool printHeader = false ) const = 0;
185 
188  virtual Teuchos::RCP<const StepState<Real> > getStepState(void) const {
189  return this->state_;
190  }
191 
192  // struct StepState (scalars, vectors) map?
193 
194  // getState
195 
196  // setState
197 
198 }; // class Step
199 
200 } // namespace ROL
201 
202 #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:74
virtual Real value(const Vector< Real > &x, Real &tol)=0
Compute value.
Provides the interface to compute optimization steps.
Definition: ROL_Step.hpp:63
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:162
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:65
Teuchos::RCP< StepState< Real > > getState(void)
Definition: ROL_Step.hpp:68
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:156
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:150
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:91
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:169
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:72
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:76
Step(void)
Definition: ROL_Step.hpp:76
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:188
State for step class. Will be used for restarts.
Definition: ROL_Types.hpp:106
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:83
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:124
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:131
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:115