ROL
ROL_StochasticProblem.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_STOCHASTICPROBLEM_HPP
45 #define ROL_STOCHASTICPROBLEM_HPP
46 
47 #include "ROL_Problem.hpp"
48 
52 
58 
59 #include "ROL_RiskVector.hpp"
63 
64 namespace ROL {
65 
66 template<typename Real>
67 class StochasticProblem : public Problem<Real> {
68 private:
69  Ptr<Objective<Real>> ORIGINAL_obj_;
70  Ptr<Vector<Real>> ORIGINAL_xprim_;
71  Ptr<Vector<Real>> ORIGINAL_xdual_;
72  Ptr<BoundConstraint<Real>> ORIGINAL_bnd_;
73  std::unordered_map<std::string,ConstraintData<Real>> ORIGINAL_con_;
74  std::unordered_map<std::string,ConstraintData<Real>> ORIGINAL_linear_con_;
75 
77  std::vector<bool> needRiskLessCon_;
78  Ptr<ParameterList> objList_;
79  std::unordered_map<std::string,std::pair<Ptr<ParameterList>,bool>> conList_;
80  std::unordered_map<std::string,size_t> statMap_;
81 
89 
90 public:
97  StochasticProblem(const Ptr<Objective<Real>> &obj,
98  const Ptr<Vector<Real>> &x,
99  const Ptr<Vector<Real>> &g = nullPtr);
100 
101  StochasticProblem(const Problem<Real> &problem) : Problem<Real>(problem) {}
102 
103  /***************************************************************************/
104  /*** Set and remove methods for constraints ********************************/
105  /***************************************************************************/
106 
107  void makeObjectiveStochastic(ParameterList &list,
108  const Ptr<SampleGenerator<Real>> &fsampler,
109  const Ptr<SampleGenerator<Real>> &gsampler = nullPtr,
110  const Ptr<SampleGenerator<Real>> &hsampler = nullPtr);
112  ParameterList &list,
113  const Ptr<SampleGenerator<Real>> &fsampler,
114  const Ptr<SampleGenerator<Real>> &gsampler = nullPtr,
115  const Ptr<SampleGenerator<Real>> &hsampler = nullPtr);
116  void makeConstraintStochastic(std::string name,
117  ParameterList &list,
118  const Ptr<SampleGenerator<Real>> &sampler,
119  const Ptr<BatchManager<Real>> &bman = nullPtr);
120  void makeLinearConstraintStochastic(std::string name,
121  ParameterList &list,
122  const Ptr<SampleGenerator<Real>> &sampler,
123  const Ptr<BatchManager<Real>> &bman = nullPtr);
124  void resetStochasticObjective(void);
125  void resetStochasticConstraint(std::string name);
126  void resetStochasticLinearConstraint(std::string name);
127  void resetStochastic(void);
128 
129  std::vector<Real> getObjectiveStatistic(void) const;
130  std::vector<Real> getConstraintStatistic(std::string name) const;
131  Real getSolutionStatistic(int comp = 0, std::string name = "") const;
132 
133  /***************************************************************************/
134  /*** Finalize and edit methods *********************************************/
135  /***************************************************************************/
136 
137  void finalize(bool lumpConstraints = false, bool printToStream = false,
138  std::ostream &outStream = std::cout) override;
139 
140  void edit(void) override;
141 
142 }; // class StochasticProblem
143 
144 } // namespace ROL
145 
147 
148 #endif // ROL_STOCHASTICPROBLEM_HPP
Provides the interface to evaluate objective functions.
void makeConstraintStochastic(std::string name, ParameterList &list, const Ptr< SampleGenerator< Real >> &sampler, const Ptr< BatchManager< Real >> &bman=nullPtr)
void resetStochasticLinearConstraint(std::string name)
std::unordered_map< std::string, size_t > statMap_
Ptr< Vector< Real > > ORIGINAL_xdual_
std::vector< Real > getConstraintStatistic(std::string name) const
Ptr< Objective< Real > > ORIGINAL_obj_
std::unordered_map< std::string, ConstraintData< Real > > ORIGINAL_linear_con_
StochasticProblem(const Ptr< Objective< Real >> &obj, const Ptr< Vector< Real >> &x, const Ptr< Vector< Real >> &g=nullPtr)
Default constructor for StochasticProblem.
Real getSolutionStatistic(int comp=0, std::string name="") const
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
std::vector< bool > needRiskLessCon_
std::unordered_map< std::string, std::pair< Ptr< ParameterList >, bool > > conList_
std::unordered_map< std::string, ConstraintData< Real > > ORIGINAL_con_
Ptr< BoundConstraint< Real > > ORIGINAL_bnd_
std::vector< Real > getObjectiveStatistic(void) const
StochasticProblem(const Problem< Real > &problem)
Ptr< ParameterList > objList_
void resetStochasticConstraint(std::string name)
Provides the interface to implement any functional that maps a random variable to a (extended) real n...
void edit(void) override
Resume editting optimization problem after finalize has been called.
void makeObjectiveStochastic(ParameterList &list, const Ptr< SampleGenerator< Real >> &fsampler, const Ptr< SampleGenerator< Real >> &gsampler=nullPtr, const Ptr< SampleGenerator< Real >> &hsampler=nullPtr)
void makeLinearConstraintStochastic(std::string name, ParameterList &list, const Ptr< SampleGenerator< Real >> &sampler, const Ptr< BatchManager< Real >> &bman=nullPtr)
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...
Ptr< Vector< Real > > ORIGINAL_xprim_