ROL
Loading...
Searching...
No Matches
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#include <unordered_set>
16
17#include "ROL_Ptr.hpp"
18#include "ROL_Types.hpp"
23
24namespace ROL {
25
26template<typename Real>
27class Problem {
28private:
29 bool isFinalized_;
30 bool hasBounds_;
31 bool hasEquality_;
32 bool hasInequality_;
36 unsigned cnt_econ_;
37 unsigned cnt_icon_;
38 unsigned cnt_linear_econ_;
39 unsigned cnt_linear_icon_;
40
41 ParameterList ppa_list_;
42
43 Ptr<Objective<Real>> obj_;
44 Ptr<Objective<Real>> nobj_;
45 Ptr<Vector<Real>> xprim_;
46 Ptr<Vector<Real>> xdual_;
47 Ptr<BoundConstraint<Real>> bnd_;
48 Ptr<Constraint<Real>> con_;
49 Ptr<Vector<Real>> mul_;
50 Ptr<Vector<Real>> res_;
51 Ptr<PolyhedralProjection<Real>> proj_;
52
53 Ptr<Vector<Real>> xfeas_;
54 Ptr<ReduceLinearConstraint<Real>> rlc_;
55
57
58protected:
59
60 Ptr<Objective<Real>> INPUT_obj_;
61 Ptr<Objective<Real>> INPUT_nobj_;
62 Ptr<Vector<Real>> INPUT_xprim_;
63 Ptr<Vector<Real>> INPUT_xdual_;
64 Ptr<BoundConstraint<Real>> INPUT_bnd_;
65 std::unordered_map<std::string,ConstraintData<Real>> INPUT_con_;
66 std::unordered_map<std::string,ConstraintData<Real>> INPUT_linear_con_;
67 std::unordered_map<std::string,ConstraintData<Real>> INPUT_proj_;
68 std::unordered_map<std::string,std::vector<std::string>> groups_;
69 std::unordered_set<std::string> grouped_constraint_names_;
70 std::vector<std::string> ungrouped_equality_constraint_names_;
72
73public:
74 virtual ~Problem() {}
75
82 Problem( const Ptr<Objective<Real>> &obj,
83 const Ptr<Vector<Real>> &x,
84 const Ptr<Vector<Real>> &g = nullPtr);
85
116
117 /***************************************************************************/
118 /*** Set and remove methods for constraints ********************************/
119 /***************************************************************************/
120
126
130
139 void addConstraint(std::string name,
140 const Ptr<Constraint<Real>> &econ,
141 const Ptr<Vector<Real>> &emul,
142 const Ptr<Vector<Real>> &eres = nullPtr,
143 bool reset = false);
144
154 void addConstraint(std::string name,
155 const Ptr<Constraint<Real>> &icon,
156 const Ptr<Vector<Real>> &imul,
157 const Ptr<BoundConstraint<Real>> &ibnd,
158 const Ptr<Vector<Real>> &ires = nullPtr,
159 bool reset = false);
160
170 void addConstraint(std::string name,
171 const Ptr<Constraint<Real>> &pcon,
172 const Ptr<Vector<Real>> &pmul,
173 const Ptr<Projection<Real>> &proj,
174 const Ptr<Vector<Real>> &pres = nullPtr,
175 bool reset = false);
176
181 void removeConstraint(std::string name);
182
191 void addLinearConstraint(std::string name,
192 const Ptr<Constraint<Real>> &linear_econ,
193 const Ptr<Vector<Real>> &linear_emul,
194 const Ptr<Vector<Real>> &linear_eres = nullPtr,
195 bool reset = false);
196
206 void addLinearConstraint(std::string name,
207 const Ptr<Constraint<Real>> &linear_icon,
208 const Ptr<Vector<Real>> &linear_imul,
209 const Ptr<BoundConstraint<Real>> &linear_ibnd,
210 const Ptr<Vector<Real>> &linear_ires = nullPtr,
211 bool reset = false);
212
217 void removeLinearConstraint(std::string name);
218
223 void setProjectionAlgorithm(ParameterList &parlist);
224
227 void addProximableObjective(const Ptr<Objective<Real>> &nobj);
228
232
238 void addConstraintGroup(const std::string &group_name,
239 const std::vector<std::string> &constraint_names);
240
245 void removeConstraintGroup(const std::string &group_name);
246
247 /***************************************************************************/
248 /*** Accessor methods ******************************************************/
249 /***************************************************************************/
250
253 const Ptr<Objective<Real>>& getObjective();
254
257 const Ptr<Objective<Real>>& getProximableObjective();
258
261 const Ptr<Vector<Real>>& getPrimalOptimizationVector();
262
265 const Ptr<Vector<Real>>& getDualOptimizationVector();
266
269 const Ptr<BoundConstraint<Real>>& getBoundConstraint();
270
273 const Ptr<Constraint<Real>>& getConstraint();
274
277 const Ptr<Vector<Real>>& getMultiplierVector();
278
281 const Ptr<Vector<Real>>& getResidualVector();
282
286 const Ptr<PolyhedralProjection<Real>>& getPolyhedralProjection();
287
291
292 Ptr<ConstraintData<Real>> getConstraintData(const std::string &constraint_name);
293
294 const std::vector<std::string>& getUngroupedEqualityConstraintNames();
295
296 const std::vector<std::string>& getUngroupedLinearEqualityConstraintNames();
297
298 const std::vector<std::string> getGroupNames();
299
300 const Ptr<ConstraintData<Real>> getGroupConstraintData(const std::string &group_name);
301
302 /***************************************************************************/
303 /*** Consistency checks ****************************************************/
304 /***************************************************************************/
305
316 Real checkLinearity(bool printToStream = false, std::ostream &outStream = std::cout) const;
317
323 void checkVectors(bool printToStream = false, std::ostream &outStream = std::cout) const;
324
330 void checkDerivatives(bool printToStream = false, std::ostream &outStream = std::cout, const Ptr<Vector<Real>> &x0 = nullPtr, Real scale = Real(1)) const;
331
338 void check(bool printToStream = false, std::ostream &outStream = std::cout, const Ptr<Vector<Real>> &x0 = nullPtr, Real scale = Real(1)) const;
339
340 /***************************************************************************/
341 /*** Finalize and edit methods *********************************************/
342 /***************************************************************************/
343
352 virtual void finalize(bool lumpConstraints = false,
353 bool printToStream = false,
354 std::ostream &outStream = std::cout,
355 bool useSlackVariables = true);
356
359 bool isFinalized() const;
360
363 virtual void edit();
364
369
370}; // class Problem
371
372} // namespace ROL
373
374#include "ROL_Problem_Def.hpp"
375
376#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_
const std::vector< std::string > & getUngroupedEqualityConstraintNames()
const std::vector< std::string > getGroupNames()
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.
std::vector< std::string > ungrouped_linear_equality_constraint_names_
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_
Ptr< ConstraintData< Real > > getConstraintData(const std::string &constraint_name)
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.
void addConstraintGroup(const std::string &group_name, const std::vector< std::string > &constraint_names)
Combine a set of constraints into a group.
Ptr< Vector< Real > > mul_
void addBoundConstraint(const Ptr< BoundConstraint< Real > > &bnd)
Add a bound constraint.
std::vector< std::string > ungrouped_equality_constraint_names_
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_
std::unordered_map< std::string, ConstraintData< Real > > INPUT_proj_
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)
Set Proximable objective function.
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...
const std::vector< std::string > & getUngroupedLinearEqualityConstraintNames()
Ptr< Vector< Real > > xdual_
Ptr< Vector< Real > > INPUT_xprim_
std::unordered_map< std::string, std::vector< std::string > > groups_
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< ConstraintData< Real > > getGroupConstraintData(const std::string &group_name)
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.
void removeConstraintGroup(const std::string &group_name)
Remove a group of constraints.
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...
void removeProximableObjective()
Remove Proximable objective function.
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.
std::unordered_set< std::string > grouped_constraint_names_
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.