44 #ifndef ROL_ALGORITHM_H 45 #define ROL_ALGORITHM_H 74 Teuchos::RCP<Step<Real> >
step_;
76 Teuchos::RCP<AlgorithmState<Real> >
state_;
88 bool printHeader =
false ) {
92 printHeader_ = printHeader;
101 bool printHeader =
false ) {
105 printHeader_ = printHeader;
113 Teuchos::ParameterList &parlist,
114 bool printHeader =
false) {
122 std::invalid_argument,
123 "Invalid step name in algorithm constructor!");
126 step_ = stepFactory.
getStep(stepname,parlist);
129 printHeader_ = printHeader;
138 std::ostream &outStream = std::cout,
139 bool printVectors =
false,
140 std::ostream &vectorStream = std::cout ) {
143 return run(x,x.
dual(),obj,con,print,outStream,printVectors,vectorStream);
154 std::ostream &outStream = std::cout,
155 bool printVectors =
false,
156 std::ostream &vectorStream = std::cout ) {
159 return run(x,g,obj,con,print,outStream,printVectors,vectorStream);
169 std::ostream &outStream = std::cout,
170 bool printVectors =
false,
171 std::ostream &vectorStream = std::cout ) {
172 return run(x,x.
dual(),obj,con,print,outStream,printVectors,vectorStream);
184 std::ostream &outStream = std::cout,
185 bool printVectors =
false,
186 std::ostream &vectorStream = std::cout ) {
188 x.
print(vectorStream);
191 std::vector<std::string> output;
194 if ( state_->iterateVec == Teuchos::null ) {
195 state_->iterateVec = x.
clone();
197 state_->iterateVec->set(x);
200 Teuchos::RCP<Vector<Real> > s = x.
clone();
203 step_->initialize(x, g, obj, con, *state_);
204 output.push_back(step_->print(*state_,
true));
206 outStream << step_->print(*state_,
true);
210 if ( state_->minIterVec == Teuchos::null ) {
211 state_->minIterVec = x.
clone();
213 state_->minIterVec->set(x);
214 state_->minIter = state_->iter;
215 state_->minValue = state_->value;
218 while (status_->check(*state_)) {
219 step_->compute(*s, x, obj, con, *state_);
220 step_->update(x, *s, obj, con, *state_);
223 x.
print(vectorStream);
227 if ( state_->minValue > state_->value ) {
228 state_->minIterVec->set(*(state_->iterateVec));
229 state_->minValue = state_->value;
230 state_->minIter = state_->iter;
233 output.push_back(step_->print(*state_,printHeader_));
235 outStream << step_->print(*state_,printHeader_);
250 std::ostream &outStream = std::cout,
251 bool printVectors =
false,
252 std::ostream &vectorStream = std::cout ) {
254 return run(x, x.
dual(), l, l.
dual(), obj, con, print, outStream, printVectors, vectorStream);
270 std::ostream &outStream = std::cout,
271 bool printVectors =
false,
272 std::ostream &vectorStream = std::cout ) {
274 x.
print(vectorStream);
277 std::vector<std::string> output;
280 if ( state_->iterateVec == Teuchos::null ) {
281 state_->iterateVec = x.
clone();
283 state_->iterateVec->set(x);
286 if ( state_->lagmultVec == Teuchos::null ) {
287 state_->lagmultVec = l.
clone();
289 state_->lagmultVec->set(l);
292 Teuchos::RCP<Vector<Real> > s = x.
clone();
295 step_->initialize(x, g, l, c, obj, con, *state_);
296 output.push_back(step_->print(*state_,
true));
298 outStream << step_->print(*state_,
true);
302 if ( state_->minIterVec == Teuchos::null ) {
303 state_->minIterVec = x.
clone();
305 state_->minIterVec->set(x);
306 state_->minIter = state_->iter;
307 state_->minValue = state_->value;
310 while (status_->check(*state_)) {
311 step_->compute(*s, x, l, obj, con, *state_);
312 step_->update(x, l, *s, obj, con, *state_);
315 x.
print(vectorStream);
318 output.push_back(step_->print(*state_,printHeader_));
320 outStream << step_->print(*state_,printHeader_);
335 std::ostream &outStream = std::cout,
336 bool printVectors =
false,
337 std::ostream &vectorStream = std::cout) {
338 return run(x,x.
dual(),l,l.
dual(),obj,con,bnd,print,outStream,printVectors,vectorStream);
353 std::ostream &outStream = std::cout,
354 bool printVectors =
false,
355 std::ostream &vectorStream = std::cout ) {
357 x.
print(vectorStream);
360 std::vector<std::string> output;
363 if ( state_->iterateVec == Teuchos::null ) {
364 state_->iterateVec = x.
clone();
366 state_->iterateVec->set(x);
369 if ( state_->lagmultVec == Teuchos::null ) {
370 state_->lagmultVec = l.
clone();
372 state_->lagmultVec->set(l);
375 Teuchos::RCP<Vector<Real> > s = x.
clone();
378 step_->initialize(x, g, l, c, obj, con, bnd, *state_);
379 output.push_back(step_->print(*state_,
true));
381 outStream << step_->print(*state_,
true);
385 if ( state_->minIterVec == Teuchos::null ) {
386 state_->minIterVec = x.
clone();
388 state_->minIterVec->set(x);
389 state_->minIter = state_->iter;
390 state_->minValue = state_->value;
393 while (status_->check(*state_)) {
394 step_->compute(*s, x, l, obj, con, bnd, *state_);
395 step_->update(x, l, *s, obj, con, bnd, *state_);
397 x.
print(vectorStream);
399 output.push_back(step_->print(*state_,printHeader_));
401 outStream << step_->print(*state_,printHeader_);
411 std::ostream &outStream = std::cout ) {
413 Teuchos::RCP<Objective<Real> > obj = opt.
getObjective();
420 if ( con == Teuchos::null ) {
421 if ( bnd == Teuchos::null ) {
422 return run(*x,*obj,print,outStream);
425 return run(*x,*obj,*bnd,print,outStream);
429 if ( bnd == Teuchos::null ) {
430 return run(*x,*l,*obj,*con,print,outStream);
433 return run(*x,*l,*obj,*con,*bnd,print,outStream);
439 return step_->printHeader();
443 return step_->print(*state_,withHeader);
446 Teuchos::RCP<const AlgorithmState<Real> >
getState(
void)
const {
Provides the interface to evaluate objective functions.
virtual std::vector< std::string > run(Vector< Real > &x, const Vector< Real > &g, Vector< Real > &l, const Vector< Real > &c, Objective< Real > &obj, EqualityConstraint< 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...
EStep StringToEStep(std::string s)
virtual std::vector< std::string > run(Vector< Real > &x, Vector< Real > &l, Objective< Real > &obj, EqualityConstraint< 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...
void stepFactory(Teuchos::ParameterList &parlist, Teuchos::RCP< ROL::Step< Real > > &step)
A minimalist step factory which specializes the Step Type depending on whether a Trust-Region or Line...
Provides the interface to compute optimization steps.
Teuchos::RCP< Step< Real > > getStep(const std::string &type, Teuchos::ParameterList &parlist) const
Contains definitions of custom data types in ROL.
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 Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Defines the linear algebra or vector space 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...
Teuchos::RCP< AlgorithmState< Real > > state_
Teuchos::RCP< BoundConstraint< Real > > getBoundConstraint(void)
State for algorithm class. Will be used for restarts.
Teuchos::RCP< const AlgorithmState< Real > > getState(void) const
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
Defines the equality constraint operator interface.
virtual std::vector< std::string > run(OptimizationProblem< Real > &opt, bool print=false, std::ostream &outStream=std::cout)
Run algorithm using a ROL::OptimizationProblem.
virtual std::vector< std::string > run(Vector< Real > &x, const Vector< Real > &g, Vector< Real > &l, const Vector< Real > &c, Objective< Real > &obj, EqualityConstraint< 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 optimization algorithms.
Provides an interface to check status of optimization algorithms.
Algorithm(const Teuchos::RCP< Step< Real > > &step, const Teuchos::RCP< StatusTest< Real > > &status, const Teuchos::RCP< 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, Objective< Real > &obj, BoundConstraint< Real > &con, 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.
Teuchos::RCP< Vector< Real > > getMultiplierVector(void)
Provides the interface to apply upper and lower bound constraints.
int isValidStep(EStep ls)
Verifies validity of a TrustRegion enum.
Teuchos::RCP< StatusTest< Real > > status_
Teuchos::RCP< EqualityConstraint< Real > > getEqualityConstraint(void)
Teuchos::RCP< Vector< Real > > getSolutionVector(void)
virtual std::vector< std::string > run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, BoundConstraint< Real > &con, 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...
Teuchos::RCP< StatusTest< Real > > getStatusTest(const std::string step, Teuchos::ParameterList &parlist)
Teuchos::RCP< Step< Real > > step_
Algorithm(const Teuchos::RCP< Step< Real > > &step, const Teuchos::RCP< StatusTest< Real > > &status, bool printHeader=false)
Constructor, given a step and a status test.
std::string getIterInfo(bool withHeader=false)
virtual std::vector< std::string > run(Vector< Real > &x, Vector< Real > &l, Objective< Real > &obj, EqualityConstraint< 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...
void deactivate(void)
Turn off bounds.
EStep
Enumeration of step types.
Teuchos::RCP< Objective< Real > > getObjective(void)
Algorithm(const std::string &stepname, Teuchos::ParameterList &parlist, bool printHeader=false)
Constructor, given a string, for the step, and a parameter list of various options. The status test is determined based on the step string.
virtual void print(std::ostream &outStream) const
std::string getIterHeader(void)