ROL
function/prox/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#include "ROL_ProxObjective.hpp"
23
24namespace ROL {
25
26template<typename Real>
27class Problem {
28private:
36 unsigned cnt_econ_;
37 unsigned cnt_icon_;
40
41 ParameterList ppa_list_;
42
43 Ptr<Objective<Real>> obj_;
44 Ptr<Vector<Real>> xprim_;
45 Ptr<Vector<Real>> xdual_;
46 Ptr<BoundConstraint<Real>> bnd_;
47 Ptr<Constraint<Real>> con_;
48 Ptr<Vector<Real>> mul_;
49 Ptr<Vector<Real>> res_;
50 Ptr<PolyhedralProjection<Real>> proj_;
51 Ptr<ProxObjective<Real>> prox_;
52
53 Ptr<Vector<Real>> xfeas_;
54 Ptr<ReduceLinearConstraint<Real>> rlc_;
55
57
58protected:
59
60 Ptr<Objective<Real>> INPUT_obj_;
61 Ptr<Vector<Real>> INPUT_xprim_;
62 Ptr<Vector<Real>> INPUT_xdual_;
63 Ptr<BoundConstraint<Real>> INPUT_bnd_;
64 std::unordered_map<std::string,ConstraintData<Real>> INPUT_con_;
65 std::unordered_map<std::string,ConstraintData<Real>> INPUT_linear_con_;
66 Ptr<ProxObjective<Real>> INPUT_prox_;
67
68public:
69 virtual ~Problem() {}
70
77 Problem( const Ptr<Objective<Real>> &obj,
78 const Ptr<Vector<Real>> &x,
79 const Ptr<Vector<Real>> &g = nullPtr);
80
103
104 /***************************************************************************/
105 /*** Set and remove methods for constraints ********************************/
106 /***************************************************************************/
107
112 void addBoundConstraint(const Ptr<BoundConstraint<Real>> &bnd);
113
117
122 void addProxObjective(const Ptr<ProxObjective<Real>> &prox);
123
126 void removeProxObjective();
127
136 void addConstraint(std::string name,
137 const Ptr<Constraint<Real>> &econ,
138 const Ptr<Vector<Real>> &emul,
139 const Ptr<Vector<Real>> &eres = nullPtr,
140 bool reset = false);
141
151 void addConstraint(std::string name,
152 const Ptr<Constraint<Real>> &icon,
153 const Ptr<Vector<Real>> &imul,
154 const Ptr<BoundConstraint<Real>> &ibnd,
155 const Ptr<Vector<Real>> &ires = nullPtr,
156 bool reset = false);
157
162 void removeConstraint(std::string name);
163
172 void addLinearConstraint(std::string name,
173 const Ptr<Constraint<Real>> &linear_econ,
174 const Ptr<Vector<Real>> &linear_emul,
175 const Ptr<Vector<Real>> &linear_eres = nullPtr,
176 bool reset = false);
177
187 void addLinearConstraint(std::string name,
188 const Ptr<Constraint<Real>> &linear_icon,
189 const Ptr<Vector<Real>> &linear_imul,
190 const Ptr<BoundConstraint<Real>> &linear_ibnd,
191 const Ptr<Vector<Real>> &linear_ires = nullPtr,
192 bool reset = false);
193
198 void removeLinearConstraint(std::string name);
199
204 void setProjectionAlgorithm(ParameterList &parlist);
205
206 /***************************************************************************/
207 /*** Accessor methods ******************************************************/
208 /***************************************************************************/
209
212 const Ptr<Objective<Real>>& getObjective();
213
216 const Ptr<Vector<Real>>& getPrimalOptimizationVector();
217
220 const Ptr<Vector<Real>>& getDualOptimizationVector();
221
224 const Ptr<BoundConstraint<Real>>& getBoundConstraint();
225
228 const Ptr<Constraint<Real>>& getConstraint();
229
232 const Ptr<Vector<Real>>& getMultiplierVector();
233
236 const Ptr<Vector<Real>>& getResidualVector();
237
241 const Ptr<PolyhedralProjection<Real>>& getPolyhedralProjection();
242
246
247 /***************************************************************************/
248 /*** Consistency checks ****************************************************/
249 /***************************************************************************/
250
261 Real checkLinearity(bool printToStream = false, std::ostream &outStream = std::cout) const;
262
268 void checkVectors(bool printToStream = false, std::ostream &outStream = std::cout) const;
269
275 void checkDerivatives(bool printToStream = false, std::ostream &outStream = std::cout) const;
276
283 void check(bool printToStream = false, std::ostream &outStream = std::cout) const;
284
285 /***************************************************************************/
286 /*** Finalize and edit methods *********************************************/
287 /***************************************************************************/
288
297 virtual void finalize(bool lumpConstraints = false, bool printToStream = false,
298 std::ostream &outStream = std::cout);
299
302 bool isFinalized() const;
303
306 virtual void edit();
307
311 void finalizeIteration();
312
313}; // class Problem
314
315} // namespace ROL
316
317#include "ROL_Problem_Def.hpp"
318
319#endif // ROL_NEWOPTIMIZATIONPROBLEM_HPP
Contains definitions of custom data types in ROL.
Provides the interface to apply upper and lower bound constraints.
Defines the general constraint operator interface.
Provides the interface to evaluate objective functions.
Ptr< ProxObjective< Real > > INPUT_prox_
Ptr< BoundConstraint< Real > > INPUT_bnd_
Problem(const Problem &problem)
Copy constructor for OptimizationProblem.
const Ptr< PolyhedralProjection< Real > > & getPolyhedralProjection()
Get the polyhedral projection object. This is a null pointer if no linear constraints and/or bounds a...
Ptr< Objective< Real > > INPUT_obj_
const Ptr< Vector< Real > > & getPrimalOptimizationVector()
Get the primal optimization space vector.
void removeConstraint(std::string name)
Remove an existing constraint.
const Ptr< Vector< Real > > & getDualOptimizationVector()
Get the dual optimization space vector.
void removeLinearConstraint(std::string name)
Remove an existing linear constraint.
bool isFinalized() const
Indicate whether or no finalize has been called.
const Ptr< Vector< Real > > & getMultiplierVector()
Get the dual constraint space vector.
const Ptr< Constraint< Real > > & getConstraint()
Get the equality constraint.
void checkVectors(bool printToStream=false, std::ostream &outStream=std::cout) const
Run vector checks for user-supplied vectors.
Ptr< Constraint< Real > > con_
std::unordered_map< std::string, ConstraintData< Real > > INPUT_linear_con_
void removeBoundConstraint()
Remove an existing bound constraint.
Ptr< Vector< Real > > xprim_
EProblem getProblemType()
Get the optimization problem type (U, B, E, or G).
void addProxObjective(const Ptr< ProxObjective< Real > > &prox)
Add a prox objective.
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.
Ptr< Vector< Real > > mul_
void addBoundConstraint(const Ptr< BoundConstraint< Real > > &bnd)
Add a bound constraint.
Ptr< BoundConstraint< Real > > bnd_
void setProjectionAlgorithm(ParameterList &parlist)
Set polyhedral projection algorithm.
void finalizeIteration()
Transform the optimization variables to the native parameterization after an optimization algorithm h...
Ptr< Vector< Real > > INPUT_xdual_
Ptr< Vector< Real > > xfeas_
Ptr< PolyhedralProjection< Real > > proj_
std::unordered_map< std::string, ConstraintData< Real > > INPUT_con_
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.
Ptr< Vector< Real > > res_
Ptr< Objective< Real > > obj_
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...
Ptr< Vector< Real > > xdual_
Ptr< Vector< Real > > INPUT_xprim_
void removeProxObjective()
Remove an existing prox objective.
void checkDerivatives(bool printToStream=false, std::ostream &outStream=std::cout) const
Run derivative checks for user-supplied objective function and constraints.
Ptr< ReduceLinearConstraint< Real > > rlc_
const Ptr< Objective< Real > > & getObjective()
Get the objective function.
const Ptr< BoundConstraint< Real > > & getBoundConstraint()
Get the bound constraint.
const Ptr< Vector< Real > > & getResidualVector()
Get the primal constraint space vector.
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...
virtual void edit()
Resume editting optimization problem after finalize has been called.
Real checkLinearity(bool printToStream=false, std::ostream &outStream=std::cout) const
Check if user-supplied linear constraints are affine.
Ptr< ProxObjective< Real > > prox_
Defines the linear algebra or vector space interface.