/usr/include/trilinos/ROL_Step.hpp is in libtrilinos-rol-dev 12.10.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | // @HEADER
// ************************************************************************
//
// Rapid Optimization Library (ROL) Package
// Copyright (2014) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact lead developers:
// Drew Kouri (dpkouri@sandia.gov) and
// Denis Ridzal (dridzal@sandia.gov)
//
// ************************************************************************
// @HEADER
#ifndef ROL_STEP_H
#define ROL_STEP_H
#include "ROL_Vector.hpp"
#include "ROL_Objective.hpp"
#include "ROL_BoundConstraint.hpp"
#include "ROL_EqualityConstraint.hpp"
#include "ROL_OptimizationProblem.hpp"
#include "ROL_Types.hpp"
#include "Teuchos_ParameterList.hpp"
/** @ingroup step_group
\class ROL::Step
\brief Provides the interface to compute optimization steps.
*/
namespace ROL {
// We need a forward declaration here, because some steps are algorithms.
template<class Real>
class Algorithm;
template <class Real>
class Step {
private:
Teuchos::RCP<StepState<Real> > state_;
protected:
Teuchos::RCP<StepState<Real> > getState(void) {
return state_;
}
public:
virtual ~Step() {}
Step(void) {
state_ = Teuchos::rcp( new StepState<Real> );
}
/** \brief Initialize step with bound constraint.
*/
virtual void initialize( Vector<Real> &x, const Vector<Real> &g,
Objective<Real> &obj, BoundConstraint<Real> &con,
AlgorithmState<Real> &algo_state ) {
initialize(x,x,g,obj,con,algo_state);
}
/** \brief Initialize step with bound constraint.
*/
virtual void initialize( Vector<Real> &x, const Vector<Real> &s, const Vector<Real> &g,
Objective<Real> &obj, BoundConstraint<Real> &con,
AlgorithmState<Real> &algo_state ) {
Real tol = std::sqrt(ROL_EPSILON<Real>()), one(1), zero(0);
// Initialize state descent direction and gradient storage
state_->descentVec = s.clone();
state_->gradientVec = g.clone();
state_->searchSize = zero;
// Project x onto constraint set
if ( con.isActivated() ) {
con.project(x);
}
// Update objective function, get value, and get gradient
obj.update(x,true,algo_state.iter);
algo_state.value = obj.value(x,tol);
algo_state.nfval++;
obj.gradient(*(state_->gradientVec),x,tol);
algo_state.ngrad++;
if ( con.isActivated() ) {
Teuchos::RCP<Vector<Real> > xnew = x.clone();
xnew->set(x);
xnew->axpy(-one,(Step<Real>::state_->gradientVec)->dual());
con.project(*xnew);
xnew->axpy(-one,x);
algo_state.gnorm = xnew->norm();
}
else {
algo_state.gnorm = (state_->gradientVec)->norm();
}
}
/** \brief Initialize step with equality constraint.
*/
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 ) {
}
/** \brief Initialize step with equality constraint.
*/
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 ) {
}
/** \brief Compute step.
*/
virtual void compute( Vector<Real> &s, const Vector<Real> &x,
Objective<Real> &obj, BoundConstraint<Real> &bnd,
AlgorithmState<Real> &algo_state ) {
throw Exception::NotImplemented(">>> ROL::Step::compute(s,x,obj,bnd,algo_state) is not implemented!");
}
/** \brief Update step, if successful.
*/
virtual void update( Vector<Real> &x, const Vector<Real> &s,
Objective<Real> &obj, BoundConstraint<Real> &bnd,
AlgorithmState<Real> &algo_state ) {
throw Exception::NotImplemented(">>> ROL::Step::update(x,s,obj,bnd,algo_state) is not implemented!");
}
/** \brief Compute step (equality constraints).
*/
virtual void compute( Vector<Real> &s, const Vector<Real> &x, const Vector<Real> &l,
Objective<Real> &obj, EqualityConstraint<Real> &con,
AlgorithmState<Real> &algo_state ) {
throw Exception::NotImplemented(">>> ROL::Step::compute(s,x,l,obj,bnd,con,algo_state) is not implemented!");
}
/** \brief Update step, if successful (equality constraints).
*/
virtual void update( Vector<Real> &x, Vector<Real> &l, const Vector<Real> &s,
Objective<Real> &obj, EqualityConstraint<Real> &con,
AlgorithmState<Real> &algo_state ) {
throw Exception::NotImplemented(">>> ROL::Step::update(x,s,l,obj,bnd,con,algo_state) is not implemented!");
}
/** \brief Compute step (equality constraints).
*/
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 ) {
throw Exception::NotImplemented(">>> ROL::Step::compute(s,x,l,obj,bnd,con,algo_state) is not implemented!");
}
/** \brief Update step, if successful (equality constraints).
*/
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 ) {
throw Exception::NotImplemented(">>> ROL::Step::update(x,s,l,obj,bnd,con,algo_state) is not implemented!");
}
// Methods using an Optimization problem
void initialize( OptimizationProblem<Real> &opt, AlgorithmState<Real> &algo_state ) {
using Teuchos::RCP;
RCP<Objective<Real> > obj = opt.getObjective();
RCP<Vector<Real> > x = opt.getSolutionVector();
RCP<BoundConstraint<Real> > bnd = opt.getBoundConstraint();
RCP<EqualityConstraint<Real> > con = opt.getEqualityConstraint();
RCP<Vector<Real> > l = opt.getMultiplierVector();
if( con == Teuchos::null ) { // has no equality constraint
if( bnd == Teuchos::null ) { // has no bound constraint or inactive
bnd = Teuchos::rcp(new BoundConstraint<Real> );
bnd->deactivate();
}
initialize(*x, x->dual(), *obj, *bnd, algo_state);
}
else { // has equality constraint
if( bnd == Teuchos::null ) {
initialize(*x,x->dual(),*l,l->dual(),*obj,*con,algo_state );
}
initialize(*x,x->dual(),*l,l->dual(),*obj,*con,*bnd,algo_state);
}
}
void compute( Vector<Real> &s, OptimizationProblem<Real> &opt, AlgorithmState<Real> &algo_state ) {
using Teuchos::RCP;
RCP<Objective<Real> > obj = opt.getObjective();
RCP<Vector<Real> > x = opt.getSolutionVector();
RCP<BoundConstraint<Real> > bnd = opt.getBoundConstraint();
RCP<EqualityConstraint<Real> > con = opt.getEqualityConstraint();
RCP<Vector<Real> > l = opt.getMultiplierVector();
if( con == Teuchos::null ) { // has no equality constraint
if( bnd == Teuchos::null ) { // has no bound constraint
bnd = Teuchos::rcp(new BoundConstraint<Real> );
bnd->deactivate();
}
compute(s,*x, *obj, *bnd, algo_state);
}
else { // has equality constraint
if( bnd == Teuchos::null ) {
compute(s,*x,*l,*obj,*con,algo_state);
}
compute(s,*x,*l,*obj,*con,*bnd,algo_state);
}
}
void update( OptimizationProblem<Real> &opt, const Vector<Real> &s, AlgorithmState<Real> &algo_state ) {
using Teuchos::RCP;
RCP<Objective<Real> > obj = opt.getObjective();
RCP<Vector<Real> > x = opt.getSolutionVector();
RCP<BoundConstraint<Real> > bnd = opt.getBoundConstraint();
RCP<EqualityConstraint<Real> > con = opt.getEqualityConstraint();
RCP<Vector<Real> > l = opt.getMultiplierVector();
if( con == Teuchos::null ) { // has no equality constraint
if( bnd == Teuchos::null ) { // has no bound constraint
bnd = Teuchos::rcp(new BoundConstraint<Real> );
bnd->deactivate();
}
update(*x, s, *obj, *bnd, algo_state);
}
else { // has equality constraint
if( bnd == Teuchos::null ) {
update(*x,*l,s,*obj,*con,algo_state);
}
update(*x,*l,s,*obj,*con,*bnd,algo_state);
}
}
/** \brief Print iterate header.
*/
virtual std::string printHeader( void ) const {
throw Exception::NotImplemented(">>> ROL::Step::printHeader() is not implemented!");
}
/** \brief Print step name.
*/
virtual std::string printName( void ) const {
throw Exception::NotImplemented(">>> ROL::Step::printName() is not implemented!");
}
/** \brief Print iterate status.
*/
virtual std::string print( AlgorithmState<Real> &algo_state, bool printHeader = false ) const {
throw Exception::NotImplemented(">>> ROL::Step::print(algo_state,printHeader) is not implemented!");
}
/** \brief Get state for step object.
*/
const Teuchos::RCP<const StepState<Real> > getStepState(void) const {
return state_;
}
// struct StepState (scalars, vectors) map?
// getState
// setState
}; // class Step
} // namespace ROL
#endif
|