ROL
ROL_Constraint.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_H
45 #define ROL_CONSTRAINT_H
46 
47 #include "ROL_Vector.hpp"
48 #include "ROL_UpdateType.hpp"
49 #include "ROL_Types.hpp"
50 #include <iostream>
51 
83 namespace ROL {
84 
85 template <class Real>
86 class Constraint {
87 private:
88  bool activated_;
89 
90 public:
91  virtual ~Constraint(void) {}
92 
93  Constraint(void) : activated_(true) {}
94 
102  virtual void update( const Vector<Real> &x, UpdateType type, int iter = -1 ) {
103  ROL_UNUSED(x);
104  ROL_UNUSED(type);
105  ROL_UNUSED(iter);
106  }
107 
113  virtual void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {}
114 
127  virtual void value(Vector<Real> &c,
128  const Vector<Real> &x,
129  Real &tol) = 0;
130 
131 
146  virtual void applyJacobian(Vector<Real> &jv,
147  const Vector<Real> &v,
148  const Vector<Real> &x,
149  Real &tol);
150 
151 
166  virtual void applyAdjointJacobian(Vector<Real> &ajv,
167  const Vector<Real> &v,
168  const Vector<Real> &x,
169  Real &tol);
170 
171 
188  virtual void applyAdjointJacobian(Vector<Real> &ajv,
189  const Vector<Real> &v,
190  const Vector<Real> &x,
191  const Vector<Real> &dualv,
192  Real &tol);
193 
194 
211  virtual void applyAdjointHessian(Vector<Real> &ahuv,
212  const Vector<Real> &u,
213  const Vector<Real> &v,
214  const Vector<Real> &x,
215  Real &tol);
216 
217 
256  virtual std::vector<Real> solveAugmentedSystem(Vector<Real> &v1,
257  Vector<Real> &v2,
258  const Vector<Real> &b1,
259  const Vector<Real> &b2,
260  const Vector<Real> &x,
261  Real &tol);
262 
263 
284  const Vector<Real> &v,
285  const Vector<Real> &x,
286  const Vector<Real> &g,
287  Real &tol) {
288  pv.set(v.dual());
289  }
290 
293  void activate(void) { activated_ = true; }
294 
297  void deactivate(void) { activated_ = false; }
298 
301  bool isActivated(void) { return activated_; }
302 
307  virtual std::vector<std::vector<Real> > checkApplyJacobian( const Vector<Real> &x,
308  const Vector<Real> &v,
309  const Vector<Real> &jv,
310  const std::vector<Real> &steps,
311  const bool printToStream = true,
312  std::ostream & outStream = std::cout,
313  const int order = 1 ) ;
314 
315 
321  virtual std::vector<std::vector<Real> > checkApplyJacobian( const Vector<Real> &x,
322  const Vector<Real> &v,
323  const Vector<Real> &jv,
324  const bool printToStream = true,
325  std::ostream & outStream = std::cout,
326  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
327  const int order = 1 ) ;
328 
334  virtual std::vector<std::vector<Real> > checkApplyAdjointJacobian(const Vector<Real> &x,
335  const Vector<Real> &v,
336  const Vector<Real> &c,
337  const Vector<Real> &ajv,
338  const bool printToStream = true,
339  std::ostream & outStream = std::cout,
340  const int numSteps = ROL_NUM_CHECKDERIV_STEPS ) ;
341 
342  /* \brief Check the consistency of the Jacobian and its adjoint. Verify that the deviation
343  \f$|\langle w^\top,Jv\rangle-\langle adj(J)w,v|\f$ is sufficiently small.
344 
345  @param[in] w is a dual constraint-space vector \f$w\in \mathcal{C}^\ast\f$
346  @param[in] v is an optimization space vector \f$v\in \mathcal{X}\f$
347  @param[in] x is the constraint argument \f$x\in\mathcal{X}\f$
348  @param[in] printToStream is is a flag that turns on/off output
349  @param[in] outStream is the output stream
350 
351  Returns the deviation.
352  */
353 
355  const Vector<Real> &v,
356  const Vector<Real> &x,
357  const bool printToStream = true,
358  std::ostream & outStream = std::cout) {
359  return checkAdjointConsistencyJacobian(w, v, x, w.dual(), v.dual(), printToStream, outStream);
360  }
361 
362  virtual Real checkAdjointConsistencyJacobian(const Vector<Real> &w,
363  const Vector<Real> &v,
364  const Vector<Real> &x,
365  const Vector<Real> &dualw,
366  const Vector<Real> &dualv,
367  const bool printToStream = true,
368  std::ostream & outStream = std::cout);
369 
370 
376  virtual std::vector<std::vector<Real> > checkApplyAdjointHessian(const Vector<Real> &x,
377  const Vector<Real> &u,
378  const Vector<Real> &v,
379  const Vector<Real> &hv,
380  const std::vector<Real> &step,
381  const bool printToScreen = true,
382  std::ostream & outStream = std::cout,
383  const int order = 1 ) ;
389  virtual std::vector<std::vector<Real> > checkApplyAdjointHessian(const Vector<Real> &x,
390  const Vector<Real> &u,
391  const Vector<Real> &v,
392  const Vector<Real> &hv,
393  const bool printToScreen = true,
394  std::ostream & outStream = std::cout,
395  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
396  const int order = 1 ) ;
397 
398 // Definitions for parametrized (stochastic) constraints
399 private:
400  std::vector<Real> param_;
401 
402 protected:
403  const std::vector<Real> getParameter(void) const {
404  return param_;
405  }
406 
407 public:
408  virtual void setParameter(const std::vector<Real> &param) {
409  param_.assign(param.begin(),param.end());
410  }
411 
412 }; // class Constraint
413 
414 } // namespace ROL
415 
416 #include "ROL_ConstraintDef.hpp"
417 
418 #endif
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 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:226
virtual void applyJacobian(Vector< Real > &jv, const Vector< Real > &v, const Vector< Real > &x, Real &tol)
Apply the constraint Jacobian at , , to vector .
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...
virtual Real checkAdjointConsistencyJacobian(const Vector< Real > &w, const Vector< Real > &v, const Vector< Real > &x, const bool printToStream=true, std::ostream &outStream=std::cout)
virtual void update(const Vector< Real > &x, UpdateType type, int iter=-1)
Update constraint function.
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.
Contains definitions of custom data types in ROL.
void deactivate(void)
Turn off constraints.
const std::vector< Real > getParameter(void) const
void activate(void)
Turn on constraints.
Defines the linear algebra or vector space interface.
Definition: ROL_Vector.hpp:80
virtual void value(Vector< Real > &c, const Vector< Real > &x, Real &tol)=0
Evaluate the constraint operator at .
#define ROL_UNUSED(x)
Definition: ROL_Vector.hpp:48
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 ...
std::vector< Real > param_
virtual void setParameter(const std::vector< Real > &param)
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 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.
#define ROL_NUM_CHECKDERIV_STEPS
Number of steps for derivative checks.
Definition: ROL_Types.hpp:74
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 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...
bool isActivated(void)
Check if constraints are on.
virtual void set(const Vector &x)
Set where .
Definition: ROL_Vector.hpp:209
virtual ~Constraint(void)
Defines the general constraint operator interface.