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_Types.hpp"
49 #include <iostream>
50 
82 namespace ROL {
83 
84 template <class Real>
85 class Constraint {
86 private:
87  bool activated_;
88 
89 public:
90  virtual ~Constraint(void) {}
91 
92  Constraint(void) : activated_(true) {}
93 
99  virtual void update( const Vector<Real> &x, bool flag = true, int iter = -1 ) {}
100 
113  virtual void value(Vector<Real> &c,
114  const Vector<Real> &x,
115  Real &tol) = 0;
116 
117 
132  virtual void applyJacobian(Vector<Real> &jv,
133  const Vector<Real> &v,
134  const Vector<Real> &x,
135  Real &tol);
136 
137 
152  virtual void applyAdjointJacobian(Vector<Real> &ajv,
153  const Vector<Real> &v,
154  const Vector<Real> &x,
155  Real &tol);
156 
157 
174  virtual void applyAdjointJacobian(Vector<Real> &ajv,
175  const Vector<Real> &v,
176  const Vector<Real> &x,
177  const Vector<Real> &dualv,
178  Real &tol);
179 
180 
197  virtual void applyAdjointHessian(Vector<Real> &ahuv,
198  const Vector<Real> &u,
199  const Vector<Real> &v,
200  const Vector<Real> &x,
201  Real &tol);
202 
203 
242  virtual std::vector<Real> solveAugmentedSystem(Vector<Real> &v1,
243  Vector<Real> &v2,
244  const Vector<Real> &b1,
245  const Vector<Real> &b2,
246  const Vector<Real> &x,
247  Real &tol);
248 
249 
270  const Vector<Real> &v,
271  const Vector<Real> &x,
272  const Vector<Real> &g,
273  Real &tol) {
274  pv.set(v.dual());
275  }
276 
279  void activate(void) { activated_ = true; }
280 
283  void deactivate(void) { activated_ = false; }
284 
287  bool isActivated(void) { return activated_; }
288 
293  virtual std::vector<std::vector<Real> > checkApplyJacobian( const Vector<Real> &x,
294  const Vector<Real> &v,
295  const Vector<Real> &jv,
296  const std::vector<Real> &steps,
297  const bool printToStream = true,
298  std::ostream & outStream = std::cout,
299  const int order = 1 ) ;
300 
301 
307  virtual std::vector<std::vector<Real> > checkApplyJacobian( const Vector<Real> &x,
308  const Vector<Real> &v,
309  const Vector<Real> &jv,
310  const bool printToStream = true,
311  std::ostream & outStream = std::cout,
312  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
313  const int order = 1 ) ;
314 
320  virtual std::vector<std::vector<Real> > checkApplyAdjointJacobian(const Vector<Real> &x,
321  const Vector<Real> &v,
322  const Vector<Real> &c,
323  const Vector<Real> &ajv,
324  const bool printToStream = true,
325  std::ostream & outStream = std::cout,
326  const int numSteps = ROL_NUM_CHECKDERIV_STEPS ) ;
327 
328  /* \brief Check the consistency of the Jacobian and its adjoint. Verify that the deviation
329  \f$|\langle w^\top,Jv\rangle-\langle adj(J)w,v|\f$ is sufficiently small.
330 
331  @param[in] w is a dual constraint-space vector \f$w\in \mathcal{C}^\ast\f$
332  @param[in] v is an optimization space vector \f$v\in \mathcal{X}\f$
333  @param[in] x is the constraint argument \f$x\in\mathcal{X}\f$
334  @param[in] printToStream is is a flag that turns on/off output
335  @param[in] outStream is the output stream
336 
337  Returns the deviation.
338  */
339 
341  const Vector<Real> &v,
342  const Vector<Real> &x,
343  const bool printToStream = true,
344  std::ostream & outStream = std::cout) {
345  return checkAdjointConsistencyJacobian(w, v, x, w.dual(), v.dual(), printToStream, outStream);
346  }
347 
348  virtual Real checkAdjointConsistencyJacobian(const Vector<Real> &w,
349  const Vector<Real> &v,
350  const Vector<Real> &x,
351  const Vector<Real> &dualw,
352  const Vector<Real> &dualv,
353  const bool printToStream = true,
354  std::ostream & outStream = std::cout);
355 
356 
362  virtual std::vector<std::vector<Real> > checkApplyAdjointHessian(const Vector<Real> &x,
363  const Vector<Real> &u,
364  const Vector<Real> &v,
365  const Vector<Real> &hv,
366  const std::vector<Real> &step,
367  const bool printToScreen = true,
368  std::ostream & outStream = std::cout,
369  const int order = 1 ) ;
375  virtual std::vector<std::vector<Real> > checkApplyAdjointHessian(const Vector<Real> &x,
376  const Vector<Real> &u,
377  const Vector<Real> &v,
378  const Vector<Real> &hv,
379  const bool printToScreen = true,
380  std::ostream & outStream = std::cout,
381  const int numSteps = ROL_NUM_CHECKDERIV_STEPS,
382  const int order = 1 ) ;
383 
384 // Definitions for parametrized (stochastic) constraints
385 private:
386  std::vector<Real> param_;
387 
388 protected:
389  const std::vector<Real> getParameter(void) const {
390  return param_;
391  }
392 
393 public:
394  virtual void setParameter(const std::vector<Real> &param) {
395  param_.assign(param.begin(),param.end());
396  }
397 
398 }; // class Constraint
399 
400 } // namespace ROL
401 
402 #include "ROL_ConstraintDef.hpp"
403 
404 #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 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 .
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.