ROL
Toggle main menu visibility
Loading...
Searching...
No Matches
src
algorithm
ROL_Solver_Def.hpp
Go to the documentation of this file.
1
// @HEADER
2
// *****************************************************************************
3
// Rapid Optimization Library (ROL) Package
4
//
5
// Copyright 2014 NTESS and the ROL contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
10
#ifndef ROL_SOLVER_DEF_HPP
11
#define ROL_SOLVER_DEF_HPP
12
13
namespace
ROL
{
14
15
template
<
typename
Real>
16
Solver<Real>::Solver
(
const
Ptr<
Problem<Real>
> &opt,
17
ParameterList &parlist,
18
const
Ptr<
Secant<Real>
> &secant )
19
:
opt_
(opt),
problemType_
(
opt_
->getProblemType()) {
20
switch
(
problemType_
) {
21
case
TYPE_U
:
algoU_
=
TypeU::AlgorithmFactory<Real>
(parlist,secant);
break
;
22
case
TYPE_P
:
algoP_
=
TypeP::AlgorithmFactory<Real>
(parlist,secant);
break
;
23
case
TYPE_B
:
algoB_
=
TypeB::AlgorithmFactory<Real>
(parlist,secant);
break
;
24
case
TYPE_E
:
algoE_
=
TypeE::AlgorithmFactory<Real>
(parlist,secant);
break
;
25
case
TYPE_EB
:
algoG_
=
TypeG::AlgorithmFactory<Real>
(parlist,secant);
break
;
26
case
TYPE_LAST
:
27
ROL_TEST_FOR_EXCEPTION(
true
,std::invalid_argument,
28
"Error in Solver::solve() : Unsupported problem type"
);
29
}
30
}
31
32
template
<
typename
Real>
33
int
Solver<Real>::solve
(
const
Ptr<
StatusTest<Real>
> &status,
34
bool
combineStatus) {
35
nullstream
bhs;
36
return
solve
(bhs,status,combineStatus);
37
}
38
39
template
<
typename
Real>
40
int
Solver<Real>::solve
( std::ostream &outStream,
41
const
Ptr<
StatusTest<Real>
> &status,
42
bool
combineStatus ) {
43
switch
(
problemType_
) {
44
case
TYPE_U
:
45
if
(status != nullPtr)
algoU_
->setStatusTest(status,combineStatus);
46
algoU_
->run(*
opt_
,outStream);
47
break
;
48
case
TYPE_P
:
49
if
(status != nullPtr)
algoP_
->setStatusTest(status,combineStatus);
50
algoP_
->run(*
opt_
,outStream);
51
break
;
52
case
TYPE_B
:
53
if
(status != nullPtr)
algoB_
->setStatusTest(status,combineStatus);
54
algoB_
->run(*
opt_
,outStream);
55
break
;
56
case
TYPE_E
:
57
if
(status != nullPtr)
algoE_
->setStatusTest(status,combineStatus);
58
algoE_
->run(*
opt_
,outStream);
59
break
;
60
case
TYPE_EB
:
61
if
(status != nullPtr)
algoG_
->setStatusTest(status,combineStatus);
62
algoG_
->run(*
opt_
,outStream);
63
break
;
64
case
TYPE_LAST
:
65
ROL_TEST_FOR_EXCEPTION(
true
,std::invalid_argument,
66
"Error in Solver::solve() : Unsupported problem type"
);
67
}
68
// TODO: Interrogate AlgorithmState and StatusTest to generate a return code
69
// that indicates why the solver has stopped
70
71
// Return an integer code
72
return
0;
73
}
74
75
template
<
typename
Real>
76
Ptr<const AlgorithmState<Real>>
Solver<Real>::getAlgorithmState
()
const
{
77
//Ptr<const AlgorithmState<Real>>& Solver<Real>::getAlgorithmState() const {
78
switch
(
problemType_
) {
79
case
TYPE_U
:
return
algoU_
->getState();
80
case
TYPE_P
:
return
algoP_
->getState();
81
case
TYPE_B
:
return
algoB_
->getState();
82
case
TYPE_E
:
return
algoE_
->getState();
83
case
TYPE_EB
:
return
algoG_
->getState();
84
case
TYPE_LAST
:
85
default
:
86
ROL_TEST_FOR_EXCEPTION(
true
,std::invalid_argument,
87
"Error in Solver::getAlgorithmState() : Unsupported problem type"
);
88
}
89
}
90
91
template
<
typename
Real>
92
void
Solver<Real>::reset
() {
93
switch
(
problemType_
) {
94
case
TYPE_U
:
algoU_
->reset();
break
;
95
case
TYPE_P
:
algoP_
->reset();
break
;
96
case
TYPE_B
:
algoB_
->reset();
break
;
97
case
TYPE_E
:
algoE_
->reset();
break
;
98
case
TYPE_EB
:
algoG_
->reset();
break
;
99
case
TYPE_LAST
:
100
default
:
101
ROL_TEST_FOR_EXCEPTION(
true
,std::invalid_argument,
102
"Error in Solver::reset() : Unsupported problem type"
);
103
}
104
}
105
106
}
// namespace ROL
107
108
#endif
// ROL_SOLVER_DEF_HPP
109
110
solve
virtual void solve(Vector< Real > &c, Vector< Real > &u, const Vector< Real > &z) override
Definition
ROL_Objective_TimeSimOpt.hpp:150
ROL::Problem
Definition
function/prox/ROL_Problem.hpp:27
ROL::Secant
Provides interface for and implements limited-memory secant operators.
Definition
ROL_Secant.hpp:45
ROL::Solver::Solver
Solver(const Ptr< Problem< Real > > &opt, ParameterList &list, const Ptr< Secant< Real > > &secant=nullPtr)
Constructor.
Definition
ROL_Solver_Def.hpp:16
ROL::Solver::algoG_
Ptr< TypeG::Algorithm< Real > > algoG_
Definition
ROL_Solver.hpp:40
ROL::Solver::reset
void reset()
Reset both Algorithm and Step.
Definition
ROL_Solver_Def.hpp:92
ROL::Solver::algoB_
Ptr< TypeB::Algorithm< Real > > algoB_
Definition
ROL_Solver.hpp:38
ROL::Solver::algoE_
Ptr< TypeE::Algorithm< Real > > algoE_
Definition
ROL_Solver.hpp:39
ROL::Solver::opt_
const Ptr< Problem< Real > > opt_
Definition
ROL_Solver.hpp:34
ROL::Solver::getAlgorithmState
Ptr< const AlgorithmState< Real > > getAlgorithmState() const
Return the AlgorithmState.
Definition
ROL_Solver_Def.hpp:76
ROL::Solver::solve
int solve(const Ptr< StatusTest< Real > > &status=nullPtr, bool combineStatus=true)
Solve optimization problem with no iteration output.
Definition
ROL_Solver_Def.hpp:33
ROL::Solver::problemType_
const EProblem problemType_
Definition
ROL_Solver.hpp:35
ROL::Solver::algoP_
Ptr< TypeP::Algorithm< Real > > algoP_
Definition
ROL_Solver.hpp:41
ROL::Solver::algoU_
Ptr< TypeU::Algorithm< Real > > algoU_
Definition
ROL_Solver.hpp:37
ROL::StatusTest
Provides an interface to check status of optimization algorithms.
Definition
ROL_StatusTest.hpp:24
ROL::TypeB::AlgorithmFactory
Ptr< Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)
Definition
ROL_TypeB_AlgorithmFactory.hpp:112
ROL::TypeE::AlgorithmFactory
Ptr< TypeE::Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)
Definition
ROL_TypeE_AlgorithmFactory.hpp:91
ROL::TypeG::AlgorithmFactory
Ptr< TypeG::Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)
Definition
ROL_TypeG_AlgorithmFactory.hpp:96
ROL::TypeP::AlgorithmFactory
Ptr< Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)
Definition
ROL_TypeP_AlgorithmFactory.hpp:98
ROL::TypeU::AlgorithmFactory
Ptr< Algorithm< Real > > AlgorithmFactory(ParameterList &parlist, const Ptr< Secant< Real > > &secant=nullPtr)
Definition
ROL_TypeU_AlgorithmFactory.hpp:91
ROL::details::nullstream
basic_nullstream< char, std::char_traits< char > > nullstream
Definition
ROL_Stream.hpp:36
ROL
Definition
ROL_ElementwiseVector.hpp:27
ROL::TYPE_U
@ TYPE_U
Definition
ROL_Types.hpp:224
ROL::TYPE_E
@ TYPE_E
Definition
ROL_Types.hpp:227
ROL::TYPE_EB
@ TYPE_EB
Definition
ROL_Types.hpp:228
ROL::TYPE_P
@ TYPE_P
Definition
ROL_Types.hpp:225
ROL::TYPE_B
@ TYPE_B
Definition
ROL_Types.hpp:226
ROL::TYPE_LAST
@ TYPE_LAST
Definition
ROL_Types.hpp:229
Generated by
1.17.0