44 #ifndef ROL_TYPEG_ALGORITHM_DEF_H
45 #define ROL_TYPEG_ALGORITHM_DEF_H
56 template<
typename Real>
65 template<
typename Real>
70 if (state_->iterateVec == nullPtr) {
71 state_->iterateVec = x.
clone();
73 state_->iterateVec->set(x);
74 if (state_->lagmultVec == nullPtr) {
75 state_->lagmultVec = mul.
clone();
77 state_->lagmultVec->set(mul);
78 if (state_->stepVec == nullPtr) {
79 state_->stepVec = x.
clone();
81 state_->stepVec->zero();
82 if (state_->gradientVec == nullPtr) {
83 state_->gradientVec = g.
clone();
85 if (state_->constraintVec == nullPtr) {
86 state_->constraintVec = c.
clone();
88 state_->constraintVec->zero();
89 state_->gradientVec->set(g);
90 if (state_->minIterVec == nullPtr) {
91 state_->minIterVec = x.
clone();
93 state_->minIterVec->set(x);
94 state_->minIter = state_->iter;
95 state_->minValue = state_->value;
98 template<
typename Real>
100 const bool combineStatus) {
101 if (!combineStatus) {
104 status_->add(status);
107 template<
typename Real>
109 std::ostream &outStream ) {
127 template<
typename Real>
133 std::ostream &outStream ) {
137 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
138 makePtrFromRef(emul));
139 problem.
finalize(
false,
false,outStream);
140 run(problem,outStream);
144 template<
typename Real>
150 std::ostream &outStream ) {
153 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
154 makePtrFromRef(imul),makePtrFromRef(ibnd));
155 problem.
finalize(
false,
false,outStream);
156 run(problem,outStream);
160 template<
typename Real>
167 std::ostream &outStream ) {
171 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
172 makePtrFromRef(imul),makePtrFromRef(ibnd));
173 problem.
finalize(
false,
false,outStream);
174 run(problem,outStream);
178 template<
typename Real>
186 std::ostream &outStream ) {
189 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
190 makePtrFromRef(emul));
191 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
192 makePtrFromRef(imul),makePtrFromRef(ibnd));
193 problem.
finalize(
false,
false,outStream);
194 run(problem,outStream);
198 template<
typename Real>
207 std::ostream &outStream ) {
211 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
212 makePtrFromRef(emul));
213 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
214 makePtrFromRef(imul),makePtrFromRef(ibnd));
215 problem.
finalize(
false,
false,outStream);
216 run(problem,outStream);
222 template<
typename Real>
230 std::ostream &outStream ) {
231 Ptr<Vector<Real>> gp = g.
clone(), irp = ires.
clone();
233 makePtrFromRef(x),gp);
234 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
235 makePtrFromRef(imul),makePtrFromRef(ibnd),irp,
false);
236 problem.
finalize(
false,
false,outStream);
237 run(problem,outStream);
249 template<
typename Real>
258 std::ostream &outStream ) {
259 Ptr<Vector<Real>> gp = g.
clone(), irp = ires.
clone();
261 makePtrFromRef(x),gp);
263 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
264 makePtrFromRef(imul),makePtrFromRef(ibnd),irp,
false);
265 problem.
finalize(
false,
false,outStream);
266 run(problem,outStream);
279 template<
typename Real>
290 std::ostream &outStream ) {
291 Ptr<Vector<Real>> gp = g.
clone(), erp = eres.
clone(), irp = ires.
clone();
293 makePtrFromRef(x),gp);
294 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
295 makePtrFromRef(emul),erp,
false);
296 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
297 makePtrFromRef(imul),makePtrFromRef(ibnd),irp,
false);
298 problem.
finalize(
false,
false,outStream);
299 run(problem,outStream);
316 template<
typename Real>
328 std::ostream &outStream ) {
329 Ptr<Vector<Real>> gp = g.
clone(), erp = eres.
clone(), irp = ires.
clone();
331 makePtrFromRef(x),gp);
333 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
334 makePtrFromRef(emul),erp,
false);
335 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
336 makePtrFromRef(imul),makePtrFromRef(ibnd),irp,
false);
337 problem.
finalize(
false,
false,outStream);
338 run(problem,outStream);
357 template<
typename Real>
365 std::ostream &outStream ) {
369 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
370 makePtrFromRef(emul));
372 makePtrFromRef(linear_econ),
373 makePtrFromRef(linear_emul));
374 problem.
finalize(
false,
false,outStream);
375 run(problem,outStream);
380 template<
typename Real>
388 std::ostream &outStream ) {
391 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
392 makePtrFromRef(imul),makePtrFromRef(ibnd));
394 makePtrFromRef(linear_econ),
395 makePtrFromRef(linear_emul));
396 problem.
finalize(
false,
false,outStream);
397 run(problem,outStream);
402 template<
typename Real>
411 std::ostream &outStream ) {
415 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
416 makePtrFromRef(imul),makePtrFromRef(ibnd));
418 makePtrFromRef(linear_econ),
419 makePtrFromRef(linear_emul));
420 problem.
finalize(
false,
false,outStream);
421 run(problem,outStream);
426 template<
typename Real>
436 std::ostream &outStream ) {
439 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
440 makePtrFromRef(emul));
441 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
442 makePtrFromRef(imul),makePtrFromRef(ibnd));
444 makePtrFromRef(linear_econ),
445 makePtrFromRef(linear_emul));
446 problem.
finalize(
false,
false,outStream);
447 run(problem,outStream);
452 template<
typename Real>
463 std::ostream &outStream ) {
467 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
468 makePtrFromRef(emul));
469 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
470 makePtrFromRef(imul),makePtrFromRef(ibnd));
472 makePtrFromRef(linear_econ),
473 makePtrFromRef(linear_emul));
474 problem.
finalize(
false,
false,outStream);
475 run(problem,outStream);
482 template<
typename Real>
493 std::ostream &outStream ) {
494 Ptr<Vector<Real>> gp = g.
clone(), erp = eres.
clone(), lerp = linear_eres.
clone();
496 makePtrFromRef(x),gp);
498 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
499 makePtrFromRef(emul),erp,
false);
501 makePtrFromRef(linear_econ),
502 makePtrFromRef(linear_emul),
504 problem.
finalize(
false,
false,outStream);
505 run(problem,outStream);
511 template<
typename Real>
522 std::ostream &outStream ) {
523 Ptr<Vector<Real>> gp = g.
clone(), irp = ires.
clone(), lerp = linear_eres.
clone();
525 makePtrFromRef(x),gp);
526 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
527 makePtrFromRef(imul),makePtrFromRef(ibnd),
530 makePtrFromRef(linear_econ),
531 makePtrFromRef(linear_emul),
533 problem.
finalize(
false,
false,outStream);
534 run(problem,outStream);
545 template<
typename Real>
557 std::ostream &outStream ) {
558 Ptr<Vector<Real>> gp = g.
clone(), irp = ires.
clone(), lerp = linear_eres.
clone();
560 makePtrFromRef(x),gp);
562 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
563 makePtrFromRef(imul),makePtrFromRef(ibnd),
566 makePtrFromRef(linear_econ),
567 makePtrFromRef(linear_emul),
569 problem.
finalize(
false,
false,outStream);
570 run(problem,outStream);
584 template<
typename Real>
598 std::ostream &outStream ) {
599 Ptr<Vector<Real>> gp = g.
clone(), erp = eres.
clone(), irp = ires.
clone(), lerp = linear_eres.
clone();
601 makePtrFromRef(x),gp);
602 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
603 makePtrFromRef(emul),erp,
false);
604 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
605 makePtrFromRef(imul),makePtrFromRef(ibnd),
608 makePtrFromRef(linear_econ),
609 makePtrFromRef(linear_emul),
611 problem.
finalize(
false,
false,outStream);
612 run(problem,outStream);
624 template<
typename Real>
639 std::ostream &outStream ) {
640 Ptr<Vector<Real>> gp = g.
clone(), erp = eres.
clone(), irp = ires.
clone(), lerp = linear_eres.
clone();
642 makePtrFromRef(x),gp);
644 problem.
addConstraint(
"EqualityConstraint",makePtrFromRef(econ),
645 makePtrFromRef(emul),erp,
false);
646 problem.
addConstraint(
"InequalityConstraint",makePtrFromRef(icon),
647 makePtrFromRef(imul),makePtrFromRef(ibnd),
650 makePtrFromRef(linear_econ),
651 makePtrFromRef(linear_emul),
653 problem.
finalize(
false,
false,outStream);
654 run(problem,outStream);
671 template<
typename Real>
673 std::ios_base::fmtflags osFlags(os.flags());
675 os << std::setw(6) << std::left <<
"iter";
676 os << std::setw(15) << std::left <<
"value";
677 os << std::setw(15) << std::left <<
"gnorm";
678 os << std::setw(15) << std::left <<
"snorm";
679 os << std::setw(10) << std::left <<
"#fval";
680 os << std::setw(10) << std::left <<
"#grad";
685 template<
typename Real>
690 template<
typename Real>
692 std::ios_base::fmtflags osFlags(os.flags());
693 os << std::scientific << std::setprecision(6);
694 if ( write_header ) writeHeader(os);
695 if ( state_->iter == 0 ) {
697 os << std::setw(6) << std::left << state_->iter;
698 os << std::setw(15) << std::left << state_->value;
699 os << std::setw(15) << std::left << state_->gnorm;
704 os << std::setw(6) << std::left << state_->iter;
705 os << std::setw(15) << std::left << state_->value;
706 os << std::setw(15) << std::left << state_->gnorm;
707 os << std::setw(15) << std::left << state_->snorm;
708 os << std::setw(10) << std::left << state_->nfval;
709 os << std::setw(10) << std::left << state_->ngrad;
715 template<
typename Real>
717 std::ios_base::fmtflags osFlags(os.flags());
718 os <<
"Optimization Terminated with Status: ";
724 template<
typename Real>
730 template<
typename Real>
Provides the interface to evaluate objective functions.
const Ptr< Constraint< Real > > & getConstraint()
Get the equality constraint.
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 writeExitStatus(std::ostream &os) const
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.
virtual void writeOutput(std::ostream &os, const bool write_header=false) const
Print iterate status.
const Ptr< BoundConstraint< Real > > & getBoundConstraint()
Get the bound constraint.
virtual void writeHeader(std::ostream &os) const
Print iterate header.
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...
Provides an interface to check status of optimization algorithms for problems with equality constrain...
std::string EExitStatusToString(EExitStatus tr)
const Ptr< Objective< Real > > & getObjective()
Get the objective function.
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...
const Ptr< Vector< Real > > & getResidualVector()
Get the primal constraint space vector.
const Ptr< Vector< Real > > & getMultiplierVector()
Get the dual constraint space vector.
void finalizeIteration()
Transform the optimization variables to the native parameterization after an optimization algorithm h...
Provides an interface to check status of optimization algorithms.
Ptr< const AlgorithmState< Real > > getState() const
void setStatusTest(const Ptr< StatusTest< Real >> &status, bool combineStatus=false)
Provides the interface to apply upper and lower bound constraints.
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< 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).
virtual void writeName(std::ostream &os) const
Print step name.
Provides an interface to check two status tests of optimization algorithms.
const Ptr< CombinedStatusTest< Real > > status_
const Ptr< Vector< Real > > & getDualOptimizationVector()
Get the dual optimization space vector.
Algorithm()
Constructor, given a step and a status test.
void initialize(const Vector< Real > &x, const Vector< Real > &g, const Vector< Real > &mul, const Vector< Real > &c)
Defines the general constraint operator interface.