63 #include "Teuchos_GlobalMPISession.hpp"
72 ROL::Ptr<ROL::Objective<Real>>
76 auto op = ROL::makePtr<ROL::DiagonalOperator<Real>>(a);
79 auto obj = ROL::makePtr<ROL::QuadraticObjective<Real>>(op,vec);
85 int main(
int argc,
char *argv[]) {
92 Teuchos::GlobalMPISession mpiSession(&argc, &argv);
96 int iprint = argc - 1;
97 ROL::Ptr<std::ostream> outStream;
100 outStream = ROL::makePtrFromRef(std::cout);
102 outStream = ROL::makePtrFromRef(bhs);
108 auto parlist = ROL::getParametersFromXmlFile(
"binary_constraint.xml");
113 RealT INF = ROL::ROL_INF<RealT>();
114 RealT NINF = ROL::ROL_NINF<RealT>();
119 auto x0_ptr = ROL::makePtr<std::vector<RealT>>(4);
120 auto x0 = ROL::makePtr<SV>(x0_ptr);
123 auto x = x0->clone(); x->set(*x0);
128 auto d_ptr = ROL::makePtr<std::vector<RealT>>(4);
129 auto d = ROL::makePtr<SV>(d_ptr);
132 auto b_ptr = ROL::makePtr<std::vector<RealT>>(4);
133 auto b = ROL::makePtr<SV>(b_ptr);
136 (*b_ptr)[0] = 1.0; (*b_ptr)[1] = 1.0;
137 (*b_ptr)[2] = 1.0; (*b_ptr)[3] = 1.0;
139 (*d_ptr)[0] = 1.0; (*d_ptr)[1] = 2.0;
140 (*d_ptr)[2] = 4.0; (*d_ptr)[3] = 8.0;
150 auto xl_ptr = ROL::makePtr<std::vector<RealT>>(4);
151 auto xl = ROL::makePtr<SV>(xl_ptr);
154 auto xu_ptr = ROL::makePtr<std::vector<RealT>>(4);
155 auto xu = ROL::makePtr<SV>(xu_ptr);
158 (*xl_ptr)[0] = 0.0; (*xl_ptr)[1] = 0.0;
159 (*xl_ptr)[2] = NINF; (*xl_ptr)[3] = NINF;
161 (*xu_ptr)[0] = 1.0; (*xu_ptr)[1] = INF;
162 (*xu_ptr)[2] = 1.0; (*xu_ptr)[3] = INF;
165 auto bnd = ROL::makePtr<ROL::Bounds<RealT>>(xl,xu);
169 auto con = ROL::makePtr<ROL::BinaryConstraint<RealT>>( bnd, gamma );
172 auto l = x->dual().clone();
173 ROL::Elementwise::Fill<RealT> FillWithOnes(1.0);
174 l->applyUnary( ROL::Elementwise::Fill<RealT>(1.0) );
183 problem_E.
check( *outStream );
188 parlist->sublist(
"Step").set(
"Type",
"Composite Step");
190 solver_cs.
solve( *outStream );
191 *outStream <<
"\n\nFinal optimization vector:";
192 x->print(*outStream);
195 x->set(*x0); l->applyUnary(FillWithOnes);
200 parlist->sublist(
"Step").set(
"Type",
"Augmented Lagrangian");
202 solver_al.
solve( *outStream );
203 *outStream <<
"\n\nFinal optimization vector:";
204 x->print(*outStream);
208 x->set(*x0); l->applyUnary(FillWithOnes);
213 parlist->sublist(
"Step").set(
"Type",
"Moreau-Yosida Penalty");
215 solver_my.
solve( *outStream );
216 *outStream <<
"\n\nFinal optimization vector:";
217 x->print(*outStream);
222 catch (std::logic_error& err) {
223 *outStream << err.what() <<
"\n";
228 std::cout <<
"End Result: TEST FAILED\n";
230 std::cout <<
"End Result: TEST PASSED\n";
virtual ROL::Ptr< Vector > clone() const =0
Clone to make a new (uninitialized) vector.
void RandomizeVector(Vector< Real > &x, const Real &lower=0.0, const Real &upper=1.0)
Fill a ROL::Vector with uniformly-distributed random numbers in the interval [lower,upper].
Defines the linear algebra or vector space interface.
Defines a no-output stream class ROL::NullStream and a function makeStreamPtr which either wraps a re...
Provides the ROL::Vector interface for scalar values, to be used, for example, with scalar constraint...
Provides a simplified interface for solving a wide range of optimization problems.
basic_nullstream< char, char_traits< char >> nullstream
ROL::Ptr< ROL::Objective< Real > > createDiagonalQuadraticObjective(const ROL::Vector< Real > &a, const ROL::Vector< Real > &b)
int main(int argc, char *argv[])
void check(std::ostream &outStream=std::cout, const int numSteps=ROL_NUM_CHECKDERIV_STEPS, const int order=1)
int solve(const ROL::Ptr< StatusTest< Real > > &status=ROL::nullPtr, const bool combineStatus=true)
Solve optimization problem with no iteration output.