ROL
algorithm/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
57namespace ROL {
58
59template<typename Real>
60class Problem {
61private:
62 bool isFinalized_;
63 bool hasBounds_;
64 bool hasEquality_;
65 bool hasInequality_;
68 unsigned cnt_econ_;
69 unsigned cnt_icon_;
70 unsigned cnt_linear_econ_;
71 unsigned cnt_linear_icon_;
72
73 ParameterList ppa_list_;
74
75 Ptr<Objective<Real>> obj_;
76 Ptr<Vector<Real>> xprim_;
77 Ptr<Vector<Real>> xdual_;
78 Ptr<BoundConstraint<Real>> bnd_;
79 Ptr<Constraint<Real>> con_;
80 Ptr<Vector<Real>> mul_;
81 Ptr<Vector<Real>> res_;
82 Ptr<PolyhedralProjection<Real>> proj_;
83
84 Ptr<Vector<Real>> xfeas_;
85 Ptr<ReduceLinearConstraint<Real>> rlc_;
86
88
89protected:
90
91 Ptr<Objective<Real>> INPUT_obj_;
92 Ptr<Vector<Real>> INPUT_xprim_;
93 Ptr<Vector<Real>> INPUT_xdual_;
94 Ptr<BoundConstraint<Real>> INPUT_bnd_;
95 std::unordered_map<std::string,ConstraintData<Real>> INPUT_con_;
96 std::unordered_map<std::string,ConstraintData<Real>> INPUT_linear_con_;
97
98public:
99 virtual ~Problem() {}
100
107 Problem( const Ptr<Objective<Real>> &obj,
108 const Ptr<Vector<Real>> &x,
109 const Ptr<Vector<Real>> &g = nullPtr);
110
115 Problem(const Problem &problem)
116 : isFinalized_(false),
117 hasBounds_(problem.hasBounds_),
118 hasEquality_(problem.hasEquality_),
122 cnt_econ_(problem.cnt_econ_),
123 cnt_icon_(problem.cnt_icon_),
126 ppa_list_(problem.ppa_list_),
127 INPUT_obj_(problem.INPUT_obj_),
128 INPUT_xprim_(problem.INPUT_xprim_),
129 INPUT_xdual_(problem.INPUT_xdual_),
130 INPUT_bnd_(problem.INPUT_bnd_),
131 INPUT_con_(problem.INPUT_con_),
133
134 /***************************************************************************/
135 /*** Set and remove methods for constraints ********************************/
136 /***************************************************************************/
137
143
147
156 void addConstraint(std::string name,
157 const Ptr<Constraint<Real>> &econ,
158 const Ptr<Vector<Real>> &emul,
159 const Ptr<Vector<Real>> &eres = nullPtr,
160 bool reset = false);
161
171 void addConstraint(std::string name,
172 const Ptr<Constraint<Real>> &icon,
173 const Ptr<Vector<Real>> &imul,
174 const Ptr<BoundConstraint<Real>> &ibnd,
175 const Ptr<Vector<Real>> &ires = nullPtr,
176 bool reset = false);
177
182 void removeConstraint(std::string name);
183
192 void addLinearConstraint(std::string name,
193 const Ptr<Constraint<Real>> &linear_econ,
194 const Ptr<Vector<Real>> &linear_emul,
195 const Ptr<Vector<Real>> &linear_eres = nullPtr,
196 bool reset = false);
197
207 void addLinearConstraint(std::string name,
208 const Ptr<Constraint<Real>> &linear_icon,
209 const Ptr<Vector<Real>> &linear_imul,
210 const Ptr<BoundConstraint<Real>> &linear_ibnd,
211 const Ptr<Vector<Real>> &linear_ires = nullPtr,
212 bool reset = false);
213
218 void removeLinearConstraint(std::string name);
219
224 void setProjectionAlgorithm(ParameterList &parlist);
225
226 /***************************************************************************/
227 /*** Accessor methods ******************************************************/
228 /***************************************************************************/
229
232 const Ptr<Objective<Real>>& getObjective();
233
236 const Ptr<Vector<Real>>& getPrimalOptimizationVector();
237
240 const Ptr<Vector<Real>>& getDualOptimizationVector();
241
244 const Ptr<BoundConstraint<Real>>& getBoundConstraint();
245
248 const Ptr<Constraint<Real>>& getConstraint();
249
252 const Ptr<Vector<Real>>& getMultiplierVector();
253
256 const Ptr<Vector<Real>>& getResidualVector();
257
261 const Ptr<PolyhedralProjection<Real>>& getPolyhedralProjection();
262
266
267 /***************************************************************************/
268 /*** Consistency checks ****************************************************/
269 /***************************************************************************/
270
281 Real checkLinearity(bool printToStream = false, std::ostream &outStream = std::cout) const;
282
288 void checkVectors(bool printToStream = false, std::ostream &outStream = std::cout) const;
289
295 void checkDerivatives(bool printToStream = false, std::ostream &outStream = std::cout, const Ptr<Vector<Real>> &x0 = nullPtr, Real scale = Real(1)) const;
296
303 void check(bool printToStream = false, std::ostream &outStream = std::cout, const Ptr<Vector<Real>> &x0 = nullPtr, Real scale = Real(1)) const;
304
305 /***************************************************************************/
306 /*** Finalize and edit methods *********************************************/
307 /***************************************************************************/
308
317 virtual void finalize(bool lumpConstraints = false, bool printToStream = false,
318 std::ostream &outStream = std::cout);
319
322 bool isFinalized() const;
323
326 virtual void edit();
327
332
333}; // class Problem
334
335} // namespace ROL
336
337#include "ROL_Problem_Def.hpp"
338
339#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.
Ptr< Vector< Real > > xprim_
EProblem getProblemType()
Get the optimization problem type (U, B, E, or G).
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_
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.
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.
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.