ROL
ROL_EqualityConstraint.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_EQUALITY_CONSTRAINT_H
45 #define ROL_EQUALITY_CONSTRAINT_H
46 
47 #include "ROL_Vector.hpp"
48 #include "ROL_Types.hpp"
49 #include "Teuchos_SerialDenseMatrix.hpp"
50 #include "Teuchos_SerialDenseVector.hpp"
51 #include "Teuchos_LAPACK.hpp"
52 #include <iostream>
53 
85 namespace ROL {
86 
87 template <class Real>
89 private:
90  bool activated_;
91 
92 public:
93 
94  virtual ~EqualityConstraint() {}
95 
108  virtual void value(Vector<Real> &c,
109  const Vector<Real> &x,
110  Real &tol) = 0;
111 
112 
127  virtual void applyJacobian(Vector<Real> &jv,
128  const Vector<Real> &v,
129  const Vector<Real> &x,
130  Real &tol);
131 
132 
147  virtual void applyAdjointJacobian(Vector<Real> &ajv,
148  const Vector<Real> &v,
149  const Vector<Real> &x,
150  Real &tol);
151 
152 
169  virtual void applyAdjointJacobian(Vector<Real> &ajv,
170  const Vector<Real> &v,
171  const Vector<Real> &x,
172  const Vector<Real> &dualv,
173  Real &tol);
174 
175 
192  virtual void applyAdjointHessian(Vector<Real> &ahuv,
193  const Vector<Real> &u,
194  const Vector<Real> &v,
195  const Vector<Real> &x,
196  Real &tol);
197 
198 
237  virtual std::vector<Real> solveAugmentedSystem(Vector<Real> &v1,
238  Vector<Real> &v2,
239  const Vector<Real> &b1,
240  const Vector<Real> &b2,
241  const Vector<Real> &x,
242  Real &tol);
243 
244 
265  const Vector<Real> &v,
266  const Vector<Real> &x,
267  const Vector<Real> &g,
268  Real &tol) {
269  pv.set(v.dual());
270  }
271 
272 
274 
280  virtual void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {}
281 
284  virtual bool isFeasible( const Vector<Real> &v ) { return true; }
285 
288  void activate(void) { this->activated_ = true; }
289 
292  void deactivate(void) { this->activated_ = false; }
293 
296  bool isActivated(void) { return this->activated_; }
297 
302  virtual std::vector<std::vector<Real> > checkApplyJacobian( const Vector<Real> &x,
303  const Vector<Real> &v,
304  const Vector<Real> &jv,
305  const std::vector<Real> &steps,
306  const bool printToStream = true,
307  std::ostream & outStream = std::cout,
308  const int order = 1 ) ;
309 
310 
316  virtual std::vector<std::vector<Real> > checkApplyJacobian( const Vector<Real> &x,
317  const Vector<Real> &v,
318  const Vector<Real> &jv,
319  const bool printToStream = true,
320  std::ostream & outStream = std::cout,
321  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
322  const int order = 1 ) ;
323 
329  virtual std::vector<std::vector<Real> > checkApplyAdjointJacobian(const Vector<Real> &x,
330  const Vector<Real> &v,
331  const Vector<Real> &c,
332  const Vector<Real> &ajv,
333  const bool printToStream = true,
334  std::ostream & outStream = std::cout,
335  const int numSteps = ROL_NUM_CHECKDERIV_STEPS ) ;
336 
337  /* \brief Check the consistency of the Jacobian and its adjoint. Verify that the deviation
338  \f$|\langle w^\top,Jv\rangle-\langle adj(J)w,v|\f$ is sufficiently small.
339 
340  @param[in] w is a dual constraint-space vector \f$w\in \mathcal{C}^\ast\f$
341  @param[in] v is an optimization space vector \f$v\in \mathcal{X}\f$
342  @param[in] x is the constraint argument \f$x\in\mathcal{X}\f$
343  @param[in] printToStream is is a flag that turns on/off output
344  @param[in] outStream is the output stream
345 
346  Returns the deviation.
347  */
348 
350  const Vector<Real> &v,
351  const Vector<Real> &x,
352  const bool printToStream = true,
353  std::ostream & outStream = std::cout) {
354  return checkAdjointConsistencyJacobian(w, v, x, w.dual(), v.dual(), printToStream, outStream);
355  }
356 
357  virtual Real checkAdjointConsistencyJacobian(const Vector<Real> &w,
358  const Vector<Real> &v,
359  const Vector<Real> &x,
360  const Vector<Real> &dualw,
361  const Vector<Real> &dualv,
362  const bool printToStream = true,
363  std::ostream & outStream = std::cout);
364 
365 
371  virtual std::vector<std::vector<Real> > checkApplyAdjointHessian(const Vector<Real> &x,
372  const Vector<Real> &u,
373  const Vector<Real> &v,
374  const Vector<Real> &hv,
375  const std::vector<Real> &step,
376  const bool printToScreen = true,
377  std::ostream & outStream = std::cout,
378  const int order = 1 ) ;
384  virtual std::vector<std::vector<Real> > checkApplyAdjointHessian(const Vector<Real> &x,
385  const Vector<Real> &u,
386  const Vector<Real> &v,
387  const Vector<Real> &hv,
388  const bool printToScreen = true,
389  std::ostream & outStream = std::cout,
390  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
391  const int order = 1 ) ;
392 
393 // Definitions for parametrized (stochastic) equality constraints
394 private:
395  std::vector<Real> param_;
396 
397 protected:
398  const std::vector<Real> getParameter(void) const {
399  return param_;
400  }
401 
402 public:
403  virtual void setParameter(const std::vector<Real> &param) {
404  param_.assign(param.begin(),param.end());
405  }
406 
407 }; // class EqualityConstraint
408 
409 } // namespace ROL
410 
412 
413 #endif
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Definition: ROL_Vector.hpp:215
virtual Real checkAdjointConsistencyJacobian(const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &x, const bool printToStream=true, std::ostream &outStream=std::cout)
Contains definitions of custom data types in ROL.
bool isActivated(void)
Check if constraints are on.
virtual void setParameter(const std::vector< Real > &param)
virtual void applyAdjointHessian(Vector< Real > &ahuv, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the derivative of the adjoint of the constraint Jacobian at to vector in direction ...
virtual std::vector< std::vector< Real > > checkApplyAdjointJacobian(const Vector< Real > &x, const Vector< Real > &v, const Vector< Real > &c, const Vector< Real > &ajv, const bool printToStream=true, std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS)
Finite-difference check for the application of the adjoint of constraint Jacobian.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:76
virtual std::vector< std::vector< Real > > checkApplyJacobian(const Vector< Real > &x, const Vector< Real > &v, const Vector< Real > &jv, const std::vector< Real > &steps, const bool printToStream=true, std::ostream &outStream=std::cout, const int order=1)
Finite-difference check for the constraint Jacobian application.
virtual void update(const Vector< Real > &x, bool flag=true, int iter=-1)
Update constraint functions. x is the optimization variable, flag = true if optimization variable is ...
virtual std::vector< Real > solveAugmentedSystem(Vector< Real > &v1, Vector< Real > &v2, const Vector< Real > &b1, const Vector< Real > &b2, const Vector< Real > &x, Real &tol)
Approximately solves the augmented system where , , , , is an identity or Riesz operator...
Defines the equality constraint operator interface.
const std::vector< Real > getParameter(void) const
virtual void applyAdjointJacobian(Vector< Real > &ajv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the adjoint of the the constraint Jacobian at , , to vector .
virtual bool isFeasible(const Vector< Real > &v)
Check if the vector, v, is feasible.
void deactivate(void)
Turn off constraints.
virtual void applyPreconditioner(Vector< Real > &pv, const Vector< Real > &v, const Vector< Real > &x, const Vector< Real > &g, Real &tol)
Apply a constraint preconditioner at , , to vector . Ideally, this preconditioner satisfies the follo...
#define ROL_NUM_CHECKDERIV_STEPS
Number of steps for derivative checks.
Definition: ROL_Types.hpp:73
virtual void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
void activate(void)
Turn on constraints.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:198
virtual std::vector< std::vector< Real > > checkApplyAdjointHessian(const Vector< Real > &x, const Vector< Real > &u, const Vector< Real > &v, const Vector< Real > &hv, const std::vector< Real > &step, const bool printToScreen=true, std::ostream &outStream=std::cout, const int order=1)
Finite-difference check for the application of the adjoint of constraint Hessian. ...
virtual void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)=0
Evaluate the constraint operator at .