ROL
algorithm/ROL_Problem.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_PROBLEM_HPP
11 #define ROL_PROBLEM_HPP
12 
13 #include <utility>
14 #include <unordered_map>
15 
16 #include "ROL_Ptr.hpp"
17 #include "ROL_Types.hpp"
22 
23 namespace ROL {
24 
25 template<typename Real>
26 class Problem {
27 private:
28  bool isFinalized_;
29  bool hasBounds_;
30  bool hasEquality_;
31  bool hasInequality_;
32  bool hasLinearEquality_;
34  unsigned cnt_econ_;
35  unsigned cnt_icon_;
36  unsigned cnt_linear_econ_;
37  unsigned cnt_linear_icon_;
38 
39  ParameterList ppa_list_;
40 
41  Ptr<Objective<Real>> obj_;
42  Ptr<Vector<Real>> xprim_;
43  Ptr<Vector<Real>> xdual_;
44  Ptr<BoundConstraint<Real>> bnd_;
45  Ptr<Constraint<Real>> con_;
46  Ptr<Vector<Real>> mul_;
47  Ptr<Vector<Real>> res_;
48  Ptr<PolyhedralProjection<Real>> proj_;
49 
50  Ptr<Vector<Real>> xfeas_;
51  Ptr<ReduceLinearConstraint<Real>> rlc_;
52 
54 
55 protected:
56 
57  Ptr<Objective<Real>> INPUT_obj_;
58  Ptr<Vector<Real>> INPUT_xprim_;
59  Ptr<Vector<Real>> INPUT_xdual_;
60  Ptr<BoundConstraint<Real>> INPUT_bnd_;
61  std::unordered_map<std::string,ConstraintData<Real>> INPUT_con_;
62  std::unordered_map<std::string,ConstraintData<Real>> INPUT_linear_con_;
63 
64 public:
65  virtual ~Problem() {}
66 
73  Problem( const Ptr<Objective<Real>> &obj,
74  const Ptr<Vector<Real>> &x,
75  const Ptr<Vector<Real>> &g = nullPtr);
76 
81  Problem(const Problem &problem)
82  : isFinalized_(false),
83  hasBounds_(problem.hasBounds_),
84  hasEquality_(problem.hasEquality_),
88  cnt_econ_(problem.cnt_econ_),
89  cnt_icon_(problem.cnt_icon_),
92  ppa_list_(problem.ppa_list_),
93  INPUT_obj_(problem.INPUT_obj_),
94  INPUT_xprim_(problem.INPUT_xprim_),
95  INPUT_xdual_(problem.INPUT_xdual_),
96  INPUT_bnd_(problem.INPUT_bnd_),
97  INPUT_con_(problem.INPUT_con_),
99 
100  /***************************************************************************/
101  /*** Set and remove methods for constraints ********************************/
102  /***************************************************************************/
103 
108  void addBoundConstraint(const Ptr<BoundConstraint<Real>> &bnd);
109 
112  void removeBoundConstraint();
113 
122  void addConstraint(std::string name,
123  const Ptr<Constraint<Real>> &econ,
124  const Ptr<Vector<Real>> &emul,
125  const Ptr<Vector<Real>> &eres = nullPtr,
126  bool reset = false);
127 
137  void addConstraint(std::string name,
138  const Ptr<Constraint<Real>> &icon,
139  const Ptr<Vector<Real>> &imul,
140  const Ptr<BoundConstraint<Real>> &ibnd,
141  const Ptr<Vector<Real>> &ires = nullPtr,
142  bool reset = false);
143 
148  void removeConstraint(std::string name);
149 
158  void addLinearConstraint(std::string name,
159  const Ptr<Constraint<Real>> &linear_econ,
160  const Ptr<Vector<Real>> &linear_emul,
161  const Ptr<Vector<Real>> &linear_eres = nullPtr,
162  bool reset = false);
163 
173  void addLinearConstraint(std::string name,
174  const Ptr<Constraint<Real>> &linear_icon,
175  const Ptr<Vector<Real>> &linear_imul,
176  const Ptr<BoundConstraint<Real>> &linear_ibnd,
177  const Ptr<Vector<Real>> &linear_ires = nullPtr,
178  bool reset = false);
179 
184  void removeLinearConstraint(std::string name);
185 
190  void setProjectionAlgorithm(ParameterList &parlist);
191 
192  /***************************************************************************/
193  /*** Accessor methods ******************************************************/
194  /***************************************************************************/
195 
198  const Ptr<Objective<Real>>& getObjective();
199 
202  const Ptr<Vector<Real>>& getPrimalOptimizationVector();
203 
206  const Ptr<Vector<Real>>& getDualOptimizationVector();
207 
210  const Ptr<BoundConstraint<Real>>& getBoundConstraint();
211 
214  const Ptr<Constraint<Real>>& getConstraint();
215 
218  const Ptr<Vector<Real>>& getMultiplierVector();
219 
222  const Ptr<Vector<Real>>& getResidualVector();
223 
227  const Ptr<PolyhedralProjection<Real>>& getPolyhedralProjection();
228 
232 
233  /***************************************************************************/
234  /*** Consistency checks ****************************************************/
235  /***************************************************************************/
236 
247  Real checkLinearity(bool printToStream = false, std::ostream &outStream = std::cout) const;
248 
254  void checkVectors(bool printToStream = false, std::ostream &outStream = std::cout) const;
255 
261  void checkDerivatives(bool printToStream = false, std::ostream &outStream = std::cout, const Ptr<Vector<Real>> &x0 = nullPtr, Real scale = Real(1)) const;
262 
269  void check(bool printToStream = false, std::ostream &outStream = std::cout, const Ptr<Vector<Real>> &x0 = nullPtr, Real scale = Real(1)) const;
270 
271  /***************************************************************************/
272  /*** Finalize and edit methods *********************************************/
273  /***************************************************************************/
274 
283  virtual void finalize(bool lumpConstraints = false, bool printToStream = false,
284  std::ostream &outStream = std::cout);
285 
288  bool isFinalized() const;
289 
292  virtual void edit();
293 
297  void finalizeIteration();
298 
299 }; // class Problem
300 
301 } // namespace ROL
302 
303 #include "ROL_Problem_Def.hpp"
304 
305 #endif // ROL_NEWOPTIMIZATIONPROBLEM_HPP
void check(bool printToStream=false, std::ostream &outStream=std::cout) const
Run vector, linearity and derivative checks for user-supplied vectors, objective function and constra...
Provides the interface to evaluate objective functions.
const Ptr< Constraint< Real > > & getConstraint()
Get the equality constraint.
Ptr< BoundConstraint< Real > > bnd_
void checkDerivatives(bool printToStream=false, std::ostream &outStream=std::cout) const
Run derivative checks for user-supplied objective function and constraints.
const Ptr< Vector< Real > > & getPrimalOptimizationVector()
Get the primal optimization space vector.
void addBoundConstraint(const Ptr< BoundConstraint< Real >> &bnd)
Add a bound constraint.
void addLinearConstraint(std::string name, const Ptr< Constraint< Real >> &linear_econ, const Ptr< Vector< Real >> &linear_emul, const Ptr< Vector< Real >> &linear_eres=nullPtr, bool reset=false)
Add a linear equality constraint.
void removeBoundConstraint()
Remove an existing bound constraint.
Contains definitions of custom data types in ROL.
void removeLinearConstraint(std::string name)
Remove an existing linear constraint.
const Ptr< BoundConstraint< Real > > & getBoundConstraint()
Get the bound constraint.
Ptr< ReduceLinearConstraint< Real > > rlc_
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
virtual void finalize(bool lumpConstraints=false, bool printToStream=false, std::ostream &outStream=std::cout)
Tranform user-supplied constraints to consist of only bounds and equalities. Optimization problem can...
Ptr< Objective< Real > > INPUT_obj_
Ptr< Objective< Real > > obj_
bool isFinalized() const
Indicate whether or no finalize has been called.
Ptr< Vector< Real > > res_
Ptr< Vector< Real > > INPUT_xprim_
const Ptr< Objective< Real > > & getObjective()
Get the objective function.
Problem(const Ptr< Objective< Real >> &obj, const Ptr< Vector< Real >> &x, const Ptr< Vector< Real >> &g=nullPtr)
Default constructor for OptimizationProblem.
std::unordered_map< std::string, ConstraintData< Real > > INPUT_linear_con_
std::unordered_map< std::string, ConstraintData< Real > > INPUT_con_
Ptr< Vector< Real > > INPUT_xdual_
const Ptr< Vector< Real > > & getResidualVector()
Get the primal constraint space vector.
const Ptr< Vector< Real > > & getMultiplierVector()
Get the dual constraint space vector.
void finalizeIteration()
Transform the optimization variables to the native parameterization after an optimization algorithm h...
Ptr< Vector< Real > > xdual_
Problem(const Problem &problem)
Copy constructor for OptimizationProblem.
Ptr< Constraint< Real > > con_
Provides the interface to apply upper and lower bound constraints.
Real checkLinearity(bool printToStream=false, std::ostream &outStream=std::cout) const
Check if user-supplied linear constraints are affine.
void addConstraint(std::string name, const Ptr< Constraint< Real >> &econ, const Ptr< Vector< Real >> &emul, const Ptr< Vector< Real >> &eres=nullPtr, bool reset=false)
Add an equality constraint.
const Ptr< PolyhedralProjection< Real > > & getPolyhedralProjection()
Get the polyhedral projection object. This is a null pointer if no linear constraints and/or bounds a...
EProblem getProblemType()
Get the optimization problem type (U, B, E, or G).
void removeConstraint(std::string name)
Remove an existing constraint.
Ptr< Vector< Real > > xfeas_
Ptr< BoundConstraint< Real > > INPUT_bnd_
virtual void edit()
Resume editting optimization problem after finalize has been called.
const Ptr< Vector< Real > > & getDualOptimizationVector()
Get the dual optimization space vector.
void checkVectors(bool printToStream=false, std::ostream &outStream=std::cout) const
Run vector checks for user-supplied vectors.
EProblem
Definition: ROL_Types.hpp:223
Ptr< Vector< Real > > xprim_
Ptr< Vector< Real > > mul_
Defines the general constraint operator interface.
void setProjectionAlgorithm(ParameterList &parlist)
Set polyhedral projection algorithm.
Ptr< PolyhedralProjection< Real > > proj_