44#ifndef ROL_TYPEB_ALGORITHM_DEF_H
45#define ROL_TYPEB_ALGORITHM_DEF_H
53template<
typename Real>
62template<
typename Real>
64 if (state_->iterateVec == nullPtr) {
65 state_->iterateVec = x.
clone();
67 state_->iterateVec->set(x);
68 if (state_->stepVec == nullPtr) {
69 state_->stepVec = x.
clone();
71 state_->stepVec->zero();
72 if (state_->gradientVec == nullPtr) {
73 state_->gradientVec = g.
clone();
75 state_->gradientVec->set(g);
76 if (state_->minIterVec == nullPtr) {
77 state_->minIterVec = x.
clone();
79 state_->minIterVec->set(x);
80 state_->minIter = state_->iter;
81 state_->minValue = state_->value;
84template<
typename Real>
88 std::ostream &outStream)
const {
92 proj_->project(primal,outStream); state_->nproj++;
97template<
typename Real>
100 if (!combineStatus) {
103 status_->add(status);
106template<
typename Real>
108 std::ostream &outStream ) {
123template<
typename Real>
127 std::ostream &outStream ) {
128 run(x,x.
dual(),obj,bnd,outStream);
131template<
typename Real>
137 std::ostream &outStream ) {
138 run(x,x.
dual(),obj,bnd,linear_econ,linear_emul,linear_emul.
dual(),outStream);
141template<
typename Real>
149 std::ostream &outStream ) {
150 ParameterList parlist;
151 proj_ = PolyhedralProjectionFactory<Real>(x,g,makePtrFromRef(bnd),makePtrFromRef(linear_econ),linear_emul,linear_eres,parlist);
152 run(x,g,obj,bnd,outStream);
155template<
typename Real>
162 std::ostream &outStream ) {
163 run(x,x.
dual(),obj,bnd,linear_icon,linear_imul,linear_ibnd,linear_imul.
dual(),outStream);
166template<
typename Real>
175 std::ostream &outStream ) {
176 Ptr<Vector<Real>> gp = g.
clone(), irp = linear_ires.
clone();
178 makePtrFromRef(x),gp);
181 makePtrFromRef(linear_icon),
182 makePtrFromRef(linear_imul),
183 makePtrFromRef(linear_ibnd),irp);
184 problem.
finalize(
false,
false,outStream);
185 run(problem,outStream);
199template<
typename Real>
208 std::ostream &outStream ) {
209 run(x,x.
dual(),obj,bnd,linear_econ,linear_emul,linear_emul.
dual(),
210 linear_icon,linear_imul,linear_ibnd,linear_imul.
dual(),outStream);
213template<
typename Real>
225 std::ostream &outStream ) {
226 Ptr<Vector<Real>> gp = g.
clone(), erp = linear_eres.
clone(), irp = linear_ires.
clone();
228 makePtrFromRef(x),gp);
231 makePtrFromRef(linear_econ),
232 makePtrFromRef(linear_emul),erp);
234 makePtrFromRef(linear_icon),
235 makePtrFromRef(linear_imul),
236 makePtrFromRef(linear_ibnd),irp);
237 problem.
finalize(
false,
false,outStream);
238 run(problem,outStream);
259template<
typename Real>
261 std::stringstream hist;
263 hist << std::setw(6) << std::left <<
"iter";
264 hist << std::setw(15) << std::left <<
"value";
265 hist << std::setw(15) << std::left <<
"gnorm";
266 hist << std::setw(15) << std::left <<
"snorm";
267 hist << std::setw(10) << std::left <<
"#fval";
268 hist << std::setw(10) << std::left <<
"#grad";
273template<
typename Real>
278template<
typename Real>
280 std::stringstream hist;
281 hist << std::scientific << std::setprecision(6);
282 if ( write_header ) writeHeader(os);
283 if ( state_->iter == 0 ) {
285 hist << std::setw(6) << std::left << state_->iter;
286 hist << std::setw(15) << std::left << state_->value;
287 hist << std::setw(15) << std::left << state_->gnorm;
292 hist << std::setw(6) << std::left << state_->iter;
293 hist << std::setw(15) << std::left << state_->value;
294 hist << std::setw(15) << std::left << state_->gnorm;
295 hist << std::setw(15) << std::left << state_->snorm;
296 hist << std::setw(10) << std::left << state_->nfval;
297 hist << std::setw(10) << std::left << state_->ngrad;
303template<
typename Real>
305 std::stringstream hist;
306 hist <<
"Optimization Terminated with Status: ";
312template<
typename Real>
318template<
typename Real>
Provides the interface to apply upper and lower bound constraints.
Provides an interface to check two status tests of optimization algorithms.
Defines the general constraint operator interface.
Provides the interface to evaluate objective functions.
const Ptr< PolyhedralProjection< Real > > & getPolyhedralProjection()
Get the polyhedral projection object. This is a null pointer if no linear constraints and/or bounds a...
const Ptr< Vector< Real > > & getPrimalOptimizationVector()
Get the primal optimization space vector.
const Ptr< Vector< Real > > & getDualOptimizationVector()
Get the dual optimization space vector.
EProblem getProblemType()
Get the optimization problem type (U, B, E, or G).
void addLinearConstraint(std::string name, const Ptr< Constraint< Real > > &linear_econ, const Ptr< Vector< Real > > &linear_emul, const Ptr< Vector< Real > > &linear_eres=nullPtr, bool reset=false)
Add a linear equality constraint.
void addBoundConstraint(const Ptr< BoundConstraint< Real > > &bnd)
Add a bound constraint.
void finalizeIteration()
Transform the optimization variables to the native parameterization after an optimization algorithm h...
const Ptr< Objective< Real > > & getObjective()
Get the objective function.
const Ptr< BoundConstraint< Real > > & getBoundConstraint()
Get the bound constraint.
virtual void finalize(bool lumpConstraints=false, bool printToStream=false, std::ostream &outStream=std::cout)
Tranform user-supplied constraints to consist of only bounds and equalities. Optimization problem can...
Provides an interface to check status of optimization algorithms.
virtual void run(Problem< Real > &problem, std::ostream &outStream=std::cout)
Run algorithm on bound constrained problems (Type-B). This is the primary Type-B interface.
void initialize(const Vector< Real > &x, const Vector< Real > &g)
virtual void writeHeader(std::ostream &os) const
Print iterate header.
Real optimalityCriterion(const Vector< Real > &x, const Vector< Real > &g, Vector< Real > &primal, std::ostream &outStream=std::cout) const
Algorithm()
Constructor, given a step and a status test.
virtual void writeExitStatus(std::ostream &os) const
virtual void writeOutput(std::ostream &os, bool write_header=false) const
Print iterate status.
virtual void writeName(std::ostream &os) const
Print step name.
const Ptr< CombinedStatusTest< Real > > status_
Ptr< const AlgorithmState< Real > > getState() const
void setStatusTest(const Ptr< StatusTest< Real > > &status, const bool combineStatus=false)
Defines the linear algebra or vector space interface.
virtual Real norm() const =0
Returns where .
virtual void set(const Vector &x)
Set where .
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis,...
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
std::string EExitStatusToString(EExitStatus tr)