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 
58 namespace ROL {
59 
60 template<typename Real>
61 class Problem {
62 private:
64  bool hasBounds_;
69  bool hasProx_;
70  unsigned cnt_econ_;
71  unsigned cnt_icon_;
72  unsigned cnt_linear_econ_;
73  unsigned cnt_linear_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 
92 protected:
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 
102 public:
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 
150  void removeBoundConstraint();
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
void removeProxObjective()
Remove an existing prox objective.
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...
Provides the interface to evaluate objective functions.
const Ptr< Constraint< Real > > & getConstraint()
Get the equality constraint.
Ptr< BoundConstraint< Real > > bnd_
void checkDerivatives(bool printToStream=false, std::ostream &outStream=std::cout) const
Run derivative checks for user-supplied objective function and constraints.
const Ptr< Vector< Real > > & getPrimalOptimizationVector()
Get the primal optimization space vector.
void addBoundConstraint(const Ptr< BoundConstraint< Real >> &bnd)
Add a bound constraint.
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 removeBoundConstraint()
Remove an existing bound constraint.
Contains definitions of custom data types in ROL.
void removeLinearConstraint(std::string name)
Remove an existing linear constraint.
const Ptr< BoundConstraint< Real > > & getBoundConstraint()
Get the bound constraint.
Ptr< ProxObjective< Real > > prox_
Ptr< ReduceLinearConstraint< Real > > rlc_
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
void addProxObjective(const Ptr< ProxObjective< Real >> &prox)
Add a prox objective.
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...
Ptr< Objective< Real > > INPUT_obj_
Ptr< Objective< Real > > obj_
bool isFinalized() const
Indicate whether or no finalize has been called.
Ptr< Vector< Real > > res_
Ptr< Vector< Real > > INPUT_xprim_
const Ptr< Objective< Real > > & getObjective()
Get the objective function.
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_linear_con_
std::unordered_map< std::string, ConstraintData< Real > > INPUT_con_
Ptr< Vector< Real > > INPUT_xdual_
const Ptr< Vector< Real > > & getResidualVector()
Get the primal constraint space vector.
const Ptr< Vector< Real > > & getMultiplierVector()
Get the dual constraint space vector.
void finalizeIteration()
Transform the optimization variables to the native parameterization after an optimization algorithm h...
Ptr< Vector< Real > > xdual_
Problem(const Problem &problem)
Copy constructor for OptimizationProblem.
Ptr< Constraint< Real > > con_
Provides the interface to apply upper and lower bound constraints.
Real checkLinearity(bool printToStream=false, std::ostream &outStream=std::cout) const
Check if user-supplied linear constraints are affine.
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.
const Ptr< PolyhedralProjection< Real > > & getPolyhedralProjection()
Get the polyhedral projection object. This is a null pointer if no linear constraints and/or bounds a...
EProblem getProblemType()
Get the optimization problem type (U, B, E, or G).
void removeConstraint(std::string name)
Remove an existing constraint.
Ptr< Vector< Real > > xfeas_
Ptr< BoundConstraint< Real > > INPUT_bnd_
virtual void edit()
Resume editting optimization problem after finalize has been called.
const Ptr< Vector< Real > > & getDualOptimizationVector()
Get the dual optimization space vector.
void checkVectors(bool printToStream=false, std::ostream &outStream=std::cout) const
Run vector checks for user-supplied vectors.
EProblem
Definition: ROL_Types.hpp:257
Ptr< Vector< Real > > xprim_
Ptr< Vector< Real > > mul_
Defines the general constraint operator interface.
void setProjectionAlgorithm(ParameterList &parlist)
Set polyhedral projection algorithm.
Ptr< ProxObjective< Real > > INPUT_prox_
Ptr< PolyhedralProjection< Real > > proj_