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
23namespace ROL {
24
25template<typename Real>
26class Problem {
27private:
28 bool isFinalized_;
29 bool hasBounds_;
30 bool hasEquality_;
31 bool hasInequality_;
35 unsigned cnt_econ_;
36 unsigned cnt_icon_;
37 unsigned cnt_linear_econ_;
38 unsigned cnt_linear_icon_;
39
40 ParameterList ppa_list_;
41
42 Ptr<Objective<Real>> obj_;
43 Ptr<Objective<Real>> nobj_;
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
52 Ptr<Vector<Real>> xfeas_;
53 Ptr<ReduceLinearConstraint<Real>> rlc_;
54
56
57protected:
58
59 Ptr<Objective<Real>> INPUT_obj_;
60 Ptr<Objective<Real>> INPUT_nobj_;
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
67public:
68 virtual ~Problem() {}
69
76 Problem( const Ptr<Objective<Real>> &obj,
77 const Ptr<Vector<Real>> &x,
78 const Ptr<Vector<Real>> &g = nullPtr);
79
104
105 /***************************************************************************/
106 /*** Set and remove methods for constraints ********************************/
107 /***************************************************************************/
108
114
118
127 void addConstraint(std::string name,
128 const Ptr<Constraint<Real>> &econ,
129 const Ptr<Vector<Real>> &emul,
130 const Ptr<Vector<Real>> &eres = nullPtr,
131 bool reset = false);
132
142 void addConstraint(std::string name,
143 const Ptr<Constraint<Real>> &icon,
144 const Ptr<Vector<Real>> &imul,
145 const Ptr<BoundConstraint<Real>> &ibnd,
146 const Ptr<Vector<Real>> &ires = nullPtr,
147 bool reset = false);
148
153 void removeConstraint(std::string name);
154
163 void addLinearConstraint(std::string name,
164 const Ptr<Constraint<Real>> &linear_econ,
165 const Ptr<Vector<Real>> &linear_emul,
166 const Ptr<Vector<Real>> &linear_eres = nullPtr,
167 bool reset = false);
168
178 void addLinearConstraint(std::string name,
179 const Ptr<Constraint<Real>> &linear_icon,
180 const Ptr<Vector<Real>> &linear_imul,
181 const Ptr<BoundConstraint<Real>> &linear_ibnd,
182 const Ptr<Vector<Real>> &linear_ires = nullPtr,
183 bool reset = false);
184
189 void removeLinearConstraint(std::string name);
190
195 void setProjectionAlgorithm(ParameterList &parlist);
196
199 void addProximableObjective(const Ptr<Objective<Real>> &nobj);
200
204
205
206 /***************************************************************************/
207 /*** Accessor methods ******************************************************/
208 /***************************************************************************/
209
212 const Ptr<Objective<Real>>& getObjective();
213
216 const Ptr<Objective<Real>>& getProximableObjective();
217
220 const Ptr<Vector<Real>>& getPrimalOptimizationVector();
221
224 const Ptr<Vector<Real>>& getDualOptimizationVector();
225
228 const Ptr<BoundConstraint<Real>>& getBoundConstraint();
229
232 const Ptr<Constraint<Real>>& getConstraint();
233
236 const Ptr<Vector<Real>>& getMultiplierVector();
237
240 const Ptr<Vector<Real>>& getResidualVector();
241
245 const Ptr<PolyhedralProjection<Real>>& getPolyhedralProjection();
246
250
251 /***************************************************************************/
252 /*** Consistency checks ****************************************************/
253 /***************************************************************************/
254
265 Real checkLinearity(bool printToStream = false, std::ostream &outStream = std::cout) const;
266
272 void checkVectors(bool printToStream = false, std::ostream &outStream = std::cout) const;
273
279 void checkDerivatives(bool printToStream = false, std::ostream &outStream = std::cout, const Ptr<Vector<Real>> &x0 = nullPtr, Real scale = Real(1)) const;
280
287 void check(bool printToStream = false, std::ostream &outStream = std::cout, const Ptr<Vector<Real>> &x0 = nullPtr, Real scale = Real(1)) const;
288
289 /***************************************************************************/
290 /*** Finalize and edit methods *********************************************/
291 /***************************************************************************/
292
301 virtual void finalize(bool lumpConstraints = false, bool printToStream = false,
302 std::ostream &outStream = std::cout);
303
306 bool isFinalized() const;
307
310 virtual void edit();
311
316
317}; // class Problem
318
319} // namespace ROL
320
321#include "ROL_Problem_Def.hpp"
322
323#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< 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_
void addLinearConstraint(std::string name, const Ptr< Constraint< Real > > &linear_icon, const Ptr< Vector< Real > > &linear_imul, const Ptr< BoundConstraint< Real > > &linear_ibnd, const Ptr< Vector< Real > > &linear_ires=nullPtr, bool reset=false)
Add a linear inequality constraint.
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.
const Ptr< Objective< Real > > & getProximableObjective()
Get proximable objective.
Ptr< Vector< Real > > xprim_
EProblem getProblemType()
Get the optimization problem type (U, B, E, G, or P).
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.
Ptr< Objective< Real > > nobj_
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_
virtual void edit()
Resume editting optimization problem after finalize has been called.
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.
void addProximableObjective(const Ptr< Objective< Real > > &nobj)
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 checkDerivatives(bool printToStream=false, std::ostream &outStream=std::cout) const
Run derivative checks for user-supplied objective function and constraints.
Ptr< ReduceLinearConstraint< Real > > rlc_
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...
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.
Real checkLinearity(bool printToStream=false, std::ostream &outStream=std::cout) const
Check if user-supplied linear constraints are affine.
Problem(const Ptr< Objective< Real > > &obj, const Ptr< Vector< Real > > &x, const Ptr< Vector< Real > > &g=nullPtr)
Default constructor for OptimizationProblem.
Ptr< Objective< Real > > INPUT_nobj_
void addConstraint(std::string name, const Ptr< Constraint< Real > > &icon, const Ptr< Vector< Real > > &imul, const Ptr< BoundConstraint< Real > > &ibnd, const Ptr< Vector< Real > > &ires=nullPtr, bool reset=false)
Add an inequality constraint.
Defines the linear algebra or vector space interface.