ROL
ROL_ConstraintAssembler.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_CONSTRAINT_ASSEMBLER_H
45 #define ROL_CONSTRAINT_ASSEMBLER_H
46 
49 #include <unordered_map>
50 
58 namespace ROL {
59 
60 template<typename Real>
62  Ptr<Constraint<Real>> constraint;
63  Ptr<Vector<Real>> multiplier;
64  Ptr<Vector<Real>> residual;
65  Ptr<BoundConstraint<Real>> bounds;
66 
68  const Ptr<Vector<Real>> &mul,
69  const Ptr<Vector<Real>> &res=nullPtr,
70  const Ptr<BoundConstraint<Real>> &bnd=nullPtr)
71  : constraint(con), multiplier(mul),
72  residual(res==nullPtr ? mul->dual().clone() : res), bounds(bnd) {}
73 };
74 
75 template<typename Real>
77 private:
78  Ptr<Constraint<Real>> con_;
79  Ptr<Vector<Real>> mul_;
80  Ptr<Vector<Real>> res_;
81  Ptr<Constraint<Real>> linear_con_;
82  Ptr<Vector<Real>> linear_mul_;
83  Ptr<Vector<Real>> linear_res_;
84  Ptr<Vector<Real>> xprim_;
85  Ptr<Vector<Real>> xdual_;
86  Ptr<BoundConstraint<Real>> bnd_;
87 
88  std::vector<Ptr<Constraint<Real>>> cvec_; // General constraints
89  std::vector<Ptr<Vector<Real>>> lvec_; // General multiplier vector
90  std::vector<Ptr<Vector<Real>>> rvec_; // General residual vector
91  std::vector<Ptr<Constraint<Real>>> lcvec_; // Linear constraints
92  std::vector<Ptr<Vector<Real>>> llvec_; // Linear multiplier vector
93  std::vector<Ptr<Vector<Real>>> lrvec_; // Linear residual vector
94  std::vector<Ptr<Vector<Real>>> psvec_; // Primal slack vector
95  std::vector<Ptr<Vector<Real>>> dsvec_; // Dual slack vector
96  std::vector<Ptr<BoundConstraint<Real>>> sbnd_; // Slack bound constraint
97 
98  std::vector<bool> isInequality_, isLinearInequality_;
99 
100  bool isNull_;
102 
103  void initializeSlackVariable( const Ptr<Constraint<Real>> &con,
104  const Ptr<BoundConstraint<Real>> &cbnd,
105  const Ptr<Vector<Real>> &s,
106  const Ptr<Vector<Real>> &x) const;
107 
108  void initialize( const std::unordered_map<std::string,ConstraintData<Real>> &input_con,
109  const Ptr<Vector<Real>> &xprim,
110  const Ptr<Vector<Real>> &xdual,
111  const Ptr<BoundConstraint<Real>> &bnd);
112 
113  void initialize( const std::unordered_map<std::string,ConstraintData<Real>> &input_con,
114  const std::unordered_map<std::string,ConstraintData<Real>> &input_lcon,
115  const Ptr<Vector<Real>> &xprim,
116  const Ptr<Vector<Real>> &xdual,
117  const Ptr<BoundConstraint<Real>> &bnd);
118 
119 public:
120  virtual ~ConstraintAssembler() {}
121 
122  ConstraintAssembler( const std::unordered_map<std::string,ConstraintData<Real>> &con,
123  const Ptr<Vector<Real>> &xprim,
124  const Ptr<Vector<Real>> &xdual,
125  const Ptr<BoundConstraint<Real>> &bnd = nullPtr);
126 
127  ConstraintAssembler( const std::unordered_map<std::string,ConstraintData<Real>> &con,
128  const std::unordered_map<std::string,ConstraintData<Real>> &linear_con,
129  const Ptr<Vector<Real>> &xprim,
130  const Ptr<Vector<Real>> &xdual,
131  const Ptr<BoundConstraint<Real>> &bnd = nullPtr);
132 
133  const Ptr<Constraint<Real>>& getConstraint() const;
134  const Ptr<Vector<Real>>& getMultiplier() const;
135  const Ptr<Vector<Real>>& getResidual() const;
136  const Ptr<Constraint<Real>>& getLinearConstraint() const;
137  const Ptr<Vector<Real>>& getLinearMultiplier() const;
138  const Ptr<Vector<Real>>& getLinearResidual() const;
139  const Ptr<Vector<Real>>& getOptVector() const;
140  const Ptr<Vector<Real>>& getDualOptVector() const;
141  const Ptr<BoundConstraint<Real>>& getBoundConstraint() const;
142 
143  bool isNull() const;
144  bool hasInequality() const;
145 
146  void resetSlackVariables();
147 
148 }; // class ConstraintAssembler
149 
150 } // namespace ROL
151 
153 
154 #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:80
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.