10#ifndef ROL_TYPEG_ALGORITHM_DEF_H
11#define ROL_TYPEG_ALGORITHM_DEF_H
22template<
typename Real>
31template<
typename Real>
36 if (
state_->iterateVec == nullPtr) {
39 state_->iterateVec->set(x);
40 if (
state_->lagmultVec == nullPtr) {
43 state_->lagmultVec->set(mul);
44 if (
state_->stepVec == nullPtr) {
48 if (
state_->gradientVec == nullPtr) {
51 if (
state_->constraintVec == nullPtr) {
54 state_->constraintVec->zero();
55 state_->gradientVec->set(g);
56 if (
state_->minIterVec == nullPtr) {
59 state_->minIterVec->set(x);
64template<
typename Real>
66 const bool combineStatus) {
73template<
typename Real>
75 std::ostream &outStream ) {
93template<
typename Real>
99 std::ostream &outStream ) {
103 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
104 makePtrFromRef(emul));
105 problem.
finalize(
false,
false,outStream);
106 run(problem,outStream);
110template<
typename Real>
116 std::ostream &outStream ) {
119 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
120 makePtrFromRef(imul),makePtrFromRef(ibnd));
121 problem.
finalize(
false,
false,outStream);
122 run(problem,outStream);
126template<
typename Real>
133 std::ostream &outStream ) {
137 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
138 makePtrFromRef(imul),makePtrFromRef(ibnd));
139 problem.
finalize(
false,
false,outStream);
140 run(problem,outStream);
144template<
typename Real>
152 std::ostream &outStream ) {
155 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
156 makePtrFromRef(emul));
157 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
158 makePtrFromRef(imul),makePtrFromRef(ibnd));
159 problem.
finalize(
false,
false,outStream);
160 run(problem,outStream);
164template<
typename Real>
173 std::ostream &outStream ) {
177 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
178 makePtrFromRef(emul));
179 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
180 makePtrFromRef(imul),makePtrFromRef(ibnd));
181 problem.
finalize(
false,
false,outStream);
182 run(problem,outStream);
188template<
typename Real>
196 std::ostream &outStream ) {
197 Ptr<Vector<Real>> gp = g.
clone(), irp = ires.
clone();
199 makePtrFromRef(x),gp);
200 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
201 makePtrFromRef(imul),makePtrFromRef(ibnd),irp,
false);
202 problem.
finalize(
false,
false,outStream);
203 run(problem,outStream);
215template<
typename Real>
224 std::ostream &outStream ) {
225 Ptr<Vector<Real>> gp = g.
clone(), irp = ires.
clone();
227 makePtrFromRef(x),gp);
229 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
230 makePtrFromRef(imul),makePtrFromRef(ibnd),irp,
false);
231 problem.
finalize(
false,
false,outStream);
232 run(problem,outStream);
245template<
typename Real>
256 std::ostream &outStream ) {
257 Ptr<Vector<Real>> gp = g.
clone(), erp = eres.
clone(), irp = ires.
clone();
259 makePtrFromRef(x),gp);
260 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
261 makePtrFromRef(emul),erp,
false);
262 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
263 makePtrFromRef(imul),makePtrFromRef(ibnd),irp,
false);
264 problem.
finalize(
false,
false,outStream);
265 run(problem,outStream);
282template<
typename Real>
294 std::ostream &outStream ) {
295 Ptr<Vector<Real>> gp = g.
clone(), erp = eres.
clone(), irp = ires.
clone();
297 makePtrFromRef(x),gp);
299 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
300 makePtrFromRef(emul),erp,
false);
301 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
302 makePtrFromRef(imul),makePtrFromRef(ibnd),irp,
false);
303 problem.
finalize(
false,
false,outStream);
304 run(problem,outStream);
323template<
typename Real>
331 std::ostream &outStream ) {
335 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
336 makePtrFromRef(emul));
338 makePtrFromRef(linear_econ),
339 makePtrFromRef(linear_emul));
340 problem.
finalize(
false,
false,outStream);
341 run(problem,outStream);
346template<
typename Real>
354 std::ostream &outStream ) {
357 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
358 makePtrFromRef(imul),makePtrFromRef(ibnd));
360 makePtrFromRef(linear_econ),
361 makePtrFromRef(linear_emul));
362 problem.
finalize(
false,
false,outStream);
363 run(problem,outStream);
368template<
typename Real>
377 std::ostream &outStream ) {
381 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
382 makePtrFromRef(imul),makePtrFromRef(ibnd));
384 makePtrFromRef(linear_econ),
385 makePtrFromRef(linear_emul));
386 problem.
finalize(
false,
false,outStream);
387 run(problem,outStream);
392template<
typename Real>
402 std::ostream &outStream ) {
405 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
406 makePtrFromRef(emul));
407 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
408 makePtrFromRef(imul),makePtrFromRef(ibnd));
410 makePtrFromRef(linear_econ),
411 makePtrFromRef(linear_emul));
412 problem.
finalize(
false,
false,outStream);
413 run(problem,outStream);
418template<
typename Real>
429 std::ostream &outStream ) {
433 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
434 makePtrFromRef(emul));
435 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
436 makePtrFromRef(imul),makePtrFromRef(ibnd));
438 makePtrFromRef(linear_econ),
439 makePtrFromRef(linear_emul));
440 problem.
finalize(
false,
false,outStream);
441 run(problem,outStream);
448template<
typename Real>
459 std::ostream &outStream ) {
460 Ptr<Vector<Real>> gp = g.
clone(), erp = eres.
clone(), lerp = linear_eres.
clone();
462 makePtrFromRef(x),gp);
464 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
465 makePtrFromRef(emul),erp,
false);
467 makePtrFromRef(linear_econ),
468 makePtrFromRef(linear_emul),
470 problem.
finalize(
false,
false,outStream);
471 run(problem,outStream);
477template<
typename Real>
488 std::ostream &outStream ) {
489 Ptr<Vector<Real>> gp = g.
clone(), irp = ires.
clone(), lerp = linear_eres.
clone();
491 makePtrFromRef(x),gp);
492 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
493 makePtrFromRef(imul),makePtrFromRef(ibnd),
496 makePtrFromRef(linear_econ),
497 makePtrFromRef(linear_emul),
499 problem.
finalize(
false,
false,outStream);
500 run(problem,outStream);
511template<
typename Real>
523 std::ostream &outStream ) {
524 Ptr<Vector<Real>> gp = g.
clone(), irp = ires.
clone(), lerp = linear_eres.
clone();
526 makePtrFromRef(x),gp);
528 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
529 makePtrFromRef(imul),makePtrFromRef(ibnd),
532 makePtrFromRef(linear_econ),
533 makePtrFromRef(linear_emul),
535 problem.
finalize(
false,
false,outStream);
536 run(problem,outStream);
550template<
typename Real>
564 std::ostream &outStream ) {
565 Ptr<Vector<Real>> gp = g.
clone(), erp = eres.
clone(), irp = ires.
clone(), lerp = linear_eres.
clone();
567 makePtrFromRef(x),gp);
568 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
569 makePtrFromRef(emul),erp,
false);
570 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
571 makePtrFromRef(imul),makePtrFromRef(ibnd),
574 makePtrFromRef(linear_econ),
575 makePtrFromRef(linear_emul),
577 problem.
finalize(
false,
false,outStream);
578 run(problem,outStream);
590template<
typename Real>
605 std::ostream &outStream ) {
606 Ptr<Vector<Real>> gp = g.
clone(), erp = eres.
clone(), irp = ires.
clone(), lerp = linear_eres.
clone();
608 makePtrFromRef(x),gp);
610 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
611 makePtrFromRef(emul),erp,
false);
612 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
613 makePtrFromRef(imul),makePtrFromRef(ibnd),
616 makePtrFromRef(linear_econ),
617 makePtrFromRef(linear_emul),
619 problem.
finalize(
false,
false,outStream);
620 run(problem,outStream);
637template<
typename Real>
639 std::ios_base::fmtflags osFlags(os.flags());
641 os << std::setw(6) << std::left <<
"iter";
642 os << std::setw(15) << std::left <<
"value";
643 os << std::setw(15) << std::left <<
"gnorm";
644 os << std::setw(15) << std::left <<
"snorm";
645 os << std::setw(10) << std::left <<
"#fval";
646 os << std::setw(10) << std::left <<
"#grad";
651template<
typename Real>
656template<
typename Real>
658 std::ios_base::fmtflags osFlags(os.flags());
659 os << std::scientific << std::setprecision(6);
661 if (
state_->iter == 0 ) {
663 os << std::setw(6) << std::left <<
state_->iter;
664 os << std::setw(15) << std::left <<
state_->value;
665 os << std::setw(15) << std::left <<
state_->gnorm;
670 os << std::setw(6) << std::left <<
state_->iter;
671 os << std::setw(15) << std::left <<
state_->value;
672 os << std::setw(15) << std::left <<
state_->gnorm;
673 os << std::setw(15) << std::left <<
state_->snorm;
674 os << std::setw(10) << std::left <<
state_->nfval;
675 os << std::setw(10) << std::left <<
state_->ngrad;
681template<
typename Real>
683 std::ios_base::fmtflags osFlags(os.flags());
684 os <<
"Optimization Terminated with Status: ";
690template<
typename Real>
696template<
typename Real>
Provides the interface to apply upper and lower bound constraints.
Provides an interface to check two status tests of optimization algorithms.
Provides an interface to check status of optimization algorithms for problems with equality constrain...
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.
const Ptr< Vector< Real > > & getMultiplierVector()
Get the dual constraint space vector.
const Ptr< Constraint< Real > > & getConstraint()
Get the equality constraint.
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...
void addConstraint(std::string name, const Ptr< Constraint< Real > > &econ, const Ptr< Vector< Real > > &emul, const Ptr< Vector< Real > > &eres=nullPtr, bool reset=false)
Add an equality constraint.
const Ptr< Objective< Real > > & getObjective()
Get the objective function.
const Ptr< BoundConstraint< Real > > & getBoundConstraint()
Get the bound constraint.
const Ptr< Vector< Real > > & getResidualVector()
Get the primal constraint space vector.
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 general constrained problems (Type-G). This is the primary Type-G interface.
virtual void writeOutput(std::ostream &os, const bool write_header=false) const
Print iterate status.
virtual void writeName(std::ostream &os) const
Print step name.
Algorithm()
Constructor, given a step and a status test.
virtual void writeHeader(std::ostream &os) const
Print iterate header.
void initialize(const Vector< Real > &x, const Vector< Real > &g, const Vector< Real > &mul, const Vector< Real > &c)
Ptr< const AlgorithmState< Real > > getState() const
virtual void writeExitStatus(std::ostream &os) const
const Ptr< CombinedStatusTest< Real > > status_
Ptr< PolyhedralProjection< Real > > proj_
void setStatusTest(const Ptr< StatusTest< Real > > &status, bool combineStatus=false)
const Ptr< AlgorithmState< Real > > state_
Defines the linear algebra or vector space interface.
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
std::string EExitStatusToString(EExitStatus tr)