44 #ifndef ROL_TYPEB_ALGORITHM_DEF_H
45 #define ROL_TYPEB_ALGORITHM_DEF_H
53 template<
typename Real>
62 template<
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;
84 template<
typename Real>
88 std::ostream &outStream)
const {
92 proj_->project(primal,outStream); state_->nproj++;
97 template<
typename Real>
100 if (!combineStatus) {
103 status_->add(status);
106 template<
typename Real>
108 std::ostream &outStream ) {
123 template<
typename Real>
127 std::ostream &outStream ) {
128 run(x,x.
dual(),obj,bnd,outStream);
131 template<
typename Real>
137 std::ostream &outStream ) {
138 run(x,x.
dual(),obj,bnd,linear_econ,linear_emul,linear_emul.
dual(),outStream);
141 template<
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);
155 template<
typename Real>
162 std::ostream &outStream ) {
163 run(x,x.
dual(),obj,bnd,linear_icon,linear_imul,linear_ibnd,linear_imul.dual(),outStream);
166 template<
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);
199 template<
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);
213 template<
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);
259 template<
typename Real>
261 std::ios_base::fmtflags osFlags(os.flags());
263 os << std::setw(6) << std::left <<
"iter";
264 os << std::setw(15) << std::left <<
"value";
265 os << std::setw(15) << std::left <<
"gnorm";
266 os << std::setw(15) << std::left <<
"snorm";
267 os << std::setw(10) << std::left <<
"#fval";
268 os << std::setw(10) << std::left <<
"#grad";
273 template<
typename Real>
278 template<
typename Real>
280 std::ios_base::fmtflags osFlags(os.flags());
281 os << std::scientific << std::setprecision(6);
282 if ( write_header ) writeHeader(os);
283 if ( state_->iter == 0 ) {
285 os << std::setw(6) << std::left << state_->iter;
286 os << std::setw(15) << std::left << state_->value;
287 os << std::setw(15) << std::left << state_->gnorm;
292 os << std::setw(6) << std::left << state_->iter;
293 os << std::setw(15) << std::left << state_->value;
294 os << std::setw(15) << std::left << state_->gnorm;
295 os << std::setw(15) << std::left << state_->snorm;
296 os << std::setw(10) << std::left << state_->nfval;
297 os << std::setw(10) << std::left << state_->ngrad;
303 template<
typename Real>
305 std::ios_base::fmtflags osFlags(os.flags());
306 os <<
"Optimization Terminated with Status: ";
312 template<
typename Real>
318 template<
typename Real>
Provides the interface to evaluate objective functions.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
const Ptr< Vector< Real > > & getPrimalOptimizationVector()
Get the primal optimization space vector.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
void addBoundConstraint(const Ptr< BoundConstraint< Real >> &bnd)
Add a bound constraint.
virtual void writeHeader(std::ostream &os) const
Print iterate header.
virtual void axpy(const Real alpha, const Vector &x)
Compute where .
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.
const Ptr< BoundConstraint< Real > > & getBoundConstraint()
Get the bound constraint.
virtual void writeExitStatus(std::ostream &os) const
void setStatusTest(const Ptr< StatusTest< Real >> &status, const bool combineStatus=false)
Defines the linear algebra or vector space interface.
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...
virtual void writeName(std::ostream &os) const
Print step name.
std::string EExitStatusToString(EExitStatus tr)
const Ptr< Objective< Real > > & getObjective()
Get the objective function.
void finalizeIteration()
Transform the optimization variables to the native parameterization after an optimization algorithm h...
Provides an interface to check status of optimization algorithms.
Algorithm()
Constructor, given a step and a status test.
virtual void writeOutput(std::ostream &os, const bool write_header=false) const
Print iterate status.
Provides the interface to apply upper and lower bound constraints.
Real optimalityCriterion(const Vector< Real > &x, const Vector< Real > &g, Vector< Real > &primal, std::ostream &outStream=std::cout) const
const Ptr< PolyhedralProjection< Real > > & getPolyhedralProjection()
Get the polyhedral projection object. This is a null pointer if no linear constraints and/or bounds a...
EProblem getProblemType()
Get the optimization problem type (U, B, E, or G).
void initialize(const Vector< Real > &x, const Vector< Real > &g)
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.
virtual void set(const Vector &x)
Set where .
virtual Real norm() const =0
Returns where .
Provides an interface to check two status tests of optimization algorithms.
const Ptr< Vector< Real > > & getDualOptimizationVector()
Get the dual optimization space vector.
Defines the general constraint operator interface.
Ptr< const AlgorithmState< Real > > getState() const
const Ptr< CombinedStatusTest< Real > > status_