ROL
function/prox/ROL_Problem.hpp
Go to the documentation of this file.
1// @HEADER
2// ************************************************************************
3//
4// Rapid Optimization Library (ROL) Package
5// Copyright (2014) Sandia Corporation
6//
7// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8// license for use of this work by or on behalf of the U.S. Government.
9//
10// Redistribution and use in source and binary forms, with or without
11// modification, are permitted provided that the following conditions are
12// met:
13//
14// 1. Redistributions of source code must retain the above copyright
15// notice, this list of conditions and the following disclaimer.
16//
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// 3. Neither the name of the Corporation nor the names of the
22// contributors may be used to endorse or promote products derived from
23// this software without specific prior written permission.
24//
25// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36//
37// Questions? Contact lead developers:
38// Drew Kouri (dpkouri@sandia.gov) and
39// Denis Ridzal (dridzal@sandia.gov)
40//
41// ************************************************************************
42// @HEADER
43
44#ifndef ROL_PROBLEM_HPP
45#define ROL_PROBLEM_HPP
46
47#include <utility>
48#include <unordered_map>
49
50#include "ROL_Ptr.hpp"
51#include "ROL_Types.hpp"
56#include "ROL_ProxObjective.hpp"
57
58namespace ROL {
59
60template<typename Real>
61class Problem {
62private:
70 unsigned cnt_econ_;
71 unsigned cnt_icon_;
74
75 ParameterList ppa_list_;
76
77 Ptr<Objective<Real>> obj_;
78 Ptr<Vector<Real>> xprim_;
79 Ptr<Vector<Real>> xdual_;
80 Ptr<BoundConstraint<Real>> bnd_;
81 Ptr<Constraint<Real>> con_;
82 Ptr<Vector<Real>> mul_;
83 Ptr<Vector<Real>> res_;
84 Ptr<PolyhedralProjection<Real>> proj_;
85 Ptr<ProxObjective<Real>> prox_;
86
87 Ptr<Vector<Real>> xfeas_;
88 Ptr<ReduceLinearConstraint<Real>> rlc_;
89
91
92protected:
93
94 Ptr<Objective<Real>> INPUT_obj_;
95 Ptr<Vector<Real>> INPUT_xprim_;
96 Ptr<Vector<Real>> INPUT_xdual_;
97 Ptr<BoundConstraint<Real>> INPUT_bnd_;
98 std::unordered_map<std::string,ConstraintData<Real>> INPUT_con_;
99 std::unordered_map<std::string,ConstraintData<Real>> INPUT_linear_con_;
100 Ptr<ProxObjective<Real>> INPUT_prox_;
101
102public:
103 virtual ~Problem() {}
104
111 Problem( const Ptr<Objective<Real>> &obj,
112 const Ptr<Vector<Real>> &x,
113 const Ptr<Vector<Real>> &g = nullPtr);
114
119 Problem(const Problem &problem)
120 : isFinalized_(false),
121 hasBounds_(problem.hasBounds_),
122 hasEquality_(problem.hasEquality_),
126 cnt_econ_(problem.cnt_econ_),
127 cnt_icon_(problem.cnt_icon_),
130 ppa_list_(problem.ppa_list_),
131 INPUT_obj_(problem.INPUT_obj_),
132 INPUT_xprim_(problem.INPUT_xprim_),
133 INPUT_xdual_(problem.INPUT_xdual_),
134 INPUT_bnd_(problem.INPUT_bnd_),
135 INPUT_con_(problem.INPUT_con_),
137
138 /***************************************************************************/
139 /*** Set and remove methods for constraints ********************************/
140 /***************************************************************************/
141
146 void addBoundConstraint(const Ptr<BoundConstraint<Real>> &bnd);
147
151
156 void addProxObjective(const Ptr<ProxObjective<Real>> &prox);
157
160 void removeProxObjective();
161
170 void addConstraint(std::string name,
171 const Ptr<Constraint<Real>> &econ,
172 const Ptr<Vector<Real>> &emul,
173 const Ptr<Vector<Real>> &eres = nullPtr,
174 bool reset = false);
175
185 void addConstraint(std::string name,
186 const Ptr<Constraint<Real>> &icon,
187 const Ptr<Vector<Real>> &imul,
188 const Ptr<BoundConstraint<Real>> &ibnd,
189 const Ptr<Vector<Real>> &ires = nullPtr,
190 bool reset = false);
191
196 void removeConstraint(std::string name);
197
206 void addLinearConstraint(std::string name,
207 const Ptr<Constraint<Real>> &linear_econ,
208 const Ptr<Vector<Real>> &linear_emul,
209 const Ptr<Vector<Real>> &linear_eres = nullPtr,
210 bool reset = false);
211
221 void addLinearConstraint(std::string name,
222 const Ptr<Constraint<Real>> &linear_icon,
223 const Ptr<Vector<Real>> &linear_imul,
224 const Ptr<BoundConstraint<Real>> &linear_ibnd,
225 const Ptr<Vector<Real>> &linear_ires = nullPtr,
226 bool reset = false);
227
232 void removeLinearConstraint(std::string name);
233
238 void setProjectionAlgorithm(ParameterList &parlist);
239
240 /***************************************************************************/
241 /*** Accessor methods ******************************************************/
242 /***************************************************************************/
243
246 const Ptr<Objective<Real>>& getObjective();
247
250 const Ptr<Vector<Real>>& getPrimalOptimizationVector();
251
254 const Ptr<Vector<Real>>& getDualOptimizationVector();
255
258 const Ptr<BoundConstraint<Real>>& getBoundConstraint();
259
262 const Ptr<Constraint<Real>>& getConstraint();
263
266 const Ptr<Vector<Real>>& getMultiplierVector();
267
270 const Ptr<Vector<Real>>& getResidualVector();
271
275 const Ptr<PolyhedralProjection<Real>>& getPolyhedralProjection();
276
280
281 /***************************************************************************/
282 /*** Consistency checks ****************************************************/
283 /***************************************************************************/
284
295 Real checkLinearity(bool printToStream = false, std::ostream &outStream = std::cout) const;
296
302 void checkVectors(bool printToStream = false, std::ostream &outStream = std::cout) const;
303
309 void checkDerivatives(bool printToStream = false, std::ostream &outStream = std::cout) const;
310
317 void check(bool printToStream = false, std::ostream &outStream = std::cout) const;
318
319 /***************************************************************************/
320 /*** Finalize and edit methods *********************************************/
321 /***************************************************************************/
322
331 virtual void finalize(bool lumpConstraints = false, bool printToStream = false,
332 std::ostream &outStream = std::cout);
333
336 bool isFinalized() const;
337
340 virtual void edit();
341
345 void finalizeIteration();
346
347}; // class Problem
348
349} // namespace ROL
350
351#include "ROL_Problem_Def.hpp"
352
353#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.
Problem(const Ptr< Objective< Real > > &obj, const Ptr< Vector< Real > > &x, const Ptr< Vector< Real > > &g=nullPtr)
Default constructor for OptimizationProblem.
Ptr< ProxObjective< Real > > prox_
Defines the linear algebra or vector space interface.