ROL
ROL_TypeB_Algorithm.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_TYPEB_ALGORITHM_H
45 #define ROL_TYPEB_ALGORITHM_H
46 
48 #include "ROL_Objective.hpp"
49 #include "ROL_Constraint.hpp"
50 #include "ROL_BoundConstraint.hpp"
52 #include "ROL_Problem.hpp"
53 
58 namespace ROL {
59 namespace TypeB {
60 
61 template<typename Real>
62 struct AlgorithmState : public ROL::AlgorithmState<Real> {
63  Real searchSize;
64  Ptr<Vector<Real>> stepVec;
65  Ptr<Vector<Real>> gradientVec;
66  int nproj;
67 
69  : searchSize(1),
70  stepVec(nullPtr),
71  gradientVec(nullPtr),
72  nproj(0) {}
73 
74  void reset() {
76  searchSize = static_cast<Real>(1);
77  if (stepVec != nullPtr) stepVec->zero();
78  if (gradientVec != nullPtr) gradientVec->zero();
79  nproj = 0;
80  }
81 };
82 
83 template<typename Real>
84 class Algorithm {
85 protected:
86  const Ptr<CombinedStatusTest<Real>> status_;
87  const Ptr<AlgorithmState<Real>> state_;
88  Ptr<PolyhedralProjection<Real>> proj_;
89 
90  void initialize(const Vector<Real> &x, const Vector<Real> &g);
91 
92  Real optimalityCriterion(const Vector<Real> &x, const Vector<Real> &g, Vector<Real> &primal,
93  std::ostream &outStream = std::cout) const;
94 
95 public:
96 
97  virtual ~Algorithm() {}
98 
101  Algorithm();
102 
103  void setStatusTest(const Ptr<StatusTest<Real>> &status,
104  const bool combineStatus = false);
105 
109  virtual void run( Problem<Real> &problem,
110  std::ostream &outStream = std::cout );
111 
115  virtual void run( Vector<Real> &x,
116  Objective<Real> &obj,
118  std::ostream &outStream = std::cout );
119 
124  virtual void run( Vector<Real> &x,
125  const Vector<Real> &g,
126  Objective<Real> &obj,
128  std::ostream &outStream = std::cout) = 0;
129 
135  virtual void run( Vector<Real> &x,
136  Objective<Real> &obj,
138  Constraint<Real> &linear_econ,
139  Vector<Real> &linear_emul,
140  std::ostream &outStream = std::cout );
141 
147  virtual void run( Vector<Real> &x,
148  const Vector<Real> &g,
149  Objective<Real> &obj,
151  Constraint<Real> &linear_econ,
152  Vector<Real> &linear_emul,
153  const Vector<Real> &linear_eres,
154  std::ostream &outStream = std::cout );
155 
161  virtual void run( Vector<Real> &x,
162  Objective<Real> &obj,
164  Constraint<Real> &linear_icon,
165  Vector<Real> &linear_imul,
166  BoundConstraint<Real> &linear_ibnd,
167  std::ostream &outStream = std::cout );
168 
174  virtual void run( Vector<Real> &x,
175  const Vector<Real> &g,
176  Objective<Real> &obj,
178  Constraint<Real> &linear_icon,
179  Vector<Real> &linear_imul,
180  BoundConstraint<Real> &linear_ibnd,
181  const Vector<Real> &linear_ires,
182  std::ostream &outStream = std::cout );
183 
189  virtual void run( Vector<Real> &x,
190  Objective<Real> &obj,
192  Constraint<Real> &linear_econ,
193  Vector<Real> &linear_emul,
194  Constraint<Real> &linear_icon,
195  Vector<Real> &linear_imul,
196  BoundConstraint<Real> &linear_ibnd,
197  std::ostream &outStream = std::cout );
198 
204  virtual void run( Vector<Real> &x,
205  const Vector<Real> &g,
206  Objective<Real> &obj,
208  Constraint<Real> &linear_econ,
209  Vector<Real> &linear_emul,
210  const Vector<Real> &linear_eres,
211  Constraint<Real> &linear_icon,
212  Vector<Real> &linear_imul,
213  BoundConstraint<Real> &linear_ibnd,
214  const Vector<Real> &linear_ires,
215  std::ostream &outStream = std::cout );
216 
219  virtual void writeHeader( std::ostream& os ) const;
220 
223  virtual void writeName( std::ostream& os ) const;
224 
227  virtual void writeOutput( std::ostream& os, bool write_header = false ) const;
228 
229  virtual void writeExitStatus( std::ostream& os ) const;
230 
231  //Ptr<const AlgorithmState<Real>>& getState() const;
232  Ptr<const AlgorithmState<Real>> getState() const;
233 
234  void reset();
235 
236 }; // class ROL::Type::Algorithm
237 
238 } // namespace TypeB
239 } // namespace ROL
240 
242 
243 #endif
Provides the interface to apply upper and lower bound constraints.
Defines the general constraint operator interface.
Provides the interface to evaluate objective functions.
Provides an interface to check status of optimization algorithms.
Provides an interface to run bound constrained optimization algorithms.
virtual void run(Problem< Real > &problem, std::ostream &outStream=std::cout)
Run algorithm on bound constrained problems (Type-B). This is the primary Type-B interface.
Ptr< PolyhedralProjection< Real > > proj_
void initialize(const Vector< Real > &x, const Vector< Real > &g)
virtual void writeHeader(std::ostream &os) const
Print iterate header.
Real optimalityCriterion(const Vector< Real > &x, const Vector< Real > &g, Vector< Real > &primal, std::ostream &outStream=std::cout) const
Algorithm()
Constructor, given a step and a status test.
virtual void writeExitStatus(std::ostream &os) const
virtual void writeOutput(std::ostream &os, bool write_header=false) const
Print iterate status.
virtual void writeName(std::ostream &os) const
Print step name.
const Ptr< AlgorithmState< Real > > state_
const Ptr< CombinedStatusTest< Real > > status_
void setStatusTest(const Ptr< StatusTest< Real >> &status, const bool combineStatus=false)
Ptr< const AlgorithmState< Real > > getState() const
virtual void run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, std::ostream &outStream=std::cout)=0
Run algorithm on bound constrained problems (Type-B). This general interface supports the use of dual...
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:84
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:143
Ptr< Vector< Real > > stepVec
Ptr< Vector< Real > > gradientVec