ROL
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 
57 namespace ROL {
58 
59 template<typename Real>
60 class Problem {
61 private:
63  bool hasBounds_;
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 
89 protected:
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 
98 public:
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 
111  /***************************************************************************/
112  /*** Set and remove methods for constraints ********************************/
113  /***************************************************************************/
114 
119  void addBoundConstraint(const Ptr<BoundConstraint<Real>> &bnd);
120 
123  void removeBoundConstraint();
124 
133  void addConstraint(std::string name,
134  const Ptr<Constraint<Real>> &econ,
135  const Ptr<Vector<Real>> &emul,
136  const Ptr<Vector<Real>> &eres = nullPtr,
137  bool reset = false);
138 
148  void addConstraint(std::string name,
149  const Ptr<Constraint<Real>> &icon,
150  const Ptr<Vector<Real>> &imul,
151  const Ptr<BoundConstraint<Real>> &ibnd,
152  const Ptr<Vector<Real>> &ires = nullPtr,
153  bool reset = false);
154 
159  void removeConstraint(std::string name);
160 
169  void addLinearConstraint(std::string name,
170  const Ptr<Constraint<Real>> &linear_econ,
171  const Ptr<Vector<Real>> &linear_emul,
172  const Ptr<Vector<Real>> &linear_eres = nullPtr,
173  bool reset = false);
174 
184  void addLinearConstraint(std::string name,
185  const Ptr<Constraint<Real>> &linear_icon,
186  const Ptr<Vector<Real>> &linear_imul,
187  const Ptr<BoundConstraint<Real>> &linear_ibnd,
188  const Ptr<Vector<Real>> &linear_ires = nullPtr,
189  bool reset = false);
190 
195  void removeLinearConstraint(std::string name);
196 
201  void setProjectionAlgorithm(ParameterList &parlist);
202 
203  /***************************************************************************/
204  /*** Accessor methods ******************************************************/
205  /***************************************************************************/
206 
209  const Ptr<Objective<Real>>& getObjective();
210 
213  const Ptr<Vector<Real>>& getPrimalOptimizationVector();
214 
217  const Ptr<Vector<Real>>& getDualOptimizationVector();
218 
221  const Ptr<BoundConstraint<Real>>& getBoundConstraint();
222 
225  const Ptr<Constraint<Real>>& getConstraint();
226 
229  const Ptr<Vector<Real>>& getMultiplierVector();
230 
233  const Ptr<Vector<Real>>& getResidualVector();
234 
238  const Ptr<PolyhedralProjection<Real>>& getPolyhedralProjection();
239 
243 
244  /***************************************************************************/
245  /*** Consistency checks ****************************************************/
246  /***************************************************************************/
247 
258  Real checkLinearity(bool printToStream = false, std::ostream &outStream = std::cout) const;
259 
265  void checkVectors(bool printToStream = false, std::ostream &outStream = std::cout) const;
266 
272  void checkDerivatives(bool printToStream = false, std::ostream &outStream = std::cout) const;
273 
280  void check(bool printToStream = false, std::ostream &outStream = std::cout) const;
281 
282  /***************************************************************************/
283  /*** Finalize and edit methods *********************************************/
284  /***************************************************************************/
285 
294  virtual void finalize(bool lumpConstraints = false, bool printToStream = false,
295  std::ostream &outStream = std::cout);
296 
299  bool isFinalized() const;
300 
303  virtual void edit();
304 
308  void finalizeIteration();
309 
310 }; // class Problem
311 
312 } // namespace ROL
313 
314 #include "ROL_Problem_Def.hpp"
315 
316 #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_
Definition: ROL_Problem.hpp:68
unsigned cnt_icon_
Definition: ROL_Problem.hpp:69
ParameterList ppa_list_
Definition: ROL_Problem.hpp:73
Ptr< Vector< Real > > INPUT_xdual_
Definition: ROL_Problem.hpp:93
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_
Definition: ROL_Problem.hpp:87
Ptr< PolyhedralProjection< Real > > proj_
Definition: ROL_Problem.hpp:82
const Ptr< Vector< Real > > & getPrimalOptimizationVector()
Get the primal optimization space vector.
bool hasLinearEquality_
Definition: ROL_Problem.hpp:66
void removeConstraint(std::string name)
Remove an existing constraint.
Ptr< Vector< Real > > xprim_
Definition: ROL_Problem.hpp:76
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_
Definition: ROL_Problem.hpp:91
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< Vector< Real > > res_
Definition: ROL_Problem.hpp:81
void removeBoundConstraint()
Remove an existing bound constraint.
EProblem getProblemType()
Get the optimization problem type (U, B, E, or G).
Ptr< ReduceLinearConstraint< Real > > rlc_
Definition: ROL_Problem.hpp:85
void setProjectionAlgorithm(ParameterList &parlist)
Set polyhedral projection algorithm.
unsigned cnt_linear_econ_
Definition: ROL_Problem.hpp:70
void finalizeIteration()
Transform the optimization variables to the native parameterization after an optimization algorithm h...
unsigned cnt_linear_icon_
Definition: ROL_Problem.hpp:71
Ptr< Vector< Real > > xdual_
Definition: ROL_Problem.hpp:77
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.
bool hasInequality_
Definition: ROL_Problem.hpp:65
Ptr< Vector< Real > > xfeas_
Definition: ROL_Problem.hpp:84
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...
Problem(const Ptr< Objective< Real >> &obj, const Ptr< Vector< Real >> &x, const Ptr< Vector< Real >> &g=nullPtr)
Default constructor for OptimizationProblem.
Ptr< Objective< Real > > obj_
Definition: ROL_Problem.hpp:75
void checkDerivatives(bool printToStream=false, std::ostream &outStream=std::cout) const
Run derivative checks for user-supplied objective function and constraints.
Ptr< Constraint< Real > > con_
Definition: ROL_Problem.hpp:79
std::unordered_map< std::string, ConstraintData< Real > > INPUT_linear_con_
Definition: ROL_Problem.hpp:96
virtual ~Problem()
Definition: ROL_Problem.hpp:99
Ptr< Vector< Real > > mul_
Definition: ROL_Problem.hpp:80
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.
Ptr< BoundConstraint< Real > > INPUT_bnd_
Definition: ROL_Problem.hpp:94
Real checkLinearity(bool printToStream=false, std::ostream &outStream=std::cout) const
Check if user-supplied linear constraints are affine.
Ptr< Vector< Real > > INPUT_xprim_
Definition: ROL_Problem.hpp:92
std::unordered_map< std::string, ConstraintData< Real > > INPUT_con_
Definition: ROL_Problem.hpp:95
Ptr< BoundConstraint< Real > > bnd_
Definition: ROL_Problem.hpp:78
void addBoundConstraint(const Ptr< BoundConstraint< Real >> &bnd)
Add a bound constraint.
bool hasLinearInequality_
Definition: ROL_Problem.hpp:67
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.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:84
EProblem
Definition: ROL_Types.hpp:255