ROL
ROL_ConstraintAssembler.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_CONSTRAINT_ASSEMBLER_H
11 #define ROL_CONSTRAINT_ASSEMBLER_H
12 
15 #include <unordered_map>
16 
24 namespace ROL {
25 
26 template<typename Real>
28  Ptr<Constraint<Real>> constraint;
29  Ptr<Vector<Real>> multiplier;
30  Ptr<Vector<Real>> residual;
31  Ptr<BoundConstraint<Real>> bounds;
32 
34  const Ptr<Vector<Real>> &mul,
35  const Ptr<Vector<Real>> &res=nullPtr,
36  const Ptr<BoundConstraint<Real>> &bnd=nullPtr)
37  : constraint(con), multiplier(mul),
38  residual(res==nullPtr ? mul->dual().clone() : res), bounds(bnd) {}
39 };
40 
41 template<typename Real>
43 private:
44  Ptr<Constraint<Real>> con_;
45  Ptr<Vector<Real>> mul_;
46  Ptr<Vector<Real>> res_;
47  Ptr<Constraint<Real>> linear_con_;
48  Ptr<Vector<Real>> linear_mul_;
49  Ptr<Vector<Real>> linear_res_;
50  Ptr<Vector<Real>> xprim_;
51  Ptr<Vector<Real>> xdual_;
52  Ptr<BoundConstraint<Real>> bnd_;
53 
54  std::vector<Ptr<Constraint<Real>>> cvec_; // General constraints
55  std::vector<Ptr<Vector<Real>>> lvec_; // General multiplier vector
56  std::vector<Ptr<Vector<Real>>> rvec_; // General residual vector
57  std::vector<Ptr<Constraint<Real>>> lcvec_; // Linear constraints
58  std::vector<Ptr<Vector<Real>>> llvec_; // Linear multiplier vector
59  std::vector<Ptr<Vector<Real>>> lrvec_; // Linear residual vector
60  std::vector<Ptr<Vector<Real>>> psvec_; // Primal slack vector
61  std::vector<Ptr<Vector<Real>>> dsvec_; // Dual slack vector
62  std::vector<Ptr<BoundConstraint<Real>>> sbnd_; // Slack bound constraint
63 
64  std::vector<bool> isInequality_, isLinearInequality_;
65 
66  bool isNull_;
68 
69  void initializeSlackVariable( const Ptr<Constraint<Real>> &con,
70  const Ptr<BoundConstraint<Real>> &cbnd,
71  const Ptr<Vector<Real>> &s,
72  const Ptr<Vector<Real>> &x) const;
73 
74  void initialize( const std::unordered_map<std::string,ConstraintData<Real>> &input_con,
75  const Ptr<Vector<Real>> &xprim,
76  const Ptr<Vector<Real>> &xdual,
77  const Ptr<BoundConstraint<Real>> &bnd);
78 
79  void initialize( const std::unordered_map<std::string,ConstraintData<Real>> &input_con,
80  const std::unordered_map<std::string,ConstraintData<Real>> &input_lcon,
81  const Ptr<Vector<Real>> &xprim,
82  const Ptr<Vector<Real>> &xdual,
83  const Ptr<BoundConstraint<Real>> &bnd);
84 
85 public:
86  virtual ~ConstraintAssembler() {}
87 
88  ConstraintAssembler( const std::unordered_map<std::string,ConstraintData<Real>> &con,
89  const Ptr<Vector<Real>> &xprim,
90  const Ptr<Vector<Real>> &xdual,
91  const Ptr<BoundConstraint<Real>> &bnd = nullPtr);
92 
93  ConstraintAssembler( const std::unordered_map<std::string,ConstraintData<Real>> &con,
94  const std::unordered_map<std::string,ConstraintData<Real>> &linear_con,
95  const Ptr<Vector<Real>> &xprim,
96  const Ptr<Vector<Real>> &xdual,
97  const Ptr<BoundConstraint<Real>> &bnd = nullPtr);
98 
99  const Ptr<Constraint<Real>>& getConstraint() const;
100  const Ptr<Vector<Real>>& getMultiplier() const;
101  const Ptr<Vector<Real>>& getResidual() const;
102  const Ptr<Constraint<Real>>& getLinearConstraint() const;
103  const Ptr<Vector<Real>>& getLinearMultiplier() const;
104  const Ptr<Vector<Real>>& getLinearResidual() const;
105  const Ptr<Vector<Real>>& getOptVector() const;
106  const Ptr<Vector<Real>>& getDualOptVector() const;
107  const Ptr<BoundConstraint<Real>>& getBoundConstraint() const;
108 
109  bool isNull() const;
110  bool hasInequality() const;
111 
112  void resetSlackVariables();
113 
114 }; // class ConstraintAssembler
115 
116 } // namespace ROL
117 
119 
120 #endif
Ptr< Vector< Real > > multiplier
std::vector< Ptr< Constraint< Real > > > lcvec_
std::vector< Ptr< Vector< Real > > > lvec_
std::vector< Ptr< BoundConstraint< Real > > > sbnd_
const Ptr< BoundConstraint< Real > > & getBoundConstraint() const
Ptr< Vector< Real > > linear_res_
const Ptr< Constraint< Real > > & getConstraint() const
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:46
ConstraintData(const Ptr< Constraint< Real >> &con, const Ptr< Vector< Real >> &mul, const Ptr< Vector< Real >> &res=nullPtr, const Ptr< BoundConstraint< Real >> &bnd=nullPtr)
const Ptr< Vector< Real > > & getLinearResidual() const
void initializeSlackVariable(const Ptr< Constraint< Real >> &con, const Ptr< BoundConstraint< Real >> &cbnd, const Ptr< Vector< Real >> &s, const Ptr< Vector< Real >> &x) const
Ptr< Vector< Real > > linear_mul_
std::vector< bool > isLinearInequality_
std::vector< Ptr< Vector< Real > > > lrvec_
ConstraintAssembler(const std::unordered_map< std::string, ConstraintData< Real >> &con, const Ptr< Vector< Real >> &xprim, const Ptr< Vector< Real >> &xdual, const Ptr< BoundConstraint< Real >> &bnd=nullPtr)
std::vector< Ptr< Vector< Real > > > rvec_
std::vector< Ptr< Vector< Real > > > dsvec_
std::vector< Ptr< Constraint< Real > > > cvec_
Ptr< BoundConstraint< Real > > bounds
Ptr< BoundConstraint< Real > > bnd_
Ptr< Vector< Real > > residual
Provides a wrapper for multiple constraints.
const Ptr< Vector< Real > > & getMultiplier() const
Provides the interface to apply upper and lower bound constraints.
const Ptr< Vector< Real > > & getDualOptVector() const
void initialize(const std::unordered_map< std::string, ConstraintData< Real >> &input_con, const Ptr< Vector< Real >> &xprim, const Ptr< Vector< Real >> &xdual, const Ptr< BoundConstraint< Real >> &bnd)
Ptr< Constraint< Real > > constraint
Ptr< Constraint< Real > > con_
std::vector< Ptr< Vector< Real > > > psvec_
Ptr< Constraint< Real > > linear_con_
const Ptr< Vector< Real > > & getOptVector() const
const Ptr< Constraint< Real > > & getLinearConstraint() const
const Ptr< Vector< Real > > & getLinearMultiplier() const
std::vector< Ptr< Vector< Real > > > llvec_
const Ptr< Vector< Real > > & getResidual() const
Defines the general constraint operator interface.