ROL
ROL_ExplicitLinearConstraint.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_EXPLICIT_LINEAR_CONSTRAINT_H
45 #define ROL_EXPLICIT_LINEAR_CONSTRAINT_H
46 
51 
60 namespace ROL {
61 
62 template <class Real>
64 private:
65  const Ptr<Constraint<Real>> lcon_;
66  const Ptr<Objective<Real>> obj_;
67  const Ptr<Vector<Real>> x_;
68  std::vector<Ptr<Constraint<Real>>> con_;
69 
70  Ptr<SimController<Real>> storage_;
71 
72  Ptr<NullSpaceOperator<Real>> nsop_;
73  Ptr<AffineTransformObjective<Real>> aobj_;
74  std::vector<Ptr<AffineTransformConstraint<Real>>> acon_;
75 
76  void feasible(const Ptr<Vector<Real>> &c) {
77  Real tol = std::sqrt(ROL_EPSILON<Real>());
78  Ptr<Vector<Real>> ran = c->clone();
79  lcon_->value(*ran,*x_,tol);
80  Real cnorm = ran->norm();
81  if ( cnorm > static_cast<Real>(1e-4)*tol ) {
83  Ptr<Vector<Real>> xzero = x_->clone(); xzero->zero();
84  lcon_->value(*ran,*xzero,tol);
85  ran->scale(static_cast<Real>(-1));
86  rsop.apply(*x_,*ran,tol);
87  //throw Exception::NotImplemented(">>> ExplicitLinearConstraint::feasible : Input x is not feasible!");
88  }
89  }
90 
91 public:
92  virtual ~ExplicitLinearConstraint(void) {}
93 
95  const Ptr<Objective<Real>> &obj,
96  const Ptr<Vector<Real>> &x,
97  const Ptr<Vector<Real>> &c)
98  : lcon_(lcon), obj_(obj), x_(x) {
99  feasible(c);
100  storage_ = makePtr<SimController<Real>>();
101  nsop_ = makePtr<NullSpaceOperator<Real>>(lcon,x_,c);
102  aobj_ = makePtr<AffineTransformObjective<Real>>(obj,nsop_,x_,storage_);
103  }
104 
106  const Ptr<Objective<Real>> &obj,
107  const Ptr<Constraint<Real>> &con,
108  const Ptr<Vector<Real>> &x,
109  const Ptr<Vector<Real>> &c)
110  : lcon_(lcon), obj_(obj), x_(x), con_({con}) {
111  feasible(c);
112  storage_ = makePtr<SimController<Real>>();
113  nsop_ = makePtr<NullSpaceOperator<Real>>(lcon,x_,c);
114  aobj_ = makePtr<AffineTransformObjective<Real>>(obj,nsop_,x_,storage_);
115  acon_.clear();
116  acon_.push_back(makePtr<AffineTransformConstraint<Real>>(con,nsop_,x_,storage_));
117  }
118 
120  const Ptr<Objective<Real>> &obj,
121  const std::vector<Ptr<Constraint<Real>>> &con,
122  const Ptr<Vector<Real>> &x,
123  const Ptr<Vector<Real>> &c)
124  : lcon_(lcon), obj_(obj), x_(x), con_(con) {
125  feasible(c);
126  storage_ = makePtr<SimController<Real>>();
127  nsop_ = makePtr<NullSpaceOperator<Real>>(lcon,x_,c);
128  aobj_ = makePtr<AffineTransformObjective<Real>>(obj,nsop_,x_,storage_);
129  acon_.clear();
130  int size = con_.size();
131  for (int i = 0; i < size; ++i) {
132  acon_.push_back(makePtr<AffineTransformConstraint<Real>>(con[i],nsop_,x_,storage_));
133  }
134  }
135 
136  const ROL::Ptr<Constraint<Real>> getExplicitConstraint(void) const {
137  return lcon_;
138  }
139 
140  const ROL::Ptr<Objective<Real>> getObjective(void) const {
141  return obj_;
142  }
143 
144  const ROL::Ptr<Constraint<Real>> getConstraint(const int ind = 0) const {
145  if (ind < 0 || ind >= static_cast<int>(con_.size())) {
146  throw Exception::NotImplemented(">>> ExplicitLinearConstraint::getConstraint : Index out of bounds!");
147  }
148  return con_[ind];
149  }
150 
151  const ROL::Ptr<Vector<Real>> getFeasibleVector(void) const {
152  return x_;
153  }
154 
155  const ROL::Ptr<Objective<Real>> getTransformedObjective(void) const {
156  return aobj_;
157  }
158 
159  const ROL::Ptr<Constraint<Real>> getTransformedConstraint(const int ind = 0) const {
160  if (ind < 0 || ind >= static_cast<int>(acon_.size())) {
161  throw Exception::NotImplemented(">>> ExplicitLinearConstraint::getTransformedConstraint : Index out of bounds!");
162  }
163  return acon_[ind];
164  }
165 
166  virtual void project(Ptr<Vector<Real>> &x,
167  const Ptr<Vector<Real>> &y) const {
168  Real tol = std::sqrt(ROL_EPSILON<Real>());
169  nsop_->apply(*x,*y,tol);
170  }
171 
172 }; // class ExplicitLinearConstraint
173 
174 } // namespace ROL
175 
176 #endif
const Ptr< Objective< Real > > obj_
const ROL::Ptr< Constraint< Real > > getTransformedConstraint(const int ind=0) const
Provides the interface to evaluate objective functions.
const ROL::Ptr< Objective< Real > > getTransformedObjective(void) const
Projects on to the null space of a linear constraint.
std::vector< Ptr< Constraint< Real > > > con_
ExplicitLinearConstraint(const Ptr< Constraint< Real >> &lcon, const Ptr< Objective< Real >> &obj, const std::vector< Ptr< Constraint< Real >>> &con, const Ptr< Vector< Real >> &x, const Ptr< Vector< Real >> &c)
ExplicitLinearConstraint(const Ptr< Constraint< Real >> &lcon, const Ptr< Objective< Real >> &obj, const Ptr< Constraint< Real >> &con, const Ptr< Vector< Real >> &x, const Ptr< Vector< Real >> &c)
Compose a constraint operator with an affine transformation, i.e.,.
const ROL::Ptr< Vector< Real > > getFeasibleVector(void) const
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
Ptr< AffineTransformObjective< Real > > aobj_
Performs null-space transformation for explicit linear equality constraints.
ExplicitLinearConstraint(const Ptr< Constraint< Real >> &lcon, const Ptr< Objective< Real >> &obj, const Ptr< Vector< Real >> &x, const Ptr< Vector< Real >> &c)
const Ptr< Constraint< Real > > lcon_
void feasible(const Ptr< Vector< Real >> &c)
Ptr< NullSpaceOperator< Real > > nsop_
std::vector< Ptr< AffineTransformConstraint< Real > > > acon_
const ROL::Ptr< Constraint< Real > > getExplicitConstraint(void) const
virtual void apply(Vector< Real > &Hv, const Vector< Real > &v, Real &tol) const
Apply linear operator.
const ROL::Ptr< Constraint< Real > > getConstraint(const int ind=0) const
Defines the general constraint operator interface.
virtual void project(Ptr< Vector< Real >> &x, const Ptr< Vector< Real >> &y) const
const ROL::Ptr< Objective< Real > > getObjective(void) const