44#ifndef ROL_ALGORITHM_H
45#define ROL_ALGORITHM_H
67 ROL::Ptr<AlgorithmState<Real> >
state_;
79 bool printHeader =
false ) {
82 state_ = ROL::makePtr<AlgorithmState<Real>>();
83 printHeader_ = printHeader;
91 const ROL::Ptr<AlgorithmState<Real> > & state,
92 bool printHeader =
false ) {
96 printHeader_ = printHeader;
102 virtual std::vector<std::string>
run( Vector<Real> &x,
103 Objective<Real> &obj,
105 std::ostream &outStream = std::cout,
106 bool printVectors =
false,
107 std::ostream &vectorStream = std::cout ) {
108 BoundConstraint<Real> bnd;
110 return run(x,x.dual(),obj,bnd,print,outStream,printVectors,vectorStream);
117 virtual std::vector<std::string>
run( Vector<Real> &x,
118 const Vector<Real> &g,
119 Objective<Real> &obj,
121 std::ostream &outStream = std::cout,
122 bool printVectors =
false,
123 std::ostream &vectorStream = std::cout ) {
124 BoundConstraint<Real> bnd;
126 return run(x,g,obj,bnd,print,outStream,printVectors,vectorStream);
132 virtual std::vector<std::string>
run( Vector<Real> &x,
133 Objective<Real> &obj,
134 BoundConstraint<Real> &bnd,
136 std::ostream &outStream = std::cout,
137 bool printVectors =
false,
138 std::ostream &vectorStream = std::cout ) {
139 return run(x,x.dual(),obj,bnd,print,outStream,printVectors,vectorStream);
146 virtual std::vector<std::string>
run( Vector<Real> &x,
147 const Vector<Real> &g,
148 Objective<Real> &obj,
149 BoundConstraint<Real> &bnd,
151 std::ostream &outStream = std::cout,
152 bool printVectors =
false,
153 std::ostream &vectorStream = std::cout ) {
155 x.print(vectorStream);
158 std::vector<std::string> output;
161 if ( state_->iterateVec == ROL::nullPtr ) {
162 state_->iterateVec = x.clone();
164 state_->iterateVec->set(x);
167 ROL::Ptr<Vector<Real> > s = x.clone();
170 step_->initialize(x, g, obj, bnd, *state_);
171 output.push_back(step_->print(*state_,
true));
173 outStream << step_->print(*state_,
true);
177 if ( state_->minIterVec == ROL::nullPtr ) {
178 state_->minIterVec = x.clone();
180 state_->minIterVec->set(x);
181 state_->minIter = state_->iter;
182 state_->minValue = state_->value;
185 while (status_->check(*state_)) {
186 step_->compute(*s, x, obj, bnd, *state_);
187 step_->update(x, *s, obj, bnd, *state_);
190 x.print(vectorStream);
194 if ( state_->minValue > state_->value ) {
195 state_->minIterVec->set(*(state_->iterateVec));
196 state_->minValue = state_->value;
197 state_->minIter = state_->iter;
200 output.push_back(step_->print(*state_,printHeader_));
202 outStream << step_->print(*state_,printHeader_);
205 std::stringstream hist;
206 hist <<
"Optimization Terminated with Status: ";
207 hist << EExitStatusToString(state_->statusFlag);
209 output.push_back(hist.str());
211 outStream << hist.str();
220 virtual std::vector<std::string>
run( Vector<Real> &x,
222 Objective<Real> &obj,
223 Constraint<Real> &con,
225 std::ostream &outStream = std::cout,
226 bool printVectors =
false,
227 std::ostream &vectorStream = std::cout ) {
229 return run(x, x.dual(), l, l.dual(), obj, con, print, outStream, printVectors, vectorStream);
238 virtual std::vector<std::string>
run( Vector<Real> &x,
239 const Vector<Real> &g,
241 const Vector<Real> &c,
242 Objective<Real> &obj,
243 Constraint<Real> &con,
245 std::ostream &outStream = std::cout,
246 bool printVectors =
false,
247 std::ostream &vectorStream = std::cout ) {
249 x.print(vectorStream);
252 std::vector<std::string> output;
255 if ( state_->iterateVec == ROL::nullPtr ) {
256 state_->iterateVec = x.clone();
258 state_->iterateVec->set(x);
261 if ( state_->lagmultVec == ROL::nullPtr ) {
262 state_->lagmultVec = l.clone();
264 state_->lagmultVec->set(l);
267 ROL::Ptr<Vector<Real> > s = x.clone();
270 step_->initialize(x, g, l, c, obj, con, *state_);
271 output.push_back(step_->print(*state_,
true));
273 outStream << step_->print(*state_,
true);
277 if ( state_->minIterVec == ROL::nullPtr ) {
278 state_->minIterVec = x.clone();
280 state_->minIterVec->set(x);
281 state_->minIter = state_->iter;
282 state_->minValue = state_->value;
285 while (status_->check(*state_)) {
286 step_->compute(*s, x, l, obj, con, *state_);
287 step_->update(x, l, *s, obj, con, *state_);
290 x.print(vectorStream);
293 output.push_back(step_->print(*state_,printHeader_));
295 outStream << step_->print(*state_,printHeader_);
298 std::stringstream hist;
299 hist <<
"Optimization Terminated with Status: ";
300 hist << EExitStatusToString(state_->statusFlag);
302 output.push_back(hist.str());
304 outStream << hist.str();
312 virtual std::vector<std::string>
run( Vector<Real> &x,
314 Objective<Real> &obj,
315 Constraint<Real> &con,
316 BoundConstraint<Real> &bnd,
318 std::ostream &outStream = std::cout,
319 bool printVectors =
false,
320 std::ostream &vectorStream = std::cout) {
321 return run(x,x.dual(),l,l.dual(),obj,con,bnd,print,outStream,printVectors,vectorStream);
328 virtual std::vector<std::string>
run( Vector<Real> &x,
329 const Vector<Real> &g,
331 const Vector<Real> &c,
332 Objective<Real> &obj,
333 Constraint<Real> &con,
334 BoundConstraint<Real> &bnd,
336 std::ostream &outStream = std::cout,
337 bool printVectors =
false,
338 std::ostream &vectorStream = std::cout ) {
340 x.print(vectorStream);
343 std::vector<std::string> output;
346 if ( state_->iterateVec == ROL::nullPtr ) {
347 state_->iterateVec = x.clone();
349 state_->iterateVec->set(x);
352 if ( state_->lagmultVec == ROL::nullPtr ) {
353 state_->lagmultVec = l.clone();
355 state_->lagmultVec->set(l);
358 ROL::Ptr<Vector<Real> > s = x.clone();
361 step_->initialize(x, g, l, c, obj, con, bnd, *state_);
362 output.push_back(step_->print(*state_,
true));
364 outStream << step_->print(*state_,
true);
368 if ( state_->minIterVec == ROL::nullPtr ) {
369 state_->minIterVec = x.clone();
371 state_->minIterVec->set(x);
372 state_->minIter = state_->iter;
373 state_->minValue = state_->value;
376 while (status_->check(*state_)) {
377 step_->compute(*s, x, l, obj, con, bnd, *state_);
378 step_->update(x, l, *s, obj, con, bnd, *state_);
380 x.print(vectorStream);
382 output.push_back(step_->print(*state_,printHeader_));
384 outStream << step_->print(*state_,printHeader_);
387 std::stringstream hist;
388 hist <<
"Optimization Terminated with Status: ";
389 hist << EExitStatusToString(state_->statusFlag);
391 output.push_back(hist.str());
393 outStream << hist.str();
399 return step_->printHeader();
403 return step_->print(*state_,withHeader);
406 ROL::Ptr<const AlgorithmState<Real> >
getState(
void)
const {
Contains definitions of custom data types in ROL.
ROL::Ptr< StatusTest< Real > > status_
virtual std::vector< std::string > run(Vector< Real > &x, Vector< Real > &l, Objective< Real > &obj, Constraint< Real > &con, BoundConstraint< Real > &bnd, bool print=false, std::ostream &outStream=std::cout, bool printVectors=false, std::ostream &vectorStream=std::cout)
Run algorithm on equality and bound constrained problems (Type-EB). This is the primary Type-EB inter...
std::string getIterHeader(void)
std::string getIterInfo(bool withHeader=false)
virtual std::vector< std::string > run(Vector< Real > &x, Vector< Real > &l, Objective< Real > &obj, Constraint< Real > &con, bool print=false, std::ostream &outStream=std::cout, bool printVectors=false, std::ostream &vectorStream=std::cout)
Run algorithm on equality constrained problems (Type-E). This is the primary Type-E interface.
virtual std::vector< std::string > run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &bnd, bool print=false, std::ostream &outStream=std::cout, bool printVectors=false, std::ostream &vectorStream=std::cout)
Run algorithm on bound constrained problems (Type-B). This general interface supports the use of dual...
virtual std::vector< std::string > run(Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &bnd, bool print=false, std::ostream &outStream=std::cout, bool printVectors=false, std::ostream &vectorStream=std::cout)
Run algorithm on bound constrained problems (Type-B). This is the primary Type-B interface.
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.
virtual std::vector< std::string > run(Vector< Real > &x, const Vector< Real > &g, 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 general interface supports the use of dual opt...
ROL::Ptr< const AlgorithmState< Real > > getState(void) const
ROL::Ptr< AlgorithmState< Real > > state_
ROL::Ptr< Step< Real > > step_
virtual std::vector< std::string > run(Vector< Real > &x, const Vector< Real > &g, Vector< Real > &l, const Vector< Real > &c, Objective< Real > &obj, Constraint< Real > &con, bool print=false, std::ostream &outStream=std::cout, bool printVectors=false, std::ostream &vectorStream=std::cout)
Run algorithm on equality constrained problems (Type-E). This general interface supports the use of d...
Algorithm(const ROL::Ptr< Step< Real > > &step, const ROL::Ptr< StatusTest< Real > > &status, bool printHeader=false)
Constructor, given a step and a status test.
Algorithm(const ROL::Ptr< Step< Real > > &step, const ROL::Ptr< StatusTest< Real > > &status, const ROL::Ptr< AlgorithmState< Real > > &state, bool printHeader=false)
Constructor, given a step, a status test, and a previously defined algorithm state.
virtual std::vector< std::string > run(Vector< Real > &x, const Vector< Real > &g, Vector< Real > &l, const Vector< Real > &c, Objective< Real > &obj, Constraint< Real > &con, BoundConstraint< Real > &bnd, bool print=false, std::ostream &outStream=std::cout, bool printVectors=false, std::ostream &vectorStream=std::cout)
Run algorithm on equality and bound constrained problems (Type-EB). This general interface supports t...
Provides an interface to run unconstrained optimization algorithms.
Provides an interface to check status of optimization algorithms.
Provides the interface to compute optimization steps.