ROL
Loading...
Searching...
No Matches
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:
36 unsigned cnt_econ_;
37 unsigned cnt_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
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.
unsigned cnt_econ_
void check(bool printToStream=false, std::ostream &outStream=std::cout, const Ptr< Vector< Real > > &x0=nullPtr, Real scale=Real(1)) const
Run vector, linearity and derivative checks for user-supplied vectors, objective function and constra...
unsigned cnt_icon_
ParameterList ppa_list_
virtual void finalize(bool lumpConstraints=false, bool printToStream=false, std::ostream &outStream=std::cout, bool useSlackVariables=true)
Tranform user-supplied constraints. Problem cannot be modified after finalize has been called without...
Problem(const Problem &problem)
Copy constructor for OptimizationProblem.
Ptr< Vector< Real > > INPUT_xdual_
const Ptr< PolyhedralProjection< Real > > & getPolyhedralProjection()
Get the polyhedral projection object. This is a null pointer if no linear constraints and/or bounds a...
EProblem problemType_
bool hasProximableObjective_
const std::vector< std::string > & getUngroupedEqualityConstraintNames()
const std::vector< std::string > getGroupNames()
Ptr< PolyhedralProjection< Real > > proj_
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.
bool hasLinearEquality_
void removeConstraint(std::string name)
Remove an existing constraint.
Ptr< Vector< Real > > xprim_
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.
Ptr< Objective< Real > > INPUT_obj_
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< Vector< Real > > res_
Ptr< ConstraintData< Real > > getConstraintData(const std::string &constraint_name)
void removeBoundConstraint()
Remove an existing bound constraint.
const Ptr< Objective< Real > > & getProximableObjective()
Get proximable objective.
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.
void addBoundConstraint(const Ptr< BoundConstraint< Real > > &bnd)
Add a bound constraint.
std::vector< std::string > ungrouped_equality_constraint_names_
Ptr< ReduceLinearConstraint< Real > > rlc_
void setProjectionAlgorithm(ParameterList &parlist)
Set polyhedral projection algorithm.
unsigned cnt_linear_econ_
Ptr< Objective< Real > > nobj_
void finalizeIteration()
Transform the optimization variables to the native parameterization after an optimization algorithm h...
unsigned cnt_linear_icon_
Ptr< Vector< Real > > xdual_
virtual void edit()
Resume editting optimization problem after finalize has been called.
Ptr< Vector< Real > > xfeas_
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.
const std::vector< std::string > & getUngroupedLinearEqualityConstraintNames()
void checkDerivatives(bool printToStream=false, std::ostream &outStream=std::cout, const Ptr< Vector< Real > > &x0=nullPtr, Real scale=Real(1)) const
Run derivative checks for user-supplied objective function and constraints.
std::unordered_map< std::string, std::vector< std::string > > groups_
Ptr< Objective< Real > > obj_
void addConstraint(std::string name, const Ptr< Constraint< Real > > &pcon, const Ptr< Vector< Real > > &pmul, const Ptr< Projection< Real > > &proj, const Ptr< Vector< Real > > &pres=nullPtr, bool reset=false)
Add a projection constraint.
Ptr< Constraint< Real > > con_
std::unordered_map< std::string, ConstraintData< Real > > INPUT_linear_con_
virtual ~Problem()
Ptr< Vector< Real > > mul_
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.
void removeProximableObjective()
Remove Proximable objective function.
Ptr< BoundConstraint< Real > > INPUT_bnd_
Real checkLinearity(bool printToStream=false, std::ostream &outStream=std::cout) const
Check if user-supplied linear constraints are affine.
Ptr< Vector< Real > > INPUT_xprim_
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_con_
Ptr< BoundConstraint< Real > > bnd_
bool hasLinearInequality_
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.