10 #ifndef ROL_TYPE_ALGORITHM_DEF_H
11 #define ROL_TYPE_ALGORITHM_DEF_H
21 template<
typename Real>
29 template<
typename Real>
34 if (state_->iterateVec == nullPtr) {
35 state_->iterateVec = x.
clone();
37 state_->iterateVec->set(x);
38 if (state_->lagmultVec == nullPtr) {
39 state_->lagmultVec = mul.
clone();
41 state_->lagmultVec->set(mul);
42 if (state_->stepVec == nullPtr) {
43 state_->stepVec = x.
clone();
45 state_->stepVec->zero();
46 if (state_->gradientVec == nullPtr) {
47 state_->gradientVec = g.
clone();
49 state_->gradientVec->set(g);
50 if (state_->constraintVec == nullPtr) {
51 state_->constraintVec = c.
clone();
53 state_->constraintVec->zero();
54 if (state_->minIterVec == nullPtr) {
55 state_->minIterVec = x.
clone();
57 state_->minIterVec->set(x);
58 state_->minIter = state_->iter;
59 state_->minValue = state_->value;
62 template<
typename Real>
64 const bool combineStatus) {
71 template<
typename Real>
73 std::ostream &outStream ) {
89 template<
typename Real>
94 std::ostream &outStream ) {
95 Problem<Real> problem(makePtrFromRef(obj), makePtrFromRef(x));
96 problem.
addConstraint(
"NEC",makePtrFromRef(econ),makePtrFromRef(emul));
97 problem.
finalize(
false,
false,outStream);
98 run(problem,outStream);
102 template<
typename Real>
109 std::ostream &outStream ) {
110 Problem<Real> problem(makePtrFromRef(obj), makePtrFromRef(x));
111 problem.
addConstraint(
"NEC",makePtrFromRef(econ),makePtrFromRef(emul));
112 problem.
addLinearConstraint(
"LEC",makePtrFromRef(linear_econ),makePtrFromRef(linear_emul));
113 problem.
finalize(
false,
false,outStream);
114 run(problem,outStream);
118 template<
typename Real>
128 std::ostream &outStream ) {
129 Ptr<Vector<Real>> gp = g.
clone(), erp = eres.
clone(), lerp = linear_eres.
clone();
130 Problem<Real> problem(makePtrFromRef(obj), makePtrFromRef(x), gp);
131 problem.
addConstraint(
"NEC",makePtrFromRef(econ),makePtrFromRef(emul),erp,
false);
132 problem.
addLinearConstraint(
"LEC",makePtrFromRef(linear_econ),makePtrFromRef(linear_emul),lerp,
false);
133 problem.
finalize(
false,
false,outStream);
134 run(problem,outStream);
145 template<
typename Real>
147 std::ios_base::fmtflags osFlags(os.flags());
149 os << std::setw(6) << std::left <<
"iter";
150 os << std::setw(15) << std::left <<
"value";
151 os << std::setw(15) << std::left <<
"cnorm";
152 os << std::setw(15) << std::left <<
"gLnorm";
153 os << std::setw(15) << std::left <<
"snorm";
154 os << std::setw(10) << std::left <<
"#fval";
155 os << std::setw(10) << std::left <<
"#grad";
160 template<
typename Real>
165 template<
typename Real>
167 std::ios_base::fmtflags osFlags(os.flags());
168 os << std::scientific << std::setprecision(6);
169 if ( write_header ) writeHeader(os);
170 if ( state_->iter == 0 ) {
172 os << std::setw(6) << std::left << state_->iter;
173 os << std::setw(15) << std::left << state_->value;
174 os << std::setw(15) << std::left << state_->cnorm;
175 os << std::setw(15) << std::left << state_->gnorm;
180 os << std::setw(6) << std::left << state_->iter;
181 os << std::setw(15) << std::left << state_->value;
182 os << std::setw(15) << std::left << state_->cnorm;
183 os << std::setw(15) << std::left << state_->gnorm;
184 os << std::setw(15) << std::left << state_->snorm;
185 os << std::setw(10) << std::left << state_->nfval;
186 os << std::setw(10) << std::left << state_->ngrad;
192 template<
typename Real>
194 std::ios_base::fmtflags osFlags(os.flags());
195 os <<
"Optimization Terminated with Status: ";
201 template<
typename Real>
207 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 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.
Contains definitions of custom data types in ROL.
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...
virtual void run(Problem< Real > &problem, std::ostream &outStream=std::cout)
Run algorithm on equality constrained problems (Type-E). This is the primary Type-E interface...
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 writeName(std::ostream &os) const
Print step name.
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...
virtual void writeOutput(std::ostream &os, const bool write_header=false) const
Print iterate status.
Provides an interface to check status of optimization algorithms.
void setStatusTest(const Ptr< StatusTest< Real >> &status, bool combineStatus=false)
const Ptr< CombinedStatusTest< Real > > status_
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.
EProblem getProblemType()
Get the optimization problem type (U, B, E, or G).
virtual void writeExitStatus(std::ostream &os) const
void initialize(const Vector< Real > &x, const Vector< Real > &g, const Vector< Real > &mul, const Vector< Real > &c)
Ptr< const AlgorithmState< Real > > getState() const
Provides an interface to check two status tests of optimization algorithms.
const Ptr< Vector< Real > > & getDualOptimizationVector()
Get the dual optimization space vector.
Algorithm()
Constructor, given a step and a status test.
Defines the general constraint operator interface.