44#ifndef ROL_TYPEU_ALGORITHM_DEF_H
45#define ROL_TYPEU_ALGORITHM_DEF_H
54template<
typename Real>
57 state_(makePtr<AlgorithmState<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>
93template<
typename Real>
95 std::ostream &outStream ) {
96 if (problem.getProblemType() == TYPE_U) {
97 run(*problem.getPrimalOptimizationVector(),
98 *problem.getDualOptimizationVector(),
99 *problem.getObjective(),
101 problem.finalizeIteration();
104 throw Exception::NotImplemented(
">>> ROL::TypeU::Algorithm::run : Optimization problem is not Type U!");
108template<
typename Real>
110 Objective<Real> &obj,
111 std::ostream &outStream ) {
112 run(x,x.dual(),obj,outStream);
115template<
typename Real>
117 Objective<Real> &obj,
118 Constraint<Real> &linear_con,
119 Vector<Real> &linear_mul,
120 std::ostream &outStream ) {
121 run(x,x.dual(),obj,linear_con,linear_mul,linear_mul.dual(),outStream);
124template<
typename Real>
126 const Vector<Real> &g,
127 Objective<Real> &obj,
128 Constraint<Real> &linear_con,
129 Vector<Real> &linear_mul,
130 const Vector<Real> &linear_c,
131 std::ostream &outStream ) {
132 Ptr<Vector<Real>> xfeas = x.clone(); xfeas->set(x);
133 ReduceLinearConstraint<Real> rlc(makePtrFromRef(linear_con),xfeas,makePtrFromRef(linear_c));
134 Ptr<Vector<Real>> s = x.clone(); s->zero();
136 run(*s,g,*rlc.transform(makePtrFromRef(obj)),outStream);
138 x.plus(*rlc.getFeasibleVector());
141template<
typename Real>
143 std::stringstream hist;
145 hist << std::setw(6) << std::left <<
"iter";
146 hist << std::setw(15) << std::left <<
"value";
147 hist << std::setw(15) << std::left <<
"gnorm";
148 hist << std::setw(15) << std::left <<
"snorm";
149 hist << std::setw(10) << std::left <<
"#fval";
150 hist << std::setw(10) << std::left <<
"#grad";
155template<
typename Real>
157 throw Exception::NotImplemented(
">>> ROL::TypeU::Algorithm::writeName() is not implemented!");
160template<
typename Real>
162 std::stringstream hist;
163 hist << std::scientific << std::setprecision(6);
164 if ( write_header ) writeHeader(os);
165 if ( state_->iter == 0 ) {
167 hist << std::setw(6) << std::left << state_->iter;
168 hist << std::setw(15) << std::left << state_->value;
169 hist << std::setw(15) << std::left << state_->gnorm;
174 hist << std::setw(6) << std::left << state_->iter;
175 hist << std::setw(15) << std::left << state_->value;
176 hist << std::setw(15) << std::left << state_->gnorm;
177 hist << std::setw(15) << std::left << state_->snorm;
178 hist << std::setw(10) << std::left << state_->nfval;
179 hist << std::setw(10) << std::left << state_->ngrad;
185template<
typename Real>
187 std::stringstream hist;
188 hist <<
"Optimization Terminated with Status: ";
194template<
typename Real>
200template<
typename Real>
Contains definitions of custom data types in ROL.
Provides an interface to run optimization algorithms.
virtual std::vector< std::string > run(Vector< Real > &x, Objective< Real > &obj, bool print=false, std::ostream &outStream=std::cout, bool printVectors=false, std::ostream &vectorStream=std::cout)
Run algorithm on unconstrained problems (Type-U). This is the primary Type-U interface.
ROL::Ptr< const AlgorithmState< Real > > getState(void) const
Provides an interface to check two status tests of optimization algorithms.
Provides an interface to check status of optimization algorithms.
Algorithm()
Constructor, given a step and a status test.
std::string EExitStatusToString(EExitStatus tr)