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