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) {
117 std::invalid_argument,
118 "Invalid step name in algorithm constructor!");
121 step_ = stepFactory.
getStep(stepname,parlist);
124 printHeader_ = printHeader;
133 std::ostream &outStream = std::cout ) {
136 return run(x,x.
dual(),obj,con,print,outStream);
147 std::ostream &outStream = std::cout ) {
150 return run(x,g,obj,con,print,outStream);
160 std::ostream &outStream = std::cout ) {
161 return run(x,x.
dual(),obj,con,print,outStream);
173 std::ostream &outStream = std::cout ) {
174 std::vector<std::string> output;
177 if ( state_->iterateVec == Teuchos::null ) {
178 state_->iterateVec = x.
clone();
180 state_->iterateVec->set(x);
183 Teuchos::RCP<Vector<Real> > s = x.
clone();
186 step_->initialize(x, g, obj, con, *state_);
187 output.push_back(step_->print(*state_,
true));
189 outStream << step_->print(*state_,
true);
193 if ( state_->minIterVec == Teuchos::null ) {
194 state_->minIterVec = x.
clone();
196 state_->minIterVec->set(x);
197 state_->minIter = state_->iter;
198 state_->minValue = state_->value;
201 while (status_->check(*state_)) {
202 step_->compute(*s, x, obj, con, *state_);
203 step_->update(x, *s, obj, con, *state_);
205 if ( state_->minValue > state_->value ) {
206 state_->minIterVec->set(*(state_->iterateVec));
207 state_->minValue = state_->value;
208 state_->minIter = state_->iter;
211 output.push_back(step_->print(*state_,printHeader_));
213 outStream << step_->print(*state_,printHeader_);
228 std::ostream &outStream = std::cout ) {
230 return run(x, x.
dual(), l, l.
dual(), obj, con, print, outStream);
246 std::ostream &outStream = std::cout ) {
247 std::vector<std::string> output;
250 if ( state_->iterateVec == Teuchos::null ) {
251 state_->iterateVec = x.
clone();
253 state_->iterateVec->set(x);
256 if ( state_->lagmultVec == Teuchos::null ) {
257 state_->lagmultVec = l.
clone();
259 state_->lagmultVec->set(l);
262 Teuchos::RCP<Vector<Real> > s = x.
clone();
265 step_->initialize(x, g, l, c, obj, con, *state_);
266 output.push_back(step_->print(*state_,
true));
268 outStream << step_->print(*state_,
true);
272 if ( state_->minIterVec == Teuchos::null ) {
273 state_->minIterVec = x.
clone();
275 state_->minIterVec->set(x);
276 state_->minIter = state_->iter;
277 state_->minValue = state_->value;
280 while (status_->check(*state_)) {
281 step_->compute(*s, x, l, obj, con, *state_);
282 step_->update(x, l, *s, obj, con, *state_);
283 output.push_back(step_->print(*state_,printHeader_));
285 outStream << step_->print(*state_,printHeader_);
300 std::ostream &outStream = std::cout ) {
301 return run(x,x.
dual(),l,l.
dual(),obj,con,bnd,print,outStream);
316 std::ostream &outStream = std::cout ) {
317 std::vector<std::string> output;
320 if ( state_->iterateVec == Teuchos::null ) {
321 state_->iterateVec = x.
clone();
323 state_->iterateVec->set(x);
326 if ( state_->lagmultVec == Teuchos::null ) {
327 state_->lagmultVec = l.
clone();
329 state_->lagmultVec->set(l);
332 Teuchos::RCP<Vector<Real> > s = x.
clone();
335 step_->initialize(x, g, l, c, obj, con, bnd, *state_);
336 output.push_back(step_->print(*state_,
true));
338 outStream << step_->print(*state_,
true);
342 if ( state_->minIterVec == Teuchos::null ) {
343 state_->minIterVec = x.
clone();
345 state_->minIterVec->set(x);
346 state_->minIter = state_->iter;
347 state_->minValue = state_->value;
350 while (status_->check(*state_)) {
351 step_->compute(*s, x, l, obj, con, bnd, *state_);
352 step_->update(x, l, *s, obj, con, bnd, *state_);
353 output.push_back(step_->print(*state_,printHeader_));
355 outStream << step_->print(*state_,printHeader_);
365 std::ostream &outStream = std::cout ) {
367 Teuchos::RCP<Objective<Real> > obj = opt.
getObjective();
373 if ( con == Teuchos::null ) {
374 if ( bnd == Teuchos::null ) {
375 return run(*x,*obj,print,outStream);
378 return run(*x,*obj,*bnd,print,outStream);
382 if ( bnd == Teuchos::null ) {
383 return run(*x,*l,*obj,*con,print,outStream);
386 return run(*x,*l,*obj,*con,*bnd,print,outStream);
392 return step_->printHeader();
396 return step_->print(*state_,withHeader);
399 Teuchos::RCP<const AlgorithmState<Real> >
getState(
void)
const {
Provides the interface to evaluate objective functions.
virtual const Vector & dual() const
Return dual representation of , for example, the result of applying a Riesz map, or change of basis...
EStep StringToEStep(std::string s)
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...
virtual std::vector< std::string > run(Vector< Real > &x, Objective< Real > &obj, BoundConstraint< Real > &con, bool print=false, std::ostream &outStream=std::cout)
Run algorithm on bound constrained problems (Type-B). This is the primary Type-B interface.
Provides the interface to compute optimization steps.
Contains definitions of custom data types in ROL.
Teuchos::RCP< const AlgorithmState< Real > > getState(void) const
virtual Teuchos::RCP< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
Defines the linear algebra or vector space interface.
Teuchos::RCP< AlgorithmState< Real > > state_
Teuchos::RCP< BoundConstraint< Real > > getBoundConstraint(void)
State for algorithm class. Will be used for restarts.
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)
Run algorithm on bound constrained problems (Type-B). This general interface supports the use of dual...
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, Vector< Real > &l, Objective< Real > &obj, EqualityConstraint< Real > &con, bool print=false, std::ostream &outStream=std::cout)
Run algorithm on equality constrained problems (Type-E). This is the primary Type-E interface...
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.
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.
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)
Run algorithm on equality constrained problems (Type-E). This general interface supports the use of d...
Teuchos::RCP< StatusTest< Real > > status_
Teuchos::RCP< EqualityConstraint< Real > > getEqualityConstraint(void)
Teuchos::RCP< Vector< Real > > getSolutionVector(void)
Teuchos::RCP< StatusTest< Real > > getStatusTest(const std::string step, Teuchos::ParameterList &parlist)
virtual std::vector< std::string > run(Vector< Real > &x, Objective< Real > &obj, bool print=false, std::ostream &outStream=std::cout)
Run algorithm on unconstrained problems (Type-U). This is the primary Type-U interface.
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, 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)
Run algorithm on equality and bound constrained problems (Type-EB). This general interface supports t...
void deactivate(void)
Turn off bounds.
EStep
Enumeration of step types.
virtual std::vector< std::string > run(Vector< Real > &x, const Vector< Real > &g, Objective< Real > &obj, bool print=false, std::ostream &outStream=std::cout)
Run algorithm on unconstrained problems (Type-U). This general interface supports the use of dual opt...
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)
Run algorithm on equality and bound constrained problems (Type-EB). This is the primary Type-EB inter...
Teuchos::RCP< Objective< Real > > getObjective(void)
Teuchos::RCP< Step< Real > > getStep(const std::string &type, Teuchos::ParameterList &parlist) const
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.
std::string getIterHeader(void)