ROL
ROL_StochasticProblem.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_STOCHASTICPROBLEM_HPP
11#define ROL_STOCHASTICPROBLEM_HPP
12
13#include "ROL_Problem.hpp"
14
18
24
25#include "ROL_RiskVector.hpp"
29
30namespace ROL {
31
32template<typename Real>
33class StochasticProblem : public Problem<Real> {
34private:
35 Ptr<Objective<Real>> ORIGINAL_obj_;
36 Ptr<Objective<Real>> ORIGINAL_nobj_;
37 Ptr<Vector<Real>> ORIGINAL_xprim_;
38 Ptr<Vector<Real>> ORIGINAL_xdual_;
39 Ptr<BoundConstraint<Real>> ORIGINAL_bnd_;
40 std::unordered_map<std::string,ConstraintData<Real>> ORIGINAL_con_;
41 std::unordered_map<std::string,ConstraintData<Real>> ORIGINAL_linear_con_;
42
44 std::vector<bool> needRiskLessCon_;
45 Ptr<ParameterList> objList_;
46 std::unordered_map<std::string,std::pair<Ptr<ParameterList>,bool>> conList_;
47 std::unordered_map<std::string,size_t> statMap_;
48
49 using Problem<Real>::INPUT_obj_;
50 using Problem<Real>::INPUT_nobj_;
51 using Problem<Real>::INPUT_xprim_;
52 using Problem<Real>::INPUT_xdual_;
53 using Problem<Real>::INPUT_bnd_;
54 using Problem<Real>::INPUT_con_;
56 using Problem<Real>::isFinalized;
57
58public:
65 StochasticProblem(const Ptr<Objective<Real>> &obj,
66 const Ptr<Vector<Real>> &x,
67 const Ptr<Vector<Real>> &g = nullPtr);
68
69 StochasticProblem(const Problem<Real> &problem) : Problem<Real>(problem) {}
70
71 /***************************************************************************/
72 /*** Set and remove methods for constraints ********************************/
73 /***************************************************************************/
74
75 void makeObjectiveStochastic(ParameterList &list,
76 const Ptr<SampleGenerator<Real>> &fsampler,
77 const Ptr<SampleGenerator<Real>> &gsampler = nullPtr,
78 const Ptr<SampleGenerator<Real>> &hsampler = nullPtr);
80 ParameterList &list,
81 const Ptr<SampleGenerator<Real>> &fsampler,
82 const Ptr<SampleGenerator<Real>> &gsampler = nullPtr,
83 const Ptr<SampleGenerator<Real>> &hsampler = nullPtr);
84 void makeConstraintStochastic(std::string name,
85 ParameterList &list,
86 const Ptr<SampleGenerator<Real>> &sampler,
87 const Ptr<BatchManager<Real>> &bman = nullPtr);
88 void makeLinearConstraintStochastic(std::string name,
89 ParameterList &list,
90 const Ptr<SampleGenerator<Real>> &sampler,
91 const Ptr<BatchManager<Real>> &bman = nullPtr);
92 void resetStochasticObjective(void);
93 void resetStochasticConstraint(std::string name);
94 void resetStochasticLinearConstraint(std::string name);
95 void resetStochastic(void);
96
97 std::vector<Real> getObjectiveStatistic(void) const;
98 std::vector<Real> getConstraintStatistic(std::string name) const;
99 Real getSolutionStatistic(int comp = 0, std::string name = "") const;
100
101 /***************************************************************************/
102 /*** Finalize and edit methods *********************************************/
103 /***************************************************************************/
104
105 void finalize(bool lumpConstraints = false, bool printToStream = false,
106 std::ostream &outStream = std::cout) override;
107
108 void edit(void) override;
109
110}; // class StochasticProblem
111
112} // namespace ROL
113
115
116#endif // ROL_STOCHASTICPROBLEM_HPP
Provides the interface to evaluate objective functions.
Ptr< BoundConstraint< Real > > INPUT_bnd_
Ptr< Objective< Real > > INPUT_obj_
bool isFinalized() const
Indicate whether or no finalize has been called.
std::unordered_map< std::string, ConstraintData< Real > > INPUT_linear_con_
Ptr< Vector< Real > > INPUT_xdual_
std::unordered_map< std::string, ConstraintData< Real > > INPUT_con_
Ptr< Vector< Real > > INPUT_xprim_
Ptr< Objective< Real > > INPUT_nobj_
Provides the interface to implement any functional that maps a random variable to a (extended) real n...
std::vector< Real > getConstraintStatistic(std::string name) const
void makeConstraintStochastic(std::string name, ParameterList &list, const Ptr< SampleGenerator< Real > > &sampler, const Ptr< BatchManager< Real > > &bman=nullPtr)
std::unordered_map< std::string, ConstraintData< Real > > ORIGINAL_con_
void edit(void) override
Resume editting optimization problem after finalize has been called.
void resetStochasticLinearConstraint(std::string name)
Ptr< Vector< Real > > ORIGINAL_xdual_
std::unordered_map< std::string, std::pair< Ptr< ParameterList >, bool > > conList_
void resetStochasticConstraint(std::string name)
Ptr< ParameterList > objList_
std::unordered_map< std::string, size_t > statMap_
void makeLinearConstraintStochastic(std::string name, ParameterList &list, const Ptr< SampleGenerator< Real > > &sampler, const Ptr< BatchManager< Real > > &bman=nullPtr)
Ptr< Objective< Real > > ORIGINAL_nobj_
Ptr< Objective< Real > > ORIGINAL_obj_
Ptr< Vector< Real > > ORIGINAL_xprim_
std::vector< Real > getObjectiveStatistic(void) const
void finalize(bool lumpConstraints=false, bool printToStream=false, std::ostream &outStream=std::cout) override
Tranform user-supplied constraints to consist of only bounds and equalities. Optimization problem can...
StochasticProblem(const Problem< Real > &problem)
Real getSolutionStatistic(int comp=0, std::string name="") const
Ptr< BoundConstraint< Real > > ORIGINAL_bnd_
std::vector< bool > needRiskLessCon_
void makeObjectiveStochastic(ParameterList &list, const Ptr< SampleGenerator< Real > > &fsampler, const Ptr< SampleGenerator< Real > > &gsampler=nullPtr, const Ptr< SampleGenerator< Real > > &hsampler=nullPtr)
std::unordered_map< std::string, ConstraintData< Real > > ORIGINAL_linear_con_
Defines the linear algebra or vector space interface.