ROL
ROL_Solver_Def.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_SOLVER_DEF_HPP
45#define ROL_SOLVER_DEF_HPP
46
47namespace ROL {
48
49template<typename Real>
51 ParameterList &parlist,
52 const Ptr<Secant<Real>> &secant )
53 : opt_(opt), problemType_(opt_->getProblemType()) {
54 switch (problemType_) {
55 case TYPE_U: algoU_ = TypeU::AlgorithmFactory<Real>(parlist,secant); break;
56 case TYPE_B: algoB_ = TypeB::AlgorithmFactory<Real>(parlist,secant); break;
57 case TYPE_E: algoE_ = TypeE::AlgorithmFactory<Real>(parlist,secant); break;
58 case TYPE_EB: algoG_ = TypeG::AlgorithmFactory<Real>(parlist,secant); break;
59 case TYPE_LAST:
60 ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
61 "Error in Solver::solve() : Unsupported problem type");
62 }
63}
64
65template<typename Real>
66int Solver<Real>::solve( const Ptr<StatusTest<Real>> &status,
67 bool combineStatus) {
68 nullstream bhs;
69 return solve(bhs,status,combineStatus);
70}
71
72template<typename Real>
73int Solver<Real>::solve( std::ostream &outStream,
74 const Ptr<StatusTest<Real>> &status,
75 bool combineStatus ) {
76 switch (problemType_) {
77 case TYPE_U:
78 if (status != nullPtr) algoU_->setStatusTest(status,combineStatus);
79 algoU_->run(*opt_,outStream);
80 break;
81 case TYPE_B:
82 if (status != nullPtr) algoB_->setStatusTest(status,combineStatus);
83 algoB_->run(*opt_,outStream);
84 break;
85 case TYPE_E:
86 if (status != nullPtr) algoE_->setStatusTest(status,combineStatus);
87 algoE_->run(*opt_,outStream);
88 break;
89 case TYPE_EB:
90 if (status != nullPtr) algoG_->setStatusTest(status,combineStatus);
91 algoG_->run(*opt_,outStream);
92 break;
93 case TYPE_LAST:
94 ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
95 "Error in Solver::solve() : Unsupported problem type");
96 }
97 // TODO: Interrogate AlgorithmState and StatusTest to generate a return code
98 // that indicates why the solver has stopped
99
100 // Return an integer code
101 return 0;
102}
103
104template<typename Real>
105Ptr<const AlgorithmState<Real>> Solver<Real>::getAlgorithmState() const {
106//Ptr<const AlgorithmState<Real>>& Solver<Real>::getAlgorithmState() const {
107 switch (problemType_) {
108 case TYPE_U: return algoU_->getState();
109 case TYPE_B: return algoB_->getState();
110 case TYPE_E: return algoE_->getState();
111 case TYPE_EB: return algoG_->getState();
112 case TYPE_LAST:
113 default:
114 ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
115 "Error in Solver::getAlgorithmState() : Unsupported problem type");
116 }
117}
118
119template<typename Real>
121 switch (problemType_) {
122 case TYPE_U: algoU_->reset(); break;
123 case TYPE_B: algoB_->reset(); break;
124 case TYPE_E: algoE_->reset(); break;
125 case TYPE_EB: algoG_->reset(); break;
126 case TYPE_LAST:
127 default:
128 ROL_TEST_FOR_EXCEPTION(true,std::invalid_argument,
129 "Error in Solver::reset() : Unsupported problem type");
130 }
131}
132
133} // namespace ROL
134
135#endif // ROL_SOLVER_DEF_HPP
136
137
virtual void solve(Vector< Real > &c, Vector< Real > &u, const Vector< Real > &z) override
Provides interface for and implements limited-memory secant operators.
Solver(const Ptr< Problem< Real > > &opt, ParameterList &list, const Ptr< Secant< Real > > &secant=nullPtr)
Constructor.
Ptr< TypeG::Algorithm< Real > > algoG_
void reset()
Reset both Algorithm and Step.
Ptr< TypeB::Algorithm< Real > > algoB_
Ptr< TypeE::Algorithm< Real > > algoE_
const Ptr< Problem< Real > > opt_
Ptr< const AlgorithmState< Real > > getAlgorithmState() const
Return the AlgorithmState.
int solve(const Ptr< StatusTest< Real > > &status=nullPtr, bool combineStatus=true)
Solve optimization problem with no iteration output.
const EProblem problemType_
Ptr< TypeU::Algorithm< Real > > algoU_
Provides an interface to check status of optimization algorithms.
Ptr< Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)
Ptr< TypeE::Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)
Ptr< TypeG::Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)
Ptr< Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)
basic_nullstream< char, char_traits< char > > nullstream
@ TYPE_U
@ TYPE_E
@ TYPE_EB
@ TYPE_B
@ TYPE_LAST