ROL
ROL_TypeG_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_TYPEG_ALGORITHM_H
45 #define ROL_TYPEG_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 TypeG {
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  Ptr<Vector<Real>> constraintVec;
67 
69  : searchSize(1),
70  stepVec(nullPtr),
71  gradientVec(nullPtr),
72  constraintVec(nullPtr) {}
73 
74  void reset() {
76  searchSize = static_cast<Real>(1);
77  if (stepVec != nullPtr) {
78  stepVec->zero();
79  }
80  if (gradientVec != nullPtr) {
81  gradientVec->zero();
82  }
83  if (constraintVec != nullPtr) {
84  constraintVec->zero();
85  }
86  }
87 };
88 
89 template<typename Real>
90 class Algorithm {
91 protected:
92  const Ptr<CombinedStatusTest<Real>> status_;
93  const Ptr<AlgorithmState<Real>> state_;
94  Ptr<PolyhedralProjection<Real>> proj_;
95 
96  void initialize( const Vector<Real> &x,
97  const Vector<Real> &g,
98  const Vector<Real> &mul,
99  const Vector<Real> &c);
100 
101 public:
102 
103  virtual ~Algorithm() {}
104 
107  Algorithm();
108 
109  void setStatusTest( const Ptr<StatusTest<Real>> &status,
110  bool combineStatus = false);
111 
115  virtual void run( Problem<Real> &problem,
116  std::ostream &outStream = std::cout );
117 
121  virtual void run( Vector<Real> &x,
122  Objective<Real> &obj,
124  Constraint<Real> &econ,
125  Vector<Real> &emul,
126  std::ostream &outStream = std::cout );
127 
131  virtual void run( Vector<Real> &x,
132  Objective<Real> &obj,
133  Constraint<Real> &icon,
134  Vector<Real> &imul,
135  BoundConstraint<Real> &ibnd,
136  std::ostream &outStream = std::cout );
137 
141  virtual void run( Vector<Real> &x,
142  Objective<Real> &obj,
144  Constraint<Real> &icon,
145  Vector<Real> &imul,
146  BoundConstraint<Real> &ibnd,
147  std::ostream &outStream = std::cout );
148 
152  virtual void run( Vector<Real> &x,
153  Objective<Real> &obj,
154  Constraint<Real> &econ,
155  Vector<Real> &emul,
156  Constraint<Real> &icon,
157  Vector<Real> &imul,
158  BoundConstraint<Real> &ibnd,
159  std::ostream &outStream = std::cout );
160 
164  virtual void run( Vector<Real> &x,
165  Objective<Real> &obj,
167  Constraint<Real> &econ,
168  Vector<Real> &emul,
169  Constraint<Real> &icon,
170  Vector<Real> &imul,
171  BoundConstraint<Real> &ibnd,
172  std::ostream &outStream = std::cout );
173 
174 
178  virtual void run( Vector<Real> &x,
179  const Vector<Real> &g,
180  Objective<Real> &obj,
182  Constraint<Real> &econ,
183  Vector<Real> &emul,
184  const Vector<Real> &eres,
185  std::ostream &outStream = std::cout ) = 0;
186 
190  virtual void run( Vector<Real> &x,
191  const Vector<Real> &g,
192  Objective<Real> &obj,
193  Constraint<Real> &icon,
194  Vector<Real> &imul,
195  BoundConstraint<Real> &ibnd,
196  const Vector<Real> &ires,
197  std::ostream &outStream = std::cout );
198 
202  virtual void run( Vector<Real> &x,
203  const Vector<Real> &g,
204  Objective<Real> &obj,
206  Constraint<Real> &icon,
207  Vector<Real> &imul,
208  BoundConstraint<Real> &ibnd,
209  const Vector<Real> &ires,
210  std::ostream &outStream = std::cout );
211 
215  virtual void run( Vector<Real> &x,
216  const Vector<Real> &g,
217  Objective<Real> &obj,
218  Constraint<Real> &econ,
219  Vector<Real> &emul,
220  const Vector<Real> &eres,
221  Constraint<Real> &icon,
222  Vector<Real> &imul,
223  BoundConstraint<Real> &ibnd,
224  const Vector<Real> &ires,
225  std::ostream &outStream = std::cout );
226 
230  virtual void run( Vector<Real> &x,
231  const Vector<Real> &g,
232  Objective<Real> &obj,
234  Constraint<Real> &econ,
235  Vector<Real> &emul,
236  const Vector<Real> &eres,
237  Constraint<Real> &icon,
238  Vector<Real> &imul,
239  BoundConstraint<Real> &ibnd,
240  const Vector<Real> &ires,
241  std::ostream &outStream = std::cout );
242 
243 
244 
245 
249  virtual void run( Vector<Real> &x,
250  Objective<Real> &obj,
252  Constraint<Real> &econ,
253  Vector<Real> &emul,
254  Constraint<Real> &linear_econ,
255  Vector<Real> &linear_emul,
256  std::ostream &outStream = std::cout );
257 
261  virtual void run( Vector<Real> &x,
262  Objective<Real> &obj,
263  Constraint<Real> &icon,
264  Vector<Real> &imul,
265  BoundConstraint<Real> &ibnd,
266  Constraint<Real> &linear_econ,
267  Vector<Real> &linear_emul,
268  std::ostream &outStream = std::cout );
269 
273  virtual void run( Vector<Real> &x,
274  Objective<Real> &obj,
276  Constraint<Real> &icon,
277  Vector<Real> &imul,
278  BoundConstraint<Real> &ibnd,
279  Constraint<Real> &linear_econ,
280  Vector<Real> &linear_emul,
281  std::ostream &outStream = std::cout );
282 
286  virtual void run( Vector<Real> &x,
287  Objective<Real> &obj,
288  Constraint<Real> &econ,
289  Vector<Real> &emul,
290  Constraint<Real> &icon,
291  Vector<Real> &imul,
292  BoundConstraint<Real> &ibnd,
293  Constraint<Real> &linear_econ,
294  Vector<Real> &linear_emul,
295  std::ostream &outStream = std::cout );
296 
300  virtual void run( Vector<Real> &x,
301  Objective<Real> &obj,
303  Constraint<Real> &econ,
304  Vector<Real> &emul,
305  Constraint<Real> &icon,
306  Vector<Real> &imul,
307  BoundConstraint<Real> &ibnd,
308  Constraint<Real> &linear_econ,
309  Vector<Real> &linear_emul,
310  std::ostream &outStream = std::cout );
311 
312 
313 
314 
318  virtual void run( Vector<Real> &x,
319  const Vector<Real> &g,
320  Objective<Real> &obj,
322  Constraint<Real> &econ,
323  Vector<Real> &emul,
324  const Vector<Real> &eres,
325  Constraint<Real> &linear_econ,
326  Vector<Real> &linear_emul,
327  const Vector<Real> &linear_eres,
328  std::ostream &outStream = std::cout );
329 
333  virtual void run( Vector<Real> &x,
334  const Vector<Real> &g,
335  Objective<Real> &obj,
336  Constraint<Real> &icon,
337  Vector<Real> &imul,
338  BoundConstraint<Real> &ibnd,
339  const Vector<Real> &ires,
340  Constraint<Real> &linear_econ,
341  Vector<Real> &linear_emul,
342  const Vector<Real> &linear_eres,
343  std::ostream &outStream = std::cout );
344 
348  virtual void run( Vector<Real> &x,
349  const Vector<Real> &g,
350  Objective<Real> &obj,
352  Constraint<Real> &icon,
353  Vector<Real> &imul,
354  BoundConstraint<Real> &ibnd,
355  const Vector<Real> &ires,
356  Constraint<Real> &linear_econ,
357  Vector<Real> &linear_emul,
358  const Vector<Real> &linear_eres,
359  std::ostream &outStream = std::cout );
360 
364  virtual void run( Vector<Real> &x,
365  const Vector<Real> &g,
366  Objective<Real> &obj,
367  Constraint<Real> &econ,
368  Vector<Real> &emul,
369  const Vector<Real> &eres,
370  Constraint<Real> &icon,
371  Vector<Real> &imul,
372  BoundConstraint<Real> &ibnd,
373  const Vector<Real> &ires,
374  Constraint<Real> &linear_econ,
375  Vector<Real> &linear_emul,
376  const Vector<Real> &linear_eres,
377  std::ostream &outStream = std::cout );
378 
382  virtual void run( Vector<Real> &x,
383  const Vector<Real> &g,
384  Objective<Real> &obj,
386  Constraint<Real> &econ,
387  Vector<Real> &emul,
388  const Vector<Real> &eres,
389  Constraint<Real> &icon,
390  Vector<Real> &imul,
391  BoundConstraint<Real> &ibnd,
392  const Vector<Real> &ires,
393  Constraint<Real> &linear_econ,
394  Vector<Real> &linear_emul,
395  const Vector<Real> &linear_eres,
396  std::ostream &outStream = std::cout );
397 
400  virtual void writeHeader( std::ostream& os ) const;
401 
404  virtual void writeName( std::ostream& os ) const;
405 
408  virtual void writeOutput( std::ostream& os, const bool write_header = false ) const;
409 
410  virtual void writeExitStatus( std::ostream& os ) const;
411 
412  //Ptr<const AlgorithmState<Real>>& getState() const;
413  Ptr<const AlgorithmState<Real>> getState() const;
414 
415  void reset();
416 
417 }; // class ROL::Algorithm
418 
419 } // namespace TypeG
420 } // namespace ROL
421 
423 
424 #endif
Ptr< Vector< Real > > gradientVec
Provides the interface to evaluate objective functions.
Ptr< Vector< Real > > stepVec
virtual void writeExitStatus(std::ostream &os) const
virtual void writeOutput(std::ostream &os, const bool write_header=false) const
Print iterate status.
virtual void writeHeader(std::ostream &os) const
Print iterate header.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
State for algorithm class. Will be used for restarts.
Definition: ROL_Types.hpp:143
Provides an interface to run general constrained optimization algorithms.
virtual void run(Problem< Real > &problem, std::ostream &outStream=std::cout)
Run algorithm on general constrained problems (Type-G). This is the primary Type-G interface...
const Ptr< AlgorithmState< Real > > state_
Ptr< Vector< Real > > constraintVec
Provides an interface to check status of optimization algorithms.
Ptr< const AlgorithmState< Real > > getState() const
void setStatusTest(const Ptr< StatusTest< Real >> &status, bool combineStatus=false)
Provides the interface to apply upper and lower bound constraints.
virtual void writeName(std::ostream &os) const
Print step name.
Ptr< PolyhedralProjection< Real > > proj_
const Ptr< CombinedStatusTest< Real > > status_
Algorithm()
Constructor, given a step and a status test.
void initialize(const Vector< Real > &x, const Vector< Real > &g, const Vector< Real > &mul, const Vector< Real > &c)
Defines the general constraint operator interface.