本文整理汇总了C++中BoundConstraint::setVectorToUpperBound方法的典型用法代码示例。如果您正苦于以下问题:C++ BoundConstraint::setVectorToUpperBound方法的具体用法?C++ BoundConstraint::setVectorToUpperBound怎么用?C++ BoundConstraint::setVectorToUpperBound使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BoundConstraint
的用法示例。
在下文中一共展示了BoundConstraint::setVectorToUpperBound方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compute
/** \brief Compute step.
Given \f$x_k\f$, this function first builds the
primal-dual active sets
\f$\mathcal{A}_k^-\f$ and \f$\mathcal{A}_k^+\f$.
Next, it uses CR to compute the inactive
components of the step by solving
\f[
\nabla^2 f(x_k)_{\mathcal{I}_k,\mathcal{I}_k}(s_k)_{\mathcal{I}_k} =
-\nabla f(x_k)_{\mathcal{I}_k}
-\nabla^2 f(x_k)_{\mathcal{I}_k,\mathcal{A}_k} (s_k)_{\mathcal{A}_k}.
\f]
Finally, it updates the active components of the
dual variables as
\f[
\lambda_{k+1} = -\nabla f(x_k)_{\mathcal{A}_k}
-(\nabla^2 f(x_k) s_k)_{\mathcal{A}_k}.
\f]
@param[out] s is the step computed via PDAS
@param[in] x is the current iterate
@param[in] obj is the objective function
@param[in] con are the bound constraints
@param[in] algo_state is the current state of the algorithm
*/
void compute( Vector<Real> &s, const Vector<Real> &x, Objective<Real> &obj, BoundConstraint<Real> &con,
AlgorithmState<Real> &algo_state ) {
Teuchos::RCP<StepState<Real> > step_state = Step<Real>::getState();
s.zero();
x0_->set(x);
res_->set(*(step_state->gradientVec));
for ( iter_ = 0; iter_ < maxit_; iter_++ ) {
/********************************************************************/
// MODIFY ITERATE VECTOR TO CHECK ACTIVE SET
/********************************************************************/
xlam_->set(*x0_); // xlam = x0
xlam_->axpy(scale_,*(lambda_)); // xlam = x0 + c*lambda
/********************************************************************/
// PROJECT x ONTO PRIMAL DUAL FEASIBLE SET
/********************************************************************/
As_->zero(); // As = 0
con.setVectorToUpperBound(*xbnd_); // xbnd = u
xbnd_->axpy(-1.0,x); // xbnd = u - x
xtmp_->set(*xbnd_); // tmp = u - x
con.pruneUpperActive(*xtmp_,*xlam_,neps_); // tmp = I(u - x)
xbnd_->axpy(-1.0,*xtmp_); // xbnd = A(u - x)
As_->plus(*xbnd_); // As += A(u - x)
con.setVectorToLowerBound(*xbnd_); // xbnd = l
xbnd_->axpy(-1.0,x); // xbnd = l - x
xtmp_->set(*xbnd_); // tmp = l - x
con.pruneLowerActive(*xtmp_,*xlam_,neps_); // tmp = I(l - x)
xbnd_->axpy(-1.0,*xtmp_); // xbnd = A(l - x)
As_->plus(*xbnd_); // As += A(l - x)
/********************************************************************/
// APPLY HESSIAN TO ACTIVE COMPONENTS OF s AND REMOVE INACTIVE
/********************************************************************/
itol_ = std::sqrt(ROL_EPSILON);
if ( useSecantHessVec_ && secant_ != Teuchos::null ) { // IHAs = H*As
secant_->applyB(*gtmp_,*As_,x);
}
else {
obj.hessVec(*gtmp_,*As_,x,itol_);
}
con.pruneActive(*gtmp_,*xlam_,neps_); // IHAs = I(H*As)
/********************************************************************/
// SEPARATE ACTIVE AND INACTIVE COMPONENTS OF THE GRADIENT
/********************************************************************/
rtmp_->set(*(step_state->gradientVec)); // Inactive components
con.pruneActive(*rtmp_,*xlam_,neps_);
Ag_->set(*(step_state->gradientVec)); // Active components
Ag_->axpy(-1.0,*rtmp_);
/********************************************************************/
// SOLVE REDUCED NEWTON SYSTEM
/********************************************************************/
rtmp_->plus(*gtmp_);
rtmp_->scale(-1.0); // rhs = -Ig - I(H*As)
s.zero();
if ( rtmp_->norm() > 0.0 ) {
//solve(s,*rtmp_,*xlam_,x,obj,con); // Call conjugate residuals
krylov_->run(s,*hessian_,*rtmp_,*precond_,iterCR_,flagCR_);
con.pruneActive(s,*xlam_,neps_); // s <- Is
}
s.plus(*As_); // s = Is + As
/********************************************************************/
// UPDATE MULTIPLIER
/********************************************************************/
if ( useSecantHessVec_ && secant_ != Teuchos::null ) {
secant_->applyB(*rtmp_,s,x);
}
else {
obj.hessVec(*rtmp_,s,x,itol_);
}
gtmp_->set(*rtmp_);
con.pruneActive(*gtmp_,*xlam_,neps_);
lambda_->set(*rtmp_);
lambda_->axpy(-1.0,*gtmp_);
lambda_->plus(*Ag_);
//.........这里部分代码省略.........